Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
/ *
Copyright ( c ) 2017 , Lars Brubaker , John Lewin
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this
list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies ,
either expressed or implied , of the FreeBSD Project .
* /
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.IO ;
using System.Linq ;
using System.Threading.Tasks ;
using MatterHackers.Agg ;
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.DataStorage ;
using MatterHackers.MatterControl.PrinterCommunication ;
using MatterHackers.MatterControl.PrintQueue ;
using MatterHackers.MatterControl.SlicerConfiguration ;
using Newtonsoft.Json ;
namespace MatterHackers.MatterControl
{
2017-06-16 18:04:47 -07:00
using System.IO.Compression ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using System.Net ;
using System.Reflection ;
2017-08-17 18:18:41 -07:00
using System.Text ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using System.Threading ;
using Agg.Font ;
using Agg.Image ;
using CustomWidgets ;
2017-08-20 02:34:39 -07:00
using MatterHackers.Agg.Platform ;
2017-06-02 17:04:02 -07:00
using MatterHackers.DataConverters3D ;
2017-06-24 10:30:11 -07:00
using MatterHackers.GCodeVisualizer ;
2017-06-16 18:04:47 -07:00
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using MatterHackers.MatterControl.Library ;
2017-06-01 18:19:37 -07:00
using MatterHackers.MatterControl.PartPreviewWindow ;
2017-08-14 08:57:24 -07:00
using MatterHackers.MeshVisualizer ;
2017-08-16 17:13:16 -07:00
using MatterHackers.PolygonMesh ;
2017-06-16 18:04:47 -07:00
using MatterHackers.SerialPortCommunication ;
2017-06-01 18:19:37 -07:00
using MatterHackers.VectorMath ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using SettingsManagement ;
2017-06-24 10:30:11 -07:00
public class BedConfig
{
2017-06-28 20:48:00 -07:00
public event EventHandler ActiveLayerChanged ;
2017-06-30 15:05:07 -07:00
public event EventHandler LoadedGCodeChanged ;
2017-08-16 17:13:16 -07:00
public View3DConfig RendererOptions { get ; } = new View3DConfig ( ) ;
2017-09-15 21:59:36 -07:00
public PrintItemWrapper printItem = null ;
2017-08-16 07:22:07 -07:00
2017-09-15 16:49:21 -07:00
public PrinterConfig Printer { get ; set ; }
public Mesh PrinterShape { get ; private set ; }
2017-08-16 17:13:16 -07:00
2017-09-15 21:59:36 -07:00
public BedConfig ( PrinterConfig printer = null , bool loadLastBedplate = false )
2017-08-16 17:13:16 -07:00
{
2017-09-15 16:49:21 -07:00
this . Printer = printer ;
2017-09-15 21:59:36 -07:00
if ( loadLastBedplate )
{
// Find the last used bed plate mcx
var directoryInfo = new DirectoryInfo ( ApplicationDataStorage . Instance . PlatingDirectory ) ;
var firstFile = directoryInfo . GetFileSystemInfos ( "*.mcx" ) . OrderByDescending ( fl = > fl . CreationTime ) . FirstOrDefault ( ) ;
// Set as the current item - should be restored as the Active scene in the MeshViewer
if ( firstFile ! = null )
{
try
{
var loadedItem = new PrintItemWrapper ( new PrintItem ( firstFile . Name , firstFile . FullName ) ) ;
if ( loadedItem ! = null )
{
this . printItem = loadedItem ;
}
2017-09-15 23:13:23 -07:00
this . Scene . Load ( firstFile . FullName ) ;
2017-09-15 21:59:36 -07:00
}
catch { }
}
}
// Clear if not assigned above
if ( this . printItem = = null )
{
this . ClearPlate ( ) ;
}
2017-08-16 17:13:16 -07:00
}
2017-07-05 12:45:42 -07:00
2017-09-15 18:45:21 -07:00
internal void ClearPlate ( )
{
string now = DateTime . Now . ToString ( "yyyyMMdd-HHmmss" ) ;
string mcxPath = Path . Combine ( ApplicationDataStorage . Instance . PlatingDirectory , now + ".mcx" ) ;
this . printItem = new PrintItemWrapper ( new PrintItem ( now , mcxPath ) ) ;
File . WriteAllText ( mcxPath , new Object3D ( ) . ToJson ( ) ) ;
this . Scene . Load ( mcxPath ) ;
ApplicationController . Instance . ActiveView3DWidget ? . PartHasBeenChanged ( ) ;
}
2017-06-30 15:05:07 -07:00
private GCodeFile loadedGCode ;
public GCodeFile LoadedGCode
{
get = > loadedGCode ;
set
{
if ( loadedGCode ! = value )
{
loadedGCode = value ;
LoadedGCodeChanged ? . Invoke ( null , null ) ;
}
}
}
2017-06-24 10:38:08 -07:00
2017-07-10 14:00:27 -07:00
public WorldView World { get ; } = new WorldView ( 0 , 0 ) ;
2017-08-16 05:53:26 -07:00
public double BuildHeight { get ; internal set ; }
public Vector3 ViewerVolume { get ; internal set ; }
public Vector2 BedCenter { get ; internal set ; }
public BedShape BedShape { get ; internal set ; }
2017-06-24 10:38:08 -07:00
// TODO: Make assignment private, wire up post slicing initialization here
public GCodeRenderer GCodeRenderer { get ; set ; }
2017-06-28 20:48:00 -07:00
public int ActiveLayerIndex
{
get
{
return activeLayerIndex ;
}
set
{
if ( activeLayerIndex ! = value )
{
activeLayerIndex = value ;
2017-07-11 12:07:22 -07:00
// Clamp activeLayerIndex to valid range
2017-06-28 20:48:00 -07:00
if ( this . GCodeRenderer = = null | | activeLayerIndex < 0 )
{
activeLayerIndex = 0 ;
}
2017-06-29 13:35:44 -07:00
else if ( activeLayerIndex > = this . LoadedGCode . LayerCount )
2017-06-28 20:48:00 -07:00
{
2017-06-29 13:35:44 -07:00
activeLayerIndex = this . LoadedGCode . LayerCount - 1 ;
2017-06-28 20:48:00 -07:00
}
2017-06-29 13:12:27 -07:00
// When the active layer changes we update the selected range accordingly - constrain to applicable values
2017-09-01 21:23:08 -07:00
this . RenderInfo . EndLayerIndex = Math . Min ( this . LoadedGCode = = null ? 0 : this . LoadedGCode . LayerCount - 1 , Math . Max ( activeLayerIndex , 1 ) ) ;
2017-06-28 20:48:00 -07:00
ActiveLayerChanged ? . Invoke ( this , null ) ;
}
}
}
private int activeLayerIndex ;
2017-08-14 08:57:24 -07:00
public InteractiveScene Scene { get ; } = new InteractiveScene ( ) ;
2017-06-28 20:48:00 -07:00
public GCodeRenderInfo RenderInfo { get ; set ; }
2017-08-16 07:22:07 -07:00
public string GCodePath
{
get
{
bool isGCode = Path . GetExtension ( printItem . FileLocation ) . ToUpper ( ) = = ".GCODE" ;
return isGCode ? printItem . FileLocation : printItem . GetGCodePathAndFileName ( ) ;
}
}
2017-08-16 17:13:16 -07:00
BedMeshGenerator bedGenerator ;
private Mesh _bedMesh ;
public Mesh Mesh
{
get
{
if ( _bedMesh = = null )
{
bedGenerator = new BedMeshGenerator ( ) ;
//Construct the thing
2017-09-15 16:49:21 -07:00
_bedMesh = bedGenerator . CreatePrintBed ( Printer ) ;
Task . Run ( ( ) = >
{
try
{
string url = Printer . Settings . GetValue ( "PrinterShapeUrl" ) ;
string extension = Printer . Settings . GetValue ( "PrinterShapeExtension" ) ;
if ( string . IsNullOrEmpty ( url ) | | string . IsNullOrEmpty ( extension ) )
{
return ;
}
using ( var stream = ApplicationController . Instance . LoadHttpAsset ( url ) )
{
var mesh = MeshFileIo . Load ( stream , extension , CancellationToken . None ) . Mesh ;
BspNode bspTree = null ;
// if there is a chached bsp tree load it
var meshHashCode = mesh . GetLongHashCode ( ) ;
string cachePath = ApplicationController . CacheablePath ( "MeshBspData" , $"{meshHashCode}.bsp" ) ;
if ( File . Exists ( cachePath ) )
{
JsonConvert . DeserializeObject < BspNode > ( File . ReadAllText ( cachePath ) ) ;
}
else
{
// else calculate it
bspTree = FaceBspTree . Create ( mesh , 20 , true ) ;
// and save it
File . WriteAllText ( cachePath , JsonConvert . SerializeObject ( bspTree ) ) ;
}
// set the mesh to use the new tree
UiThread . RunOnIdle ( ( ) = >
{
mesh . FaceBspTree = bspTree ;
this . PrinterShape = mesh ;
// TODO: Need to send a notification that the mesh changed so the UI can pickup and render
} ) ;
}
}
catch { }
} ) ;
2017-08-16 17:13:16 -07:00
}
return _bedMesh ;
}
}
private Mesh _buildVolumeMesh ;
public Mesh BuildVolumeMesh
{
get
{
if ( _buildVolumeMesh = = null )
{
//Construct the thing
//_buildVolumeMesh = CreatePrintBed(printer);
}
return _buildVolumeMesh ;
}
}
2017-08-24 13:58:06 -07:00
internal void Render3DLayerFeatures ( DrawEventArgs e )
2017-06-28 20:48:00 -07:00
{
if ( this . RenderInfo ! = null )
{
2017-07-06 07:56:38 -07:00
// If needed, update the RenderType flags to match to current user selection
2017-07-05 12:45:42 -07:00
if ( RendererOptions . IsDirty )
{
this . RenderInfo . RefreshRenderType ( ) ;
RendererOptions . IsDirty = false ;
}
2017-08-24 13:58:06 -07:00
this . GCodeRenderer . Render3D ( this . RenderInfo , e ) ;
2017-06-28 20:48:00 -07:00
}
}
2017-06-30 21:37:58 -07:00
2017-08-16 17:13:16 -07:00
public void LoadGCode ( string filePath , CancellationToken cancellationToken , Action < double , string > progressReporter )
2017-06-30 21:37:58 -07:00
{
2017-07-14 13:55:02 -07:00
this . LoadedGCode = GCodeMemoryFile . Load ( filePath , cancellationToken , progressReporter ) ;
2017-06-30 21:37:58 -07:00
this . GCodeRenderer = new GCodeRenderer ( loadedGCode ) ;
if ( ActiveSliceSettings . Instance . PrinterSelected )
{
GCodeRenderer . ExtruderWidth = ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . nozzle_diameter ) ;
}
else
{
GCodeRenderer . ExtruderWidth = . 4 ;
}
try
{
// TODO: After loading we reprocess the entire document just to compute filament used. If it's a feature we need, seems like it should just be normal step during load and result stored in a property
GCodeRenderer . GCodeFileToDraw ? . GetFilamentUsedMm ( ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . filament_diameter ) ) ;
}
catch ( Exception ex )
{
Debug . Print ( ex . Message ) ;
}
}
2017-08-16 17:13:16 -07:00
public void RecreateBed ( )
{
if ( bedGenerator ! = null )
{
2017-09-15 16:49:21 -07:00
_bedMesh = bedGenerator . CreatePrintBed ( Printer ) ;
2017-08-16 17:13:16 -07:00
}
}
2017-06-24 10:30:11 -07:00
}
2017-06-02 17:04:02 -07:00
2017-08-15 19:13:55 -07:00
public class PrinterViewState
{
2017-09-01 11:44:18 +03:00
public bool SliceSettingsTabPinned
{
get = > UserSettings . Instance . get ( UserSettingsKey . SliceSettingsTabPinned ) = = "true" ;
set
{
UserSettings . Instance . set ( UserSettingsKey . SliceSettingsTabPinned , value ? "true" : "false" ) ;
}
}
public int SliceSettingsTabIndex
{
get
{
int . TryParse ( UserSettings . Instance . get ( UserSettingsKey . SliceSettingsTabIndex ) , out int tabIndex ) ;
return tabIndex ;
}
set
{
UserSettings . Instance . set ( UserSettingsKey . SliceSettingsTabIndex , value . ToString ( ) ) ;
}
}
public double SliceSettingsWidth
{
get
{
double . TryParse ( UserSettings . Instance . get ( UserSettingsKey . SliceSettingsWidth ) , out double controlWidth ) ;
return controlWidth ;
}
set
{
UserSettings . Instance . set ( UserSettingsKey . SliceSettingsWidth , value . ToString ( ) ) ;
}
}
2017-08-15 19:13:55 -07:00
}
2017-06-24 10:30:11 -07:00
public class PrinterConfig
{
2017-08-16 17:13:16 -07:00
public BedConfig Bed { get ; }
2017-08-15 19:13:55 -07:00
public PrinterViewState ViewState { get ; } = new PrinterViewState ( ) ;
2017-08-17 18:18:41 -07:00
public PrinterSettings Settings { get ; private set ; } = ActiveSliceSettings . Instance ;
2017-09-15 12:08:00 -07:00
public PrinterConnection Connection { get ; private set ; } = PrinterConnection . Instance ;
2017-08-16 05:53:26 -07:00
private EventHandler unregisterEvents ;
2017-09-15 21:59:36 -07:00
public PrinterConfig ( bool loadLastBedplate )
2017-08-16 05:53:26 -07:00
{
2017-09-15 21:59:36 -07:00
this . Bed = new BedConfig ( this , loadLastBedplate ) ;
2017-08-16 17:13:16 -07:00
ActiveSliceSettings . SettingChanged . RegisterEvent ( Printer_SettingChanged , ref unregisterEvents ) ;
// TODO: Needed?
//ApplicationController.Instance.AdvancedControlsPanelReloading.RegisterEvent(CheckSettingChanged, ref unregisterEvents);
2017-08-16 05:53:26 -07:00
ActiveSliceSettings . ActivePrinterChanged . RegisterEvent ( ( s , e ) = >
{
this . Settings = ActiveSliceSettings . Instance ;
2017-08-31 15:52:27 -07:00
this . ReloadSettings ( ) ;
this . Bed . RecreateBed ( ) ;
2017-08-16 05:53:26 -07:00
} , ref unregisterEvents ) ;
}
2017-08-16 17:13:16 -07:00
private void ReloadSettings ( )
{
this . Bed . BuildHeight = this . Settings . GetValue < double > ( SettingsKey . build_height ) ;
this . Bed . ViewerVolume = new Vector3 ( this . Settings . GetValue < Vector2 > ( SettingsKey . bed_size ) , this . Bed . BuildHeight ) ;
this . Bed . BedCenter = this . Settings . GetValue < Vector2 > ( SettingsKey . print_center ) ;
this . Bed . BedShape = this . Settings . GetValue < BedShape > ( SettingsKey . bed_shape ) ;
}
private void Printer_SettingChanged ( object sender , EventArgs e )
{
if ( e is StringEventArgs stringEvent )
{
if ( stringEvent . Data = = SettingsKey . bed_size
| | stringEvent . Data = = SettingsKey . print_center
| | stringEvent . Data = = SettingsKey . build_height
| | stringEvent . Data = = SettingsKey . bed_shape )
{
this . ReloadSettings ( ) ;
this . Bed . RecreateBed ( ) ;
}
}
}
2017-06-24 10:30:11 -07:00
}
2017-05-23 19:03:30 -07:00
2017-06-24 10:30:11 -07:00
public class View3DConfig
{
2017-07-05 12:45:42 -07:00
public bool IsDirty { get ; internal set ; }
2017-06-24 10:30:11 -07:00
public bool RenderGrid
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
get
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
string value = UserSettings . Instance . get ( "GcodeViewerRenderGrid" ) ;
if ( value = = null )
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
RenderGrid = true ;
return true ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
return ( value = = "True" ) ;
}
set
{
UserSettings . Instance . set ( "GcodeViewerRenderGrid" , value . ToString ( ) ) ;
2017-07-05 12:45:42 -07:00
this . IsDirty = true ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
}
2017-06-24 08:32:09 -07:00
2017-06-24 10:30:11 -07:00
public bool RenderMoves
{
get { return ( UserSettings . Instance . get ( "GcodeViewerRenderMoves" ) = = "True" ) ; }
set
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
UserSettings . Instance . set ( "GcodeViewerRenderMoves" , value . ToString ( ) ) ;
2017-07-05 12:45:42 -07:00
this . IsDirty = true ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
}
2017-06-24 08:32:09 -07:00
2017-06-24 10:30:11 -07:00
public bool RenderRetractions
{
get { return ( UserSettings . Instance . get ( "GcodeViewerRenderRetractions" ) = = "True" ) ; }
set
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
UserSettings . Instance . set ( "GcodeViewerRenderRetractions" , value . ToString ( ) ) ;
2017-07-05 12:45:42 -07:00
this . IsDirty = true ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
}
2017-06-24 08:32:09 -07:00
2017-06-24 10:30:11 -07:00
public bool RenderSpeeds
{
get { return ( UserSettings . Instance . get ( "GcodeViewerRenderSpeeds" ) = = "True" ) ; }
set
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
UserSettings . Instance . set ( "GcodeViewerRenderSpeeds" , value . ToString ( ) ) ;
2017-07-05 12:45:42 -07:00
this . IsDirty = true ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
}
2017-06-24 08:32:09 -07:00
2017-06-24 10:30:11 -07:00
public bool SimulateExtrusion
{
get { return ( UserSettings . Instance . get ( "GcodeViewerSimulateExtrusion" ) = = "True" ) ; }
set
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
UserSettings . Instance . set ( "GcodeViewerSimulateExtrusion" , value . ToString ( ) ) ;
2017-07-05 12:45:42 -07:00
this . IsDirty = true ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
}
2017-06-24 08:32:09 -07:00
2017-06-24 10:30:11 -07:00
public bool TransparentExtrusion
{
get { return ( UserSettings . Instance . get ( "GcodeViewerTransparentExtrusion" ) = = "True" ) ; }
set
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
UserSettings . Instance . set ( "GcodeViewerTransparentExtrusion" , value . ToString ( ) ) ;
2017-07-05 12:45:42 -07:00
this . IsDirty = true ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
}
2017-06-24 08:32:09 -07:00
2017-06-24 10:30:11 -07:00
public bool HideExtruderOffsets
{
get
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
string value = UserSettings . Instance . get ( "GcodeViewerHideExtruderOffsets" ) ;
if ( value = = null )
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
return true ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
return ( value = = "True" ) ;
2017-06-24 08:32:09 -07:00
}
2017-06-24 10:30:11 -07:00
set
2017-06-24 08:32:09 -07:00
{
2017-06-24 10:30:11 -07:00
UserSettings . Instance . set ( "GcodeViewerHideExtruderOffsets" , value . ToString ( ) ) ;
2017-07-05 12:45:42 -07:00
this . IsDirty = true ;
2017-06-24 08:32:09 -07:00
}
}
2017-06-24 10:30:11 -07:00
public bool SyncToPrint
{
2017-07-03 09:29:09 -07:00
get = > UserSettings . Instance . get ( "LayerViewSyncToPrint" ) = = "True" ;
2017-07-05 12:45:42 -07:00
set
{
UserSettings . Instance . set ( "LayerViewSyncToPrint" , value . ToString ( ) ) ;
this . IsDirty = true ;
}
2017-06-24 10:30:11 -07:00
}
}
public class ApplicationController
{
public ThemeConfig Theme { get ; set ; } = new ThemeConfig ( ) ;
2017-09-15 23:13:23 -07:00
public PrinterConfig Printer { get ; }
2017-06-24 08:32:09 -07:00
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
public Action RedeemDesignCode ;
public Action EnterShareCode ;
private static ApplicationController globalInstance ;
public RootedObjectEventHandler AdvancedControlsPanelReloading = new RootedObjectEventHandler ( ) ;
public RootedObjectEventHandler CloudSyncStatusChanged = new RootedObjectEventHandler ( ) ;
public RootedObjectEventHandler DoneReloadingAll = new RootedObjectEventHandler ( ) ;
public RootedObjectEventHandler PluginsLoaded = new RootedObjectEventHandler ( ) ;
public static Action SignInAction ;
public static Action SignOutAction ;
2017-09-15 23:13:23 -07:00
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
public static Action WebRequestFailed ;
public static Action WebRequestSucceeded ;
public TerminalRedirector Terminal { get ; } = new TerminalRedirector ( ) ;
#if DEBUG
public const string EnvironmentName = "TestEnv_" ;
#else
public const string EnvironmentName = "" ;
#endif
/// <summary>
/// Allows application components to hook initial SystemWindow Load event without an existing Widget instance
/// </summary>
public static event EventHandler Load ;
public static Func < string , Task < Dictionary < string , string > > > GetProfileHistory ;
private readonly static object thumbsLock = new object ( ) ;
private Queue < Func < Task > > queuedThumbCallbacks = new Queue < Func < Task > > ( ) ;
private AutoResetEvent thumbGenResetEvent = new AutoResetEvent ( false ) ;
Task thumbnailGenerator = null ;
internal void QueueForGeneration ( Func < Task > func )
{
lock ( thumbsLock )
{
if ( thumbnailGenerator = = null )
{
// Spin up a new thread once needed
thumbnailGenerator = Task . Run ( ( Action ) ThumbGeneration ) ;
}
queuedThumbCallbacks . Enqueue ( func ) ;
thumbGenResetEvent . Set ( ) ;
}
}
private async void ThumbGeneration ( )
{
2017-06-04 08:25:02 -07:00
Thread . CurrentThread . Name = $"ThumbnailGeneration" ;
2017-06-13 13:08:53 -07:00
while ( ! MatterControlApplication . Instance . HasBeenClosed )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-06-13 13:08:53 -07:00
Thread . Sleep ( 100 ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-06-13 13:08:53 -07:00
try
{
if ( queuedThumbCallbacks . Count > 0 )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-06-13 13:08:53 -07:00
Func < Task > callback ;
lock ( thumbsLock )
{
callback = queuedThumbCallbacks . Dequeue ( ) ;
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
await callback ( ) ;
}
2017-06-13 13:08:53 -07:00
else
2017-06-04 08:25:02 -07:00
{
2017-06-13 13:08:53 -07:00
// Process until queuedThumbCallbacks is empty then wait for new tasks via QueueForGeneration
thumbGenResetEvent . WaitOne ( ) ;
2017-06-04 08:25:02 -07:00
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
2017-06-13 13:08:53 -07:00
catch ( ThreadAbortException e )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
return ;
}
2017-06-13 13:08:53 -07:00
catch ( Exception ex )
{
Console . WriteLine ( "Error generating thumbnail: " + ex . Message ) ;
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
}
public static Func < PrinterInfo , string , Task < PrinterSettings > > GetPrinterProfileAsync ;
public static Func < string , IProgress < SyncReportType > , Task > SyncPrinterProfiles ;
public static Func < Task < OemProfileDictionary > > GetPublicProfileList ;
public static Func < string , Task < PrinterSettings > > DownloadPublicProfileAsync ;
public SlicePresetsWindow EditMaterialPresetsWindow { get ; set ; }
public SlicePresetsWindow EditQualityPresetsWindow { get ; set ; }
public ApplicationView MainView ;
public event EventHandler ApplicationClosed ;
private EventHandler unregisterEvents ;
private Dictionary < string , List < PrintItemAction > > registeredLibraryActions = new Dictionary < string , List < PrintItemAction > > ( ) ;
static int applicationInstanceCount = 0 ;
public static int ApplicationInstanceCount
{
get
{
if ( applicationInstanceCount = = 0 )
{
Assembly mcAssembly = Assembly . GetEntryAssembly ( ) ;
if ( mcAssembly ! = null )
{
string applicationName = Path . GetFileNameWithoutExtension ( mcAssembly . Location ) . ToUpper ( ) ;
Process [ ] p1 = Process . GetProcesses ( ) ;
foreach ( System . Diagnostics . Process pro in p1 )
{
try
{
if ( pro ? . ProcessName ! = null
& & pro . ProcessName . ToUpper ( ) . Contains ( applicationName ) )
{
applicationInstanceCount + + ;
}
}
catch
{
}
}
}
}
return applicationInstanceCount ;
}
}
public LibraryConfig Library { get ; }
private void InitializeLibrary ( )
{
if ( Directory . Exists ( ApplicationDataStorage . Instance . DownloadsDirectory ) )
{
this . Library . RegisterRootProvider (
new DynamicContainerLink (
"Downloads" . Localize ( ) ,
LibraryProviderHelpers . LoadInvertIcon ( "FileDialog" , "download_folder.png" ) ,
( ) = > new FileSystemContainer ( ApplicationDataStorage . Instance . DownloadsDirectory )
{
UseIncrementedNameDuringTypeChange = true
} ) ) ;
}
this . Library . RegisterRootProvider (
new DynamicContainerLink (
"Calibration Parts" . Localize ( ) ,
LibraryProviderHelpers . LoadInvertIcon ( "FileDialog" , "folder.png" ) ,
2017-07-31 22:16:15 -07:00
( ) = > new CalibrationPartsContainer ( ) )
{
IsReadOnly = true
} ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
this . Library . RegisterRootProvider (
new DynamicContainerLink (
"Print Queue" . Localize ( ) ,
LibraryProviderHelpers . LoadInvertIcon ( "FileDialog" , "queue_folder.png" ) ,
( ) = > new PrintQueueContainer ( ) ) ) ;
var rootLibraryCollection = Datastore . Instance . dbSQLite . Table < PrintItemCollection > ( ) . Where ( v = > v . Name = = "_library" ) . Take ( 1 ) . FirstOrDefault ( ) ;
if ( rootLibraryCollection ! = null )
{
int rooteLibraryID = rootLibraryCollection . Id ;
this . Library . RegisterRootProvider (
new DynamicContainerLink (
"Local Library" . Localize ( ) ,
LibraryProviderHelpers . LoadInvertIcon ( "FileDialog" , "library_folder.png" ) ,
( ) = > new SqliteLibraryContainer ( rooteLibraryID ) ) ) ;
}
this . Library . RegisterRootProvider (
new DynamicContainerLink (
"Print History" . Localize ( ) ,
LibraryProviderHelpers . LoadInvertIcon ( "FileDialog" , "folder.png" ) ,
2017-07-31 22:16:15 -07:00
( ) = > new HistoryContainer ( ) )
{
IsReadOnly = true
} ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
if ( File . Exists ( ApplicationDataStorage . Instance . CustomLibraryFoldersPath ) )
{
// Add each path defined in the CustomLibraryFolders file as a new FileSystemContainerItem
foreach ( string directory in File . ReadLines ( ApplicationDataStorage . Instance . CustomLibraryFoldersPath ) )
{
if ( Directory . Exists ( directory ) )
{
this . Library . RegisterRootProvider (
2017-06-03 15:11:12 -07:00
new FileSystemContainer . DirectoryContainerLink ( directory )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
UseIncrementedNameDuringTypeChange = true
} ) ;
}
}
}
this . Library . RegisterRootProvider (
new DynamicContainerLink (
"SD Card" . Localize ( ) ,
LibraryProviderHelpers . LoadInvertIcon ( "FileDialog" , "sd_folder.png" ) ,
( ) = > new SDCardContainer ( ) ,
( ) = >
{
2017-06-13 17:22:49 -07:00
var printer = PrinterConnection . Instance ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
return ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . has_sd_card_reader )
& & printer . PrinterIsConnected
& & ! ( printer . PrinterIsPrinting | | printer . PrinterIsPaused ) ;
2017-07-31 22:16:15 -07:00
} )
{
IsReadOnly = true
} ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
public ApplicationController ( )
{
2017-08-22 22:18:06 -07:00
ScrollBar . DefaultMargin = new BorderDouble ( right : 3 ) ;
ScrollBar . ScrollBarWidth = 10 * GuiWidget . DeviceScale ;
2017-07-27 18:20:16 -07:00
DefaultThumbBackground . DefaultBackgroundColor = RGBA_Bytes . Transparent ;
2017-07-12 14:47:01 -07:00
Object3D . AssetsPath = ApplicationDataStorage . Instance . LibraryAssetsPath ;
2017-09-15 23:13:23 -07:00
this . Printer = new PrinterConfig ( loadLastBedplate : true ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
this . Library = new LibraryConfig ( ) ;
this . Library . ContentProviders . Add ( new [ ] { "stl" , "amf" , "mcx" } , new MeshContentProvider ( ) ) ;
2017-06-21 07:41:12 -07:00
this . Library . ContentProviders . Add ( "gcode" , new GCodeContentProvider ( ) ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
// Name = "MainSlidePanel";
2017-06-21 07:29:22 -07:00
ActiveTheme . ThemeChanged . RegisterEvent ( ( s , e ) = >
{
if ( ! MatterControlApplication . IsLoading )
{
ReloadAll ( ) ;
}
} , ref unregisterEvents ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-06-10 11:24:21 -07:00
ActiveSliceSettings . MaterialPresetChanged + = ( s , e ) = >
{
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
} ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
// Remove consumed ClientToken from running list on shutdown
2017-06-13 13:08:53 -07:00
ApplicationClosed + = ( s , e ) = >
{
ApplicationSettings . Instance . ReleaseClientToken ( ) ;
// Release the waiting ThumbnailGeneration task so it can shutdown gracefully
thumbGenResetEvent ? . Set ( ) ;
} ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-06-13 17:22:49 -07:00
PrinterConnection . Instance . CommunicationStateChanged . RegisterEvent ( ( s , e ) = >
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-09-15 12:08:00 -07:00
var printerConnection = s as PrinterConnection ;
2017-09-01 21:23:08 -07:00
switch ( printerConnection . CommunicationState )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-06-13 17:32:38 -07:00
case CommunicationStates . Printing :
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
if ( UserSettings . Instance . IsTouchScreen )
{
2017-09-15 12:08:00 -07:00
// TODO: In general this basic hook won't work with multi-tenancy
UiThread . RunOnIdle ( ( ) = > PrintingWindow . Show ( ApplicationController . Instance . Printer ) ) ; // HACK: We need to show the instance that's printing not the static instance
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
break ;
}
} , ref unregisterEvents ) ;
this . InitializeLibrary ( ) ;
2017-06-13 13:08:53 -07:00
2017-06-16 18:04:47 -07:00
PrinterConnection . Instance . ConnectionSucceeded . RegisterEvent ( ( s , e ) = >
{
// run the print leveling wizard if we need to for this printer
if ( ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . print_leveling_required_to_print )
| | ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . print_leveling_enabled ) )
{
PrintLevelingData levelingData = ActiveSliceSettings . Instance . Helpers . GetPrintLevelingData ( ) ;
if ( levelingData ? . HasBeenRunAndEnabled ( ) ! = true )
{
2017-09-15 12:08:00 -07:00
UiThread . RunOnIdle ( ( ) = > LevelWizardBase . ShowPrintLevelWizard ( ApplicationController . Instance . Printer ) ) ; // HACK: We need to show the instance that's printing not the static instance
2017-06-16 18:04:47 -07:00
}
}
} , ref unregisterEvents ) ;
2017-06-13 13:08:53 -07:00
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
public void StartSignIn ( )
{
2017-06-13 17:22:49 -07:00
if ( PrinterConnection . Instance . PrinterIsPrinting
| | PrinterConnection . Instance . PrinterIsPaused )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
// can't sign in while printing
UiThread . RunOnIdle ( ( ) = >
StyledMessageBox . ShowMessageBox ( null , "Please wait until the print has finished and try again." . Localize ( ) , "Can't sign in while printing" . Localize ( ) )
) ;
}
else // do the regular sign in
{
SignInAction ? . Invoke ( ) ;
}
}
private static TypeFace monoSpacedTypeFace = null ;
public static TypeFace MonoSpacedTypeFace
{
get
{
if ( monoSpacedTypeFace = = null )
{
2017-08-20 02:34:39 -07:00
monoSpacedTypeFace = TypeFace . LoadFrom ( AggContext . StaticData . ReadAllText ( Path . Combine ( "Fonts" , "LiberationMono.svg" ) ) ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
return monoSpacedTypeFace ;
}
}
public static Task < T > LoadCacheableAsync < T > ( string cacheKey , string cacheScope , string staticDataFallbackPath = null ) where T : class
{
string cachePath = CacheablePath ( cacheScope , cacheKey ) ;
try
{
if ( File . Exists ( cachePath ) )
{
// Load from cache and deserialize
return Task . FromResult (
JsonConvert . DeserializeObject < T > ( File . ReadAllText ( cachePath ) ) ) ;
}
}
catch
{
// Fall back to StaticData
}
try
{
if ( staticDataFallbackPath ! = null
2017-08-20 02:34:39 -07:00
& & AggContext . StaticData . FileExists ( staticDataFallbackPath ) )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
return Task . FromResult (
2017-08-20 02:34:39 -07:00
JsonConvert . DeserializeObject < T > ( AggContext . StaticData . ReadAllText ( staticDataFallbackPath ) ) ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
}
catch
{
}
return Task . FromResult ( default ( T ) ) ;
}
/// <summary>
/// Requests fresh content from online services, falling back to cached content if offline
/// </summary>
/// <param name="collector">The custom collector function to load the content</param>
/// <returns></returns>
public async static Task < T > LoadCacheableAsync < T > ( string cacheKey , string cacheScope , Func < Task < T > > collector , string staticDataFallbackPath = null ) where T : class
{
string cachePath = CacheablePath ( cacheScope , cacheKey ) ;
try
{
// Try to update the document
T item = await collector ( ) ;
if ( item ! = null )
{
// update cache on success
File . WriteAllText ( cachePath , JsonConvert . SerializeObject ( item , Formatting . Indented ) ) ;
return item ;
}
}
catch
{
// Fall back to preexisting cache if failed
}
return await LoadCacheableAsync < T > ( cacheKey , cacheScope , staticDataFallbackPath ) ;
}
private static string cacheDirectory = Path . Combine ( ApplicationDataStorage . ApplicationUserDataPath , "data" , "temp" , "cache" ) ;
public static string CacheablePath ( string cacheScope , string cacheKey )
{
string scopeDirectory = Path . Combine ( cacheDirectory , cacheScope ) ;
// Ensure directory exists
Directory . CreateDirectory ( scopeDirectory ) ;
string cachePath = Path . Combine ( scopeDirectory , cacheKey ) ;
return cachePath ;
}
// Indicates if given file can be opened on the design surface
public bool IsLoadableFile ( string filePath )
{
string extension = Path . GetExtension ( filePath ) . ToLower ( ) ;
string extensionWithoutPeriod = extension . Trim ( '.' ) ;
return ! string . IsNullOrEmpty ( extension )
& & ( ApplicationSettings . OpenDesignFileParams . Contains ( extension )
| | ApplicationController . Instance . Library . ContentProviders . Keys . Contains ( extensionWithoutPeriod ) ) ;
}
public void StartSignOut ( )
{
2017-06-13 17:22:49 -07:00
if ( PrinterConnection . Instance . PrinterIsPrinting
| | PrinterConnection . Instance . PrinterIsPaused )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
// can't log out while printing
UiThread . RunOnIdle ( ( ) = >
StyledMessageBox . ShowMessageBox ( null , "Please wait until the print has finished and try again." . Localize ( ) , "Can't log out while printing" . Localize ( ) )
) ;
}
else // do the regular log out
{
bool allowShowingSignOutWarning = true ;
if ( allowShowingSignOutWarning )
{
// Warn on sign out that no access to user printers and cloud library put a 'Don't remind me again' check box
StyledMessageBox . ShowMessageBox ( ( clickedSignOut ) = >
{
if ( clickedSignOut )
{
SignOutAction ? . Invoke ( ) ;
}
} , "Are you sure you want to sign out? You will not have access to your printer profiles or cloud library." . Localize ( ) , "Sign Out?" . Localize ( ) , StyledMessageBox . MessageType . YES_NO , "Sign Out" . Localize ( ) , "Cancel" . Localize ( ) ) ;
}
else // just run the sign out event
{
SignOutAction ? . Invoke ( ) ;
}
}
}
bool pendingReloadRequest = false ;
public void ReloadAll ( )
{
if ( pendingReloadRequest | | MainView = = null )
{
return ;
}
pendingReloadRequest = true ;
UiThread . RunOnIdle ( ( ) = >
{
using ( new QuickTimer ( $"ReloadAll_{reloadCount++}:" ) )
{
MainView ? . CloseAllChildren ( ) ;
using ( new QuickTimer ( "ReloadAll_AddElements" ) )
{
MainView ? . CreateAndAddChildren ( ) ;
}
this . DoneReloadingAll ? . CallEvents ( null , null ) ;
}
pendingReloadRequest = false ;
} ) ;
}
static int reloadCount = 0 ;
public void OnApplicationClosed ( )
{
ApplicationClosed ? . Invoke ( null , null ) ;
}
static void LoadOemOrDefaultTheme ( )
{
// if not check for the oem color and use it if set
// else default to "Blue - Light"
string oemColor = OemSettings . Instance . ThemeColor ;
if ( string . IsNullOrEmpty ( oemColor ) )
{
ActiveTheme . Instance = ActiveTheme . GetThemeColors ( "Blue - Light" ) ;
}
else
{
ActiveTheme . Instance = ActiveTheme . GetThemeColors ( oemColor ) ;
}
}
public static ApplicationController Instance
{
get
{
if ( globalInstance = = null )
{
//using (new PerformanceTimer("Startup", "AppController Instance"))
{
globalInstance = new ApplicationController ( ) ;
// Set the default theme colors
LoadOemOrDefaultTheme ( ) ;
// Accessing any property on ProfileManager will run the static constructor and spin up the ProfileManager instance
bool na = ProfileManager . Instance . IsGuestProfile ;
2017-08-06 10:44:27 -07:00
globalInstance . MainView = new DesktopView ( ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-08-16 05:53:26 -07:00
ActiveSliceSettings . ActivePrinterChanged . RegisterEvent ( ( s , e ) = >
{
if ( ! MatterControlApplication . IsLoading )
{
ApplicationController . Instance . ReloadAll ( ) ;
}
} , ref globalInstance . unregisterEvents ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
}
return globalInstance ;
}
}
2017-06-01 18:19:37 -07:00
public class MeshViewState
{
public Matrix4X4 RotationMatrix { get ; internal set ; } = Matrix4X4 . Identity ;
public Matrix4X4 TranslationMatrix { get ; internal set ; } = Matrix4X4 . Identity ;
}
public MeshViewState PartPreviewState { get ; set ; } = new MeshViewState ( ) ;
2017-06-02 13:17:30 -07:00
public View3DWidget ActiveView3DWidget { get ; internal set ; }
2017-09-15 18:45:21 -07:00
public string PrintingItemName { get ; set ; }
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
public string CachePath ( ILibraryItem libraryItem )
{
// TODO: Use content SHA
return string . IsNullOrEmpty ( libraryItem . ID ) ? null : ApplicationController . CacheablePath ( "ItemThumbnails" , $"{libraryItem.ID}.png" ) ;
}
/ *
private static string CachePath ( ILibraryItem libraryItem , int width , int height )
{
// TODO: Use content SHA
return string . IsNullOrEmpty ( libraryItem . ID ) ? null : ApplicationController . CacheablePath ( "ItemThumbnails" , $"{libraryItem.ID}_{width}x{height}.png" ) ;
} * /
public void ReloadAdvancedControlsPanel ( )
{
AdvancedControlsPanelReloading . CallEvents ( this , null ) ;
}
// public LibraryDataView CurrentLibraryDataView = null;
public void SwitchToPurchasedLibrary ( )
{
var purchasedContainer = Library . RootLibaryContainer . ChildContainers . Where ( c = > c . ID = = "LibraryProviderPurchasedKey" ) . FirstOrDefault ( ) ;
if ( purchasedContainer ! = null )
{
// TODO: Navigate to purchased container
throw new NotImplementedException ( "SwitchToPurchasedLibrary" ) ;
}
}
public void SwitchToSharedLibrary ( )
{
// Switch to the shared library
var libraryContainer = Library . RootLibaryContainer . ChildContainers . Where ( c = > c . ID = = "LibraryProviderSharedKey" ) . FirstOrDefault ( ) ;
if ( libraryContainer ! = null )
{
// TODO: Navigate to purchased container
throw new NotImplementedException ( "SwitchToSharedLibrary" ) ;
}
}
public void ChangeCloudSyncStatus ( bool userAuthenticated , string reason = "" )
{
UserSettings . Instance . set ( UserSettingsKey . CredentialsInvalid , userAuthenticated ? "false" : "true" ) ;
UserSettings . Instance . set ( UserSettingsKey . CredentialsInvalidReason , userAuthenticated ? "" : reason ) ;
CloudSyncStatusChanged . CallEvents ( this , new CloudSyncEventArgs ( ) { IsAuthenticated = userAuthenticated } ) ;
// Only fire UserChanged if it actually happened - prevents runaway positive feedback loop
if ( ! string . IsNullOrEmpty ( AuthenticationData . Instance . ActiveSessionUsername )
& & AuthenticationData . Instance . ActiveSessionUsername ! = AuthenticationData . Instance . LastSessionUsername )
{
// only set it if it is an actual user name
AuthenticationData . Instance . LastSessionUsername = AuthenticationData . Instance . ActiveSessionUsername ;
}
UserChanged ( ) ;
}
// Called after every startup and at the completion of every authentication change
public void UserChanged ( )
{
ProfileManager . ReloadActiveUser ( ) ;
// Ensure SQLite printers are imported
ProfileManager . Instance . EnsurePrintersImported ( ) ;
var guest = ProfileManager . Load ( "guest" ) ;
// If profiles.json was created, run the import wizard to pull in any SQLite printers
if ( guest ? . Profiles ? . Any ( ) = = true
& & ! ProfileManager . Instance . IsGuestProfile
& & ! ProfileManager . Instance . PrintersImported )
{
// Show the import printers wizard
2017-08-23 15:51:29 -07:00
WizardWindow . Show < CopyGuestProfilesToUser > ( ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
}
public class CloudSyncEventArgs : EventArgs
{
public bool IsAuthenticated { get ; set ; }
}
public void OnLoadActions ( )
{
Load ? . Invoke ( this , null ) ;
// Pushing this after load fixes that empty printer list
ApplicationController . Instance . UserChanged ( ) ;
2017-09-15 18:45:21 -07:00
bool showAuthWindow = WizardWindow . ShouldShowAuthPanel ? . Invoke ( ) ? ? false ;
if ( showAuthWindow )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-09-15 18:45:21 -07:00
if ( ApplicationSettings . Instance . get ( ApplicationSettingsKey . SuppressAuthPanel ) ! = "True" )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-09-15 18:45:21 -07:00
//Launch window to prompt user to sign in
UiThread . RunOnIdle ( ( ) = > WizardWindow . ShowPrinterSetup ( ) ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
}
else
{
2017-09-15 18:45:21 -07:00
//If user in logged in sync before checking to prompt to create printer
if ( ApplicationController . SyncPrinterProfiles = = null )
{
RunSetupIfRequired ( ) ;
}
else
{
ApplicationController . SyncPrinterProfiles . Invoke ( "ApplicationController.OnLoadActions()" , null ) . ContinueWith ( ( task ) = >
{
RunSetupIfRequired ( ) ;
} ) ;
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
2017-09-15 18:45:21 -07:00
if ( AggContext . OperatingSystem = = OSType . Android )
{
// show this last so it is on top
if ( UserSettings . Instance . get ( "SoftwareLicenseAccepted" ) ! = "true" )
{
UiThread . RunOnIdle ( ( ) = > WizardWindow . Show < LicenseAgreementPage > ( ) ) ;
}
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
if ( ActiveSliceSettings . Instance . PrinterSelected
& & ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . auto_connect ) )
{
UiThread . RunOnIdle ( ( ) = >
{
//PrinterConnectionAndCommunication.Instance.HaltConnectionThread();
2017-06-13 17:22:49 -07:00
PrinterConnection . Instance . ConnectToActivePrinter ( ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
} , 2 ) ;
}
}
2017-08-03 15:24:41 -07:00
private static void RunSetupIfRequired ( )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
if ( ! ProfileManager . Instance . ActiveProfiles . Any ( ) )
{
// Start the setup wizard if no profiles exist
UiThread . RunOnIdle ( ( ) = > WizardWindow . ShowPrinterSetup ( ) ) ;
}
}
private EventHandler unregisterEvent ;
2017-08-17 18:18:41 -07:00
public Stream LoadHttpAsset ( string url )
{
string fingerPrint = ToSHA1 ( url ) ;
string cachePath = ApplicationController . CacheablePath ( "HttpAssets" , fingerPrint ) ;
if ( File . Exists ( cachePath ) )
{
return File . Open ( cachePath , FileMode . Open ) ;
}
else
{
var client = new WebClient ( ) ;
var bytes = client . DownloadData ( url ) ;
File . WriteAllBytes ( cachePath , bytes ) ;
return new MemoryStream ( bytes ) ;
}
}
/// <summary>
/// Compute hash for string encoded as UTF8
/// </summary>
/// <param name="s">String to be hashed</param>
public static string ToSHA1 ( string s )
{
byte [ ] bytes = Encoding . UTF8 . GetBytes ( s ) ;
// var timer = Stopwatch.StartNew();
using ( var sha1 = System . Security . Cryptography . SHA1 . Create ( ) )
{
byte [ ] hash = sha1 . ComputeHash ( bytes ) ;
string SHA1 = BitConverter . ToString ( hash ) . Replace ( "-" , string . Empty ) ;
// Console.WriteLine("{0} {1} {2}", SHA1, timer.ElapsedMilliseconds, filePath);
return SHA1 ;
}
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
/// <summary>
/// Download an image from the web into the specified ImageBuffer
/// </summary>
/// <param name="uri"></param>
public void DownloadToImageAsync ( ImageBuffer imageToLoadInto , string uriToLoad , bool scaleToImageX , IRecieveBlenderByte scalingBlender = null )
{
if ( scalingBlender = = null )
{
scalingBlender = new BlenderBGRA ( ) ;
}
WebClient client = new WebClient ( ) ;
client . DownloadDataCompleted + = ( object sender , DownloadDataCompletedEventArgs e ) = >
{
try // if we get a bad result we can get a target invocation exception. In that case just don't show anything
{
// scale the loaded image to the size of the target image
byte [ ] raw = e . Result ;
Stream stream = new MemoryStream ( raw ) ;
ImageBuffer unScaledImage = new ImageBuffer ( 10 , 10 ) ;
if ( scaleToImageX )
{
2017-08-20 02:34:39 -07:00
AggContext . StaticData . LoadImageData ( stream , unScaledImage ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
// If the source image (the one we downloaded) is more than twice as big as our dest image.
while ( unScaledImage . Width > imageToLoadInto . Width * 2 )
{
// The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
// So we scale as many times as we need to to get the Image to be the right size.
// If this were going to be a non-uniform scale we could do the x and y separately to get better results.
ImageBuffer halfImage = new ImageBuffer ( unScaledImage . Width / 2 , unScaledImage . Height / 2 , 32 , scalingBlender ) ;
halfImage . NewGraphics2D ( ) . Render ( unScaledImage , 0 , 0 , 0 , halfImage . Width / ( double ) unScaledImage . Width , halfImage . Height / ( double ) unScaledImage . Height ) ;
unScaledImage = halfImage ;
}
double finalScale = imageToLoadInto . Width / ( double ) unScaledImage . Width ;
imageToLoadInto . Allocate ( imageToLoadInto . Width , ( int ) ( unScaledImage . Height * finalScale ) , imageToLoadInto . Width * ( imageToLoadInto . BitDepth / 8 ) , imageToLoadInto . BitDepth ) ;
imageToLoadInto . NewGraphics2D ( ) . Render ( unScaledImage , 0 , 0 , 0 , finalScale , finalScale ) ;
}
else
{
2017-08-20 02:34:39 -07:00
AggContext . StaticData . LoadImageData ( stream , imageToLoadInto ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
imageToLoadInto . MarkImageChanged ( ) ;
}
catch
{
}
} ;
try
{
client . DownloadDataAsync ( new Uri ( uriToLoad ) ) ;
}
catch
{
}
}
/// <summary>
/// Cancels prints within the first two minutes or interactively prompts the user to confirm cancellation
/// </summary>
/// <returns>A boolean value indicating if the print was canceled</returns>
public bool ConditionalCancelPrint ( )
{
bool canceled = false ;
2017-06-13 17:22:49 -07:00
if ( PrinterConnection . Instance . SecondsPrinted > 120 )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
StyledMessageBox . ShowMessageBox (
( bool response ) = >
{
if ( response )
{
2017-06-13 17:22:49 -07:00
UiThread . RunOnIdle ( ( ) = > PrinterConnection . Instance . Stop ( ) ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
canceled = true ;
}
canceled = false ;
} ,
"Cancel the current print?" . Localize ( ) ,
"Cancel Print?" . Localize ( ) ,
StyledMessageBox . MessageType . YES_NO ,
"Cancel Print" . Localize ( ) ,
"Continue Printing" . Localize ( ) ) ;
}
else
{
2017-06-13 17:22:49 -07:00
PrinterConnection . Instance . Stop ( ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
canceled = false ;
}
return canceled ;
}
/// <summary>
/// Register the given PrintItemAction into the named section
/// </summary>
/// <param name="section">The section to register in</param>
/// <param name="printItemAction">The action to register</param>
public void RegisterLibraryAction ( string section , PrintItemAction printItemAction )
{
List < PrintItemAction > items ;
if ( ! registeredLibraryActions . TryGetValue ( section , out items ) )
{
items = new List < PrintItemAction > ( ) ;
registeredLibraryActions . Add ( section , items ) ;
}
items . Add ( printItemAction ) ;
}
/// <summary>
/// Enumerate the given section, returning all registered actions
/// </summary>
/// <param name="section">The section to enumerate</param>
/// <returns></returns>
public IEnumerable < PrintItemAction > RegisteredLibraryActions ( string section )
{
List < PrintItemAction > items ;
if ( registeredLibraryActions . TryGetValue ( section , out items ) )
{
return items ;
}
return Enumerable . Empty < PrintItemAction > ( ) ;
}
2017-06-16 18:04:47 -07:00
2017-08-07 14:19:28 -07:00
public event EventHandler < WidgetSourceEventArgs > AddPrintersTabRightElement ;
public void NotifyPrintersTabRightElement ( GuiWidget sourceExentionArea )
{
AddPrintersTabRightElement ? . Invoke ( this , new WidgetSourceEventArgs ( sourceExentionArea ) ) ;
}
2017-06-16 18:04:47 -07:00
private string doNotAskAgainMessage = "Don't remind me again" . Localize ( ) ;
2017-09-15 18:45:21 -07:00
public async void PrintPart ( PrintItemWrapper printItem , bool overrideAllowGCode = false )
2017-06-16 18:04:47 -07:00
{
try
{
// If leveling is required or is currently on
if ( ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . print_leveling_required_to_print )
| | ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . print_leveling_enabled ) )
{
PrintLevelingData levelingData = ActiveSliceSettings . Instance . Helpers . GetPrintLevelingData ( ) ;
if ( levelingData ? . HasBeenRunAndEnabled ( ) ! = true )
{
2017-09-15 12:08:00 -07:00
LevelWizardBase . ShowPrintLevelWizard ( ApplicationController . Instance . Printer ) ; // HACK: We need to show the instance that's printing not the static instance
2017-06-16 18:04:47 -07:00
return ;
}
}
2017-09-15 18:45:21 -07:00
2017-06-16 18:04:47 -07:00
// Save any pending changes before starting the print
await ApplicationController . Instance . ActiveView3DWidget . PersistPlateIfNeeded ( ) ;
2017-09-15 18:45:21 -07:00
if ( printItem ! = null )
2017-06-16 18:04:47 -07:00
{
2017-09-15 18:45:21 -07:00
this . PrintingItemName = printItem . Name ;
string pathAndFile = printItem . FileLocation ;
2017-06-16 18:04:47 -07:00
if ( ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . has_sd_card_reader )
& & pathAndFile = = QueueData . SdCardFileName )
{
PrinterConnection . Instance . StartSdCardPrint ( ) ;
}
else if ( ActiveSliceSettings . Instance . IsValid ( ) )
{
if ( File . Exists ( pathAndFile ) )
{
// clear the output cache prior to starting a print
2017-08-03 16:35:22 -07:00
PrinterConnection . Instance . TerminalLog . Clear ( ) ;
2017-06-16 18:04:47 -07:00
string hideGCodeWarning = ApplicationSettings . Instance . get ( ApplicationSettingsKey . HideGCodeWarning ) ;
if ( Path . GetExtension ( pathAndFile ) . ToUpper ( ) = = ".GCODE"
& & hideGCodeWarning = = null
& & ! overrideAllowGCode )
{
CheckBox hideGCodeWarningCheckBox = new CheckBox ( doNotAskAgainMessage ) ;
hideGCodeWarningCheckBox . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
hideGCodeWarningCheckBox . Margin = new BorderDouble ( top : 6 , left : 6 ) ;
2017-08-07 15:47:27 -07:00
hideGCodeWarningCheckBox . HAnchor = Agg . UI . HAnchor . Left ;
2017-06-16 18:04:47 -07:00
hideGCodeWarningCheckBox . Click + = ( sender , e ) = >
{
if ( hideGCodeWarningCheckBox . Checked )
{
ApplicationSettings . Instance . set ( ApplicationSettingsKey . HideGCodeWarning , "true" ) ;
}
else
{
ApplicationSettings . Instance . set ( ApplicationSettingsKey . HideGCodeWarning , null ) ;
}
} ;
2017-09-15 18:45:21 -07:00
UiThread . RunOnIdle ( ( ) = >
{
StyledMessageBox . ShowMessageBox (
( bool messageBoxResponse ) = >
{
if ( messageBoxResponse )
{
PrinterConnection . Instance . CommunicationState = CommunicationStates . PreparingToPrint ;
PrintItemWrapper partToPrint = printItem ;
SlicingQueue . Instance . QueuePartForSlicing ( partToPrint ) ;
partToPrint . SlicingDone + = partToPrint_SliceDone ;
}
} ,
gcodeWarningMessage ,
"Warning - GCode file" . Localize ( ) ,
new GuiWidget [ ]
{
new VerticalSpacer ( ) ,
hideGCodeWarningCheckBox
} ,
StyledMessageBox . MessageType . YES_NO ) ;
} ) ;
2017-06-16 18:04:47 -07:00
}
else
{
PrinterConnection . Instance . CommunicationState = CommunicationStates . PreparingToPrint ;
2017-09-15 18:45:21 -07:00
PrintItemWrapper partToPrint = printItem ;
2017-06-16 18:04:47 -07:00
SlicingQueue . Instance . QueuePartForSlicing ( partToPrint ) ;
partToPrint . SlicingDone + = partToPrint_SliceDone ;
}
}
}
}
}
catch ( Exception )
{
}
}
private string gcodeWarningMessage = "The file you are attempting to print is a GCode file.\n\nIt is recommended that you only print Gcode files known to match your printer's configuration.\n\nAre you sure you want to print this GCode file?" . Localize ( ) ;
2017-09-15 18:45:21 -07:00
public void PrintActivePartIfPossible ( PrintItemWrapper printItem , bool overrideAllowGCode = false )
2017-06-16 18:04:47 -07:00
{
2017-09-15 18:45:21 -07:00
if ( PrinterConnection . Instance . CommunicationState = = CommunicationStates . Connected
| | PrinterConnection . Instance . CommunicationState = = CommunicationStates . FinishedPrint )
2017-06-16 18:04:47 -07:00
{
2017-09-15 18:45:21 -07:00
PrintPart ( printItem , overrideAllowGCode ) ;
2017-06-16 18:04:47 -07:00
}
}
private void partToPrint_SliceDone ( object sender , EventArgs e )
{
PrintItemWrapper partToPrint = sender as PrintItemWrapper ;
if ( partToPrint ! = null )
{
partToPrint . SlicingDone - = partToPrint_SliceDone ;
string gcodePathAndFileName = partToPrint . GetGCodePathAndFileName ( ) ;
if ( gcodePathAndFileName ! = "" )
{
bool originalIsGCode = Path . GetExtension ( partToPrint . FileLocation ) . ToUpper ( ) = = ".GCODE" ;
if ( File . Exists ( gcodePathAndFileName ) )
{
// Create archive point for printing attempt
if ( Path . GetExtension ( partToPrint . FileLocation ) . ToUpper ( ) = = ".MCX" )
{
// TODO: We should zip mcx and settings when starting a print
string platingDirectory = Path . Combine ( ApplicationDataStorage . Instance . ApplicationLibraryDataPath , "PrintHistory" ) ;
Directory . CreateDirectory ( platingDirectory ) ;
string now = DateTime . Now . ToString ( "yyyyMMdd-HHmmss" ) ;
string archivePath = Path . Combine ( platingDirectory , now + ".zip" ) ;
using ( var file = File . OpenWrite ( archivePath ) )
using ( var zip = new ZipArchive ( file , ZipArchiveMode . Create ) )
{
zip . CreateEntryFromFile ( partToPrint . FileLocation , "PrinterPlate.mcx" ) ;
zip . CreateEntryFromFile ( ActiveSliceSettings . Instance . DocumentPath , ActiveSliceSettings . Instance . GetValue ( SettingsKey . printer_name ) + ".printer" ) ;
zip . CreateEntryFromFile ( gcodePathAndFileName , "sliced.gcode" ) ;
}
}
// read the last few k of the file and see if it says "filament used". We use this marker to tell if the file finished writing
if ( originalIsGCode )
{
PrinterConnection . Instance . StartPrint ( gcodePathAndFileName ) ;
return ;
}
else
{
int bufferSize = 32000 ;
using ( Stream fileStream = new FileStream ( gcodePathAndFileName , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
{
byte [ ] buffer = new byte [ bufferSize ] ;
fileStream . Seek ( Math . Max ( 0 , fileStream . Length - bufferSize ) , SeekOrigin . Begin ) ;
int numBytesRead = fileStream . Read ( buffer , 0 , bufferSize ) ;
fileStream . Close ( ) ;
string fileEnd = System . Text . Encoding . UTF8 . GetString ( buffer ) ;
if ( fileEnd . Contains ( "filament used" ) )
{
PrinterConnection . Instance . StartPrint ( gcodePathAndFileName ) ;
return ;
}
}
}
}
PrinterConnection . Instance . CommunicationState = CommunicationStates . Connected ;
}
}
}
// TODO: this must be wired up to PrinterConnection.ErrorReported
public void PrinterReportsError ( object sender , EventArgs e )
{
var foundStringEventArgs = e as FoundStringEventArgs ;
if ( foundStringEventArgs ! = null )
{
string message = "Your printer is reporting a hardware Error. This may prevent your printer from functioning properly." . Localize ( )
+ "\n"
+ "\n"
+ "Error Reported" . Localize ( ) + ":"
+ $" \" { foundStringEventArgs . LineToCheck } \ "." ;
UiThread . RunOnIdle ( ( ) = >
2017-09-15 18:45:21 -07:00
StyledMessageBox . ShowMessageBox ( null , message , "Printer Hardware Error" . Localize ( ) )
2017-06-16 18:04:47 -07:00
) ;
}
}
2017-08-07 14:19:28 -07:00
}
public class WidgetSourceEventArgs : EventArgs
{
public GuiWidget Source { get ; }
2017-06-16 18:04:47 -07:00
2017-08-07 14:19:28 -07:00
public WidgetSourceEventArgs ( GuiWidget source )
{
this . Source = source ;
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
}
}