Ejemplo n.º 1
0
        static List <ElevationBox> BuildElevationBoxesFrom(
            Transaction transaction,
            List <ObjectId> boxes,
            List <ObjectId> labels)
        {
            var elevationBoxes = new List <ElevationBox>();

            foreach (var box in boxes)
            {
                var polyline = transaction.GetObject(box, OpenMode.ForRead) as Polyline;
                foreach (var label in labels)
                {
                    var mtext = transaction.GetObject(label, OpenMode.ForRead) as MText;
                    if (mtext == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < polyline.NumberOfVertices; i++)
                    {
                        if (PointExtensions.IsNear(mtext.Location, polyline.GetPoint3dAt(i)) &&
                            !elevationBoxes.Exists(b => b.Id == polyline.Id))
                        {
                            var match = Regex.Match(
                                mtext.Text,
                                @"Elevation (\d+)",
                                RegexOptions.IgnoreCase);

                            if (!match.Success)
                            {
                                continue;
                            }

                            int elevation = int.Parse(match.Groups[1].Value);

                            var b = new ElevationBox(polyline)
                            {
                                Id        = polyline.Id,
                                Elevation = elevation
                            };

                            b.SetSides(polyline);
                            elevationBoxes.Add(b);

                            continue;
                        }
                    }
                }
            }

            return(elevationBoxes);
        }
Ejemplo n.º 2
0
        public static void Insert(Point3d point)
        {
            var boxes = ElevationBox.InsideElevationBoxes(point);

            if (boxes.Count == 0)
            {
                Editor().WriteMessage("\nError!  You must insert a riser inside an elevation box.");
                return;
            }

            if (boxes.Count(b => b.FloorTag != null) != 1)
            {
                Editor().WriteMessage("\nError!  You must insert a floor tag on each floor.");
                return;
            }

            var floorTag = boxes.Select(b => b.FloorTag).Single();
            var offset   = new Point3d(
                x: point.X - floorTag.Position.X,
                y: point.Y - floorTag.Position.Y,
                0);

            var allFloorTags = FloorTag.GetFloorTags();

            if (allFloorTags.Count > 10)
            {
                Editor().WriteMessage("\nError! LoopCAD cannot handle more than ten floors.");
                return;
            }

            var selectedFloorTags = new List <FloorTag>()
            {
                floorTag
            };

            if (allFloorTags.Count > 1)
            {
                var pko = new PromptKeywordOptions("");
                foreach (var ft in allFloorTags)
                {
                    if (ft.Name != floorTag.Name)
                    {
                        pko.Keywords.Add($"{allFloorTags.IndexOf(ft)}: {ft.Name}");
                    }
                }

                pko.Message   = "\nChoose floor to run riser pipe to ";
                pko.AllowNone = false;

                PromptResult result = Editor().GetKeywords(pko);

                if (result.Status == PromptStatus.OK)
                {
                    int floorIndex = int.Parse(result.StringResult[0].ToString());
                    selectedFloorTags.Add(allFloorTags[floorIndex]);
                }
            }

            if (selectedFloorTags.Count != 2)
            {
                Editor().WriteMessage("Error! The riser could not be inserted on two floors.");

                return;
            }

            char suffix = (char)((byte)RiserLabel.HighestSuffix() + 1);
            int  number = RiserLabel.HighestNumber() + 1;

            foreach (var ft in selectedFloorTags)
            {
                // This point will be disposed, so clone it
                var newPoint = new Point3d(
                    x: ft.Position.X + offset.X,
                    y: ft.Position.Y + offset.Y,
                    z: ft.Position.Z + offset.Z);

                Riser.Insert(newPoint);

                var labeler = new Labeler(
                    new LabelSpecs
                {
                    Tag             = RiserLabel.TagName,
                    BlockName       = RiserLabel.BlockName,
                    Layer           = RiserLabel.LayerName,
                    LayerColorIndex = ColorIndices.Cyan,
                    TextHeight      = 8.0,
                    XOffset         = 15.0,
                });

                labeler.CreateLabel($"R.{number}.{suffix}", position: newPoint);

                // Number increments, but suffix is shared between the
                // upper and lower riser, and used to match them.
                number++;
            }
        }