Esempio n. 1
0
        internal static void ImportFromExisting(string settingsFilePath)
        {
            if (string.IsNullOrEmpty(settingsFilePath) || !File.Exists(settingsFilePath))
            {
                return;
            }

            var printerIdentifier = new PrinterInfo
            {
                Name = Path.GetFileNameWithoutExtension(settingsFilePath),
                Id   = Guid.NewGuid().ToString()
            };

            string importType = Path.GetExtension(settingsFilePath).ToLower();

            switch (importType)
            {
            case ".printer":
                var profile = LoadProfileFromDisk(settingsFilePath);
                profile.ID = Guid.NewGuid().ToString();
                break;

            case ".ini":
                var settingsToImport = SettingsLayer.LoadFromIni(settingsFilePath);

                var           oemProfile = new OemProfile(settingsToImport);
                SettingsLayer baseConfig = SliceSettingsOrganizer.Instance.GetDefaultSettings();

                var layeredProfile = new LayeredProfile(oemProfile, baseConfig)
                {
                    ID           = printerIdentifier.Id,
                    DocumentPath = Path.Combine(profilesPath, printerIdentifier.Id + ".json")
                };

                // TODO: Resolve name conflicts
                layeredProfile.UserLayer["MatterControl.PrinterName"] = printerIdentifier.Name;
                layeredProfile.Save();

                break;
            }

            ProfileData.Profiles.Add(printerIdentifier);

            UserSettings.Instance.set("ActiveProfileID", printerIdentifier.Id);

            Instance = LoadProfile(printerIdentifier.Id);
        }
Esempio n. 2
0
 private static SettingsProfile LoadProfileFromDisk(string profilePath)
 {
     return(new SettingsProfile(LayeredProfile.LoadFile(profilePath)));
 }
Esempio n. 3
0
        internal static void AcquireNewProfile(string make, string model, string printerName)
        {
            string guid = Guid.NewGuid().ToString();

            OemProfile    printerProfile = LoadHttpOemProfile(make, model);
            SettingsLayer baseConfig     = SliceSettingsOrganizer.Instance.GetDefaultSettings();

            var layeredProfile = new LayeredProfile(printerProfile, baseConfig)
            {
                ID           = guid,
                DocumentPath = Path.Combine(profilesPath, guid + ".json")
            };

            layeredProfile.UserLayer["MatterControl.PrinterName"] = printerName;

            // Import named macros as defined in the following printers: (Airwolf Axiom, HD, HD-R, HD2x, HDL, HDx, Me3D Me2, Robo R1[+])
            var classicDefaultMacros = layeredProfile.GetValue("default_macros");

            if (!string.IsNullOrEmpty(classicDefaultMacros))
            {
                var namedMacros = new Dictionary <string, string>();
                namedMacros["Lights On"]  = "M42 P6 S255";
                namedMacros["Lights Off"] = "M42 P6 S0";
                namedMacros["Offset 0.8"] = "M565 Z0.8;\nM500";
                namedMacros["Offset 0.9"] = "M565 Z0.9;\nM500";
                namedMacros["Offset 1"]   = "M565 Z1;\nM500";
                namedMacros["Offset 1.1"] = "M565 Z1.1;\nM500";
                namedMacros["Offset 1.2"] = "M565 Z1.2;\nM500";
                namedMacros["Z Offset"]   = "G1 Z10;\nG28;\nG29;\nG1 Z10;\nG1 X5 Y5 F4000;\nM117;";

                foreach (string namedMacro in classicDefaultMacros.Split(','))
                {
                    string gcode;
                    if (namedMacros.TryGetValue(namedMacro.Trim(), out gcode))
                    {
                        layeredProfile.Macros.Add(new GCodeMacro()
                        {
                            Name  = namedMacro.Trim(),
                            GCode = gcode
                        });
                    }
                }
            }

            // Copy OemProfile presets into user layers
            layeredProfile.MaterialLayers.AddRange(layeredProfile.OemProfile.MaterialLayers);
            layeredProfile.QualityLayers.AddRange(layeredProfile.OemProfile.QualityLayers);

            layeredProfile.OemProfile.MaterialLayers.Clear();
            layeredProfile.OemProfile.QualityLayers.Clear();

            layeredProfile.Save();

            ProfileData.Profiles.Add(new PrinterInfo
            {
                Name = printerName,
                Id   = guid
            });

            UserSettings.Instance.set("ActiveProfileID", guid);

            Instance = new SettingsProfile(layeredProfile);
        }
Esempio n. 4
0
        static ActiveSliceSettings()
        {
            // Ensure the profiles directory exists
            Directory.CreateDirectory(profilesPath);

            if (true)
            {
                ProfileData = new ProfileData();

                if (!File.Exists(profilesDBPath))
                {
                    // Import class profiles from the db into local json files
                    DataStorage.ClassicDB.ClassicSqlitePrinterProfiles.ImportPrinters(ProfileData, profilesPath);
                    File.WriteAllText(profilesDBPath, JsonConvert.SerializeObject(ProfileData, Formatting.Indented));

                    // TODO: Upload new profiles to webservice
                }

                ProfileData.Profiles.CollectionChanged += Profiles_CollectionChanged;

                foreach (string filePath in Directory.GetFiles(profilesPath, "*.json"))
                {
                    string fileName = Path.GetFileName(filePath);
                    if (fileName == "config.json" || fileName == "profiles.json")
                    {
                        continue;
                    }

                    try
                    {
                        var profile = new SettingsProfile(LayeredProfile.LoadFile(filePath));
                        ProfileData.Profiles.Add(new PrinterInfo()
                        {
                            AutoConnect = profile.DoAutoConnect(),
                            BaudRate    = profile.BaudRate(),
                            ComPort     = profile.ComPort(),
                            DriverType  = profile.DriverType(),
                            Id          = profile.ID,
                            Make        = profile.Make,
                            Model       = profile.Model,
                            Name        = profile.Name(),
                        });
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Error loading profile: {1}\r\n{2}", filePath, ex.Message);
                    }
                }
            }
            else
            {
                // Load or import the profiles.json document
                if (File.Exists(profilesDBPath))
                {
                    ProfileData = JsonConvert.DeserializeObject <ProfileData>(File.ReadAllText(profilesDBPath));
                }
                else
                {
                    ProfileData = new ProfileData();

                    // Import class profiles from the db into local json files
                    DataStorage.ClassicDB.ClassicSqlitePrinterProfiles.ImportPrinters(ProfileData, profilesPath);
                    File.WriteAllText(profilesDBPath, JsonConvert.SerializeObject(ProfileData, Formatting.Indented));

                    // TODO: Upload new profiles to webservice
                }
            }

            ActiveSliceSettings.LoadStartupProfile();
        }
Esempio n. 5
0
 internal SettingsProfile(LayeredProfile profile)
 {
     layeredProfile = profile;
 }
		public static void LoadQualitySettings(LayeredProfile layeredProfile, Printer printer)
		{
			var collections = Datastore.Instance.dbSQLite.Table<SliceSettingsCollection>().Where(v => v.PrinterId == printer.Id && v.Tag == "quality");
			foreach (var collection in collections)
			{
				var settingsDictionary = LoadSettings(collection);
				layeredProfile.QualityLayers[collection.Name] = new SettingsLayer(settingsDictionary);
			}
		}
		private static void LoadMaterialSettings(LayeredProfile layeredProfile, Printer printer)
		{
			var materialAssignments = printer.MaterialCollectionIds.Split(',');

			var collections = Datastore.Instance.dbSQLite.Table<SliceSettingsCollection>().Where(v => v.PrinterId == printer.Id && v.Tag == "material");
			foreach (var collection in collections)
			{
				var settingsDictionary = LoadSettings(collection);
				layeredProfile.MaterialLayers[collection.Name] = new SettingsLayer(settingsDictionary);
			}
		}
Esempio n. 8
0
		internal SettingsProfile(LayeredProfile profile)
		{
			layeredProfile = profile;
		}
		internal static void AcquireNewProfile(string make, string model, string printerName)
		{
			string guid = Guid.NewGuid().ToString();

			OemProfile printerProfile = LoadHttpOemProfile(make, model);
			SettingsLayer baseConfig = LoadMatterHackersBaseLayer();

			var layeredProfile = new LayeredProfile(
				printerProfile, 
				baseConfig);
			layeredProfile.DocumentPath = Path.Combine(profilesPath, guid + ".json");
			layeredProfile.Save();

			ProfileData.Profiles.Add(new PrinterInfo
			{
				Name = printerName,
				Id = guid
			});

			Instance = new SettingsProfile(layeredProfile);
		}