# HG changeset patch # User lbessard # Date 1176907168 -7200 # Node ID 69075340d6a9174dff0c28e8442cf23175b017ca # Parent 58a65b90171997b5f27fa6bef2efb876efec13d9 Adding support for forbidding insertion of function block into function diff -r 58a65b901719 -r 69075340d6a9 PLCControler.py --- 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] diff -r 58a65b901719 -r 69075340d6a9 PLCOpenEditor.py --- 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 -*- diff -r 58a65b901719 -r 69075340d6a9 Viewer.py --- 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) diff -r 58a65b901719 -r 69075340d6a9 examples/example.xml --- 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 @@ - + - - - @@ -65,6 +62,13 @@ + + + + + + + @@ -91,7 +95,7 @@ - FBDTest + OUT @@ -386,7 +390,7 @@ - + @@ -395,24 +399,22 @@ -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 *) @@ -847,14 +849,14 @@ 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;