Example #1
0
        private bool IsHole(IFace2 face)
        {
            ISurface surf = face.IGetSurface();

            if (surf.IsCylinder())
            {
                double[] uvBounds = face.GetUVBounds() as double[];

                double[] evalData = surf.Evaluate((uvBounds[1] - uvBounds[0]) / 2, (uvBounds[3] - uvBounds[2]) / 2, 1, 1) as double[];

                double[] pt = new double[] { evalData[0], evalData[1], evalData[2] };

                int sense = face.FaceInSurfaceSense() ? 1 : -1;

                double[] norm = new double[] { evalData[evalData.Length - 3] * sense, evalData[evalData.Length - 2] * sense, evalData[evalData.Length - 1] * sense };

                double[] cylParams = surf.CylinderParams as double[];

                double[] orig = new double[] { cylParams[0], cylParams[1], cylParams[2] };

                double[] dir = new double[] { pt[0] - orig[0], pt[1] - orig[1], pt[2] - orig[2] };

                IMathUtility mathUtils = swApp.IGetMathUtility();

                IMathVector dirVec  = mathUtils.CreateVector(dir) as IMathVector;
                IMathVector normVec = mathUtils.CreateVector(norm) as IMathVector;

                return(GetAngle(dirVec, normVec) < Math.PI / 2);
            }
            else
            {
                throw new NotSupportedException("Only cylindrical face is supported");
            }
        }
 public static Vector3 GetClosestPointOnTs(IFace2 f, Vector3 curvePoint)
 {
     var pt = f.GetClosestPointOn(curvePoint.X, curvePoint.Y, curvePoint.Z)
         .CastArray<double>()
         .ToVector3();
     return pt;
 }
Example #3
0
        public void Main()
        {
            PartDoc part = swApp.ActiveDoc as PartDoc;

            if (part != null)
            {
                IFace2 face = (part as IModelDoc2).ISelectionManager.GetSelectedObject6(1, -1) as IFace2;

                if (face != null && face.IGetSurface().IsSphere())
                {
                    double[] sphereParams = face.IGetSurface().SphereParams as double[];

                    IModeler modeler = swApp.IGetModeler();

                    ISurface sphereSurf = modeler.CreateSphericalSurface2(
                        new double[] { sphereParams[0], sphereParams[1], sphereParams[2] },
                        new double[] { 0, 0, 1 },
                        new double[] { 1, 0, 0 }, sphereParams[3]) as ISurface;

                    m_PreviewBody = sphereSurf.CreateTrimmedSheet4(new ICurve[] { null }, true) as IBody2;

                    m_PreviewBody.Display3(part, ToColorRef(255, 255, 0), (int)swTempBodySelectOptions_e.swTempBodySelectOptionNone);

                    part.ClearSelectionsNotify += new DPartDocEvents_ClearSelectionsNotifyEventHandler(OnClearSelections);
                }
                else
                {
                    swApp.SendMsgToUser("Please select spherical surface");
                }
            }
            else
            {
                swApp.SendMsgToUser("Please open part document");
            }
        }
Example #4
0
        public void Main()
        {
            IModelDoc2 doc = swApp.IActiveDoc2;

            if (doc != null)
            {
                IFace2 face = doc.ISelectionManager.GetSelectedObject6(1, -1) as IFace2;

                if (face != null)
                {
                    if (IsHole(face))
                    {
                        swApp.SendMsgToUser("Selected face is hole");
                    }
                    else
                    {
                        swApp.SendMsgToUser("Selected face is boss");
                    }
                }
                else
                {
                    throw new Exception("Face is not selected");
                }
            }
            else
            {
                throw new Exception("No document opened");
            }
        }
 /// <summary>
 /// Returns all the curves of the face in a single array with each loop
 /// seperated by a null entry as required by Surface::CreateTrimmedSheet4
 /// </summary>
 /// <param name="face"></param>
 /// <param name="transformer"></param>
 /// <returns></returns>
 private static ICurve[] GetCurvesForTrimming(IFace2 face, Func <ICurve, ICurve> transformer)
 {
     return(face
            .GetTrimLoops()
            .Select(curves => curves.Select(transformer).ToList())
            .PackForTrimming());
 }
        public static void Render(IFace2[] faces, Color color, double lineWidth, bool isSolid)
        {
            using (ModernOpenGl.SetColor(color, ShadingModel.Smooth, solidBody:isSolid))
            using (ModernOpenGl.SetLineWidth(lineWidth))
            {
                faces
                    .ForEach(face =>
                    {
                        var strips = FaceTriStrips.Unpack(face.GetTessTriStrips(true).CastArray<double>());
                        var norms = FaceTriStrips.Unpack(face.GetTessTriStripNorms().CastArray<double>());
                        Debug.Assert(norms.Length == strips.Length);
                        Debug.Assert(norms.Zip(strips, (a, b) => a.Length == b.Length).All(x => x));
                        norms.Zip(strips, (normStrip, pointStrip) => normStrip.Zip(pointStrip, (norm, point) => new { norm, point }))
                        .ForEach(strip =>
                        {
                            using (ModernOpenGl.Begin(PrimitiveType.TriangleStrip))
                            {
                                foreach (var vertex in strip)
                                {
                                    GL.Normal3(vertex.norm);
                                    GL.Vertex3(vertex.point);
                                }
                            }
                        });
                    });

            }
        }
 public void AddMate(IFeature feature, IFace2 face, int mateType, int alignType)
 {
     ClearSelection();
     feature.Select2(true, (int)swSelectionMarkAction_e.swSelectionMarkAppend);
     (face as IEntity).Select4(true, null);
     Assembly.AddMate3(mateType, alignType, false, 0, 0, 0, 0, 0, 0, 0, 0, false, out qe);
     ClearSelection();
 }
        public static Vector3 GetClosestPointOnTs(IFace2 f, Vector3 curvePoint)
        {
            var pt = f.GetClosestPointOn(curvePoint.X, curvePoint.Y, curvePoint.Z)
                     .CastArray <double>()
                     .ToVector3();

            return(pt);
        }
Example #9
0
        public static Vector3 GetClosestPointOnTs(IFace2 f, Vector3 curvePoint)
        {
            var pt = (f.GetClosestPointOn(curvePoint.X, curvePoint.Y, curvePoint.Z)
                      as double[])
                     .ToVector3();

            return(pt);
        }
        public static Range3Single GetBoxTs(this IFace2 face)
        {
            var box = (double[])face.GetBox();

            return(new Range3Single(
                       box[0], box[1], box[2],
                       box[3], box[4], box[5]));
        }
 public void AddMate(IFace2 face1, IFace2 face2, int mateType, int alignType)
 {
     ClearSelection();
     (face1 as IEntity).Select4(true, null);
     (face2 as IEntity).Select4(true, null);
     Assembly.AddMate3(mateType, alignType, false, 0, 0, 0, 0, 0, 0, 0, 0, false, out qe);
     ClearSelection();
 }
        private static double[][] GetTessTrianglesTs(this IFace2 face, bool noConversion)
        {
            var data = (double[])face.GetTessTriangles(noConversion);

            return(data.Select((value, index) => new { value, index })
                   .GroupBy(x => x.index / 3, x => x.value) // a group is a point of the triangle
                   .Select(x => x.ToArray())
                   .ToArray());
        }
 /// <summary>
 /// Returns all the trim loops of the face as list of a list of curves
 /// </summary>
 /// <param name="face"></param>
 /// <returns></returns>
 public static List <List <ICurve> > GetTrimLoops(this IFace2 face)
 {
     return(face
            .GetLoops()
            .CastArray <ILoop2>()
            .OrderBy(l => l.IsOuter() ? 0 : 1)
            .Select(l => l.GetEdges().CastArray <IEdge>().Select(e => (ICurve)e.GetCurve()))
            .Select(curves => curves.Select(c => (ICurve)c.Copy()).ToList())
            .ToList());
 }
Example #14
0
        public static MaterialBuilder GetMaterialBuilder(this IFace2 face)
        {
            if (!face.HasMaterialPropertyValues())
            {
                return(null);
            }

            var materialValue = face.MaterialPropertyValues as double[];

            return(MaterialUtility.MaterialValueToMaterialBuilder(materialValue));
        }
        public static bool GetDistance(this IFace2 entity0, IFace2 entity1, out double[] posacast, out double[] posbcast)
        {
            var bounds = entity1.GetUVBounds().CastArray<double>();

            var param = new[] {bounds[0], bounds[2], bounds[1], bounds[3]};

            object posa, posb;
            double distance;
            var result = ((IEntity) entity0).GetDistance(entity1, true, param, out posa, out posb, out distance);
            posacast = posa.CastArray<double>();
            posbcast = posb.CastArray<double>();
            return result == 0;
        }
        public static bool GetDistance(this IFace2 entity0, IFace2 entity1, out double[] posacast, out double[] posbcast)
        {
            var bounds = entity1.GetUVBounds().CastArray <double>();

            var param = new[] { bounds[0], bounds[2], bounds[1], bounds[3] };

            object posa, posb;
            double distance;
            var    result = ((IEntity)entity0).GetDistance(entity1, true, param, out posa, out posb, out distance);

            posacast = posa.CastArray <double>();
            posbcast = posb.CastArray <double>();
            return(result == 0);
        }
        /// <summary>
        /// 如果外环是个圆,获取和外环同圆心的内环圆
        /// </summary>
        /// <param name="face"></param>
        /// <returns></returns>
        public static bool TryGetInnerLoop(this IFace2 face, out ILoop2 innerLoop)
        {
            var outloop = face.GetOuterLoop();

            innerLoop = outloop;
            if (outloop.TryGetOneCircleEdge(out IEdge edge))
            {
                var circlePoint = edge.GetCirlceParams().Item1;
                innerLoop = face.GetLoopsWithoutOuterLoop().Where(l =>
                                                                  l.TryGetOneCircleEdge(out IEdge Inneredge) ? (IsSameVector3(Inneredge.GetCirlceParams().Item1, circlePoint) ? true : false): false
                                                                  ).FirstOrDefault();
                return(innerLoop != null ? true : false);
            }
            return(false);
        }
        private static ICurve[] SplitFaceOnIsoCurves(IFace2 face, int curvesCount, bool vOrU)
        {
            var curves = new List <ICurve>();

            var surf = face.IGetSurface();

            var uvBounds = face.GetUVBounds() as double[];
            var minU     = uvBounds[0];
            var maxU     = uvBounds[1];
            var minV     = uvBounds[2];
            var maxV     = uvBounds[3];

            double thisMin;
            double thisMax;
            double otherMin;
            double otherMax;

            if (vOrU) //if v param
            {
                thisMin  = minV;
                thisMax  = maxV;
                otherMin = minU;
                otherMax = maxU;
            }
            else //if u param
            {
                thisMin  = minU;
                thisMax  = maxU;
                otherMin = minV;
                otherMax = maxV;
            }

            var step = (thisMax - thisMin) / (curvesCount - 1);

            for (int i = 1; i < curvesCount - 1; i++)
            {
                var par   = thisMin + i * step;
                var curve = surf.MakeIsoCurve2(vOrU, ref par);

                double u;
                double v;

                if (vOrU)
                {
                    u = otherMin;
                    v = par;
                }
                else
                {
                    u = par;
                    v = otherMin;
                }

                var pt = surf.Evaluate(u, v, 0, 0) as double[];

                var startPt = new double[] { pt[0], pt[1], pt[2] };

                if (vOrU)
                {
                    u = otherMax;
                    v = par;
                }
                else
                {
                    u = par;
                    v = otherMax;
                }

                pt = surf.Evaluate(u, v, 0, 0) as double[];

                var endPt = new double[] { pt[0], pt[1], pt[2] };

                curve = curve.CreateTrimmedCurve2(startPt[0], startPt[1], startPt[2], endPt[0], endPt[1], endPt[2]);

                curves.Add(curve);
            }

            return(curves.ToArray());
        }
 /// <summary>
 /// Returns all the curves of the face in a single array with each loop
 /// seperated by a null entry as required by Surface::CreateTrimmedSheet4
 /// </summary>
 /// <param name="face"></param>
 /// <param name="transformer"></param>
 /// <returns></returns>
 private static ICurve[] GetCurvesForTrimming(IFace2 face,Func<ICurve,ICurve> transformer )
 {
     return face
         .GetTrimLoops()
         .Select(curves=>curves.Select(transformer).ToList())
         .PackForTrimming();
 }
 /// <summary>
 /// 获取外环
 /// </summary>
 /// <param name="face">IFace Interface</param>
 /// <returns></returns>
 public static ILoop2 GetOuterLoop(this IFace2 face)
 {
     return(face.GetLoopsEx().Where(loop => loop.IsOuter()).FirstOrDefault());
 }
 /// <summary>
 /// 获取面上所有环
 /// </summary>
 /// <param name="face"></param>
 /// <returns></returns>
 public static IEnumerable <ILoop2> GetLoopsEx(this IFace2 face)
 {
     return((face.GetLoops() as object[]).Cast <ILoop2>());
 }
Example #22
0
        /// <summary>
        /// Create a BSplineFace from the TrimCurve data.
        /// http://help.solidworks.com/2015/English/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IFace2~GetTrimCurves2.html
        /// </summary>
        /// <param name="swFace"></param>
        /// <returns></returns>
        public static BSplineFace Create(IFace2 swFace)
        {
            var start = 0;

            var packedData = swFace.GetTrimCurves2(WantCubic: true, WantNRational: false).CastArray <double>();
            var reader     = new GetTrimCurves2DataReader(packedData);

            // Packed Double 1
            // An integer pair containing number of loops and total number of SP curves (trim curves).
            // The length of any edge list generated immediately after a call to IFace2::GetTrimCurves2
            // will be equal to the number of SP curves
            var packedDouble1 = reader.ReadDouble().DoubleToInteger();
            int numLoops      = packedDouble1.Item1;
            int numSPCurves   = packedDouble1.Item2;

            // PackeDouble 2
            // Series of integer pairs containing the number of SP curves in each loop.
            // The first integer in each pair represents the number of curves in the odd loops;
            // the second represents the even. The total number of integer pairs is half the
            // number of loops, rounded up
            var curvesPerLoopLookup = reader.ReadIntegers(numLoops).ToList();

            var i = 0;

            // PackedDouble 3[]  ( Array of doubles )
            // For each SP curve, a set of two integer pairs.
            // The first contains the order of the curve and
            // a Boolean indicating if it is periodic.If the curve is periodic,
            // it is clamped (that is, knots of multiplicity = order exists at each end of the curve).
            // The second contains the dimension of the curve and the number of control points in it.
            // If the dimension is 2, then the curve is non - rational; if the dimension is 3,
            // then the curve is rational.
            var spCurveInfos = reader
                               .ReadBufferedIntegers(bufferSize: 4, numberOfBuffers: numSPCurves)
                               .Do(b =>
            {
                LogViewer.Log($"Get TrimCurves2 'PackedDouble 3' buffer {i++}");
                LogViewer.Log(string.Join(" ", b));
            })
                               .Select(b => new { order = b[0], isPeriodic = b[1] == 1, dimension = b[2], isRational = b[2] == 3, numCtrlPoints = b[3] })
                               .ToList();

            var spCurveInfos2 = spCurveInfos
                                .Select
                                    (info =>
            {
                var knots = reader.Read(info.order + info.numCtrlPoints).ToList();
                return(new { info.order, info.isPeriodic, info.dimension, info.isRational, info.numCtrlPoints, knots });
            })
                                .ToList();

            var trimCurves = spCurveInfos2
                             .Select
                                 (info =>
            {
                var ctrlPoints = reader
                                 .Read(info.numCtrlPoints * info.dimension)
                                 .Buffer(info.dimension, info.dimension)
                                 .Select(ToRationalVector3)
                                 .ToList();

                return(new BSpline2D
                           (controlPoints: ctrlPoints.ToArray()
                           , knotVectorU: info.knots.ToArray()
                           , order: info.order
                           , isClosed: info.isPeriodic
                           , isRational: info.dimension == 3));
            })
                             .ToArray();


            var bLoops = curvesPerLoopLookup
                         .Scan(new { start = 0, step = 0 }, (acc, count) => new { start = acc.start + acc.step, step = count })
                         .Skip(1)
                         .Select(o => trimCurves.ToArraySegment(o.start, o.step).ToArray())
                         .ToArray();


            fixLoops(bLoops);

            // packed double 4
            var surfaceDimension = reader.ReadDouble().DoubleToInteger().Item1;

            // packed double 5
            var uvOrder = reader.ReadDouble().DoubleToInteger().Map((u, v) => new { u, v });

            // packed double 6
            var uvNumCtrlPoints = reader.ReadDouble().DoubleToInteger().Map((u, v) => new { u, v });

            // packed double 7
            var uvIsPeriodic = reader.ReadDouble().DoubleToInteger().Map((u, v) => new { u, v });

            // surfaceKnotValuesU
            var uKnots = reader.Read(uvOrder.u + uvNumCtrlPoints.u).ToArray();

            // surfaceKnotValuesV
            var vKnots = reader.Read(uvOrder.v + uvNumCtrlPoints.v).ToArray();

            // surfaceCtrlPoinCoords
            var surfaceCtrlPoints = reader.Read(surfaceDimension * uvNumCtrlPoints.u * uvNumCtrlPoints.v)
                                    .Buffer(surfaceDimension, surfaceDimension)
                                    .Select(ToRationalVector4WithWeighRescaling)
                                    .ToList();

            // packed doubles 8
            // TODO handle the case for multiple surfaces
            var indexFlags = reader.ReadDouble().DoubleToInteger().Map((nSurface, index) => new { nSurface, index });

            var ctrlPointsArray = surfaceCtrlPoints.Reshape(uvNumCtrlPoints.u, uvNumCtrlPoints.v);

            var bSurface = new BSplineSurface(ctrlPointsArray, uvOrder.u, uvOrder.v, uKnots, vKnots, surfaceDimension, uvIsPeriodic.u == 1, uvIsPeriodic.v == 1);

            return(new BSplineFace(bSurface, bLoops));
        }
        private void AddMateCylinderLocator(IComponent2 cylinderLocator, IFace2 cylinderBase)
        {
            IFeature firstFeature = cylinderLocator.FeatureByName(configuration[Property.MOUNTING_CYLINDER_PLANE_NAME_1]);
            IFeature secondFeature = cylinderLocator.FeatureByName(configuration[Property.MOUNTING_CYLINDER_PLANE_NAME_2]);

            mounter.AddMate(firstFeature, cylinderBase, (int)swMateType_e.swMateTANGENT, (int)swMateAlign_e.swAlignSAME);
            mounter.AddMate(secondFeature, cylinderBase, (int)swMateType_e.swMateTANGENT, (int)swMateAlign_e.swAlignSAME);
        }
 public static double[][] GetTessTrianglesNoConversion(this IFace2 face) => face.GetTessTrianglesTs(true);
        /// <summary>
        /// Create a BSplineFace from the TrimCurve data.
        /// http://help.solidworks.com/2015/English/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IFace2~GetTrimCurves2.html
        /// </summary>
        /// <param name="swFace"></param>
        /// <returns></returns>
        public static BSplineFace Create(IFace2 swFace)
        {
            var start = 0;

            var packedData = swFace.GetTrimCurves2(true, false).CastArray <double>();
            var reader     = new GetTrimCurves2DataReader(packedData);

            // Packed Double 1
            var packedDouble1 = reader.ReadDouble().DoubleToInteger();
            int numLoops      = packedDouble1.Item1;
            int numSPCurves   = packedDouble1.Item2;

            // PackeDouble 2
            var curvesPerLoopLookup = reader.ReadIntegers(numLoops).ToList();

            // PackedDouble 3
            var spCurveInfos = reader
                               .ReadBufferedIntegers(4, numSPCurves)
                               .Select(b => new { order = b[0], isPeriodic = b[1] == 1, dimension = b[2], isRational = b[2] == 3, numCtrlPoints = b[3] })
                               .ToList();

            var spCurveInfos2 = spCurveInfos
                                .Select
                                    (info =>
            {
                var knots = reader.Read(info.order + info.numCtrlPoints).ToList();
                return(new { info, knots });
            })
                                .ToList();

            var trimCurves = spCurveInfos2
                             .Select
                                 (info =>
            {
                var ctrlPoints = reader
                                 .Read(info.info.numCtrlPoints * info.info.dimension)
                                 .Buffer(info.info.dimension, info.info.dimension)
                                 .Select(ToRationalVector3)
                                 .ToList();

                return(new BSpline2D(ctrlPoints.ToArray(), info.knots.ToArray(), info.info.order, info.info.isPeriodic));
            })
                             .ToArray();


            var bLoops = curvesPerLoopLookup
                         .Scan(new { start = 0, step = 0 }, (acc, count) => new { start = acc.start + acc.step, step = count })
                         .Skip(1)
                         .Select(o => trimCurves.ToArraySegment(o.start, o.step).ToArray())
                         .ToArray();

            // packed double 4
            var surfaceDimension = reader.ReadDouble().DoubleToInteger().Item1;

            // packed double 5
            var uvOrder = reader.ReadDouble().DoubleToInteger().Map((u, v) => new { u, v });

            // packed double 6
            var uvNumCtrlPoints = reader.ReadDouble().DoubleToInteger().Map((u, v) => new { u, v });

            // packed double 7
            var uvIsPeriodic = reader.ReadDouble().DoubleToInteger().Map((u, v) => new { u, v });

            // surfaceKnotValuesU
            var uKnots = reader.Read(uvOrder.u + uvNumCtrlPoints.u).ToArray();

            // surfaceKnotValuesV
            var vKnots = reader.Read(uvOrder.v + uvNumCtrlPoints.v).ToArray();

            // surfaceCtrlPoinCoords
            var surfaceCtrlPoints = reader.Read(surfaceDimension * uvNumCtrlPoints.u * uvNumCtrlPoints.v)
                                    .Buffer(surfaceDimension, surfaceDimension)
                                    .Select(ToRationalVector4)
                                    .ToList();

            // packed doubles 8
            // TODO handle the case for multiple surfaces
            var indexFlags = reader.ReadDouble().DoubleToInteger().Map((nSurface, index) => new { nSurface, index });

            var ctrlPointsArray = surfaceCtrlPoints.Reshape(uvNumCtrlPoints.u, uvNumCtrlPoints.v);

            var bSurface = new BSplineSurface(ctrlPointsArray, uvOrder.u, uvOrder.v, uKnots, vKnots);

            return(new BSplineFace(bSurface, bLoops));
        }
 /// <summary>
 /// 获取除了外环的所有环
 /// </summary>
 /// <param name="face">IFace Interface</param>
 /// <returns></returns>
 public static IEnumerable <ILoop2> GetLoopsWithoutOuterLoop(this IFace2 face)
 {
     return(face.GetLoopsEx().Where(loop => !loop.IsOuter()));
 }
Example #27
0
 public static bool IsSheetBody(this IFace2 face)
 {
     return((face.GetBody() as Body2).GetType() == (int)swBodyType_e.swSheetBody);
 }
 /// <summary>
 /// 获取面所在的特征
 /// </summary>
 /// <param name="face"></param>
 /// <returns></returns>
 public static IFeature GetFeatureEx(this IFace2 face)
 {
     return(face.GetFeature() as IFeature);
 }
Example #29
0
 public SwFace(IFace2 face) : base(face as IEntity)
 {
     Face = face;
 }
        /// <summary>
        /// 求面于某点的距离
        /// </summary>
        /// <param name="face"><see cref="IFace2"/></param>
        /// <param name="point"><see cref="Vector3"/></param>
        /// <returns></returns>
        public static double DistanceWithPoint(this IFace2 face, Vector3 point)
        {
            var facePoint = face.GetClosestPointOn(point.X, point.Y, point.Z);

            return(point.Distance(new Vector3(facePoint)));
        }
 /// <summary>
 /// 转换为实体
 /// </summary>
 /// <param name="face"></param>
 /// <returns></returns>
 public static IEntity AsEnitity(this IFace2 face)
 {
     return((IEntity)face);
 }
 /// <summary>
 /// 获取面的法向量
 /// </summary>
 /// <param name="face"></param>
 /// <returns></returns>
 public static Vector3 GetNormal(this IFace2 face)
 {
     return(new Vector3(face.Normal as double[]));
 }
Example #33
0
 public static bool IsPlanarFace(this IFace2 face)
 {
     return(face.IGetSurface().IsPlane());
 }
        /// <summary>
        /// Create a BSplineFace from the TrimCurve data.
        /// http://help.solidworks.com/2015/English/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IFace2~GetTrimCurves2.html
        /// </summary>
        /// <param name="swFace"></param>
        /// <returns></returns>
        public static BSplineFace Create(IFace2 swFace )
        {
            var start = 0;

            var packedData = swFace.GetTrimCurves2(WantCubic: true, WantNRational: false).CastArray<double>();
            var reader = new GetTrimCurves2DataReader(packedData);

            // Packed Double 1
            // An integer pair containing number of loops and total number of SP curves (trim curves).
            // The length of any edge list generated immediately after a call to IFace2::GetTrimCurves2
            // will be equal to the number of SP curves
            var packedDouble1 = reader.ReadDouble().DoubleToInteger();
            int numLoops = packedDouble1.Item1;
            int numSPCurves = packedDouble1.Item2;

            // PackeDouble 2
            // Series of integer pairs containing the number of SP curves in each loop.
            // The first integer in each pair represents the number of curves in the odd loops;
            // the second represents the even. The total number of integer pairs is half the 
            // number of loops, rounded up
            var curvesPerLoopLookup = reader.ReadIntegers(numLoops).ToList();

            var i = 0;

            // PackedDouble 3[]  ( Array of doubles )
            // For each SP curve, a set of two integer pairs.
            // The first contains the order of the curve and
            // a Boolean indicating if it is periodic.If the curve is periodic,
            // it is clamped (that is, knots of multiplicity = order exists at each end of the curve).
            // The second contains the dimension of the curve and the number of control points in it. 
            // If the dimension is 2, then the curve is non - rational; if the dimension is 3,
            // then the curve is rational.
            var spCurveInfos = reader
                .ReadBufferedIntegers(bufferSize: 4, numberOfBuffers: numSPCurves)
                .Do(b =>
                {
                    LogViewer.Log($"Get TrimCurves2 'PackedDouble 3' buffer {i++}");
                    LogViewer.Log(string.Join(" ",b));
                })
                .Select(b => new {order = b[0], isPeriodic = b[1]== 1, dimension=b[2], isRational=b[2]==3, numCtrlPoints = b[3]})
                .ToList();

            var spCurveInfos2 = spCurveInfos
                .Select
                (info =>
                {
                    var knots = reader.Read(info.order + info.numCtrlPoints).ToList();
                    return new {info.order,info.isPeriodic, info.dimension, info.isRational, info.numCtrlPoints, knots};
                })
                .ToList();

            var trimCurves = spCurveInfos2
                .Select
                (info =>
                {
                    var ctrlPoints = reader
                        .Read(info.numCtrlPoints*info.dimension)
                        .Buffer(info.dimension, info.dimension)
                        .Select(ToRationalVector3)
                        .ToList();

                    return new BSpline2D
                        ( controlPoints: ctrlPoints.ToArray()
                        , knotVectorU: info.knots.ToArray()
                        , order: info.order
                        , isClosed: info.isPeriodic
                        , isRational: info.dimension==3);

                })
                .ToArray();


            var bLoops = curvesPerLoopLookup
                .Scan(new {start = 0, step = 0}, (acc, count) => new {start = acc.start + acc.step, step = count})
                .Skip(1)
                .Select(o => trimCurves.ToArraySegment(o.start, o.step).ToArray())
                .ToArray();


            fixLoops(bLoops);

            // packed double 4
            var surfaceDimension = reader.ReadDouble().DoubleToInteger().Item1;

            // packed double 5
            var uvOrder = reader.ReadDouble().DoubleToInteger().Map((u, v) => new {u, v});

            // packed double 6
            var uvNumCtrlPoints = reader.ReadDouble().DoubleToInteger().Map((u, v) => new {u, v});

            // packed double 7
            var uvIsPeriodic = reader.ReadDouble().DoubleToInteger().Map((u, v) => new {u, v});

            // surfaceKnotValuesU
            var uKnots = reader.Read(uvOrder.u + uvNumCtrlPoints.u).ToArray();
            
            // surfaceKnotValuesV
            var vKnots = reader.Read(uvOrder.v + uvNumCtrlPoints.v).ToArray();

            // surfaceCtrlPoinCoords
            var surfaceCtrlPoints = reader.Read(surfaceDimension*uvNumCtrlPoints.u*uvNumCtrlPoints.v)
                .Buffer(surfaceDimension, surfaceDimension)
                .Select(ToRationalVector4WithWeighRescaling)
                .ToList();

            // packed doubles 8 
            // TODO handle the case for multiple surfaces
            var indexFlags = reader.ReadDouble().DoubleToInteger().Map((nSurface, index) => new {nSurface, index});

            var ctrlPointsArray = surfaceCtrlPoints.Reshape(uvNumCtrlPoints.u, uvNumCtrlPoints.v);

            var bSurface = new BSplineSurface(ctrlPointsArray,uvOrder.u, uvOrder.v,uKnots, vKnots, surfaceDimension, uvIsPeriodic.u ==1, uvIsPeriodic.v==1);

            return new BSplineFace(bSurface, bLoops);

        }
 public static double[][] GetTessTrianglesAllowConversion(this IFace2 face) => face.GetTessTrianglesTs(false);
Example #36
0
 public SwFace(IFace2 face, ISwDocument doc) : base(face as IEntity, doc)
 {
     Face = face;
 }
Example #37
0
 internal SwFace(IFace2 face, ISwDocument doc, ISwApplication app) : base((IEntity)face, doc, app)
 {
     Face        = face;
     m_MathUtils = app.Sw.IGetMathUtility();
 }
Example #38
0
 public IFace2Object(IFace2 IFace2instance)
 {
     IFace2Instance = IFace2instance;
 }