hongji.li
2023-11-03 aefafd2142478d4fb07d6b8b45c3047e247389e0
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
Quintiq file version 2.0
#parent: #root
Method DrawNode (
  internal[DrawNodeInfo] drawinfo,
  UnitPeriod element
) id:Method_FormCapacityPlanning_DrawNode
{
  #keys: '[145730.1.1156292293]'
  Body:
  [*
    // Determine colors for gantt chart nodes
    nr := MacroPlan.GlobalParameters_MP().NumberOfDecimals();
    below := element.BottleneckThreshold();
    above := element.OverloadThreshold();
    
    changeoverratio := Duration::Zero();
    if( element.istype( UnitPeriodTimeBase ) )
    {
      changeoverratio := element.astype( UnitPeriodTimeBase ).ChangeoverDurationRatio();
    }
    if( element.Duration() > Duration::Zero() )
    {
      // Quantity aggregated unit without child, show as irrelevant
      if( element.Unit().CapacityType() = GlobalParameters_MP::GetCapacityTypeQuantityAggregation()
          and element.ChildOfUnitDimension( relsize ) = 0 )
      {
        color := ifexpr( element.HasConstraintViolations(), ColorScheme.GanttChart_Error(),ColorScheme.GanttChart_Irrelevant() );
        drawinfo.AddCompartment( color, element.FreeCapacityRatio() );
      }
      //infinte and no child, show purple
      else if ( not element.Unit().IsPotentialBottleneck() )
      {
        color := ifexpr( element.HasConstraintViolations(), ColorScheme.GanttChart_Error(), ColorScheme.GanttChart_Neutral1() );
        drawinfo.AddCompartment( color, element.Duration() );
      }
      //infinite but with child, show constraint violation if its children is overloaded
      else if ( element.Unit().HasCapacityTypeInfinite() and element.Unit().IsPotentialBottleneck() )
      {
        color := ifexpr( element.HasConstraintViolations(),  ColorScheme.GanttChart_Error(), ColorScheme.GanttChart_Neutral1() );
        drawinfo.AddCompartment( color, element.UsedCapacityRatio() );
        drawinfo.AddCompartment( ColorScheme.GanttChart_Free(), element.FreeCapacityRatio() );
      }
      //units which are part of an aggregation
      else if ( element.Unit().IsForCapacityAggregation() )
      {
        color := ifexpr( element.HasConstraintViolations(), ColorScheme.GanttChart_Error(), ColorScheme.GanttChart_Custom2() ); 
        drawinfo.AddCompartment( color, element.UsedCapacityRatio() );
        drawinfo.AddCompartment( ColorScheme.GanttChart_Changeover(), changeoverratio );
        drawinfo.AddCompartment( ColorScheme.GanttChart_Free(), element.FreeCapacityRatio() );
        //drawinfo.AddCompartment( ColorScheme.GanttChart_Irrelevant(), element.TotalUnavailableCapacityRatio() );
      }
      // IsPlannedInfinite, show purple
      else if ( element.IsPlannedInfinite() )
      {
        color := ifexpr( element.HasConstraintViolations(), ColorScheme.GanttChart_Error(), ColorScheme.GanttChart_Neutral1() ); 
        drawinfo.AddCompartment( color, element.Duration() );
      }
      else
      {
      
        displayutilizationpercentage := element.DisplayUtilizationPercentageWithMaxLoadRatio();
        loadpercentage := displayutilizationpercentage.Round( nr );
    
        color :=  ColorScheme.GanttChart_Good();
        if ( element.HasConstraintViolations() )
        {
          color := ColorScheme.GanttChart_Error();
        }
        else if ( below > 0 and above > 0 )
        {
          if ( loadpercentage > below and loadpercentage <= above and element.Period_MP().IsWithinBottleneckWindow() )
          {
            color := ColorScheme.GanttChart_Warning2();
          }
          else if ( loadpercentage > above )
          {
            color := ColorScheme.GanttChart_Warning1();
          }
        }
        
        usedCapacityRatio := ifexpr( element.Unit().CapacityType() = GlobalParameters_MP::GetCapacityTypeTransportQuantity()
                                    ,element.astype( UnitPeriodTransportQuantity).DisplayUsedCapacityRatio()
                                    ,element.UsedCapacityRatio() );
           
        freeCapacityRatio := ifexpr( element.Unit().CapacityType() = GlobalParameters_MP::GetCapacityTypeTransportQuantity()
                                    ,element.astype( UnitPeriodTransportQuantity).DisplayFreeCapacityRatio()
                                    ,element.FreeCapacityRatio() );
    
        drawinfo.AddCompartment( color, usedCapacityRatio );
        drawinfo.AddCompartment( ColorScheme.GanttChart_Changeover(), changeoverratio );
        drawinfo.AddCompartment( ColorScheme.GanttChart_Free(), freeCapacityRatio );
      }
    
      color := ifexpr( not element.HasOpenUnit(), ColorScheme.GanttChart_Error(), ColorScheme.GanttChart_Irrelevant() );
      drawinfo.AddCompartment( color, element.TotalUnavailableCapacityRatio() );
    }
    
    if ( drawinfo.BackgroundColor().IsDark() )
    {
      drawinfo.TextColor( Color::White() );
    }
  *]
  Declarative: true
}