예제 #1
0
        public override void OnActivate()
        {
            Inputs[InputNames.GeometricSolverPipe].Send(NotificationNames.DisableAll);
            var uiBuilder     = ActionsGraph[InputNames.UiBuilderInput].Get <UiBuilder>();
            var sketchControl = uiBuilder.GetItemAtPath("Ribbon/Modelling/Sketch/Sketch");

            _sketchButton = (ISketchButton)sketchControl;
            if (Document.Root.Get <DocumentContextInterpreter>().ActiveSketch != -1)
            {
                var sketchNode = Document.Root[Document.Root.Get <DocumentContextInterpreter>().ActiveSketch];

                // rebuild sketch faces
                sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = null;
                var results = AutoGroupLogic.BuildAutoFaces(sketchNode, Document);
                Document.Transact();
                if (results.Count > 0)
                {
                    TopoDSShape finalShape = results[0];
                    // if there is more than one shape on the sketch, we need to sew the faces resulted from BuildAutoFaces
                    for (int i = 1; i < results.Count; i++)
                    {
                        if (results[i] == null)
                        {
                            continue;
                        }
                        var sew = new BRepBuilderAPISewing(1.0e-06, true, true, true, false);
                        sew.Add(finalShape);
                        sew.Add(results[i]);
                        var messg = new MessageProgressIndicator();
                        sew.Perform(messg);

                        finalShape = sew.SewedShape;
                    }

                    sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = finalShape;

                    // we need to set transparency to 1 (don't show) before we set it to hidden
                    sketchNode.Set <DrawingAttributesInterpreter>().Transparency = 1;
                    sketchNode.Set <DrawingAttributesInterpreter>().Visibility   = ObjectVisibility.Hidden;
                }
                int index;
                NodeUtils.SetSketchTransparency(Document, sketchNode,
                                                NodeUtils.SketchHas3DApplied(Document, sketchNode, out index) ? ObjectVisibility.Hidden : ObjectVisibility.ToBeDisplayed);
            }
            Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, new DataPackage(null));
            Document.Root.Get <DocumentContextInterpreter>().ActiveSketch = -1;
            RemoveHighlightCurrentSketchNodes();
            Document.Commit("reset active sketch");
            _sketchButton.Unblock();
            if (ActionsGraph.PendingAction != null && ActionsGraph.PendingAction.Name == ModifierNames.None)
            {
                Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.SwitchSelectionMode, TopAbsShapeEnum.TopAbs_FACE);
            }
            ActionsGraph.SwitchAction(ModifierNames.None);
        }
예제 #2
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);
        }
        public override bool Execute()
        {
            //  NodeUtils.UpdateSketches(Dependency[0].ReferenceBuilder.Node, this.Builder);

            // Get the extrusion referenece shape, height and extrusion type
            var sketchNode = Dependency[0].ReferenceBuilder.Node;

            if (sketchNode == null)
            {
                return(false);
            }
            TopoDSShape face = null;

            if (sketchNode != null)
            {
                face = sketchNode.Children[2].Get <MeshTopoShapeInterpreter>().Shape;
            }
            var         rootNode   = Parent.Root;
            var         shapes     = AutoGroupLogic.BuildAutoFaces(sketchNode, rootNode.Get <DocumentContextInterpreter>().Document);// ?? face;
            TopoDSShape finalShape = null;

            if (shapes.Count > 0)
            {
                finalShape = shapes[0];
                for (int i = 1; i < shapes.Count; i++)
                {
                    if (shapes[i] == null)
                    {
                        continue;
                    }
                    var sew = new BRepBuilderAPISewing(1.0e-06, true, true, true, false);
                    sew.Add(finalShape);
                    sew.Add(shapes[i]);
                    var messg = new MessageProgressIndicator();
                    sew.Perform(messg);

                    finalShape = sew.SewedShape;
                }
            }
            if (finalShape == null)
            {
                finalShape = face;
            }
            var height        = Dependency[2].Real;
            var extrusionType = Dependency[1].Integer;

            // Don't allow 0 height
            if (Math.Abs(height) < Precision.Confusion)
            {
                return(false);
            }

            // Build the extruded shape
            TopoDSShape resultShape = extrusionType == (int)ExtrusionTypes.MidPlane
                                             ? ExtrudeMidPlane(finalShape, height)
                                             : ExtrudeToDepth(finalShape, height);

            Shape = resultShape;

            return(true);
        }