public static MathTransform GetTranslationFromVector(this IMathUtility m, IMathVector v)
        {
            var vData = v.ArrayData.CastArray <double>();
            var xForm = new[] { 1, 0, 0, 0, 1, 0, 0, 0, 1, vData[0], vData[1], vData[2], 1, 0, 0, 0 };

            return((MathTransform)m.CreateTransform(xForm));
        }
 public OffsetBuilder(ISldWorks app, IModelDoc2 model)
 {
     m_App       = app;
     m_Model     = model;
     m_Modeler   = app.IGetModeler();
     m_MathUtils = m_App.IGetMathUtility();
 }
        /// <summary>
        /// Creates a new joint editor proptery manager page that allows the user to edit joint properties.
        /// </summary>
        /// <param name="robot">Active robot model</param>
        /// <param name="joint">Joint to be edited</param>
        /// <param name="document">Active assembly document</param>
        /// <param name="swApp">Solidworks application environment</param>
        public JointPMPage(RobotModel robot, Joint joint, AssemblyDoc document, SldWorks swApp)
        {
            //Validate parameters
            if (robot == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null robot model.");
            if (document == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null assembly document.");
            if (swApp == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null solidworks application interface.");

            //Initialize fields
            this.robot = robot;
            this.swApp = swApp;
            currentJoint = joint;
            mathUtil = ((IMathUtility)swApp.GetMathUtility());

            //AssemblyDoc inherits ModelDoc2 but the relationship dosn't carry through the COM interface
            //Having two fields prevents having to cast half of the time
            modelDoc = (ModelDoc2)document;
            assemblyDoc = document;

            //Setup the page, its controls and their visual layout
            SetupPage();

            SelectionObservers = new List<SelectionObserver>();
            ButtonObservers = new List<ButtonObserver>();
            CheckboxObservers = new List<CheckboxObserver>();
        }
Example #4
0
        internal SwTempPrimitive(IMathUtility mathUtils, IModeler modeler, SwTempBody[] bodies, bool isCreated)
        {
            m_MathUtils = mathUtils;
            m_Modeler   = modeler;

            m_Creator = new ElementCreator <ISwTempBody[]>(CreateBodies, bodies, isCreated);
        }
Example #5
0
        internal SwMemorySheetGeometryBuilder(ISwApplication app)
        {
            m_App = app;

            m_MathUtils = m_App.Sw.IGetMathUtility();
            m_Modeler   = m_App.Sw.IGetModeler();
        }
        private IBody2[] CreateToolBodies(IModeler modeler, IMathUtility mathUtils, List <object> tools)
        {
            var toolBodies = new List <IBody2>();

            foreach (var tool in tools)
            {
                if (tool is IFeature)
                {
                    var sketch = (tool as IFeature).GetSpecificFeature2() as ISketch;

                    var sketchContours = sketch.GetSketchContours() as object[];

                    if (sketchContours != null)
                    {
                        foreach (ISketchContour skCont in sketchContours)
                        {
                            toolBodies.Add(CreateBodyFromSketchContour(modeler, mathUtils, skCont));
                        }
                    }
                }

                if (tool is ISketchContour)
                {
                    toolBodies.Add(CreateBodyFromSketchContour(modeler, mathUtils, tool as ISketchContour));
                }
            }

            return(toolBodies.ToArray());
        }
Example #7
0
        public static double[] Origin(this IRefPlane plane, IMathUtility math)
        {
            var transform   = plane.Transform;
            var originWorld = math.Point(new[] { 0.0, 0, 0 });

            return(originWorld.MultiplyTransformTs(transform).ArrayData.CastArray <double>());
        }
        /// <summary>
        /// 获取基准面原点
        /// </summary>
        /// <param name="plane"></param>
        /// <param name="math"></param>
        /// <returns></returns>
        public static double[] Origin(this IRefPlane plane, IMathUtility math)
        {
            var transform   = plane.Transform;
            var originWorld = math.CreatePoint(new[] { 0.0, 0, 0 }) as MathVector;

            return(((MathTransform)originWorld.MultiplyTransform(transform)).ArrayData as double[]);
        }
Example #9
0
        public static double[] Normal(this IRefPlane plane, IMathUtility math)
        {
            var transform   = plane.Transform;
            var normalWorld = math.Vector(new[] { 0.0, 0, 1 });

            return(normalWorld.MultiplyTransformTs(transform).ArrayData.CastArray <double>());
        }
        public static MathVector Vector(this IMathUtility m, double[] a, double [] b)
        {
            var p0 = m.Point(a);
            var p1 = m.Point(b);

            return(p1.SubtractTs(p0));
        }
        /// <summary>
        /// 投影
        /// </summary>
        /// <param name="m"></param>
        /// <param name="h"></param>
        /// <param name="p"></param>
        /// <param name="cameraVector"></param>
        /// <param name="mathP"></param>
        /// <returns></returns>
        public static MathVector Project(this ITriadManipulator m, swTriadManipulatorControlPoints_e h, IMathPoint p, IMathVector cameraVector, IMathUtility mathP)
        {
            IMathUtility math = mathP;

            //var zero = (IMathPoint)math.CreatePoint(new[] { 0, 0, 0 });
            //double pT, qT;
            switch (h)
            {
            case swTriadManipulatorControlPoints_e.swTriadManipulatorOrigin:
                return((MathVector)p.Subtract(m.Origin));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorXAxis:

                return(ClosestPointOnAxis(m, p, cameraVector, m.XAxis));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorYAxis:
                return(ClosestPointOnAxis(m, p, cameraVector, m.YAxis));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorZAxis:
                return(ClosestPointOnAxis(m, p, cameraVector, m.ZAxis));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorXYPlane:
                return((MathVector)p.Subtract(m.Origin));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorYZPlane:
                return((MathVector)p.Subtract(m.Origin));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorZXPlane:
                return((MathVector)p.Subtract(m.Origin));

            default:
                throw new ArgumentOutOfRangeException(nameof(h), h, null);
            }
        }
        public static MathVector Project(this ITriadManipulator m, swTriadManipulatorControlPoints_e h, IMathPoint p, IMathVector cameraVector, IMathUtility mathP)
        {
            IMathUtility math = mathP;
            var zero = (IMathPoint) math.CreatePoint(new[] {0, 0, 0});
            double pT, qT;
            switch (h)
            {
                case swTriadManipulatorControlPoints_e.swTriadManipulatorOrigin:
                    return (MathVector) p.Subtract(m.Origin);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorXAxis:

                    return ClosestPointOnAxis(m, p, cameraVector, m.XAxis);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorYAxis:
                    return ClosestPointOnAxis(m, p, cameraVector, m.YAxis);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorZAxis:
                    return ClosestPointOnAxis(m, p, cameraVector, m.ZAxis);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorXYPlane:
                    return (MathVector) p.Subtract(m.Origin);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorYZPlane:
                    return (MathVector) p.Subtract(m.Origin);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorZXPlane:
                    return (MathVector) p.Subtract(m.Origin);
                default:
                    throw new ArgumentOutOfRangeException(nameof(h), h, null);
            }
        }
        public static double[] Cross(this IMathUtility math, double[] a, double[] b)
        {
            var v0 = (IMathVector)math.CreateVector(a);
            var v1 = (IMathVector)math.CreateVector(b);

            return((double[])((IMathVector)v0.Cross(v1)).ArrayData);
        }
        public static MathTransform CreateTranslationTransform
            (this ITriadManipulator m, swTriadManipulatorControlPoints_e h, IMathUtility math, double value)
        {
            MathVector translVector = null;
            switch (h)
            {
                case swTriadManipulatorControlPoints_e.swTriadManipulatorOrigin:
                    break;
                case swTriadManipulatorControlPoints_e.swTriadManipulatorXAxis:
                    translVector = (MathVector)math.CreateVector(new[] {value, 0, 0});
                    break;
                case swTriadManipulatorControlPoints_e.swTriadManipulatorYAxis:
                    translVector = (MathVector)math.CreateVector(new[] {0, value, 0});
                    break;
                case swTriadManipulatorControlPoints_e.swTriadManipulatorZAxis:
                    translVector = (MathVector)math.CreateVector(new[] {0, 0, value});
                    break;
                case swTriadManipulatorControlPoints_e.swTriadManipulatorXYPlane:
                    break;
                case swTriadManipulatorControlPoints_e.swTriadManipulatorYZPlane:
                    break;
                case swTriadManipulatorControlPoints_e.swTriadManipulatorZXPlane:
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(h), h, null);
            }

            if (translVector == null)
                return null;

            return math.ComposeTransform(m.XAxis, m.YAxis, m.ZAxis, translVector, 1.0);
        }
Example #15
0
        private double[] GetDirection(IModelDoc2 model, object inputObj)
        {
            if (inputObj is IFace2)
            {
                ISurface surf = (inputObj as IFace2).GetSurface() as ISurface;

                if (surf.IsCylinder())
                {
                    double[] cylParams = surf.CylinderParams as double[];

                    return(new double[] { cylParams[3], cylParams[4], cylParams[5] });
                }
            }
            else if (inputObj is IFeature)
            {
                IRefPlane refPlane = (inputObj as IFeature).GetSpecificFeature2() as IRefPlane;

                if (refPlane != null)
                {
                    IMathUtility mathUtils = swApp.GetMathUtility() as IMathUtility;
                    IMathVector  vec       = mathUtils.CreateVector(new double[] { 0, 0, 1 }) as IMathVector;
                    vec = vec.MultiplyTransform(refPlane.Transform) as IMathVector;
                    return(vec.ArrayData as double[]);
                }
            }

            throw new NullReferenceException("Failed to find the direction. Please select cylindrical face or plane");
        }
Example #16
0
        internal MacroFeatureParametersParser(ISldWorks app)
        {
            MathUtils = app.IGetMathUtility();

            //TODO: pass logger as parameter
            m_Logger = new TraceLogger("xCAD.MacroFeature");
        }
Example #17
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");
            }
        }
        /// <summary>
        /// 获取基准面的法向量
        /// </summary>
        /// <param name="plane"></param>
        /// <param name="math"></param>
        /// <returns></returns>
        public static double[] Normal(this IRefPlane plane, IMathUtility math)
        {
            var transform   = plane.Transform;
            var normalWorld = math.CreateVector(new[] { 0.0, 0, 1 }) as MathVector;

            return(((MathTransform)normalWorld.MultiplyTransform(transform)).ArrayData as double[]);
        }
        internal MacroFeatureParametersParser(ISwApplication app)
        {
            m_App     = app;
            MathUtils = m_App.Sw.IGetMathUtility();

            //TODO: pass logger as parameter
            m_Logger = new TraceLogger("xCAD.MacroFeature");
        }
Example #20
0
        internal SwTempPrimitive(SwTempBody[] bodies, ISwApplication app, bool isCreated)
        {
            m_App = app;

            m_MathUtils = m_App.Sw.IGetMathUtility();
            m_Modeler   = m_App.Sw.IGetModeler();

            m_Creator = new ElementCreator <ISwTempBody[]>(CreateBodies, bodies, isCreated);
        }
Example #21
0
        private void ExportToStl(string filePath, float[] tessTriangs, float[] tessNorms, double[] transformMatrix)
        {
            IMathUtility   mathUtils = swApp.IGetMathUtility();
            IMathTransform transform = (mathUtils.CreateTransform(transformMatrix) as IMathTransform).IInverse();

            using (FileStream fileStream = File.Create(filePath))
            {
                using (BinaryWriter writer = new BinaryWriter(fileStream))
                {
                    byte[] header = new byte[80];

                    writer.Write(header);

                    uint triangsCount = (uint)tessTriangs.Length / 9;
                    writer.Write(triangsCount);

                    for (uint i = 0; i < triangsCount; i++)
                    {
                        float normalX = tessNorms[i * 9];
                        float normalY = tessNorms[i * 9 + 1];
                        float normalZ = tessNorms[i * 9 + 2];

                        IMathVector mathVec = mathUtils.CreateVector(
                            new double[] { normalX, normalY, normalZ }) as IMathVector;

                        mathVec = mathVec.MultiplyTransform(transform) as IMathVector;

                        double[] vec = mathVec.ArrayData as double[];

                        writer.Write((float)vec[0]);
                        writer.Write((float)vec[1]);
                        writer.Write((float)vec[2]);

                        for (uint j = 0; j < 3; j++)
                        {
                            float vertX = tessTriangs[i * 9 + j * 3];
                            float vertY = tessTriangs[i * 9 + j * 3 + 1];
                            float vertZ = tessTriangs[i * 9 + j * 3 + 2];

                            IMathPoint mathPt = mathUtils.CreatePoint(
                                new double[] { vertX, vertY, vertZ }) as IMathPoint;

                            mathPt = mathPt.MultiplyTransform(transform) as IMathPoint;

                            double[] pt = mathPt.ArrayData as double[];

                            writer.Write((float)pt[0]);
                            writer.Write((float)pt[1]);
                            writer.Write((float)pt[2]);
                        }

                        ushort atts = 0;
                        writer.Write(atts);
                    }
                }
            }
        }
Example #22
0
        internal SwMemorySolidGeometryBuilder(ISwApplication app, IMemoryGeometryBuilderDocumentProvider geomBuilderDocsProvider)
        {
            m_App = app;

            m_MathUtils = m_App.Sw.IGetMathUtility();
            m_Modeler   = m_App.Sw.IGetModeler();

            m_GeomBuilderDocsProvider = geomBuilderDocsProvider;
        }
Example #23
0
 public static bool PlaneOriginAndNormalEquals(this IRefPlane p,
                                               IMathUtility math,
                                               double[] origin,
                                               double[] normal,
                                               double tol)
 {
     return(PlaneOriginEquals(p, math, origin, tol) &&
            PlaneNormalEquals(p, math, normal, tol));
 }
Example #24
0
        //NOTE: keeping the pointer in this class only so it can be properly disposed
        internal SwTempBody(IBody2 body, ISwApplication app) : base(null, null, app)
        {
            if (!body.IsTemporaryBody())
            {
                throw new ArgumentException("Body is not temp");
            }

            m_TempBody  = body;
            m_MathUtils = app.Sw.IGetMathUtility();
        }
Example #25
0
        internal SwBoundingBox(ISwDocument doc, ISwApplication app)
        {
            m_Doc = doc;

            m_MathUtils = app.Sw.IGetMathUtility();

            m_Creator = new ElementCreator <EditableBox3D>(CreateBox, null, false);

            UserUnits = false;
        }
 public static bool PlaneOriginAndNormalEquals(this IRefPlane p, 
     IMathUtility math ,
     double[] origin,
     double[] normal,
     double tol)
 {
     return PlaneOriginEquals(p, math, origin, tol) &&
         PlaneNormalEquals(p, math, normal, tol);
     
 }
 /// <summary>
 /// Find the vector in model space from the point to the viewers eye.
 /// </summary>
 /// <param name="modelView"></param>
 /// <param name="mathUtility"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 private static MathVector ViewVector(IModelView modelView, IMathUtility mathUtility, IMathPoint p)
 {
     var world2screen = modelView.Transform;
     var pScreen = (MathPoint) p.MultiplyTransform(world2screen);
     var vv = (IMathVector) mathUtility.CreateVector(new[] {0.0, 0, 1});
     var pScreenUp = (MathPoint) pScreen.AddVector(vv);
     var pWorldDelta = (MathPoint) pScreenUp.MultiplyTransform((MathTransform) world2screen.Inverse());
     var viewVector = (MathVector) p.Subtract(pWorldDelta);
     return viewVector;
 }
Example #28
0
        /// <summary>
        /// Find the vector in model space from the point to the viewers eye.
        /// </summary>
        /// <param name="modelView"></param>
        /// <param name="mathUtility"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        private static MathVector ViewVector(IModelView modelView, IMathUtility mathUtility, IMathPoint p)
        {
            var world2screen = modelView.Transform;
            var pScreen      = (MathPoint)p.MultiplyTransform(world2screen);
            var vv           = (IMathVector)mathUtility.CreateVector(new[] { 0.0, 0, 1 });
            var pScreenUp    = (MathPoint)pScreen.AddVector(vv);
            var pWorldDelta  = (MathPoint)pScreenUp.MultiplyTransform((MathTransform)world2screen.Inverse());
            var viewVector   = (MathVector)p.Subtract(pWorldDelta);

            return(viewVector);
        }
Example #29
0
        internal SwMemoryGeometryBuilder(ISwApplication app, IMemoryGeometryBuilderDocumentProvider geomBuilderDocsProvider)
        {
            m_App = app;

            m_MathUtils = app.Sw.IGetMathUtility();
            m_Modeler   = app.Sw.IGetModeler();

            WireBuilder  = new SwMemoryWireGeometryBuilder(app);
            SheetBuilder = new SwMemorySheetGeometryBuilder(app);
            SolidBuilder = new SwMemorySolidGeometryBuilder(app, geomBuilderDocsProvider);
        }
Example #30
0
        private IBody2 CreateBodyFromSketchContour(IModeler modeler,
                                                   IMathUtility mathUtils, ISketchContour skCont, double height, bool midPlane)
        {
            var sketch = skCont.Sketch;

            if (sketch.Is3D())
            {
                throw new UserErrorException("Only 2D sketches are supported");
            }

            var transform = sketch.ModelToSketchTransform.IInverse();

            var boundary = (skCont.GetEdges() as object[])
                           .Cast <IEdge>()
                           .Select(e =>
            {
                var curve = e.IGetCurve().ICopy();    //must copy curve otherwise CreateTrimmedSheet4 is failing
                return(curve);
            }).ToArray();

            var centerPt = mathUtils.CreatePoint(new double[] { 0, 0, 0 }) as IMathPoint;
            var dirVec   = mathUtils.CreateVector(new double[] { 0, 0, 1 }) as IMathVector;
            var refVec   = mathUtils.CreateVector(new double[] { 1, 0, 0 }) as IMathVector;

            centerPt = centerPt.IMultiplyTransform(transform);
            dirVec   = dirVec.IMultiplyTransform(transform);
            refVec   = refVec.IMultiplyTransform(transform);

            if (midPlane)
            {
                var dirRevVec = new Vector(dirVec.ArrayData as double[]);
                dirRevVec.Scale(-1);

                var origPt = new Point(centerPt.ArrayData as double[]);

                MoveCurves(origPt, dirRevVec, height / 2, boundary, mathUtils);
                centerPt = mathUtils.CreatePoint(origPt.Move(dirRevVec, height / 2).ToArray()) as IMathPoint;
            }

            var surf = modeler.CreatePlanarSurface2(centerPt.ArrayData, dirVec.ArrayData, refVec.ArrayData) as ISurface;

            var sheetBody = surf.CreateTrimmedSheet4(boundary, true) as Body2;

            if (sheetBody == null)
            {
                throw new NullReferenceException("Failed to create trimmed sheet from surface region");
            }

            var solidBody = modeler.CreateExtrudedBody(sheetBody, dirVec as MathVector, height) as IBody2;

            var faces = (solidBody.GetFaces() as object[]).Cast <IFace2>().ToArray();

            return(modeler.CreateSheetFromFaces(faces));
        }
        /// <summary>
        ///  Transformation matrix data:
        ///
        ///    |a b c.n |
        ///    |d e f.o |
        ///    |g h i.p |
        ///    |j k l.m |
        ///
        /// The SOLIDWORKS transformation matrix is stored as a homogeneous matrix of 16 elements, ordered as shown.The first 9 elements(a to i) are elements of a 3x3 rotational sub-matrix, the next 3 elements(j, k, l) define a translation vector, and the next 1 element(m) is a scaling factor.The last 3 elements(n, o, p) are unused in this context.
        ///
        /// The 3x3 rotational sub-matrix represents 3 axis sets:
        ///
        /// row 1 for x-axis components of rotation
        /// row 2 for y-axis components of rotation
        /// row 3 for z-axis components of rotation
        /// The 3 axes are constrained to be orthogonal and unified so that they
        /// produce a pure rotational transformation.Reflections can also be added
        /// to these axes by setting the components to negative.The rotation sub-matrix
        /// coupled with the lower-left translation vector and the lower-right corner scaling
        /// factor creates an affine transformation, which is a transformation that preserves lines
        /// and parallelism; i.e., maps parallel lines to parallel lines.
        ///
        /// If the 3 axis sets of the 3x3 rotational sub-matrix are not orthogonal or unified,
        /// then they are automatically corrected according to the following rules:
        ///
        ///
        /// If any axis is 0, or any two axes are parallel, or all axes are coplanar, then an identity matrix replaces the rotational sub-matrix.
        ///
        /// All axes are corrected to be of unit length.
        ///
        /// The axes are built to be orthogonal to each other in the prioritized order of Z, X, Y (X is orthogonal to Z, Y is orthogonal to Z and X).
        /// </summary>
        /// <param name=""></param>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public static MathTransform ToSwMatrix(this IMathUtility math, Matrix4x4 matrix)
        {
            var    _ = matrix;
            double a = _.M11, b = _.M12, c = _.M13, n = _.M14;
            double d = _.M21, e = _.M22, f = _.M23, o = _.M24;
            double g = _.M31, h = _.M32, i = _.M33, p = _.M34;
            double j = _.M41, k = _.M42, l = _.M43, m = _.M44;

            double[] data = new[] { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p };

            return((MathTransform)math.CreateTransform(data));
        }
Example #32
0
        internal static IMathTransform ToMathTransform(this IMathUtility mathUtils, TransformMatrix matrix)
        {
            var data = new double[]
            {
                matrix.M11 / Math.Abs(matrix.M11), matrix.M12, matrix.M13,
                matrix.M21, matrix.M22 / Math.Abs(matrix.M22), matrix.M23,
                matrix.M31, matrix.M32, matrix.M33 / Math.Abs(matrix.M33),
                matrix.M41, matrix.M42, matrix.M43,
                Math.Abs(matrix.M11),
                matrix.M14, matrix.M24, matrix.M34
            };

            return(mathUtils.CreateTransform(data) as IMathTransform);
        }
Example #33
0
        internal SwComponent(IComponent2 comp, SwAssembly rootAssembly, ISwApplication app) : base(comp, rootAssembly, app)
        {
            m_RootAssembly   = rootAssembly;
            Component        = comp;
            Children         = new SwChildComponentsCollection(rootAssembly, this);
            m_FeaturesLazy   = new Lazy <ISwFeatureManager>(() => new SwComponentFeatureManager(this, rootAssembly, app));
            m_DimensionsLazy = new Lazy <ISwDimensionsCollection>(() => new SwFeatureManagerDimensionsCollection(Features));

            m_MathUtils = app.Sw.IGetMathUtility();

            Bodies = new SwComponentBodyCollection(comp, rootAssembly);

            m_FilePathResolver = ((SwApplication)OwnerApplication).Services.GetService <IFilePathResolver>();
        }
        private IBody2[] CropGeometry(IModeler modeler, IMathUtility mathUtils,
                                      List <IBody2> targetBodies, List <object> trimTools)
        {
            if (targetBodies == null || !targetBodies.Any())
            {
                throw new UserErrorException("Select target bodies to trim");
            }

            if (trimTools == null || !trimTools.Any())
            {
                throw new UserErrorException("Select trim tools (sketches or sketch regions)");
            }

            var resBodies = new List <IBody2>();

            var toolBodies = CreateToolBodies(modeler, mathUtils, trimTools);

            if (!toolBodies.Any())
            {
                throw new UserErrorException("No closed regions found in the selected trim tools");
            }

            foreach (var inputBody in targetBodies)
            {
                if (inputBody == null)
                {
                    continue; //TODO: investigate why first body is null
                }

                foreach (var solidBody in toolBodies)
                {
                    var targetBody = inputBody.ICopy();

                    var toolBody = solidBody.ICopy();

                    int      err;
                    object[] res = targetBody.Operations2((int)swBodyOperationType_e.SWBODYINTERSECT, toolBody, out err) as object[];

                    if (res != null)
                    {
                        foreach (IBody2 resBody in res)
                        {
                            resBodies.Add(resBody);
                        }
                    }
                }
            }

            return(resBodies.ToArray());
        }
        public static IMathTransform CreateTransFormTransformationMaxtrix(
            this IMathUtility mathUtils, TransformationMaxtrix transform)
        {
            var arrData = new double[]
            {
                transform.Rotation.M11, transform.Rotation.M12, transform.Rotation.M13,
                transform.Rotation.M21, transform.Rotation.M22, transform.Rotation.M23,
                transform.Rotation.M31, transform.Rotation.M32, transform.Rotation.M33,
                transform.Translation.X, transform.Translation.Y, transform.Translation.Z,
                transform.Scale,
                0, 0, 0
            };

            return(mathUtils.CreateTransform(arrData) as IMathTransform);
        }
 public static double[] Normal(this IRefPlane plane, IMathUtility math)
 {
     var transform = plane.Transform;
     var normalWorld = math.Vector(new[] {0.0, 0, 1});
     return normalWorld.MultiplyTransformTs(transform).ArrayData.CastArray<double>();
 }
 public MountFace(IMathUtility mathUtility)
     : base(mathUtility)
 {
 }
 public static bool PlaneNormalEquals(this IRefPlane p, IMathUtility mathUtility, double[] normal, double tol)
 {
     return MathPointExtensions.Equals(mathUtility.Vector(p.Normal(mathUtility)), mathUtility.Vector(normal), tol);
 }
 public static bool PlaneOriginEquals(this IRefPlane p, IMathUtility mathUtility, double[] origin, double tol)
 {
     return MathPointExtensions.Equals(mathUtility.Point(p.Origin(mathUtility)), mathUtility.Point(origin), tol);
 }
 public static double[] Origin(this IRefPlane plane, IMathUtility math)
 {
     var transform = plane.Transform;
     var originWorld = math.Point(new[] {0.0, 0, 0});
     return originWorld.MultiplyTransformTs(transform).ArrayData.CastArray<double>();
 }
 public Model(IMathUtility mathUtility)
 {
     MathUtility = mathUtility;
         Helper = Helper.Instance;//f*****g hard code!
         //TODO: replace on more better solution
 }
 public Locator(IMathUtility mathUtility)
     : base(mathUtility)
 {
 }
 public static MathVector ToSWVector(this Vector3 v, IMathUtility m=null) =>(m ?? SwAddinBase.Active.Math).Vector(new[] {v.X, v.Y, v.Z});
        public static EdgeDistance ClosestDistanceBetweenTwoCurves(IMathUtility m,ICurve curve0, ICurve curve1)
        {
            var curveDomain = curve1.Domain();

            var solver = new BrentSearch
                (t =>
                {
                    var pt = curve1.PointAt(t);
                    return (curve0.ClosestPointOn(pt).Point - pt).Length();
                }
                , curveDomain[0]
                , curveDomain[1]
                );

            solver.Minimize();
            var param = solver.Solution;

            var pt1 = curve1.PointAt(param);
            var pt0 = curve0.ClosestPointOn(pt1).Point;
            var edge = new Edge3(pt1, pt0);
            return new EdgeDistance(edge, solver.Value);
        }
 public static MathTransform ToSwTransform(this Matrix4x4 m, IMathUtility math = null) => 
     (math ?? SwAddinBase.Active.Math).ToSwMatrix(m);