Quintiq file version 2.0
#parent: #root
Method SetDefaultValue () id:Method_DialogSelectOptimizer_SetDefaultValue
{
  #keys: '[112884.0.24363403]'
  Body:
  [*
    // Set default value for components
    
    run := MacroPlan.Optimization().GetLastRegularAlgorithmRun();
    
    // Optimizer
    lastUsedOptimizer := MacroPlan.LastUsedOptimizerPuzzle();
    
    if( isnull( lastUsedOptimizer ) )
    {
      lastUsedOptimizer := MacroPlan.OptimizerPuzzleWorld();
    }
    
    Dialog.SetSelectionOptimizer( lastUsedOptimizer );
       
    // Strategy
    strategy := AlgorithmRun::GetLastStrategyUsed( MacroPlan.GlobalParameters_MP(), run, ScenarioManager, true, false );
    SelectionStrategy.BoundValue( guard( strategy.Name(), '' ) );
    
    
    // Set the default planning start and end
    feedback := '';
    if( Period_MP::HasPeriod( feedback, MacroPlan ) )
    {
      Dialog.SetDefaultPlanningStartAndEnd();
      
      // Prevent the usage of last optimizer start if it is historical
      if( not isnull( run )
          and MacroPlan.StartOfPlanningPeriod().Start() <= run.PeriodFirstStart() )
      {
        // Using bound value is not working as expected
        periodstart := select( MacroPlan, PlanningPeriod, p, p.Start() = run.PeriodFirstStart() );
        periodend := select( MacroPlan, PlanningPeriod, p, p.PeriodEnd() = run.PeriodLastEnd() );
        SelectionPeriodFrom.Data( periodstart );
        SelectionPeriodTo.Data( periodend );
      }
    }
    
    CheckBoxOverrideManualPlanning.Checked( guard( run.HasOverwrittenManualPlanning(), false ) );
  *]
}
