瀏覽代碼

merged model move from testing branch, can now move model from one location to another (useful to reuse example models as instance models

Lucas Heer 7 年之前
父節點
當前提交
0a72f86596
共有 8 個文件被更改,包括 285 次插入173 次删除
  1. 二進制
      bootstrap/bootstrap.m.gz
  2. 32 0
      bootstrap/core_algorithm.alc
  3. 11 0
      bootstrap/main.alc
  4. 二進制
      bootstrap/minimal.m.gz
  5. 14 1
      main.py
  6. 20 0
      wrappers/classes/modelverse.xml
  7. 4 0
      wrappers/modelverse.py
  8. 204 172
      wrappers/modelverse_SCCD.py

二進制
bootstrap/bootstrap.m.gz


+ 32 - 0
bootstrap/core_algorithm.alc

@@ -1046,6 +1046,7 @@ String function cmd_help():
 	result = ""
 	result = result + ("Model operations\n")
 	result = result + ("    model_add                       -- Add a new model\n")
+	result = result + ("    model_move                      -- Move a model to a different location\n")
 	result = result + ("    model_modify                    -- Modify an existing model\n")
 	result = result + ("    model_list                      -- List all models\n")
 	result = result + ("    model_list_full                 -- List all models with full info\n")
@@ -1093,6 +1094,35 @@ String function cmd_help():
 
 	return result!
 
+String function cmd_model_move(source : String, target : String):
+	String source_id
+	source_id = get_entry_id(source)
+	if (source_id != ""):
+		if (get_entry_id(target) == ""):
+			// Create folders on path to the target
+			create_folders(current_user_id, get_foldername(target))
+
+			// Change location, first the name
+			instantiate_attribute(core, source_id, "name", target)
+
+			// Now the folder links
+			Element links
+			links = allIncomingAssociationInstances(core, source_id, "contains")
+			while (set_len(links) > 0):
+				model_delete_element(core, set_pop(links))
+			instantiate_link(core, "contains", "", get_entry_id(get_foldername(target)), source_id)
+
+			// Flush caches
+			dict_add(caches["models"], target, caches["models"][source])
+			dict_delete(caches["models"], source)
+
+			// Done
+			return "Success"!
+		else:
+			return "Model exists: " + target!
+	else:
+		return "Model does not exist: " + source!
+
 String function cmd_model_add(type : String, name : String, code : String):
 	// Model addition operation, which uses model upload commands of the compiler
 	String location
@@ -2367,6 +2397,8 @@ Void function user_function_skip_init(user_id : String):
 			output(cmd_help())
 		elif (cmd == "model_add"):
 			output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
+		elif (cmd == "model_move"):
+			output(cmd_model_move(single_input("Model name?"), single_input("New location?")))
 		elif (cmd == "process_execute"):
 			output(cmd_process_execute(single_input("Process to execute?"), dict_input("Model bindings to use?")))
 		elif (cmd == "process_signature"):

+ 11 - 0
bootstrap/main.alc

@@ -0,0 +1,11 @@
+include "bootstrap/primitives.alc"
+include "utils.alh"
+include "core_algorithm.alh"
+include "task_manager.alh"
+
+Void function __main():
+	if (get_taskname() == "task_manager"):
+		task_management()
+	else:
+		new_task()
+	return!

二進制
bootstrap/minimal.m.gz


+ 14 - 1
main.py

@@ -72,7 +72,9 @@ if __name__ == "__main__":
     parser.add_argument("-u", action="store_true", default=False, help="Upload metamodels to Modelverse at startup")
     parser.add_argument("-im", action="store_true", default=False, help="Instance modeling")
     parser.add_argument("-exm", action="store_true", default=False, help="Example modeling")
-    parser.add_argument("-m", help="Model to open. Not using this argument will create a new, empty model.")
+    parser.add_argument("-m", help="Model to open. Omit  this argument to create a new, empty model.")
+    parser.add_argument("-c", nargs=2, help="Copy model from one location to another. Useful to resuse example models"
+                                                      "as instance models")
     args = parser.parse_args()
 
     mv.init()
@@ -88,6 +90,17 @@ if __name__ == "__main__":
         print("Uploading evolution transformations ...")
         upload_ops.upload_evolution_ops()
 
+    # copy model from src to dest
+    if args.c:
+        if not len(args.c) == 2:
+            print("Please specify source and target location for copy")
+            sys.exit(-1)
+        src = args.c[0]
+        dest = args.c[1]
+        print("Copying model {} to {}".format(src, dest))
+        mv.model_move(src, dest)
+        sys.exit(0)
+
     # determine modeling mode
     mode = None
     if args.im and args.exm or (not args.im and not args.exm):

+ 20 - 0
wrappers/classes/modelverse.xml

@@ -353,6 +353,20 @@
                         </state>
                     </state>
 
+                    <state id="model_move">
+                        <onentry>
+                            <raise event="request">
+                                <parameter expr="['model_move', self.parameters[0], self.parameters[1]]"/>
+                            </raise>
+                        </onentry>
+
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
+                            <raise event="result">
+                                <parameter expr="None"/>
+                            </raise>
+                        </transition>
+                    </state>
+
                     <state id="model_delete">
                         <onentry>
                             <raise event="request">
@@ -1557,6 +1571,12 @@
                             </script>
                         </transition>
 
+                        <transition cond="self.expect_action(None, 'model_move')" target="../../operations/model_move">
+                            <script>
+                                self.load_action(None)
+                            </script>
+                        </transition>
+
                         <transition cond="self.expect_action(None, 'model_delete')" target="../../operations/model_delete">
                             <script>
                                 self.load_action(None)

+ 4 - 0
wrappers/modelverse.py

@@ -227,6 +227,10 @@ def model_add(model_name, metamodel_name, model_code=""):
     INPUT("model_add", None, [model_name, metamodel_name, model_code])
     return OUTPUT()
 
+def model_move(source_name, target_name):
+    INPUT("model_move", None, [source_name, target_name])
+    return OUTPUT()
+
 def model_delete(model_name):
     INPUT("model_delete", None, [model_name])
     return OUTPUT()

文件差異過大導致無法顯示
+ 204 - 172
wrappers/modelverse_SCCD.py