123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- import wrappers.modelverse as mv
- from verifier import verify
- from evolution.node_ops import NodeDelete, NodeRetype, NodeAdd
- from evolution.edge_ops import EdgeAdd, EdgeDel
- from evolution.upload_ops import upload_evolution_ops
- from sketchUI.main import run_ui
- def upload_graph_MM():
- print("Uploading graph metamodel ...")
- try:
- mv.model_delete("formalisms/graphMM")
- except mv.UnknownLocation:
- pass
- content = open("models/sketching/graphMM.mvc").read()
- mv.model_add("formalisms/graphMM", "formalisms/SimpleClassDiagrams", content)
- def upload_example_models():
- print("Uploading example models ...")
- # clear all example models
- try:
- mv.model_delete("models/example")
- except mv.UnknownLocation:
- # folder does not exist, ignore
- pass
- content = open("models/sketching/example_model_1.mvc").read()
- mv.model_add("models/example/ex1", "formalisms/graphMM", content)
- mv.verify("models/example/ex1", "formalisms/graphMM")
- content = open("models/sketching/example_model_2.mvc").read()
- mv.model_add("models/example/ex2", "formalisms/graphMM", content)
- mv.verify("models/example/ex2", "formalisms/graphMM")
- def upload_instance_model():
- print("Uploading instance model ...")
- # clear all example models
- try:
- mv.model_delete("models/instance")
- except mv.UnknownLocation:
- # folder does not exist, ignore
- pass
- content = open("models/sketching/instance_model.mvc").read()
- mv.model_add("models/instance/im1", "formalisms/graphMM", content)
- mv.verify("models/instance/im1", "formalisms/graphMM")
- def upload_rename_alc():
- print("Loading rename ALC ...")
- try:
- mv.model_delete("models/graph_ops/rename")
- except mv.UnknownLocation:
- pass
- mv.transformation_add_AL({"instance": "formalisms/graphMM"}, {"rename_out": "formalisms/graphMM"},
- "models/graph_ops/rename", open("models/lucas/rename.alc").read())
- def exec_rename_alc():
- print("Executing rename ALC ...")
- try:
- mv.model_delete("models/rename_out")
- except mv.UnknownLocation:
- pass
- """
- ctrl = Controller(keep_running=False)
- thrd = Thread(target=ctrl.start)
- thrd.daemon = True
- thrd.start()
- """
- mv.transformation_execute_AL("models/graph_ops/rename",
- {"instance": "models/instance/im1"},
- {"rename_out": "models/rename_out"})
- """
- # TODO: Wait until ALC is ready to accept input, maybe there is a way to wait for output events?
- try:
- while True:
- # pass data to ALC via statechart
- inp = raw_input("Input:")
- ctrl.addInput(Event("data_inp", "datap", [inp]))
- except KeyboardInterrupt:
- ctrl.addInput(Event("terminate", "inp"))
- print("Done")
- """
- """
- def upload_verify_alc():
- print("Loading verify ALC ...")
- try:
- mv.model_delete("models/graph_ops/verify")
- except mv.UnknownError:
- pass
- mv.transformation_add_AL({"instance": "formalisms/graphMM"}, {"out": "formalisms/graphMM"},
- "models/graph_ops/verify", open("models/lucas/verify.alc").read())
- def exec_verify_alc():
- print("Executing verify ALC ...")
- try:
- mv.model_delete("models/verify_out")
- except mv.UnknownError:
- pass
- mv.transformation_execute_AL("models/graph_ops/verify",
- {"instance": "models/instance/im1"},
- {"out": "models/verify_out"})
- """
- def _callback(model):
- print("foo")
- if __name__ == "__main__":
- import sys
- mv.init()
- mv.login("admin", "admin")
- upload_graph_MM()
- #upload_example_models()
- #upload_instance_model()
- #sys.exit()
- from commons import new_example_model
- exm = new_example_model()
- run_ui(mode="EXM", model=exm)
- #run_ui(mode="IM", model="models/instance/im1")
- print("verify ... ")
- print(mv.verify(exm, "formalisms/graphMM"))
- sys.exit(0)
- #upload_instance_model()
- # evolution with manual transformations in python code
- #print("Uploading evolution operations ...")
- #upload_evolution_ops()
- #edgedel = EdgeDel()
- #print("Performing local edge del ...")
- #edgedel.execute("models/example/ex2", "e3", local=True, check_last=True)
- #print(mv.element_list_nice("models/example/ex1"))
- #print(mv.element_list_nice("models/example/ex2"))
- #print(mv.element_list_nice("models/instance/im1"))
- """
- print("Adding manual transformation ...")
- mv.transformation_add_MANUAL({}, {"gm":"formalisms/graphMM"}, "graph_ops/new_example_model")
- print("Adding process model ...")
- mv.model_add("process/my_pm", "formalisms/ProcessModel", open("models/sketching/process_model.mvc").read())
- print("Executing process model ...")
- mv.process_execute("process/my_pm", {"exm":"models/example/ex1"}, {"graph_ops/new_example_model":_callback})
- """
- """
- print("Retyping node ...")
- retype_node("models/example/ex1", "n2", "PesonalComputer", local=False)
- upload_rename_alc()
- exec_rename_alc()
- upload_verify_alc()
- exec_verify_alc()
- # verification with pure python wrapper calls
- print("Verifying instance model ...")
- ret = verify("models/instance/im1")
- if not ret["OK"]:
- print(ret["error"])
- else:
- print("Verify OK")
- """
|