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.º 2
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();
     }
 }