///<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);
        }
        ///<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;
        }
        ///<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 mesh");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IRhinoMeshObject mesh_object = MRhinoMeshObject.ConstCast(go.Object(0).Object());

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

            SampleCsColoredMeshConduit conduit = new SampleCsColoredMeshConduit(mesh_object.m_runtime_object_serial_number);

            conduit.Enable();
            context.m_doc.Regen();

            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Press <Enter> to continue");
            gs.AcceptNothing();
            gs.GetString();

            conduit.Disable();
            context.m_doc.Regen();

            return(IRhinoCommand.result.success);
        }
        ///<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 mesh");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IRhinoMeshObject mesh_object = MRhinoMeshObject.ConstCast(go.Object(0).Object());
              if (null == mesh_object)
            return IRhinoCommand.result.failure;

              SampleCsColoredMeshConduit conduit = new SampleCsColoredMeshConduit(mesh_object.m_runtime_object_serial_number);
              conduit.Enable();
              context.m_doc.Regen();

              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Press <Enter> to continue");
              gs.AcceptNothing();
              gs.GetString();

              conduit.Disable();
              context.m_doc.Regen();

              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 polysurface to explode");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnBrep brep = go.Object(0).Brep();

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

            for (int i = 0; i < brep.m_F.Count(); i++)
            {
                OnBrep faceBrep = brep.DuplicateFace(i, true);
                if (null != faceBrep)
                {
                    context.m_doc.AddBrepObject(faceBrep);
                }
            }

            context.m_doc.DeleteObject(go.Object(0));
            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)
        {
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select polysurface to explode");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IOnBrep brep = go.Object(0).Brep();
              if (null == brep)
            return IRhinoCommand.result.failure;

              for (int i = 0; i < brep.m_F.Count(); i++)
              {
            OnBrep faceBrep = brep.DuplicateFace(i, true);
            if (null != faceBrep)
              context.m_doc.AddBrepObject(faceBrep);
              }

              context.m_doc.DeleteObject(go.Object(0));
              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)
        {
            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;
        }
예제 #8
0
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select objects for Z analysis");
              go.SetGeometryFilter(
            IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object |
            IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object |
            IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object
            );
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

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

            if (obj.InAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID))
              // This object is already in Z analysis mode
              continue;

            if (obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, true))
              // A new object is in Z analysis mode
              count++;
              }

              context.m_doc.Redraw();
              RhUtil.RhinoApp().Print(string.Format("{0} objects were put into Z-Analysis mode.\n", count));

              return IRhinoCommand.result.success;
        }
        ///<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);
        }
        ///<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 or polysurface for direction display");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              MRhinoObjRef obj_ref = go.Object(0);
              IOnBrep brep = obj_ref.Brep();
              if (null == brep)
            return IRhinoCommand.result.failure;

              bool bIsSolid = brep.IsSolid();
              bool bFlip = false;

              SampleCsSurfaceDirectionConduit conduit = new SampleCsSurfaceDirectionConduit();
              conduit.SetBrep(brep);
              conduit.Enable();
              context.m_doc.Redraw();

              MRhinoGetOption gf = new MRhinoGetOption();
              gf.SetCommandPrompt("Press Enter when done");
              gf.AcceptNothing();
              if (!bIsSolid)
            gf.AddCommandOption(new MRhinoCommandOptionName("Flip"));

              for (; ; )
              {
            IRhinoGet.result res = gf.GetOption();

            if (res == IRhinoGet.result.option)
            {
              bFlip = !bFlip;
              conduit.SetFlip(bFlip);
              context.m_doc.Redraw();
              continue;
            }

            if (res == IRhinoGet.result.nothing)
            {
              if (!bIsSolid && bFlip)
              {
            OnBrep flipped_brep = new OnBrep(brep);
            flipped_brep.Flip();
            context.m_doc.ReplaceObject(obj_ref, flipped_brep);
              }
            }

            break;
              }

              conduit.Disable();
              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)
        {
            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);
        }
        ///<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");
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

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

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

            // 1.) Try the object test
            RhUtil.RhinoApp().Print("Object Test: ");
            if (IsLeader(obj))
            {
                RhUtil.RhinoApp().Print("object is a leader.\n");
            }
            else
            {
                RhUtil.RhinoApp().Print("object is not a leader.\n");
            }

            // 2.) Try the GUID test
            RhUtil.RhinoApp().Print("GUID Test: ");
            if (IsLeader(obj.Attributes().m_uuid))
            {
                RhUtil.RhinoApp().Print("object is a leader.\n");
            }
            else
            {
                RhUtil.RhinoApp().Print("object is not a leader.\n");
            }

            // 3.) Try the geometry test
            RhUtil.RhinoApp().Print("Geometry Test: ");
            if (IsLeader(obj_ref.Geometry()))
            {
                RhUtil.RhinoApp().Print("object is a leader.\n");
            }
            else
            {
                RhUtil.RhinoApp().Print("object is not a leader.\n");
            }

            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 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);
        }
        ///<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 move");
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoXformObjectList list = new MRhinoXformObjectList();

            if (list.AddObjects(go, true) < 1)
            {
                return(IRhinoCommand.result.failure);
            }

            MRhinoGetPoint gp = new MRhinoGetPoint();

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

            RhinoGetTranslation gt = new RhinoGetTranslation();

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

            OnXform xform = new OnXform();

            if (gt.CalculateTransform(gt.View().ActiveViewport(), gt.Point(), ref xform))
            {
                // TODO: do object transformation here.
            }

            return(IRhinoCommand.result.success);
        }
        ///<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;
        }
        ///<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;
        }
        ///<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);
        }
        ///<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 hatch to explode");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.hatch_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IRhinoHatch hatchObject = MRhinoHatch.ConstCast(go.Object(0).Object());
              if (null == hatchObject)
            return IRhinoCommand.result.failure;

              List<Guid> objectGuids = new List<Guid>();
              int objectGuids_Count = ExplodeHatch(context.m_doc, hatchObject.Attributes().m_uuid, ref objectGuids);

              return IRhinoCommand.result.success;
        }
        ///<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 rectangular light");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnLight light = go.Object(0).Light();

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

            if (!light.IsRectangularLight())
            {
                RhUtil.RhinoApp().Print("Not a rectangular light.\n");
                return(IRhinoCommand.result.nothing);
            }

            On3dPoint  origin = light.Location();
            On3dVector xaxis  = light.Length();
            On3dVector yaxis  = light.Width();

            OnPlane    plane      = new OnPlane(origin, xaxis, yaxis);
            OnInterval x_interval = new OnInterval(0.0, xaxis.Length());
            OnInterval y_interval = new OnInterval(0.0, yaxis.Length());

            OnMesh mesh = RhUtil.RhinoMeshPlane(plane, x_interval, y_interval, 2, 2);

            if (null != mesh)
            {
                mesh.ConvertQuadsToTriangles();
                context.m_doc.AddMeshObject(mesh);
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.cancel);
        }
예제 #20
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);
        }
예제 #21
0
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects for Z analysis");
            go.SetGeometryFilter(
                IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object |
                IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object |
                IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object
                );
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            int count = 0;

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

                if (obj.InAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID))
                {
                    // This object is already in Z analysis mode
                    continue;
                }

                if (obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, true))
                {
                    // A new object is in Z analysis mode
                    count++;
                }
            }

            context.m_doc.Redraw();
            RhUtil.RhinoApp().Print(string.Format("{0} objects were put into Z-Analysis mode.\n", count));

            return(IRhinoCommand.result.success);
        }
    ///<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 edge curve");
      go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
      go.GetObjects(1, 1);
      if (go.CommandResult() != IRhinoCommand.result.success)
        return go.CommandResult();

      IRhinoObject obj = go.Object(0).Object();
      IOnBrep brep = go.Object(0).Brep();
      IOnBrepEdge edge = go.Object(0).Edge();
      if (null == obj || null == brep || null == edge)
        return IRhinoCommand.result.failure;

      MRhinoObjectAttributes attribs = new MRhinoObjectAttributes(obj.Attributes());
      if (attribs.GroupCount() > 0)
        attribs.RemoveFromAllGroups();

      for (int i = 0; i < edge.TrimCount(); i++)
      {
        IOnBrepTrim trim = edge.Trim(i);
        if (null != trim)
        {
          IOnBrepFace face = trim.Face();
          if (null != face)
          {
            OnBrep face_brep = brep.DuplicateFace(face.m_face_index, true);
            if (null != face_brep)
            {
              MRhinoBrepObject face_brep_obj = context.m_doc.AddBrepObject(face_brep, attribs);
              if (null != face_brep_obj)
                face_brep_obj.Select();
            }
          }
        }
      }

      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)
        {
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select edge curve");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IRhinoObject obj = go.Object(0).Object();
              IOnBrep brep = go.Object(0).Brep();
              IOnBrepEdge edge = go.Object(0).Edge();
              if (null == obj || null == brep || null == edge)
            return IRhinoCommand.result.failure;

              MRhinoObjectAttributes attribs = new MRhinoObjectAttributes(obj.Attributes());
              if (attribs.GroupCount() > 0)
            attribs.RemoveFromAllGroups();

              for (int i = 0; i < edge.TrimCount(); i++)
              {
            IOnBrepTrim trim = edge.Trim(i);
            if (null != trim)
            {
              IOnBrepFace face = trim.Face();
              if (null != face)
              {
            OnBrep face_brep = brep.DuplicateFace(face.m_face_index, true);
            if (null != face_brep)
            {
              MRhinoBrepObject face_brep_obj = context.m_doc.AddBrepObject(face_brep, attribs);
              if (null != face_brep_obj)
                face_brep_obj.Select();
            }
              }
            }
              }

              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)
        {
            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);
        }
        ///<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;
        }
        ///<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;
        }
        ///<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;
        }
        ///<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 rectangular light");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IOnLight light = go.Object(0).Light();
              if (null == light)
            return IRhinoCommand.result.failure;

              if (!light.IsRectangularLight())
              {
            RhUtil.RhinoApp().Print("Not a rectangular light.\n");
            return IRhinoCommand.result.nothing;
              }

              On3dPoint origin = light.Location();
              On3dVector xaxis = light.Length();
              On3dVector yaxis = light.Width();

              OnPlane plane = new OnPlane(origin, xaxis, yaxis);
              OnInterval x_interval = new OnInterval(0.0, xaxis.Length());
              OnInterval y_interval = new OnInterval(0.0, yaxis.Length());

              OnMesh mesh = RhUtil.RhinoMeshPlane(plane, x_interval, y_interval, 2, 2);
              if (null != mesh)
              {
            mesh.ConvertQuadsToTriangles();
            context.m_doc.AddMeshObject(mesh);
            context.m_doc.Redraw();
              }

              return IRhinoCommand.result.cancel;
        }
예제 #29
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;
        }
        ///<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");
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

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

              // 1.) Try the object test
              RhUtil.RhinoApp().Print("Object Test: ");
              if (IsLeader(obj))
            RhUtil.RhinoApp().Print("object is a leader.\n");
              else
            RhUtil.RhinoApp().Print("object is not a leader.\n");

              // 2.) Try the GUID test
              RhUtil.RhinoApp().Print("GUID Test: ");
              if (IsLeader(obj.Attributes().m_uuid))
            RhUtil.RhinoApp().Print("object is a leader.\n");
              else
            RhUtil.RhinoApp().Print("object is not a leader.\n");

              // 3.) Try the geometry test
              RhUtil.RhinoApp().Print("Geometry Test: ");
              if (IsLeader(obj_ref.Geometry()))
            RhUtil.RhinoApp().Print("object is a leader.\n");
              else
            RhUtil.RhinoApp().Print("object is not a leader.\n");

              return IRhinoCommand.result.success;
        }
예제 #31
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 hatch to explode");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.hatch_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IRhinoHatch hatchObject = MRhinoHatch.ConstCast(go.Object(0).Object());

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

            List <Guid> objectGuids       = new List <Guid>();
            int         objectGuids_Count = ExplodeHatch(context.m_doc, hatchObject.Attributes().m_uuid, ref objectGuids);

            return(IRhinoCommand.result.success);
        }
        ///<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 move");
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              MRhinoXformObjectList list = new MRhinoXformObjectList();
              if (list.AddObjects(go, true) < 1)
            return IRhinoCommand.result.failure;

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

              RhinoGetTranslation gt = new RhinoGetTranslation();
              gt.SetCommandPrompt("Point to move to");
              gt.AppendObjects(list);
              gt.SetBasePoint(gp.Point());
              gt.DrawLineFromPoint(gp.Point(), true);
              gt.GetXform();
              if (gt.CommandResult() != IRhinoCommand.result.success)
            return gt.CommandResult();

              OnXform xform = new OnXform();
              if (gt.CalculateTransform(gt.View().ActiveViewport(), gt.Point(), ref xform))
              {
            // TODO: do object transformation here.
              }

              return IRhinoCommand.result.success;
        }
예제 #33
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 or polysurface for direction display");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref = go.Object(0);
            IOnBrep      brep    = obj_ref.Brep();

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

            bool bIsSolid = brep.IsSolid();
            bool bFlip    = false;

            SampleCsSurfaceDirectionConduit conduit = new SampleCsSurfaceDirectionConduit();

            conduit.SetBrep(brep);
            conduit.Enable();
            context.m_doc.Redraw();

            MRhinoGetOption gf = new MRhinoGetOption();

            gf.SetCommandPrompt("Press Enter when done");
            gf.AcceptNothing();
            if (!bIsSolid)
            {
                gf.AddCommandOption(new MRhinoCommandOptionName("Flip"));
            }

            for (; ;)
            {
                IRhinoGet.result res = gf.GetOption();

                if (res == IRhinoGet.result.option)
                {
                    bFlip = !bFlip;
                    conduit.SetFlip(bFlip);
                    context.m_doc.Redraw();
                    continue;
                }

                if (res == IRhinoGet.result.nothing)
                {
                    if (!bIsSolid && bFlip)
                    {
                        OnBrep flipped_brep = new OnBrep(brep);
                        flipped_brep.Flip();
                        context.m_doc.ReplaceObject(obj_ref, flipped_brep);
                    }
                }

                break;
            }

            conduit.Disable();
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
예제 #34
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);
        }
예제 #35
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select a curve object
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select curve");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

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

              // Get the active view
              MRhinoView view = RhUtil.RhinoApp().ActiveView();
              if (null == view)
            return IRhinoCommand.result.failure;

              // Get the construction plane from the active view
              OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane);

              // Create a construction plane aligned bounding box
              OnBoundingBox bbox = new OnBoundingBox();
              IRhinoObject[] objs = new IRhinoObject[1] { obj };
              bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane);
              if (rc == false)
            return IRhinoCommand.result.failure;

              // Validate bounding box
              if (0 != bbox.IsDegenerate())
              {
            RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n");
            return IRhinoCommand.result.nothing;
              }

              // ON_BrepBox wants 8 points defining the box corners
              // arranged in this order:
              //
              //          v7______________v6
              //           |\             |\
              //           | \            | \
              //           |  \ _____________\
              //           |   v4         |   v5
              //           |   |          |   |
              //           |   |          |   |
              //          v3---|---------v2   |
              //           \   |          \   |
              //            \  |           \  |
              //             \ |            \ |
              //              \v0____________\v1
              //
              On3dPoint[] box_corners = new On3dPoint[8];
              box_corners[0] = bbox.Corner(0, 0, 0);
              box_corners[1] = bbox.Corner(1, 0, 0);
              box_corners[2] = bbox.Corner(1, 1, 0);
              box_corners[3] = bbox.Corner(0, 1, 0);
              box_corners[4] = bbox.Corner(0, 0, 1);
              box_corners[5] = bbox.Corner(1, 0, 1);
              box_corners[6] = bbox.Corner(1, 1, 1);
              box_corners[7] = bbox.Corner(0, 1, 1);

              // Transform points to the world-xy plane
              OnXform p2w = new OnXform();
              p2w.ChangeBasis(plane, OnUtil.On_xy_plane);
              for (int i = 0; i < 8; i++)
            box_corners[i].Transform(p2w);

              // Make a brep box
              OnBrep brep = OnUtil.ON_BrepBox(box_corners);
              if (null != brep)
              {
            context.m_doc.AddBrepObject(brep);
            context.m_doc.Redraw();
              }

              return IRhinoCommand.result.success;
        }
예제 #36
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;*/
        }
        ///<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, polysurface, or mesh to export");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref = go.Object(0);

            IRhinoObject obj = obj_ref.Object();

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

            List <IRhinoObject> obj_list = new List <IRhinoObject>();

            obj_list.Add(obj);

            ArrayMRhinoObjectMesh mesh_list       = new ArrayMRhinoObjectMesh(obj_list.Count);
            OnMeshParameters      mesh_parameters = _mesh_parameters;
            int mesh_ui_style = !context.IsInteractive() ? 2 : _mesh_ui_style;

            IRhinoCommand.result res = RhUtil.RhinoMeshObjects(obj_list.ToArray(), ref mesh_parameters, ref mesh_ui_style, ref mesh_list);
            if (res == IRhinoCommand.result.success)
            {
                if (mesh_ui_style >= 0 && mesh_ui_style <= 1)
                {
                    _mesh_ui_style = mesh_ui_style;
                }
                _mesh_parameters = mesh_parameters;
            }
            else
            {
                RhUtil.RhinoApp().Print("No mesh to export.\n");
                return(res);
            }

            string filename = string.Empty;

            if (context.IsInteractive())
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Title            = "Export";
                dialog.Filter           = "Geomview files|*.off";
                dialog.InitialDirectory = DirectoryManager.DefaultDirectory(DirectoryManager.FileTypes.ftExport);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return(IRhinoCommand.result.cancel);
                }

                filename = dialog.FileName;
            }
            else
            {
                MRhinoGetString gs = new MRhinoGetString();
                gs.SetCommandPrompt("Export file name");
                gs.GetString();
                if (gs.CommandResult() != IRhinoCommand.result.success)
                {
                    return(gs.CommandResult());
                }

                filename = gs.String().Trim();
            }

            try
            {
                OnMesh mesh = mesh_list.First().GetMesh();

                int vertex_count = mesh.VertexCount();
                int face_count   = mesh.FaceCount();
                int edge_count   = mesh.Topology().m_tope.Count();

                System.IO.StreamWriter file = new System.IO.StreamWriter(filename);

                // Write out the first line of the file header
                file.WriteLine("OFF");

                // Write the header information
                file.WriteLine(string.Format("{0} {1} {2}", vertex_count, face_count, edge_count));

                file.WriteLine();

                // Write out all the vertices in order
                for (int i = 0; i < vertex_count; i++)
                {
                    On3fPoint p = mesh.m_V[i];
                    file.WriteLine(string.Format("{0} {1} {2}", p.x.ToString("F"), p.y.ToString("F"), p.z.ToString("F")));
                }

                file.WriteLine();

                // Write out all the faces
                for (int i = 0; i < face_count; i++)
                {
                    OnMeshFace f = mesh.m_F[i];
                    if (f.IsQuad())
                    {
                        file.WriteLine(string.Format("4 {0} {1} {2} {3}", f.get_vi(0), f.get_vi(1), f.get_vi(2), f.get_vi(3)));
                    }
                    else
                    {
                        file.WriteLine(string.Format("3 {0} {1} {2}", f.get_vi(0), f.get_vi(1), f.get_vi(2)));
                    }
                }

                file.Close();
            }
            catch (Exception e)
            {
                RhUtil.RhinoApp().Print(string.Format("{0}\n", e.Message));
            }

            return(IRhinoCommand.result.success);
        }
예제 #38
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;
        }
예제 #39
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;
        }
예제 #40
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);
        }
        ///<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, polysurface, or mesh to export");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              MRhinoObjRef obj_ref = go.Object(0);

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

              List<IRhinoObject> obj_list = new List<IRhinoObject>();
              obj_list.Add(obj);

              ArrayMRhinoObjectMesh mesh_list = new ArrayMRhinoObjectMesh(obj_list.Count);
              OnMeshParameters mesh_parameters = _mesh_parameters;
              int mesh_ui_style = !context.IsInteractive() ? 2 : _mesh_ui_style;

              IRhinoCommand.result res = RhUtil.RhinoMeshObjects(obj_list.ToArray(), ref mesh_parameters, ref mesh_ui_style, ref mesh_list);
              if (res == IRhinoCommand.result.success)
              {
            if (mesh_ui_style >= 0 && mesh_ui_style <= 1)
              _mesh_ui_style = mesh_ui_style;
            _mesh_parameters = mesh_parameters;
              }
              else
              {
            RhUtil.RhinoApp().Print("No mesh to export.\n");
            return res;
              }

              string filename = string.Empty;

              if (context.IsInteractive())
              {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Title = "Export";
            dialog.Filter = "Geomview files|*.off";
            dialog.InitialDirectory = DirectoryManager.DefaultDirectory(DirectoryManager.FileTypes.ftExport);
            if (dialog.ShowDialog() != DialogResult.OK)
              return IRhinoCommand.result.cancel;

            filename = dialog.FileName;
              }
              else
              {
            MRhinoGetString gs = new MRhinoGetString();
            gs.SetCommandPrompt("Export file name");
            gs.GetString();
            if (gs.CommandResult() != IRhinoCommand.result.success)
              return gs.CommandResult();

            filename = gs.String().Trim();
              }

              try
              {
            OnMesh mesh = mesh_list.First().GetMesh();

            int vertex_count = mesh.VertexCount();
            int face_count = mesh.FaceCount();
            int edge_count = mesh.Topology().m_tope.Count();

            System.IO.StreamWriter file = new System.IO.StreamWriter(filename);

            // Write out the first line of the file header
            file.WriteLine("OFF");

            // Write the header information
            file.WriteLine(string.Format("{0} {1} {2}", vertex_count, face_count, edge_count));

            file.WriteLine();

            // Write out all the vertices in order
            for (int i = 0; i < vertex_count; i++)
            {
              On3fPoint p = mesh.m_V[i];
              file.WriteLine(string.Format("{0} {1} {2}", p.x.ToString("F"), p.y.ToString("F"), p.z.ToString("F")));
            }

            file.WriteLine();

            // Write out all the faces
            for (int i = 0; i < face_count; i++)
            {
              OnMeshFace f = mesh.m_F[i];
              if (f.IsQuad())
            file.WriteLine(string.Format("4 {0} {1} {2} {3}", f.get_vi(0), f.get_vi(1), f.get_vi(2), f.get_vi(3)));
              else
            file.WriteLine(string.Format("3 {0} {1} {2}", f.get_vi(0), f.get_vi(1), f.get_vi(2)));
            }

            file.Close();
              }
              catch (Exception e)
              {
            RhUtil.RhinoApp().Print(string.Format("{0}\n", e.Message));
              }

              return IRhinoCommand.result.success;
        }
예제 #42
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select a curve object
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select curve");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Validate the selection
            IRhinoObject obj = go.Object(0).Object();

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

            // Get the active view
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

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

            // Get the construction plane from the active view
            OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane);

            // Create a construction plane aligned bounding box
            OnBoundingBox bbox = new OnBoundingBox();

            IRhinoObject[] objs = new IRhinoObject[1] {
                obj
            };
            bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane);

            if (rc == false)
            {
                return(IRhinoCommand.result.failure);
            }

            // Validate bounding box
            if (0 != bbox.IsDegenerate())
            {
                RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n");
                return(IRhinoCommand.result.nothing);
            }

            // ON_BrepBox wants 8 points defining the box corners
            // arranged in this order:
            //
            //          v7______________v6
            //           |\             |\
            //           | \            | \
            //           |  \ _____________\ 
            //           |   v4         |   v5
            //           |   |          |   |
            //           |   |          |   |
            //          v3---|---------v2   |
            //           \   |          \   |
            //            \  |           \  |
            //             \ |            \ |
            //              \v0____________\v1
            //
            On3dPoint[] box_corners = new On3dPoint[8];
            box_corners[0] = bbox.Corner(0, 0, 0);
            box_corners[1] = bbox.Corner(1, 0, 0);
            box_corners[2] = bbox.Corner(1, 1, 0);
            box_corners[3] = bbox.Corner(0, 1, 0);
            box_corners[4] = bbox.Corner(0, 0, 1);
            box_corners[5] = bbox.Corner(1, 0, 1);
            box_corners[6] = bbox.Corner(1, 1, 1);
            box_corners[7] = bbox.Corner(0, 1, 1);

            // Transform points to the world-xy plane
            OnXform p2w = new OnXform();

            p2w.ChangeBasis(plane, OnUtil.On_xy_plane);
            for (int i = 0; i < 8; i++)
            {
                box_corners[i].Transform(p2w);
            }

            // Make a brep box
            OnBrep brep = OnUtil.ON_BrepBox(box_corners);

            if (null != brep)
            {
                context.m_doc.AddBrepObject(brep);
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.success);
        }
예제 #43
0
        /// <summary>
        /// This gets called when when the user runs this command.
        /// </summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select objects to animate
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to animate");
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Select path curve
            MRhinoGetObject gc = new MRhinoGetObject();

            gc.SetCommandPrompt("Select path curve");
            gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve);
            gc.EnableDeselectAllBeforePostSelect(false);
            gc.GetObjects(1, 1);
            if (gc.CommandResult() != IRhinoCommand.result.success)
            {
                return(gc.CommandResult());
            }

            // Get the curve
            IOnCurve crv = gc.Object(0).Curve();

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

            // Create an array of normalized curve parameters
            List <double> slist = new List <double>(m_max_steps);

            for (int i = 0; i < m_max_steps; i++)
            {
                double s = (double)i / ((double)m_max_steps - 1);
                slist.Add(s);
            }

            // Get the real parameters along the curve
            double[] tlist = new double[m_max_steps];
            if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist))
            {
                return(IRhinoCommand.result.failure);
            }

            // Create the display conduit
            SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit();

            // Get points along curve
            On3dPoint        start = new On3dPoint(crv.PointAtStart());
            List <On3dPoint> plist = new List <On3dPoint>(tlist.Length);

            for (int i = 0; i < m_max_steps; i++)
            {
                On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i]));
                plist.Add(pt);
            }

            // Hide objects and add them to conduit's object array
            for (int i = 0; i < go.ObjectCount(); i++)
            {
                MRhinoObjRef objref = go.Object(i);
                context.m_doc.HideObject(objref);
                conduit.m_objects.Add(objref.Object());
            }

            // Do animation...
            conduit.Enable();

            for (int i = 0; i < m_max_steps; i++)
            {
                On3dVector v = plist[i] - start;
                conduit.m_xform.Translation(v);
                context.m_doc.Redraw();
                Thread.Sleep(100);
            }

            for (int i = m_max_steps - 1; i >= 0; i--)
            {
                On3dVector v = plist[i] - start;
                conduit.m_xform.Translation(v);
                if (0 != i)
                {
                    context.m_doc.Redraw();
                    Thread.Sleep(100);
                }
            }

            conduit.Disable();

            // Show hidden objects
            for (int i = 0; i < go.ObjectCount(); i++)
            {
                MRhinoObjRef objref = go.Object(i);
                context.m_doc.ShowObject(objref);
            }

            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)
        {
            // Select objects to animate
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select objects to animate");
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              // Select path curve
              MRhinoGetObject gc = new MRhinoGetObject();
              gc.SetCommandPrompt("Select path curve");
              gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve);
              gc.EnableDeselectAllBeforePostSelect(false);
              gc.GetObjects(1, 1);
              if (gc.CommandResult() != IRhinoCommand.result.success)
            return gc.CommandResult();

              // Get the curve
              IOnCurve crv = gc.Object(0).Curve();
              if (null == crv )
            return IRhinoCommand.result.failure;

              // Create an array of normalized curve parameters
              List<double> slist = new List<double>(m_max_steps);
              for (int i = 0; i < m_max_steps; i++ )
              {
            double s = (double)i / ( (double)m_max_steps - 1 );
            slist.Add(s);
              }

              // Get the real parameters along the curve
              double[] tlist = new double[m_max_steps];
              if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist))
            return IRhinoCommand.result.failure;

              // Create the display conduit
              SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit();

              // Get points along curve
              On3dPoint start = new On3dPoint(crv.PointAtStart());
              List<On3dPoint> plist = new List<On3dPoint>(tlist.Length);
              for (int i = 0; i < m_max_steps; i++)
              {
            On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i]));
            plist.Add(pt);
              }

              // Hide objects and add them to conduit's object array
              for (int i = 0; i < go.ObjectCount(); i++ )
              {
            MRhinoObjRef objref = go.Object(i);
            context.m_doc.HideObject(objref);
            conduit.m_objects.Add(objref.Object());
              }

              // Do animation...
              conduit.Enable();

              for (int i = 0; i < m_max_steps; i++)
              {
            On3dVector v = plist[i] - start;
            conduit.m_xform.Translation(v);
            context.m_doc.Redraw();
            Thread.Sleep(100);
              }

              for (int i = m_max_steps - 1; i >= 0; i--)
              {
            On3dVector v = plist[i] - start;
            conduit.m_xform.Translation(v);
            if (0 != i)
            {
              context.m_doc.Redraw();
              Thread.Sleep(100);
            }
              }

              conduit.Disable();

              // Show hidden objects
              for (int i = 0; i < go.ObjectCount(); i++)
              {
            MRhinoObjRef objref = go.Object(i);
            context.m_doc.ShowObject(objref);
              }

              context.m_doc.Redraw();

              return IRhinoCommand.result.success;
        }