Exemple #1
0
        static IEnumerable <NXOpen.Curve> ToEdgeCurveMany(Curve curve)
        {
            switch (curve)
            {
            case LineCurve lineCurve:

                yield return(ToEdgeCurve(lineCurve));

                yield break;

            case PolylineCurve polylineCurve:

                foreach (var line in ToEdgeCurveMany(polylineCurve))
                {
                    yield return(line);
                }
                yield break;

            case ArcCurve arcCurve:

                foreach (var arc in ToEdgeCurveMany(arcCurve))
                {
                    yield return(arc);
                }
                yield break;

            case PolyCurve polyCurve:

                foreach (var segment in ToEdgeCurveMany(polyCurve))
                {
                    yield return(segment);
                }
                yield break;

            case NurbsCurve nurbsCurve:

                foreach (var nurbs in CurveEncoder.ToNXCurves(nurbsCurve, UnitConverter.NoScale))
                {
                    yield return(nurbs);
                }
                yield break;

            default:
                if (curve.HasNurbsForm() != 0)
                {
                    var nurbsForm = curve.ToNurbsCurve();
                    foreach (var c in CurveEncoder.ToNXCurves(nurbsForm, UnitConverter.NoScale))
                    {
                        yield return(c);
                    }
                }
                else
                {
                    throw new Exception($"Unable to convert {curve} to DB.Curve");
                }
                yield break;
            }
        }
        public static NXOpen.DisplayableObject[] ToShape(this GeometryBase geometry, double factor)
        {
            switch (geometry)
            {
            case Point point:
                return(new NXOpen.DisplayableObject[] { point.ToPoint(factor) });

            case PointCloud pointCloud:
                return(pointCloud.ToPoints(factor));

            case Curve curve:
                return(CurveEncoder.ToNXCurves(curve, factor).OfType <NXOpen.DisplayableObject>().ToArray());

            //case Brep brep:
            //  return ToGeometryObjectMany(BrepEncoder.ToRawBrep(brep, factor)).OfType<NXOpen.GeometryObject>().ToArray();

            //case Extrusion extrusion:
            //  return ToGeometryObjectMany(ExtrusionEncoder.ToRawBrep(extrusion, factor)).OfType<NXOpen.GeometryObject>().ToArray();

            //case SubD subD:
            //  return ToGeometryObjectMany(SubDEncoder.ToRawBrep(subD, factor)).OfType<NXOpen.GeometryObject>().ToArray(); ;

            //case Mesh mesh:
            //  return new NXOpen.GeometryObject[] { MeshEncoder.ToMesh(MeshEncoder.ToRawMesh(mesh, factor)) };

            default:
                //if (geometry.HasBrepForm)
                //{
                //  var brepForm = Brep.TryConvertBrep(geometry);
                //  if (BrepEncoder.EncodeRaw(ref brepForm, factor))
                //    return ToGeometryObjectMany(brepForm).OfType<NXOpen.GeometryObject>().ToArray();
                //}

                return(new NXOpen.DisplayableObject[0]);
            }
        }
Exemple #3
0
        public static IEnumerable <NXOpen.Curve> ToNXCurves(NurbsCurve value, double factor)
        {
            if (value.Degree == 1)
            {
                var curvePoints = value.Points;
                int pointCount  = curvePoints.Count;
                if (pointCount > 1)
                {
                    NXOpen.Point3d end, start = curvePoints[0].Location.ToXYZ(factor);
                    for (int p = 1; p < pointCount; start = end, ++p)
                    {
                        end = curvePoints[p].Location.ToXYZ(factor);
                        yield return(WorkPart.Curves.CreateLine(start, end));
                    }
                }
            }
            else if (value.Degree == 2)
            {
                for (int s = 0; s < value.SpanCount; ++s)
                {
                    var segment = value.Trim(value.SpanDomain(s)) as NurbsCurve;
                    yield return(CurveEncoder.ToNXSpline(segment, factor));
                }
            }
            else if (value.IsClosable(DistanceTolerance * 1.01))
            {
                var segments = value.DuplicateSegments();
                if (segments.Length == 1)
                {
                    if
                    (
                        value.NormalizedLengthParameter(0.5, out var mid) &&
                        value.Split(mid) is Curve[] half
                    )
                    {
                        yield return((half[0] as NurbsCurve).ToNXSpline(factor));

                        yield return((half[1] as NurbsCurve).ToNXSpline(factor));
                    }
                    else
                    {
                        throw new Exception("Failed to Split closed Edge");
                    }
                }
                else
                {
                    foreach (var segment in segments)
                    {
                        yield return((segment as NurbsCurve).ToNXSpline(factor));
                    }
                }
            }
            else if (value.GetNextDiscontinuity(Continuity.C1_continuous, value.Domain.Min, value.Domain.Max, out var t))
            {
                var splitters = new List <double>()
                {
                    t
                };
                while (value.GetNextDiscontinuity(Continuity.C1_continuous, t, value.Domain.Max, out t))
                {
                    splitters.Add(t);
                }

                var segments = value.Split(splitters);
                foreach (var segment in segments.Cast <NurbsCurve>())
                {
                    yield return(CurveEncoder.ToNXSpline(segment, factor));
                }
            }
            else
            {
                yield return(CurveEncoder.ToNXSpline(value, factor));
            }
        }