PM_to_FTG.alc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. Boolean function main(model : Element):
  5. // Find all activities
  6. Element known_activities
  7. Element known_formalisms
  8. Element activity_mapping
  9. Element formalism_mapping
  10. Element elems
  11. String elem
  12. String type
  13. String new_elem
  14. activity_mapping = dict_create()
  15. formalism_mapping = dict_create()
  16. known_activities = dict_create()
  17. known_formalisms = dict_create()
  18. elems = allInstances(model, "PM/Exec")
  19. while (set_len(elems) > 0):
  20. elem = set_pop(elems)
  21. type = read_attribute(model, elem, "name")
  22. if dict_in(known_activities, type):
  23. new_elem = known_activities[type]
  24. else:
  25. new_elem = instantiate_node(model, "FTG/Activity", "")
  26. instantiate_attribute(model, new_elem, "name", type)
  27. dict_add(known_activities, type, new_elem)
  28. dict_add(activity_mapping, elem, new_elem)
  29. elems = allInstances(model, "PM/Data")
  30. while (set_len(elems) > 0):
  31. elem = set_pop(elems)
  32. type = read_attribute(model, elem, "type")
  33. if dict_in(known_formalisms, type):
  34. new_elem = known_formalisms[type]
  35. else:
  36. new_elem = instantiate_node(model, "FTG/Formalism", "")
  37. instantiate_attribute(model, new_elem, "name", type)
  38. dict_add(known_formalisms, type, new_elem)
  39. dict_add(formalism_mapping, elem, new_elem)
  40. elems = allInstances(model, "PM/Produces")
  41. while (set_len(elems) > 0):
  42. elem = set_pop(elems)
  43. new_elem = instantiate_link(model, "FTG/Produces", "", activity_mapping[readAssociationSource(model, elem)], formalism_mapping[readAssociationDestination(model, elem)])
  44. instantiate_attribute(model, new_elem, "name", read_attribute(model, elem, "name"))
  45. elems = allInstances(model, "PM/Consumes")
  46. while (set_len(elems) > 0):
  47. elem = set_pop(elems)
  48. new_elem = instantiate_link(model, "FTG/Consumes", "", formalism_mapping[readAssociationDestination(model, elem)], activity_mapping[readAssociationSource(model, elem)])
  49. instantiate_attribute(model, new_elem, "name", read_attribute(model, elem, "name"))
  50. return True!