--- a/PLCControler.py Fri Oct 05 18:11:27 2007 +0200
+++ b/PLCControler.py Fri Oct 05 18:11:51 2007 +0200
@@ -383,63 +383,70 @@
# Project Pous management functions
#-------------------------------------------------------------------------------
+ def RemoveElementEditing(self, index):
+ self.ElementsOpened.pop(index)
+ if self.CurrentElementEditing > index:
+ self.CurrentElementEditing -= 1
+ if len(self.ElementsOpened) > 0:
+ self.CurrentElementEditing = max(0, min(self.CurrentElementEditing, len(self.ElementsOpened) - 1))
+ else:
+ self.CurrentElementEditing = None
+
# Add a Pou to Project
- def ProjectAddPou(self, name, pou_type, body_type):
+ def ProjectAddPou(self, pou_name, pou_type, body_type):
# Add the pou to project
- self.Project.appendPou(name, pou_type, body_type)
- self.SetPouInterfaceReturnType(name, "BOOL")
+ self.Project.appendPou(pou_name, pou_type, body_type)
+ if pou_type == "function":
+ self.SetPouInterfaceReturnType(pou_name, "BOOL")
self.RefreshPouUsingTree()
self.RefreshBlockTypes()
self.BufferProject()
# Remove a pou from project
- def ProjectRemovePou(self, name):
- removed = None
+ def ProjectRemovePou(self, pou_name):
# Search if the pou removed is currently opened
- for i, pou in enumerate(self.ElementsOpened):
- if pou == name:
- removed = i
- # If found, remove pou from list of opened pous and actualize current edited
- if removed != None:
- self.ElementsOpened.pop(removed)
- if self.CurrentElementEditing > removed:
- self.CurrentElementEditing -= 1
- if len(self.ElementsOpened) > 0:
- self.CurrentElementEditing = max(0, min(self.CurrentElementEditing, len(self.ElementsOpened) - 1))
- else:
- self.CurrentElementEditing = None
+ for i, element in enumerate(self.ElementsOpened):
+ words = element.split("::")
+ if words[0] == "P" and words[1] == pou_name:
+ self.RemoveElementEditing(i)
# Remove pou from project
- self.Project.removePou(name)
+ self.Project.removePou(pou_name)
self.RefreshPouUsingTree()
self.RefreshBlockTypes()
self.BufferProject()
# Add a configuration to Project
- def ProjectAddConfiguration(self, name):
- self.Project.addConfiguration(name)
+ def ProjectAddConfiguration(self, config_name):
+ self.Project.addConfiguration(config_name)
self.RefreshPouUsingTree()
self.RefreshBlockTypes()
self.BufferProject()
# Remove a configuration from project
- def ProjectRemoveConfiguration(self, name):
- self.Project.removeConfiguration(name)
+ def ProjectRemoveConfiguration(self, config_name):
+ # Search if the pou removed is currently opened
+ for i, element in enumerate(self.ElementsOpened):
+ words = element.split("::")
+ if words[0] == "C" and words[1] == config_name:
+ self.RemoveElementEditing(i)
+ self.Project.removeConfiguration(config_name)
+ self.BufferProject()
+
+ # Add a resource to a configuration of the Project
+ def ProjectAddConfigurationResource(self, config_name, resource_name):
+ self.Project.addConfigurationResource(config_name, resource_name)
self.RefreshPouUsingTree()
self.RefreshBlockTypes()
self.BufferProject()
- # Add a resource to a configuration of the Project
- def ProjectAddConfigurationResource(self, config, name):
- self.Project.addConfigurationResource(config, name)
- self.RefreshPouUsingTree()
- self.RefreshBlockTypes()
- self.BufferProject()
-
# Remove a resource from a configuration of the project
- def ProjectRemoveConfigurationResource(self, config, name):
- self.Project.removeConfigurationResource(config, name)
- self.RefreshPouUsingTree()
- self.RefreshBlockTypes()
+ def ProjectRemoveConfigurationResource(self, config_name, resource_name):
+ # Search if the pou removed is currently opened
+ for i, element in enumerate(self.ElementsOpened):
+ words = element.split("::")
+ if words[0] == "R" and words[1] == config_name and words[2] == resource_name:
+ self.RemoveElementEditing(i)
+ self.Project.removeConfigurationResource(config_name, resource_name)
self.BufferProject()
# Add a Transition to a Project Pou
@@ -448,11 +455,33 @@
pou.addTransition(transition_name, transition_type)
self.BufferProject()
- # Add a Transition to a Project Pou
+ # Remove a Transition from a Project Pou
+ def ProjectRemovePouTransition(self, pou_name, transition_name):
+ # Search if the pou removed is currently opened
+ for i, element in enumerate(self.ElementsOpened):
+ words = element.split("::")
+ if words[0] == "T" and words[1] == pou_name and words[2] == transition_name:
+ self.RemoveElementEditing(i)
+ pou = self.Project.getPou(pou_name)
+ pou.removeTransition(transition_name)
+ self.BufferProject()
+
+ # Add an Action to a Project Pou
def ProjectAddPouAction(self, pou_name, action_name, action_type):
pou = self.Project.getPou(pou_name)
pou.addAction(action_name, action_type)
self.BufferProject()
+
+ # Remove an Action from a Project Pou
+ def ProjectRemovePouAction(self, pou_name, action_name):
+ # Search if the pou removed is currently opened
+ for i, element in enumerate(self.ElementsOpened):
+ words = element.split("::")
+ if words[0] == "A" and words[1] == pou_name and words[2] == action_name:
+ self.RemoveElementEditing(i)
+ pou = self.Project.getPou(pou_name)
+ pou.removeAction(action_name)
+ self.BufferProject()
# Change the name of a pou
def ChangePouName(self, old_name, new_name):
@@ -594,18 +623,6 @@
action = pou.getAction(pou_action)
return action.getBodyType()
- # Add a Transition to a Project Pou
- def ProjectRemovePouTransition(self, pou_name, transition_name):
- pou = self.Project.getPou(pou_name)
- pou.removeTransition(transition_name)
- self.BufferProject()
-
- # Add a Transition to a Project Pou
- def ProjectRemovePouAction(self, pou_name, action_name):
- pou = self.Project.getPou(pou_name)
- pou.removeAction(action_name)
- self.BufferProject()
-
# Extract varlists from a list of vars
def ExtractVarLists(self, vars):
varlist_list = []
@@ -901,17 +918,17 @@
# Return Function Block types checking for recursion
def GetFunctionBlockTypes(self):
if self.CurrentElementEditing != None:
+ name = ""
+ type = None
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 = ""
- type = None
+ if words[0] in ["P","T","A"]:
+ if len(words) == 1:
+ name = current_name
+ else:
+ name = words[1]
+ type = self.GetPouType(name)
blocktypes = []
for category in BlockTypes[:-1]:
for block in category["list"]:
@@ -1032,6 +1049,12 @@
else:
self.CurrentElementEditing = None
+ # Close current element editing
+ def CloseAllElements(self):
+ # Clear the pou opened list
+ self.ElementsOpened = []
+ self.CurrentElementEditing = None
+
# Change current element editing for pou given by name
def ChangeElementEditing(self, name):
# Verify that element is opened