main.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import wrappers.modelverse as mv
  2. from verifier import verify
  3. from evolution.node_ops import NodeDelete, NodeRetype, NodeAdd
  4. from evolution.edge_ops import EdgeAdd, EdgeDel
  5. from evolution.upload_ops import upload_evolution_ops
  6. from sketchUI.main import run_ui
  7. def upload_graph_MM():
  8. print("Uploading graph metamodel ...")
  9. try:
  10. mv.model_delete("formalisms/graphMM")
  11. except mv.UnknownLocation:
  12. pass
  13. content = open("models/sketching/graphMM.mvc").read()
  14. mv.model_add("formalisms/graphMM", "formalisms/SimpleClassDiagrams", content)
  15. def upload_example_models():
  16. print("Uploading example models ...")
  17. # clear all example models
  18. try:
  19. mv.model_delete("models/example")
  20. except mv.UnknownLocation:
  21. # folder does not exist, ignore
  22. pass
  23. content = open("models/sketching/example_model_1.mvc").read()
  24. mv.model_add("models/example/ex1", "formalisms/graphMM", content)
  25. mv.verify("models/example/ex1", "formalisms/graphMM")
  26. content = open("models/sketching/example_model_2.mvc").read()
  27. mv.model_add("models/example/ex2", "formalisms/graphMM", content)
  28. mv.verify("models/example/ex2", "formalisms/graphMM")
  29. def upload_instance_model():
  30. print("Uploading instance model ...")
  31. # clear all example models
  32. try:
  33. mv.model_delete("models/instance")
  34. except mv.UnknownLocation:
  35. # folder does not exist, ignore
  36. pass
  37. content = open("models/sketching/instance_model.mvc").read()
  38. mv.model_add("models/instance/im1", "formalisms/graphMM", content)
  39. mv.verify("models/instance/im1", "formalisms/graphMM")
  40. def upload_rename_alc():
  41. print("Loading rename ALC ...")
  42. try:
  43. mv.model_delete("models/graph_ops/rename")
  44. except mv.UnknownLocation:
  45. pass
  46. mv.transformation_add_AL({"instance": "formalisms/graphMM"}, {"rename_out": "formalisms/graphMM"},
  47. "models/graph_ops/rename", open("models/lucas/rename.alc").read())
  48. def exec_rename_alc():
  49. print("Executing rename ALC ...")
  50. try:
  51. mv.model_delete("models/rename_out")
  52. except mv.UnknownLocation:
  53. pass
  54. """
  55. ctrl = Controller(keep_running=False)
  56. thrd = Thread(target=ctrl.start)
  57. thrd.daemon = True
  58. thrd.start()
  59. """
  60. mv.transformation_execute_AL("models/graph_ops/rename",
  61. {"instance": "models/instance/im1"},
  62. {"rename_out": "models/rename_out"})
  63. """
  64. # TODO: Wait until ALC is ready to accept input, maybe there is a way to wait for output events?
  65. try:
  66. while True:
  67. # pass data to ALC via statechart
  68. inp = raw_input("Input:")
  69. ctrl.addInput(Event("data_inp", "datap", [inp]))
  70. except KeyboardInterrupt:
  71. ctrl.addInput(Event("terminate", "inp"))
  72. print("Done")
  73. """
  74. """
  75. def upload_verify_alc():
  76. print("Loading verify ALC ...")
  77. try:
  78. mv.model_delete("models/graph_ops/verify")
  79. except mv.UnknownError:
  80. pass
  81. mv.transformation_add_AL({"instance": "formalisms/graphMM"}, {"out": "formalisms/graphMM"},
  82. "models/graph_ops/verify", open("models/lucas/verify.alc").read())
  83. def exec_verify_alc():
  84. print("Executing verify ALC ...")
  85. try:
  86. mv.model_delete("models/verify_out")
  87. except mv.UnknownError:
  88. pass
  89. mv.transformation_execute_AL("models/graph_ops/verify",
  90. {"instance": "models/instance/im1"},
  91. {"out": "models/verify_out"})
  92. """
  93. def _callback(model):
  94. print("foo")
  95. if __name__ == "__main__":
  96. import sys
  97. mv.init()
  98. mv.login("admin", "admin")
  99. upload_graph_MM()
  100. #upload_example_models()
  101. #upload_instance_model()
  102. #sys.exit()
  103. from commons import new_example_model
  104. exm = new_example_model()
  105. run_ui(mode="EXM", model=exm)
  106. #run_ui(mode="IM", model="models/instance/im1")
  107. print("verify ... ")
  108. print(mv.verify(exm, "formalisms/graphMM"))
  109. sys.exit(0)
  110. #upload_instance_model()
  111. # evolution with manual transformations in python code
  112. #print("Uploading evolution operations ...")
  113. #upload_evolution_ops()
  114. #edgedel = EdgeDel()
  115. #print("Performing local edge del ...")
  116. #edgedel.execute("models/example/ex2", "e3", local=True, check_last=True)
  117. #print(mv.element_list_nice("models/example/ex1"))
  118. #print(mv.element_list_nice("models/example/ex2"))
  119. #print(mv.element_list_nice("models/instance/im1"))
  120. """
  121. print("Adding manual transformation ...")
  122. mv.transformation_add_MANUAL({}, {"gm":"formalisms/graphMM"}, "graph_ops/new_example_model")
  123. print("Adding process model ...")
  124. mv.model_add("process/my_pm", "formalisms/ProcessModel", open("models/sketching/process_model.mvc").read())
  125. print("Executing process model ...")
  126. mv.process_execute("process/my_pm", {"exm":"models/example/ex1"}, {"graph_ops/new_example_model":_callback})
  127. """
  128. """
  129. print("Retyping node ...")
  130. retype_node("models/example/ex1", "n2", "PesonalComputer", local=False)
  131. upload_rename_alc()
  132. exec_rename_alc()
  133. upload_verify_alc()
  134. exec_verify_alc()
  135. # verification with pure python wrapper calls
  136. print("Verifying instance model ...")
  137. ret = verify("models/instance/im1")
  138. if not ret["OK"]:
  139. print(ret["error"])
  140. else:
  141. print("Verify OK")
  142. """