示例#1
0
        /// <summary>
        /// DS Ellipse to SpeckleEllipse
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public Ellipse EllipseToSpeckle(DS.Ellipse e)
        {
            using (DS.Plane basePlane = DS.Plane.ByOriginNormalXAxis(e.CenterPoint, e.Normal, e.MajorAxis))
            {
                var ellipse = new Ellipse(
                    PlaneToSpeckle(basePlane),
                    e.MajorAxis.Length,
                    e.MinorAxis.Length,
                    new Interval(e.StartParameter(), e.EndParameter()),
                    null,
                    ModelUnits);

                CopyProperties(ellipse, e);
                return(ellipse);
            }
        }
        public Base CurveToSpeckle(DS.Curve curve, string units = null)
        {
            var  u = units ?? ModelUnits;
            Base speckleCurve;

            if (curve.IsLinear())
            {
                using (DS.Line line = curve.GetAsLine())
                {
                    speckleCurve = LineToSpeckle(line, u);
                }
            }
            else if (curve.IsArc())
            {
                using (DS.Arc arc = curve.GetAsArc())
                {
                    speckleCurve = ArcToSpeckle(arc, u);
                }
            }
            else if (curve.IsCircle())
            {
                using (DS.Circle circle = curve.GetAsCircle())
                {
                    speckleCurve = CircleToSpeckle(circle, u);
                }
            }
            else if (curve.IsEllipse())
            {
                using (DS.Ellipse ellipse = curve.GetAsEllipse())
                {
                    speckleCurve = EllipseToSpeckle(ellipse, u);
                }
            }
            else
            {
                speckleCurve = CurveToSpeckle(curve.ToNurbsCurve(), u);
            }

            CopyProperties(speckleCurve, curve);
            return(speckleCurve);
        }
示例#3
0
        public Base CurveToSpeckle(DS.Curve curve)
        {
            Base speckleCurve;

            if (curve.IsLinear())
            {
                using (DS.Line line = curve.GetAsLine())
                {
                    speckleCurve = LineToSpeckle(line);
                }
            }
            else if (curve.IsArc())
            {
                using (DS.Arc arc = curve.GetAsArc())
                {
                    speckleCurve = ArcToSpeckle(arc);
                }
            }
            else if (curve.IsCircle())
            {
                using (DS.Circle circle = curve.GetAsCircle())
                {
                    speckleCurve = CircleToSpeckle(circle);
                }
            }
            else if (curve.IsEllipse())
            {
                using (DS.Ellipse ellipse = curve.GetAsEllipse())
                {
                    speckleCurve = EllipseToSpeckle(ellipse);
                }
            }
            else
            {
                speckleCurve = CurveToSpeckle(curve.ToNurbsCurve());
            }

            CopyProperties(speckleCurve, curve);
            return(speckleCurve);
        }
        /// <summary>
        /// DS Ellipse to SpeckleEllipse
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public Ellipse EllipseToSpeckle(DS.Ellipse e, string units = null)
        {
            var u = units ?? ModelUnits;

            using (DS.Plane basePlane = DS.Plane.ByOriginNormalXAxis(e.CenterPoint, e.Normal, e.MajorAxis))
            {
                var ellipse = new Ellipse(
                    PlaneToSpeckle(basePlane, u),
                    e.MajorAxis.Length,
                    e.MinorAxis.Length,
                    new Interval(e.StartParameter(), e.EndParameter()),
                    null,
                    u);

                CopyProperties(ellipse, e);

                ellipse.length = e.Length;
                ellipse.bbox   = BoxToSpeckle(e.BoundingBox.ToCuboid(), u);

                return(ellipse);
            }
        }
        public Base CurveToSpeckle(NurbsCurve curve, string units = null)
        {
            var  u = units ?? ModelUnits;
            Base speckleCurve;

            if (curve.IsLinear())
            {
                using (DS.Line line = curve.GetAsLine())
                {
                    speckleCurve = LineToSpeckle(line, u);
                }
            }
            else if (curve.IsArc())
            {
                using (DS.Arc arc = curve.GetAsArc())
                {
                    speckleCurve = ArcToSpeckle(arc, u);
                }
            }
            else if (curve.IsCircle())
            {
                using (DS.Circle circle = curve.GetAsCircle())
                {
                    speckleCurve = CircleToSpeckle(circle, u);
                }
            }
            else if (curve.IsEllipse())
            {
                using (DS.Ellipse ellipse = curve.GetAsEllipse())
                {
                    speckleCurve = EllipseToSpeckle(ellipse, u);
                }
            }
            else
            {
                // SpeckleCurve DisplayValue
                DS.Curve[]    curves = curve.ApproximateWithArcAndLineSegments();
                List <double> polylineCoordinates =
                    curves.SelectMany(c => PointListToFlatArray(new DS.Point[2] {
                    c.StartPoint, c.EndPoint
                })).ToList();
                polylineCoordinates.AddRange(PointToArray(curves.Last().EndPoint));
                curves.ForEach(c => c.Dispose());

                Polyline      displayValue = new Polyline(polylineCoordinates, u);
                List <double> dsKnots      = curve.Knots().ToList();
                dsKnots.RemoveAt(dsKnots.Count - 1);
                dsKnots.RemoveAt(0);

                Curve spkCurve = new Curve(displayValue, u);
                spkCurve.weights  = curve.Weights().ToList();
                spkCurve.points   = PointListToFlatArray(curve.ControlPoints()).ToList();
                spkCurve.knots    = dsKnots;
                spkCurve.degree   = curve.Degree;
                spkCurve.periodic = curve.IsPeriodic;
                spkCurve.rational = curve.IsRational;
                spkCurve.closed   = curve.IsClosed;
                spkCurve.domain   = new Interval(curve.StartParameter(), curve.EndParameter());
                //spkCurve.Properties

                //spkCurve.GenerateHash();
                spkCurve.length = curve.Length;
                spkCurve.bbox   = BoxToSpeckle(curve.BoundingBox.ToCuboid(), u);

                speckleCurve = spkCurve;
            }

            CopyProperties(speckleCurve, curve);
            return(speckleCurve);
        }