コード例 #1
0
        public void AddEntityToPOIs(Entity ent)
        {
            switch (ent)
            {
            case Polyline pline:
                switch (GetPipeSystem(pline))
                {
                case PipeSystemEnum.Ukendt:
                    prdDbg($"Wrong type of pline supplied: {pline.Handle}");
                    return;

                case PipeSystemEnum.Stål:
                    POIs.Add(new POI(pline, pline.StartPoint.To2D(), EndType.Start, PSM, DriGraph));
                    POIs.Add(new POI(pline, pline.EndPoint.To2D(), EndType.End, PSM, DriGraph));
                    break;

                case PipeSystemEnum.Kobberflex:
                case PipeSystemEnum.AluPex:
                    #region STIK        //Find forbindelse til forsyningsrøret
                    Point3d pt    = pline.StartPoint;
                    var     query = allPipes.Where(x =>
                                                   pt.IsOnCurve(x, 0.025) &&
                                                   pline.Handle != x.Handle &&
                                                   GetPipeSystem(x) == PipeSystemEnum.Stål);

                    if (query.FirstOrDefault() != default)
                    {
                        Polyline parent = query.FirstOrDefault();
                        POIs.Add(new POI(parent, parent.GetClosestPointTo(pt, false).To2D(), EndType.StikAfgrening, PSM, DriGraph));
                    }

                    pt = pline.EndPoint;
                    if (query.FirstOrDefault() != default)
                    {
                        //This shouldn't happen now, because AssignPlinesAndBlocksToAlignments
                        //guarantees that the end point is never on a supply pipe
                        Polyline parent = query.FirstOrDefault();
                        POIs.Add(new POI(parent, parent.GetClosestPointTo(pt, false).To2D(), EndType.StikAfgrening, PSM, DriGraph));
                    }
                    #endregion

                    //Tilføj almindelige ender til POIs
                    POIs.Add(new POI(pline, pline.StartPoint.To2D(), EndType.StikStart, PSM, DriGraph));
                    POIs.Add(new POI(pline, pline.EndPoint.To2D(), EndType.StikEnd, PSM, DriGraph));
                    break;

                default:
                    throw new System.Exception("Supplied a new PipeSystemEnum! Add to code kthxbai.");
                }
                break;

            case BlockReference br:
                Transaction      tx  = br.Database.TransactionManager.TopTransaction;
                BlockTableRecord btr = br.BlockTableRecord.Go <BlockTableRecord>(tx);
                foreach (Oid oid in btr)
                {
                    if (!oid.IsDerivedFrom <BlockReference>())
                    {
                        continue;
                    }
                    BlockReference nestedBr = oid.Go <BlockReference>(tx);
                    if (!nestedBr.Name.Contains("MuffeIntern"))
                    {
                        continue;
                    }
                    Point3d wPt = nestedBr.Position;
                    wPt = wPt.TransformBy(br.BlockTransform);
                    EndType endType;
                    if (nestedBr.Name.Contains("BRANCH"))
                    {
                        endType = EndType.Branch;
                    }
                    else
                    {
                        endType = EndType.Main;
                        //Handle special case of AFGRSTUDS
                        //which does not coincide with an end on polyline
                        //but is situated somewhere along the polyline
                        if (br.RealName() == "AFGRSTUDS")
                        {
                            PropertySetManager psmPipeline =
                                new PropertySetManager(dB, PSetDefs.DefinedSets.DriPipelineData);
                            PSetDefs.DriPipelineData driPipelineData = new PSetDefs.DriPipelineData();

                            string branchAlName = psmPipeline.ReadPropertyString(br, driPipelineData.BranchesOffToAlignment);
                            if (branchAlName.IsNoE())
                            {
                                prdDbg(
                                    $"WARNING! Afgrstuds {br.Handle} has no BranchesOffToAlignment value.\n" +
                                    $"This happens if there are objects with no alignment assigned.\n" +
                                    $"To fix enter main alignment name in BranchesOffToAlignment field.");
                            }

                            var polylines = allPipes
                                            //.GetFjvPipes(tx, true)
                                            //.HashSetOfType<Polyline>(tx, true)
                                            .Where(x => psmPipeline.FilterPropetyString
                                                       (x, driPipelineData.BelongsToAlignment, branchAlName));
                            //.ToHashSet();

                            foreach (Polyline polyline in polylines)
                            {
                                Point3d nearest = polyline.GetClosestPointTo(wPt, false);
                                if (nearest.DistanceHorizontalTo(wPt) < 0.01)
                                {
                                    POIs.Add(new POI(polyline, nearest.To2D(), EndType.Branch, PSM, DriGraph));
                                    break;
                                }
                            }
                        }
                    }
                    POIs.Add(new POI(br, wPt.To2D(), endType, PSM, DriGraph));
                }
                break;

            default:
                throw new System.Exception("Wrong type of object supplied!");
            }
        }