def loadXODE(self, filename, reload=False): """ loads an XODE file (xml format) and parses it. """ f = open(filename) self._currentXODEfile = filename p = xode.parser.Parser() self.root = p.parseFile(f) f.close() try: # filter all xode "world" objects from root, take only the first one world = [ x for x in self.root.getChildren() if isinstance(x, xode.parser.World) ][0] except IndexError: # malicious format, no world tag found print(("no <world> tag found in " + filename + ". quitting.")) sys.exit() self.world = world.getODEObject() self._setWorldParameters() try: # filter all xode "space" objects from world, take only the first one space = [ x for x in world.getChildren() if isinstance(x, xode.parser.Space) ][0] except IndexError: # malicious format, no space tag found print(("no <space> tag found in " + filename + ". quitting.")) sys.exit() self.space = space.getODEObject() # load bodies and geoms for painting self.body_geom = [] self._parseBodies(self.root) if self.verbosity > 0: print("-------[body/mass list]-----") for (body, _) in self.body_geom: try: print((body.name, body.getMass())) except AttributeError: print("<Nobody>") # now parse the additional parameters at the end of the xode file self.loadConfig(filename, reload)
def loadXODE(self, filename, reload=False): """ loads an XODE file (xml format) and parses it. """ f = file(filename) self._currentXODEfile = filename p = xode.parser.Parser() self.root = p.parseFile(f) f.close() try: # filter all xode "world" objects from root, take only the first one world = filter(lambda x: isinstance(x, xode.parser.World), self.root.getChildren())[0] except IndexError: # malicious format, no world tag found print "no <world> tag found in " + filename + ". quitting." sys.exit(1) self.world = world.getODEObject() self._setWorldParameters() try: # filter all xode "space" objects from world, take only the first one space = filter(lambda x: isinstance(x, xode.parser.Space), world.getChildren())[0] except IndexError: # malicious format, no space tag found print "no <space> tag found in " + filename + ". quitting." sys.exit(1) self.space = space.getODEObject() # load bodies and geoms for painting self.body_geom = [] self._parseBodies(self.root) if self.verbose: print "-------[body/mass list]-----" for (body, _) in self.body_geom: try: print body.name, body.getMass() except AttributeError: print "<Nobody>" # now parse the additional parameters at the end of the xode file self.loadConfig(filename, reload) return