graphics/GraphicCommons.py
changeset 98 ec5d7af033d8
parent 90 2245e8776086
child 99 2b18a72dcaf0
equal deleted inserted replaced
97:28337cd092fd 98:ec5d7af033d8
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 import wx
    25 import wx
    26 from math import *
    26 from math import *
    27 
    27 from plcopen.structures import IsOfType
    28 
    28 
    29 #-------------------------------------------------------------------------------
    29 #-------------------------------------------------------------------------------
    30 #                               Common constants
    30 #                               Common constants
    31 #-------------------------------------------------------------------------------
    31 #-------------------------------------------------------------------------------
    32 
    32 
   704         return self.ParentBlock
   704         return self.ParentBlock
   705     
   705     
   706     # Returns the connector name
   706     # Returns the connector name
   707     def GetType(self):
   707     def GetType(self):
   708         return self.Type
   708         return self.Type
       
   709     
       
   710     # Returns if connector type is compatible with type given
       
   711     def IsCompatible(self, type):
       
   712         return IsOfType(type, self.Type) or IsOfType(self.Type, type)
   709     
   713     
   710     # Changes the connector name
   714     # Changes the connector name
   711     def SetType(self, type):
   715     def SetType(self, type):
   712         self.Type = type
   716         self.Type = type
   713     
   717     
   966     
   970     
   967     # Returns connector to which start point is connected
   971     # Returns connector to which start point is connected
   968     def GetStartConnected(self):
   972     def GetStartConnected(self):
   969         return self.StartConnected
   973         return self.StartConnected
   970     
   974     
       
   975     # Returns connector to which start point is connected
       
   976     def GetStartConnectedType(self):
       
   977         if self.StartConnected:
       
   978             return self.StartConnected.GetType()
       
   979         return None
       
   980     
   971     # Returns connector to which end point is connected
   981     # Returns connector to which end point is connected
   972     def GetEndConnected(self):
   982     def GetEndConnected(self):
   973         return self.EndConnected
   983         return self.EndConnected
       
   984     
       
   985     # Returns connector to which end point is connected
       
   986     def GetEndConnectedType(self):
       
   987         if self.EndConnected:
       
   988             return self.EndConnected.GetType()
       
   989         return None
       
   990     
       
   991     def IsConnectedCompatible(self):
       
   992         if self.StartConnected:
       
   993             return self.StartConnected.IsCompatible(self.GetEndConnectedType())
       
   994         elif self.EndConnected:
       
   995             return True
       
   996         return False
   974     
   997     
   975     # Unconnect the start and end points
   998     # Unconnect the start and end points
   976     def Clean(self):
   999     def Clean(self):
   977         if self.StartConnected:
  1000         if self.StartConnected:
   978             self.UnConnectStartPoint()
  1001             self.UnConnectStartPoint()
  1607         if handle_type == HANDLE_POINT:
  1630         if handle_type == HANDLE_POINT:
  1608             # Try to connect point to a connector
  1631             # Try to connect point to a connector
  1609             new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey)
  1632             new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey)
  1610             connector = self.Parent.FindBlockConnector(new_pos)
  1633             connector = self.Parent.FindBlockConnector(new_pos)
  1611             if connector:
  1634             if connector:
  1612                 if handle == 0 and self.EndConnected != connector:
  1635                 if handle == 0 and self.EndConnected != connector and connector.IsCompatible(self.GetEndConnectedType()):
  1613                     connector.Connect((self, handle))
  1636                     connector.Connect((self, handle))
  1614                     self.SetStartPointDirection(connector.GetDirection())
  1637                     self.SetStartPointDirection(connector.GetDirection())
  1615                     self.ConnectStartPoint(connector.GetPosition(), connector)
  1638                     self.ConnectStartPoint(connector.GetPosition(), connector)
  1616                     self.oldPos = connector.GetPosition()
  1639                     self.oldPos = connector.GetPosition()
  1617                     self.Dragging = False
  1640                     self.Dragging = False
  1618                 elif handle != 0 and self.StartConnected != connector:
  1641                 elif handle != 0 and self.StartConnected != connector and connector.IsCompatible(self.GetStartConnectedType()):
  1619                     connector.Connect((self, handle))
  1642                     connector.Connect((self, handle))
  1620                     self.SetEndPointDirection(connector.GetDirection())
  1643                     self.SetEndPointDirection(connector.GetDirection())
  1621                     self.ConnectEndPoint(connector.GetPosition(), connector)
  1644                     self.ConnectEndPoint(connector.GetPosition(), connector)
  1622                     self.oldPos = connector.GetPosition()
  1645                     self.oldPos = connector.GetPosition()
  1623                     self.Dragging = False
  1646                     self.Dragging = False