예제 #1
0
        public static void Main(string[] args)
        {
            // Init agg with our OpenGL window definition
            // AggContext.Init(embeddedResourceName: "lion.config.json");
            // AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.OpenGLWinformsWindowProvider, agg_platform_win32";
            AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.GlfwProvider.GlfwWindowProvider, MatterHackers.GlfwProvider";

            var demoWidget = new Lion();

            var systemWindow = new SystemWindow(512, 400);

            systemWindow.Title = demoWidget.Title;
            systemWindow.AddChild(demoWidget);
            SingleWindowProvider.SetWindowTheme(Color.Black, 12, false, () => new Button("X", 0, 0), 3, Color.LightGray, Color.DarkGray);
            systemWindow.ShowAsSystemWindow();
        }
        public static void Main(string[] args)
        {
            // Force OpenGL
            var Glfw = false;

            if (Glfw)
            {
                AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.GlfwProvider.GlfwWindowProvider, MatterHackers.GlfwProvider";
            }
            else
            {
                AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.OpenGLWinformsWindowProvider, agg_platform_win32";
            }

            var downloadsDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");

            List <string> possibleMeshes = new()
            {
                "architest_18.stl",
                "Runout Sensor.stl",
                "Swoop Shell_rev9.STL",
                "Engine-Benchmark.stl"
            };

            possibleMeshes.AddRange(args);

            var meshPath = "";

            foreach (var path in possibleMeshes)
            {
                meshPath = Path.Combine(downloadsDirectory, path);
                if (File.Exists(meshPath))
                {
                    break;
                }
            }

            MeshViewerApplication app = new MeshViewerApplication(true, meshPath);

            SingleWindowProvider.SetWindowTheme(Color.Black, 12, () => new Button("X", 0, 0), 3, Color.LightGray, Color.DarkGray);
            app.ShowAsSystemWindow();
        }
    }
예제 #3
0
        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();
        }