陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
Quintiq file version 2.0
#parent: #root
Method DrawNode (
  UnitPeriod element,
  internal[WebDrawNodeInfo] drawinfo
) id:Method_BaseFormCapacityPlanning_DrawNode
{
  #keys: '[145730.1.1000510444]'
  Body:
  [*
    // Determine colors for unit period gantt chart nodes
    macroplan := element.MacroPlan();
    nr := macroplan.GlobalParameters_MP().NumberOfDecimals();
    below := element.BottleneckThreshold();
    above := element.OverloadThreshold();
    textcolour := ColorScheme.CapacityGanttChart_DefaultText();
    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.CapacityGanttChart_Error(), ColorScheme.CapacityGanttChart_Irrelevant() );
        drawinfo.AddCompartment( color , element.FreeCapacityRatio() );
      }
      //infinte and no child, show purple
      else if ( not element.Unit().IsPotentialBottleneck() )
      {
        color := ifexpr( element.HasConstraintViolations(), ColorScheme.CapacityGanttChart_Error(), ColorScheme.CapacityGanttChart_Infinite() );
        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.CapacityGanttChart_Error(), ColorScheme.CapacityGanttChart_Infinite() );
        drawinfo.AddCompartment( color, element.UsedCapacityRatio() );
        drawinfo.AddCompartment( ColorScheme.CapacityGanttChart_Free(), element.FreeCapacityRatio() );
      }
      //units which are part of an aggregation
      else if ( element.Unit().IsForCapacityAggregation() )
      {
        color := ifexpr( element.HasConstraintViolations(), ColorScheme.CapacityGanttChart_Error(), ColorScheme.CapacityGanttChart_Aggregation() );
        drawinfo.AddCompartment( color, element.UsedCapacityRatio() );
        drawinfo.AddCompartment( ColorScheme.CapacityGanttChart_Changeover(), changeoverratio );
        drawinfo.AddCompartment( ColorScheme.CapacityGanttChart_Free(), element.FreeCapacityRatio() );
        textcolour :=  ColorScheme.CapacityGanttChart_TextGood();
      }
      // IsPlannedInfinite, show purple
      else if ( element.IsPlannedInfinite() )
      {
        color := ifexpr( element.HasConstraintViolations(), ColorScheme.CapacityGanttChart_Error(), ColorScheme.CapacityGanttChart_Infinite() );
        drawinfo.AddCompartment( color, element.Duration() );
        textcolour := ColorScheme.CapacityGanttChart_Infinite();
      }
      else
      {
        displayutilizationpercentage := element.DisplayUtilizationPercentageWithMaxLoadRatio();
        loadpercentage := displayutilizationpercentage.Round( nr );
    
        color :=  ColorScheme.CapacityGanttChart_Good();
        textcolour := ColorScheme.CapacityGanttChart_TextGood();
        
        if ( element.HasConstraintViolations() )
        {
          color := ColorScheme.CapacityGanttChart_Error();
        }
        
        else if ( below > 0 and above > 0 )
        {
          if ( loadpercentage > below and loadpercentage <= above and element.Period_MP().IsWithinBottleneckWindow() )
          {
            color := ColorScheme.CapacityGanttChart_WarningMid();
            textcolour := ColorScheme.CapacityGanttChart_WarningText();
          }
          else if ( loadpercentage > above )
          {
            color := ColorScheme.CapacityGanttChart_WarningHigh();
            textcolour := ColorScheme.CapacityGanttChart_WarningText();
          }
        }
    
        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.CapacityGanttChart_Changeover(), changeoverratio );
        drawinfo.AddCompartment( ColorScheme.CapacityGanttChart_Free(), freeCapacityRatio );
      }
      // in case no available duration
      color := ifexpr( not element.HasOpenUnit(), ColorScheme.CapacityGanttChart_Error(), ColorScheme.CapacityGanttChart_Irrelevant() );
      drawinfo.AddCompartment( color, element.TotalUnavailableCapacityRatio() );
    }
    
    if ( element.HasConstraintViolations() )
    {
      textcolour := ColorScheme.CapacityGanttChart_WarningText();
    }
    drawinfo.TextColor( textcolour );
  *]
  Declarative: true
}