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