示例#1
0
        public void SetTransformationTestRotationAndTranslation()
        {
            var originBaseSketch   = new gpPnt(1, 1, 0);
            var originSecondSketch = new gpPnt(10, 1, 0);
            var T             = new gpTrsf();
            var oldSystemAxis = new gpAx3(originBaseSketch, new gpDir(0, 0, 1));
            var newSystemAxis = new gpAx3(originSecondSketch, new gpDir(1, 0, 0));

            T.SetTransformation(oldSystemAxis, newSystemAxis);

            var point = new gpPnt(10, 3, 8).Transformed(T);

            var translationPart = new gpTrsf();

            translationPart.SetTranslation(new gpPnt(0, 0, 0), point);
            gpTrsf mult1 = T.Inverted.Multiplied(translationPart);
            var    try1  = new gpPnt(0, 0, 0).Transformed(mult1); // ok

            Assert.AreEqual(try1.X, 10);
            Assert.AreEqual(try1.Y, 3);
            Assert.AreEqual(try1.Z, 8);
            gpTrsf mult2 = translationPart.Multiplied(T.Inverted);
            var    try2  = new gpPnt(0, 0, 0).Transformed(mult2); // nok

            Assert.AreEqual(try2.X, 17);
            Assert.AreEqual(try2.Y, -3);
            Assert.AreEqual(try2.Z, 1);
        }
示例#2
0
 public static void TranslateSketchNode(NodeBuilder nodeBuilder, Point3D translateValue, Node sketchNode)//, gpTrsf translation)
 {
     if (nodeBuilder.FunctionName == FunctionNames.Point)
     {
         gpTrsf translation        = new gpTrsf();
         var    sketchAxisLocation = NodeBuilderUtils.GetTransformedAxis(new NodeBuilder(sketchNode)).Location;
         var    newValue           = new Point3D(sketchAxisLocation.X + translateValue.X, sketchAxisLocation.Y + translateValue.Y,
                                                 sketchAxisLocation.Z + translateValue.Z);
         translation.SetTranslation(sketchAxisLocation, newValue.GpPnt);
         nodeBuilder.Node.Set <TransformationInterpreter>().CurrTransform = translation;
         nodeBuilder.ExecuteFunction();
     }
     else
     {
         var affectedPoints = GetPointNodes(nodeBuilder.Node);
         if (affectedPoints == null)
         {
             return;
         }
         var sketchAxisLocation = NodeBuilderUtils.GetTransformedAxis(new NodeBuilder(sketchNode)).Location;
         foreach (var point in affectedPoints)
         {
             var nb       = new NodeBuilder(point);
             var oldValue = nb[1].TransformedPoint3D;
             var newValue = new Point3D(oldValue.X + translateValue.X, oldValue.Y + translateValue.Y,
                                        oldValue.Z + translateValue.Z);
             var translation = new gpTrsf();
             translation.SetTranslation(sketchAxisLocation, newValue.GpPnt);
             nb.Node.Set <TransformationInterpreter>().CurrTransform = translation;
             nb.ExecuteFunction();
         }
     }
 }
        private static gpTrsf GetTranslateTrsf(Point3D transformedPosition)
        {
            var translateTrsf = new gpTrsf();

            translateTrsf.SetTranslation(new gpVec(transformedPosition.X, transformedPosition.Y,
                                                   transformedPosition.Z));
            return(translateTrsf);
        }
            private static gpTrsf BuildTranslation(Point3D point1, Point3D point2)
            {
                var vector         = new gpVec(point1.GpPnt, point2.GpPnt);
                var transformation = new gpTrsf();

                transformation.SetTranslation(vector);//{Translation = vector};
                return(transformation);
            }
        /// <summary>
        ///   Build a vector from the two pints, scale the vector with the desired value
        ///   and calculate a transformation applied on the first point to generate where
        ///   the second point should be.
        /// </summary>
        public static Point3D ScaleSegment(Point3D point1, Point3D point2, double scale)
        {
            var vector = new gpVec(point1.GpPnt, point2.GpPnt);

            vector.Scale(scale);
            var transformation = new gpTrsf();

            transformation.SetTranslation(vector);

            // Apply the transformation on the vertex
            return(new Point3D(point1.GpPnt.Transformed(transformation)));
        }
示例#6
0
        public void SetTransformationTestMultipleTrsf()
        {
            var originBaseSketch   = new gpPnt(1, 1, 0);
            var originSecondSketch = new gpPnt(10, 1, 0);

            var T             = new gpTrsf();
            var oldSystemAxis = new gpAx3(originBaseSketch, new gpDir(0, 0, 1));
            var newSystemAxis = new gpAx3(originSecondSketch, new gpDir(1, 0, 0));

            T.SetTransformation(oldSystemAxis, newSystemAxis);

            var point = new gpPnt(10, 3, 8).Transformed(T);

            var translationPart = new gpTrsf();

            translationPart.SetTranslation(new gpPnt(0, 0, 0), point);
            gpTrsf mult1 = T.Inverted.Multiplied(translationPart);
            var    try1  = new gpPnt(0, 0, 0).Transformed(mult1); // ok: transformations needed to obtain global point (10, 3, 8)

            Assert.AreEqual(try1.X, 10);
            Assert.AreEqual(try1.Y, 3);
            Assert.AreEqual(try1.Z, 8);

            //reversed order doesn't work
            gpTrsf mult2 = translationPart.Multiplied(T.Inverted);
            var    try2  = new gpPnt(0, 0, 0).Transformed(mult2);

            Assert.AreEqual(try2.X, 17);
            Assert.AreEqual(try2.Y, -3);
            Assert.AreEqual(try2.Z, 1);

            //translate entire 'object'
            var translation1 = new gpTrsf();

            translation1.SetTranslation(new gpPnt(1, 1, 0), new gpPnt(7, 1, 0));
            var multipleTrsfs = translation1.Multiplied(mult1);
            var try11         = new gpPnt(0, 0, 0).Transformed(multipleTrsfs);

            Assert.AreEqual(try11.X, 16);
            Assert.AreEqual(try11.Y, 3);
            Assert.AreEqual(try11.Z, 8);

            //reversed order doesn't work
            var multipleTrsfs2 = mult1.Multiplied(translation1);
            var try12          = new gpPnt(0, 0, 0).Transformed(multipleTrsfs2);

            Assert.AreEqual(try12.X, 10);
            Assert.AreEqual(try12.Y, 3);
            Assert.AreEqual(try12.Z, 14);
        }
        /// <summary>
        ///   Make an extrusion starting from a shape until a height.
        /// </summary>
        /// <param name = "originalShape"></param>
        /// <param name = "height"></param>
        /// <returns></returns>
        private static TopoDSShape ExtrudeMidPlane(TopoDSShape originalShape, double height)
        {
            TopoDSShape prismShape = null;

            // Make the Extrusion
            if (originalShape != null)
            {
                try
                {
                    // Get the Face to be extruded
                    var face = originalShape;// OCTopoDS.Face(originalShape);

                    // Get the direction
                    var dir = GeomUtils.ExtractDirection(face);
                    if (dir == null)
                    {
                        return(null);
                    }

                    // Build the translated shape
                    var translationVector = new gpVec(dir);
                    translationVector.Multiply(-1 * height / 2);
                    var transformation = new gpTrsf();
                    transformation.SetTranslation(translationVector);
                    var brepTrans       = new BRepBuilderAPITransform(originalShape, transformation, false);
                    var translatedShape = brepTrans.Shape;

                    // Extract the face of the translated shape
                    //baseEx.Init(translatedShape, TopAbsShapeEnum.TopAbs_FACE, TopAbsShapeEnum.TopAbs_SHAPE);
                    //baseEx.Next();
                    var translatedFace = translatedShape;// OCTopoDS.Face(translatedShape);

                    // Describe the height through a vector
                    var vector = new gpVec(dir);
                    vector.Multiply(height);

                    // Make the prism
                    prismShape = new BRepPrimAPIMakePrism(translatedFace, vector, false, true).Shape;
                }
                catch (Exception ex)
                {
                    Log.Error("Error on extrude: " + ex.Message);
                    return(null);
                }
            }

            return(prismShape);
        }
示例#8
0
        public override bool Execute()
        {
            // Get the reference nodes to see if Cut was applied or it is the first time
            var cutShapes = Dependency[3].ReferenceList;

            if (cutShapes == null)
            {
                return(false);
            }
            var rootNode = Parent.Root;
            // Get the Cut dependencies (cutting shape, cut depth and cut type)
            var cuttingShape = Dependency[0].ReferedShape;
            var sketchNode   = Dependency[0].ReferenceBuilder.Node;
            var faces        = AutoGroupLogic.BuildAutoFaces(sketchNode, rootNode.Get <DocumentContextInterpreter>().Document);
            var depth        = Dependency[1].Real;
            var cutType      = (CutTypes)Dependency[2].Integer;

            cuttingShape = faces.First(); // firstFace.Shape;
            // Test the cutting shape
            if (cuttingShape == null || cuttingShape.IsNull)
            {
                return(false);
            }

            var dir = GeomUtils.ExtractDirection(cuttingShape) ??
                      sketchNode.Children[1].Get <Axis3DInterpreter>().Axis.GpAxis.Direction;

            // Build a list with the cutting prisms used to Cut the objects
            var cuttingPrisms = new List <TopoDSShape>();

            var depthM = cutType == CutTypes.ToDepth ? depth : 7000;

            if (Math.Abs(depthM) < Precision.Confusion)
            {
                depthM = 0.1;
            }
            foreach (var face in faces)
            {
                TopoDSShape cutPrismShape     = null;
                var         translationVector = new gpVec(dir);
                translationVector.Multiply(-1 * depthM / 2);
                var transformation = new gpTrsf();
                transformation.SetTranslation(translationVector);
                var brepTrans       = new BRepBuilderAPITransform(face, transformation, false);
                var translatedShape = brepTrans.Shape;
                var translatedFace  = translatedShape;

                // Describe the height through a vector
                var vector = new gpVec(dir);
                vector.Multiply(depthM);

                // Make the prism
                cutPrismShape = new BRepPrimAPIMakePrism(translatedFace, vector, false, true).Shape;

                cuttingPrisms.Add(cutPrismShape);
            }
            if (cuttingPrisms.Count == 0)
            {
                return(false);
            }
            var document  = rootNode.Get <DocumentContextInterpreter>().Document;
            var shapeList = new List <int>();

            if (Dependency[3].ReferenceList.Count > 0)
            {
                shapeList.AddRange(Dependency[3].ReferenceList.Select(sse => sse.Node.Index));
            }
            else
            {
                shapeList.AddRange(NodeUtils.GetDocumentSolids(document));
                shapeList.Remove(Parent.Index);
            }
            TopoDSShape resShape = null;

            foreach (var cuttingPrism in cuttingPrisms)
            {
                // If the Cut is executed first time
                if (cutShapes.Count <= 0 || resShape == null)
                {
                    // Put back the shapes
                    // Cut them again
                    var cutModifiedNodes = new List <SceneSelectedEntity>();
                    resShape = CutThroughAll(rootNode, cuttingPrism, cutModifiedNodes, shapeList);
                    Dependency[3].ReferenceList = cutModifiedNodes;
                    cutShapes = Dependency[3].ReferenceList;
                }
                else
                {
                    // Execute Cut on the shapes from ReferenceList
                    resShape = CutThroughShape(resShape, cuttingPrism);
                }
            }

            if (resShape == null)
            {
                return(false);
            }

            // Show the new Cut shape
            Shape = resShape;

            return(true);
        }