//添加元素 void FilterParameter::addQDomElement(FilterParameterSet &par, QDomElement &np) { QString name=np.attribute("name"); QString type=np.attribute("type"); qDebug(" Reading Param with name %s : %s",qPrintable(name),qPrintable(type)); if(type=="Bool") { par.addBool(name,np.attribute("value")!=QString("false")); return; } if(type=="Int") { par.addInt(name,np.attribute("value").toInt()); return; } if(type=="Float") { par.addFloat(name,np.attribute("value").toDouble()); return; } if(type=="String") { par.addString(name,np.attribute("value")); return; } if(type=="AbsPerc") { par.addAbsPerc(name,np.attribute("value").toFloat(),np.attribute("min").toFloat(),np.attribute("max").toFloat()); return; } if(type=="Color") { par.addColor(name,QColor::QColor(np.attribute("rgb").toUInt())); return; } if(type=="Matrix44") { Matrix44f mm; for(int i=0;i<16;++i) mm.V()[i]=np.attribute(QString("val")+QString::number(i)).toDouble(); par.addMatrix44(name,mm); return; } if(type=="Enum") { QStringList list = QStringList::QStringList(); for(QDomElement ns = np.firstChildElement("EnumString"); !ns.isNull(); ns = ns.nextSiblingElement("EnumString")){ list<<ns.attribute("value"); } par.addEnum(name,np.attribute("value").toInt(),list); return; } if(type == MeshPointerName()) { par.addMesh(name, np.attribute(ValueName()).toInt()); return; } if(type == FloatListName()) { QList<float> values; for(QDomElement listItem = np.firstChildElement(ItemName()); !listItem.isNull(); listItem = listItem.nextSiblingElement(ItemName())) { values.append(listItem.attribute(ValueName()).toFloat()); } par.addFloatList(name,values); return; } if(type == DynamicFloatName()) { par.addDynamicFloat(name, np.attribute(ValueName()).toFloat(), np.attribute(MinName()).toFloat(), np.attribute(MaxName()).toFloat(), np.attribute(MaskName()).toInt()); return; } if(type == OpenFileNameName()) { par.addOpenFileName(name, np.attribute(ValueName())); return; } if(type == SaveFileNameName()) { par.addSaveFileName(name, np.attribute(ValueName())); return; } if(type=="Point3f") { Point3f val; val[0]=np.attribute("x").toFloat(); val[1]=np.attribute("y").toFloat(); val[2]=np.attribute("z").toFloat(); par.addPoint3f(name, val); return; } assert(0); // we are trying to parse an unknown xml element }
void FilterParameterSet::addMatrix44 (QString name, Matrix44f defaultVal, QString desc, QString tooltip) { assert(!hasParameter(desc)); FilterParameter p(name,desc,tooltip); QList<QVariant> matrixVals; for(int i=0;i<16;++i) matrixVals.append(defaultVal.V()[i]); p.fieldVal=matrixVals; p.fieldType=FilterParameter::PARMATRIX; paramList.push_back(p); }
//对matrix类型参数的操作 Matrix44f FilterParameterSet::getMatrix44(QString name) const { const FilterParameter *p=findParameter(name); assert(p); assert(p->fieldType==FilterParameter::PARMATRIX); assert(p->fieldVal.type()==QVariant::List); Matrix44f matrix; QList<QVariant> matrixVals = p->fieldVal.toList(); assert(matrixVals.size()==16); for(int i=0;i<16;++i) matrix.V()[i]=matrixVals[i].toDouble(); return matrix; }
bool RichParameterFactory::create( const QDomElement& np,RichParameter** par ) { QString name=np.attribute("name"); QString type=np.attribute("type"); QString desc=np.attribute("description"); QString tooltip=np.attribute("tooltip"); qDebug(" Reading Param with name %s : %s",qPrintable(name),qPrintable(type)); bool corrconv = false; if(type=="RichBool") { QString val = np.attribute("value").toLower(); if ((val != QString("true")) && (val != QString("false"))) return false; *par = new RichBool(name,np.attribute("value")!=QString("false"),desc,tooltip); return true; } if(type=="RichInt") { int val = np.attribute("value").toInt(&corrconv); if (!corrconv) return false; *par = new RichInt(name,val,desc,tooltip); return true; } if(type=="RichFloat") { float val = np.attribute("value").toFloat(&corrconv); if (!corrconv) return false; *par = new RichFloat(name,val,desc,tooltip); return true; } if(type=="RichString") { *par = new RichString(name,np.attribute("value"),desc,tooltip); return true; } if(type=="RichAbsPerc") { float val = np.attribute("value").toFloat(&corrconv); if ((!corrconv) && (val >= 0.0f) && (val <= 100.0f)) return false; float min = np.attribute("min").toFloat(&corrconv); if (!corrconv) return false; float max = np.attribute("max").toFloat(&corrconv); if (!corrconv) return false; *par = new RichAbsPerc(name,val,min,max,desc,tooltip); return true; } if(type=="RichColor") { unsigned int r = np.attribute("r").toUInt(&corrconv); if ((!corrconv) && (r <= 255)) return false; unsigned int g = np.attribute("g").toUInt(&corrconv); if ((!corrconv) && (g <= 255)) return false; unsigned int b = np.attribute("b").toUInt(&corrconv); if ((!corrconv) && (b <= 255)) return false; unsigned int a = np.attribute("a").toUInt(&corrconv); if ((!corrconv) && (a <= 255)) return false; QColor col(r,g,b,a); *par= new RichColor(name,col,desc,tooltip); return true; } if(type=="RichMatrix44f") { Matrix44f mm; for(int i=0;i<16;++i) { float val = np.attribute(QString("val")+QString::number(i)).toFloat(&corrconv); if (!corrconv) return false; mm.V()[i]=val; } *par = new RichMatrix44f(name,mm,desc,tooltip); return true; } if(type=="RichEnum") { QStringList list; int enum_card = np.attribute(QString("enum_cardinality")).toUInt(&corrconv); if (!corrconv) return false; for(int i=0;i<enum_card;++i) list<<np.attribute(QString("enum_val")+QString::number(i)); int val = np.attribute("value").toInt(&corrconv); if ((!corrconv) && (val >=0) && (val < enum_card)) return false; *par = new RichEnum(name,val,list,desc,tooltip); return true; } if(type == "RichMesh") { int val = np.attribute("value").toInt(&corrconv); if (!corrconv) return false; *par = new RichMesh(name, val,desc,tooltip); return true; } if(type == "RichFloatList") { //to be implemented assert(0); } if(type == "RichDynamicFloat") { float min = np.attribute("min").toFloat(&corrconv); if (!corrconv) return false; float max = np.attribute("max").toFloat(&corrconv); if (!corrconv) return false; float val = np.attribute("value").toFloat(&corrconv); if ((!corrconv) && (val >= min) && (val <= max)) return false; *par = new RichDynamicFloat(name, val, min, max, desc, tooltip); return true; } if(type == "RichOpenFile") { QStringList list; int exts_card = np.attribute(QString("exts_cardinality")).toUInt(&corrconv); if (!corrconv) return false; for(int i=0;i<exts_card;++i) list<<np.attribute(QString("exts_val")+QString::number(i)); QString defdir = np.attribute("value"); *par = new RichOpenFile(name,defdir,list,desc,tooltip); return true; } if(type == "RichSaveFile") { QString deffile = np.attribute("value"); QString ext = np.attribute("ext"); *par = new RichSaveFile(name,deffile,ext,desc,tooltip); return true; } if(type=="RichPoint3f") { Point3f val; val[0]=np.attribute("x").toFloat(&corrconv); if (!corrconv) return false; val[1]=np.attribute("y").toFloat(&corrconv); if (!corrconv) return false; val[2]=np.attribute("z").toFloat(&corrconv); if (!corrconv) return false; *par = new RichPoint3f(name, val,desc,tooltip); return true; } if(type=="RichShotf") { Shotf val; assert(0); //TODO!!!! *par = new RichShotf(name, val,desc,tooltip); return true; } return false; }