@@ -6,6 +6,22 @@ def __init__(self):
6
6
self .STATUS = ""
7
7
self .operation_count = 0
8
8
self .glob_lst = {}
9
+ self .entity_path = "./sample/ses_db"
10
+
11
+ self .sm = SystemManager ("./sample/ses_db" , "./sample/model_db" , './sample/pes_db' )
12
+
13
+ self .entity_db = []
14
+ self .model_db = {}
15
+ self .make_db ()
16
+
17
+ def make_db (self ):
18
+ self . entity_db = [f for f in listdir (self .entity_path ) if isfile (join (self .entity_path , f ))]
19
+ for _file in self .entity_db :
20
+ self .model_db [_file [:- 5 ]] = os .path .join (os .path .abspath (self .entity_path ), _file )
21
+
22
+ def clear_system (self ):
23
+ self .glob_lst = {}
24
+ self .operation_count = 0
9
25
10
26
def print_current_menu (self , update , current_num ):
11
27
if current_num == 1 :
@@ -16,8 +32,16 @@ def print_current_menu(self, update, current_num):
16
32
update .message .reply_text ("4. Delete Entity" )
17
33
update .message .reply_text ("0. Exit" )
18
34
elif len (self .STATUS ) == 2 :
19
- if self .STATUS == "11" :
20
- self .create_option (update )
35
+ if self .STATUS [0 ] == "1" :
36
+ self .setting_step (update )
37
+ elif current_num == 2 :
38
+ if len (self .STATUS ) == 1 :
39
+ #model management
40
+ update .message .reply_text (self .STATUS )
41
+ elif len (self .STATUS ) == 2 :
42
+ if self .STATUS [0 ] == "1" :
43
+ self .setting_step (update )
44
+
21
45
elif current_num == "0" :
22
46
if self .STATUS == "" :
23
47
update .message .reply_text ("over" )
@@ -27,6 +51,8 @@ def print_current_menu(self, update, current_num):
27
51
def setting_step (self , update ):
28
52
if self .STATUS == "11" :
29
53
self .create_option (update )
54
+ if self .STATUS == "12" :
55
+ self .read_option (update )
30
56
31
57
def YN_again_menu (self , update , restart_num ):
32
58
if update .message .text == "y" :
@@ -58,8 +84,22 @@ def Chk_int(self, update, _num):
58
84
update .message .reply_text ("please type int" )
59
85
return False
60
86
87
+ def print_entity_db (self ,update ):
88
+ fmt = "{0: <13}\t {1: <13}"
89
+ for k ,v in self .model_db .items ():
90
+ update .message .reply_text (fmt .format (k ,v ))
91
+
92
+ def print_entity_information (self , update , target ):
93
+ fmt = "{0: <10}{name: <15}\t {arity: <5}\t {opt: <5}"
94
+ _str = ""
95
+ _str += "Name: " + target .entity_name + "\n "
96
+ _str += fmt .format ("Entities: " , name = "Name" , arity = "Arity" , opt = "Optional" ) + "\n "
97
+ entities = target .core_attribute .retrieve_entities ()
61
98
99
+ for idx , entity in enumerate (entities ):
100
+ _str += "\t " + fmt .format (idx + 1 , name = entity [0 ], arity = entity [1 ], opt = entity [2 ]) + "\n "
62
101
102
+ update .message .reply_text (_str )
63
103
64
104
65
105
def create_option (self , update ):
@@ -299,8 +339,60 @@ def create_option(self, update):
299
339
elif self .operation_count == 23 :
300
340
print (self .glob_lst )
301
341
if self .YN_again_menu (update , 4 ):
302
- pass
342
+ esm = EntityManager ()
343
+ msa = ModelStructuralAttribute ()
344
+ entity = esm .create_entity_structure ()
345
+ entity .set_name (self .glob_lst ["name" ])
346
+ if int (self .glob_lst ["num_input_port" ]) > 0 :
347
+ for i in range (int (self .glob_lst ["num_input_port" ])):
348
+ nm = "in" + str (i + 1 )
349
+ msa .insert_input_port (nm )
350
+ if int (self .glob_lst ["num_output_port" ]) > 0 :
351
+ for i in range (int (self .glob_lst ["num_output_port" ])):
352
+ nm = "out" + str (i + 1 )
353
+ msa .insert_input_port (nm )
354
+ for i in range (len (self .glob_lst ["entities name" ])):
355
+ msa .insert_entity (self .glob_lst ["entities name" ][i ], self .glob_lst ["attribute number" ][i ],
356
+ self .glob_lst ["optional" ][i ])
357
+ if len (self .glob_lst ["ex_in_portnum" ]) > 0 :
358
+ for i in range (len (self .glob_lst ["ex_in_portnum" ])):
359
+ msa .insert_coupling (("" , self .glob_lst ["ex_in_portnum" ][i ]), (self .glob_lst ["ex_in_entity" ][i ],
360
+ self .glob_lst ["ex_in_portenti" ][i ]))
361
+ if len (self .glob_lst ["ex_out_portnum" ]) > 0 :
362
+ for i in range (len (self .glob_lst ["ex_out_portnum" ])):
363
+ msa .insert_coupling ((self .glob_lst ["ex_out_entity" ][i ], self .glob_lst ["ex_out_portenti" ][i ]),
364
+ ("" , self .glob_lst ["ex_out_portnum" ][i ]))
365
+ if len (self .glob_lst ["internal_out_entity" ]) > 0 :
366
+ for i in range (len (self .glob_lst ["internal_out_entity" ])):
367
+ msa .insert_coupling ((self .glob_lst ["internal_out_entity" ][i ],
368
+ self .glob_lst ["internal_out_port" ][i ]),
369
+ (self .glob_lst ["internal_in_entity" ][i ],
370
+ self .glob_lst ["internal_in_port" ][i ]))
371
+ entity .set_core_attribute (msa )
372
+ esm .create_system (entity )
373
+ esm .export_system_entity_structure (entity , self .entity_path , str (self .glob_lst ["name" ]) + ".json" )
374
+
375
+ self .clear_system ()
376
+
303
377
else :
304
378
if update .message .text == "y" :
305
379
update .message .reply_text ("created entities: " + str (self .glob_lst ["entities name" ]))
306
- update .message .reply_text ("choose first entity out to other" )
380
+ update .message .reply_text ("choose first entity out to other" )
381
+
382
+ def read_option (self , update ):
383
+ if self .operation_count == 0 :
384
+ self .print_entity_db (update )
385
+ update .message .reply_text ("Type name of Entity" )
386
+ self .operation_count += 1
387
+ elif self .operation_count == 1 :
388
+ if update .message .text in self .model_db .keys ():
389
+ model = self .sm .esm .import_system_entity_structure (self .model_db [update .message .text ])
390
+ print (model )
391
+ self .print_entity_information (update , model )
392
+ #update.message.reply_text(model)
393
+ self .clear_system ()
394
+ else :
395
+ update .message .reply_text ("[ERR] Entity Not Found" )
396
+ update .message .reply_text ("Type name of Entity" )
397
+
398
+
0 commit comments