chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
106
107
108
109
110
111
Quintiq file version 2.0
#parent: CustomDrawComponentSupplyChainVisualization/CustomDrawDataLayerSCVEdge
Response OnDrawObject (
  shadow[SCVEdge] object
) id:Response_CustomDrawComponentSupplyChainVisualization_CustomDrawDataLayerSCVEdge_OnDrawObject
{
  #keys: '[132894.0.877949609]'
  Body:
  [*
    // Draw PISPIPSCVEdge
    scvConfig := DataHolderSCVConfiguration.Data();
    
    node1 := select( scvConfig, SCVNode, n,
                     object.DestinationKey() = n.Key().AsQUILL() );
    
    node2 := select( scvConfig, SCVNode, n,
                     object.OriginKey() = n.Key().AsQUILL() );  
    
    sourceNode := ifexpr( node1.IsUpstream(), node1, node2 );
    targetNode := ifexpr( node1.IsUpstream(), node2, node1 );
    
    adjustmentX := scvConfig.NodeSize();
    adjustmentY := floor( scvConfig.NodeSize() / 2 );
    
    // Adjust line based on its orientations
    topdown := sourceNode.Y() + adjustmentY
               < targetNode.Y() + adjustmentY;
    leftright := sourceNode.X() + adjustmentX
                 < targetNode.X();
    padding := 6;
    
    fromy := region.Top() + padding;
    toy := region.Height() - padding;
    
    if( topdown )
    {
      if( not leftright )
      {
        fromy := region.Top() + padding;
        toy := region.Height() - padding;
      }
    }
    else
    {
      if( leftright )
      {
        fromy := region.Height() - padding;
        toy := region.Top() + padding;
      }
    }
    
    // Get line quantity and label
    quantity := 0.0;
    lineLabel := FormSupplyChainVisualization.ReturnEdgeLabel( sourceNode, targetNode, quantity );
    
    // Color the line gray if quantity is 0 or smaller
    lineColor := ColorScheme.SCVEdge();
    if( quantity <= 0.0 )
    {
      lineColor := ColorScheme.SCVNode();
      // 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.Left(), fromy, region.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.Width() - region.Left() );
    degree := atan( -gradient ) * 180 / pi;
    // Get the mid length of the line, it is where the text should start, the reason being
    // rotation rotate with top left of the draw region as the corner. 
    radius := sqrt( sqr( [Real]region.Right() - region.Left() ) + sqr( [Real]region.Bottom() - region.Top() ) );
    
    surface.Font().Name( scvConfig.FontName() )
                  .Size( scvConfig.FontSize() )
                  .Angle( [Number]degree );
    
    textformat := TextFormat::Construct( TextFormat::AlignCenter() );
                            
    // Rotate the text to 
    if( sourceNode.Y() = targetNode.Y() )
    {
      textformat := TextFormat::Construct( TextFormat::AlignCentered() );
      surface.TextZoom( region.Left(), region.Top() - scvConfig.FontSize() * 2,
                        region.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
      surface.TextZoom( region.Left(), ifexpr( gradient > 0, region.Top() - 10, region.Bottom() - 22 ),
                        [Number]radius, region.Height(),
                        lineLabel, textformat );    
    }
  *]
  CanBindMultiple: false
  DefinitionID: 'Responsedef_CustomDrawDataLayer_OnDrawObject'
}