public SyncingPrintersPage()
            : base("Close")
        {
            TextWidget syncingText = new TextWidget("Syncing Profiles...".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor);

            syncingDetails = new TextWidget("Retrieving sync information...".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 10);
            syncingDetails.AutoExpandBoundsToText = true;
            contentRow.AddChild(syncingText);
            contentRow.AddChild(syncingDetails);
            Progress <SyncReportType> progress = new Progress <SyncReportType>(ReportProgress);

            ApplicationController.SyncPrinterProfiles("SyncingPrintersPage.ctor()", progress).ContinueWith((task) =>
            {
                if (!ProfileManager.Instance.ActiveProfiles.Any())
                {
                    // Switch to setup wizard if no profiles exist
                    WizardWindow.ChangeToSetupPrinterForm();
                }
                else if (ProfileManager.Instance.ActiveProfiles.Count() == 1)
                {
                    //Set as active printer
                    ActiveSliceSettings.SwitchToProfile(ProfileManager.Instance.ActiveProfiles.First().ID);
                    // only close the window if we are not switching to the setup printer form
                    UiThread.RunOnIdle(WizardWindow.Close);
                }
                else                 // multiple printers - close the window
                {
                    UiThread.RunOnIdle(WizardWindow.Close);
                }
            });
            footerRow.AddChild(new HorizontalSpacer());
            footerRow.AddChild(cancelButton);
        }
Esempio n. 2
0
        private bool OnSave()
        {
            if (!string.IsNullOrEmpty(printerNameInput.Text))
            {
                this.ActivePrinter.Name = printerNameInput.Text;

                if (this.ActivePrinter.Make == null || this.ActivePrinter.Model == null)
                {
                    return(false);
                }
                else
                {
                    ActiveSliceSettings.AcquireNewProfile(ActivePrinter.Make, ActivePrinter.Model, ActivePrinter.Name);
                    return(true);
                }
            }
            else
            {
                this.printerNameError.TextColor = RGBA_Bytes.Red;
                this.printerNameError.Text      = "Printer name cannot be blank";
                this.printerNameError.Visible   = true;

                return(false);
            }
        }
        public PrinterProfileHistoryPage()
            : base(unlocalizedTextForTitle: "Restore Settings")
        {
            scrollWindow = new ScrollableWidget()
            {
                AutoScroll = true,
                HAnchor    = HAnchor.ParentLeftRight,
                VAnchor    = VAnchor.ParentBottomTop,
            };
            scrollWindow.ScrollArea.HAnchor = HAnchor.ParentLeftRight;
            contentRow.FlowDirection        = FlowDirection.TopToBottom;
            contentRow.AddChild(scrollWindow);

            var revertButton = textImageButtonFactory.Generate("Restore".Localize());

            footerRow.AddChild(revertButton);
            footerRow.AddChild(new HorizontalSpacer());
            footerRow.AddChild(cancelButton);
            revertButton.Click += async(s, e) =>
            {
                int index = radioButtonList.IndexOf(radioButtonList.Where(r => r.Checked).FirstOrDefault());

                if (index != -1)
                {
                    string profileToken = printerProfileData[orderedProfiles[index]];

                    var activeProfile = ProfileManager.Instance.ActiveProfile;

                    // Download the specified json profile
                    var jsonProfile = await ApplicationController.GetPrinterProfileAsync(activeProfile, profileToken);

                    if (jsonProfile != null)
                    {
                        // Persist downloaded profile
                        jsonProfile.Save();

                        // Update active instance without calling ReloadAll
                        ActiveSliceSettings.RefreshActiveInstance(jsonProfile);
                    }

                    UiThread.RunOnIdle(WizardWindow.Close);
                }
            };

            LoadHistoryItems();
        }
        public static void ImportPrinter(Printer printer, ProfileData profileData, string profilePath)
        {
            var printerInfo = new PrinterInfo()
            {
                Name = printer.Name,
                Id   = printer.Id.ToString()
            };

            profileData.Profiles.Add(printerInfo);

            var layeredProfile = ActiveSliceSettings.LoadEmptyProfile();

            layeredProfile.OemProfile = new OemProfile(LoadOemLayer(printer));

            LoadQualitySettings(layeredProfile, printer);
            LoadMaterialSettings(layeredProfile, printer);

            layeredProfile.ID = printer.Id.ToString();

            layeredProfile.UserLayer["MatterControl.PrinterName"]            = printer.Name ?? "";
            layeredProfile.UserLayer["MatterControl.Make"]                   = printer.Make ?? "";
            layeredProfile.UserLayer["MatterControl.Model"]                  = printer.Model ?? "";
            layeredProfile.UserLayer["MatterControl.BaudRate"]               = printer.BaudRate ?? "";
            layeredProfile.UserLayer["MatterControl.ComPort"]                = printer.ComPort ?? "";
            layeredProfile.UserLayer["MatterControl.AutoConnect"]            = printer.AutoConnect ? "1" : "0";
            layeredProfile.UserLayer["MatterControl.DefaultMaterialPresets"] = printer.MaterialCollectionIds ?? "";
            layeredProfile.UserLayer["MatterControl.WindowsDriver"]          = printer.DriverType ?? "";
            layeredProfile.UserLayer["MatterControl.DeviceToken"]            = printer.DeviceToken ?? "";
            layeredProfile.UserLayer["MatterControl.DeviceType"]             = printer.DeviceType ?? "";

            if (string.IsNullOrEmpty(UserSettings.Instance.get("ActiveProfileID")))
            {
                UserSettings.Instance.set("ActiveProfileID", printer.Id.ToString());
            }

            layeredProfile.UserLayer["MatterControl.ActiveThemeIndex"] = UserSettings.Instance.get("ActiveThemeIndex");

            // Import macros from the database
            var allMacros = Datastore.Instance.dbSQLite.Query <CustomCommands>("SELECT * FROM CustomCommands WHERE PrinterId = " + printer.Id);

            layeredProfile.Macros = allMacros.Select(macro => new GCodeMacro()
            {
                GCode        = macro.Value.Trim(),
                Name         = macro.Name,
                LastModified = macro.DateLastModified
            }).ToList();

            string query           = string.Format("SELECT * FROM PrinterSetting WHERE Name = 'PublishBedImage' and PrinterId = {0};", printer.Id);
            var    publishBedImage = Datastore.Instance.dbSQLite.Query <PrinterSetting>(query).FirstOrDefault();

            layeredProfile.UserLayer["MatterControl.PublishBedImage"] = publishBedImage?.Value == "true" ? "1" : "0";

            // Print leveling
            var printLevelingData = PrintLevelingData.Create(
                new SettingsProfile(layeredProfile),
                printer.PrintLevelingJsonData,
                printer.PrintLevelingProbePositions);

            layeredProfile.UserLayer["MatterControl.PrintLevelingData"]    = JsonConvert.SerializeObject(printLevelingData);
            layeredProfile.UserLayer["MatterControl.PrintLevelingEnabled"] = printer.DoPrintLeveling ? "true" : "false";

            layeredProfile.UserLayer["MatterControl.ManualMovementSpeeds"] = printer.ManualMovementSpeeds;

            // TODO: Where can we find CalibrationFiiles in the current model?
            //layeredProfile.SetActiveValue("MatterControl.CalibrationFiles", printer.Make);

            layeredProfile.ID = printer.Id.ToString();
            string fullProfilePath = Path.Combine(profilePath, printer.Id + ".json");

            File.WriteAllText(fullProfilePath, JsonConvert.SerializeObject(layeredProfile, Formatting.Indented));
        }