| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod GetCopies ( | 
|   Number nrcopies, | 
|   Routings routings | 
| ) as owning Routings | 
| { | 
|   TextBody: | 
|   [* | 
|     //return Routing::GetCopies_Slow( nrcopies, routings );  | 
|      | 
|     copies := construct( RoutingPairs );  | 
|     returnset := construct(  Routings );  | 
|     if ( routings.Size() > 0 )  | 
|     { | 
|       routings.Element( 0 ).MacroPlan().RoutingPair( relflush );  | 
|     } | 
|      | 
|      | 
|     traverse( routings, Elements, routing )  | 
|     { | 
|       for ( i := 1; i <= nrcopies; i++ )  | 
|       { | 
|         routingname := routing.MacroPlan().GetUniqueRoutingName( routing.Name() + GlobalParameters_MP::GetCopyString() ); | 
|          | 
|         newrouting := Routing::Create( routing.MacroPlan(), | 
|                                        routingname, | 
|                                        routingname, | 
|                                        routing.Start(), | 
|                                        routing.End(), | 
|                                        routing.AllowWIPInventory(), | 
|                                        false  | 
|                                        ); | 
|         newrouting.CopyHelper( i );  | 
|         routingpair := routing.MacroPlan().RoutingPair( relnew, FirstRouting := routing, SecondRouting := newrouting );                                    | 
|         copies.Add(  routingpair );  | 
|         returnset.Add( newrouting );   | 
|         // Copy rouitng step with operations | 
|         traverse( routing, RoutingStep, rs ) | 
|         { | 
|           rs.Copy( newrouting ); | 
|         } | 
|       } | 
|     } | 
|      | 
|     debuginfo( 'Step 1 created copies size = ', copies.Size() );  | 
|       | 
|     // Propagated all Operation-Step-Routing relation before copy operation link | 
|     Transaction::Transaction().Propagate(); | 
|      | 
|     debuginfo(  'propagated' ); | 
|     traverse( copies, Elements, routingpair )  | 
|     { | 
|       routing := routingpair.FirstRouting();  | 
|       newrouting := routingpair.SecondRouting();  | 
|       traverse( routing, RoutingStep.Operation.SourceOperationLink, ol ) | 
|       { | 
|         ol.Copy( newrouting ); | 
|       } | 
|     } | 
|     debuginfo(  'Step 2 done' );  | 
|     if ( routings.Size() > 0 )  | 
|     { | 
|       routings.Element( 0 ).MacroPlan().RoutingPair( relflush );  | 
|     } | 
|      | 
|     return &returnset; | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |