Example #1
0
        public Rhino.Commands.Result GetPoints(Rhino.RhinoDoc doc)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();
            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select point");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Point   pt     = go.Object(0).Point();
            Rhino.Geometry.Point3d pointA = pt.Location;

            go.SetCommandPrompt("Select surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Surface surfaceB = go.Object(0).Surface();
            double u, v;

            if (surfaceB.ClosestPoint(pointA, out u, out v))
            {
                Rhino.Geometry.Point3d pointC = surfaceB.PointAt(u, v);

                Rhino.Geometry.Vector3d vector = pointA - pointC;
                // write list pointD
            }

            return(Rhino.Commands.Result.Success);
        }
  public static Rhino.Commands.Result CircleCenter(Rhino.RhinoDoc doc)
  {
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select objects");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
    go.GetMultiple(1, 0);
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();

    Rhino.DocObjects.ObjRef[] objrefs = go.Objects();
    if( objrefs==null )
      return Rhino.Commands.Result.Nothing;

    double tolerance = doc.ModelAbsoluteTolerance;
    for( int i=0; i<objrefs.Length; i++ )
    {
      // get the curve geometry
      Rhino.Geometry.Curve curve = objrefs[i].Curve();
      if( curve==null )
        continue;
      Rhino.Geometry.Circle circle;
      if( curve.TryGetCircle(out circle, tolerance) )
      {
        Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i+1, circle.Center);
      }
    }
    return Rhino.Commands.Result.Success;
  }
Example #3
0
    public static Rhino.Commands.Result AddObjectsToGroup(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to group");
        go.GroupSelect = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        List <Guid> ids = new List <Guid>();

        for (int i = 0; i < go.ObjectCount; i++)
        {
            ids.Add(go.Object(i).ObjectId);
        }
        int index = doc.Groups.Add(ids);

        doc.Views.Redraw();
        if (index >= 0)
        {
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var go = new Rhino.Input.Custom.GetObject();
      go.SetCommandPrompt("Select objects to copy in place");
      go.GroupSelect = true;
      go.SubObjectSelect = false;
      go.GetMultiple(1, 0);
      if (go.CommandResult() != Result.Success)
        return go.CommandResult();

      var xform = Transform.Identity;
      var group_map = new Dictionary<int, int>();

      foreach (var obj_ref in go.Objects())
      {
        if (obj_ref != null)
        {
          var obj = obj_ref.Object();
          var duplicate = doc.Objects.Transform(obj_ref.ObjectId, xform, false);
          RhinoUpdateObjectGroups(ref obj, ref group_map);
        } 
      }
      doc.Views.Redraw();
      return Result.Success;
    }
Example #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select block to explode");
            go.GeometryFilter = ObjectType.InstanceReference;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            var iref = go.Object(0).Object() as Rhino.DocObjects.InstanceObject;

            if (null == iref)
            {
                return(Result.Failure);
            }

            var  xform = Transform.Identity;
            bool rc    = ExplodeBlockHelper(doc, iref, xform);

            if (rc)
            {
                doc.Objects.Delete(go.Object(0), false);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Example #6
0
    public static Result CopyGroups(RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select objects to copy in place");
        go.GroupSelect     = true;
        go.SubObjectSelect = false;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Result.Success)
        {
            return(go.CommandResult());
        }

        var xform     = Transform.Identity;
        var group_map = new Dictionary <int, int>();

        foreach (var obj_ref in go.Objects())
        {
            if (obj_ref != null)
            {
                var obj       = obj_ref.Object();
                var duplicate = doc.Objects.Transform(obj_ref.ObjectId, xform, false);
                RhinoUpdateObjectGroups(ref obj, ref group_map);
            }
        }
        doc.Views.Redraw();
        return(Result.Success);
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var go = new Rhino.Input.Custom.GetObject();
      go.SetCommandPrompt("Select objects");
      go.EnablePreSelect(true, true);
      go.EnablePostSelect(true);
      go.GetMultiple(0, 0);
      if (go.CommandResult() != Result.Success)
        return go.CommandResult();

      var selected_objects = go.Objects().ToList();

      if (go.ObjectsWerePreselected)
      {
        go.EnablePreSelect(false, true);
        go.DeselectAllBeforePostSelect = false;
        go.EnableUnselectObjectsOnExit(false);
        go.GetMultiple(0, 0);
        if (go.CommandResult() == Result.Success)
        {
          foreach (var obj in go.Objects())
          {
            selected_objects.Add(obj);
            // The normal behavior of commands is that when they finish,
            // objects that were pre-selected remain selected and objects
            // that were post-selected will not be selected. Because we
            // potentially could have both, we'll try to do something
            // consistent and make sure post-selected objects also stay selected
            obj.Object().Select(true);
          }
        }
      }
      return selected_objects.Count > 0 ? Result.Success : Result.Nothing;
    }
Example #8
0
    public static Rhino.Commands.Result TweenCurve(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.Geometry.Curve curve0 = go.Object(0).Curve();
        Rhino.Geometry.Curve curve1 = go.Object(1).Curve();
        if (null != curve0 && null != curve1)
        {
            Rhino.Geometry.Curve[] curves = Rhino.Geometry.Curve.CreateTweenCurves(curve0, curve1, 1);
            if (null != curves)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    doc.Objects.AddCurve(curves[i]);
                }

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

        return(Rhino.Commands.Result.Failure);
    }
    public static Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef rail_ref;
        var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref);

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

        var rail_crv = rail_ref.Curve();

        if (rail_crv == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        var gx = new Rhino.Input.Custom.GetObject();

        gx.SetCommandPrompt("Select cross section curves");
        gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        gx.EnablePreSelect(false, true);
        gx.GetMultiple(1, 0);
        if (gx.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gx.CommandResult());
        }

        var cross_sections = new List <Rhino.Geometry.Curve>();

        for (int i = 0; i < gx.ObjectCount; i++)
        {
            var crv = gx.Object(i).Curve();
            if (crv != null)
            {
                cross_sections.Add(crv);
            }
        }
        if (cross_sections.Count < 1)
        {
            return(Rhino.Commands.Result.Failure);
        }

        var sweep = new Rhino.Geometry.SweepOneRail();

        sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
        sweep.ClosedSweep           = false;
        sweep.SweepTolerance        = doc.ModelAbsoluteTolerance;
        sweep.SetToRoadlikeTop();
        var breps = sweep.PerformSweep(rail_crv, cross_sections);

        for (int i = 0; i < breps.Length; i++)
        {
            doc.Objects.AddBrep(breps[i]);
        }
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Example #10
0
    public static Rhino.Commands.Result ConstrainedCopy(Rhino.RhinoDoc doc)
    {
        // Get a single planar closed curve
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select curve");
        go.GeometryFilter          = Rhino.DocObjects.ObjectType.Curve;
        go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }
        var objref      = go.Object(0);
        var base_curve  = objref.Curve();
        var first_point = objref.SelectionPoint();

        if (base_curve == null || !first_point.IsValid)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        Rhino.Geometry.Plane plane;
        if (!base_curve.TryGetPlane(out plane))
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Get a point constrained to a line passing through the initial selection
        // point and parallel to the plane's normal
        var gp = new Rhino.Input.Custom.GetPoint();

        gp.SetCommandPrompt("Offset point");
        gp.DrawLineFromPoint(first_point, true);
        var line = new Rhino.Geometry.Line(first_point, first_point + plane.Normal);

        gp.Constrain(line);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }
        var second_point = gp.Point();

        Rhino.Geometry.Vector3d vec = second_point - first_point;
        if (vec.Length > 0.001)
        {
            var  xf = Rhino.Geometry.Transform.Translation(vec);
            Guid id = doc.Objects.Transform(objref, xf, false);
            if (id != Guid.Empty)
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }
        return(Rhino.Commands.Result.Cancel);
    }
Example #11
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to define block
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select surface or polysurface to box morph");
            go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep;
            go.SubObjectSelect = false;
            go.Get();
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.BoundingBox bbox = brep.GetBoundingBox(true);

            // The original box points
            Rhino.Geometry.Point3d[] box = new Rhino.Geometry.Point3d[8];
            box[0] = bbox.Corner(true, true, true);
            box[1] = bbox.Corner(false, true, true);
            box[2] = bbox.Corner(false, false, true);
            box[3] = bbox.Corner(true, false, true);
            box[4] = bbox.Corner(true, true, false);
            box[5] = bbox.Corner(false, true, false);
            box[6] = bbox.Corner(false, false, false);
            box[7] = bbox.Corner(true, false, false);

            // The modified box points
            Rhino.Geometry.Point3d[] corners = new Rhino.Geometry.Point3d[8];
            corners[0] = box[0];
            corners[1] = box[1];
            corners[2] = box[2];
            corners[3] = box[3];
            corners[4] = box[4];
            corners[5] = box[5];
            corners[6] = box[6] * 2; // some goofy point
            corners[7] = box[7];

            BoxMorph box_morph = new BoxMorph(box, corners);

            if (box_morph.IsValid() && !box_morph.IsIdentity())
            {
                if (box_morph.Morph(brep))
                {
                    doc.Objects.Add(brep);
                    doc.Views.Redraw();
                }
            }

            return(Result.Success);
        }
    public static Rhino.Commands.Result HatchCurve(Rhino.RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select closed planar curve");
        go.GeometryFilter          = Rhino.DocObjects.ObjectType.Curve;
        go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
        go.SubObjectSelect         = false;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

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

        if (curve == null || !curve.IsClosed || !curve.IsPlanar())
        {
            return(Rhino.Commands.Result.Failure);
        }

        string hatch_name = doc.HatchPatterns[doc.HatchPatterns.CurrentHatchPatternIndex].Name;
        var    rc         = Rhino.Input.RhinoGet.GetString("Hatch pattern", true, ref hatch_name);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        hatch_name = hatch_name.Trim();
        if (string.IsNullOrWhiteSpace(hatch_name))
        {
            return(Rhino.Commands.Result.Nothing);
        }
        int index = doc.HatchPatterns.Find(hatch_name, true);

        if (index < 0)
        {
            Rhino.RhinoApp.WriteLine("Hatch pattern does not exist.");
            return(Rhino.Commands.Result.Nothing);
        }

        var hatches = Rhino.Geometry.Hatch.Create(curve, index, 0, 1);

        for (int i = 0; i < hatches.Length; i++)
        {
            doc.Objects.AddHatch(hatches[i]);
        }
        if (hatches.Length > 0)
        {
            doc.Views.Redraw();
        }
        return(Rhino.Commands.Result.Success);
    }
Example #13
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();
            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select points");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            Rhino.Input.GetResult res = go.GetMultiple(1, 0);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            RhinoApp.WriteLine("Points {0} were selected", go.ObjectCount);

            try
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.FileName = "PointFile.xyz";
                dialog.Filter   = "XYZ file|*.xyz|text file|*.txt";
                dialog.Title    = "Save point cloud file";
                dialog.ShowDialog();

                if (dialog.FileName == "")
                {
                    return(Rhino.Commands.Result.Failure);
                }

                FileStream   fileStream = (System.IO.FileStream)dialog.OpenFile(); //  new FileStream(@"C:\Users\KTW\Documents\PointFile.xyz", FileMode.Create, FileAccess.Write);
                StreamWriter writer     = new StreamWriter(fileStream);

                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Rhino.Geometry.Point   pt   = go.Object(i).Point();
                    Rhino.Geometry.Point3d pt3d = pt.Location;

                    string text = pt3d.X + " " + pt3d.Y + " " + pt3d.Z;
                    writer.WriteLine(text);
                }

                RhinoApp.WriteLine("File was saved");
                fileStream.Close();
            }
            catch (Exception e)
            {
                RhinoApp.WriteLine("{0}", e.Message);
            }

            return(Rhino.Commands.Result.Success);
        }
    public static Rhino.Commands.Result IntersectLines(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select lines");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }
        if (go.ObjectCount != 2)
        {
            return(Rhino.Commands.Result.Failure);
        }

        LineCurve crv0 = go.Object(0).Geometry() as LineCurve;
        LineCurve crv1 = go.Object(1).Geometry() as LineCurve;

        if (crv0 == null || crv1 == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Line     line0 = crv0.Line;
        Line     line1 = crv1.Line;
        Vector3d v0    = line0.Direction;

        v0.Unitize();
        Vector3d v1 = line1.Direction;

        v1.Unitize();

        if (v0.IsParallelTo(v1) != 0)
        {
            Rhino.RhinoApp.WriteLine("Selected lines are parallel.");
            return(Rhino.Commands.Result.Nothing);
        }

        double a, b;

        if (!Rhino.Geometry.Intersect.Intersection.LineLine(line0, line1, out a, out b))
        {
            Rhino.RhinoApp.WriteLine("No intersection found.");
            return(Rhino.Commands.Result.Nothing);
        }

        Point3d pt0 = line0.PointAt(a);

        doc.Objects.AddPoint(pt0);
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            Mesh meshObj;
            Point3d pointObj = new Point3d(0.0,0.0,0.0);

            RhinoApp.WriteLine("dikka dikka dikka...");

            Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
            gp.SetCommandPrompt("Start of ray");
            gp.Get();
            if (gp.CommandResult() != Rhino.Commands.Result.Success)
                return gp.CommandResult();

            pointObj = gp.Point();
            doc.Objects.AddPoint(pointObj);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select the mesh to print");
            go.Get();
            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("sdfafadsfda");
                return rc;
            }

            RhinoApp.WriteLine("2 2 dikka dikka dikka...");

            meshObj = new Mesh();
            if (go.ObjectCount == 1)
            {
                ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId);
                meshObj = tmpRef.Mesh();
                if (meshObj == null)
                {
                    return rc;
                }
            }

            Ray3d rayObj = new Ray3d(pointObj, new Vector3d(1.0, 1.0, 1.0));
            doc.Objects.AddPoint(rayObj.PointAt(1.0));
            doc.Objects.AddPoint(rayObj.PointAt(2.0));
            doc.Objects.AddPoint(rayObj.PointAt(3.0));

            double p  = Intersection.MeshRay(meshObj, rayObj);
            string a = string.Format("mesh ray gives {0:0.00}",p);
            doc.Objects.AddPoint(rayObj.PointAt(p));
            RhinoApp.WriteLine(a);
            return Rhino.Commands.Result.Success;
        }
Example #16
0
    public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Source curve");
        go0.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go0.SubObjectSelect = false;
        go0.EnablePreSelect(false, true);
        go0.DeselectAllBeforePostSelect = false;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go0.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0);

        Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject();
        go1.SetCommandPrompt("Source curve");
        go1.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go1.SubObjectSelect = false;
        go1.EnablePreSelect(false, true);
        go1.DeselectAllBeforePostSelect = false;
        go1.Get();
        if (go1.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go1.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0);

        Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Example #17
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            RhinoApp.WriteLine("The {0} command is under construction.", EnglishName);

            Rhino.Input.Custom.GetObject gmesh = new Rhino.Input.Custom.GetObject();
            gmesh.SetCommandPrompt("Get the Mesh");
            gmesh.GeometryFilter  = Rhino.DocObjects.ObjectType.Mesh;
            gmesh.SubObjectSelect = true;
            gmesh.Get();
            if (gmesh.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gmesh.CommandResult());
            }
            Rhino.DocObjects.ObjRef      objref = gmesh.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Rhino.Geometry.Mesh mesh = objref.Mesh();
            if (mesh == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            obj.Select(false);

            MeshTextureCoordinateList texture_list = mesh.TextureCoordinates;

            for (int i = 0; i < texture_list.Count - 1; i++)
            {
                Point2f f1 = texture_list[i];
                Point2f f2 = texture_list[i + 1];
                Point3d t1 = new Point3d(f1.X, f1.Y, 0);
                Point3d t2 = new Point3d(f2.X, f2.Y, 0);
                Line    l  = new Line(t1, t2);
                doc.Objects.AddLine(l);
                RhinoApp.WriteLine("Line added");
            }
            doc.Views.Redraw();
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            p.painted_object_        = mesh;
            p.if_painted_object_set_ = true;
            mesh.UserDictionary.Set("name", "myMesh");
            mesh.UserDictionary.Set("isMovable", false);
            p.graph = new DijkstraGraph(10);
            RhinoApp.WriteLine("Mesh Got");
            return(Result.Success);
        }
Example #18
0
        public Rhino.Commands.Result delete(Rhino.RhinoDoc doc)
        {
            // Input incomplate
            double _incomplate = 0.1;

            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input incomplate(0.0 ~ 1.0)<0.1>");
            Rhino.Input.GetResult res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _incomplate = input.Number();
            }
            if (_incomplate == 0.0)
            {
                _incomplate = 0.1;
            }

            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select elements");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            res = go.GetMultiple(1, 1024 * 10);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            System.Collections.Generic.List <Guid> list = new System.Collections.Generic.List <Guid>();
            for (int i = 0; i < go.ObjectCount; i++)
            {
                Guid guid = go.Object(i).ObjectId;
                list.Add(guid);
            }

            int deleteCount = (int)((double)(list.Count) * _incomplate);

            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
            for (int i = 0; i < deleteCount; i++)
            {
                Guid guid = list[i];
                ot.Delete(guid, true);
            }

            return(Rhino.Commands.Result.Success);
        }
    public static Rhino.Commands.Result ExtrudeBrepFace(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Select surface to extrude");
        go0.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface;
        go0.SubObjectSelect = true;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go0.CommandResult());
        }

        Rhino.Geometry.BrepFace face = go0.Object(0).Face();
        if (null == face)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject();
        go1.SetCommandPrompt("Select path curve");
        go1.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
        go1.SubObjectSelect             = true;
        go1.DeselectAllBeforePostSelect = false;
        go1.Get();
        if (go1.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go1.CommandResult());
        }

        Rhino.Geometry.Curve curve = go1.Object(0).Curve();
        if (null == curve)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Brep brep = face.CreateExtrusion(curve, true);
        if (null != brep)
        {
            doc.Objects.Add(brep);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Example #20
0
    public static Rhino.Commands.Result IntersectCurves(Rhino.RhinoDoc doc)
    {
        // Select two curves to intersect
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Validate input
        var curveA = go.Object(0).Curve();
        var curveB = go.Object(1).Curve();

        if (curveA == null || curveB == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Calculate the intersection
        const double intersection_tolerance = 0.001;
        const double overlap_tolerance      = 0.0;
        var          events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curveA, curveB, intersection_tolerance, overlap_tolerance);

        // Process the results
        if (events != null)
        {
            for (int i = 0; i < events.Count; i++)
            {
                var ccx_event = events[i];
                doc.Objects.AddPoint(ccx_event.PointA);
                if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon)
                {
                    doc.Objects.AddPoint(ccx_event.PointB);
                    doc.Objects.AddLine(ccx_event.PointA, ccx_event.PointB);
                }
            }
            doc.Views.Redraw();
        }
        return(Rhino.Commands.Result.Success);
    }
Example #21
0
    public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Surface to splop on");
        go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface;
        go.SubObjectSelect = false;
        go.EnablePreSelect(false, true);
        go.DeselectAllBeforePostSelect = false;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef srfref = go.Object(0);

        double u, v;

        srfref.SurfaceParameter(out u, out v);

        Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u, v);

        Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv);
        Rhino.Geometry.GeometryBase           geom  = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Example #22
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select surface or polysurface to smash");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;
            go.Get();
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.Unroller unroller = new Rhino.Geometry.Unroller(brep);
            unroller.AbsoluteTolerance = doc.ModelAbsoluteTolerance;
            unroller.RelativeTolerance = 1.0; // big relative tolerance for smash
            unroller.ExplodeSpacing    = 2.0;
            unroller.ExplodeOutput     = true;

            Rhino.Geometry.Curve[]   unrolledCurves = null;
            Rhino.Geometry.Point3d[] unrolledPoints = null;
            Rhino.Geometry.TextDot[] unrolledDots   = null;

            Rhino.Geometry.Brep[] output = unroller.PerformUnroll(out unrolledCurves, out unrolledPoints, out unrolledDots);
            if (null != output)
            {
                for (int i = 0; i < output.Length; i++)
                {
                    doc.Objects.Add(output[i]);
                }
            }

            doc.Views.Redraw();

            return(Rhino.Commands.Result.Success);
        }
    public static Rhino.Commands.Result LineBetweenCurves(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef objRef0 = go.Object(0);
        Rhino.DocObjects.ObjRef objRef1 = go.Object(1);

        double t0 = Rhino.RhinoMath.UnsetValue;
        double t1 = Rhino.RhinoMath.UnsetValue;

        Rhino.Geometry.Curve curve0 = objRef0.CurveParameter(out t0);
        Rhino.Geometry.Curve curve1 = objRef1.CurveParameter(out t1);
        if (null == curve0 || !Rhino.RhinoMath.IsValidDouble(t0) ||
            null == curve1 || !Rhino.RhinoMath.IsValidDouble(t1))
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Line line = Rhino.Geometry.Line.Unset;
        bool rc = Rhino.Geometry.Line.TryCreateBetweenCurves(curve0, curve1, ref t0, ref t1, false, false, out line);

        if (rc)
        {
            if (Guid.Empty != doc.Objects.AddLine(line))
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }
        return(Rhino.Commands.Result.Failure);
    }
  public static Rhino.Commands.Result IntersectCurves(Rhino.RhinoDoc doc)
  {
    // Select two curves to intersect
    var go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select two curves");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GetMultiple(2, 2);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();

    // Validate input
    var curveA = go.Object(0).Curve();
    var curveB = go.Object(1).Curve();
    if (curveA == null || curveB == null)
      return Rhino.Commands.Result.Failure;

    // Calculate the intersection
    const double intersection_tolerance = 0.001;
    const double overlap_tolerance = 0.0;
    var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curveA, curveB, intersection_tolerance, overlap_tolerance);

    // Process the results
    if (events != null)
    {
      for (int i = 0; i < events.Count; i++)
      {
        var ccx_event = events[i];
        doc.Objects.AddPoint(ccx_event.PointA);
        if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon)
        {
          doc.Objects.AddPoint(ccx_event.PointB);
          doc.Objects.AddLine(ccx_event.PointA, ccx_event.PointB);
        }
      }
      doc.Views.Redraw();
    }
    return Rhino.Commands.Result.Success;
  }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select objects");
            go.EnablePreSelect(true, true);
            go.EnablePostSelect(true);
            go.GetMultiple(0, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            var selected_objects = go.Objects().ToList();

            if (go.ObjectsWerePreselected)
            {
                go.EnablePreSelect(false, true);
                go.DeselectAllBeforePostSelect = false;
                go.EnableUnselectObjectsOnExit(false);
                go.GetMultiple(0, 0);
                if (go.CommandResult() == Result.Success)
                {
                    foreach (var obj in go.Objects())
                    {
                        selected_objects.Add(obj);
                        // The normal behavior of commands is that when they finish,
                        // objects that were pre-selected remain selected and objects
                        // that were post-selected will not be selected. Because we
                        // potentially could have both, we'll try to do something
                        // consistent and make sure post-selected objects also stay selected
                        obj.Object().Select(true);
                    }
                }
            }
            return(selected_objects.Count > 0 ? Result.Success : Result.Nothing);
        }
    public static Rhino.Commands.Result CircleCenter(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects");
        go.GeometryFilter          = Rhino.DocObjects.ObjectType.Curve;
        go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef[] objrefs = go.Objects();
        if (objrefs == null)
        {
            return(Rhino.Commands.Result.Nothing);
        }

        double tolerance = doc.ModelAbsoluteTolerance;

        for (int i = 0; i < objrefs.Length; i++)
        {
            // get the curve geometry
            Rhino.Geometry.Curve curve = objrefs[i].Curve();
            if (curve == null)
            {
                continue;
            }
            Rhino.Geometry.Circle circle;
            if (curve.TryGetCircle(out circle, tolerance))
            {
                Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i + 1, circle.Center);
            }
        }
        return(Rhino.Commands.Result.Success);
    }
  public static Rhino.Commands.Result HatchCurve(Rhino.RhinoDoc doc)
  {
    var go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select closed planar curve");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
    go.SubObjectSelect = false;
    go.Get();
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();

    var curve = go.Object(0).Curve();
    if( curve==null || !curve.IsClosed || !curve.IsPlanar() )
      return Rhino.Commands.Result.Failure;

    string hatch_name = doc.HatchPatterns[doc.HatchPatterns.CurrentHatchPatternIndex].Name;
    var rc = Rhino.Input.RhinoGet.GetString("Hatch pattern", true, ref hatch_name);
    if( rc!= Rhino.Commands.Result.Success )
      return rc;
    hatch_name = hatch_name.Trim();
    if( string.IsNullOrWhiteSpace(hatch_name) )
      return Rhino.Commands.Result.Nothing;
    int index = doc.HatchPatterns.Find(hatch_name, true);
    if( index < 0 )
    {
      Rhino.RhinoApp.WriteLine("Hatch pattern does not exist.");
      return Rhino.Commands.Result.Nothing;
    }

    var hatches = Rhino.Geometry.Hatch.Create( curve, index, 0, 1);
    for( int i=0; i<hatches.Length; i++ )
      doc.Objects.AddHatch(hatches[i]);
    if( hatches.Length>0 )
      doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
    public static Rhino.Commands.Result ExtrudeBrepFace(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Select surface to extrude");
        go0.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
        go0.SubObjectSelect = true;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
          return go0.CommandResult();

        Rhino.Geometry.BrepFace face = go0.Object(0).Face();
        if (null == face)
          return Rhino.Commands.Result.Failure;

        Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject();
        go1.SetCommandPrompt("Select path curve");
        go1.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go1.SubObjectSelect = true;
        go1.DeselectAllBeforePostSelect = false;
        go1.Get();
        if (go1.CommandResult() != Rhino.Commands.Result.Success)
          return go1.CommandResult();

        Rhino.Geometry.Curve curve = go1.Object(0).Curve();
        if (null == curve)
          return Rhino.Commands.Result.Failure;

        Rhino.Geometry.Brep brep = face.CreateExtrusion(curve, true);
        if (null != brep)
        {
          doc.Objects.Add(brep);
          doc.Views.Redraw();
        }

        return Rhino.Commands.Result.Success;
    }
 /// <summary>
 /// Select object for which an area value can be calculated
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForArea(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select closed curve, hatch, surface, or mesh", 359));
     go.AcceptNothing(true);
     go.SubObjectSelect = false;
     go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Hatch | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh;
     go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         objref.Dispose();
       }
     }
   }
 }
Example #30
0
 public static Commands.Result GetOneObject(string prompt, bool acceptNothing, Rhino.DocObjects.ObjectType filter, out Rhino.DocObjects.ObjRef rhObject)
 {
   rhObject = null;
   Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
   go.SetCommandPrompt(prompt);
   go.AcceptNothing(acceptNothing);
   go.GeometryFilter = filter;
   go.Get();
   Commands.Result rc = go.CommandResult();
   if (rc == Rhino.Commands.Result.Success && go.ObjectCount > 0)
   {
     rhObject = go.Object(0);
   }
   go.Dispose();
   return rc;
 }
Example #31
0
        private void RunScript(object x, object y, ref object A)
        {
            try
            {
                if (sign)
                {
                    sign = false;
                    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
                    go.Get();
                    Rhino.DocObjects.ObjRef or = go.Object(0);
                    ID = or.ObjectId;

                    Rhino.DocObjects.RhinoObject obj = RhinoDoc.ActiveDoc.Objects.Find(ID);
                    TextObject T = (TextObject)obj;
                    TextEntity t = T.TextGeometry;
                    m_tags = new Rhino.Display.Text3d(t.Text, t.Plane, t.TextHeight + 1);
                }
            }
            catch (Exception ex) { Print(ex.ToString()); }
        }
Example #32
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);
        }
Example #33
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select sphere");
            go.GeometryFilter          = Rhino.DocObjects.ObjectType.Surface;
            go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedSurface;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep || 1 != brep.Faces.Count)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Surface srf = brep.Faces[0].UnderlyingSurface();
            if (null == srf)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Sphere sphere;
            if (!srf.TryGetSphere(out sphere))
            {
                RhinoApp.WriteLine("Surface is not a sphere");
                return(Result.Nothing);
            }

            Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
            gn.SetCommandPrompt("New radius");
            gn.SetDefaultNumber(sphere.Radius);
            gn.SetLowerLimit(1.0, false); // or whatever you deem appripriate...
            gn.Get();
            if (gn.CommandResult() != Result.Success)
            {
                return(gn.CommandResult());
            }

            sphere.Radius = gn.Number();

            // Sometimes, Surface.TryGetSphere() will return a sphere with a left-handed
            // plane. So, ensure the plane is right-handed.
            Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(
                sphere.EquitorialPlane.Origin,
                sphere.EquitorialPlane.XAxis,
                sphere.EquitorialPlane.YAxis
                );

            sphere.EquitorialPlane = plane;

            Rhino.Geometry.RevSurface rev_srf = sphere.ToRevSurface();
            if (null != rev_srf)
            {
                doc.Objects.Replace(go.Object(0).ObjectId, rev_srf);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Example #34
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            nishanchiPlugin pluginObj = ((nishanchiPlugin)this.PlugIn);

            Boolean selectedObjectIsBrep = false;
            Boolean selectedObjectIsCurve = false;

            if (!pluginObj.trackerConnected)
            {
                RhinoApp.WriteLine("Tracker disconnected");
                return Rhino.Commands.Result.Failure;
            }
            connectKbEvt();

            //Ask the user to select Breps to print.
            //Result rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select the surfaces to print",
            //false, Rhino.DocObjects.ObjectType.Surface, out objrefs);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select the entity to print");
            go.GroupSelect = true;

            //Set this to go.GetMultiple(0,0) if you want to allow multiple entities to be selected
            go.GetMultiple(0, 1);

            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                disconnectKbEvt();
                return rc;
            }

            List<Rhino.Geometry.Brep> breps = new List<Rhino.Geometry.Brep>();
            List<Rhino.Geometry.Curve> curves = new List<Rhino.Geometry.Curve>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                ObjRef tmpRef = new ObjRef(go.Object(i).ObjectId);
                Rhino.Geometry.Brep brep = tmpRef.Brep();
                if (brep != null)
                {
                    breps.Add(brep);
                    selectedObjectIsBrep = true;
                }

                Rhino.Geometry.Curve curve = tmpRef.Curve();
                if (curve != null)
                {
                    curves.Add(curve);
                    selectedObjectIsCurve = true;
                }

            }
            if (selectedObjectIsBrep)
                RhinoApp.WriteLine("Selected " + breps.Count + " surfaces! Good! No, not, really, I'm just a program, I couldn't care less.");

            if (selectedObjectIsCurve)
                RhinoApp.WriteLine("Selected " + curves.Count + " curves! Good! No, not, really, I'm just a program, I couldn't care less.");

            createEntities(doc);

            fastrak trackerObj = pluginObj.trackerObj;
            int numPoints = 0;
            int numIntersections = 0;
            Boolean retval;

            RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker."));
            pluginObj.trackerObj.setContinuous();
            RhinoApp.WriteLine(string.Format("Printing mode enabled now."));

            Curve[] intersectionCurves;
            Point3d[] intersectionPoints;

            running = true;
            while (running)
            {
                retval = trackerObj.readFrame();
                if (retval)
                {
                    //q0,q1,q2,q3 Quaternion begin
                    //Compute the rotation matrix
                    rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z);
                    orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);
                    orientationQuat.GetRotation(out angle, out axis);
                    rotMat = Transform.Rotation(angle, axis, origin);

                    // Compute the new positions for the nozzlePoints and also compute the new lines
                    for (int i = 0; i < numNozzles; i++)
                    {
                        nozzleStartPointRxTx[i] = rotMat * nozzleStartPointRxRx[i];
                        nozzleStartPointTxTx[i] = nozzleStartPointRxTx[i] + rxTxTx;

                        nozzleEndPointRxTx[i] = rotMat * nozzleEndPointRxRx[i];
                        nozzleEndPointTxTx[i] = nozzleEndPointRxTx[i] + rxTxTx;

                        nozzleLinesTx[i] = new Line(nozzleStartPointTxTx[i], nozzleEndPointTxTx[i]);
                        nozzleCurves[i] = new LineCurve(nozzleLinesTx[i]);
                    }

                    numIntersections = 0;
                    if (selectedObjectIsBrep)
                    {
                        for (int i = 0; i < numNozzles; i++)
                        {
                            foreach (Brep b in breps)
                            {
                                try
                                {
                                    Intersection.CurveBrep(nozzleCurves[i], b, nozzleTolerance, out intersectionCurves, out intersectionPoints);
                                    if (intersectionPoints.Length > 0)
                                    {
                                        intersectionsBits[i] = 1;
                                        numIntersections++;
                                    }
                                    else
                                    {
                                        intersectionsBits[i] = 0;
                                    }
                                }
                                catch (Exception e)
                                {
                                    RhinoApp.WriteLine(e.Message);
                                }
                            }
                        }
                    }

                    if (selectedObjectIsCurve)
                    {
                        for (int i = 0; i < numNozzles; i++)
                        {
                            foreach (Curve c in curves)
                            {
                                try
                                {
                                    var events = Intersection.CurveCurve(nozzleCurves[i], c, nozzleTolerance, nozzleTolerance);
                                    if (events != null)
                                    {
                                        if (events.Count >= 1)
                                        {
                                            intersectionsBits[i] = 1;
                                            numIntersections++;
                                        }
                                        else
                                        {
                                            intersectionsBits[i] = 0;
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    RhinoApp.WriteLine(e.Message);
                                }
                            }
                        }
                    }

                    if (pluginObj.printHeadConnected)
                    {
                        // I print
                        if (((numPoints % 5) == 0)&&(numIntersections > 0))
                        {
                            string p = printCommand();
                            //RhinoApp.WriteLine(p);
                            pluginObj.printHeadObj.printFrame(p);
                            //pluginObj.printHeadObj.printFullLine();
                        }
                    }

                    numPoints++;
                }

                //And, I move the printer like thing on the screen
                if ((numPoints % 10) == 0)
                {
                    for (int i = 0; i < numNozzles; i++)
                    {
                        doc.Objects.Delete(lineGuids[i],false);
                        lineGuids[i] = doc.Objects.AddLine(nozzleLinesTx[i]);
                    }
                    doc.Objects.Delete(ballGuid, false);
                    ball = new Sphere(rxTxTx, ballRadius);
                    ballGuid = doc.Objects.AddSphere(ball);

                    doc.Views.ActiveView.Redraw();
                    RhinoApp.Wait();
                }
            }

            running = false;
            removeEntities(doc);

            RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker."));
            pluginObj.trackerObj.stopContinuous();
            disconnectKbEvt();
            RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!"));
            return Rhino.Commands.Result.Success;
        }
Example #35
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef[] objRefsA;
            // RhinoApp.WriteLine("Hi there!!");
            var rc = RhinoGet.GetMultipleObjects("Select set of curves to Boolean (A)", false, ObjectType.Curve, out objRefsA);

            if (rc != Result.Success)
            {
                return(rc);
            }

            var getB = new Rhino.Input.Custom.GetObject();

            getB.AcceptNothing(false);
            getB.GeometryFilter = ObjectType.Curve;
            getB.SetCommandPrompt("Select second set of curves to Boolean (B)");
            getB.DisablePreSelect(); //<-- disable pre-selection on second get object
            var result = getB.GetMultiple(1, 0);

            if (result != GetResult.Object)
            {
                return(rc);
            }

            // Convert curves to polylines. Perhaps this should have more control?
            var curvesA = Polyline3D.ConvertCurvesToPolyline(objRefsA.Select(r => r.Curve()));
            var curvesB = Polyline3D.ConvertCurvesToPolyline(getB.Objects().Select(r => r.Curve()));

            if (_options == null)
            {
                _options = new PolylineBooleanOptions();
                _options.Initialize(doc.ModelAbsoluteTolerance, mode.Equals(RunMode.Scripted));
                _options.SetCommandPrompt("Select boolean type (click to toggle)");
                _options.AcceptNothing(true);
            }

            _options.EnableTransparentCommands(true);
            _options.SetOriginalCurves(curvesA, curvesB);

            while (true)
            {
                var res = _options.Get();
                RhinoApp.WriteLine(res.ToString());

                if (res == GetResult.Point)
                {
                    _options.ToggleBoolean();
                }

                if (res == GetResult.Cancel)
                {
                    return(_options.CommandResult());
                }

                if (res == GetResult.Nothing)
                {
                    break;
                }

                if (res == GetResult.Option)
                {
                    // update the enum options
                    _options.UpdateOptions();
                    _options.CalculateBoolean();
                }
            }

            // deleselect all.
            doc.Objects.Select(doc.Objects.GetSelectedObjects(true, true).Select(obj => obj.Id), false);
            // return the offset
            var guids = _options.Results.Select(pl => doc.Objects.AddPolyline(pl));

            doc.Objects.Select(guids);
            return(Result.Success);
        }
Example #36
0
 public static Commands.Result GetMultipleObjects(string prompt, bool acceptNothing, Rhino.DocObjects.ObjectType filter, out Rhino.DocObjects.ObjRef[] rhObjects)
 {
   rhObjects = null;
   Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
   go.SetCommandPrompt(prompt);
   go.AcceptNothing(acceptNothing);
   go.GeometryFilter = filter;
   go.GetMultiple(1, 0); //David: changed this from GetMultiple(1, -1), which is a much rarer case (imo).
   Commands.Result rc = go.CommandResult();
   if (rc == Rhino.Commands.Result.Success && go.ObjectCount > 0)
   {
     rhObjects = go.Objects();
   }
   go.Dispose();
   return rc;
 }
 /// <summary>
 /// Select an object for object name display
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForName(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select object", 384));
     go.AcceptNothing(true);
     go.SubObjectSelect = false;
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         objref.Dispose();
       }
     }
   }
 }
Example #38
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface |
                                                               Rhino.DocObjects.ObjectType.PolysrfFilter |
                                                               Rhino.DocObjects.ObjectType.Mesh;
            int integer1 = 300;
            int integer2 = 300;

            Rhino.Input.Custom.OptionInteger optionInteger1 = new Rhino.Input.Custom.OptionInteger(integer1, 200, 900);
            Rhino.Input.Custom.OptionInteger optionInteger2 = new Rhino.Input.Custom.OptionInteger(integer2, 200, 900);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
            go.GeometryFilter = geometryFilter;
            go.AddOptionInteger("Option1", ref optionInteger1);
            go.AddOptionInteger("Option2", ref optionInteger2);
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

            for (; ;)
            {
                var res = go.GetMultiple(1, 0);

                if (res == Rhino.Input.GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    continue;
                }

                else if (res != Rhino.Input.GetResult.Object)
                {
                    return(Result.Cancel);
                }

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

                break;
            }

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

            int objectCount = go.ObjectCount;

            integer1 = optionInteger1.CurrentValue;
            integer2 = optionInteger2.CurrentValue;

            RhinoApp.WriteLine("Select object count = {0}", objectCount);
            RhinoApp.WriteLine("Value of integer1 = {0}", integer1);
            RhinoApp.WriteLine("Value of integer2 = {0}", integer2);

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Pick some objects to smooth
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to smooth");
            go.SubObjectSelect       = false;
            go.ReferenceObjectSelect = false;
            go.GeometryFilter        = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Mesh;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            // Prompt for some command line options. In this case,
            // we will clone the -Smooth command.
            Rhino.Input.Custom.GetOption gs = new Rhino.Input.Custom.GetOption();
            gs.SetCommandPrompt("Choose smooth option");
            gs.AcceptNothing(true);
            for (; ;)
            {
                gs.ClearCommandOptions();

                Rhino.Input.Custom.OptionDouble smooth_factor_option  = new Rhino.Input.Custom.OptionDouble(m_smooth_factor);
                Rhino.Input.Custom.OptionToggle use_cplane_option     = new Rhino.Input.Custom.OptionToggle(m_use_cplane, "World", "CPlane");
                Rhino.Input.Custom.OptionToggle smooth_x_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_x, "No", "Yes");
                Rhino.Input.Custom.OptionToggle smooth_y_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_y, "No", "Yes");
                Rhino.Input.Custom.OptionToggle smooth_z_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_z, "No", "Yes");
                Rhino.Input.Custom.OptionToggle fix_boundaries_option = new Rhino.Input.Custom.OptionToggle(m_fix_boundaries, "No", "Yes");

                int smooth_factor_index  = gs.AddOptionDouble("SmoothFactor", ref smooth_factor_option);
                int use_cplane_index     = gs.AddOptionToggle("CoordinateSystem", ref use_cplane_option);
                int smooth_x_index       = gs.AddOptionToggle("X", ref smooth_x_option);
                int smooth_y_index       = gs.AddOptionToggle("Y", ref smooth_y_option);
                int smooth_z_index       = gs.AddOptionToggle("Z", ref smooth_z_option);
                int fix_boundaries_index = gs.AddOptionToggle("FixBoundaries", ref fix_boundaries_option);

                Rhino.Input.GetResult getrc = gs.Get();
                if (gs.CommandResult() != Result.Success)
                {
                    return(gs.CommandResult());
                }

                if (getrc == Rhino.Input.GetResult.Option)
                {
                    int index = gs.OptionIndex();
                    if (index == smooth_factor_index)
                    {
                        m_smooth_factor = smooth_factor_option.CurrentValue;
                    }
                    else if (index == use_cplane_index)
                    {
                        m_use_cplane = use_cplane_option.CurrentValue;
                    }
                    else if (index == smooth_x_index)
                    {
                        m_smooth_x = smooth_x_option.CurrentValue;
                    }
                    else if (index == smooth_y_index)
                    {
                        m_smooth_y = smooth_y_option.CurrentValue;
                    }
                    else if (index == smooth_z_index)
                    {
                        m_smooth_z = smooth_z_option.CurrentValue;
                    }
                    else if (index == fix_boundaries_index)
                    {
                        m_fix_boundaries = fix_boundaries_option.CurrentValue;
                    }

                    continue;
                }

                break;
            }

            // Build a command line macro that we can script
            StringBuilder sb = new StringBuilder();

            sb.Append("_-Smooth ");
            sb.Append(string.Format("_SmoothFactor={0} ", m_smooth_factor));
            sb.Append(string.Format("_CoordinateSystem={0} ", m_use_cplane ? "_CPlane" : "_World"));
            sb.Append(string.Format("_X={0} ", m_smooth_x ? "_Yes" : "_No"));
            sb.Append(string.Format("_Y={0} ", m_smooth_y ? "_Yes" : "_No"));
            sb.Append(string.Format("_Z={0} ", m_smooth_z ? "_Yes" : "_No"));
            sb.Append(string.Format("_FixBoundaries={0} ", m_fix_boundaries ? "_Yes" : "_No"));
            sb.Append("_Enter");

            string script = sb.ToString();

#if (!RELEASE)
            Rhino.RhinoApp.WriteLine(script);
#endif

            // Script the smooth command
            Rhino.RhinoApp.RunScript(script, false);

            return(Result.Success);
        }
        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);
        }
Example #41
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to define block
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select objects to define block");
            go.ReferenceObjectSelect = false;
            go.SubObjectSelect       = false;
            go.GroupSelect           = true;

            // Phantoms, grips, lights, etc., cannot be in blocks.
            var forbidden_geometry_filter = Rhino.DocObjects.ObjectType.Light |
                                            Rhino.DocObjects.ObjectType.Grip | Rhino.DocObjects.ObjectType.Phantom;
            var geometry_filter = forbidden_geometry_filter ^ Rhino.DocObjects.ObjectType.AnyObject;

            go.GeometryFilter = geometry_filter;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            // Block base point
            Rhino.Geometry.Point3d base_point;
            var rc = Rhino.Input.RhinoGet.GetPoint("Block base point", false, out base_point);

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

            // Block definition name
            string idef_name = "";

            rc = Rhino.Input.RhinoGet.GetString("Block definition name", false, ref idef_name);
            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }
            // Validate block name
            idef_name = idef_name.Trim();
            if (string.IsNullOrEmpty(idef_name))
            {
                return(Rhino.Commands.Result.Nothing);
            }

            // See if block name already exists
            Rhino.DocObjects.InstanceDefinition existing_idef = doc.InstanceDefinitions.Find(idef_name, true);
            if (existing_idef != null)
            {
                Rhino.RhinoApp.WriteLine("Block definition {0} already exists", idef_name);
                return(Rhino.Commands.Result.Nothing);
            }

            // Gather all of the selected objects
            var geometry   = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>();
            var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                var rhinoObject = go.Object(i).Object();
                if (rhinoObject != null)
                {
                    geometry.Add(rhinoObject.Geometry);
                    attributes.Add(rhinoObject.Attributes);
                }
            }

            // Gather all of the selected objects
            int idef_index = doc.InstanceDefinitions.Add(idef_name, string.Empty, base_point, geometry, attributes);

            if (idef_index < 0)
            {
                Rhino.RhinoApp.WriteLine("Unable to create block definition", idef_name);
                return(Rhino.Commands.Result.Failure);
            }

            return(Rhino.Commands.Result.Success);
        }
  public static Rhino.Commands.Result GetMultipleWithOptions(Rhino.RhinoDoc doc)
  {
    const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | 
                                                       Rhino.DocObjects.ObjectType.PolysrfFilter | 
                                                       Rhino.DocObjects.ObjectType.Mesh;
    int integer1 = 300;
    int integer2 = 300;

    Rhino.Input.Custom.OptionInteger optionInteger1 = new Rhino.Input.Custom.OptionInteger(integer1, 200, 900);
    Rhino.Input.Custom.OptionInteger optionInteger2 = new Rhino.Input.Custom.OptionInteger(integer2, 200, 900);

    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
    go.GeometryFilter = geometryFilter;
    go.AddOptionInteger("Option1", ref optionInteger1);
    go.AddOptionInteger("Option2", ref optionInteger2);
    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.Object)
        return Rhino.Commands.Result.Cancel;

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

      break;
    }

    if (bHavePreselectedObjects)
    {
      // Normally when command finishes, pre-selected objects will remain
      // selected, when and post-selected objects will be unselected.
      // With this sample, it is possible to have a combination of 
      // pre-selected and post-selected objects. To make sure everything
      // "looks the same", unselect everything before finishing the command.
      for (int i = 0; i < go.ObjectCount; i++)
      {
        Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object();
        if (null != rhinoObject)
          rhinoObject.Select(false);
      }
      doc.Views.Redraw();
    }

    int objectCount = go.ObjectCount;
    integer1 = optionInteger1.CurrentValue;
    integer2 = optionInteger2.CurrentValue;

    Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount);
    Rhino.RhinoApp.WriteLine("Value of integer1 = {0}", integer1);
    Rhino.RhinoApp.WriteLine("Value of integer2 = {0}", integer2);

    return Rhino.Commands.Result.Success;
  }
 /// <summary>
 /// Select an object which will be used for the user text list
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForUserText(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select object", 361));
     go.AcceptNothing(true);
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         SetupSelectObjectPanelHelper(TextFieldType.usertext, false);
         objref.Dispose();
       }
     }
   }
 }
Example #44
0
        public Boolean createDimensions(List <Guid> guidList)
        {
            doc = RhinoDoc.ActiveDoc;
            go  = new Rhino.Input.Custom.GetObject();
            go.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            go.SetCommandPrompt("Select panels to create dimensions");
            while (true)
            {
                go.ClearCommandOptions();

                // perform the get operation. This will prompt the user to select the list of curves, but also
                // allow for command line options defined above
                GetResult result = go.GetMultiple(1, 0);

                if (result == GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    continue;
                }
                else if (result == GetResult.Number)
                {
                    continue;
                }
                else if (result != GetResult.Object)
                {
                }

                if (go.ObjectsWerePreselected)
                {
                    go.EnablePreSelect(true, true);
                    break;
                }

                break;
            }

            int objecTCount = go.ObjectCount;

            foreach (ObjRef objRef in go.Objects()) //Go through each curve  in the objects list
            {
                Curve curve = objRef.Curve();

                // If curve is null, means objRef is not a curve
                if (curve == null)
                {
                    dimensionsCreated = false;
                    continue;
                }

                // If curve is not Closed Curve
                if (curve.IsClosed == false)
                {
                    RhinoApp.WriteLine(objRef.ToString() + " curve is open");
                    dimensionsCreated = false;
                    continue;
                }

                if (curve.IsPlanar() == false)
                {
                    RhinoApp.WriteLine(objRef.ToString() + " curve is not planar");
                    dimensionsCreated = false;
                    continue;
                }
                MetrixUtilities.createMetrixRealDimension();
                BoundingBox boundingBox = curve.GetBoundingBox(Plane.WorldXY);
                Point3d     min         = boundingBox.Min;
                Point3d     max         = boundingBox.Max;

                //Add Horizontal dimension
                origin       = new Point3d(min.X, max.Y, 0);
                offset       = new Point3d(max.X, max.Y, 0);
                pt           = new Point3d((offset.X - origin.X) / 2, max.Y + 180, 0);
                plane        = Plane.WorldXY;
                plane.Origin = origin;
                guidList     = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension


                //Add vertical Dimensions
                origin       = new Point3d(min.X, min.Y, 0);
                offset       = new Point3d(min.X, max.Y, 0); //left
                pt           = new Point3d(min.X - 180, (offset.Y - origin.Y) / 2, 0);
                plane        = Plane.WorldXY;
                plane.XAxis  = new Vector3d(0, -1, 0); //-1 to rotate the dimension vertically
                plane.YAxis  = new Vector3d(-1, 0, 0);
                plane.ZAxis  = new Vector3d(0, 0, -1);
                plane.Origin = origin;
                guidList     = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension

                dimensionsCreated = true;
            }
            doc.Views.Redraw(); //finally redraw to refresh the screen and display dimensions to user
            return(dimensionsCreated);
        }
    public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
    {
        // Select objects to orient
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to orient");
        go.SubObjectSelect = false;
        go.GroupSelect     = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Point to orient from
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Point to orient from");
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Define source plane
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }
        Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
        source_plane.Origin = gp.Point();

        // Surface to orient on
        Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject();
        gs.SetCommandPrompt("Surface to orient on");
        gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface;
        gs.SubObjectSelect             = true;
        gs.DeselectAllBeforePostSelect = false;
        gs.OneByOnePostSelect          = true;
        gs.Get();
        if (gs.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gs.CommandResult());
        }

        Rhino.DocObjects.ObjRef objref = gs.Object(0);
        // get selected surface object
        Rhino.DocObjects.RhinoObject obj = objref.Object();
        if (obj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // get selected surface (face)
        Rhino.Geometry.Surface surface = objref.Surface();
        if (surface == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // Unselect surface
        obj.Select(false);

        // Point on surface to orient to
        gp.SetCommandPrompt("Point on surface to orient to");
        gp.Constrain(surface, false);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Do transformation
        Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
        double u, v;

        if (surface.ClosestPoint(gp.Point(), out u, out v))
        {
            Rhino.Geometry.Plane target_plane;
            if (surface.FrameAt(u, v, out target_plane))
            {
                // Build transformation
                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);

                // Do the transformation. In this example, we will copy the original objects
                const bool delete_original = false;
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    doc.Objects.Transform(go.Object(i), xform, delete_original);
                }

                doc.Views.Redraw();
                rc = Rhino.Commands.Result.Success;
            }
        }
        return(rc);
    }
            ///<summary> This gets called when when the user runs this command.</summary> 
            protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
            {
                SourceConduit m_source_conduit = SourceConduit.Instance;

                //Rhino.DocObjects.ObjRef location;

                string type = "custom";

                Rhino.Input.Custom.GetObject GO = new Rhino.Input.Custom.GetObject();
                GO.SetCommandPrompt("Select source surface...");
                GO.GeometryFilter = Rhino.DocObjects.ObjectType.Brep;
                GO.AddOption("Crowd");
                GO.GroupSelect = false;
                GO.SubObjectSelect = false;
                GO.EnableClearObjectsOnEntry(false);
                GO.EnableUnselectObjectsOnExit(false);
                GO.DeselectAllBeforePostSelect = false;

                int Men = 100, Women = 100, Kids = 100, effort = 0;

                do
                {
                    Rhino.Input.GetResult GR = GO.Get();

                    if (GR == Rhino.Input.GetResult.Option)
                    {
                        type = GO.Option().EnglishName;
                        if (type == "Crowd")
                        {
                            Rhino.Input.RhinoGet.GetInteger("Number of Men in Crowd...", true, ref Men);
                            Rhino.Input.RhinoGet.GetInteger("Number of Women in Crowd...", true, ref Women);
                            Rhino.Input.RhinoGet.GetInteger("Number of Children in Crowd...", true, ref Kids);

                            Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption();
                            GOpt.SetCommandPrompt("Speech Activity");
                            GOpt.AddOption("SoftOrWhispered");
                            GOpt.AddOption("Conversation");
                            GOpt.AddOption("CompetingConversation");
                            GOpt.AddOption("Singing");
                            GOpt.AddOption("AllShouting");
                            GOpt.AcceptNothing(false);

                            GOpt.Get();
                            effort = GOpt.OptionIndex() - 1;
                        }
                        continue;
                    }
                    else if (GR == Rhino.Input.GetResult.Object)
                    {
                        for (int i = 0; i < GO.ObjectCount; i++)
                        {
                            Rhino.DocObjects.ObjRef obj = GO.Object(i);

                            Rhino.DocObjects.RhinoObject rhObj = doc.Objects.Find(obj.ObjectId);

                            double Area = (rhObj.Geometry as Rhino.Geometry.Brep).GetArea();

                            rhObj.Attributes.Name = "Acoustical Source";
                            rhObj.Geometry.SetUserString("SourceType", "");

                            double[] SPL = new double[] { 120, 120, 120, 120, 120, 120, 120, 120 };

                            if (type == "Crowd")
                            {
                                //double mod = (effort < 3) ? .5 : 1;

                                //Correct for tightly packed spaces, and competing speech.
                                //if (Area / (Men + Women + Kids) < 3.0f)
                                //{
                                //    //In overcrowded scenarios, vocal effort escalates as such:
                                //    //whispering becomes conversation.
                                //    //conversation becomes competing conversation.
                                //    //competing conversation becomes shouting.
                                //    //Singing stays singing... I'm pretty sure experienced singers wouldn't start shouting...
                                //    if (effort < 2) effort++;
                                //    else effort = 4;
                                //}

                                for (int oct = 0; oct < 8; oct++)
                                {
                                    double Power = Men * Math.Pow(10, Males[effort][oct] / 10) + Women * Math.Pow(10, Females[effort][oct] / 10) + Kids * Math.Pow(10, Children[effort][oct] / 10);
                                    //Power /= (Area);
                                    SPL[oct] = 10 * Math.Log10(Power) + 11;
                                }
                            }
                            else
                            {
                                Rhino.Input.RhinoGet.GetNumber("62.5 Hz. Sound Power Level", true, ref SPL[0]);
                                Rhino.Input.RhinoGet.GetNumber("125 Hz. Sound Power Level", true, ref SPL[1]);
                                Rhino.Input.RhinoGet.GetNumber("250 Hz. Sound Power Level", true, ref SPL[2]);
                                Rhino.Input.RhinoGet.GetNumber("500 Hz. Sound Power Level", true, ref SPL[3]);
                                Rhino.Input.RhinoGet.GetNumber("1000 Hz. Sound Power Level", true, ref SPL[4]);
                                Rhino.Input.RhinoGet.GetNumber("2000 Hz. Sound Power Level", true, ref SPL[5]);
                                Rhino.Input.RhinoGet.GetNumber("4000 Hz. Sound Power Level", true, ref SPL[6]);
                                Rhino.Input.RhinoGet.GetNumber("8000 Hz. Sound Power Level", true, ref SPL[7]);
                            }

                            rhObj.Geometry.SetUserString("SWL", Utilities.PachTools.EncodeSourcePower(SPL));
                            rhObj.Geometry.SetUserString("Phase", "0;0;0;0;0;0;0;0");
                            doc.Objects.ModifyAttributes(rhObj, rhObj.Attributes, true);

                            m_source_conduit.SetSource(rhObj);
                        }

                        doc.Views.Redraw();
                        return Result.Success;
                    }
                    else return Result.Cancel;
                } while (true);
            }
Example #47
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            pluginObj = ((nishanchiPlugin)this.PlugIn);
            RhinoView viewObj = doc.Views.ActiveView;
            RhinoViewport viewPortObj = viewObj.ActiveViewport;
            Vector3d originalCameraVector = viewPortObj.CameraDirection;
            Point3d originalCameraLocation = viewPortObj.CameraLocation;
            Mesh meshObj;

            Boolean logging = false;
            StreamWriter logWriter = null;

            String reportString;
            String logString;
            String printCommandStr;

            if (((nishanchiPlugin)this.PlugIn).logEnabled())
            {
                logWriter = new StreamWriter(((nishanchiPlugin)this.PlugIn).getNewLogFile());
                logWriter.WriteLine("Printing...");
                logging = true;
            }

            if (!pluginObj.trackerConnected)
            {
                RhinoApp.WriteLine("Tracker disconnected");
                return Rhino.Commands.Result.Failure;
            }

            connectKbEvt();

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select the mesh to print");
            go.Get();
            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                disconnectKbEvt();
                return rc;
            }

            meshObj = new Mesh();
            if (go.ObjectCount == 1){
                ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId);
                meshObj = tmpRef.Mesh();
                if (meshObj == null){
                    disconnectKbEvt();
                    return rc;
                }
            }

            createNozzles(doc);
            cameraPoint = new tPoint(Nozzle.XOffset + 100.0, Nozzle.YOffset, Nozzle.ZOffset + (Nozzle.ZMultiplier * ((numNozzles-1)/2)));

            fastrak trackerObj = pluginObj.trackerObj;
            int numPoints = 0;

            Boolean retval;

            RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker."));
            pluginObj.trackerObj.setContinuous();
            RhinoApp.WriteLine(string.Format("Printing mode enabled now."));

            running = true;
            while (running)
            {
                retval = trackerObj.readFrame();
                if (retval)
                {
                    //q0,q1,q2,q3 Quaternion begin
                    //Compute the rotation matrix
                    reportString = String.Format("{0},{1},{2}", trackerObj.x, trackerObj.y, trackerObj.z);
                    logString = String.Format("p,{0},{1},{2},{3},{4},{5},{6},{7}", numPoints, trackerObj.x, trackerObj.y, trackerObj.z, trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);

                    RhinoApp.WriteLine(reportString);
                    if (logging)
                    {
                        logWriter.WriteLine(logString);
                    }

                    rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z);
                    orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);
                    orientationQuat.GetRotation(out angle, out axis);
                    rotMat = Transform.Rotation(angle, axis, origin);

                    // Compute the new positions for the nozzlePoints and also compute the new lines
                    for (int i = 0; i < numNozzles; i++)
                    {
                        nozzles[i].computeTxTx(rotMat, rxTxTx);
                    }

                    //And, I move the view around
                    if ((numPoints % 100) == 0)
                    {
                        cameraPoint.computeTxTx(rotMat, rxTxTx);
                        viewPortObj.SetCameraLocation(cameraPoint.txTx(), true);
                        viewPortObj.SetCameraDirection(nozzles[4].vector(), true);
                        viewPortObj.Rotate(Math.PI / 2, nozzles[4].vector(), cameraPoint.txTx());
                        cameraUpTx = rotMat * cameraUpRx;
                        viewPortObj.CameraUp = cameraUpTx;

                        removeNozzleLinesFromDocument(doc);
                        addNozzleLinesToDocument(doc);
                        doc.Views.ActiveView.Redraw();
                        RhinoApp.Wait();
                    }

                    //Compute ray intersections
                    if ((numPoints % 4) == 0)
                    {
                        //RhinoApp.WriteLine("Calculating intersections..");
                        for (int i = 0; i < numNozzles; i++)
                        {
                            nozzles[i].rayIntersectionDistance = Intersection.MeshRay(meshObj,nozzles[i].ray());
                        }

                        printCommandStr = printCommand();
                        //RhinoApp.WriteLine(printCommandStr);

                        if (logging)
                        {
                            logString = String.Format("c,{0},{1}", numPoints, printCommandStr);
                            logWriter.WriteLine(logString);
                        }
                    }
                    numPoints++;
                }
            }

            running = false;

            //clean up
            removeNozzleLinesFromDocument(doc);
            doc.Views.ActiveView.Redraw();
            RhinoApp.WriteLine("Removing printHead objects!!");

            if (logging)
            {
                logWriter.Close();
                ((nishanchiPlugin)this.PlugIn).closeLogFile();
            }

            //stop the tracker
            RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker."));
            pluginObj.trackerObj.stopContinuous();
            disconnectKbEvt();
            RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!"));

            //setup the viewport as it was
            viewPortObj.SetCameraLocation(originalCameraLocation, true);
            viewPortObj.SetCameraDirection(originalCameraVector, true);

            return Rhino.Commands.Result.Success;
        }
            ///<summary> This gets called when when the user runs this command.</summary> 
            protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
            {
                SourceConduit m_source_conduit = SourceConduit.Instance;

                Rhino.Input.Custom.GetObject GO = new Rhino.Input.Custom.GetObject();
                GO.SetCommandPrompt("Select source curve...");
                GO.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
                GO.AddOption("TrafficWelsh");
                GO.AddOption("TrafficFHWA");
                GO.AddOption("AircraftANCON");
                GO.AddOption("Custom");
                //GO.AddOptionList("SourceType", new List<string>() { "TrafficWelshStandard", "TrafficFHWA Standard", "Custom" }, 2);
                GO.GroupSelect = false;
                GO.SubObjectSelect = false;
                GO.EnableClearObjectsOnEntry(false);
                GO.EnableUnselectObjectsOnExit(false);
                GO.DeselectAllBeforePostSelect = false;

                int pavement = 0;
                double SPLW = 0;
                double[] SWL = new double[] { 120, 120, 120, 120, 120, 120, 120, 120 };
                double velocity = 83;
                double delta = 45;
                double choice = 0;
                for (; ; )
                {
                    Rhino.Input.GetResult GR = GO.GetMultiple(1, 1);
                    int type = GO.OptionIndex();
                    if (GR == Rhino.Input.GetResult.Option)
                    {
                        choice = (int)type;
                        //type = GO.Option().EnglishName;
                        if (type == 1)//"Traffic (Welsh Standard)")
                        {
                            Rhino.Input.RhinoGet.GetNumber("Input basis road sound pressure level at 1 m from street...", false, ref SPLW);
                            SPLW += 8;
                        }
                        else if (type == 2)//"Traffic (FHWA Standard)")
                        {
                            ///Described at:
                            ///http://www.fhwa.dot.gov/environment/noise/traffic_noise_model/old_versions/tnm_version_10/tech_manual/tnm03.cfm#tnma2

                            double s = 0;
                            //int i = 0;

                            Rhino.Input.RhinoGet.GetNumber("Enter the speed of traffic on this road (in kph)...", false, ref s);

                            ///Pavement
                            Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption();
                            GOpt.SetCommandPrompt("Pavement type...");
                            GOpt.AddOption("Average_DGAC_PCC)");
                            GOpt.AddOption("DGAC_Asphalt");
                            GOpt.AddOption("PCC_Concrete");
                            GOpt.AddOption("OGAC_OpenGradedAsphalt");
                            GOpt.AcceptNothing(false);
                            GOpt.Get();
                            pavement = GOpt.OptionIndex();

                            ///Vehicle tallies
                            double[] Veh = new double[5] { 0, 0, 0, 0, 0 };
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of automobiles per hour...", false, ref Veh[0]);
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of medium trucks per hour...", false, ref Veh[1]);
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of heavy trucks per hour...", false, ref Veh[2]);
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of buses per hour...", false, ref Veh[3]);
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of motorcycles per hour...", false, ref Veh[4]);

                            bool throttle = false;
                            int t = 0;
                            Rhino.Input.RhinoGet.GetBool("Full throttle?", false, "Yes", "No", ref throttle);
                            t = (throttle) ? 1 : 0;
                            double root2 = Math.Sqrt(2);
                            double vtot = 0;
                            double[] Es = new double[8] { 0, 0, 0, 0, 0, 0, 0, 0 };

                            for (int v = 0; v < 5; v++)
                            {
                                double A = FHWATraffic[v][pavement][t][0];
                                double B = FHWATraffic[v][pavement][t][1];
                                double C = FHWATraffic[v][pavement][t][2];
                                double D1 = FHWATraffic[v][pavement][t][3];
                                double D2 = FHWATraffic[v][pavement][t][4];
                                double E1 = FHWATraffic[v][pavement][t][5];
                                double E2 = FHWATraffic[v][pavement][t][6];
                                double F1 = FHWATraffic[v][pavement][t][7];
                                double F2 = FHWATraffic[v][pavement][t][8];
                                double G1 = FHWATraffic[v][pavement][t][9];
                                double G2 = FHWATraffic[v][pavement][t][10];
                                double H1 = FHWATraffic[v][pavement][t][11];
                                double H2 = FHWATraffic[v][pavement][t][12];
                                double I1 = FHWATraffic[v][pavement][t][13];
                                double I2 = FHWATraffic[v][pavement][t][14];
                                double J1 = FHWATraffic[v][pavement][t][15];
                                double J2 = FHWATraffic[v][pavement][t][16];

                                vtot += Veh[v];

                                for (int oct = 0; oct < 8; oct++)
                                {
                                    double f = 62.5 * Math.Pow(2, oct);
                                    double[] freq = new double[3] { f / root2, f, f * root2 };

                                    for (int oct3 = 0; oct3 < 3; oct3++)
                                    {
                                        double Ea = Math.Pow(0.6214 * s, A / 10) * Math.Pow(10, B / 10) + Math.Pow(10, C / 10);
                                        double logf = Math.Log10(freq[oct3]);
                                        double Ls = 10 * Math.Log10(Ea) + (D1 + 0.6214 * D2 * s) + (E1 + 0.6214 * E2 * s) * logf
                                            + (F1 + 0.6214 * F2 * s) * logf * logf + (G1 + 0.6214 * G2 * s) * logf * logf * logf
                                            + (H1 + 0.6214 * H2 * s) * logf * logf * logf * logf + (I1 + 0.6214 * I2 * s) * logf * logf * logf * logf * logf
                                            + (J1 + 0.6214 * J2 * s) * logf * logf * logf * logf * logf * logf;
                                        Es[oct] += 0.0476 * Math.Pow(10, Ls / 10) * Veh[v] / s;
                                    }
                                }
                            }

                            double[] Awt = new double[8] { -26, -16, -9, -3, 0, 1.2, 1, -1 };
                            double dmod = 10 * Math.Log10(1 / (Utilities.Numerics.PiX2 * 15));

                            for (int oct = 0; oct < 8; oct++)
                            {
                                SWL[oct] = 10 * Math.Log10(Es[oct]) - Awt[oct] - dmod;//
                            }
                        }
                        else if (type == 3)//"Aircraft (ANCON-derived)")
                        {
                            Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption();
                            GOpt.SetCommandPrompt("Takeoff or Landing?");
                            GOpt.AddOption("Takeoff");
                            GOpt.AddOption("Landing");
                            GOpt.AddOption("Both");
                            GOpt.AcceptNothing(false);
                            GOpt.Get();
                            int TL_Choice = GOpt.OptionIndex();

                            double SWLA = 150;

                            Rhino.Input.RhinoGet.GetNumber("What is the broadband sound power of the aircraft (in dBA)?", false, ref SWLA);
                            Rhino.Input.RhinoGet.GetNumber("What is the maximum velocity of the aircraft in m/s?", false, ref velocity);
                            Rhino.Input.RhinoGet.GetNumber("What is the slant angle for this aircraft?", false, ref delta);

                            double[][] Aircraft_Normalization = new double[3][] {
                                //new double[8]{ -12, -10.5, -12, -15, -20, -27, -40, -44},
                                //new double[8]{-11, -13, -12, -13.5, -18, -21, -25, -35},
                                //new double[8]{-11, -10.5, -12, -13.5, -18, -21, -25, -35}
                            new double[8] { 6.191472203, 7.691472203, 6.191472203, 3.191472203, -1.808527797, -8.808527797,-21.8085278, -25.8085278},
                            new double[8] { 5.6783811710, 3.6783811710, 4.678381171, 3.178381171, -1.321618829, -4.321618829, -8.321618829, -18.32161883},
                            new double[8] { 5.678381171, 6.178381171, 4.678381171, 3.178381171, -1.321618829, -4.321618829, -8.321618829, -18.32161883}
                            };

                            for (int oct = 0; oct < 8; oct++)
                            {
                                SWL[oct] = SWLA + Aircraft_Normalization[TL_Choice-1][oct];//
                            }
                        }
                        //    continue;
                        //    //return Result.Success;
                        //}
                    }
                    else if (GR == Rhino.Input.GetResult.Object)
                    {
                        for (int i = 0; i < GO.ObjectCount; i++)
                        {
                            Rhino.DocObjects.ObjRef obj = GO.Object(i);

                            Rhino.DocObjects.RhinoObject rhObj = doc.Objects.Find(obj.ObjectId);

                            rhObj.Attributes.Name = "Acoustical Source";

                            if (choice == 1)//"Traffic (Welsh Standard)")
                            {
                                rhObj.Geometry.SetUserString("SourceType", "Traffic (Welsh)");
                                for (int oct = 0; oct < 8; oct++) SWL[oct] = SPLW + WelshTraffic[oct];
                            }
                            else if (choice == 2)//"Traffic (FWHA Standard)")
                            {
                                rhObj.Geometry.SetUserString("SourceType", "Traffic (FHWA)");
                            }
                            else if (choice == 3)//"Aircraft (ANCON-derived)")
                            {
                                rhObj.Geometry.SetUserString("SourceType", "Aircraft (ANCON derived)");
                                rhObj.Geometry.SetUserString("Velocity", velocity.ToString());
                                rhObj.Geometry.SetUserString("delta", delta.ToString());
                            }
                            else
                            {
                                Rhino.Input.RhinoGet.GetNumber("62.5 Hz. Sound Power Level", true, ref SWL[0]);
                                Rhino.Input.RhinoGet.GetNumber("125 Hz. Sound Power Level", true, ref SWL[1]);
                                Rhino.Input.RhinoGet.GetNumber("250 Hz. Sound Power Level", true, ref SWL[2]);
                                Rhino.Input.RhinoGet.GetNumber("500 Hz. Sound Power Level", true, ref SWL[3]);
                                Rhino.Input.RhinoGet.GetNumber("1000 Hz. Sound Power Level", true, ref SWL[4]);
                                Rhino.Input.RhinoGet.GetNumber("2000 Hz. Sound Power Level", true, ref SWL[5]);
                                Rhino.Input.RhinoGet.GetNumber("4000 Hz. Sound Power Level", true, ref SWL[6]);
                                Rhino.Input.RhinoGet.GetNumber("8000 Hz. Sound Power Level", true, ref SWL[7]);
                            }

                            rhObj.Geometry.SetUserString("SWL", Utilities.PachTools.EncodeSourcePower(SWL));
                            rhObj.Geometry.SetUserString("Phase", "0;0;0;0;0;0;0;0");
                            doc.Objects.ModifyAttributes(rhObj, rhObj.Attributes, true);

                            m_source_conduit.SetSource(rhObj);
                        }

                        doc.Views.Redraw();
                        return Result.Success;
                    }
                    else return Result.Cancel;
                }
            }
  public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
  {
    // Select objects to orient
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select objects to orient");
    go.SubObjectSelect = false;
    go.GroupSelect = true;
    go.GetMultiple(1, 0);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();

    // Point to orient from
    Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
    gp.SetCommandPrompt("Point to orient from");
    gp.Get();
    if (gp.CommandResult() != Rhino.Commands.Result.Success)
      return gp.CommandResult();

    // Define source plane
    Rhino.Display.RhinoView view = gp.View();
    if (view == null)
    {
      view = doc.Views.ActiveView;
      if (view == null)
        return Rhino.Commands.Result.Failure;
    }
    Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
    source_plane.Origin = gp.Point();

    // Surface to orient on
    Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject();
    gs.SetCommandPrompt("Surface to orient on");
    gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
    gs.SubObjectSelect = true;
    gs.DeselectAllBeforePostSelect = false;
    gs.OneByOnePostSelect = true;
    gs.Get();
    if (gs.CommandResult() != Rhino.Commands.Result.Success)
      return gs.CommandResult();

    Rhino.DocObjects.ObjRef objref = gs.Object(0);
    // get selected surface object
    Rhino.DocObjects.RhinoObject obj = objref.Object();
    if (obj == null)
      return Rhino.Commands.Result.Failure;
    // get selected surface (face)
    Rhino.Geometry.Surface surface = objref.Surface();
    if (surface == null)
      return Rhino.Commands.Result.Failure;
    // Unselect surface
    obj.Select(false);

    // Point on surface to orient to
    gp.SetCommandPrompt("Point on surface to orient to");
    gp.Constrain(surface, false);
    gp.Get();
    if (gp.CommandResult() != Rhino.Commands.Result.Success)
      return gp.CommandResult();

    // Do transformation
    Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
    double u, v;
    if (surface.ClosestPoint(gp.Point(), out u, out v))
    {
      Rhino.Geometry.Plane target_plane;
      if (surface.FrameAt(u, v, out target_plane))
      {
        // Build transformation
        Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);

        // Do the transformation. In this example, we will copy the original objects
        const bool delete_original = false;
        for (int i = 0; i < go.ObjectCount; i++)
          doc.Objects.Transform(go.Object(i), xform, delete_original);

        doc.Views.Redraw();
        rc = Rhino.Commands.Result.Success;
      }
    }
    return rc;
  }
Example #50
0
 static Commands.Result GetGripsHelper(out Rhino.DocObjects.GripObject[] grips, string prompt, bool singleGrip)
 {
   grips = null;
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     if (!string.IsNullOrEmpty(prompt))
       go.SetCommandPrompt(prompt);
     go.SubObjectSelect = false;
     go.GeometryFilter = Rhino.DocObjects.ObjectType.Grip;
     go.GroupSelect = false;
     go.AcceptNothing(true);
     if (singleGrip)
       go.Get();
     else
       go.GetMultiple(1, 0);
     Commands.Result rc = go.CommandResult();
     if (Rhino.Commands.Result.Success == rc)
     {
       Rhino.DocObjects.ObjRef[] objrefs = go.Objects();
       if (null != objrefs && objrefs.Length > 0)
       {
         System.Collections.Generic.List<Rhino.DocObjects.GripObject> griplist = new System.Collections.Generic.List<Rhino.DocObjects.GripObject>();
         for (int i = 0; i < objrefs.Length; i++)
         {
           Rhino.DocObjects.ObjRef ob = objrefs[i];
           if (null == ob)
             continue;
           Rhino.DocObjects.GripObject grip = ob.Object() as Rhino.DocObjects.GripObject;
           if (grip != null)
             griplist.Add(grip);
           ob.Dispose();
         }
         if (griplist.Count > 0)
           grips = griplist.ToArray();
       }
     }
     return rc;
   }
 }