示例#1
0
        /// <summary>
        /// Add an array of 3-D points to the document
        /// </summary>
        public object AddPoints(object pointsObj)
        {
            On3dPointArray points = new On3dPointArray();

            if (SampleCsRhinoScriptUtils.ConvertToOn3dPointArray(pointsObj, ref points))
            {
                MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc();
                if (null != doc)
                {
                    ArrayList objectIds = new ArrayList();
                    for (int i = 0; i < points.Count(); i++)
                    {
                        MRhinoObject rhinoObj = doc.AddPointObject(points[i]);
                        if (null != rhinoObj)
                        {
                            objectIds.Add(rhinoObj.ModelObjectId().ToString());
                        }
                    }
                    if (objectIds.Count > 0)
                    {
                        doc.Redraw();
                        return(objectIds.ToArray());
                    }
                }
            }
            return(null);
        }
        bool GetArrowHead(On2dVector dir, On2dPoint tip, double scale, ref On3dPointArray triangle)
        {
            double arrow_size = m_default_arrow_size * scale;

            On2dPointArray corners = new On2dPointArray();

            corners.Reserve(3);
            corners.SetCount(3);

            On2dVector up = new On2dVector(-dir.y, dir.x);

            corners[0].Set(tip.x, tip.y);
            corners[1].x = tip.x + arrow_size * (0.25 * up.x - dir.x);
            corners[1].y = tip.y + arrow_size * (0.25 * up.y - dir.y);
            corners[2].x = corners[1].x - 0.5 * arrow_size * up.x;
            corners[2].y = corners[1].y - 0.5 * arrow_size * up.y;

            triangle.Reserve(corners.Count());
            triangle.SetCount(corners.Count());

            for (int i = 0; i < corners.Count(); i++)
            {
                triangle[i] = m_plane.PointAt(corners[i].x, corners[i].y);
            }

            return(true);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select two surfaces or polysurfacs to intersect");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(2, 2);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnBrep B0 = go.Object(0).Brep();
            IOnBrep B1 = go.Object(1).Brep();

            if (null == B0 || null == B1)
            {
                return(IRhinoCommand.result.failure);
            }

            OnCurve[]      curves = null;
            On3dPointArray points = null;
            bool           rc     = RhUtil.RhinoIntersectBreps(B0, B1, context.m_doc.AbsoluteTolerance(), out curves, out points);

            if (
                false == rc ||
                null == curves ||
                0 == curves.Length ||
                null == points ||
                0 == curves.Length
                )
            {
                RhUtil.RhinoApp().Print("No intersections found.\n");
                return(IRhinoCommand.result.nothing);
            }

            if (null != curves)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    context.m_doc.AddCurveObject(curves[i]);
                }
            }

            if (null != points)
            {
                for (int i = 0; i < points.Count(); i++)
                {
                    context.m_doc.AddPointObject(points[i]);
                }
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
        // Returns a new RMA.OpenNURBS.On3dPointArray object
        public On3dPointArray ToPointArray()
        {
            int            count  = this.Count;
            On3dPointArray points = new On3dPointArray(count);

            for (int i = 0; i < count; i++)
            {
                points.Append(this[i]);
            }
            return(points);
        }
 // Adds one or more points from a RMA.OpenNURBS.On3dPointArray object
 public void Add(On3dPointArray points)
 {
     if (points != null)
     {
         int point_count = points.Count();
         int total_count = this.Count + point_count;
         this.Capacity = total_count;
         for (int i = 0; i < point_count; i++)
         {
             Add(points.get_ValueAt(i));
         }
     }
 }
 /// <summary>
 /// Convert an object to an On3dPointArray
 /// </summary>
 public static bool ConvertToOn3dPointArray(object pointsObj, ref On3dPointArray points)
 {
     bool rc = false;
       int pointsCount = points.Count();
       Array pointsArr = pointsObj as Array;
       if (null != pointsArr)
       {
     for (int i = 0; i < pointsArr.Length; i++)
     {
       On3dPoint point = new On3dPoint();
       if (SampleCsRhinoScriptUtils.ConvertToOn3dPoint(pointsArr.GetValue(i), ref point))
     points.Append(point);
     }
     rc = (points.Count() - pointsCount > 0);
       }
       return rc;
 }
        /// <summary>
        /// Convert an object to an On3dPointArray
        /// </summary>
        static public bool ConvertToOn3dPointArray(object pointsObj, ref On3dPointArray points)
        {
            bool  rc          = false;
            int   pointsCount = points.Count();
            Array pointsArr   = pointsObj as Array;

            if (null != pointsArr)
            {
                for (int i = 0; i < pointsArr.Length; i++)
                {
                    On3dPoint point = new On3dPoint();
                    if (SampleCsRhinoScriptUtils.ConvertToOn3dPoint(pointsArr.GetValue(i), ref point))
                    {
                        points.Append(point);
                    }
                }
                rc = (points.Count() - pointsCount > 0);
            }
            return(rc);
        }
示例#8
0
        ///<summary>
        /// This gets called when when the user runs this command.
        ///</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetFileDialog dlg = new MRhinoGetFileDialog();

            if (dlg.DisplayFileDialog(IRhinoGetFileDialog.file_dialog_type.open_text_file_dialog))
            {
                string filename = dlg.FileName();
                string line     = "";
                RhUtil.RhinoApp().Print(string.Format("Opening file {0}.\n", filename));

                char[] delim = new char[2];
                delim[0] = ','; delim[1] = '\0';

                On3dPointArray points = new On3dPointArray(8);

                StreamReader reader = new StreamReader(filename);
                line = reader.ReadLine();

                while (line != null && line.Length > 0)
                {
                    string[] substrs = line.Split(delim);
                    if (substrs.Length == 3)
                    {
                        On3dPoint p = new On3dPoint();
                        p.x = double.Parse(substrs[0]);
                        p.y = double.Parse(substrs[1]);
                        p.z = double.Parse(substrs[2]);
                        points.Append(p);
                    }
                    line = reader.ReadLine();
                }

                OnNurbsCurve curve = RhUtil.RhinoInterpCurve(3, points, null, null, 1);
                context.m_doc.AddCurveObject(curve);
                reader.Close();
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
        ///<summary> 
        /// This gets called when when the user runs this command.
        ///</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetFileDialog dlg = new MRhinoGetFileDialog();
              if (dlg.DisplayFileDialog(IRhinoGetFileDialog.file_dialog_type.open_text_file_dialog))
              {
            string filename = dlg.FileName();
            string line = "";
            RhUtil.RhinoApp().Print(string.Format("Opening file {0}.\n", filename));

            char[] delim = new char[2];
            delim[0] = ','; delim[1] = '\0';

            On3dPointArray points = new On3dPointArray(8);

            StreamReader reader = new StreamReader(filename);
            line = reader.ReadLine();

            while(line != null && line.Length > 0)
            {
              string[] substrs = line.Split(delim);
              if(substrs.Length == 3)
              {
            On3dPoint p = new On3dPoint();
            p.x = double.Parse(substrs[0]);
            p.y = double.Parse(substrs[1]);
            p.z = double.Parse(substrs[2]);
            points.Append(p);
              }
              line = reader.ReadLine();
            }

            OnNurbsCurve curve = RhUtil.RhinoInterpCurve(3, points, null, null, 1);
            context.m_doc.AddCurveObject(curve);
            reader.Close();
              }

              context.m_doc.Redraw();

              return IRhinoCommand.result.success;
        }
        /// <summary>
        /// Public constructor
        /// </summary>
        public SampleCsDrawArrowheadConduit(OnPlane plane, OnLine line, double scale)
            : base(new MSupportChannels(MSupportChannels.SC_CALCBOUNDINGBOX | MSupportChannels.SC_DRAWOVERLAY), false)
        {
            m_bDraw     = false;
            m_plane     = plane;
            m_line      = line;
            m_arrowhead = new On3dPointArray();

            double x = 0, y = 0;

            m_plane.ClosestPointTo(line.from, ref x, ref y);
            On2dPoint from = new On2dPoint(x, y);

            m_plane.ClosestPointTo(line.to, ref x, ref y);
            On2dPoint to = new On2dPoint(x, y);

            On2dVector dir = new On2dVector(from - to);

            dir.Unitize();

            m_bDraw = GetArrowHead(dir, from, scale, ref m_arrowhead);
        }
 /// <summary>
 /// Add an array of 3-D points to the document
 /// </summary>
 public object AddPoints(object pointsObj)
 {
     On3dPointArray points = new On3dPointArray();
       if (SampleCsRhinoScriptUtils.ConvertToOn3dPointArray(pointsObj, ref points))
       {
     MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc();
     if (null != doc)
     {
       ArrayList objectIds = new ArrayList();
       for (int i = 0; i < points.Count(); i++)
       {
     MRhinoObject rhinoObj = doc.AddPointObject(points[i]);
     if (null != rhinoObj)
       objectIds.Add(rhinoObj.ModelObjectId().ToString());
       }
       if (objectIds.Count > 0)
       {
     doc.Redraw();
     return objectIds.ToArray();
       }
     }
       }
       return null;
 }
        bool GetArrowHead(On2dVector dir, On2dPoint tip, double scale, ref On3dPointArray triangle)
        {
            double arrow_size = m_default_arrow_size * scale;

              On2dPointArray corners = new On2dPointArray();
              corners.Reserve(3);
              corners.SetCount(3);

              On2dVector up = new On2dVector(-dir.y, dir.x);
              corners[0].Set(tip.x, tip.y);
              corners[1].x = tip.x + arrow_size * (0.25 * up.x - dir.x);
              corners[1].y = tip.y + arrow_size * (0.25 * up.y - dir.y);
              corners[2].x = corners[1].x - 0.5 * arrow_size * up.x;
              corners[2].y = corners[1].y - 0.5 * arrow_size * up.y;

              triangle.Reserve(corners.Count());
              triangle.SetCount(corners.Count());

              for (int i = 0; i < corners.Count(); i++)
            triangle[i] = m_plane.PointAt(corners[i].x, corners[i].y);

              return true;
        }
        /// <summary>
        /// Public constructor
        /// </summary>
        public SampleCsDrawArrowheadConduit(OnPlane plane, OnLine line, double scale)
            : base(new MSupportChannels(MSupportChannels.SC_CALCBOUNDINGBOX | MSupportChannels.SC_DRAWOVERLAY), false)
        {
            m_bDraw = false;
              m_plane = plane;
              m_line = line;
              m_arrowhead = new On3dPointArray();

              double x = 0, y = 0;

              m_plane.ClosestPointTo(line.from, ref x, ref y);
              On2dPoint from = new On2dPoint(x, y);

              m_plane.ClosestPointTo(line.to, ref x, ref y);
              On2dPoint to = new On2dPoint(x, y);

              On2dVector dir = new On2dVector(from - to);
              dir.Unitize();

              m_bDraw = GetArrowHead(dir, from, scale, ref m_arrowhead);
        }
 // Construct from a RMA.OpenNURBS.On3dPointArray object
 public Rhino3dPointList(On3dPointArray points)
 {
     Add(points);
 }