chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Quintiq file version 2.0
#parent: #root
Method SequenceNodes
{
  Description: 'Determine the sequence the nodes should be in.'
  TextBody:
  [*
    rows := selectsortedset( this, UIGraphRow, row, true, row.RowNr() );
    
    toprow := this.First();
    topnodes := selectsortedset( this, UIGraphNode, node, node.Row() = toprow.RowNr(),
                                 -1 * counter( node.GetSubgraph(), Elements, n, not isnull( n.Component() ) ),
                                 node.Name() );
    
    tailrows := selectset( this, UIGraphRow, r, not isnull( r.Previous() ) );
    
    nodes := construct( LibOpt_UIGraphNodes );
    
    traverse( topnodes, Elements, topnode )
    {
      if( toprow.UIGraphNode( relsize ) > 0 )
      {
        // Calculate the position of the nodes
        this.PositionNodes();
      }
      
      subgraph := topnode.GetSubgraph();
      
      new := selectsortedset( subgraph.Difference( nodes ), Elements, node, true,
                              -node.Row() );
      nodes := nodes.Union( subgraph );
      not_added := construct( LibOpt_UIGraphNodes );
      
      // Interpolate desired X value from children
      traverse( new, Elements, node )
      {
        children := selectset( node, Outgoing, arc, not isnull( arc.Destination().UIGraphRow() ) );
        if( children.Size() > 0 )
        {
          node.X( average( children, Elements, arc, arc.Destination().X() ) );
          node.UIGraphRow( relset, rows.Element( node.Row() ) );
        }
        else
        {
          not_added.Add( node );
        }
      }
      
      // Add the elements that were not added yet
      traverse( not_added, Elements, node )
      {
        node.UIGraphRow( relset, rows.Element( node.Row() ) );
        node.X( guard( node.UIGraphRow().Last().X() + 1, 0 ) );
      }
      
      // Sort top row
      toprow.SortNodes( selectsortedset( toprow, UIGraphNode, node,
                                         true,
                                         node.X(), node.Name() ) );
      
      // Sort top down
      traverse( tailrows, Elements, row )
      {
        row.SortTopDown();
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}