public void ComputeHorizontal()
        {
            var document   = TestUtils.DefaultsSetup();
            var sketch     = new SketchCreator(document);
            var sketchNode = sketch.BuildSketchNode();

            document.Transact();

            var pointLinker = sketch.PointLinker;
            var line        = ConstraintUtils.BuildLine(document, pointLinker, new Point3D(1, 1, 0), new Point3D(3, 1, 0));
            var options     = new SketchHinterOptions
            {
                ParallelAngle = GeomUtils.DegreesToRadians(5.0),
                PointRange    = 3.0
            };
            var sketchHinter = new Hinter2D(sketchNode, document, options);

            sketchHinter.Populate();

            var result = sketchHinter.ApplyAlgorithms(line);

            document.Commit("Drawn line");

            Assert.AreEqual(sketchHinter.HinterShapes[line.Node.Index].Builder.Node.Index, line.Node.Index);
            Assert.IsNotEmpty(result);
        }
        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);
        }
Exemple #3
0
        // Draw two parallel lines and delete one of the points -> constraint and line should be deleted, as well
        public void ParallelLinesDeletePointTest()
        {
            var document = TestUtils.DefaultsSetup();

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

            document.Transact();

            TestUtils.Line(document, sketchNode, new Point3D(0, 0, 0), new Point3D(1, 1, 0));

            var lineBuilder2 = TestUtils.Line(document, sketchNode, new Point3D(0, 1, 0), new Point3D(1, 2, 0));

            document.Commit("Drawn line");
            document.Transact();
            var options = new SketchHinterOptions
            {
                ParallelAngle = GeomUtils.DegreesToRadians(5.0),
                PointRange    = 3.0
            };
            var sketchHinter = new Hinter2D(sketchNode, document, options);

            sketchHinter.Populate();

            sketchHinter.ApplyAlgorithms(lineBuilder2);
            document.Commit("Parallel constraint added");
            document.Transact();
            Assert.AreEqual(document.Root.Children.Count, 8);
            Assert.AreEqual(document.Root[7].Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name, Constraint2DNames.ParallelFunction);

            var nodeToDelete = document.Root[2];

            NodeBuilderUtils.DeleteNode(nodeToDelete, document);
            document.Commit("Deleted");
            // the other line point remains
            Assert.AreEqual(5, document.Root.Children.Count, "Line is not deleted");
        }
Exemple #4
0
        // Draw two parallel lines and delete one of the lines -> constraint should be deleted, as well
        public void RectangleDeleteLineTest()
        {
            var document = TestUtils.DefaultsSetup();

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

            document.Transact();

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

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

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

            pointBuilder3[0].Reference          = sketchNode;
            pointBuilder3[1].TransformedPoint3D = new Point3D(7, 4, 0);
            pointBuilder3.ExecuteFunction();
            var pointBuilder4 = new NodeBuilder(document, FunctionNames.Point);

            pointBuilder4[0].Reference          = sketchNode;
            pointBuilder4[1].TransformedPoint3D = new Point3D(1, 4, 0);
            pointBuilder4.ExecuteFunction();

            var lineBuilder = new NodeBuilder(document, FunctionNames.LineTwoPoints);

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


            var lineBuilder2 = new NodeBuilder(document, FunctionNames.LineTwoPoints);

            lineBuilder2[0].Reference = pointBuilder2.Node;
            lineBuilder2[1].Reference = pointBuilder3.Node;
            lineBuilder2.ExecuteFunction();

            var lineBuilder3 = new NodeBuilder(document, FunctionNames.LineTwoPoints);

            lineBuilder3[0].Reference = pointBuilder3.Node;
            lineBuilder3[1].Reference = pointBuilder4.Node;
            lineBuilder3.ExecuteFunction();

            var lineBuilder4 = new NodeBuilder(document, FunctionNames.LineTwoPoints);

            lineBuilder4[0].Reference = pointBuilder4.Node;
            lineBuilder4[1].Reference = pointBuilder.Node;
            lineBuilder4.ExecuteFunction();
            document.Commit("Drawn line");
            document.Transact();
            var options = new SketchHinterOptions
            {
                ParallelAngle = GeomUtils.DegreesToRadians(5.0),
                PointRange    = 3.0
            };
            var sketchHinter = new Hinter2D(sketchNode, document, options);

            sketchHinter.Populate();

            sketchHinter.ApplyAlgorithms(lineBuilder2);
            sketchHinter.ApplyAlgorithms(lineBuilder);
            document.Commit("Perpendicular constraint added");
            document.Transact();

            Assert.AreEqual(document.Root.Children.Count, 15);
            var nodeToDelete = document.Root[3];

            NodeBuilderUtils.DeleteNode(nodeToDelete, document);
            document.Commit("Deleted");
            Assert.AreEqual(7, document.Root.Children.Count, "Line is not deleted");
        }
Exemple #5
0
        // Draw two parallel lines and delete one of the lines -> constraint should be deleted, as well
        public void PerpendicularDeleteLineTest()
        {
            var document = TestUtils.DefaultsSetup();
            var sh       = new ShapeGraph();

            sh.SetDocument(document);

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

            document.Transact();

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

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

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

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

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

            pointBuilder3[0].Reference          = sketchNode;
            pointBuilder3[1].TransformedPoint3D = new Point3D(4, 5, 0);
            pointBuilder3.ExecuteFunction();
            var lineBuilder2 = new NodeBuilder(document, FunctionNames.LineTwoPoints);

            lineBuilder2[0].Reference = pointBuilder2.Node;
            lineBuilder2[1].Reference = pointBuilder3.Node;
            lineBuilder2.ExecuteFunction();

            document.Commit("Drawn line");
            document.Transact();
            var options = new SketchHinterOptions
            {
                ParallelAngle = GeomUtils.DegreesToRadians(5.0),
                PointRange    = 3.0
            };
            var sketchHinter = new Hinter2D(sketchNode, document, options);

            sketchHinter.Populate();

            sketchHinter.ApplyAlgorithms(lineBuilder2);
            document.Commit("Perpendicular constraint added");
            document.Transact();
            Assert.AreEqual(document.Root.Children.Count, 7);
            Assert.AreEqual(document.Root[6].Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name, Constraint2DNames.PerpendicularFunction);

            var nodeToDelete = document.Root[3];

            NodeBuilderUtils.DeleteNode(nodeToDelete, document);
            document.Commit("Deleted");
            Assert.AreEqual(4, document.Root.Children.Count, "Line is not deleted");
        }
Exemple #6
0
        // Draw two parallel lines and delete one of the lines -> constraint should be deleted, as well
        public void PerpendicularLinesTest()
        {
            var document = TestUtils.DefaultsSetup();
            var sh       = new ShapeGraph();

            sh.SetDocument(document);

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

            document.Transact();

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

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

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

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

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

            pointBuilder3[0].Reference          = sketchNode;
            pointBuilder3[1].TransformedPoint3D = new Point3D(4, 5, 0);
            pointBuilder3.ExecuteFunction();
            var lineBuilder2 = new NodeBuilder(document, FunctionNames.LineTwoPoints);

            lineBuilder2[0].Reference = pointBuilder2.Node;
            lineBuilder2[1].Reference = pointBuilder3.Node;
            lineBuilder2.ExecuteFunction();

            document.Commit("Drawn line");
            document.Transact();
            var options = new SketchHinterOptions
            {
                ParallelAngle = GeomUtils.DegreesToRadians(5.0),
                PointRange    = 3.0
            };
            var sketchHinter = new Hinter2D(sketchNode, document, options);

            sketchHinter.Populate();

            sketchHinter.ApplyAlgorithms(lineBuilder2);
            document.Commit("Perpendicular constraint added");
            document.Transact();
            Assert.AreEqual(document.Root.Children.Count, 7);
            Assert.AreEqual(document.Root[6].Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name, Constraint2DNames.PerpendicularFunction);

            var expectedReferringTo = new SortedDictionary <int, List <int> >
            {
                { 1, new List <int> {
                      0
                  } },
                { 2, new List <int> {
                      0
                  } },
                { 3, new List <int> {
                      1, 2
                  } },
                { 4, new List <int> {
                      0
                  } },
                { 5, new List <int> {
                      4, 2
                  } },
                { 6, new List <int> {
                      3, 5
                  } }
            };

            foreach (var key in expectedReferringTo.Keys)
            {
                CollectionAssert.AreEquivalent(expectedReferringTo[key], sh.ReferringTo[key]);
            }
            var expectedReferrencedBy = new SortedDictionary <int, List <int> >
            {
                { 0, new List <int> {
                      1, 2, 4
                  } },
                { 1, new List <int> {
                      3
                  } },
                { 2, new List <int> {
                      3, 5
                  } },
                { 3, new List <int> {
                      6
                  } },
                { 4, new List <int> {
                      5
                  } },
                { 5, new List <int> {
                      6
                  } }
            };

            foreach (var key in expectedReferrencedBy.Keys)
            {
                CollectionAssert.AreEquivalent(expectedReferrencedBy[key], sh.ReferrencedBy[key]);
            }
        }