yanyuan
2023-11-10 143ef74e2eeee697ac8fda3d9032a790fbb4e146
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
Quintiq file version 2.0
#parent: #root
StaticMethod GetEntitiesToSave (
  Entitys checkEntities
) as owning Entitys
{
  Description:
  [*
    Web introduced new bookmark logic. Keep bookmark as short as possible.
    If all children (and descendants) checked, store the parent only. If partial, then no choice we store the checked children.
  *]
  TextBody:
  [*
    result := construct( Entitys ); // Entities to bookmark
    
    // Filter out system (WIP) entities and parent entities
    checkLeafEntities := selectset( checkEntities, Elements, c, not c.GetIsSystem() and c.ChildEntity( relsize ) = 0 );
    
    // Based on filtered entities, get all their parents
    allParentsSorted := selectsortedset( Entity::GetAllParents( checkLeafEntities ), 
                                         Elements, e, 
                                         e.ChildEntity( relsize ) > 0, // Filter out the leaf as GetAllParents return the entity itself as well
                                         e.DisplayIndex() );           // Sort from root down to lower level entities 
    
    // Important to start with root, as we will remove 'intersecting' leaf entities as we loop
    traverse( allParentsSorted, Elements, parent, checkLeafEntities.Size() > 0 ) // Continue as long as there's entities to be considered
    {
      leafDescendants := parent.GetLeafDescendants(); 
    
      // If current parent's leaf descendants are found in user checked entities
      // We only bookmark the parent and remove leaf descendants from the list and proceed next parent
      // Example (Food demo): Add unit Plants if ALL Denmark, Hungary and France machines are part of user checked entities
      if( checkLeafEntities.ContainsAll( leafDescendants ) )
      {
        checkLeafEntities.Remove( leafDescendants );  
        result.Add( parent );  
      }
    }
    
    // If there's leaf entities left (not all siblings check), add them to the result
    if( checkLeafEntities.Size() > 0 )
    {
      result := result.Union( checkLeafEntities );
    }
    
    return &result;
  *]
}