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);
        }
        private void ConstraintApplied(object sender, RoutedEventArgs e)
        {
            var button     = (CheckBox)sender;
            var descriptor = (ConstraintDependencyDescription)button.DataContext;
            var isChecked  = button.IsChecked ?? false;

            _document.Transact();
            var functionName = descriptor.FunctionName;

            if (isChecked)
            {
                var firstPointIndex = NodeUtils.GetFirstPointIndex(_nodeList[0]);
                _constraintDocumentHelper.SetMousePosition(firstPointIndex);
                var res = _constraintDocumentHelper.ApplyConstraint(_nodeList, functionName);
                if (res.Node == null)
                {
                    _constraintDocumentHelper.Remove(_nodeList, functionName);
                    MessageBox.Show("Could not apply constraint!");
                }
                else
                {
                    foreach (var node in _nodeList)
                    {
                        NodeBuilderUtils.AdddHintsForNode(_document, node, res.Node);
                    }
                }
            }
            else
            {
                var appliedConstraints = _constraintDocumentHelper.CheckAppliedConstraints(_nodeList);
                foreach (var constraint in appliedConstraints)
                {
                    NodeBuilderUtils.DeleteConstraintNode(_document, constraint);
                }
            }
            _stepsToUndo++;
            _document.Commit("Applied/Removed constraint: " + descriptor.Descriptor);
            EnableUndo = true;
            SceneChanged();
        }
Ejemplo n.º 3
0
 private void ListBoxOnSelectionChanged(object sender, SelectionChangedEventArgs selectionChangedEventArgs)
 {
     if (((ListBox)sender).SelectedItems.Count > 0)
     {
         var sketchNode   = ((NewConstraintInfo)((ListBox)sender).SelectedItems[0]).SketchNode;
         var currentNodes = ((NewConstraintInfo)((ListBox)sender).SelectedItems[0]).SelectedNodes;
         var document     = sketchNode.Root.Get <DocumentContextInterpreter>().Document;
         document.Transact();
         var constraintDocumentHelper = new ConstraintDocumentHelper(document, sketchNode);
         var firstPointIndex          = NodeUtils.GetFirstPointIndex(currentNodes[0]);
         constraintDocumentHelper.SetMousePosition(firstPointIndex);
         var constraintAdded = constraintDocumentHelper.ApplyConstraint(currentNodes,
                                                                        ((NewConstraintInfo)((ListBox)sender).SelectedItems[0]).ConstraintFunctionName);
         if (currentNodes.Count == 1)
         {
             NodeBuilderUtils.AdddHintsForNode(document, currentNodes[0], constraintAdded.Node);
         }
         constraintDocumentHelper.ImpactAndSolve(currentNodes[0]);
         document.Commit("Added constraint to scene");
         UpdateFieldValue();
     }
 }