private AISShape AddToContext(NodeBuilder builder, TopoDSShape sourceShape, gpTrsf mirrorTransform)
        {
            var shape    = new BRepBuilderAPITransform(sourceShape, mirrorTransform, true).Shape;
            var aisShape = new AISShape(shape);

            _context.Display(aisShape, false);
            _context.SetTransparency(aisShape, 0.8, false);
            ApplyColor(builder, aisShape);
            return(aisShape);
        }
 protected static TopoDSShape ApplyEvolveOnShape(gpTrsf mirrorTransform, TopoDSShape sourceShape)
 {
     try
     {
         var myBRepTransformation = new BRepBuilderAPITransform(mirrorTransform);
         myBRepTransformation.Perform(sourceShape, true);
         return(myBRepTransformation.IsDone ? myBRepTransformation.Shape : null);
     }
     catch (Exception ex)
     {
         Log.Error("Error on making mirror: " + ex.Message);
         return(null);
     }
 }
        /// <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);
        }
Exemplo n.º 4
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);
        }