/// <summary> /// This method pushes changes from the GraphLayout.Graph objects /// back to the workspace models, but only for nodes placed by NodeAutocomplete. /// </summary> private static void SaveLayoutGraphForNodeAutoComplete(this WorkspaceModel workspace, List <GraphLayout.Graph> layoutSubgraphs, Guid?originalNodeGUID) { // Assign coordinates to nodes outside groups foreach (var node in workspace.Nodes) { GraphLayout.Graph graph = layoutSubgraphs .FirstOrDefault(g => g.FindNode(node.GUID) != null); if (graph != null) { GraphLayout.Node n = graph.FindNode(node.GUID); double offsetY = graph.OffsetY; //skipping the original node to avoid jumping of node if (node.GUID != originalNodeGUID) { node.X = n.X; node.Y = n.Y + n.NotesHeight + offsetY; } node.ReportPosition(); workspace.HasUnsavedChanges = true; double noteOffset = -n.NotesHeight; foreach (NoteModel note in n.LinkedNotes) { if (note.IsSelected || DynamoSelection.Instance.Selection.Count == 0) { note.X = node.X; note.Y = node.Y + noteOffset; noteOffset += note.Height + GraphLayout.Graph.VerticalNoteDistance; note.ReportPosition(); } } } } }
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(); }
/// <summary> /// This method pushes changes from the GraphLayout.Graph objects /// back to the workspace models. /// </summary> private static void SaveLayoutGraph(this WorkspaceModel workspace, List <GraphLayout.Graph> layoutSubgraphs) { // Assign coordinates to nodes inside groups foreach (var group in workspace.Annotations) { GraphLayout.Graph graph = layoutSubgraphs .FirstOrDefault(g => g.FindNode(group.GUID) != null); if (graph != null) { GraphLayout.Node n = graph.FindNode(group.GUID); double deltaX = n.X - group.X; double deltaY = n.Y - group.Y + graph.OffsetY; foreach (var node in group.Nodes.OfType <NodeModel>()) { node.X += deltaX; node.Y += deltaY; node.ReportPosition(); } foreach (NoteModel note in n.LinkedNotes) { if (note.IsSelected || DynamoSelection.Instance.Selection.Count == 0) { note.X += deltaX; note.Y += deltaY; note.ReportPosition(); } } } } // Assign coordinates to nodes outside groups foreach (var node in workspace.Nodes) { GraphLayout.Graph graph = layoutSubgraphs .FirstOrDefault(g => g.FindNode(node.GUID) != null); if (graph != null) { GraphLayout.Node n = graph.FindNode(node.GUID); double offsetY = graph.OffsetY; node.X = n.X; node.Y = n.Y + n.NotesHeight + offsetY; node.ReportPosition(); workspace.HasUnsavedChanges = true; double noteOffset = -n.NotesHeight; foreach (NoteModel note in n.LinkedNotes) { if (note.IsSelected || DynamoSelection.Instance.Selection.Count == 0) { note.X = node.X; note.Y = node.Y + noteOffset; noteOffset += note.Height + GraphLayout.Graph.VerticalNoteDistance; note.ReportPosition(); } } } } }
/// <summary> /// This method pushes changes from the GraphLayout.Graph objects /// back to the workspace models. /// </summary> private static void SaveLayoutGraph(this WorkspaceModel workspace, List <GraphLayout.Graph> layoutSubgraphs) { // Assign coordinates to nodes inside groups foreach (var group in workspace.Annotations) { GraphLayout.Graph graph = layoutSubgraphs .FirstOrDefault(g => g.FindNode(group.GUID) != null); if (graph != null) { GraphLayout.Node n = graph.FindNode(group.GUID); double deltaX = n.X - group.X; double deltaY = n.Y - group.Y + graph.OffsetY; // We update the posistion of all nodes in the // parent group + all nodes in any potential // nested groups. foreach (var node in group.Nodes .OfType <NodeModel>() .Union(group.Nodes.OfType <AnnotationModel>().SelectMany(x => x.Nodes.OfType <NodeModel>()))) { node.X += deltaX; node.Y += deltaY; node.ReportPosition(); } foreach (NoteModel note in n.LinkedNotes) { if (note.PinnedNode != null) { continue; } if (note.IsSelected || DynamoSelection.Instance.Selection.Count == 0) { note.X += deltaX; note.Y += deltaY; note.ReportPosition(); } } group.ReportPosition(); } } // Assign coordinates to nodes outside groups foreach (var node in workspace.Nodes) { GraphLayout.Graph graph = layoutSubgraphs .FirstOrDefault(g => g.FindNode(node.GUID) != null); if (graph != null) { GraphLayout.Node n = graph.FindNode(node.GUID); double offsetY = graph.OffsetY; node.X = n.X; node.Y = n.Y + n.NotesHeight + offsetY; node.ReportPosition(); workspace.HasUnsavedChanges = true; double noteOffset = -n.NotesHeight; foreach (NoteModel note in n.LinkedNotes) { if (note.PinnedNode != null) { continue; } if (note.IsSelected || DynamoSelection.Instance.Selection.Count == 0) { note.X = node.X; note.Y = node.Y + noteOffset; noteOffset += note.Height + GraphLayout.Graph.VerticalNoteDistance; note.ReportPosition(); } } } } // Assign coordinates to connectors outside of groups foreach (var connector in workspace.Connectors) { foreach (var pin in connector.ConnectorPinModels) { GraphLayout.Graph graph = layoutSubgraphs .FirstOrDefault(g => g.FindNode(pin.GUID) != null); if (graph != null) { GraphLayout.Node n = graph.FindNode(pin.GUID); pin.CenterX = n.X; pin.CenterY = n.Y; pin.ReportPosition(); workspace.HasUnsavedChanges = true; } } } }