Ejemplo n.º 1
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);
        }
        protected override Status FixImpl(CheckResult checkResult, out List <ObjectId> resultIds)
        {
            resultIds = new List <ObjectId>();
            var crossingCheckResult = checkResult as CrossingCheckResult;

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

            var crossingInfo = crossingCheckResult.CrossingInfo;
            var distinctIds  = new HashSet <ObjectId>();

            distinctIds.Add(crossingInfo.SourceId);
            distinctIds.Add(crossingInfo.TargetId);

            using (var transaction = Document.Database.TransactionManager.StartTransaction())
            {
                //// distinctIds == 1说明是自交线
                bool isSelfIntersection = (distinctIds.Count == 1);

                var modelSpace = (BlockTableRecord)transaction.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Document.Database), OpenMode.ForWrite);
                foreach (var sourceId in distinctIds)
                {
                    var sourceCurve = transaction.GetObject(sourceId, OpenMode.ForWrite) as Curve;
                    DBObjectCollection allSplitCurves = null;
                    if (isSelfIntersection)
                    {
                        allSplitCurves = CurveUtils.SplitSelfIntersectCurve(sourceCurve, crossingInfo.IntersectPoints, transaction);
                    }
                    else // Use CurveUtils.SplitCurve take less time.
                    {
                        allSplitCurves = CurveUtils.SplitCurve(sourceCurve, crossingInfo.IntersectPoints);
                    }

                    // The splitted curves has the same layer with original curve,
                    // so we needn't set its layer explicitly.
                    foreach (Curve splitCurve in allSplitCurves)
                    {
                        var curveId = modelSpace.AppendEntity(splitCurve);
                        transaction.AddNewlyCreatedDBObject(splitCurve, true);
                        // Add splited curve to resultIds.
                        resultIds.Add(curveId);
                    }

                    if (allSplitCurves.Count > 0)
                    {
                        // Erase the old one
                        sourceCurve.Erase();
                    }
                }
                transaction.Commit();
            }
            return(Status.Fixed);
        }
Ejemplo n.º 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);
        }