Exemplo n.º 1
0
        private static void CheckTLBCompatibility()
        {
            Version vnum = new Version(1, 0, 0, 0);

            try
            {
                try
                {
                    vnum = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion);
                }
                catch { }

                // the featurecam tlb version is a property on the app now adays...
                // if the app doesn't have that propety, the next line will throw a com exception
                if (fc.MajorTLBVersionNum != vnum.Build)
                {
                    MessageDisplay.ShowWarning(
                        LanguageSupport.Translate("Warning: This dll add-in was compiled against v{0} of FeatureCAM tlb."), vnum.Build.ToString());
                }
            }
            catch
            {
                // must be tlb version 1?
                MessageDisplay.ShowWarning(
                    LanguageSupport.Translate("Warning: This dll add-in was compiled against v{0} of FeatureCAM tlb, and should not be run with older versions of FeatureCAM."), vnum.Build.ToString());
            }
        }
Exemplo n.º 2
0
        private void StartVericut()
        {
            try
            {
                if (!File.Exists(Variables.vericut_fpath))
                {
                    MessageDisplay.ShowError(
                        LanguageSupport.Translate("Vericut path {0} is invalid. The file doesn't exist."), Variables.vericut_fpath);
                    return;
                }
                if (!File.Exists(Variables.vcproj_fpath))
                {
                    MessageDisplay.ShowError(
                        LanguageSupport.Translate("Vericut project {0} doesn't exist. Can't open it in VERICUT."), Variables.vcproj_fpath);
                    return;
                }

                using (Process proc = new Process())
                {
                    proc.StartInfo.FileName    = Variables.vericut_fpath;
                    proc.StartInfo.Arguments   = String.Format("\"{0}\"", Variables.vcproj_fpath);
                    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    proc.Start();
                    proc.WaitForExit(0);
                    if (proc != null)
                    {
                        proc.Dispose();
                    }
                }
            }
            catch (Exception Ex)
            {
                LogFile.WriteException(Ex, "StartVericut");
            }
        }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (cb_solids.CheckedItems.Count == 0)
            {
                return;
            }

            if (cb_export_as.SelectedItem == null)
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("You have to select whether to export selected solids as clamps or design."));
                return;
            }
            if (cb_attach_to.SelectedItem == null)
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("You have to select attach component."));
                return;
            }

            selected_solids = new List <string>();
            for (int i = 0; i < cb_solids.CheckedItems.Count; i++)
            {
                selected_solids.Add(cb_solids.CheckedItems[i].ToString());
            }
            attach_to       = cb_attach_to.SelectedItem.ToString();
            export_as_clamp = (cb_export_as.SelectedIndex == 0);

            fm_doc = null;
            this.Close();
        }
Exemplo n.º 4
0
        public UCSsDlg_TurnMill(int selected_setup_index)
        {
            setup_index = selected_setup_index;
            InitializeComponent();

            this.Text       = LanguageSupport.Translate(this.Text);
            label2.Text     = LanguageSupport.Translate(label2.Text);
            label7.Text     = LanguageSupport.Translate(label7.Text);
            label4.Text     = LanguageSupport.Translate(label4.Text);
            label5.Text     = LanguageSupport.Translate(label5.Text);
            label1.Text     = LanguageSupport.Translate(label1.Text);
            label3.Text     = LanguageSupport.Translate(label3.Text);
            btn_OK.Text     = LanguageSupport.Translate(btn_OK.Text);
            btn_Cancel.Text = LanguageSupport.Translate(btn_Cancel.Text);

            cb_attach_ucss_to_subspindle.Enabled = !Variables.are_all_setups_milling;
            label3.Enabled = !Variables.are_all_setups_milling;
            /* Attach axis */
            cb_attach_ucss_to.Items.Clear();
            cb_attach_ucss_to_subspindle.Items.Clear();
            if (Variables.setups_info[setup_index].attach_components != null)
            {
                foreach (string attach_comp in Variables.setups_info[setup_index].attach_components)
                {
                    cb_attach_ucss_to.Items.Add(attach_comp);
                    cb_attach_ucss_to_subspindle.Items.Add(attach_comp);
                }
            }
            if (Variables.setups_info[setup_index].attach_ucss_to != "" && cb_attach_ucss_to.Items.Contains(Variables.setups_info[setup_index].attach_ucss_to))
            {
                cb_attach_ucss_to.SelectedItem = Variables.setups_info[setup_index].attach_ucss_to;
            }
            if (Variables.setups_info[setup_index].attach_ucss_to_subspindle != "" && cb_attach_ucss_to_subspindle.Items.Contains(Variables.setups_info[setup_index].attach_ucss_to_subspindle))
            {
                cb_attach_ucss_to_subspindle.SelectedItem = Variables.setups_info[setup_index].attach_ucss_to_subspindle;
            }

            cb_ucs_location.Items.Clear();
            cb_ucs_location_subspindle.Items.Clear();
            if (Variables.all_ucss != null)
            {
                foreach (UCS ucs in Variables.all_ucss)
                {
                    cb_ucs_location.Items.Add(ucs.name);
                    cb_ucs_location_subspindle.Items.Add(ucs.name);
                }
            }
            if (Variables.setups_info[setup_index].attach_ucs != "" && cb_ucs_location.Items.Contains(Variables.setups_info[setup_index].attach_ucs))
            {
                cb_ucs_location.SelectedItem = Variables.setups_info[setup_index].attach_ucs;
            }
            if (Variables.setups_info[setup_index].attach_ucs_subspindle != "" && cb_ucs_location.Items.Contains(Variables.setups_info[setup_index].attach_ucs_subspindle))
            {
                cb_ucs_location_subspindle.SelectedItem = Variables.setups_info[setup_index].attach_ucs_subspindle;
            }
        }
Exemplo n.º 5
0
 private void b_select_output_dir_Click(object sender, EventArgs e)
 {
     outputDirBrowserDialog1.Description  = LanguageSupport.Translate("Select output directory");
     outputDirBrowserDialog1.SelectedPath = Variables.doc_options.output_dirpath;
     if (outputDirBrowserDialog1.ShowDialog() == DialogResult.OK)
     {
         tb_output_dir.Text = outputDirBrowserDialog1.SelectedPath;
         Variables.doc_options.output_dirpath = tb_output_dir.Text;
     }
 }
Exemplo n.º 6
0
 private void b_select_setup_template_Click(object sender, EventArgs e)
 {
     openSetupTemplateFileDialog1.Filter          = LanguageSupport.Translate("VCPROJECT file (*.vcproject)|*.vcproject");
     openSetupTemplateFileDialog1.FileName        = "";
     openSetupTemplateFileDialog1.CheckFileExists = true;
     openSetupTemplateFileDialog1.Title           = LanguageSupport.Translate("Select template VERICUT project for the setup");
     if (openSetupTemplateFileDialog1.ShowDialog() == DialogResult.OK)
     {
         tb_setup_template_fpath.Text = openSetupTemplateFileDialog1.FileName;
         Variables.setups_info[cb_setups.SelectedIndex].options.template_fpath = tb_setup_template_fpath.Text;
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static public void FeatureCAMToVericut()
        {
            LanguageSupport.InitializeTranslation(fc.CurrentLanguage, @"Localization");
            CheckTLBCompatibility();
            if (!IsLicensedProperly())
            {
                return;
            }

            Variables.doc = (FeatureCAM.FMDocument)fc.ActiveDocument;
            if (Variables.doc == null)
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("No files are open"));
                return;
            }

            if (File.Exists(@"C:\ProgramData\FeatureCAM\vericut_addin.ini"))
            {
                Variables.vericut_fpath = File.ReadAllText(@"C:\ProgramData\FeatureCAM\vericut_addin.ini").Replace("VERICUT_PATH=", "").Trim();
            }

            if (Variables.doc.path != "")
            {
                Variables.doc_ini_fpath = Variables.doc.FullName + ".fcvini";
                LogFile.SetLogFilePath(Variables.doc.FullName + ".log");
                if (File.Exists(Variables.doc_ini_fpath))
                {
                    Variables.doc_options = GetSavedOptions("", Variables.doc_ini_fpath);
                    Variables.doc_options.read_from_file = true;
                }
            }

            Init.InitializeVariables();

            // helper function to force a single instance of plugin form
            if (main_form != null)
            {
                main_form.BringToFront();
            }
            else
            {
                LogFile.Write("Initialize form");
                main_form = new MainForm();
                LogFile.Write("Display form");
                main_form.Show();
                main_form.TopLevel = true;
                main_form.TopMost  = true;
                System.Windows.Forms.Application.Run(main_form);
            }
        }
Exemplo n.º 8
0
        public MainForm()
        {
            InitializeComponent();
            label1.Text = LanguageSupport.Translate(label1.Text);
            b_select_output_dir.Text = LanguageSupport.Translate(b_select_output_dir.Text);
            label3.Text                  = LanguageSupport.Translate(label3.Text);
            b_select_template.Text       = LanguageSupport.Translate(b_select_template.Text);
            label9.Text                  = LanguageSupport.Translate(label9.Text);
            cb_ucs_transition.Text       = LanguageSupport.Translate(cb_ucs_transition.Text);
            cb_combine_setups.Text       = LanguageSupport.Translate(cb_combine_setups.Text);
            groupBox1.Text               = LanguageSupport.Translate(groupBox1.Text);
            label5.Text                  = LanguageSupport.Translate(label5.Text);
            b_select_setup_template.Text = LanguageSupport.Translate(b_select_setup_template.Text);
            cb_export_nc.Text            = LanguageSupport.Translate(cb_export_nc.Text);
            cb_export_tools.Text         = LanguageSupport.Translate(cb_export_tools.Text);
            btn_toolOptions.Text         = LanguageSupport.Translate(btn_toolOptions.Text);
            label2.Text                  = LanguageSupport.Translate(label2.Text);
            btn_UCSs.Text                = LanguageSupport.Translate(btn_UCSs.Text);
            label8.Text                  = LanguageSupport.Translate(label8.Text);
            btn_StockDesign.Text         = LanguageSupport.Translate(btn_StockDesign.Text);
            label10.Text                 = LanguageSupport.Translate(label10.Text);
            btn_Fixtures.Text            = LanguageSupport.Translate(btn_Fixtures.Text);
            label6.Text                  = LanguageSupport.Translate(label6.Text);
            btn_WorkOffsets.Text         = LanguageSupport.Translate(btn_WorkOffsets.Text);
            btn_MachineTurretInfo.Text   = LanguageSupport.Translate(btn_MachineTurretInfo.Text);
            btn_ExportAndLoadVC.Text     = LanguageSupport.Translate(btn_ExportAndLoadVC.Text);
            btn_cancel.Text              = LanguageSupport.Translate(btn_cancel.Text);
            btn_help.Text                = LanguageSupport.Translate(btn_help.Text);
            fileToolStripMenuItem.Text   = LanguageSupport.Translate(fileToolStripMenuItem.Text);
            exportToolStripMenuItem.Text = LanguageSupport.Translate(exportToolStripMenuItem.Text);
            exportAndOpenInVericutToolStripMenuItem.Text = LanguageSupport.Translate(exportAndOpenInVericutToolStripMenuItem.Text);
            exitToolStripMenuItem.Text         = LanguageSupport.Translate(exitToolStripMenuItem.Text);
            optionsToolStripMenuItem.Text      = LanguageSupport.Translate(optionsToolStripMenuItem.Text);
            vericutToolStripMenuItem.Text      = LanguageSupport.Translate(vericutToolStripMenuItem.Text);
            toolToolStripMenuItem.Text         = LanguageSupport.Translate(toolToolStripMenuItem.Text);
            saveSettingsToolStripMenuItem.Text = LanguageSupport.Translate(saveSettingsToolStripMenuItem.Text);
            helpToolStripMenuItem.Text         = LanguageSupport.Translate(helpToolStripMenuItem.Text);
            helpToolStripMenuItem1.Text        = LanguageSupport.Translate(helpToolStripMenuItem1.Text);

            try
            {
                SetDefaultParams();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
                MessageBox.Show(Ex.StackTrace);
            }
        }
        public static void Export()
        {
            try
            {
                if (!Directory.Exists(Variables.doc_options.output_dirpath))
                {
                    Directory.CreateDirectory(Variables.doc_options.output_dirpath);
                }

                if (!FCExporter.SaveNCCode(FCToVericut.Application, Variables.doc,
                                           Variables.fname_no_ext, ".mcd", Variables.doc_options.output_dirpath,
                                           Variables.setups_info, Variables.GetSaveNCForAllSetups(),
                                           Variables.is_single_program, Variables.doc_options.combine_setups))
                {
                    LogFile.Write("Failed to save nc code");
                    MessageDisplay.ShowError(
                        LanguageSupport.Translate("Abort export: Failed to save NC code. Check for errors in the Op List."));
                    return;
                }

                Variables.doc.InvalidateToolpaths();
                ExportTools(FCToVericut.Application, Variables.doc);

                FCExporter.ExportStock((FMStock)Variables.doc.Stock, Variables.setups_info,
                                       Variables.doc_options.output_dirpath);

                /* Each setup has it's own clamps and possibly part solid. So we save them per setup. */
                FCExporter.ExportClamps((FMSolids)Variables.doc.Solids, Variables.setups_info,
                                        Variables.doc_options.output_dirpath);

                FCExporter.ExportDesign((FMSolids)Variables.doc.Solids, Variables.setups_info,
                                        Variables.doc_options.output_dirpath);

                /* If we need to update projects file, do it now */
                if (Variables.doc_options.is_export_project)
                {
                    VcProject_Manager.ConstructNewVCProjectFile(
                        Variables.setups_info.Count);
                }
                MessageDisplay.ShowMessage(LanguageSupport.Translate("Export completed."));
            }
            catch (Exception Ex)
            {
                LogFile.WriteException(Ex, "Export");
            }
            finally
            {
            }
        }
Exemplo n.º 10
0
        public void SetDefaults(List <TurretInfo> turrets, List <string> subsystems)
        {
            if (turrets == null)
            {
                return;
            }
            if (turrets.Count == 0)
            {
                return;
            }

            clm_subsystem.Items.Clear();
            if (subsystems != null)
            {
                foreach (string subsystem in subsystems)
                {
                    clm_subsystem.Items.Add(subsystem);
                }
            }

            dg_turrets.Rows.Clear();

            foreach (TurretInfo turret_info in turrets)
            {
                if (turret_info.available)
                {
                    switch (turret_info.type)
                    {
                    case FeatureCAM.tagFMTurretIDType.eTIDT_SubLower:
                        dg_turrets.Rows.Add(LanguageSupport.Translate(ltss), clm_type.Items[(turret_info.b_axis ? 0 : 1)]);
                        break;

                    case FeatureCAM.tagFMTurretIDType.eTIDT_SubUpper:
                        dg_turrets.Rows.Add(LanguageSupport.Translate(utss), clm_type.Items[(turret_info.b_axis ? 0 : 1)]);
                        break;

                    case FeatureCAM.tagFMTurretIDType.eTIDT_MainLower:
                        dg_turrets.Rows.Add(LanguageSupport.Translate(ltms), clm_type.Items[(turret_info.b_axis ? 0 : 1)]);
                        break;

                    case FeatureCAM.tagFMTurretIDType.eTIDT_MainUpper:
                        dg_turrets.Rows.Add(LanguageSupport.Translate(utms), clm_type.Items[(turret_info.b_axis ? 0 : 1)]);
                        break;
                    }
                }
            }
        }
        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();
        }
Exemplo n.º 12
0
        public MachineTurretsDlg(List <TurretInfo> turrets, List <string> subsystems)
        {
            InitializeComponent();

            this.Text                  = LanguageSupport.Translate(this.Text);
            btn_Ok.Text                = LanguageSupport.Translate(btn_Ok.Text);
            btn_Cancel.Text            = LanguageSupport.Translate(btn_Cancel.Text);
            clm_turret_name.HeaderText = LanguageSupport.Translate(clm_turret_name.HeaderText);
            clm_type.HeaderText        = LanguageSupport.Translate(clm_type.HeaderText);
            clm_subsystem.HeaderText   = LanguageSupport.Translate(clm_subsystem.HeaderText);
            clm_type.Items.Clear();
            clm_type.Items.AddRange(new object[] {
                LanguageSupport.Translate("Milling head"),
                LanguageSupport.Translate("Turret")
            });

            SetDefaults(turrets, subsystems);
        }
Exemplo n.º 13
0
 private void b_select_template_Click(object sender, EventArgs e)
 {
     openProjectFileDialog1.Filter          = LanguageSupport.Translate("VCPROJECT file (*.vcproject)|*.vcproject");
     openProjectFileDialog1.FileName        = "";
     openProjectFileDialog1.CheckFileExists = true;
     openProjectFileDialog1.Title           = LanguageSupport.Translate("Select template VERICUT project");
     if (openProjectFileDialog1.ShowDialog() == DialogResult.OK)
     {
         tb_proj_template_fpath.Text = openProjectFileDialog1.FileName;
         Variables.doc_options.vc_template_proj_fpath = tb_proj_template_fpath.Text;
         Variables.doc_options.vc_template_proj_fpath = tb_proj_template_fpath.Text;
         Variables.doc_options.is_export_project      = (tb_proj_template_fpath.Text != "");
         if (cb_setups.SelectedIndex >= 0)
         {
             if (this.tb_setup_template_fpath.Text == "" && this.tb_proj_template_fpath.Text != "")
             {
                 Variables.setups_info[cb_setups.SelectedIndex].attach_components = FindAllAttachComponents(Path.GetFullPath(this.tb_proj_template_fpath.Text));
                 Variables.setups_info[cb_setups.SelectedIndex].attach_components.Sort();
                 Variables.setups_info[cb_setups.SelectedIndex].subsystems = VericutMachineReader.GetMachineSubsystems(Path.GetFullPath(this.tb_proj_template_fpath.Text));
             }
         }
     }
 }
        public ClampsDlg(int selected_setup_index)
        {
            setup_index = selected_setup_index;

            InitializeComponent();
            this.Text                 = FeatureCAMExporter.LanguageSupport.Translate(this.Text);
            cb_export_clamps.Text     = FeatureCAMExporter.LanguageSupport.Translate(cb_export_clamps.Text);
            btn_SelectPartSolids.Text = FeatureCAMExporter.LanguageSupport.Translate(btn_SelectPartSolids.Text);
            groupBox1.Text            = FeatureCAMExporter.LanguageSupport.Translate(groupBox1.Text);
            label3.Text               = FeatureCAMExporter.LanguageSupport.Translate(label3.Text);
            btn_Apply.Text            = FeatureCAMExporter.LanguageSupport.Translate(btn_Apply.Text);
            btn_OK.Text               = FeatureCAMExporter.LanguageSupport.Translate(btn_OK.Text);
            btn_Cancel.Text           = FeatureCAMExporter.LanguageSupport.Translate(btn_Cancel.Text);
            export.HeaderText         = FeatureCAMExporter.LanguageSupport.Translate(export.HeaderText);
            attach_to.HeaderText      = FeatureCAMExporter.LanguageSupport.Translate(attach_to.HeaderText);
            solid.HeaderText          = FeatureCAMExporter.LanguageSupport.Translate(solid.HeaderText);
            export.Items.Clear();
            export.Items.Add(LanguageSupport.Translate("Yes"));
            export.Items.Add(LanguageSupport.Translate("No"));

            /* Clamps and part solid */
            dataGrid_clamps_and_design1.Rows.Clear();
            attach_to.Items.Clear();
            if (Variables.setups_info[setup_index].attach_components != null)
            {
                foreach (string attach_comp in Variables.setups_info[setup_index].attach_components)
                {
                    attach_to.Items.Add(attach_comp);
                }
                foreach (string component in Variables.setups_info[setup_index].attach_components)
                {
                    this.cb_attach_to.Items.Add(component);
                }
            }
            InitializeSolidsGridView();
        }
Exemplo n.º 15
0
        private void b_select_part_solid_Click(object sender, EventArgs e)
        {
            FeatureCAM.FMSolid selected_solid = null;

            if (Variables.doc.Solids.Count > 0)
            {
                foreach (FeatureCAM.FMSolid solid in Variables.doc.Solids)
                {
                    if (solid.Selected)
                    {
                        if (selected_solid == null)
                        {
                            selected_solid = solid;
                        }
                        else
                        {
                            MessageDisplay.ShowError(
                                LanguageSupport.Translate("More than one solid is selected in the part. Please select only one solid and try again."));
                            return;
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        private void GetDataFromFormAndExport()
        {
            Variables.doc_options.is_export_project = (tb_proj_template_fpath.Text != "");

            if (Variables.doc_options.output_dirpath == "")
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("Output directory path must be set. Please fix it and try again."));
                return;
            }
            else
            {
                Variables.doc_options.output_dirpath = tb_output_dir.Text;
            }
            if (Variables.fname_no_ext == "")
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("Output file name must be set. Please fix it and try again."));
                return;
            }
            if (Variables.doc_options.is_export_project && Variables.doc_options.vc_template_proj_fpath == "")
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("If exporting VERICUT project file, template file path must be set. Please fix it and try again."));
                return;
            }
            if (Variables.doc_options.is_export_project && !File.Exists(Variables.doc_options.vc_template_proj_fpath))
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("If exporting VERICUT project file, template file path must exist. File {0} doesn't exist. Please select existing file and try again."), Variables.doc_options.vc_template_proj_fpath);
                return;
            }

            FeatureCAM.FMSetup world = Variables.doc.Setups.Item("STOCK");
            if (Variables.setups_info[cb_setups.SelectedIndex].attach_ucs == null ||
                Variables.setups_info[cb_setups.SelectedIndex].attach_ucs == "")
            {
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("If using UCS for specifying the location of the bottom most clamp, UCS has to be selected. Please select existing UCS and try again."));
                return;
            }
            for (int si = 0; si < Variables.setups_info.Count; si++)
            {
                if (!Variables.setups_info[si].enabled)
                {
                    continue;
                }
                /* Main spindle */
                FeatureCAM.FMUcs ucs = Variables.doc.UCSs.Item(Variables.setups_info[si].attach_ucs);
                Variables.setups_info[si].options.ucs_attach = ucs.Name;
                if (ucs != null)
                {
                    FeatureCAM.FMSetup temp_setup = Variables.doc.AddSetup(ucs.Name + "_temp_setup", FeatureCAM.tagFMSetupType.eST_Milling, null, ucs.Name, Type.Missing);
                    temp_setup.Enabled = false;
                    Variables.all_ucss[0].ComputeCoordinatesInRelationToSetup(temp_setup,
                                                                              out Variables.setups_info[si].setup_solid_x, out Variables.setups_info[si].setup_solid_y, out Variables.setups_info[si].setup_solid_z,
                                                                              out Variables.setups_info[si].setup_solid_i, out Variables.setups_info[si].setup_solid_j, out Variables.setups_info[si].setup_solid_k);
                    FeatureCAM.FMUcs temp_setup_ucs = temp_setup.ucs;
                    temp_setup.Delete();
                    temp_setup_ucs.Delete();
                }
                if (world != null && ucs != null)
                {
                    double ucs_x, ucs_y, ucs_z;
                    ucs.GetLocation(out ucs_x, out ucs_y, out ucs_z);
                    world.MapWorldToSetup(ref ucs_x, ref ucs_y, ref ucs_z);
                }
                /* Subspindle */
                if (!String.IsNullOrEmpty(Variables.setups_info[si].attach_ucs_subspindle))
                {
                    ucs = Variables.doc.UCSs.Item(Variables.setups_info[si].attach_ucs_subspindle);
                    Variables.setups_info[si].options.ucs_attach_subspindle = ucs.Name;
                    if (ucs != null)
                    {
                        FeatureCAM.FMSetup temp_setup = Variables.doc.AddSetup(ucs.Name + "_temp_setup_sub", FeatureCAM.tagFMSetupType.eST_Milling, null, ucs.Name, Type.Missing);
                        temp_setup.Enabled = false;
                        Variables.all_ucss[0].ComputeCoordinatesInRelationToSetup(temp_setup,
                                                                                  out Variables.setups_info[si].sub_setup_solid_x, out Variables.setups_info[si].sub_setup_solid_y, out Variables.setups_info[si].sub_setup_solid_z,
                                                                                  out Variables.setups_info[si].sub_setup_solid_i, out Variables.setups_info[si].sub_setup_solid_j, out Variables.setups_info[si].sub_setup_solid_k);
                        FeatureCAM.FMUcs temp_setup_ucs = temp_setup.ucs;
                        temp_setup.Delete();
                        temp_setup_ucs.Delete();
                    }
                }
            }
            Close();
            Exporter.Export();
        }
Exemplo n.º 17
0
        public StockDesignDlg(int selected_setup_index)
        {
            setup_index = selected_setup_index;

            InitializeComponent();

            this.Text             = LanguageSupport.Translate(this.Text);
            cb_export_stock.Text  = LanguageSupport.Translate(cb_export_stock.Text);
            label8.Text           = LanguageSupport.Translate(label8.Text);
            cb_export_design.Text = LanguageSupport.Translate(cb_export_design.Text);
            label1.Text           = LanguageSupport.Translate(label1.Text);
            label2.Text           = LanguageSupport.Translate(label2.Text);
            btn_Ok.Text           = LanguageSupport.Translate(btn_Ok.Text);
            btn_Cancel.Text       = LanguageSupport.Translate(btn_Cancel.Text);

            this.cb_export_stock.Checked = Variables.setups_info[setup_index].options.is_export_stock;

            cb_export_stock.Checked         = Variables.setups_info[setup_index].options.is_export_stock;
            this.cb_attach_stock_to.Enabled = cb_export_stock.Checked;
            this.label8.Enabled             = cb_export_stock.Checked;

            cb_attach_stock_to.Items.Clear();
            if (Variables.setups_info[setup_index].attach_components != null)
            {
                foreach (string attach_comp in Variables.setups_info[setup_index].attach_components)
                {
                    cb_attach_stock_to.Items.Add(attach_comp);
                }
            }
            if (Variables.setups_info[setup_index].attach_stock_to != "" && cb_attach_stock_to.Items.Contains(Variables.setups_info[setup_index].attach_stock_to))
            {
                cb_attach_stock_to.SelectedItem = Variables.setups_info[setup_index].attach_stock_to;
            }
            cb_design_solid.Items.Clear();
            if (Variables.all_solids != null)
            {
                foreach (SolidInfo solid in Variables.all_solids)
                {
                    cb_design_solid.Items.Add(solid.name);
                }
            }
            cb_attach_design_to.Items.Clear();
            if (Variables.setups_info[setup_index].attach_components != null)
            {
                foreach (string attach_comp in Variables.setups_info[setup_index].attach_components)
                {
                    cb_attach_design_to.Items.Add(attach_comp);
                }
            }
            if (Variables.setups_info[setup_index].part != null)
            {
                if (Variables.setups_info[setup_index].part.Count != 0)
                {
                    cb_export_design.Checked = true;
                    if (cb_attach_design_to.Items.Contains(Variables.setups_info[setup_index].part[0].attach_to))
                    {
                        cb_attach_design_to.SelectedItem = Variables.setups_info[setup_index].part[0].attach_to;
                    }
                    if (cb_design_solid.Items.Contains(Variables.setups_info[setup_index].part[0].name))
                    {
                        cb_design_solid.SelectedItem = Variables.setups_info[setup_index].part[0].name;
                    }
                }
                else
                {
                    cb_export_design.Checked = false;
                }
            }
            else
            {
                cb_export_design.Checked = false;
            }
        }
        private static void ExportTools(FeatureCAM.Application app, FMDocument doc)
        {
            StringBuilder tool_info    = new StringBuilder(),
                          tls_fcontent = new StringBuilder(),
                          tool_list    = new StringBuilder();
            int nc_prog          = 1,
                init_num         = 1;
            string crib_pos      = "",
                   nc_prog_fpath = "";

            try
            {
                /* At the moment we construct full tool list, which can be time consuming.
                 * So if we have a lot of setups that don't get exported, we do have a pointless delay
                 */
                FCExporter.ToolsToList(app, doc, Variables.setups_info, Variables.GetSaveToolsForAllSetups(),
                                       (Variables.doc_options.combine_setups == 1), Variables.doc_options.output_dirpath, Variables.doc.Metric);
                if (Variables.doc_options.combine_setups == 0)
                {
                    for (int si = 0; si < Variables.setups_info.Count; si++)
                    {
                        if (Variables.setups_info[si].options.is_export_tools)
                        {
                            Variables.setups_info[si].tool_fpath = Path.Combine(Variables.doc_options.output_dirpath,
                                                                                Variables.fname_no_ext + "_" + (string)Variables.setups_info[si].name + ".tls");
                            tool_info    = new StringBuilder();
                            tls_fcontent = new StringBuilder();
                            tool_list    = new StringBuilder();
                            for (int i = 0; i < Variables.setups_info[si].tools.Count; i++)
                            {
                                if (Variables.setups_info[si].tools[i].cutter_geom.Count == 0)
                                {
                                    continue;
                                }
                                if (tool_info.Length > 0)
                                {
                                    tool_info.AppendLine("");
                                }
                                tool_info.Append(
                                    VericutTool.ToXML(Variables.setups_info[si].tools[i], doc.Metric));
                                nc_prog       = Convert.ToInt32(Convert.ToString(Variables.setups_info[si].tools[i].turr_type).Replace("eTT_TURRET", ""));
                                nc_prog_fpath = Variables.setups_info[si].nc_fpaths[nc_prog - 1];
                                crib_pos      = String.Format("{0}:{1}",
                                                              Convert.ToString(Variables.setups_info[si].tools[i].turr_type).Replace("eTT_TURRET", ""),
                                                              Convert.ToInt32(Variables.setups_info[si].tools[i].id));
                                AppendToToolList(tool_list, nc_prog, init_num, crib_pos, nc_prog_fpath, Variables.setups_info[si].tools[i].optional_id);
                            }
                            Variables.setups_info[si].tool_list = "<ToolChange>" + Environment.NewLine +
                                                                  Utilities.Indent(tool_list.ToString(), 1) +
                                                                  "</ToolChange>";
                            tls_fcontent.AppendLine("<?xml version=\"1.0\"?>");
                            tls_fcontent.AppendLine("<CGTechToolLibrary>");
                            tls_fcontent.AppendLine(Utilities.Indent("<Tools>", 1));
                            tls_fcontent.AppendLine(Utilities.Indent(tool_info.ToString(), 2));
                            tls_fcontent.AppendLine(Utilities.Indent("</Tools>", 1));
                            tls_fcontent.Append("</CGTechToolLibrary>");
                            File.WriteAllText(Variables.setups_info[si].tool_fpath, tls_fcontent.ToString());
                            LogFile.Write(String.Format("Tool info was written to {0}", Variables.setups_info[si].tool_fpath));
                        }
                    }
                }
                else
                {
                    if (Variables.setups_info[0].options.is_export_tools)
                    {
                        for (int si = 0; si < Variables.setups_info.Count; si++)
                        {
                            if (Variables.setups_info[si].options.is_export_tools)
                            {
                                Variables.setups_info[si].tool_fpath = Path.Combine(Variables.doc_options.output_dirpath,
                                                                                    Variables.fname_no_ext + ".tls");
                            }
                        }
                        for (int i = 0; i < Variables.setups_info[0].tools.Count; i++)
                        {
                            if (Variables.setups_info[0].tools[i].cutter_geom.Count == 0)
                            {
                                continue;
                            }
                            tool_info.Append(tool_info.Length > 0 ? "\n" : "");
                            tool_info.Append(
                                VericutTool.ToXML(Variables.setups_info[0].tools[i], Variables.doc.Metric));
                            nc_prog       = Convert.ToInt32(Convert.ToString(Variables.setups_info[0].tools[i].turr_type).Replace("eTT_TURRET", ""));
                            nc_prog_fpath = Variables.setups_info[0].nc_fpaths[nc_prog - 1];
                            crib_pos      = String.Format("{0}:{1}",
                                                          Convert.ToString(Variables.setups_info[0].tools[i].turr_type).Replace("eTT_TURRET", ""),
                                                          Convert.ToInt32(Variables.setups_info[0].tools[i].id));
                            AppendToToolList(tool_list, nc_prog, init_num, crib_pos, nc_prog_fpath, Variables.setups_info[0].tools[i].optional_id);
                        }
                        Variables.setups_info[0].tool_list = "<ToolChange>" + Environment.NewLine +
                                                             Utilities.Indent(tool_list.ToString(), 1) +
                                                             "</ToolChange>";
                        tls_fcontent.AppendLine("<?xml version=\"1.0\"?>");
                        tls_fcontent.AppendLine("<CGTechToolLibrary>");
                        tls_fcontent.AppendLine(Utilities.Indent("<Tools>", 1));
                        tls_fcontent.AppendLine(Utilities.Indent(tool_info.ToString(), 2));
                        tls_fcontent.AppendLine(Utilities.Indent("</Tools>", 1));
                        tls_fcontent.Append("</CGTechToolLibrary>");
                        File.WriteAllText(Variables.setups_info[0].tool_fpath, tls_fcontent.ToString());
                        LogFile.Write(String.Format("Tool info was written to {0}", Variables.setups_info[0].tool_fpath));
                    }
                }
            }
            catch (Exception Ex)
            {
                LogFile.Write(String.Format("Exception occured during tool export. Exception details: {0}\n", Ex.Message));
                MessageDisplay.ShowError(
                    LanguageSupport.Translate("Failed to export tools"));
            }
        }