--- a/PLCControler.py Wed Sep 19 13:32:24 2007 +0200
+++ b/PLCControler.py Wed Sep 19 15:20:59 2007 +0200
@@ -1455,7 +1455,7 @@
for type, varlist in pou.getVars():
for var in varlist.getVariable():
if var.getName() == varname:
- return var.getType()
+ return var.getType().getValue()
return ""
def SetConnectionWires(self, connection, connector):
--- a/PLCOpenEditor.py Wed Sep 19 13:32:24 2007 +0200
+++ b/PLCOpenEditor.py Wed Sep 19 15:20:59 2007 +0200
@@ -2645,8 +2645,13 @@
def VariableTypeFunction(event):
row = self.VariablesGrid.GetGridCursorRow()
self.Table.SetValueByName(row, "Type", base_type)
- self.SaveValues()
self.Table.ResetView(self.VariablesGrid)
+ self.SaveValues(False)
+ self.Viewer.RefreshView()
+ self.Viewer.VerifyVariableTypeCompatibility()
+ self.Controler.BufferProject()
+ self.ParentWindow.RefreshTitle()
+ self.ParentWindow.RefreshEditMenu()
event.Skip()
return VariableTypeFunction
--- a/TextViewer.py Wed Sep 19 13:32:24 2007 +0200
+++ b/TextViewer.py Wed Sep 19 15:20:59 2007 +0200
@@ -239,7 +239,10 @@
self.RefreshJumpList()
self.EmptyUndoBuffer()
self.DisableEvents = False
-
+
+ def VerifyVariableTypeCompatibility(self):
+ pass
+
def OnStyleNeeded(self, event):
self.TextChanged = True
line = self.LineFromPosition(self.GetEndStyled())
--- a/Viewer.py Wed Sep 19 13:32:24 2007 +0200
+++ b/Viewer.py Wed Sep 19 15:20:59 2007 +0200
@@ -272,6 +272,15 @@
self.Comments = {}
self.SelectedElement = None
+ # Verify wires type compatibility
+ def VerifyVariableTypeCompatibility(self):
+ to_delete = []
+ for wire in self.Wires:
+ if not wire.IsConnectedCompatible():
+ to_delete.append(wire)
+ for wire in to_delete:
+ wire.Delete()
+
# Remove all elements
def CleanView(self):
for block in self.Blocks.keys():
@@ -324,10 +333,6 @@
self.RefreshScrollBars()
self.Refresh(False)
- def Scroll(self, x, y):
- print "Scroll to (%d, %d)"%(x, y)
- wx.ScrolledWindow.Scroll(self, x, y)
-
def RefreshScrollBars(self):
xstart, ystart = self.GetViewStart()
window_size = self.GetClientSize()
--- a/graphics/GraphicCommons.py Wed Sep 19 13:32:24 2007 +0200
+++ b/graphics/GraphicCommons.py Wed Sep 19 15:20:59 2007 +0200
@@ -24,7 +24,7 @@
import wx
from math import *
-
+from plcopen.structures import IsOfType
#-------------------------------------------------------------------------------
# Common constants
@@ -707,6 +707,10 @@
def GetType(self):
return self.Type
+ # Returns if connector type is compatible with type given
+ def IsCompatible(self, type):
+ return IsOfType(type, self.Type) or IsOfType(self.Type, type)
+
# Changes the connector name
def SetType(self, type):
self.Type = type
@@ -968,10 +972,29 @@
def GetStartConnected(self):
return self.StartConnected
+ # Returns connector to which start point is connected
+ def GetStartConnectedType(self):
+ if self.StartConnected:
+ return self.StartConnected.GetType()
+ return None
+
# Returns connector to which end point is connected
def GetEndConnected(self):
return self.EndConnected
+ # Returns connector to which end point is connected
+ def GetEndConnectedType(self):
+ if self.EndConnected:
+ return self.EndConnected.GetType()
+ return None
+
+ def IsConnectedCompatible(self):
+ if self.StartConnected:
+ return self.StartConnected.IsCompatible(self.GetEndConnectedType())
+ elif self.EndConnected:
+ return True
+ return False
+
# Unconnect the start and end points
def Clean(self):
if self.StartConnected:
@@ -1609,13 +1632,13 @@
new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey)
connector = self.Parent.FindBlockConnector(new_pos)
if connector:
- if handle == 0 and self.EndConnected != connector:
+ if handle == 0 and self.EndConnected != connector and connector.IsCompatible(self.GetEndConnectedType()):
connector.Connect((self, handle))
self.SetStartPointDirection(connector.GetDirection())
self.ConnectStartPoint(connector.GetPosition(), connector)
self.oldPos = connector.GetPosition()
self.Dragging = False
- elif handle != 0 and self.StartConnected != connector:
+ elif handle != 0 and self.StartConnected != connector and connector.IsCompatible(self.GetStartConnectedType()):
connector.Connect((self, handle))
self.SetEndPointDirection(connector.GetDirection())
self.ConnectEndPoint(connector.GetPosition(), connector)
--- a/plcopen/structures.py Wed Sep 19 13:32:24 2007 +0200
+++ b/plcopen/structures.py Wed Sep 19 15:20:59 2007 +0200
@@ -262,7 +262,9 @@
"""
def IsOfType(test, reference):
- while test != None:
+ if reference is None:
+ return True
+ while test is not None:
if test == reference:
return True
test = TypeHierarchy[test]
@@ -272,7 +274,7 @@
returns list of all types that correspont to the ANY* meta type
"""
def GetSubTypes(reference):
- return [ typename for typename, parenttype in TypeHierarchy_list if typename[:3] != "ANY" and IsOfType(typename, reference)]
+ return [typename for typename, parenttype in TypeHierarchy_list if typename[:3] != "ANY" and IsOfType(typename, reference)]
#-------------------------------------------------------------------------------