コード例 #1
0
        /// <summary> RunCommandPickPlane is a helper method for picking an existing surface to draw on </summary>
        /// <param name="mRhinoDoc"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        protected Result RunCommandPickPlane(RhinoDoc mRhinoDoc, RunMode mode)
        {
            //routine for picking an existing surface to draw on

            //please select a plane

            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select surface", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Surface refSrf = objref.Surface();
            refSrf.FrameAt(.5, .5, out plane1);

            Point3d  pOrigin = refSrf.PointAt(1, 1);
            Point3d  pY      = refSrf.PointAt(0.5, 1);
            Point3d  pX      = refSrf.PointAt(1, 0.75);
            Vector3d vX      = Rhino.Geometry.Point3d.Subtract(pX, pOrigin);
            Vector3d vY      = Rhino.Geometry.Point3d.Subtract(pY, pOrigin);

            plane1 = new Plane(pOrigin, vX, vY);

            Rhino.DocObjects.RhinoObject rhobj = objref.Object();
            rhobj.Select(false);

            mRhinoDoc.Objects.AddPoint(pOrigin);
            mRhinoDoc.Objects.AddPoint(pX);
            mRhinoDoc.Objects.AddPoint(pY);
            mRhinoDoc.Views.Redraw();

            return(Result.Success);
        }
コード例 #2
0
 static Rhino.DocObjects.ObjectType SpaceMorphObjectFilter()
 {
     Rhino.DocObjects.ObjectType filter =
         Rhino.DocObjects.ObjectType.Point |
         Rhino.DocObjects.ObjectType.PointSet |
         Rhino.DocObjects.ObjectType.Curve |
         Rhino.DocObjects.ObjectType.Surface |
         Rhino.DocObjects.ObjectType.PolysrfFilter |
         Rhino.DocObjects.ObjectType.Mesh |
         Rhino.DocObjects.ObjectType.Grip |
         Rhino.DocObjects.ObjectType.Cage;
     return(filter);
 }
コード例 #3
0
        public static GeometryLarge CreateGeometry(MaterialType mType, string mName)

        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;

            //Allow user to pick multiple objects
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Curve;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()
            {
                GeometryFilter              = geometryFilter,
                GroupSelect                 = true,
                SubObjectSelect             = false,
                DeselectAllBeforePostSelect = false
            };
            go.SetCommandPrompt("Pick one or two closed curves.");
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);

            bool bHavePreselectedObjects = false;

            for (;;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }
                break;
            }

            //Unselects the preselected objects
            if (bHavePreselectedObjects)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }

                doc.Views.Redraw();
            }

            ObjRef[]     objs           = go.Objects();
            List <Curve> selectedCurves = new List <Curve>();

            foreach (ObjRef objRef in objs)
            {
                if (objRef.Curve() == null)
                {
                    RhinoApp.WriteLine("One of the selected objects was invalid.");
                    continue;
                }
                else if (!objRef.Curve().IsClosed)
                {
                    RhinoApp.WriteLine("One of the selected curves was not closed.");
                    continue;
                }
                selectedCurves.Add(objRef.Curve());
            }

            GeometryLarge larg;

            //if the curve is not closed do nothing
            switch (selectedCurves.Count)
            {
            case 0:
                Rhino.RhinoApp.WriteLine("No valid geometries was found.");
                return(null);

            case 1:
                larg = DrawAndSaveUserAttr(Brep.CreatePlanarBreps(selectedCurves)[0], doc, mType, mName);
                break;

            case 2:
                Brep brep1 = Brep.CreatePlanarBreps(new[] { selectedCurves[0] })[0];
                Brep brep2 = Brep.CreatePlanarBreps(new[] { selectedCurves[1] })[0];

                double area      = Brep.CreateBooleanUnion(new[] { brep1, brep2 }, 0.001)[0].GetArea();
                double brep1Area = brep1.GetArea();
                double brep2Area = brep2.GetArea();
                if (area > 0.999 * brep1Area && area < 1.001 * brep1Area)
                {
                    Brep brep = Brep.CreateBooleanDifference(brep1, brep2, doc.ModelAbsoluteTolerance)[0];
                    larg = DrawAndSaveUserAttr(brep, doc, mType, mName);
                    break;
                }

                else if (area > 0.999 * brep2Area && area < 1.001 * brep2Area)
                {
                    Brep brep = Brep.CreateBooleanDifference(brep1, brep2, doc.ModelAbsoluteTolerance)[0];
                    larg = DrawAndSaveUserAttr(brep, doc, mType, mName);
                    break;
                }
                else
                {
                    RhinoApp.WriteLine("The curves were not inside one another.");
                    return(null);
                }

            default:
                return(null);
            }

            foreach (ObjRef objRef in objs)
            {
                doc.Objects.Delete(objRef, false);
            }
            return(larg);
        }
コード例 #4
0
        //Creates reinforcement objects and saves them into the selected point as userData
        public static Reinforcement[] CreateReinforcements(string mName, double diam)
        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;

            //Allow user to pick multiple objects
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()
            {
                GeometryFilter              = geometryFilter,
                GroupSelect                 = true,
                SubObjectSelect             = false,
                DeselectAllBeforePostSelect = false
            };
            go.SetCommandPrompt("Pick all the points that you want to change to reinforcement.");
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);

            bool bHavePreselectedObjects = false;

            for (;;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }
                break;
            }

            //Unselects the preselected objects
            if (bHavePreselectedObjects)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }

                doc.Views.Redraw();
            }


            int layerIndex = GetOrCreateLayer(doc, "Reinforcement", Color.Black);

            if (layerIndex == 999)
            {
                return new Reinforcement[] {}
            }
            ;


            Reinforcement[] reinfList = { };
            //Create reinforcement objects for each selected points
            ObjRef[] objects = go.Objects();
            if (objects != null)
            {
                reinfList = CreateReinfObjs(doc, objects, layerIndex, mName, diam);
            }



            return(reinfList);
        }
コード例 #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Pick all the points that you want to change to reinforcement.");
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

            for (;;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);

                /*
                 * if (res == Rhino.Input.GetResult.Option)
                 * {
                 *  go.EnablePreSelect(false, true);
                 *  continue;
                 * }
                 * else if (res != Rhino.Input.GetResult.Option)
                 * {
                 *  return Rhino.Commands.Result.Cancel;
                 * }
                 */
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }
                break;
            }

            List <Point3d> points = new List <Point3d>();

            if (bHavePreselectedObjects)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                doc.Views.Redraw();
            }

            int layerIndex = getLayerIndex(doc, "Reinforcement");

            doc.Layers[layerIndex].Color = Color.Black;
            if (layerIndex == 999)
            {
                return(Result.Failure);
            }

            ObjRef[] objects = go.Objects();
            foreach (ObjRef obj in objects)
            {
                Point3d point = obj.Point().Location;

                //TODO add the functionality how to assign different steel materials.
                Reinforcement reinf = new Reinforcement(ProjectPlugIn.Instance.CurrentBeam)
                {
                    Material = new SteelMaterial("B500B", SteelType.Reinforcement, ProjectPlugIn.Instance.CurrentBeam),
                    Centroid = point,
                    Diameter = 8
                };



                ObjectAttributes attr = new ObjectAttributes();
                attr.UserData.Add(reinf);
                attr.SetUserString("Name", "Reinforcement");
                attr.LayerIndex = layerIndex;

                //Unused code to create a hatch around the point

                /*
                 * doc.Objects.AddCurve(reinf.OutLine,attr);
                 * ObjectAttributes attrHatch = new ObjectAttributes();
                 * attrHatch.LayerIndex = layerIndex;
                 * doc.Objects.AddHatch(reinf.Hatch, attrHatch);
                 */


                doc.Objects.ModifyAttributes(obj, attr, true);
            }



            return(Result.Success);
        }
コード例 #6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;

            Rhino.DocObjects.ObjRef objref;
            Result rc = Rhino.Input.RhinoGet.GetOneObject("Select first/main polysurface or surface to bool",
                                                          false, geometryFilter, out objref);

            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }
            if (objref == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.Brep brep = objref.Brep();
            bool resIssolid          = brep.IsSolid;

            if (!resIssolid)
            {
                Dialogs.ShowMessage("Your polysurface or surface is not solid! Result might not be valid!", "Warning!");
            }
            Guid firstBrep = objref.ObjectId;

            doc.Objects.UnselectAll(true);


            //Select rest of polysurfaces or surfaces to bool
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select rest of polysurfaces or surfaces to bool");
            go.GeometryFilter = geometryFilter | Rhino.DocObjects.ObjectType.InstanceReference;
            go.GroupSelect    = true;
            go.GetMultiple(1, 0);

            bool isSolid = true;

            //Add set to breps list
            List <Rhino.Geometry.Brep> breps = new List <Rhino.Geometry.Brep>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                //Explode if instance object and add to breps list
                if (go.Object(i).Object() is InstanceObject)
                {
                    InstanceObject     instObj = go.Object(i).Object() as InstanceObject;
                    RhinoObject[]      explodedObjects;
                    ObjectAttributes[] attributesOfExplodedObjects;
                    Transform[]        transformOfExplodedObjects;

                    instObj.Explode(false, out explodedObjects, out attributesOfExplodedObjects, out transformOfExplodedObjects);
                    Guid addedObjectID = doc.Objects.Add(explodedObjects[0].Geometry, explodedObjects[0].Attributes);

                    ObjRef objrefs            = new Rhino.DocObjects.ObjRef(addedObjectID);
                    Rhino.Geometry.Brep brepd = objrefs.Brep();

                    brepd.Transform(transformOfExplodedObjects[0]);

                    resIssolid = brepd.IsSolid;
                    if (!resIssolid)
                    {
                        isSolid = false;
                    }
                    if (brepd != null && firstBrep != addedObjectID)
                    {
                        breps.Add(brepd);
                    }
                    doc.Objects.Delete(addedObjectID, true);
                }
                else
                {
                    Rhino.DocObjects.ObjRef objrefs = go.Object(i);
                    Rhino.Geometry.Brep     brepd   = objrefs.Brep();
                    resIssolid = brepd.IsSolid;
                    if (!resIssolid)
                    {
                        isSolid = false;
                    }
                    if (brepd != null && firstBrep != objrefs.ObjectId)
                    {
                        breps.Add(brepd);
                    }
                }
            }
            if (!isSolid)
            {
                Dialogs.ShowMessage("At least on polysurface or surface to subtract is not solid! Result might not be valid!", "Warning!");
            }

            doc.Objects.UnselectAll(true);

            //Create layers for failed and successfull booleans if not already existing
            var fail_layer_index = doc.Layers.FindName("FJ Boolean Fails");

            if (fail_layer_index == null)
            {
                string name_fail_layer          = "FJ Boolean Fails";
                Rhino.DocObjects.Layer boolFail = new Rhino.DocObjects.Layer();
                boolFail.Name  = name_fail_layer;
                boolFail.Color = System.Drawing.Color.Red;
                doc.Layers.Add(boolFail);
                fail_layer_index = doc.Layers.FindName(name_fail_layer);
            }

            var done_layer_index = doc.Layers.FindName("FJ Boolean Done");

            if (done_layer_index == null)
            {
                string name_done_layer          = "FJ Boolean Done";
                Rhino.DocObjects.Layer boolDone = new Rhino.DocObjects.Layer();
                boolDone.Name  = name_done_layer;
                boolDone.Color = System.Drawing.Color.BlueViolet;
                doc.Layers.Add(boolDone);
                done_layer_index = doc.Layers.FindName(name_done_layer);
            }

            //Compute boolean union
            double tolerance = doc.ModelAbsoluteTolerance;
            int    a         = 0;

            for (int i = 0; i < breps.Count; i++)
            {
                RhinoApp.WriteLine("computing number: " + i + " of: " + breps.Count + " operations...");

                List <Brep> brepBool = new List <Brep>();
                brepBool.Add(brep);
                brepBool.Add(breps[i]);
                Rhino.Geometry.Brep[] brepBoolNew = Rhino.Geometry.Brep.CreateBooleanUnion(brepBool, tolerance, true);

                if (brepBoolNew == null || brepBoolNew.Length > 1)
                {
                    a++;
                    doc.Objects.Delete(go.Object(i).Object());

                    var    boolresultfail = doc.Objects.AddBrep(breps[i]);
                    ObjRef objFailref     = new ObjRef(boolresultfail);
                    Rhino.DocObjects.RhinoObject objFail = objFailref.Object();
                    objFail.Attributes.LayerIndex = fail_layer_index.Index;
                    objFail.CommitChanges();
                }
                else
                {
                    brep = brepBoolNew[0];
                    doc.Objects.Delete(go.Object(i).Object());

                    var    boolresult = doc.Objects.AddBrep(breps[i]);
                    ObjRef obj20ref   = new ObjRef(boolresult);
                    Rhino.DocObjects.RhinoObject obj2Org = obj20ref.Object();
                    obj2Org.Attributes.LayerIndex = done_layer_index.Index;
                    obj2Org.CommitChanges();
                }

                doc.Views.Redraw();
            }

            RhinoApp.WriteLine(a + " of " + breps.Count + " operations failed!");

            Rhino.DocObjects.RhinoObject obj1Org = objref.Object();
            doc.Objects.Delete(obj1Org);

            doc.Objects.AddBrep(brep);

            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }