pn_interface.alc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. include "primitives.alh"
  2. include "constructors.alh"
  3. include "object_operations.alh"
  4. include "library.alh"
  5. include "conformance_scd.alh"
  6. include "io.alh"
  7. include "metamodels.alh"
  8. include "modelling.alh"
  9. Element function find_attribute_type_s(model : Element, elem : String, name : String):
  10. Element mm_elem
  11. Element direct_type
  12. direct_type = dict_read_node(model["type_mapping"], model["model"][elem])
  13. mm_elem = find_attribute_definer(model["metamodel"], direct_type, name)
  14. if (element_eq(mm_elem, read_root())):
  15. // Couldn't find element, so is not allowed!
  16. log("Undefined attribute!")
  17. return read_root()
  18. else:
  19. return getName(model["metamodel"], dict_read_edge(mm_elem, name))
  20. Element function tf_printNode(tf_pn_model: Element, tf_pn_node: Element):
  21. //print header name
  22. String tf_pn_node_name
  23. tf_pn_node_name = getName(tf_pn_model, tf_pn_node)
  24. log(string_join("name: ",tf_pn_node_name) )
  25. log(string_join("type: ", getName(tf_pn_model["metamodel"], dict_read_node(tf_pn_model["type_mapping"], tf_pn_node)) ))
  26. //log(getName(tf_pn_model["metamodel"], dict_read_node(tf_pn_model["type_mapping"], tf_pn_node)))
  27. log("attributes:")
  28. //get the list of attributes
  29. Element tf_pn_attributelist
  30. tf_pn_attributelist = dict_keys(getAttributeList(tf_pn_model, tf_pn_node_name))
  31. String tf_pn_attributename
  32. String tf_pn_attributetype
  33. while (integer_lt(0, read_nr_out(tf_pn_attributelist))):
  34. //print attribute name and its value
  35. tf_pn_attributename = set_pop(tf_pn_attributelist)
  36. tf_pn_attributetype = find_attribute_type_s(tf_pn_model, tf_pn_node_name, tf_pn_attributename)
  37. if( tf_pn_attributetype == "String"):
  38. log(string_join(string_join(string_join(" ",tf_pn_attributename), " : "),read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename)))
  39. elif (tf_pn_attributetype == "Integer"):
  40. log(string_join(string_join(string_join(" ",tf_pn_attributename), " : "),cast_i2s(read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename))))
  41. else:
  42. log(string_join(tf_pn_attributename, " : "))
  43. log(read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename))
  44. return 0
  45. Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Element, tf_ma_model: Element ):
  46. Element tf_ma_metamodelTransf
  47. tf_ma_metamodelTransf = dict_read(dict_read(tf_ma_transformation, "metamodel"), "model")
  48. Element tf_ma_pattern_nodes
  49. tf_ma_pattern_nodes = create_node()
  50. tf_ma_pattern_nodes = allOutgoingAssociationInstances(tf_ma_transformation, tf_ma_pattern, dict_read(tf_ma_metamodelTransf, "pre2ram"))
  51. //check if this works
  52. Element tf_ma_ramified_node
  53. while (integer_lt(0, read_nr_out(tf_ma_pattern_nodes))):
  54. tf_ma_ramified_node = read_edge_dst(set_pop(tf_ma_pattern_nodes))
  55. //tf_printNode(tf_ma_transformation, tf_ma_ramified_node)
  56. Element tf_ma_attrlist
  57. return 0
  58. Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
  59. Element tf_er_lhs
  60. // get the lhs of the rule
  61. tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
  62. // find the matches of the rule
  63. tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
  64. return 0
  65. Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
  66. //create a list of all rules
  67. Element tf_tf_rules
  68. tf_tf_rules = allInstances(tf_tf_transformation, dict_read(dict_read(dict_read(tf_tf_transformation, "metamodel"), "model"), "Rule"))
  69. //execute rules in random order
  70. Element tf_tf_rule
  71. while (integer_lt(0, read_nr_out(tf_tf_rules))):
  72. tf_tf_rule = set_pop(tf_tf_rules)
  73. //tf_printNode(tf_tf_transformation, tf_tf_rule)
  74. tf_executeRule(tf_tf_transformation, tf_tf_rule, tf_tf_model)
  75. return 0
  76. Element function petrinet_transformation(root: Element):
  77. // Create A transformation model for petrinets (useful for testing)
  78. //////////////////////////////////
  79. //initialise an empty transformation model for petrinet
  80. Element my_model
  81. my_model = instantiate_model(root["PetriNets_MTransformation"])
  82. define_inheritance(my_model, "l3")
  83. dict_add(root, "transf_petrinet_fire", my_model)
  84. ////////////////////////////
  85. // root node
  86. instantiate_node(my_model, "Transformation", "PetrinetFire")
  87. instantiate_attribute(my_model, "PetrinetFire", "name", "PetriNetFire")
  88. ////////////////////////////
  89. // rule: find transitions
  90. //rule: find_transitions
  91. instantiate_node(my_model, "Rule", "find_transitions")
  92. instantiate_attribute(my_model, "find_transitions", "name", "find_transitions")
  93. instantiate_attribute(my_model, "find_transitions", "precedence", 1)
  94. //connect to transformation
  95. instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "find_transitions")
  96. //precondition: lhs_precondition
  97. instantiate_node(my_model, "Precondition","lhs_precondition")
  98. //connect to rule
  99. instantiate_link(my_model, "lhs", "", "find_transitions", "lhs_precondition")
  100. //Transition_LHS: lhs_find_all
  101. instantiate_node(my_model, "Transition_LHS","lhs_find_all")
  102. instantiate_attribute(my_model, "lhs_find_all", "plabel", 1)
  103. //connect to rule
  104. instantiate_link(my_model, "pre2ram", "", "lhs_precondition", "lhs_find_all")
  105. //precondition: nac_precondition
  106. instantiate_node(my_model, "Precondition","nac_precondition")
  107. //connect to rule
  108. instantiate_link(my_model, "nac", "", "find_transitions", "nac_precondition")
  109. //Transition_LHS: nac_transition_place_before
  110. instantiate_node(my_model, "Transition_LHS","nac_transition_place_before")
  111. instantiate_attribute(my_model, "nac_transition_place_before", "plabel", 1)
  112. //connect to rule
  113. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_transition_place_before")
  114. //Place_LHS: nac_place_before
  115. instantiate_node(my_model, "Place_LHS","nac_place_before")
  116. instantiate_attribute(my_model, "nac_place_before", "plabel", 2)
  117. instantiate_attribute(my_model, "nac_place_before", "tokens", "lambda x: sum([1 for i in x.out if i.weight<x.tokens]) == len(x.transition)")
  118. //connect to rule
  119. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_place_before")
  120. //P2T_LHS: nac_ft_p2t
  121. instantiate_link(my_model, "P2T_LHS", "nac_p2tlhs_before", "nac_place_before", "nac_transition_place_before")
  122. instantiate_attribute(my_model, "nac_p2tlhs_before", "plabel", 3)
  123. instantiate_attribute(my_model, "nac_p2tlhs_before", "weight", "lambda x: True")
  124. //connect to rule
  125. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_p2tlhs_before")
  126. return my_model
  127. Element function pn_operations():
  128. Element ops
  129. ops = create_node()
  130. dict_add(ops, "fire", petrinet_fire)
  131. dict_add(ops, "enabled", petrinet_enabled)
  132. return ops
  133. Element function petrinet_enabled(model : Element):
  134. Element set_enabled
  135. set_enabled = petrinet_enabled_set(model)
  136. output("Enabled transitions:")
  137. while (0 < read_nr_out(set_enabled)):
  138. output(getName(model, set_pop(set_enabled)))
  139. return model
  140. Element function petrinet_enabled_set(model : Element):
  141. Element all_transitions
  142. all_transitions = allInstances(model, model["metamodel"]["model"]["Transition"])
  143. Element enabled_transitions
  144. enabled_transitions = create_node()
  145. Element under_study
  146. Element in_arcs
  147. Element arc_under_study
  148. Boolean enabled
  149. while (0 < read_nr_out(all_transitions)):
  150. under_study = set_pop(all_transitions)
  151. enabled = True
  152. // Find all incoming transitions
  153. in_arcs = allIncomingAssociationInstances(model, under_study, model["metamodel"]["model"]["P2T"])
  154. while (0 < read_nr_out(in_arcs)):
  155. arc_under_study = set_pop(in_arcs)
  156. Integer present_tokens
  157. Integer required_tokens
  158. required_tokens = read_attribute(model, getName(model, arc_under_study), "weight")
  159. present_tokens = read_attribute(model, getName(model, read_edge_src(arc_under_study)), "tokens")
  160. if (present_tokens < required_tokens):
  161. // Less tokens than required, so disable the transition completely
  162. enabled = False
  163. if (enabled):
  164. set_add(enabled_transitions, under_study)
  165. return enabled_transitions
  166. Element function petrinet_fire(model : Element):
  167. output("Transition to fire?")
  168. Element transition
  169. transition = input()
  170. if (dict_in(model["model"], transition)):
  171. transition = model["model"][transition]
  172. if (set_in(petrinet_enabled_set(model), transition)):
  173. Element workset
  174. Element working_place
  175. Element working_arc
  176. Integer new_value
  177. // Consume tokens
  178. workset = allIncomingAssociationInstances(model, transition, model["metamodel"]["model"]["P2T"])
  179. while (0 < read_nr_out(workset)):
  180. working_arc = set_pop(workset)
  181. working_place = read_edge_src(working_arc)
  182. new_value = integer_subtraction(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
  183. unset_attribute(model, getName(model, working_place), "tokens")
  184. instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
  185. output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
  186. // Add tokens
  187. workset = allOutgoingAssociationInstances(model, transition, model["metamodel"]["model"]["T2P"])
  188. while (0 < read_nr_out(workset)):
  189. working_arc = set_pop(workset)
  190. working_place = read_edge_dst(working_arc)
  191. new_value = integer_addition(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
  192. unset_attribute(model, getName(model, working_place), "tokens")
  193. instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
  194. output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
  195. output("Transition fired!")
  196. else:
  197. output("Cannot fire if not enabled; aborting")
  198. else:
  199. output("Unknown transition; aborting")
  200. return model
  201. Element function petrinet_loaded(model : Element):
  202. String cmd
  203. Element attr_list_pn
  204. Element attr_keys_pn
  205. String attr_key_pn
  206. Element metamodel_element_pn
  207. String typename
  208. Boolean bottom
  209. Element other_metamodel
  210. bottom = False
  211. other_metamodel = create_node()
  212. dict_add(other_metamodel, "model", model["model"])
  213. dict_add(other_metamodel, "type_mapping", create_node())
  214. dict_add(other_metamodel, "metamodel", import_node("models/LTM_bottom"))
  215. dict_add(other_metamodel, "inheritance", other_metamodel["metamodel"]["model"]["__Inheritance"])
  216. output("Model loaded, ready for commands!")
  217. output("Use 'help' command for a list of possible commands")
  218. while (True):
  219. output("Please give your command.")
  220. cmd = input()
  221. if (cmd == "help"):
  222. output("Generic model operations:")
  223. output(" instantiate -- Create a new model element")
  224. output(" delete -- Delete an existing element")
  225. output(" attr_add -- Add an attribute to an element")
  226. output(" attr_del -- Delete an attribute of an element")
  227. output(" rename -- Rename an existing element")
  228. output(" modify -- Modify the attributes of an element")
  229. output(" list -- Prints the list of elements in the model")
  230. output(" types -- Prints the list of elements that can be instantiated")
  231. output(" read -- Prints the current state of a model element")
  232. output(" verify -- Check whether the model conforms to the metamodel")
  233. output(" retype -- Change the type of an element")
  234. output(" switch -- Switch between conformance bottom and the linguistic metamodel")
  235. output(" exit -- Unload the model and go back to the loading prompt")
  236. if (bool_not(bottom)):
  237. output("Model-specific operations:")
  238. Element specific_ops
  239. specific_ops = dict_keys(pn_operations())
  240. String specific_op
  241. while (0 < dict_len(specific_ops)):
  242. specific_op = set_pop(specific_ops)
  243. output(" " + specific_op)
  244. elif (cmd == "exit"):
  245. return model
  246. elif (cmd == "instantiate"):
  247. String mm_type_name
  248. output("Type to instantiate?")
  249. mm_type_name = input()
  250. if (dict_in(model["metamodel"]["model"], mm_type_name)):
  251. String element_name
  252. output("Name of new element?")
  253. element_name = input()
  254. if (dict_in(model["model"], element_name)):
  255. output("Element already exists; aborting")
  256. else:
  257. if (is_edge(model["metamodel"]["model"][mm_type_name])):
  258. output("Source name?")
  259. String src_name
  260. src_name = input()
  261. if (dict_in(model["model"], src_name)):
  262. output("Destination name?")
  263. String dst_name
  264. dst_name = input()
  265. if (dict_in(model["model"], dst_name)):
  266. instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
  267. if (dict_in(model["model"], element_name)):
  268. output("Instantiation successful!")
  269. else:
  270. output("Instantiation error!")
  271. else:
  272. output("Unknown destination; aborting")
  273. else:
  274. output("Unknown source; aborting")
  275. else:
  276. instantiate_node(model, mm_type_name, element_name)
  277. if (dict_in(model["model"], element_name)):
  278. output("Instantiation successful!")
  279. else:
  280. output("Instantiation error!")
  281. else:
  282. output("Unknown type specified; aborting")
  283. elif (cmd == "modify"):
  284. String model_name
  285. output("Element to modify?")
  286. model_name = input()
  287. if (dict_in(model["model"], model_name)):
  288. Element attrs
  289. attrs = getAttributeList(model, model_name)
  290. String attr_name
  291. output("Attribute to modify?")
  292. attr_name = input()
  293. if (set_in(dict_keys(attrs), attr_name)):
  294. output("New value?")
  295. unset_attribute(model, model_name, attr_name)
  296. instantiate_attribute(model, model_name, attr_name, input())
  297. output("Modified!")
  298. else:
  299. output("No such attribute!")
  300. else:
  301. output("No such model!")
  302. elif (cmd == "attr_add"):
  303. String model_name
  304. output("Which model do you want to assign an attribute to?")
  305. model_name = input()
  306. if (dict_in(model["model"], model_name)):
  307. Element attrs
  308. attrs = getAttributeList(model, model_name)
  309. String attr_name
  310. output("Which attribute do you wish to assign?")
  311. attr_name = input()
  312. if (set_in(dict_keys(attrs), attr_name)):
  313. output("Value of attribute?")
  314. instantiate_attribute(model, model_name, attr_name, input())
  315. output("Added attribute!")
  316. else:
  317. output("No such attribute!")
  318. else:
  319. output("No such model!")
  320. elif (cmd == "attr_del"):
  321. String model_name
  322. output("Which model do you want to remove an attribute of?")
  323. model_name = input()
  324. if (dict_in(model["model"], model_name)):
  325. Element attrs
  326. attrs = getAttributeList(model, model_name)
  327. output(print_dict(attrs))
  328. String attr_name
  329. output("Which attribute do you want to delete?")
  330. attr_name = input()
  331. if (set_in(dict_keys(attrs), attr_name)):
  332. unset_attribute(model, model_name, attr_name)
  333. else:
  334. output("No such attribute!")
  335. else:
  336. output("No such model!")
  337. elif (cmd == "delete"):
  338. output("What is the name of the element you want to delete?")
  339. cmd = input()
  340. if (dict_in(model["model"], cmd)):
  341. model_delete_element(model, cmd)
  342. output("Deleted!")
  343. else:
  344. output("No such element; aborting")
  345. elif (cmd == "rename"):
  346. output("Old name?")
  347. String old_name_e
  348. old_name_e = input()
  349. if (dict_in(model["model"], old_name_e)):
  350. output("New name?")
  351. String new_name_e
  352. new_name_e = input()
  353. if (dict_in(model["model"], new_name_e)):
  354. output("New name already used; aborting")
  355. else:
  356. dict_add(model["model"], new_name_e, model["model"][old_name_e])
  357. dict_delete(model["model"], old_name_e)
  358. output("Rename complete!")
  359. else:
  360. output("Unknown element; aborting")
  361. elif (cmd == "list"):
  362. Element keys_m
  363. keys_m = dict_keys(model["model"])
  364. output("List of all elements:")
  365. String v_m
  366. while (read_nr_out(keys_m) > 0):
  367. v_m = set_pop(keys_m)
  368. // Filter out anonymous objects
  369. typename = getName(model["metamodel"], dict_read_node(model["type_mapping"], model["model"][v_m]))
  370. if (bool_not(string_startswith(v_m, "__"))):
  371. output(((" " + v_m) + " : ") + typename)
  372. elif (cmd == "read"):
  373. output("Element to read?")
  374. cmd = input()
  375. if (dict_in(model["model"], cmd)):
  376. Element read_elem
  377. read_elem = model["model"][cmd]
  378. metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
  379. output("Name: " + cmd)
  380. output("Type: " + getName(model["metamodel"], metamodel_element_pn))
  381. if (is_edge(read_elem)):
  382. output("Source: " + getName(model, read_edge_src(read_elem)))
  383. output("Destination: " + getName(model, read_edge_dst(read_elem)))
  384. if (cast_v2s(read_elem) != "None"):
  385. output("Value: " + cast_v2s(read_elem))
  386. output("Defines attributes:")
  387. attr_list_pn = getInstantiatableAttributes(model, read_elem)
  388. attr_keys_pn = dict_keys(attr_list_pn)
  389. while (0 < read_nr_out(attr_keys_pn)):
  390. attr_key_pn = set_pop(attr_keys_pn)
  391. output((((" " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
  392. output("Attributes:")
  393. attr_list_pn = getAttributeList(model, cmd)
  394. attr_keys_pn = dict_keys(attr_list_pn)
  395. while (0 < read_nr_out(attr_keys_pn)):
  396. attr_key_pn = set_pop(attr_keys_pn)
  397. output(((((" " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, getName(model, read_elem), attr_key_pn)))
  398. else:
  399. output("Unknown element; aborting")
  400. elif (cmd == "verify"):
  401. output(conformance_scd(model))
  402. elif (cmd == "types"):
  403. Element keys_t
  404. keys_t = dict_keys(model["metamodel"]["model"])
  405. output("List of types:")
  406. String v_t
  407. while (read_nr_out(keys_t) > 0):
  408. v_t = set_pop(keys_t)
  409. if (bool_not(string_startswith(v_t, "__"))):
  410. output(string_join((" " + v_t) + " : ", getName(model["metamodel"]["metamodel"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
  411. elif (cmd == "retype"):
  412. output("Element to retype?")
  413. String elementname
  414. elementname = input()
  415. if (dict_in(model["model"], elementname)):
  416. output("New type")
  417. typename = input()
  418. if (dict_in(model["metamodel"]["model"], typename)):
  419. // OK, do the retyping
  420. // First try removing the previous type if it exists
  421. dict_delete(model["type_mapping"], model["model"][elementname])
  422. // Now add the new type
  423. dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
  424. output("Retyped!")
  425. else:
  426. output("Unknown type; aborting")
  427. else:
  428. output("Unknown element; aborting")
  429. elif (cmd == "switch"):
  430. bottom = bool_not(bottom)
  431. Element tmp_model
  432. tmp_model = model
  433. model = other_metamodel
  434. other_metamodel = tmp_model
  435. if (bottom):
  436. // The type mapping we are using is probably not complete for our model
  437. // so we completely recreate it from the model we have.
  438. output("Switching to conformance bottom mode!")
  439. generate_bottom_type_mapping(model)
  440. else:
  441. // We already switched the models and such, so we are already done!
  442. output("Switching to linguistic metamodel!")
  443. elif (bool_and(dict_in(pn_operations(), cmd), bool_not(bottom))):
  444. // A model-specific operation, so execute that one
  445. Element specific_op
  446. specific_op = dict_read(pn_operations(), cmd)
  447. specific_op(model)
  448. else:
  449. output("Unknown command; aborting")
  450. output("Use command 'help' to get a list of available commands")
  451. Element function initial_prompt():
  452. output("Welcome to the Model Management Interface, running live on the Modelverse!")
  453. output("Use 'help' command for a list of possible commands")
  454. String command
  455. Element root
  456. Element metamodel
  457. String name
  458. Element my_model
  459. String mm_name
  460. root = create_metamodels()
  461. while (True):
  462. output("Please give your command.")
  463. command = input()
  464. if (command == "help"):
  465. output("Currently no model is loaded, so your operations are limited to:")
  466. output(" new -- Create a new model and save it for future use")
  467. output(" load -- Load a previously made model")
  468. output(" rename -- Rename a previously made model")
  469. output(" delete -- Delete a previously made model")
  470. output(" list -- Show a list of all stored models")
  471. output(" help -- Show a list of possible commands")
  472. elif (command == "new"):
  473. output("Metamodel to instantiate?")
  474. mm_name = input()
  475. if (dict_in(root, mm_name)):
  476. output("Name of model?")
  477. name = input()
  478. if (dict_in(root, name)):
  479. output("Model exists; aborting")
  480. else:
  481. my_model = instantiate_model(root[mm_name])
  482. dict_add(root, name, my_model)
  483. petrinet_loaded(my_model)
  484. else:
  485. output("Unknown metamodel; aborting")
  486. elif (command == "load"):
  487. output("Model to load?")
  488. name = input()
  489. if (dict_in(root, name)):
  490. my_model = root[name]
  491. petrinet_loaded(my_model)
  492. else:
  493. output("Model not found; aborting")
  494. elif (command == "list"):
  495. Element keys
  496. String m_menu_list
  497. keys = dict_keys(root)
  498. output("Found models:")
  499. while (read_nr_out(keys) > 0):
  500. m_menu_list = set_pop(keys)
  501. output(((" " + m_menu_list) + " : ") + reverseNameLookup(root, root[m_menu_list]["metamodel"]))
  502. elif (command == "delete"):
  503. output("Model to delete?")
  504. name = input()
  505. if (dict_in(root, name)):
  506. dict_delete(root, name)
  507. output("Deleted!")
  508. else:
  509. output("Model not found; aborting")
  510. elif (command == "rename"):
  511. output("Old name?")
  512. String old_name
  513. old_name = input()
  514. if (dict_in(root, old_name)):
  515. output("New name?")
  516. String new_name
  517. new_name = input()
  518. if (dict_in(root, new_name)):
  519. output("Model exists; aborting")
  520. else:
  521. dict_add(root, new_name, root[old_name])
  522. dict_delete(root, old_name)
  523. output("Rename complete!")
  524. else:
  525. output("Model not found; aborting")
  526. else:
  527. output("Command not recognized, use 'help' for a list of possible commands")
  528. Void function main():
  529. //initial_prompt()
  530. log("==========================================================================")
  531. log("=== creating metamodels")
  532. Element root
  533. root = create_metamodels()
  534. log("=== load instantiation of transformation metamodel")
  535. Element transf
  536. transf = petrinet_transformation(root)
  537. log("=== check conformance of transformation")
  538. log(conformance_scd(transf))
  539. log("=== run transform")
  540. tf_transform(transf, create_node())
  541. log("=== done")
  542. log("==========================================================================")
  543. return