Пример #1
0
        private void BuildAndEnterSketch(Document document)
        {
            var sketchCreator     = new SketchCreator(document);
            var currentSketch     = sketchCreator.CurrentSketch;
            var sketchNodeBuilder = new NodeBuilder(currentSketch);

            Document.Transact();

            Log.InfoFormat("StartSketch - Command line input");
            var firstvector    = new gpDir(Points[1].GpPnt.X - Points[0].GpPnt.X, Points[1].GpPnt.Y - Points[0].GpPnt.Y, Points[1].GpPnt.Z - Points[0].GpPnt.Z);
            var secondvector   = new gpDir(Points[2].GpPnt.X - Points[0].GpPnt.X, Points[2].GpPnt.Y - Points[0].GpPnt.Y, Points[2].GpPnt.Z - Points[0].GpPnt.Z);
            var normal         = firstvector.Crossed(secondvector);
            var _normalOnPlane = new gpAx1(Points[0].GpPnt, normal);
            var sketchAx2      = new gpAx2();

            sketchAx2.Axis = (_normalOnPlane);
            var plane = new gpPln(new gpAx3(sketchAx2));

            Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane);
            sketchNodeBuilder[0].Axis3D = new Axis(sketchNodeBuilder[0].Axis3D.Location, new Point3D(new gpPnt(_normalOnPlane.Direction.XYZ)));
            HighlightCurrentSketchNodes(sketchNodeBuilder.Node);
            NodeBuilderUtils.HidePlanes(Document);
            Document.Commit("sketch created");
            AddNodeToTree(sketchNodeBuilder.Node);
            Document.Transact();
            Document.Root.Get <DocumentContextInterpreter>().ActiveSketch = sketchNodeBuilder.Node.Index;
            _sketchButton.Block();
            Document.Commit("Started editing sketch");
        }
Пример #2
0
        /// <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");
            }
        }