QDomNode QDomDocumentProto::replaceChild(const QDomNode& newChild, const QDomNode& oldChild) { QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject()); if (item) return item->replaceChild(newChild, oldChild); return QDomNode(); }
void OpenModelica::setInputParametersXml(QDomDocument &doc,MOParameters *parameters) { QDomElement xfmi = doc.firstChildElement("fmiModelDescription"); QDomElement oldxfmi = xfmi; QDomElement xExp = xfmi.firstChildElement("DefaultExperiment"); QDomElement oldxExp = xExp; double starttime = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::STARTTIME),0).toDouble(); double stoptime = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::STOPTIME),1).toDouble(); int nbIntervals = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::NBINTERVALS),2).toInt(); double stepSize = (stoptime-starttime)/nbIntervals; MOParameter * curParam; MOParameterListed* curParamListed; for(int i=0;i<parameters->size();i++) { curParam = parameters->at(i); if(!curParam->name().contains(" ")) // remove old parameters, temporary { if(curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::SOLVER)) { curParamListed = dynamic_cast<MOParameterListed*>(curParam); xExp.setAttribute(curParamListed->name(),curParamListed->strValue()); } else if(curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::OUTPUT)) { curParamListed = dynamic_cast<MOParameterListed*>(curParam); xExp.setAttribute(curParamListed->name(),curParamListed->strValue()); } else if (curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::NBINTERVALS)) { xExp.setAttribute("stepSize",QString::number(stepSize)); } else { xExp.setAttribute(curParam->name(),curParam->value().toString()); } } } // update xfmi with new vars xfmi.replaceChild(xExp,oldxExp); doc.replaceChild(xfmi,oldxfmi); }
void ModPlusExeCtrl::setInputVariablesXml(QDomDocument & doc, QString modelName, MOVector<Variable> *variables) { QDomElement xfmi = doc.firstChildElement("fmiModelDescription"); QDomElement oldxfmi = xfmi; QDomElement xModelVars = xfmi.firstChildElement("ModelVariables"); QDomElement oldxModelVars = xModelVars; QDomNodeList listScalarVars = xModelVars.elementsByTagName("ScalarVariable"); // filling map QMap<QString,int> mapScalarVars; //<name,index in listScalarVars> QMap<QDomElement,QDomElement> mapNewScalarVars; // <old node,new node> QDomElement curVar; QDomElement oldVar; QDomElement newVar; int index; QDomElement oldType; QDomElement newType; QString localVarName; // create map for index looking for(int i=0;i<listScalarVars.size();i++) { curVar = listScalarVars.at(i).toElement(); mapScalarVars.insert(curVar.attribute("name"),i); } // change variables values for(int i=0;i<variables->size();i++) { // getting local var name (name in init file does not contain model name) localVarName = variables->at(i)->name(Variable::SHORT); if(localVarName.contains(modelName)) localVarName = localVarName.remove(modelName+"."); index = mapScalarVars.value(localVarName,-1); if(index>-1) { oldVar = listScalarVars.at(index).toElement(); newVar = oldVar; oldType = newVar.firstChildElement("Real"); if(oldType.isNull()) oldType = newVar.firstChildElement("Integer"); if(oldType.isNull()) oldType = newVar.firstChildElement("Boolean"); if(!oldType.isNull()) { newType = oldType; newType.setAttribute("start",variables->at(i)->value().toString()); newVar.replaceChild(newType,oldType); xModelVars.replaceChild(newVar,oldVar); } xModelVars.replaceChild(newVar,oldVar); } } // update xfmi with new vars xfmi.replaceChild(xModelVars,oldxModelVars); doc.replaceChild(xfmi,oldxfmi); }