Example #1
0
 /// <summary>
 /// Creates a new instance for <paramref name="port"/> and its <paramref name="adapter"/>.
 /// </summary>
 /// <param name="context">The context of the reshape gesture.</param>
 /// <param name="port">The port whose visualization shall be resized.</param>
 /// <param name="adapter">The adapter whose render size shall be changed.</param>
 /// <param name="position">The position of the handle.</param>
 public PortReshapeHandle(IInputModeContext context, IPort port, NodeStylePortStyleAdapter adapter, HandlePositions position)
 {
     this.context  = context;
     this.position = position;
     this.adapter  = adapter;
     this.port     = port;
     this.Margins  = 4;
 }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public EventPortStyle()
 {
     adapter = new NodeStylePortStyleAdapter(new EventNodeStyle
     {
         Characteristic = EventCharacteristic.BoundaryInterrupting,
         Type           = EventType.Compensation
     })
     {
         RenderSize = BpmnConstants.EventPortSize
     };
     renderer = EventPortStyleRenderer.Instance;
 }
Example #3
0
        /// <summary>
        ///   Creates the sample graph of this demo.
        /// </summary>
        private void CreateSampleGraph(GraphControl graphControl)
        {
            var graph          = graphControl.Graph;
            var blackPortStyle =
                new NodeStylePortStyleAdapter(new ShapeNodeStyle
            {
                Shape = ShapeNodeShape.Ellipse,
                Brush = Brushes.Black,
                Pen   = null
            })
            {
                RenderSize = new SizeD(3, 3)
            };

            graph.SetUndoEngineEnabled(true);

            CreateSubgraph(graph, Colors.Firebrick, 0);
            CreateSubgraph(graph, Colors.Orange, 200);
            CreateSubgraph(graph, Colors.Green, 600);

            // the blue nodes have some additional ports besides the ones used by the edge
            var nodes = CreateSubgraph(graph, Colors.RoyalBlue, 400);

            graph.AddPort(nodes[0], FreeNodePortLocationModel.Instance.CreateParameter(new PointD(1, 0.2)), blackPortStyle);
            graph.AddPort(nodes[0], FreeNodePortLocationModel.Instance.CreateParameter(new PointD(1, 0.8)), blackPortStyle);

            var candidateProvider = PortCandidateProviders.FromShapeGeometry(nodes[2], 0, 0.25, 0.5, 0.75);

            candidateProvider.Style = blackPortStyle;
            IEnumerable <IPortCandidate> candidates = candidateProvider.GetSourcePortCandidates(graphControl.InputModeContext);

            foreach (IPortCandidate portCandidate in candidates)
            {
                if (portCandidate.Validity != PortCandidateValidity.Dynamic)
                {
                    portCandidate.CreatePort(graphControl.InputModeContext);
                }
            }
            graph.GetUndoEngine().Clear();
        }
 /// <summary>
 /// Creates a new instance for <paramref name="port"/> and its <paramref name="adapter"/>.
 /// </summary>
 /// <param name="port">The port whose visualization shall be resized.</param>
 /// <param name="adapter">The adapter whose render size shall be changed.</param>
 public PortReshapeHandlerProvider(IPort port, NodeStylePortStyleAdapter adapter)
 {
     this.port    = port;
     this.adapter = adapter;
 }
        /// <summary>
        /// Creates the default input mode for the GraphControl,
        /// a <see cref="GraphEditorInputMode"/>.
        /// </summary>
        /// <remarks>
        /// The control uses a custom node creation callback that creates business objects for newly
        /// created nodes.
        /// </remarks>
        /// <returns>a new GraphEditorInputMode instance</returns>
        protected virtual IInputMode CreateEditorMode()
        {
            var mode = new GraphEditorInputMode
            {
                // don't allow nodes to be created using a mouse click
                AllowCreateNode = false,
                // don't allow bends to be created using a mouse drag on an edge
                AllowCreateBend = false,
                // disable node resizing
                ShowHandleItems = GraphItemTypes.Bend | GraphItemTypes.Edge,
                // enable orthogonal edge creation and editing
                OrthogonalEdgeEditingContext = new OrthogonalEdgeEditingContext(),
                // enable drag and drop
                NodeDropInputMode = { Enabled = true },
                // disable moving labels
                MoveLabelInputMode = { Enabled = false },
                // enable snapping for easier orthogonal edge editing
                SnapContext = new GraphSnapContext {
                    Enabled = true
                },
                CreateEdgeInputMode =
                {
                    // only allow starting an edge creation over a valid port candidate
                    StartOverCandidateOnly = true,
                    // show all port candidates when hovering over a node
                    ShowPortCandidates     = ShowPortCandidates.All
                }
            };
            // wrap the original node creator so it copies the ports and labels from the dragged node
            var originalNodeCreator = mode.NodeDropInputMode.ItemCreator;

            mode.NodeDropInputMode.ItemCreator =
                (context, graph, draggedNode, dropTarget, layout) => {
                if (draggedNode != null)
                {
                    var newNode = originalNodeCreator(context, graph, new SimpleNode {
                        Style = draggedNode.Style, Layout = draggedNode.Layout
                    }, dropTarget, layout);
                    // copy the ports
                    foreach (var port in draggedNode.Ports)
                    {
                        var descriptor = (PortDescriptor)port.Tag;
                        var portStyle  = new NodeStylePortStyleAdapter(new ShapeNodeStyle {
                            Brush = descriptor.EdgeDirection == EdgeDirection.In ? Brushes.Green : Brushes.DodgerBlue,
                            Pen   = null,
                            Shape = ShapeNodeShape.Rectangle
                        })
                        {
                            RenderSize = new SizeD(5, 5)
                        };
                        var newPort = graph.AddPort(newNode, port.LocationParameter, portStyle, port.Tag);
                        // create the port labels
                        var parameter = new InsideOutsidePortLabelModel().CreateOutsideParameter();
                        graph.AddLabel(newPort, descriptor.LabelText, parameter, tag: descriptor);
                    }
                    // copy the labels
                    foreach (var label in draggedNode.Labels)
                    {
                        graph.AddLabel(newNode, label.Text, label.LayoutParameter, label.Style, tag: label.Tag);
                    }
                    return(newNode);
                }
                // fallback
                return(originalNodeCreator(context, graph, draggedNode, dropTarget, layout));
            };

            mode.CreateEdgeInputMode.EdgeCreated += (sender, args) => {
                var sourcePortLabel = args.SourcePort.Labels.FirstOrDefault();
                var targetPortLabel = args.TargetPort.Labels.FirstOrDefault();
                if (sourcePortLabel != null)
                {
                    ReplaceLabelModel(args.SourcePort, sourcePortLabel);
                }
                if (targetPortLabel != null)
                {
                    ReplaceLabelModel(args.TargetPort, targetPortLabel);
                }
            };

            graphControl.Graph.EdgeRemoved += (sender, args) => {
                var sourcePortLabel = args.SourcePort.Labels.FirstOrDefault();
                var targetPortLabel = args.TargetPort.Labels.FirstOrDefault();
                if (sourcePortLabel != null && !graphControl.Graph.EdgesAt(args.SourcePort).Any())
                {
                    graphControl.Graph.SetLabelLayoutParameter(sourcePortLabel,
                                                               new InsideOutsidePortLabelModel().CreateOutsideParameter());
                }
                if (targetPortLabel != null && !graphControl.Graph.EdgesAt(args.TargetPort).Any())
                {
                    graphControl.Graph.SetLabelLayoutParameter(targetPortLabel,
                                                               new InsideOutsidePortLabelModel().CreateOutsideParameter());
                }
            };

            return(mode);
        }