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
66
67
68
69
Quintiq file version 2.0
#parent: #root
Function CalcX
{
  TextBody:
  [*
    // Adhi Jan-30-2016 (created)
    
    routingstep := this.RoutingStep();
    rcv := this.RoutingConfiguratorView();
    
    value := guard( routingstep.X(), 0 );
    
    if( not isnull( routingstep ) and not isnull( rcv ) )
    {
      /*
        To ensure centre alignment, we need to know the routing step with the highest number of operation
        if this operation has the highest number of operation, then draw as usual.
        Else, the logic will calculate the offset from x-position to make sure the operation are aligned in the centre
      */
      routing := this.GetRouting();
      rsmaxwidth := routing.MaxNrOfOperations();
      rs := routingstep.Operation( relsize );
    
      // If the routing step has the highest number of operation, draw like normal
      if( rs = rsmaxwidth )
      {
        value := value + rcv.OperationOffsetX();
      }
      else
      {
      // Else, align to the centre
        /*
          If the number of operation within this routing is an even number
          the middle part is offset
          Else, the middle part is the middle point of the ((numberofoperation/2) + 1)th operation
        */
        centeroffset := value
                        + routingstep.Width() / 2;
    
        if( rs mod 2 = 0 )
        {
          value := round( centeroffset
                          - rcv.OperationOffsetX() / 2
                          - ( rs / 2 ) * rcv.OperationWidth()
                          - ( ( rs / 2 ) - 1 ) * rcv.OperationOffsetX() );
        }
        else
        {
          value := round( centeroffset
                          - rcv.OperationWidth() / 2
                          - ( ( rs - 1 ) / 2 )* rcv.OperationWidth()
                          - ( ( rs - 1 ) / 2 ) * rcv.OperationOffsetX() );
        }
      }
    
      // If previous operation exists, just check the last x position + offset + operation width
      if( not isnull( this.Previous() ) )
      {
        value := this.Previous().X()
                 + rcv.OperationOffsetX()
                 + rcv.OperationWidth();
      }
    }
    
    
    this.X( value );
  *]
}