Exemplo n.º 1
0
        public void JsCmd()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;

            var basePt = doc.Editor.GetPoint("\n请输入起始点:");

            if (basePt.Status == PromptStatus.OK)
            {
                var jigOpt = new JigPromptPointOptions();

                var line = new Line(basePt.Value, basePt.Value);

                var polyLine = new Polyline(4)
                {
                    Closed = true
                };

                var hatch = new Hatch();

                hatch.SetHatchPattern(HatchPatternType.PreDefined, "BOX");

                var wall = new JigHelper();

                wall.PrapareForNextInput(jigOpt, "\n请输入墙顶中心坐标:");

                wall.SetEntities(new Entity[] { line });

                wall.SetUpdate(jig =>
                {
                    line.EndPoint = jig.Point;
                });

                if (wall.Drag() != PromptStatus.OK)
                {
                    return;
                }

                wall.PrapareForNextInput(jigOpt, "\n请输入墙面宽度:");

                wall.SetEntities(new Entity[] { polyLine, hatch });

                wall.SetUpdate(jig =>
                {
                    var edgePt = jig.Point;

                    var centerToEdgeLength = (line.StartPoint - line.EndPoint)
                                             .CrossProduct(edgePt - line.EndPoint)
                                             .Length / line.Length;

                    var centerToEdge = (line.StartPoint - line.EndPoint)
                                       .RotateBy(Math.PI / 2, Vector3d.ZAxis)
                                       .GetNormal() * centerToEdgeLength;

                    Point3d pt;

                    pt = line.StartPoint - centerToEdge;
                    polyLine.SetPointAt(0, new Point2d(pt.X, pt.Y));

                    pt = line.StartPoint + centerToEdge;
                    polyLine.SetPointAt(1, new Point2d(pt.X, pt.Y));

                    pt = line.EndPoint + centerToEdge;
                    polyLine.SetPointAt(2, new Point2d(pt.X, pt.Y));

                    pt = line.EndPoint - centerToEdge;
                    polyLine.SetPointAt(3, new Point2d(pt.X, pt.Y));

                    var loop = new HatchLoop(HatchLoopTypes.Polyline);

                    for (int i = 0; i < polyLine.NumberOfVertices; i++)
                    {
                        loop.Polyline.Add(new BulgeVertex(polyLine.GetPoint2dAt(i), polyLine.GetBulgeAt(i)));
                    }

                    if (hatch.NumberOfLoops > 0)
                    {
                        hatch.RemoveLoopAt(0);
                    }
                    hatch.AppendLoop(loop);
                });
                if (wall.Drag() != PromptStatus.OK)
                {
                    return;
                }
            }
        }
Exemplo n.º 2
0
        public Tuple <Line, Wall> JigWall(string name, string hatchPattern)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;

            var basePt = doc.Editor.GetPoint("\n请输入起始点:");

            if (basePt.Status == PromptStatus.OK)
            {
                var jigOpt = new JigPromptPointOptions();

                var line = new Line(basePt.Value, basePt.Value);

                var polyLine = new Polyline(4)
                {
                    Closed = true
                };

                polyLine.AddVertexAt(0, Point2d.Origin, 0, 0, 0);
                polyLine.AddVertexAt(0, Point2d.Origin, 0, 0, 0);
                polyLine.AddVertexAt(0, Point2d.Origin, 0, 0, 0);
                polyLine.AddVertexAt(0, Point2d.Origin, 0, 0, 0);


                var hatch = new Hatch();

                hatch.SetHatchPattern(HatchPatternType.PreDefined, hatchPattern);

                var wall = new JigHelper();

                wall.PrapareForNextInput(jigOpt, "\n请输入墙顶中心坐标:");

                wall.SetEntities(new Entity[] { line });

                wall.SetUpdate(jig =>
                {
                    line.EndPoint = jig.Point;
                });

                if (wall.Drag() != PromptStatus.OK)
                {
                    return(null);
                }

                wall.PrapareForNextInput(jigOpt, "\n请输入墙面宽度:");

                wall.SetEntities(new Entity[] { polyLine, hatch });

                wall.SetUpdate(jig =>
                {
                    var edgePt = jig.Point;

                    var centerToEdgeLength = (line.StartPoint - line.EndPoint)
                                             .CrossProduct(edgePt - line.EndPoint)
                                             .Length / line.Length;

                    var centerToEdge = (line.StartPoint - line.EndPoint)
                                       .RotateBy(Math.PI / 2, Vector3d.ZAxis)
                                       .GetNormal() * centerToEdgeLength;

                    Point3d pt;

                    pt = line.StartPoint - centerToEdge;
                    polyLine.SetPointAt(0, new Point2d(pt.X, pt.Y));

                    pt = line.StartPoint + centerToEdge;
                    polyLine.SetPointAt(1, new Point2d(pt.X, pt.Y));

                    pt = line.EndPoint + centerToEdge;
                    polyLine.SetPointAt(2, new Point2d(pt.X, pt.Y));

                    pt = line.EndPoint - centerToEdge;
                    polyLine.SetPointAt(3, new Point2d(pt.X, pt.Y));

                    var loop = new HatchLoop(HatchLoopTypes.Polyline);

                    for (int i = 0; i < polyLine.NumberOfVertices; i++)
                    {
                        loop.Polyline.Add(new BulgeVertex(polyLine.GetPoint2dAt(i), polyLine.GetBulgeAt(i)));
                    }

                    if (hatch.NumberOfLoops > 0)
                    {
                        hatch.RemoveLoopAt(0);
                    }
                    hatch.AppendLoop(loop);
                });
                if (wall.Drag() != PromptStatus.OK)
                {
                    return(null);
                }

                return(Tuple.Create(line, new Wall
                {
                    Name = name,
                    Pos = new Point {
                        X = line.StartPoint.X, Y = line.StartPoint.Y
                    },
                    Dir = new Point
                    {
                        X = line.EndPoint.X - line.StartPoint.X,
                        Y = line.EndPoint.Y - line.StartPoint.Y,
                    },
                    Size = new Size
                    {
                        W = (polyLine.GetPoint2dAt(0) - polyLine.GetPoint2dAt(1)).Length,
                        H = (polyLine.GetPoint2dAt(1) - polyLine.GetPoint2dAt(2)).Length,
                    },
                    Hatch = hatchPattern,
                }));
            }
            return(null);
        }