Lai,Risheng
2023-11-02 30c02e0c981b16be0918483543f4b812956c45d4
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Quintiq file version 2.0
#parent: PanelSCV/CustomDrawDataLayerSCVEdge
Response OnDrawObject (
  shadow[SCVEdge] object
) id:Response_PanelSCV_CustomDrawDataLayerSCVEdge_OnDrawObject
{
  #keys: '[134266.2.4973606]'
  CanBindMultiple: false
  DefinitionID: 'Responsedef_WebCustomDrawDataLayer_OnDrawObject'
  QuillAction
  {
    Body:
    [*
      // Draw object
      scvConfig := MacroPlan.SCVConfiguration();
      
      adjustmentX := scvConfig.NodeSize();
      adjustmentY := floor( scvConfig.NodeSize() / 2 );
      
      // Adjust line based on its orientations
      
      topdown := object.ToY() > object.FromY();
      leftright := object.ToX() > object.FromX();
      
      padding := 6;
      
      
      fromy := region.BoundingRect().Top() + padding;
      toy := region.BoundingRect().Height() - padding;
      
      if( topdown )
      {
        if( not leftright )
        {
          fromy := region.BoundingRect().Top() + padding;
          toy := region.BoundingRect().Height() - padding;
        }
      }
      else
      {
        if( leftright )
        {
          fromy := region.BoundingRect().Height() - padding;
          toy := region.BoundingRect().Top() + padding;
        }
      }
      
      // Get line quantity and label
      quantity := object.Quantity();
      lineLabel := object.Label()
      
      // Color the line gray if quantity is 0 or smaller
      lineColor := ColorScheme.SupplyChainVisualization_Edge();
      if( quantity <= 0.0 )
      {
        lineColor := ColorScheme.SupplyChainVisualization_Node();
        // Color the text gray too
        surface.TextColor( lineColor );
      }
      
      //Initialize drawing parameters
      surface.Pen().Color( lineColor )
                   .Width( 1 );
      surface.Brush().Color( lineColor );
      
      // Draw the directional line
      line := GraphicalLine::LineTo( region.BoundingRect().Left(), fromy, region.BoundingRect().Width(), toy );
      line.ArrowToEnd( true ).ArrowPos( GraphicalLine::ArrowPosMiddle() );
      surface.Draw( line );
      
      // Draw quantity label
      // Get rotation angle to rotate the text to the same angle as the line
      gradient := ( toy - fromy ) / ( region.BoundingRect().Width() - region.BoundingRect().Left() );
      degree := atan( -gradient ) * 180 / pi;
      // Webclient doesn't support negative degree rotation
      
      surface.Font().Name( scvConfig.FontName() )
                    .Size( scvConfig.FontSize() )
                    .Angle( [Number]degree );
      
      textformat := TextFormat::Construct( TextFormat::AlignCenter() );
      
      // Rotate the text to 
      if( object.FromY() = object.ToY() )
      {
        surface.TextZoom( region.BoundingRect().Left(), region.BoundingRect().Top() - scvConfig.FontSize(),
                          region.BoundingRect().Width(), scvConfig.FontSize() * 2,
                          lineLabel, textformat );
      }
      else
      {
        // If targetnode and sourcenode have different Y positions,
        // it means there is a gradient and we need to rotate the 
        // text. The hardcoded offsets below are the sweet numbers
        // that we found that allows the text to have even distance to line
        // for any angle of rotation
        textformat := TextFormat::Construct( TextFormat::AlignCentered() );
        surface.TextZoom( region.BoundingRect().Left(), region.BoundingRect().Top() + ifexpr( gradient > 0, -14, -4 ),
                          region.BoundingRect().Width(), region.BoundingRect().Height(),
                          [String]lineLabel, textformat );    
      }
    *]
    GroupServerCalls: false
  }
}