--- 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)