plcopen/structures.py
changeset 391 07447ee3538e
parent 373 db5f282946b0
child 404 d5a5eaea7844
--- a/plcopen/structures.py	Fri Jul 24 12:49:57 2009 +0200
+++ b/plcopen/structures.py	Fri Jul 24 17:12:59 2009 +0200
@@ -33,6 +33,8 @@
                      "D" : ["DINT", "UDINT", "REAL", "DWORD"],
                      "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} 
 
+_ = lambda x:x
+
 # Helper for emulate join on element list
 def JoinList(separator, mylist):
     if len(mylist) > 0 :
@@ -92,7 +94,7 @@
                 generator.Program += JoinList([(", ", ())], vars)
                 generator.Program += [(");\n", ())]
             else:
-                generator.Warnings.append("\"%s\" function cancelled in \"%s\" POU: No input connected"%(type, generator.TagName.split("::")[-1]))
+                generator.Warnings.append(_("\"%s\" function cancelled in \"%s\" POU: No input connected")%(type, generator.TagName.split("::")[-1]))
         if link:
             connectionPoint = link.getposition()[-1]
         else:
@@ -134,7 +136,7 @@
                 output_info = (generator.TagName, "block", block.getlocalId(), "output", i)
                 return generator.ExtractModifier(variable, [("%s.%s"%(name, variable.getformalParameter()), output_info)], output_info)
     if link is not None:
-        raise ValueError, "No output variable found"
+        raise ValueError, _("No output variable found")
 
 def initialise_block(type, name, block = None):
     return [(type, name, None, None)]
@@ -160,98 +162,98 @@
     - The default modifier which can be "none", "negated", "rising" or "falling"
 """
 
-BlockTypes = [{"name" : "Standard function blocks", "list":
+BlockTypes = [{"name" : _("Standard function blocks"), "list":
                [{"name" : "SR", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], 
                     "outputs" : [("Q1","BOOL","none")],
-                    "comment" : "SR bistable\nThe SR bistable is a latch where the Set dominates.",
+                    "comment" : _("SR bistable\nThe SR bistable is a latch where the Set dominates."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "RS", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("S","BOOL","none"),("R1","BOOL","none")], 
                     "outputs" : [("Q1","BOOL","none")],
-                    "comment" : "RS bistable\nThe RS bistable is a latch where the Reset dominates.",
+                    "comment" : _("RS bistable\nThe RS bistable is a latch where the Reset dominates."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "SEMA", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], 
                     "outputs" : [("BUSY","BOOL","none")],
-                    "comment" : "Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources.",
+                    "comment" : _("Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("CLK","BOOL","none")], 
                     "outputs" : [("Q","BOOL","none")],
-                    "comment" : "Rising edge detector\nThe output produces a single pulse when a rising edge is detected.",
+                    "comment" : _("Rising edge detector\nThe output produces a single pulse when a rising edge is detected."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("CLK","BOOL","none")], 
                     "outputs" : [("Q","BOOL","none")],
-                    "comment" : "Falling edge detector\nThe output produces a single pulse when a falling edge is detected.",
+                    "comment" : _("Falling edge detector\nThe output produces a single pulse when a falling edge is detected."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "CTU", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], 
                     "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
-                    "comment" : "Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value.",
+                    "comment" : _("Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "CTD", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], 
                     "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
-                    "comment" : "Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value.",
+                    "comment" : _("Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "CTUD", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], 
                     "outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")],
-                    "comment" : "Up-down counter\nThe up-down counter has two inputs CU and CD. It can be used to both count up on one input ans down on the other.",
+                    "comment" : _("Up-down counter\nThe up-down counter has two inputs CU and CD. It can be used to both count up on one input and down on the other."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "TP", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
-                    "comment" : "Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration.",
+                    "comment" : _("Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "TON", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
-                    "comment" : "On-delay timer\nThe on-delay timer can be used to delay setting an output true, for fixed period after an input becomes true.",
+                    "comment" : _("On-delay timer\nThe on-delay timer can be used to delay setting an output true, for fixed period after an input becomes true."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "TOF", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
-                    "comment" : "Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false.",
+                    "comment" : _("Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 ]},
-              {"name" : "Additionnal function blocks", "list":
+              {"name" : _("Additionnal function blocks"), "list":
 ##                {"name" : "RTC", "type" : "functionBlock", "extensible" : False, 
 ##                    "inputs" : [("EN","BOOL","none"),("PDT","DATE_AND_TIME","none")], 
 ##                    "outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")],
-##                    "comment" : "Real time clock\nThe real time clock has many uses including time stamping, setting dates and times of day in batch reports, in alarm messages and so on.",
+##                    "comment" : _("Real time clock\nThe real time clock has many uses including time stamping, setting dates and times of day in batch reports, in alarm messages and so on."),
 ##                    "generate" : generate_block, "initialise" : initialise_block},
                [{"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], 
                     "outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")],
-                    "comment" : "Integral\nThe integral function block integrates the value of input XIN over time.",
+                    "comment" : _("Integral\nThe integral function block integrates the value of input XIN over time."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], 
                     "outputs" : [("XOUT","REAL","none")],
-                    "comment" : "Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN.",
+                    "comment" : _("Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "PID", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("AUTO","BOOL","none"),("PV","REAL","none"),("SP","REAL","none"),("X0","REAL","none"),("KP","REAL","none"),("TR","REAL","none"),("TD","REAL","none"),("CYCLE","TIME","none")], 
                     "outputs" : [("XOUT","REAL","none")],
-                    "comment" : "PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control.",
+                    "comment" : _("PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "RAMP", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("RUN","BOOL","none"),("X0","REAL","none"),("X1","REAL","none"),("TR","TIME","none"),("CYCLE","TIME","none"),("HOLDBACK","BOOL","none"),("ERROR","REAL","none"),("PV","REAL","none")], 
                     "outputs" : [("RAMP","BOOL","none"),("XOUT","REAL","none")],
-                    "comment" : "Ramp\nThe RAMP function block is modelled on example given in the standard but with the addition of a 'Holdback' feature.",
+                    "comment" : _("Ramp\nThe RAMP function block is modelled on example given in the standard but with the addition of a 'Holdback' feature."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 {"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, 
                     "inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], 
                     "outputs" : [("Q","BOOL","none")],
-                    "comment" : "Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2.",
+                    "comment" : _("Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2."),
                     "generate" : generate_block, "initialise" : initialise_block},
 ##                {"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, 
 ##                    "inputs" : [("PV1","REAL","none"),("PV2","REAL","none"),("RATIO","REAL","none"),("TIMON","TIME","none"),("TIMOFF","TIME","none"),("TOLERANCE","BOOL","none"),("RESET","BOOL","none"),("CYCLE","TIME","none")], 
 ##                    "outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")],
-##                    "comment" : "Ratio monitor\nThe ratio_monitor function block checks that one process value PV1 is always a given ratio (defined by input RATIO) of a second process value PV2.",
+##                    "comment" : _("Ratio monitor\nThe ratio_monitor function block checks that one process value PV1 is always a given ratio (defined by input RATIO) of a second process value PV2."),
 ##                    "generate" : generate_block, "initialise" : initialise_block}
                 ]},
              ]
@@ -503,7 +505,12 @@
         if fields[1]:
             # If function section name given
             if fields[0]:
-                Current_section = {"name" : fields[0], "list" : []}
+                words = fields[0].split('"')
+                if len(words) > 1:
+                    section_name = words[1]
+                else:
+                    section_name = fields[0]
+                Current_section = {"name" : section_name, "list" : []}
                 Standard_Functions_Decl.append(Current_section)
                 Function_decl_list = []
             if Current_section:
@@ -563,7 +570,10 @@
                             # create the copy of decl dict to be appended to section
                             Function_decl_copy = Function_decl.copy()
                             # Have to generate type description in comment with freshly redefined types
-                            Function_decl_copy["comment"] += (
+                            words = Function_decl_copy["comment"].split('"')
+                            if len(words) > 1:
+                                Function_decl_copy["comment"] = words[1]
+                            Function_decl_copy["usage"] = (
                                 "\n (" +
                                 str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in Function_decl["inputs"]]).strip("[]").replace("'",'') +
                                 " ) => (" +