Exemple #1
0
        /* machine_type = LATHE or MILLING */
        public static void LoadProjectToEureka(string stock_fpath, string tdb_fpath, string project_fpath)
        {
            string fcontent = "";
            string new_template_path;

            try
            {
                Variables.eureka_app = FCToEUREKA.StartEUREKA();
                Directory.CreateDirectory(Variables.output_dirpath);
                new_template_path     = Path.Combine(Variables.output_dirpath, Path.GetFileName(Variables.eureka_template_fpath));
                Variables.eureka_proj = (Eureka.Project)Variables.eureka_app.OpenProject(Variables.eureka_template_fpath, true, true);
                if (Variables.eureka_proj.GetControllerCount() == 0)
                {
                    MessageBox.Show(
                        "Failed to load data into EUREKA project. Selected project should have at least 1 controller.",
                        Variables.prog_name,
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                Variables.eureka_proj.Units = (Variables.doc.Metric ? 0 : 1);
                Variables.eureka_proj.SelectProgramFile(Variables.setups_info[0].nc_fpath, 0, "");
                Eureka.Controller controller = (Eureka.Controller)Variables.eureka_proj.GetControllerByIndex(0);
                /* Setup information */
                GetNCCodeInfo(controller);

                string workpieceID = Variables.eureka_proj.GetWorkPieceID(0);

                Variables.eureka_proj.RemoveShape(workpieceID + ".*");
                LoadStockInfo(stock_fpath, workpieceID);

                Eureka.ToolLibrary tool_lib = (Eureka.ToolLibrary)((Eureka.Machine)controller.Machine).ToolLibrary;
                tool_lib.FilePath = tdb_fpath;
                tool_lib.ReadFromFile(tdb_fpath, null);

                Variables.eureka_app.Refresh();
                Variables.eureka_app.ActiveProject().SaveAs(project_fpath);

                /* Stock identification */


                /* Clamps information */
                fcontent += GetClampsInfo();

                /* Tool information */
                fcontent += tdb_fpath;

                /* Save result */
                fcontent += "BEGIN_SAVE_STOCK" + Lib.EOL +
                            "  |1|NCMAC|" + "saved_" + Path.GetFileName(Variables.output_dirpath) + "|" + Lib.EOL +
                            "END";
            }
            catch (Exception Ex)
            { }
        }
Exemple #2
0
        private static void GetNCCodeInfo(Eureka.Controller controller)
        {
            double xx, xy, xz,
                   yx, yy, yz,
                   zx, zy, zz;
            double x = 0, y = 0, z = 0;
            double stock_x, stock_y, stock_z;
            double stock_thickness;
            double stock_bbox_xmin, stock_bbox_xmax,
                   stock_bbox_ymin, stock_bbox_ymax,
                   stock_bbox_zmin, stock_bbox_zmax;
            int work_ref_index;

            Variables.stock.GetLocation(out stock_x, out stock_y, out stock_z);
            Variables.stock.BoundingBox(out stock_bbox_xmin, out stock_bbox_ymin, out stock_bbox_zmin,
                                        out stock_bbox_xmax, out stock_bbox_ymax, out stock_bbox_zmax,
                                        tagFMCoordinateSpace.eCS_World, null);
            stock_thickness = stock_bbox_zmax - stock_bbox_zmin;

            if (Variables.stock.IndexType == tagFMIndexType.eIT_None)
            {
                Variables.doc.ActiveSetup.ucs.GetVectors(out xx, out xy, out xz,
                                                         out yx, out yy, out yz,
                                                         out zx, out zy, out zz);
                double tempx, tempy, tempz;
                tempx = tempy = tempz = 0;
                if (xx == 1 && xy == 0 && xz == 0 &&
                    yx == 0 && yy == 1 && yz == 0)
                {
                    tempz = z + stock_bbox_zmin;
                }

                controller.RemoveAllDefaultWorkReferences();
                work_ref_index = controller.GetWorkReferenceIndex("G" + Variables.doc.ActiveSetup.FixtureID);
                if (work_ref_index > 0)
                {
                    controller.SetDefaultWorkReference(work_ref_index,
                                                       Math.Round(Lib.FromUnitsToUnits(Variables.offset_x, Variables.doc.Metric, true), 4),
                                                       Math.Round(Lib.FromUnitsToUnits(Variables.offset_y, Variables.doc.Metric, true), 4),
                                                       Math.Round(Lib.FromUnitsToUnits(-1 * Variables.offset_z, Variables.doc.Metric, true), 4));
                }
            }
            else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisX ||
                     Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisY ||
                     Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisZ)
            {
                foreach (FMSetup setup in Variables.doc.Setups)
                {
                    if (Variables.stock.Type == tagFMStockType.eST_Block)
                    {
                        x = stock_x + x;
                        y = stock_y + y;
                        z = stock_z + stock_thickness + z;
                    }
                    controller.RemoveAllDefaultWorkReferences();
                    work_ref_index = controller.GetWorkReferenceIndex("G" + Variables.doc.ActiveSetup.FixtureID);
                    if (work_ref_index > 0)
                    {
                        controller.SetDefaultWorkReference(work_ref_index,
                                                           Math.Round(Lib.Inch2MM(x), 4),
                                                           Math.Round(Lib.Inch2MM(y), 4),
                                                           Math.Round(Lib.Inch2MM(z), 4));
                    }
                }
            }
            else if (Variables.stock.IndexType == tagFMIndexType.eIT_5thAxis)
            {
                if (Variables.use_DATUM)
                {
                    string touch_off_setup_name;

                    touch_off_setup_name = Variables.stock.TouchOffSetup;
                    FMSetup setup = Variables.doc.Setups.Item(touch_off_setup_name);
                    setup.ucs.GetLocation(out x, out y, out z);
                    x += Variables.offset_x;
                    y += Variables.offset_y;
                    z += Variables.offset_z;
                    controller.RemoveAllDefaultWorkReferences();
                    work_ref_index = controller.GetWorkReferenceIndex(Variables.doc.ActiveSetup.FixtureID);
                    if (work_ref_index > 0)
                    {
                        controller.SetDefaultWorkReference(work_ref_index,
                                                           Math.Round(Lib.Inch2MM(x), 4),
                                                           Math.Round(Lib.Inch2MM(y), 4),
                                                           Math.Round(Lib.Inch2MM(z), 4));
                    }
                }
                else
                {
                    foreach (FMSetup setup in Variables.doc.Setups)
                    {
                        if (Variables.stock.Type == tagFMStockType.eST_Block)
                        {
                            x = stock_x + x;
                            y = stock_y + y;
                            z = stock_z + stock_thickness + z;
                        }
                        setup.MapSetupToWorld(ref x, ref y, ref z);
                        setup.ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz);
                    }
                }
            }
        }