Esempio n. 1
0
    def __init__(self, xml, obj_classes, check_valid=True):
        LoadingHelpers.checkAttribExist(xml, "name")
        self.Name = xml.get("name")
        self.Position = Position2D(
            xml.find("position")) if xml.find("position") is not None else None
        self.Shape = Shape2D(
            xml.find("shape")) if xml.find("shape") is not None else None
        self.Tags = [l.text for l in xml.find("tags").findall("tag")
                     ] if xml.find("tags") is not None else []

        self.Color = Color(
            xml.find("color")) if xml.find("color") is not None else None

        if xml.get("class"):  # merge info with class
            other = copy.deepcopy(
                [c for c in obj_classes if c.Name == xml.get("class")][0])
            # self is prioritary
            self.Position = self.Position if self.Position is not None else other.Position
            self.Shape = self.Shape if self.Shape is not None else other.Shape
            self.Color = self.Color if self.Color is not None else other.Color
            self.Tags += other.Tags

            self.Marker = copy.deepcopy(other.Marker)
            if xml.find("marker") is not None:
                self.Marker.merge(xml.find("marker"))
        else:
            self.Marker = Marker(
                xml.find("marker")) if xml.find("marker") is not None else None

        if check_valid is True:
            self.check_valid(
            )  # disabled when manually creating a class through code
        print self.Tags  #TODO remove
Esempio n. 2
0
 def __init__(self, xml, validate=True):
     self.Name = ""
     self.Position = Position2D(None, validate=False)
     if validate:
         LoadingHelpers.checkAttribExist(xml, "name")
         self.Name = xml.get("name")
         self.Position = Position2D(xml, validate)
Esempio n. 3
0
    def merge(self, xml_other):  # other is prioritary
        self.Type = xml_other.attrib[
            "type"] if "type" in xml_other.attrib else self.Type
        self.Namespace = xml_other.attrib[
            "ns"] if "ns" in xml_other.attrib else self.Namespace
        self.Z = float(
            xml_other.attrib["z"]) if "z" in xml_other.attrib else self.Z

        if xml_other.find("scale") is not None:
            LoadingHelpers.checkAttribExist(xml_other.find("scale"), "x", "y",
                                            "z")
            other_scale = [
                float(xml_other.find("scale").get("x")),
                float(xml_other.find("scale").get("y")),
                float(xml_other.find("scale").get("z"))
            ]
            self.Scale = other_scale

        if xml_other.find("orientation") is not None:
            LoadingHelpers.checkAttribExist(xml_other.find("orientation"), "x",
                                            "y", "z")
            other_ori = [
                float(xml_other.find("orientation").get("x")),
                float(xml_other.find("orientation").get("y")),
                float(xml_other.find("orientation").get("z"))
            ]
            self.Orientation = other_ori

        self.MeshPath = xml_other.attrib[
            "mesh_path"] if "mesh_path" in xml_other.attrib else self.MeshPath
Esempio n. 4
0
    def __init__(self, xml):
        LoadingHelpers.checkAttribExist(xml, "type", "ns", "z")
        LoadingHelpers.checkChildExist(xml, "scale", "orientation")

        self.Type = xml.get("type")
        LoadingHelpers.checkValueValid(self.Type, "cube", "cylinder", "sphere",
                                       "arrow", "mesh")
        self.Namespace = xml.get("ns")
        self.Z = float(xml.get("z"))

        LoadingHelpers.checkAttribExist(xml.find("scale"), "x", "y", "z")
        self.Scale = [
            float(xml.find("scale").get("x")),
            float(xml.find("scale").get("y")),
            float(xml.find("scale").get("z"))
        ]
        self.Orientation = [
            float(xml.find("orientation").get("x")),
            float(xml.find("orientation").get("z")),
            float(xml.find("orientation").get("z"))
        ]

        # Type-specific attributes
        self.MeshPath = xml.find("mesh_path").text if xml.find(
            "mesh_path") is not None else ""
Esempio n. 5
0
 def __init__(self, xml, xml_classes):
     LoadingHelpers.checkAttribExist(xml, "name")
     self.Name = xml.get("name")
     self.Elements = [
         Container(c, xml_classes) for c in xml.findall("container")
     ]
     self.Elements += [
         Object(o, xml_classes) for o in xml.findall("object")
     ]
Esempio n. 6
0
 def __init__(self, xml, validate=True):
     self.X = self.Y = self.A = 0.0
     self.HasAngle = False
     self.Frame = "map"
     if validate:
         LoadingHelpers.checkAttribExist(xml, "x", "y")
         self.X = float(xml.get("x"))
         self.Y = float(xml.get("y"))
         self.A = float(xml.get("a")) if "a" in xml.attrib else 0.0
         self.Frame = xml.get(
             "frame_id") if "frame_id" in xml.attrib else "map"
         self.HasAngle = "a" in xml.attrib
Esempio n. 7
0
 def __init__(self, xml):
     LoadingHelpers.checkAttribExist(xml, "name")
     base = [c for c in map.MapManager.Colors if c.Name == xml.get("name")]
     if base:
         color = copy.deepcopy(base[0])
         self.Name = color.Name
         self.R = color.R
         self.G = color.G
         self.B = color.B
         self.A = color.A
     else:  # create a new color
         LoadingHelpers.checkAttribExist(xml, "name", "r", "g", "b")
         self.Name = xml.get("name")
         self.R = float(xml.get("r"))
         self.G = float(xml.get("g"))
         self.B = float(xml.get("b"))
         self.A = float(xml.get("a"))
Esempio n. 8
0
    def __init__(self, xml):
        LoadingHelpers.checkAttribExist(xml, "type")
        LoadingHelpers.checkChildExist(xml, "position", "marker", "color")
        self.Name = "terrain"
        self.Position = Position2D(xml.find("position"))
        self.Shape = Shape2D(xml)
        self.Marker = Marker(xml.find("marker"))
        self.Color = Color(xml.find("color"))

        self.Layers = [Layer(l) for l in xml.findall("layer")]

        # Copy walls from other layers (includes)
        for layer in self.Layers:
            for include in layer.Includes:
                for l in self.Layers:
                    if l.Name == include:
                        for w in l.Walls:
                            layer.Walls.append(copy.deepcopy(w))
Esempio n. 9
0
    def __init__(self, xml):
        LoadingHelpers.checkAttribExist(xml, "type")

        self.Type = xml.get("type")
        LoadingHelpers.checkValueValid(self.Type, "rect", "circle", "point")

        if self.Type == "rect":
            LoadingHelpers.checkAttribExist(xml, "w", "h")
            self.Width = float(xml.get("w"))
            self.Height = float(xml.get("h"))
        elif self.Type == "circle":
            LoadingHelpers.checkAttribExist(xml, "r")
            self.Radius = float(xml.get("r"))
        else:
            raise ValueError("ERROR: Shape type '{}' not supported.".format(
                self.Type))
Esempio n. 10
0
 def __init__(self, xml):
     LoadingHelpers.checkAttribExist(xml, "name")
     LoadingHelpers.checkChildExist(xml, "position", "shape")
     self.Name = xml.get("name")
     self.Position = Position2D(xml.find("position"))
     self.Shape = Shape2D(xml.find("shape"))
Esempio n. 11
0
 def __init__(self, xml):
     LoadingHelpers.checkAttribExist(xml, "name")
     self.Name = xml.get("name")
     self.Includes = [i.get("name") for i in xml.findall("include")]
     self.Walls = [Wall(w) for w in xml.findall("wall")]
Esempio n. 12
0
 def __init__(self, xml, obj_classes):
     LoadingHelpers.checkAttribExist(xml, "name")
     self.Name = xml.get("name")
     super(Class, self).__init__(xml, obj_classes, check_valid=False)