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); }
/// <summary> /// Called when Enter Sketch is pressed. If a node is selected in the tree or a shape is selected on the drawing stage, /// the sketch containing that node/shape is selected for editing, otherwise a new sketch will be created in OnMouseDownAction /// </summary> public override void OnActivate() { base.OnActivate(); if (Document.Root.Children.Count > 0) { Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.SwitchSelectionMode, TopAbsShapeEnum.TopAbs_FACE); } else { Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.SwitchSelectionMode, TopAbsShapeEnum.TopAbs_SOLID); } ActionsGraph[InputNames.CoordinateParser].Send(CoordinatateParserNames.SetStage, ParserStage.Unknown); Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.Enable); Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Disable); Reset(); ShowHint(ModelingResources.StartSketch); Inputs[InputNames.GeometricSolverPipe].Send(NotificationNames.DisableAll); var uiBuilder = ActionsGraph[InputNames.UiBuilderInput].Get <UiBuilder>(); var sketchControl = uiBuilder.GetItemAtPath("Ribbon/Modelling/Sketch/Sketch"); _sketchButton = (ISketchButton)sketchControl; var selected = Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get <List <SceneSelectedEntity> >(); Node node = null; if (selected.Count > 0) { node = selected[0].Node; } else { node = Inputs[InputNames.NodeSelect].GetData(NotificationNames.GetValue).Get <Node>(); } if (node != null) { Node sketchNode = AutoGroupLogic.FindSketchNode(node); if (sketchNode != null) { Document.Transact(); Document.Root.Get <DocumentContextInterpreter>().ActiveSketch = sketchNode.Index; NodeUtils.SetSketchTransparency(Document, sketchNode, 0); Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.Resume); var axis = new NodeBuilder(sketchNode)[0].TransformedAxis3D; var plane = new gpPln(new gpAx3(axis.Location, axis.Direction)); Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane); //if (Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetPlane).Data == null) //{ // var plane = new gpPln(new gpAx3()); // Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane); // //ActionsGraph[InputNames.View].Send(NotificationNames.SwitchView, plane); //} _sketchButton.Block(); HighlightCurrentSketchNodes(sketchNode); Document.Commit("Started editing sketch"); BackToNeutralModifier(); Log.Info("StartSketch - current sketch exists"); _sketchButton.Block(); return; } } if (Document.Root.Children.Count == 0) { CreatePlane(new Point3D(-20, -10, 0), new Point3D(20, -10, 0), new Point3D(20, 10, 0), new Point3D(-20, 10, 0), "Top"); CreatePlane(new Point3D(-20, 0, -10), new Point3D(20, 0, -10), new Point3D(20, 0, 10), new Point3D(-20, 0, 10), "Right"); CreatePlane(new Point3D(0, -20, -10), new Point3D(0, 20, -10), new Point3D(0, 20, 10), new Point3D(0, -20, 10), "Front"); Document.Commit("Default planes created"); } Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Enable); Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.SwitchSelectionMode, TopAbsShapeEnum.TopAbs_FACE); Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.Resume); var sketchCreator = new SketchCreator(Document, false); if (sketchCreator.CurrentSketch == null) { ShowHint(ModelingResources.StartSketch); Log.Info("StartSketch - no current sketch"); } }