コード例 #1
0
        ///<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 curve");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              go.EnableSubObjectSelect(false);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IOnCurve curve = go.Object(0).Curve();
              if (null == curve)
            return IRhinoCommand.result.failure;

              // Several types of OnCurve objects can have the form of a polyline,
              // including OnLineCurve, a degree 1 OnNurbsCurve, ON_PolylineCurve,
              // and ON_PolyCurve (whose segments form a polyline). OnCurve.IsPolyline
              // tests a curve to see if it can be represented as a polyline.
              ArrayOn3dPoint points = new ArrayOn3dPoint(64);
              int point_count = curve.IsPolyline(points);
              if (point_count > 0)
              {
            string point_str = string.Empty;
            for (int i = 0; i < point_count; i++)
            {
              point_str = string.Empty;
              RhUtil.RhinoFormatPoint(points[i], ref point_str);
              RhUtil.RhinoApp().Print(string.Format("Point {0} = {1}\n", i, point_str));
            }
              }

              return IRhinoCommand.result.success;
        }
コード例 #2
0
        ///<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 surface edge");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
            go.EnableSubObjectSelect();
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref   = go.Object(0);
            IOnBrepEdge  brep_edge = obj_ref.Edge();

            if (null == brep_edge)
            {
                return(IRhinoCommand.result.failure);
            }

            IOnBrep brep = brep_edge.Brep();

            if (null == brep)
            {
                return(IRhinoCommand.result.failure);
            }

            // TODO: add functionality here...

            return(IRhinoCommand.result.success);
        }
コード例 #3
0
        ///<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 curves to apply linear tags");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              go.EnableSubObjectSelect(false);
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              EstimatorTagForm form = new EstimatorTagForm();
              form.m_str_title = "Add Linear Tags";
              form.m_str_prompt = "Select one or more linear tags.";
              form.m_type = EstimatorTag.tag_type.linear_tag;

              DialogResult rc = form.ShowDialog();
              if (rc == DialogResult.Cancel)
            return IRhinoCommand.result.cancel;

              List<string> tag_strings = new List<string>(form.m_selected_tags.Count);

              EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn;
              int i = 0;

              for (i = 0; i < form.m_selected_tags.Count; i++)
              {
            int index = form.m_selected_tags[i];
            tag_strings.Add(plugin.m_tag_table[index].Id());
              }

              for (i = 0; i < go.ObjectCount(); i++)
            EstimatorHelpers.AddData(go.Object(i).Object(), tag_strings.ToArray());

              return IRhinoCommand.result.success;
        }
コード例 #4
0
        ///<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 solid meshes for volume calculation");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
            go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh);
            go.EnableSubObjectSelect(false);
            go.EnableGroupSelect();
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            List <IOnMesh> meshes = new List <IOnMesh>();

            for (int i = 0; i < go.ObjectCount(); i++)
            {
                IOnMesh mesh = go.Object(i).Mesh();
                if (mesh != null)
                {
                    meshes.Add(mesh);
                }
            }
            if (meshes.Count == 0)
            {
                return(IRhinoCommand.result.nothing);
            }

            OnBoundingBox bbox = new OnBoundingBox();

            for (int i = 0; i < meshes.Count; i++)
            {
                meshes[i].GetBoundingBox(ref bbox, 1);
            }
            On3dPoint base_point = bbox.Center();

            double total_volume         = 0.0;
            double total_error_estimate = 0.0;
            string msg;

            for (int i = 0; i < meshes.Count; i++)
            {
                double error_estimate = 0.0;
                double volume         = meshes[i].Volume(base_point, ref error_estimate);
                msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate);
                RhUtil.RhinoApp().Print(msg);
                total_volume         += volume;
                total_error_estimate += error_estimate;
            }

            msg = string.Format("Total volume = {0:f} (+/- {1:f})\n",
                                total_volume,
                                total_error_estimate);
            RhUtil.RhinoApp().Print(msg);

            return(IRhinoCommand.result.success);
        }
コード例 #5
0
        ///<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);
        }
コード例 #6
0
        ///<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 object to move");
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint pointFrom = gp.Point();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(pointFrom);
            gp.DrawLineFromPoint(pointFrom, true);
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint pointTo = gp.Point();

            On3dVector dir = new On3dVector(pointTo - pointFrom);

            if (dir.IsTiny())
            {
                return(IRhinoCommand.result.nothing);
            }

            OnXform xform = new OnXform();

            xform.Translation(dir);

            MRhinoObjRef objectRef = go.Object(0);

            context.m_doc.TransformObject(ref objectRef, xform);
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
コード例 #7
0
        ///<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 solid meshes for volume calculation");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
              go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh);
              go.EnableSubObjectSelect(false);
              go.EnableGroupSelect();
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              List<IOnMesh> meshes = new List<IOnMesh>();
              for (int i = 0; i < go.ObjectCount(); i++)
              {
            IOnMesh mesh = go.Object(i).Mesh();
            if (mesh != null)
              meshes.Add(mesh);
              }
              if (meshes.Count == 0)
            return IRhinoCommand.result.nothing;

              OnBoundingBox bbox = new OnBoundingBox();
              for (int i = 0; i < meshes.Count; i++)
            meshes[i].GetBoundingBox(ref bbox, 1);
              On3dPoint base_point = bbox.Center();

              double total_volume = 0.0;
              double total_error_estimate = 0.0;
              string msg;
              for (int i = 0; i < meshes.Count; i++)
              {
            double error_estimate = 0.0;
            double volume = meshes[i].Volume(base_point, ref error_estimate);
            msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate);
            RhUtil.RhinoApp().Print(msg);
            total_volume += volume;
            total_error_estimate += error_estimate;
              }

              msg = string.Format("Total volume = {0:f} (+/- {1:f})\n",
                          total_volume,
                          total_error_estimate);
              RhUtil.RhinoApp().Print(msg);

              return IRhinoCommand.result.success;
        }
コード例 #8
0
        ///<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 surface");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnSurface srf = go.Object(0).Surface();

            if (null == srf)
            {
                return(IRhinoCommand.result.failure);
            }

            IOnNurbsSurface ns = srf.NurbsSurface();

            if (null == ns)
            {
                RhUtil.RhinoApp().Print("Not a NURBS surface.\n");
                return(IRhinoCommand.result.nothing);
            }

            On3dPoint cv  = new On3dPoint();
            string    str = string.Empty;

            for (int u = 0; u < ns.CVCount(0); u++)
            {
                for (int v = 0; v < ns.CVCount(1); v++)
                {
                    if (ns.GetCV(u, v, ref cv))
                    {
                        str = string.Empty;
                        RhUtil.RhinoFormatPoint(cv, ref str);
                        RhUtil.RhinoApp().Print(string.Format("CV({0},{1}) = {2}\n", u, v, str));
                    }
                }
            }

            return(IRhinoCommand.result.success);
        }
コード例 #9
0
        ///<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;
        }
コード例 #10
0
        ///<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 curves to apply linear tags");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            EstimatorTagForm form = new EstimatorTagForm();

            form.m_str_title  = "Add Linear Tags";
            form.m_str_prompt = "Select one or more linear tags.";
            form.m_type       = EstimatorTag.tag_type.linear_tag;

            DialogResult rc = form.ShowDialog();

            if (rc == DialogResult.Cancel)
            {
                return(IRhinoCommand.result.cancel);
            }

            List <string> tag_strings = new List <string>(form.m_selected_tags.Count);

            EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn;
            int             i      = 0;

            for (i = 0; i < form.m_selected_tags.Count; i++)
            {
                int index = form.m_selected_tags[i];
                tag_strings.Add(plugin.m_tag_table[index].Id());
            }

            for (i = 0; i < go.ObjectCount(); i++)
            {
                EstimatorHelpers.AddData(go.Object(i).Object(), tag_strings.ToArray());
            }

            return(IRhinoCommand.result.success);
        }
コード例 #11
0
        ///<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 curve");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnCurve curve = go.Object(0).Curve();

            if (null == curve)
            {
                return(IRhinoCommand.result.failure);
            }

            // Several types of OnCurve objects can have the form of a polyline,
            // including OnLineCurve, a degree 1 OnNurbsCurve, ON_PolylineCurve,
            // and ON_PolyCurve (whose segments form a polyline). OnCurve.IsPolyline
            // tests a curve to see if it can be represented as a polyline.
            ArrayOn3dPoint points      = new ArrayOn3dPoint(64);
            int            point_count = curve.IsPolyline(points);

            if (point_count > 0)
            {
                string point_str = string.Empty;
                for (int i = 0; i < point_count; i++)
                {
                    point_str = string.Empty;
                    RhUtil.RhinoFormatPoint(points[i], ref point_str);
                    RhUtil.RhinoApp().Print(string.Format("Point {0} = {1}\n", i, point_str));
                }
            }

            return(IRhinoCommand.result.success);
        }
コード例 #12
0
        ///<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 object to move");
              go.EnableSubObjectSelect(false);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              MRhinoGetPoint gp = new MRhinoGetPoint();
              gp.SetCommandPrompt("Point to move from");
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              On3dPoint pointFrom = gp.Point();

              gp.SetCommandPrompt("Point to move to");
              gp.SetBasePoint(pointFrom);
              gp.DrawLineFromPoint(pointFrom, true);
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              On3dPoint pointTo = gp.Point();

              On3dVector dir = new On3dVector(pointTo - pointFrom);
              if (dir.IsTiny())
            return IRhinoCommand.result.nothing;

              OnXform xform = new OnXform();
              xform.Translation(dir);

              MRhinoObjRef objectRef = go.Object(0);
              context.m_doc.TransformObject(ref objectRef, xform);
              context.m_doc.Redraw();

              return IRhinoCommand.result.success;
        }
コード例 #13
0
        ///<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 surface");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object);
              go.EnableSubObjectSelect(false);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IOnSurface srf = go.Object(0).Surface();
              if (null == srf)
            return IRhinoCommand.result.failure;

              IOnNurbsSurface ns = srf.NurbsSurface();
              if (null == ns)
              {
            RhUtil.RhinoApp().Print("Not a NURBS surface.\n");
            return IRhinoCommand.result.nothing;
              }

              On3dPoint cv = new On3dPoint();
              string str = string.Empty;
              for (int u = 0; u < ns.CVCount(0); u++)
              {
            for (int v = 0; v < ns.CVCount(1); v++)
            {
              if (ns.GetCV(u, v, ref cv))
              {
            str = string.Empty;
            RhUtil.RhinoFormatPoint(cv, ref str);
            RhUtil.RhinoApp().Print(string.Format("CV({0},{1}) = {2}\n", u, v, str));
              }
            }
              }

              return IRhinoCommand.result.success;
        }
コード例 #14
0
        ///<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 surface edge");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
              go.EnableSubObjectSelect();
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              MRhinoObjRef obj_ref = go.Object(0);
              IOnBrepEdge brep_edge = obj_ref.Edge();
              if (null == brep_edge)
            return IRhinoCommand.result.failure;

              IOnBrep brep = brep_edge.Brep();
              if (null == brep)
            return IRhinoCommand.result.failure;

              // TODO: add functionality here...

              return IRhinoCommand.result.success;
        }
コード例 #15
0
        ///<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 objects to apply item tag");
              go.EnableSubObjectSelect(false);
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              EstimatorTagForm form = new EstimatorTagForm();
              form.m_str_title = "Add Item Tag";
              form.m_str_prompt = "Select an item tag.";
              form.m_type = EstimatorTag.tag_type.item_tag;

              DialogResult rc = form.ShowDialog();
              if (rc == DialogResult.Cancel)
            return IRhinoCommand.result.cancel;

              List<string> tag_strings = new List<string>(form.m_selected_tags.Count);

              EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn;
              int i = 0;

              for (i = 0; i < form.m_selected_tags.Count; i++)
              {
            int index = form.m_selected_tags[i];
            tag_strings.Add(plugin.m_tag_table[index].Id());
              }

              for (i = 0; i < go.ObjectCount(); i++)
              {
            EstimatorHelpers.RemoveAllData(go.Object(i).Object());
            EstimatorHelpers.AddData(go.Object(i).Object(), tag_strings.ToArray());
              }

              return IRhinoCommand.result.success;
        }
コード例 #16
0
        ///<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 tagged object to report");
              go.EnableSubObjectSelect(false);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IRhinoObject obj = go.Object(0).Object();
              if (null == obj)
            return IRhinoCommand.result.failure;

              IOnGeometry geo = obj.Geometry();
              if (null == geo)
            return IRhinoCommand.result.failure;

              string[] string_array = null;
              if (0 == EstimatorHelpers.GetData(obj, ref string_array))
              {
            RhUtil.RhinoApp().Print("No Estimator tag data found.\n");
            return IRhinoCommand.result.nothing;
              }

              string filename = null;

              SaveFileDialog sd = new SaveFileDialog();
              sd.DefaultExt = "xml";
              sd.Filter = "XML file (*.xml)|*.xml|All files (*.*)|*.*";
              sd.AddExtension = true;
              sd.RestoreDirectory = true;
              sd.Title = "Save";
              if (sd.ShowDialog() == DialogResult.OK)
            filename = sd.FileName;
              sd.Dispose();
              sd = null;

              if (null == filename)
            return IRhinoCommand.result.cancel;

              XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8);
              writer.Formatting = Formatting.Indented;
              writer.WriteStartDocument();
              writer.WriteComment("Saved on " + DateTime.Now);

              // Write root element
              writer.WriteStartElement("Estimator");
              writer.WriteAttributeString("Version", "1.0");

              // Write object
              writer.WriteStartElement("Object");
              writer.WriteAttributeString("Type", geo.ObjectType().ToString());
              writer.WriteElementString("Uuid", obj.Attributes().m_uuid.ToString());
              if (obj.Attributes().m_name.Length > 0)
            writer.WriteElementString("Name", obj.Attributes().m_name);
              else
            writer.WriteElementString("Name", "(none)");

              // Write object length
              double length = EstimatorHelpers.GetLength(obj);
              if (length > 0.0)
            writer.WriteElementString("Length", length.ToString());
              else
            writer.WriteElementString("Length", "n/a");

              double tol = context.m_doc.AbsoluteTolerance();

              // Write object area
              double area = EstimatorHelpers.GetArea(obj, tol);
              if (area > 0.0)
            writer.WriteElementString("Area", area.ToString());
              else
            writer.WriteElementString("Area", "n/a");

              // Write object volume
              double volume = EstimatorHelpers.GetVolume(obj);
              if (volume > 0.0)
            writer.WriteElementString("Volume", volume.ToString());
              else
            writer.WriteElementString("Volume", "n/a");

              // Write object tags
              writer.WriteStartElement("Tags");
              for (int i = 0; i < string_array.Length; i++)
            writer.WriteElementString("Tag", string_array[i]);

              writer.WriteEndElement(); // Tags

              writer.WriteEndElement(); // Object

              writer.WriteEndElement(); // Estimator

              writer.WriteEndDocument();
              writer.Flush();
              writer.Close();

              return IRhinoCommand.result.success;
        }
コード例 #17
0
        ///<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 tagged object to report");
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IRhinoObject obj = go.Object(0).Object();

            if (null == obj)
            {
                return(IRhinoCommand.result.failure);
            }

            IOnGeometry geo = obj.Geometry();

            if (null == geo)
            {
                return(IRhinoCommand.result.failure);
            }

            string[] string_array = null;
            if (0 == EstimatorHelpers.GetData(obj, ref string_array))
            {
                RhUtil.RhinoApp().Print("No Estimator tag data found.\n");
                return(IRhinoCommand.result.nothing);
            }

            string filename = null;

            SaveFileDialog sd = new SaveFileDialog();

            sd.DefaultExt       = "xml";
            sd.Filter           = "XML file (*.xml)|*.xml|All files (*.*)|*.*";
            sd.AddExtension     = true;
            sd.RestoreDirectory = true;
            sd.Title            = "Save";
            if (sd.ShowDialog() == DialogResult.OK)
            {
                filename = sd.FileName;
            }
            sd.Dispose();
            sd = null;

            if (null == filename)
            {
                return(IRhinoCommand.result.cancel);
            }

            XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8);

            writer.Formatting = Formatting.Indented;
            writer.WriteStartDocument();
            writer.WriteComment("Saved on " + DateTime.Now);

            // Write root element
            writer.WriteStartElement("Estimator");
            writer.WriteAttributeString("Version", "1.0");

            // Write object
            writer.WriteStartElement("Object");
            writer.WriteAttributeString("Type", geo.ObjectType().ToString());
            writer.WriteElementString("Uuid", obj.Attributes().m_uuid.ToString());
            if (obj.Attributes().m_name.Length > 0)
            {
                writer.WriteElementString("Name", obj.Attributes().m_name);
            }
            else
            {
                writer.WriteElementString("Name", "(none)");
            }

            // Write object length
            double length = EstimatorHelpers.GetLength(obj);

            if (length > 0.0)
            {
                writer.WriteElementString("Length", length.ToString());
            }
            else
            {
                writer.WriteElementString("Length", "n/a");
            }

            double tol = context.m_doc.AbsoluteTolerance();

            // Write object area
            double area = EstimatorHelpers.GetArea(obj, tol);

            if (area > 0.0)
            {
                writer.WriteElementString("Area", area.ToString());
            }
            else
            {
                writer.WriteElementString("Area", "n/a");
            }

            // Write object volume
            double volume = EstimatorHelpers.GetVolume(obj);

            if (volume > 0.0)
            {
                writer.WriteElementString("Volume", volume.ToString());
            }
            else
            {
                writer.WriteElementString("Volume", "n/a");
            }

            // Write object tags
            writer.WriteStartElement("Tags");
            for (int i = 0; i < string_array.Length; i++)
            {
                writer.WriteElementString("Tag", string_array[i]);
            }

            writer.WriteEndElement(); // Tags

            writer.WriteEndElement(); // Object

            writer.WriteEndElement(); // Estimator

            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();

            return(IRhinoCommand.result.success);
        }
コード例 #18
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            int nValue = _nValue;
              double dValue = _dValue;

              MRhinoGetObject go = new MRhinoGetObject();
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              go.EnableGroupSelect(true);
              go.EnableSubObjectSelect(false);
              go.EnableClearObjectsOnEntry(false);
              go.EnableUnselectObjectsOnExit(false);
              go.EnableDeselectAllBeforePostSelect(false);

              bool bHavePreselectedObjects = false;

              for (; ; )
              {
            go.ClearCommandOptions();

            int dOptionIndex = go.AddCommandOptionNumber(
              new MRhinoCommandOptionName("Double"),
              new MRhinoGet.DoubleOption(dValue),
              "Double value", false, 0.1, 99.9
              );

            int nOptionIndex = go.AddCommandOptionInteger(
              new MRhinoCommandOptionName("Integer"),
              new MRhinoGet.IntegerOption(nValue),
              "Integer value", 1, 99
              );

            IRhinoGet.result res = go.GetObjects(1, 0);

            if (res == IRhinoGet.result.option)
            {
              IRhinoCommandOption commandOption = go.Option();
              if (null != commandOption)
              {
            int optionIndex = commandOption.m_option_index;
            if (optionIndex == nOptionIndex)
              nValue = (int)commandOption.m_number_option_value;
            else if (optionIndex == dOptionIndex)
              dValue = commandOption.m_number_option_value;
              }

              go.EnablePreSelect(false);
              continue;
            }

            else if (res != IRhinoGet.result.@object)
              return IRhinoCommand.result.cancel;

            if (go.ObjectsWerePreSelected())
            {
              bHavePreselectedObjects = true;
              go.EnablePreSelect(false);
              continue;
            }

            break;
              }

              if (bHavePreselectedObjects)
              {
            // Normally, pre-selected objects will remain selected, when a
            // command finishes, and post-selected objects will be unselected.
            // This this way of picking, it is possible to have a combination
            // of pre-selected and post-selected. So, to make sure everything
            // "looks the same", lets unselect everything before finishing
            // the command.
            for (int i = 0; i < go.ObjectCount(); i++)
            {
              IRhinoObject rhinoObject = go.Object(i).Object();
              if (null != rhinoObject)
            rhinoObject.Select(false);
            }
            context.m_doc.Redraw();
              }

              int objectCount = go.ObjectCount();
              _dValue = dValue;
              _nValue = nValue;

              RhUtil.RhinoApp().Print(string.Format("Select object count = {0}\n", objectCount));
              RhUtil.RhinoApp().Print(string.Format("Value of double = {0}\n", _dValue));
              RhUtil.RhinoApp().Print(string.Format("Value of integer = {0}\n", _nValue));

              return IRhinoCommand.result.success;
        }
コード例 #19
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            int    nValue = _nValue;
            double dValue = _dValue;

            MRhinoGetObject go = new MRhinoGetObject();

            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.EnableGroupSelect(true);
            go.EnableSubObjectSelect(false);
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.EnableDeselectAllBeforePostSelect(false);

            bool bHavePreselectedObjects = false;

            for (; ;)
            {
                go.ClearCommandOptions();

                int dOptionIndex = go.AddCommandOptionNumber(
                    new MRhinoCommandOptionName("Double"),
                    new MRhinoGet.DoubleOption(dValue),
                    "Double value", false, 0.1, 99.9
                    );

                int nOptionIndex = go.AddCommandOptionInteger(
                    new MRhinoCommandOptionName("Integer"),
                    new MRhinoGet.IntegerOption(nValue),
                    "Integer value", 1, 99
                    );

                IRhinoGet.result res = go.GetObjects(1, 0);

                if (res == IRhinoGet.result.option)
                {
                    IRhinoCommandOption commandOption = go.Option();
                    if (null != commandOption)
                    {
                        int optionIndex = commandOption.m_option_index;
                        if (optionIndex == nOptionIndex)
                        {
                            nValue = (int)commandOption.m_number_option_value;
                        }
                        else if (optionIndex == dOptionIndex)
                        {
                            dValue = commandOption.m_number_option_value;
                        }
                    }

                    go.EnablePreSelect(false);
                    continue;
                }

                else if (res != IRhinoGet.result.@object)
                {
                    return(IRhinoCommand.result.cancel);
                }

                if (go.ObjectsWerePreSelected())
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false);
                    continue;
                }

                break;
            }

            if (bHavePreselectedObjects)
            {
                // Normally, pre-selected objects will remain selected, when a
                // command finishes, and post-selected objects will be unselected.
                // This this way of picking, it is possible to have a combination
                // of pre-selected and post-selected. So, to make sure everything
                // "looks the same", lets unselect everything before finishing
                // the command.
                for (int i = 0; i < go.ObjectCount(); i++)
                {
                    IRhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                context.m_doc.Redraw();
            }

            int objectCount = go.ObjectCount();

            _dValue = dValue;
            _nValue = nValue;

            RhUtil.RhinoApp().Print(string.Format("Select object count = {0}\n", objectCount));
            RhUtil.RhinoApp().Print(string.Format("Value of double = {0}\n", _dValue));
            RhUtil.RhinoApp().Print(string.Format("Value of integer = {0}\n", _nValue));

            return(IRhinoCommand.result.success);
        }
コード例 #20
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Step 1, select objects to include in the instance definition
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select objects to define block");
              go.EnableReferenceObjectSelect(false);
              go.EnableSubObjectSelect(false);
              go.EnableGroupSelect(true);
              // Phantoms, grips, lights, etc., cannot be in instance definitions.
              uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object |
                                              IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object |
                                              IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object
                                              );
              uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object;
              go.SetGeometryFilter(geometry_filter);
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              // Step 2, select base point
              MRhinoGetPoint gp = new MRhinoGetPoint();
              gp.SetCommandPrompt("Block base point");
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              On3dPoint base_point = gp.Point();

              // Step 3, get instance definition name
              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Block definition name");
              gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc));
              gs.GetString();
              if (gs.CommandResult() != IRhinoCommand.result.success)
            return gs.CommandResult();

              string idef_name = gs.String().Trim();
              if (string.IsNullOrEmpty(idef_name))
            return IRhinoCommand.result.nothing;

              // Step 4, verify objects
              int found_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name);
              List<IRhinoObject> objects = new List<IRhinoObject>();

              bool bQuietly = context.IsInteractive() ? false : true;

              for (int i = 0; i < go.ObjectCount(); i++)
              {
            IRhinoObject obj = go.Object(i).Object();
            if (obj == null)
              continue;

            // Probably don't need to do this...
            if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType()))
              continue;

            if (obj.ObjectType() == IOn.object_type.instance_reference)
            {
              IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj);
              if (iref_obj != null)
              {
            if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0)
            {
              if (!bQuietly)
                RhUtil.RhinoApp().Print("Unable to create block.\n");
              return IRhinoCommand.result.failure;
            }
              }
            }
            objects.Add(obj);
              }

              // Step 5, create instance definition
              OnInstanceDefinition idef = new OnInstanceDefinition();
              idef.SetName(idef_name);

              int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly);
              if (idef_index < 0)
            return IRhinoCommand.result.failure;

              // Step 6, create the instance reference
              OnXform xform = new OnXform();
              xform.Translation(base_point - new On3dPoint(OnUtil.On_origin));
              IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform);
              if (inst_obj != null)
              {
            inst_obj.Select(true);
              }
              else
              {
            if (!bQuietly)
              RhUtil.RhinoApp().Print("Error creating block.\n");
            return IRhinoCommand.result.failure;
              }

              // Step 7, delete existing geometry
              for (int i = 0; i < objects.Count; i++)
            context.m_doc.DeleteObject(new MRhinoObjRef(objects[i]));

              context.m_doc.Redraw();

              return IRhinoCommand.result.success;
        }
コード例 #21
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            Model.globalContext = context;

            // get file info after it has been loaded into memory.
            Model.txtFilename = context.m_doc.GetPathName();
            Model.txtTitle = context.m_doc.GetTitle();
            //  http://wiki.mcneel.com/developer/sdksamples/meshvolume
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt( "Select solid meshes for volume calculation" );
              go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object );
              go.SetGeometryAttributeFilter( IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh );
              go.EnableSubObjectSelect(false);
              go.EnableGroupSelect();
              go.GetObjects( 1, 0 );
              if( go.CommandResult() != IRhinoCommand.result.success )
            return go.CommandResult();

              List<IOnMesh> meshes = new List<IOnMesh>();
              for( int i = 0; i < go.ObjectCount(); i++ )
              {
            IOnMesh mesh = go.Object(i).Mesh();
            if( mesh != null )
              meshes.Add( mesh );
              }
              if( meshes.Count == 0 )
            return IRhinoCommand.result.nothing;

              OnBoundingBox bbox = new OnBoundingBox();
              for( int i = 0; i < meshes.Count; i++ )
            meshes[i].GetBoundingBox( ref bbox, 1 );
              On3dPoint base_point = bbox.Center();

              double total_volume = 0.0;
              double total_error_estimate = 0.0;
              string msg;
              for( int i = 0; i < meshes.Count; i++ )
              {
            double error_estimate = 0.0;
            double volume = meshes[i].Volume( base_point, ref error_estimate );
            msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n",i,volume,error_estimate);
            RhUtil.RhinoApp().Print( msg );
            total_volume += volume;
            total_error_estimate += error_estimate;
              }
              msg = string.Format("Total volume = {0:f} (+/- {1:f})\n",
                      total_volume,
                      total_error_estimate);
              RhUtil.RhinoApp().Print( msg );
              return IRhinoCommand.result.success;

            /*
            System.Guid id = CsDockingDialogDockBar.ID();
              bool bVisible = RMA.UI.MRhinoDockBarManager.IsDockBarVisible(id);

              string prompt;
              if (bVisible)
            prompt = string.Format("{0} window is visible. New value", EnglishCommandName());
              else
            prompt = string.Format("{0} window is hidden. New value", EnglishCommandName());

              MRhinoGetOption go = new MRhinoGetOption();
              go.SetCommandPrompt(prompt);
              int h_option = go.AddCommandOption(new MRhinoCommandOptionName("Hide"));
              int s_option = go.AddCommandOption(new MRhinoCommandOptionName("Show"));
              int t_option = go.AddCommandOption(new MRhinoCommandOptionName("Toggle"));
              go.GetOption();
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IRhinoCommandOption opt = go.Option();
              if (opt == null)
            return IRhinoCommand.result.failure;

              int option_index = opt.m_option_index;
              if (h_option == option_index)
              {
            if (bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, false, false);
              }
              else if (s_option == option_index)
              {
            if (!bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, true, false);
              }
              else if (t_option == option_index)
              {
            if (bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, false, false);
            else
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, true, false);
              }

              return IRhinoCommand.result.success;*/
        }
コード例 #22
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Step 1, select objects to include in the instance definition
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to define block");
            go.EnableReferenceObjectSelect(false);
            go.EnableSubObjectSelect(false);
            go.EnableGroupSelect(true);
            // Phantoms, grips, lights, etc., cannot be in instance definitions.
            uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object |
                                                    IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object |
                                                    IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object
                                                    );
            uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object;

            go.SetGeometryFilter(geometry_filter);
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Step 2, select base point
            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Block base point");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint base_point = gp.Point();

            // Step 3, get instance definition name
            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Block definition name");
            gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc));
            gs.GetString();
            if (gs.CommandResult() != IRhinoCommand.result.success)
            {
                return(gs.CommandResult());
            }

            string idef_name = gs.String().Trim();

            if (string.IsNullOrEmpty(idef_name))
            {
                return(IRhinoCommand.result.nothing);
            }

            // Step 4, verify objects
            int found_index             = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name);
            List <IRhinoObject> objects = new List <IRhinoObject>();

            bool bQuietly = context.IsInteractive() ? false : true;

            for (int i = 0; i < go.ObjectCount(); i++)
            {
                IRhinoObject obj = go.Object(i).Object();
                if (obj == null)
                {
                    continue;
                }

                // Probably don't need to do this...
                if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType()))
                {
                    continue;
                }

                if (obj.ObjectType() == IOn.object_type.instance_reference)
                {
                    IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj);
                    if (iref_obj != null)
                    {
                        if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0)
                        {
                            if (!bQuietly)
                            {
                                RhUtil.RhinoApp().Print("Unable to create block.\n");
                            }
                            return(IRhinoCommand.result.failure);
                        }
                    }
                }
                objects.Add(obj);
            }

            // Step 5, create instance definition
            OnInstanceDefinition idef = new OnInstanceDefinition();

            idef.SetName(idef_name);

            int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly);

            if (idef_index < 0)
            {
                return(IRhinoCommand.result.failure);
            }

            // Step 6, create the instance reference
            OnXform xform = new OnXform();

            xform.Translation(base_point - new On3dPoint(OnUtil.On_origin));
            IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform);

            if (inst_obj != null)
            {
                inst_obj.Select(true);
            }
            else
            {
                if (!bQuietly)
                {
                    RhUtil.RhinoApp().Print("Error creating block.\n");
                }
                return(IRhinoCommand.result.failure);
            }

            // Step 7, delete existing geometry
            for (int i = 0; i < objects.Count; i++)
            {
                context.m_doc.DeleteObject(new MRhinoObjRef(objects[i]));
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }