/// <summary> /// 获取平面高度 /// </summary> /// <param name="face"></param> /// <returns></returns> private double GetFaceIsHighst(FaceData faceData) { double zMax = Math.Round(faceData.BoxMaxCorner.Z, 3); double faceZ = zMax; Edge[] egs = null; try { egs = faceData.Face.GetEdges(); } catch { return(0); } if (egs != null) { foreach (Edge eg in egs) { foreach (Face fa in eg.GetFaces()) { if (fa.Tag != faceData.Face.Tag) { FaceData data = FaceUtils.AskFaceData(fa); double z = Math.Round(data.BoxMaxCorner.Z, 3); if (z > zMax) { zMax = z; } } } } } return(zMax - faceZ); }
public static AbstractFaceSlopeAndDia CreateFaceSlopeAndDia(Face face) { FaceData data = FaceUtils.AskFaceData(face); AbstractFaceSlopeAndDia faceSd = null; switch (face.SolidFaceType) { case Face.FaceType.Planar: faceSd = new PlaneFaceSlopeAndDia(data); break; case Face.FaceType.Cylindrical: faceSd = new CylinderFaceSlopeAndDia(data); break; case Face.FaceType.Conical: faceSd = new CircularConeFaceSlopeAndDia(data); break; default: faceSd = new SweptFaceFaceSlopeAndDia(data); break; } return(faceSd); }
/// <summary> /// 干涉面 /// </summary> public void GetInterferenceOfFace() { List <Tag> outFace = new List <Tag>(); Body eleBody = GetOccsInBods(this.eleModel.PartTag)[0]; Body workpieceBody = GetOccsInBods(this.workpiece)[0]; List <Face> faces = AnalysisUtils.SetInterferenceOutFace(eleBody, workpieceBody); for (int i = 0; i < (faces.Count) / 2 - 1; i++) { FaceData data1 = FaceUtils.AskFaceData(faces[i * 2]); FaceData data2 = FaceUtils.AskFaceData(faces[i * 2 + 1]); if (data1.Equals(data2)) { Tag face3; NXOpen.Features.Feature feat1 = AssmbliesUtils.WaveFace(faces[i * 2]); NXOpen.Features.Feature feat2 = AssmbliesUtils.WaveFace(faces[i * 2 + 1]); Body[] bodys1 = (feat1 as NXOpen.Features.BodyFeature).GetBodies(); Body[] bodys2 = (feat2 as NXOpen.Features.BodyFeature).GetBodies(); Tag bodyTag1 = Intersect(bodys1[0], bodys2[0]); if (bodyTag1 != Tag.Null) { outFace.Add(bodyTag1); } } } SewSolidBody(outFace); }
/// <summary> /// 获取最低面 /// </summary> /// <returns></returns> private void PullFaceForWave(List <Body> bodys) { foreach (Body body in bodys) { FaceData maxFace = null; double zMin = 9999; foreach (Face face in body.GetFaces()) { FaceData data = FaceUtils.AskFaceData(face); Point3d center = UMathUtils.GetMiddle(data.BoxMaxCorner, data.BoxMinCorner); if (zMin > center.Z) { zMin = center.Z; maxFace = data; } } if (maxFace != null) { double z = maxFace.BoxMaxCorner.Z + this.datum.EleHeight; if (z > 0) { try { SynchronousUtils.CreatePullFace(new Vector3d(0, 0, -1), z, maxFace.Face); } catch { } } } } }
public void GetInterferenceOfArea() { Body eleBody = GetOccsInBods(this.eleModel.PartTag)[0]; Body workpieceBody = GetOccsInBods(this.workpiece)[0]; List <Face> faces = AnalysisUtils.SetInterferenceOutFace(eleBody, workpieceBody); double minArea = 0; for (int i = 0; i < (faces.Count) / 2 - 1; i++) { FaceData data1 = FaceUtils.AskFaceData(faces[i * 2]); FaceData data2 = FaceUtils.AskFaceData(faces[i * 2 + 1]); if (data1.Equals(data2)) { double area1 = FaceUtils.GetFaceArea(faces[i * 2]); double area2 = FaceUtils.GetFaceArea(faces[i * 2 + 1]); if (area1 > area2) { minArea += area2; } else { minArea += area1; } } } AttributeUtils.AttributeOperation("Area", minArea, this.eleModel.PartTag); }
public static AbstractCircleFace Create(Face face) { FaceData data = FaceUtils.AskFaceData(face); AbstractCircleFace abs = null; switch (face.SolidFaceType) { case Face.FaceType.Cylindrical: abs = new CylinderFace(data); break; case Face.FaceType.Conical: abs = new CircularConeFace(data); break; case Face.FaceType.Planar: List <ArcEdgeData> edge = new List <ArcEdgeData>(); if (CircleAnnylusFace.IsCircleAnnylus(face, out edge)) { abs = new CircleAnnylusFace(data, edge); } break; default: break; } return(abs); }
public override void SetDimForFace(ref LinearDimension ld, Vector3d vec) { foreach (Face face in this.ToolingBox.GetBodies()[0].GetFaces()) { if (face.SolidFaceType == Face.FaceType.Cylindrical) { Point3d originPt = new Point3d(0, 0, 0); Vector3d normal = new Vector3d(0, 0, 0); FaceUtils.AskFaceOriginAndNormal(face, out originPt, out normal); double angle1 = UMathUtils.Angle(vec, new Vector3d(1, 1, 1)); if (UMathUtils.IsEqual(angle1, 0)) { ld.HandleOrientation = normal; ld.HandleOrigin = originPt; } } else { FaceData fd = FaceUtils.AskFaceData(face); Vector3d temp = fd.Dir; this.Matr.ApplyVec(ref temp); double angle = UMathUtils.Angle(vec, temp); if (UMathUtils.IsEqual(angle, 0)) { ld.HandleOrientation = fd.Dir; ld.HandleOrigin = fd.Point; } } } }
/// <summary> /// 分析面 /// </summary> /// <param name="vec"></param> public void AnalyzeFace(Vector3d vec) { this.FaceData = FaceUtils.AskFaceData(this.face); this.ResultsNum = TraceARay.AskTraceARayForFaceData(face, vec); this.Vec = vec; if (this.face.SolidFaceType == Face.FaceType.Planar) //平面 { this.MaxRadius = 0; this.MinRadius = 0; double angle = Math.Round(UMathUtils.Angle(vec, this.FaceData.Dir), 3); this.MaxSlope = angle; this.MinSlope = angle; return; } if (this.face.SolidFaceType == Face.FaceType.Cylindrical) { this.MaxRadius = Math.Round(this.FaceData.Radius, 3) * this.FaceData.IntNorm; this.MinRadius = Math.Round(this.FaceData.Radius, 3) * this.FaceData.IntNorm; AskFace(vec); return; } if (this.face.SolidFaceType == Face.FaceType.Conical) { this.MaxRadius = Math.Round(this.FaceData.Radius, 3) * this.FaceData.IntNorm; this.MinRadius = Math.Round(this.FaceData.RadData, 3) * this.FaceData.IntNorm; AskFace(vec); return; } else { double[] slope; double[] rad; FaceUtils.GetSweptSlope(this.face, vec, out slope, out rad); foreach (double temp in slope) { if (this.MaxSlope > temp) { this.MaxSlope = Math.Round(temp, 3); } if (this.MinSlope < temp) { this.MinSlope = Math.Round(temp, 3); } } foreach (double temp in rad) { if (this.MaxRadius > temp) { this.MaxRadius = Math.Round(temp, 3); } if (this.MinRadius < temp) { this.MinRadius = Math.Round(temp, 3); } } } }
/// <summary> /// 基准面设定属性 /// </summary> /// <param name="body"></param> private void SetDatumAttr(Body body) { foreach (Face fe in body.GetFaces()) { FaceData data = FaceUtils.AskFaceData(fe); if (UMathUtils.IsEqual(data.BoxMinCorner.Z, data.BoxMaxCorner.Z) && UMathUtils.IsEqual(data.BoxMinCorner.Z, this.sketch.LeiLine[0].StartPoint.Z)) { AttributeUtils.AttributeOperation("DatumFace", "Datum", fe); } } }
public List <Face> EleFaceSort() { List <Face> faces = new List <Face>(); faces.AddRange(EleModel.PartTag.Bodies.ToArray()[0].GetFaces()); faces.Sort(delegate(Face a, Face b) { FaceData data1 = FaceUtils.AskFaceData(a); FaceData data2 = FaceUtils.AskFaceData(b); return(data1.Point.Z.CompareTo((data2.Point.Z))); }); return(faces); }
/// <summary> /// 获取边 /// </summary> /// <param name="xEdge"></param> /// <param name="yEdge"></param> public void GetEdge(out List <Edge> xEdge, out Point centerCom) { xEdge = new List <Edge>(); centerCom = null; string str = ""; ElectrodeModel ele = null; foreach (ElectrodeModel em in eleModels) { if (em.Info.AllInfo.SetValue.Positioning == "" || em.Info.AllInfo.SetValue.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase)) { ele = em; } } if (ele == null) { return; } List <Face> faces = new List <Face>(); faces.AddRange(ele.PartTag.Bodies.ToArray()[0].GetFaces()); Point elePoint = ele.GetSetPoint(); faces.Sort(delegate(Face a, Face b) { FaceData data1 = FaceUtils.AskFaceData(a); FaceData data2 = FaceUtils.AskFaceData(b); return(data1.Point.Z.CompareTo((data2.Point.Z))); }); foreach (Component ct in AssmbliesUtils.GetPartComp(this.PartTag, ele.PartTag)) { ElectrodeSetValueInfo value = ElectrodeSetValueInfo.GetAttribute(ct); if (value.Positioning == "" || value.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase)) { centerCom = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, elePoint.Tag) as Point; foreach (Edge eg in faces[10].GetEdges()) { NXOpen.UF.UFEval.Line lineData; if (EdgeUtils.GetLineData(eg, out lineData, ref str)) { if (UMathUtils.IsEqual(lineData.start[1], lineData.end[1])) { xEdge.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, eg.Tag) as Edge); } } } } } }
public override void SetDimForFace(ref LinearDimension ld, Vector3d vec) { foreach (Face face in this.ToolingBox.GetBodies()[0].GetFaces()) { FaceData fd = FaceUtils.AskFaceData(face); Vector3d temp = fd.Dir; this.Matr.ApplyVec(ref temp); double angle = UMathUtils.Angle(vec, temp); if (UMathUtils.IsEqual(angle, 0)) { ld.HandleOrientation = fd.Dir; ld.HandleOrigin = fd.Point; } } }
/// <summary> /// 获取点到面的投影点 /// </summary> /// <param name="pt"></param> /// <param name="face"></param> /// <returns></returns> public static Point3d GetPointToFaceDis(Point pt, Face face) { FaceData faceData = FaceUtils.AskFaceData(face); Matrix4 mat = new Matrix4(); mat.Identity(); mat.TransformToZAxis(faceData.Point, faceData.Dir); Point3d temp = pt.Coordinates; mat.ApplyPos(ref temp); Matrix4 invers = mat.GetInversMatrix(); temp.Z = 0; invers.ApplyPos(ref temp); return(temp); }
/// <summary> /// 获得基准面 /// </summary> /// <returns></returns> private FaceData GetDatumFace() { string er = AttributeUtils.GetAttrForString(analysisBody.AnaFaces[1].Face, "DatumFace"); if (er.Equals("Datum", StringComparison.CurrentCultureIgnoreCase)) { return(analysisBody.AnaFaces[1].Data); } foreach (AnalysisFaceSlopeAndDia fe in analysisBody.AnaFaces) { string da = AttributeUtils.GetAttrForString(fe.Face, "DatumFace"); if (da.Equals("Datum", StringComparison.CurrentCultureIgnoreCase)) { return(fe.Data); } } FaceLoopUtils.LoopList[] loops = FaceLoopUtils.AskFaceLoops(analysisBody.AnaFaces[0].Face.Tag); foreach (FaceLoopUtils.LoopList lt in FaceLoopUtils.AskFaceLoops(analysisBody.AnaFaces[0].Face.Tag)) //找到竖直面 { if (lt.Type == 2) { Edge edg = NXObjectManager.Get(lt.EdgeList[0]) as Edge; foreach (Face fe in edg.GetFaces()) { if (!fe.Equals(analysisBody.AnaFaces[0].Face)) { foreach (Edge eg in fe.GetEdges()) { foreach (Face fc in eg.GetFaces()) { FaceData fd = FaceUtils.AskFaceData(fc); double angle = UMathUtils.Angle(fd.Dir, new Vector3d(0, 0, 1)); if (UMathUtils.IsEqual(angle, 0)) { return(fd); } } } } } } } return(null); }
/// <summary> /// 获取loop最高z值 /// </summary> /// <param name="edges"></param> /// <returns></returns> private double GetLoopMaxOfZ(List <Edge> edges) { double zMax = Math.Round(faceData.BoxMaxCorner.Z, 4); foreach (Edge e in edges) { foreach (Face fa in e.GetFaces()) { if (fa.Tag != face.Tag) { FaceData data = FaceUtils.AskFaceData(fa); double z = Math.Round(data.BoxMaxCorner.Z, 4); if (z > zMax) { zMax = z; } } } } return(zMax); }
public double GetInserHost() { double min = 99999; foreach (Face fc in this.Body.GetFaces()) { { if (fc.SolidFaceType == Face.FaceType.Cylindrical) { FaceData da = FaceUtils.AskFaceData(fc); if (da.IntNorm == -1) { if (min > da.Radius) { min = da.Radius; } } } } } return(min); }
/// <summary> /// 获取平面高度 /// </summary> /// <param name="face"></param> /// <returns></returns> private double GetFaceIsHighst(Face face) { FaceData faceData = FaceUtils.AskFaceData(face); double zMax = Math.Round(faceData.BoxMaxCorner.Z, 3); double faceZ = zMax; foreach (Edge eg in face.GetEdges()) { foreach (Face fa in eg.GetFaces()) { if (fa.Tag != face.Tag) { FaceData data = FaceUtils.AskFaceData(fa); double z = Math.Round(data.BoxMaxCorner.Z, 3); if (z > zMax) { zMax = z; } } } } return(zMax - faceZ); }
/// <summary> /// 设置切削层 /// </summary> /// <param name="zLevel"></param> public void SetCutLevel(Face zLevel) { NXOpen.CAM.ZLevelMillingBuilder builder1; builder1 = workPart.CAMSetup.CAMOperationCollection.CreateZlevelMillingBuilder(this.Oper); FaceData face = FaceUtils.AskFaceData(zLevel); builder1.CutLevel.InitializeData(); builder1.CutLevel.RangeType = CutLevel.RangeTypes.Single; builder1.CutLevel.TopZc = 0; builder1.CutLevel.SetRangeDepth(0, Math.Abs(face.BoxMinCorner.Z + 0.05), NXOpen.CAM.CutLevel.MeasureTypes.TopLevel); try { builder1.Commit(); } catch (NXException ex) { LogMgr.WriteLog("ZLevelMillingModel.SetCutLevel 错误" + ex.Message); } finally { builder1.Destroy(); } }
/// <summary> /// 获取最低面 /// </summary> /// <returns></returns> private List <Face> GetMaxFaceForWave(Body[] bodys) { List <Face> temp = new List <Face>(); foreach (Body body in bodys) { Face maxFace = null; double zMin = 9999; foreach (Face face in body.GetFaces()) { FaceData data = FaceUtils.AskFaceData(face); Point3d center = UMathUtils.GetMiddle(data.BoxMaxCorner, data.BoxMinCorner); if (zMin > center.Z) { zMin = center.Z; maxFace = face; } } temp.Add(maxFace); } return(temp); }
public PlanarBoundary(Face face) { this.face = face; this.faceData = FaceUtils.AskFaceData(this.face); }
/// <summary> ///检查体 /// </summary> /// <returns></returns> public BodyInfo GetBodyInfoForInterference(bool extract, out List <string> err) { err = new List <string>(); List <Face> dischargeFace = new List <Face>(); List <Face> temp = new List <Face>(); List <Body> bodys = new List <Body>(); try { AnalysisUtils.SetInterferenceOutFace(this.eleBody, this.toolBody, out temp, out bodys); } catch (NXException ex) { err.Add("干涉检查错误!" + ex.Message); } if (bodys.Count > 0) { LayerUtils.MoveDisplayableObject(252, bodys.ToArray()); if (extract) { this.eleBody.Color = 186; } err.Add("电极头有过切,请检查!"); } dischargeFace = temp.Where(a => a.GetBody().Equals((this.eleBody))).Distinct().ToList(); //过滤电极面 List <Face> tt = temp.Where(a => a.GetBody().Equals((this.toolBody))).Distinct().ToList(); List <Face> faces = new List <Face>(); foreach (Face fe in dischargeFace) { FaceData data1 = FaceUtils.AskFaceData(fe); foreach (Face fa in tt) { FaceData fd = FaceUtils.AskFaceData(fa); if (UMathUtils.SelfDis(data1.Dir) == 0) { if (data1.FaceType == fd.FaceType && data1.IntNorm == -fd.IntNorm) { faces.Add(fe); break; } } else { double anlge = UMathUtils.Angle(data1.Dir, fd.Dir); if (data1.FaceType == fd.FaceType && data1.IntNorm == -fd.IntNorm && UMathUtils.IsEqual(anlge, Math.PI)) { faces.Add(fe); break; } } } } if (extract) { ExtractFace(this.toolBody, faces.ToArray()); } BodyInfo info = new BodyInfo(eleBody, faces); info.SetAttribute(csys, matr); return(info); }