def symmetrize(self): if self.values["comp_side"] not in ["R", "L"]: gear.log("Can't symmetrize central component", gear.sev_error) return False #self.setParamDefValue("comp_side", uti.convertRLName(self.values["comp_side"])) for name, paramDef in self.paramDefs.items(): if paramDef.valueType == c.siString: self.setParamDefValue(name, uti.convertRLName(self.values[name])) for name, t in self.tra.items(): self.tra[name] = tra.getSymmetricalTransform2(t) for name, blade in self.blades.items(): self.blades[name] = vec.Blade(tra.getSymmetricalTransform2(blade.transform)) return True
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"))
def setFromHierarchy(self, root): self.root = root self.model = self.root.Model # --------------------------------------------------- # First check and set the settings self.settings = self.root.Properties("settings") if not self.settings: gear.log( "Can't find the 'setting' property. %s is not a proper guide." % self.root.Name, gear.sev_error) self.valid = False return self.setParamDefValuesFromProperty(self.settings) # --------------------------------------------------- # Then get the objects 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) obj = self.model.FindChild(self.getName(localName)) if not obj: break self.tra[localName] = obj.Kinematics.Global.Transform self.atra.append(obj.Kinematics.Global.Transform) self.pos[ localName] = obj.Kinematics.Global.Transform.Translation self.apos.append( obj.Kinematics.Global.Transform.Translation) 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: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue self.tra[name] = obj.Kinematics.Global.Transform self.atra.append(obj.Kinematics.Global.Transform) self.pos[name] = obj.Kinematics.Global.Transform.Translation self.apos.append(obj.Kinematics.Global.Transform.Translation) for name in self.save_primitive: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue self.prim[name] = pri.getPrimitive(obj) for name in self.save_blade: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue self.blades[name] = vec.Blade(obj.Kinematics.Global.Transform) self.size = self.getSize() self.root_size = self.root.size.Value