/// <summary> /// 设置加工层 /// </summary> /// <param name="ele">电极</param> public void SetCutLevels(CAMElectrode ele) { if (OperIsValid) { _SetCutLevels(ele); } }
public void SetMillArea(CAMElectrode ele) { var tags = new List <NXOpen.Tag>(); ele.GentleFaces.ForEach(u => { tags.Add(u.FaceTag); }); tags = tags.Distinct().ToList(); Helper.SetCamgeom(NXOpen.UF.CamGeomType.CamCutArea, OperTag, tags); }
/// <summary> /// 根据类型自动设置相关参数 /// </summary> public virtual void AutoAnalysis(CAMElectrode ele, NXOpen.Tag WorkGeometryGroup, NXOpen.Tag ProgramGroup, NXOpen.Tag MethodGroupRoot , CAMCutter CAMCutter, CAMCutter refCAMCutter ) { if (AnalysisOperIsValid(ele)) { CreateOper(WorkGeometryGroup, ProgramGroup, MethodGroupRoot, CAMCutter); if (refCAMCutter != null) { SetReferenceCutter(refCAMCutter); } AutoSet(ele); } }
/// <summary> /// 设置非切削移动 区域起点 /// </summary> protected virtual void _SetRegionStartPoints(CAMElectrode ele) { if (OperIsValid) { var electrode = ele.Electrode; var baseFace = electrode.BaseFace; var result = baseFace.GetCenterPointEx(); var box = ele.BodyBox; var info = electrode.GetElectrodeInfo(); result.X = System.Math.Abs(box.MaxX - box.MinX); result.Z = System.Math.Abs(info.HEADPULLUPH); Helper.SetRegionStartPoints(OperTag, result); } }
public override void Apply() { var body = Snap.Globals.WorkPart.Bodies.FirstOrDefault(); var ele = ElecManage.Electrode.GetElectrode(body); if (ele != null) { ele.InitAllFace(); //AutoCAMUI.Helper.AutoCAM(ele); var camConfig = CNCConfig.CAMConfig.GetInstance(); var camEle = new AutoCAMUI.CAMElectrode(); camEle.Init(ele, camConfig); AutoCAMUI.AutoCamBusiness.AutoCam(camEle, camConfig); } }
/// <summary> /// 设置切削层 /// </summary> protected virtual void _SetCutLevels(CAMElectrode ele) { if (OperIsValid) { var zLevels = new List <double>(); zLevels.Add(ele.BodyBox.MaxZ); var hFace = ele.HorizontalFaces.OrderBy(u => u.GetSnapFace().GetCenterPointEx().Z).FirstOrDefault(); if (hFace != null) { zLevels.Add(hFace.GetSnapFace().GetCenterPointEx().Z); } zLevels.Add(ele.Electrode.BaseFace.GetCenterPointEx().Z); zLevels = zLevels.OrderByDescending(u => u).ToList(); Helper.SetCutLevels(OperTag, zLevels, (int)levelsPosition.BottomLevel); } }
protected override void AutoSet(CAMElectrode ele) { _SetPartStockAndFloorStock(ele.CamConfig.CAVITYPartStock, ele.CamConfig.CAVITYFloorStock); _SetCutLevels(ele); _SetRegionStartPoints(ele); }
public static List <ICAMOper> CreateCamOper( NXOpen.Tag WorkGeometryGroup, NXOpen.Tag ProgramGroup, NXOpen.Tag MethodGroupRoot, NXOpen.Tag cutterGroupRootTag, CAMElectrode ele, CNCConfig.CAMConfig.ProjectInfo project, List <CAMCutter> cutterDetails, double fireNum ) { var result = new List <ICAMOper>(); foreach (var item in project.Details) { var operConfig = ele.CamConfig.Operations.FirstOrDefault(m => m.显示名称 == item.工序); Func <string, CAMCutter> GetCutterAction = (s) => { var c = cutterDetails.FirstOrDefault(m => m.CutterName == s); if (ele.CamConfig.SparkPosition == CNCConfig.CAMConfig.E_SparkPosition.CheatKnife || ele.CamConfig.SparkPosition == CNCConfig.CAMConfig.E_SparkPosition.CheatKnifeZ ) { var tempC = cutterDetails.FirstOrDefault(m => m.CutterName == s + fireNum.ToString()); if (tempC != null) { c = tempC; } } return(c); }; var cutter = GetCutterAction(item.刀具); var refCutter = cutterDetails.FirstOrDefault(m => m.CutterName == item.参考刀具); if (operConfig == null) { throw new Exception("配置工具方案工序配置异常!"); } ICAMOper camOper = null; switch (operConfig.模版类型) { case CNCConfig.CAMConfig.S_OperationTemplate.EACT_AUTOCAM: { switch (GetEnumByKey(operConfig.模板名称)) { case E_TmplateOper.FACE_MILLING_KC: { camOper = new JYTools_FACE_MILLING_KC_Oper(); break; } } break; } default: { switch (GetEnumByKey(operConfig.模板名称)) { case E_TmplateOper.FACE_MILLING_TOP: { camOper = new WsqAutoCAM_FACE_MILLING_TOP_Oper(); break; } case E_TmplateOper.CAVITY_MILL_C: { camOper = new WsqAutoCAM_CAVITY_MILL_C_Oper(); break; } case E_TmplateOper.CAVITY_PLANAR_MILL: { camOper = new WsqAutoCAM_CAVITY_PLANAR_MILL_Oper(); break; } case E_TmplateOper.CAVITY_MILL_REF: { camOper = new WsqAutoCAM_CAVITY_MILL_REF_Oper(); break; } case E_TmplateOper.FACE_MILLING_BASE: { camOper = new WsqAutoCAM_FACE_MILLING_BASE_Oper(); break; } case E_TmplateOper.FACE_MILLING: { camOper = new WsqAutoCAM_FACE_MILLING_Oper(); break; } case E_TmplateOper.PLANAR_MILL_BASE: { camOper = new WsqAutoCAM_PLANAR_MILL_BASE_Oper(); break; } case E_TmplateOper.PLANAR_MILL: { camOper = new WsqAutoCAM_PLANAR_MILL_Oper(); break; } case E_TmplateOper.ZLEVEL_PROFILE_STEEP: { camOper = new WsqAutoCAM_ZLEVEL_PROFILE_STEEP_Oper(); break; } case E_TmplateOper.ZLEVEL_CORNER: { camOper = new WsqAutoCAM_ZLEVEL_CORNER_Oper(); break; } case E_TmplateOper.CONTOUR_AREA_NON_STEEP: { camOper = new WsqAutoCAM_CONTOUR_AREA_NON_STEEP_Oper(); break; } case E_TmplateOper.FLOWCUT_REF_TOOL: { camOper = new WsqAutoCAM_FLOWCUT_REF_TOOL_Oper(); break; } case E_TmplateOper.FACE_MILLING_CORNER: { camOper = new WsqAutoCAM_FACE_MILLING_CORNER_Oper(); break; } case E_TmplateOper.CONTOUR_TEXT: { camOper = new WsqAutoCAM_CONTOUR_TEXT_Oper(); break; } } break; } } if (camOper != null) { result.Add(camOper); camOper.FRIENUM = fireNum; camOper.AutoAnalysis(ele, WorkGeometryGroup, ProgramGroup, MethodGroupRoot, cutter, refCutter); if (item.切深 > 0) { camOper.SetCutDepth(item.切深); } if (item.进给 > 0) { camOper.SetFeedRate(item.进给); } } } return(result); }
public static List <CAMCutter> CreateCutter(CAMElectrode ele, CNCConfig.CAMConfig camConfig, NXOpen.Tag cutterGroupRootTag, out CNCConfig.CAMConfig.ProjectInfo project) { var eleInfo = ele.Electrode.GetElectrodeInfo(); List <CAMCutter> result = new List <CAMCutter>(); var info = ele.Electrode.GetElectrodeInfo(); var cutterConfigs = camConfig.FindCutterInfo(info.MAT_NAME); project = camConfig.Projects.Where(u => u.方案名称 == "自动").FirstOrDefault() ?? camConfig.Projects.Where(u => u.方案名称 == "自动").FirstOrDefault(); if (project == null) { throw new Exception("配置工具未配置方案!"); } var cutterStrs = new List <string>(); project.Details.ForEach(u => { cutterStrs.Add(u.刀具); cutterStrs.Add(u.参考刀具); }); cutterStrs = cutterStrs.Where(u => !string.IsNullOrEmpty(u)).ToList(); cutterStrs = cutterStrs.Distinct().ToList(); foreach (var item in cutterStrs) { var cutterConfig = cutterConfigs.FirstOrDefault(m => m.刀具名称 == item); if (cutterConfig != null) { Action <double> action = (f) => { var camCutter = new CAMCutter(); camCutter.AUTOCAM_TYPE = AUTOCAM_TYPE.mill_planar; camCutter.AUTOCAM_SUBTYPE = AUTOCAM_SUBTYPE.MILL; camCutter.CutterName = cutterConfig.刀具名称 + (f != 0 ? f.ToString() : ""); camCutter.TL_DIAMETER = double.Parse(cutterConfig.直径) + (f * 2); camCutter.TL_COR1_RAD = double.Parse(cutterConfig.R角) + f; camCutter.TL_COR1_RAD = camCutter.TL_COR1_RAD < 0 ? 0 : camCutter.TL_COR1_RAD; camCutter.TL_HEIGHT = double.Parse(cutterConfig.刀长); camCutter.TL_FLUTE_LN = double.Parse(cutterConfig.刃长); camCutter.TL_NUMBER = int.Parse(cutterConfig.刀号); camCutter.TL_ADJ_REG = int.Parse(cutterConfig.补正号); camCutter.Speed = double.Parse(cutterConfig.转速); camCutter.FeedRate = double.Parse(cutterConfig.进给); camCutter.FEED_TRAVERSAL = double.Parse(cutterConfig.横越); camCutter.CutDepth = double.Parse(cutterConfig.切深); result.Add(camCutter); }; action(0); if (eleInfo.FINISH_NUMBER > 0) //精 { action(eleInfo.FINISH_SPACE); } if (eleInfo.MIDDLE_NUMBER > 0) //中 { action(eleInfo.MIDDLE_SPACE); } if (eleInfo.ROUGH_NUMBER > 0) //粗 { action(eleInfo.ROUGH_SPACE); } } else { throw new Exception("配置工具方案刀具配置异常!"); } } result = Helper.CreateCutter(result, cutterGroupRootTag); return(result); }
/// <summary> /// 自动编程 /// </summary> public static void AutoCam(CAMElectrode ele, CNCConfig.CAMConfig camConfig) { //安全距离 var safeDistance = 10; var autoBlankOffset = new double[] { camConfig.AutoBlankXPlus, camConfig.AutoBlankXReduce, camConfig.AutoBlankYPlus, camConfig.AutoBlankYReduce, camConfig.AutoBlankZPlus, camConfig.AutoBlankZReduce }; var eleInfo = ele.Electrode.GetElectrodeInfo(); var bodyBox = ele.BodyBox; //几何组根节点 NXOpen.Tag geometryGroupRootTag; //程序组根节点 NXOpen.Tag orderGroupRootTag; //刀具组根节点 NXOpen.Tag cutterGroupRootTag; //方法组根节点 NXOpen.Tag methodGroupRootTag; //几何体组 NXOpen.Tag workGeometryGroupTag; //TODO 初始化对象 NXOpen.Tag setup_tag; ufSession.Setup.AskSetup(out setup_tag); ufSession.Setup.AskGeomRoot(setup_tag, out geometryGroupRootTag); ufSession.Setup.AskProgramRoot(setup_tag, out orderGroupRootTag); ufSession.Setup.AskMctRoot(setup_tag, out cutterGroupRootTag); ufSession.Setup.AskMthdRoot(setup_tag, out methodGroupRootTag); //根据配置文件创建刀具 CNCConfig.CAMConfig.ProjectInfo projectConfig; var cutters = CreateCutter(ele, camConfig, cutterGroupRootTag, out projectConfig); //TODO删除旧的程序 //TODO 创建坐标系和几何体 //加工坐标系 NXOpen.Tag workMcsGroupTag; ufSession.Ncgeom.Create(AUTOCAM_TYPE.mill_planar, AUTOCAM_SUBTYPE.MCS, out workMcsGroupTag); ufSession.Obj.SetName(workMcsGroupTag, AUTOCAM_ROOTNAME.GEOM_EACT); ufSession.Ncgroup.AcceptMember(geometryGroupRootTag, workMcsGroupTag); //TODO 设置安全平面 var normal = new Snap.Vector(0, 0, 1); var origin = new Snap.Position((bodyBox.MinX + bodyBox.MaxX) / 2, (bodyBox.MinY + bodyBox.MaxY) / 2, bodyBox.MaxZ + safeDistance); ufSession.Cam.SetClearPlaneData(workMcsGroupTag, origin.Array, normal.Array); //TODO 创建几何体 ufSession.Ncgeom.Create(AUTOCAM_TYPE.mill_planar, AUTOCAM_SUBTYPE.WORKPIECE, out workGeometryGroupTag); ufSession.Obj.SetName(workGeometryGroupTag, eleInfo.Elec_Name); ufSession.Ncgroup.AcceptMember(workMcsGroupTag, workGeometryGroupTag); //TODO 添加Body作为工作几何体 Helper.SetCamgeom(NXOpen.UF.CamGeomType.CamPart, workGeometryGroupTag, new List <NXOpen.Tag> { ele.Electrode.ElecBody.NXOpenTag }); //TODO 设置毛坯为自动块 ufSession.Cam.SetAutoBlank(workGeometryGroupTag, NXOpen.UF.UFCam.BlankGeomType.AutoBlockType, autoBlankOffset); Action <string, double, int> action = (type, fireNum, number) => { //TODO 创建程序 NXOpen.Tag programGroupTag; ufSession.Ncprog.Create(AUTOCAM_TYPE.mill_planar, AUTOCAM_SUBTYPE.PROGRAM, out programGroupTag); ufSession.Obj.SetName(programGroupTag, string.Format("{0}-{1}", eleInfo.Elec_Name, type)); ufSession.Ncgroup.AcceptMember(orderGroupRootTag, programGroupTag); var list = CAMOper.CreateCamOper(workGeometryGroupTag, programGroupTag, methodGroupRootTag, cutterGroupRootTag, ele, projectConfig, cutters, fireNum); list = list.Where(u => u.OperIsValid).ToList(); //var exMsg=Helper.PathGenerate(programGroupTag); //Helper.ShowInfoWindow(exMsg); }; if (eleInfo.FINISH_NUMBER > 0) //精 { action("F", eleInfo.FINISH_SPACE, eleInfo.FINISH_NUMBER); } if (eleInfo.MIDDLE_NUMBER > 0) //中 { action("M", eleInfo.MIDDLE_SPACE, eleInfo.MIDDLE_NUMBER); } if (eleInfo.ROUGH_NUMBER > 0) //粗 { action("R", eleInfo.ROUGH_SPACE, eleInfo.ROUGH_NUMBER); } }
/// <summary> /// 根据电极分析数据设置工序相关参数 /// </summary> protected virtual void AutoSet(CAMElectrode ele) { }
/// <summary> /// 根据电极分析数据判断该工序是否可用 /// </summary> protected virtual bool AnalysisOperIsValid(CAMElectrode ele) { return(true); }
protected override void AutoSet(CAMElectrode ele) { SetMillArea(Enumerable.Select(ele.HorizontalFaces, u => u.FaceTag).ToList()); }
protected override void AutoSet(CAMElectrode ele) { SetBoundary(ele.HorizontalFaces); }
protected override void AutoSet(CAMElectrode ele) { SetBoundary(ele.Electrode); }
protected override void AutoSet(CAMElectrode ele) { SetMillArea(ele.Electrode); }
protected override void AutoSet(CAMElectrode ele) { SetCutLevels(ele); }
protected override bool AnalysisOperIsValid(CAMElectrode ele) { return(ele.HorizontalFaces.Count > 0); }
protected override void AutoSet(CAMElectrode ele) { SetBoundaryAndCutFloor(ele.Electrode); _SetRegionStartPoints(ele); }