public static Rhino.Commands.Result AddLinearDimension2(Rhino.RhinoDoc doc)
  {
    Point3d origin = new Point3d(1,1,0);
    Point3d offset = new Point3d(11,1,0);
    Point3d pt = new Point3d((offset.X-origin.X)/2,3,0);

    Plane plane = Plane.WorldXY;
    plane.Origin = origin;

    double u,v;
    plane.ClosestParameter(origin, out u, out v);
    Point2d ext1 = new Point2d(u, v);

    plane.ClosestParameter(offset, out u, out v);
    Point2d ext2 = new Point2d(u, v);

    plane.ClosestParameter(pt, out u, out v);
    Point2d linePt = new Point2d(u, v);

    LinearDimension dimension = new LinearDimension(plane, ext1, ext2, linePt);
    if (doc.Objects.AddLinearDimension(dimension) != Guid.Empty)
    {
      doc.Views.Redraw();
      return Rhino.Commands.Result.Success;
    }
    return Rhino.Commands.Result.Failure;
  }
    public static Result Leader(RhinoDoc doc)
    {
        var points = new Point3d[]
        {
          new Point3d(1, 1, 0),
          new Point3d(5, 1, 0),
          new Point3d(5, 5, 0),
          new Point3d(9, 5, 0)
        };

        var xy_plane = Plane.WorldXY;

        var points2d = new List<Point2d>();
        foreach (var point3d in points)
        {
          double x, y;
          if (xy_plane.ClosestParameter(point3d, out x, out y))
          {
        var point2d = new Point2d(x, y);
        if (points2d.Count < 1 || point2d.DistanceTo(points2d.Last<Point2d>()) > RhinoMath.SqrtEpsilon)
          points2d.Add(point2d);
          }
        }

        doc.Objects.AddLeader(xy_plane, points2d);
        doc.Views.Redraw();
        return Result.Success;
    }
        public static double Get(bool IsLeftComp, double r, Polyline line, Point2d TheIntersectPoint, int Index, Point2d StartPoint)
        {
            double oldBulge = line.GetBulgeAt(Index - 1);
            if (oldBulge == 0)
                return 0;//这里可能不对,可能有两个交点,而默认为一个交点
            else
            {
                double delta = System.Math.Atan(System.Math.Abs(oldBulge)) * 2;

                //这里计算新的半径时,要考虑方向因素,可能新半径会更小,也可能会更大
                //取决于路径的偏移方向,以及圆心的位置
                double newRadius = line.GetPoint2dAt(Index - 1).GetDistanceTo(line.GetPoint2dAt(Index)) / 2 / System.Math.Sin(delta);//新弧的半径
                if (IsLeftComp)
                {
                    if (oldBulge < 0)
                        newRadius += r;
                    else newRadius -= r;
                }
                else
                {
                    if (oldBulge > 0)
                        newRadius += r;
                    else newRadius -= r;
                }

                double newChord = StartPoint.GetDistanceTo(TheIntersectPoint);
                double newBulge = System.Math.Tan(
                    System.Math.Asin(newChord / 2 / newRadius) / 2
                    )
                    * line.GetBulgeAt(Index - 1) / System.Math.Abs(line.GetBulgeAt(Index - 1));
                return -newBulge;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Creates a new instance of PolylineSegment from two points, a bulge, a start width and an end width.
 /// </summary>
 /// <param name="startPoint">The start point of the segment.</param>
 /// <param name="endPoint">The end point of the segment.</param>
 /// <param name="bulge">The bulge of the segment.</param>
 /// <param name="startWidth">The start width of the segment.</param>
 /// <param name="endWidth">The end width of the segment.</param>
 public PolylineSegment(Point2d startPoint, Point2d endPoint, double bulge, double startWidth, double endWidth)
 {
     _startPoint = startPoint;
     _endPoint = endPoint;
     _bulge = bulge;
     _startWidth = startWidth;
     _endWidth = endWidth;
 }
Beispiel #5
0
 /// <summary>
 /// Creates a new instance of PolylineSegment from two points and a bulge.
 /// </summary>
 /// <param name="startPoint">The start point of the segment.</param>
 /// <param name="endPoint">The end point of the segment.</param>
 /// <param name="bulge">The bulge of the segment.</param>
 public PolylineSegment(Point2d startPoint, Point2d endPoint, double bulge)
 {
     _startPoint = startPoint;
     _endPoint = endPoint;
     _bulge = bulge;
     _startWidth = 0.0;
     _endWidth = 0.0;
 }
 protected override void OnDynamicDraw(GetPointDrawEventArgs e)
 {
     base.OnDynamicDraw(e);
     var xform = e.Viewport.GetTransform(CoordinateSystem.World, CoordinateSystem.Screen);
     var current_point = e.CurrentPoint;
     current_point.Transform(xform);
     var screen_point = new Point2d(current_point.X, current_point.Y);
     var msg = string.Format("screen {0:F}, {1:F}", current_point.X, current_point.Y);
     e.Display.Draw2dText(msg, System.Drawing.Color.Blue, screen_point, false);
 }
Beispiel #7
0
 public Imagen(Point2d rect, Point3d centerImage, List<Color> colors, double sizePixels)
 {
     this.rect = rect;
     this.centerImage = centerImage;
     this.colors = colors;
     this.sizePixels = sizePixels;
     this.pixels = new List<Pixel>();
     this.ents = new List<Entity>();
     PixelsConfig();
 }
Beispiel #8
0
 public Sierpinski(Point3d center, Double size = 100)
 {
     Triangle = new Polyline();
     this.Size = size;
     A = new Point2d(center.X - size / 2, center.Y);
     B = new Point2d(center.X, center.Y + size);
     C = new Point2d(center.X + size / 2, center.Y);
     Triangle.AddVertexAt(0, A, 0, 0, 0);
     Triangle.AddVertexAt(1, B, 0, 0, 0);
     Triangle.AddVertexAt(2, C, 0, 0, 0);
     Triangle.Closed = true;
     depth = 0;
 }
Beispiel #9
0
 public Sierpinski(Point2d a, Point2d b, Point2d c)
 {
     Triangle = new Polyline();
     A = a;
     B = b;
     C = c;
     this.Size = B.GetDistanceTo(A);
     Triangle.AddVertexAt(0, A, 0, 0, 0);
     Triangle.AddVertexAt(1, B, 0, 0, 0);
     Triangle.AddVertexAt(2, C, 0, 0, 0);
     Triangle.Closed = true;
     depth = 0;
 }
Beispiel #10
0
 public Window(
     string title,
     Point2d<int> position,
     Size2d<int> size,
     SDL.SDL_WindowFlags flags)
 {
     window = SDL.SDL_CreateWindow(
         title,
         position.X,
         position.Y,
         size.Width,
         size.Height,
         flags);
 }
Beispiel #11
0
        private Point2d? GetNextScanPoint()
        {
            Gap nextGap = null;
            var delta = int.MaxValue;

            foreach (var gap in _scene.Gaps)
            {
                if (gap.Width() <= Config.RobotWidth * Config.UnitsInMeter)
                    continue;

                var tmpDelta = Math.Abs(gap.PositionIndex() - _robot.PositionIndex);
                if (tmpDelta >= delta)
                    continue;

                delta = tmpDelta;
                nextGap = gap;

                if (delta == 0)
                    break;
            }

            if (nextGap == null)
                return null;

            //TODO: Возможен баг, если угол Gap больше 180 градусов
            var gapWidth = nextGap.Width();
            //if (gapWidth <= Config.RobotWidth * Config.UnitsInMeter)
            //    continue;

            //var l1 = Logic.Distance(_robot.Position, nextGap.Item1.GetPoint2D());
            //var p1 = Logic.GetDividingPoint(_robot.Position, nextGap.Item1.GetPoint2D(), 1 / l1);

            //var l2 = Logic.Distance(_robot.Position, nextGap.Item2.GetPoint2D());
            //var p2 = Logic.GetDividingPoint(_robot.Position, nextGap.Item2.GetPoint2D(), 1 / l2);

            //var intersection = Logic.LineIntersection(p1, p2, nextGap.Item1.GetPoint2D(), nextGap.Item2.GetPoint2D());

            //var gapWidth = Logic.Distance(p1, p2);

            //TODO: подумать
            //var gapWidth = nextGap.Width();
            //if (gapWidth <= Config.RobotWidth * Config.UnitsInMeter)
            //    throw new Exception("Ширина пробела меньше ширины робота");

            var coef = Math.Min(Config.CameraMaxDistance * Config.UnitsInMeter / gapWidth, 0.5);
            var vector = new Point2d(nextGap.Item2.X - nextGap.Item1.X, nextGap.Item2.Y - nextGap.Item1.Y);

            return new Point2d(nextGap.Item1.X + coef * vector.X, nextGap.Item1.Y + coef * vector.Y);
        }
Beispiel #12
0
        public static void TileContour()
        {
            AcadLib.CommandStart.Start((doc) =>
            {
                Database db = doc.Database;
                Editor ed = doc.Editor;

                // Jig отрисовки полилинии по задаваемым точкам.
                TileLineJig jigTest = new TileLineJig();
                PromptResult jigRes;
                bool status = true;
                do
                {
                    jigRes = ed.Drag(jigTest);
                    if (jigRes.Status == PromptStatus.OK)
                    {
                        // Добавление указанной точки
                        jigTest.AddNewPromptPoint();
                    }
                    else if (jigRes.Status == PromptStatus.Cancel || jigRes.Status == PromptStatus.Error)
                    {
                        return;
                    }
                    else if (jigRes.Status == PromptStatus.Other)
                    {
                        status = false;
                    }
                } while (status);

                // Добавление полилинии в чертеж.
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();
                    pl.SetDatabaseDefaults();
                    for (int i = 0; i < jigTest.AllVertex.Count; i++)
                    {
                        Point3d pt3d = jigTest.AllVertex[i];
                        Point2d pt2d = new Point2d(pt3d.X, pt3d.Y);
                        pl.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid);
                    }
                    pl.TransformBy(jigTest.UCS);
                    btr.AppendEntity(pl);
                    tr.AddNewlyCreatedDBObject(pl, true);
                    tr.Commit();
                }
            });
        }
Beispiel #13
0
        public static Point2d? LineIntersection(Point2d p1, Point2d p2, Point2d p3, Point2d p4)
        {
            var dx12 = p2.X - p1.X;
            var dy12 = p2.Y - p1.Y;
            var dx34 = p4.X - p3.X;
            var dy34 = p4.Y - p3.Y;

            var denominator = (dy12 * dx34 - dx12 * dy34);

            var t1 = ((p1.X - p3.X) * dy34 + (p3.Y - p1.Y) * dx34) / denominator;

            if (double.IsInfinity(t1))
                return null;

            return new Point2d(p1.X + dx12 * t1, p1.Y + dy12 * t1);
        }
Beispiel #14
0
        public void Create(Point2d ptCell, BlockTableRecord cs, Transaction t)
        {
            var cellWidth = ColorBookHelper.CellWidth;
            var cellHeight = ColorBookHelper.CellHeight;
            var margin = ColorBookHelper.Margin;
            var marginHalf = margin * 0.5;

            Point3d ptText = new Point3d(ptCell.X + cellWidth * 0.5, ptCell.Y - ColorBookHelper.TextHeight-margin, 0);

            Polyline pl = new Polyline(4);
            pl.AddVertexAt(0, new Point2d(ptCell.X+margin, ptText.Y- marginHalf), 0, 0, 0);
            pl.AddVertexAt(1, new Point2d(ptCell.X+cellWidth- margin, ptText.Y- marginHalf), 0, 0, 0);
            pl.AddVertexAt(2, new Point2d(ptCell.X + cellWidth-margin, ptCell.Y-cellHeight+margin), 0, 0, 0);
            pl.AddVertexAt(3, new Point2d(ptCell.X+margin, ptCell.Y - cellHeight+margin), 0, 0, 0);
            pl.Closed = true;
            pl.SetDatabaseDefaults();
            pl.Color = Color;

            cs.AppendEntity(pl);
            t.AddNewlyCreatedDBObject(pl, true);

            Hatch h = new Hatch();
            h.SetDatabaseDefaults();
            h.SetHatchPattern(HatchPatternType.PreDefined, "Solid");
            h.Annotative = AnnotativeStates.False;

            cs.AppendEntity(h);
            t.AddNewlyCreatedDBObject(h, true);

            h.Associative = true;
            h.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection(new[] { pl.Id }));
            h.Color = Color;
            h.EvaluateHatch(true);

            DBText text = new DBText();
            text.SetDatabaseDefaults();
            text.HorizontalMode = TextHorizontalMode.TextCenter;
            text.Annotative = AnnotativeStates.False;
            text.Height = ColorBookHelper.TextHeight;
            text.AlignmentPoint = ptText;
            text.AdjustAlignment(cs.Database);
            text.TextStyleId = ColorBookHelper.IdTextStylePik;
            text.TextString = Name;

            cs.AppendEntity(text);
            t.AddNewlyCreatedDBObject(text, true);
        }
        public static DPoint3d closestPointOnSurf(DPoint3d point, ISurface surf, double tol, out double Dist, out Point2d UV, out DVector3d normal)
        {
            Bentley.Interop.MicroStationDGN.Point3d cpRef = new Bentley.Interop.MicroStationDGN.Point3d();
            cpRef.X = point.X;
            cpRef.Y = point.Y;
            cpRef.Z = point.Z;

            Bentley.Interop.MicroStationDGN.Point3d cp = new Bentley.Interop.MicroStationDGN.Point3d();
            Bentley.Interop.MicroStationDGN.Point2d cp2d = new Bentley.Interop.MicroStationDGN.Point2d();

            Dist = GeometryTools.BSplineSurfaceComputeMinimumDistance(ref cp, ref cp2d, ref cpRef, tol, surf.com_bsplineSurface);
            UV = new Point2d();
            UV.X = cp2d.X;
            UV.Y = cp2d.Y;

            normal = NormalAtUVParameterOnSurface(surf.com_bsplineSurface, UV.X, UV.Y);

            return new DPoint3d(cp.X, cp.Y, cp.Z);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Rectangle"/> class.
        /// </summary>
        public Rectangle(Point2d bottomLeftCorner, Point2d topRightCorner)
        {
            if (bottomLeftCorner == null)
                throw new ArgumentNullException(nameof(bottomLeftCorner));

            if (topRightCorner == null)
                throw new ArgumentNullException(nameof(topRightCorner));

            BottomLeftCorner = bottomLeftCorner;
            TopRightCorner = topRightCorner;

            Width = topRightCorner.X - bottomLeftCorner.X;
            Height = topRightCorner.Y - bottomLeftCorner.Y;

            CenterPoint =
                AddIn.CreatePoint2D(
                    bottomLeftCorner.X + Width / 2,
                    bottomLeftCorner.Y + Height / 2
                );
        }
Beispiel #17
0
        private void addOutsides(BlockTableRecord btrPanel, Transaction t)
        {
            if (panelBase.Panel.outsides?.outside?.Count()>0)
             {
            foreach (var outside in panelBase.Panel.outsides.outside)
            {
               Polyline plOut = new Polyline();
               Point2d pt;// =new Point2d(outside.posi.X, outside.posi.Y);
               double width = Math.Abs(outside.width)+70;
               // Если это левое примыкание Outside
               if (Math.Abs(outside.posi.X)<10)
               {
                  pt = new Point2d(outside.posi.X, outside.posi.Y);
                  panelBase.XMinContour = width;
                  panelBase.XStartTile = width+11;
                  //panelBase.XMinPanel = pt.X;
                  panelBase.IsOutsideLeft = true;
               }
               else
               {
                  pt = new Point2d(outside.posi.X-70, outside.posi.Y);
                  panelBase.XMaxContour += -70;
                  panelBase.XMaxPanel = pt.X + width;
                  panelBase.IsOutsideRight = true;
               }

               plOut.AddVertexAt(0, pt, 0, 0, 0);
               pt = new Point2d(pt.X+ width, pt.Y);
               plOut.AddVertexAt(1, pt, 0, 0, 0);
               pt = new Point2d(pt.X, pt.Y+outside.height);
               plOut.AddVertexAt(2, pt, 0, 0, 0);
               pt = new Point2d(pt.X- width, pt.Y);
               plOut.AddVertexAt(3, pt, 0, 0, 0);
               plOut.Closed = true;

               plOut.Layer = "0";
               btrPanel.AppendEntity(plOut);
               t.AddNewlyCreatedDBObject(plOut, true);
            }
             }
        }
        /// <summary>
        /// Returns the tangents between the active CircularArc2d instance complete circle and a point.
        /// </summary>
        /// <remarks>
        /// Tangents start points are on the object to which this method applies, end points on the point passed as argument.
        /// Tangents are always returned in the same order: the tangent on the left side of the line from the circular arc center
        /// to the point before the other one. 
        /// </remarks>
        /// <param name="arc">The instance to which this method applies.</param>
        /// <param name="pt">The Point2d to which tangents are searched</param>
        /// <returns>An array of LineSegement2d representing the tangents (2) or null if there is none.</returns>
        public static LineSegment2d[] GetTangentsTo(this CircularArc2d arc, Point2d pt)
        {
            // check if the point is inside the circle
            Point2d center = arc.Center;
            if (pt.GetDistanceTo(center) <= arc.Radius)
                return null;

            Vector2d vec = center.GetVectorTo(pt) / 2.0;
            CircularArc2d tmp = new CircularArc2d(center + vec, vec.Length);
            Point2d[] inters = arc.IntersectWith(tmp);
            if (inters == null)
                return null;
            LineSegment2d[] result = new LineSegment2d[2];
            Vector2d v1 = inters[0] - center;
            Vector2d v2 = inters[1] - center;
            int i = vec.X * v1.Y - vec.Y - v1.X > 0 ? 0 : 1;
            int j = i ^ 1;
            result[i] = new LineSegment2d(inters[0], pt);
            result[j] = new LineSegment2d(inters[1], pt);
            return result;
        }
Beispiel #19
0
        static void SelectEvents_OnSelect(
            ObjectsEnumerator JustSelectedEntities, 
            SelectionDeviceEnum SelectionDevice, 
            Point ModelPosition, 
            Point2d ViewPosition, 
            View View)
        {
            VertexSelectEffect effect = new VertexSelectEffect(
                _clientGraphicsMng,
                ModelPosition, 
                0.01, 
                0.8);

            RenderStyles styles =
                AdnInventorUtilities.GetProperty(
                    AdnInventorUtilities.InventorApplication.ActiveDocument, 
                    "RenderStyles") as RenderStyles;

            effect.GraphicsNode.RenderStyle = styles["Glass (Limo Tint)"];

            _clientGraphicsMng.DrawDynamicGraphics(effect);
        }
Beispiel #20
0
        void select_OnPreSelect(ref object PreSelectEntity, out bool DoHighlight, ref ObjectCollection MorePreSelectEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
        {
            DoHighlight = true;

            //���õ������ѡ�Ķ�������ã�����ǰ�涨��Ĺ�����������֪���ö���һ����һ����
            Edge edge;
            edge = (Edge)PreSelectEntity;

            //ȷ���Ƿ�����ñ����в����ӵı�
            EdgeCollection edges;
            edges = edge.TangentiallyConnectedEdges;
            if (edges.Count > 1)
            {
                //�������������ߵĶ��󼯺�
                MorePreSelectEntities = ThisApplication.TransientObjects.CreateObjectCollection(null);

                for (int i = 1; i <= edges.Count; i++)
                {
                    MorePreSelectEntities.Add(edges[i]);
                }
            }
        }
        public void RedrawScene(Point2d robotPos, Scene scene)
        {
            _graphics.Clear(Color.White);

            double maxX = scene.Points.Max(p => p.X), minX = scene.Points.Min(p => p.X);
            double maxY = scene.Points.Max(p => p.Y), minY = scene.Points.Min(p => p.Y);

            var scaleX = (sceneBox.Width - 20) / (maxX - minX);
            var scaleY = (sceneBox.Height - 20) / (maxY - minY);

            var scale = Math.Min(scaleX, scaleY) / 2;
            var center = new Point2d((minX - maxX) / 2 * scale, (minY - maxX) / 2 * scale);

            DrawPoint(_robotBrush, GetPoint(robotPos, center, scale));

            var e = scene.Points.GetEnumerator();
            if (!e.MoveNext())
                return;

            var prev = GetPoint(e.Current.GetPoint2D(), center, scale);
            DrawPoint(e.Current.IsScanned() ? _pointBrush : _uPointBrush, prev);

            while (e.MoveNext())
            {
                var cur = GetPoint(e.Current.GetPoint2D(), center, scale);
                DrawLine(_uLinePen, prev, cur);
                DrawPoint(e.Current.IsScanned() ? _pointBrush : _uPointBrush, cur);

                prev = cur;
            }

            foreach (var gap in scene.Gaps)
            {
                DrawPoint(Brushes.Gold, GetPoint(gap.Item1.GetPoint2D(), center, scale));
                DrawPoint(Brushes.Gold, GetPoint(gap.Item2.GetPoint2D(), center, scale));
            }
        }
Beispiel #22
0
        public virtual int getSnappedPoint(Point2d fromPt, Point2d toPt)
        {
            int ret = touchvgPINVOKE.MgSnap_getSnappedPoint__SWIG_0(swigCPtr, Point2d.getCPtr(fromPt), Point2d.getCPtr(toPt));

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #23
0
        public static Vector3d _NormalAt(this BrepFace face, Point2d midPoint)
        {
            var normal = face.NormalAt(midPoint.X, midPoint.Y);

            return(normal);
        }
Beispiel #24
0
 public static Point2i Floor(this Point2d p)
 {
     return(new Point2i((int)Math.Floor(p.X), (int)Math.Floor(p.Y)));
 }
Beispiel #25
0
 /// <summary>
 ///     Evaluates if the points are clockwise.
 /// </summary>
 /// <param name="p1">First point.</param>
 /// <param name="p2">Second point</param>
 /// <param name="p3">Third point</param>
 /// <returns>True if points are clockwise, False otherwise.</returns>
 private static bool Clockwise(Point2d p1, Point2d p2, Point2d p3)
 {
     return((p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X) < 1e-8);
 }
Beispiel #26
0
 public abstract Point2d Transform(Point2d v);
Beispiel #27
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve  tc = null;
            int    nrBoundaryVertices = 0;
            int    degree             = 0;
            double angle = 0;

            DA.GetData(0, ref tc);
            DA.GetData(1, ref nrBoundaryVertices);
            DA.GetData(2, ref degree);
            DA.GetData(3, ref angle);

            if (tc == null || !tc.IsValid || !tc.IsClosed)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input curve is either unvalid or not closed!"); return;
            }

            Curve _targetCurve = tc;

            // number of control points, tells about the complexity of the curve
            int nrCont = _targetCurve.ToNurbsCurve().Points.Count;
            int crDeg  = _targetCurve.Degree;

            int idealDegree = nrCont * crDeg;
            int deg         = Math.Min(Math.Max(25, idealDegree), 50);

            //  number of boundary subdivisions
            int _n = 23 * deg;

            double[] t             = _targetCurve.DivideByCount(_n, true);
            var      _targetPoints = Enumerable.Range(0, _n).Select(i => _targetCurve.PointAt(t[(i + (int)(angle / Math.PI / 2.0 * _n)) % _n])).ToList();

            // now, do the actual work and compute the three complex polynomials
            // ok, let's get the coefficients
            List <double> xs1 = _targetPoints.Select(o => o.X).ToList(); // 1 ms
            LaplaceData   kx  = new LaplaceData(xs1, deg);

            List <double> ys1 = _targetPoints.Select(o => o.Y).ToList(); // 1 ms
            LaplaceData   ky  = new LaplaceData(ys1, deg);

            List <double> zs1 = _targetPoints.Select(o => o.Z).ToList(); // 1 ms
            LaplaceData   kkz = new LaplaceData(zs1, deg);

            var c  = new Circle(1.0);
            var kk = MeshingParameters.Default;

            kk.GridAmplification = (double)nrBoundaryVertices / 10.0;
            var MM = Mesh.CreateFromPlanarBoundary(c.ToNurbsCurve(), kk, DocumentTolerance());

            // bottleneck
            for (int ii = 0; ii < MM.Vertices.Count; ii++)
            {
                var x = MM.Vertices[ii].X;
                var y = MM.Vertices[ii].Y;

                var p = new Point2d(x, y);
                MM.Vertices.SetVertex(ii, kx.eval(p), ky.eval(p), kkz.eval(p));
            }

            DA.SetData(0, MM);
        }
 /// <summary>
 /// Constructs a geodesic between 2 points, used by ShortPath command in Rhino.
 /// </summary>
 /// <param name="start">start point of curve in parameter space. Points must be distinct in the domain of thie surface.</param>
 /// <param name="end">end point of curve in parameter space. Points must be distinct in the domain of thie surface.</param>
 /// <param name="tolerance">tolerance used in fitting discrete solution.</param>
 /// <returns>a geodesic curve on the surface on success. null on failure.</returns>
 public Curve ShortPath(Point2d start, Point2d end, double tolerance)
 {
   IntPtr pConstSurface = ConstPointer();
   IntPtr pNewCurve = UnsafeNativeMethods.RHC_RhinoShortPath(pConstSurface, start, end, tolerance);
   return GeometryBase.CreateGeometryHelper(pNewCurve, null) as Curve;
 }
Beispiel #29
0
 private void SerializePoint(IDataBlock block, Point2d point)
 {
     block.Writer.Write(point.X);
     block.Writer.Write(point.Y);
 }
Beispiel #30
0
 public void DrawArrow(Point2d p1, Point2d p2, DicomColor color)
 {
     DrawArrow(p1.X, p1.Y, p2.X, p2.Y, color);
 }
 internal IfcAxis2Placement2D(DatabaseIfc db, Point2d position, Vector2d dir)
     : base(db, position)
 {
     if (dir.Length > 0 && new Vector3d(dir.X, dir.Y, 0).IsParallelTo(Vector3d.XAxis, Math.PI / 1800) != 1)
         RefDirection = new IfcDirection(db, dir);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LinearDimension"/> class, based on three points.
 /// </summary>
 public static LinearDimension FromPoints(Point3d extensionLine1End, Point3d extensionLine2End, Point3d pointOnDimensionLine)
 {
   Point3d[] points = new Point3d[] { extensionLine1End, extensionLine2End, pointOnDimensionLine };
   // Plane dimPlane = new Plane(extensionLine1End, extensionLine2End, pointOnDimensionLine);
   Plane dimPlane;
   if (Plane.FitPlaneToPoints(points, out dimPlane) != PlaneFitResult.Success)
     return null;
   double s, t;
   if (!dimPlane.ClosestParameter(extensionLine1End, out s, out t))
     return null;
   Point2d ext1 = new Point2d(s, t);
   if (!dimPlane.ClosestParameter(extensionLine2End, out s, out t))
     return null;
   Point2d ext2 = new Point2d(s, t);
   if (!dimPlane.ClosestParameter(pointOnDimensionLine, out s, out t))
     return null;
   Point2d linePt = new Point2d(s, t);
   return new LinearDimension(dimPlane, ext1, ext2, linePt);
 }
Beispiel #33
0
        // --- Test ---
        internal double TeoricRadius(Point2d p, AM_Mesh2d pSpaceFunction)
        {
            double f = SpaceFunction(p, pSpaceFunction);

            return(AM_Mesh2d.RadCoef * f);
        }
Beispiel #34
0
        public void Main()
        {
            Document        doc = AcAp.DocumentManager.MdiActiveDocument;
            Database        db  = doc.Database;
            Editor          ed  = doc.Editor;
            List <ObjectId> ids = null;

            LayoutManager layManager = LayoutManager.Current;
            ObjectId      layoutId   = layManager.GetLayoutId(layManager.CurrentLayout);
            //Layout layoutObj = (Layout)tr.GetObject(layoutId, OpenMode.ForRead);
            Layout       layoutObj       = layoutId.Open(OpenMode.ForRead) as Layout;
            PlotSettings plotSettingsObj = new PlotSettings(layoutObj.ModelType);
            string       setName         = "Langamer_Plot";

            using (var trAddPlotSet = db.TransactionManager.StartTransaction())
            {
                // Adiciona o PlotSetup ao DWG atual **********************************************************************************************
                string   plotSetDWGName = "Z:\\Lisp\\dwg_plot_setup.dwg";
                Database dbPlotSet      = new Database();
                dbPlotSet.ReadDwgFile(plotSetDWGName, FileOpenMode.OpenForReadAndAllShare, true, "");
                using (var trPlotSet = dbPlotSet.TransactionManager.StartTransaction())
                {
                    BlockTable btPlotSet  = trPlotSet.GetObject(dbPlotSet.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    var        btrPlotSet = trPlotSet.GetObject(btPlotSet[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                    Layout     loPlotSet  = trPlotSet.GetObject(btrPlotSet.LayoutId, OpenMode.ForWrite) as Layout;

                    PlotSettings psPlotSet = new PlotSettings(loPlotSet.ModelType);
                    psPlotSet.CopyFrom(loPlotSet);

                    psPlotSet.AddToPlotSettingsDictionary(db);
                    trPlotSet.Commit();
                    trAddPlotSet.Commit();
                }
            }

            using (var tr = db.TransactionManager.StartTransaction())
            {
                BlockTable       bt  = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;


                DBDictionary plotSettingsDic = (DBDictionary)tr.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForRead);
                if (!plotSettingsDic.Contains(setName))
                {
                    return;
                }

                ObjectId plotSettingsId = plotSettingsDic.GetAt(setName);

                //layout type
                bool bModel = layoutObj.ModelType;
                plotSettingsObj = tr.GetObject(plotSettingsId, OpenMode.ForRead) as PlotSettings;

                if (plotSettingsObj.ModelType != bModel)
                {
                    return;
                }

                object backgroundPlot = Application.GetSystemVariable("BACKGROUNDPLOT");
                Application.SetSystemVariable("BACKGROUNDPLOT", 0);
                // Fim: Adiciona o PlotSetup ao DWG atual ****************************************************************************************

                // Pega todos os POLYLINE do desenho atual **********************************************************************************************
                // Cast the BlockTableRecord into IEnumerable<T> collection
                IEnumerable <ObjectId> b = btr.Cast <ObjectId>();

                // Using LINQ statement to select LWPOLYLINE from ModelSpace
                ids = (from id1 in b
                       where OpenObject(tr, id1) is BlockReference &&
                       OpenObject(tr, id1).Layer == "LANG-GR-PRANCHA 1"
                       select id1).ToList <ObjectId>();
                // Fim: Pega todos os POLYLINE do desenho atual **********************************************************************************************

                foreach (var id in ids)
                {
                    //ObjectId id = ids[0];
                    //Polyline objPl = tr.GetObject(id, OpenMode.ForRead) as Polyline;
                    BlockReference objPrancha = tr.GetObject(id, OpenMode.ForRead) as BlockReference;
                    Extents3d      bounds     = (Extents3d)objPrancha.Bounds.Value;
                    Point2d        ptMin      = new Point2d(bounds.MinPoint.X, bounds.MinPoint.Y);
                    Point2d        ptMax      = new Point2d(bounds.MaxPoint.X, bounds.MaxPoint.Y);
                    Extents2d      plotWin    = new Extents2d(ptMin, ptMax);

                    GetSheetExtents(tr, objPrancha);

                    try
                    {
                        PlotSettingsValidator psv = PlotSettingsValidator.Current;
                        psv.SetPlotWindowArea(plotSettingsObj, plotWin);
                        psv.SetPlotRotation(plotSettingsObj, PlotRotation.Degrees180);

                        //now plot the setup...
                        PlotInfo plotInfo = new PlotInfo();
                        plotInfo.Layout           = layoutObj.ObjectId;
                        plotInfo.OverrideSettings = plotSettingsObj;
                        PlotInfoValidator piv = new PlotInfoValidator();
                        piv.Validate(plotInfo);

                        string outName = "C:\\Users\\weiglas.ribeiro.LANGAMER\\Desktop\\" + System.DateTime.Now.Millisecond + ".pdf";

                        using (var pe = PlotFactory.CreatePublishEngine())
                        {
                            // Begin plotting a document.
                            pe.BeginPlot(null, null);
                            pe.BeginDocument(plotInfo, doc.Name, null, 1, true, outName);

                            // Begin plotting the page
                            PlotPageInfo ppi = new PlotPageInfo();
                            pe.BeginPage(ppi, plotInfo, true, null);
                            pe.BeginGenerateGraphics(null);
                            pe.EndGenerateGraphics(null);

                            // Finish the sheet
                            pe.EndPage(null);

                            // Finish the document
                            pe.EndDocument(null);

                            //// And finish the plot
                            pe.EndPlot(null);
                        }
                    }
                    catch (Exception er)
                    {
                    }
                }
                tr.Commit();
            }
        }
Beispiel #35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LineCurve"/> class, by
        /// setting start and end point from two <see cref="Point2d">2D points</see>.</summary>
        /// <param name="from">A start point.</param>
        /// <param name="to">An end point.</param>
        /// <since>5.0</since>
        public LineCurve(Point2d from, Point2d to)
        {
            IntPtr ptr = UnsafeNativeMethods.ON_LineCurve_New2(from, to);

            ConstructNonConstObject(ptr);
        }
 private SurfaceCurvature(double u, double v)
 {
   m_uv = new Point2d(u, v);
 }
Beispiel #37
0
 public void DrawLine(Point2d p1, Point2d p2, DicomColor color)
 {
     DrawLine(p1.X, p1.Y, p2.X, p2.Y, color);
 }
Beispiel #38
0
        public virtual Point2d snapPoint(MgMotion sender, Point2d orignPt)
        {
            Point2d ret = new Point2d(touchvgPINVOKE.MgSnap_snapPoint(swigCPtr, MgMotion.getCPtr(sender), Point2d.getCPtr(orignPt)), true);

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #39
0
        public override Point2d getHandlePoint(int index)
        {
            Point2d ret = new Point2d(touchvgPINVOKE.MgLines_getHandlePoint(swigCPtr, index), true);

            return(ret);
        }
Beispiel #40
0
 PtToStr(Point2d pt)
 {
     return(PtToStr(pt, DistanceUnitFormat.Current, -1));
 }
        /// <summary>
        /// Draws the panel.
        /// </summary>
        /// <param name="xLowerBound">The x lower bound.</param>
        /// <param name="xUpperBound">The x upper bound.</param>
        /// <param name="yLowerBound">The y lower bound.</param>
        /// <param name="yUpperBound">The y upper bound.</param>
        /// <param name="panel">The panel.</param>
        /// <param name="para">The para.</param>
        public static void drawPanel(double xLowerBound, double xUpperBound, double yLowerBound, double yUpperBound, PerforationPanel panel, PanelParameters para)
        {
            RhinoDoc    doc      = RhinoDoc.ActiveDoc;
            List <Guid> guidList = new List <Guid>();

            // Create a new layer called Panel Perimeter
            string layerName = "PANEL PERIMETER";

            // Does a layer with the same name already exist?
            int layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            // Bottom and left justified the panels in the grid
            double panelX0 = xLowerBound;
            double panelX1 = panelX0 + panel.X;
            double panelY0 = yUpperBound;
            double panelY1 = panelY0 + panel.Y;

            // Position the panel to be in the middle of the grid
            //double panelX0 = xLowerBound + ((xUpperBound - xLowerBound) - panel.X) /2 ;
            //double panelX1 = panelX0 + panel.X;
            //double panelY1 = yLowerBound  - ((yLowerBound - yUpperBound) - panel.Y) / 2;
            //double panelY0 = panelY1 - panel.Y;

            BoundingBox    panelBox          = new BoundingBox(panelX0, panelY0, 0, panelX1, panelY1, 0);
            List <Point3d> rectangle_corners = panelBox.GetCorners().Distinct().ToList();

            // add 1st point at last to close the loop
            rectangle_corners.Add(rectangle_corners[0]);
            panel.Perimeter = doc.Objects.AddPolyline(rectangle_corners);

            guidList.Add(panel.Perimeter);

            // Create a new layer called Border
            layerName = "BORDERS";

            // Does a layer with the same name already exist?
            layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Purple);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            double borderX0 = panelX0 + panel.LeftBorder;
            double borderY0 = panelY0 + panel.BottomBorder;
            double borderX1 = panelX1 - panel.RightBorder;
            double borderY1 = panelY1 - panel.TopBorder;

            panelBox          = new BoundingBox(borderX0, borderY0, 0, borderX1, borderY1, 0);
            rectangle_corners = panelBox.GetCorners().Distinct().ToList();
            // add 1st point at last to close the loop
            rectangle_corners.Add(rectangle_corners[0]);
            panel.Border = doc.Objects.AddPolyline(rectangle_corners);

            guidList.Add(panel.Border);

            // Create a new layer called LABELS
            layerName = "LABELS";

            // Does a layer with the same name already exist?
            layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Red);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(borderX0, borderY0, 0);
            string       text         = panel.PartName;
            double       height       = para.LabelHeight;
            const string font         = "Arial";

            Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
            plane.Origin = pt;
            panel.Label  = doc.Objects.AddText(text, plane, height, font, false, false);
            guidList.Add(panel.Label);

            // If Dot font needs to be drawn
            if (para.DotFont == 1)
            {
                // Create a new layer called DOTS
                layerName = "DOTS";

                // Does a layer with the same name already exist?
                layerIndex = doc.Layers.Find(layerName, true);

                // If layer does not exist
                if (layerIndex == -1)
                {
                    // Add a new layer to the document
                    layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black);
                }

                doc.Layers.SetCurrentLayerIndex(layerIndex, true);

                // Put in the Dot Matrix Label
                // Draw at the right side of the border aand 10mm from the bottom and 100mm from the left edge
                pt = new Point3d(panelX1 - 100, panelY0 + 5, 0);
                DotMatrixLabellerCommand.Instance.drawDotMatrix(pt, panel.PartName, Properties.Settings.Default.DotMatrixHeight, panel.X);
            }

            if (para.PatternDirection == 1)
            {
                // Export the selected curves
                RhinoApp.RunScript("SelAll", true);
                RhinoApp.RunScript("-_Rotate 0,0,0 90", true);
            }

            PerforationForm perforationForm = new PerforationForm(new Rhino.DocObjects.ObjRef(panel.Border).Curve());

            perforationForm.drawPerforationDesign(panel.PatternName, true);

            if (para.PatternDirection == 1)
            {
                // Export the selected curves
                RhinoApp.RunScript("SelAll", true);
                RhinoApp.RunScript("-_Rotate 0,0,0 -90", true);
            }

            // Draw Dimension
            // Find the Dimension Style

            // Create a new layer called DIMENSION
            layerName = "DIMENSION";

            // Does a layer with the same name already exist?
            layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            // Add the word perforated area to the panel
            pt           = new Rhino.Geometry.Point3d(((borderX1 + borderX0) / 2) - 117.5, ((borderY1 + borderY0) / 2) + 33, 0);
            text         = "PERFORATED \nAREA";
            height       = para.LabelHeight / 2;
            plane.Origin = pt;
            Guid perforatedAreaLabel = doc.Objects.AddText(text, plane, height, font, false, false);

            guidList.Add(perforatedAreaLabel);

            DimensionStyle dimStyle      = doc.DimStyles.Find("Metrix Real", true);
            int            dimStyleIndex = 0;

            if (dimStyle == null)
            {
                dimStyleIndex = doc.DimStyles.Add("Metrix Real");
                dimStyle      = doc.DimStyles.Find("Metrix Real", true);
            }
            else
            {
                dimStyleIndex = dimStyle.Index;
            }

            dimStyle.TextHeight             = 40;
            dimStyle.TextGap                = 25;
            dimStyle.ExtensionLineExtension = 25;
            dimStyle.ExtensionLineOffset    = 25;
            dimStyle.LengthResolution       = 0;
            dimStyle.AngleResolution        = 0;

            dimStyle.ArrowLength           = 25;
            dimStyle.LeaderArrowLength     = 25;
            dimStyle.FitText               = DimensionStyle.TextFit.TextInside;
            dimStyle.FixedExtensionLength  = 25;
            dimStyle.FixedExtensionOn      = true;
            dimStyle.DimRadialTextLocation = DimensionStyle.TextLocation.AboveDimLine;
            doc.DimStyles.Modify(dimStyle, dimStyleIndex, false);
            dimStyle.LeaderTextVerticalAlignment = TextVerticalAlignment.Middle;
            doc.DimStyles.SetCurrent(dimStyleIndex, false);

            // Add horizontal dimension
            Point3d origin = new Point3d(panelX1, panelY0, 0);
            Point3d offset = new Point3d(panelX0, panelY0, 0);

            pt = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 4), 0);

            plane        = Plane.WorldXY;
            plane.Origin = origin;

            double u, v;

            plane.ClosestParameter(origin, out u, out v);
            Point2d ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            Point2d ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            Point2d linePt = new Point2d(u, v);

            LinearDimension dimension = new LinearDimension(plane, ext1, ext2, linePt);
            Guid            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            // Add horizontal borders dimension
            origin = new Point3d(panelX0, panelY0, 0);
            offset = new Point3d(borderX0, panelY0, 0);
            pt     = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 2), 0);


            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            // Add horizontal borders dimension
            origin = new Point3d(panelX1, panelY0, 0);
            offset = new Point3d(borderX1, panelY0, 0);
            pt     = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 2), 0);


            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            // Add vertical dimension for panel

            origin = new Point3d(panelX0, panelY0, 0);
            offset = new Point3d(panelX0, panelY1, 0);
            pt     = new Point3d(panelX0 - (dimStyle.TextHeight * 4), (offset.Y - origin.Y) / 2, 0);

            plane        = Plane.WorldXY;
            plane.XAxis  = new Vector3d(0, -1, 0);
            plane.YAxis  = new Vector3d(-1, 0, 0);
            plane.ZAxis  = new Vector3d(0, 0, -1);
            plane.Origin = origin;

            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            // Add vertical dimension for panel

            origin = new Point3d(panelX0, panelY0, 0);
            offset = new Point3d(panelX0, borderY0, 0);
            pt     = new Point3d(panelX0 - (dimStyle.TextHeight * 2), (offset.Y - origin.Y) / 2, 0);

            plane        = Plane.WorldXY;
            plane.XAxis  = new Vector3d(0, -1, 0);
            plane.YAxis  = new Vector3d(-1, 0, 0);
            plane.ZAxis  = new Vector3d(0, 0, -1);
            plane.Origin = origin;

            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            origin = new Point3d(panelX0, panelY1, 0);
            offset = new Point3d(panelX0, borderY1, 0);
            pt     = new Point3d(panelX0 - (dimStyle.TextHeight * 2), (offset.Y - origin.Y) / 2, 0);

            plane        = Plane.WorldXY;
            plane.XAxis  = new Vector3d(0, -1, 0);
            plane.YAxis  = new Vector3d(-1, 0, 0);
            plane.ZAxis  = new Vector3d(0, 0, -1);
            plane.Origin = origin;

            plane.ClosestParameter(origin, out u, out v);
            ext1 = new Point2d(u, v);

            plane.ClosestParameter(offset, out u, out v);
            ext2 = new Point2d(u, v);

            plane.ClosestParameter(pt, out u, out v);
            linePt = new Point2d(u, v);

            dimension = new LinearDimension(plane, ext1, ext2, linePt);
            dimGuid   = doc.Objects.AddLinearDimension(dimension);

            guidList.Add(dimGuid);

            doc.Views.Redraw();

            RhinoObject panelPerimeterObj = doc.Objects.Find(panel.Perimeter);

            // Select all objects on Perforation Layer
            Rhino.DocObjects.RhinoObject[] rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.PerforationLayerName);

            double tolerance = Properties.Settings.Default.Tolerance;

            Rhino.Geometry.Curve panelPerimeterCurve = panelPerimeterObj.Geometry as Rhino.Geometry.Curve;

            // If tool perforation layer is missing
            if (rhinoObjs == null)
            {
                // Select all objects on Perforation Layer
                rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.ToolHitLayerName);
            }

            if (Convert.ToBoolean(panel.DrawPerf) == true && rhinoObjs != null)
            {
                foreach (RhinoObject rhinoObj in rhinoObjs)
                {
                    Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve;

                    if (testCurve != null)
                    {
                        if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA)
                        {
                            guidList.Add(rhinoObj.Id);
                        }
                    }
                }
            }

            // Export the panel

            doc.Objects.UnselectAll();


            doc.Objects.Select(panel.Perimeter);

            // Get all of the objects on the layer. If layername is bogus, you will
            // just get an empty list back

            Rhino.DocObjects.RhinoObject label = doc.Objects.Find(panel.Label);
            string exportFileName = "1";

            if (label != null)
            {
                label.Select(true);
                Rhino.Geometry.TextEntity textentity = label.Geometry as Rhino.Geometry.TextEntity;
                exportFileName = textentity.Text + ".dxf";
            }

            // Select all objects on DOTS Layer
            rhinoObjs = doc.Objects.FindByLayer("DOTS");

            tolerance           = Properties.Settings.Default.Tolerance;
            panelPerimeterCurve = panelPerimeterObj.Geometry as Rhino.Geometry.Curve;

            if (rhinoObjs != null)
            {
                foreach (RhinoObject rhinoObj in rhinoObjs)
                {
                    Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve;

                    if (testCurve != null)
                    {
                        if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA)
                        {
                            rhinoObj.Select(true);
                        }
                    }
                }
            }

            // Select all objects on Tool Hit
            rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.ToolHitLayerName);

            if (rhinoObjs == null)
            {
                rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.PerforationLayerName);
            }

            if (rhinoObjs != null)
            {
                foreach (RhinoObject rhinoObj in rhinoObjs)
                {
                    Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve;

                    if (testCurve != null)
                    {
                        if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA)
                        {
                            rhinoObj.Select(true);
                        }
                    }
                }
            }

            string command = string.Format("-_Export \"" + Path.GetDirectoryName(doc.Path) + @"\" + exportFileName + "\"  Scheme \"R12 Lines & Arcs\" Enter");

            // Export the selected curves
            RhinoApp.RunScript(command, true);

            // Unselect all objects
            doc.Objects.UnselectAll();

            // Default layer index
            int defaultLayerIndex = doc.Layers.Find("Default", true);

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            if (Convert.ToBoolean(panel.DrawPerf) != true)
            {
                // Delete the Perforation layer as it consumes too much memory
                // Create a new layer called DIMENSION
                layerName = "PERFORATION";

                // Does a layer with the same name already exist?
                layerIndex = doc.Layers.Find(layerName, true);

                // Get all of the objects on the layer. If layername is bogus, you will
                // just get an empty list back
                Rhino.DocObjects.RhinoObject[] rhobjs = doc.Objects.FindByLayer(layerName);

                if (rhobjs != null)
                {
                    if (rhobjs.Length > 0)
                    {
                        for (int i = 0; i < rhobjs.Length; i++)
                        {
                            doc.Objects.Delete(rhobjs[i], true);
                        }
                    }
                }

                doc.Layers.Delete(layerIndex, true);
            }

            foreach (Guid g in guidList)
            {
                int idx = RhinoDoc.ActiveDoc.Groups.Find(panel.PartName, false);

                if (idx < 0)
                {
                    idx = RhinoDoc.ActiveDoc.Groups.Add(panel.PartName);
                }

                RhinoDoc.ActiveDoc.Groups.AddToGroup(idx, g);
            }
        }
Beispiel #42
0
 public override float hitTest(Point2d pt, float tol, MgHitResult res) {
   float ret = touchvgPINVOKE.MgImageShape_hitTest(swigCPtr, Point2d.getCPtr(pt), tol, MgHitResult.getCPtr(res));
   if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Beispiel #43
0
        //  -----------------------------
        //  |                           |
        //  |     TEXT                  |
        //  |                           |
        //  |         <----bufer------->|
        //  -----------------------------

        /// <summary>
        /// Tạo một hình bao quanh text
        /// </summary>
        /// <param name="text">Text cần bound</param>
        /// <param name="boundType">Kiểu bao </param>
        /// <param name="bufer">Khoảng bufer</param>
        public static void CreateTextBound(DBText text, BoundType boundType, double bufer = 0)
        {
            RectangleEx rec = GetTextBounds(text);

            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database acDb  = acDoc.Database;
            Editor   acEd  = acDoc.Editor;

            switch (boundType)
            {
            case BoundType.Rectangle:
            {
                using (Transaction tr = acDoc.TransactionManager.StartTransaction())
                {
                    Polyline pl = new Polyline();
                    pl.AddVertexAt(0, rec.LowerLeft, 0, 0, 0);
                    pl.AddVertexAt(1, rec.UpperLeft, 0, 0, 0);
                    pl.AddVertexAt(2, rec.UpperRight, 0, 0, 0);
                    pl.AddVertexAt(3, rec.LowerRight, 0, 0, 0);
                    pl.Closed = true;
                    //pl.AddVertexAt(4, rec.LowerLeft, 0, 0, 0);

                    BlockTableRecord bRec = tr.GetObject(acDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    bRec.AppendEntity(pl);
                    tr.AddNewlyCreatedDBObject(pl, true);
                    tr.Commit();
                }
                break;
            }

            case BoundType.Circle:
            {
                using (Transaction tr = acDoc.TransactionManager.StartTransaction())
                {
                    Circle c = new Circle();

                    c.Center = new Point3d(rec.Center.X, rec.Center.Y, 0);
                    double radius = Enesy.EnesyCAD.Helper.Point2dHelper.Distance(rec.LowerLeft, rec.Center);
                    c.Radius = radius;

                    BlockTableRecord bRec = tr.GetObject(acDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    bRec.AppendEntity(c);
                    tr.AddNewlyCreatedDBObject(c, true);
                    tr.Commit();
                }
                break;
            }

            case BoundType.Triangle:
            {
                using (Transaction tr = acDoc.TransactionManager.StartTransaction())
                {
                    Circle c = new Circle();

                    c.Center = new Point3d(rec.Center.X, rec.Center.Y, 0);
                    double radius = Enesy.EnesyCAD.Helper.Point2dHelper.Distance(rec.LowerLeft, rec.Center);
                    c.Radius = radius;
                    double cos30  = Math.Sqrt(3) / 2;
                    double tang30 = 0.5 / cos30;

                    //
                    Point2d p1 = Enesy.EnesyCAD.Helper.Point2dHelper.Offset2d(Enesy.EnesyCAD.Helper.Point3dHelper.ToPoint2d(c.Center), 0, 2 * radius);
                    Point2d p2 = Enesy.EnesyCAD.Helper.Point2dHelper.Offset2d(Enesy.EnesyCAD.Helper.Point3dHelper.ToPoint2d(c.Center), -radius / tang30, -radius);
                    Point2d p3 = Enesy.EnesyCAD.Helper.Point2dHelper.Offset2d(Enesy.EnesyCAD.Helper.Point3dHelper.ToPoint2d(c.Center), radius / tang30, -radius);

                    Polyline pl = new Polyline();
                    pl.AddVertexAt(0, p1, 0, 0, 0);
                    pl.AddVertexAt(1, p2, 0, 0, 0);
                    pl.AddVertexAt(2, p3, 0, 0, 0);
                    pl.Closed = true;

                    BlockTableRecord bRec = tr.GetObject(acDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    bRec.AppendEntity(pl);
                    tr.AddNewlyCreatedDBObject(pl, true);
                    tr.Commit();
                }
                break;
            }

            case BoundType.None:
            {
                break;
            }

            default: break;
            }
        }
Beispiel #44
0
        public Point2d endPoint()
        {
            Point2d ret = new Point2d(touchvgPINVOKE.MgLine_endPoint(swigCPtr), false);

            return(ret);
        }
Beispiel #45
0
        /// <summary>
        /// Trả về một Rectangle bao quanh một chuỗi
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static RectangleEx GetTextBounds(DBText s, double bufer = 0.1)
        {
            //bufer *= s.Height;

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            Autodesk.AutoCAD.GraphicsInterface.TextStyle style = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
            byte n;

            Transaction tr = db.TransactionManager.StartTransaction();

            try
            {
                using (tr)
                {
                    BlockTableRecord btr            = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    string           text           = s.TextString;
                    TextStyleTable   textStyleTable = tr.GetObject
                                                      (
                        db.TextStyleTableId,
                        OpenMode.ForRead
                                                      ) as TextStyleTable;

                    string currentTextStyle = Application.GetSystemVariable("TEXTSTYLE").ToString();

                    ObjectId textStyleId = ObjectId.Null;
                    textStyleId = textStyleTable[currentTextStyle];
                    Autodesk.AutoCAD.GraphicsInterface.TextStyle iStyle
                        = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();

                    // get textstyle of newly created text
                    TextStyleTableRecord txtbtr = (TextStyleTableRecord)tr.GetObject(textStyleId, OpenMode.ForRead);
                    // copy properties from TextStyleTableRecord and dbtext to temp AcGi.TextStyle (just very limited one for the future calculation)
                    style.FileName = txtbtr.FileName;
                    // then copy properties from existing text
                    style.TextSize       = s.Height; // txtbtr.TextSize;
                    style.ObliquingAngle = s.Oblique;
                    style.XScale         = s.WidthFactor;
                    // load temp style record
                    try
                    {
                        n = style.LoadStyleRec;
                    }
                    catch { return(null); }// something wrong then exit on error

                    // find out the extents
                    Point2d minpt, maxpt;
                    // get extends of text
                    Extents2d ex = style.ExtentsBox(text, true, true, null);

                    minpt = ex.MinPoint;
                    maxpt = ex.MaxPoint;



                    tr.Commit();
                    RectangleEx rec = new RectangleEx(Math.Abs(minpt.X - maxpt.X),
                                                      Math.Abs(minpt.Y - maxpt.Y));

                    Point2d textPos = new Point2d(s.Position.X, s.Position.Y);
                    bufer = s.Height * 0.3;

                    rec.LowerLeft  = new Point2d(textPos.X - bufer, textPos.Y - bufer);
                    rec.UpperLeft  = new Point2d(rec.LowerLeft.X, rec.LowerLeft.Y + rec.Height + 2 * bufer);
                    rec.UpperRight = new Point2d(rec.UpperLeft.X + rec.Width + 2 * bufer, rec.UpperLeft.Y);
                    rec.LowerRight = new Point2d(rec.UpperRight.X, rec.LowerLeft.Y);

                    return(rec);
                }
            }
            catch (System.Exception exc)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(exc.Message + "\n" + exc.StackTrace);
                return(null);
            }
            finally { }
        }
Beispiel #46
0
        public Point2d center()
        {
            Point2d ret = new Point2d(touchvgPINVOKE.MgLine_center(swigCPtr), true);

            return(ret);
        }
Beispiel #47
0
 public override bool setHandlePoint(int index, Point2d pt, float tol) {
   bool ret = touchvgPINVOKE.MgImageShape_setHandlePoint(swigCPtr, index, Point2d.getCPtr(pt), tol);
   if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Beispiel #48
0
        public virtual bool drawPerpMark(GiGraphics gs, GiContext ctx, Point2d a, Point2d b, Point2d perp, Point2d c, float len)
        {
            bool ret = touchvgPINVOKE.MgSnap_drawPerpMark(swigCPtr, GiGraphics.getCPtr(gs), GiContext.getCPtr(ctx), Point2d.getCPtr(a), Point2d.getCPtr(b), Point2d.getCPtr(perp), Point2d.getCPtr(c), len);

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #49
0
        // --- Impostazioni ---
        internal Point2d InsertPoint(AM_Mesh2d pSpaceFunction)
        {
            AM_Edge pRif = null;

            for (int i = 0; i < 3; i++)
            {
                if (GetNearTriangle(i) == null)
                {
                    pRif = m_pEdges[i];
                    break;
                }

                if (GetNearTriangle(i).m_FaceType == EFaceType.FT_ACCEPTED)
                {
                    pRif = m_pEdges[i];
                }
            }

            if (pRif == null)
            {
                return(Vertex(0).Coord);
            }

            Point2d thirdPoint     = Point2d.Origin;
            Point2d midPoint       = 0.5 * (pRif.OrgCoord() + pRif.DestCoord());
            Point2d directionPoint = m_CircumCenter;

            for (int i = 0; i < 3; i++)
            {
                if (Vertex(i) != pRif.Origin() &&
                    Vertex(i) != pRif.Destination())
                {
                    thirdPoint = Vertex(i).Coord;
                    break;
                }
            }

            if (m_CircumCenter == midPoint) //triangolo rettangolo
            {
                directionPoint = thirdPoint;
            }

            double radius = TeoricRadius(midPoint, pSpaceFunction);
            double p      = (pRif.OrgCoord() - pRif.DestCoord()).Length / 2;
            double q      = (midPoint - m_CircumCenter).Length;

            if (radius < p)
            {
                radius = p;
            }
            if (q != 0)
            {
                double tmp = (p * p + q * q) / (2 * q);
                if (radius > tmp)
                {
                    radius = tmp;
                }
            }

            Vector2d versor;

            if (AM_Edge.LeftOf(directionPoint, pRif) && AM_Edge.RightOf(thirdPoint, pRif) ||
                AM_Edge.LeftOf(thirdPoint, pRif) && AM_Edge.RightOf(directionPoint, pRif))
            {
                versor = midPoint - directionPoint;
            }
            else
            {
                versor = directionPoint - midPoint;
            }
            versor.Unitize();

            double  d     = radius + Math.Sqrt(radius * radius - p * p);
            Point2d point = midPoint + d * versor;

            return(point);
        }
Beispiel #50
0
 public static extern ExceptionStatus core_FileNode_read_Point2d(IntPtr node, out Point2d returnValue);
 /// <summary>
 /// Sets the three locations of the point, using two-dimensional points that refer to the plane of the annotation.
 /// </summary>
 public void SetLocations(Point2d extensionLine1End, Point2d extensionLine2End, Point2d pointOnDimensionLine)
 {
   IntPtr pThis = NonConstPointer();
   UnsafeNativeMethods.ON_LinearDimension2_SetLocations(pThis, extensionLine1End, extensionLine2End, pointOnDimensionLine);
 }
Beispiel #52
0
 private global::System.IntPtr SwigDirectorgetHandlePoint(int index)
 {
     return(Point2d.getCPtr(getHandlePoint(index)).Handle);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LineCurve"/> class, by
 /// setting start and end point from two <see cref="Point2d">2D points</see>.</summary>
 /// <param name="from">A start point.</param>
 /// <param name="to">An end point.</param>
 public LineCurve(Point2d from, Point2d to)
 {
   IntPtr ptr = UnsafeNativeMethods.ON_LineCurve_New2(from,to);
   ConstructNonConstObject(ptr);
 }
Beispiel #54
0
        public Point2d endPoint()
        {
            Point2d ret = new Point2d(touchvgPINVOKE.MgBaseLines_endPoint(swigCPtr), true);

            return(ret);
        }
Beispiel #55
0
    /// <summary>
    /// Copies the unmanaged array to a managed counterpart.
    /// </summary>
    /// <returns>The managed array.</returns>
    public Point2d[] ToArray()
    {
      int count = Count;
      if (count < 1)
        return new Point2d[0];

      Point2d[] rc = new Point2d[count];
      UnsafeNativeMethods.ON_2dPointArray_CopyValues(m_ptr, rc);
      return rc;
    }
Beispiel #56
0
        public virtual bool insertPoint(int segment, Point2d pt)
        {
            bool ret = (SwigDerivedClassHasMethod("insertPoint", swigMethodTypes38) ? touchvgPINVOKE.MgBaseLines_insertPointSwigExplicitMgBaseLines(swigCPtr, segment, Point2d.getCPtr(pt)) : touchvgPINVOKE.MgBaseLines_insertPoint(swigCPtr, segment, Point2d.getCPtr(pt)));

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
    /// <summary>
    /// Constructs a rolling ball fillet between two surfaces.
    /// </summary>
    /// <param name="surfaceA">A first surface.</param>
    /// <param name="uvA">A point in the parameter space of FaceA near where the fillet is expected to hit the surface.</param>
    /// <param name="surfaceB">A second surface.</param>
    /// <param name="uvB">A point in the parameter space of FaceB near where the fillet is expected to hit the surface.</param>
    /// <param name="radius">A radius value.</param>
    /// <param name="tolerance">A tolerance value used for approximating and intersecting offset surfaces.</param>
    /// <returns>A new array of rolling ball fillet surfaces; this array can be empty on failure.</returns>
    /// <exception cref="ArgumentNullException">If surfaceA or surfaceB are null.</exception>
    public static Surface[] CreateRollingBallFillet(Surface surfaceA, Point2d uvA, Surface surfaceB, Point2d uvB, double radius, double tolerance)
    {
      if (surfaceA == null) throw new ArgumentNullException("surfaceA");
      if (surfaceB == null) throw new ArgumentNullException("surfaceB");

      IntPtr pConstSurfaceA = surfaceA.ConstPointer();
      IntPtr pConstSurfaceB = surfaceB.ConstPointer();
      using (Runtime.InteropWrappers.SimpleArraySurfacePointer srfs = new Rhino.Runtime.InteropWrappers.SimpleArraySurfacePointer())
      {
        IntPtr pSurfaces = srfs.NonConstPointer();
        UnsafeNativeMethods.RHC_RhinoSimpleRollingBallFillet2(pConstSurfaceA, uvA,
          pConstSurfaceB, uvB, radius, tolerance, pSurfaces);
        return srfs.ToNonConstArray();
      }
    }
Beispiel #58
0
 public override void setPoint(int index, Point2d pt) {
   touchvgPINVOKE.MgImageShape_setPoint(swigCPtr, index, Point2d.getCPtr(pt));
   if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
 }
    /// <summary>
    /// Constructs an interpolated curve on a surface, using 2D surface points.
    /// </summary>
    /// <param name="points">A list, an array or any enumerable set of 2D points.</param>
    /// <param name="tolerance">A tolerance value.</param>
    /// <returns>A new nurbs curve, or null on error.</returns>
    public NurbsCurve InterpolatedCurveOnSurfaceUV(System.Collections.Generic.IEnumerable<Point2d> points, double tolerance)
    {
      NurbsCurve rc = null;
      if (null == points)
        return null;

      Point2d[] ptArray = points as Point2d[];
      if (null == ptArray)
      {
        System.Collections.Generic.IList<Point2d> pointList = points as System.Collections.Generic.IList<Point2d>;
        if (pointList != null)
        {
          ptArray = new Point2d[pointList.Count];
          pointList.CopyTo(ptArray, 0);
        }
        else
        {
          System.Collections.Generic.List<Point2d> list = new System.Collections.Generic.List<Point2d>();
          foreach (Point2d pt in list)
          {
            list.Add(pt);
          }
          ptArray = list.ToArray();
        }
      }

      int count = ptArray.Length;
      if (count >= 2)
      {
        // check for closed curve
        int is_closed = 0;
        if (count > 3)
        {
          Point2d pt = ptArray[0];
          if (pt.DistanceTo(ptArray[count - 1]) < RhinoMath.SqrtEpsilon)
            is_closed = 1;
        }

        IntPtr ptr = ConstPointer();
        IntPtr pNC = UnsafeNativeMethods.ON_Surface_InterpCrvOnSrf(ptr, count, ptArray, is_closed, tolerance, 1);
        rc = GeometryBase.CreateGeometryHelper(pNC, null) as NurbsCurve;
      }
      return rc;
    }
Beispiel #60
0
 public override Point2d getHandlePoint(int index) {
   Point2d ret = new Point2d(touchvgPINVOKE.MgImageShape_getHandlePoint(swigCPtr, index), true);
   return ret;
 }