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 ;
2018-03-17 20:53:36 -07:00
using MatterHackers.MatterControl.DesignTools.Operations ;
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 Newtonsoft.Json ;
2017-12-11 14:15:50 -08:00
using System.Collections.ObjectModel ;
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
namespace MatterHackers.MatterControl
{
2018-04-04 10:11:57 -07:00
using System.ComponentModel ;
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 ;
2018-01-26 17:53:54 -08:00
using MatterHackers.DataConverters3D.UndoCommands ;
2017-06-16 18:04:47 -07:00
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling ;
2018-01-23 09:52:05 -08:00
using MatterHackers.MatterControl.DesignTools ;
2018-01-29 13:50:55 -08:00
using MatterHackers.MatterControl.DesignTools.Operations ;
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-10-17 09:40:56 -07:00
using MatterHackers.MatterControl.PartPreviewWindow.View3D ;
2017-10-18 14:56:10 -07:00
using MatterHackers.MatterControl.PrinterControls.PrinterConnections ;
2018-02-26 17:48:15 -08:00
using MatterHackers.PolygonMesh ;
using MatterHackers.RenderOpenGl ;
2017-06-16 18:04:47 -07:00
using MatterHackers.SerialPortCommunication ;
2018-02-21 15:23:54 -08: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-12-16 13:56:59 -08:00
public class AppContext
{
/// <summary>
2018-03-26 16:54:36 -07:00
/// Native platform features
2017-12-16 13:56:59 -08:00
/// </summary>
public static INativePlatformFeatures Platform { get ; set ; }
2017-12-16 19:09:25 -08:00
2017-12-18 17:22:50 -08:00
public static bool IsLoading { get ; internal set ; } = true ;
2017-12-16 19:09:25 -08:00
/// <summary>
/// The root SystemWindow
/// </summary>
public static SystemWindow RootSystemWindow { get ; internal set ; }
2017-12-16 13:56:59 -08:00
}
2017-06-24 10:30:11 -07:00
public class ApplicationController
{
2018-03-26 16:54:36 -07:00
private Dictionary < Type , HashSet < IObject3DEditor > > objectEditorsByType ;
2018-04-07 12:17:23 -07:00
public ThemeConfig Theme { get ; set ; }
2017-06-24 10:30:11 -07:00
2017-12-11 14:15:50 -08:00
public RunningTasksConfig Tasks { get ; set ; } = new RunningTasksConfig ( ) ;
2017-09-17 14:23:28 -07:00
// A list of printers which are open (i.e. displaying a tab) on this instance of MatterControl
2017-09-20 18:05:15 -07:00
public IEnumerable < PrinterConfig > ActivePrinters { get ; } = new List < PrinterConfig > ( ) ;
2017-09-17 14:23:28 -07:00
2017-12-20 18:25:12 -08:00
private static PrinterConfig emptyPrinter = new PrinterConfig ( PrinterSettings . Empty ) ;
2017-09-17 14:23:28 -07:00
2017-11-14 14:15:34 -08:00
private static string cacheDirectory = Path . Combine ( ApplicationDataStorage . ApplicationUserDataPath , "data" , "temp" , "cache" ) ;
2018-03-26 16:54:36 -07:00
// TODO: Any references to this property almost certainly need to be reconsidered. ActiveSliceSettings static references that assume a single printer
2017-09-20 18:05:15 -07:00
// selection are being redirected here. This allows us to break the dependency to the original statics and consolidates
// us down to a single point where code is making assumptions about the presence of a printer, printer counts, etc. If we previously checked for
2017-09-17 14:23:28 -07:00
// PrinterConnection.IsPrinterConnected, that could should be updated to iterate ActiverPrinters, checking each one and acting on each as it would
// have for the single case
2017-09-20 18:05:15 -07:00
public PrinterConfig ActivePrinter { get ; private set ; } = emptyPrinter ;
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 CloudSyncStatusChanged = new RootedObjectEventHandler ( ) ;
public RootedObjectEventHandler DoneReloadingAll = 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 ;
#if DEBUG
public const string EnvironmentName = "TestEnv_" ;
#else
public const string EnvironmentName = "" ;
#endif
2017-12-16 19:09:25 -08:00
public bool ApplicationExiting { get ; internal set ; } = false ;
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 < string , Task < Dictionary < string , string > > > GetProfileHistory ;
private readonly static object thumbsLock = new object ( ) ;
private Queue < Func < Task > > queuedThumbCallbacks = new Queue < Func < Task > > ( ) ;
2017-11-14 15:45:23 -08:00
public async Task SetActivePrinter ( PrinterConfig printer , bool allowChangedEvent = true )
2017-09-20 18:05:15 -07:00
{
2017-09-23 14:44:43 -07:00
var initialPrinter = this . ActivePrinter ;
if ( initialPrinter ? . Settings . ID ! = printer . Settings . ID )
{
2017-11-14 15:45:23 -08:00
// TODO: Consider if autosave is appropriate
if ( initialPrinter ! = emptyPrinter )
{
2018-02-13 17:00:23 -08:00
await initialPrinter . Bed . SaveChanges ( null , CancellationToken . None ) ;
2017-11-14 15:45:23 -08:00
}
2017-09-23 14:44:43 -07:00
// If we have an active printer, run Disable
if ( initialPrinter . Settings ! = PrinterSettings . Empty )
{
initialPrinter ? . Connection ? . Disable ( ) ;
}
// ActivePrinters is IEnumerable to force us to use SetActivePrinter until it's ingrained in our pattern - cast to list since it is and we need to add
( this . ActivePrinters as List < PrinterConfig > ) . Add ( printer ) ;
this . ActivePrinter = printer ;
// TODO: Decide if non-printer contexts should prompt for a printer, if we should have a default printer, or get "ActiveTab printer" working
// HACK: short term solution to resolve printer reference for non-printer related contexts
DragDropData . Printer = printer ;
2017-12-18 17:22:50 -08:00
if ( ! AppContext . IsLoading )
2017-09-23 14:44:43 -07:00
{
// Fire printer changed event
}
BedSettings . SetMakeAndModel (
2018-03-26 16:54:36 -07:00
printer . Settings . GetValue ( SettingsKey . make ) ,
2017-09-23 14:44:43 -07:00
printer . Settings . GetValue ( SettingsKey . model ) ) ;
ActiveSliceSettings . SwitchToPrinterTheme ( ) ;
if ( allowChangedEvent )
{
ActiveSliceSettings . OnActivePrinterChanged ( null ) ;
}
2017-12-18 17:22:50 -08:00
if ( ! AppContext . IsLoading
2017-09-23 14:44:43 -07:00
& & printer . Settings . PrinterSelected
& & printer . Settings . GetValue < bool > ( SettingsKey . auto_connect ) )
{
UiThread . RunOnIdle ( ( ) = >
{
2018-01-06 12:00:14 -08:00
printer . Settings . printer . Connection . Connect ( ) ;
2017-09-23 14:44:43 -07:00
} , 2 ) ;
}
}
}
2017-11-14 15:45:23 -08:00
internal async Task ClearActivePrinter ( )
2017-09-23 14:44:43 -07:00
{
2017-11-14 15:45:23 -08:00
await this . SetActivePrinter ( emptyPrinter ) ;
2017-09-23 14:44:43 -07:00
}
2017-12-16 08:55:20 -08:00
public void LaunchBrowser ( string targetUri )
{
UiThread . RunOnIdle ( ( ) = >
{
2018-04-05 13:55:23 -07:00
if ( ! string . IsNullOrEmpty ( OemSettings . Instance . AffiliateCode )
2018-03-16 15:43:32 -07:00
& & targetUri . Contains ( "matterhackers.com" ) )
{
2018-04-05 13:55:23 -07:00
if ( targetUri . Contains ( "?" ) )
2018-03-16 15:43:32 -07:00
{
targetUri + = $"&aff={OemSettings.Instance.AffiliateCode}" ;
}
else
{
targetUri + = $"?aff={OemSettings.Instance.AffiliateCode}" ;
}
}
2017-12-16 08:55:20 -08:00
Process . Start ( targetUri ) ;
} ) ;
}
2017-09-23 14:44:43 -07:00
public void RefreshActiveInstance ( PrinterSettings updatedPrinterSettings )
{
ActivePrinter . SwapToSettings ( updatedPrinterSettings ) ;
/ *
// TODO: Should we rebroadcast settings changed events for each settings?
bool themeChanged = ActivePrinter . Settings . GetValue ( SettingsKey . active_theme_name ) ! = updatedProfile . GetValue ( SettingsKey . active_theme_name ) ;
ActiveSliceSettings . SettingChanged . CallEvents ( null , new StringEventArgs ( SettingsKey . printer_name ) ) ;
2017-09-23 09:19:32 -07:00
// TODO: Decide if non-printer contexts should prompt for a printer, if we should have a default printer, or get "ActiveTab printer" working
// HACK: short term solution to resolve printer reference for non-printer related contexts
DragDropData . Printer = printer ;
2017-09-23 14:44:43 -07:00
if ( themeChanged )
{
UiThread . RunOnIdle ( ActiveSliceSettings . SwitchToPrinterTheme ) ;
}
else
{
UiThread . RunOnIdle ( ApplicationController . Instance . ReloadAdvancedControlsPanel ) ;
} * /
2017-09-20 18:05:15 -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
private AutoResetEvent thumbGenResetEvent = new AutoResetEvent ( false ) ;
Task thumbnailGenerator = null ;
internal void QueueForGeneration ( Func < Task > func )
{
2018-04-05 13:55:23 -07:00
lock ( thumbsLock )
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-10-09 07:58:32 -07:00
if ( thumbnailGenerator = = null )
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
{
// 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" ;
2018-04-05 13:55:23 -07:00
while ( ! this . ApplicationExiting )
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
{
2018-03-26 16:54:36 -07:00
// Process until queuedThumbCallbacks is empty then wait for new tasks via QueueForGeneration
2017-06-13 13:08:53 -07:00
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-12-09 14:20:25 -08:00
catch ( AppDomainUnloadedException )
{
return ;
}
2017-10-20 06:09:14 -07:00
catch ( ThreadAbortException )
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-11-21 07:05:16 -08:00
return ;
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 ( 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
}
2017-10-09 07:58:32 -07:00
// Null task reference on exit
thumbnailGenerator = null ;
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
}
2018-04-05 13:55:23 -07:00
public static Func < PrinterInfo , string , Task < PrinterSettings > > GetPrinterProfileAsync ;
public static Func < string , IProgress < ProgressStatus > , Task > SyncPrinterProfiles ;
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 < Task < OemProfileDictionary > > GetPublicProfileList ;
public static Func < string , Task < PrinterSettings > > DownloadPublicProfileAsync ;
public SlicePresetsWindow EditMaterialPresetsWindow { get ; set ; }
public SlicePresetsWindow EditQualityPresetsWindow { get ; set ; }
2017-12-17 00:00:41 -08:00
public GuiWidget MainView ;
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
private EventHandler unregisterEvents ;
private Dictionary < string , List < PrintItemAction > > registeredLibraryActions = new Dictionary < string , List < PrintItemAction > > ( ) ;
2018-04-09 15:17:05 -07:00
private List < SceneSelectionOperation > registeredSceneOperations ;
private void RebuildSceneOperations ( )
2017-09-18 17:57:06 -07:00
{
2018-04-09 15:17:05 -07:00
registeredSceneOperations = new List < SceneSelectionOperation > ( )
2017-10-13 15:16:14 -07:00
{
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
2018-03-28 17:20:47 -07:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Group" . Localize ( ) ,
Action = ( scene ) = >
2018-03-28 17:20:47 -07:00
{
2018-04-09 15:17:05 -07:00
var selectedItem = scene . SelectedItem ;
scene . SelectedItem = null ;
2018-03-28 17:20:47 -07:00
2018-04-09 15:17:05 -07:00
var newGroup = new Object3D ( )
2018-03-28 17:20:47 -07:00
{
2018-04-09 15:17:05 -07:00
Name = "Group" . Localize ( )
} ;
2018-03-28 17:20:47 -07:00
2018-04-09 15:17:05 -07:00
// When grouping items, move them to be centered on their bounding box
newGroup . Children . Modify ( ( gChildren ) = >
{
selectedItem . Clone ( ) . Children . Modify ( ( sChildren ) = >
2018-03-28 17:20:47 -07:00
{
2018-04-09 15:17:05 -07:00
var center = selectedItem . GetAxisAlignedBoundingBox ( ) . Center ;
2018-03-28 17:20:47 -07:00
2018-04-09 15:17:05 -07:00
foreach ( var child in sChildren )
{
child . Translate ( - center . X , - center . Y , 0 ) ;
gChildren . Add ( child ) ;
}
newGroup . Translate ( center . X , center . Y , 0 ) ;
} ) ;
2018-03-28 17:20:47 -07:00
} ) ;
2018-04-09 15:17:05 -07:00
scene . UndoBuffer . AddAndDo ( new ReplaceCommand ( selectedItem . Children . ToList ( ) , new List < IObject3D > { newGroup } ) ) ;
2018-03-28 17:20:47 -07:00
2018-04-09 15:17:05 -07:00
newGroup . MakeNameNonColliding ( ) ;
2018-03-28 17:20:47 -07:00
2018-04-09 15:17:05 -07:00
scene . SelectedItem = newGroup ;
2018-03-28 17:20:47 -07:00
2018-04-09 15:17:05 -07:00
} ,
IsEnabled = ( scene ) = > scene . HasSelection
& & scene . SelectedItem is SelectionGroup
& & scene . SelectedItem . Children . Count > 1 ,
Icon = AggContext . StaticData . LoadIcon ( "group.png" , 16 , 16 ) . SetPreMultiply ( ) ,
2018-03-28 17:20:47 -07:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
{
TitleResolver = ( ) = > "Ungroup" . Localize ( ) ,
Action = ( scene ) = > scene . UngroupSelection ( ) ,
IsEnabled = ( scene ) = > scene . HasSelection ,
Icon = AggContext . StaticData . LoadIcon ( "ungroup.png" , 16 , 16 ) . SetPreMultiply ( ) ,
} ,
new SceneSelectionSeparator ( ) ,
new SceneSelectionOperation ( )
{
TitleResolver = ( ) = > "Duplicate" . Localize ( ) ,
Action = ( scene ) = > scene . DuplicateItem ( ) ,
IsEnabled = ( scene ) = > scene . HasSelection ,
Icon = AggContext . StaticData . LoadIcon ( "duplicate.png" ) . SetPreMultiply ( ) ,
} ,
new SceneSelectionOperation ( )
2018-02-13 13:42:57 -08:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Remove" . Localize ( ) ,
Action = ( scene ) = > scene . DeleteSelection ( ) ,
IsEnabled = ( scene ) = > scene . HasSelection ,
Icon = AggContext . StaticData . LoadIcon ( "remove.png" ) . SetPreMultiply ( ) ,
} ,
new SceneSelectionSeparator ( ) ,
new SceneSelectionOperation ( )
{
TitleResolver = ( ) = > "Align" . Localize ( ) ,
Action = ( scene ) = >
2018-02-13 13:42:57 -08:00
{
2018-04-09 15:17:05 -07:00
scene . AddSelectionAsChildren ( new Align3D ( ) ) ;
if ( scene . SelectedItem is Align3D arange )
{
arange . Rebuild ( null ) ;
}
} ,
Icon = AggContext . StaticData . LoadIcon ( "align_left.png" , 16 , 16 , IconColor . Theme ) . SetPreMultiply ( ) ,
IsEnabled = ( scene ) = > scene . SelectedItem is SelectionGroup ,
2018-02-13 13:42:57 -08:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
2017-10-17 09:40:56 -07:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Lay Flat" . Localize ( ) ,
Action = ( scene ) = >
2017-10-23 14:26:10 -07:00
{
2018-04-09 15:17:05 -07:00
if ( scene . HasSelection )
{
scene . MakeLowestFaceFlat ( scene . SelectedItem ) ;
}
} ,
IsEnabled = ( scene ) = > scene . HasSelection ,
Icon = AggContext . StaticData . LoadIcon ( "lay_flat.png" , 16 , 16 ) . SetPreMultiply ( ) ,
2018-01-09 15:47:00 -08:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
2018-01-18 07:33:12 -08:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Make Support" . Localize ( ) ,
Action = ( scene ) = >
2018-01-18 07:33:12 -08:00
{
2018-04-09 15:17:05 -07:00
if ( scene . SelectedItem ! = null
& & ! scene . SelectedItem . VisibleMeshes ( ) . All ( i = > i . object3D . OutputType = = PrintOutputTypes . Support ) )
{
scene . UndoBuffer . AddAndDo ( new MakeSupport ( scene . SelectedItem ) ) ;
}
} ,
Icon = AggContext . StaticData . LoadIcon ( "support.png" ) . SetPreMultiply ( ) ,
IsEnabled = ( scene ) = > scene . HasSelection ,
2018-01-18 07:33:12 -08:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionSeparator ( ) ,
new SceneSelectionOperation ( )
{
TitleResolver = ( ) = > "Combine" . Localize ( ) ,
Action = ( scene ) = > MeshWrapperObject3D . WrapSelection ( new CombineObject3D ( ) , scene ) ,
Icon = AggContext . StaticData . LoadIcon ( "combine.png" ) . SetPreMultiply ( ) ,
IsEnabled = ( scene ) = > scene . SelectedItem is SelectionGroup ,
} ,
new SceneSelectionOperation ( )
{
TitleResolver = ( ) = > "Subtract" . Localize ( ) ,
Action = ( scene ) = > MeshWrapperObject3D . WrapSelection ( new SubtractObject3D ( ) , scene ) ,
Icon = AggContext . StaticData . LoadIcon ( "subtract.png" ) . SetPreMultiply ( ) ,
IsEnabled = ( scene ) = > scene . SelectedItem is SelectionGroup ,
} ,
new SceneSelectionOperation ( )
{
TitleResolver = ( ) = > "Intersect" . Localize ( ) ,
Action = ( scene ) = > MeshWrapperObject3D . WrapSelection ( new IntersectionObject3D ( ) , scene ) ,
Icon = AggContext . StaticData . LoadIcon ( "intersect.png" ) ,
IsEnabled = ( scene ) = > scene . SelectedItem is SelectionGroup ,
} ,
new SceneSelectionOperation ( )
{
TitleResolver = ( ) = > "Subtract & Replace" . Localize ( ) ,
Action = ( scene ) = > MeshWrapperObject3D . WrapSelection ( new SubtractAndReplaceObject3D ( ) , scene ) ,
Icon = AggContext . StaticData . LoadIcon ( "subtract_and_replace.png" ) . SetPreMultiply ( ) ,
IsEnabled = ( scene ) = > scene . SelectedItem is SelectionGroup ,
} ,
new SceneSelectionSeparator ( ) ,
new SceneSelectionOperation ( )
2018-01-26 17:53:54 -08:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Linear Array" . Localize ( ) ,
Action = ( scene ) = >
2018-02-07 15:57:27 -08:00
{
2018-04-09 15:17:05 -07:00
scene . AddSelectionAsChildren ( new ArrayLinear3D ( ) ) ;
if ( scene . SelectedItem is ArrayLinear3D array )
{
array . Rebuild ( null ) ;
}
} ,
Icon = AggContext . StaticData . LoadIcon ( "array_linear.png" ) . SetPreMultiply ( ) ,
IsEnabled = ( scene ) = > scene . HasSelection & & ! ( scene . SelectedItem is SelectionGroup ) ,
2018-01-26 17:53:54 -08:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
2018-02-09 18:10:41 -08:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Radial Array" . Localize ( ) ,
Action = ( scene ) = >
2018-02-09 18:10:41 -08:00
{
2018-04-09 15:17:05 -07:00
scene . AddSelectionAsChildren ( new ArrayRadial3D ( ) ) ;
if ( scene . SelectedItem is ArrayRadial3D array )
{
array . Rebuild ( null ) ;
}
} ,
Icon = AggContext . StaticData . LoadIcon ( "array_radial.png" ) . SetPreMultiply ( ) ,
IsEnabled = ( scene ) = > scene . HasSelection & & ! ( scene . SelectedItem is SelectionGroup ) ,
2018-02-09 18:10:41 -08:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
2018-02-09 18:10:41 -08:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Advanced Array" . Localize ( ) ,
Action = ( scene ) = >
2018-02-09 18:10:41 -08:00
{
2018-04-09 15:17:05 -07:00
scene . AddSelectionAsChildren ( new ArrayAdvanced3D ( ) ) ;
if ( scene . SelectedItem is ArrayAdvanced3D array )
{
array . Rebuild ( null ) ;
}
} ,
Icon = AggContext . StaticData . LoadIcon ( "array_advanced.png" ) . SetPreMultiply ( ) ,
IsEnabled = ( scene ) = > scene . HasSelection & & ! ( scene . SelectedItem is SelectionGroup ) ,
2018-02-09 18:10:41 -08:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionSeparator ( ) ,
new SceneSelectionOperation ( )
2018-04-01 16:06:31 -07:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Pinch" . Localize ( ) ,
Action = ( scene ) = >
{
var pinch = new PinchObject3D ( ) ;
MeshWrapperObject3D . WrapSelection ( pinch , scene ) ;
} ,
Icon = AggContext . StaticData . LoadIcon ( "pinch.png" , 16 , 16 , IconColor . Theme ) ,
IsEnabled = ( scene ) = > scene . HasSelection ,
2018-04-01 16:06:31 -07:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
2018-04-02 14:15:27 -07:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Curve" . Localize ( ) ,
Action = ( scene ) = >
{
var curve = new CurveObject3D ( ) ;
MeshWrapperObject3D . WrapSelection ( curve , scene ) ;
} ,
Icon = AggContext . StaticData . LoadIcon ( "curve.png" , 16 , 16 , IconColor . Theme ) ,
IsEnabled = ( scene ) = > scene . HasSelection ,
2018-04-02 14:15:27 -07:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
2018-03-17 20:53:36 -07:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Fit to Bounds" . Localize ( ) ,
Action = ( scene ) = >
{
var selectedItem = scene . SelectedItem ;
scene . SelectedItem = null ;
var fit = FitToBounds3D . Create ( selectedItem . Clone ( ) ) ;
fit . MakeNameNonColliding ( ) ;
2018-03-17 20:53:36 -07:00
2018-04-09 15:17:05 -07:00
scene . UndoBuffer . AddAndDo ( new ReplaceCommand ( new List < IObject3D > { selectedItem } , new List < IObject3D > { fit } ) ) ;
2018-03-26 16:54:36 -07:00
2018-04-09 15:17:05 -07:00
scene . SelectedItem = fit ;
} ,
//Icon = AggContext.StaticData.LoadIcon("array_linear.png").SetPreMultiply(),
IsEnabled = ( scene ) = > scene . HasSelection & & ! ( scene . SelectedItem is SelectionGroup ) ,
2018-03-17 20:53:36 -07:00
} ,
2018-04-09 15:17:05 -07:00
#if DEBUG // keep this work in progress to the editor for now
new SceneSelectionSeparator ( ) ,
new SceneSelectionOperation ( )
2018-01-31 22:53:27 -08:00
{
2018-04-09 15:17:05 -07:00
TitleResolver = ( ) = > "Package" . Localize ( ) ,
Action = ( scene ) = >
{
var selectedItem = scene . SelectedItem ;
scene . SelectedItem = null ;
var package = Package3D . Create ( selectedItem . Clone ( ) ) ;
package . MakeNameNonColliding ( ) ;
2018-03-18 08:47:07 -07:00
2018-04-09 15:17:05 -07:00
scene . UndoBuffer . AddAndDo ( new ReplaceCommand ( new List < IObject3D > { selectedItem } , new List < IObject3D > { package } ) ) ;
2018-03-18 08:47:07 -07:00
2018-04-09 15:17:05 -07:00
scene . SelectedItem = package ;
} ,
IsEnabled = ( scene ) = > scene . HasSelection ,
2018-01-31 22:53:27 -08:00
} ,
2018-04-09 15:17:05 -07:00
new SceneSelectionOperation ( )
{
TitleResolver = ( ) = > "Bend" . Localize ( ) ,
Action = ( scene ) = > new BendObject3D ( scene . SelectedItem ) ,
IsEnabled = ( scene ) = > scene . HasSelection ,
} ,
#endif
} ;
}
2017-09-18 17:57:06 -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
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 ; }
2018-01-30 11:50:22 -08:00
public GraphConfig Graph { get ; }
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
private void InitializeLibrary ( )
{
if ( Directory . Exists ( ApplicationDataStorage . Instance . DownloadsDirectory ) )
{
2018-01-15 12:38:43 -08:00
this . Library . RegisterContainer (
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
new DynamicContainerLink (
2017-12-04 14:08:54 -08:00
( ) = > "Downloads" . Localize ( ) ,
2017-12-15 14:55:10 -08:00
AggContext . StaticData . LoadIcon ( Path . Combine ( "FileDialog" , "download_folder.png" ) ) ,
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
( ) = > new FileSystemContainer ( ApplicationDataStorage . Instance . DownloadsDirectory )
{
UseIncrementedNameDuringTypeChange = true
} ) ) ;
}
2018-01-15 12:38:43 -08:00
this . Library . RegisterContainer (
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
new DynamicContainerLink (
2017-12-04 14:08:54 -08:00
( ) = > "Calibration Parts" . Localize ( ) ,
2017-12-15 14:55:10 -08:00
AggContext . StaticData . LoadIcon ( Path . Combine ( "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
2018-01-15 12:38:43 -08:00
this . Library . RegisterContainer (
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
new DynamicContainerLink (
2017-12-04 14:08:54 -08:00
( ) = > "Print Queue" . Localize ( ) ,
2017-12-15 14:55:10 -08:00
AggContext . StaticData . LoadIcon ( Path . Combine ( "FileDialog" , "queue_folder.png" ) ) ,
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
( ) = > new PrintQueueContainer ( ) ) ) ;
var rootLibraryCollection = Datastore . Instance . dbSQLite . Table < PrintItemCollection > ( ) . Where ( v = > v . Name = = "_library" ) . Take ( 1 ) . FirstOrDefault ( ) ;
if ( rootLibraryCollection ! = null )
{
2018-01-15 12:38:43 -08:00
this . Library . RegisterContainer (
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
new DynamicContainerLink (
2017-12-04 14:08:54 -08:00
( ) = > "Local Library" . Localize ( ) ,
2017-12-15 14:55:10 -08:00
AggContext . StaticData . LoadIcon ( Path . Combine ( "FileDialog" , "library_folder.png" ) ) ,
2017-10-09 07:55:09 -07:00
( ) = > new SqliteLibraryContainer ( rootLibraryCollection . Id ) ) ) ;
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
}
2018-01-15 12:38:43 -08:00
this . Library . RegisterContainer (
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
new DynamicContainerLink (
2017-12-04 14:08:54 -08:00
( ) = > "Print History" . Localize ( ) ,
2017-12-15 14:55:10 -08:00
AggContext . StaticData . LoadIcon ( Path . Combine ( "FileDialog" , "folder.png" ) ) ,
2017-10-09 07:55:09 -07:00
( ) = > new PrintHistoryContainer ( ) )
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
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 ) )
{
2017-12-15 14:55:10 -08:00
//if (Directory.Exists(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
{
2018-01-15 12:38:43 -08:00
this . Library . RegisterContainer (
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
} ) ;
}
}
}
2018-01-15 12:38:43 -08:00
this . Library . RegisterContainer (
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
new DynamicContainerLink (
2017-12-04 14:08:54 -08:00
( ) = > "SD Card" . Localize ( ) ,
2017-12-15 14:55:10 -08:00
AggContext . StaticData . LoadIcon ( Path . Combine ( "FileDialog" , "sd_folder.png" ) ) ,
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
( ) = > new SDCardContainer ( ) ,
( ) = >
{
2017-09-17 14:23:28 -07:00
var printer = this . ActivePrinter ;
2018-01-30 18:04:00 -08:00
return printer . Settings . GetValue < bool > ( SettingsKey . has_sd_card_reader ) ;
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
2017-11-14 14:15:34 -08:00
this . Library . PlatingHistory = new PlatingHistoryContainer ( ) ;
2018-01-15 12:38:43 -08:00
this . Library . RegisterContainer (
2017-11-14 14:15:34 -08:00
new DynamicContainerLink (
2017-12-04 14:08:54 -08:00
( ) = > "Plating History" . Localize ( ) ,
2017-12-15 14:55:10 -08:00
AggContext . StaticData . LoadIcon ( Path . Combine ( "FileDialog" , "folder.png" ) ) ,
2018-04-07 22:51:10 -07:00
( ) = > this . Library . PlatingHistory ) ) ;
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 ( )
{
2018-04-07 12:17:23 -07:00
// Initialize the AppContext theme object which will sync its content with Agg ActiveTheme changes
this . Theme = new ThemeConfig ( ) ;
2018-04-09 16:59:17 -07:00
ActiveTheme . ThemeChanged . RegisterEvent ( ( s , e ) = >
2018-04-07 12:17:23 -07:00
{
this . Theme . RebuildTheme ( ActiveTheme . Instance ) ;
2018-04-09 15:17:05 -07:00
this . RebuildSceneOperations ( ) ;
2018-04-07 12:17:23 -07:00
} , ref unregisterEvents ) ;
this . Theme . RebuildTheme ( ActiveTheme . Instance ) ;
2018-02-06 22:27:46 -08:00
Object3D . AssetsPath = Path . Combine ( ApplicationDataStorage . Instance . ApplicationLibraryDataPath , "Assets" ) ;
2017-11-10 23:03:48 -08:00
ScrollBar . DefaultMargin = new BorderDouble ( right : 1 ) ;
ScrollBar . ScrollBarWidth = 8 * GuiWidget . DeviceScale ;
ScrollBar . GrowThumbBy = 2 ;
2017-12-16 13:56:59 -08:00
// Initialize statics
2017-10-31 11:43:25 -07:00
DefaultThumbBackground . DefaultBackgroundColor = Color . Transparent ;
2017-07-12 14:47:01 -07:00
Object3D . AssetsPath = ApplicationDataStorage . Instance . LibraryAssetsPath ;
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 ( ) ;
2018-01-30 11:50:22 -08:00
this . Graph = new GraphConfig ( ) ;
2017-11-03 13:43:31 -07:00
this . Library . ContentProviders . Add ( new [ ] { "stl" , "obj" , "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 ) = >
{
2017-12-18 17:22:50 -08:00
if ( ! AppContext . IsLoading )
2017-06-21 07:29:22 -07:00
{
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-09-19 11:42:46 -07:00
ActiveSliceSettings . SettingChanged . RegisterEvent ( ( s , e ) = >
{
if ( e is StringEventArgs stringArg
2018-01-13 18:54:40 -08:00
& & SettingsOrganizer . SettingsData . TryGetValue ( stringArg . Data , out SliceSettingData settingsData )
2017-09-19 11:42:46 -07:00
& & settingsData . ReloadUiWhenChanged )
{
UiThread . RunOnIdle ( ReloadAll ) ;
}
} , ref unregisterEvents ) ;
2017-12-04 10:35:24 -08:00
2018-04-09 15:54:30 -07:00
bool waitingForBedHeat = false ;
bool waitingForExtruderHeat = false ;
double heatDistance = 0 ;
double heatStart = 0 ;
// show temperature heating for m109 and m190
PrinterConnection . AnyCommunicationStateChanged . RegisterEvent ( ( s , e ) = >
{
var printerConnection = this . ActivePrinter . Connection ;
if ( printerConnection . PrinterIsPrinting | | printerConnection . PrinterIsPaused )
{
switch ( printerConnection . DetailedPrintingState )
{
case DetailedPrintingState . HeatingBed :
2018-04-09 16:59:17 -07:00
Tasks . Execute (
"Heating Bed" . Localize ( ) ,
( reporter , cancellationToken ) = >
{
waitingForBedHeat = true ;
waitingForExtruderHeat = false ;
2018-04-09 15:54:30 -07:00
2018-04-09 16:59:17 -07:00
var progressStatus = new ProgressStatus ( ) ;
heatStart = printerConnection . ActualBedTemperature ;
heatDistance = Math . Abs ( printerConnection . TargetBedTemperature - heatStart ) ;
2018-04-09 15:54:30 -07:00
2018-04-09 16:59:17 -07:00
while ( heatDistance > 0 & & waitingForBedHeat )
{
var remainingDistance = Math . Abs ( printerConnection . TargetBedTemperature - printerConnection . ActualBedTemperature ) ;
progressStatus . Status = $"Heating Bed ({printerConnection.ActualBedTemperature:0}/{printerConnection.TargetBedTemperature:0})" ;
progressStatus . Progress0To1 = ( heatDistance - remainingDistance ) / heatDistance ;
reporter . Report ( progressStatus ) ;
Thread . Sleep ( 10 ) ;
}
2018-04-09 15:54:30 -07:00
2018-04-09 16:59:17 -07:00
return Task . CompletedTask ;
} ,
new RunningTaskActions ( )
{
ReadOnlyReporting = true
} ) ;
2018-04-09 15:54:30 -07:00
break ;
case DetailedPrintingState . HeatingExtruder :
2018-04-09 16:59:17 -07:00
Tasks . Execute (
"Heating Extruder" . Localize ( ) ,
( reporter , cancellationToken ) = >
{
waitingForBedHeat = false ;
waitingForExtruderHeat = true ;
2018-04-09 15:54:30 -07:00
2018-04-09 16:59:17 -07:00
var progressStatus = new ProgressStatus ( ) ;
2018-04-09 15:54:30 -07:00
2018-04-09 16:59:17 -07:00
heatStart = printerConnection . GetActualHotendTemperature ( 0 ) ;
heatDistance = Math . Abs ( printerConnection . GetTargetHotendTemperature ( 0 ) - heatStart ) ;
2018-04-09 15:54:30 -07:00
2018-04-09 16:59:17 -07:00
while ( heatDistance > 0 & & waitingForExtruderHeat )
{
var currentDistance = Math . Abs ( printerConnection . GetTargetHotendTemperature ( 0 ) - printerConnection . GetActualHotendTemperature ( 0 ) ) ;
progressStatus . Progress0To1 = ( heatDistance - currentDistance ) / heatDistance ;
2018-04-11 12:51:51 -07:00
progressStatus . Status = $"Heating Extruder ({printerConnection.GetActualHotendTemperature(0):0}/{printerConnection.GetTargetHotendTemperature(0):0})" ;
2018-04-09 16:59:17 -07:00
reporter . Report ( progressStatus ) ;
Thread . Sleep ( 1000 ) ;
}
2018-04-09 15:54:30 -07:00
2018-04-09 16:59:17 -07:00
return Task . CompletedTask ;
} ,
new RunningTaskActions ( )
{
ReadOnlyReporting = true
} ) ;
2018-04-09 15:54:30 -07:00
break ;
case DetailedPrintingState . HomingAxis :
case DetailedPrintingState . Printing :
default :
// clear any existing waiting states
waitingForBedHeat = false ;
waitingForExtruderHeat = false ;
break ;
}
}
else
{
// turn of any running temp feedback tasks
waitingForBedHeat = false ;
waitingForExtruderHeat = false ;
}
} , ref unregisterEvent ) ;
// show countdown for turning off heat if required
2018-01-30 15:47:12 -08:00
PrinterConnection . HeatTurningOffSoon . RegisterEvent ( ( s , e ) = >
2018-01-30 14:48:53 -08:00
{
2018-04-07 22:51:10 -07:00
var printerConnection = this . ActivePrinter . Connection ;
2018-01-30 14:48:53 -08:00
2018-04-05 12:44:51 -07:00
if ( printerConnection . AnyHeatIsOn )
2018-01-30 14:48:53 -08:00
{
2018-02-20 18:27:52 -08:00
Tasks . Execute ( "Disable Heaters" . Localize ( ) , ( reporter , cancellationToken ) = >
2018-01-30 14:48:53 -08:00
{
var progressStatus = new ProgressStatus ( ) ;
2018-01-30 15:47:12 -08:00
while ( printerConnection . SecondsUntilTurnOffHeaters > 0
2018-01-30 14:48:53 -08:00
& & ! cancellationToken . IsCancellationRequested
2018-01-30 15:47:12 -08:00
& & printerConnection . ContinuWaitingToTurnOffHeaters )
2018-01-30 14:48:53 -08:00
{
reporter . Report ( progressStatus ) ;
2018-01-30 15:47:12 -08:00
progressStatus . Status = "Turn Off Heat in" . Localize ( ) + " " + printerConnection . SecondsUntilTurnOffHeaters . ToString ( "0" ) ;
2018-01-30 14:48:53 -08:00
Thread . Sleep ( 100 ) ;
}
if ( ! cancellationToken . IsCancellationRequested
2018-01-30 15:47:12 -08:00
& & printerConnection . ContinuWaitingToTurnOffHeaters )
2018-01-30 14:48:53 -08:00
{
2018-03-21 14:20:43 -07:00
printerConnection . TurnOffBedAndExtruders ( TurnOff . Now ) ;
2018-01-30 14:48:53 -08:00
}
2018-04-05 13:55:23 -07:00
if ( cancellationToken . IsCancellationRequested )
2018-02-09 13:37:21 -08:00
{
printerConnection . ContinuWaitingToTurnOffHeaters = false ;
}
2018-01-30 14:48:53 -08:00
return Task . CompletedTask ;
} ) ;
}
} , ref unregisterEvents ) ;
2017-10-10 16:40:59 -07:00
PrinterConnection . ErrorReported . RegisterEvent ( ( s , 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-10-18 19:54:06 -07:00
StyledMessageBox . ShowMessageBox ( message , "Printer Hardware Error" . Localize ( ) )
2017-10-10 16:40:59 -07:00
) ;
}
} , ref unregisterEvent ) ;
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 . InitializeLibrary ( ) ;
2017-06-13 13:08:53 -07:00
2017-09-17 21:08:16 -07:00
PrinterConnection . AnyConnectionSucceeded . RegisterEvent ( ( s , e ) = >
2017-06-16 18:04:47 -07:00
{
// run the print leveling wizard if we need to for this printer
2017-09-17 21:08:16 -07:00
var printer = ApplicationController . Instance . ActivePrinters . Where ( p = > p . Connection = = s ) . FirstOrDefault ( ) ;
2018-04-05 13:55:23 -07:00
if ( printer ! = null )
2017-06-16 18:04:47 -07:00
{
2018-04-09 12:22:18 -07:00
ApplicationController . Instance . RunAnyRequiredCalibration ( printer , this . Theme ) ;
2017-06-16 18:04:47 -07:00
}
} , ref unregisterEvents ) ;
2018-03-26 16:54:36 -07:00
HashSet < IObject3DEditor > mappedEditors ;
objectEditorsByType = new Dictionary < Type , HashSet < IObject3DEditor > > ( ) ;
foreach ( IObject3DEditor editor in PluginFinder . CreateInstancesOf < IObject3DEditor > ( ) )
{
foreach ( Type type in editor . SupportedTypes ( ) )
{
if ( ! objectEditorsByType . TryGetValue ( type , out mappedEditors ) )
{
mappedEditors = new HashSet < IObject3DEditor > ( ) ;
objectEditorsByType . Add ( type , mappedEditors ) ;
}
mappedEditors . Add ( editor ) ;
}
}
}
2018-04-09 12:22:18 -07:00
public bool RunAnyRequiredCalibration ( PrinterConfig printer , ThemeConfig theme )
2018-04-06 14:58:25 -07:00
{
if ( PrintLevelingData . NeedsToBeRun ( printer ) )
{
// run probe calibration first if we need to
if ( ProbeCalibrationWizard . NeedsToBeRun ( printer ) )
{
UiThread . RunOnIdle ( ( ) = >
{
2018-04-09 12:22:18 -07:00
ProbeCalibrationWizard . ShowProbeCalibrationWizard ( printer , theme ) ;
2018-04-06 14:58:25 -07:00
} ) ;
}
else // run the leveling wizard
{
UiThread . RunOnIdle ( ( ) = >
{
2018-04-09 12:22:18 -07:00
LevelWizardBase . ShowPrintLevelWizard ( printer , theme ) ;
2018-04-06 14:58:25 -07:00
} ) ;
}
return true ;
}
return false ;
}
2018-03-26 16:54:36 -07:00
public HashSet < IObject3DEditor > GetEditorsForType ( Type selectedItemType )
{
HashSet < IObject3DEditor > mappedEditors ;
objectEditorsByType . TryGetValue ( selectedItemType , out mappedEditors ) ;
if ( mappedEditors = = null )
{
foreach ( var kvp in objectEditorsByType )
{
var editorType = kvp . Key ;
if ( editorType . IsAssignableFrom ( selectedItemType ) )
{
mappedEditors = kvp . Value ;
break ;
}
}
}
return mappedEditors ;
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-10-09 07:58:32 -07:00
internal void Shutdown ( )
{
// Ensure all threads shutdown gracefully on close
// Release any waiting generator threads
thumbGenResetEvent ? . Set ( ) ;
2018-02-01 17:25:42 -08:00
// Kill all long running tasks (this will release the silcing thread if running)
foreach ( var task in Tasks . RunningTasks )
{
task . CancelTask ( ) ;
}
2017-10-09 07:58:32 -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
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 ;
}
}
2018-01-28 07:53:23 -08:00
private static TypeFace titilliumTypeFace = null ;
public static TypeFace TitilliumTypeFace
{
get
{
if ( titilliumTypeFace = = null )
{
titilliumTypeFace = TypeFace . LoadFrom ( AggContext . StaticData . ReadAllText ( Path . Combine ( "Fonts" , "TitilliumWeb-Black.svg" ) ) ) ;
}
return titilliumTypeFace ;
}
}
private static TypeFace damionTypeFace = null ;
public static TypeFace DamionTypeFace
{
get
{
if ( damionTypeFace = = null )
{
damionTypeFace = TypeFace . LoadFrom ( AggContext . StaticData . ReadAllText ( Path . Combine ( "Fonts" , "Damion-Regular.svg" ) ) ) ;
}
return damionTypeFace ;
}
}
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 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 ) ;
}
public static string CacheablePath ( string cacheScope , string cacheKey )
{
string scopeDirectory = Path . Combine ( cacheDirectory , cacheScope ) ;
// Ensure directory exists
Directory . CreateDirectory ( scopeDirectory ) ;
2017-12-28 16:45:34 -08:00
return Path . Combine ( scopeDirectory , cacheKey ) ;
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
}
// 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 )
2018-03-26 16:54:36 -07:00
& & ( ApplicationSettings . OpenDesignFileParams . Contains ( extension )
2017-11-07 12:06:43 -08:00
| | this . Library . ContentProviders . Keys . Contains ( extensionWithoutPeriod ) ) ;
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-11-07 11:31:30 -08:00
public bool IsReloading { get ; private set ; } = false ;
2017-11-07 13:54:09 -08: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 ReloadAll ( )
{
2017-11-08 23:39:35 -08:00
var reloadingOverlay = new GuiWidget
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Stretch ,
BackgroundColor = this . Theme . DarkShade
} ;
2017-11-07 12:06:43 -08:00
2017-11-07 13:54:09 -08:00
reloadingOverlay . AddChild ( new TextWidget ( "Reloading" . Localize ( ) + "..." , textColor : Color . White , pointSize : this . Theme . DefaultFontSize * 1.5 )
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-11-07 12:06:43 -08:00
HAnchor = HAnchor . Center ,
VAnchor = VAnchor . Center
} ) ;
2017-12-16 19:09:25 -08:00
AppContext . RootSystemWindow . AddChild ( reloadingOverlay ) ;
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-11-07 11:31:30 -08:00
this . IsReloading = 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
UiThread . RunOnIdle ( ( ) = >
{
using ( new QuickTimer ( $"ReloadAll_{reloadCount++}:" ) )
{
2017-12-17 00:00:41 -08:00
MainView = new WidescreenPanel ( ) ;
this . DoneReloadingAll ? . CallEvents ( null , null ) ;
using ( new QuickTimer ( "Time to AddMainview: " ) )
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-12-17 00:00:41 -08:00
AppContext . RootSystemWindow . CloseAllChildren ( ) ;
AppContext . RootSystemWindow . AddChild ( MainView ) ;
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-11-07 11:31:30 -08:00
this . IsReloading = false ;
2017-11-07 13:54:09 -08: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
}
static int reloadCount = 0 ;
2018-02-13 17:00:23 -08:00
public async void OnApplicationClosed ( )
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-11-30 08:52:01 -08:00
// Release the waiting ThumbnailGeneration task so it can shutdown gracefully
thumbGenResetEvent ? . Set ( ) ;
2017-11-14 15:45:23 -08:00
// Save changes before close
if ( this . ActivePrinter ! = null
& & this . ActivePrinter ! = emptyPrinter )
{
2018-02-13 17:00:23 -08:00
await this . ActivePrinter . Bed . SaveChanges ( null , CancellationToken . None ) ;
2017-11-14 15:45:23 -08:00
}
2017-11-30 08:52:01 -08:00
ApplicationSettings . Instance . ReleaseClientToken ( ) ;
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-12-16 20:06:03 -08:00
internal static void LoadOemOrDefaultTheme ( )
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 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 )
{
2017-12-16 20:06:03 -08:00
globalInstance = new ApplicationController ( ) ;
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-12-16 20:06:03 -08:00
ActiveSliceSettings . ActivePrinterChanged . RegisterEvent ( ( s , e ) = >
{
2017-12-18 17:22:50 -08:00
if ( ! AppContext . IsLoading )
2017-08-16 05:53:26 -07:00
{
2017-12-16 20:06:03 -08:00
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-09-16 01:11:44 -07:00
public DragDropData DragDropData { get ; set ; } = new DragDropData ( ) ;
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 ; }
2017-09-25 22:27:46 -07:00
2017-11-03 10:32:11 -07:00
public string ShortProductName = > "MatterControl" ;
2017-10-07 15:17:39 -07:00
public string ProductName = > "MatterHackers: MatterControl" ;
2017-09-20 15:28:58 -07:00
2017-09-28 21:52:35 -07:00
public string ThumbnailCachePath ( ILibraryItem libraryItem )
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
{
// TODO: Use content SHA
return string . IsNullOrEmpty ( libraryItem . ID ) ? null : ApplicationController . CacheablePath ( "ItemThumbnails" , $"{libraryItem.ID}.png" ) ;
}
2017-12-17 11:07:32 -08:00
public string ThumbnailCachePath ( 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" ) ;
}
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 SwitchToPurchasedLibrary ( )
{
var purchasedContainer = Library . RootLibaryContainer . ChildContainers . Where ( c = > c . ID = = "LibraryProviderPurchasedKey" ) . FirstOrDefault ( ) ;
if ( purchasedContainer ! = null )
{
// TODO: Navigate to purchased container
throw new NotImplementedException ( "SwitchToPurchasedLibrary" ) ;
}
}
2017-12-18 17:22:50 -08:00
public void OnLoadActions ( )
{
// TODO: Calling UserChanged seems wrong. Load the right user before we spin up controls, rather than after
// Pushing this after load fixes that empty printer list
/////////////////////ApplicationController.Instance.UserChanged();
bool showAuthWindow = PrinterSetup . ShouldShowAuthPanel ? . Invoke ( ) ? ? false ;
if ( showAuthWindow )
{
if ( ApplicationSettings . Instance . get ( ApplicationSettingsKey . SuppressAuthPanel ) ! = "True" )
{
//Launch window to prompt user to sign in
UiThread . RunOnIdle ( ( ) = > DialogWindow . Show ( PrinterSetup . GetBestStartPage ( ) ) ) ;
}
}
else
{
//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 ( ) ;
} ) ;
}
}
// TODO: This should be moved into the splash screen and shown instead of MainView
if ( AggContext . OperatingSystem = = OSType . Android )
{
// show this last so it is on top
if ( UserSettings . Instance . get ( "SoftwareLicenseAccepted" ) ! = "true" )
{
UiThread . RunOnIdle ( ( ) = > DialogWindow . Show < LicenseAgreementPage > ( ) ) ;
}
}
if ( ApplicationController . Instance . ActivePrinter is PrinterConfig printer
& & printer . Settings . PrinterSelected
& & printer . Settings . GetValue < bool > ( SettingsKey . auto_connect ) )
{
UiThread . RunOnIdle ( ( ) = >
{
//PrinterConnectionAndCommunication.Instance.HaltConnectionThread();
printer . Connection . Connect ( ) ;
} , 2 ) ;
}
2018-03-08 10:36:00 -08:00
if ( AssetObject3D . AssetManager = = null )
{
2018-03-26 16:54:36 -07:00
AssetObject3D . AssetManager = new AssetManager ( ) ;
2018-03-08 10:36:00 -08:00
}
2017-12-18 17:22:50 -08:00
//HtmlWindowTest();
}
private static void RunSetupIfRequired ( )
{
if ( ! ProfileManager . Instance . ActiveProfiles . Any ( ) )
{
// Start the setup wizard if no profiles exist
UiThread . RunOnIdle ( ( ) = > DialogWindow . Show ( PrinterSetup . GetBestStartPage ( ) ) ) ;
}
}
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 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 ;
}
2018-02-14 08:36:28 -08:00
UiThread . RunOnIdle ( this . UserChanged ) ;
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
}
// 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
2018-03-26 16:54:36 -07:00
& & ! ProfileManager . Instance . IsGuestProfile
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
& & ! ProfileManager . Instance . PrintersImported )
{
// Show the import printers wizard
2017-11-08 15:56:37 -08:00
DialogWindow . 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
}
}
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.
2017-12-15 20:29:16 -08:00
// So we scale as many times as we need to get the Image to be the right size.
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 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 ;
}
2017-09-16 01:11:44 -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
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
}
2017-11-14 15:45:23 -08: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
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-09-17 21:08:16 -07:00
if ( this . ActivePrinter . Connection . 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-09-17 21:08:16 -07:00
UiThread . RunOnIdle ( ( ) = > this . ActivePrinter . Connection . 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-09-17 21:08:16 -07:00
this . ActivePrinter . Connection . 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
2018-01-09 15:47:00 -08:00
public IEnumerable < SceneSelectionOperation > RegisteredSceneOperations = > registeredSceneOperations ;
2017-09-18 17:57:06 -07:00
2018-02-06 13:31:25 -08:00
public static IObject3D ClipboardItem { get ; internal set ; }
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 ( ) ;
2018-02-09 18:11:55 -08:00
public async Task PrintPart ( EditContext editContext , PrinterConfig printer , IProgress < ProgressStatus > reporter , CancellationToken cancellationToken , bool overrideAllowGCode = false )
2017-06-16 18:04:47 -07:00
{
2018-02-09 18:11:55 -08:00
var object3D = editContext . Content ;
var partFilePath = editContext . SourceFilePath ;
var gcodeFilePath = editContext . GCodeFilePath ;
var printItemName = editContext . SourceItem . Name ;
2017-10-16 17:28:18 -07:00
// Exit if called in a non-applicable state
if ( this . ActivePrinter . Connection . CommunicationState ! = CommunicationStates . Connected
& & this . ActivePrinter . Connection . CommunicationState ! = CommunicationStates . FinishedPrint )
{
return ;
}
2017-06-16 18:04:47 -07:00
try
{
// If leveling is required or is currently on
2018-04-09 12:22:18 -07:00
if ( ApplicationController . Instance . RunAnyRequiredCalibration ( printer , this . Theme ) )
2017-06-16 18:04:47 -07:00
{
2018-04-06 14:58:25 -07:00
// We need to calibrate. So, don't print this part.
return ;
2017-06-16 18:04:47 -07:00
}
2018-02-09 18:11:55 -08:00
//if (!string.IsNullOrEmpty(partFilePath) && File.Exists(partFilePath))
2017-06-16 18:04:47 -07:00
{
2017-11-15 07:41:36 -08:00
this . PrintingItemName = printItemName ;
2017-09-23 09:19:32 -07:00
if ( ActiveSliceSettings . Instance . IsValid ( ) )
2017-06-16 18:04:47 -07:00
{
{
// clear the output cache prior to starting a print
2017-09-17 21:08:16 -07:00
this . ActivePrinter . Connection . TerminalLog . Clear ( ) ;
2017-06-16 18:04:47 -07:00
string hideGCodeWarning = ApplicationSettings . Instance . get ( ApplicationSettingsKey . HideGCodeWarning ) ;
2017-11-15 07:41:36 -08:00
if ( Path . GetExtension ( partFilePath ) . ToUpper ( ) = = ".GCODE"
2017-06-16 18:04:47 -07:00
& & hideGCodeWarning = = null
& & ! overrideAllowGCode )
{
2017-10-16 17:09:00 -07:00
var hideGCodeWarningCheckBox = new CheckBox ( doNotAskAgainMessage )
{
TextColor = ActiveTheme . Instance . PrimaryTextColor ,
Margin = new BorderDouble ( top : 6 , left : 6 ) ,
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 (
2017-12-11 22:22:56 -08:00
( messageBoxResponse ) = >
2017-09-15 18:45:21 -07:00
{
if ( messageBoxResponse )
{
2017-09-17 21:08:16 -07:00
this . ActivePrinter . Connection . CommunicationState = CommunicationStates . PreparingToPrint ;
2018-02-09 18:11:55 -08:00
this . ArchiveAndStartPrint ( partFilePath , gcodeFilePath ) ;
2017-09-15 18:45:21 -07:00
}
} ,
2017-10-16 17:09:00 -07:00
"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
"Warning - GCode file" . Localize ( ) ,
new GuiWidget [ ]
{
new VerticalSpacer ( ) ,
hideGCodeWarningCheckBox
} ,
StyledMessageBox . MessageType . YES_NO ) ;
} ) ;
2017-06-16 18:04:47 -07:00
}
else
{
2017-09-17 21:08:16 -07:00
this . ActivePrinter . Connection . CommunicationState = CommunicationStates . PreparingToPrint ;
2017-10-16 17:09:00 -07:00
2018-02-09 18:11:55 -08:00
await ApplicationController . Instance . SliceItemLoadOutput (
2017-10-16 17:09:00 -07:00
printer ,
2018-02-09 18:11:55 -08:00
printer . Bed . Scene ,
2017-12-11 14:15:50 -08:00
gcodeFilePath ) ;
2017-10-16 17:09:00 -07:00
2018-02-09 18:11:55 -08:00
this . ArchiveAndStartPrint ( partFilePath , gcodeFilePath ) ;
2017-06-16 18:04:47 -07:00
}
2017-12-11 22:22:56 -08:00
2018-03-19 11:45:28 -07:00
await MonitorPrintTask ( printer ) ;
2017-06-16 18:04:47 -07:00
}
}
}
}
catch ( Exception )
{
}
}
2018-03-21 17:17:36 -07:00
public void ResetTranslationMap ( )
{
TranslationMap . ActiveTranslationMap = new TranslationMap ( "Translations" , UserSettings . Instance . Language ) ;
}
2018-03-19 11:45:28 -07:00
public async Task MonitorPrintTask ( PrinterConfig printer )
{
2018-04-09 18:05:46 -07:00
string layerDetails = ( printer . Bed . LoadedGCode . LayerCount > 0 ) ? $" of {printer.Bed.LoadedGCode.LayerCount}" : "" ;
await ApplicationController . Instance . Tasks . Execute (
"Printing" . Localize ( ) ,
2018-03-19 11:45:28 -07:00
( reporterB , cancellationTokenB ) = >
{
var progressStatus = new ProgressStatus ( ) ;
reporterB . Report ( progressStatus ) ;
return Task . Run ( ( ) = >
{
string printing = "Printing" . Localize ( ) ;
int totalLayers = printer . Connection . TotalLayersInPrint ;
while ( ! printer . Connection . PrinterIsPrinting
& & ! cancellationTokenB . IsCancellationRequested )
{
// Wait for printing
Thread . Sleep ( 200 ) ;
}
while ( ( printer . Connection . PrinterIsPrinting | | printer . Connection . PrinterIsPaused )
& & ! cancellationTokenB . IsCancellationRequested )
{
2018-04-09 18:05:46 -07:00
progressStatus . Status = $"{printing} ({printer.Connection.CurrentlyPrintingLayer + 1}{layerDetails}) - {printer.Connection.PercentComplete:0}%" ;
2018-03-19 11:45:28 -07:00
progressStatus . Progress0To1 = printer . Connection . PercentComplete / 100 ;
reporterB . Report ( progressStatus ) ;
Thread . Sleep ( 200 ) ;
}
} ) ;
} ,
taskActions : new RunningTaskActions ( )
{
RichProgressWidget = ( ) = > PrinterTabPage . PrintProgressWidget ( printer ) ,
Pause = ( ) = > UiThread . RunOnIdle ( ( ) = >
{
printer . Connection . RequestPause ( ) ;
} ) ,
Resume = ( ) = > UiThread . RunOnIdle ( ( ) = >
{
printer . Connection . Resume ( ) ;
} ) ,
Stop = ( ) = > UiThread . RunOnIdle ( ( ) = >
{
ApplicationController . Instance . ConditionalCancelPrint ( ) ;
} )
} ) ;
}
2018-02-09 18:11:55 -08:00
/// <summary>
/// Archives MCX and validates GCode results before starting a print operation
/// </summary>
/// <param name="sourcePath">The source file which originally caused the slice->print operation</param>
/// <param name="gcodeFilePath">The resulting GCode to print</param>
private void ArchiveAndStartPrint ( string sourcePath , string gcodeFilePath )
2017-06-16 18:04:47 -07:00
{
2018-02-09 18:11:55 -08:00
if ( File . Exists ( sourcePath )
& & File . Exists ( gcodeFilePath ) )
2017-06-16 18:04:47 -07:00
{
2018-02-09 18:11:55 -08:00
//if (gcodeFilePath != "")
2017-06-16 18:04:47 -07:00
{
2018-02-09 18:11:55 -08:00
bool originalIsGCode = Path . GetExtension ( sourcePath ) . ToUpper ( ) = = ".GCODE" ;
2017-11-15 08:04:29 -08:00
if ( File . Exists ( gcodeFilePath ) )
2017-06-16 18:04:47 -07:00
{
// Create archive point for printing attempt
2018-02-09 18:11:55 -08:00
if ( Path . GetExtension ( sourcePath ) . ToUpper ( ) = = ".MCX" )
2017-06-16 18:04:47 -07:00
{
// TODO: We should zip mcx and settings when starting a print
string platingDirectory = Path . Combine ( ApplicationDataStorage . Instance . ApplicationLibraryDataPath , "PrintHistory" ) ;
Directory . CreateDirectory ( platingDirectory ) ;
2018-01-03 14:42:26 -08:00
string now = "Workspace " + DateTime . Now . ToString ( "yyyy-MM-dd HH_mm_ss" ) ;
2017-06-16 18:04:47 -07:00
string archivePath = Path . Combine ( platingDirectory , now + ".zip" ) ;
using ( var file = File . OpenWrite ( archivePath ) )
using ( var zip = new ZipArchive ( file , ZipArchiveMode . Create ) )
{
2018-02-09 18:11:55 -08:00
zip . CreateEntryFromFile ( sourcePath , "PrinterPlate.mcx" ) ;
2017-06-16 18:04:47 -07:00
zip . CreateEntryFromFile ( ActiveSliceSettings . Instance . DocumentPath , ActiveSliceSettings . Instance . GetValue ( SettingsKey . printer_name ) + ".printer" ) ;
2017-11-15 08:04:29 -08:00
zip . CreateEntryFromFile ( gcodeFilePath , "sliced.gcode" ) ;
2017-06-16 18:04:47 -07:00
}
}
if ( originalIsGCode )
{
2017-11-15 08:04:29 -08:00
this . ActivePrinter . Connection . StartPrint ( gcodeFilePath ) ;
2017-06-16 18:04:47 -07:00
return ;
}
else
{
2018-02-09 18:11:55 -08:00
// 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
2017-06-16 18:04:47 -07:00
int bufferSize = 32000 ;
2017-11-15 08:04:29 -08:00
using ( Stream fileStream = new FileStream ( gcodeFilePath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
2017-06-16 18:04:47 -07:00
{
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" ) )
{
2017-11-15 08:04:29 -08:00
this . ActivePrinter . Connection . StartPrint ( gcodeFilePath ) ;
2017-06-16 18:04:47 -07:00
return ;
}
}
}
}
2017-09-17 21:08:16 -07:00
this . ActivePrinter . Connection . CommunicationState = CommunicationStates . Connected ;
2017-06-16 18:04:47 -07:00
}
}
}
2018-02-09 18:11:55 -08:00
public async Task SliceItemLoadOutput ( PrinterConfig printer , IObject3D object3D , string gcodeFilePath )
2017-10-16 17:09:00 -07:00
{
// Slice
2018-02-01 21:42:09 -08:00
bool slicingSucceeded = false ;
2018-02-20 18:27:52 -08:00
await ApplicationController . Instance . Tasks . Execute ( "Slicing" . Localize ( ) , async ( reporter , cancellationToken ) = >
2017-12-11 14:15:50 -08:00
{
2018-02-09 18:11:55 -08:00
slicingSucceeded = await Slicer . SliceItem (
2018-03-26 16:54:36 -07:00
object3D ,
gcodeFilePath ,
2017-12-11 14:15:50 -08:00
printer ,
new SliceProgressReporter ( reporter , printer ) ,
2018-01-17 08:32:40 -08:00
cancellationToken ) ;
2017-12-11 14:15:50 -08:00
} ) ;
2018-02-01 21:42:09 -08:00
// Skip loading GCode output if slicing failed
if ( ! slicingSucceeded )
{
return ;
}
2018-02-20 18:27:52 -08:00
await ApplicationController . Instance . Tasks . Execute ( "Loading GCode" . Localize ( ) , ( innerProgress , token ) = >
2017-12-11 14:15:50 -08:00
{
2018-02-20 18:27:52 -08:00
var status = new ProgressStatus ( ) ;
2017-12-11 14:15:50 -08:00
innerProgress . Report ( status ) ;
printer . Bed . LoadGCode ( gcodeFilePath , token , ( progress0to1 , statusText ) = >
{
UiThread . RunOnIdle ( ( ) = >
{
status . Progress0To1 = progress0to1 ;
status . Status = statusText ;
innerProgress . Report ( status ) ;
} ) ;
} ) ;
return Task . CompletedTask ;
} ) ;
2017-10-16 17:09:00 -07:00
}
2018-04-05 18:46:31 -07:00
internal GuiWidget GetViewOptionButtons ( BedConfig sceneContext , PrinterConfig printer , ThemeConfig theme )
2018-04-02 16:21:34 -07:00
{
var container = new FlowLayoutWidget ( ) ;
var bedButton = new RadioIconButton ( AggContext . StaticData . LoadIcon ( "bed.png" , IconColor . Theme ) , theme )
{
Name = "Bed Button" ,
ToolTipText = "Show Print Bed" . Localize ( ) ,
2018-04-05 18:46:31 -07:00
Checked = sceneContext . RendererOptions . RenderBed ,
2018-04-02 16:21:34 -07:00
Margin = theme . ButtonSpacing ,
ToggleButton = true ,
Height = 24 ,
Width = 24
} ;
bedButton . CheckedStateChanged + = ( s , e ) = >
{
2018-04-05 18:46:31 -07:00
sceneContext . RendererOptions . RenderBed = bedButton . Checked ;
2018-04-02 16:21:34 -07:00
} ;
container . AddChild ( bedButton ) ;
2018-04-04 10:11:57 -07:00
RadioIconButton printAreaButton = null ;
2018-04-09 17:43:31 -07:00
if ( sceneContext . BuildHeight > 0 )
2018-04-02 16:21:34 -07:00
{
2018-04-04 10:11:57 -07:00
printAreaButton = new RadioIconButton ( AggContext . StaticData . LoadIcon ( "print_area.png" , IconColor . Theme ) , theme )
2018-04-02 16:21:34 -07:00
{
Name = "Bed Button" ,
ToolTipText = "Show Print Area" . Localize ( ) ,
2018-04-05 18:46:31 -07:00
Checked = sceneContext . RendererOptions . RenderBuildVolume ,
2018-04-02 16:21:34 -07:00
Margin = theme . ButtonSpacing ,
ToggleButton = true ,
2018-04-09 17:43:31 -07:00
Enabled = printer ? . ViewState . ViewMode ! = PartViewMode . Layers2D ,
2018-04-02 16:21:34 -07:00
Height = 24 ,
Width = 24
} ;
printAreaButton . CheckedStateChanged + = ( s , e ) = >
{
2018-04-05 18:46:31 -07:00
sceneContext . RendererOptions . RenderBuildVolume = printAreaButton . Checked ;
2018-04-02 16:21:34 -07:00
} ;
container . AddChild ( printAreaButton ) ;
}
2018-04-06 14:38:13 -07:00
this . BindBedOptions ( container , bedButton , printAreaButton , sceneContext . RendererOptions ) ;
2018-04-04 10:11:57 -07:00
2018-04-09 17:43:31 -07:00
if ( printer ! = null )
{
// Disable print area button in GCode2D view
EventHandler < ViewModeChangedEventArgs > viewModeChanged = ( s , e ) = >
{
printAreaButton . Enabled = printer . ViewState . ViewMode ! = PartViewMode . Layers2D ;
} ;
printer . ViewState . ViewModeChanged + = viewModeChanged ;
container . Closed + = ( s , e ) = >
{
printer . ViewState . ViewModeChanged - = viewModeChanged ;
} ;
}
2018-04-02 16:21:34 -07:00
return container ;
}
2018-04-04 10:11:57 -07:00
public void BindBedOptions ( GuiWidget container , ICheckbox bedButton , ICheckbox printAreaButton , View3DConfig renderOptions )
{
PropertyChangedEventHandler syncProperties = ( s , e ) = >
{
switch ( e . PropertyName )
{
case nameof ( renderOptions . RenderBed ) :
bedButton . Checked = renderOptions . RenderBed ;
break ;
case nameof ( renderOptions . RenderBuildVolume ) when printAreaButton ! = null :
printAreaButton . Checked = renderOptions . RenderBuildVolume ;
break ;
}
} ;
2018-04-09 17:43:31 -07:00
2018-04-04 10:11:57 -07:00
renderOptions . PropertyChanged + = syncProperties ;
container . Closed + = ( s , e ) = >
{
renderOptions . PropertyChanged - = syncProperties ;
} ;
}
2017-09-16 01:11:44 -07:00
public class CloudSyncEventArgs : EventArgs
{
public bool IsAuthenticated { get ; set ; }
}
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
}
2017-09-16 01:11:44 -07:00
public class DragDropData
{
public View3DWidget View3DWidget { get ; set ; }
2017-09-23 09:19:32 -07:00
public PrinterConfig Printer { get ; internal set ; }
2017-10-05 22:32:23 -07:00
public BedConfig SceneContext { get ; set ; }
2017-09-16 01:11:44 -07:00
public void Reset ( )
{
this . View3DWidget = null ;
2017-10-05 22:32:23 -07:00
this . SceneContext = null ;
2017-09-16 01:11:44 -07:00
}
}
2017-12-11 14:15:50 -08:00
public class RunningTaskDetails : IProgress < ProgressStatus >
{
public event EventHandler < ProgressStatus > ProgressChanged ;
2017-12-12 17:53:32 -08:00
public Func < GuiWidget > DetailsItemAction { get ; set ; }
2017-12-11 22:22:56 -08:00
2017-12-11 14:15:50 -08:00
public RunningTaskDetails ( CancellationTokenSource tokenSource )
{
this . tokenSource = tokenSource ;
}
public string Title { get ; set ; }
2018-04-09 16:59:17 -07:00
2017-12-12 17:53:32 -08:00
public RunningTaskActions TaskActions { get ; internal set ; }
2017-12-11 14:15:50 -08:00
private CancellationTokenSource tokenSource ;
public void Report ( ProgressStatus progressStatus )
{
this . ProgressChanged ? . Invoke ( this , progressStatus ) ;
}
public void CancelTask ( )
{
this . tokenSource . Cancel ( ) ;
}
}
2017-12-12 17:53:32 -08:00
public class RunningTaskActions
{
public Func < GuiWidget > RichProgressWidget { get ; set ; }
public Action Pause { get ; set ; }
public Action Resume { get ; set ; }
public Action Stop { get ; set ; }
2018-04-09 16:59:17 -07:00
/// <summary>
/// Indicates if the task should suppress pause/resume/stop operations
/// </summary>
public bool ReadOnlyReporting { get ; set ; } = false ;
2017-12-12 17:53:32 -08:00
}
2017-12-11 14:15:50 -08:00
public class RunningTasksConfig
{
public event EventHandler TasksChanged ;
private ObservableCollection < RunningTaskDetails > executingTasks = new ObservableCollection < RunningTaskDetails > ( ) ;
public IEnumerable < RunningTaskDetails > RunningTasks = > executingTasks . ToList ( ) ;
public RunningTasksConfig ( )
{
executingTasks . CollectionChanged + = ( s , e ) = >
{
this . TasksChanged ? . Invoke ( this , null ) ;
} ;
}
2018-02-20 18:27:52 -08:00
public Task Execute ( string taskTitle , Func < IProgress < ProgressStatus > , CancellationToken , Task > func , RunningTaskActions taskActions = null )
2017-12-11 14:15:50 -08:00
{
var tokenSource = new CancellationTokenSource ( ) ;
2017-12-11 22:22:56 -08:00
var taskDetails = new RunningTaskDetails ( tokenSource )
{
2017-12-12 17:53:32 -08:00
TaskActions = taskActions ,
2018-02-20 18:27:52 -08:00
Title = taskTitle
2017-12-11 22:22:56 -08:00
} ;
2017-12-11 14:15:50 -08:00
executingTasks . Add ( taskDetails ) ;
return Task . Run ( async ( ) = >
{
2017-12-12 18:18:39 -08:00
try
{
await func ? . Invoke ( taskDetails , tokenSource . Token ) ;
}
catch
{
}
2017-12-11 14:15:50 -08:00
executingTasks . Remove ( taskDetails ) ;
} ) ;
}
}
2017-12-16 13:56:59 -08:00
2017-12-18 17:22:50 -08:00
public enum ReportSeverity2 { Warning , Error }
2017-12-16 13:56:59 -08:00
public interface INativePlatformFeatures
{
event EventHandler PictureTaken ;
void TakePhoto ( string imageFileName ) ;
void OpenCameraPreview ( ) ;
void PlaySound ( string fileName ) ;
void ConfigureWifi ( ) ;
bool CameraInUseByExternalProcess { get ; set ; }
bool IsNetworkConnected ( ) ;
2017-12-18 13:17:31 -08:00
void FindAndInstantiatePlugins ( SystemWindow systemWindow ) ;
2017-12-18 17:22:50 -08:00
void ProcessCommandline ( ) ;
void PlatformInit ( Action < string > reporter ) ;
2017-12-16 13:56:59 -08:00
}
2017-12-18 17:22:50 -08:00
public static class Application
2017-12-16 13:56:59 -08:00
{
2017-12-18 17:22:50 -08:00
private static ProgressBar progressBar ;
private static TextWidget statusText ;
private static FlowLayoutWidget progressPanel ;
private static string lastSection = "" ;
private static Stopwatch timer ;
2017-12-16 13:56:59 -08:00
2017-12-18 17:22:50 -08:00
public static string PlatformFeaturesProvider { get ; set ; } = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl" ;
2017-12-20 18:25:12 -08:00
2017-12-18 17:22:50 -08:00
public static SystemWindow LoadRootWindow ( int width , int height )
2017-12-16 13:56:59 -08:00
{
2017-12-18 17:22:50 -08:00
timer = Stopwatch . StartNew ( ) ;
2017-12-16 13:56:59 -08:00
2018-02-21 15:23:54 -08:00
var systemWindow = new RootSystemWindow ( width , height ) ;
2017-12-18 17:22:50 -08:00
2018-02-26 17:48:15 -08:00
var overlay = new GuiWidget ( )
{
BackgroundColor = Color . DarkGray
} ;
2017-12-18 17:22:50 -08:00
overlay . AnchorAll ( ) ;
systemWindow . AddChild ( overlay ) ;
2018-03-11 17:46:59 -07:00
var spinner = new LogoSpinner ( overlay , rotateX : - 0.05 ) ;
2018-02-21 15:23:54 -08:00
2017-12-18 17:22:50 -08:00
progressPanel = new FlowLayoutWidget ( FlowDirection . TopToBottom )
2017-12-16 13:56:59 -08:00
{
2018-02-21 15:23:54 -08:00
Position = new Vector2 ( 0 , height * . 25 ) ,
HAnchor = HAnchor . Center | HAnchor . Fit ,
VAnchor = VAnchor . Fit ,
2018-03-08 17:23:03 -08:00
MinimumSize = new Vector2 ( 400 , 100 ) ,
2018-02-21 15:23:54 -08:00
Margin = new BorderDouble ( 0 , 0 , 0 , 200 )
2017-12-18 17:22:50 -08:00
} ;
overlay . AddChild ( progressPanel ) ;
2017-12-16 13:56:59 -08:00
2018-02-21 15:23:54 -08:00
progressPanel . AddChild ( statusText = new TextWidget ( "" , textColor : new Color ( "#9ad5dd" ) )
2017-12-18 17:22:50 -08:00
{
2018-02-27 08:46:54 -08:00
MinimumSize = new Vector2 ( 200 , 30 ) ,
2018-02-21 15:23:54 -08:00
HAnchor = HAnchor . Center ,
AutoExpandBoundsToText = true
2017-12-18 17:22:50 -08:00
} ) ;
progressPanel . AddChild ( progressBar = new ProgressBar ( )
{
2018-02-21 15:23:54 -08:00
FillColor = new Color ( "#049eb6" ) ,
BorderColor = new Color ( "#006f83" ) ,
2017-12-18 17:22:50 -08:00
Height = 11 ,
2018-02-27 08:46:54 -08:00
Width = 230 ,
2018-02-21 15:23:54 -08:00
HAnchor = HAnchor . Center ,
2017-12-18 17:22:50 -08:00
VAnchor = VAnchor . Absolute
} ) ;
AppContext . RootSystemWindow = systemWindow ;
// Hook SystemWindow load and spin up MatterControl once we've hit first draw
systemWindow . Load + = ( s , e ) = >
2017-12-16 13:56:59 -08:00
{
2017-12-18 17:22:50 -08:00
ReportStartupProgress ( 0.02 , "First draw->RunOnIdle" ) ;
//UiThread.RunOnIdle(() =>
2017-12-20 18:25:12 -08:00
Task . Run ( async ( ) = >
2017-12-16 13:56:59 -08:00
{
2018-03-28 18:05:06 -07:00
try
2017-12-18 17:22:50 -08:00
{
2018-03-28 18:05:06 -07:00
ReportStartupProgress ( 0.15 , "MatterControlApplication.Initialize" ) ;
var mainView = await Initialize ( systemWindow , ( progress0To1 , status ) = >
{
ReportStartupProgress ( 0.2 + progress0To1 * 0.7 , status ) ;
} ) ;
TranslationMap . ActiveTranslationMap = new TranslationMap ( "Translations" , UserSettings . Instance . Language ) ;
ReportStartupProgress ( 0.9 , "AddChild->MainView" ) ;
systemWindow . AddChild ( mainView , 0 ) ;
ReportStartupProgress ( 1 , "" ) ;
systemWindow . BackgroundColor = Color . Transparent ;
overlay . Close ( ) ;
}
catch ( Exception ex )
{
UiThread . RunOnIdle ( ( ) = >
{
var theme = ApplicationController . Instance . Theme ;
statusText . Visible = false ;
2017-12-18 17:22:50 -08:00
2018-03-28 18:05:06 -07:00
var errorTextColor = Color . White ;
2018-03-21 17:17:36 -07:00
2018-03-28 18:05:06 -07:00
progressPanel . Margin = 0 ;
progressPanel . VAnchor = VAnchor . Center | VAnchor . Fit ;
progressPanel . BackgroundColor = Color . DarkGray ;
progressPanel . Padding = 20 ;
progressPanel . Border = 1 ;
progressPanel . BorderColor = Color . Red ;
2017-12-18 17:22:50 -08:00
2018-03-28 18:05:06 -07:00
progressPanel . AddChild (
new TextWidget ( "Startup Failure" . Localize ( ) + ":" , pointSize : theme . DefaultFontSize , textColor : errorTextColor ) ) ;
progressPanel . AddChild (
new TextWidget ( ex . Message , pointSize : theme . FontSize9 , textColor : errorTextColor ) ) ;
var closeButton = new TextButton ( "Close" , theme , Color . White )
{
BackgroundColor = theme . SlightShade ,
HAnchor = HAnchor . Right ,
VAnchor = VAnchor . Absolute
} ;
closeButton . Click + = ( s1 , e1 ) = >
{
systemWindow . Close ( ) ;
} ;
spinner . SpinLogo = false ;
progressBar . Visible = false ;
progressPanel . AddChild ( closeButton ) ;
} ) ;
}
2017-12-18 17:22:50 -08:00
2017-12-27 05:42:28 -08:00
AppContext . IsLoading = false ;
2017-12-18 17:22:50 -08:00
} ) ;
} ;
// Block indefinitely
ReportStartupProgress ( 0 , "ShowAsSystemWindow" ) ;
return systemWindow ;
2017-12-16 13:56:59 -08:00
}
2017-12-20 18:25:12 -08:00
public static async Task < GuiWidget > Initialize ( SystemWindow systemWindow , Action < double , string > reporter )
2017-12-16 13:56:59 -08:00
{
2017-12-18 17:22:50 -08:00
AppContext . Platform = AggContext . CreateInstanceFrom < INativePlatformFeatures > ( PlatformFeaturesProvider ) ;
reporter ? . Invoke ( 0.01 , "PlatformInit" ) ;
AppContext . Platform . PlatformInit ( ( status ) = >
{
reporter ? . Invoke ( 0.01 , status ) ;
} ) ;
// TODO: Appears to be unused and should be removed
// set this at startup so that we can tell next time if it got set to true in close
UserSettings . Instance . Fields . StartCount = UserSettings . Instance . Fields . StartCount + 1 ;
reporter ? . Invoke ( 0.05 , "ApplicationController" ) ;
var na = ApplicationController . Instance ;
// Set the default theme colors
reporter ? . Invoke ( 0.1 , "LoadOemOrDefaultTheme" ) ;
ApplicationController . LoadOemOrDefaultTheme ( ) ;
// Accessing any property on ProfileManager will run the static constructor and spin up the ProfileManager instance
reporter ? . Invoke ( 0.2 , "ProfileManager" ) ;
bool na2 = ProfileManager . Instance . IsGuestProfile ;
2017-12-20 18:25:12 -08:00
await ProfileManager . Instance . Initialize ( ) ;
2017-12-18 17:22:50 -08:00
reporter ? . Invoke ( 0.3 , "MainView" ) ;
ApplicationController . Instance . MainView = new WidescreenPanel ( ) ;
// now that we are all set up lets load our plugins and allow them their chance to set things up
reporter ? . Invoke ( 0.8 , "Plugins" ) ;
AppContext . Platform . FindAndInstantiatePlugins ( systemWindow ) ;
reporter ? . Invoke ( 0.9 , "Process Commandline" ) ;
AppContext . Platform . ProcessCommandline ( ) ;
reporter ? . Invoke ( 0.91 , "OnLoadActions" ) ;
ApplicationController . Instance . OnLoadActions ( ) ;
2018-03-20 18:25:40 -07:00
UiThread . SetInterval ( ( ) = >
{
ApplicationController . Instance . ActivePrinter . Connection . OnIdle ( ) ;
2018-04-11 17:35:34 -07:00
} , . 1 ) ;
2017-12-18 17:22:50 -08:00
return ApplicationController . Instance . MainView ;
2017-12-16 13:56:59 -08:00
}
2017-12-18 17:22:50 -08:00
private static void ReportStartupProgress ( double progress0To1 , string section )
2017-12-16 13:56:59 -08:00
{
2017-12-18 18:36:41 -08:00
UiThread . RunOnIdle ( ( ) = >
{
statusText . Text = section ;
progressBar . RatioComplete = progress0To1 ;
progressPanel . Invalidate ( ) ;
2017-12-18 17:22:50 -08:00
2017-12-18 18:36:41 -08:00
Console . WriteLine ( $"Time to '{lastSection}': {timer.ElapsedMilliseconds}" ) ;
timer . Restart ( ) ;
2017-12-18 17:22:50 -08:00
2017-12-18 18:36:41 -08:00
lastSection = section ;
} ) ;
2017-12-16 13:56:59 -08: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
}