deleted label from graphical info
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Wed, 25 May 2011 10:09:53 +0000 (12:09 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Wed, 25 May 2011 10:09:53 +0000 (12:09 +0200)
src/nepi/core/design.py
src/nepi/core/metadata.py
src/nepi/util/graphical_info.py
src/nepi/util/guid.py
src/nepi/util/parser/_xml.py
src/nepi/util/parser/base.py

index a2a9b2d..c899344 100644 (file)
@@ -13,8 +13,6 @@ from nepi.util.guid import GuidGenerator
 from nepi.util.graphical_info import GraphicalInfo
 from nepi.util.parser._xml import XmlExperimentParser
 import sys
-    
-
 
 class ConnectorType(ConnectorTypeBase):
     def __init__(self, testbed_id, factory_id, name, help, max = -1, min = 0):
@@ -201,7 +199,7 @@ class Box(AttributesMap):
         # factory_attributes -- factory attributes for box construction
         self._factory_attributes = dict()
         # graphical_info -- GUI position information
-        self.graphical_info = GraphicalInfo(str(self._guid))
+        self.graphical_info = GraphicalInfo()
 
         for connector_type in factory.connector_types:
             connector = Connector(self, connector_type)
@@ -527,13 +525,13 @@ class FactoriesProvider(object):
         del self._factories[factory_id]
 
 class TestbedDescription(AttributesMap):
-    def __init__(self, guid_generator, provider):
+    def __init__(self, guid_generator, provider, guid = None):
         super(TestbedDescription, self).__init__()
         self._guid_generator = guid_generator
-        self._guid = guid_generator.next()
+        self._guid = guid_generator.next(guid)
         self._provider = provider
         self._boxes = dict()
-        self.graphical_info = GraphicalInfo(str(self._guid))
+        self.graphical_info = GraphicalInfo()
 
         metadata = Metadata(provider.testbed_id, provider.testbed_version)
         for attr in metadata.testbed_attributes().attributes:
@@ -556,8 +554,8 @@ class TestbedDescription(AttributesMap):
     def box(self, guid):
         return self._boxes[guid] if guid in self._boxes else None
 
-    def create(self, factory_id):
-        guid = self._guid_generator.next()
+    def create(self, factory_id, guid = None):
+        guid = self._guid_generator.next(guid)
         factory = self._provider.factory(factory_id)
         box = factory.create(guid, self)
         self._boxes[guid] = box
@@ -574,8 +572,8 @@ class TestbedDescription(AttributesMap):
         self._boxes = None
 
 class ExperimentDescription(object):
-    def __init__(self, guid = 0):
-        self._guid_generator = GuidGenerator(guid)
+    def __init__(self):
+        self._guid_generator = GuidGenerator()
         self._testbed_descriptions = dict()
 
     @property
@@ -608,16 +606,17 @@ class ExperimentDescription(object):
             if box: return box
         return None
 
-    def add_testbed_description(self, provider):
+    def add_testbed_description(self, provider, guid = None):
         testbed_description = TestbedDescription(self._guid_generator, 
-                provider)
+                provider, guid)
         guid = testbed_description.guid
         self._testbed_descriptions[guid] = testbed_description
         return testbed_description
 
-    def remove_testbed_description(self, testbed_description):
-        guid = testbed_description.guid
+    def remove_testbed_description(self, guid):
+        testbed_description = self._testbed_descriptions[guid]
         del self._testbed_descriptions[guid]
+        testbed_description.destroy()
 
     def destroy(self):
         for testbed_description in self.testbed_descriptions:
index c8015cd..b344d5a 100644 (file)
@@ -182,6 +182,13 @@ class Metadata(object):
             value = "",
             flags = Attribute.DesignOnly
         )),
+        ("label", dict(
+            name = "label",
+            validation_function = validation.is_string,
+            type = Attribute.STRING,
+            flags = Attribute.DesignOnly,
+            help = "A unique identifier for referring to this testbed",
+        )),
     )
     
     DEPLOYMENT_ATTRIBUTES = (
index 12a40bd..2a09ba2 100644 (file)
@@ -5,10 +5,9 @@
 class GraphicalInfo(object):
     """ This class allows to describe the position and dimensions of a 
     2D object in a GUI canvas"""
-    def __init__(self, label):
+    def __init__(self):
         self.x = 0.0
         self.y = 0.0
         self.width = 0.0
         self.height = 0.0
-        self.label = label
 
index 7e28552..3198e25 100644 (file)
@@ -2,10 +2,17 @@
 # -*- coding: utf-8 -*-
 
 class GuidGenerator(object):
-    def __init__(self, guid = 0):
-        self._last_guid = guid
+    def __init__(self):
+        self._guids = list()
 
-    def next(self):
-        self._last_guid += 1
-        return self._last_guid
+    def next(self, guid = None):
+        if guid != None:
+            if guid in self._guids:
+                raise RuntimeError("guid %d is already assigned" % guid)
+        else:
+            last_guid = 0 if len(self._guids) == 0 else self._guids[-1]
+            guid = last_guid + 1 
+        self._guids.append(guid)
+        self._guids.sort()
+        return guid
 
index b240776..7f439cf 100644 (file)
@@ -63,12 +63,11 @@ class XmlExperimentParser(ExperimentParser):
     def graphical_info_data_to_xml(self, doc, parent_tag, guid, data):
         graphical_info_tag = doc.createElement("graphical_info") 
         parent_tag.appendChild(graphical_info_tag)
-        (x, y, width, height, label) = data.get_graphical_info_data(guid)
+        (x, y, width, height) = data.get_graphical_info_data(guid)
         graphical_info_tag.setAttribute("x", str(x))
         graphical_info_tag.setAttribute("y", str(y))
         graphical_info_tag.setAttribute("width", str(width))
         graphical_info_tag.setAttribute("height", str(height))
-        graphical_info_tag.setAttribute("label", str(label))
 
     def factory_attributes_data_to_xml(self, doc, parent_tag, guid, data):
         factory_attributes_tag = doc.createElement("factory_attributes")
@@ -197,8 +196,7 @@ class XmlExperimentParser(ExperimentParser):
             y = float(graphical_info_tag.getAttribute("y"))
             width = float(graphical_info_tag.getAttribute("width"))
             height = float(graphical_info_tag.getAttribute("height"))
-            label = str(graphical_info_tag.getAttribute("label"))
-            data.add_graphical_info_data(guid, x, y, width, height, label)
+            data.add_graphical_info_data(guid, x, y, width, height)
 
     def factory_attributes_data_from_xml(self, tag, guid, data):
         factory_attributes_tag_list = tag.getElementsByTagName(
index 1737f14..fcc8efc 100644 (file)
@@ -30,7 +30,7 @@ class ExperimentData(object):
         box_data["factory_id"] = factory_id
         self.data[guid] = box_data
 
-    def add_graphical_info_data(self, guid, x, y, width, height, label):
+    def add_graphical_info_data(self, guid, x, y, width, height):
         data = self.data[guid]
         if not "graphical_info" in data:
             data["graphical_info"] = dict()
@@ -39,7 +39,6 @@ class ExperimentData(object):
         graphical_info_data["y"] = y
         graphical_info_data["width"] = width
         graphical_info_data["height"] = height
-        graphical_info_data["label"] = label
 
     def add_factory_attribute_data(self, guid, name, value):
         data = self.data[guid]
@@ -120,8 +119,7 @@ class ExperimentData(object):
         return (graphical_info_data["x"],
                 graphical_info_data["y"],
                 graphical_info_data["width"],
-                graphical_info_data["height"],
-                graphical_info_data["label"])
+                graphical_info_data["height"])
 
     def get_factory_attribute_data(self, guid):
         data = self.data[guid]
@@ -215,7 +213,7 @@ class ExperimentParser(object):
 
     def graphical_info_to_data(self, data, guid, g_info):
         data.add_graphical_info_data(guid, g_info.x, g_info.y, g_info.width, 
-                g_info.height, g_info.label)
+                g_info.height)
 
     def factory_attributes_to_data(self, data, guid, factory_attributes):
         factory_attributes = factory_attributes or dict()
@@ -273,7 +271,7 @@ class ExperimentParser(object):
         from nepi.core.design import FactoriesProvider
         (testbed_id, testbed_version) = data.get_testbed_data(guid)
         provider = FactoriesProvider(testbed_id, testbed_version)
-        experiment_description.add_testbed_description(provider)
+        experiment_description.add_testbed_description(provider, guid)
         testbed_description = experiment_description.testbed_description(guid)
         self.graphical_info_from_data(testbed_description, data)
         self.attributes_from_data(testbed_description, data)
@@ -284,7 +282,8 @@ class ExperimentParser(object):
                 testbed_guid)
         self.factory_attributes_from_data(testbed_description, factory_id,
                 guid, data)
-        box = testbed_description.create(factory_id)
+        box = testbed_description.create(factory_id, guid)
+
         self.graphical_info_from_data(box, data)
         self.attributes_from_data(box, data)
         self.traces_from_data(box, data)
@@ -292,13 +291,12 @@ class ExperimentParser(object):
         self.routes_from_data(box, data)
 
     def graphical_info_from_data(self, element, data):
-        (x, y, width, height, label) =  data.get_graphical_info_data(
+        (x, y, width, height) =  data.get_graphical_info_data(
                 element.guid)
         element.graphical_info.x = x
         element.graphical_info.y = y
         element.graphical_info.width = width
         element.graphical_info.height = height
-        element.graphical_info.label = label
 
     def factory_attributes_from_data(self, testbed_description, factory_id, 
             guid, data):