Adding Test when creating ConnectionBlock
authorlbessard
Wed, 18 Mar 2009 16:42:12 +0100
changeset 330 d803ba077da0
parent 329 1cf72cb51dc9
child 331 9106d66bd204
Adding Test when creating ConnectionBlock
Dialogs.py
Viewer.py
--- a/Dialogs.py	Wed Mar 18 16:09:52 2009 +0100
+++ b/Dialogs.py	Wed Mar 18 16:42:12 2009 +0100
@@ -230,7 +230,6 @@
         return None
     
     def OnOK(self, event):
-        error = []
         selected = self.TypeTree.GetSelection()
         block_name = self.BlockName.GetValue()
         name_enabled = self.BlockName.IsEnabled()
@@ -840,10 +839,11 @@
               size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
 
         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
-        
         if wx.VERSION >= (2, 5, 0):
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
             self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
         else:
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
             wx.EVT_PAINT(self.Preview, self.OnPaint)
         
         self._init_sizers()
@@ -852,6 +852,9 @@
         self._init_ctrls(parent, controler)
         self.Connection = None
         self.MinConnectionSize = None
+        
+        self.PouNames = []
+        self.PouElementNames = []
     
     def SetPreviewFont(self, font):
         self.Preview.SetFont(font)
@@ -880,6 +883,37 @@
         values["width"], values["height"] = self.Connection.GetSize()
         return values
 
+    def SetPouNames(self, pou_names):
+        self.PouNames = [pou_name.upper() for pou_name in pou_names]
+        
+    def SetPouElementNames(self, element_names):
+        self.PouElementNames = [element_name.upper() for element_name in element_names]
+
+    def OnOK(self, event):
+        connection_name = self.ConnectionName.GetValue()
+        if connection_name == "":
+            message = wx.MessageDialog(self, "Form isn't complete. Name must be filled!", "Error", wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        elif not TestIdentifier(connection_name):
+            message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%connection_name, "Error", wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        elif connection_name.upper() in IEC_KEYWORDS:
+            message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%connection_name, "Error", wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        elif connection_name.upper() in self.PouNames:
+            message = wx.MessageDialog(self, "\"%s\" pou already exists!"%connection_name, "Error", wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        elif connection_name.upper() in self.PouElementNames:
+            message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%connection_name, "Error", wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        else:
+            self.EndModal(wx.ID_OK)
+
     def OnTypeChanged(self, event):
         self.RefreshPreview()
         event.Skip()
--- a/Viewer.py	Wed Mar 18 16:09:52 2009 +0100
+++ b/Viewer.py	Wed Mar 18 16:42:12 2009 +0100
@@ -1731,6 +1731,8 @@
     def AddNewConnection(self, bbox):
         dialog = ConnectionPropertiesDialog(self.ParentWindow, self.Controler)
         dialog.SetPreviewFont(self.GetFont())
+        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
+        dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
         dialog.SetMinConnectionSize((bbox.width, bbox.height))
         if dialog.ShowModal() == wx.ID_OK:
             id = self.GetNewId()
@@ -2051,6 +2053,8 @@
     def EditConnectionContent(self, connection):
         dialog = ConnectionPropertiesDialog(self.ParentWindow, self.Controler)
         dialog.SetPreviewFont(self.GetFont())
+        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
+        dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
         dialog.SetMinConnectionSize(connection.GetSize())
         values = {"name" : connection.GetName(), "type" : connection.GetType()}
         dialog.SetValues(values)