yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
Method SelectScenario (
  ScenarioMP scenario
) as Boolean id:Method_ApplicationMacroPlanner_SelectScenario
{
  #keys: '[137862.0.9024813]'
  Body:
  [*
    // Select the active MacroPlan based on passed in scenario
    // Set active MacroPlan to the application
    // ComponentMDS::Create( Application ) is not available in Editor -- still finding, if exist, all this code will be moved.
    status := false;
    
    if( not isnull( scenario ) )
    {
      editor := ExternalMDSEditor::Editor();
      allinfo := editor.ObjectInfos();
    
      mdsInfo := select ( allinfo, Elements, oinfo,
                          oinfo.MDSID().MDSKey() = scenario.DatasetMDSID()
                          or oinfo.Name() = scenario.DatasetName());
    
      if ( not isnull( mdsInfo ) )
      {
      
        if( not mdsInfo.IsLoaded() )
        {
          scenario.SetAvailable( '' );
        }
      
        loop := true;
        p := Progress::Level( 'Loading scenario...', 10 );
      
        // changed the operation in "p.Current() < p.Maximum()" from <= to < as p.Maximum will never be reached
        // causing an infinite loop when a dataset is no longer available
        while( loop and p.Current() < p.Maximum() )
        {
          componentmds := ApplicationScope.ComponentMDS();
          mdsinstance := select( componentmds, ComponentMDSKinds.ComponentMDSInstances, m, m.MDSID().MDSKey() = scenario.DatasetMDSID() );
      
          if( not isnull( mdsinstance ) )
          {
            mdsinstance.ComponentMDSKind().SelectInstance( mdsinstance );
            componentmds.Apply();
            // To set the data holder if only a scenario has changed.
            if( DataHolderActiveScenario.Data() <> scenario )
            {
              DataHolderActiveScenario.Data( scenario );
              /*Setting the dataholder manually so that it can trigger the ondatachange for other dataholders that depend on it. When, this 
              dataholder is bind to extractor to retrieve MacroPlan automatically, it failed to trigger other dataholder ondatachange response when the MacroPlan first created.
              */
              DataHolderMacroPlanner.Data( MacroPlan );
            }
            status := true;
            loop := false;
          }
          p.Increment();
        }
      } 
    }
    
    return status;
  *]
}