2014-01-29 19:09:30 -08:00
/ *
2015-01-28 16:07:40 -08:00
Copyright ( c ) 2014 , 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 .
* /
using MatterHackers.Agg ;
2015-04-08 15:20:10 -07:00
using MatterHackers.Agg.PlatformAbstract ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg.UI ;
2014-06-11 14:52:58 -07:00
using MatterHackers.Localizations ;
2014-01-29 19:09:30 -08:00
using MatterHackers.MatterControl.DataStorage ;
2014-03-16 10:23:56 -07:00
using MatterHackers.MatterControl.PluginSystem ;
2014-06-11 14:52:58 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
2014-03-16 10:23:56 -07:00
using MatterHackers.MatterControl.PrintQueue ;
2014-05-06 18:25:16 -07:00
using MatterHackers.MatterControl.SettingsManagement ;
2014-06-11 14:52:58 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2014-10-12 08:18:24 -07:00
using MatterHackers.PolygonMesh.Processors ;
2015-04-08 17:47:17 -07:00
using MatterHackers.RenderOpenGl.OpenGl ;
2015-04-08 15:20:10 -07:00
using MatterHackers.VectorMath ;
2015-05-20 13:37:08 -07:00
using Mindscape.Raygun4Net ;
2015-04-08 15:20:10 -07:00
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Globalization ;
using System.IO ;
using System.Text.RegularExpressions ;
using System.Threading ;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl
{
2015-04-08 15:20:10 -07:00
public class MatterControlApplication : SystemWindow
{
public bool RestartOnClose = false ;
private static readonly Vector2 minSize = new Vector2 ( 600 , 600 ) ;
private static MatterControlApplication instance ;
private string [ ] commandLineArgs = null ;
private string confirmExit = "Confirm Exit" . Localize ( ) ;
private bool DoCGCollectEveryDraw = false ;
private int drawCount = 0 ;
private bool firstDraw = true ;
private AverageMillisecondTimer millisecondTimer = new AverageMillisecondTimer ( ) ;
private Gaming . Game . DataViewGraph msGraph = new Gaming . Game . DataViewGraph ( new Vector2 ( 20 , 500 ) , 50 , 50 , 0 , 200 ) ;
private string savePartsSheetExitAnywayMessage = "You are currently saving a parts sheet, are you sure you want to exit?" . Localize ( ) ;
private bool ShowMemoryUsed = false ;
private Stopwatch totalDrawTime = new Stopwatch ( ) ;
private string unableToExitMessage = "Oops! You cannot exit while a print is active." . Localize ( ) ;
private string unableToExitTitle = "Unable to Exit" . Localize ( ) ;
2015-05-28 11:52:29 -07:00
#if ! DEBUG
2015-05-20 13:37:08 -07:00
private static RaygunClient _raygunClient = new RaygunClient ( "hQIlyUUZRGPyXVXbI6l1dA==" ) ;
2015-05-28 11:52:29 -07:00
#endif
2015-05-20 13:37:08 -07:00
2015-04-08 15:20:10 -07:00
static MatterControlApplication ( )
2015-01-13 10:56:20 -08:00
{
2015-04-08 15:20:10 -07:00
// Because fields on this class call localization methods and because those methods depend on the StaticData provider and because the field
// initializers run before the class constructor, we need to init the platform specific provider in the static constructor (or write a custom initializer method)
//
// Initialize a standard file system backed StaticData provider
StaticData . Instance = new MatterHackers . Agg . FileSystemStaticData ( ) ;
2015-01-13 10:56:20 -08:00
}
2015-04-08 15:20:10 -07:00
private MatterControlApplication ( double width , double height , out bool showWindow )
: base ( width , height )
2015-01-22 12:27:18 -08:00
{
2015-04-03 15:31:20 -07:00
Name = "MatterControl" ;
2015-01-23 10:22:02 -08:00
showWindow = false ;
2014-06-24 12:32:12 -07:00
2015-04-08 15:20:10 -07: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 ;
this . commandLineArgs = Environment . GetCommandLineArgs ( ) ;
Thread . CurrentThread . CurrentCulture = CultureInfo . InvariantCulture ;
2014-01-29 19:09:30 -08:00
2015-04-08 17:47:17 -07:00
bool forceSofwareRendering = false ;
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-05-06 10:29:32 -07:00
case "TEST" :
CheckKnownAssemblyConditionalCompSymbols ( ) ;
return ;
2015-04-08 17:47:17 -07:00
case "FORCE_SOFTWARE_RENDERING" :
forceSofwareRendering = true ;
GL . ForceSoftwareRendering ( ) ;
break ;
2015-01-15 14:17:26 -08:00
case "MHSERIAL_TO_ANDROID" :
{
Dictionary < string , string > vidPid_NameDictionary = new Dictionary < string , string > ( ) ;
string [ ] MHSerialLines = File . ReadAllLines ( Path . Combine ( ".." , ".." , "StaticData" , "Drivers" , "MHSerial" , "MHSerial.inf" ) ) ;
foreach ( string line in MHSerialLines )
{
if ( line . Contains ( "=DriverInstall," ) )
{
string name = Regex . Match ( line , "%(.*).name" ) . Groups [ 1 ] . Value ;
string vid = Regex . Match ( line , "VID_(.*)&PID" ) . Groups [ 1 ] . Value ;
string pid = Regex . Match ( line , "PID_([0-9a-fA-F]+)" ) . Groups [ 1 ] . Value ;
string vidPid = "{0},{1}" . FormatWith ( vid , pid ) ;
if ( ! vidPid_NameDictionary . ContainsKey ( vidPid ) )
{
vidPid_NameDictionary . Add ( vidPid , name ) ;
}
}
}
using ( StreamWriter deviceFilter = new StreamWriter ( "deviceFilter.txt" ) )
{
using ( StreamWriter serialPort = new StreamWriter ( "serialPort.txt" ) )
{
foreach ( KeyValuePair < string , string > vidPid_Name in vidPid_NameDictionary )
{
string [ ] vidPid = vidPid_Name . Key . Split ( ',' ) ;
int vid = Int32 . Parse ( vidPid [ 0 ] , System . Globalization . NumberStyles . HexNumber ) ;
int pid = Int32 . Parse ( vidPid [ 1 ] , System . Globalization . NumberStyles . HexNumber ) ;
serialPort . WriteLine ( "customTable.AddProduct(0x{0:X4}, 0x{1:X4}, cdcDriverType); // {2}" . FormatWith ( vid , pid , vidPid_Name . Value ) ) ;
deviceFilter . WriteLine ( "<!-- {2} -->\n<usb-device vendor-id=\"{0}\" product-id=\"{1}\" />" . FormatWith ( vid , pid , vidPid_Name . Value ) ) ;
}
}
}
}
return ;
2015-04-08 15:20:10 -07:00
case "CLEAR_CACHE" :
2015-04-11 14:29:35 -07:00
AboutWidget . DeleteCacheData ( ) ;
2015-04-08 15:20:10 -07:00
break ;
case "SHOW_MEMORY" :
ShowMemoryUsed = true ;
break ;
case "DO_GC_COLLECT_EVERY_DRAW" :
ShowMemoryUsed = true ;
DoCGCollectEveryDraw = true ;
break ;
case "CREATE_AND_SELECT_PRINTER" :
if ( currentCommandIndex + 1 < = commandLineArgs . Length )
{
currentCommandIndex + + ;
string argument = commandLineArgs [ currentCommandIndex ] ;
string [ ] printerData = argument . Split ( ',' ) ;
if ( printerData . Length > = 2 )
{
Printer ActivePrinter = new Printer ( ) ;
ActivePrinter . Name = "Auto: {0} {1}" . FormatWith ( printerData [ 0 ] , printerData [ 1 ] ) ;
ActivePrinter . Make = printerData [ 0 ] ;
ActivePrinter . Model = printerData [ 1 ] ;
2014-12-31 11:37:08 -08:00
2015-03-27 14:13:11 -07:00
if ( printerData . Length = = 3 )
{
ActivePrinter . ComPort = printerData [ 2 ] ;
}
2015-04-08 15:20:10 -07:00
PrinterSetupStatus test = new PrinterSetupStatus ( ActivePrinter ) ;
test . LoadDefaultSliceSettings ( ActivePrinter . Make , ActivePrinter . Model ) ;
ActivePrinterProfile . Instance . ActivePrinter = ActivePrinter ;
}
}
break ;
case "CONNECT_TO_PRINTER" :
if ( currentCommandIndex + 1 < = commandLineArgs . Length )
{
PrinterConnectionAndCommunication . Instance . ConnectToActivePrinter ( ) ;
}
break ;
case "START_PRINT" :
if ( currentCommandIndex + 1 < = commandLineArgs . Length )
{
bool hasBeenRun = false ;
currentCommandIndex + + ;
string fullPath = commandLineArgs [ currentCommandIndex ] ;
QueueData . Instance . RemoveAll ( ) ;
if ( ! string . IsNullOrEmpty ( fullPath ) )
{
string fileName = Path . GetFileNameWithoutExtension ( fullPath ) ;
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( fileName , fullPath ) ) ) ;
PrinterConnectionAndCommunication . Instance . CommunicationStateChanged . RegisterEvent ( ( sender , e ) = >
{
if ( ! hasBeenRun & & PrinterConnectionAndCommunication . Instance . CommunicationState = = PrinterConnectionAndCommunication . CommunicationStates . Connected )
{
hasBeenRun = true ;
PrinterConnectionAndCommunication . Instance . PrintActivePartIfPossible ( ) ;
}
} , ref unregisterEvent ) ;
}
}
break ;
2015-04-14 17:15:58 -07:00
2015-05-28 11:52:29 -07:00
case "SLICE_AND_EXPORT_GCODE" :
if ( currentCommandIndex + 1 < = commandLineArgs . Length )
{
currentCommandIndex + + ;
string fullPath = commandLineArgs [ currentCommandIndex ] ;
QueueData . Instance . RemoveAll ( ) ;
if ( ! string . IsNullOrEmpty ( fullPath ) )
{
string fileName = Path . GetFileNameWithoutExtension ( fullPath ) ;
PrintItemWrapper printItemWrapper = new PrintItemWrapper ( new PrintItem ( fileName , fullPath ) ) ;
QueueData . Instance . AddItem ( printItemWrapper ) ;
2015-04-14 17:15:58 -07:00
2015-05-28 11:52:29 -07:00
SlicingQueue . Instance . QueuePartForSlicing ( printItemWrapper ) ;
ExportPrintItemWindow exportForTest = new ExportPrintItemWindow ( printItemWrapper ) ;
exportForTest . ExportGcodeCommandLineUtility ( fileName ) ;
}
}
break ;
2015-04-08 15:20:10 -07:00
}
if ( MeshFileIo . ValidFileExtensions ( ) . Contains ( Path . GetExtension ( command ) . ToUpper ( ) ) )
{
// If we are the only instance running then do nothing.
// Else send these to the running instance so it can load them.
}
}
//WriteTestGCodeFile();
2014-03-02 15:28:47 -08:00
#if ! DEBUG
2015-04-08 15:20:10 -07:00
if ( File . Exists ( "RunUnitTests.txt" ) )
2014-03-02 15:28:47 -08:00
#endif
2015-04-08 15:20:10 -07:00
{
2014-07-28 13:48:28 -07:00
#if IS_WINDOWS_FORMS
2015-04-08 15:20:10 -07:00
if ( ! Clipboard . IsInitialized )
{
Clipboard . SetSystemClipboard ( new WindowsFormsClipboard ( ) ) ;
}
2014-07-28 13:48:28 -07:00
#endif
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
// you can turn this on to debug some bounds issues
//GuiWidget.DebugBoundsUnderMouse = true;
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
GuiWidget . DefaultEnforceIntegerBounds = true ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
if ( ActiveTheme . Instance . DisplayMode = = ActiveTheme . ApplicationDisplayType . Touchscreen )
{
TextWidget . GlobalPointSizeScaleRatio = 1.3 ;
}
2014-08-30 16:03:28 -07:00
2015-01-14 11:51:53 -08:00
this . AddChild ( ApplicationController . Instance . MainView ) ;
2015-04-08 15:20:10 -07:00
this . MinimumSize = minSize ;
this . Padding = new BorderDouble ( 0 ) ; //To be re-enabled once native borders are turned off
2014-01-29 19:09:30 -08:00
#if false // this is to test freeing gcodefile memory
2015-04-08 15:20:10 -07:00
Button test = new Button ( "test" ) ;
test . Click + = ( sender , e ) = >
{
//MatterHackers.GCodeVisualizer.GCodeFile gcode = new GCodeVisualizer.GCodeFile();
//gcode.Load(@"C:\Users\lbrubaker\Downloads\drive assy.gcode");
SystemWindow window = new SystemWindow ( 100 , 100 ) ;
window . ShowAsSystemWindow ( ) ;
} ;
allControls . AddChild ( test ) ;
2014-01-29 19:09:30 -08:00
#endif
2015-04-08 15:20:10 -07:00
this . AnchorAll ( ) ;
2014-01-29 19:09:30 -08:00
2015-04-08 17:47:17 -07:00
if ( ! forceSofwareRendering )
{
UseOpenGL = true ;
}
2015-04-08 15:20:10 -07:00
string version = "1.2" ;
2014-05-22 16:55:28 -07:00
2015-04-08 15:20:10 -07:00
Title = "MatterControl {0}" . FormatWith ( version ) ;
if ( OemSettings . Instance . WindowTitleExtra ! = null & & OemSettings . Instance . WindowTitleExtra . Trim ( ) . Length > 0 )
{
Title = Title + " - {1}" . FormatWith ( version , OemSettings . Instance . WindowTitleExtra ) ;
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
UiThread . RunOnIdle ( CheckOnPrinter ) ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
string desktopPosition = ApplicationSettings . Instance . get ( "DesktopPosition" ) ;
if ( desktopPosition ! = null & & desktopPosition ! = "" )
{
string [ ] sizes = desktopPosition . Split ( ',' ) ;
2014-04-12 11:54:05 -07:00
2015-04-08 15:20:10 -07:00
//If the desktop position is less than -10,-10, override
int xpos = Math . Max ( int . Parse ( sizes [ 0 ] ) , - 10 ) ;
int ypos = Math . Max ( int . Parse ( sizes [ 1 ] ) , - 10 ) ;
DesktopPosition = new Point2D ( xpos , ypos ) ;
}
2015-01-23 10:22:02 -08:00
showWindow = true ;
2015-04-08 15:20:10 -07:00
}
2014-01-29 19:09:30 -08:00
2015-04-15 10:08:36 -07:00
public enum ReportSeverity2 { Warning , Error }
2015-05-28 11:03:45 -07:00
public void ReportException ( Exception e , string key = "" , string value = "" , ReportSeverity2 warningLevel = ReportSeverity2 . Warning )
2015-04-15 10:08:36 -07:00
{
2015-05-28 11:52:29 -07:00
// Conditionally spin up error reporting if not on the Stable channel
string channel = UserSettings . Instance . get ( "UpdateFeedType" ) ;
if ( string . IsNullOrEmpty ( channel ) | | channel ! = "release" | | OemSettings . Instance . WindowTitleExtra = = "Experimental" )
{
#if ! DEBUG
_raygunClient . Send ( e ) ;
#endif
}
2015-04-15 10:08:36 -07:00
}
2015-04-08 15:20:10 -07:00
private event EventHandler unregisterEvent ;
public static MatterControlApplication Instance
{
get
{
if ( instance = = null )
{
// try and open our window matching the last size that we had for it.
string windowSize = ApplicationSettings . Instance . get ( "WindowSize" ) ;
int width = 1280 ;
int height = 720 ;
if ( windowSize ! = null & & windowSize ! = "" )
{
string [ ] sizes = windowSize . Split ( ',' ) ;
width = Math . Max ( int . Parse ( sizes [ 0 ] ) , ( int ) minSize . x + 1 ) ;
height = Math . Max ( int . Parse ( sizes [ 1 ] ) , ( int ) minSize . y + 1 ) ;
}
bool showWindow ;
instance = new MatterControlApplication ( width , height , out showWindow ) ;
if ( showWindow )
{
instance . ShowAsSystemWindow ( ) ;
}
}
return instance ;
}
}
2014-02-27 14:56:20 -08:00
2015-04-08 15:20:10 -07:00
[STAThread]
public static void Main ( )
{
2015-05-20 12:24:26 -07:00
// Make sure we have the right working directory as we assume everything relative to the executable.
2015-04-08 15:20:10 -07:00
Directory . SetCurrentDirectory ( Path . GetDirectoryName ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) ) ;
2015-05-20 13:37:08 -07:00
System . Windows . Forms . Application . ThreadException + = new ThreadExceptionEventHandler ( Application_ThreadException ) ;
AppDomain . CurrentDomain . UnhandledException + = new UnhandledExceptionEventHandler ( CurrentDomain_UnhandledException ) ;
//throw new Exception("Forced exception thrown manually!");
2015-04-08 15:20:10 -07:00
Datastore . Instance . Initialize ( ) ;
2015-05-20 12:24:26 -07:00
#if ! DEBUG
2015-05-22 13:00:57 -07:00
// Conditionally spin up error reporting if not on the Stable channel
2015-05-20 12:24:26 -07:00
string channel = UserSettings . Instance . get ( "UpdateFeedType" ) ;
2015-05-20 13:37:08 -07:00
if ( string . IsNullOrEmpty ( channel ) | | channel ! = "release" | | OemSettings . Instance . WindowTitleExtra = = "Experimental" )
2015-05-20 12:24:26 -07:00
#endif
{
2015-05-20 13:37:08 -07:00
System . Windows . Forms . Application . ThreadException + = new ThreadExceptionEventHandler ( Application_ThreadException ) ;
AppDomain . CurrentDomain . UnhandledException + = new UnhandledExceptionEventHandler ( CurrentDomain_UnhandledException ) ;
2015-05-20 12:24:26 -07:00
}
2015-04-08 15:20:10 -07:00
MatterControlApplication app = MatterControlApplication . Instance ;
}
2015-05-20 13:37:08 -07:00
private static void Application_ThreadException ( object sender , ThreadExceptionEventArgs e )
{
2015-05-28 11:52:29 -07:00
#if ! DEBUG
_raygunClient . Send ( e . Exception ) ;
#endif
2015-05-20 13:37:08 -07:00
}
private static void CurrentDomain_UnhandledException ( object sender , UnhandledExceptionEventArgs e )
{
2015-05-28 11:52:29 -07:00
#if ! DEBUG
_raygunClient . Send ( e . ExceptionObject as Exception ) ;
#endif
2015-05-20 13:37:08 -07:00
}
2015-04-08 15:20:10 -07:00
public static void WriteTestGCodeFile ( )
{
2015-01-19 17:33:17 -08:00
using ( StreamWriter file = new StreamWriter ( "PerformanceTest.gcode" ) )
{
//int loops = 150000;
int loops = 150 ;
int steps = 200 ;
double radius = 50 ;
Vector2 center = new Vector2 ( 150 , 100 ) ;
file . WriteLine ( "G28 ; home all axes" ) ;
file . WriteLine ( "G90 ; use absolute coordinates" ) ;
file . WriteLine ( "G21 ; set units to millimeters" ) ;
file . WriteLine ( "G92 E0" ) ;
file . WriteLine ( "G1 F7800" ) ;
file . WriteLine ( "G1 Z" + ( 5 ) . ToString ( ) ) ;
WriteMove ( file , center ) ;
for ( int loop = 0 ; loop < loops ; loop + + )
{
for ( int step = 0 ; step < steps ; step + + )
{
Vector2 nextPosition = new Vector2 ( radius , 0 ) ;
nextPosition . Rotate ( MathHelper . Tau / steps * step ) ;
WriteMove ( file , center + nextPosition ) ;
}
}
2014-02-04 10:47:57 -08:00
2015-01-19 17:33:17 -08:00
file . WriteLine ( "M84 ; disable motors" ) ;
}
2015-04-08 15:20:10 -07:00
}
public void DoAutoConnectIfRequired ( object state )
{
ActivePrinterProfile . CheckForAndDoAutoConnect ( ) ;
}
public void LaunchBrowser ( string targetUri )
{
UiThread . RunOnIdle ( ( state ) = >
{
System . Diagnostics . Process . Start ( targetUri ) ;
} ) ;
}
public override void OnClosed ( EventArgs e )
{
UserSettings . Instance . Fields . StartCountDurringExit = UserSettings . Instance . Fields . StartCount ;
TerminalWindow . CloseIfOpen ( ) ;
PrinterConnectionAndCommunication . Instance . Disable ( ) ;
//Close connection to the local datastore
Datastore . Instance . Exit ( ) ;
PrinterConnectionAndCommunication . Instance . HaltConnectionThread ( ) ;
SlicingQueue . Instance . ShutDownSlicingThread ( ) ;
ApplicationController . Instance . OnApplicationClosed ( ) ;
if ( RestartOnClose )
{
string appPathAndFile = System . Reflection . Assembly . GetExecutingAssembly ( ) . Location ;
string pathToAppFolder = Path . GetDirectoryName ( appPathAndFile ) ;
ProcessStartInfo runAppLauncherStartInfo = new ProcessStartInfo ( ) ;
runAppLauncherStartInfo . Arguments = "\"{0}\" \"{1}\"" . FormatWith ( appPathAndFile , 1000 ) ;
runAppLauncherStartInfo . FileName = Path . Combine ( pathToAppFolder , "Launcher.exe" ) ;
runAppLauncherStartInfo . WindowStyle = ProcessWindowStyle . Hidden ;
runAppLauncherStartInfo . CreateNoWindow = true ;
Process . Start ( runAppLauncherStartInfo ) ;
}
base . OnClosed ( e ) ;
}
public override void OnClosing ( out bool CancelClose )
{
// save the last size of the window so we can restore it next time.
ApplicationSettings . Instance . set ( "WindowSize" , string . Format ( "{0},{1}" , Width , Height ) ) ;
ApplicationSettings . Instance . set ( "DesktopPosition" , string . Format ( "{0},{1}" , DesktopPosition . x , DesktopPosition . y ) ) ;
//Save a snapshot of the prints in queue
QueueData . Instance . SaveDefaultQueue ( ) ;
if ( PrinterConnectionAndCommunication . Instance . PrinterIsPrinting )
{
StyledMessageBox . ShowMessageBox ( null , unableToExitMessage , unableToExitTitle ) ;
CancelClose = true ;
}
else if ( PartsSheet . IsSaving ( ) )
{
StyledMessageBox . ShowMessageBox ( onConfirmExit , savePartsSheetExitAnywayMessage , confirmExit , StyledMessageBox . MessageType . YES_NO ) ;
CancelClose = true ;
}
else
{
base . OnClosing ( out CancelClose ) ;
}
}
public override void OnDraw ( Graphics2D graphics2D )
{
totalDrawTime . Restart ( ) ;
GuiWidget . DrawCount = 0 ;
base . OnDraw ( graphics2D ) ;
totalDrawTime . Stop ( ) ;
millisecondTimer . Update ( ( int ) totalDrawTime . ElapsedMilliseconds ) ;
if ( ShowMemoryUsed )
{
long memory = GC . GetTotalMemory ( false ) ;
this . Title = "Allocated = {0:n0} : {1:000}ms, d{2} Size = {3}x{4}, onIdle = {5:00}:{6:00}, drawCount = {7}" . FormatWith ( memory , millisecondTimer . GetAverage ( ) , drawCount + + , this . Width , this . Height , UiThread . CountExpired , UiThread . Count , GuiWidget . DrawCount ) ;
if ( DoCGCollectEveryDraw )
{
GC . Collect ( ) ;
}
}
if ( firstDraw & & commandLineArgs . Length < 2 )
{
UiThread . RunOnIdle ( DoAutoConnectIfRequired ) ;
firstDraw = false ;
foreach ( string arg in commandLineArgs )
{
string argExtension = Path . GetExtension ( arg ) . ToUpper ( ) ;
if ( argExtension . Length > 1
& & MeshFileIo . ValidFileExtensions ( ) . Contains ( argExtension ) )
{
QueueData . Instance . AddItem ( new PrintItemWrapper ( new DataStorage . PrintItem ( Path . GetFileName ( arg ) , Path . GetFullPath ( arg ) ) ) ) ;
}
}
TerminalWindow . ShowIfLeftOpen ( ) ;
#if false
foreach ( CreatorInformation creatorInfo in RegisteredCreators . Instance . Creators )
{
if ( creatorInfo . description . Contains ( "Image" ) )
{
creatorInfo . functionToLaunchCreator ( null , null ) ;
}
}
#endif
}
2014-02-27 14:56:20 -08:00
2015-04-08 15:20:10 -07:00
//msGraph.AddData("ms", totalDrawTime.ElapsedMilliseconds);
//msGraph.Draw(MatterHackers.Agg.Transform.Affine.NewIdentity(), graphics2D);
}
public override void OnMouseMove ( MouseEventArgs mouseEvent )
{
if ( GuiWidget . DebugBoundsUnderMouse )
{
Invalidate ( ) ;
}
base . OnMouseMove ( mouseEvent ) ;
}
public override void OnParentChanged ( EventArgs e )
{
if ( File . Exists ( "RunUnitTests.txt" ) )
{
//DiagnosticWidget diagnosticView = new DiagnosticWidget(this);
}
base . OnParentChanged ( e ) ;
// now that we are all set up lets load our plugins and allow them their chance to set things up
FindAndInstantiatePlugins ( ) ;
}
public void OpenCameraPreview ( )
{
//Camera launcher placeholder (KP)
if ( ApplicationSettings . Instance . get ( "HardwareHasCamera" ) = = "true" )
{
//Do something
}
else
{
//Do something else (like show warning message)
}
}
public void PlaySound ( string fileName )
{
if ( OsInformation . OperatingSystem = = OSType . Windows )
{
using ( var mediaStream = StaticData . Instance . OpenSteam ( Path . Combine ( "Sounds" , fileName ) ) )
{
( new System . Media . SoundPlayer ( mediaStream ) ) . Play ( ) ;
}
}
}
private static void WriteMove ( StreamWriter file , Vector2 center )
{
file . WriteLine ( "G1 X" + center . x . ToString ( ) + " Y" + center . y . ToString ( ) ) ;
}
private void CheckOnPrinter ( object state )
{
2015-03-25 18:01:57 -07:00
try
{
PrinterConnectionAndCommunication . Instance . OnIdle ( ) ;
}
2015-04-08 15:20:10 -07:00
catch ( Exception e )
2015-03-25 18:01:57 -07:00
{
Debug . Print ( e . Message ) ;
#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-04-08 15:20:10 -07:00
private void FindAndInstantiatePlugins ( )
{
2014-01-29 19:09:30 -08:00
#if false
2015-04-08 15:20:10 -07:00
string pluginDirectory = Path . Combine ( ".." , ".." , ".." , "MatterControlPlugins" , "bin" ) ;
2014-01-29 19:09:30 -08:00
#if DEBUG
2015-04-08 15:20:10 -07:00
pluginDirectory = Path . Combine ( pluginDirectory , "Debug" ) ;
2014-01-29 19:09:30 -08:00
#else
2015-04-08 15:20:10 -07:00
pluginDirectory = Path . Combine ( pluginDirectory , "Release" ) ;
2014-01-29 19:09:30 -08:00
#endif
2015-04-08 15:20:10 -07:00
if ( ! Directory . Exists ( pluginDirectory ) )
{
string dataPath = DataStorage . ApplicationDataStorage . Instance . ApplicationUserDataPath ;
pluginDirectory = Path . Combine ( dataPath , "Plugins" ) ;
}
// TODO: this should look in a plugin folder rather than just the application directory (we probably want it in the user folder).
PluginFinder < MatterControlPlugin > pluginFinder = new PluginFinder < MatterControlPlugin > ( pluginDirectory ) ;
2014-01-29 19:09:30 -08:00
#else
2015-03-09 16:23:38 -07:00
PluginFinder < MatterControlPlugin > pluginFinder = new PluginFinder < MatterControlPlugin > ( ) ;
2014-01-29 19:09:30 -08:00
#endif
2014-11-25 07:47:03 -08:00
2015-04-08 15:20:10 -07:00
string oemName = ApplicationSettings . Instance . GetOEMName ( ) ;
2015-03-09 16:23:38 -07:00
foreach ( MatterControlPlugin plugin in pluginFinder . Plugins )
2015-04-08 15:20:10 -07:00
{
string pluginInfo = plugin . GetPluginInfoJSon ( ) ;
Dictionary < string , string > nameValuePairs = Newtonsoft . Json . JsonConvert . DeserializeObject < Dictionary < string , string > > ( pluginInfo ) ;
2014-07-15 14:02:03 -07:00
2015-04-08 15:20:10 -07:00
if ( nameValuePairs ! = null & & nameValuePairs . ContainsKey ( "OEM" ) )
{
if ( nameValuePairs [ "OEM" ] = = oemName )
{
plugin . Initialize ( this ) ;
}
}
else
{
plugin . Initialize ( this ) ;
}
}
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private void onConfirmExit ( bool messageBoxResponse )
{
bool CancelClose ;
if ( messageBoxResponse )
{
base . OnClosing ( out CancelClose ) ;
}
}
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 ( ) ;
ClipperLib . Clipper . 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
}
2015-04-08 15:20:10 -07:00
}