Esempio n. 1
0
        public override Snap.NX.Face GetChamferFace()
        {
            if (ChamferFace != null)
            {
                return(ChamferFace);
            }
            Snap.NX.Face result  = null;
            var          results = new List <Snap.NX.Face>();

            if (BaseFace != null)
            {
                var baseFOriention = new Snap.Orientation(BaseFace.GetFaceDirection());
                var v1             = Snap.Vector.Unit(baseFOriention.AxisX);
                var v2             = Snap.Vector.Unit(baseFOriention.AxisY);
                var v3             = Snap.Vector.Unit(v1 + v2);
                var v4             = v3.Copy(Snap.Geom.Transform.CreateRotation(new Snap.Position(), BaseFace.GetFaceDirection(), 90)).Unitize();

                var chamferFaces = ElecBody.Faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane && Snap.Compute.Distance(u, BaseFace) < SnapEx.Helper.Tolerance).ToList();
                chamferFaces.ForEach(u =>
                {
                    var faceDir = u.GetFaceDirection();
                    if (SnapEx.Helper.Equals(v3, faceDir, SnapEx.Helper.Tolerance) ||
                        SnapEx.Helper.Equals(-v3, faceDir, SnapEx.Helper.Tolerance) ||
                        SnapEx.Helper.Equals(-v4, faceDir, SnapEx.Helper.Tolerance) ||
                        SnapEx.Helper.Equals(v4, faceDir, SnapEx.Helper.Tolerance)
                        )
                    {
                        results.Add(u);
                    }
                });
            }

            result = results.FirstOrDefault();

            if (results.Count > 1)
            {
                var baseFaceBoxUV = BaseFace.BoxUV;
                var elecBasePos   = BaseFace.Position((baseFaceBoxUV.MinU + baseFaceBoxUV.MaxU) / 2, (baseFaceBoxUV.MinV + baseFaceBoxUV.MaxV) / 2);

                var faceDirection = BaseFace.GetFaceDirection();
                var plane         = new Snap.Geom.Surface.Plane(elecBasePos, faceDirection);

                foreach (var u in results)
                {
                    var uv          = u.BoxUV;
                    var cneterPoint = u.Position((uv.MaxU + uv.MinU) / 2, (uv.MaxV + uv.MaxV) / 2);
                    var resullt     = Snap.Compute.ClosestPoints(cneterPoint, plane);
                    var dir         = Snap.Vector.Unit(resullt.Point1 - resullt.Point2);
                    if (SnapEx.Helper.Equals(dir, -faceDirection) && Snap.Compute.Distance(BaseFace, u) < SnapEx.Helper.Tolerance)
                    {
                        result = u;
                        break;
                    }
                }
            }

            ChamferFace = result;

            return(result);
        }
Esempio n. 2
0
        protected override Snap.NX.Face GetTopFace()
        {
            var faceDirection = BaseFace.GetFaceDirection();
            var faces         = ElecBody.Faces.ToList();
            var topFace       = faces.Where(u => u.IsHasAttr(ELEC_BASE_BOTTOM_FACE)).FirstOrDefault();

            if (topFace == null)
            {
                var topFaces = faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane).Where(u => SnapEx.Helper.Equals(-faceDirection, u.GetFaceDirection())).ToList();
                topFace = topFaces.FirstOrDefault();
                if (topFaces.Count > 1)
                {
                    var basePlane       = BaseFace as Snap.NX.Face.Plane;
                    var baseOrigin      = basePlane.Geometry.Origin;
                    var baseFaceBox     = BaseFace.Box;
                    var baseCenterPoint = new Snap.Position((baseFaceBox.MaxX + baseFaceBox.MinX) / 2, (baseFaceBox.MaxY + baseFaceBox.MinY) / 2, (baseFaceBox.MaxZ + baseFaceBox.MinZ) / 2);
                    topFaces.ForEach(u => {
                        var uBox         = u.Box;
                        var uCenterPoint = new Snap.Position((uBox.MaxX + uBox.MinX) / 2, (uBox.MaxY + uBox.MinY) / 2, (uBox.MaxZ + uBox.MinZ) / 2);
                        if (SnapEx.Helper.Equals(u.GetFaceDirection(), Snap.Vector.Unit(uCenterPoint - baseCenterPoint), SnapEx.Helper.Tolerance))
                        {
                            topFace = u;
                            return;
                        }
                    });
                }
            }
            TopFace = topFace;
            return(topFace);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取象限类型
        /// </summary>
        public QuadrantType GetQuadrantType(Snap.Orientation wcs, QuadrantType defaultQ = QuadrantType.First)
        {
            var result      = defaultQ;
            var chamferFace = GetChamferFace();

            if (chamferFace != null && BaseFace != null)
            {
                var dir = chamferFace.GetFaceDirection().Copy(GetElecTransWcsToAcs(BaseFace.GetFaceDirection(), wcs));
                result = SnapEx.Helper.GetQuadrantType(dir);
            }
            return(result);
        }
Esempio n. 4
0
        public override Snap.NX.Face GetTopFace()
        {
            if (TopFace != null)
            {
                return(TopFace);
            }
            var faceDirection = BaseFace.GetFaceDirection();
            var faces         = ElecBody.Faces.ToList();
            var topFaces      = faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane).Where(u =>
                                                                                                                 SnapEx.Helper.Equals(-faceDirection, u.GetFaceDirection())
                                                                                                                 ).ToList();
            var topFace = topFaces.OrderByDescending(u => u.GetPlaneProjectArea(faceDirection)).FirstOrDefault();

            if (topFace == null)
            {
                topFace = BaseFace;
            }
            TopFace = topFace;
            return(topFace);
        }
Esempio n. 5
0
        public override Snap.NX.Face GetChamferFace()
        {
            Snap.NX.Face result  = null;
            var          results = new List <Snap.NX.Face>();

            if (BaseFace != null && DiagonalLine != null)
            {
                var boxUV  = BaseFace.BoxUV;
                var points = new List <Snap.Position>();
                points.Add(BaseFace.Position(boxUV.MinU, boxUV.MinV));
                points.Add(BaseFace.Position(boxUV.MinU, boxUV.MaxV));
                points.Add(BaseFace.Position(boxUV.MaxU, boxUV.MinV));
                points.Add(BaseFace.Position(boxUV.MaxU, boxUV.MaxV));

                points.RemoveAll(u => SnapEx.Helper.Equals(u, DiagonalLine.StartPoint, SnapEx.Helper.Tolerance));
                points.RemoveAll(u => SnapEx.Helper.Equals(u, DiagonalLine.EndPoint, SnapEx.Helper.Tolerance));
                var v1 = Snap.Vector.Unit(points.First() - DiagonalLine.StartPoint);
                var v2 = Snap.Vector.Unit(points.First() - DiagonalLine.EndPoint);
                var v3 = Snap.Vector.Unit(v1 + v2);
                var v4 = v3.Copy(Snap.Geom.Transform.CreateRotation(new Snap.Position(), BaseFace.GetFaceDirection(), 90)).Unitize();

                if (points.Count > 0)
                {
                    ElecBody.Faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane).ToList().ForEach(u =>
                    {
                        var faceDir = u.GetFaceDirection();
                        if (SnapEx.Helper.Equals(v3, faceDir, SnapEx.Helper.Tolerance) ||
                            SnapEx.Helper.Equals(-v3, faceDir, SnapEx.Helper.Tolerance) ||
                            SnapEx.Helper.Equals(-v4, faceDir, SnapEx.Helper.Tolerance) ||
                            SnapEx.Helper.Equals(v4, faceDir, SnapEx.Helper.Tolerance)
                            )
                        {
                            results.Add(u);
                        }
                    });
                }
            }

            result = results.FirstOrDefault();

            if (results.Count > 1)
            {
                var baseFaceBoxUV = BaseFace.BoxUV;
                var elecBasePos   = BaseFace.Position((baseFaceBoxUV.MinU + baseFaceBoxUV.MaxU) / 2, (baseFaceBoxUV.MinV + baseFaceBoxUV.MaxV) / 2);

                var faceDirection = BaseFace.GetFaceDirection();
                var plane         = new Snap.Geom.Surface.Plane(elecBasePos, faceDirection);

                results.ForEach(u => {
                    var uv          = u.BoxUV;
                    var cneterPoint = u.Position((uv.MaxU + uv.MinU) / 2, (uv.MaxV + uv.MaxV) / 2);
                    var resullt     = Snap.Compute.ClosestPoints(cneterPoint, plane);
                    var dir         = Snap.Vector.Unit(resullt.Point1 - resullt.Point2);
                    if (SnapEx.Helper.Equals(dir, -faceDirection))
                    {
                        result = u;
                        return;
                    }
                });
            }

            ChamferFace = result;

            return(result);
        }