Пример #1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (ViewModelBase.IsInDesignModeStatic)
            {
                return;
            }

            IsBusy               = false;
            IsIndeterminate      = true;
            EntityModels         = new ObservableCollection <EntityModel>();
            EntityRelationModels = new ObservableCollection <EntityRelationModel>();

            _cluster = new Cluster("couchbaseClients/couchbase");
            _bucket  = _cluster.OpenBucket();
            _manager = _bucket.CreateManager(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]);

            // model is a GraphLinksModel using instances of NodeData as the node data
            // and LinkData as the link data
            _graphModel            = new GraphLinksModel <NodeData, String, String, LinkData>();
            _graphModel.Modifiable = true;

            _nodes = new ObservableCollection <NodeData>();
            _links = new ObservableCollection <LinkData>();

            _graphModel.NodesSource = _nodes;
            _graphModel.LinksSource = _links;

            SearchText = ConfigurationManager.AppSettings["DefaultEntity"];
            int.TryParse(ConfigurationManager.AppSettings["PageSize"], out PageSize);
            PageSize = PageSize > 0 ? PageSize : 1000;

            LoadSchema();
            LoadState();
        }
Пример #2
0
        private void UpdateDiagram(ObservableCollection <DataTableInfo> _tables)
        {
            var model = new GraphLinksModel <Entity, String, String, Relationship>();
            ObservableCollection <Entity> obcollection = new ObservableCollection <Entity>();

            foreach (var table in _tables)
            {
                DataTableInfo dtInfo = table as DataTableInfo;
                if (dtInfo != null)
                {
                    obcollection.Add(new Entity()
                    {
                        Key   = dtInfo.TableName,
                        Items = dtInfo.Rows.Select(c => new Attribute(c.DataRow["AttributeName"].ToString(), true, NodeFigure.Decision, "Yellow")).ToArray()
                    });
                }
            }

            model.NodesSource = obcollection;
            myDiagram.InitialCenteredNodeData = model.NodesSource.OfType <Entity>().First();

            //      model.LinksSource = new ObservableCollection<Relationship>() {
            //  new Relationship() { From="Products", To="Suppliers", Text="0..N", ToText="1" },
            //  new Relationship() { From="Products", To="Categories", Text="0..N", ToText="1" },
            //  new Relationship() { From="Order Details", To="Products", Text="0..N", ToText="1" },
            //   new Relationship() { From="Order Details", To="Person", Text="0..N", ToText="1" }
            //};

            model.HasUndoManager = true;
            myDiagram.Model      = model;
        }
Пример #3
0
        public StateChart()
        {
            InitializeComponent();

            // because we cannot data-bind the Route.Points property,
            // we use a custom PartManager to read/write the Transition.Points data property
            myDiagram.PartManager = new CustomPartManager();

            // create the diagram's data model
            var model = new GraphLinksModel <State, String, String, Transition>();
            // initialize it from data in an XML file that is an embedded resource
            String xml = Demo.MainPage.Instance.LoadText("StateChart", "xml");

            // set the Route.Points after nodes have been built and the layout has finished
            myDiagram.LayoutCompleted += UpdateRoutes;
            model.Load <State, Transition>(XElement.Parse(xml), "State", "Transition");
            model.Modifiable     = true; // let the user modify the graph
            model.HasUndoManager = true; // support undo/redo
            myDiagram.Model      = model;

            // add a tool that lets the user shift the position of the link labels
            var tool = new SimpleLabelDraggingTool();

            tool.Diagram = myDiagram;
            myDiagram.MouseMoveTools.Insert(0, tool);
        }
Пример #4
0
        public static void SaveAdjencyMatrix(string filePath, GraphLinksModel <NodeModel, string, string, LinkModel> model)
        {
            using (var sw = new StreamWriter(filePath))
            {
                var nodes = (ObservableCollection <NodeModel>)model.NodesSource;
                foreach (var node in nodes)
                {
                    sw.WriteLine($"Vertex{{{node.Text}({(int)node.Location.X},{(int)node.Location.Y})}}");
                }

                var links  = (ObservableCollection <LinkModel>)model.LinksSource;
                var matrix = CreateMatrix(links, nodes);

                for (int i = 0; i < nodes.Count; i++)
                {
                    for (int j = 0; j < nodes.Count; j++)
                    {
                        if (string.IsNullOrEmpty(matrix[i, j, 0]))
                        {
                            sw.Write($"0 ");
                        }
                        else
                        {
                            sw.Write($"{matrix[i, j, 0]} ");
                        }
                    }
                    sw.WriteLine();
                }
            }
        }
Пример #5
0
        private GraphLinksModel <NodeData, String, String, LinkData> CreateModel()
        {
            var model = new GraphLinksModel <NodeData, String, String, LinkData>();

            model.MemberNodesPath = "";
            model.GroupNodePath   = "";
            return(model);
        }
Пример #6
0
        public MainWindow()
        {
            InitializeComponent();

            // model is a GraphLinksModel using instances of MyNodeData as the node data
            // and MyLinkData as the link data
            var model = new GraphLinksModel <MyNodeData, String, String, MyLinkData>();

            model.NodesSource = new ObservableCollection <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "Alpha", Color = "LightBlue"
                },
                new MyNodeData()
                {
                    Key = "Beta", Color = "Orange"
                },
                new MyNodeData()
                {
                    Key = "Gamma", Color = "LightGreen"
                },
                new MyNodeData()
                {
                    Key = "Delta", Color = "Pink"
                }
            };

            model.LinksSource = new ObservableCollection <MyLinkData>()
            {
                new MyLinkData()
                {
                    From = "Alpha", To = "Beta"
                },
                new MyLinkData()
                {
                    From = "Alpha", To = "Gamma"
                },
                new MyLinkData()
                {
                    From = "Beta", To = "Beta"
                },
                new MyLinkData()
                {
                    From = "Gamma", To = "Delta"
                },
                new MyLinkData()
                {
                    From = "Delta", To = "Alpha"
                }
            };

            model.Modifiable     = true;
            model.HasUndoManager = true;

            myDiagram.Model = model;
        }
        public ActivityDiagramPage()
        {
            InitializeComponent();
            Application.Current.MainWindow.Width  = 1000;
            Application.Current.MainWindow.Height = 600;
            var model = new GraphLinksModel <ActivityDiagramNodeData, String, String, ActivityDiagramLinkData>();

            model.NodesSource = new ObservableCollection <ActivityDiagramNodeData>();

            model.LinksSource    = new ObservableCollection <ActivityDiagramLinkData>();
            model.Modifiable     = true;
            model.HasUndoManager = false;
            diagram.Model        = model;
            diagram.AllowDrop    = true;
            var labelTool = new SimpleLabelDraggingTool();

            labelTool.Diagram = diagram;
            diagram.MouseMoveTools.Insert(0, labelTool);
            palette.Model                 = new GraphLinksModel <ActivityDiagramNodeData, String, String, ActivityDiagramLinkData>();
            flowPalette.Model             = new GraphLinksModel <ActivityDiagramNodeData, String, String, ActivityDiagramLinkData>();
            flowPalette.Model.NodesSource = new List <ActivityDiagramNodeData>()
            {
                new ActivityDiagramNodeData()
                {
                    Key = Constants.UML_AD_INITIAL_ACTIVITY, Category = Constants.UML_AD_INITIAL_ACTIVITY, Name = Constants.UML_AD_INITIAL_ACTIVITY
                },
                new ActivityDiagramNodeData()
                {
                    Key = Constants.UML_AD_FINAL_ACTIVITY, Category = Constants.UML_AD_FINAL_ACTIVITY, Name = Constants.UML_AD_FINAL_ACTIVITY
                },
                new ActivityDiagramNodeData()
                {
                    Key = Constants.UML_AD_DECISION, Category = Constants.UML_AD_DECISION, Name = Constants.UML_AD_DECISION
                },
                new ActivityDiagramNodeData()
                {
                    Key = Constants.UML_AD_DECISION_MERGE, Category = Constants.UML_AD_DECISION_MERGE, Name = Constants.UML_AD_DECISION_MERGE
                },
                new ActivityDiagramNodeData()
                {
                    Key = Constants.UML_AD_FORK, Category = Constants.UML_AD_FORK, Name = Constants.UML_AD_FORK
                },
                new ActivityDiagramNodeData()
                {
                    Key = Constants.UML_AD_JOIN, Category = Constants.UML_AD_JOIN, Name = Constants.UML_AD_JOIN
                },
            };

            model.NodeKeyPath      = "Key";
            model.LinkFromPath     = "From";
            model.LinkToPath       = "To";
            model.NodeCategoryPath = "Category";
            model.NodeIsGroupPath  = "IsSubGraph";
            model.GroupNodePath    = "SubGraphKey";
        }
Пример #8
0
        public void UpdateMatrix(GraphLinksModel <NodeModel, string, string, LinkModel> model, Diagram diagram)
        {
            ObservableCollection <Line> lines = new ObservableCollection <Line>();


            var dictionary = new Dictionary <string, Dictionary <string, LinkModel> >();

            foreach (NodeModel node in model.NodesSource)
            {
                if (!dictionary.ContainsKey(node.Key))
                {
                    var a = new Dictionary <String, LinkModel>();
                    dictionary.Add(node.Key, a);
                }
            }

            foreach (LinkModel link in model.LinksSource)
            {
                dictionary[link.From][link.To] = link;
            }

            foreach (var from in dictionary.Keys)
            {
                ObservableCollection <LinkModel> routes = new ObservableCollection <LinkModel>();
                foreach (var to in dictionary.Keys)
                {
                    LinkModel linkModel;

                    if (dictionary[to].ContainsKey(from) && !dictionary[to][from].IsOriented)
                    {
                        linkModel = dictionary[to][from];
                    }

                    else if (dictionary[from].ContainsKey(to))
                    {
                        linkModel = dictionary[from][to];
                    }
                    else
                    {
                        linkModel = new LinkModel(from, to, "")
                        {
                            model = model
                        };
                    }

                    routes.Add(linkModel);
                }

                lines.Add(new Line()
                {
                    Heading = from, Values = routes
                });
            }
            App.Current.Dispatcher.Invoke(() => MatrixControl.ItemsSource = matrixData = lines);
        }
Пример #9
0
        public Navigator()
        {
            InitializeComponent();

            var model = new GraphLinksModel <NavModelNodeData, String, String, NavModelLinkData>();

            model.NodeKeyPath     = "Key";
            model.NodeIsGroupPath = "IsSubGraph";
            model.GroupNodePath   = "SubGraphKey";
            model.LinkFromPath    = "From";
            model.LinkToPath      = "To";

            using (Stream stream = Demo.MainPage.Instance.GetStream("Navigator", "xml")) {
                using (StreamReader reader = new StreamReader(stream)) {
                    XElement root = XElement.Load(reader);
                    // Create NavModelNodeData objects to represent the nodes in the diagram
                    var modelNodes = new ObservableCollection <NavModelNodeData>();
                    // Find all elements in XML file with tag "n"
                    var nodeElts = from n in root.Descendants("n") select n;
                    foreach (XElement xe in nodeElts)
                    {
                        modelNodes.Add(new NavModelNodeData()
                        {
                            // The name of the NavModelNodeData
                            Key = XHelper.Read("name", xe, ""),
                            // Parent subgraph reference; may be null
                            SubGraphKey = XHelper.Read("subGraph", xe, ""),
                            // If isSubGraph attribute was "True", the NavModelNodeData will be a subGraph
                            IsSubGraph = XHelper.Read("isSubGraph", xe, false),
                            // From "x" and "y" attribute values, sets Node's starting positon
                            InitPosition = new Point(XHelper.Read("x", xe, 0.0), XHelper.Read("y", xe, 0.0))
                        });
                    }
                    // Create highlightable NavModelLinkData objects using the information
                    // about how the nodes are connected (contained in links part of XML file)
                    var modelLinks = new ObservableCollection <NavModelLinkData>();
                    // Find all elements in XML file with tag "l"
                    var linkElts = from l in root.Descendants("l") select l;
                    foreach (XElement xe in linkElts)
                    {
                        modelLinks.Add(new NavModelLinkData()
                        {
                            From = XHelper.Read("from", xe, ""),
                            To   = XHelper.Read("to", xe, "")
                        });
                    }
                    // initialize the model
                    model.NodesSource = modelNodes;
                    model.LinksSource = modelLinks;
                }
            }
            myDiagram.Model = model;
        }
Пример #10
0
        public InteractiveForce()
        {
            InitializeComponent();

            var model = new GraphLinksModel <SimpleData, String, String, LinkData>();
            var nodes = GenerateNodes();

            model.NodesSource = nodes;
            model.LinksSource = GenerateLinks(nodes);
            model.Modifiable  = true;
            myDiagram.Model   = model;
        }
Пример #11
0
        public static bool IsOriented(this GraphLinksModel <NodeModel, string, string, LinkModel> model)
        {
            foreach (LinkModel link in model.LinksSource)
            {
                if (!link.IsOriented)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #12
0
        public static void SaveByEdges(string fileName, GraphLinksModel <NodeModel, string, string, LinkModel> model)
        {
            using (var sw = new StreamWriter(fileName))
            {
                var nodes = (ObservableCollection <NodeModel>)model.NodesSource;
                foreach (var node in nodes)
                {
                    sw.WriteLine($"Vertex{{{node.Text}({(int) node.Location.X},{(int) node.Location.Y})}}");
                }

                var links         = (ObservableCollection <LinkModel>)model.LinksSource;
                var nodesNameList = ((ObservableCollection <NodeModel>)model.NodesSource).Select((t) => t.Text)
                                    .ToList();
                var nodesKeyList = ((ObservableCollection <NodeModel>)model.NodesSource).Select((t) => t.Key).ToList();

                var sb      = new StringBuilder();
                var counter = 0;
                foreach (var link in links)
                {
                    if (counter % 5 == 0)
                    {
                        if (counter != 0)
                        {
                            sb.Append("}");
                            sw.WriteLine(sb);
                            sb.Clear();
                        }
                        sb.Append("Edges{");
                    }

                    var orientatedChar = link.IsOriented ? "1" : "-1";
                    var nameFrom       = nodesNameList[nodesKeyList.IndexOf(link.From)];
                    var nameTo         = nodesNameList[nodesKeyList.IndexOf(link.To)];

                    sb.Append($"{counter}({link.Text},{nameFrom},{nameTo},{orientatedChar})");
                    if ((counter + 1) % 5 != 0 && counter + 1 != links.Count)
                    {
                        sb.Append(',');
                    }

                    counter++;
                }

                if (sb.Length != 0)
                {
                    sb.Append("}");
                    sw.WriteLine(sb);
                }
            }
        }
Пример #13
0
 private void SwitchGraph()
 {
     try
     {
         var tmp = Model;
         Model  = model2;
         model2 = tmp;
         OnFileLoaded();
     }
     catch (Exception e)
     {
         MessageBox.Show("Oops.. something goes wrong...\n\n" + e.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Пример #14
0
        public static IEnumerable <IEnumerable <int> > GetMatrix(this GraphLinksModel <NodeModel, string, string, LinkModel> model)
        {
            List <List <int> > matrix = new List <List <int> >();


            var dictionary = new Dictionary <string, Dictionary <string, LinkModel> >();

            foreach (NodeModel node in model.NodesSource)
            {
                if (!dictionary.ContainsKey(node.Key))
                {
                    var a = new Dictionary <String, LinkModel>();
                    dictionary.Add(node.Key, a);
                }
            }

            foreach (LinkModel link in model.LinksSource)
            {
                dictionary[link.From][link.To] = link;
            }

            foreach (var from in dictionary.Keys)
            {
                var line = new List <int>();
                foreach (var to in dictionary.Keys)
                {
                    int weight;

                    if (dictionary[to].ContainsKey(from) && !dictionary[to][from].IsOriented)
                    {
                        int.TryParse(dictionary[to][from].Weight, out weight);
                    }

                    else if (dictionary[from].ContainsKey(to))
                    {
                        int.TryParse(dictionary[from][to].Weight, out weight);
                    }
                    else
                    {
                        weight = -1;
                    }

                    line.Add(weight);
                }

                matrix.Add(line);
            }

            return(matrix);
        }
        public ClassDiagramPage()
        {
            InitializeComponent();
            LinkTypes = new List <LinkTypeComboBoxItem>()
            {
                new LinkTypeComboBoxItem(1, Constants.UML_CD_ASSOCIATION),
                new LinkTypeComboBoxItem(2, Constants.UML_CD_AGGREGATION),
                new LinkTypeComboBoxItem(3, Constants.UML_CD_GENERALIZATION),
                new LinkTypeComboBoxItem(4, Constants.UML_CD_ANCHOR)
            };
            SelectedLinkType                   = LinkTypes.First().Name;
            linkTypeComboBox.ItemsSource       = LinkTypes.OrderBy(item => item.Id);
            linkTypeComboBox.DisplayMemberPath = "Name";
            linkTypeComboBox.SelectedValuePath = "Name";
            linkTypeComboBox.SelectedValue     = Constants.UML_CD_ASSOCIATION;

            Application.Current.MainWindow.Width  = 1000;
            Application.Current.MainWindow.Height = 600;
            DiagramModel                  = new GraphLinksModel <ClassDiagramNodeData, String, String, ClassDiagramLinkData>();
            DiagramModel.NodesSource      = new ObservableCollection <ClassDiagramNodeData>();
            DiagramModel.LinksSource      = new ObservableCollection <ClassDiagramLinkData>();
            DiagramModel.Modifiable       = true;
            DiagramModel.HasUndoManager   = false;
            DiagramModel.NodeKeyPath      = "Key";
            DiagramModel.LinkFromPath     = "From";
            DiagramModel.LinkToPath       = "To";
            DiagramModel.NodeCategoryPath = "Category";
            DiagramModel.NodeIsGroupPath  = "IsSubGraph";
            DiagramModel.GroupNodePath    = "SubGraphKey";

            diagram.Model     = DiagramModel;
            diagram.AllowDrop = true;

            var labelTool = new SimpleLabelDraggingTool();

            labelTool.Diagram = diagram;
            diagram.MouseMoveTools.Insert(0, labelTool);

            palette.Model = new GraphLinksModel <ClassDiagramNodeData, String, String, ClassDiagramLinkData>();

            notePalette.Model             = new GraphLinksModel <ClassDiagramNodeData, String, String, ClassDiagramLinkData>();
            notePalette.Model.NodesSource = new List <ClassDiagramNodeData>()
            {
                new ClassDiagramNodeData()
                {
                    Key = "Note", Category = "Note", Name = "Note"
                }
            };
        }
        private void CreateSubGraph(EntityEx group)
        {
            ISubGraphModel sgmodel = myDiagram.Model as ISubGraphModel;

            if (sgmodel == null)
            {
                return;
            }

            var nodes = MainDataCollection;

            if (group == null)
            {
                var rootCollection = nodes.Where(n => String.IsNullOrEmpty(n.RootName));
                foreach (EntityEx entity in rootCollection)
                {
                    entity.Color      = String.Format("#{0:X}{1:X}{2:X}", 80 + rand.Next(100), 80 + rand.Next(100), 80 + rand.Next(100));
                    entity.IsSubGraph = true;
                    if (group != null)
                    {
                        entity.SubGraphKey = group.Key;
                    }
                    sgmodel.AddNode(entity);
                }

                //    GraphLinksModel<EntityEx, String, String, Relationship> model = myDiagram.Model as GraphLinksModel<EntityEx, String, String, Relationship>;
                //    model.LinksSource = new ObservableCollection<Relationship>() {
                //    new Relationship() { From="SVMEmailSignatureType", To="ASMComplexSystemType", Text="0..N", ToText="1" }
                //};

                GraphLinksModel <EntityEx, String, String, Relationship> model = myDiagram.Model as GraphLinksModel <EntityEx, String, String, Relationship>;
                model.LinksSource = mainRelationCollection;
            }
            else
            {
                var rootCollection = nodes.Where(n => n.RootName.Equals(group.Key));
                foreach (EntityEx entity in rootCollection)
                {
                    entity.Color      = String.Format("#{0:X}{1:X}{2:X}", 80 + rand.Next(100), 80 + rand.Next(100), 80 + rand.Next(100));
                    entity.IsSubGraph = false;
                    if (group != null)
                    {
                        entity.SubGraphKey = group.Key;
                    }
                    sgmodel.AddNode(entity);
                }
            }
            myDiagram.InitialCenteredNodeData = sgmodel.NodesSource.OfType <EntityEx>().First();
        }
Пример #17
0
        public FamilyTree()
        {
            InitializeComponent();

            var model = new GraphLinksModel <PersonData, String, String, UniversalLinkData>();

            model.NodeKeyPath      = "Name";
            model.LinkFromPath     = "From";
            model.LinkToPath       = "To";
            model.LinkCategoryPath = "Category";
            List <PersonData> modelNodes = new List <PersonData>();

            using (Stream stream = Demo.MainPage.Instance.GetStream("FamilyTree", "xml")) {
                using (StreamReader reader = new StreamReader(stream)) {
                    XElement root = XElement.Load(reader);
                    foreach (PersonData pn in root.Descendants().OfType <XElement>().Select(x => new PersonData(x)))
                    {
                        modelNodes.Add(pn);
                    }
                    model.NodesSource = modelNodes;
                }
            }
            // Using the node data, create the appropriate list of link data types.
            List <UniversalLinkData> familyLinks = new List <UniversalLinkData>();

            foreach (PersonData pn in model.NodesSource)
            {
                if (pn.Parent != null)
                {
                    familyLinks.Add(new UniversalLinkData()
                    {
                        To = pn.Name, From = pn.Parent, Category = "Child"
                    });
                }
                if (pn.Spouses != null)
                {
                    foreach (String str in pn.Spouses)
                    {
                        familyLinks.Add(new UniversalLinkData()
                        {
                            To = pn.Name, From = str, Category = "Marriage"
                        });
                    }
                }
            }

            model.LinksSource = familyLinks;
            myDiagram.Model   = model;
        }
Пример #18
0
 public UmlPage()
 {
     Application.Current.MainWindow.Width  = 1000;
     Application.Current.MainWindow.Height = 600;
     DiagramModel                  = new GraphLinksModel <NodeData, string, string, LinkData>();
     DiagramModel.NodesSource      = new ObservableCollection <NodeData>();
     DiagramModel.LinksSource      = new ObservableCollection <LinkData>();
     DiagramModel.Modifiable       = false;
     DiagramModel.HasUndoManager   = false;
     DiagramModel.NodeKeyPath      = "Key";
     DiagramModel.LinkFromPath     = "From";
     DiagramModel.LinkToPath       = "To";
     DiagramModel.NodeCategoryPath = "Category";
     DiagramModel.NodeIsGroupPath  = "IsSubGraph";
     DiagramModel.GroupNodePath    = "SubGraphKey";
 }
Пример #19
0
        public static List <int> GetAllValues(this GraphLinksModel <NodeModel, string, string, LinkModel> model)
        {
            var matrix = model.GetMatrix();

            var values = new List <int>();

            foreach (var row in matrix)
            {
                foreach (var cell in row)
                {
                    values.Add(cell);
                }
            }

            return(values);
        }
Пример #20
0
        public SequentialFunction()
        {
            InitializeComponent();

            var model = new GraphLinksModel <NodeData, String, String, LinkData>();
            // initialize it from data in an XML file that is an embedded resource
            String xml = Demo.MainPage.Instance.LoadText("SequentialFunction", "xml");

            model.Load <NodeData, LinkData>(XElement.Parse(xml), "Node", "Link");
            model.Modifiable     = true;
            model.HasUndoManager = true;
            myDiagram.Model      = model;

            myDiagram.MouseDownTools.Insert(0, new LinkShiftingTool()
            {
                Diagram = myDiagram
            });
        }
Пример #21
0
        public FriendWheel()
        {
            InitializeComponent();

            var nodes = new List <String>()
            {
                "Joshua", "Daniel", "Robert", "Noah", "Anthony",
                "Elizabeth", "Addison", "Alexis", "Ella", "Samantha",
                "Joseph", "Scott", "James", "Ryan", "Benjamin",
                "Walter", "Gabriel", "Christian", "Nathan", "Simon",
                "Isabella", "Emma", "Olivia", "Sophia", "Ava",
                "Emily", "Madison", "Tina", "Elena", "Mia",
                "Jacob", "Ethan", "Michael", "Alexander", "William",
                "Natalie", "Grace", "Lily", "Alyssa", "Ashley",
                "Sarah", "Taylor", "Hannah", "Brianna", "Hailey",
                "Christopher", "Aiden", "Matthew", "David", "Andrew",
                "Kaylee", "Juliana", "Leah", "Anna", "Allison",
                "John", "Samuel", "Tyler", "Dylan", "Jonathan",
            };

            var links = new ObservableCollection <LinkData>();
            // create a bunch of random "friend" relationships
            Random rand = new Random();

            for (int i = 0; i < nodes.Count * 2; i++)
            {
                int a = rand.Next(nodes.Count);
                int b = rand.Next(nodes.Count / 4) + 1;
                links.Add(new LinkData()
                {
                    From  = nodes[a],
                    To    = nodes[(a + b) % nodes.Count],
                    Color = String.Format("#{0:X}{1:X}{2:X}", 90 + rand.Next(90), 90 + rand.Next(90), 90 + rand.Next(90))
                });
            }

            var model = new GraphLinksModel <String, String, String, LinkData>();

            model.NodeKeyIsNodeData = true;
            model.NodesSource       = nodes;
            model.LinksSource       = links;
            myDiagram.Model         = model;
        }
Пример #22
0
        public BeatPaths()
        {
            InitializeComponent();

            // create a model where the node data is the abbreviated team name
            // and the link data are instances of Beat, defined below
            var model = new GraphLinksModel <String, String, String, Beat>();

            // assume this model is not Modifiable
            // link references to nodes are the same as the node data itself (the team names)
            model.NodeKeyIsNodeData = true;
            // automatically initialize NodesSource from the references in the link data
            model.NodeKeyReferenceAutoInserts = true;
            // specify the two properties of the Beat link data class
            model.LinkFromPath = "Winner";
            model.LinkToPath   = "Loser";

            // load the XML data from a file that is an embedded resource
            using (Stream stream = Demo.MainPage.Instance.GetStream("BeatPaths", "xml")) {
                using (StreamReader reader = new StreamReader(stream)) {
                    XElement root = XElement.Load(reader);

                    // Iterate over all the nested elements inside the root element
                    // collect a new Beat() for each XElement,
                    // remembering the interesting attribute values.
                    // Call ToList() to avoid recomputation of deferred Linq Select operation
                    model.LinksSource = root.Nodes()
                                        .OfType <XElement>()
                                        .Select(x => new Beat()
                    {
                        Winner = x.Attribute("w").Value,
                        Loser  = x.Attribute("l").Value
                    })
                                        .ToList();

                    // don't forget to have the Diagram use this model!
                    myDiagram.Model = model;
                }
            }
        }
Пример #23
0
        public Planogram()
        {
            InitializeComponent();

            // Initialize the different options for nodePalette (Stored in the Tag of the listbox items so we can bind to them)
            paletteOptions[0] = new ObservableCollection <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "Shelf", Category = "Shelf", IsSubGraph = true, Width = 100, Height = 100
                },
                new MyNodeData()
                {
                    Key = "Rack", Category = "Rack", IsSubGraph = true, Width = 100, Height = 100
                },
                new MyNodeData()
                {
                    Key = "Title", Category = "Title", IsSubGraph = false
                },
                new MyNodeData()
                {
                    Key = "Note", Category = "Note", IsSubGraph = false
                },
                new MyNodeData()
                {
                    Key = "Label", Category = "Label", IsSubGraph = false
                }
            };
            paletteOptions[1] = new ObservableCollection <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "BlueW", Color = "LightBlue", IsSubGraph = false, Width = 75, Height = 50
                },
                new MyNodeData()
                {
                    Key = "YellowW", Color = "LightYellow", IsSubGraph = false, Width = 75, Height = 50
                },
                new MyNodeData()
                {
                    Key = "GreenW", Color = "LightGreen", IsSubGraph = false, Width = 75, Height = 50
                }
            };
            paletteOptions[2] = new ObservableCollection <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "BlueT", Color = "LightBlue", IsSubGraph = false, Width = 50, Height = 75
                },
                new MyNodeData()
                {
                    Key = "YellowT", Color = "LightYellow", IsSubGraph = false, Width = 50, Height = 75
                },
                new MyNodeData()
                {
                    Key = "GreenT", Color = "LightGreen", IsSubGraph = false, Width = 50, Height = 75
                }
            };
            paletteOptions[3] = new ObservableCollection <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "Blue", Color = "LightBlue", IsSubGraph = false, Width = 50, Height = 50
                },
                new MyNodeData()
                {
                    Key = "Yellow", Color = "LightYellow", IsSubGraph = false, Width = 50, Height = 50
                },
                new MyNodeData()
                {
                    Key = "Green", Color = "LightGreen", IsSubGraph = false, Width = 50, Height = 50
                }
            };

            var nodePalModel = new GraphLinksModel <MyNodeData, String, String, GraphLinksModelLinkData <String, String> >();

            nodePalModel.NodesSource = paletteOptions[1];
            nodePalette.Model        = nodePalModel;

            // Give myDiagram a few racks and shelves to start with.
            var model = new GraphLinksModel <MyNodeData, String, String, GraphLinksModelLinkData <String, String> >();

            model.NodesSource = new ObservableCollection <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "Rack1", Category = "Rack", IsSubGraph = true, Width = 300, Height = 200, Location = new Point(50, 0)
                },
                new MyNodeData()
                {
                    Key = "Rack2", Category = "Rack", IsSubGraph = true, Width = 300, Height = 200, Location = new Point(350, 0)
                },
                new MyNodeData()
                {
                    Key = "Shelf1", Category = "Shelf", IsSubGraph = true, Width = 300, Height = 75, Location = new Point(50, 200)
                },
                new MyNodeData()
                {
                    Key = "Shelf2", Category = "Shelf", IsSubGraph = true, Width = 300, Height = 75, Location = new Point(350, 200)
                },
                new MyNodeData()
                {
                    Key = "Shelf3", Category = "Shelf", IsSubGraph = true, Width = 300, Height = 75, Location = new Point(50, 285)
                },
                new MyNodeData()
                {
                    Key = "Shelf4", Category = "Shelf", IsSubGraph = true, Width = 300, Height = 75, Location = new Point(350, 285)
                },
            };

            myDiagram.Model      = model;
            model.Modifiable     = true; // Allows adding more nodes
            model.HasUndoManager = true; // Add support for undo/redo

            myDiagram.AllowDrop = true;

            printButton.Command = myDiagram.CommandHandler.PrintCommand;
        }
Пример #24
0
        public FlowChart()
        {
            InitializeComponent();

            // use custom tools and PartManager; these could have been defined in XAML also
            myDiagram.PartManager   = new MyPartManager();
            myDiagram.LinkingTool   = new MyLinkingTool();
            myDiagram.RelinkingTool = new MyRelinkingTool();

            myDiagram.AllowDrop = true;

            // set up the model for the Palette
            var paletteModel = new GraphLinksModel <MyNodeData, String, String, MyLinkData>();

            // this creates the palette's model's data in code:
            paletteModel.NodesSource = new List <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "Comment", Text = "Comment", Category = "Comment", Figure = NodeFigure.Rectangle
                },
                new MyNodeData()
                {
                    Key = "Start", Text = "Start", Category = "Start", Figure = NodeFigure.RoundedRectangle
                },
                new MyNodeData()
                {
                    Key = "Step", Text = "Step", Category = "Standard", Figure = NodeFigure.Rectangle
                },
                new MyNodeData()
                {
                    Key = "Input", Text = "Input", Category = "Standard", Figure = NodeFigure.Input
                },
                new MyNodeData()
                {
                    Key = "Output", Text = "Output", Category = "Standard", Figure = NodeFigure.Output
                },
                new MyNodeData()
                {
                    Key = "Conditional", Text = "?", Category = "Standard", Figure = NodeFigure.Diamond
                },
                new MyNodeData()
                {
                    Key = "Read", Text = "Read", Category = "Standard", Figure = NodeFigure.Ellipse
                },
                new MyNodeData()
                {
                    Key = "Write", Text = "Write", Category = "Standard", Figure = NodeFigure.Ellipse
                },
                new MyNodeData()
                {
                    Key = "ManualOperation", Text = "Manual Operation", Category = "Standard", Figure = NodeFigure.ManualOperation
                },
                new MyNodeData()
                {
                    Key = "DataBase", Text = "DataBase", Category = "Standard", Figure = NodeFigure.Database
                },
                new MyNodeData()
                {
                    Key = "End", Text = "End", Category = "End", Figure = NodeFigure.RoundedRectangle
                }
            };
            myPalette.Model = paletteModel;

            // set up an initial model for the Diagram
            var model = new GraphLinksModel <MyNodeData, String, String, MyLinkData>();
            // and initialize it from the XML file that is an embedded resource
            String xml = Demo.MainPage.Instance.LoadText("FlowChart", "xml");

            model.Load <MyNodeData, MyLinkData>(XElement.Parse(xml), "MyNodeData", "MyLinkData");
            model.Modifiable     = true;
            model.HasUndoManager = true;
            myDiagram.Model      = model;
        }
        // metoda pro deserializaci datového modelu grafu z kotr xml
        private void Load_Click(object sender, RoutedEventArgs e)
        {
            var diagramModel = diagram.Model as GraphLinksModel <ClassDiagramNodeData, String, String, ClassDiagramLinkData>;

            if (diagramModel == null)
            {
                return;
            }

            DiagramUtils diagramUtils = new DiagramUtils();
            var          diagramXml   = diagramUtils.LoadDiagramDialog();

            try
            {
                if (diagramXml == null)
                {
                    return;
                }
                if (diagramXml.Name != Constants.UML_CD_XML_ROOT_STRING)
                {
                    throw new ProcessManagerException("This file cannot be imported, because it contains different diagram type data.");
                }
                //vypnu validaci z UPMM(protože diagram může být uložený jako nevalidovaný)
                var validationAttribute = diagramXml.Attribute(Constants.UML_CD_XML_VALIDATION_ATTRIBUTE_STRING);
                if (validationAttribute != null)
                {
                    ValidationComboBox.SelectedIndex = Int32.Parse(validationAttribute.Value);
                }
                else
                {
                    ValidationComboBox.SelectedIndex = 0;
                }

                //zkontroluju, jestli všechny uzly, které mají IRI mají svůj elemnet v načteném profilu procesu
                var loadedModel = new GraphLinksModel <ClassDiagramNodeData, string, string, ClassDiagramLinkData>();
                loadedModel.Load <ClassDiagramNodeData, ClassDiagramLinkData>(diagramXml, Constants.UML_CD_XML_NODE_STRING, Constants.UML_CD_XML_LINK_STRING);

                string[] categories     = { "Class" };
                int      countOfMissing = 0;
                foreach (string IRI in (loadedModel.NodesSource as ObservableCollection <ClassDiagramNodeData>).Where(x => categories.Contains(x.Category)).Select(x => x.IRI))
                {
                    if (!SoftwareProcessProfile.Any(x => x.IRI == IRI))
                    {
                        countOfMissing++;
                    }
                }

                if (countOfMissing > 0)
                {
                    throw new ProcessManagerException("Diagram can't be loaded, because it does not match your OWL profile.");
                }
                else
                {
                    //pokud všechny uzly s IRI mají své IRI v profilu, přidám diagram,
                    diagramModel.Load <ClassDiagramNodeData, ClassDiagramLinkData>(diagramXml, Constants.UML_CD_XML_NODE_STRING, Constants.UML_CD_XML_LINK_STRING);
                }
            }
            catch (Exception ex)
            {
                new Utils().ShowExceptionMessageBox(ex);
            }
        }
Пример #26
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            model = new GraphLinksModel <NodeData, string, string, LinkData>();

            #region Get Bus, Branch From Database
            string path       = @"E:\Coop\bugs\newProFor10.2.1\WECC_2028ADS_database";
            string connection = string.Format("data source={0}\\GridView.db; PRAGMA synchronous=off", path);
            conn = new SQLiteConnection(connection);
            conn.Open();

            SQLiteCommand cmd = conn.CreateCommand();
            cmd.CommandText = string.Format("Select BusID, Name From Bus");
            SQLiteDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                string busID   = reader["BusID"].ToString();
                string busName = reader["Name"].ToString();
                Bus    bus     = new Bus(busID, busName);
                busDict.Add(busID, bus);
                buses.Add(bus);
            }
            reader.Close();

            cmd.CommandText = string.Format("Select BranchID, FromBus, ToBus, CKT, Ratio From Branch");
            reader          = cmd.ExecuteReader();
            while (reader.Read())
            {
                string branchID  = reader["BranchID"].ToString();
                string fromBusID = reader["FromBus"].ToString();
                string toBusID   = reader["ToBus"].ToString();
                string ckt       = reader["CKT"].ToString();
                double ratio     = double.Parse(reader["Ratio"].ToString());
                Bus    fromBus   = busDict[fromBusID];
                Bus    toBus     = busDict[toBusID];

                Branch branch = new Branch(fromBusID, toBusID, ckt);
                branch.BranchID = branchID;
                fromBus.branchList.Add(branch);
                toBus.branchList.Add(branch);
                branch.FromBus = fromBus;
                branch.ToBus   = toBus;
                branch.Ratio   = ratio;
                branches.Add(branch);
            }
            reader.Close();
            #endregion

            #region Get Generator From Database
            cmd.CommandText = string.Format("Select GeneratorKey, GeneratorName, BusID, GeneratorID From Generator");
            reader          = cmd.ExecuteReader();
            while (reader.Read())
            {
                string GenKey        = reader["GeneratorKey"].ToString();
                string GeneratorName = reader["GeneratorName"].ToString();
                string BusID         = reader["BusID"].ToString();
                string GeneratorID   = reader["GeneratorID"].ToString();
                if (!busDict.ContainsKey(BusID))
                {
                    continue;
                }

                Generator generator = new Generator(GenKey, GeneratorName, BusID, GeneratorID);

                Bus corBus = busDict[BusID];
                generator.bus = corBus;
                corBus.generatorList.Add(generator);

                generators.Add(generator);
            }
            reader.Close();
            #endregion

            #region Get Load From DataBase
            cmd.CommandText = string.Format("Select BusID, LoadID From PSSELoad");
            reader          = cmd.ExecuteReader();
            while (reader.Read())
            {
                string BusID  = reader["BusID"].ToString();
                string LoadID = reader["LoadID"].ToString();
                Load   load   = new Load(BusID, LoadID);

                Bus corBus = busDict[BusID];
                load.bus = corBus;
                corBus.loadList.Add(load);

                loads.Add(load);
            }
            reader.Close();
            #endregion

            GetBusList();
        }
Пример #27
0
        public MainWindow()
        {
            InitializeComponent();

            // model is a GraphLinksModel using instances of MyNodeData as the node data
            // and MyLinkData as the link data
            var model = new GraphLinksModel <MyNodeData, String, String, MyLinkData>();

            model.NodesSource = new ObservableCollection <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "Alpha", Color = "LightBlue"
                },
                new MyNodeData()
                {
                    Key = "Beta", Color = "Orange"
                },
                new MyNodeData()
                {
                    Key = "Gamma", Color = "LightGreen"
                },
                new MyNodeData()
                {
                    Key = "Delta", Color = "Pink"
                }
            };

            model.LinksSource = new ObservableCollection <MyLinkData>()
            {
                new MyLinkData()
                {
                    From = "Alpha", To = "Beta"
                },
                new MyLinkData()
                {
                    From = "Alpha", To = "Gamma"
                },
                new MyLinkData()
                {
                    From = "Beta", To = "Beta"
                },
                new MyLinkData()
                {
                    From = "Gamma", To = "Delta"
                },
                new MyLinkData()
                {
                    From = "Delta", To = "Alpha"
                }
            };

            model.Modifiable     = true;
            model.HasUndoManager = true;

            myDiagram.Model     = model;
            myDiagram.AllowDrop = true;

            myPalette.Model             = new GraphLinksModel <MyNodeData, String, String, MyLinkData>();
            myPalette.Model.NodesSource = new List <MyNodeData>()
            {
                new MyNodeData()
                {
                    Key = "One", Color = "PapayaWhip"
                },
                new MyNodeData()
                {
                    Key = "Two", Color = "Lavender"
                },
                new MyNodeData()
                {
                    Key = "Three", Color = "PaleGreen"
                },
            };

#if DOTNET4
            Touch.FrameReported += Touch_FrameReported;
#endif
        }
Пример #28
0
        public DecisionTree()
        {
            InitializeComponent();

            // Although the graph is just a tree, we don't use a TreeModel because we
            // want to distinguish links coming from different "ports".
            var model = new GraphLinksModel <Info, String, String, UniversalLinkData>();

            model.NodeKeyPath      = "Key";
            model.NodeCategoryPath = "Category"; // the DataTemplate name for Node templates

            // Create all of the node data that we might show.
            var nodes = new List <Info>()
            {
                new Info()
                {
                    Key = StartName
                },                       // the root node

                // intermediate nodes: decisions on personality characteristics
                new Info()
                {
                    Key = "I"
                },
                new Info()
                {
                    Key = "E"
                },

                new Info()
                {
                    Key = "IN"
                },
                new Info()
                {
                    Key = "IS"
                },
                new Info()
                {
                    Key = "EN"
                },
                new Info()
                {
                    Key = "ES"
                },

                new Info()
                {
                    Key = "INT"
                },
                new Info()
                {
                    Key = "INF"
                },
                new Info()
                {
                    Key = "IST"
                },
                new Info()
                {
                    Key = "ISF"
                },
                new Info()
                {
                    Key = "ENT"
                },
                new Info()
                {
                    Key = "ENF"
                },
                new Info()
                {
                    Key = "EST"
                },
                new Info()
                {
                    Key = "ESF"
                },

                // terminal nodes: the personality descriptions
                new Info()
                {
                    Key  = "INTJ",
                    Text = "INTJ: Scientist\rThe most self-confident of all types.  They focus on possibilities and use empirical logic to think about the future.  They prefer that events and people serve some positive use.  1% of population.	"
                },
                new Info()
                {
                    Key  = "INTP",
                    Text = "INTP: Architect\rAn architect of ideas, number systems, computer languages, and many other concepts.  They exhibit great precision in thought and language.  1% of the population."
                },
                new Info()
                {
                    Key  = "INFJ",
                    Text = "INFJ: Author\rFocus on possibilities.  Place emphasis on values and come to decisions easily.  They have a strong drive to contribute to the welfare of others.  1% of population."
                },
                new Info()
                {
                    Key  = "INFP",
                    Text = "INFP: Questor\rPresent a calm and pleasant face to the world.  Although they seem reserved, they are actually very idealistic and care passionately about a few special people or a cause.  1% of the population."
                },
                new Info()
                {
                    Key  = "ISTJ",
                    Text = "ISTJ: Trustee\rISTJ's like organized lives. They are dependable and trustworthy, as they dislike chaos and work on a task until completion. They prefer to deal with facts than emotions. 6% of the population."
                },
                new Info()
                {
                    Key  = "ISTP",
                    Text = "ISTP: Artisan\rISTP's are quiet people who are very capable at analyzing how things work. Though quiet, they can be influential, with their seclusion making them all the more skilled. 17% of the population."
                },
                new Info()
                {
                    Key  = "ISFJ",
                    Text = "ISFJ: Conservator\rISFJ's are not particularly social and tend to be most concerned with maintaining order in their lives. They are dutiful, and respectful towards and interested in others, though they are often shy. They are, therefore, trustworthy, but not bossy. 6% of the population."
                },
                new Info()
                {
                    Key  = "ISFP",
                    Text = "ISFP: Author\rFocus on possibilities.  Place emphasis on values and come to decisions easily.  They have a strong drive to contribute to the welfare of others.  1% of population."
                },
                new Info()
                {
                    Key  = "ENTJ",
                    Text = "ENTJ: Fieldmarshal\rThe driving force of this personality is to lead.  They like to impose structure and harness people to work towards distant goals.  They reject inefficiency.  5% of the population."
                },
                new Info()
                {
                    Key  = "ENTP",
                    Text = "ENTP: Inventor\rExercise their ingenuity by dealing with social, physical, and mechanical relationships.  They are always sensitive to future possibilities.  5% of the population."
                },
                new Info()
                {
                    Key  = "ENFJ",
                    Text = "ENFJ: Pedagogue\rExcellent leaders; they are charismatic and never doubt that others will follow them and do as they ask.   They place a high value on cooperation.  5% of the population."
                },
                new Info()
                {
                    Key  = "ENFP",
                    Text = "ENFP: Journalist\rPlace significance in everyday occurrences.  They have great ability to understand the motives of others.  They see life as a great drama.  They have a great impact on others.  5% of the population."
                },
                new Info()
                {
                    Key  = "ESTJ",
                    Text = "ESTJ: Administrator\rESTJ's are pragmatic, and thus well-suited for business or administrative roles. They are traditionalists are conservatives, believing in the status quo. 13% of the population."
                },
                new Info()
                {
                    Key  = "ESTP",
                    Text = "ESTP: Promoter\rESTP's tend to manipulate others in order to attain access to the finer aspects of life. However, they enjoy heading to such places with others. They are social and outgoing and are well-connected. 13% of the population."
                },
                new Info()
                {
                    Key  = "ESFJ",
                    Text = "ESFJ: Seller\rESFJ's tend to be social and concerned for others. They follow tradition and enjoy a structured community environment. Always magnanimous towards others, they expect the same respect and appreciation themselves. 13% of the population."
                },
                new Info()
                {
                    Key  = "ESFP",
                    Text = "ESFP: Entertainer\rThe mantra of the ESFP would be \"Carpe Diem.\" They enjoy life to the fullest. They do not, thus, like routines and long-term goals. In general, they are very concerned with others and tend to always try to help others, often perceiving well their needs. 13% of the population."
                }
            };

            // Provide the same choice information for all of the nodes on each level.
            // The level is implicit in the number of characters in the Key, except for the root node.
            // In a different application, there might be different choices for each node, so the initialization would be above, where the Info's are created.
            // But for this application, it makes sense to share the initialization code based on tree level.
            foreach (Info d in nodes)
            {
                if (d.Key == StartName)
                {
                    d.Category = "DecisionNode";
                    d.A        = "I";
                    d.AText    = "Introversion";
                    d.AToolTip = "The Introvert is “territorial” and desires space and solitude to recover energy.  Introverts enjoy solitary activities such as reading and meditating.  25% of the population.";
                    d.B        = "E";
                    d.BText    = "Extraversion";
                    d.BToolTip = "The Extravert is “sociable” and is energized by the presence of other people.  Extraverts experience loneliness when not in contact with others.  75% of the population.";
                }
                else
                {
                    switch (d.Key.Length)
                    {
                    case 1:
                        d.Category = "DecisionNode";
                        d.A        = "N";
                        d.AText    = "Intuition";
                        d.AToolTip = "The “intuitive” person bases their lives on predictions and ingenuity.  They consider the future and enjoy planning ahead.  25% of the population.";
                        d.B        = "S";
                        d.BText    = "Sensing";
                        d.BToolTip = "The “sensing” person bases their life in facts, thinking primarily of their present situation.  They are realistic and practical.  75% of the population.";
                        break;

                    case 2:
                        d.Category = "DecisionNode";
                        d.A        = "T";
                        d.AText    = "Thinking";
                        d.AToolTip = "The “thinking” person bases their decisions based on facts and without personal bias.  They are more comfortable with making impersonal judgments.  50% of the population.";
                        d.B        = "F";
                        d.BText    = "Feeling";
                        d.BToolTip = "The “feeling” person bases their decisions on personal experience and emotion.  They make their emotions very visible.  50% of the population.";
                        break;

                    case 3:
                        d.Category = "DecisionNode";
                        d.A        = "J";
                        d.AText    = "Judgment";
                        d.AToolTip = "The “judging” person enjoys closure.  They establish deadlines and take them seriously.  They despise being late.  50% of the population.";
                        d.B        = "P";
                        d.BText    = "Perception";
                        d.BToolTip = "The “perceiving” person likes to keep options open and fluid.  They have little regard for deadlines.  Dislikes making decisions unless they are completely sure of they are right.  50% of the population.";
                        break;

                    default:
                        d.Category = "PersonalityNode";
                        break;
                    }
                }
            }
            model.NodesSource = nodes;

            // Use the Key of each Info to construct the proper link data from the parent Info.
            // In a different application such programmatic construction of the links might not be possible.
            // But in this application, the relationships can be determined by splitting up the Key string.
            var links = new List <UniversalLinkData>();

            foreach (Info info in nodes)
            {
                String key = info.Key;
                if (key == StartName)
                {
                    continue;
                }
                if (key.Length == 0)
                {
                    continue;
                }
                // e.g., if key=="INTJ", we want: prefix="INT" and letter="J"
                String prefix = key.Substring(0, key.Length - 1);
                String letter = key[key.Length - 1].ToString();
                if (prefix.Length == 0)
                {
                    prefix = StartName;
                }
                // e.g., connect node "INT" with port "J" to node "INTJ" with the whole node as the port
                links.Add(new UniversalLinkData(prefix, letter, key, null));
            }
            model.LinksSource = links;

            myDiagram.Model = model;
        }
Пример #29
0
        // Create some sample data.
        private void LoadData()
        {
            var vpm   = (VirtualizingPartManager)myDiagram.PartManager;
            var nodes = new ObservableCollection <NodeData>()
            {
            };
            var links = new ObservableCollection <LinkData>()
            {
            };

            // in production usage you'll probably want to remove these status updates,
            // which slows down scrolling and zooming
            vpm.Status = () => {
                myStatus.Text = "created " + vpm.NodesCount.ToString() + "/" + nodes.Count.ToString() + " nodes," +
                                "  " + vpm.LinksCount.ToString() + "/" + links.Count.ToString() + " links."
                                + "  " + myDiagram.Panel.DiagramBounds.ToString();
            };

            // create the node data and the link data for the model
            GenerateNodes(nodes);
            GenerateLinks(nodes, links);

            // create the model with the data
            var model = new GraphLinksModel <NodeData, String, String, LinkData>();

            model.LinksSource = links;
            model.NodesSource = nodes;

            // NOTE: regular DiagramLayouts (such as TreeLayout) will not work with this virtualizing scheme!
            // You need to make sure VirtualizingPartManager.ComputeNodeBounds returns good values
            // for every NodeData object.

            // just in case you set model.Modifiable = true, this makes sure the viewport is updated after every transaction:
            model.Changed += (s, e) => {
                if (e.Change == ModelChange.CommittedTransaction || e.Change == ModelChange.FinishedUndo || e.Change == ModelChange.FinishedRedo)
                {
                    vpm.UpdateViewport(myDiagram.Panel.ViewportBounds, myDiagram.Panel.ViewportBounds);
                }
            };

            // do the initial layout *before* assigning to the Diagram.Model --
            // this avoids creating all of the Nodes and Links and then throwing away everything
            // outside of the viewport
            VirtualizingTreeLayout layout = myDiagram.Layout as VirtualizingTreeLayout;

            if (layout != null)
            {
                layout.Model = model;
                layout.DoLayout(null, null);
            }

            // initialize the Diagram with the model and its data
            myDiagram.Model = model;

            // remove the "Loading..." status indicator
            var loading = myDiagram.PartsModel.FindNodeByKey("Loading");

            if (loading != null)
            {
                myDiagram.PartsModel.RemoveNode(loading);
            }
        }
Пример #30
0
        public SequenceDiagram()
        {
            InitializeComponent();

            var model = new GraphLinksModel <NodeData, String, String, LinkData>();

            model.NodesSource = new ObservableCollection <NodeData>()
            {
                new NodeData()
                {
                    Key = "Fred", Text = "Fred: Patron", IsSubGraph = true, Location = new Point(0, 0)
                },
                new NodeData()
                {
                    Key = "Bob", Text = "Bob: Waiter", IsSubGraph = true, Location = new Point(100, 0)
                },
                new NodeData()
                {
                    Key = "Hank", Text = "Hank: Cook", IsSubGraph = true, Location = new Point(200, 0)
                },
                new NodeData()
                {
                    Key = "Renee", Text = "Renee: Cashier", IsSubGraph = true, Location = new Point(300, 0)
                }
            };
            model.LinksSource = new ObservableCollection <LinkData>()
            {
                new LinkData()
                {
                    From = "Fred", To = "Bob", Text = "order", Time = 1, Duration = 2
                },
                new LinkData()
                {
                    From = "Bob", To = "Hank", Text = "order food", Time = 2, Duration = 3
                },
                new LinkData()
                {
                    From = "Bob", To = "Fred", Text = "serve drinks", Time = 3, Duration = 1
                },
                new LinkData()
                {
                    From = "Hank", To = "Bob", Text = "finish cooking", Time = 5, Duration = 1
                },
                new LinkData()
                {
                    From = "Bob", To = "Fred", Text = "serve food", Time = 6, Duration = 2
                },
                new LinkData()
                {
                    From = "Fred", To = "Renee", Text = "pay", Time = 8, Duration = 1
                }
            };
            myDiagram.Model = model;

            // add an Activity node for each Message recipient
            model.Modifiable = true;
            double max = 0;

            foreach (LinkData d in model.LinksSource)
            {
                var grp = model.FindNodeByKey(d.To);
                var act = new NodeData()
                {
                    SubGraphKey = d.To,
                    Location    = new Point(grp.Location.X, BarRoute.ConvertTimeToY(d.Time) - BarRoute.ActivityInset),
                    Length      = d.Duration * BarRoute.MessageSpacing + BarRoute.ActivityInset * 2,
                };
                model.AddNode(act);
                max = Math.Max(max, act.Location.Y + act.Length);
            }
            // now make sure all of the lifelines are long enough
            foreach (NodeData d in model.NodesSource)
            {
                if (d.IsSubGraph)
                {
                    d.Length = max - BarRoute.LineStart + BarRoute.LineTrail;
                }
            }
            model.Modifiable = false;
        }