Dynamo.Graph.Workspaces.WorkspaceModel.SaveLayoutGraph C# (CSharp) Method

SaveLayoutGraph() private method

This method pushes changes from the GraphLayout.Graph objects back to the workspace models.
private SaveLayoutGraph ( ) : void
return void
        private void SaveLayoutGraph()
        {
            // Assign coordinates to nodes inside groups
            foreach (var group in 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.SelectedModels.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 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();
                    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();
                        }
                    }
                }
            }
        }
WorkspaceModel