Exemple #1
0
        public BoxMorph(Rhino.Geometry.Point3d[] box, Rhino.Geometry.Point3d[] corners)
        {
            if (8 == box.Length)
            {
                m_box = new Rhino.Geometry.Point3d[8];
                for (int i = 0; i < 8; i++)
                {
                    m_box[i] = box[i];
                }
            }

            if (8 == corners.Length)
            {
                m_corners = new Rhino.Geometry.Point3d[8];
                for (int i = 0; i < 8; i++)
                {
                    m_corners[i] = corners[i];
                }
            }

            if (null != m_box)
            {
                m_ref_x = new Rhino.Geometry.Line(m_box[0], m_box[1]);
                m_ref_y = new Rhino.Geometry.Line(m_box[0], m_box[3]);
                m_ref_z = new Rhino.Geometry.Line(m_box[0], m_box[4]);
            }
        }
Exemple #2
0
        void ReconstructColumnByCurve
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Line curve,
            Optional <Autodesk.Revit.DB.FamilySymbol> type,
            Optional <Autodesk.Revit.DB.Level> level
        )
        {
            if (curve.FromZ > curve.ToZ)
            {
                curve.Flip();
            }

            var scaleFactor = 1.0 / Revit.ModelUnits;

            curve = curve.ChangeUnits(scaleFactor);

            SolveOptionalType(ref type, doc, BuiltInCategory.OST_StructuralColumns, nameof(type));

            if (!type.Value.IsActive)
            {
                type.Value.Activate();
            }

            SolveOptionalLevel(doc, curve, ref level, out var bbox);

            // Type
            ChangeElementTypeId(ref element, type.Value.Id);

            if (element is FamilyInstance familyInstance && element.Location is LocationCurve locationCurve)
            {
                locationCurve.Curve = curve.ToHost();
            }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Geometry.Circle circle;
            Result rc = Rhino.Input.RhinoGet.GetCircle(out circle);

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

            int n = 19;

            Rhino.Geometry.Point3d[] points = PointsOnCircle(new Rhino.Geometry.Point3d(0, 0, 0), 5.0, n);
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    Rhino.Geometry.Line line = new Rhino.Geometry.Line(points[i], points[j]);
                    doc.Objects.AddLine(line);
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
 private void Visualize(ref Rhino.Geometry.Line line)
 {
     if (!viz.enabled)
     {
         viz.enabled = true;
     }
     viz.line = line;
 }
        public bool PickFrustumTest(Rhino.Geometry.Line line, out double t, out double depth, out double distance)
        {
            t        = -1;
            depth    = -1;
            distance = -1;
            IntPtr pConstThis = ConstPointer();

            return(UnsafeNativeMethods.CRhinoPickContext_PickLine2(pConstThis, line.From, line.To, ref t, ref depth, ref distance));
        }
Exemple #6
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);
    }
        /// <summary>
        /// Perform the 'get' operation.
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public Commands.Result Get(out Rhino.Geometry.Line line)
        {
            IntPtr pThis = NonConstPointer();

            line = Rhino.Geometry.Line.Unset;
            int rc = UnsafeNativeMethods.RHC_RhinoGetLine2(pThis, ref line, IntPtr.Zero);

            return((Commands.Result)rc);
        }
Exemple #8
0
        static public bool CreateSections(Rhino.RhinoDoc doc, Rhino.Geometry.GeometryBase geo, Rhino.Geometry.Surface surfaceB, Rhino.Geometry.Curve curve, double interval, ref List <PlanePoint> points)
        {
            Rhino.Geometry.Interval domain = curve.Domain;  // fixed issue
            for (double t = domain.T0; t < domain.T1; t += interval)
            {
                Rhino.Geometry.Point3d  pt        = curve.PointAt(t);
                Rhino.Geometry.Vector3d tangent   = curve.TangentAt(t);
                Rhino.Geometry.Vector3d curvature = curve.CurvatureAt(t);
                Rhino.Geometry.Plane    plane     = new Rhino.Geometry.Plane();
                curve.FrameAt(t, out plane);

                doc.Objects.AddPoint(pt);
                curvature = curvature * 10.0;
                Rhino.Geometry.Line line = new Rhino.Geometry.Line(pt, curvature);
                doc.Objects.AddLine(line);
                RhinoApp.WriteLine("Curve at {0}", t);

                Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d();

                bool ret = false;
                if (geo is Rhino.Geometry.Brep)
                {
                    Rhino.Geometry.Brep brepA = (Rhino.Geometry.Brep)geo;
                    ret = GetNormalVector(brepA, pt, ref normal);
                    RhinoApp.WriteLine("   Added Brep point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z);
                }
                else if (geo is Rhino.Geometry.Surface)
                {
                    Rhino.Geometry.Surface surfaceA = (Rhino.Geometry.Surface)geo;
                    ret = GetNormalVector(surfaceA, pt, ref normal);
                    RhinoApp.WriteLine("   Added surface point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z);
                }

                if (ret)
                {
                    Rhino.Geometry.Vector3d ucoord = CrossProduct(tangent, normal);
                    Rhino.Geometry.Plane    plane2 = new Rhino.Geometry.Plane(pt, ucoord, tangent); // normal);
                    double[] parameters            = plane2.GetPlaneEquation();

                    PlanePoint PlanePoint = new PlanePoint();
                    PlanePoint.pt        = pt;
                    PlanePoint.A         = parameters[0];
                    PlanePoint.B         = parameters[1];
                    PlanePoint.C         = parameters[2];
                    PlanePoint.D         = parameters[3];
                    PlanePoint.curvature = curvature;
                    points.Add(PlanePoint);

                    Rhino.Geometry.Interval     Interval1    = new Rhino.Geometry.Interval(-0.1, -0.1);
                    Rhino.Geometry.Interval     Interval2    = new Rhino.Geometry.Interval(0.1, 0.1);
                    Rhino.Geometry.PlaneSurface PlaneSurface = new Rhino.Geometry.PlaneSurface(plane2, Interval1, Interval2);
                    doc.Objects.AddSurface(PlaneSurface);
                }
            }
            return(true);
        }
 public Guid AddLine(Rhino.Geometry.Point3d p1, Rhino.Geometry.Point3d p2)
 {
   Rhino.Geometry.Line l = new Rhino.Geometry.Line(p1, p2);
   if (l.IsValid)
   {
     Guid id = Guid.NewGuid();
     m_lines_dict.Add(id, l);
     return id;
   }
   return Guid.Empty;
 }
Exemple #10
0
 public Guid AddLine(Rhino.Geometry.Point3d p1, Rhino.Geometry.Point3d p2)
 {
     Rhino.Geometry.Line l = new Rhino.Geometry.Line(p1, p2);
     if (l.IsValid)
     {
         Guid id = Guid.NewGuid();
         m_lines_dict.Add(id, l);
         return(id);
     }
     return(Guid.Empty);
 }
        /// <summary>
        /// Intersects a curve and an infinite line.
        /// </summary>
        /// <param name="curve">Curve to intersect.</param>
        /// <param name="line">Infinite line to intesect.</param>
        /// <param name="tolerance">If the distance from a point on curve to line
        /// is &lt;= tolerance, then the point will be part of an intersection
        /// event. If the tolerance &lt;= 0.0, then 0.001 is used.</param>
        /// <param name="overlapTolerance">If t1 and t2 are parameters of curve's
        /// intersection events and the distance from curve(t) to line is &lt;=
        /// overlapTolerance for every t1 &lt;= t &lt;= t2, then the event will
        /// be returened as an overlap event. If overlapTolerance &lt;= 0.0,
        /// then tolerance * 2.0 is used.</param>
        /// <returns>A collection of intersection events.</returns>
        public static Rhino.Geometry.Intersect.CurveIntersections IntersectCurveLine(
            Rhino.Geometry.Curve curve,
            Rhino.Geometry.Line line,
            double tolerance,
            double overlapTolerance
            )
        {
            if (!curve.IsValid || !line.IsValid || line.Length < Rhino.RhinoMath.SqrtEpsilon)
            {
                return(null);
            }

            // Extend the line through the curve's bounding box
            var bbox = curve.GetBoundingBox(false);

            if (!bbox.IsValid)
            {
                return(null);
            }

            var dir = line.Direction;

            dir.Unitize();

            var points = bbox.GetCorners();
            var plane  = new Rhino.Geometry.Plane(line.From, dir);

            double max_dist;
            var    min_dist = max_dist = plane.DistanceTo(points[0]);

            for (var i = 1; i < points.Length; i++)
            {
                var dist = plane.DistanceTo(points[i]);
                if (dist < min_dist)
                {
                    min_dist = dist;
                }
                if (dist > max_dist)
                {
                    max_dist = dist;
                }
            }

            // +- 1.0 makes the line a little bigger than the bounding box
            line.From = line.From + dir * (min_dist - 1.0);
            line.To   = line.From + dir * (max_dist + 1.0);

            // Calculate curve-curve intersection
            var line_curve = new Rhino.Geometry.LineCurve(line);

            return(Rhino.Geometry.Intersect.Intersection.CurveCurve(curve, line_curve, tolerance, overlapTolerance));
        }
Exemple #12
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Line line,
            Autodesk.Revit.DB.FamilySymbol familySymbol,
            Autodesk.Revit.DB.Level level
        )
        {
            var element = PreviousElement(doc, Iteration);

            try
            {
                if (element?.Pinned ?? true)
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        line = line.Scale(scaleFactor);
                    }

                    if (line.Length < Revit.ShortCurveTolerance)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is too short.", Params.Input[0].Name));
                    }
                    else if (level == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is mandatory.", Params.Input[2].Name));
                    }
                    else
                    {
                        if (element is FamilyInstance && familySymbol.Id != element.GetTypeId())
                        {
                            var newElmentId = element.ChangeTypeId(familySymbol.Id);
                            if (newElmentId != ElementId.InvalidElementId)
                            {
                                element = doc.GetElement(newElmentId);
                            }
                        }

                        if (element is FamilyInstance familyInstance && element.Location is LocationCurve locationCurve)
                        {
                            locationCurve.Curve = line.ToHost();
                        }
                        else
                        {
                            element = doc.Create.NewFamilyInstance(line.ToHost(), familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Column);
                        }
                    }
                }
Exemple #13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Line axis = Rhino.Geometry.Line.Unset;
            if (DA.GetData("Axis", ref axis))
            {
                if (axis.FromZ > axis.ToZ)
                {
                    axis.Flip();
                }
            }

            FamilySymbol familySymbol = null;

            if (!DA.GetData("FamilyType", ref familySymbol) && Params.Input[1].Sources.Count == 0)
            {
                familySymbol = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultFamilyTypeId(new ElementId(BuiltInCategory.OST_StructuralColumns))) as FamilySymbol;
            }

            if (!familySymbol.IsActive)
            {
                familySymbol.Activate();
            }

            Autodesk.Revit.DB.Level level = null;
            DA.GetData("Level", ref level);
            if (level == null)
            {
                using (var collector = new FilteredElementCollector(Revit.ActiveDBDocument))
                {
                    foreach (var levelN in collector.OfClass(typeof(Level)).ToElements().Cast <Level>().OrderBy(c => c.Elevation))
                    {
                        if (level == null)
                        {
                            level = levelN;
                        }
                        else if (axis.FromZ > levelN.Elevation)
                        {
                            level = levelN;
                        }
                    }
                }
            }

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, familySymbol, level));
        }
  public static Rhino.Commands.Result ObjectDecoration(Rhino.RhinoDoc doc)
  {
    // Define a line
    var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Point3d(10, 0, 0));

    // Make a copy of Rhino's default object attributes
    var attribs = doc.CreateDefaultAttributes();

    // Modify the object decoration style
    attribs.ObjectDecoration = Rhino.DocObjects.ObjectDecoration.BothArrowhead;

    // Create a new curve object with our attributes
    doc.Objects.AddLine(line, attribs);
    doc.Views.Redraw();

    return Rhino.Commands.Result.Success;
  }
    public static Rhino.Commands.Result ObjectDecoration(Rhino.RhinoDoc doc)
    {
        // Define a line
        var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Point3d(10, 0, 0));

        // Make a copy of Rhino's default object attributes
        var attribs = doc.CreateDefaultAttributes();

        // Modify the object decoration style
        attribs.ObjectDecoration = Rhino.DocObjects.ObjectDecoration.BothArrowhead;

        // Create a new curve object with our attributes
        doc.Objects.AddLine(line, attribs);
        doc.Views.Redraw();

        return(Rhino.Commands.Result.Success);
    }
    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;
    }
Exemple #17
0
        void ReconstructColumnByCurve
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Line curve,
            Optional <Autodesk.Revit.DB.FamilySymbol> type,
            Optional <Autodesk.Revit.DB.Level> level
        )
        {
            if (curve.FromZ > curve.ToZ)
            {
                curve.Flip();
            }

            var scaleFactor = 1.0 / Revit.ModelUnits;

            if (scaleFactor != 1.0)
            {
                curve = curve.Scale(scaleFactor);
            }

            if (curve.Length < Revit.ShortCurveTolerance)
            {
                ThrowArgumentException(nameof(curve), "Curve is too short.");
            }

            SolveOptionalType(ref type, doc, BuiltInCategory.OST_StructuralColumns, nameof(type));

            if (!type.Value.IsActive)
            {
                type.Value.Activate();
            }

            SolveOptionalLevel(ref level, doc, curve.FromZ, nameof(level));

            // Type
            ChangeElementTypeId(ref element, type.Value.Id);

            if (element is FamilyInstance familyInstance && element.Location is LocationCurve locationCurve)
            {
                locationCurve.Curve = curve.ToHost();
            }
Exemple #18
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Line line,
            Autodesk.Revit.DB.FamilySymbol familySymbol,
            Autodesk.Revit.DB.Level level
        )
        {
            var element = PreviousElement(doc, Iteration);

            try
            {
                if (element?.Pinned ?? true)
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        line = line.Scale(scaleFactor);
                    }

                    if (line.Length < Revit.ShortCurveTolerance)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is too short.", Params.Input[0].Name));
                    }
                    else if (level == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is mandatory.", Params.Input[2].Name));
                    }
                    else
                    {
                        element = doc.Create.NewFamilyInstance(line.ToHost(), familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Column);
                    }
                }
            }
            catch (Exception e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
            }
            finally
            {
                ReplaceElement(doc, DA, Iteration, element);
            }
        }
    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);
    }
Exemple #20
0
 public ConduitLine(Rhino.Geometry.Line inputline)
 {
     RoadWidth = 4;
     Color     = CommonFunc.colorSetting.GetColorFromValue(RoadWidth);
     line      = inputline;
 }
Exemple #21
0
        public override void DrawViewportWires(Grasshopper.Kernel.IGH_PreviewArgs args)
        {
            if (Hidden)
            {
                return;
            }
            if (listArrow != null)
            {
                args.Display.DrawLines(listArrow, System.Drawing.Color.Red);
            }
            //targetSrf
            if (listPnt != null)
            {
                args.Display.DrawPoints(targetSrf, Rhino.Display.PointStyle.Simple, 1, System.Drawing.Color.White);
            }
            //eigenvectors
            if (crossCyan != null)
            {
                args.Display.DrawLines(crossCyan, System.Drawing.Color.Cyan);
            }
            if (crossMagenta != null)
            {
                args.Display.DrawLines(crossMagenta, System.Drawing.Color.Magenta);
            }
            if (listError != null)
            {
                foreach (var error in listError)
                {
                    args.Display.DrawCurve(error, System.Drawing.Color.Red, 10);
                }
            }

            /*if (listSlice != null)
             * {
             *  foreach (var slice in listSlice.Values)
             *  {
             *      var pl = slice.pl;
             *      args.Display.DrawPolygon(new Rhino.Geometry.Point3d[] { pl.PointAt(-2, -2), pl.PointAt(-2, 2), pl.PointAt(2, 2), pl.PointAt(2, -2) }, System.Drawing.Color.Azure, true);
             *  }
             * }*/
            foreach (var branch in listBranch)
            {
                switch (branch.branchType)
                {
                case Mothra4.branch.type.fix:
                    args.Display.DrawCurve(branch.crv, System.Drawing.Color.Orange, 3);
                    break;

                case Mothra4.branch.type.reinforce:
                    args.Display.DrawCurve(branch.crv, System.Drawing.Color.Cyan, 3);
                    break;

                case Mothra4.branch.type.kink:
                    args.Display.DrawCurve(branch.crv, System.Drawing.Color.Purple, 3);
                    break;

                case Mothra4.branch.type.open:
                    args.Display.DrawCurve(branch.crv, System.Drawing.Color.Green, 3);
                    break;
                }
            }
            foreach (var leaf in listLeaf)
            {
                if (leaf.airySrf != null)
                {
                    var srf = leaf.airySrf.Duplicate() as Rhino.Geometry.NurbsSurface;
                    srf.Transform(zScale);
                    srf.Transform(zDown2);
                    args.Display.DrawSurface(srf, System.Drawing.Color.Brown, 3);
                }
            }
            foreach (var leaf in listLeaf)
            {
                if (leaf.shellSrf != null)
                {
                    var srf = leaf.shellSrf.Duplicate() as Rhino.Geometry.NurbsSurface;
                    srf.Transform(zDown_eq);
                    args.Display.DrawSurface(srf, System.Drawing.Color.Brown, 3);
                }
            }

            /*foreach (var branch in listBranch)
             * {
             *  if (branch.airyCrv != null)
             *  {
             *      var crv = branch.airyCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
             *      crv.Transform(zScale);
             *      args.Display.DrawCurve(crv, System.Drawing.Color.SeaGreen, 4);
             *  }
             * }*/
            foreach (var branch in listBranch)
            {
                if (branch.branchType == branch.type.fix)
                {
                    double x = 0, y = 0, z = branch.slice2.height;
                    for (int i = 0; i < branch.N; i++)
                    {
                        x += branch.crv.Points[i].Location.X;
                        y += branch.crv.Points[i].Location.Y;
                        z += branch.crv.Points[i].Location.Z;
                    }
                    x /= branch.N;
                    y /= branch.N;
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x - 1d, y - 1d, z), new Rhino.Geometry.Point3d(x + 1d, y - 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x - 1d, y - 1d, z), new Rhino.Geometry.Point3d(x - 1d, y + 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x + 1d, y + 1d, z), new Rhino.Geometry.Point3d(x + 1d, y - 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x + 1d, y + 1d, z), new Rhino.Geometry.Point3d(x - 1d, y + 1d, z), System.Drawing.Color.Blue);
                }
                if (branch.branchType == branch.type.open && branch.endTypeL == branch.endtype.fix)
                {
                    double x = branch.crv.Points[0].Location.X;
                    double y = branch.crv.Points[0].Location.Y;
                    double z = branch.sliceL.height;
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x - 1d, y - 1d, z), new Rhino.Geometry.Point3d(x + 1d, y - 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x - 1d, y - 1d, z), new Rhino.Geometry.Point3d(x - 1d, y + 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x + 1d, y + 1d, z), new Rhino.Geometry.Point3d(x + 1d, y - 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x + 1d, y + 1d, z), new Rhino.Geometry.Point3d(x - 1d, y + 1d, z), System.Drawing.Color.Blue);
                }
                if (branch.branchType == branch.type.open && branch.endTypeR == branch.endtype.fix)
                {
                    double x = branch.crv.Points[branch.crv.Points.Count - 1].Location.X;
                    double y = branch.crv.Points[branch.crv.Points.Count - 1].Location.Y;
                    double z = branch.sliceR.height;
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x - 1d, y - 1d, z), new Rhino.Geometry.Point3d(x + 1d, y - 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x - 1d, y - 1d, z), new Rhino.Geometry.Point3d(x - 1d, y + 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x + 1d, y + 1d, z), new Rhino.Geometry.Point3d(x + 1d, y - 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x + 1d, y + 1d, z), new Rhino.Geometry.Point3d(x - 1d, y + 1d, z), System.Drawing.Color.Blue);
                }
            }
            foreach (var branch in listBranch)
            {
                if (branch.shellCrv != null)
                {
                    if (branch.branchType == branch.type.kink || branch.branchType == branch.type.reinforce || branch.branchType == branch.type.open)
                    {
                        var crv = branch.shellCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
                        crv.Transform(zDown_eq);
                        args.Display.DrawCurve(crv, System.Drawing.Color.SeaGreen, 3);
                    }
                }
            }
            //find max value of reinforcement
            if (listBranch != null)
            {
                foreach (var branch in listBranch)
                {
                    if (branch.tuples != null)
                    {
                        if (branch.branchType == branch.type.fix)
                        {
                            foreach (var tup in branch.tuples)
                            {
                                var circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), 0.5);
                                circle.Transform(zDown);
                                args.Display.DrawCircle(circle, System.Drawing.Color.Yellow, 2);
                                circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, branch.slice2.height), 0.5);
                                circle.Transform(zDown_eq);
                                args.Display.DrawCircle(circle, System.Drawing.Color.Yellow, 2);
                            }
                        }
                        else
                        {
                            foreach (var tup in branch.tuples)
                            {
                                var D = tup.SPK[0, 0] / 2d;
                                if (D > 0)
                                {
                                    var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z + D));
                                    line.Transform(zDown);
                                    args.Display.DrawLine(line, System.Drawing.Color.Red, 2);
                                }
                                else
                                {
                                    var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z + D));
                                    line.Transform(zDown);
                                    args.Display.DrawLine(line, System.Drawing.Color.Blue, 2);
                                }
                            }
                        }
                    }
                }
            }

            /*
             * if (a != null)
             * {
             *  args.Display.DrawPoints(a, Rhino.Display.PointStyle.X, 2, System.Drawing.Color.Blue);
             *
             * }*/
            if (a2 != null)
            {
                args.Display.DrawPoints(a2, Rhino.Display.PointStyle.X, 2, System.Drawing.Color.Blue);
            }
        }
Exemple #22
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Line line,
            Autodesk.Revit.DB.FamilySymbol familySymbol,
            Autodesk.Revit.DB.Level level
        )
        {
            var element = PreviousElement(doc, Iteration);

            if (!element?.Pinned ?? false)
            {
                ReplaceElement(doc, DA, Iteration, element);
            }
            else
            {
                try
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        line = line.Scale(scaleFactor);
                    }

                    if (line.Length < Revit.ShortCurveTolerance)
                    {
                        throw new Exception(string.Format("Parameter '{0}' is too short.", Params.Input[0].Name));
                    }

                    if (level == null)
                    {
                        throw new Exception(string.Format("Parameter '{0}' is mandatory.", Params.Input[2].Name));
                    }

                    if (element is FamilyInstance && familySymbol.Id != element.GetTypeId())
                    {
                        var newElmentId = element.ChangeTypeId(familySymbol.Id);
                        if (newElmentId != ElementId.InvalidElementId)
                        {
                            element = doc.GetElement(newElmentId);
                        }
                    }

                    if (element is FamilyInstance familyInstance && element.Location is LocationCurve locationCurve)
                    {
                        locationCurve.Curve = line.ToHost();
                    }
                    else
                    {
                        element = CopyParametersFrom(doc.Create.NewFamilyInstance(line.ToHost(), familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Column), element);
                    }

                    if (line.Direction.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0)
                    {
                        element.get_Parameter(BuiltInParameter.SLANTED_COLUMN_TYPE_PARAM).Set((int)SlantedOrVerticalColumnType.CT_EndPoint);
                    }
                    else
                    {
                        element.get_Parameter(BuiltInParameter.SLANTED_COLUMN_TYPE_PARAM).Set((int)SlantedOrVerticalColumnType.CT_Vertical);
                    }

                    ReplaceElement(doc, DA, Iteration, element);
                }
 /// <summary>
 /// Gets the world coordinate line in the view frustum
 /// that projects to a point on the screen.
 /// </summary>
 /// <param name="screenX">(screenx,screeny) = screen location.</param>
 /// <param name="screenY">(screenx,screeny) = screen location.</param>
 /// <returns>3d world coordinate line segment starting on the near clipping plane and ending on the far clipping plane.</returns>
 Rhino.Geometry.Line GetFrustumLine( double screenX, double screenY)
 {
   Rhino.Geometry.Line line = new Rhino.Geometry.Line();
   IntPtr pConstThis = ConstPointer();
   if (!UnsafeNativeMethods.ON_Viewport_GetFrustumLine(pConstThis, screenX, screenY, ref line))
     line = Rhino.Geometry.Line.Unset;
   return line;
 }
Exemple #24
0
 /// <summary>
 /// Converts a Rhino Line to a SketchUp Edge
 /// </summary>
 public static SketchUpNET.Edge ToSkpGeo(this Rhino.Geometry.Line v)
 {
     return(new SketchUpNET.Edge(v.PointAt(0).ToSkpGeo(), v.PointAt(1.0).ToSkpGeo(), DefaultLayer));
 }
 public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Vector3d V)
 {
     V.Unitize();
     Dir = new Rhino.Geometry.Line(rec, rec + V);
 }
Exemple #26
0
 /// <summary>
 /// Draws the lines in a control polygons.
 /// <para>This is an helper function.</para>
 /// </summary>
 /// <param name="line">Line between two grips.</param>
 /// <param name="startStatus">Index of Grip status at start of line.</param>
 /// <param name="endStatus">Index if Grip status at end of line.</param>
 /// <since>5.0</since>
 public void DrawControlPolygonLine(Rhino.Geometry.Line line, int startStatus, int endStatus)
 {
     DrawControlPolygonLine(line.From, line.To, startStatus, endStatus);
 }
Exemple #27
0
 public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Point3d dir)
 {
     Rhino.Geometry.Vector3d V = rec - dir;
     V.Unitize();
     Dir = new Rhino.Geometry.Line(rec, rec + dir);
 }
Exemple #28
0
        private string getInputs(GH_Component ThisComponent, IGH_DataAccess DA, int i)
        {
            string datahere  = "";
            string paramType = "";

            try
            {
                if (ThisComponent.Params.Input[i].Access == GH_ParamAccess.item)
                {
                    convetToItem(ThisComponent, i, DA);
                    IGH_Goo inputObject = null;
                    DA.GetData(i, ref inputObject);
                    paramType = inputObject.GetType().ToString();

                    if (paramType == "Grasshopper.Kernel.Types.GH_Line")
                    {
                        convetToItem(ThisComponent, i, DA);
                        Rhino.Geometry.Line inputLine = Rhino.Geometry.Line.Unset;
                        DA.GetData(i, ref inputLine);
                        datahere = "\"gCPy.Line(" + inputLine.FromX.ToString() + ", "
                                   + inputLine.FromY.ToString() + ", "
                                   + inputLine.FromZ.ToString() + ", "
                                   + inputLine.ToX.ToString() + ", "
                                   + inputLine.ToY.ToString() + ", "
                                   + inputLine.ToZ.ToString() + ")\"";
                    }
                    else if
                    (paramType == "Grasshopper.Kernel.Types.GH_Point")
                    {
                        convetToItem(ThisComponent, i, DA);
                        Rhino.Geometry.Point3d inputPoint = Rhino.Geometry.Point3d.Unset;
                        DA.GetData(i, ref inputPoint);
                        datahere = "\"gCPy.Point(" + inputPoint.X.ToString() + ", "
                                   + inputPoint.Y.ToString() + ", "
                                   + inputPoint.Z.ToString() + ")\"";
                    }
                    else if (paramType == "Grasshopper.Kernel.Types.GH_Circle")
                    {
                        convetToItem(ThisComponent, i, DA);
                        Rhino.Geometry.Circle inputCircle = Rhino.Geometry.Circle.Unset;
                        DA.GetData(i, ref inputCircle);
                        datahere = "\"gCPy.Circle(" + inputCircle.Center.X.ToString() + ","     // xpos
                                   + inputCircle.Center.Y.ToString() + ","                      // ypos
                                   + inputCircle.Center.Z.ToString() + ","                      // zpos
                                   + inputCircle.Radius.ToString() + ","                        // radius
                                   + inputCircle.Plane.XAxis.ToString() + ","                   // x axis vector0 , x axis vector1 , x axis vector 2
                                   + inputCircle.Plane.YAxis.ToString() + ","                   // y axis vector
                                   + inputCircle.Plane.ZAxis.ToString() + ")\"";                // z axis vector
                    }
                    else if (paramType == "Grasshopper.Kernel.Types.GH_Curve")
                    {
                        datahere += "\"Ok This is a curve ... Take Care .. add all your things here\"";
                    }
                    else if (paramType == "Grasshopper.Kernel.Types.GH_String")
                    {
                        convetToItem(ThisComponent, i, DA);
                        string inputString = string.Empty;
                        DA.GetData(i, ref inputString);
                        datahere = "\"" + inputString.Replace(Environment.NewLine, "\\n").Replace("'", @"\'").Replace("\"", "\\\\" + "\"").Replace("\\n", "\\\\n") + "\"";
                    }
                    else if (paramType == "Grasshopper.Kernel.Types.GH_Integer")
                    {
                        convetToItem(ThisComponent, i, DA);
                        int inputInt = 0;
                        DA.GetData(i, ref inputInt);
                        datahere = inputInt.ToString();
                    }
                    else if (paramType == "Grasshopper.Kernel.Types.GH_Number")
                    {
                        convetToItem(ThisComponent, i, DA);
                        double inputNum = 0.0;
                        DA.GetData(i, ref inputNum);
                        datahere = inputNum.ToString();
                    }
                    else if (paramType == "Grasshopper.Kernel.Types.GH_Boolean")
                    {
                        convetToItem(ThisComponent, i, DA);
                        bool inputBool = false;
                        DA.GetData(i, ref inputBool);
                        datahere = inputBool ? "True" : "False";
                    }
                    else
                    {
                        datahere = "None";
                    }
                }
                else
                {
                    string thisInputString = ThisComponent.Params.Input[i].VolatileData.DataDescription(false, false).Trim().Replace(System.Environment.NewLine, ",");
                    datahere = recomposeInputString(thisInputString);
                }
            }
            catch (Exception errf)
            { //MessageBox.Show(errf.ToString());
            }

            return(datahere);
        }
Exemple #29
0
 public ConduitLine(Rhino.Geometry.Line inputline, int roadWidth)
 {
     this.RoadWidth = roadWidth / 1000;
     Color          = CommonFunc.colorSetting.GetColorFromValue(RoadWidth);
     line           = inputline;
 }
Exemple #30
0
 public bool SolveOptionalLevel(DB.Document doc, Rhino.Geometry.Line line, ref Optional <DB.Level> level, out Rhino.Geometry.BoundingBox bbox)
 {
     bbox = line.BoundingBox;
     return(SolveOptionalLevel(doc, bbox.IsValid ? bbox.Min.Z : double.NaN, ref level));
 }
Exemple #31
0
        public override void BakeGeometry(Rhino.RhinoDoc doc, Rhino.DocObjects.ObjectAttributes att, List<Guid> obj_ids)
        {
            Rhino.Geometry.Transform zDown_airy = Rhino.Geometry.Transform.Translation(0, 0, 2d);
            Rhino.DocObjects.ObjectAttributes a2 = att.Duplicate();
            a2.LayerIndex = 2;
            Rhino.DocObjects.ObjectAttributes a3 = att.Duplicate();
            a3.LayerIndex = 3;
            Rhino.DocObjects.ObjectAttributes a4 = att.Duplicate();
            a4.LayerIndex = 4;
            Rhino.DocObjects.ObjectAttributes a5 = att.Duplicate();
            a5.LayerIndex = 5;
            Rhino.DocObjects.ObjectAttributes a6 = att.Duplicate();
            a6.LayerIndex = 6;
            Rhino.DocObjects.ObjectAttributes a7 = att.Duplicate();
            a7.LayerIndex = 7;
            foreach (var leaf in listLeaf)
            {
                var airySrf=leaf.airySrf.Duplicate() as Rhino.Geometry.NurbsSurface;
                airySrf.Transform(zScale);
                airySrf.Transform(zDown_airy);
                Guid id = doc.Objects.AddSurface(airySrf, a2);
                obj_ids.Add(id);
                var srf = leaf.shellSrf.Duplicate() as Rhino.Geometry.NurbsSurface;
                srf.Transform(zDown_eq);
                id = doc.Objects.AddSurface(srf, a3);
                obj_ids.Add(id);
            }
            foreach (var branch in listBranch)
            {
                //var airyCrv=branch.airyCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
                //airyCrv.Transform(zDown_airy);
                //Guid id = doc.Objects.AddCurve(airyCrv, a2);
                //obj_ids.Add(id);
                if (branch.branchType == branch.type.kink || branch.branchType == branch.type.reinforce||branch.branchType == branch.type.open)
                {
                    var crv = branch.shellCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
                    crv.Transform(zDown_eq);
                    Guid id = doc.Objects.AddCurve(crv, a7);
                    obj_ids.Add(id);
                }
            }
            if (crossMagenta != null)
            {
                foreach (var line in crossMagenta)
                {
                    Guid id = doc.Objects.AddLine(line, a4);
                    obj_ids.Add(id);
                }
            }
            if (listBranch != null)
            {
                foreach (var branch in listBranch)
                {
                    if (branch.branchType == branch.type.fix)
                    {
                        if (branch.tuples != null)
                        {
                            foreach (var tup in branch.tuples)
                            {
                                var circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), 0.5);
                                circle.Transform(zDown);
                                Guid id = doc.Objects.AddCircle(circle, a6);
                                obj_ids.Add(id);
                                circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, branch.slice2.height), 0.5);
                                circle.Transform(zDown_eq);
                                id = doc.Objects.AddCircle(circle, a6);
                                obj_ids.Add(id);
                            }
                        }
                    }
                    if (branch.branchType == branch.type.kink || branch.branchType == branch.type.reinforce||branch.branchType==branch.type.open)
                    {
                        if (branch.tuples != null)
                        {
                            foreach (var tup in branch.tuples)
                            {
                                var D = tup.SPK[0, 0]/2d;
                                if (D > 0)
                                {
                                    var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z + D));
                                    line.Transform(zDown);
                                    Guid id = doc.Objects.AddLine(line, a5);
                                    obj_ids.Add(id);
                                }
                            }
                        }
                    }

                }
            }
        }
 public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Point3d dir)
 {
     Rhino.Geometry.Vector3d V = rec - dir;
     V.Unitize();
     Dir = new Rhino.Geometry.Line(rec, rec + dir);
 }
Exemple #33
0
 public override void BakeGeometry(Rhino.RhinoDoc doc, Rhino.DocObjects.ObjectAttributes att, List <Guid> obj_ids)
 {
     Rhino.Geometry.Transform          zDown_airy = Rhino.Geometry.Transform.Translation(0, 0, 2d);
     Rhino.DocObjects.ObjectAttributes a2         = att.Duplicate();
     a2.LayerIndex = 2;
     Rhino.DocObjects.ObjectAttributes a3 = att.Duplicate();
     a3.LayerIndex = 3;
     Rhino.DocObjects.ObjectAttributes a4 = att.Duplicate();
     a4.LayerIndex = 4;
     Rhino.DocObjects.ObjectAttributes a5 = att.Duplicate();
     a5.LayerIndex = 5;
     Rhino.DocObjects.ObjectAttributes a6 = att.Duplicate();
     a6.LayerIndex = 6;
     Rhino.DocObjects.ObjectAttributes a7 = att.Duplicate();
     a7.LayerIndex = 7;
     foreach (var leaf in listLeaf)
     {
         var airySrf = leaf.airySrf.Duplicate() as Rhino.Geometry.NurbsSurface;
         airySrf.Transform(zScale);
         airySrf.Transform(zDown_airy);
         Guid id = doc.Objects.AddSurface(airySrf, a2);
         obj_ids.Add(id);
         var srf = leaf.shellSrf.Duplicate() as Rhino.Geometry.NurbsSurface;
         srf.Transform(zDown_eq);
         id = doc.Objects.AddSurface(srf, a3);
         obj_ids.Add(id);
     }
     foreach (var branch in listBranch)
     {
         //var airyCrv=branch.airyCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
         //airyCrv.Transform(zDown_airy);
         //Guid id = doc.Objects.AddCurve(airyCrv, a2);
         //obj_ids.Add(id);
         if (branch.branchType == branch.type.kink || branch.branchType == branch.type.reinforce)
         {
             var crv = branch.shellCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
             crv.Transform(zDown_eq);
             Guid id = doc.Objects.AddCurve(crv, a7);
             obj_ids.Add(id);
         }
     }
     if (crossMagenta != null)
     {
         foreach (var line in crossMagenta)
         {
             Guid id = doc.Objects.AddLine(line, a4);
             obj_ids.Add(id);
         }
     }
     if (listBranch != null)
     {
         foreach (var branch in listBranch)
         {
             if (branch.branchType == branch.type.fix)
             {
                 if (branch.tuples != null)
                 {
                     foreach (var tup in branch.tuples)
                     {
                         var circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), 0.5);
                         circle.Transform(zDown);
                         Guid id = doc.Objects.AddCircle(circle, a6);
                         obj_ids.Add(id);
                         circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, branch.slice2.height), 0.5);
                         circle.Transform(zDown_eq);
                         id = doc.Objects.AddCircle(circle, a6);
                         obj_ids.Add(id);
                     }
                 }
             }
             if (branch.branchType == branch.type.kink || branch.branchType == branch.type.reinforce)
             {
                 if (branch.tuples != null)
                 {
                     foreach (var tup in branch.tuples)
                     {
                         var D = tup.SPK[0, 0] / 2d;
                         if (D > 0)
                         {
                             var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z + D));
                             line.Transform(zDown);
                             Guid id = doc.Objects.AddLine(line, a5);
                             obj_ids.Add(id);
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #34
0
 public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Vector3d V)
 {
     V.Unitize();
     Dir = new Rhino.Geometry.Line(rec, rec + V);
 }
Exemple #35
0
 /// <summary>
 /// Draws the lines in a control polygons.
 /// <para>This is an helper function.</para>
 /// </summary>
 /// <param name="line">Line between two grips.</param>
 /// <param name="startStatus">Grip status at start of line.</param>
 /// <param name="endStatus">Grip status at end of line.</param>
 /// <since>5.0</since>
 public void DrawControlPolygonLine(Rhino.Geometry.Line line, GripStatus startStatus, GripStatus endStatus)
 {
     DrawControlPolygonLine(line, startStatus.m_index, endStatus.m_index);
 }
Exemple #36
0
        void RhinoApp_KeyboardEvent(int key)
        {
            //Debug.WriteLine(key);

            //myKeyPressed = key == 16;

            //return;
            if (key == 17) // ctrl key pressed
            {
                Rhino.RhinoApp.WriteLine("Fire");

                System.Drawing.Point myloc = System.Windows.Forms.Cursor.Position;
                Rhino.UI.MouseCursor.SetToolTip("heywassup");
                //Rhino.RhinoApp.WriteLine(myloc.X.ToString()+","+myloc.Y.ToString());
                Rhino.Display.RhinoView  myViewport       = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;
                System.Drawing.Rectangle view_screen_rect = myViewport.ScreenRectangle;

                double XCoor = myloc.X - view_screen_rect.Left;
                double YCoor = myloc.Y - view_screen_rect.Top;
                //Rhino.RhinoApp.WriteLine(XCoor + "," + YCoor);


                Rhino.Display.RhinoViewport viewport          = myViewport.ActiveViewport;
                System.Drawing.Point        view_client_point = new System.Drawing.Point();
                view_client_point.X = (int)XCoor;
                view_client_point.Y = (int)YCoor;

                Rhino.Geometry.Line myLine = new Rhino.Geometry.Line();
                bool gotline = viewport.GetFrustumLine(view_client_point.X, view_client_point.Y, out myLine);
                if (gotline == true)
                {
                    List <Guid> myGuids        = myInterop.allGuids;
                    List <Guid> myHoveredGuids = new List <Guid>();

                    foreach (Guid guid in myGuids)
                    {
                        Rhino.DocObjects.RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid);
                        Rhino.Geometry.Curve[]       myCrvs;
                        Rhino.Geometry.Point3d[]     myPts;
                        bool cbx = Rhino.Geometry.Intersect.Intersection.CurveBrep(myLine.ToNurbsCurve(), foundObject.Geometry.GetBoundingBox(true).ToBrep(), 0.01, out myCrvs, out myPts);
                        if (myPts.Length > 0)
                        {
                            myHoveredGuids.Add(foundObject.Id);
                        }
                    }

                    if (myHoveredGuids.Count > 0)
                    {
                        List <double> allDists = new List <double>();
                        foreach (Guid guid in myHoveredGuids)
                        {
                            Rhino.DocObjects.RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid);
                            Rhino.Geometry.Point3d       myCe        = foundObject.Geometry.GetBoundingBox(true).Center;
                            double dist = myLine.To.DistanceTo(myCe);
                            allDists.Add(dist);
                        }
                        var sorted = allDists
                                     .Select((x, i) => new KeyValuePair <double, int>(x, i))
                                     .OrderBy(x => x.Key)
                                     .ToList();

                        List <double> B   = sorted.Select(x => x.Key).ToList();
                        List <int>    idx = sorted.Select(x => x.Value).ToList();
                        Rhino.RhinoApp.WriteLine(myHoveredGuids[idx[0]].ToString());
                        RhinoApp.Idle += OnIdleHover;
                    }
                    else
                    {
                        Rhino.RhinoApp.WriteLine("C'est la dech");
                    }
                }
                else
                {
                    Rhino.RhinoApp.WriteLine("no keys");
                }
            }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select curve to intersect");
            go.GeometryFilter = ObjectType.Curve;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

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

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

            var gp = new GetPoint();

            gp.SetCommandPrompt("First point of infinite intersecting line");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var from = gp.Point();

            gp.SetCommandPrompt("Second point of infinite intersecting line");
            gp.SetBasePoint(from, true);
            gp.DrawLineFromPoint(from, true);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var line = new Rhino.Geometry.Line(from, gp.Point());

            if (!line.IsValid || line.Length < Rhino.RhinoMath.SqrtEpsilon)
            {
                return(Result.Nothing);
            }

            var ccx = IntersectCurveLine(curve, line, doc.ModelAbsoluteTolerance, doc.ModelAbsoluteTolerance);

            if (null != ccx)
            {
                foreach (var x in ccx)
                {
                    if (x.IsPoint)
                    {
                        doc.Objects.AddPoint(x.PointA);
                    }
                }
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Exemple #38
0
        public override void DrawViewportWires(Grasshopper.Kernel.IGH_PreviewArgs args)
        {
            if (Hidden)
            {
                return;
            }
            if (listArrow != null)
            {
                args.Display.DrawLines(listArrow, System.Drawing.Color.Red);
            }
            //targetSrf
            if (listPnt != null)
            {
                args.Display.DrawPoints(targetSrf, Rhino.Display.PointStyle.Simple, 1, System.Drawing.Color.White);
            }
            //eigenvectors
            if (crossCyan != null)
            {
                args.Display.DrawLines(crossCyan, System.Drawing.Color.Cyan);
            }
            if (crossMagenta != null)
            {
                args.Display.DrawLines(crossMagenta, System.Drawing.Color.Magenta);
            }
            if (listError != null)
            {
                foreach (var error in listError)
                {
                    args.Display.DrawCurve(error, System.Drawing.Color.Red, 10);
                }
            }
            /*if (listSlice != null)
            {
                foreach (var slice in listSlice.Values)
                {
                    var pl = slice.pl;
                    args.Display.DrawPolygon(new Rhino.Geometry.Point3d[] { pl.PointAt(-2, -2), pl.PointAt(-2, 2), pl.PointAt(2, 2), pl.PointAt(2, -2) }, System.Drawing.Color.Azure, true);
                }
            }*/
            foreach (var branch in listBranch)
            {
                switch (branch.branchType)
                {
                    case Mothra4.branch.type.fix:
                        args.Display.DrawCurve(branch.crv, System.Drawing.Color.Orange, 3);
                        break;
                    case Mothra4.branch.type.reinforce:
                        args.Display.DrawCurve(branch.crv, System.Drawing.Color.Cyan, 3);
                        break;
                    case Mothra4.branch.type.kink:
                        args.Display.DrawCurve(branch.crv, System.Drawing.Color.Purple, 3);
                        break;
                    case Mothra4.branch.type.open:
                        args.Display.DrawCurve(branch.crv, System.Drawing.Color.Green, 3);
                        break;
                }
            }
            foreach (var leaf in listLeaf)
            {
                if (leaf.airySrf != null)
                {
                    var srf = leaf.airySrf.Duplicate() as Rhino.Geometry.NurbsSurface;
                    srf.Transform(zScale);
                    args.Display.DrawSurface(srf, System.Drawing.Color.Brown, 3);
                }
            }
            foreach (var leaf in listLeaf)
            {
                if (leaf.shellSrf != null)
                {
                    var srf = leaf.shellSrf.Duplicate() as Rhino.Geometry.NurbsSurface;
                    srf.Transform(zDown_eq);
                    args.Display.DrawSurface(srf, System.Drawing.Color.Brown, 3);
                }
            }
            /*foreach (var branch in listBranch)
            {
                if (branch.airyCrv != null)
                {
                    var crv = branch.airyCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
                    crv.Transform(zScale);
                    args.Display.DrawCurve(crv, System.Drawing.Color.SeaGreen, 4);
                }
            }*/
            foreach (var branch in listBranch)
            {
                if (branch.branchType == branch.type.fix)
                {
                    double x = 0, y = 0, z = branch.slice2.height;
                    for (int i = 0; i < branch.N; i++)
                    {
                        x += branch.crv.Points[i].Location.X;
                        y += branch.crv.Points[i].Location.Y;
                        z += branch.crv.Points[i].Location.Z;
                    }
                    x /= branch.N;
                    y /= branch.N;
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x - 1d, y - 1d, z), new Rhino.Geometry.Point3d(x + 1d, y - 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x - 1d, y - 1d, z), new Rhino.Geometry.Point3d(x - 1d, y + 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x + 1d, y + 1d, z), new Rhino.Geometry.Point3d(x + 1d, y - 1d, z), System.Drawing.Color.Blue);
                    args.Display.DrawLine(new Rhino.Geometry.Point3d(x + 1d, y + 1d, z), new Rhino.Geometry.Point3d(x - 1d, y + 1d, z), System.Drawing.Color.Blue);
                }
            }
            foreach (var branch in listBranch)
            {
                if (branch.shellCrv != null)
                {
                    if (branch.branchType == branch.type.kink || branch.branchType == branch.type.reinforce || branch.branchType == branch.type.open)
                    {

                        var crv = branch.shellCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
                        crv.Transform(zDown_eq);
                        args.Display.DrawCurve(crv, System.Drawing.Color.SeaGreen, 3);
                    }
                }
            }
            //find max value of reinforcement
            if (listBranch != null)
            {
                foreach (var branch in listBranch)
                {
                    if (branch.tuples != null)
                    {
                        if (branch.branchType == branch.type.fix)
                        {
                            foreach (var tup in branch.tuples)
                            {
                                var circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), 0.5);
                                circle.Transform(zDown);
                                args.Display.DrawCircle(circle, System.Drawing.Color.Yellow, 2);
                                circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, branch.slice2.height), 0.5);
                                circle.Transform(zDown_eq);
                                args.Display.DrawCircle(circle, System.Drawing.Color.Yellow, 2);
                            }
                        }
                        else
                        {
                            foreach (var tup in branch.tuples)
                            {
                                var D = tup.SPK[0, 0]/2d;
                                if (D > 0)
                                {
                                    var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z + D));
                                    line.Transform(zDown);
                                    args.Display.DrawLine(line, System.Drawing.Color.Red, 2);
                                }
                                else
                                {
                                    var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z + D));
                                    line.Transform(zDown);
                                    args.Display.DrawLine(line, System.Drawing.Color.Blue, 2);
                                }
                            }
                        }
                    }
                }
            }

            /*
            if (a != null)
            {
                args.Display.DrawPoints(a, Rhino.Display.PointStyle.X, 2, System.Drawing.Color.Blue);

            }*/
            if (a2 != null)
            {
                args.Display.DrawPoints(a2, Rhino.Display.PointStyle.X, 2, System.Drawing.Color.Blue);

            }
        }