4 logger
= logging
.getLogger()
6 matchKind
=set([('toElem','fromElem')])
8 def match(kindA
, kindB
):
9 ''' Check if Connection's kind are matching '''
10 if ((kindA
, kindB
) in matchKind
) or ((kindB
, kindA
) in matchKind
):
13 logger
.warning('Problem with match in Connection')
18 class Connection(object):
19 def __init__(self
, elem
, kind
,dpos
):
20 ''' A Connection connect an Element and another Connection.
21 A Connection always contains its own Element (elem).
22 Its link contains a Connection (or is None) '''
25 self
.__kind
= kind
# see kind in matchKind
27 self
.__bmp
= wx
.Image("images/"+self
.__kind
+'.png').ConvertToBitmap()
31 ''' Give the picture you see on panel. When a State is connected, its Connections are not visible. '''
32 if type(self
.__elem
) == element
.State
and self
.__link
!= None:
33 self
.__bmp
.SetSize((0,0))
35 self
.__bmp
.SetSize((12,12))
40 ''' Connection's pictures relative position'''
41 if type(self
.__elem
) == element
.State
and self
.__link
!= None:
42 # drawn line in panel from connection start at the centre of state if connection.link != None
43 return ( (self
.__elem
.zone
[1][0]-self
.__elem
.zone
[0][0])/2,(self
.__elem
.zone
[1][1]-self
.__elem
.zone
[0][1])/2)
61 """ link setter is used when trying to connect or deconnect two Connection """
62 if conn
== None: # = deconnection
63 if self
.__link
== None:
67 self
.__link
.__link
= None
69 self
.elem
.connectionChanged()
70 oldLink
.elem
.connectionChanged()
71 elif type(self
.elem
)== element
.State
and type(conn
.elem
) == element
.State
:
72 logger
.info('Do not connect two states together')
73 elif type(self
.elem
) == element
.State
or type(conn
.elem
) == element
.State
:
74 if match(conn
.__kind
, self
.__kind
): # = connection to another conn OR change connection
76 oldConnLink
= conn
.__link
77 if oldConnLink
!= None :
78 # detach the previously connected
79 conn
.__link
.__link
= None
81 self
.__link
= conn
# connect to the new one
83 #The 4 connections involved tell they have changed
84 self
.elem
.connectionChanged()
85 conn
.elem
.connectionChanged()
87 oldLink
.elem
.connectionChanged()
88 if oldConnLink
!= None:
89 oldConnLink
.elem
.connectionChanged()
91 logger
.warning('Problem with kind in link.setter')
94 logger
.info('Please only connect state with transformation')