-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller_file_type.py
159 lines (121 loc) · 4.42 KB
/
controller_file_type.py
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
#!/usr/bin/python
import model as m
import view_file_type as v
import controller as c
import rparser as rpa
import sbml_lex
import pnml_lex
import txt_convert
import txt2_lex
import_libsbml = True
try:
import sbml_convert
except AttributeError:
import_libsbml = False
import pnml_convert
import petri_net
import petri_net_data
#import RPndHolder as pndh
import converter_matrixtostochasticpetrinet
import converter_stochasticpetrinettomatrix
import spectral_a
class ControllerFileType(c.Controller):
""" The ControllerFileType class is a specific controller that inherits from the general Controller class and is used to manage the user interactions of the file export configuration window and the application (ViewFileType). """
M_OPEN = 0
M_SAVE = 1
_path = None
_modus = 0
def __init__(self):
""" Constructor of ControllerConfigurationComponent. """
# call constructor of parent class
c.Controller.__init__(self)
# set default values
self._path = None
self._modus = 0
def __init__(self, model = None, view = None):
""" Constructor of ControllerConfigurationComponent. """
# call constructor of parent class
c.Controller.__init__(self, model, view)
# set default values
self._path = None
self._modus = 0
def update(self):
""" Interface to notify MVCObserver objects about a general data change. """
pass
def update_component(self, key):
""" Interface to notify Observer objects about a data change of a component. """
pass
def update_output(self):
""" Interface to notify Observer objects about a data change of simulation results. """
pass
def reset(self):
""" Interface to notify MVCObserver objects about a reset event. """
pass
def undo(self):
""" Interface to notify Observer objects about an undo. """
pass
@property
def modus(self):
""" Return modus. """
return self._modus
@property
def path(self):
""" Return path. """
return self._path
@modus.setter
def modus(self, m):
""" Set modus. """
self._modus = m
@path.setter
def path(self, p):
""" Set path. """
self._path = p
def open(self, lexer):
""" Input file with the define path will be opened, analysed and a PetriNet object will be created if possible and assigned to the functional core of the MVC architecture. """
# check if a path is defined
if self._path == None:
# abort method
return False
# read file
f = infile = open(self._path, 'r')
# create token list
token_list = lexer.lex(f)
# set parser
parser = rpa.RParser()
# set token list
parser.data = token_list
# parse token list to PetriNetData
parser.parse()
# set the data
self._model.data = petri_net.PetriNet()
self._model.data.petri_net_data = parser.output
# set converter
self._model.data.converter_components = converter_matrixtostochasticpetrinet.ConverterMatrixToStochasticPetriNet()
self._model.data.converter_matrices = converter_stochasticpetrinettomatrix.ConverterStochasticPetriNetToMatrix()
# instantiate algorithm to calculate the positions of the individual components
layout = spectral_a.Spectral()
# initial properties
layout.width = 900
layout.height = 600
layout.border = 85
layout.d_radius = 85
# set algorithm
self._model.data.converter_components.layout = layout
# set data
self._model.data.converter_components.layout.data = self._model.data.petri_net_data
# convert components
self._model.data.convert_components()
# notification ot the other observers
self._model.notify()
return True
def save(self, converter):
""" Output file with the defined path will be created through a defined format. For this the data stored in the model of the MVC architecture is used. """
# check if a path is defined
if self._path == None:
# abort method
return False
# create token list from the PetriNetData object
token = converter.getPetriNetData()
# create output file
converter.save(self._path)
return True