陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
Quintiq file version 2.0
#parent: #root
Method Copy (LibOpt_Component start_component, LibOpt_ScopeElements scope_elements) as LibOpt_Run
{
  Description: 'This method copies the `LibOpt_Component` structure of this `LibOpt_Run` into a new run while allowing for a new Start Component and using the `scope_elements` parameter as the start scope.'
  TextBody:
  [*
    run := this.Optimizer().CreateRun();
    // Copy the components and contexts
    occ := ObjectCopyComponent::Create();
    traverse( this, Component, component )
    {
      component.Copy( occ, run );
    }
    traverse( this, RunContext, context )
    {
      context.Copy( occ, run );
    }
    
    freeze_propagation := false;
    occ.Execute( freeze_propagation );
    
    // Copy settings
    run.DebugScope( this.DebugScope() );
    run.InOneTransaction( this.InOneTransaction() );
    // Copy the start component
    if( not isnull( start_component ) )
    {
      run.SetStartComponent( start_component.Name() );
    }
    
    // Copy the start scope
    if( not isnull( scope_elements ) )
    {
      scope := LibOpt_Scope::Create( run );
      scope.Add( scope_elements );
      run.SetStartScope( scope );
    }
    
    // Some components and contexts may have overridden the default copy behavior. Execute the post-copy initialization:
    // first context (more static data)
    traverse( run, RunContext, context_copy )
    {
      context_copy.InitAsCopy( this );
    }
    // then components (may rely on contexts)
    traverse( this, Component, component_original )
    {
      component_copy := selectobject( run, Component, c, c.Name() = component_original.Name() );
      component_copy.InitAsCopyOf( component_original );
    }
    
    return run;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}