示例#1
0
        public void InitializeInputModes()
        {
            // Create a default editor input mode
            GraphEditorInputMode editMode = new GraphEditorInputMode();

            // then customize it to suit our needs

            // orthogonal edges
            editMode.OrthogonalEdgeEditingContext = new OrthogonalEdgeEditingContext();

            // snapping
            editMode.SnapContext = new GraphSnapContext {
                CollectEdgeSnapLines            = false,
                CollectNodePairSegmentSnapLines = false,
                CollectNodePairSnapLines        = false,
                CollectPortSnapLines            = false,
                SnapBendAdjacentSegments        = false,
                SnapPortAdjacentSegments        = false,
                SnapBendsToSnapLines            = false,
                SnapSegmentsToSnapLines         = false,
                GridSnapType = GridSnapTypes.All,
                NodeGridConstraintProvider = new GridConstraintProvider <INode>(20),
                GridSnapDistance           = double.MaxValue,
                VisualizeSnapResults       = false,
            };


            // tweak the CreateEdgeInputMode
            editMode.CreateEdgeInputMode.ShowPortCandidates    = ShowPortCandidates.None;
            editMode.CreateEdgeInputMode.SnapToTargetCandidate = false;

            //Enable label editing only for edges and edge labels
            editMode.LabelEditableItems = GraphItemTypes.Edge | GraphItemTypes.EdgeLabel;

            // we add a command to the KeyboardInputMode, although this will not be triggered
            // by a keyboard gesture, this has the advantage that the command is disabled
            // if any of the input modes owns the mutex.
            editMode.KeyboardInputMode.AddCommandBinding(UMLClassStyle.AdjustNodeBoundsCommand,
                                                         delegate(object sender, ExecutedCommandEventArgs args) {
                INode node = args.Parameter as INode;
                if (node != null && node.Style is UMLClassStyle)
                {
                    UMLClassStyle style = (UMLClassStyle)node.Style;
                    var preferredSize   = style.GetPreferredSize(node);
                    preferredSize       = new SizeD(Math.Max(node.Layout.Width, preferredSize.Width), preferredSize.Height);
                    RectD newBounds     = new RectD(node.Layout.GetTopLeft(), preferredSize);
                    editMode.SetNodeLayout(node, newBounds);
                }
            });

            // customize the node creation
            editMode.NodeCreator = CreateNode;

            // and finally register our input mode with the control.
            graphControl.InputMode = editMode;
        }
示例#2
0
        private void ResizeNodeExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            NodeControl nodeControl = e.OriginalSource as NodeControl;

            if (nodeControl != null)
            {
                // parameter is desired size
                var desiredSize = (Size?)e.Parameter;
                if (desiredSize.HasValue)
                {
                    INode node = nodeControl.Item;
                    GraphEditorInputMode mode   = (GraphEditorInputMode)graphControl.InputMode;
                    IRectangle           layout = node.Layout;
                    // adjust only height
                    mode.SetNodeLayout(node, new RectD(layout.X, layout.Y, layout.Width, desiredSize.Value.Height));
                    e.Handled = true;
                }
            }
        }