Пример #1
0
        /// <summary>
        /// 判断当前面是否与某个面相关联
        /// </summary>
        /// <param name="face">判断是否关联的面</param>
        /// <param name="associateDist">容忍值,就是容差</param>
        /// <param name="peakValue">距离值,属于特定的距离判定</param>
        /// <returns></returns>
        internal bool IsAssocaitedWithAnotherFace(PartFace anotherFace, double associateDist, double peakValue)
        {
            /*
            * 判断原则
            * 1、两个面平行且距离小于某个固定值
            * 2、指令面的所有顶点,投影到被关联面,至少有一个点位于关联面的内部
            * 3、如果是开槽关联,则上述两条不适用
            */

            //如果他们是同一个板件的不同面,永远都是不关联的
            if (this.Part == anotherFace.Part)
                return false;

            //如果两个面不平行,那也是不关联的
            //TODO:这里用到了Plane属于CAD的实体,是否会造成内存泄漏?
            if (!anotherFace.Plane.IsParallelTo(this.Plane))
            {
                return false;
            }

            //如果面试四个水平边,也不进行判断,(考虑到开槽、层板孔指令的适用范围)
            if (anotherFace.IsHorizontalFace)
                return false;

            ////不再做距离关联,距离的判断放到点的判断中
            ////如果两个面的距离大于一定距离也就不关联
            //if (anotherFace.Plane.DistanceTo(this.Point1) > dist)
            //{
            //    return false;
            //}

            //需要判断两件事情:
            //1、距离的判断,如嵌入的深度等等
            //2、板件是否嵌入,嵌入一个点还是两个点等等
            if (!IsDistEnough(anotherFace, this.Point1, peakValue, associateDist))
                return false;

            //用using,使用完就销毁掉这些对象
            using (Line line1 = new Line(this.Point1, this.Point4))
            using (Line line2 = new Line(this.Point2, this.Point3))
            using (Line fLine1 = new Line(anotherFace.Point1, anotherFace.Point2))
            using (Line fLine2 = new Line(anotherFace.Point2, anotherFace.Point3))
            using (Line fLine3 = new Line(anotherFace.Point3, anotherFace.Point4))
            using (Line fLine4 = new Line(anotherFace.Point4, anotherFace.Point1))
            {
                using (Line line1Project = line1.GetOrthoProjectedCurve(anotherFace.Plane) as Line)
                using (Line line2Project = line2.GetOrthoProjectedCurve(anotherFace.Plane) as Line)
                {
                    Line[] lines = new Line[] { fLine1, fLine2, fLine3, fLine4 };

                    foreach (Line l in lines)
                    {
                        Point3dCollection pts1 = new Point3dCollection();
                        Point3dCollection pts2 = new Point3dCollection();

                        l.IntersectWith(line1Project, Intersect.OnBothOperands, pts1, IntPtr.Zero, IntPtr.Zero);

                        if (pts1.Count > 0)
                            return true;

                        l.IntersectWith(line2Project, Intersect.OnBothOperands, pts2, IntPtr.Zero, IntPtr.Zero);
                        if (pts2.Count > 0)
                            return true;
                    }
                }
            }

            return false;
        }