Beispiel #1
0
 public static T newInThread <T>(this GraphLayout graphLayout) where T : UIElement
 {
     return((T)graphLayout.wpfInvoke(
                () => {
         return (T)typeof(T).ctor();
     }));
 }
Beispiel #2
0
        public void highlightTrees(object treePair)
        {
            var pair = treePair as TreePair;

            if (pair == null)
            {
                return;
            }

            var g = new BidirectionalGraph <object, IEdge <object> >();
            var l = new GraphLayout();

            addNodesToGraph(pair._first._root, null, g);
            addNodesToGraph(pair._second._root, null, g);

            var slp = new GraphSharp.Algorithms.Layout.Simple.Tree.SimpleTreeLayoutParameters();

            slp.Direction = GraphSharp.Algorithms.Layout.LayoutDirection.TopToBottom;
            slp.LayerGap  = 100.0;
            slp.VertexGap = 100.0;

            l.LayoutAlgorithmType = "Tree";
            l.Graph            = g;
            l.LayoutMode       = LayoutMode.Automatic;
            l.LayoutParameters = slp;
            _layout            = l;

            OnPropertyChanged("_layout");
        }
Beispiel #3
0
        public void highlightTree(object tree)
        {
            var t = tree as GeneticTree;

            if (t == null)
            {
                return;
            }

            var g = new BidirectionalGraph <object, IEdge <object> >();
            var l = new GraphLayout();

            addNodesToGraph(t._root, null, g);

            var slp = new GraphSharp.Algorithms.Layout.Simple.Tree.SimpleTreeLayoutParameters();

            slp.Direction = GraphSharp.Algorithms.Layout.LayoutDirection.TopToBottom;
            slp.LayerGap  = 100.0;
            slp.VertexGap = 100.0;

            l.LayoutAlgorithmType = "Tree";
            l.Graph            = g;
            l.LayoutMode       = LayoutMode.Automatic;
            l.LayoutParameters = slp;
            _mutationLayout    = l;
            OnPropertyChanged("_mutationLayout");
        }
 public LayoutExampleWindow(GraphLayout layout, string sourceGraphPath)
 {
     InitializeComponent();
     this.layout          = layout;
     this.sourceGraphPath = sourceGraphPath;
     Loaded += OnLoaded;
 }
Beispiel #5
0
        protected void graphLayout_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (IsExperimentRunning == false)
            {
                //check if current GraphLayout at the specified coordinates is occluded by another graph view
                //Checking on GraphLayout not this GraphView, because hit elemenent must be checked relative to the current GraphLayout origin, not constant graph view element
                Point clickPoint            = e.GetPosition(GraphLayout);
                bool  isGraphLayoutOccluded = IsUIElementOccludedByAnotherGraphView(GraphLayout, clickPoint);

                if (!isGraphLayoutOccluded)
                {
                    IInputElement ele = GraphLayout.InputHitTest(clickPoint);
                    if (ele != null && HACK_VertexControl.Visibility != System.Windows.Visibility.Visible)
                    {
                        // if they clicked on a edge start redirecting the edge
                        DependencyObject obj = (DependencyObject)ele;
                        TraceLab.UI.WPF.Controls.RoutePointThumb routePointThumb = obj.GetParent <TraceLab.UI.WPF.Controls.RoutePointThumb>(this);
                        if (routePointThumb == null)
                        {
                            GraphSharp.Controls.EdgeControl edge = obj.GetParent <GraphSharp.Controls.EdgeControl>(this);
                            if (CanRedirectLink(edge))
                            {
                                StartRedirectLinkDrag(e, clickPoint, edge);
                            }
                        }
                    }
                }
            }
        }
Beispiel #6
0
        // called when there is a graphCache[graphFamily] item to process
        // called only through currentOutputAction or the output actions menu
        public void ProcessGraph(string graphFamily)
        {
            var execution = Exec.lastExecution; // atomically copy it

            if (execution == null)
            {
                return;                    // something's wrong
            }
            lock (Exec.exporterMutex) { GraphLayoutHandler.SetGraphLayout(GraphLayout.MessageGraph("...", "... working ...", "...")); plot.DoInvalidate(); }
            Dictionary <string, object> layoutCache = execution.layoutCache; // Dictionary<string, GraphLayout>
            GraphLayout layout;

            if (layoutCache.ContainsKey(graphFamily))
            {
                layout = (GraphLayout)layoutCache[graphFamily];
            }
            else
            {
                var graph = execution.graphCache[graphFamily];
                if (graph.VertexCount == 0 || graph.EdgeCount == 0) // GraphSharp crashes in these cases
                {
                    layout = GraphLayout.MessageGraph("...", "...", "... empty .");
                }
                else
                {
                    try { layout = new GraphLayout("Graph Layout", graph); }
                    catch { layout = GraphLayout.MessageGraph("...", "...", "... failed !!!"); }
                }
            }
            execution.layoutCache[graphFamily] = layout;
            lock (Exec.exporterMutex) { GraphLayoutHandler.SetGraphLayout(layout); plot.DoInvalidate(); }
        }
        public static GraphLayout  edgeToFirst(this GraphLayout graphLayout, object vertexToLink)
        {
            var vertices = graphLayout.vertices();

            graphLayout.edge(vertexToLink, vertices[0]);
            return(graphLayout);
        }
Beispiel #8
0
        public static T add_UIElement <T>(this GraphLayout graphLayout) where T : UIElement
        {
            var uiElement = graphLayout.newInThread <T>();

            graphLayout.add_Node(uiElement);
            return(uiElement);
        }
        public static GraphLayout  edgeFromLast(this GraphLayout graphLayout, object vertexToLink)
        {
            var vertices = graphLayout.vertices();

            graphLayout.edge(vertices[vertices.size() - 1], vertexToLink);
            return(graphLayout);
        }
 // Constructors
 public AAlgorithm(CitiesLocations newCitiesLocations, CitiesConnections newCitiesConnectios,
                   GraphLayout _graphLayout, int _algSpeed)
 {
     citiesLocations   = newCitiesLocations;
     citiesConnecitons = newCitiesConnectios;
     algSpeed          = _algSpeed;
     graphLayout       = _graphLayout;
 }
 // Constructors
 public AAlgorithm(CitiesLocations newCitiesLocations, CitiesConnections newCitiesConnectios, 
     GraphLayout _graphLayout, int _algSpeed)
 {
     citiesLocations = newCitiesLocations;
     citiesConnecitons = newCitiesConnectios;
     algSpeed = _algSpeed;
     graphLayout = _graphLayout;
 }
Beispiel #12
0
 public static GraphLayout background(this GraphLayout graphLayout, Brush brush)
 {
     return((GraphLayout)graphLayout.wpfInvoke(
                () => {
         graphLayout.Background = brush;
         return graphLayout;
     }));
 }
Beispiel #13
0
 public void OutputClear()   // external call, wait until we switch to this page
 {
     if (MainTabbedPage.theMainTabbedPage.CurrentPage == MainTabbedPage.theOutputPageNavigation)
     {
         SetText("");
         lock (Exec.exporterMutex) { GraphLayoutHandler.SetGraphLayout(GraphLayout.MessageGraph("Preparing ...", "...", "...")); plot.DoInvalidate(); }
     }
 }
Beispiel #14
0
        public static TextBox add_TextBox(this GraphLayout graphLayout, string textValue)
        {
            var textBox = graphLayout.newInThread <TextBox>();

            textBox.set_Text(textValue);
            graphLayout.add_Node(textBox);
            return(textBox);
        }
 public static GraphLayout  edgeFromAll(this GraphLayout graphLayout, object vertexToLink)
 {
     foreach (var vertex in graphLayout.vertices())
     {
         graphLayout.edge(vertex, vertexToLink);
     }
     return(graphLayout);
 }
Beispiel #16
0
 public static BidirectionalGraph <object, IEdge <object> > get_Graph(this GraphLayout graphLayout)
 {
     return((BidirectionalGraph <object, IEdge <object> >)
            graphLayout.wpfInvoke(
                () => {
         return graphLayout.Graph;
     }));
 }
Beispiel #17
0
 public static GraphLayout set(this GraphLayout graphLayout, BidirectionalGraph <object, IEdge <object> > graph)
 {
     return((GraphLayout)graphLayout.wpfInvoke(
                () => {
         graphLayout.Graph = graph;
         return graphLayout;
     }));
 }
Beispiel #18
0
 public static GraphLayout showAllLayouts(this GraphLayout graphLayout, int miliSeconds)
 {
     foreach (var layoutType in graphLayout.layouts())
     {
         "showing layout: {0}".format(layoutType).debug();
         graphLayout.layout(layoutType).sleep(miliSeconds);
     }
     return(graphLayout);
 }
Beispiel #19
0
        public static Button add_Button(this GraphLayout graphLayout, string text, int width, int height)
        {
            var button = graphLayout.add_UIElement <Button>();

            button.set(text);
            button.width_Wpf(width);
            button.height_Wpf(height);
            return(button);
        }
 void ApplyLayout(GraphLayout layout)
 {
     try {
         diagramControl.RelayoutDiagramItems(layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl)));
         diagramControl.Items.OfType <IDiagramConnector>().ForEach(connector => { connector.Type = layout.GetDiagramConnectorType(); connector.UpdateRoute(); });
         diagramControl.FitToDrawing();
     } catch (Exception e) {
         DXMessageBox.Show(string.Format("Error message: '{0}'", e.Message), "Error has been occurred");
     }
 }
        public static object node(this GraphLayout graphLayout, int nodeId)
        {
            var vertices = graphLayout.vertices();

            if (vertices.size() > nodeId)
            {
                return(vertices[nodeId]);
            }
            return(null);
        }
Beispiel #22
0
 public static CodeStreamGraphNode add_CodeStreamEdge(this GraphLayout graphLayout, O2CodeStream codeStream, O2CodeStreamNode codeStreamNode, CodeStreamGraphNode previousGraphNode)
 {
     return((CodeStreamGraphNode)graphLayout.wpfInvoke(
                () =>
     {
         var codeStreamGraphNode = new CodeStreamGraphNode(codeStream, codeStreamNode);
         graphLayout.add_Edge(previousGraphNode, codeStreamGraphNode);
         return codeStreamGraphNode;
     }));
 }
Beispiel #23
0
        /// <summary>
        /// Sets the nodes position from custom graph.
        /// </summary>
        /// <param name="graph">The graph.</param>
        private void SetNodesPositionFromCustomGraph(CustomGraph graph)
        {
            StringBuilder s = new StringBuilder();

            for (int i = 0; i < graph.Vertices.Count(); i++)
            {
                GraphLayout.SetX(graphLayout.GetVertexControl(graphLayout.Graph.Vertices.ElementAt(i)), graph.Vertices.ElementAt(i).X);
                GraphLayout.SetY(graphLayout.GetVertexControl(graphLayout.Graph.Vertices.ElementAt(i)), graph.Vertices.ElementAt(i).Y);
            }
        }
Beispiel #24
0
        public async Task <IHttpActionResult> SaveLayout([FromBody] GraphLayout layout, Guid networkId, string key = null)
        {
            await _dispatcher.Execute(new SaveLayoutCommand()
            {
                NetworkId   = networkId,
                Key         = key,
                GraphLayout = layout
            }, User);

            return(Ok());
        }
Beispiel #25
0
        /// <summary>
        /// Sets the nodes position to save.
        /// </summary>
        private void SetNodesPositionToSave(CustomGraph graphToSave)
        {
            foreach (CustomVertex vertex in graphLayout.Graph.Vertices)
            {
                double vertexX = GraphLayout.GetX(graphLayout.GetVertexControl(vertex));
                double vertexY = GraphLayout.GetY(graphLayout.GetVertexControl(vertex));

                graphToSave.Vertices.Where(var => var.CompareTo(vertex)).FirstOrDefault().X = vertexX;
                graphToSave.Vertices.Where(var => var.CompareTo(vertex)).FirstOrDefault().Y = vertexY;
            }
        }
Beispiel #26
0
 public static GraphLayout overlapRemovalParameters(this GraphLayout graphLayout, float horizontalGap, float verticalGap)
 {
     return((GraphLayout)graphLayout.wpfInvoke(
                () =>
     {
         var overlapRemovalParameters = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters();
         overlapRemovalParameters.HorizontalGap = horizontalGap;
         overlapRemovalParameters.VerticalGap = verticalGap;
         graphLayout.OverlapRemovalParameters = overlapRemovalParameters;
         return graphLayout;
     }));
 }
Beispiel #27
0
 public static T add_WinForm <T>(this GraphLayout graphLayout, int width, int height) where T : System.Windows.Forms.Control
 {
     return((T)graphLayout.wpfInvoke(
                () => {
         var controlHost = graphLayout.add_UIElement <WindowsFormsHost>();
         controlHost.width_Wpf(width);
         controlHost.height_Wpf(height);
         var winFormsControl = (System.Windows.Forms.Control) typeof(T).ctor();
         winFormsControl.Dock = System.Windows.Forms.DockStyle.Fill;
         controlHost.Child = winFormsControl;
         return winFormsControl;
     }));
 }
Beispiel #28
0
        //Funcion dedicada al boton "Graficar"
        private void button3_Click(object sender, EventArgs e)
        {
            //No se puede crear el grafo si no se han añadido vertices
            if (contador != 0)
            {
                //No se puede crear el grafo si no se marcar el tipo de grafo que es
                if (opc_noponderado.Checked == false && opc_ponderado.Checked == false)
                {
                    MessageBox.Show("Seleccione el tipo de grafo");
                }
                // el else del if anterior
                else
                {
                    Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
                    GraphLayout.Controls.Clear();

                    viewer.EdgeInsertButtonVisible = false;
                    viewer.LayoutAlgorithmSettingsButtonVisible = false;
                    viewer.SaveButtonVisible      = false;
                    viewer.SaveGraphButtonVisible = false;
                    viewer.UndoRedoButtonsVisible = false;

                    viewer.NavigationVisible = false;
                    for (int i = 0; i < contador; i++)
                    {
                        graph.AddNode(az[i].ToString());
                    }
                    viewer.Graph = graph;
                    this.SuspendLayout();
                    viewer.Dock = System.Windows.Forms.DockStyle.Fill;
                    GraphLayout.Controls.Add(viewer);
                    GraphLayout.ResumeLayout();
                    grafocreado = true;
                }
            }
            //Mensaje de error si se intento crear el grafo con una cantidad de vertices 0
            else
            {
                MessageBox.Show("No se añadio ningun vertice o no se selecciono tipo de grafo", "Error");
            }

            //Si el grafo fue creado desactivamos los botones menos el de reset
            if (grafocreado == true)
            {
                opc_noponderado.Enabled  = false;
                opc_ponderado.Enabled    = false;
                agregar_Vertice.Enabled  = false;
                eliminar_Vertice.Enabled = false;
                Graficar.Enabled         = false;
            }
        }
Beispiel #29
0
        public static GraphLayout edge(this GraphLayout graphLayout, object fromVertex, object toVertex)
        {
            if (graphLayout == fromVertex || graphLayout == toVertex)  // can add graphLayout as an edge
            {
                return(graphLayout);
            }
            var graph = graphLayout.get_Graph();

            return((GraphLayout)graphLayout.wpfInvoke(
                       () => {
                graph.edge(fromVertex, toVertex);
                return graphLayout;
            }));
        }
        private void setProperties()
        {
            var g = new BidirectionalGraph <object, IEdge <object> >();
            var l = new GraphLayout();

            addNodesToGraph(_tree._root, null, g);


            var slp = new GraphSharp.Algorithms.Layout.Simple.Tree.SimpleTreeLayoutParameters();

            slp.Direction         = GraphSharp.Algorithms.Layout.LayoutDirection.TopToBottom;
            slp.LayerGap          = 100.0;
            slp.VertexGap         = 100.0;
            l.LayoutAlgorithmType = "Tree";
            l.Graph            = g;
            l.LayoutMode       = LayoutMode.Automatic;
            l.LayoutParameters = slp;
            _layout            = l;


            _promotionSquare  = -1;
            _pickerVisibility = Visibility.Hidden;
            COLORS            = new string[] { "White", "Black" };
            DEPTHS            = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            _board            = new Board(Board.DEFAULT_POSITION);
            _playerColor      = COLORS[0];
            _color            = true;
            playerMove        = true;
            OnPropertyChanged("_playerColor");
            _pieces  = new PieceIndex[Board.BOARD_EDGE * Board.BOARD_EDGE];
            _buttons = new SquareTypeIndex[Board.BOARD_EDGE * Board.BOARD_EDGE];

            colorChanged = new RelayCommand(x => changeColor(), x => true);
            clickEmpty   = new RelayCommand(x => resetChessboardButtons(), x => true);
            clickAllied  = new RelayCommand(x => highlightTargetSquares(x), x => true);
            clickCurrent = new RelayCommand(x => resetChessboardButtons(), x => true);
            clickTarget  = new RelayCommand(x => moveToTargetSquare(x), x => true);

            promoteQueen  = new RelayCommand(x => promoteQ(), x => true);
            promoteRook   = new RelayCommand(x => promoteR(), x => true);
            promoteBishop = new RelayCommand(x => promoteB(), x => true);
            promoteKnight = new RelayCommand(x => promoteN(), x => true);

            for (int i = 0; i < _pieces.Length; i++)
            {
                _pieces[i]  = new PieceIndex(_board._indices[i], (byte)i);
                _buttons[i] = new SquareTypeIndex(0, (byte)i);
            }
            resetChessboardButtons();
        }
        public JsonResult GetGraphLayout(string gmlString)
        {
            string path = Server.MapPath("~/App_Data");


            List <Coordinate> coordinates = GraphLayout.ComputeLayout(path, gmlString);

            JsonResult result = Json(new
            {
                coords = JsonConvert.SerializeObject(coordinates)
            });

            return(result);
        }
 public static O2CodeStream show(this O2CodeStream o2CodeStream, GraphLayout graphLayout)
 {
     try
     {                  
         //graphLayout.newGraph();
         graphLayout.tree();                
         foreach (var streamNode in o2CodeStream.StreamNode_First)
             graphLayout.show_CodeStreamNode(o2CodeStream, streamNode, null);
     }
     catch (Exception ex)
     {
         ex.log("in O2CodeStream.show GraphLayout");
     }
     return o2CodeStream;
 }
Beispiel #33
0
        private void RunLayoutGraph(GraphLayout.Graph graph)
        {
            // Support undo for graph layout command
            List<ModelBase> undoItems = new List<ModelBase>();
            undoItems.AddRange(Model.Nodes);
            undoItems.AddRange(Model.Notes);
            WorkspaceModel.RecordModelsForModification(undoItems, Model.UndoRecorder);
            graph.RecordInitialPosition();

            // Sugiyama algorithm steps
            graph.RemoveCycles();
            graph.AssignLayers();
            graph.OrderNodes();

            // Node and graph positioning
            graph.DistributeNodePosition();
            graph.SetGraphPosition();
        }
Beispiel #34
0
        private void GenerateLayoutGraph(GraphLayout.Graph graph)
        {
            foreach (AnnotationModel group in Model.Annotations)
            {
                // Treat a group as a graph layout node/vertex
                graph.AddNode(group.GUID, group.Width, group.Height, group.X, group.Y);
            }

            foreach (NodeModel node in Model.Nodes)
            {
                AnnotationModel group = Model.Annotations.Where(
                    g => g.SelectedModels.Contains(node)).ToList().FirstOrDefault();

                // Do not process nodes within groups
                if (group == null)
                {
                    graph.AddNode(node.GUID, node.Width, node.Height, node.X, node.Y);
                }
            }

            foreach (ConnectorModel edge in Model.Connectors)
            {
                AnnotationModel startGroup = null, endGroup = null;
                startGroup = Model.Annotations.Where(
                    g => g.SelectedModels.Contains(edge.Start.Owner)).ToList().FirstOrDefault();
                endGroup = Model.Annotations.Where(
                    g => g.SelectedModels.Contains(edge.End.Owner)).ToList().FirstOrDefault();

                // Treat a group as a node, but do not process edges within a group
                if (startGroup == null || endGroup == null || startGroup != endGroup)
                {
                    graph.AddEdge(
                        startGroup == null ? edge.Start.Owner.GUID : startGroup.GUID,
                        endGroup == null ? edge.End.Owner.GUID : endGroup.GUID,
                        edge.Start.Center.X, edge.Start.Center.Y, edge.End.Center.X, edge.End.Center.Y);
                }
            }

            // Link a note to the nearest node
            foreach (NoteModel note in Model.Notes)
            {
                GraphLayout.Node nd = graph.Nodes.OrderBy(node =>
                    Math.Pow(node.X + node.Width / 2 - note.X - note.Width / 2, 2) +
                    Math.Pow(node.Y + node.Height / 2 - note.Y - note.Height / 2, 2)).FirstOrDefault();

                if (nd != null)
                {
                    nd.LinkedNotes.Add(note);
                }
            }
        }
Beispiel #35
0
        private void SaveLayoutGraph(GraphLayout.Graph graph)
        {
            // Assign coordinates to nodes inside groups
            foreach (var group in Model.Annotations)
            {
                var g = graph.FindNode(group.GUID);
                double deltaX = g.X - group.X;
                double deltaY = g.Y - group.Y;
                foreach (var node in group.SelectedModels.OfType<NodeModel>())
                {
                    node.X += deltaX;
                    node.Y += deltaY;
                    node.ReportPosition();
                }

                foreach (NoteModel note in g.LinkedNotes)
                {
                    note.X += deltaX;
                    note.Y += deltaY;
                    note.ReportPosition();
                }
            }

            // Assign coordinates to nodes outside groups
            foreach (var node in Model.Nodes)
            {
                var n = graph.FindNode(node.GUID);
                if (n != null)
                {
                    double deltaX = n.X - node.X;
                    double deltaY = n.Y - node.Y;

                    node.X = n.X;
                    node.Y = n.Y;
                    node.ReportPosition();
                    HasUnsavedChanges = true;

                    foreach (NoteModel note in n.LinkedNotes)
                    {
                        note.X += deltaX;
                        note.Y += deltaY;
                        note.ReportPosition();
                    }
                }
            }

            // Fit view to the new graph layout
            DynamoSelection.Instance.ClearSelection();
            ResetFitViewToggle(null);
            FitViewInternal();
        }
Beispiel #36
0
        /// <summary>
        /// This function calls the graph layout algorithm methods.
        /// </summary>
        /// <param name="graph">The subgraph to be processed.</param>
        /// <param name="isGroupLayout">True if all selected models are groups.</param>
        private void RunLayoutSubgraph(GraphLayout.Graph graph, bool isGroupLayout)
        {
            // Select relevant nodes
            graph.Nodes.ToList().ForEach(x => x.IsSelected = true);

            // Save subgraph position before running the layout
            graph.RecordInitialPosition();

            // Sugiyama algorithm steps
            graph.RemoveCycles();
            graph.AssignLayers();
            graph.OrderNodes();

            // Node and graph positioning
            graph.DistributeNodePosition();
            graph.SetGraphPosition(isGroupLayout);

            // Reset layer information and deselect nodes
            graph.ResetLayers();
            graph.Nodes.ToList().ForEach(x => x.IsSelected = false);
        }
Beispiel #37
0
        /// <summary>
        /// This function calls the graph layout algorithm methods.
        /// </summary>
        /// <param name="graph">The subgraph to be processed.</param>
        /// <param name="isGroupLayout">True if all selected models are groups.</param>
        private void RunLayoutSubgraph(GraphLayout.Graph graph, bool isGroupLayout)
        {
            // Save subgraph position before running the layout
            graph.RecordInitialPosition();

            // Sugiyama algorithm steps
            graph.RemoveCycles();
            graph.AssignLayers();
            graph.OrderNodes();

            // Node and graph positioning
            graph.DistributeNodePosition();
            graph.SetGraphPosition(isGroupLayout);
        }