2014-01-29 19:09:30 -08:00
/ *
2016-07-21 13:49:22 -07:00
Copyright ( c ) 2016 , Lars Brubaker , Kevin Pope
2014-01-29 19:09:30 -08:00
All rights reserved .
Redistribution and use in source and binary forms , with or without
2015-04-08 15:20:10 -07:00
modification , are permitted provided that the following conditions are met :
2014-01-29 19:09:30 -08:00
1. Redistributions of source code must retain the above copyright notice , this
2015-04-08 15:20:10 -07:00
list of conditions and the following disclaimer .
2014-01-29 19:09:30 -08:00
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
2015-04-08 15:20:10 -07:00
and / or other materials provided with the distribution .
2014-01-29 19:09:30 -08:00
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
2015-04-08 15:20:10 -07:00
of the authors and should not be interpreted as representing official policies ,
2014-01-29 19:09:30 -08:00
either expressed or implied , of the FreeBSD Project .
* /
2016-09-23 16:34:52 -07:00
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Globalization ;
using System.IO ;
2017-03-15 16:17:06 -07:00
using System.Linq ;
2016-09-23 16:34:52 -07:00
using System.Threading ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg ;
2017-08-20 02:34:39 -07:00
using MatterHackers.Agg.Platform ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg.UI ;
2017-03-15 16:17:06 -07:00
using MatterHackers.DataConverters3D ;
2014-01-29 19:09:30 -08:00
using MatterHackers.MatterControl.DataStorage ;
2014-03-16 10:23:56 -07:00
using MatterHackers.MatterControl.PluginSystem ;
2017-12-16 20:06:03 -08:00
using MatterHackers.MatterControl.PrinterControls.PrinterConnections ;
2014-03-16 10:23:56 -07:00
using MatterHackers.MatterControl.PrintQueue ;
2014-06-11 14:52:58 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2015-04-08 17:47:17 -07:00
using MatterHackers.RenderOpenGl.OpenGl ;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl
{
2017-12-16 20:06:03 -08:00
public static class MatterControlApplication
2015-04-08 15:20:10 -07:00
{
2016-08-26 18:30:21 -07:00
#if DEBUG
2017-01-23 16:56:41 -08:00
2016-08-26 18:30:21 -07:00
//public static string MCWSBaseUri { get; } = "http://192.168.2.129:9206";
public static string MCWSBaseUri { get ; } = "https://mattercontrol-test.appspot.com" ;
#else
public static string MCWSBaseUri { get ; } = "https://mattercontrol.appspot.com" ;
#endif
2017-12-17 00:17:21 -08:00
public static GuiWidget Initialize ( SystemWindow systemWindow , Action < double , string > reporter )
2015-01-13 10:56:20 -08:00
{
2017-08-20 02:34:39 -07:00
if ( AggContext . OperatingSystem = = OSType . Mac & & AggContext . StaticData = = null )
2015-09-14 10:26:12 -07:00
{
// Set working directory - this duplicates functionality in Main but is necessary on OSX as Main fires much later (after the constructor in this case)
2015-12-23 16:23:19 -08:00
// resulting in invalid paths due to path tests running before the working directory has been overridden. Setting the value before initializing StaticData
2015-09-14 10:26:12 -07:00
// works around this architectural difference.
Directory . SetCurrentDirectory ( Path . GetDirectoryName ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) ) ;
}
2015-04-08 15:20:10 -07:00
// Initialize a standard file system backed StaticData provider
2017-08-20 02:34:39 -07:00
if ( AggContext . StaticData = = null ) // it may already be initialized by tests
2015-08-23 17:21:47 -07:00
{
2017-12-17 00:17:21 -08:00
reporter ? . Invoke ( 0.01 , "StaticData" ) ;
2017-08-20 02:34:39 -07:00
AggContext . StaticData = new MatterHackers . Agg . FileSystemStaticData ( ) ;
2015-08-23 17:21:47 -07:00
}
2015-01-13 10:56:20 -08:00
2016-12-02 10:52:33 -08:00
2017-12-16 19:25:46 -08:00
ApplicationSettings . Instance . set ( "HardwareHasCamera" , "false" ) ;
2016-12-02 10:52:33 -08:00
2017-12-16 20:06:03 -08:00
// TODO: Appears to be unused and should be removed
2016-12-02 10:52:33 -08:00
// 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 ;
2017-12-16 20:06:03 -08:00
var commandLineArgs = Environment . GetCommandLineArgs ( ) ;
2016-12-02 10:52:33 -08:00
Thread . CurrentThread . CurrentCulture = CultureInfo . InvariantCulture ;
2015-04-08 15:20:10 -07:00
for ( int currentCommandIndex = 0 ; currentCommandIndex < commandLineArgs . Length ; currentCommandIndex + + )
{
string command = commandLineArgs [ currentCommandIndex ] ;
2015-01-23 10:22:02 -08:00
string commandUpper = command . ToUpper ( ) ;
2015-04-08 15:20:10 -07:00
switch ( commandUpper )
{
2015-04-08 17:47:17 -07:00
case "FORCE_SOFTWARE_RENDERING" :
2016-12-02 16:49:18 -08:00
GL . HardwareAvailable = false ;
2015-04-08 17:47:17 -07:00
break ;
2015-04-08 15:20:10 -07:00
case "CLEAR_CACHE" :
2016-04-25 13:55:40 -07:00
AboutWidget . DeleteCacheData ( 0 ) ;
2015-04-08 15:20:10 -07:00
break ;
case "SHOW_MEMORY" :
2017-12-16 19:25:46 -08:00
DesktopRootSystemWindow . ShowMemoryUsed = true ;
2015-04-08 15:20:10 -07:00
break ;
}
}
2017-12-17 00:17:21 -08:00
reporter ? . Invoke ( 0.05 , "ApplicationController" ) ;
2017-12-16 20:06:03 -08:00
var na = ApplicationController . Instance ;
2014-01-29 19:09:30 -08:00
2017-12-16 20:06:03 -08:00
// Set the default theme colors
2017-12-17 00:17:21 -08:00
reporter ? . Invoke ( 0.1 , "LoadOemOrDefaultTheme" ) ;
2017-12-16 20:06:03 -08:00
ApplicationController . LoadOemOrDefaultTheme ( ) ;
2014-01-29 19:09:30 -08:00
2017-12-16 20:06:03 -08:00
// Accessing any property on ProfileManager will run the static constructor and spin up the ProfileManager instance
2017-12-17 00:17:21 -08:00
reporter ? . Invoke ( 0.2 , "ProfileManager" ) ;
2017-12-16 20:06:03 -08:00
bool na2 = ProfileManager . Instance . IsGuestProfile ;
2016-07-24 17:26:24 -07:00
2017-12-17 00:17:21 -08:00
reporter ? . Invoke ( 0.3 , "MainView" ) ;
ApplicationController . Instance . MainView = new WidescreenPanel ( ) ;
2016-12-01 22:03:15 -08:00
// now that we are all set up lets load our plugins and allow them their chance to set things up
2017-12-17 00:17:21 -08:00
reporter ? . Invoke ( 0.8 , "Plugins" ) ;
2017-12-18 13:17:31 -08:00
AppContext . Platform . FindAndInstantiatePlugins ( systemWindow ) ;
2016-12-01 22:03:15 -08:00
if ( ApplicationController . Instance . PluginsLoaded ! = null )
{
ApplicationController . Instance . PluginsLoaded . CallEvents ( null , null ) ;
}
2017-12-16 20:06:03 -08:00
// TODO: Do we still want to support command line arguments for adding to the queue?
2016-07-24 17:26:24 -07:00
foreach ( string arg in commandLineArgs )
2015-04-08 15:20:10 -07:00
{
2016-07-24 17:26:24 -07:00
string argExtension = Path . GetExtension ( arg ) . ToUpper ( ) ;
if ( argExtension . Length > 1
& & MeshFileIo . ValidFileExtensions ( ) . Contains ( argExtension ) )
2015-04-08 15:20:10 -07:00
{
2016-07-24 17:26:24 -07:00
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( Path . GetFileName ( arg ) , Path . GetFullPath ( arg ) ) ) ) ;
2015-04-08 15:20:10 -07:00
}
2016-07-24 17:26:24 -07:00
}
2015-04-08 15:20:10 -07:00
2017-12-17 00:17:21 -08:00
reporter ? . Invoke ( 0.9 , "AfterLoad" ) ;
2017-12-16 20:06:03 -08:00
AfterLoad ( ) ;
return ApplicationController . Instance . MainView ;
}
public static void AfterLoad ( )
{
// ApplicationController.Instance.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
2017-12-17 00:17:21 -08:00
/////////////////////ApplicationController.Instance.UserChanged();
2017-12-16 20:06:03 -08:00
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 ( ) ;
} ) ;
}
}
2017-12-18 12:54:48 -08:00
// TODO: This should be moved into the splash screen and shown instead of MainView
2017-12-16 20:06:03 -08:00
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 ) ;
}
// ApplicationController.Instance.OnLoadActions }}
2016-07-13 17:20:31 -07:00
2016-09-12 21:55:40 -07:00
//HtmlWindowTest();
2017-12-18 12:54:48 -08:00
UiThread . RunOnIdle ( CheckOnPrinter ) ;
2017-12-18 12:51:03 -08:00
ApplicationController . Instance . IsLoading = false ;
2017-12-16 20:06:03 -08:00
}
2017-03-15 16:17:06 -07:00
2017-12-16 20:06:03 -08:00
private static void RunSetupIfRequired ( )
{
if ( ! ProfileManager . Instance . ActiveProfiles . Any ( ) )
{
// Start the setup wizard if no profiles exist
UiThread . RunOnIdle ( ( ) = > DialogWindow . Show ( PrinterSetup . GetBestStartPage ( ) ) ) ;
}
2016-09-12 21:55:40 -07:00
}
2017-12-16 20:06:03 -08:00
private static void CheckOnPrinter ( )
2015-04-08 15:20:10 -07:00
{
2015-03-25 18:01:57 -07:00
try
{
2017-12-16 20:06:03 -08:00
// TODO: UiThread should not be driving anything in Printer.Connection
2017-09-17 21:08:16 -07:00
ApplicationController . Instance . ActivePrinter . Connection . OnIdle ( ) ;
2015-03-25 18:01:57 -07:00
}
2015-04-08 15:20:10 -07:00
catch ( Exception e )
2015-03-25 18:01:57 -07:00
{
Debug . Print ( e . Message ) ;
2015-09-17 13:45:26 -07:00
GuiWidget . BreakInDebugger ( ) ;
2015-03-25 18:01:57 -07:00
#if DEBUG
throw e ;
#endif
}
2015-04-08 15:20:10 -07:00
UiThread . RunOnIdle ( CheckOnPrinter ) ;
}
2014-01-29 19:09:30 -08:00
2015-05-05 07:25:47 -07:00
private static void AssertDebugNotDefined ( )
{
#if DEBUG
throw new Exception ( "DEBUG is defined and should not be!" ) ;
#endif
}
public static void CheckKnownAssemblyConditionalCompSymbols ( )
{
MatterControlApplication . AssertDebugNotDefined ( ) ;
MatterHackers . GCodeVisualizer . GCodeFile . AssertDebugNotDefined ( ) ;
MatterHackers . Agg . Graphics2D . AssertDebugNotDefined ( ) ;
MatterHackers . Agg . UI . SystemWindow . AssertDebugNotDefined ( ) ;
MatterHackers . Agg . ImageProcessing . InvertLightness . AssertDebugNotDefined ( ) ;
MatterHackers . Localizations . TranslationMap . AssertDebugNotDefined ( ) ;
MatterHackers . MarchingSquares . MarchingSquaresByte . AssertDebugNotDefined ( ) ;
MatterHackers . MatterControl . PluginSystem . MatterControlPlugin . AssertDebugNotDefined ( ) ;
MatterHackers . MatterSlice . MatterSlice . AssertDebugNotDefined ( ) ;
MatterHackers . MeshVisualizer . MeshViewerWidget . AssertDebugNotDefined ( ) ;
MatterHackers . RenderOpenGl . GLMeshTrianglePlugin . AssertDebugNotDefined ( ) ;
}
2015-02-19 10:56:54 -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
}