Menu

#41 How can we add support for expr-fill-color?

now
open
nobody
None
2022-02-17
2022-02-15
vali dan
No

Hi guys, thanks for this awesome project you created!

We found out that some of the colors are not interpreted by WebVisu.
As we found out, the element "expr-fill-color" is not interpreted.
Here is an XML snippet:

        <element type="simple">
                <simple-shape>rectangle</simple-shape>
                <elem-id>1</elem-id>
                <center>145,70</center>
                <line-width>0</line-width>
                <has-frame-color>true</has-frame-color>
                <has-inside-color>true</has-inside-color>
                <frame-color>0,0,0</frame-color>
                <frame-color-alarm>0,0,0</frame-color-alarm>
                <fill-color>0,255,0</fill-color>
                <fill-color-alarm>255,0,0</fill-color-alarm>
                <expr-fill-color>
                        <expr>
                                <var>.dwFarbe_F1</var>
                        </expr>
                </expr-fill-color>
                <text-align-horz>center</text-align-horz>
                <text-align-vert>center</text-align-vert>
                <font-height>-19</font-height>
                <font-height-point-size>14</font-height-point-size>
                <font-weight>700</font-weight>
                <font-italic>false</font-italic>
                <font-underline>false</font-underline>
                <font-strike-out>false</font-strike-out>
                <font-char-set>0</font-char-set>
                <text-id>5</text-id>
                <font-name>Arial</font-name>
                <font-color>0,0,0</font-color>
                <enable-text-input>false</enable-text-input>
                <text-display>
                        <expr>
                                <var>.rlF1</var>
                        </expr>
                </text-display>
                <text-format><![CDATA[Feuchte:| || || || || |%3.1f| |%%rF]]></text-format>
                <hidden-input>false</hidden-input>
                <rect>10,50,281,91</rect>
        </element>

At the end of the file are the variables:

                <variable name=".dwFarbe_F1">4,418284,4,5</variable>

Therefore we wanted to add this functionality, but it its a unclear how/when the variables are interpreted? And the rgb value needs to be somehow converted.

A few hints would be greatly appreciated.
If we get it working we would create a pull-request to give something back..

Discussion

  • vali dan

    vali dan - 2022-02-15

    I will add some info that we already gathered:

    The parsing most likely needs to be added in codesys.pp.js at line 741.

                        var exprFillColor = [];
                        var expr_fillColor = $myMedia.find('expr-fill-color');
                        if (expr_fillColor.length) {
                            exprFillColor = parseExpression(expr_fillColor);
                            // Read out value from visuVariables?
                            // convert to RGB?
                            // overwrite fill_color
                        }
    
     
  • vali dan

    vali dan - 2022-02-15

    I feel like this case is not supported yet, so we could read the variables from xml and look for the correct one at this place, would this work?

     
  • vali dan

    vali dan - 2022-02-15

    I currently have no running system here, but I guess this should be the way:

                        var exprFillColor = [];
                        var expr_fillColor = $myMedia.find('expr-fill-color');
                        if (expr_fillColor.length) {
                            exprFillColor = parseExpression(expr_fillColor);
                            // get value from visuVariables
                            // name is e.g. ".dwFarbe_F1" - value e.g. "4,418284,4,5"
                            exprFillColorRAW = visuVariables[exprFillColor];                        
                            // convert to RGB
                            exprFillColorRGB = TODOCONVERT(exprFillColorRAW);
                            // overwrite fill_color
                            fill_color = exprFillColorRGB;
                        }
    
     
  • Frank Benkert

    Frank Benkert - 2022-02-16

    Hi vali dan,
    Thank you for your efforts to contribute a solution to the problem you found.
    Unfortunately it is not that easy to implement.
    The parsing is only the first half; the continuous evaluation of the variable and the drawing is the other half.

    First of all: when can such an expression be specified? How can we determine wether we should use the constant "fill-color" or the expression "expr-fill-color"?

    Then we have to pass the expression "expr-fill-color" and probably also "expr-fill-color-alarm" ??? additionally to the register function "registerSimpleShape". This one puts this via "newSimpleShape" into the global array "drawObjects". Of course the two expressions have to be saved there as well.

    And finally the current value of the variables must be determined in "drawAllObjects" by calling "evalExpression".

    This is because the variable can change its value all the time and not only when the shapes are read for the first time.

    Can you provide me with a complete test project? Maybe I can give it a try.

    cu
    Frank

     
  • vali dan

    vali dan - 2022-02-17

    Hi Frank

    Thank you very much for taking your time to answer our question, we really appreciate this.
    We spent some time yesterday and figured out the drawing part of it as well.

    Regarding your question, the expr-*-color - that always reference variables, are used when one adds variable names to this dialog in CoDeSys Element Configuration - Colorvariables:

    We only implemented the "Fill Color" variable for now, as this currently suffices.

    The parsing code used (codesys.pp.js, inserted at line 742), stores "name: " and then the variable name inside the fill_color, when expr-fill-color is present:

                        var expr_fillColor = $myMedia.find("expr-fill-color");
                        if (expr_fillColor.length){
                            var fill_colorE = parseExpression(expr_fillColor)
                            fill_color = "name: " + fill_colorE[0].value;
                        }
    

    For the dynamic updating we added this code in drawing.pp.js at line 1271. The color value must be converted from dword to rgb(red,green,blue). The value e.g. for yellow is 65535.

                if (obj.fillStyle.includes("name")) {
                    var name = obj.fillStyle.substring(10).slice(0, -1);
                    var decimalColor = visuVariables[name].value;
                    var red = (decimalColor & 0xFF) << 16;
                    var green = (decimalColor & 0xFF00);
                    var blue = (decimalColor & 0xFF0000) >> 16;  
                    fillStyle = decimalToColorString(red | green | blue);
                } else {            
                    fillStyle = obj.fillStyle;
                }
    

    Similarly, the code could be extended for the other expr- values.

     

Log in to post a comment.

MongoDB Logo MongoDB