Beispiel #1
0
        public void LoadSlicePresets(string make, string model, string tag)
        {
            string[] slicePresetPaths = GetSlicePresets(make, model, tag);

            foreach (string filePath in slicePresetPaths)
            {
                SliceSettingsCollection     collection   = null;
                Dictionary <string, string> settingsDict = LoadSliceSettingsFromFile(filePath);

                if (settingsDict.Count > 0)
                {
                    collection           = new DataStorage.SliceSettingsCollection();
                    collection.Name      = Path.GetFileNameWithoutExtension(filePath);
                    collection.PrinterId = ActivePrinter.Id;
                    collection.Tag       = tag;
                    collection.Commit();

                    if (tag == "material" && defaultMaterialPreset != null && collection.Name == defaultMaterialPreset)
                    {
                        ActivePrinter.MaterialCollectionIds = collection.Id.ToString();
                        ActivePrinter.Commit();
                    }
                    else if (tag == "quality" && defaultQualityPreset != null && collection.Name == defaultQualityPreset)
                    {
                        ActivePrinter.QualityCollectionId = collection.Id;
                        ActivePrinter.Commit();
                    }
                    CommitSliceSettings(settingsDict, collection.Id);
                }
            }
        }
        private SliceSettingsCollection GetSliceSettings(string make, string model)
        {
            SliceSettingsCollection     collection   = null;
            Dictionary <string, string> settingsDict = LoadSliceSettingsFromFile(make, model);

            if (settingsDict.Count > 0)
            {
                collection      = new DataStorage.SliceSettingsCollection();
                collection.Name = this.ActivePrinter.Name;
                collection.Commit();

                this.ActivePrinter.DefaultSettingsCollectionId = collection.Id;
                this.ActivePrinter.Commit();

                foreach (KeyValuePair <string, string> item in settingsDict)
                {
                    DataStorage.SliceSetting sliceSetting = new DataStorage.SliceSetting();
                    sliceSetting.Name  = item.Key;
                    sliceSetting.Value = item.Value;
                    sliceSetting.SettingsCollectionId = collection.Id;
                    sliceSetting.Commit();
                }
            }
            return(collection);
        }
        private static void LoadDefaultConfigrationSettings(List <ClassicSettingsLayer> settings)
        {
            SliceSettingsCollection defaultCollection = new SliceSettingsCollection();

            defaultCollection.Name = "__default__";
            ClassicSettingsLayer defaultSettingsLayer = LoadConfigurationSettingsFromFile(Path.Combine("PrinterSettings", "config.ini"), defaultCollection);

            settings.Add(defaultSettingsLayer);
        }
        private void LoadDefaultConfigrationSettings()
        {
            SliceSettingsCollection defaultCollection = new SliceSettingsCollection();

            defaultCollection.Name = "__default__";
            SettingsLayer defaultSettingsLayer = LoadConfigurationSettingsFromFile(Path.Combine("PrinterSettings", "config.ini"), defaultCollection);

            this.activeSettingsLayers.Add(defaultSettingsLayer);
        }
        private SettingsLayer LoadConfigurationSettingsFromDatastore(SliceSettingsCollection collection)
        {
            Dictionary <string, SliceSetting> settingsDictionary = new Dictionary <string, SliceSetting>();

            foreach (SliceSetting s in GetCollectionSettings(collection.Id))
            {
                settingsDictionary[s.Name] = s;
            }

            return(new SettingsLayer(collection, settingsDictionary));
        }
 private void ValidateQualitySettings()
 {
     if (activePrinter != null)
     {
         int index = activePrinter.QualityCollectionId;
         SliceSettingsCollection collection = Datastore.Instance.dbSQLite.Table <SliceSettingsCollection>().Where(v => v.Id == index).Take(1).FirstOrDefault();
         if (collection == null)
         {
             ActivePrinterProfile.Instance.ActiveQualitySettingsID = 0;
         }
     }
 }
Beispiel #7
0
        public void ChangeToSlicePresetDetail(SliceSettingsCollection collection = null)
        {
            if (collection != null)
            {
                Dictionary <string, SliceSetting> settingsDictionary = new Dictionary <string, SliceSetting>();
                foreach (SliceSetting s in GetCollectionSettings(collection.Id))
                {
                    settingsDictionary[s.Name] = s;
                }

                this.ActivePresetLayer = new SettingsLayer(collection, settingsDictionary);
            }
            UiThread.RunOnIdle(DoChangeToSlicePresetDetail);
        }
 public void ChangeToSlicePresetDetail(SliceSettingsCollection collection = null)
 {
     if (collection != null)
     {
         Dictionary <string, DataStorage.SliceSetting> settingsDictionary = new Dictionary <string, DataStorage.SliceSetting>();
         IEnumerable <DataStorage.SliceSetting>        settingsList       = GetCollectionSettings(collection.Id);
         foreach (DataStorage.SliceSetting s in settingsList)
         {
             settingsDictionary[s.Name] = s;
         }
         this.ActivePresetLayer = new SettingsLayer(collection, settingsDictionary);
     }
     UiThread.RunOnIdle(DoChangeToSlicePresetDetail);
 }
        private static Dictionary <string, string> LoadSettings(SliceSettingsCollection collection)
        {
            var settings = Datastore.Instance.dbSQLite.Query <SliceSetting>(
                string.Format("SELECT * FROM SliceSetting WHERE SettingsCollectionID = " + collection.Id));

            var dictionary = new Dictionary <string, string>();

            foreach (var setting in settings)
            {
                // Not distinct on .Name; last value wins
                dictionary[setting.Name] = setting.Value;
            }

            return(dictionary);
        }
Beispiel #10
0
        public SliceSettingsCollection LoadDefaultSliceSettings(string make, string model)
        {
            SliceSettingsCollection     collection   = null;
            Dictionary <string, string> settingsDict = LoadSliceSettingsFromFile(GetDefaultPrinterSlicePath(make, model));

            if (settingsDict.Count > 0)
            {
                collection      = new DataStorage.SliceSettingsCollection();
                collection.Name = this.ActivePrinter.Name;
                collection.Commit();

                this.ActivePrinter.DefaultSettingsCollectionId = collection.Id;

                CommitSliceSettings(settingsDict, collection.Id);
            }
            return(collection);
        }
Beispiel #11
0
        bool OnSave()
        {
            if (printerNameInput.Text != "")
            {
                this.ActivePrinter.Name = printerNameInput.Text;
                if (this.ActivePrinter.Make == null || this.ActivePrinter.Model == null)
                {
                    return(false);
                }
                else
                {
                    //Load the default slice settings for the make and model combination - if they exist
                    SliceSettingsCollection collection = LoadDefaultSliceSettings(this.ActivePrinter.Make, this.ActivePrinter.Model);

                    if (defaultMovementSpeeds != null)
                    {
                        this.ActivePrinter.ManualMovementSpeeds = defaultMovementSpeeds;
                    }

                    //Ordering matters - need to get Id for printer prior to loading slice presets
                    this.ActivePrinter.AutoConnectFlag = true;
                    this.ActivePrinter.Commit();

                    LoadSlicePresets(this.ActivePrinter.Make, this.ActivePrinter.Model, "material");
                    LoadSlicePresets(this.ActivePrinter.Make, this.ActivePrinter.Model, "quality");



                    foreach (CustomCommands customCommand in printerCustomCommands)
                    {
                        customCommand.PrinterId = ActivePrinter.Id;
                        customCommand.Commit();
                    }

                    return(true);
                }
            }
            else
            {
                this.printerNameError.TextColor = RGBA_Bytes.Red;
                this.printerNameError.Text      = "Printer name cannot be blank";
                this.printerNameError.Visible   = true;
                return(false);
            }
        }
Beispiel #12
0
        private void onPresetLoad(OpenFileDialogParams openParams)
        {
            if (openParams.FileNames != null)
            {
                SliceSettingsCollection settingsCollection;
                try
                {
                    if (File.Exists(openParams.FileName))
                    {
                        //Create collection to hold preset settings
                        settingsCollection           = new SliceSettingsCollection();
                        settingsCollection.Tag       = windowController.filterTag;
                        settingsCollection.PrinterId = ActivePrinterProfile.Instance.ActivePrinter.Id;
                        settingsCollection.Name      = System.IO.Path.GetFileNameWithoutExtension(openParams.FileName);
                        settingsCollection.Commit();

                        string[] lines = System.IO.File.ReadAllLines(openParams.FileName);
                        foreach (string line in lines)
                        {
                            //Ignore commented lines
                            if (!line.StartsWith("#"))
                            {
                                string[] settingLine         = line.Split('=');
                                string   keyName             = settingLine[0].Trim();
                                string   settingDefaultValue = settingLine[1].Trim();

                                //To do - validate imported settings as valid (KP)
                                SliceSetting sliceSetting = new SliceSetting();
                                sliceSetting.Name  = keyName;
                                sliceSetting.Value = settingDefaultValue;
                                sliceSetting.SettingsCollectionId = settingsCollection.Id;
                                sliceSetting.Commit();
                            }
                        }
                        windowController.ChangeToSlicePresetList();
                    }
                }
                catch (Exception)
                {
                    // Error loading configuration
                }
            }
        }
 private void ValidateMaterialSettings()
 {
     if (activePrinter != null && activePrinter.MaterialCollectionIds != null)
     {
         string[] activeMaterialPresets = activePrinter.MaterialCollectionIds.Split(',');
         for (int i = 0; i < activeMaterialPresets.Count(); i++)
         {
             int index = 0;
             Int32.TryParse(activeMaterialPresets[i], out index);
             if (index != 0)
             {
                 SliceSettingsCollection collection = Datastore.Instance.dbSQLite.Table <SliceSettingsCollection>().Where(v => v.Id == index).Take(1).FirstOrDefault();
                 if (collection == null)
                 {
                     ActivePrinterProfile.Instance.SetMaterialSetting(i + 1, 0);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Loads a SliceSettingsCollection from StaticData PrinterSettings
        /// </summary>
        /// <param name="make">The make to load</param>
        /// <param name="model">The model to load</param>
        public SliceSettingsCollection LoadSettingsFromConfigFile(string make, string model)
        {
            Dictionary <string, string> settingsDict = LoadSliceSettingsFromFile(Path.Combine("PrinterSettings", make, model, "config.ini"));

            if (settingsDict.Count > 0)
            {
                SliceSettingsCollection collection = new SliceSettingsCollection();
                collection.Name = this.ActivePrinter.Name;
                collection.Commit();

                this.ActivePrinter.DefaultSettingsCollectionId = collection.Id;

                CommitSliceSettings(settingsDict, collection.Id);

                return(collection);
            }

            // Return null if the loaded settings dictionary was empty
            return(null);
        }
        public static PrinterSettingsLayer LoadOemLayer(Printer printer)
        {
            SliceSettingsCollection collection;

            if (printer.DefaultSettingsCollectionId != 0)
            {
                int activePrinterSettingsID = printer.DefaultSettingsCollectionId;
                collection = Datastore.Instance.dbSQLite.Table <SliceSettingsCollection>().Where(v => v.Id == activePrinterSettingsID).Take(1).FirstOrDefault();
            }
            else
            {
                collection      = new SliceSettingsCollection();
                collection.Name = printer.Name;
                collection.Commit();

                printer.DefaultSettingsCollectionId = collection.Id;
            }

            return(new PrinterSettingsLayer(LoadSettings(collection)));
        }
        void duplicatePresets_Click(object sender, MouseEventArgs mouseEvent)
        {
            UiThread.RunOnIdle((state) =>
            {
                DataStorage.SliceSettingsCollection duplicateCollection = new SliceSettingsCollection();
                duplicateCollection.Name      = string.Format("{0} (copy)".FormatWith(windowController.ActivePresetLayer.settingsCollectionData.Name));
                duplicateCollection.Tag       = windowController.ActivePresetLayer.settingsCollectionData.Tag;
                duplicateCollection.PrinterId = windowController.ActivePresetLayer.settingsCollectionData.PrinterId;


                Dictionary <string, DataStorage.SliceSetting> settingsDictionary = new Dictionary <string, DataStorage.SliceSetting>();
                IEnumerable <DataStorage.SliceSetting> settingsList = this.windowController.GetCollectionSettings(windowController.ActivePresetLayer.settingsCollectionData.Id);
                foreach (DataStorage.SliceSetting s in settingsList)
                {
                    settingsDictionary[s.Name] = s;
                }
                SettingsLayer duplicateLayer       = new SettingsLayer(duplicateCollection, settingsDictionary);
                windowController.ActivePresetLayer = duplicateLayer;
                windowController.ChangeToSlicePresetDetail();
            });
        }
        public void LoadPrinterConfigurationSettings()
        {
            if (ActivePrinterProfile.Instance.ActivePrinter != null)
            {
                SliceSettingsCollection collection;
                if (ActivePrinterProfile.Instance.ActivePrinter.DefaultSettingsCollectionId != 0)
                {
                    int activePrinterSettingsID = ActivePrinterProfile.Instance.ActivePrinter.DefaultSettingsCollectionId;
                    collection = Datastore.Instance.dbSQLite.Table <SliceSettingsCollection>().Where(v => v.Id == activePrinterSettingsID).Take(1).FirstOrDefault();
                }
                else
                {
                    collection      = new SliceSettingsCollection();
                    collection.Name = ActivePrinterProfile.Instance.ActivePrinter.Name;
                    collection.Commit();

                    ActivePrinterProfile.Instance.ActivePrinter.DefaultSettingsCollectionId = collection.Id;
                    ActivePrinterProfile.Instance.ActivePrinter.Commit();
                }
                SettingsLayer printerSettingsLayer = LoadConfigurationSettingsFromDatastore(collection);
                this.activeSettingsLayers.Add(printerSettingsLayer);
            }
        }
Beispiel #18
0
        public void Save()
        {
            //Load the default slice settings for the make and model combination - if they exist
            SliceSettingsCollection collection = LoadDefaultSliceSettings(this.ActivePrinter.Make, this.ActivePrinter.Model);

            if (defaultMovementSpeeds != null)
            {
                this.ActivePrinter.ManualMovementSpeeds = defaultMovementSpeeds;
            }

            //Ordering matters - need to get Id for printer prior to loading slice presets
            this.ActivePrinter.AutoConnectFlag = true;
            this.ActivePrinter.Commit();

            LoadSlicePresets(this.ActivePrinter.Make, this.ActivePrinter.Model, "material");
            LoadSlicePresets(this.ActivePrinter.Make, this.ActivePrinter.Model, "quality");

            foreach (CustomCommands customCommand in printerCustomCommands)
            {
                customCommand.PrinterId = ActivePrinter.Id;
                customCommand.Commit();
            }
        }
        public string GetMaterialValue(string sliceSetting, int extruderNumber1Based)
        {
            int    numberOfActiveLayers = activeSettingsLayers.Count;
            string settingValue         = null;

            if (ActivePrinterProfile.Instance.GetMaterialSetting(extruderNumber1Based) != 0)
            {
                int materialOneSettingsID                    = ActivePrinterProfile.Instance.GetMaterialSetting(extruderNumber1Based);
                SliceSettingsCollection collection           = Datastore.Instance.dbSQLite.Table <SliceSettingsCollection>().Where(v => v.Id == materialOneSettingsID).Take(1).FirstOrDefault();
                SettingsLayer           printerSettingsLayer = LoadConfigurationSettingsFromDatastore(collection);
                if (printerSettingsLayer.settingsDictionary.ContainsKey(sliceSetting))
                {
                    settingValue = printerSettingsLayer.settingsDictionary[sliceSetting].Value;
                }
            }

            if (settingValue == null)
            {
                //Go through settings layers one-by-one, starting with quality (index = 2), in reverse order, until we find a layer that contains the value
                int startingLayer = Math.Min(numberOfActiveLayers - 1, 2);
                for (int i = startingLayer; i >= 0; i--)
                {
                    if (activeSettingsLayers[i].settingsDictionary.ContainsKey(sliceSetting))
                    {
                        settingValue = activeSettingsLayers[i].settingsDictionary[sliceSetting].Value;
                        return(settingValue);
                    }
                }
            }

            if (settingValue == null)
            {
                settingValue = "Unknown";
            }

            return(settingValue);
        }
        bool OnSave()
        {
            if (printerNameInput.Text != "")
            {
                this.ActivePrinter.Name = printerNameInput.Text;
                if (this.ActivePrinter.Make == null || this.ActivePrinter.Model == null)
                {
                    return(false);
                }
                else
                {
                    //Load the default slice settings for the make and model combination - if they exist
                    SliceSettingsCollection collection = GetSliceSettings(this.ActivePrinter.Make, this.ActivePrinter.Model);
                    if (collection != null)
                    {
                        this.ActivePrinter.DefaultSettingsCollectionId = collection.Id;
                    }
                    this.ActivePrinter.AutoConnectFlag = true;
                    this.ActivePrinter.Commit();

                    foreach (CustomCommands customCommand in printerCustomCommands)
                    {
                        customCommand.PrinterId = ActivePrinter.Id;
                        customCommand.Commit();
                    }

                    return(true);
                }
            }
            else
            {
                this.printerNameError.TextColor = RGBA_Bytes.Red;
                this.printerNameError.Text      = "Printer name cannot be blank";
                this.printerNameError.Visible   = true;
                return(false);
            }
        }
 public ClassicSettingsLayer(SliceSettingsCollection settingsCollection, Dictionary <string, SliceSetting> settingsDictionary)
 {
     this.settingsCollectionData = settingsCollection;
     this.settingsDictionary     = settingsDictionary;
 }
        private static ClassicSettingsLayer LoadConfigurationSettingsFromFile(string pathAndFileName, SliceSettingsCollection collection)
        {
            Dictionary <string, SliceSetting> settingsDictionary = new Dictionary <string, SliceSetting>();
            ClassicSettingsLayer activeCollection;

            try
            {
                if (StaticData.Instance.FileExists(pathAndFileName))
                {
                    foreach (string line in StaticData.Instance.ReadAllLines(pathAndFileName))
                    {
                        //Ignore commented lines
                        if (!line.StartsWith("#"))
                        {
                            string[] settingLine         = line.Split('=');
                            string   keyName             = settingLine[0].Trim();
                            string   settingDefaultValue = settingLine[1].Trim();

                            SliceSetting sliceSetting = new SliceSetting();
                            sliceSetting.Name  = keyName;
                            sliceSetting.Value = settingDefaultValue;

                            settingsDictionary.Add(keyName, sliceSetting);
                        }
                    }
                    activeCollection = new ClassicSettingsLayer(collection, settingsDictionary);
                    return(activeCollection);
                }
                return(null);
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
                GuiWidget.BreakInDebugger();
                Debug.WriteLine(string.Format("Error loading configuration: {0}", e));
                return(null);
            }
        }
Beispiel #23
0
            public PresetListItem(SlicePresetsWindow windowController, SliceSettingsCollection preset)
            {
                this.preset          = preset;
                this.BackgroundColor = RGBA_Bytes.White;
                this.HAnchor         = HAnchor.ParentLeftRight;
                this.Margin          = new BorderDouble(6, 0, 6, 3);
                this.Padding         = new BorderDouble(3);

                LinkButtonFactory linkButtonFactory = new LinkButtonFactory();

                linkButtonFactory.fontSize = 10;

                int        maxLabelWidth = 300;
                TextWidget materialLabel = new TextWidget(preset.Name, pointSize: 14);

                materialLabel.EllipsisIfClipped = true;
                materialLabel.VAnchor           = Agg.UI.VAnchor.ParentCenter;
                materialLabel.MinimumSize       = new Vector2(maxLabelWidth, materialLabel.Height);
                materialLabel.Width             = maxLabelWidth;

                Button materialEditLink = linkButtonFactory.Generate("edit");

                materialEditLink.VAnchor = Agg.UI.VAnchor.ParentCenter;
                materialEditLink.Click  += (sender, e) =>
                {
                    UiThread.RunOnIdle(() =>
                    {
                        windowController.ChangeToSlicePresetDetail(preset);
                    });
                };

                Button materialRemoveLink = linkButtonFactory.Generate("remove");

                materialRemoveLink.Margin  = new BorderDouble(left: 4);
                materialRemoveLink.VAnchor = Agg.UI.VAnchor.ParentCenter;
                materialRemoveLink.Click  += (sender, e) =>
                {
                    UiThread.RunOnIdle(() =>
                    {
                        //Unwind this setting if it is currently active
                        if (ActivePrinterProfile.Instance.ActivePrinter != null)
                        {
                            if (preset.Id == ActivePrinterProfile.Instance.ActiveQualitySettingsID)
                            {
                                ActivePrinterProfile.Instance.ActiveQualitySettingsID = 0;
                            }

                            string[] activeMaterialPresets = ActivePrinterProfile.Instance.ActivePrinter.MaterialCollectionIds.Split(',');
                            for (int i = 0; i < activeMaterialPresets.Count(); i++)
                            {
                                int index = 0;
                                Int32.TryParse(activeMaterialPresets[i], out index);
                                if (preset.Id == index)
                                {
                                    ActivePrinterProfile.Instance.SetMaterialSetting(i + 1, 0);
                                }
                            }
                        }
                        preset.Delete();
                        windowController.ChangeToSlicePresetList();
                        ActiveSliceSettings.Instance.LoadAllSettings();
                        ApplicationController.Instance.ReloadAdvancedControlsPanel();
                    });
                };

                this.AddChild(materialLabel);
                this.AddChild(new HorizontalSpacer());
                this.AddChild(materialEditLink);
                this.AddChild(materialRemoveLink);

                this.Height = 35;
            }