Пример #1
0
        public void TestPolygon()
        {
            int n;

            while (true)
            {
                double d = Interaction.GetValue("\nNumber of edges");
                if (double.IsNaN(d))
                {
                    return;
                }
                n = (int)d;
                if (n > 2)
                {
                    break;
                }
            }
            var center = Interaction.GetPoint("\nCenter");

            Draw.Circle(center, 5);
            var end = Interaction.GetPoint("\nOne vertex");

            Draw.Circle(end, 5);
            Draw.Polygon(n, center, end);
        }
Пример #2
0
        public static void PolyClean4()
        {
            double value = Interaction.GetValue("\nDirection:1-R to L;2-B to T;3-L to R;4-T to B");

            if (double.IsNaN(value))
            {
                return;
            }
            int n = (int)value;

            if (!new int[] { 1, 2, 3, 4 }.Contains(n))
            {
                return;
            }
            Algorithms.Direction dir = (Algorithms.Direction)n;

            var ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            int m   = 0;

            ids.QForEach <Polyline>(poly =>
            {
                if (Algorithms.PolyClean_SetTopoDirection(poly, dir))
                {
                    m++;
                }
            });
            Interaction.WriteLine("{0} handled.", m);
        }
Пример #3
0
        public static void PolyClean3()
        {
            double value = Interaction.GetValue("\nNumber of segs to fit an arc, 0 for smart determination", 0);

            if (double.IsNaN(value))
            {
                return;
            }
            int n = (int)value;

            var ids       = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            var entsToAdd = new List <Polyline>();

            ids.QForEach <Polyline>(poly =>
            {
                var pts     = poly.GetPolylineFitPoints(n);
                var poly1   = NoDraw.Pline(pts);
                poly1.Layer = poly.Layer;
                try
                {
                    poly1.ConstantWidth = poly.ConstantWidth;
                }
                catch
                {
                }
                poly1.XData = poly.XData;
                poly.Erase();
                entsToAdd.Add(poly1);
            });
            entsToAdd.ToArray().AddToCurrentSpace();
            Interaction.WriteLine("{0} handled.", entsToAdd.Count);
        }
Пример #4
0
        public static void PolyClean2()
        {
            double epsilon = Interaction.GetValue("\nEpsilon", _polyClean2Epsilon);

            if (double.IsNaN(epsilon))
            {
                return;
            }
            _polyClean2Epsilon = epsilon;

            var ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            int m   = 0;
            int n   = 0;

            ids.QForEach <Polyline>(poly =>
            {
                int count = Algorithms.PolyClean_ReducePoints(poly, epsilon);
                if (count > 0)
                {
                    m++;
                    n += count;
                }
            });
            Interaction.WriteLine("{1} vertex removed from {0} polyline.", m, n);
        }
Пример #5
0
        public void TestOffset()
        {
            var    id    = Interaction.GetEntity("\nPolyline");
            var    poly  = id.QOpenForRead <Polyline>();
            double value = Interaction.GetValue("\nOffset");

            poly.OffsetPoly(Enumerable.Range(0, poly.NumberOfVertices).Select(index => value).ToArray()).AddToCurrentSpace();
        }
Пример #6
0
        public void TestDivide()
        {
            var id  = Interaction.GetEntity("\nSelect curve");
            var cv  = id.QOpenForRead <Curve>();
            int num = (int)Interaction.GetValue("\nNumbers");

            Draw.Divide(cv, num, new DBPoint());
        }
Пример #7
0
        public void TestMeasure()
        {
            var    id     = Interaction.GetEntity("\nSelect curve");
            var    cv     = id.QOpenForRead <Curve>();
            double length = Interaction.GetValue("\nInterval");

            Draw.Measure(cv, length, new DBPoint());
        }
Пример #8
0
        public void TestEllipse()
        {
            var center = Interaction.GetPoint("\nCenter");

            Draw.Circle(center, 5);
            var endX = Interaction.GetPoint("\nEnd of one axis");

            Draw.Circle(endX, 5);
            double radiusY = Interaction.GetValue("\nRadius of another axis");

            Draw.Ellipse(center, endX, radiusY);
        }
Пример #9
0
        public void TestArc2()
        {
            var start = Interaction.GetPoint("\nStart");

            Draw.Circle(start, 5);
            var center = Interaction.GetPoint("\nCenter");

            Draw.Circle(center, 5);
            double angle = Interaction.GetValue("\nAngle");

            Draw.ArcSCA(start, center, angle);
        }
Пример #10
0
        public static void ShowObject()
        {
            var    ids     = QuickSelection.SelectAll().ToArray();
            double handle1 = Interaction.GetValue("Handle of entity");

            if (double.IsNaN(handle1))
            {
                return;
            }
            long handle2 = Convert.ToInt64(handle1);
            var  id      = HostApplicationServices.WorkingDatabase.GetObjectId(false, new Handle(handle2), 0);
            var  col     = new ObjectId[] { id };

            Interaction.HighlightObjects(col);
            Interaction.ZoomObjects(col);
        }
Пример #11
0
        public static void PolyTrimExtend() // mod 20130228
        {
            double epsilon = Interaction.GetValue("\nEpsilon", _polyTrimExtendEpsilon);

            if (double.IsNaN(epsilon))
            {
                return;
            }
            _polyTrimExtendEpsilon = epsilon;

            var visibleLayers = DbHelper
                                .GetAllLayerIds()
                                .QOpenForRead <LayerTableRecord>()
                                .Where(layer => !layer.IsHidden && !layer.IsFrozen && !layer.IsOff)
                                .Select(layer => layer.Name)
                                .ToList();

            var ids = Interaction
                      .GetSelection("\nSelect polyline", "LWPOLYLINE")
                      .QWhere(pline => visibleLayers.Contains(pline.Layer) && pline.Visible)
                      .ToArray(); // newly 20130729

            var pm = new ProgressMeter();

            pm.Start("Processing...");
            pm.SetLimit(ids.Length);
            ids.QOpenForWrite <Polyline>(list =>
            {
                foreach (var poly in list)
                {
                    int[] indices = { 0, poly.NumberOfVertices - 1 };
                    foreach (int index in indices)
                    {
                        var end = poly.GetPoint3dAt(index);
                        foreach (var poly1 in list)
                        {
                            if (poly1 != poly)
                            {
                                var closest  = poly1.GetClosestPointTo(end, false);
                                double dist  = closest.DistanceTo(end);
                                double dist1 = poly1.StartPoint.DistanceTo(end);
                                double dist2 = poly1.EndPoint.DistanceTo(end);

                                double distance = poly1.GetDistToPoint(end);
                                if (poly1.GetDistToPoint(end) > 0)
                                {
                                    if (dist1 <= dist2 && dist1 <= dist && dist1 < epsilon)
                                    {
                                        poly.SetPointAt(index, new Point2d(poly1.StartPoint.X, poly1.StartPoint.Y));
                                    }
                                    else if (dist2 <= dist1 && dist2 <= dist && dist2 < epsilon)
                                    {
                                        poly.SetPointAt(index, new Point2d(poly1.EndPoint.X, poly1.EndPoint.Y));
                                    }
                                    else if (dist <= dist1 && dist <= dist2 && dist < epsilon)
                                    {
                                        poly.SetPointAt(index, new Point2d(closest.X, closest.Y));
                                    }
                                }
                            }
                        }
                    }
                    pm.MeterProgress();
                }
            });
            pm.Stop();
        }