示例#1
0
        static ProjectOptions GetSavedOptions(string addin_ini_fpath, string fc_doc_ini_fpath)
        {
            LogFile.Write(String.Format("Reading options from {0}", fc_doc_ini_fpath));

            ProjectOptions options = new ProjectOptions();

            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(options.GetType());
            TextReader reader = new StreamReader(fc_doc_ini_fpath);

            options = (ProjectOptions)serializer.Deserialize(reader);
            reader.Close();

            return(options);
        }
        public static void SaveOptions(ProjectOptions options, string addin_ini_fpath)
        {
            if (Variables.doc.path == "")
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("Cannot save selected options to the file. File needs to be saved first."));
                LogFile.Write("Cannot save selected options to the file. File needs to be saved first.");
                return;
            }

            File.WriteAllText(@"C:\ProgramData\FeatureCAM\vericut_addin.ini",
                              string.Format("VERICUT_PATH={0}", Variables.vericut_fpath));

            /* This function will save shared options to addin ini file
             * and
             * project specific options to doc ini file
             */
            if (options.all_setup_options == null)
            {
                options.all_setup_options = new List <FeatureCAMExporter.SetupOptions>();
            }
            else
            {
                options.all_setup_options.Clear();
            }
            for (int i = 0; i < Variables.setups_info.Count; i++)
            {
                Variables.setups_info[i].options.clamps        = Variables.setups_info[i].clamps;
                Variables.setups_info[i].options.parts         = Variables.setups_info[i].part;
                Variables.setups_info[i].options.fixture       = Variables.setups_info[i].fixture_id;
                Variables.setups_info[i].options.offsets       = Variables.setups_info[i].work_offsets;
                Variables.setups_info[i].options.is_subspindle = Variables.setups_info[i].sub_spindle;

                options.all_setup_options.Add(Variables.setups_info[i].options);
            }
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(options.GetType());
            System.Xml.XmlWriterSettings           settings   = new System.Xml.XmlWriterSettings();
            settings.NewLineChars        = Environment.NewLine;
            settings.NewLineOnAttributes = true;
            settings.Indent             = true;
            settings.NewLineHandling    = System.Xml.NewLineHandling.Replace;
            settings.OmitXmlDeclaration = true;
            settings.CloseOutput        = true;
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(Variables.doc_ini_fpath, settings);
            serializer.Serialize(writer, options);
            writer.Close();
        }