def readLayoutFile(self, filename): layoutTree = etree.parse(filename) root = layoutTree.getroot() wallList = {} doorList = defaultdict(dict) for child in root: if child.tag == 'room': # parse the walls walls = child.findall('wall') for w in walls: wallName = w.attrib['name'] c = w.find('center') pos = self._extractListStr(c.text) pos = [float(p) for p in pos] s = w.find('size') size = self._extractListStr(s.text) size = [float(p) for p in size] wall = Wall(size, pos, self.environment, False) color = w.findtext('color') if color is not None: color = [float(p) for p in self._extractListStr(color)] wall.color = color wallList[wallName] = wall doors = child.findall('door') for d in doors: wallName = d.attrib['wall'] c = d.find('center') pos = self._extractListStr(c.text) pos = self._mixedToFloats(pos) s = d.find('size') size = self._extractListStr(s.text) size = self._mixedToFloats(size) doorList[wallName] = (pos, size) obstacles = child.findall('obstacle') for o in obstacles: wallName = o.attrib['name'] c = o.find('center') pos = self._extractListStr(c.text) pos = [float(p) for p in pos] s = o.find('size') size = self._extractListStr(s.text) size = [float(p) for p in size] wall = Wall(size, pos, self.environment, True) color = o.findtext('color') if color is not None: color = [float(p) for p in self._extractListStr(color.text)] wall.color = color wallList[wallName] = wall holeWalls = [] for key, dim in doorList.items(): victimWall = key doorPos, doorSize = dim holeWalls += Wall.cutHoleInWall(wallList[victimWall], doorSize, doorPos) wallList.pop(victimWall) holeWalls += wallList.values() return holeWalls