Ejemplo n.º 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);
                }
            }
        }
        public void SetMaterialSetting(int extruderPosition, int settingId)
        {
            string[] newMaterialSettingsArray;
            string[] currentMaterialSettingsArray;

            string materialSettings = ActivePrinter.MaterialCollectionIds;

            if (materialSettings != null)
            {
                currentMaterialSettingsArray = materialSettings.Split(',');
            }
            else
            {
                currentMaterialSettingsArray = new string[extruderPosition];
            }

            //Resize the array of material settings if necessary
            if (currentMaterialSettingsArray.Count() < extruderPosition)
            {
                newMaterialSettingsArray = new string[extruderPosition];
                for (int i = 0; i < currentMaterialSettingsArray.Length; i++)
                {
                    newMaterialSettingsArray[i] = currentMaterialSettingsArray[i];
                }
            }
            else
            {
                newMaterialSettingsArray = currentMaterialSettingsArray;
            }
            newMaterialSettingsArray[extruderPosition - 1] = settingId.ToString();

            ActivePrinter.MaterialCollectionIds = String.Join(",", newMaterialSettingsArray);
            ActivePrinter.Commit();
        }
Ejemplo n.º 3
0
 public void SetPrintLevelingProbePositions(double[] printLevelingPositions3_xyz)
 {
     if (ActivePrinter != null)
     {
         ActivePrinter.SetPrintLevelingPositions(printLevelingPositions3_xyz);
         ActivePrinter.Commit();
     }
 }
Ejemplo n.º 4
0
        private static void ParsePrintersStatus()
        {
            int    active_printer     = 0;
            bool   result             = false;
            string DefaultPrinterName = null;

            active_printer         = (int)QueryPref("ActivePrinterIsDefault", active_printer);
            ActivePrinterIsDefault = (ActivePrinter)active_printer;

            if (ActivePrinterIsDefault == ActivePrinter.SET_ACTIVE_AS_DEFAULT ||
                ActivePrinterIsDefault == ActivePrinter.SET_ACTIVE_USB_PRINTER)
            {
                ManagementObjectSearcher searcher;
                searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer WHERE Default = True");
                foreach (ManagementObject defPrinter in searcher.Get())
                {
                    if (defPrinter["WorkOffline"].ToString().ToLowerInvariant() == "false")
                    {
                        Log.Info("Default Printer " + defPrinter["Name"].ToString() + "is Online");
                        break;
                    }
                    Log.Info("Default printer is not online. Try to finde online printer");
                    DefaultPrinterName = defPrinter["Name"].ToString();
                    if (ActivePrinterIsDefault == ActivePrinter.SET_ACTIVE_USB_PRINTER)
                    {
                        searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer WHERE PortName LIKE '%USB%'");
                    }
                    else
                    {
                        searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer WHERE Default = False");
                    }
                    foreach (ManagementObject defPrint in searcher.Get())
                    {
                        defPrint.InvokeMethod("SetDefaultPrinter", new object[] { defPrint["Name"].ToString() });
                        if (defPrint["WorkOffline"].ToString().ToLowerInvariant() == "false")
                        {
                            Log.Info("Set Printer " + defPrint["Name"].ToString() + "as Default");
                            result = true;
                            break;
                        }
                    }
                    if (!result)
                    {
                        if (!String.IsNullOrEmpty(DefaultPrinterName))
                        {
                            //If we did not finde enything, restore original
                            defPrinter.InvokeMethod("SetDefaultPrinter", new object[] { DefaultPrinterName });
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This function returns one of the three positions that will be probed when setting
        /// up print leveling.
        /// </summary>
        /// <param name="position0To2"></param>
        /// <returns></returns>
        public Vector3 GetPrintLevelingProbePosition(int position0To2)
        {
            if (ActivePrinter != null)
            {
                double[] positions = ActivePrinter.GetPrintLevelingPositions();
                switch (position0To2)
                {
                case 0:
                    return(new Vector3(positions[0], positions[1], positions[2]));

                case 1:
                    return(new Vector3(positions[3], positions[4], positions[5]));

                case 2:
                    return(new Vector3(positions[6], positions[7], positions[8]));

                default:
                    throw new Exception("there are only 3 probe positions.");
                }
            }

            return(Vector3.Zero);
        }