瀏覽代碼

Readded modify, and added attr_add and attr_del

Yentl Van Tendeloo 9 年之前
父節點
當前提交
9be6a2fb13

+ 2 - 4
bootstrap/modelling.alc

@@ -189,7 +189,7 @@ Void function define_inheritance(model : Element, inheritance_name : String):
 
 	return
 
-Void function model_delete_link(model : Element, name : String):
+Void function model_delete_element(model : Element, name : String):
 	// Remove the link
 	// 1) from the type mapping
 	dict_delete(model["type_mapping"], model["model"][name])
@@ -197,8 +197,6 @@ Void function model_delete_link(model : Element, name : String):
 	// 2) from the model
 	delete_element(model["model"][name])
 
-	// The entry in the model is automagically removed
-
 	return
 
 Element function read_attribute(model : Element, element : String, attribute : String):
@@ -228,7 +226,7 @@ Void function unset_attribute(model : Element, element : String, attribute : Str
 
 	while (list_len(attr_links) > 0):
 		attr_link = set_pop(attr_links)
-		model_delete_link(model, getName(model, attr_link))
+		model_delete_element(model, getName(model, attr_link))
 
 	return
 

+ 38 - 1
integration/code/pn_interface.alc

@@ -124,6 +124,7 @@ Element function petrinet_loaded(model : Element):
 			output("  delete      -- Delete an existing element")
 			output("  attr_add    -- Add an attribute to an existing element")
 			output("  rename      -- Rename an existing element")
+			output("  modify      -- Modify the attributes of an element")
 			output("  list        -- Prints the list of elements in the model")
 			output("  types       -- Prints the list of elements that can be instantiated")
 			output("  read        -- Prints the current state of a model element")
@@ -178,6 +179,25 @@ Element function petrinet_loaded(model : Element):
 							output("Instantiation error!")
 			else:
 				output("Unknown type specified; aborting")
+		elif (cmd == "modify"):
+			String model_name
+			output("Element to modify?")
+			model_name = input()
+			if (dict_in(model["model"], model_name)):
+				Element attrs
+				attrs = getAttributeList(model, model_name)
+				String attr_name
+				output("Attribute to modify?")
+				attr_name = input()
+				if (set_in(dict_keys(attrs), attr_name)):
+					output("New value?")
+					unset_attribute(model, model_name, attr_name)
+					instantiate_attribute(model, model_name, attr_name, input())
+					output("Modified!")
+				else:
+					output("No such attribute!")
+			else:
+				output("No such model!")
 		elif (cmd == "attr_add"):
 			String model_name
 			output("Which model do you want to assign an attribute to?")
@@ -197,11 +217,28 @@ Element function petrinet_loaded(model : Element):
 					output("No such attribute!")
 			else:
 				output("No such model!")
+		elif (cmd == "attr_del"):
+			String model_name
+			output("Which model do you want to remove an attribute of?")
+			model_name = input()
+			if (dict_in(model["model"], model_name)):
+				Element attrs
+				attrs = getAttributeList(model, model_name)
+				output(print_dict(attrs))
+				String attr_name
+				output("Which attribute do you want to delete?")
+				attr_name = input()
+				if (set_in(dict_keys(attrs), attr_name)):
+					unset_attribute(model, model_name, attr_name)
+				else:
+					output("No such attribute!")
+			else:
+				output("No such model!")
 		elif (cmd == "delete"):
 			output("What is the name of the element you want to delete?")
 			cmd = input()
 			if (dict_in(model["model"], cmd)):
-				delete_element(model["model"][cmd])
+				model_delete_element(model, cmd)
 				output("Deleted!")
 			else:
 				output("No such element; aborting")

+ 6 - 7
integration/test_pn_interface.py

@@ -48,17 +48,17 @@ read_p1 =           ["Name: p1",
                      "Type: Place",
                      "Defines attributes:",
                      "Attributes:",
-                     "   tokens : Integer = 5"]
+                     '   "tokens" : "Integer" = None']
 read_p1_1 =         ["Name: p1",
                      "Type: Place",
                      "Defines attributes:",
                      "Attributes:",
-                     "   tokens : Integer = 1"]
+                     '   "tokens" : "Integer" = 1']
 read_p2 =           ["Name: p2",
                      "Type: Place",
                      "Defines attributes:",
                      "Attributes:",
-                     "   tokens : Integer = 0"]
+                     '   "tokens" : "Integer" = None']
 read_t1 =           ["Name: t1",
                      "Type: Transition",
                      "Defines attributes:",
@@ -69,14 +69,14 @@ read_p2t =          ["Name: p2t",
                      "Destination: t1",
                      "Defines attributes:",
                      "Attributes:",
-                     "   weight : Integer = 2"]
+                     '   "weight" : "Integer" = None']
 read_t2p =          ["Name: t2p",
                      "Type: T2P",
                      "Source: t1",
                      "Destination: p2",
                      "Defines attributes:",
                      "Attributes:",
-                     "   weight : Integer = 1"]
+                     '   "weight" : "Integer" = None']
 read_fail =         ["Unknown element; aborting"]
 enabled =           ["Enabled transitions:"]
 enabled_t1 =        ["t1"]
@@ -101,8 +101,7 @@ rename_model_fail_not_exists = ["Unknown element; aborting"]
 rename_model_fail_exists= ["New name already used; aborting"]
 help_msg =          ["Currently no model is loaded, so your operations are "
                      "limited to:",
-                     "  new    -- Create a new model and save it for future "
-                     "use",
+                     "  new    -- Create a new model and save it for future use"
                      "  load   -- Load a previously made model",
                      "  rename -- Rename a previously made model",
                      "  delete -- Delete a previously made model",

+ 1 - 0
interface/HUTN/includes/modelling.alh

@@ -17,3 +17,4 @@ Void function define_inheritance(model : Element, inheritance_name : String)
 Void function unset_attribute(model : Element, elem : String, name : String)
 Void function construct_model()
 Element function read_attribute(model : Element, elem : String, name : String)
+Void function model_delete_element(model : Element, name : String)