/// <summary> /// Creates or connects a PlatformWindow to the given SystemWindow /// </summary> public void ShowSystemWindow(SystemWindow systemWindow) { IPlatformWindow platformWindow; bool singleWindowMode = WinformsSystemWindow.SingleWindowMode; bool isFirstWindow = singlePlatformWindow == null; if ((singleWindowMode && isFirstWindow) || !singleWindowMode) { if (systemWindow.PlatformWindow == null) { platformWindow = AggContext.CreateInstanceFrom <IPlatformWindow>(AggContext.Config.ProviderTypes.SystemWindow); platformWindow.Caption = systemWindow.Title; platformWindow.MinimumSize = systemWindow.MinimumSize; } else { platformWindow = systemWindow.PlatformWindow; } } else { platformWindow = singlePlatformWindow; } platformWindow.ShowSystemWindow(systemWindow); }
public async Task AabbCalculatedCorrectlyForCurvedFitObjects() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); // Automation runner must do as much as program.cs to spin up platform string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.ProcessCommandline(); var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var fit = await FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), 1.0)); var curve = new CurveObject3D_2(); curve.Children.Add(fit); await curve.Rebuild(); var curveAabb = curve.GetAxisAlignedBoundingBox(); root.Children.Add(curve); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-17.5, -9.9, -10), new Vector3(17.5, 11.97, 10)), 1.0)); }
static void Main(string[] args) { // this sets the global culture for the app and all new threads CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; // make sure we can bulid a system relevant serial port FrostedSerialPortFactory.GetPlatformSerialPort = (serialPortName) => { return(new CSharpSerialPortWrapper(serialPortName)); }; // and make sure the app is set correctly Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; // Set default Agg providers AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.OpenGLWinformsWindowProvider, agg_platform_win32"; //AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.MatterControl.WinformsSingleWindowProvider, MatterControl.Winforms"; string userProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); // Load optional user configuration IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true) .AddJsonFile(Path.Combine(userProfilePath, "MatterControl.json"), optional: true) .Build(); // Override defaults via configuration config.Bind("Agg:ProviderTypes", AggContext.Config.ProviderTypes); config.Bind("Agg:GraphicsMode", AggContext.Config.GraphicsMode); Slicer.RunInProcess = config.GetValue <bool>("MatterControl:Slicer:Debug"); Slicer.RunInProcess = true; // Make sure we have the right working directory as we assume everything relative to the executable. Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); Datastore.Instance.Initialize(); // Init platformFeaturesProvider before ShowAsSystemWindow string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; MatterHackers.MatterControl.AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); MatterHackers.MatterControl.AppContext.Platform.ProcessCommandline(); config.Bind("MatterControl", MatterHackers.MatterControl.AppContext.Options); // Get startup bounds from MatterControl and construct system window //var systemWindow = new DesktopMainWindow(400, 200) var(width, height) = RootSystemWindow.GetStartupBounds(); var systemWindow = Application.LoadRootWindow(width, height); systemWindow.ShowAsSystemWindow(); }
public static void StartupMC() { StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); // Automation runner must do as much as program.cs to spin up platform string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.InitPluginFinder(); AppContext.Platform.ProcessCommandline(); }
public void PinchChangesMesh() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); // Automation runner must do as much as program.cs to spin up platform string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; MatterControl.AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); MatterControl.AppContext.Platform.InitPluginFinder(); MatterControl.AppContext.Platform.ProcessCommandline(); RunTest(); }
public void AabbCalculatedCorrectlyForCurvedFitObjects() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); // Automation runner must do as much as program.cs to spin up platform string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.ProcessCommandline(); DoAabbCalculatedCorrectlyForCurvedFitObjects(); }
public async Task AabbCalculatedCorrectlyForAlignedFitObject() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); // Automation runner must do as much as program.cs to spin up platform string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.ProcessCommandline(); var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var fit = await FitToBoundsObject3D_2.Create(cube); fit.SizeX = 10; fit.SizeY = 10; fit.SizeZ = 6; Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-5, -5, -10), new Vector3(5, 5, -4)), .01)); var bigCube = await CubeObject3D.Create(20, 20, 20); Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .01)); var align = new AlignObject3D(); align.Children.Add(bigCube); align.Children.Add(fit); await align.Rebuild(); align.XAlign = Align.Center; align.YAlign = Align.Center; align.ZAlign = Align.Max; align.Advanced = true; align.ZOffset = 1; await align.Rebuild(); var alignAabb = align.GetAxisAlignedBoundingBox(); Assert.IsTrue(alignAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01)); alignAabb = align.GetAxisAlignedBoundingBox(); root.Children.Add(align); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01)); }
public static void Main(string[] args) { #if false // this is for some early testing of SLA output var test = new PhotonFile(); void Progress(string message) { Debug.WriteLine(message); } var sourceFile = @"C:\Users\LarsBrubaker\Downloads\10mm-benchy.photon"; if (File.Exists(sourceFile)) { test.ReadFile(sourceFile, Progress); test.SaveFile(@"C:\Users\LarsBrubaker\Downloads\10mm-bench2.photon"); } else { sourceFile = @"C:\Users\larsb\Downloads\_rocktopus.ctb"; test.ReadFile(sourceFile, Progress); test.SaveFile(@"C:\Users\larsb\Downloads\_rocktopus.photon"); } #endif #if false // this is for processing print log exports var filename = "C:\\Users\\LarsBrubaker\\Downloads\\210309 B2 print_log.txt"; var lines = File.ReadAllLines(filename); var newPosition = default(Vector3); var ePosition = 0.0; var instruction = 0; var layer = 0; using (var writetext = new StreamWriter("C:\\Temp\\printlog.gcode")) { foreach (var line in lines) { if (line.Contains(" G1 ")) { GCodeFile.GetFirstNumberAfter("X", line, ref newPosition.X); GCodeFile.GetFirstNumberAfter("Y", line, ref newPosition.Y); GCodeFile.GetFirstNumberAfter("Z", line, ref newPosition.Z); GCodeFile.GetFirstNumberAfter("E", line, ref ePosition); writetext.WriteLine($"G1 X{newPosition.X} Y{newPosition.Y} Z{newPosition.Z} E{ePosition}"); instruction++; if (instruction % 500 == 0) { writetext.WriteLine($"; LAYER:{layer++}"); } } } } #endif // Set the global culture for the app, current thread and all new threads CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; // make sure we can build a system relevant serial port FrostedSerialPortFactory.GetPlatformSerialPort = (serialPortName) => { return(new CSharpSerialPortWrapper(serialPortName)); }; // Set default Agg providers AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.GlfwProvider.GlfwWindowProvider, MatterHackers.GlfwProvider"; // for now we will ship release with the old renderer #if !DEBUG AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.MatterControl.WinformsSingleWindowProvider, MatterControl.Winforms"; #endif string userProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); _raygunClient = new RaygunClient("hQIlyUUZRGPyXVXbI6l1dA==") // this is the PC key { ApplicationVersion = VersionInfo.Instance.ReleaseVersion }; #if !DEBUG if (AggContext.OperatingSystem == OSType.Windows) { waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, "MatterControl#Startup", out bool created); if (!created) { // If an instance is already running, create a service proxy and execute ShellOpenFile var proxy = new ServiceProxy(); // and at least one argument is an acceptable shell file extension var itemsToAdd = args.Where(f => File.Exists(f) && shellFileExtensions.Contains(Path.GetExtension(f).ToLower())); if (itemsToAdd.Any()) { // notify the running instance of the event proxy.ShellOpenFile(itemsToAdd.ToArray()); } System.Threading.Thread.Sleep(1000); // Finally, close the process spawned by Explorer.exe return; } var serviceHost = new ServiceHost(typeof(LocalService), new[] { new Uri(ServiceBaseUri) }); serviceHost.AddServiceEndpoint(typeof(IMainService), new NetNamedPipeBinding(), mainServiceName); serviceHost.Open(); Console.Write( "Service started: {0};", string.Join(", ", serviceHost.Description.Endpoints.Select(s => s.ListenUri.AbsoluteUri).ToArray())); } #endif // If MatterControl isn't running and valid files were shelled, schedule a StartupAction to open the files after load var shellFiles = args.Where(f => File.Exists(f) && shellFileExtensions.Contains(Path.GetExtension(f).ToLower())); if (shellFiles.Any()) { ApplicationController.StartupActions.Add(new ApplicationController.StartupAction() { Title = "Shell Files", Priority = 0, Action = () => { // Open each shelled file foreach (string file in shellFiles) { ApplicationController.Instance.ShellOpenFile(file); } } }); } // Load optional user configuration IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true) .AddJsonFile(Path.Combine(userProfilePath, "MatterControl.json"), optional: true) .Build(); // Override defaults via configuration config.Bind("Agg:ProviderTypes", AggContext.Config.ProviderTypes); config.Bind("Agg:GraphicsMode", AggContext.Config.GraphicsMode); Slicer.RunInProcess = config.GetValue <bool>("MatterControl:Slicer:Debug"); Application.EnableF5Collect = config.GetValue <bool>("MatterControl:Application:EnableF5Collect"); Application.EnableNetworkTraffic = config.GetValue <bool>("MatterControl:Application:EnableNetworkTraffic", true); Application.MiniTouchScreen.Make = config.GetValue <string>("MatterControl:MiniTouchScreen:Make", ""); Application.MiniTouchScreen.Model = config.GetValue <string>("MatterControl:MiniTouchScreen:Model", ""); // Make sure we have the right working directory as we assume everything relative to the executable. Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); Datastore.Instance.Initialize(DesktopSqlite.CreateInstance()); if (UserSettings.Instance.get(UserSettingsKey.ApplicationUseHeigResDisplays) == "true") { SetProcessDpiAwareness((int)DpiAwareness.PerMonitorAware); } var isExperimental = OemSettings.Instance.WindowTitleExtra == "Experimental"; #if !DEBUG // Conditionally spin up error reporting if not on the Stable channel string channel = UserSettings.Instance.get(UserSettingsKey.UpdateFeedType); if (string.IsNullOrEmpty(channel) || channel != "release" || isExperimental) #endif { System.Windows.Forms.Application.ThreadException += (s, e) => { if (raygunNotificationCount++ < RaygunMaxNotifications) { _raygunClient.Send(e.Exception); } if (System.Windows.Forms.Application.OpenForms.Count > 0 && !System.Windows.Forms.Application.OpenForms[0].InvokeRequired) { System.Windows.Forms.Application.Exit(); } }; AppDomain.CurrentDomain.UnhandledException += (s, e) => { if (raygunNotificationCount++ < RaygunMaxNotifications) { _raygunClient.Send(e.ExceptionObject as Exception); } System.Windows.Forms.Application.Exit(); }; } // Init platformFeaturesProvider before ShowAsSystemWindow string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; string textSizeMode = UserSettings.Instance.get(UserSettingsKey.ApplicationTextSize); if (!string.IsNullOrEmpty(textSizeMode)) { if (double.TryParse(textSizeMode, out double textSize)) { GuiWidget.DeviceScale = textSize; } } AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.InitPluginFinder(); AppContext.Platform.ProcessCommandline(); config.Bind("MatterControl", MatterHackers.MatterControl.AppContext.Options); // Get startup bounds from MatterControl and construct system window // var systemWindow = new DesktopMainWindow(400, 200) var(width, height) = RootSystemWindow.GetStartupBounds(); var systemWindow = Application.LoadRootWindow(width, height); var theme = ApplicationController.Instance.Theme; SingleWindowProvider.SetWindowTheme(theme.TextColor, theme.DefaultFontSize - 1, theme.InvertIcons, () => theme.CreateSmallResetButton(), theme.ToolbarPadding, theme.TabBarBackground, new Color(theme.PrimaryAccentColor, 175)); ApplicationController.Instance.KeepAwake = KeepAwake; systemWindow.ShowAsSystemWindow(); }
public async Task AlignObjectHasCorrectPositionsOnXAxis() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); // Automation runner must do as much as program.cs to spin up platform string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.ProcessCommandline(); var scene = new InteractiveScene(); var cube = await CubeObject3D.Create(20, 20, 20); cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10); Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01)); scene.Children.Add(cube); var bigCube = await CubeObject3D.Create(40, 40, 40); bigCube.Matrix = Matrix4X4.CreateTranslation(20, 20, 20); Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01)); scene.Children.Add(bigCube); // select them scene.SelectedItem = cube; scene.AddToSelection(bigCube); // create an align of them var align = new AlignObject3D(); align.AddSelectionAsChildren(scene, scene.SelectedItem); var unalignedBounds = align.GetAxisAlignedBoundingBox(); // assert the align in built correctly Assert.AreEqual(1, scene.Children.Count); Assert.AreEqual(2, align.Children.Count); Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(60, 70, 40)), 1.0)); align.SelectedChild = new SelectedChildren() { cube.ID.ToString() }; Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0)); // turn align on align.XAlign = Align.Min; await align.Rebuild(); Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0)); // turn it off align.XAlign = Align.None; await align.Rebuild(); Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0)); // turn it back on align.XAlign = Align.Min; await align.Rebuild(); Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0)); // remove the align and assert stuff moved back to where it started align.Remove(null); Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01)); Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01)); }
public async Task AabbCalculatedCorrectlyForPinchedFitObjects() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); // Automation runner must do as much as program.cs to spin up platform string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.InitPluginFinder(); AppContext.Platform.ProcessCommandline(); // build without pinch { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); root.Children.Add(cube); Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001)); root.Children.Remove(cube); var fit = await FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; root.Children.Add(fit); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), .001)); } // build with pinch { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var fit = await FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; var pinch = new PinchObject3D_2(); pinch.Children.Add(fit); await pinch.Rebuild(); root.Children.Add(pinch); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001)); } // build with translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var translate = new TranslateObject3D(cube, 11, 0, 0); root.Children.Add(translate); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } // build with pinch and translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var translate = new TranslateObject3D(cube, 11, 0, 0); var pinch = new PinchObject3D_2(); pinch.Children.Add(translate); root.Children.Add(pinch); await pinch.Rebuild(); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } // build with pinch and translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var fit = await FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; var translate = new TranslateObject3D(fit, 11, 0, 0); var pinch = new PinchObject3D_2(); pinch.Children.Add(translate); await pinch.Rebuild(); root.Children.Add(pinch); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } }
public static void Main(string[] args) { // Set the global culture for the app, current thread and all new threads CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; // make sure we can build a system relevant serial port FrostedSerialPortFactory.GetPlatformSerialPort = (serialPortName) => { return(new CSharpSerialPortWrapper(serialPortName)); }; // Set default Agg providers AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.MatterControl.WinformsSingleWindowProvider, MatterControl.Winforms"; string userProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); _raygunClient = new RaygunClient("hQIlyUUZRGPyXVXbI6l1dA==") // this is the PC key { ApplicationVersion = VersionInfo.Instance.ReleaseVersion }; if (AggContext.OperatingSystem == OSType.Windows) { waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, "MatterControl#Startup", out bool created); if (!created) { // If an instance is already running, create a service proxy and execute ShellOpenFile var proxy = new ServiceProxy(); // and at least one argument is an acceptable shell file extension var itemsToAdd = args.Where(f => File.Exists(f) && shellFileExtensions.Contains(Path.GetExtension(f).ToLower())); if (itemsToAdd.Any()) { // notify the running instance of the event proxy.ShellOpenFile(itemsToAdd.ToArray()); } System.Threading.Thread.Sleep(1000); // Finally, close the process spawned by Explorer.exe return; } // #endif var serviceHost = new ServiceHost( typeof(LocalService), new Uri[] { new Uri("net.pipe://localhost/mattercontrol") }); serviceHost.AddServiceEndpoint(typeof(IMainService), new NetNamedPipeBinding(), mainServiceName); serviceHost.Open(); Console.Write( "Service started: {0};", string.Join(", ", serviceHost.Description.Endpoints.Select(s => s.ListenUri.AbsoluteUri).ToArray())); } // Load optional user configuration IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true) .AddJsonFile(Path.Combine(userProfilePath, "MatterControl.json"), optional: true) .Build(); // Override defaults via configuration config.Bind("Agg:ProviderTypes", AggContext.Config.ProviderTypes); config.Bind("Agg:GraphicsMode", AggContext.Config.GraphicsMode); Slicer.RunInProcess = config.GetValue <bool>("MatterControl:Slicer:Debug"); Application.EnableF5Collect = config.GetValue <bool>("MatterControl:Application:EnableF5Collect"); Application.EnableNetworkTraffic = config.GetValue <bool>("MatterControl:Application:EnableNetworkTraffic", true); // Make sure we have the right working directory as we assume everything relative to the executable. Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); Datastore.Instance.Initialize(DesktopSqlite.CreateInstance()); #if !DEBUG // Conditionally spin up error reporting if not on the Stable channel string channel = UserSettings.Instance.get(UserSettingsKey.UpdateFeedType); if (string.IsNullOrEmpty(channel) || channel != "release" || OemSettings.Instance.WindowTitleExtra == "Experimental") #endif { System.Windows.Forms.Application.ThreadException += (s, e) => { if (raygunNotificationCount++ < RaygunMaxNotifications) { _raygunClient.Send(e.Exception); } if (System.Windows.Forms.Application.OpenForms.Count > 0 && !System.Windows.Forms.Application.OpenForms[0].InvokeRequired) { System.Windows.Forms.Application.Exit(); } }; AppDomain.CurrentDomain.UnhandledException += (s, e) => { if (raygunNotificationCount++ < RaygunMaxNotifications) { _raygunClient.Send(e.ExceptionObject as Exception); } System.Windows.Forms.Application.Exit(); }; } // Init platformFeaturesProvider before ShowAsSystemWindow string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.InitPluginFinder(); AppContext.Platform.ProcessCommandline(); config.Bind("MatterControl", MatterHackers.MatterControl.AppContext.Options); // Get startup bounds from MatterControl and construct system window // var systemWindow = new DesktopMainWindow(400, 200) var(width, height) = RootSystemWindow.GetStartupBounds(); var systemWindow = Application.LoadRootWindow(width, height); systemWindow.ShowAsSystemWindow(); }
public static async Task RunTest( AutomationTest testMethod, string staticDataPathOverride = null, double maxTimeToRun = 60, QueueTemplate queueItemFolderToAdd = QueueTemplate.None, int overrideWidth = -1, int overrideHeight = -1, string defaultTestImages = null) { // Walk back a step in the stack and output the callers name //StackTrace st = new StackTrace(false); //Debug.WriteLine("\r\n ***** Running automation test: {0} {1} ", st.GetFrames().Skip(1).First().GetMethod().Name, DateTime.Now); if (staticDataPathOverride == null) { // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl staticDataPathOverride = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData"); } #if DEBUG string outputDirectory = "Debug"; #else string outputDirectory = "Release"; #endif Environment.CurrentDirectory = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "bin", outputDirectory); // Override the default SystemWindow type without config.json AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.OpenGLWinformsWindowProvider, agg_platform_win32"; #if !__ANDROID__ // Set the static data to point to the directory of MatterControl AggContext.StaticData = new FileSystemStaticData(staticDataPathOverride); #endif // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl")); if (queueItemFolderToAdd != QueueTemplate.None) { MatterControlUtilities.AddItemsToQueue(queueItemFolderToAdd.ToString()); } if (defaultTestImages == null) { defaultTestImages = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestImages"); } UserSettings.Instance.set(UserSettingsKey.ThumbnailRenderingMode, "orthographic"); //GL.HardwareAvailable = false; var config = TestAutomationConfig.Load(); if (config.UseAutomationDialogs) { AggContext.Config.ProviderTypes.DialogProvider = "MatterHackers.Agg.Platform.AutomationDialogProvider, GuiAutomation"; } // Extract mouse speed from config AutomationRunner.TimeToMoveMouse = config.TimeToMoveMouse; AutomationRunner.UpDelaySeconds = config.MouseUpDelay; // Automation runner must do as much as program.cs to spin up platform string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.ProcessCommandline(); var(width, height) = RootSystemWindow.GetStartupBounds(); rootSystemWindow = Application.LoadRootWindow( overrideWidth == -1 ? width : overrideWidth, overrideHeight == -1 ? height : overrideHeight); OemSettings.Instance.ShowShopButton = false; if (!config.UseAutomationMouse) { AutomationRunner.InputMethod = new WindowsInputMethods(); } await AutomationRunner.ShowWindowAndExecuteTests( rootSystemWindow, testMethod, maxTimeToRun, defaultTestImages, closeWindow : () => { if (ApplicationController.Instance.ActivePrinter.Connection.CommunicationState == CommunicationStates.Printing) { ApplicationController.Instance.ActivePrinter.Connection.Disable(); } rootSystemWindow.Close(); }); }
public static void Main() { // this sets the global culture for the app and all new threads CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; // and make sure the app is set correctly Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; if (AggContext.OperatingSystem == OSType.Mac) { _raygunClient = new RaygunClient("qmMBpKy3OSTJj83+tkO7BQ=="); // this is the Mac key } else { _raygunClient = new RaygunClient("hQIlyUUZRGPyXVXbI6l1dA=="); // this is the PC key } AggContext.Init(embeddedResourceName: "config.json"); // Make sure we have the right working directory as we assume everything relative to the executable. Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); Datastore.Instance.Initialize(); #if !DEBUG // Conditionally spin up error reporting if not on the Stable channel string channel = UserSettings.Instance.get(UserSettingsKey.UpdateFeedType); if (string.IsNullOrEmpty(channel) || channel != "release" || OemSettings.Instance.WindowTitleExtra == "Experimental") #endif { System.Windows.Forms.Application.ThreadException += (s, e) => { if (raygunNotificationCount++ < RaygunMaxNotifications) { _raygunClient.Send(e.Exception); } }; AppDomain.CurrentDomain.UnhandledException += (s, e) => { if (raygunNotificationCount++ < RaygunMaxNotifications) { _raygunClient.Send(e.ExceptionObject as Exception); } }; } // Init platformFeaturesProvider before ShowAsSystemWindow string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl"; AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider); AppContext.Platform.ProcessCommandline(); // Get startup bounds from MatterControl and construct system window //var systemWindow = new DesktopMainWindow(400, 200) var(width, height) = RootSystemWindow.GetStartupBounds(); var systemWindow = Application.LoadRootWindow(width, height); systemWindow.ShowAsSystemWindow(); }