コード例 #1
0
        public DragAndDropForm()
        {
            InitializeComponent();

            description.LoadFile(new MemoryStream(Resources.description), RichTextBoxStreamType.RichText);

            InitializeStylesList();

            // add the visual grid
            const int gridWidth = 80;
            GridInfo  gridInfo  = new GridInfo(gridWidth);

            var grid = new GridVisualCreator(gridInfo);

            graphControl.BackgroundGroup.AddChild(grid, CanvasObjectDescriptors.AlwaysDirtyInstance);

            // Create and configure a GraphSnapContext to enable snapping
            var context = new GraphSnapContext
            {
                NodeToNodeDistance         = 30,
                NodeToEdgeDistance         = 20,
                SnapOrthogonalMovement     = false,
                SnapDistance               = 10,
                SnapSegmentsToSnapLines    = true,
                NodeGridConstraintProvider = new GridConstraintProvider <INode>(gridInfo),
                BendGridConstraintProvider = new GridConstraintProvider <IBend>(gridInfo),
                SnapBendsToSnapLines       = true,
                GridSnapType               = GridSnapTypes.All
            };

            // Create and register a graph editor input mode for editing the graph
            // in the canvas.
            var editorInputMode = new GraphEditorInputMode();

            editorInputMode.SnapContext             = context;
            editorInputMode.AllowGroupingOperations = true;

            ConfigureNodeDropInputMode(editorInputMode);

            // use the mode in our control
            graphControl.InputMode = editorInputMode;


            // Set the default node style to the style of the first item in the list of nodes
            if (styleListBox.Items.Count > 0)
            {
                INode node = styleListBox.Items[0] as INode;
                if (node != null)
                {
                    graphControl.Graph.NodeDefaults.Style = node.Style;
                }
            }
            graphControl.Graph.SetUndoEngineEnabled(true);

            // populate the control with some nodes
            CreateSampleGraph();

            featuresComboBox.Items.AddRange(functionOptions);
            featuresComboBox.SelectedIndex = 0;
        }
コード例 #2
0
        private void InitializeSnapping()
        {
            // Initialize snapping state
            SnappingEnabled = snappingButton.Checked;

            // Initialize SnapContext
            GraphEditorInputMode geim = graphControl.InputMode as GraphEditorInputMode;

            if (geim != null)
            {
                graphSnapContext = new GraphSnapContext
                {
                    // disable snapping features as shown in previous tutorial step
                    // so they won't distract from grid snapping.
                    // Please note that snapping and grid snapping
                    // can be used together
                    Enabled = SnappingEnabled,
                    SnapBendAdjacentSegments = false,
                    SnapBendsToSnapLines     = false,
                    SnapNodesToSnapLines     = false,
                    SnapOrthogonalMovement   = false,
                    SnapPortAdjacentSegments = false,
                    SnapSegmentsToSnapLines  = false
                };
                labelSnapContext = new LabelSnapContext
                {
                    Enabled = SnappingEnabled,
                };
                geim.SnapContext      = graphSnapContext;
                geim.LabelSnapContext = labelSnapContext;
            }
        }
コード例 #3
0
        override protected void CollectGridSnapResults(GraphSnapContext context, CollectSnapResultsEventArgs args, RectD suggestedLayout, INode node)
        {
            // node.Layout isn't updated, yet, so we have to calculate the delta between the the new suggested layout and the current node.Layout
            PointD delta = suggestedLayout.TopLeft - node.Layout.GetTopLeft();

            // get outline of the shape and iterate over it's path point
            IShapeGeometry geometry = node.Style.Renderer.GetShapeGeometry(node, node.Style);
            GeneralPath    outline  = geometry.GetOutline();

            if (outline != null)
            {
                GeneralPath.PathCursor cursor = outline.CreateCursor();
                while (cursor.MoveNext())
                {
                    // ignore PathType.Close as we had the path point as first point
                    // and cursor.CurrentEndPoint is always (0, 0) for PathType.Close
                    if (cursor.PathType != PathType.Close)
                    {
                        // adjust path point by the delta calculated above and add an according SnapResult
                        PointD endPoint = cursor.CurrentEndPoint + delta;
                        AddGridSnapResultCore(context, args, endPoint, node, GridSnapTypes.GridPoints, SnapPolicy.ToNearest, SnapPolicy.ToNearest);
                    }
                }
            }
        }
コード例 #4
0
 protected virtual void InitializeSnapContext()
 {
     snapContext         = new GraphSnapContext();
     snapContext.Enabled = false;
     // disable grid snapping
     snapContext.GridSnapType = GridSnapTypes.None;
     // add constraint provider for nodes, bends, and ports
     snapContext.NodeGridConstraintProvider = new GridConstraintProvider <INode>(gridInfo);
     snapContext.BendGridConstraintProvider = new GridConstraintProvider <IBend>(gridInfo);
     snapContext.PortGridConstraintProvider = new GridConstraintProvider <IPort>(gridInfo);
 }
コード例 #5
0
        public DragAndDropWindow()
        {
            InitializeComponent();

            InitializeStylesList();

            // add the visual grid
            const int gridWidth = 80;
            GridInfo  gridInfo  = new GridInfo(gridWidth);

            var grid = new GridVisualCreator(gridInfo);

            graphControl.BackgroundGroup.AddChild(grid);

            // Create and configure a GraphSnapContext to enable snapping
            var context = new GraphSnapContext
            {
                NodeToNodeDistance         = 30,
                NodeToEdgeDistance         = 20,
                SnapOrthogonalMovement     = false,
                SnapDistance               = 10,
                SnapSegmentsToSnapLines    = true,
                NodeGridConstraintProvider = new GridConstraintProvider <INode>(gridInfo),
                BendGridConstraintProvider = new GridConstraintProvider <IBend>(gridInfo),
                SnapBendsToSnapLines       = true,
                GridSnapType               = GridSnapTypes.All
            };

            // Create and register a graph editor input mode for editing the graph
            // in the canvas.
            var editorInputMode = new GraphEditorInputMode {
                AllowGroupingOperations = true
            };

            editorInputMode.SnapContext = context;
            editorInputMode.OrthogonalEdgeEditingContext = new OrthogonalEdgeEditingContext();
            // use the style, size and labels of the currently selected palette node for newly created nodes
            editorInputMode.NodeCreator = GetNodeCreator(editorInputMode.NodeCreator);

            ConfigureNodeDropInputMode(editorInputMode);

            // use the mode in our control
            graphControl.InputMode = editorInputMode;

            // Enable undo
            graphControl.Graph.SetUndoEngineEnabled(true);

            // populate the control with some nodes
            CreateSampleGraph();

            featuresComboBox.ItemsSource   = functionOptions;
            featuresComboBox.SelectedIndex = 0;
        }
コード例 #6
0
        /// <summary>
        /// Creates a pre-configured <see cref="GraphSnapContext"/> for this demo.
        /// </summary>
        protected virtual GraphSnapContext CreateGraphSnapContext()
        {
            var context = new GraphSnapContext
            {
                SnapOrthogonalMovement   = false,
                SnapBendAdjacentSegments = true,
                GridSnapType             = GridSnapTypes.All,
                SnapDistance             = 10
            };

            // use the free additional snap lines
            context.CollectSnapLines += CollectAdditionalGraphSnapLines;

            return(context);
        }
コード例 #7
0
        // Adds grid to the GraphControl and grid constraint provider to the snap context
        protected virtual void InitializeGrid(GraphSnapContext context)
        {
            GridInfo gridInfo = new GridInfo {
                HorizontalSpacing = 200, VerticalSpacing = 200
            };

            grid = new GridVisualCreator(gridInfo);
            GraphControl.BackgroundGroup.AddChild(grid, CanvasObjectDescriptors.AlwaysDirtyInstance);

            GraphControl.Invalidate();
            GraphControl.ZoomChanged     += delegate { GraphControl.Invalidate(); };
            GraphControl.ViewportChanged += delegate { GraphControl.Invalidate(); };

            context.NodeGridConstraintProvider = new GridConstraintProvider <INode>(gridInfo);
            context.BendGridConstraintProvider = new GridConstraintProvider <IBend>(gridInfo);
        }
コード例 #8
0
        private void InitializeSnapping()
        {
            // Initialize snapping state
            SnappingEnabled = snappingButton.IsChecked ?? false;

            // Initialize SnapContext
            GraphEditorInputMode geim = graphControl.InputMode as GraphEditorInputMode;

            if (geim != null)
            {
                snapContext = new GraphSnapContext
                {
                    Enabled = SnappingEnabled,
                };
                geim.SnapContext = snapContext;
            }
        }
コード例 #9
0
        public SnapLinesForm()
        {
            InitializeComponent();

            description.LoadFile(new MemoryStream(Resources.description), RichTextBoxStreamType.RichText);

            SetupOptions();

            snapContext = new GraphSnapContext();

            // intialize input mode
            graphEditorInputMode = new GraphEditorInputMode()
            {
                AllowGroupingOperations      = true,
                OrthogonalEdgeEditingContext = new OrthogonalEdgeEditingContext(),
                SnapContext = snapContext
            };
            GraphControl.InputMode = graphEditorInputMode;

            GraphControl.Graph.GetDecorator().EdgeDecorator.EdgeReconnectionPortCandidateProviderDecorator.SetImplementation(
                edge => true, EdgeReconnectionPortCandidateProviders.AllNodeCandidates);

            // initialize grid
            this.gridInfo = new GridInfo {
                HorizontalSpacing = 30, VerticalSpacing = 30
            };
            grid = new GridVisualCreator(gridInfo);
            GraphControl.BackgroundGroup.AddChild(grid);

            snapContext.NodeGridConstraintProvider = new GridConstraintProvider <INode>(gridInfo);
            snapContext.BendGridConstraintProvider = new GridConstraintProvider <IBend>(gridInfo);

            // initialize current values
            OnSnappingChanged(this, null);
            OnGridHorizontalWidthChanged(this, null);
            OnGridVerticalWidthChanged(this, null);

            GraphControl.Invalidate();
            GraphControl.ZoomChanged     += delegate { UpdateGrid(); };
            GraphControl.ViewportChanged += delegate { UpdateGrid(); };

            InitializeGraph();
        }
コード例 #10
0
        /// <summary>
        /// Calls <see cref="ISnapLineProvider.AddSnapLines"/> of the wrapped provider and adds custom <see cref="OrthogonalSnapLine"/>s
        /// for the <paramref name="item"/>.
        /// </summary>
        /// <param name="context">The context which holds the settings for the snap lines. </param>
        /// <param name="args">The argument to use for adding snap lines.</param>
        /// <param name="item">The item to add snaplines for.</param>
        public void AddSnapLines(GraphSnapContext context, CollectGraphSnapLinesEventArgs args, IModelItem item)
        {
            wrapped.AddSnapLines(context, args, item);

            // add snaplines for orthogonal labels
            ILabelOwner labelOwner = item as ILabelOwner;

            if (labelOwner != null)
            {
                foreach (ILabel label in labelOwner.Labels)
                {
                    var    layout = label.GetLayout();
                    double upX    = Math.Round(layout.UpX, 6); // round UpX to it's first 6 digits
                    if (upX == 0 || upX == 1 || upX == -1)     // check if it's orthogonal
                    // label is orthogonal
                    {
                        RectD bounds = layout.GetBounds();

                        // add snaplines to the top, bottom, left and right border of the label
                        PointD topCenter = bounds.TopLeft + new PointD(layout.Width / 2, 0);
                        var    snapLine  = new OrthogonalSnapLine(SnapLineOrientation.Horizontal, SnapLineSnapTypes.Bottom,
                                                                  SnapLine.SnapLineFixedLineKey, topCenter, bounds.MinX - 10, bounds.MaxX + 10, label, 100);
                        args.AddAdditionalSnapLine(snapLine);

                        PointD bottomCenter = bounds.BottomLeft + new PointD(layout.Width / 2, 0);
                        snapLine = new OrthogonalSnapLine(SnapLineOrientation.Horizontal, SnapLineSnapTypes.Top,
                                                          SnapLine.SnapLineFixedLineKey, bottomCenter, bounds.MinX - 10, bounds.MaxX + 10, label, 100);
                        args.AddAdditionalSnapLine(snapLine);

                        PointD leftCenter = bounds.TopLeft + new PointD(0, layout.Height / 2);
                        snapLine = new OrthogonalSnapLine(SnapLineOrientation.Vertical, SnapLineSnapTypes.Right,
                                                          SnapLine.SnapLineFixedLineKey, leftCenter, bounds.MinY - 10, bounds.MaxY + 10, label, 100);
                        args.AddAdditionalSnapLine(snapLine);

                        PointD rightCenter = bounds.TopRight + new PointD(0, layout.Height / 2);
                        snapLine = new OrthogonalSnapLine(SnapLineOrientation.Vertical, SnapLineSnapTypes.Left,
                                                          SnapLine.SnapLineFixedLineKey, rightCenter, bounds.MinY - 10, bounds.MaxY + 10, label, 100);
                        args.AddAdditionalSnapLine(snapLine);
                    }
                }
            }
        }
コード例 #11
0
        private void InitializeSnapping()
        {
            // Initializes snapping state
            SnappingEnabled = snappingButton.Checked;

            // Initializes SnapContext
            GraphEditorInputMode geim = graphControl.InputMode as GraphEditorInputMode;

            if (geim != null)
            {
                graphSnapContext = new GraphSnapContext
                {
                    Enabled = SnappingEnabled,
                };
                labelSnapContext = new LabelSnapContext
                {
                    Enabled = SnappingEnabled,
                };
                geim.SnapContext      = graphSnapContext;
                geim.LabelSnapContext = labelSnapContext;
            }
        }
コード例 #12
0
        private void OnLoaded(object source, EventArgs args)
        {
            snapContext = new GraphSnapContext();

            // intialize input mode
            graphEditorInputMode = new GraphEditorInputMode()
            {
                AllowGroupingOperations      = true,
                OrthogonalEdgeEditingContext = new OrthogonalEdgeEditingContext(),
                SnapContext = snapContext
            };
            GraphControl.InputMode = graphEditorInputMode;

            GraphControl.Graph.GetDecorator().EdgeDecorator.EdgeReconnectionPortCandidateProviderDecorator.SetImplementation(
                edge => true, EdgeReconnectionPortCandidateProviders.AllNodeCandidates);

            // initialize grid
            this.gridInfo = new GridInfo {
                HorizontalSpacing = 30, VerticalSpacing = 30
            };
            grid = new GridVisualCreator(gridInfo);
            GraphControl.BackgroundGroup.AddChild(grid);

            snapContext.NodeGridConstraintProvider = new GridConstraintProvider <INode>(gridInfo);
            snapContext.BendGridConstraintProvider = new GridConstraintProvider <IBend>(gridInfo);

            // initialize current values
            OnSnappingChanged(this, null);
            OnGridHorizontalWidthChanged(this, null);
            OnGridVerticalWidthChanged(this, null);

            GraphControl.Invalidate();
            GraphControl.ZoomChanged     += delegate { UpdateGrid(); };
            GraphControl.ViewportChanged += delegate { UpdateGrid(); };

            InitializeGraph();
        }
コード例 #13
0
 protected override void CollectGridSnapResults(GraphSnapContext context, CollectSnapResultsEventArgs args, RectD suggestedLayout, INode node)
 {
     AddGridSnapResult(context, args, suggestedLayout.GetTopLeft(), node);
 }