Exemplo n.º 1
0
        public override void OnActivate()
        {
            _pointAdded = false;
            var firstShape = NodeBuilderUtils.IdentifySelectedObjectLabel(Document.Root);

            if (firstShape == null)
            {
                ErrorSplineSelected();
                return;
            }

            _function = firstShape.Get <FunctionInterpreter>();
            if (_function == null)
            {
                ErrorSplineSelected();
                return;
            }
            if (_function.Name != FunctionNames.Spline)
            {
                ErrorSplineSelected();
                return;
            }

            Document.Transact();
            _pointAdded = true;

            var mouseCursorInput = Inputs[InputNames.MouseCursorInput];

            mouseCursorInput.Send(NotificationNames.SetResourceManager, MetaActionResource.ResourceManager);
            mouseCursorInput.Send(NotificationNames.SetCursorName, "splineaddpoint.cur");
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Builds the solver info (magic points and planes) receiving as parameter a shape.
        /// </summary>
        /// <param name = "solverObject"></param>
        /// <param name = "shape"></param>
        /// <param name = "parallelPrecision"></param>
        /// <param name = "computeParallelism"></param>
        public static void BuildSolverInfo(SolverGeometricObject solverObject, Node shape,
                                           double parallelPrecision, bool computeParallelism)
        {
            var solidShape = ShapeUtils.ExtractShape(solverObject.Parent);

            // Build a list with the magic points made by the vertexes
            BuildPointList(shape, solverObject);
            var functionName = shape.Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name;

            if (functionName == FunctionNames.LineTwoPoints || functionName == FunctionNames.Arc ||
                functionName == FunctionNames.Arc3P || functionName == FunctionNames.Circle ||
                functionName == FunctionNames.Ellipse)
            {
                // Build a list with the edges
                BuildEdgeList(solidShape, solverObject);
            }
            // Build a list with the magic points made by the faces/surfaces
            BuildFaceList(solidShape, solverObject);

            // Build a list with parallel axis
            if (!computeParallelism)
            {
                return;
            }
            if (NodeBuilderUtils.NodeIsOnSketch(new NodeBuilder(shape)))
            {
                BuildParallelAxisList(solidShape, solverObject, parallelPrecision);
            }
        }
Exemplo n.º 3
0
        private void GetRotateValue(ref object resultvalue)
        {
            var nb = new NodeBuilder(Parent);

            if (nb.FunctionName != FunctionNames.Sketch)
            {
                return;
            }

            var interpreter = Parent.Get <TransformationInterpreter>();

            if (interpreter == null)
            {
                return;
            }
            var transformations = NodeBuilderUtils.GetTransformations(nb);
            var multiplied      = new gpTrsf();

            foreach (var trsf in transformations)
            {
                multiplied = multiplied.Multiplied(trsf);
            }
            var matr = multiplied.VectorialPart;
            // extract rotation from matrix
        }
Exemplo n.º 4
0
        private void ProposeSelectedReferenceShape(TopoDSShape face, Mouse3DPosition mouseData)
        {
            SceneSelectedEntity selectedNode = null;

            if (face != null)
            {
                selectedNode = GeomUtils.IdentifyNode(Document.Root, face);
                if (selectedNode == null)
                {
                    return;
                }
            }
            else
            {
                var node = NodeBuilderUtils.IdentifySelectedObjectLabel(Document.Root);
                if (node != null)
                {
                    selectedNode = new SceneSelectedEntity(node);
                }
            }
            if (selectedNode == null)
            {
                return;
            }
            if (_axisBuilder.Node != null && selectedNode.Node.Index == _axisBuilder.Node.Index)
            {
                SetWorkingPlane();
                _dragging     = true;
                _startDragPos = mouseData.Point;
                return;
            }
            // The scene selected entity is hold as reference

            Propose(selectedNode);
        }
        private void SetLength(object data)
        {
            if (Builder[0].ReferenceBuilder.FunctionName == FunctionNames.Circle)
            {
                BeginUpdate();
                var nb = new NodeBuilder(Builder[0].ReferenceBuilder.Node);
                nb[1].Real = (double)data / 2;
                nb.ExecuteFunction();
                EndVisualUpdate("Updated radius");
            }
            if (Builder[0].ReferenceBuilder.FunctionName != FunctionNames.LineTwoPoints)
            {
                return;
            }
            BeginUpdate();
            TreeUtils.SetLineLength(Builder[0].ReferenceBuilder.Node, (double)data);
            var document   = _viewInfo.Document;
            var constraint = NodeBuilderUtils.ShapeHasConstraint(Builder[0].ReferenceBuilder.Node, Constraint2DNames.LineLengthFunction, document);

            if (constraint != -1)
            {
                var nb = new NodeBuilder(document.Root[constraint]);
                nb.Dependency[2].Real = (double)data;
                nb.ExecuteFunction();
            }
            CallSolverForLineChanges(Builder[0].ReferenceBuilder.Node);
            EndVisualUpdate("Updated Length");
        }
Exemplo n.º 6
0
        public void DeleteCircleTest()
        {
            var document = TestUtils.DefaultsSetup();

            document.Transact();
            var sketchCreator = new SketchCreator(document, false);
            var sketchNode    = sketchCreator.BuildSketchNode();

            var pointBuilder = new NodeBuilder(document, FunctionNames.Point);

            pointBuilder[0].Reference          = sketchNode;
            pointBuilder[1].TransformedPoint3D = new Point3D();
            pointBuilder.ExecuteFunction();
            var circleBuilder = new NodeBuilder(document, FunctionNames.Circle);

            circleBuilder[0].Reference = pointBuilder.Node;
            circleBuilder[1].Real      = 20;
            circleBuilder.ExecuteFunction();
            //document.Commit("Draw first circle");
            var nodeToDelete = document.Root[2];

            NodeBuilderUtils.DeleteNode(nodeToDelete, document);
            document.Commit("Deleted");
            Assert.AreEqual(1, document.Root.Children.Count, "Circle is not deleted");
            Assert.AreEqual(FunctionNames.Sketch, document.Root[0].Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name);
        }
Exemplo n.º 7
0
 private void SetInternalRadius(object data)
 {
     BeginUpdate();
     Builder[1].Real = (double)data;
     NodeBuilderUtils.UpdateSketchesOnFaces(new NodeBuilder(Parent));
     EndVisualUpdate("Fillet 2D radius changed");
 }
Exemplo n.º 8
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");
        }
Exemplo n.º 9
0
        private void SetTranslateValue(object data)
        {
            var nodeBuilder        = new NodeBuilder(Parent);
            var _3dShapesFunctions = new List <string>();

            _3dShapesFunctions.AddRange(new[] { FunctionNames.Sphere, FunctionNames.Box, FunctionNames.Cylinder,
                                                FunctionNames.Torus, FunctionNames.Cone, FunctionNames.Boolean });
            if (_3dShapesFunctions.Contains(nodeBuilder.FunctionName))
            {
                NodeUtils.TranslateSolids(nodeBuilder, (Point3D)data);
                return;
            }
            var sketchNode = NodeBuilderUtils.FindBaseSketchNode(Parent);

            var document = sketchNode.Root.Get <DocumentContextInterpreter>().Document;
            var newPoint = (Point3D)data;

            document.Transact();
            if (NodeUtils.NodeIsOnSketch(nodeBuilder))
            {
                NodeUtils.TranslateSketchNode(nodeBuilder, newPoint, sketchNode);
            }
            else
            {
                NodeUtils.Translate3DNode(nodeBuilder, document, newPoint);
            }
            document.Commit("Translated");
            EndVisualUpdate("Translate object");
        }
Exemplo n.º 10
0
        protected override void OnMouseDownAction(Mouse3DPosition mouseData)
        {
            if (Points.Count == 0)
            {
                Points.Add(mouseData.Point);
                _firstCoordinateSet = true;
                Points.Add(new Point3D());
                return;
            }
            if (Points.Count == 2)
            {
                InitSession();
                var sketchCreator = new SketchCreator(Document);
                var normalOnPlane = sketchCreator.NormalOnSketch.Value.GpAxis;

                var builder = NodeBuilderUtils.BuildLineInDocument(Document, false, normalOnPlane, Points[0], Points[1]);

                NodeBuilderUtils.BuildDimensionForLine(Document, builder, Points[0], Points[1]);
                UpdateView();
                Points.Clear();
                AddNodeToTree(builder.Node);
                RebuildTreeView();
                Document.Commit("Added Dimension");
            }
        }
Exemplo n.º 11
0
        protected void UpdateLineLock()
        {
            BeginUpdate();

            var constraint = NodeBuilderUtils.ShapeHasConstraint(Parent, Constraint2DNames.LineLengthFunction, _viewInfo.Document);

            if (constraint != -1)
            {
                _viewInfo.Document.Root.Remove(constraint);
                // remove dimension
                var dimensionNodeIndex = 0;
                foreach (var child in _viewInfo.Document.Root.Children)
                {
                    if (child.Value.Get <FunctionInterpreter>().Name == FunctionNames.Dimension)
                    {
                        if (child.Value.Children[1].Get <ReferenceInterpreter>().Node.Index == Parent.Index)
                        {
                            dimensionNodeIndex = child.Value.Index;
                            break;
                        }
                    }
                }
                if (dimensionNodeIndex != 0)
                {
                    _viewInfo.Document.Root.Remove(dimensionNodeIndex);
                }
            }
            else
            {
                NodeBuilderUtils.AddLengthAndDimensionConstraint(_viewInfo.Document, Parent, true);
            }
            EndVisualUpdate("Update constraint");
        }
Exemplo n.º 12
0
        private void RemoveButtonClick(object sender, EventArgs e)
        {
            var constraintDesc = (ConstraintListItem)listConstraints.SelectedItem;

            NodeBuilderUtils.DeleteNode(constraintDesc.Builder.Node, _document);
            RefreshList();
        }
Exemplo n.º 13
0
        public void CutDeleteBaseTest2()
        {
            var document = TestUtils.DefaultsSetup();

            var sketchCreator = new SketchCreator(document, false);
            var sketchNode    = sketchCreator.BuildSketchNode();

            document.Transact();

            var circleBuilder = TestUtils.Circle(document, sketchNode, new Point3D(0, 0, 0), 10);

            TestUtils.Circle(document, sketchNode, new Point3D(20, 20, 0), 10);
            Assert.AreEqual(circleBuilder.LastExecute, true);
            sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, document);
            var extrudeBuilder = new NodeBuilder(document, FunctionNames.Extrude);

            extrudeBuilder[0].Reference = sketchNode;
            extrudeBuilder[1].Integer   = 0;
            extrudeBuilder[2].Real      = 10;
            extrudeBuilder.ExecuteFunction();
            Assert.AreEqual(extrudeBuilder.LastExecute, true);
            document.Commit("Extrude created");
            document.Transact();
            var volume = GeomUtils.GetSolidVolume(extrudeBuilder.Shape);

            Assert.AreEqual(volume, 2 * Math.PI * 1000);
            Assert.AreEqual(document.Root.Children.Count, 6);

            var sketchNode2 = sketchCreator.BuildSketchNode();

            document.Commit("Second sketch created");
            document.Transact();
            TestUtils.Circle(document, sketchNode2, new Point3D(0, 0, 0), 5);
            sketchNode2.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode2, document);

            var cutBuilder = new NodeBuilder(document, FunctionNames.Cut);

            cutBuilder[0].Reference = sketchNode2;
            cutBuilder[2].Integer   = (int)ExtrusionTypes.MidPlane;
            cutBuilder[1].Real      = 10000;
            cutBuilder.ExecuteFunction();
            Assert.AreEqual(cutBuilder.LastExecute, true);
            volume = GeomUtils.GetSolidVolume(cutBuilder.Shape);
            Assert.AreEqual(volume, 2 * Math.PI * 1000 - Math.PI * 250);
            Assert.AreEqual(document.Root.Children.Count, 10);

            var nodeToDelete = document.Root[2];

            NodeBuilderUtils.DeleteNode(nodeToDelete, document);
            document.Commit("Deleted");
            document.Transact();
            NodeUtils.RebuildAllSketchFaces(document);
            extrudeBuilder.ExecuteFunction();
            cutBuilder.ExecuteFunction();
            document.Commit("Finished");
            Assert.IsTrue(cutBuilder.LastExecute);
            volume = GeomUtils.GetSolidVolume(cutBuilder.Shape);
            Assert.AreEqual(8, document.Root.Children.Count, "Circle is not deleted");
            Assert.AreEqual(volume, Math.PI * 1000);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a fused face (FaceFuse node) with all the coliding shapes
        /// </summary>
        /// <param name="colidingShapes"></param>
        private static void CreateFusedShape(List <Node> colidingShapes, Document _document)
        {
            var builder      = new NodeBuilder(_document, FunctionNames.FaceFuse);
            var colidingList = new List <SceneSelectedEntity>();

            foreach (var node in colidingShapes)
            {
                colidingList.Add(new SceneSelectedEntity(node));
            }

            builder.Dependency[0].ReferenceList = colidingList;
            bool result = builder.ExecuteFunction();

            if (result == false)
            {
                NodeBuilderUtils.DeleteNode(builder.Node, _document);
                _nodeFused = null;
            }
            else
            {
                _nodeFused = builder.Node;
            }

            // The fused face is not visible in the scene, neither in the tree view
            if (_nodeFused != null)
            {
                Hide(_nodeFused);
                _nodeFused.Set <TreeViewVisibilityInterpreter>();
            }
        }
        private void MouseDownHandler(Mouse3DPosition mouseData)
        {
            if (_currentHandler == null)
            {
                return;
            }
            _currentHandler.previousMousePosition = mouseData.Point.GpPnt;
            _currentHandler.startX = mouseData.Initial2Dx;
            _currentHandler.startY = mouseData.Initial2Dy;
            var selectedNodes = NodeBuilderUtils.IdentifyShapesUnderMouse(_editingDocument.Root, mouseData.Initial2Dx,
                                                                          mouseData.Initial2Dy, ViewInfo.View);

            if (selectedNodes.Count <= 0 && (_currentHandler.SelectedEntity == null || _currentHandler.SelectedEntity.Node == null))
            {
                return;
            }
            if (selectedNodes.Count > 0)
            {
                _currentHandler.StartDragging(selectedNodes[0]);
            }
            else
            {
                _currentHandler.StartDragging(_currentHandler.SelectedEntity);
            }
            var pusherInput = ActionsGraph[InputNames.CommandLinePrePusher];

            pusherInput.Send(NotificationNames.Reset);
            pusherInput.Send(NotificationNames.PushValue, _currentHandler);
            pusherInput.Send(NotificationNames.PushValue, _editingDocument);
            _editingDocument.Transact();

            ViewInfo.SwitchAction(ModifierNames.HandleDragging);
        }
Exemplo n.º 16
0
 public static void TranslateSketchNode(NodeBuilder nodeBuilder, Point3D translateValue, Node sketchNode)//, gpTrsf translation)
 {
     if (nodeBuilder.FunctionName == FunctionNames.Point)
     {
         gpTrsf translation        = new gpTrsf();
         var    sketchAxisLocation = NodeBuilderUtils.GetTransformedAxis(new NodeBuilder(sketchNode)).Location;
         var    newValue           = new Point3D(sketchAxisLocation.X + translateValue.X, sketchAxisLocation.Y + translateValue.Y,
                                                 sketchAxisLocation.Z + translateValue.Z);
         translation.SetTranslation(sketchAxisLocation, newValue.GpPnt);
         nodeBuilder.Node.Set <TransformationInterpreter>().CurrTransform = translation;
         nodeBuilder.ExecuteFunction();
     }
     else
     {
         var affectedPoints = GetPointNodes(nodeBuilder.Node);
         if (affectedPoints == null)
         {
             return;
         }
         var sketchAxisLocation = NodeBuilderUtils.GetTransformedAxis(new NodeBuilder(sketchNode)).Location;
         foreach (var point in affectedPoints)
         {
             var nb       = new NodeBuilder(point);
             var oldValue = nb[1].TransformedPoint3D;
             var newValue = new Point3D(oldValue.X + translateValue.X, oldValue.Y + translateValue.Y,
                                        oldValue.Z + translateValue.Z);
             var translation = new gpTrsf();
             translation.SetTranslation(sketchAxisLocation, newValue.GpPnt);
             nb.Node.Set <TransformationInterpreter>().CurrTransform = translation;
             nb.ExecuteFunction();
         }
     }
 }
Exemplo n.º 17
0
        public override bool Execute()
        {
            var nodes = NodeBuilderUtils.CopyPaste(Dependency[0].ReferenceBuilder.Node);

            var nb          = new NodeBuilder(Dependency[1].ReferenceBuilder.Node);
            var sketchNodes = new List <Node>();

            foreach (var point in nodes)
            {
                var transformation = point.Set <TransformationInterpreter>();
                transformation.CurrTransform.SetMirror(nb.Dependency[1].TransformedPoint3D.GpPnt);
                var node = NodeBuilderUtils.FindSketchNode(point);
                if (node != null)
                {
                    sketchNodes.Add(node);
                }
                var nb1 = new NodeBuilder(point);
                nb1.ExecuteFunction();
            }

            if (sketchNodes.Count > 0)
            {
                var document = sketchNodes[0].Root.Get <DocumentContextInterpreter>().Document;
                foreach (var sketchNode in sketchNodes)
                {
                    int shapeIndex = 0;
                    if (NodeUtils.SketchHas3DApplied(document, sketchNode, out shapeIndex))
                    {
                        sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, document);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 18
0
        protected override void PreviewFillet()
        {
            InitSession();
            bool result;
            bool linesChamfer = _filletNodes[0].Node.Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name == FunctionNames.LineTwoPoints &&
                                _filletNodes[1].Node.Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name == FunctionNames.LineTwoPoints;

            if (!linesChamfer)
            {
                Builder = new NodeBuilder(Document, FunctionNames.Fillet2D);
                Builder[0].ReferenceList = SelectedShapes;
                Builder[1].Real          = SizeWindow.Value;
                Builder[2].Integer       = (int)FilletChamferTypes.SimpleChamfer2D;
                result = Builder.ExecuteFunction();
                SizeWindow.FailedValue = !result;
            }
            else
            {
                result = NodeBuilderUtils.BuildChamfer(_filletNodes[0], _filletNodes[1], AnimationDocument, Document, SizeWindow.Value);
                AnimationDocument.Revert();
            }
            if (!result)
            {
                InitSession();
            }

            Send(InputNames.View, NotificationNames.RefreshView);
        }
Exemplo n.º 19
0
        public void DeleteLineTest()
        {
            var document = TestUtils.DefaultsSetup();

            document.Transact();
            var sketchCreator = new SketchCreator(document, false);
            var sketchNode    = sketchCreator.BuildSketchNode();

            var pointBuilder = new NodeBuilder(document, FunctionNames.Point);

            pointBuilder[0].Reference          = sketchNode;
            pointBuilder[1].TransformedPoint3D = new Point3D();
            var pointBuilder2 = new NodeBuilder(document, FunctionNames.Point);

            pointBuilder2[0].Reference          = sketchNode;
            pointBuilder2[1].TransformedPoint3D = new Point3D(1, 1, 0);
            pointBuilder.ExecuteFunction();
            var lineBuilder = new NodeBuilder(document, FunctionNames.LineTwoPoints);

            lineBuilder[0].Reference = pointBuilder.Node;
            lineBuilder[1].Reference = pointBuilder2.Node;
            lineBuilder.ExecuteFunction();

            var nodeToDelete = document.Root[3];

            NodeBuilderUtils.DeleteNode(nodeToDelete, document);
            document.Commit("Deleted");
            Assert.AreEqual(1, document.Root.Children.Count, "Line is not deleted");
            Assert.AreEqual(FunctionNames.Sketch, document.Root[0].Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name);
        }
Exemplo n.º 20
0
        private void SetRotateValue(object data)
        {
            BeginUpdate();

            var nodeBuilder   = new NodeBuilder(Parent);
            var mouseRotation = TransformationInterpreter.GetRotateTrsf((Point3D)data);
            var sketchNode    = NodeBuilderUtils.FindBaseSketchNode(Parent);

            var document = sketchNode.Root.Get <DocumentContextInterpreter>().Document;

            if (!NodeUtils.NodeIsOnSketch(nodeBuilder))
            {
                var list        = NodeBuilderUtils.GetAllContained3DNodesIndexes(nodeBuilder.Node).Distinct().ToList();
                var sketchNodes = new List <Node>();
                foreach (var nodeIndex in list)
                {
                    var node             = document.Root[nodeIndex.Key];
                    var shapeNodeBuilder = new NodeBuilder(node);
                    if (FunctionNames.GetSolids().Contains(nodeBuilder.FunctionName))
                    {
                        continue;
                    }

                    var affectedSketchNode = shapeNodeBuilder.Dependency[0].ReferenceBuilder.Node;

                    if (affectedSketchNode != null)
                    {
                        var nb1 = new NodeBuilder(affectedSketchNode);
                        if (nb1.Dependency[2].Reference == null)
                        {
                            sketchNodes.Add(affectedSketchNode);
                        }
                    }
                }

                document.Transact();
                foreach (var solid in sketchNodes)
                {
                    var nb          = new NodeBuilder(solid);
                    var trsfCurrent = nb.Node.Get <TransformationInterpreter>().CurrTransform;
                    trsfCurrent = trsfCurrent.Multiplied(mouseRotation);
                    // we need to invert the transformation to make it positive for the x-axis
                    trsfCurrent = trsfCurrent.Inverted;

                    var transformationInfo = new TransformationInfo
                    {
                        SketchIndex    = solid.Index,
                        Transformation = mouseRotation,
                        TrsfIndex      = TransformationInfo.maxTrsfIndex,
                        RefSketchIndex = -2
                    };
                    TransformationInfo.maxTrsfIndex++;
                    TransformationInterpreter.Transformations.Add(transformationInfo);
                    nb.Node.Set <TransformationInterpreter>().CurrTransform = trsfCurrent;
                    nb.ExecuteFunction();
                }
                document.Commit("Rotated");
            }
            EndVisualUpdate("Rotate object");
        }
        public void SetArcInternalAngleBothPositiveTest()
        {
            var sketchCreator = new SketchCreator(_document, false);
            var sketchNode = sketchCreator.BuildSketchNode();
            _document.Transact();

            // s >0, e > 0, s > e
            var arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(0.535898, 2, 0),
                                           new Point3D(7.464101, 2, 0));
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 240) < 0.00001, "Incorrect internal angle");
            var endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 300);

            Assert.IsTrue(Math.Abs(endPoint.X - 4) < 0.00001);
            Assert.IsTrue(Math.Abs(endPoint.Y - 4) < 0.00001);

            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(0.535898, 2, 0),
                                           new Point3D(7.464101, 2, 0));
            
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 240) < 0.00001, "Incorrect internal angle");
            endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 180);

            Assert.IsTrue(Math.Abs(endPoint.X - 7.464101) < 0.00001);
            Assert.IsTrue(Math.Abs(endPoint.Y + 2) < 0.00001);

            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(4, 4, 0),
                                          new Point3D(7.464101, 2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 300) < 0.00001, "Incorrect internal angle");
            endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 60);

            Assert.IsTrue(Math.Abs(endPoint.X - 0.535898) < 0.00001);
            Assert.IsTrue(Math.Abs(endPoint.Y - 2) < 0.00001);

            // s >0, e > 0, s < e

            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(7.464101, 2, 0), new Point3D(0.535898, 2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 120) < 0.00001, "Incorrect internal angle");
            endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 60);

            Assert.IsTrue(Math.Abs(endPoint.X - 4) < 0.00001);
            Assert.IsTrue(Math.Abs(endPoint.Y - 4) < 0.00001);

            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(7.464101, 2, 0), new Point3D(0.535898, 2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 120) < 0.00001, "Incorrect internal angle");
            endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 180);

            Assert.IsTrue(Math.Abs(endPoint.X - 0.535898) < 0.00001);
            Assert.IsTrue(Math.Abs(endPoint.Y + 2) < 0.00001);

            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(4, 4, 0), new Point3D(0.535898, 2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 60) < 0.00001, "Incorrect internal angle");
            endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 300);

            Assert.IsTrue(Math.Abs(endPoint.X - 7.464101) < 0.00001);
            Assert.IsTrue(Math.Abs(endPoint.Y - 2) < 0.00001);
        }
Exemplo n.º 22
0
        public override bool Execute()
        {
            var axis      = NodeBuilderUtils.GetTransformedAxis(Dependency[0].ReferenceBuilder);
            var zoomLevel = CoreGlobalPreferencesSingleton.Instance.ZoomLevel;

            Shape = OccShapeCreatorCode.CreateCircle(axis, zoomLevel);
            return(true);
        }
        private void PreviewLine()
        {
            InitSession();
            var builder = NodeBuilderUtils.BuildLineInDocument(Document, false, normalOnPlane, Points[0], Points[1]);

            PreviewLineInDocument(Document, Points[0], Points[1]);
            NodeBuilderUtils.BuildDimensionForLine(Document, builder, Points[0], Points[1]);
        }
Exemplo n.º 24
0
        private void SetInternalRadius(object data)
        {
            BeginUpdate();
            Builder[2].Real = (double)data;
            NodeBuilderUtils.UpdateSketchesOnFaces(Builder);

            EndVisualUpdate("Extrude depth changed");
        }
Exemplo n.º 25
0
 private void OnSetLengthValueHandler(object data)
 {
     BeginUpdate();
     TreeUtils.SetLineLength(Parent, (double)data);
     CallSolverForLineChanges(Parent);
     NodeBuilderUtils.UpdateSketchesOnFaces(new NodeBuilder(Parent));
     EndVisualUpdate("Updated length");
 }
        public void GetArcAnglesTest()
        {
            var sketchCreator = new SketchCreator(_document, false);
            var sketchNode = sketchCreator.BuildSketchNode();
            _document.Transact();

            var arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 3, 0), new Point3D(8, 3, 0),
                                           new Point3D(4, 7, 0));

            Assert.AreEqual(NodeBuilderUtils.GetStartAngle(arcBuilder), 0);
            Assert.AreEqual(NodeBuilderUtils.GetEndAngle(arcBuilder), 90);
            Assert.AreEqual(NodeBuilderUtils.GetInternalAngle(arcBuilder), 90);

            // s >0, e > 0, s < e
            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(7.464101, 2, 0),
                                           new Point3D(0.535898, 2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetStartAngle(arcBuilder) - 30) < 0.00001, "Incorrect start angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetEndAngle(arcBuilder) - 150) < 0.00001, "Incorrect end angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 120) < 0.00001, "Incorrect internal angle");

            // s >0, e > 0, s > e
            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(0.535898, 2, 0), new Point3D(7.464101, 2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetStartAngle(arcBuilder) - 150) < 0.00001, "Incorrect start angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetEndAngle(arcBuilder) - 30) < 0.00001, "Incorrect end angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 240) < 0.00001, "Incorrect internal angle");

            // s < 0, e < 0, s > e
            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(7.464101, -2, 0),
                                           new Point3D(0.535898, -2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetStartAngle(arcBuilder) + 30) < 0.00001, "Incorrect start angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetEndAngle(arcBuilder) + 150) < 0.00001, "Incorrect end angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 240) < 0.00001, "Incorrect internal angle");

            // s < 0, e < 0, s < e
            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(0.535898, -2, 0), new Point3D(7.464101, -2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetStartAngle(arcBuilder) + 150) < 0.00001, "Incorrect start angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetEndAngle(arcBuilder) + 30) < 0.00001, "Incorrect end angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 120) < 0.00001, "Incorrect internal angle");

            // s > 0, e < 0 
            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(7.464101, 2, 0),
                                           new Point3D(7.464101, -2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetStartAngle(arcBuilder) - 30) < 0.00001, "Incorrect start angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetEndAngle(arcBuilder) + 30) < 0.00001, "Incorrect end angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 300) < 0.00001, "Incorrect internal angle");

            // s < 0, e > 0
            arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(7.464101, -2, 0), new Point3D(7.464101, 2, 0));

            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetStartAngle(arcBuilder) + 30) < 0.00001, "Incorrect start angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetEndAngle(arcBuilder) - 30) < 0.00001, "Incorrect end angle");
            Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 60) < 0.00001, "Incorrect internal angle");
        }
        private void AddNewPoint(Point3D coordinate)
        {
            if (Points.Count == 2 && Points[0].IsEqual(coordinate))
            {
                return;
            }
            SetCoordinate(coordinate);
            AddNewEmptyPoint();
            if (Points.Count <= 2)
            {
                return;
            }
            var builder = BuildLine();

            AddNodeToTree(builder.Node);

            Hinter2D.SetOrigin(builder[0].RefTransformedPoint3D);
            Hinter2D.Populate();
            Hinter2D.ApplyAlgorithms(new NodeBuilder(builder[0].Reference));
            Hinter2D.ApplyAlgorithms(new NodeBuilder(builder[1].Reference));

            var axis        = NodeBuilderUtils.GetTransformedAxis(new NodeBuilder(sketchNode));
            var result      = Hinter2D.ApplyAlgorithms(builder);
            var constraints = new List <NodeBuilder>();

            foreach (var res in result)
            {
                constraints.AddRange(res.constraintNodes);
            }
            foreach (var constraint in constraints)
            {
                if (constraint.FunctionName == Constraint2DNames.ParallelFunction || constraint.FunctionName == Constraint2DNames.PerpendicularFunction)
                {
                    var secondNode = constraint.Dependency[0].Reference.Index == builder.Node.Index ? constraint.Dependency[1].Reference : constraint.Dependency[0].Reference;
                    NodeBuilderUtils.AdddHintsForNode(Document, secondNode, constraint.Node, axis);
                }
            }

            var sseList = constraints.Select(c => new SceneSelectedEntity(c.Node)).ToList();

            var newNode = new NodeBuilder(Document, FunctionNames.LineHints);

            newNode[0].Reference     = builder.Node;
            newNode[1].ReferenceList = sseList;
            newNode[2].Axis3D        = new Axis(axis);
            newNode.Color            = Color.Black;
            newNode.Node.Set <TransformationInterpreter>().Translate = new gpPnt();
            if (!newNode.ExecuteFunction())
            {
                Document.Root.Remove(newNode.Node.Index);
            }

            CommitFinal("Added line to scene");
            UpdateView();
            Reset();
            Inputs[InputNames.UiElementsItem].Send(NotificationNames.SelectNode, builder.Node);
        }
Exemplo n.º 28
0
        private void SetMinorRadius(object data)
        {
            BeginUpdate();
            var previousMajor = GetPreviousMajorRadius();

            SetRadius(previousMajor, (double)data);
            NodeBuilderUtils.UpdateSketchesOnFaces(new NodeBuilder(Parent));
            EndUpdate(PropertyDescriptorsResources.EllipseTab_Set_minor_radius);
        }
Exemplo n.º 29
0
        private void SetInternalAngleValue(object data)
        {
            if (Builder.Node.Children.Count == 0)
                return;
            BeginUpdate();
            var angle = (double)data;

            Builder[2].RefTransformedPoint3D = NodeBuilderUtils.SetInternalAngle(Builder, angle);
            EndVisualUpdate("");
        }
Exemplo n.º 30
0
        public override void OnActivate()
        {
            Reset();

            _selectedNode = NodeBuilderUtils.IdentifySelectedObjectLabel(Document.Root);
            if (_selectedNode == null)
            {
                BackToNeutralModifier();
            }
        }