-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAbstractable.py
More file actions
223 lines (182 loc) · 6.83 KB
/
Copy pathAbstractable.py
File metadata and controls
223 lines (182 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# -*- coding: utf-8 -*-
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
# Abstractable.py ---
# --------------------------------
# Copyright (c) 2014
# Laurent CAPOCCHI
# University of Corsica
# --------------------------------
# Version 1.0 last modified: 20/01/14
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
#
# GENERAL NOTES AND REMARKS:
#
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
#
# GLOBAL VARIABLES AND FUNCTIONS
#
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
import sys
import gettext
_ = gettext.gettext
from Mixins.Attributable import Attributable
import Container
# import Components
#---------------------------------------------------------
class Abstractable:
""" Mixin class for the abstraction hierarchy.
Adds dynamically the 'layers' attribute. This one contains the list of diagrams associated with one level.
"""
DUMP_ATTR = ['layers', 'current_level', 'DAM', 'UAM']
###
def __init__(self, dia):
""" Constructor.
"""
### current level
self.current_level = 0
self.diagram = dia
### dico of layers, dico of Downward and Upward functions according to layers
if hasattr(dia, 'layers'):
self.layers = getattr(dia, 'layers')
self.DAM = getattr(dia, 'DAM')
self.UAM = getattr(dia, 'UAM')
else:
self.layers = {0:dia}
self.DAM = {}
self.UAM = {}
#===============================================================================
# overwriting for Diagram class
#===============================================================================
###
def SetDiagram(self, diagram):
""" Set the diagram.
"""
### if diagram has layers attribute and layer exist, then load it
if hasattr(diagram, 'layers') and diagram.current_level in diagram.layers:
self.diagram = diagram.layers[self.GetCurrentLevel()]
#self.layers = diagram.layers
#self.current_level = diagram.current_level
self.DAM = diagram.DAM
self.UAM = diagram.UAM
else:
self.diagram = diagram
self.AddLayer(diagram, self.GetCurrentLevel())
###
def GetDiagram(self):
""" Return Diagram instance.
"""
return self.diagram
#===============================================================================
#
#===============================================================================
###
def GetDiagramByLevel(self, l):
""" Return layer form level l.
if layer dosen't exist, None is returned.
"""
return self.layers.get(l, None)
###
def SetDiagramByLevel(self, d, l):
""" Update the layers form diagram d at level l.
"""
self.layers.update({l:d})
###
def GetLayers(self):
""" Get layers dico.
"""
return self.layers
###
def GetCurrentLevel(self):
""" Return the current layer viewed in the canvas.
"""
return self.current_level
def GetUAM(self):
""" Return the dictionary of the code of Upward Atomic Model.
"""
return self.UAM
def GetDAM(self):
""" Return the dictionary of the code of Downward Atomic Model.
"""
return self.DAM
def SetDAM(self, cl, val):
"""
"""
self.DAM[cl] = val
def SetUAM(self, cl, val):
"""
"""
self.UAM[cl] = val
def SetCurrentLevel(self, l):
""" Set the current level viewed in the canvas.
"""
self.current_level = l
###
def NextLevel(self):
""" return the last depth abstract level.
"""
return self.GetLevelLenght()
###
def GetLevelLenght(self):
""" Get the number of layers defined in the canvas.
"""
return len(self.GetLayers())
###
def AddLayer(self, d, l):
""" Add the diagram d at level l/
"""
if l in self.layers:
self.SetDiagramByLevel(d, l)
else:
### add new diagram according the new layer
self.layers[l] = d
import WizardGUI
### add new DAM and UAM according to new layer
self.SetUAM(l, WizardGUI.atomicCode('UAM%d'%l))
self.SetDAM(l, WizardGUI.atomicCode('DAM%d'%l))
###
def LoadDiagram(self, l):
""" Load diagram at the level l in the current canvas.
"""
layers = self.GetLayers()
canvas = self
print("current level is", l, layers)
if l in layers:
dia = canvas.GetDiagramByLevel(l)
canvas.SetCurrentLevel(l)
sys.stdout.write("load diagram %d"%l)
sys.stdout.write(str(self.layers))
else:
dia = Container.Diagram()
dia.SetParent(canvas)
canvas.SetCurrentLevel(l)
#canvas.SetDiagram(dia)
sys.stdout.write("New diagram at level %s"%l, self.layers)
### add new or update new attributes layers and current_layer to diagram
setattr(dia, 'layers', canvas.GetLayers())
setattr(dia, 'current_level', canvas.GetCurrentLevel())
setattr(dia, 'DAM', canvas.GetDAM())
setattr(dia, 'UAM', canvas.GetUAM())
### add new or update new attributes layers and current_layer to diagram at level 0
d0 = canvas.GetDiagramByLevel(0)
setattr(d0, 'layers', canvas.GetLayers())
setattr(d0, 'current_level', canvas.GetCurrentLevel())
setattr(d0, 'DAM', canvas.GetDAM())
setattr(d0, 'UAM', canvas.GetUAM())
#=======================================================================
# ### Add Attributes for dump only for ContainerBlock
#=======================================================================
# frame = canvas.GetTopLevelParent()
# is_detached_frame = isinstance(frame, DetachedFrame.DetachedFrame)
# parent_frame_is_canvas = isinstance(frame.GetParent(), Container.ShapeCanvas)
# if is_detached_frame and not parent_frame_is_canvas:
# d0 = canvas.GetDiagramByLevel(0)
# ### only once
# if not (d0.HasAttr('layers') and d0.HasAttr('current_level')):
# d0.AddAttributes(['layers', 'current_level'])
# self.SetDiagramByLevel(0, d0)
#=======================================================================
### update canvas
canvas.SetDiagram(dia)
canvas.deselect()
canvas.Refresh()