Browse Source

Add selection of files when saving.

Bentley James Oakes 7 years ago
parent
commit
ee688b6983

+ 32 - 36
client/modelverse_connector.js

@@ -9,8 +9,9 @@ class ModelVerseConnector {
         ModelVerseConnector.WORKING = 1;
         ModelVerseConnector.OKAY = 2;
 
-        ModelVerseConnector.curr_model = null;
+        ModelVerseConnector.connected = true;
 
+        ModelVerseConnector.curr_model = null;
         ModelVerseConnector.element_map = {};
     }
 
@@ -32,28 +33,21 @@ class ModelVerseConnector {
         set_colour(colours[status]);
     }
 
-    static save_model(response, data){
-
-
-        if (response != 200){
-            ModelVerseConnector.set_status(ModelVerseConnector.ERROR);
-            return;
-        }
+    static save_model(model_name, data){
 
         ModelVerseConnector.set_status(ModelVerseConnector.WORKING);
 
-        console.log("Save model:");
+        console.log("Save model: " + model_name);
 
         let parsed_data = JSON.parse(data);
         // console.log(parsed_data);
         let m = JSON.parse(parsed_data['data']['m']);
         let mms = JSON.parse(parsed_data['data']['mms']);
 
-        console.log(m);
-        // console.log(mms);
-
         let SCD = "formalisms/SimpleClassDiagrams";
-        let model_name = "test_model";
+        let model_delete = {
+            "data": utils.jsons(["model_delete", model_name])
+        };
         let model_create = {
             "data": utils.jsons(["model_add", SCD, model_name, ""])
         };
@@ -62,18 +56,12 @@ class ModelVerseConnector {
             "data": utils.jsons(["model_modify", model_name, SCD])
         };
 
-        let node_add = {
-            "data": utils.jsons(["instantiate_node", "Class", "test"])
-        };
-
         ModelVerseConnector.curr_model = model_name;
 
         ModelVerseConnector.send_command(model_create)
             .then(ModelVerseConnector.get_output)
             .then(ModelVerseConnector.send_command(model_edit))
             .then(ModelVerseConnector.get_output)
-            .then(ModelVerseConnector.send_command(node_add))
-            .then(ModelVerseConnector.get_output)
             .then(function(data){
 
                 let node_creation_promises = [];
@@ -578,34 +566,43 @@ class ModelVerseConnector {
     }
 
 
-    static choose_model(){
+    static choose_model(status, model_to_save){
 
         console.log("Choosing model: ");
 
+        if (status != undefined && status != 200){
+            ModelVerseConnector.set_status(ModelVerseConnector.ERROR);
+            return;
+        };
+
+        let loading_mode = (model_to_save == undefined);
+
         let folders = [""];
         let files = [];
 
         ModelVerseConnector.set_status(ModelVerseConnector.WORKING);
 
-        if (ModelVerseConnector.curr_model){
+        // only exit on load
+        if (ModelVerseConnector.curr_model && loading_mode){
             let command = {"data": utils.jsons(["exit"])};
             this.send_command(command).then(this.get_output)
             .then(function(data){
-                //console.log(command);
-                //console.log(data);
-
                 ModelVerseConnector.curr_model = null;
             });
         }
 
 
         let startDir = "/";
-        let fileb = FileBrowser.getFileBrowser(ModelVerseConnector.get_files_in_folder, false, false, __getRecentDir(startDir));
+        let fileb = FileBrowser.getFileBrowser(ModelVerseConnector.get_files_in_folder, false, !loading_mode, __getRecentDir(startDir));
         let feedback = GUIUtils.getTextSpan('', "feedback");
         let title = "ModelVerse Explorer";
 
         let callback = function (filenames) {
-            ModelVerseConnector.load_model(filenames[0]);
+            if (loading_mode) {
+                ModelVerseConnector.load_model(filenames[0]);
+            }else{
+                ModelVerseConnector.save_model(filenames[0], model_to_save);
+            }
         };
 
         GUIUtils.setupAndShowDialog(
@@ -625,24 +622,23 @@ class ModelVerseConnector {
 
     }
 
-    static load_model(filename) {
+    static load_model(model_name) {
 
-        let model_name = filename;
         let metamodel = "formalisms/SimpleClassDiagrams";
 
         //fix slashes on filename
-        if (model_name.endsWith("/")){
-            model_name = model_name.slice(0, -1);
-        }
-
-        if (model_name.startsWith("/")){
-            model_name = model_name.slice(1);
-        }
+        // if (model_name.endsWith("/")){
+        //     model_name = model_name.slice(0, -1);
+        // }
+        //
+        // if (model_name.startsWith("/")){
+        //     model_name = model_name.slice(1);
+        // }
 
 
         console.log("Loading model: " + model_name);
         ModelVerseConnector.set_status(ModelVerseConnector.WORKING);
-        ModelVerseConnector.curr_model = filename;
+        ModelVerseConnector.curr_model = model_name;
 
 
 

+ 207 - 5
users/(default)/Toolbars/ModelVerse/ModelVerse.buttons.model

@@ -270,7 +270,7 @@
 							"2": {
 								"textContent": {
 									"type": "string",
-									"value": "dumpModel"
+									"value": "loadModel"
 								},
 								"style": {
 									"type": "map<string,string>",
@@ -360,11 +360,195 @@
 					"value": "/Formalisms/__Utilities__/Buttons/Buttons/Button/1.instance"
 				},
 				"$type": "/Formalisms/__Utilities__/Buttons/Buttons.defaultIcons/ButtonIcon"
+			},
+			"21": {
+				"typename": {
+					"type": "string",
+					"value": "ButtonIcon"
+				},
+				"position": {
+					"type": "list<double>",
+					"value": [
+						866,
+						384
+					]
+				},
+				"orientation": {
+					"type": "double",
+					"value": 0
+				},
+				"scale": {
+					"type": "list<double>",
+					"value": [
+						1,
+						1
+					]
+				},
+				"mapper": {
+					"type": "code",
+					"value": ""
+				},
+				"parser": {
+					"type": "code",
+					"value": ""
+				},
+				"$contents": {
+					"type": "map<string,*>",
+					"value": {
+						"nodes": {
+							"1": {
+								"width": {
+									"type": "double",
+									"value": "120"
+								},
+								"height": {
+									"type": "double",
+									"value": "50"
+								},
+								"cornerRadius": {
+									"type": "double",
+									"value": "25"
+								},
+								"style": {
+									"type": "map<string,string>",
+									"value": {
+										"stroke": "#af0000",
+										"stroke-dasharray": "",
+										"fill": "#000000",
+										"fill-opacity": 0.05,
+										"stroke-width": 2
+									}
+								},
+								"mapper": {
+									"type": "code",
+									"value": ""
+								},
+								"parser": {
+									"type": "code",
+									"value": ""
+								},
+								"$type": "/Formalisms/__LanguageSyntax__/ConcreteSyntax/ConcreteSyntax/Rectangle",
+								"position": {
+									"type": "list<double>",
+									"value": [
+										0,
+										0
+									]
+								},
+								"orientation": {
+									"type": "double",
+									"value": 0
+								},
+								"scale": {
+									"type": "list<double>",
+									"value": [
+										1,
+										1
+									]
+								}
+							},
+							"2": {
+								"textContent": {
+									"type": "string",
+									"value": "saveModel"
+								},
+								"style": {
+									"type": "map<string,string>",
+									"value": {
+										"stroke": "#000000",
+										"stroke-dasharray": "",
+										"fill": "#ffffff",
+										"fill-opacity": 0.75,
+										"font-size": "13px",
+										"stroke-width": 1
+									}
+								},
+								"mapper": {
+									"type": "code",
+									"value": "({\"textContent\":getAttr(\"name\")})"
+								},
+								"parser": {
+									"type": "code",
+									"value": "({\"name\":getAttr(\"textContent\")})"
+								},
+								"$type": "/Formalisms/__LanguageSyntax__/ConcreteSyntax/ConcreteSyntax/Text",
+								"position": {
+									"type": "list<double>",
+									"value": [
+										10,
+										13
+									]
+								},
+								"orientation": {
+									"type": "double",
+									"value": 0
+								},
+								"scale": {
+									"type": "list<double>",
+									"value": [
+										1,
+										1
+									]
+								}
+							},
+							"3": {
+								"$type": "/Formalisms/__LanguageSyntax__/ConcreteSyntax/ConcreteSyntax/Contain",
+								"position": {
+									"type": "list<double>",
+									"value": [
+										17.74899850809561,
+										12.998998508095553
+									]
+								},
+								"orientation": {
+									"type": "double",
+									"value": 0
+								},
+								"scale": {
+									"type": "list<double>",
+									"value": [
+										1,
+										1
+									]
+								},
+								"link-style": {
+									"type": "map<string,string>",
+									"value": {
+										"stroke": "#00ffff",
+										"stroke-dasharray": "",
+										"stroke-opacity": 0.1,
+										"arrow-start": "none",
+										"arrow-end": "classic-wide-long"
+									}
+								}
+							}
+						},
+						"edges": [
+							{
+								"src": "1",
+								"dest": 3
+							},
+							{
+								"src": 3,
+								"dest": "2"
+							}
+						]
+					}
+				},
+				"$asuri": {
+					"type": "string",
+					"value": "/Formalisms/__Utilities__/Buttons/Buttons/Button/21.instance"
+				},
+				"$type": "/Formalisms/__Utilities__/Buttons/Buttons.defaultIcons/ButtonIcon"
 			}
 		},
 		"edges": [],
 		"metamodels": [
-			"/Formalisms/__Utilities__/Buttons/Buttons.defaultIcons"
+			"/Formalisms/__Utilities__/Buttons/Buttons.defaultIcons",
+			"/Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram.defaultIcons",
+			"/Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram.umlIcons",
+			"/Formalisms/__LanguageSyntax__/ConcreteSyntax/ConcreteSyntax.defaultIcons",
+			"/Formalisms/SCCD/SCCD.defaultIcons"
 		]
 	},
 	"asm": {
@@ -387,7 +571,22 @@
 			"1": {
 				"name": {
 					"type": "string",
-					"value": "dumpModel"
+					"value": "loadModel"
+				},
+				"tooltip": {
+					"type": "string",
+					"value": ""
+				},
+				"code": {
+					"type": "code",
+					"value": "if (ModelVerseConnector.connected == undefined){\n    WindowManagement.openDialog(_ERROR,'Connect to the ModelVerse first');\n}else{\n    ModelVerseConnector.choose_model();\n}"
+				},
+				"$type": "/Formalisms/__Utilities__/Buttons/Buttons/Button"
+			},
+			"21": {
+				"name": {
+					"type": "string",
+					"value": "saveModel"
 				},
 				"tooltip": {
 					"type": "string",
@@ -395,14 +594,17 @@
 				},
 				"code": {
 					"type": "code",
-					"value": "ModelVerseConnector.dump_model()"
+					"value": "if (ModelVerseConnector.connected == undefined){\n    WindowManagement.openDialog(_ERROR,'Connect to the ModelVerse first');\n}else{\n    _httpReq('GET', '/current.state?wid='+_context.aswid, undefined,                \n    ModelVerseConnector.choose_model);\n}"
 				},
 				"$type": "/Formalisms/__Utilities__/Buttons/Buttons/Button"
 			}
 		},
 		"edges": [],
 		"metamodels": [
-			"/Formalisms/__Utilities__/Buttons/Buttons"
+			"/Formalisms/__Utilities__/Buttons/Buttons",
+			"/Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram",
+			"/Formalisms/__LanguageSyntax__/ConcreteSyntax/ConcreteSyntax",
+			"/Formalisms/SCCD/SCCD"
 		]
 	}
 }