Adding support for forbidding insertion of function block into function
authorlbessard
Wed, 18 Apr 2007 16:39:28 +0200
changeset 13 69075340d6a9
parent 12 58a65b901719
child 14 cd0133ed377b
Adding support for forbidding insertion of function block into function
PLCControler.py
PLCOpenEditor.py
Viewer.py
examples/example.xml
--- a/PLCControler.py	Fri Apr 13 17:54:40 2007 +0200
+++ b/PLCControler.py	Wed Apr 18 16:39:28 2007 +0200
@@ -758,20 +758,32 @@
     # Return Block types checking for recursion
     def GetBlockTypes(self):
         if self.CurrentElementEditing != None:
-            current_name = self.ElementsOpened[self.CurrentElementEditing]
-            words = current_name.split("::")
-            if len(words) == 1:
-                name = current_name
+            if self.Project:
+                current_name = self.ElementsOpened[self.CurrentElementEditing]
+                words = current_name.split("::")
+                if len(words) == 1:
+                    name = current_name
+                else:
+                    name = words[1]
+                type = self.GetPouType(name)
             else:
-                name = words[1]
-            blocktypes = [category for category in BlockTypes[:-1]]
-            blocktypes.append({"name" : "User-defined POUs", "list": []})
+                name = ""
+                type = None
+            if type == "function":
+                blocktypes = []
+                for category in BlockTypes[:-1]:
+                    cat = {"name" : category["name"], "list" : []}
+                    for block in category["list"]:
+                        if block["type"] == "function":
+                            cat["list"].append(block)
+                    if len(cat["list"]) > 0:
+                        blocktypes.append(cat)
+            else:
+                blocktypes = [category for category in BlockTypes[:-1]]
             if self.Project:
-                pou = self.Project.getPou(name)
-                name = pou.getName()
-                type = pou.pouType.getValue()
+                blocktypes.append({"name" : "User-defined POUs", "list": []})
                 for blocktype in BlockTypes[-1]["list"]:
-                    if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] == "functionBlock"):
+                    if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
                         blocktypes[-1]["list"].append(blocktype)
             return blocktypes
         return []
@@ -926,6 +938,17 @@
         self.CurrentElementEditing = index
 
     # Return language in which current pou editing is written
+    def GetCurrentElementEditingType(self):
+        if self.CurrentElementEditing != None:
+            name = self.ElementsOpened[self.CurrentElementEditing]
+            words = name.split("::")
+            if len(words) == 1:
+                return self.GetPouType(name)
+            else:
+                return self.GetPouType(words[1])
+        return None
+
+    # Return language in which current pou editing is written
     def GetCurrentElementEditingBodyType(self):
         if self.CurrentElementEditing != None:
             name = self.ElementsOpened[self.CurrentElementEditing]
--- a/PLCOpenEditor.py	Fri Apr 13 17:54:40 2007 +0200
+++ b/PLCOpenEditor.py	Wed Apr 18 16:39:28 2007 +0200
@@ -1,4 +1,3 @@
-#Boa:Frame:PLCOpenEditor
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
--- a/Viewer.py	Fri Apr 13 17:54:40 2007 +0200
+++ b/Viewer.py	Wed Apr 18 16:39:28 2007 +0200
@@ -494,10 +494,11 @@
 #-------------------------------------------------------------------------------
 
     def PopupBlockMenu(self, connector = None):
+        type = self.Controler.GetCurrentElementEditingType()
         self.ContextualMenu.FindItemByPosition(0).Enable(connector != None)
         self.ContextualMenu.FindItemByPosition(1).Enable(connector != None)
-        self.ContextualMenu.FindItemByPosition(2).Enable(connector != None)
-        self.ContextualMenu.FindItemByPosition(3).Enable(connector != None)
+        self.ContextualMenu.FindItemByPosition(2).Enable(connector != None and type != "function")
+        self.ContextualMenu.FindItemByPosition(3).Enable(connector != None and type != "function")
         self.ContextualMenu.FindItemByPosition(5).Enable(False)
         self.ContextualMenu.FindItemByPosition(6).Enable(False)
         self.ContextualMenu.FindItemByPosition(8).Enable(False)
--- a/examples/example.xml	Fri Apr 13 17:54:40 2007 +0200
+++ b/examples/example.xml	Wed Apr 18 16:39:28 2007 +0200
@@ -23,11 +23,8 @@
   <types>
     <dataTypes/>
     <pous>
-      <pou name="FBDTest" pouType="function">
+      <pou name="FBDTest" pouType="functionBlock">
         <interface>
-          <returnType>
-            <BOOL/>
-          </returnType>
           <inputVars>
             <variable name="IN1">
               <type>
@@ -65,6 +62,13 @@
               </type>
             </variable>
           </inputVars>
+          <outputVars>
+            <variable name="OUT">
+              <type>
+                <BOOL/>
+              </type>
+            </variable>
+          </outputVars>
         </interface>
         <body>
           <FBD>
@@ -91,7 +95,7 @@
                   <position y="198" x="517"/>
                 </connection>
               </connectionPointIn>
-              <expression>FBDTest</expression>
+              <expression>OUT</expression>
             </outVariable>
             <block localId="6" height="84" width="99" typeName="AND">
               <position y="105" x="235"/>
@@ -386,7 +390,7 @@
             </variable>
           </inputVars>
           <outputVars>
-            <variable name="ENO">
+            <variable name="ERROR">
               <type>
                 <BOOL/>
               </type>
@@ -395,24 +399,22 @@
         </interface>
         <body>
           <IL>
-LD   Y1
-SUB  Y2     (* Substract Y2 from Y1 *)
-ST   Temp   (* Store Y1-Y2 in Temp *)
-MUL  Temp   (* Multiply by Temp to square *)
-ADD( X1     (* Defer ADD *)
-SUB  X2     (* Substract X1 from X2 *)
-ST   Temp   (* Store X1-X2 in Temp *)
-MUL  Temp   (* Multiply by Temp to square *)
-)
-CAL  SQRT   (* Call Square root fun *)
-ST   ILTest (* Setup function result *)
-GT   TMax   (* Greater than TMax ? *)
-JMPC ERR    (* Yes, Jump to Error *)
-S    ENO    (* Set ENO *)
-RET         (* Normal return *)
-
-ERR:
-RET         (* Error return, ENO not set *)
+     LD   Y1
+     SUB  Y2     (* Substract Y2 from Y1 *)
+     ST   Temp   (* Store Y1-Y2 in Temp *)
+     MUL  Temp   (* Multiply by Temp to square *)
+     ADD( X1     (* Defer ADD *)
+     SUB  X2     (* Substract X1 from X2 *)
+     ST   Temp   (* Store X1-X2 in Temp *)
+     MUL  Temp   (* Multiply by Temp to square *)
+     )
+     CAL  SQRT   (* Call Square root fun *)
+     ST   ILTest (* Setup function result *)
+     GT   TMax   (* Greater than TMax ? *)
+     JMPC ERR    (* Yes, Jump to Error *)
+     S    ERROR  (* Set ERROR *)
+     RET         (* Normal return *)
+ERR: RET         (* Error return, ENO not set *)
           </IL>
         </body>
       </pou>
@@ -847,14 +849,14 @@
           <ST>
 IF Collision THEN
   Speed := 0;
-  Brakes := ON;
+  Brakes := TRUE;
 END_IF;
 
-IF (Gate = CLOSED) AND
-    (Pump = ON) AND (Temp > 200.0) THEN
-  Control_State := Active;
+IF (Gate = TRUE) AND
+    (Pump = TRUE) AND (Temp > 200.0) THEN
+  Control_State := TRUE;
 ELSE
-  Control_State := Hold;
+  Control_State := FALSE;
   PumpSpeed := 10.0;
 END_IF;
           </ST>