فهرست منبع

Add IPython notebook and several simpler operations

Yentl Van Tendeloo 7 سال پیش
والد
کامیت
0d97178a07
4فایلهای تغییر یافته به همراه358 افزوده شده و 24 حذف شده
  1. 225 0
      Untitled.ipynb
  2. 4 2
      bootstrap/core_algorithm.alc
  3. 118 0
      wrappers/modelverse.py
  4. 11 22
      wrappers/modelverse_SCCD.py

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 225 - 0
Untitled.ipynb


+ 4 - 2
bootstrap/core_algorithm.alc

@@ -234,9 +234,7 @@ String function get_entry_id(name : String):
 	if (string_get(name, string_len(name) - 1) == "/"):
 		name = string_substr(name, 0, string_len(name) - 1)
 
-	log("Got location: " + name)
 	name = string_replace(name, "~", "users/" + cast_string(read_attribute(core, current_user_id, "name")))
-	log("Rewrote: " + name)
 
 	if (dict_in(caches["models"], name)):
 		if (dict_in(core, caches["models"])):
@@ -310,6 +308,8 @@ String function create_folders(user_id : String, folder_name : String):
 		return get_entry_id(folder_name)!
 
 	i = 0
+	folder_name = string_replace(folder_name, "~", "users/" + cast_string(read_attribute(core, current_user_id, "name")))
+
 	hierarchy = string_split(folder_name, "/")
 	prev = get_entry_id("")
 	cummul = ""
@@ -342,6 +342,8 @@ String function create_folders(user_id : String, folder_name : String):
 String function store_entry(model_id : String, full_name : String, user_id : String):
 	String prev
 
+	full_name = string_replace(full_name, "~", "users/" + cast_string(read_attribute(core, current_user_id, "name")))
+
 	if (get_entry_id(full_name) != ""):
 		// Delete any old models
 		model_delete(get_entry_id(full_name))

+ 118 - 0
wrappers/modelverse.py

@@ -304,6 +304,14 @@ def model_add(model_name, metamodel_name, model_code=""):
     INPUT("model_add", [model_name, metamodel_name, model_code])
     return OUTPUT()
 
+def model_define(model_name, metamodel_name, model_code=""):
+    try:
+        INPUT("model_add", [model_name, metamodel_name, model_code])
+        return OUTPUT()
+    except ModelExists:
+        INPUT("model_overwrite", [model_name, model_code])
+        return OUTPUT()
+
 def model_move(source_name, target_name):
     INPUT("model_move", [source_name, target_name])
     return OUTPUT()
@@ -665,3 +673,113 @@ def service_set(port, value):
 def service_poll(port):
     """Checks whether or not the Modelverse side has any input ready to be processed."""
     raise NotImplementedError()
+
+def show(model_name):
+    data_list = INPUT("element_list_nice", [model_name])
+    result = OUTPUT()
+    import uuid
+    INPUT("model_types", [model_name])
+    is_scd = len([i for i in OUTPUT() if i[0] == "formalisms/SimpleClassDiagrams"]) > 0
+
+    edges = []
+    texts = []
+    rectangles = []
+
+    defined_attributes = {}
+    names = {}
+    group_counter = 0
+    todo_edges = []
+    locations = {}
+
+    if is_scd:
+        for elem in result:
+            if elem["__type"] == "AttributeLink":
+                defined_attributes.setdefault(elem["__source"], []).append((elem["name"], elem["__target"], True if elem["optional"] == True else False))
+            if "name" in elem:
+                names[elem["__id"]] = elem["name"]
+
+    for elem in list(result):
+        is_edge = False
+        attrs = {}
+        for key, value in elem.items():
+            if key == "__id":
+                element_id = value
+            elif key == "__source":
+                element_source = value
+                is_edge = True
+            elif key == "__target":
+                element_target = value
+                is_edge = True
+            elif key == "__type":
+                element_type = value
+            else:
+                attrs[key] = value
+        max_text = 0
+
+        if is_edge:
+            edge_edge = len([x for x in result if (x["__id"] == element_source or x["__id"] == element_target) and "__source" in x]) > 0
+        else:
+            edge_edge = False
+
+        if is_edge:
+            if not (elem["__type"] == "AttributeLink" and is_scd):
+                todo_edges.append({"source": element_source, "target": element_target, "source_x": 0 if edge_edge else 100, "source_y": 0 if edge_edge else 30, "target_x": 100, "target_y": 30})
+        else:
+            # Add the group
+            x, y = 30 + (group_counter * 250) % 1000, 30 + ((group_counter / 4) * 250)
+            locations[element_id] = (x, y)
+            group_counter += 1
+
+            # Add the text elements
+            # First the header
+            texts.append({"text": "%s : %s" % (element_id, element_type), "x": x + 10, "y": y + 10})
+            max_text = max(len(texts[-1]["text"]), max_text)
+            # Then the attributes
+            text_counter = 1
+
+            for name, attr_type, optional in defined_attributes.get(elem["__id"], []):
+                text = "%s : %s" % (name, names.get(attr_type, "(%s)" % attr_type))
+                if optional:
+                    text = text.replace(" : ", " ?: ")
+                texts.append({"text": text, "x": x + 10, "y": y + 25 + text_counter * 11})
+                max_text = max(len(text), max_text)
+                text_counter += 1
+
+            if text_counter > 1:
+                text_counter += 1
+
+            for key, value in attrs.items():
+                if isinstance(value, dict):
+                    if value["AL"] == "":
+                        text = "(%s)" % key
+                    else:
+                        text = "%s = ^%s" % (key, value['AL'])
+                else:
+                    text = ("%s = %s" % (key, value)) if value is not None else ("(%s)" % key)
+                texts.append({"text": text, "x": x + 10, "y": y + 25 + text_counter * 11})
+                max_text = max(len(text), max_text)
+                text_counter += 1
+
+            # Add the rectangle
+            rectangles.append({"x": x, "y": y, "width": max_text * 8, "height": 35 + text_counter * 11})
+
+            # Add the line
+            edges.append({"sx": x, "sy": y + 20, "tx": x + max_text * 8, "ty": y + 20})
+
+    for edge in todo_edges:
+        edges.append({"sx": locations[edge["source"]][0] + edge["source_x"], "sy": locations[edge["source"]][1] + edge["source_y"], "tx": locations[edge["target"]][0] + edge["target_x"], "ty": locations[edge["target"]][1]})
+
+    print("Got rectangles: " + str(rectangles))
+    print("Got edges: " + str(edges))
+    print("Got text: " + str(texts))
+
+    data_content = '<svg width="1000" height="800">'
+    for rec in rectangles:
+        data_content += '<rect x="%s" y="%s" width="%s" height="%s" fill="white" stroke="black"/>' % (rec["x"], rec["y"], rec["width"], rec["height"])
+    for edge in edges:
+        data_content += '<line x1="%s" y1="%s" x2="%s" y2="%s" fill="black"/>' % (edge["sx"], edge["sy"], edge["tx"], edge["ty"])
+    for text in texts:
+        data_content += '<text x="%s" y="%s" fill="black">%s</text>' % (text["x"], text["y"], text["text"])
+
+    data_content += '</svg>'
+    return data_content

+ 11 - 22
wrappers/modelverse_SCCD.py

@@ -1948,11 +1948,6 @@ class Modelverse(RuntimeClassBase):
         _initialized_behaviour_operations_37.setTrigger(None)
         _initialized_behaviour_operations_37.setGuard(self._initialized_behaviour_operations_37_guard)
         self.states["/initialized/behaviour/operations"].addTransition(_initialized_behaviour_operations_37)
-        _initialized_behaviour_operations_38 = Transition(self, self.states["/initialized/behaviour/operations"], [self.states["/initialized/behaviour/wait_for_action/history"]])
-        _initialized_behaviour_operations_38.setAction(self._initialized_behaviour_operations_38_exec)
-        _initialized_behaviour_operations_38.setTrigger(None)
-        _initialized_behaviour_operations_38.setGuard(self._initialized_behaviour_operations_38_guard)
-        self.states["/initialized/behaviour/operations"].addTransition(_initialized_behaviour_operations_38)
         
         # transition /initialized/behaviour/operations/store_on_scripted/transformation_add
         _initialized_behaviour_operations_store_on_scripted_transformation_add_0 = Transition(self, self.states["/initialized/behaviour/operations/store_on_scripted/transformation_add"], [self.states["/initialized/behaviour/wait_for_action/megamodelling"]])
@@ -2530,46 +2525,40 @@ class Modelverse(RuntimeClassBase):
         return self.expect_response_partial('Admin permission denied', pop=True)
     
     def _initialized_behaviour_operations_32_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['InterfaceMismatch', self.split_response(self.responses.pop(0))[0]]))
-    
-    def _initialized_behaviour_operations_32_guard(self, parameters):
-        return self.expect_response_partial('Incorrect format: ', pop=False)
-    
-    def _initialized_behaviour_operations_33_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['UnknownElement', self.split_response(self.responses.pop(0))[0]]))
     
-    def _initialized_behaviour_operations_33_guard(self, parameters):
+    def _initialized_behaviour_operations_32_guard(self, parameters):
         return self.expect_response_partial('Element not found: ', pop=False)
     
-    def _initialized_behaviour_operations_34_exec(self, parameters):
+    def _initialized_behaviour_operations_33_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['UnknownModel', self.split_response(self.responses.pop(0))[0]]))
     
-    def _initialized_behaviour_operations_34_guard(self, parameters):
+    def _initialized_behaviour_operations_33_guard(self, parameters):
         return self.expect_response_partial('Model not found: ', pop=False)
     
-    def _initialized_behaviour_operations_35_exec(self, parameters):
+    def _initialized_behaviour_operations_34_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['UnknownMetamodellingHierarchy', 'Metamodelling hierarchy could not be resolved or automatically inferred: there is no typing relation between your specified model and metamodel (%s)' % self.responses.pop(0)]))
     
-    def _initialized_behaviour_operations_35_guard(self, parameters):
+    def _initialized_behaviour_operations_34_guard(self, parameters):
         return self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)
     
-    def _initialized_behaviour_operations_36_exec(self, parameters):
+    def _initialized_behaviour_operations_35_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['TypeMismatch', self.responses.pop(0)]))
     
-    def _initialized_behaviour_operations_36_guard(self, parameters):
+    def _initialized_behaviour_operations_35_guard(self, parameters):
         return self.expect_response_partial('Signature mismatch in operation for tag: ', pop=False)
     
-    def _initialized_behaviour_operations_37_exec(self, parameters):
+    def _initialized_behaviour_operations_36_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['SignatureMismatch', self.responses.pop(0)]))
     
-    def _initialized_behaviour_operations_37_guard(self, parameters):
+    def _initialized_behaviour_operations_36_guard(self, parameters):
         return self.expect_response_partial('Signature mismatch: ', pop=False)
     
-    def _initialized_behaviour_operations_38_exec(self, parameters):
+    def _initialized_behaviour_operations_37_exec(self, parameters):
         print("Unknown Error: " + self.responses[0])
         self.raiseInternalEvent(Event("exception", None, ['UnknownError', 'Error: %s' % self.responses.pop(0)]))
     
-    def _initialized_behaviour_operations_38_guard(self, parameters):
+    def _initialized_behaviour_operations_37_guard(self, parameters):
         return self.expect_response_partial('', pop=False)
     
     def _initialized_behaviour_operations_store_on_scripted_transformation_add_0_exec(self, parameters):