Skip to content

Commit

Permalink
Merge pull request #207 from pyoscx/catalog_super_class
Browse files Browse the repository at this point in the history
Catalog super class
  • Loading branch information
mander76 authored Dec 11, 2023
2 parents 3d2f63d + 3901e86 commit 9715d41
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 381 deletions.
154 changes: 10 additions & 144 deletions scenariogeneration/xosc/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Properties,
Parameter,
convert_float,
_BaseCatalog,
)
from .utils import (
EntityRef,
Expand Down Expand Up @@ -445,7 +446,7 @@ def get_element(self):
return element


class Pedestrian(VersionBase):
class Pedestrian(_BaseCatalog):
"""the Pedestrian class creates a pedestrian type entity of openscenario
Parameters
Expand Down Expand Up @@ -529,6 +530,7 @@ def __init__(self, name, mass, category, boundingbox, model=None, role=None):
role (Role): the role of the Vehicle
Default: None
"""
super().__init__()
self.name = name
self.model = model
self.mass = convert_float(mass)
Expand All @@ -538,7 +540,6 @@ def __init__(self, name, mass, category, boundingbox, model=None, role=None):
raise TypeError("boundingbox input is not of type BoundingBox")

self.boundingbox = boundingbox
self.parameters = ParameterDeclarations()
self.properties = Properties()
self.role = convert_enum(role, Role, True)

Expand Down Expand Up @@ -594,51 +595,6 @@ def parse(element):

return pedestrian

def dump_to_catalog(self, filename, catalogtype, description, author):
"""dump_to_catalog creates a new catalog and adds the Pedestrian to it
Parameters
----------
filename (str): path of the new catalog file
catalogtype (str): name of the catalog
description (str): description of the catalog
author (str): author of the catalog
"""
cf = CatalogFile()
cf.create_catalog(filename, catalogtype, description, author)
cf.add_to_catalog(self)
cf.dump()

def append_to_catalog(self, filename):
"""adds the Pedestrian to an existing catalog
Parameters
----------
filename (str): path to the catalog file
"""
cf = CatalogFile()
cf.open_catalog(filename)
cf.add_to_catalog(self)
cf.dump()

def add_parameter(self, parameter):
"""adds a parameter declaration to the pedestrian
Parameters
----------
parameter (Parameter): A new parameter declaration for the pedestrian
"""
if not isinstance(parameter, Parameter):
raise TypeError("parameter input is not of type Parameter")
self.parameters.add_parameter(parameter)
return self

def add_property(self, name, value):
"""adds a single property to the pedestrian
Expand Down Expand Up @@ -689,14 +645,14 @@ def get_attributes(self):
def get_element(self):
"""returns the elementTree of the pedestrian"""
element = ET.Element("Pedestrian", attrib=self.get_attributes())
element.append(self.parameters.get_element())
self.add_parameters_to_element(element)
element.append(self.boundingbox.get_element())
element.append(self.properties.get_element())

return element


class MiscObject(VersionBase):
class MiscObject(_BaseCatalog):
"""the MiscObject Class creates a MiscObject for openscenario
Parameters
Expand Down Expand Up @@ -773,13 +729,13 @@ def __init__(self, name, mass, category, boundingbox, model3d=None):
model3d (str): path to model file (valid from V1.1)
Default: None
"""
super().__init__()
self.name = name
self.mass = convert_float(mass)
self.category = convert_enum(category, MiscObjectCategory)
if not isinstance(boundingbox, BoundingBox):
raise TypeError("boundingbox input is not of type BoundingBox")
self.boundingbox = boundingbox
self.parameters = ParameterDeclarations()
self.properties = Properties()
self.model3d = model3d

Expand Down Expand Up @@ -830,51 +786,6 @@ def parse(element):
object.properties = properties
return object

def dump_to_catalog(self, filename, catalogtype, description, author):
"""dump_to_catalog creates a new catalog and adds the MiscObject to it
Parameters
----------
filename (str): path of the new catalog file
catalogtype (str): name of the catalog
description (str): description of the catalog
author (str): author of the catalog
"""
cf = CatalogFile()
cf.create_catalog(filename, catalogtype, description, author)
cf.add_to_catalog(self)
cf.dump()

def append_to_catalog(self, filename):
"""adds the MiscObject to an existing catalog
Parameters
----------
filename (str): path to the catalog file
"""
cf = CatalogFile()
cf.open_catalog(filename)
cf.add_to_catalog(self)
cf.dump()

def add_parameter(self, parameter):
"""adds a parameter declaration to the MiscObject
Parameters
----------
parameter (Parameter): A new parameter declaration for the MiscObject
"""
if not isinstance(parameter, Parameter):
raise TypeError("parameter input is not of type Parameter")
self.parameters.add_parameter(parameter)
return self

def add_property(self, name, value):
"""adds a single property to the MiscObject
Expand Down Expand Up @@ -912,14 +823,14 @@ def get_attributes(self):
def get_element(self):
"""returns the elementTree of the MiscObject"""
element = ET.Element("MiscObject", attrib=self.get_attributes())
element.append(self.parameters.get_element())
self.add_parameters_to_element(element)
element.append(self.boundingbox.get_element())
element.append(self.properties.get_element())

return element


class Vehicle(VersionBase):
class Vehicle(_BaseCatalog):
"""the Vehicle Class creates a Vehicle for openscenario
Parameters
Expand Down Expand Up @@ -1059,6 +970,7 @@ def __init__(
role (Role): the role of the Vehicle
Default: None
"""
super().__init__()
self.name = name
if not isinstance(boundingbox, BoundingBox):
raise TypeError("boundingbox input is not of type BoundingBox")
Expand All @@ -1074,7 +986,6 @@ def __init__(
max_acceleration_rate,
max_deceleration_rate,
)
self.parameters = ParameterDeclarations()
self.properties = Properties()
self.mass = convert_float(mass)
self.model3d = model3d
Expand Down Expand Up @@ -1165,38 +1076,6 @@ def parse(element):

return vehicle

def dump_to_catalog(self, filename, catalogtype, description, author):
"""dump_to_catalog creates a new catalog and adds the vehicle to it
Parameters
----------
filename (str): path of the new catalog file
catalogtype (str): name of the catalog
description (str): description of the catalog
author (str): author of the catalog
"""
cf = CatalogFile()
cf.create_catalog(filename, catalogtype, description, author)
cf.add_to_catalog(self)
cf.dump()

def append_to_catalog(self, filename):
"""adds the vehicle to an existing catalog
Parameters
----------
filename (str): path to the catalog file
"""
cf = CatalogFile()
cf.open_catalog(filename)
cf.add_to_catalog(self)
cf.dump()

def add_axle(self, axle):
"""adds an additional axle to the vehicle
Expand All @@ -1209,19 +1088,6 @@ def add_axle(self, axle):
self.axles.add_axle(axle)
return self

def add_parameter(self, parameter):
"""adds a parameter declaration to the vehicle
Parameters
----------
parameter (Parameter): A new parameter declaration for the vehicle
"""
if not isinstance(parameter, Parameter):
raise TypeError("parameter input is not of type Parameter")
self.parameters.add_parameter(parameter)
return self

def add_property(self, name, value):
"""adds a single property to the vehicle
Expand Down Expand Up @@ -1275,7 +1141,7 @@ def get_attributes(self):
def get_element(self):
"""returns the elementTree of the Vehicle"""
element = ET.Element("Vehicle", attrib=self.get_attributes())
element.append(self.parameters.get_element())
self.add_parameters_to_element(element)
element.append(self.boundingbox.get_element())
element.append(self.dynamics.get_element("Performance"))
element.append(self.axles.get_element())
Expand Down
Loading

0 comments on commit 9715d41

Please sign in to comment.