hongji.li
2023-11-11 df5a7e1ad6835e78b2f9eb7428817b0c23b116bc
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
Quintiq file version 2.0
#parent: CustomDrawComponentSupplyChainVisualization/CustomDrawDataLayerNode
Response OnDrawObject (
  shadow[SCVNode] object
) id:Response_CustomDrawComponentSupplyChainVisualization_CustomDrawDataLayerNode_OnDrawObject
{
  #keys: '[132894.0.851837207]'
  Body:
  [*
    // Draw SCVNode
    
    // Drawing parameters, node label, node title, label width, title width
    scvconfig := DataHolderSCVConfiguration.Data();
    nodesize := scvconfig.NodeSize();
    
    nodetitle := ''
    nodelabel := ''
    iconimage := '';
    textformat := TextFormat::Construct( TextFormat::AlignBottom(), TextFormat::AlignCenter() ); 
    
    // Specify labels, iconimage based on draw type
    if( object.istype( shadow[SCVPISPIPNode] ) )
    {
      pisp := object.astype( shadow[SCVPISPIPNode] ).ProductInStockingPointInPeriod().ProductInStockingPoint_MP();
      nodetitle := pisp.Product_MP().Name();
      nodelabel := pisp.StockingPoint_MP().Name()
      iconimage := ifexpr( pisp.Product_MP().IconName() <> '', pisp.Product_MP().IconName(), 'PRODUCT2' );
    
    }           
    else if( object.istype( shadow[SCVRoutingStepNode] ) )
    {
      routingStep := select( object.astype( shadow[SCVRoutingStepNode] ), OperationInNode.Operation.RoutingStep, rs, true );
      nodelabel := routingStep.Name();
      iconimage := ifexpr( routingStep.Operation( relsize ) > 1, 'SIZES', 'SHAPE_SQUARE_BLUE' );
    }
    else if( object.istype( shadow[SCVLaneNode] ) )
    {
      lane := object.astype( shadow[SCVLaneNode] ).Lane();
      nodelabel := lane.Name();
      iconimage := 'DELIVERY_AMBER';
    }
    else if( object.istype( shadow[SCVISNode] ) )
    {
      nodelabel := object.Name();
      iconimage := 'HAND_TRUCK_BOX';
    }
    else if( object.istype( shadow[SCVSDNode] ) )
    {
      node := object.astype( shadow[SCVSDNode] );
      nodelabel := object.Name();
      iconimage := ifexpr( node.ProductInStockingPointInPeriod().GetAreAllAssociatedSDIPsFulfilled(), 'DOCUMENT', 'DOCUMENT_DIRTY' );
    }
    
    // Text width, derived from horizontal offset
    textWidth := floor( scvconfig.OffsetX() / 2 );
    textOffsetX := floor( ( nodesize - textWidth ) / 2 );
    textHeight := floor( scvconfig.OffsetY() / 2 );
    
    // Draw node
    if( scvconfig.IsUsingIconName() or not object.istype( shadow[SCVPISPIPNode] ) )
    {
      surface.Image( region.Left(), region.Top(), nodesize, nodesize, iconimage )
    }
    else
    {
      node := object.astype( shadow[SCVPISPIPNode] );
      penWidth := 2;
      
      if( node.ProductInStockingPointInPeriod().istype( ProductInStockingPointInPeriodPlanning )
          and not node.ProductInStockingPointInPeriod().astype( ProductInStockingPointInPeriodPlanning ).IsValidPlannedBalance() ) // violation, no color with red border
      {
        // Draw planning violation indicator
        surface.Pen().Color( ColorScheme.SCVNodeViolation() );    
        
        textformat := TextFormat::Construct( TextFormat::AlignCentered() ); 
        surface.TextColor( ColorScheme.SCVNodeViolation() );                                                                     
        surface.TextZoom( region.Left(), region.Top(), nodesize, nodesize, '!', textformat );  
      }
      else if( object.IsRoot() ) // root color, with border
      {
        surface.Pen().Color( Color::Black() )
        surface.Brush().Color( ColorScheme.SCVRootNode() ) 
      } 
      else // normal node, node color, no border
      {
        penWidth := 0;
        surface.Brush().Color( ColorScheme.SCVNode() );  
      }
      
      surface.Pen().Width( penWidth );
      circle := Shape::Circle( region.Left(), region.Top(), nodesize );
      surface.Fill( circle );
      surface.Draw( circle );
    }
    
    // Update pen parameters
    surface.Font().Name( scvconfig.FontName() )
                  .Size(scvconfig.FontSize() );
    surface.TextColor( Color::Black() );
    
    // Draw text
    if( object.IsRoot() )
    {
      surface.Font().Bold( true );
     
      // Draw period below the root node
      periodStart := scvconfig.Period_MP().StartDate();
      periodString := periodStart.Format( 'D-MM-YOnMax(-)OnMin(-)' );
      
      nodelabel := nodelabel + String::NewLine() + periodString;
    }
    
    // For node title, we define a region above the top of the node
    // then align it bottom, so that the text sticks to the top of the node
    // Draw node title
    surface.TextZoom( region.Left() + textOffsetX, // X
                      region.Top() - textHeight,   // Y
                      textWidth,                   // Width
                      textHeight,                  // Height
                      nodetitle,                   // Text
                      textformat );                // Text format
    
    // For text label, we make the draw region starts at the bottom of the node then align it top, so that
    // it sticks to the bottom of the node                      
    textformat := TextFormat::Construct( TextFormat::AlignTop(), TextFormat::AlignCenter() ); 
    // Draw node label
    surface.TextZoom( region.Left() + textOffsetX,
                      region.Bottom(),             
                      textWidth,                   
                      textHeight,                  
                      nodelabel,
                      textformat );
    
    // Draw indication for stream limit hit
    isUpstreamLimitHit := object.IsUpstream() and object.IsDepthLimitMet();
    isDownstreamLimitHit := not object.IsUpstream() and object.IsDepthLimitMet();
    
    // Special handling for root
    if( object.IsRoot() )
    {
      node := object.astype( shadow[SCVPISPIPNode] );
      isUpstreamLimitHit := scvconfig.UpstreamDepthLimit() = 0 
                            and ( ( FormSupplyChainVisualization.GetInputOutputs( node.ProductInStockingPointInPeriod(), true /*isupstream*/ ).Size() > 0 )
                                    or node.ProductInStockingPointInPeriod().InventorySupplyQuantity() > 0 );
      isDownstreamLimitHit := scvconfig.DownstreamDepthLimit() = 0 
                              and ( ( FormSupplyChainVisualization.GetInputOutputs( node.ProductInStockingPointInPeriod(), false /*isupstream*/ ).Size() > 0 )
                                      or node.ProductInStockingPointInPeriod().SalesDemandInPeriodBase( relsize ) > 0 );                                                                        
    }
    
    textformat := TextFormat::Construct( TextFormat::AlignCentered() );
    
    if( isUpstreamLimitHit )
    {
      surface.Font().Bold( true );
      surface.TextColor( ColorScheme.SCVEdge() );
            
      surface.TextZoom( region.Left() + 2 * -nodesize,
                        region.Top(),
                        nodesize,
                        nodesize,
                        '...',
                        textformat );
    }
    
    if( isDownstreamLimitHit )
    {
      surface.Font().Bold( true );
      surface.TextColor( ColorScheme.SCVEdge() );
      
      surface.TextZoom( region.Left() + 2 * nodesize,
                        region.Top(),
                        nodesize,
                        nodesize,
                        '...',
                        textformat );
    }
  *]
  CanBindMultiple: false
  DefinitionID: 'Responsedef_CustomDrawDataLayer_OnDrawObject'
}