Exemplo n.º 1
0
        /***************************************************/

        public static BHG.ICurve FromRhino(this RHG.Curve rCurve)
        {
            if (rCurve == null)
            {
                return(null);
            }

            Type curveType = rCurve.GetType();

            if (rCurve.IsLinear() && rCurve.SpanCount < 2)
            {
                return(new BHG.Line {
                    Start = rCurve.PointAtStart.FromRhino(), End = rCurve.PointAtEnd.FromRhino(), Infinite = false
                });
            }
            if (rCurve.IsCircle())
            {
                RHG.Circle circle = new RHG.Circle();
                rCurve.TryGetCircle(out circle);
                return(circle.FromRhino());
            }
            else if (rCurve.IsArc() || typeof(RHG.ArcCurve).IsAssignableFrom(curveType))
            {
                RHG.Arc arc = new RHG.Arc();
                rCurve.TryGetArc(out arc);
                return(arc.FromRhino());
            }
            else if (rCurve.IsPolyline() || typeof(RHG.PolylineCurve).IsAssignableFrom(curveType))
            {
                RHG.Polyline polyline = new RHG.Polyline();
                rCurve.TryGetPolyline(out polyline);
                return(polyline.FromRhino());
            }
            else if (rCurve.IsClosed && rCurve.IsEllipse())
            {
                RHG.Ellipse ellipse = new RHG.Ellipse();
                rCurve.TryGetEllipse(out ellipse);
                return(ellipse.FromRhino());
            }
            else if (rCurve is RHG.NurbsCurve)
            {
                return(((RHG.NurbsCurve)rCurve).FromRhino());
            }
            else if (rCurve is RHG.PolyCurve)
            {
                return(((RHG.PolyCurve)rCurve).FromRhino());  //The test of IsPolyline above is very important to make sure we can cast to PolyCurve here
            }
            else
            {
                return((rCurve.ToNurbsCurve()).FromRhino());
            }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select curves");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.Geometry.Curve curve = go.Object(i).Curve();
                if (null == curve)
                {
                    return(Result.Failure);
                }

                if (curve is LineCurve)
                {
                    RhinoApp.WriteLine("Curve {0} is a line.", i);
                }
                else if (curve is ArcCurve)
                {
                    if (curve.IsClosed)
                    {
                        RhinoApp.WriteLine("Curve {0} is a circle.", i);
                    }
                    else
                    {
                        RhinoApp.WriteLine("Curve {0} is an arc.", i);
                    }
                }
                else if (curve is PolylineCurve)
                {
                    RhinoApp.WriteLine("Curve {0} is a polyline.", i);
                }
                else if (curve is PolyCurve)
                {
                    RhinoApp.WriteLine("Curve {0} is a polycurve.", i);
                }
                else if (curve is NurbsCurve)
                {
                    if (curve.IsEllipse())
                    {
                        if (curve.IsClosed)
                        {
                            RhinoApp.WriteLine("Curve {0} is an ellipse.", i);
                        }
                        else
                        {
                            RhinoApp.WriteLine("Curve {0} is an elliptical arc.", i);
                        }
                    }
                    else
                    {
                        RhinoApp.WriteLine("Curve {0} is a NURBS curve.", i);
                    }
                }
                else
                {
                    RhinoApp.WriteLine("Curve {0} is an unknown type.", i);
                }
            }

            return(Result.Success);
        }