private static void LoadStockInfo(string stock_fpath, string workpieceID) { 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; if (!(Variables.stock.Type == tagFMStockType.eST_Block && Variables.stock.IndexType == tagFMIndexType.eIT_None)) { 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; Variables.stock.GetLocation(out stock_x, out stock_y, out stock_z); if (Variables.stock.Type == tagFMStockType.eST_Block) { stock_z = stock_z - stock_thickness; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisX) { stock_y = stock_z = 0; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisY) { stock_x = stock_z = 0; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisZ) { stock_y = stock_z = 0; } Variables.eureka_proj.AddFileShape("stock", workpieceID, stock_fpath, Variables.offset_x, Variables.offset_y, Variables.offset_z, 0, 0, 0, ""); Variables.eureka_proj.SetShapeAsStock(workpieceID + ".stock"); } else { FMSetup setup = Variables.doc.Setups.Item(Variables.selected_setup_id + 1); FMUcs ucs = setup.ucs; double i, j, k; double x, y, z, xx, xy, xz, yx, yy, yz, zx, zy, zz; ucs.GetLocation(out x, out y, out z); ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); ComputeEulerAngles(ucs, out i, out j, out k); Variables.eureka_proj.AddFileShape("stock", workpieceID, stock_fpath, Variables.offset_x, Variables.offset_y, -1 * Variables.offset_z, i, j, k, ""); Variables.eureka_proj.SetShapeAsStock(workpieceID + ".stock"); } }
private static string GetStockInfo() { string fcontent = ""; 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; if (!(Variables.stock.Type == tagFMStockType.eST_Block && Variables.stock.IndexType == tagFMIndexType.eIT_None)) { 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; Variables.stock.GetLocation(out stock_x, out stock_y, out stock_z); if (Variables.stock.Type == tagFMStockType.eST_Block) { stock_z = stock_z - stock_thickness; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisX) { stock_y = stock_z = 0; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisY) { stock_x = stock_z = 0; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisZ) { stock_y = stock_z = 0; } fcontent += "BEGIN_MODEL" + Environment.NewLine + Lib.tab + "|UNITS|" + (Variables.doc.Metric ? "MM" : "INCH") + "|" + Environment.NewLine + Lib.tab + "|VECTOR|" + 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(Variables.offset_z, Variables.doc.Metric, true), 4) + "|0.0,0.0,0.0|" + Environment.NewLine + Lib.tab + "|MATRICE_OXY|" + Math.Round(stock_x, 4) + "," + Math.Round(stock_y, 4) + "," + Math.Round(stock_z, 4) + "," + "1.0,0.0,0.0,0.0,1.0,0.0|" + Environment.NewLine + Lib.tab + "|STOCK|STL|stock.stl|0.1|" + Environment.NewLine + "END" + Environment.NewLine + Environment.NewLine; } else { FMSetup setup = Variables.doc.Setups.Item(Variables.selected_setup_id + 1); FMUcs ucs = setup.ucs; double x, y, z, xx, xy, xz, yx, yy, yz, zx, zy, zz; ucs.GetLocation(out x, out y, out z); ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); 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); double tempx, tempy, tempz; tempx = tempy = tempz = 0; if (xx == 1 && xy == 0 && xz == 0 && yx == 0 && yy == 1 && yz == 0) { tempz = (stock_bbox_zmax - stock_bbox_zmin) + z; } setup.MapWorldToSetup(ref tempx, ref tempy, ref tempz); fcontent += "BEGIN_MODEL" + Environment.NewLine + Lib.tab + "|UNITS|" + (Variables.doc.Metric ? "MM" : "INCH") + "|" + Environment.NewLine + Lib.tab + "|VECTOR|" + 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(Variables.offset_z, Variables.doc.Metric, true), 4) + "|0.0,0.0,0.0|" + Environment.NewLine + Lib.tab + "|MATRICE_OXY|" + Math.Round(x, 4) + "," + Math.Round(y, 4) + "," + Math.Round(z, 4) + "," + xx + "," + xy + "," + xz + "," + yx + "," + yy + "," + yz + "|" + Environment.NewLine + Lib.tab + "|STOCK|STL|stock.stl|0.1|" + Environment.NewLine + "END" + Environment.NewLine + Environment.NewLine; } return(fcontent); }
private static void SetCoordSystemInfo(SetupInfo setup_info, ref string mod_setup_info) { int pos_s, pos_e, insert_at; string coord_sys_desc, new_component_str; try { if (setup_info.ucss == null) { return; } FindXMLBlock(mod_setup_info, "CSystems", out pos_s, out pos_e); if (pos_s < 0 || pos_e < 0) //there is no Setups info in the template { new_component_str = " <CSystems Simulation=\"off\">" + Environment.NewLine + " <Machine></Machine>" + Environment.NewLine + " </CSystems>" + Environment.NewLine; } else { new_component_str = mod_setup_info.Substring(pos_s, pos_e - pos_s); } coord_sys_desc = ""; FMUcs attach_ucs = Variables.doc.UCSs.Item(setup_info.attach_ucs); FMSetup temp_setup = Variables.doc.AddSetup(setup_info.attach_ucs + "_temp_setup", tagFMSetupType.eST_Milling, null, attach_ucs.Name, Type.Missing); temp_setup.Enabled = false; foreach (UCS ucs in Variables.all_ucss) { double x, y, z, i, j, k; ucs.ComputeCoordinatesInRelationToSetup(temp_setup, out x, out y, out z, out i, out j, out k); coord_sys_desc += String.Format(" <CSystem Name=\"{0}\" Type=\"component\" Visible=\"none\" Color=\"-1\" Transition=\"{1}\">\r\n", (!setup_info.sub_spindle ? "" : "(Main) ") + ucs.name, (ucs.name.Equals(Variables.doc_options.trans_ucs) ? "on" : "off")) + String.Format(" <Attach>{0}</Attach>\r\n", (!ucs.name.Equals(Variables.doc_options.trans_ucs) ? setup_info.attach_ucss_to : setup_info.attach_stock_to)) + String.Format(" <Position X=\"{0}\" Y=\"{1}\" Z=\"{2}\"/>\r\n", Math.Round(x, 4), Math.Round(y, 4), Math.Round(z, 4)) + String.Format(" <Rotation I=\"{0}\" J=\"{1}\" K=\"{2}\"/>\r\n", i, j, k) + String.Format(" </CSystem>\r\n"); } FMUcs temp_setup_ucs = temp_setup.ucs; temp_setup.Delete(); temp_setup_ucs.Delete(); if (!String.IsNullOrEmpty(setup_info.attach_ucs_subspindle)) { attach_ucs = Variables.doc.UCSs.Item(setup_info.attach_ucs_subspindle); temp_setup = Variables.doc.AddSetup(setup_info.attach_ucs_subspindle + "_temp_setup", tagFMSetupType.eST_Milling, null, attach_ucs.Name, Type.Missing); temp_setup.Enabled = false; if (setup_info.attach_ucss_to_subspindle != "") { foreach (UCS ucs in Variables.all_ucss) { double x, y, z, i, j, k; ucs.ComputeCoordinatesInRelationToSetup(temp_setup, out x, out y, out z, out i, out j, out k); coord_sys_desc += String.Format(" <CSystem Name=\"{0}\" Type=\"component\" Visible=\"none\" Color=\"-1\" Transition=\"{1}\">\r\n", "(Sub) " + ucs.name, (ucs.name.Equals(Variables.doc_options.trans_ucs) ? "on" : "off")) + String.Format(" <Attach>{0}</Attach>\r\n", (!ucs.name.Equals(Variables.doc_options.trans_ucs) ? setup_info.attach_ucss_to_subspindle : setup_info.attach_stock_to_subspindle)) + String.Format(" <Position X=\"{0}\" Y=\"{1}\" Z=\"{2}\"/>\r\n", Math.Round(x, 4), Math.Round(y, 4), Math.Round(z, 4)) + String.Format(" <Rotation I=\"{0}\" J=\"{1}\" K=\"{2}\"/>\r\n", i, j, k) + String.Format(" </CSystem>\r\n"); } } temp_setup_ucs = temp_setup.ucs; temp_setup.Delete(); temp_setup_ucs.Delete(); } insert_at = new_component_str.IndexOf("</CSystems>"); insert_at = new_component_str.LastIndexOf(Environment.NewLine, insert_at) + Environment.NewLine.Length; new_component_str = new_component_str.Insert(insert_at, coord_sys_desc); if (pos_s < 0 || pos_e < 0) //there is no Setups info in the template { insert_at = mod_setup_info.IndexOf("</Setup>"); insert_at = mod_setup_info.LastIndexOf(Environment.NewLine, insert_at) + Environment.NewLine.Length; mod_setup_info = mod_setup_info.Insert(insert_at, new_component_str); } else { mod_setup_info = mod_setup_info.Substring(0, pos_s) + new_component_str + mod_setup_info.Substring(pos_e); } } catch (Exception Ex) { LogFile.WriteException(Ex, "SetCoordSystemInfo"); } }