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
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
181
182
183
184
Quintiq file version 2.0
#parent: PanelSCV/CustomDrawDataLayerSCVNode_549
Response OnDrawObject (
  shadow[SCVNode] object
) id:Response_PanelSCV_CustomDrawDataLayerSCVNode_OnDrawObject
{
  #keys: '[134266.2.4979938]'
  CanBindMultiple: false
  DefinitionID: 'Responsedef_WebCustomDrawDataLayer_OnDrawObject'
  QuillAction
  {
    Body:
    [*
      // Draw SCVNode
      
      // Drawing parameters, node label, node title, label width, title width
      scvconfig := MacroPlan.SCVConfiguration();
      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.BoundingRect().Left(), region.BoundingRect().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.SupplyChainVisualization_NodeViolation() );    
          
          textformat_violation := TextFormat::Construct( TextFormat::AlignCentered() ); 
          surface.TextColor( ColorScheme.SupplyChainVisualization_NodeViolation() );                                                                     
          surface.TextZoom( region.BoundingRect().Left(), region.BoundingRect().Top(), nodesize, nodesize, '!', textformat_violation );
        }
        else if( object.IsRoot() ) // root color, with border
        {
          surface.Pen().Color( Color::Black() )
          surface.Brush().Color( ColorScheme.SupplyChainVisualization_RootNode() ) 
        } 
        else // normal node, node color, no border
        {
          penWidth := 0;
          surface.Brush().Color( ColorScheme.SupplyChainVisualization_Node() );  
        }
        
        surface.Pen().Width( penWidth );
        circle := Shape::Circle( region.BoundingRect().Left(), region.BoundingRect().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 := object.astype( shadow[SCVPISPIPNode] ).ProductInStockingPointInPeriod().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.BoundingRect().Left() + textOffsetX, // X
                        region.BoundingRect().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(), TextFormat::WrapWords() ); 
      // Draw node label
      surface.TextZoom( region.BoundingRect().Left() + textOffsetX,
                        region.BoundingRect().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.SupplyChainVisualization_Edge() );
              
        surface.TextZoom( region.BoundingRect().Left() + 2 * -nodesize,
                          region.BoundingRect().Top(),
                          nodesize,
                          nodesize,
                          '...',
                          textformat );
      }
      
      if( isDownstreamLimitHit )
      {
        surface.Font().Bold( true );
        surface.TextColor( ColorScheme.SupplyChainVisualization_Edge() );
        
        surface.TextZoom( region.BoundingRect().Left() + 2 * nodesize,
                          region.BoundingRect().Top(),
                          nodesize,
                          nodesize,
                          '...',
                          textformat );
      }
    *]
    GroupServerCalls: false
  }
}