private IEnumerable <IntersectionInfo> GetApparentIntersections(CurveVertex current, IEnumerable <CurveVertex> danglingVertices,
                                                                        HashSet <CurveVertex> visitedVertices, Transaction transaction)
        {
            visitedVertices.Add(current);
            var result = new List <IntersectionInfo>();
            var ids    = Editor.SelectEntitiesAtPoint(SelectionFilterUtils.OnlySelectCurve(), current.Point, _tolerance);

            foreach (var id in ids)
            {
                // Check whether danglingVertices contains this id.
                var vertices = danglingVertices.Where(it => it.Id == id);
                if (!vertices.Any())
                {
                    continue;
                }

                // Check each vertex of this id.
                foreach (var vertex in vertices)
                {
                    if (vertex == current)
                    {
                        continue;
                    }

                    if (visitedVertices.Contains(vertex))
                    {
                        continue;
                    }

                    var distance = (vertex.Point - current.Point).Length;
                    if (distance.Larger(_tolerance * 2))
                    {
                        continue;
                    }

                    // Calcuate the intersection info of these two vertices.
                    var info = CalcApparentIntersection(current, vertex, transaction);
                    if (info != null)
                    {
                        result.Add(info);
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Select entities at point by editor.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="editor"></param>
        /// <returns></returns>
        protected ObjectId[] SelectCurvesAtPoint(Point3d point)
        {
            var selectionFilter = SelectionFilterUtils.OnlySelectCurve();

            return(Editor.SelectEntitiesAtPoint(selectionFilter, point));
        }
Beispiel #3
0
        private IntersectionInfo GetUnderShootIntersection(CurveVertex vertex, Transaction transaction, double tolerance)
        {
            var curve         = transaction.GetObject(vertex.Id, OpenMode.ForRead);
            var desiredExtend = CurveUtils.GetExtendType((Curve)curve, vertex.Point);

            var line       = curve as Line;
            var arc        = curve as Arc;
            var polyline   = curve as Polyline;
            var polyline2d = curve as Polyline2d;

            if (polyline != null)
            {
                line = CurveUtils.CutOutLineFromPolyLine(polyline, vertex.Point);
            }
            else if (polyline2d != null)
            {
                line = CurveUtils.CutOutLineFromPolyline2d(polyline2d, vertex.Point, transaction);
            }

            // Construct a polygon to get adjacent entities.
            Point3dCollection polygon = null;

            if (line != null)
            {
                var direction = line.EndPoint - line.StartPoint;
                if (desiredExtend == ExtendType.ExtendStart)
                {
                    direction = -1.0 * direction;
                }
                polygon = BuildSelectionPolygonForLine(vertex.Point, direction, tolerance);
            }
            else if (arc != null)
            {
                polygon = BuildSelectionPolygonForArc(vertex.Point, tolerance);
            }

            // Zoom window
            var minPt   = new Point3d(vertex.Point.X - tolerance, vertex.Point.Y - tolerance, 0.0);
            var maxPt   = new Point3d(vertex.Point.X + tolerance, vertex.Point.Y + tolerance, 0.0);
            var extents = new Extents3d(minPt, maxPt);

            Editor.ZoomToWin(extents, factor: 2.0);

            var selectionResult = Editor.SelectCrossingPolygon(polygon, SelectionFilterUtils.OnlySelectCurve());

            if (selectionResult.Status != PromptStatus.OK || selectionResult.Value == null)
            {
                return(null);
            }

            // Check each adjacent entity whether they are intersected.
            var intersectionInfos = new List <IntersectionInfo>();
            var adjacentIds       = selectionResult.Value.GetObjectIds();

            foreach (ObjectId objId in adjacentIds)
            {
                var targetCurve = transaction.GetObject(objId, OpenMode.ForRead) as Curve;
                if (targetCurve == null)
                {
                    continue;
                }

                // Calculate the intersection
                IntersectionInfo info = null;
                if (line != null)
                {
                    info = IntersectLineAndCurve(line, targetCurve, vertex.Point, desiredExtend);
                }
                else if (arc != null)
                {
                    info = IntersectArcAndCurve(arc, targetCurve, vertex.Point, desiredExtend);
                }

                if (info != null && info.SourceExtendType == desiredExtend)
                {
                    info.SourceId = vertex.Id;
                    info.TargetId = objId;

                    intersectionInfos.Add(info);
                }
            }

            // Get nearest point.
            if (intersectionInfos.Count <= 0)
            {
                return(null);
            }

            var nearest     = intersectionInfos[0];
            var nearsetDist = (intersectionInfos[0].IntersectPoint - vertex.Point).Length;

            for (int i = 1; i < intersectionInfos.Count; i++)
            {
                var dist = (intersectionInfos[i].IntersectPoint - vertex.Point).Length;
                if (dist < nearsetDist)
                {
                    nearsetDist = dist;
                    nearest     = intersectionInfos[i];
                }
            }

            if (nearsetDist.Larger(tolerance))
            {
                return(null);
            }

            return(nearest);
        }
        public ObjectIdCollection GetDuplicateCurveIdsByCurve(Transaction trans, Curve curve)
        {
            var duplicateCurveIds = new ObjectIdCollection();
            var entityIds         = EditorUtils.SelectObjectsByEntityBoundingBox(base.Editor, SelectionFilterUtils.OnlySelectCurve(), curve, _tolerance * 2);

            var currentLine    = curve as Line;
            var currentArc     = curve as Arc;
            var currentPline   = curve as Polyline;
            var currentPline2d = curve as Polyline2d;

            foreach (ObjectId entityId in entityIds)
            {
                // Filter out itself.
                if (entityId == curve.ObjectId)
                {
                    continue;
                }

                var entity = trans.GetObject(entityId, OpenMode.ForRead) as Curve;
                if (entity == null)
                {
                    continue;
                }

                // 所有的比较,都需要比较起始点和终点是否重合,如果不重合,则认为不是duplicate curves.
                if (IsStartAndEndPointsEquals(curve, entity) == false)
                {
                    continue;
                }

                var line    = entity as Line;
                var arc     = entity as Arc;
                var pline   = entity as Polyline;
                var pline2d = entity as Polyline2d;

                bool isDuplicate = false;

                if (currentLine != null)
                {
                    // 找Line的重复直线或多段线
                    // 如果是Line->Line,则为重合
                    // 如果是Line->Polyline,则比较长度
                    // 如果是Line->Polyline2d,则比较长度
                    if (line != null)
                    {
                        isDuplicate = true;
                    }
                    else if (pline != null && IsLengthEquals(currentLine, pline, _tolerance))
                    {
                        isDuplicate = true;
                    }
                    else if (pline2d != null && IsLengthEquals(currentLine, pline2d, _tolerance))
                    {
                        isDuplicate = true;
                    }
                }
                else if (currentArc != null)
                {
                    // 找Arc的重复Arc,比较Arc的StartAngle和EndAngle
                    if (arc != null)
                    {
                        if ((((currentArc.StartPoint - arc.StartPoint).Length < _tolerance) &&
                             Math.Abs(currentArc.StartAngle - arc.StartAngle) < _tolerance &&
                             Math.Abs(currentArc.EndAngle - arc.EndAngle) < _tolerance) ||
                            (((currentArc.StartPoint - arc.EndPoint).Length < _tolerance) &&
                             Math.Abs(currentArc.StartAngle - arc.EndAngle) < _tolerance &&
                             Math.Abs(currentArc.EndAngle - arc.StartAngle) < _tolerance))
                        {
                            isDuplicate = true;
                        }
                    }
                }
                else if (currentPline != null)
                {
                    // 找Polyline的重复直线或多段线
                    // 如果是Polyline->Line,则比较及长度
                    // 如果是Polyline->Polyline 则比较所有节点位置
                    // 如果是Polyline->Polyline2d 则比较所有节点位置
                    if (line != null && IsLengthEquals(line, currentPline, _tolerance))
                    {
                        isDuplicate = true;
                    }
                    else if (pline != null && IsVertexesEquals(currentPline, pline, _tolerance, trans))
                    {
                        isDuplicate = true;
                    }
                    else if (pline2d != null && IsVertexesEquals(currentPline, pline2d, _tolerance, trans))
                    {
                        isDuplicate = true;
                    }
                }
                else if (currentPline2d != null)
                {
                    // 找Polyline的重复直线或多段线
                    // 如果是Polyline2d->Line,则比较长度
                    // 如果是Polyline->Polyline 则比较所有节点位置
                    // 如果是Polyline->Polyline2d 则比较所有节点位置
                    if (line != null && IsLengthEquals(line, currentPline2d, _tolerance))
                    {
                        isDuplicate = true;
                    }
                    else if (pline != null && IsVertexesEquals(pline, currentPline2d, _tolerance, trans))
                    {
                        isDuplicate = true;
                    }
                    else if (pline2d != null && IsVertexesEquals(currentPline2d, pline2d, _tolerance, trans))
                    {
                        isDuplicate = true;
                    }
                }
                if (isDuplicate)
                {
                    duplicateCurveIds.Add(entityId);
                }
            }

            // 如果找到重复线,则将其自己也加入到duplicateCurveIds
            if (duplicateCurveIds.Count > 0)
            {
                duplicateCurveIds.Add(curve.ObjectId);
            }

            return(duplicateCurveIds);
        }