graphics/GraphicCommons.py
changeset 99 2b18a72dcaf0
parent 98 ec5d7af033d8
child 102 85875dcb7754
equal deleted inserted replaced
98:ec5d7af033d8 99:2b18a72dcaf0
    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 from plcopen.structures import IsOfType
    27 from plcopen.structures import IsOfType, IsEndType
    28 
    28 
    29 #-------------------------------------------------------------------------------
    29 #-------------------------------------------------------------------------------
    30 #                               Common constants
    30 #                               Common constants
    31 #-------------------------------------------------------------------------------
    31 #-------------------------------------------------------------------------------
    32 
    32 
   701     
   701     
   702     # Returns the connector parent block
   702     # Returns the connector parent block
   703     def GetParentBlock(self):
   703     def GetParentBlock(self):
   704         return self.ParentBlock
   704         return self.ParentBlock
   705     
   705     
   706     # Returns the connector name
   706     # Returns the connector type
   707     def GetType(self):
   707     def GetType(self):
       
   708         if IsEndType(self.Type):
       
   709             return self.Type
       
   710         else:
       
   711             return self.ParentBlock.GetConnectionResultType(self)
       
   712     
       
   713     # Returns the connector type
       
   714     def GetConnectedType(self):
       
   715         if IsEndType(self.Type):
       
   716             return self.Type
       
   717         elif len(self.Wires) == 1:
       
   718             return self.Wires[0][0].GetOtherConnectedType(self.Wires[0][1])
   708         return self.Type
   719         return self.Type
   709     
   720     
   710     # Returns if connector type is compatible with type given
   721     # Returns if connector type is compatible with type given
   711     def IsCompatible(self, type):
   722     def IsCompatible(self, type):
   712         return IsOfType(type, self.Type) or IsOfType(self.Type, type)
   723         reference = self.GetType()
       
   724         return IsOfType(type, reference) or IsOfType(reference, type)
   713     
   725     
   714     # Changes the connector name
   726     # Changes the connector name
   715     def SetType(self, type):
   727     def SetType(self, type):
   716         self.Type = type
   728         self.Type = type
   717     
   729     
   985     # Returns connector to which end point is connected
   997     # Returns connector to which end point is connected
   986     def GetEndConnectedType(self):
   998     def GetEndConnectedType(self):
   987         if self.EndConnected:
   999         if self.EndConnected:
   988             return self.EndConnected.GetType()
  1000             return self.EndConnected.GetType()
   989         return None
  1001         return None
       
  1002     
       
  1003     def GetOtherConnectedType(self, handle):
       
  1004         if handle == 0:
       
  1005             return self.GetEndConnectedType()
       
  1006         else:
       
  1007             return self.GetStartConnectedType()
   990     
  1008     
   991     def IsConnectedCompatible(self):
  1009     def IsConnectedCompatible(self):
   992         if self.StartConnected:
  1010         if self.StartConnected:
   993             return self.StartConnected.IsCompatible(self.GetEndConnectedType())
  1011             return self.StartConnected.IsCompatible(self.GetEndConnectedType())
   994         elif self.EndConnected:
  1012         elif self.EndConnected: