/// <summary> /// If a connector has connectorPins, their edges get added to the combined graph. /// </summary> /// <param name="combinedGraph"></param> /// <param name="connector"></param> private static void AddConnectorEdgesIncludingPinEdges(GraphLayout.Graph combinedGraph, ConnectorModel connector, Guid?start = null, Guid?end = null) { ///Bail if there are no connectorPins if (connector.ConnectorPinModels.Count < 1) { Guid startGuid = start == null ? connector.Start.Owner.GUID : (Guid)start; Guid endGuid = end == null ? connector.End.Owner.GUID : (Guid)end; combinedGraph.AddEdge(startGuid, endGuid, connector.Start.Center.X, connector.Start.Center.Y, connector.End.Center.X, connector.End.Center.Y); return; } ///Add an edge between the left-most (start) node ///(its corresponding port) to which this connector connects, and the first connectorPin. combinedGraph.AddEdge(connector.Start.Owner.GUID, connector.ConnectorPinModels[0].GUID, connector.Start.Center.X, connector.Start.Center.Y, connector.ConnectorPinModels[0].CenterX, connector.ConnectorPinModels[0].CenterY); ///Add an edge between all other connectorPins that follow, ///from left to right (except for last one) for (int i = 0; i < connector.ConnectorPinModels.Count; i++) { if (i != connector.ConnectorPinModels.Count - 1) { combinedGraph.AddEdge(connector.ConnectorPinModels[i].GUID, connector.ConnectorPinModels[i + 1].GUID, connector.ConnectorPinModels[i].CenterX, connector.ConnectorPinModels[i].CenterY, connector.ConnectorPinModels[i + 1].CenterX, connector.ConnectorPinModels[i + 1].CenterY); } } ///Add an edge between the last connectorPin and the right-most (end) node ///(its corresponding port) to which this connector connects. combinedGraph.AddEdge(connector.ConnectorPinModels[connector.ConnectorPinModels.Count - 1].GUID, connector.End.Owner.GUID, connector.ConnectorPinModels[connector.ConnectorPinModels.Count - 1].CenterX, connector.ConnectorPinModels[connector.ConnectorPinModels.Count - 1].CenterY, connector.End.Center.X, connector.End.Center.Y); }
private void DoGraphAutoLayout(object o) { if (Model.Nodes.Count == 0) { return; } var graph = new GraphLayout.Graph(); var models = new Dictionary <ModelBase, UndoRedoRecorder.UserAction>(); foreach (NodeModel x in Model.Nodes) { graph.AddNode(x.GUID, x.Width, x.Height, x.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } foreach (ConnectorModel x in Model.Connectors) { graph.AddEdge(x.Start.Owner.GUID, x.End.Owner.GUID, x.Start.Center.Y, x.End.Center.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } Model.RecordModelsForModification(new List <ModelBase>(Model.Nodes)); // Sugiyama algorithm steps graph.RemoveCycles(); graph.AssignLayers(); graph.OrderNodes(); // Assign coordinates to node models graph.NormalizeGraphPosition(); foreach (var x in Model.Nodes) { var id = x.GUID; x.X = graph.FindNode(id).X; x.Y = graph.FindNode(id).Y; x.ReportPosition(); } // Fit view to the new graph layout DynamoSelection.Instance.ClearSelection(); ResetFitViewToggle(null); FitViewInternal(); }
private void DoGraphAutoLayout(object o) { if (Model.Nodes.Count() == 0) { return; } var graph = new GraphLayout.Graph(); var models = new Dictionary <ModelBase, UndoRedoRecorder.UserAction>(); foreach (AnnotationModel x in Model.Annotations) { // Treat a group as a graph layout node/vertex graph.AddNode(x.GUID, x.Width, x.Height, x.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } foreach (NodeModel x in Model.Nodes) { AnnotationModel group = Model.Annotations.Where( s => s.SelectedModels.Contains(x)).ToList().FirstOrDefault(); // Do not process nodes within groups if (group == null) { graph.AddNode(x.GUID, x.Width, x.Height, x.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } } foreach (ConnectorModel x in Model.Connectors) { AnnotationModel startGroup = null, endGroup = null; startGroup = Model.Annotations.Where( s => s.SelectedModels.Contains(x.Start.Owner)).ToList().FirstOrDefault(); endGroup = Model.Annotations.Where( s => s.SelectedModels.Contains(x.End.Owner)).ToList().FirstOrDefault(); // Connector does not belong to any group if ((startGroup == null) && (endGroup == null)) { graph.AddEdge(x.Start.Owner.GUID, x.End.Owner.GUID, x.Start.Center.Y, x.End.Center.Y); } // Connector starts from a node within a group else if ((startGroup != null) && (endGroup == null)) { graph.AddEdge(startGroup.GUID, x.End.Owner.GUID, x.Start.Center.Y, x.End.Center.Y); } // Connector ends at a node within a group else if ((startGroup == null) && (endGroup != null)) { graph.AddEdge(x.Start.Owner.GUID, endGroup.GUID, x.Start.Center.Y, x.End.Center.Y); } models.Add(x, UndoRedoRecorder.UserAction.Modification); } // Support undo for graph layout command WorkspaceModel.RecordModelsForModification(new List <ModelBase>(Model.Nodes), Model.UndoRecorder); // Sugiyama algorithm steps graph.RemoveCycles(); graph.AssignLayers(); graph.OrderNodes(); graph.NormalizeGraphPosition(); // Assign coordinates to nodes inside groups foreach (var x in Model.Annotations) { var id = x.GUID; double deltaX = graph.FindNode(id).X - x.X; double deltaY = graph.FindNode(id).Y - x.Y; foreach (var n in x.SelectedModels) { n.X += deltaX; n.Y += deltaY; n.ReportPosition(); } } // Assign coordinates to nodes outside groups foreach (var x in Model.Nodes) { var n = graph.FindNode(x.GUID); if (n != null) { x.X = n.X; x.Y = n.Y; x.ReportPosition(); } } // Fit view to the new graph layout DynamoSelection.Instance.ClearSelection(); ResetFitViewToggle(null); FitViewInternal(); }
private void DoGraphAutoLayout(object o) { if (Model.Nodes.Count == 0) return; var graph = new GraphLayout.Graph(); var models = new Dictionary<ModelBase, UndoRedoRecorder.UserAction>(); foreach (NodeModel x in Model.Nodes) { graph.AddNode(x.GUID, x.Width, x.Height, x.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } foreach (ConnectorModel x in Model.Connectors) { graph.AddEdge(x.Start.Owner.GUID, x.End.Owner.GUID, x.Start.Center.Y, x.End.Center.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } Model.RecordModelsForModification(new List<ModelBase>(Model.Nodes)); // Sugiyama algorithm steps graph.RemoveCycles(); graph.AssignLayers(); graph.OrderNodes(); // Assign coordinates to node models graph.NormalizeGraphPosition(); foreach (var x in Model.Nodes) { var id = x.GUID; x.X = graph.FindNode(id).X; x.Y = graph.FindNode(id).Y; x.ReportPosition(); } // Fit view to the new graph layout DynamoSelection.Instance.ClearSelection(); ResetFitViewToggle(null); FitViewInternal(); }
private void DoGraphAutoLayout(object o) { if (Model.Nodes.Count() == 0) return; var graph = new GraphLayout.Graph(); var models = new Dictionary<ModelBase, UndoRedoRecorder.UserAction>(); foreach (AnnotationModel x in Model.Annotations) { // Treat a group as a graph layout node/vertex graph.AddNode(x.GUID, x.Width, x.Height, x.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } foreach (NodeModel x in Model.Nodes) { AnnotationModel group = Model.Annotations.Where( s => s.SelectedModels.Contains(x)).ToList().FirstOrDefault(); // Do not process nodes within groups if (group == null) { graph.AddNode(x.GUID, x.Width, x.Height, x.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } } foreach (ConnectorModel x in Model.Connectors) { AnnotationModel startGroup = null, endGroup = null; startGroup = Model.Annotations.Where( s => s.SelectedModels.Contains(x.Start.Owner)).ToList().FirstOrDefault(); endGroup = Model.Annotations.Where( s => s.SelectedModels.Contains(x.End.Owner)).ToList().FirstOrDefault(); // Connector does not belong to any group if ((startGroup == null) && (endGroup == null)) graph.AddEdge(x.Start.Owner.GUID, x.End.Owner.GUID, x.Start.Center.Y, x.End.Center.Y); // Connector starts from a node within a group else if ((startGroup != null) && (endGroup == null)) graph.AddEdge(startGroup.GUID, x.End.Owner.GUID, x.Start.Center.Y, x.End.Center.Y); // Connector ends at a node within a group else if ((startGroup == null) && (endGroup != null)) graph.AddEdge(x.Start.Owner.GUID, endGroup.GUID, x.Start.Center.Y, x.End.Center.Y); models.Add(x, UndoRedoRecorder.UserAction.Modification); } // Support undo for graph layout command WorkspaceModel.RecordModelsForModification(new List<ModelBase>(Model.Nodes), Model.UndoRecorder); // Sugiyama algorithm steps graph.RemoveCycles(); graph.AssignLayers(); graph.OrderNodes(); graph.NormalizeGraphPosition(); // Assign coordinates to nodes inside groups foreach (var x in Model.Annotations) { var id = x.GUID; double deltaX = graph.FindNode(id).X - x.X; double deltaY = graph.FindNode(id).Y - x.Y; foreach (var n in x.SelectedModels) { n.X += deltaX; n.Y += deltaY; n.ReportPosition(); } } // Assign coordinates to nodes outside groups foreach (var x in Model.Nodes) { var n = graph.FindNode(x.GUID); if (n != null) { x.X = n.X; x.Y = n.Y; x.ReportPosition(); } } // Fit view to the new graph layout DynamoSelection.Instance.ClearSelection(); ResetFitViewToggle(null); FitViewInternal(); }