plugins/svgui/svgui.py
author lbessard
Tue, 04 Sep 2007 17:16:42 +0200
changeset 19 73257cea38bd
parent 13 f1f0edbeb313
child 20 d3cb5020997b
permissions -rw-r--r--
Adding Plugin params visualization with basic controls
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
     1
import os
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
     2
from DEFControler import DEFControler
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
     3
from defeditor import EditorFrame
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     4
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
     5
class _EditorFramePlug(EditorFrame):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
     6
    def OnClose(self, event):
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
     7
        self.OnPlugClose()
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
     8
        event.Skip()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
     9
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    10
class _DEFControlerPlug(DEFControler):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    11
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    12
    ViewClass = _EditorFramePlug
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    13
    
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    14
    def __init__(self, buspath):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    15
        filepath = os.path.join(buspath, "gui.def")
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    16
        if os.path.isfile(filepath):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    17
            self.OpenXMLFile(filepath)
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    18
        else:
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    19
            self.CreateRootElement()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    20
            self.SetFilePath(filepath)
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    21
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    22
    def ReqSave(self):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    23
        self.SaveXMLFile()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    24
        return True
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    25
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    26
    def Generate_C(self, dirpath, locations):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    27
        self.GenerateProgram(filepath)
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    28
        return {"headers":["program.h"],"sources":["program.cpp"]}
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    29
    
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    30
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    31
    "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    32
    "STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"}
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    33
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    34
class RootClass:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    35
    
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    36
    ChildsType = _DEFControlerPlug
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    37
    
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    38
    def BlockTypesFactory(self):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    39
        def generate_svgui_block(generator, block, body, link):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    40
            controller = generator.GetController()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    41
            name = block.getInstanceName()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    42
            type = block.getTypeName()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    43
            block_infos = GetBlockType(type)
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    44
            bus_id, name = [word for word in name.split("_") if word != ""]
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    45
            block_id = self.PlugChilds[bus_id].GetElementIdFromName(name)
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    46
            if block_id == None:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    47
                raise ValueError, "No corresponding block found"
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    48
            if not generator.ComputedBlocks.get(name, False):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    49
                for num, variable in enumerate(block.inputVariables.getVariable()):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    50
                    connections = variable.connectionPointIn.getConnections()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    51
                    if connections and len(connections) == 1:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    52
                        parameter = "__I%s%d_%d_%d"%(TYPECONVERSION[block_infos["inputs"][num][1]], bus_id, block_id, num)
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    53
                        value = generator.ComputeFBDExpression(body, connections[0])
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    54
                        generator.Program += ("  %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value)))
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    55
                generator.ComputedBlocks[name] = True
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    56
            if link:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    57
                connectionPoint = link.getPosition()[-1]
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    58
                for num, variable in enumerate(block.outputVariables.getVariable()):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    59
                    blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    60
                    if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY():
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    61
                        return "__Q%s%d_%d_%d"%(TYPECONVERSION[block_infos["outputs"][num][1]], bus_id, block_id, num)
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    62
                raise ValueError, "No output variable found"
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    63
            else:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    64
                return None
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    65
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    66
        return [{"name" : "SVGUI function blocks", "list" :
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    67
           [{"name" : "Container", "type" : "functionBlock", "extensible" : False, 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    68
             "inputs" : [("X","FLOAT","none"),("SetX","BOOL","none"),("Y","FLOAT","none"),("SetY","BOOL","none"),("Angle","FLOAT","none"),("SetAngle","BOOL","none")], 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    69
             "outputs" : [("X","FLOAT","none"),("X Changed","BOOL","none"),("Y","FLOAT","none"),("Y Changed","BOOL","none"),("Angle","FLOAT","none"),("Angle Changed","BOOL","none")],
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    70
             "comment" : "SVGUI Container", "generate": generate_svgui_block},
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    71
            {"name" : "Button", "type" : "functionBlock", "extensible" : False, 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    72
             "inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")], 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    73
             "outputs" : [("Visible","BOOL","none"),("State","BOOL","none")],
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    74
             "comment" : "SVGUI Button", "generate": generate_svgui_block},
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    75
            {"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False, 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    76
             "inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")], 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    77
             "outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")],
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    78
             "comment" : "SVGUI Text Control", "generate": generate_svgui_block},
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    79
            {"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False, 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    80
             "inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")], 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    81
             "outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")],
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    82
             "comment" : "SVGUI ScrollBar", "generate": generate_svgui_block},
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    83
            {"name" : "NoteBook", "type" : "functionBlock", "extensible" : False, 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    84
             "inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")], 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    85
             "outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")],
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    86
             "comment" : "SVGUI Notebook", "generate": generate_svgui_block},
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    87
            {"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False, 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    88
             "inputs" : [("Angle","FLOAT","none"),("Set Angle","BOOL","none")], 
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    89
             "outputs" : [("Angle","FLOAT","none"),("Angle changed","BOOL","none")],
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    90
             "comment" : "SVGUI Rotating Control", "generate": generate_svgui_block}
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    91
           ]}]
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    92
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    93
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    94
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    95
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    96
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    97
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    98
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    99
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   100