import shutil
import sys
import os
sys.path.append("wrappers")
from modelverse import *

init()
login("admin", "admin")

model_add("formalisms/ReachabilityGraph", "formalisms/SimpleClassDiagrams", open("models/ReachabilityGraph/metamodels/reachability_graph.mvc", "r").read())
model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("models/PetriNets/metamodels/PetriNets.mvc", 'r').read())
model_add("formalisms/Encapsulated_PetriNet", "formalisms/SimpleClassDiagrams", open("models/EncapsulatedPetriNets/metamodels/epn.mvc", 'r').read())
model_add("formalisms/PW_Plant", "formalisms/SimpleClassDiagrams", open("models/PowerWindow/metamodels/plant.mvc", 'r').read())
model_add("formalisms/PW_Environment", "formalisms/SimpleClassDiagrams", open("models/PowerWindow/metamodels/environment.mvc", 'r').read())
model_add("formalisms/PW_Control", "formalisms/SimpleClassDiagrams", open("models/PowerWindow/metamodels/control.mvc", 'r').read())
model_add("formalisms/Requirements", "formalisms/SimpleClassDiagrams", open("models/PowerWindow/metamodels/requirements.mvc", 'r').read())
model_add("formalisms/Query", "formalisms/SimpleClassDiagrams", open("models/SafetyQuery/metamodels/query.mvc", 'r').read())
model_add("formalisms/Architecture", "formalisms/SimpleClassDiagrams", open("models/PowerWindow/metamodels/architecture.mvc", 'r').read())

model_add("models/pm_powerwindow", "formalisms/ProcessModel", open("models/PowerWindow/PM_analyze.mvc", 'r').read())
model_add("formalisms/FormalismTransformationGraph", "formalisms/SimpleClassDiagrams", open("models/FTGPM/metamodels/FTG_MM.mvc", 'r').read())

def add_traceability(model):
    instantiate(model, "Association", edge=("PM/Exec", "FTG/Activity"), ID="activity_link")
    instantiate(model, "Association", edge=("PM/Data", "FTG/Formalism"), ID="formalism_link")

transformation_add_AL({"PM": "formalisms/ProcessModel"}, {"FTG": "formalisms/FormalismTransformationGraph"}, "models/generate_FTG", open("models/FTGPM/transformations/PM_to_FTG.alc", 'r').read(), add_traceability)

transformation_execute_AL("models/generate_FTG", {"PM": "models/pm_powerwindow"}, {"FTG": "models/ftg_powerwindow"})
for i in element_list_nice("models/ftg_powerwindow"):
    print(i)
