예제 #1
0
        protected virtual void OnLoaded(object src, EventArgs args)
        {
            InitializeInputModes();

            // Decorate the lookup of the nodes to change the default behavior
            // for moving, selection paint, resizing, etc.
            IGraph graph = graphControl.Graph;

            ILookupDecorator decorator = graph.Lookup <ILookupDecorator>();

            if (decorator != null && decorator.CanDecorate(typeof(INode)))
            {
                decorator.AddLookup(typeof(INode), new UMLNodeLookupChainLink());
            }

            // register a node grid with the canvas' input mode context lookup
            GridConstraintProvider <INode> nodeGrid = new GridConstraintProvider <INode>(20);
            IContextLookupChainLink        gridLink =
                Lookups.AddingLookupChainLink(typeof(IGridConstraintProvider <INode>), nodeGrid);

            graphControl.InputModeContextLookupChain.Add(gridLink);

            // remove the highlight indicator manager from the input context - disables highlight hints
            IContextLookupChainLink hidingLink = Lookups.HidingLookupChainLink(typeof(HighlightIndicatorManager <IModelItem>));

            graphControl.InputModeContextLookupChain.Add(hidingLink);

            // Create a style
            var umlStyle = new NodeControlNodeStyle("ClassInfoNodeStyle");

            graph.NodeDefaults.Style = umlStyle;

            // Add a sample node
            INode node = CreateNode(null, graphControl.Graph, new PointD(100, 100), null);

            node.Tag = CreateDefaultClassInfo();

            // Enable clipboard
            graphControl.Clipboard = new GraphClipboard
            {
                ToClipboardCopier =
                {
                    Clone                    = GraphCopier.CloneTypes.Tags,
                    ReferentialIdentityTypes = GraphCopier.CloneTypes.All
                },
                FromClipboardCopier =
                {
                    Clone                    = GraphCopier.CloneTypes.Tags,
                    ReferentialIdentityTypes = GraphCopier.CloneTypes.All
                },
                DuplicateCopier =
                {
                    Clone                    = GraphCopier.CloneTypes.Tags,
                    ReferentialIdentityTypes = GraphCopier.CloneTypes.All
                }
            };
        }
예제 #2
0
        /// <summary>
        /// Sets, removes and updates the custom selection decoration for nodes,
        /// edges, and labels according to the current settings.
        /// </summary>
        public void UpdateDecoration()
        {
            var selectedZoomMode = (StyleDecorationZoomPolicy)zoomModeComboBox.SelectedItem;

            nodeDecorationInstaller.ZoomPolicy  = selectedZoomMode;
            edgeDecorationInstaller.ZoomPolicy  = selectedZoomMode;
            labelDecorationInstaller.ZoomPolicy = selectedZoomMode;

            var graphDecorator = graphControl.Graph.GetDecorator();
            var nodeDecorator  = graphDecorator.NodeDecorator;
            var edgeDecorator  = graphDecorator.EdgeDecorator;
            var labelDecorator = graphDecorator.LabelDecorator;

            if (!IsChecked(CustomNodeDecoratorButton) && nodeDecorationLookupChainLink != null)
            {
                nodeDecorator.Remove(nodeDecorationLookupChainLink);
                nodeDecorationLookupChainLink = null;
            }
            else if (IsChecked(CustomNodeDecoratorButton) && nodeDecorationLookupChainLink == null)
            {
                nodeDecorationLookupChainLink = nodeDecorator.SelectionDecorator.SetFactory(node => nodeDecorationInstaller);
            }
            if (!IsChecked(CustomEdgeDecoratorButton) && edgeDecorationLookupChainLink != null)
            {
                edgeDecorator.Remove(edgeDecorationLookupChainLink);
                edgeDecorationLookupChainLink = null;
            }
            else if (IsChecked(CustomEdgeDecoratorButton) && edgeDecorationLookupChainLink == null)
            {
                edgeDecorationLookupChainLink = edgeDecorator.SelectionDecorator.SetFactory(edge => edgeDecorationInstaller);
            }
            if (!IsChecked(CustomLabelDecoratorButton) && labelDecorationLookupChainLink != null)
            {
                labelDecorator.Remove(labelDecorationLookupChainLink);
                labelDecorationLookupChainLink = null;
            }
            else if (IsChecked(CustomLabelDecoratorButton) && labelDecorationLookupChainLink == null)
            {
                labelDecorationLookupChainLink = labelDecorator.SelectionDecorator.SetFactory(label => labelDecorationInstaller);
            }
        }
예제 #3
0
        public UMLClassStyleDemo()
        {
            InitializeComponent();
            InitializeInputModes();
            openButton.SetCommand(Commands.Open, graphControl);

            saveButton.SetCommand(Commands.SaveAs, graphControl);

            graphControl.FileOperationsEnabled = true;


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

            // Decorate the lookup of the nodes to change the default behavior
            // for moving, selection paint, resizing, etc.
            IGraph graph = graphControl.Graph;

            graph.SetUndoEngineEnabled(true);

            var nodeDecorator = graph.GetDecorator().NodeDecorator;

            // set a custom IPositionHandler for nodes with UMLClassStyle
            nodeDecorator.PositionHandlerDecorator.SetImplementationWrapper(
                node => node.Style is UMLClassStyle,
                (node, handler) => new UMLPositionHandler(handler, node));

            // for resizing the item using a shadow and grid
            nodeDecorator.ReshapeHandleProviderDecorator.SetImplementationWrapper(
                node => node.Style is UMLClassStyle,
                (node, provider) => {
                if (provider is ReshapeHandleProviderBase)
                {
                    ((ReshapeHandleProviderBase)provider).HandlePositions = HandlePositions.East | HandlePositions.West;
                }
                return(provider);
            });
            nodeDecorator.NodeSnapResultProviderDecorator.SetImplementation(node => node.Style is UMLClassStyle, new MyNodeSnapResultProvider());

            // constrain the size
            nodeDecorator.SizeConstraintProviderDecorator.SetImplementation(
                node => node.Style is UMLClassStyle,
                new NodeSizeConstraintProvider(new SizeD(100, 0), new SizeD(800, double.MaxValue)));


            // to decorate the node's lookup for types which are not provided with the GraphDecorator
            // we need to decorate the "low level" lookup decorator:
            var lookupDecorator = graph.SafeLookup <ILookupDecorator>();

            // set a custom IReshapeHandler
            // for dragging the item using a shadow and grid
            lookupDecorator.Add <INode, IReshapeHandler>((node, handler) => new UMLReshapeHandler(handler));

            // get the class info from the tag:
            lookupDecorator.Add <INode, ClassInfo>(node => node.Tag as ClassInfo);

            // register a node grid with the canvas' input mode context lookup
            GridConstraintProvider <INode> nodeGrid = new GridConstraintProvider <INode>(20);
            IContextLookupChainLink        gridLink =
                Lookups.AddingLookupChainLink(typeof(IGridConstraintProvider <INode>), nodeGrid);

            graphControl.InputModeContextLookupChain.Add(gridLink);

            // remove the highlight indicator manager from the input context - disables highlight hints
            IContextLookupChainLink hidingLink = Lookups.HidingLookupChainLink(typeof(HighlightIndicatorManager <IModelItem>));

            graphControl.InputModeContextLookupChain.Add(hidingLink);

            // Create a style
            UMLClassStyle umlStyle = new UMLClassStyle();

            graph.NodeDefaults.Style = umlStyle;
            graph.NodeDefaults.Size  = new SizeD(100, 100);

            // Add a sample node
            INode sampleNode = graph.CreateNode(new PointD(100, 100));

            sampleNode.Tag = CreateDefaultClassInfo();
            SizeF preferredSize = umlStyle.GetPreferredSize(sampleNode);

            graph.SetNodeLayout(sampleNode, new RectD(new PointD(100, 100), preferredSize));

            // Enable clipboard
            graphControl.Clipboard = new GraphClipboard {
                ToClipboardCopier =
                {
                    Clone                    = GraphCopier.CloneTypes.Tags,
                    ReferentialIdentityTypes = GraphCopier.CloneTypes.All
                },
                FromClipboardCopier =
                {
                    Clone                    = GraphCopier.CloneTypes.Tags,
                    ReferentialIdentityTypes = GraphCopier.CloneTypes.All
                },
                DuplicateCopier =
                {
                    Clone                    = GraphCopier.CloneTypes.Tags,
                    ReferentialIdentityTypes = GraphCopier.CloneTypes.All
                }
            };
        }