Ejemplo n.º 1
0
def generateFromXml(parent, name, xml_def, color):

    if str(type(xml_def)) != "<type 'Element'>":
        gear.log("Invalid input", gear.sev_error)
        return False

    xObject = xsixmldom.xmlToObject(xml_def)
    obj = xObject.generateObject(parent)
    obj.Name = name

    uti.setColor(obj, color)

    return obj
Ejemplo n.º 2
0
def generateFromXml(parent, name, xml_def, color):

    if str(type(xml_def)) != "<type 'Element'>":
        gear.log("Invalid input", gear.sev_error)
        return False

    xObject = xsixmldom.xmlToObject(xml_def)
    obj = xObject.generateObject(parent)
    obj.Name = name

    uti.setColor(obj, color)

    return obj
Ejemplo n.º 3
0
    def setFromXml(self, xml_comp):

        # ---------------------------------------------------
        # Settings
        xml_settings = xml_comp.find("settings")
        self.setParamDefValuesFromXml(xml_settings)

        # ---------------------------------------------------
        # First get all the object available in the xml (it's faster that way)
        xml_objects = xml_comp.find("objects")
        for xml_obj in xml_objects.findall("x3dobject"):
            localName = xml_obj.get("localName")
            xObj = xsixmldom.xmlToObject(xml_obj)

            xml_kine = xml_obj.find("kinematics")
            if xml_kine and len(xml_kine):
                t = xObj.getGlobalTransform()
                self.tra[localName] = t
                self.pos[localName] = t.Translation

            xml_prim = xml_obj.find("primitive")
            if xml_prim and len(xml_prim):
                self.prim[localName] = pri.getPrimitive(xml_obj)

            if localName in self.save_blade:
                self.blades[localName] = vec.Blade(self.tra[localName])

        # ---------------------------------------------------
        # Then check what is missing
        for name in self.save_transform:
            if "#" in name:
                i = 0
                while not self.minmax[name].max > 0 or i < self.minmax[
                        name].max:
                    localName = string.replaceSharpWithPadding(name, i)

                    if localName not in self.tra.keys():
                        break

                    self.atra.append(self.tra[localName])
                    self.apos.append(self.pos[localName])

                    i += 1

                if i < self.minmax[name].min:
                    gear.log(
                        "Minimum of object requiered for " + name +
                        " hasn't been reached", gear.sev_warning)
                    self.valid = False
                    continue
            else:
                if name not in self.tra.keys():
                    gear.log("Object missing : %s" % name, gear.sev_warning)
                    self.valid = False
                    continue

                self.atra.append(self.tra[name])
                self.apos.append(self.pos[name])

        for name in self.save_primitive:
            if name not in self.prim.keys():
                gear.log("Object missing : %s" % name, gear.sev_warning)
                self.valid = False
                continue

        for name in self.save_blade:
            if name not in self.blades.keys():
                gear.log("Object missing : %s" % name, gear.sev_warning)
                self.valid = False
                continue

        self.size = self.getSize()
        self.root_size = float(xml_comp.get("root_size"))
Ejemplo n.º 4
0
    def setFromXml(self, xml_comp):

        # ---------------------------------------------------
        # Settings
        xml_settings = xml_comp.find("settings")
        self.setParamDefValuesFromXml(xml_settings)

        # ---------------------------------------------------
        # First get all the object available in the xml (it's faster that way)
        xml_objects = xml_comp.find("objects")
        for xml_obj in xml_objects.findall("x3dobject"):
            localName = xml_obj.get("localName")
            xObj = xsixmldom.xmlToObject(xml_obj)

            xml_kine = xml_obj.find("kinematics")
            if xml_kine and len(xml_kine):
                t = xObj.getGlobalTransform()
                self.tra[localName] = t
                self.pos[localName] = t.Translation

            xml_prim = xml_obj.find("primitive")
            if xml_prim  and len(xml_prim):
                self.prim[localName] = pri.getPrimitive(xml_obj)

            if localName in self.save_blade:
                self.blades[localName] = vec.Blade(self.tra[localName])

        # ---------------------------------------------------
        # Then check what is missing
        for name in self.save_transform:
            if "#" in name:
                i = 0
                while not self.minmax[name].max > 0 or i < self.minmax[name].max:
                    localName = string.replaceSharpWithPadding(name, i)

                    if localName not in self.tra.keys():
                        break

                    self.atra.append(self.tra[localName])
                    self.apos.append(self.pos[localName])

                    i += 1

                if i < self.minmax[name].min:
                    gear.log("Minimum of object requiered for "+name+" hasn't been reached", gear.sev_warning)
                    self.valid = False
                    continue
            else:
                if name not in self.tra.keys():
                    gear.log("Object missing : %s"%name, gear.sev_warning)
                    self.valid = False
                    continue

                self.atra.append(self.tra[name])
                self.apos.append(self.pos[name])

        for name in self.save_primitive:
            if name not in self.prim.keys():
                gear.log("Object missing : %s"%name, gear.sev_warning)
                self.valid = False
                continue

        for name in self.save_blade:
            if name not in self.blades.keys():
                gear.log("Object missing : %s"%name, gear.sev_warning)
                self.valid = False
                continue

        self.size = self.getSize()
        self.root_size = float(xml_comp.get("root_size"))