modelverse_connector.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. class ModelVerseConnector {
  2. constructor(address) {
  3. ModelVerseConnector.taskname = "task_manager";
  4. ModelVerseConnector.address = (address == undefined) ? "http://127.0.0.1:8001" : address;
  5. ModelVerseConnector.ERROR = 0;
  6. ModelVerseConnector.WORKING = 1;
  7. ModelVerseConnector.OKAY = 2;
  8. ModelVerseConnector.curr_model = null;
  9. }
  10. static set_status(status) {
  11. let red = "rgb(220,20,60)";
  12. let yellow = "rgb(218,165,32)";
  13. let green = "rgb(50,205,50)";
  14. let colours = [red, yellow, green];
  15. let set_colour = function (colour) {
  16. let mv_toolbar = $('#div_toolbar_\\2f Toolbars\\2f ModelVerse\\2f ModelVerse\\2e buttons\\2e model');
  17. mv_toolbar.css("background-color", colour)
  18. };
  19. set_colour(colours[status]);
  20. }
  21. static load_MV_model(AS, CS) {
  22. return new Promise(
  23. function (resolve, reject) {
  24. console.log("Load MV Model");
  25. console.log(AS);
  26. console.log(CS);
  27. let metamodel = "Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram.defaultIcons.metamodel";
  28. let class_type = "/Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram.defaultIcons/ClassIcon";
  29. DataUtils.loadmm(metamodel,
  30. function(){
  31. console.log("Metamodel loaded: " + metamodel);
  32. });
  33. let model_classes = [];
  34. let model_associations = [];
  35. let model_inheris = [];
  36. let model_attribs = {};
  37. for (let i in AS) {
  38. let obj = AS[i];
  39. let obj_type = obj["__type"];
  40. if (obj_type == "Class") {
  41. model_classes.push(obj["__id"]);
  42. }else if (obj_type == "Association"){
  43. model_associations.push([obj["__source"], obj["__target"], obj["__id"]]);
  44. }else if (obj_type == "Inheritance"){
  45. model_inheris.push([obj["__source"], obj["__target"]]);
  46. }else if (obj_type == "AttributeLink") {
  47. if (model_attribs[obj["__source"]] == undefined){
  48. model_attribs[obj["__source"]] = [];
  49. }
  50. model_attribs[obj["__source"]].push([obj["__target"], obj["__id"]]);
  51. }
  52. }
  53. let class_locs = {};
  54. for (const cs_ele of CS){
  55. if (!(cs_ele["__type"] == "Group")){
  56. continue;
  57. }
  58. let asid = cs_ele["__asid"];
  59. let pos = [cs_ele["x"], cs_ele["y"]];
  60. class_locs[asid] = pos;
  61. }
  62. let ele_ids = {};
  63. __typeToCreate = class_type;
  64. let map_promises = [];
  65. for (const id of model_classes){
  66. map_promises.push(new Promise(function(resolve, reject){
  67. let updateClass =
  68. function(status, resp){
  69. let data = JSON.parse(resp);
  70. let uri = class_type + "/" + data["data"] + ".instance";
  71. ele_ids[id] = uri;
  72. let changes = {"name": id};
  73. if (model_attribs[id] != undefined){
  74. let attrib_changes = [];
  75. for (let attrib of model_attribs[id]){
  76. //console.log(attrib);
  77. let attrib_change = {
  78. "name": attrib[1],
  79. "type" : attrib[0]
  80. };
  81. attrib_changes.push(attrib_change);
  82. }
  83. changes["attributes"] = attrib_changes;
  84. }
  85. DataUtils.update(uri, changes);
  86. resolve();
  87. };
  88. let pos = class_locs[id];
  89. if (pos == undefined || pos == null){
  90. pos = [100, 100];
  91. }
  92. let vert_offset = 200;
  93. DataUtils.create(pos[0], pos[1] + vert_offset, updateClass);
  94. }));
  95. }
  96. Promise.all(map_promises).then(function(){
  97. for (const inheri of model_inheris){
  98. let connectionType = "/Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram.defaultIcons/InheritanceLink.type";
  99. let source = ele_ids[inheri[0]];
  100. let target = ele_ids[inheri[1]];
  101. if (source == undefined || target == undefined){
  102. console.log("ERROR: Can't create inheritance between " + inheri[0] + " and " + inheri[1]);
  103. continue;
  104. }
  105. HttpUtils.httpReq(
  106. 'POST',
  107. HttpUtils.url(connectionType,__NO_USERNAME),
  108. {'src':source,
  109. 'dest':target,
  110. 'pos':undefined,
  111. 'segments':undefined});
  112. }
  113. })
  114. .then(function(){
  115. let assoc_create_promises = [];
  116. for (const assoc of model_associations){
  117. assoc_create_promises.push(new Promise(function(resolve, reject){
  118. let connectionType = "/Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram.defaultIcons/AssociationLink.type";
  119. let source = ele_ids[assoc[0]];
  120. let target = ele_ids[assoc[1]];
  121. if (source == undefined || target == undefined){
  122. console.log("ERROR: Can't create association between " + assoc[0] + " and " + assoc[1]);
  123. resolve();
  124. }
  125. let assoc_create_callback = function(status, resp){
  126. let id = JSON.parse(resp)["data"];
  127. let assoc_id = connectionType.replace(".type", "/") + id + ".instance";
  128. ele_ids[assoc[2]] = assoc_id;
  129. resolve();
  130. };
  131. HttpUtils.httpReq(
  132. 'POST',
  133. HttpUtils.url(connectionType,__NO_USERNAME),
  134. {'src':source,
  135. 'dest':target,
  136. 'pos':undefined,
  137. 'segments':undefined},
  138. assoc_create_callback);
  139. }));
  140. }
  141. Promise.all(assoc_create_promises).then(function(){
  142. for (const assoc of model_associations){
  143. let uri = ele_ids[assoc[2]];
  144. let changes = {"name" : assoc[2]};
  145. console.log("Updating " + uri);
  146. DataUtils.update(uri, changes);
  147. }
  148. });
  149. });
  150. resolve();
  151. });
  152. }
  153. /*********COMMUNICATION FUNCTIONS**********/
  154. static send_command(param_dict) {
  155. return new Promise(
  156. function (resolve, reject) {
  157. let callback = function (status, resp) {
  158. if (utils.isHttpSuccessCode(status)) {
  159. //console.log("send_command Resolve: " + resp);
  160. resolve(resp);
  161. } else {
  162. console.log("send_command Reject: " + resp);
  163. reject(resp);
  164. }
  165. };
  166. if (!("op" in param_dict)) {
  167. param_dict["op"] = "set_input";
  168. }
  169. if (!("taskname" in param_dict)) {
  170. param_dict["taskname"] = ModelVerseConnector.taskname;
  171. }
  172. let params = "";
  173. for (const [key, value] of Object.entries(param_dict)) {
  174. params += key + "=" + value + "&";
  175. }
  176. //take off last &
  177. params = params.slice(0, -1);
  178. console.log("Sending: " + params);
  179. HttpUtils.httpReq("POST", ModelVerseConnector.address,
  180. params,
  181. callback
  182. );
  183. });
  184. }
  185. static get_output() {
  186. return new Promise(
  187. function (resolve, reject) {
  188. let callback = function (status, resp) {
  189. if (utils.isHttpSuccessCode(status)) {
  190. console.log("get_output Resolve: " + resp);
  191. resolve(resp);
  192. } else {
  193. console.log("get_output reject: " + resp);
  194. reject(resp);
  195. }
  196. };
  197. let params = "op=get_output&taskname=" + ModelVerseConnector.taskname;
  198. HttpUtils.httpReq("POST", ModelVerseConnector.address,
  199. params,
  200. callback
  201. );
  202. }
  203. );
  204. }
  205. /*********END COMMUNICATION FUNCTIONS**********/
  206. /*********WRAPPER FUNCTIONS**********/
  207. static connect(username_param, password_param) {
  208. console.log("Connecting to: " + ModelVerseConnector.address);
  209. ModelVerseConnector.set_status(ModelVerseConnector.WORKING);
  210. let username = username_param || "admin";
  211. let password = password_param || "admin";
  212. let username_params = {
  213. "value": "\"" + username + "\""
  214. };
  215. let password_params = {
  216. "value": "\"" + password + "\""
  217. };
  218. let quiet_mode_params = {
  219. "value": "\"quiet\""
  220. };
  221. this.get_output().then(
  222. function(data){
  223. data = data.replace(/"/g, "");
  224. ModelVerseConnector.taskname = data;
  225. }
  226. )
  227. .then(() => this.send_command(username_params)).then(this.get_output)
  228. .then(() => this.send_command(password_params)).then(this.get_output)
  229. .then(() => this.send_command(quiet_mode_params)).then(this.get_output)
  230. .then(this.get_output)
  231. .then(function () {
  232. ModelVerseConnector.set_status(ModelVerseConnector.OKAY);
  233. })
  234. .catch(
  235. function () {
  236. WindowManagement.openDialog(_ERROR, 'failed to login to the ModelVerse!');
  237. ModelVerseConnector.set_status(ModelVerseConnector.ERROR);
  238. }
  239. );
  240. };
  241. //TODO: Cache this data if too slow
  242. static async get_files_in_folder(folder_name){
  243. return await ModelVerseConnector.model_list(folder_name);
  244. }
  245. static model_list(folder_name){
  246. return new Promise(function(resolve, reject) {
  247. console.log("Listing models in: '" + folder_name + "'");
  248. let folder_param = folder_name;
  249. //fix slashes on filename
  250. if (folder_param.endsWith("/")){
  251. folder_param = folder_param.slice(0, -1);
  252. }
  253. if (folder_param.startsWith("/")){
  254. folder_param = folder_param.slice(1);
  255. }
  256. let model_types = {
  257. "data": utils.jsons(["model_list", folder_param])
  258. };
  259. ModelVerseConnector.send_command(model_types).then(ModelVerseConnector.get_output)
  260. .then(function (data) {
  261. let files = [];
  262. data = data.replace("Success: ", "");
  263. let new_files = JSON.parse(data).split("\n");
  264. for (let i in new_files) {
  265. let file = new_files[i];
  266. files.push(folder_name + file);
  267. }
  268. files.sort();
  269. resolve(files);
  270. });
  271. });
  272. }
  273. static choose_model(){
  274. console.log("Choosing model: ");
  275. let folders = [""];
  276. let files = [];
  277. ModelVerseConnector.set_status(ModelVerseConnector.WORKING);
  278. if (ModelVerseConnector.curr_model){
  279. let command = {"data": utils.jsons(["drop"])};
  280. this.send_command(command).then(this.get_output)
  281. .then(function(data){
  282. //console.log(command);
  283. //console.log(data);
  284. ModelVerseConnector.curr_model = null;
  285. });
  286. }
  287. let startDir = "/";
  288. let fileb = FileBrowser.getFileBrowser(ModelVerseConnector.get_files_in_folder, false, false, __getRecentDir(startDir));
  289. let feedback = GUIUtils.getTextSpan('', "feedback");
  290. let title = "ModelVerse Explorer";
  291. let callback = function (filenames) {
  292. ModelVerseConnector.load_model(filenames[0]);
  293. };
  294. GUIUtils.setupAndShowDialog(
  295. [fileb['filebrowser'], null, null, feedback],
  296. function () {
  297. let value = [fileb['getselection']()];
  298. if (value.length > 0 && value[0] != "" && startDir) {
  299. __setRecentDir(startDir, value[0].substring(0, value[0].lastIndexOf('/') + 1));
  300. }
  301. return value;
  302. },
  303. __TWO_BUTTONS,
  304. title,
  305. callback);
  306. ModelVerseConnector.set_status(ModelVerseConnector.OKAY);
  307. }
  308. static load_model(filename) {
  309. let model_name = filename;
  310. let metamodel = "formalisms/SimpleClassDiagrams";
  311. //fix slashes on filename
  312. if (model_name.endsWith("/")){
  313. model_name = model_name.slice(0, -1);
  314. }
  315. if (model_name.startsWith("/")){
  316. model_name = model_name.slice(1);
  317. }
  318. console.log("Loading model: " + model_name);
  319. ModelVerseConnector.set_status(ModelVerseConnector.WORKING);
  320. ModelVerseConnector.curr_model = filename;
  321. //get CS for model
  322. let SCD = "formalisms/SimpleClassDiagrams";
  323. let MM_render = "formalisms/SCD_graphical";
  324. let render_trans_model = "models/render_SCD";
  325. let render_MM = this.get_render_mm();
  326. let render_trans_code = this.get_render_trans();
  327. let render_model_add = {
  328. 'data': encodeURIComponent(utils.jsons(["model_add", SCD, MM_render, render_MM]))};
  329. let transformation_between = {
  330. 'data' : encodeURIComponent(utils.jsons(["transformation_add_AL", "rendered", MM_render, "abstract", SCD, "", "rendered", MM_render, "", render_trans_model]))
  331. };
  332. let transformation_data = {
  333. 'data' : encodeURIComponent(utils.jsons(["transformation_add_AL", render_trans_code]))
  334. };
  335. let model_rendered = {
  336. 'data' : encodeURIComponent(utils.jsons(["model_render", model_name, render_trans_model, "models/rendered_model"]))
  337. };
  338. //get AS for model
  339. let model_types = {
  340. "data": utils.jsons(["model_types", model_name])
  341. };
  342. let model_modify = {
  343. "data": utils.jsons(["model_modify", model_name, metamodel])
  344. };
  345. let model_dump = {
  346. "data": utils.jsons(["JSON"])
  347. };
  348. let model_CS = null;
  349. //CS COMMANDS
  350. //TODO: only need to add models if not present
  351. this.send_command(render_model_add).then(this.get_output)
  352. .then(this.send_command(transformation_between)).then(this.get_output)
  353. .then(this.send_command({})).then(this.get_output)
  354. .then(this.send_command(transformation_data)).then(this.get_output)
  355. .then(this.send_command(model_rendered)).then(this.get_output)
  356. .then(function(data){
  357. data = data.replace("Success: ", "");
  358. model_CS = eval(JSON.parse(data));
  359. })
  360. //AS COMMANDS
  361. .then(this.send_command(model_types)).then(this.get_output)
  362. .then(function(data){
  363. console.log("model_types");
  364. console.log(data);
  365. })
  366. .then(this.send_command(model_modify)).then(this.get_output)
  367. .then(function(data){
  368. console.log("model_modify");
  369. console.log(data);
  370. })
  371. .then(this.send_command(model_dump)).then(this.get_output)
  372. .then(function(data){
  373. data = data.replace("Success: ", "");
  374. let AS = eval(JSON.parse(data));
  375. ModelVerseConnector.load_MV_model(AS, model_CS)
  376. })
  377. .then(function () {
  378. ModelVerseConnector.set_status(ModelVerseConnector.OKAY);
  379. })
  380. .catch(
  381. function (err) {
  382. console.log("Error with model loading!");
  383. console.log(err);
  384. ModelVerseConnector.set_status(ModelVerseConnector.ERROR);
  385. }
  386. );
  387. }
  388. /*********END WRAPPER FUNCTIONS**********/
  389. static get_render_mm(){
  390. let mm = "include \"primitives.alh\"\n" +
  391. "\n" +
  392. "SimpleAttribute Natural {}\n" +
  393. "SimpleAttribute String {}\n" +
  394. "SimpleAttribute Boolean {}\n" +
  395. "\n" +
  396. "Class GraphicalElement {\n" +
  397. " x : Natural\n" +
  398. " y : Natural\n" +
  399. " layer : Natural\n" +
  400. "}\n" +
  401. "\n" +
  402. "Class Group : GraphicalElement {\n" +
  403. " __asid : String\n" +
  404. " dirty : Boolean\n" +
  405. "}\n" +
  406. "\n" +
  407. "Association ConnectingLine (Group, Group) {\n" +
  408. " offsetSourceX : Natural\n" +
  409. " offsetSourceY : Natural\n" +
  410. " offsetTargetX : Natural\n" +
  411. " offsetTargetY : Natural\n" +
  412. " lineWidth : Natural\n" +
  413. " lineColour : String\n" +
  414. " arrow : Boolean\n" +
  415. " __asid : String\n" +
  416. " dirty : Boolean\n" +
  417. " layer : Natural\n" +
  418. "}\n" +
  419. "\n" +
  420. "Class LineElement : GraphicalElement {\n" +
  421. " lineWidth : Natural\n" +
  422. " lineColour : String\n" +
  423. "}\n" +
  424. "\n" +
  425. "Class Text : LineElement {\n" +
  426. " text : String\n" +
  427. "}\n" +
  428. "\n" +
  429. "Class Line : LineElement {\n" +
  430. " targetX : Natural\n" +
  431. " targetY : Natural\n" +
  432. " arrow : Boolean\n" +
  433. "}\n" +
  434. "\n" +
  435. "Class Shape : LineElement {\n" +
  436. " fillColour : String\n" +
  437. " width : Natural\n" +
  438. " height : Natural\n" +
  439. "}\n" +
  440. "\n" +
  441. "Class Figure : GraphicalElement {\n" +
  442. " width : Natural\n" +
  443. " height : Natural\n" +
  444. "}\n" +
  445. "\n" +
  446. "Class SVG {\n" +
  447. " data : String\n" +
  448. "}\n" +
  449. "\n" +
  450. "Class Rectangle : Shape {\n" +
  451. "}\n" +
  452. "\n" +
  453. "Class Ellipse : Shape {\n" +
  454. "}\n" +
  455. "\n" +
  456. "Association contains (Group, GraphicalElement) {}\n" +
  457. "Association renders (Figure, SVG) {\n" +
  458. " source_lower_cardinality = 1\n" +
  459. " target_lower_cardinality = 1\n" +
  460. " target_upper_cardinality = 1\n" +
  461. "}"
  462. ;
  463. return mm;
  464. }
  465. static get_render_trans(){
  466. let trans = "include \"primitives.alh\"\n" +
  467. "include \"modelling.alh\"\n" +
  468. "include \"object_operations.alh\"\n" +
  469. "include \"utils.alh\"\n" +
  470. "\n" +
  471. "Boolean function main(model : Element):\n" +
  472. "\tElement elements\n" +
  473. "\tString class\n" +
  474. "\tElement attrs\n" +
  475. "\tElement attr_keys\n" +
  476. "\tString attr_key\n" +
  477. "\tString group\n" +
  478. "\tString elem\n" +
  479. "\tInteger loc\n" +
  480. "\tInteger text_loc\n" +
  481. "\tElement related_groups\n" +
  482. "\tloc = 10\n" +
  483. "\n" +
  484. "\tElement groups\n" +
  485. "\tgroups = dict_create()\n" +
  486. "\n" +
  487. "\telements = allInstances(model, \"rendered/Group\")\n" +
  488. "\twhile (set_len(elements) > 0):\n" +
  489. "\t\tgroup = set_pop(elements)\n" +
  490. "\t\tif (set_len(allIncomingAssociationInstances(model, group, \"TracabilityClass\")) == 0):\n" +
  491. "\t\t\tElement to_remove\n" +
  492. "\t\t\tString elem_to_remove\n" +
  493. "\t\t\tto_remove = allAssociationDestinations(model, group, \"rendered/contains\")\n" +
  494. "\t\t\twhile (set_len(to_remove) > 0):\n" +
  495. "\t\t\t\telem_to_remove = set_pop(to_remove)\n" +
  496. "\t\t\t\tif (read_type(model, elem_to_remove) == \"rendered/Group\"):\n" +
  497. "\t\t\t\t\tset_add(to_remove, elem_to_remove)\n" +
  498. "\t\t\t\telse:\n" +
  499. "\t\t\t\t\tmodel_delete_element(model, elem_to_remove)\n" +
  500. "\t\t\tmodel_delete_element(model, group)\n" +
  501. "\n" +
  502. "\telements = allInstances(model, \"abstract/Class\")\n" +
  503. "\twhile (set_len(elements) > 0):\n" +
  504. "\t\tclass = set_pop(elements)\n" +
  505. "\t\t\n" +
  506. "\t\tInteger x\n" +
  507. "\t\tInteger y\n" +
  508. "\t\tx = loc\n" +
  509. "\t\ty = 10\n" +
  510. "\n" +
  511. "\t\t// Check if there is already an associated element\n" +
  512. "\t\tif (set_len(allOutgoingAssociationInstances(model, class, \"TracabilityClass\")) > 0):\n" +
  513. "\t\t\t// Yes, but is it still clean?\n" +
  514. "\t\t\tBoolean dirty\n" +
  515. "\t\t\tdirty = False\n" +
  516. "\n" +
  517. "\t\t\trelated_groups = allAssociationDestinations(model, class, \"TracabilityClass\")\n" +
  518. "\t\t\twhile (set_len(related_groups) > 0):\n" +
  519. "\t\t\t\tgroup = set_pop(related_groups)\n" +
  520. "\t\t\t\tif (value_eq(read_attribute(model, group, \"dirty\"), True)):\n" +
  521. "\t\t\t\t\t// No, so mark all as dirty\n" +
  522. "\t\t\t\t\tdirty = True\n" +
  523. "\t\t\t\t\tbreak!\n" +
  524. "\t\t\t\telse:\n" +
  525. "\t\t\t\t\t// Yes, so just ignore this!\n" +
  526. "\t\t\t\t\tcontinue!\n" +
  527. "\n" +
  528. "\t\t\tif (bool_not(dirty)):\n" +
  529. "\t\t\t\tdict_add(groups, class, group)\n" +
  530. "\t\t\t\tcontinue!\n" +
  531. "\t\t\telse:\n" +
  532. "\t\t\t\trelated_groups = allAssociationDestinations(model, class, \"TracabilityClass\")\n" +
  533. "\t\t\t\tElement to_remove\n" +
  534. "\t\t\t\tString elem_to_remove\n" +
  535. "\t\t\t\twhile (set_len(related_groups) > 0):\n" +
  536. "\t\t\t\t\tgroup = set_pop(related_groups)\n" +
  537. "\t\t\t\t\tto_remove = allAssociationDestinations(model, group, \"rendered/contains\")\n" +
  538. "\t\t\t\t\tx = create_value(read_attribute(model, group, \"x\"))\n" +
  539. "\t\t\t\t\ty = create_value(read_attribute(model, group, \"y\"))\n" +
  540. "\t\t\t\t\twhile (set_len(to_remove) > 0):\n" +
  541. "\t\t\t\t\t\telem_to_remove = set_pop(to_remove)\n" +
  542. "\t\t\t\t\t\tif (read_type(model, elem_to_remove) == \"rendered/Group\"):\n" +
  543. "\t\t\t\t\t\t\tset_add(to_remove, elem_to_remove)\n" +
  544. "\t\t\t\t\t\telse:\n" +
  545. "\t\t\t\t\t\t\tmodel_delete_element(model, elem_to_remove)\n" +
  546. "\t\t\t\t\tmodel_delete_element(model, group)\n" +
  547. "\n" +
  548. "\t\tattr_keys = dict_keys(getAttributeList(model, class))\n" +
  549. "\t\ttext_loc = 5\n" +
  550. "\n" +
  551. "\t\tgroup = instantiate_node(model, \"rendered/Group\", \"\")\n" +
  552. "\t\tinstantiate_attribute(model, group, \"x\", x)\n" +
  553. "\t\tinstantiate_attribute(model, group, \"y\", y)\n" +
  554. "\t\tinstantiate_attribute(model, group, \"__asid\", list_read(string_split_nr(class, \"/\", 1), 1))\n" +
  555. "\t\tinstantiate_attribute(model, group, \"layer\", 0)\n" +
  556. "\t\tdict_add(groups, class, group)\n" +
  557. "\t\tloc = loc + 200\n" +
  558. "\n" +
  559. "\t\telem = instantiate_node(model, \"rendered/Rectangle\", \"\")\n" +
  560. "\t\tinstantiate_attribute(model, elem, \"x\", 0)\n" +
  561. "\t\tinstantiate_attribute(model, elem, \"y\", 0)\n" +
  562. "\t\tinstantiate_attribute(model, elem, \"height\", 40 + set_len(getInstantiatableAttributes(model, class, \"abstract/AttributeLink\")) * 20)\n" +
  563. "\t\tinstantiate_attribute(model, elem, \"width\", 150)\n" +
  564. "\t\tinstantiate_attribute(model, elem, \"lineWidth\", 2) \n" +
  565. "\t\tinstantiate_attribute(model, elem, \"lineColour\", \"black\")\n" +
  566. "\t\tinstantiate_attribute(model, elem, \"fillColour\", \"white\")\n" +
  567. "\t\tinstantiate_attribute(model, elem, \"layer\", 1)\n" +
  568. "\t\tinstantiate_link(model, \"rendered/contains\", \"\", group, elem)\n" +
  569. "\n" +
  570. "\t\tString multiplicities\n" +
  571. "\t\tString lower_card\n" +
  572. "\t\tString upper_card\n" +
  573. "\t\tif (element_eq(read_attribute(model, class, \"lower_cardinality\"), read_root())):\n" +
  574. "\t\t\tlower_card = \"*\"\n" +
  575. "\t\telse:\n" +
  576. "\t\t\tlower_card = cast_value(read_attribute(model, class, \"lower_cardinality\"))\n" +
  577. "\t\tif (element_eq(read_attribute(model, class, \"upper_cardinality\"), read_root())):\n" +
  578. "\t\t\tupper_card = \"*\"\n" +
  579. "\t\telse:\n" +
  580. "\t\t\tupper_card = cast_value(read_attribute(model, class, \"upper_cardinality\"))\n" +
  581. "\t\tmultiplicities = (((\"[\" + lower_card) + \"..\") + upper_card) + \"]\"\n" +
  582. "\n" +
  583. "\t\telem = instantiate_node(model, \"rendered/Text\", \"\")\n" +
  584. "\t\tinstantiate_attribute(model, elem, \"x\", 5)\n" +
  585. "\t\tinstantiate_attribute(model, elem, \"y\", 3)\n" +
  586. "\t\tinstantiate_attribute(model, elem, \"lineWidth\", 1)\n" +
  587. "\t\tinstantiate_attribute(model, elem, \"lineColour\", \"black\")\n" +
  588. "\t\tif (element_neq(read_attribute(model, class, \"name\"), read_root())):\n" +
  589. "\t\t\tinstantiate_attribute(model, elem, \"text\", string_join(read_attribute(model, class, \"name\"), \" \" + multiplicities))\n" +
  590. "\t\telse:\n" +
  591. "\t\t\tinstantiate_attribute(model, elem, \"text\", \"(unnamed) \" + multiplicities)\n" +
  592. "\t\tinstantiate_attribute(model, elem, \"layer\", 2)\n" +
  593. "\t\tinstantiate_link(model, \"rendered/contains\", \"\", group, elem)\n" +
  594. "\n" +
  595. "\t\telem = instantiate_node(model, \"rendered/Line\", \"\")\n" +
  596. "\t\tinstantiate_attribute(model, elem, \"x\", 0)\n" +
  597. "\t\tinstantiate_attribute(model, elem, \"y\", 20)\n" +
  598. "\t\tinstantiate_attribute(model, elem, \"targetX\", 150)\n" +
  599. "\t\tinstantiate_attribute(model, elem, \"targetY\", 20)\n" +
  600. "\t\tinstantiate_attribute(model, elem, \"lineWidth\", 1)\n" +
  601. "\t\tinstantiate_attribute(model, elem, \"lineColour\", \"black\")\n" +
  602. "\t\tinstantiate_attribute(model, elem, \"arrow\", False)\n" +
  603. "\t\tinstantiate_attribute(model, elem, \"layer\", 2)\n" +
  604. "\t\tinstantiate_link(model, \"rendered/contains\", \"\", group, elem)\n" +
  605. "\n" +
  606. "\t\tattrs = getInstantiatableAttributes(model, class, \"abstract/AttributeLink\")\n" +
  607. "\t\tattr_keys = dict_keys(attrs)\n" +
  608. "\t\twhile (dict_len(attr_keys) > 0):\n" +
  609. "\t\t\tattr_key = set_pop(attr_keys)\n" +
  610. "\t\t\telem = instantiate_node(model, \"rendered/Text\", \"\")\n" +
  611. "\t\t\tinstantiate_attribute(model, elem, \"x\", 5)\n" +
  612. "\t\t\tinstantiate_attribute(model, elem, \"y\", text_loc + 20)\n" +
  613. "\t\t\tinstantiate_attribute(model, elem, \"lineWidth\", 1)\n" +
  614. "\t\t\tinstantiate_attribute(model, elem, \"lineColour\", \"black\")\n" +
  615. "\t\t\tinstantiate_attribute(model, elem, \"text\", (attr_key + \" : \") + cast_string(list_read(string_split_nr(attrs[attr_key], \"/\", 1), 1)))\n" +
  616. "\t\t\tinstantiate_attribute(model, elem, \"layer\", 2)\n" +
  617. "\t\t\tinstantiate_link(model, \"rendered/contains\", \"\", group, elem)\n" +
  618. "\t\t\ttext_loc = text_loc + 15\n" +
  619. "\n" +
  620. "\t\tinstantiate_link(model, \"TracabilityClass\", \"\", class, group)\n" +
  621. "\n" +
  622. "\t// Flush all associations\n" +
  623. "\telements = allInstances(model, \"rendered/ConnectingLine\")\n" +
  624. "\twhile (set_len(elements) > 0):\n" +
  625. "\t\tclass = set_pop(elements)\n" +
  626. "\t\tmodel_delete_element(model, class)\n" +
  627. "\n" +
  628. "\t// Rerender associations\n" +
  629. "\telements = allInstances(model, \"abstract/Association\")\n" +
  630. "\twhile (set_len(elements) > 0):\n" +
  631. "\t\tclass = set_pop(elements)\n" +
  632. "\n" +
  633. "\t\tattr_keys = dict_keys(getAttributeList(model, class))\n" +
  634. "\n" +
  635. "\t\telem = instantiate_link(model, \"rendered/ConnectingLine\", \"\", groups[readAssociationSource(model, class)], groups[readAssociationDestination(model, class)])\n" +
  636. "\t\tinstantiate_attribute(model, elem, \"offsetSourceX\", 75)\n" +
  637. "\t\tinstantiate_attribute(model, elem, \"offsetSourceY\", 30)\n" +
  638. "\t\tinstantiate_attribute(model, elem, \"offsetTargetX\", 75)\n" +
  639. "\t\tinstantiate_attribute(model, elem, \"offsetTargetY\", 30)\n" +
  640. "\t\tinstantiate_attribute(model, elem, \"lineWidth\", 1)\n" +
  641. "\t\tinstantiate_attribute(model, elem, \"lineColour\", \"black\")\n" +
  642. "\t\tinstantiate_attribute(model, elem, \"arrow\", True)\n" +
  643. "\t\tinstantiate_attribute(model, elem, \"__asid\", list_read(string_split_nr(class, \"/\", 1), 1))\n" +
  644. "\t\tinstantiate_attribute(model, elem, \"layer\", 0)\n" +
  645. "\t\tlog(\"Real ASID: \" + cast_value(class))\n" +
  646. "\t\tlog(\"Found ASID \" + cast_value(list_read(string_split_nr(class, \"/\", 1), 1)))\n" +
  647. "\t\tinstantiate_link(model, \"rendered/contains\", \"\", group, elem)\n" +
  648. "\n" +
  649. "\treturn True!";
  650. return trans;
  651. }
  652. }