예제 #1
0
        /// <summary>
        /// A new sketch is created: if the user clicked on the face of a solid, that face's normal is used as axis for the new sketch, otherwise
        /// the default axis with position (0,0,0) and direction (0,0,1) is used.
        /// </summary>
        /// <param name="mouseData"></param>
        protected override void OnMouseDownAction(Mouse3DPosition mouseData)
        {
            base.OnMouseDownAction(mouseData);

            Log.Info("StartSketch - OnMouseDownAction");

            //var checkSketch = new SketchCreator(Document, false);
            //if (checkSketch.CurrentSketch != null) return;
            Log.Info("StartSketch - OnMouseDownAction - current sketch null");

            var sketchCreator     = new SketchCreator(Document);
            var currentSketch     = sketchCreator.CurrentSketch;
            var sketchNodeBuilder = new NodeBuilder(currentSketch);

            Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.BuildSelections, mouseData);
            var entities =
                Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get
                <List <SceneSelectedEntity> >();

            var selectedFace = (SelectionInfo)Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetFace).Data;

            Document.Transact();
            var transformationInfo = new TransformationInfo();

            transformationInfo.SketchIndex = sketchNodeBuilder.Node.Index;
            Log.InfoFormat("StartSketch - OnMouseDownAction - selected entities count {0}", entities.Count);
            var normalOnPlane = new Axis(new Point3D(0, 0, 0), new Point3D(0, 0, 1)).GpAxis;

            if (Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetPlane).Data != null)
            {
                normalOnPlane.Location =
                    ((gpPln)Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetPlane).Data).Axis.Location;
                normalOnPlane.Direction =
                    ((gpPln)Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetPlane).Data).Axis.Direction;
                if (selectedFace != null)
                {
                    var _3DShapesFunctions = new List <string>();
                    _3DShapesFunctions.AddRange(new[] { FunctionNames.Sphere, FunctionNames.Box, FunctionNames.Cylinder,
                                                        FunctionNames.Torus, FunctionNames.Cone, FunctionNames.Plane });
                    var nb = new NodeBuilder(selectedFace.selectedNode);
                    if (nb.FunctionName == string.Empty || _3DShapesFunctions.Contains(nb.FunctionName))
                    {
                        transformationInfo.RefSketchIndex = -1;
                    }
                    else
                    {
                        transformationInfo.RefSketchIndex = nb.Dependency[0].Reference.Index;
                        var faces       = GeomUtils.ExtractFaces(nb.Shape);
                        var face        = faces[selectedFace.face];
                        var orientation = face.Orientation();
                        if (orientation == TopAbsOrientation.TopAbs_REVERSED)
                        {
                            normalOnPlane.Direction = normalOnPlane.Direction.Reversed;
                        }
                    }
                }
                else
                {
                    transformationInfo.RefSketchIndex = -1;
                }
            }
            else
            {
                var plane = new gpPln(new gpAx3());
                Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane);
                transformationInfo.RefSketchIndex = -1;
            }

            if (selectedFace != null)
            {
                var nb = new NodeBuilder(selectedFace.selectedNode);
                if (nb.FunctionName != FunctionNames.Plane)
                {
                    sketchNodeBuilder[2].Reference = nb.Node;
                    sketchNodeBuilder[3].Integer   = selectedFace.face;
                }
            }
            _sketchButton.Block();

            sketchNodeBuilder[0].TransformedAxis3D = new Axis(new Point3D(0, 0, 0), new Point3D(0, 0, 1)).GpAxis;
            var transformation = sketchNodeBuilder.Node.Set <TransformationInterpreter>();

            if (selectedFace != null)
            {
                var solids = new List <string> {
                    string.Empty
                };
                solids.AddRange(FunctionNames.GetSolids());
                if (solids.Contains(new NodeBuilder(selectedFace.selectedNode).FunctionName))
                {
                    var    oldSystemAxis = new gpAx3(new gpPnt(0, 0, 0), new gpDir(0, 0, 1));
                    var    newSystemAxis = new gpAx3(normalOnPlane.Location, normalOnPlane.Direction);
                    gpTrsf T             = new gpTrsf();
                    T.SetTransformation(oldSystemAxis, newSystemAxis);
                    transformation.CurrTransform = T.Inverted;
                }
                else
                {
                    var allTrsfs =
                        NodeBuilderUtils.GetTransformedAxis(
                            new NodeBuilder(selectedFace.selectedNode).Dependency[0].ReferenceBuilder);
                    gpTrsf T             = new gpTrsf();
                    var    oldSystemAxis = new gpAx3(new gpPnt(0, 0, 0), new gpDir(0, 0, 1));
                    //  var oldSystemAxis = new gpAx3(allTrsfs.Location, allTrsfs.Direction);
                    normalOnPlane.Direction = NodeBuilderUtils.RoundToPrecision(normalOnPlane.Direction);
                    var newSystemAxis = new gpAx3(normalOnPlane.Location, normalOnPlane.Direction);
                    // T.SetDisplacement(oldSystemAxis, newSystemAxis);
                    T.SetTransformation(oldSystemAxis, newSystemAxis);
                    transformation.CurrTransform = T.Inverted;
                }
                transformationInfo.Transformation = transformation.CurrTransform;
            }
            else
            {
                transformation.TranslateWith(new Point3D(normalOnPlane.Location));
                transformationInfo.Transformation = transformation.CurrTransform;
            }
            transformationInfo.TrsfIndex = TransformationInfo.maxTrsfIndex;
            TransformationInfo.maxTrsfIndex++;
            TransformationInterpreter.Transformations.Add(transformationInfo);

            sketchNodeBuilder.ExecuteFunction();

            AddNodeToTree(sketchNodeBuilder.Node);
            NodeBuilderUtils.HidePlanes(Document);
            HighlightCurrentSketchNodes(sketchNodeBuilder.Node);
            Document.Commit("sketch created");
            BackToNeutralModifier();
        }