Quintiq file version 2.0
#parent: CustomDrawRC/CustomDrawDataLayerOp
Response OnDrawObject (
  Operation object
) id:Response_CustomDrawRC_CustomDrawDataLayerOp_OnDrawObject
{
  #keys: '[139394.0.1282162832]'
  CanBindMultiple: false
  DefinitionID: 'Responsedef_WebCustomDrawDataLayer_OnDrawObject'
  QuillAction
  {
    Body:
    [*
      // Draw operation
      imagesize := ifexpr( object.Unit().IconName() <> '',
                           minvalue( region.BoundingRect().Height(), region.BoundingRect().Width() ), 0 );
      
      //Initialize borders
      surface.Pen().Style( PenSpecification::StyleSolid() );
      surface.Pen().Width( 1 )
      surface.Pen().Color( ColorScheme.RoutingConfigurator_RoutingOutline() );  
      
      //Initialize filled colors
      //It is safe to use color scheme as the routing config is not user / scenario specific
      colorstart := ColorScheme.RoutingConfigurator_OperationFromColor();
      colorend := ColorScheme.RoutingConfigurator_OperationToColor();
      
      // Set color to black if operation is being disabled
      if( not object.IsEnabled() )
      {
        colorstart := ColorScheme.RoutingConfigurator_Disabled();
        colorend := ColorScheme.RoutingConfigurator_Disabled();
      }
      
      surface.Brush().LinearGradient( region.BoundingRect(), colorstart, colorend, 0.0 );
      surface.Fill( region.Shape() );
      
      surface.Image( region.BoundingRect().Left(), region.BoundingRect().Top(), imagesize, imagesize, object.Unit().IconName()  + '(32)'  );
      surface.Rect( region.BoundingRect().Left(), region.BoundingRect().Top(), 
                    region.BoundingRect().Width(), region.BoundingRect().Height(), ColorScheme.RoutingConfigurator_RoutingOutline() );                                
      
      
      //Draw text
      rcv := MacroPlan.RoutingConfiguratorView();
      surface.Font().Name( rcv.FontName() );
      surface.Font().Size( rcv.FontSize() );
      surface.TextColor( Color::Black() );
      
      textformat := TextFormat::Construct( TextFormat::AlignLeft(), TextFormat::AlignMiddle() ); //doesnt work
      // Add pen width to push the text rightward more to avoid clipping with the border
      surface.TextZoom( imagesize + surface.Pen().Width(), 0, region.BoundingRect().Width() - imagesize , region.BoundingRect().Height(), text, textformat ); // Add offset for images
      
      //draw input output drop here!
      //guide to be drawn below the operation
      routing := guard( object.RoutingStep().Routing(), null( Routing ) );                                           
      
      if( not isnull( routing ) and not routing.HasInputOrOutput() )
      {
        surface.Pen().Style( PenSpecification::StyleDotted() );
        surface.Pen().Width( rcv.EdgeThickness() )
        surface.Pen().Color( ColorScheme.RoutingConfigurator_DropHereHelp() );  
        surface.Brush().Color( ColorScheme.RoutingConfigurator_DropHereHelp() ); // to paint the solid arrowhead
        
        surface.TextColor( ColorScheme.RoutingConfigurator_DropHereHelp() );
      
        lblx := region.BoundingRect().Left();
        lbly := region.BoundingRect().Height() + 20;
        
        midh := [Number]( region.BoundingRect().Height() / 2 );
        midw := [Number]( region.BoundingRect().Width() / 2 );
      
        line := GraphicalLine::LineTo( midw, lbly, midw, midh );
        line.ArrowToEnd( true ).ArrowPos( GraphicalLine::ArrowPosEnd() );
        surface.Draw( line );
        
        textformat.WrapWords();
        surface.TextZoom( lblx, lbly, region.BoundingRect().Width(), region.BoundingRect().Height(),
                          Translations::MP_Routing_DropHereIO(), textformat ); 
      }
    *]
    GroupServerCalls: false
  }
}
