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):
# 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)
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:
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
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
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:
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 = (
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
# -*- 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
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")
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(
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()
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]
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]
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()
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)
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)
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):