コード例 #1
0
 /// <summary>
 /// Enable folding - change the GraphControls graph to a managed view
 /// that provides the actual collapse/expand state.
 /// </summary>
 private void EnableFolding()
 {
     // create the manager
     manager = new FoldingManager();
     // replace the displayed graph with a managed view
     graphControl.Graph = manager.CreateFoldingView().Graph;
     WrapGroupNodeStyles();
 }
コード例 #2
0
        /// <summary>
        /// Helper method that creates a window that displays an alternative view of the
        /// MasterGraph using a separate FoldingManager and therefor a separate set of
        /// dummy items.
        /// </summary>
        /// <remarks>
        /// This allows for using different visualizations of the folding edges and collapsed group nodes.
        /// </remarks>
        /// <param name="foldingEdgeConverter">The edge converter to use</param>
        private void ShowAdditionalManager(IFoldingEdgeConverter foldingEdgeConverter)
        {
            // create the GraphControl
            GraphControl graphControl = new GraphControl();

            // create a new manager for the same master graph.
            FoldingManager manager = new FoldingManager(foldingManager.MasterGraph);

            // assign the provided converter
            manager.FoldingEdgeConverter = foldingEdgeConverter;

            // create a view
            IFoldingView foldingView = manager.CreateFoldingView();

            // make the view disappear once it becomes invalid
            foldingView.AutoSwitchToAncestor = false;
            // set the graph
            graphControl.Graph = foldingView.Graph;
            // and edit mode
            graphControl.InputMode = CreateEditorMode();
            // share the clipboard with the rest of the windows
            graphControl.Clipboard = this.graphControl.Clipboard;

            // create the form
            Form form = new Form();

            graphControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;

            form.Size             = new Size(300, 300);
            graphControl.Location = new Point(0, 0);
            graphControl.Size     = form.Size;
            form.Text             = "Separate FoldingManager using " + foldingEdgeConverter;
            form.SuspendLayout();
            form.Controls.Add(graphControl);
            form.ResumeLayout();
            form.Visible = true;
            form.Owner   = this;

            // fit the bounds
            graphControl.FitGraphBounds();

            // setup delegate to dispose the window once the view becomes invalid
            foldingView.PropertyChanged += delegate(object _sender, PropertyChangedEventArgs _e) {
                if (_e.PropertyName == "Invalid" && foldingView.Invalid)
                {
                    manager.Dispose();
                    form.Close();
                    form.Dispose();
                }
            };
        }
コード例 #3
0
 /// <summary>
 /// Enables folding - changes the GraphControl's graph to a managed view
 /// that provides the actual collapse/expand state.
 /// </summary>
 private void EnableFolding()
 {
     // Creates the folding manager and sets its master graph to
     // the single graph that has served for all purposes up to this point
     manager = new FoldingManager(Graph);
     // Creates a managed view from the master graph and
     // replaces the existing graph view with a managed view
     graphControl.Graph = manager.CreateFoldingView().Graph;
     // Change the default style for group nodes. We use <see cref="CollapsibleNodeStyleDecorator"/>
     // to wrap the <see cref="PanelNodeStyle"/> from the last demo, since we want to have nice
     // +/- buttons for collapse/expand. Note that if you haven't defined
     // a custom group node style, you don't have to do anything at all, since
     // <see cref="FoldingManager"/> already
     // provides such a decorated group node style by default.
     Graph.GroupNodeDefaults.Style = new CollapsibleNodeStyleDecorator(Graph.GroupNodeDefaults.Style);
 }
コード例 #4
0
        /// <summary>
        /// Initializes styles and decorators for the graph.
        /// </summary>
        private void InitializeGraph()
        {
            var foldingManager = new FoldingManager();
            var graph          = foldingManager.CreateFoldingView().Graph;

            var decorator = graph.GetDecorator();

            // For rotated nodes, need to provide port candidates that are backed by a rotatable port location model
            // If you want to support non-rotated port candidates, you can just provide undecorated instances here
            decorator.NodeDecorator.PortCandidateProviderDecorator.SetFactory(
                node => node.Style is RotatableNodeStyleDecorator, CreatePortCandidateProvider);

            decorator.PortDecorator.EdgePathCropperDecorator.SetImplementation(new AdjustOutlinePortInsidenessEdgePathCropper());
            decorator.NodeDecorator.GroupBoundsCalculatorDecorator.SetImplementation(new RotationAwareGroupBoundsCalculator());

            graph.NodeDefaults.Style = new RotatableNodeStyleDecorator(new ShinyPlateNodeStyle {
                Brush = Brushes.Orange, DrawShadow = false
            });
            graph.NodeDefaults.ShareStyleInstance = false;
            graph.NodeDefaults.Size = new SizeD(100, 50);

            var coreLabelModel = new InteriorLabelModel();

            graph.NodeDefaults.Labels.LayoutParameter =
                new RotatableNodeLabelModelDecorator(coreLabelModel).CreateWrappingParameter(InteriorLabelModel.Center);

            // Make ports visible
            graph.NodeDefaults.Ports.Style = new NodeStylePortStyleAdapter(new ShapeNodeStyle {
                Shape = ShapeNodeShape.Ellipse, Brush = Brushes.Red
            });
            // Use a rotatable port model as default
            graph.NodeDefaults.Ports.LocationParameter =
                new RotatablePortLocationModelDecorator().CreateWrappingParameter(FreeNodePortLocationModel.NodeTopAnchored);

            graph.GroupNodeDefaults.Style = new PanelNodeStyle {
                Color = Color.LightBlue
            };

            graph.EdgeDefaults.Labels.LayoutParameter = new EdgePathLabelModel {
                Distance = 10
            }.CreateDefaultParameter();

            // enable undo
            foldingManager.MasterGraph.SetUndoEngineEnabled(true);

            graphControl.Graph = graph;
        }
コード例 #5
0
        private void InitializeGraphDefaults()
        {
            FoldingManager fm = new FoldingManager();

            graphControl.Graph = fm.CreateFoldingView().Graph;
            var folderNodeConverter = fm.FolderNodeConverter as DefaultFolderNodeConverter;

            if (folderNodeConverter != null)
            {
                folderNodeConverter.CopyFirstLabel = true;
                folderNodeConverter.FolderNodeSize = new SizeD(80, 60);
            }

            IGraph graph = graphControl.Graph;

            graphControl.NavigationCommandsEnabled = true;

            //Create graph
            graph.NodeDefaults.Size = new SizeD(60, 30);

            // set the style as the default for all new nodes
            graph.NodeDefaults.Style = new ShinyPlateNodeStyle
            {
                Brush  = Brushes.Orange,
                Insets = new InsetsD(5),
                Radius = 5,
            };

            // set the style as the default for all new edges
            graph.EdgeDefaults.Style = new PolylineEdgeStyle {
                TargetArrow = Arrows.Default
            };

            var groupNodeStyle = new CollapsibleNodeStyleDecorator(new PanelNodeStyle
            {
                Color            = Color.FromArgb(255, 202, 220, 255),
                LabelInsetsColor = Color.FromArgb(255, 218, 234, 255),
                Insets           = new InsetsD(15, 31, 15, 15)
            });
            var groupNodeDefaults = graph.GroupNodeDefaults;

            groupNodeDefaults.Labels.LayoutParameter = InteriorStretchLabelModel.North;
            groupNodeDefaults.Labels.Style           = new DefaultLabelStyle {
                StringFormat = { Alignment = StringAlignment.Far }
            };
            groupNodeDefaults.Style = groupNodeStyle;
        }
コード例 #6
0
        /// <summary>
        /// Helper method that creates a window that displays an alternative view of the
        /// MasterGraph using a separate FoldingManager and therefore a separate set of
        /// dummy items.
        /// </summary>
        /// <remarks>
        /// This allows for using different visualizations of the folding edges and collapsed group nodes.
        /// </remarks>
        /// <param name="foldingEdgeConverter">The edge converter to use</param>
        private void ShowAdditionalManager(IFoldingEdgeConverter foldingEdgeConverter)
        {
            // create the window
            Window window = new Window();

            window.Title = "Separate FoldingManager using " + foldingEdgeConverter;

            // create the GraphControl
            GraphControl graphControl = new GraphControl();

            // create a new manager for the same master graph.
            FoldingManager manager = new FoldingManager(foldingManager.MasterGraph);

            // assign the provided converter
            manager.FoldingEdgeConverter = foldingEdgeConverter;

            // create a view
            IFoldingView foldingView = manager.CreateFoldingView();

            // make the view disappear once it becomes invalid
            foldingView.AutoSwitchToAncestor = false;
            // set the graph
            graphControl.Graph = foldingView.Graph;
            // and edit mode
            graphControl.InputMode = CreateEditorMode();
            // share the clipboard with the rest of the windows
            graphControl.Clipboard = this.graphControl.Clipboard;

            // show the window
            window.Content = graphControl;
            window.Width   = window.Height = 300;
            window.Owner   = this;
            window.Show();

            // fit the bounds
            graphControl.FitGraphBounds();

            // setup delegate to dispose the window once the view becomes invalid
            foldingView.PropertyChanged += delegate(object _sender, PropertyChangedEventArgs _e) {
                if (_e.PropertyName == "Invalid" && foldingView.Invalid)
                {
                    manager.Dispose();
                    window.Close();
                }
            };
        }
コード例 #7
0
        private void ShowContents(INode localRoot)
        {
            GraphControl groupContentsGraphControl = new GraphControl();

            // now obtain a view for the given node from the manager
            IFoldingView foldingView = foldingManager.CreateFoldingView(localRoot);

            // instead of switching to the ancestor if the localRoot is removed from the graph,
            // we want to dispose the window, instead.
            foldingView.AutoSwitchToAncestor = false;

            // assign the graph and input mode
            groupContentsGraphControl.Graph     = foldingView.Graph;
            groupContentsGraphControl.InputMode = CreateEditorMode();
            // share the clipboard so that we can cut and copy between the windows
            groupContentsGraphControl.Clipboard = this.graphControl.Clipboard;

            groupContentsGraphControl.SmoothingMode = this.graphControl.SmoothingMode;

            // Create the form
            Form form = new Form();

            form.Load += delegate {
                groupContentsGraphControl.FitGraphBounds();
            };
            // show the master graph
            groupContentsGraphControl.Dock = DockStyle.Fill;
            form.ClientSize = new Size(300, 300);
            form.Text       = "Contents of " + localRoot;
            form.SuspendLayout();
            form.Controls.Add(groupContentsGraphControl);
            form.ResumeLayout();
            form.Owner   = this;
            form.Visible = true;

            // setup delegate to dispose the window once the view becomes invalid
            foldingView.PropertyChanged += delegate(object _sender, PropertyChangedEventArgs _e) {
                if (_e.PropertyName == "Invalid" && foldingView.Invalid)
                {
                    foldingView.Dispose();
                    form.Close();
                    form.Dispose();
                }
            };
        }
        /// <summary>
        /// Activates folding, sets the defaults for new graph elements and registers mappers
        /// </summary>
        private void InitializeGraphDefaults()
        {
            var fm = new FoldingManager();

            graphControl.Graph = fm.CreateFoldingView().Graph;

            IGraph graph = graphControl.Graph;

            graphControl.NavigationCommandsEnabled = true;

            //Create graph
            graph.NodeDefaults.Size = new SizeD(60, 30);

            // set the style as the default for all new nodes
            graph.NodeDefaults.Style = PartialNodeStyle;

            // set the style as the default for all new edges
            graph.EdgeDefaults.Style = PartialEdgeStyle;

            CollapsibleNodeStyleDecorator groupNodeStyle = PartialGroupNodeStyle;
            var groupNodeDefaults = graph.GroupNodeDefaults;

            groupNodeDefaults.Labels.LayoutParameter = InteriorStretchLabelModel.North;
            groupNodeDefaults.Labels.Style           = new DefaultLabelStyle {
                StringFormat = { Alignment = StringAlignment.Far }
            };
            groupNodeDefaults.Style = groupNodeStyle;

            //Create and register mappers that specifiy partial graph elements
            partialNodesMapper = new MasterViewConversionMapper <INode, bool>(graph)
            {
                DefaultValue = true
            };
            partialEdgesMapper = new MasterViewConversionMapper <IEdge, bool>(graph)
            {
                DefaultValue = true
            };

            graphControl.GraphMLIOHandler.AddInputMapper(yWorks.Layout.Partial.PartialLayout.AffectedNodesDpKey.Name, partialNodesMapper);
            graphControl.GraphMLIOHandler.AddInputMapper(yWorks.Layout.Partial.PartialLayout.AffectedEdgesDpKey.Name, partialEdgesMapper);
        }
        /// <summary>
        /// Enables and configures folding.
        /// </summary>
        private void InitializeFolding()
        {
            var manager = new FoldingManager(graphControl.Graph)
            {
                FolderNodeConverter = new DefaultFolderNodeConverter {
                    CopyFirstLabel  = true,
                    CloneNodeStyle  = true,
                    FolderNodeSize  = new SizeD(210, 120),
                    FolderNodeStyle = new CollapsibleNodeStyleDecorator(new IsometricGroupNodeStyle())
                    {
                        ButtonPlacement = InteriorLabelModel.SouthWest
                    }
                },
                FoldingEdgeConverter = new DefaultFoldingEdgeConverter {
                    CopyFirstLabel = true
                }
            };

            graphControl.Graph = manager.CreateFoldingView().Graph;
            graphControl.Graph.IsGroupNodeChanged += (sender, args) => AdaptGroupNodes();
        }
コード例 #10
0
        /// <summary>
        /// Initializes the graph instance setting default styles
        /// and creating a small sample graph.
        /// </summary>
        protected virtual void InitializeGraph()
        {
            // Create the folding manager
            foldingManager = new FoldingManager();

            // initialize it with some default for this demo.
            InitializeFoldingManager();

            // initialize the master graph
            foldingManager.MasterGraph.GroupNodeDefaults.Style =
                new CollapsibleNodeStyleDecorator(new PanelNodeStyle {
                Color = Colors.LightSkyBlue
            });
            foldingManager.MasterGraph.NodeDefaults.Style = new BevelNodeStyle {
                Color = Colors.Black
            };

            // enable undoability on the master graph
            foldingManager.MasterGraph.SetUndoEngineEnabled(true);

            // create a managed view
            IFoldingView view = foldingManager.CreateFoldingView();

            view.EnqueueNavigationalUndoUnits = true;

            // and display it
            graphControl.Graph = view.Graph;

            IGraph graph = foldingManager.MasterGraph;

            // try loading the initial sample graph
            try {
                string s = Environment.CurrentDirectory;
                graphControl.ImportFromGraphML(new FileInfo(s + "\\sample.graphml"));
            } catch (IOException) {
                // create initial sample data in our model
                CreateInitialModelGraph(graph);
            }
        }
コード例 #11
0
        private void ShowContents(INode localRoot)
        {
            Window window = new Window();

            window.Title = "Contents of " + localRoot;
            // we create a new control
            GraphControl groupContentsGraphControl = new GraphControl();

            // now obtain a view for the given node from the manager
            IFoldingView foldingView = foldingManager.CreateFoldingView(localRoot);

            // instead of switching to the ancestor if the localRoot is removed from the graph,
            // we want to dispose the window, instead.
            foldingView.AutoSwitchToAncestor = false;

            // assign the graph and input mode
            groupContentsGraphControl.Graph     = foldingView.Graph;
            groupContentsGraphControl.InputMode = CreateEditorMode();
            // share the clipboard so that we can cut and copy between the windows
            groupContentsGraphControl.Clipboard = this.graphControl.Clipboard;

            // show the window
            window.Content = groupContentsGraphControl;
            window.Width   = window.Height = 300;
            window.Owner   = this;
            window.Show();

            // and fit the bounds
            window.Dispatcher.BeginInvoke(new Action(() => groupContentsGraphControl.FitGraphBounds()));

            // register a delegate that will dispose the window when the view gets invalid
            foldingView.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {
                if (e.PropertyName == "Invalid" && foldingView.Invalid)
                {
                    window.Close();
                }
            };
        }
コード例 #12
0
        /// <summary>
        /// Initializes the graph instance, setting default styles
        /// and creating a small sample graph.
        /// </summary>
        protected virtual void InitializeGraph()
        {
            // create the manager for the folding operations
            FoldingManager foldingManager = new FoldingManager();

            // create a view
            foldingView = foldingManager.CreateFoldingView();

            // and set it to the GraphControl
            graphControl.Graph = foldingView.Graph;

            // decorate the behavior of nodes
            NodeDecorator nodeDecorator = graphControl.Graph.GetDecorator().NodeDecorator;

            // adjust the insets so that labels are considered
            nodeDecorator.InsetsProviderDecorator.SetImplementationWrapper(
                delegate(INode node, INodeInsetsProvider insetsProvider) {
                if (insetsProvider != null)
                {
                    InsetsD insets = insetsProvider.GetInsets(node);
                    return(new LabelInsetsProvider(insets));
                }
                else
                {
                    return(new LabelInsetsProvider());
                }
            });

            //Constrain group nodes to at least the size of their labels
            nodeDecorator.SizeConstraintProviderDecorator.SetImplementationWrapper(
                (node, oldImpl) => new LabelSizeConstraintProvider(oldImpl));

            fixedGroupNodeLayout = graphControl.Graph.MapperRegistry.CreateMapper <INode, RectD?>("NodeLayouts");
            ReadSampleGraph();
            incrementalNodes.UnionWith(graphControl.Graph.Nodes);
        }
コード例 #13
0
 public static IFoldingView CreateManagedView(this FoldingManager manager)
 {
     return(manager.CreateFoldingView());
 }