protected override Status FixImpl(CheckResult checkResult, out List <ObjectId> resultIds)
        {
            resultIds = new List <ObjectId>();
            var apparentIntersectionCheckResult = checkResult as ApparentIntersectionCheckResult;

            if (apparentIntersectionCheckResult == null)
            {
                return(Status.Rejected);
            }

            var intersection = apparentIntersectionCheckResult.IntersectionInfo;

            using (var transaction = Document.Database.TransactionManager.StartTransaction())
            {
                CurveUtils.ExtendCurve(intersection.SourceId, intersection.IntersectPoint, intersection.SourceExtendType, transaction);
                CurveUtils.ExtendCurve(intersection.TargetId, intersection.IntersectPoint, intersection.TargetExtendType, transaction);

                // Add sourceId and targetId in the resultIds.
                resultIds.Add(intersection.SourceId);
                resultIds.Add(intersection.TargetId);

                // Target curve
                transaction.Commit();
            }
            return(Status.Fixed);
        }
예제 #2
0
        public Dictionary <ObjectId, List <ObjectId> > Fix(bool breakTarget)
        {
            if (UnderShootInfos == null || !UnderShootInfos.Any())
            {
                return(new Dictionary <ObjectId, List <ObjectId> >());
            }

            var result   = new Dictionary <ObjectId, List <ObjectId> >();
            var database = Editor.Document.Database;

            using (var transaction = database.TransactionManager.StartTransaction())
            {
                var blockTable = (BlockTable)transaction.GetObject(database.BlockTableId, OpenMode.ForRead);
                var modelSpace = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                // Group by target Id, and split it in one time.
                var groups = UnderShootInfos.GroupBy(it => it.TargetId);
                foreach (var group in groups)
                {
                    // Extend source curves first.
                    foreach (var intersectionInfo in group)
                    {
                        CurveUtils.ExtendCurve(intersectionInfo.SourceId, intersectionInfo.IntersectPoint, intersectionInfo.SourceExtendType, transaction);
                    }

                    if (breakTarget)
                    {
                        // Then split the target
                        var points = group.Select(it => it.IntersectPoint);

                        var spliltCurves = CurveUtils.SplitCurve(group.Key, points.ToArray(), transaction);

                        if (spliltCurves != null && spliltCurves.Count > 0)
                        {
                            // The splitted curves has the same layer with original curve,
                            // so we needn't set its layer explicitly.
                            var ids = new List <ObjectId>();
                            foreach (Curve splitCurve in spliltCurves)
                            {
                                var id = modelSpace.AppendEntity(splitCurve);
                                transaction.AddNewlyCreatedDBObject(splitCurve, true);
                                ids.Add(id);
                            }
                            result.Add(group.Key, ids);

                            // Erase the original one
                            var originCurve = (Entity)transaction.GetObject(group.Key, OpenMode.ForRead) as Curve;
                            if (originCurve != null)
                            {
                                originCurve.UpgradeOpen();
                                originCurve.Erase();
                            }
                        }
                    }
                }
                transaction.Commit();
            }
            return(result);
        }
예제 #3
0
        protected override Status FixImpl(CheckResult checkResult, out List <ObjectId> resultIds)
        {
            resultIds = new List <ObjectId>();
            var undershootCheckResult = checkResult as UnderShootCheckResult;

            if (undershootCheckResult == null)
            {
                return(Status.Rejected);
            }

            var intersection = undershootCheckResult.IntersectionInfo;

            using (var transaction = Document.Database.TransactionManager.StartTransaction())
            {
                // Extend source curve
                CurveUtils.ExtendCurve(intersection.SourceId, intersection.IntersectPoint, intersection.SourceExtendType, transaction);
                resultIds.Add(intersection.SourceId);

                // Break target curve
                if (BreakTargetCurve)
                {
                    var blockTable = (BlockTable)transaction.GetObject(Document.Database.BlockTableId, OpenMode.ForRead);
                    var modelSpace = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    var splittedCurves = CurveUtils.SplitCurve(intersection.TargetId, new Point3d[] { intersection.IntersectPoint }, transaction);
                    if (splittedCurves != null && splittedCurves.Count > 0)
                    {
                        foreach (DBObject dbObj in splittedCurves)
                        {
                            var splitedCurve = dbObj as Entity;
                            if (splitedCurve == null)
                            {
                                continue;
                            }

                            var objId = modelSpace.AppendEntity(splitedCurve);
                            transaction.AddNewlyCreatedDBObject(splitedCurve, true);
                            resultIds.Add(objId);
                        }

                        // Erase the original one
                        var sourceCurve = (Entity)transaction.GetObject(intersection.TargetId, OpenMode.ForRead) as Curve;
                        if (sourceCurve != null)
                        {
                            sourceCurve.UpgradeOpen();
                            sourceCurve.Erase();
                        }
                    }
                }
                transaction.Commit();
            }
            return(Status.Fixed);
        }