コード例 #1
0
ファイル: map_attributes.py プロジェクト: utcoupe/coupe19
    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
コード例 #2
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
コード例 #3
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)
コード例 #4
0
ファイル: map_classes.py プロジェクト: mouhandiaye/coupe18
 def __init__(self, initdict):
     LoadingHelpers.checkKeysExist(initdict, "position", "marker")
     super(Waypoint, self).__init__({
         "position":
         Position2D(initdict["position"]),
         "marker":
         MarkerRViz(initdict["marker"])
     })
コード例 #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")
     ]
コード例 #6
0
ファイル: map_attributes.py プロジェクト: utcoupe/coupe19
 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
コード例 #7
0
ファイル: map_classes.py プロジェクト: mouhandiaye/coupe18
 def __init__(self, initdict):
     LoadingHelpers.checkKeysExist(initdict, "position", "shape", "marker",
                                   "properties")
     super(Zone, self).__init__({
         "position":
         Position2D(initdict["position"]),
         "shape":
         Shape2D(initdict["shape"]),
         "marker":
         MarkerRViz(initdict["marker"]),
         "properties":
         DictManager(initdict["properties"])
     })
コード例 #8
0
ファイル: map_attributes.py プロジェクト: utcoupe/coupe19
    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 ""
コード例 #9
0
ファイル: map_classes.py プロジェクト: mouhandiaye/coupe18
    def __init__(self, initdict):
        LoadingHelpers.checkKeysExist(initdict, "shape", "marker", "walls")

        # Instantiate the walls before creating the dict
        for layer in initdict["walls"]:
            for wall in initdict["walls"][layer]:
                initdict["walls"][layer][wall] = Wall(
                    initdict["walls"][layer][wall])
            initdict["walls"][layer] = DictManager(initdict["walls"][layer])

        super(Terrain, self).__init__({
            "shape": Shape2D(initdict["shape"]),
            "marker": MarkerRViz(initdict["marker"]),
            "walls": DictManager(initdict["walls"]),
        })
コード例 #10
0
ファイル: map_classes.py プロジェクト: mouhandiaye/coupe18
 def __init__(self, initdict):
     LoadingHelpers.checkKeysExist(initdict, "position", "shape", "marker",
                                   "chest", "trajectory")
     super(Entity, self).__init__({
         "position":
         Position2D(initdict["position"]),
         "shape":
         Shape2D(initdict["shape"]),
         "marker":
         MarkerRViz(initdict["marker"]),
         "chest":
         None,  # TODO Implement
         "trajectory":
         Trajectory(initdict["trajectory"])
     })
コード例 #11
0
ファイル: map_attributes.py プロジェクト: utcoupe/coupe19
 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"))
コード例 #12
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))
コード例 #13
0
    def __init__(self, xml, obj_classes):
        LoadingHelpers.checkChildExist(xml, "shape", "containers", "color")
        self.Shape = Shape2D(xml.find("shape"))
        xml.find("containers").attrib["name"] = "robot"
        self.Container = Container(xml.find("containers"), obj_classes)
        self.Color = Color(xml.find("color"))

        #TODO temporary, considering robot as rect. real xml marker (e.g. for meshes) ?
        m = ET.Element("marker")
        m.attrib["ns"] = "robot"
        m.attrib["type"] = "cube"
        m.attrib["z"] = 0.35 / 2
        scale = ET.SubElement(m, "scale")
        scale.attrib["x"] = self.Shape.Height
        scale.attrib["y"] = self.Shape.Width
        scale.attrib["z"] = 0.35
        orientation = ET.SubElement(m, "orientation")
        orientation.attrib["x"] = 0.0
        orientation.attrib["y"] = 0.0
        orientation.attrib["z"] = 0.0
        self.Marker = Marker(m)
コード例 #14
0
ファイル: map_attributes.py プロジェクト: utcoupe/coupe19
    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))
コード例 #15
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"))
コード例 #16
0
ファイル: map_classes.py プロジェクト: mouhandiaye/coupe18
 def __init__(self, initdict):
     LoadingHelpers.checkKeysExist(initdict, "position", "shape")
     super(Wall, self).__init__({
         "position": Position2D(initdict["position"]),
         "shape": Shape2D(initdict["shape"])
     })
コード例 #17
0
ファイル: map_attributes.py プロジェクト: mouhandiaye/coupe18
 def __init__(self, initdict):
     LoadingHelpers.checkKeysExist(initdict, "frame_id", "x", "y", "type")
     super(Position2D, self).__init__(initdict)
コード例 #18
0
ファイル: map_attributes.py プロジェクト: mouhandiaye/coupe18
 def __init__(self, initdict):
     LoadingHelpers.checkKeysExist(initdict, "ns", "id", "type", "scale",
                                   "z", "orientation", "color")
     # TODO let some arguments be optional (orientation not given -> 0, 0, 0)
     super(MarkerRViz, self).__init__(initdict)
コード例 #19
0
ファイル: map_attributes.py プロジェクト: mouhandiaye/coupe18
 def __init__(self, initdict):
     LoadingHelpers.checkKeysExist(initdict, "type")
     # TODO : validate for each shape type
     super(Shape2D, self).__init__(initdict)
コード例 #20
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)
コード例 #21
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")]