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