@@ -20,7 +20,7 @@ public static class LayoutExtensions
20
20
/// </summary>
21
21
/// <param name="workspace">Workspace on which graph layout will be performed.</param>
22
22
/// <param name="reuseUndoRedoGroup">If true, skip initializing new undo action group.</param>
23
- internal static List < GraphLayout . Graph > DoGraphAutoLayout ( this WorkspaceModel workspace , bool reuseUndoRedoGroup = false )
23
+ internal static List < GraphLayout . Graph > DoGraphAutoLayout ( this WorkspaceModel workspace , bool reuseUndoRedoGroup = false , bool isNodeAutoComplete = false , Guid ? originalNodeGUID = null )
24
24
{
25
25
if ( workspace . Nodes . Count ( ) < 2 ) return null ;
26
26
@@ -50,7 +50,14 @@ public static class LayoutExtensions
50
50
// Run layout algorithm for each subgraph
51
51
layoutSubgraphs . Skip ( 1 ) . ToList ( ) . ForEach ( g => RunLayoutSubgraph ( g , isGroupLayout ) ) ;
52
52
AvoidSubgraphOverlap ( layoutSubgraphs ) ;
53
- SaveLayoutGraph ( workspace , layoutSubgraphs ) ;
53
+
54
+ if ( isNodeAutoComplete )
55
+ {
56
+ SaveLayoutGraphForNodeAutoComplete ( workspace , layoutSubgraphs , originalNodeGUID ) ;
57
+ }
58
+ else {
59
+ SaveLayoutGraph ( workspace , layoutSubgraphs ) ;
60
+ }
54
61
55
62
// Restore the workspace model selection information
56
63
selection . ToList ( ) . ForEach ( x => x . Select ( ) ) ;
@@ -426,6 +433,46 @@ private static void SaveLayoutGraph(this WorkspaceModel workspace, List<GraphLay
426
433
node . ReportPosition ( ) ;
427
434
workspace . HasUnsavedChanges = true ;
428
435
436
+ double noteOffset = - n . NotesHeight ;
437
+ foreach ( NoteModel note in n . LinkedNotes )
438
+ {
439
+ if ( note . IsSelected || DynamoSelection . Instance . Selection . Count == 0 )
440
+ {
441
+ note . X = node . X ;
442
+ note . Y = node . Y + noteOffset ;
443
+ noteOffset += note . Height + GraphLayout . Graph . VerticalNoteDistance ;
444
+ note . ReportPosition ( ) ;
445
+ }
446
+ }
447
+ }
448
+ }
449
+ }
450
+ /// <summary>
451
+ /// This method pushes changes from the GraphLayout.Graph objects
452
+ /// back to the workspace models, but only for nodes placed by NodeAutocomplete.
453
+ /// </summary>
454
+ private static void SaveLayoutGraphForNodeAutoComplete ( this WorkspaceModel workspace , List < GraphLayout . Graph > layoutSubgraphs , Guid ? originalNodeGUID )
455
+ {
456
+ // Assign coordinates to nodes outside groups
457
+ foreach ( var node in workspace . Nodes )
458
+ {
459
+ GraphLayout . Graph graph = layoutSubgraphs
460
+ . FirstOrDefault ( g => g . FindNode ( node . GUID ) != null ) ;
461
+
462
+ if ( graph != null )
463
+ {
464
+ GraphLayout . Node n = graph . FindNode ( node . GUID ) ;
465
+ double offsetY = graph . OffsetY ;
466
+ //skipping the original node to avoid jumping of node
467
+ if ( node . GUID != originalNodeGUID )
468
+ {
469
+ node . X = n . X ;
470
+ node . Y = n . Y + n . NotesHeight + offsetY ;
471
+
472
+ }
473
+ node . ReportPosition ( ) ;
474
+ workspace . HasUnsavedChanges = true ;
475
+
429
476
double noteOffset = - n . NotesHeight ;
430
477
foreach ( NoteModel note in n . LinkedNotes )
431
478
{
0 commit comments