Menu

CustomUO color

Auke Nauta
2021-08-14
2021-08-16
  • Auke Nauta

    Auke Nauta - 2021-08-14

    Hi,

    I have created a CustomUO (IronPython script) which performs a gas membrane simulation (one feed, two output treams).

    Depending on the input parameters, the actual model can fail.
    In this case I return 'dummy' values in the output streams.

    I would like to be able to set the color of the CustomUO object to my preference (red for instance) when my model did not run correctly.
    The user of the flowsheet can then immediately see that there was an (internal) error.

    I played around with SkiaSharp SKColor, but I can't get it to function.
    (Expected SKColor, got SKColor...)

    Can anyone help?

    Thanks and greetings,
    Auke Nauta

     
  • Auke Nauta

    Auke Nauta - 2021-08-16

    Hi,

    I (sort of!) figured it out:

    While I could not set the 'LineColor' property usinga new SKColor vriable (why?), I managed to change the existing 'LineColor' using the following code:

    Me.GraphicObject.OverrideColors = solver_OK == 0; # override the object color when the solver fails
    Me.GraphicObject.LineColor=Me.GraphicObject.LineColor.WithRed(255) # set error linecolor
    Me.GraphicObject.UpdateStatus() # and update the object in the flowsheet

    This sets the color of the CutomUO object to yellow in case of an internal solver calculation error...

    Greetings,
    Auke Nauta

     
  • Daniel Medeiros

    Daniel Medeiros - 2021-08-16

    You can override the entire draw routine like this:

    import clr
    clr.AddReference("SkiaSharp")
    from SkiaSharp import SKPaint, SKColor, SKColors, SKCanvas, SKPath, SKPathEffect, SKRect
    
    ms1 = Flowsheet.GetFlowsheetSimulationObject('MSTR-01')
    
    ms1g = ms1.GraphicObject
    
    def drawStream(gobj, canvas, color):
        gobj.CreateConnectors(0, 0)
        gobj.UpdateStatus()
    
        myBGPen = SKPaint()
    
        myBGPen.Color = color
        myBGPen.IsStroke = False
        myBGPen.IsAntialias = True
    
        rect = SKRect(gobj.X, gobj.Y, gobj.X + gobj.Width, gobj.Y + gobj.Height)
    
        canvas.DrawRect(rect, myBGPen)
    
        myPen = SKPaint()
    
        myPen.Color = SKColors.Black
        myPen.StrokeWidth = 0.1
        myPen.IsStroke = True
        myPen.IsAntialias = True
        myPen.PathEffect = SKPathEffect.CreateCorner(0.3)
    
        gp = SKPath()
    
        gp.MoveTo((gobj.X), (gobj.Y + 0.35 * gobj.Height))
        gp.LineTo((gobj.X + 0.75 * gobj.Width), (gobj.Y + 0.35 * gobj.Height))
        gp.LineTo((gobj.X + 0.75 * gobj.Width), (gobj.Y + 0.25 * gobj.Height))
        gp.LineTo((gobj.X + gobj.Width), (gobj.Y + 0.5 * gobj.Height))
        gp.LineTo((gobj.X + 0.75 * gobj.Width), (gobj.Y + 0.75 * gobj.Height))
        gp.LineTo((gobj.X + 0.75 * gobj.Width), (gobj.Y + 0.65 * gobj.Height))
        gp.LineTo((gobj.X), (gobj.Y + 0.65 * gobj.Height))
        gp.LineTo((gobj.X), (gobj.Y + 0.35 * gobj.Height))
    
        gp.Close()
    
        canvas.DrawPath(gp, myPen)
    
    ms1g.DrawOverride = drawStream1
    
     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.