Example #1
0
QVariant MOParameters::value(QString name,QVariant defaultValue) const
{
    MOParameter* param = this->findItem(name,MOParameter::NAME);
    if(param)
        return param->getFieldValue(MOParameter::VALUE);
    else
    {
        QString msg = "MOParameters : did not find parameter :"+name;
        InfoSender::instance()->debug(msg);
        return defaultValue;
    }
}
Example #2
0
void WidgetParameters::setDefaultValues()
{
    QVariant defaultValue;
    MOParameter* curParam;
    QWidget* curWidget;


    for(int i=0;i<_mapValueWidgets.keys().size();i++)
    {
        //        curIndex = _mapValueWidgets.keys().at(i);
        //        iParam = _localParameters->findItem(curIndex,MOParameter::INDEX);
        curParam = _mapValueWidgets.keys().at(i);
        curWidget = _mapValueWidgets.value(curParam,NULL);

        // get default value
        defaultValue = curParam->getFieldValue(MOParameter::DEFAULTVALUE);

        setValue(curWidget,defaultValue);
    }

}
Example #3
0
QGridLayout* WidgetParameters::buildLayoutFromParameters()
{
    //Adding Layout
    QGridLayout *mainLayout = new QGridLayout(this);

    // get groups
    QMultiMap<QString,MOParameter*> groupmap = _localParameters->groupmap();
    QStringList groups = groupmap.uniqueKeys();


    QStringList paramNames;
    for(int i=0;i<_localParameters->size();i++)
        paramNames.push_back(_localParameters->at(i)->name());

    QPushButton *newPush;
    MOParameter* parameter;
    MOParameterListed *paramList;
    QList<MOParameter*> groupParameters;
    QGridLayout *curLayout;
    QGroupBox *curBox;

    // create group box
    for(int iG=0;iG<groups.size();iG++)
    {
        int iRow=0;
        if(groups.size()>1)
        {
            curBox = new QGroupBox(groups.at(iG),this);
            curLayout = new QGridLayout(curBox);
        }
        else
            curLayout = mainLayout;

        groupParameters = groupmap.values(groups.at(iG));

        // to reproduce parameters order, start from the end
        // it seems MultiMap behaves like a pile
        for(int iP=groupParameters.size()-1;iP>=0;iP--)
        {
            parameter = groupParameters.at(iP);
            // add setting
            QString dispName;
            if(parameter->name().contains("/"))
                dispName = parameter->name().section("/",1,-1);
            else
                dispName = parameter->name();

            curLayout->addWidget(new QLabel(parameter->description()),iRow,0);
            //boxLayout->addWidget(new QLabel(dispName),iRow,0);

            int type = parameter->getFieldValue(MOParameter::TYPE).toInt();
            QWidget *valueWidget;
            QVariant value = parameter->getFieldValue(MOParameter::VALUE);

            switch(type)
            {
            case MOParameter::STRING :
                valueWidget = new QLineEdit(this);
                ((QLineEdit*)valueWidget)->setText(value.toString());
                connect(((QLineEdit*)valueWidget),SIGNAL(textChanged(QString)),this,SLOT(onValueChanged()));
                break;
            case MOParameter::FILEPATH :
                valueWidget = new QLineEdit(this);
                ((QLineEdit*)valueWidget)->setText(value.toString());
                connect(((QLineEdit*)valueWidget),SIGNAL(textChanged(QString)),this,SLOT(onValueChanged()));
                // add button
                newPush = new QPushButton("...",this);
                newPush->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Preferred);
                _pathsMap.insert(newPush,((QLineEdit*)valueWidget));
                curLayout->addWidget(newPush,iRow,2);
                connect(newPush,SIGNAL(clicked()),this,SLOT(onSelectFileClicked()));
                break;
            case MOParameter::FOLDERPATH :
                valueWidget = new QLineEdit(this);
                ((QLineEdit*)valueWidget)->setText(value.toString());
                connect(((QLineEdit*)valueWidget),SIGNAL(textChanged(QString)),this,SLOT(onValueChanged()));
                //add button
                newPush = new QPushButton("...",this);
                newPush->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Preferred);
                _pathsMap.insert(newPush,((QLineEdit*)valueWidget));
                curLayout->addWidget(newPush,iRow,2);
                connect(newPush,SIGNAL(clicked()),this,SLOT(onSelectFolderClicked()));
                break;

            case MOParameter::DOUBLE :
                valueWidget = new QScienceSpinBox(this);
                ((QScienceSpinBox*)valueWidget)->setMinimum(parameter->getFieldValue(MOParameter::MIN).toDouble());
                ((QScienceSpinBox*)valueWidget)->setMaximum(parameter->getFieldValue(MOParameter::MAX).toDouble());
                ((QScienceSpinBox*)valueWidget)->setDecimals(10);
                ((QScienceSpinBox*)valueWidget)->setValue(value.toDouble());
                connect(((QScienceSpinBox*)valueWidget),SIGNAL(valueChanged(double)),this,SLOT(onValueChanged()));
                break;
            case MOParameter::INT :
                valueWidget = new QSpinBox(this);
                ((QSpinBox*)valueWidget)->setMinimum(parameter->getFieldValue(MOParameter::MIN).toInt());
                ((QSpinBox*)valueWidget)->setMaximum(parameter->getFieldValue(MOParameter::MAX).toInt());
                ((QSpinBox*)valueWidget)->setValue(value.toInt());
                connect(((QSpinBox*)valueWidget),SIGNAL(valueChanged(int)),this,SLOT(onValueChanged()));
                break;
            case MOParameter::BOOL :
                valueWidget = new QCheckBox(this);
                Qt::CheckState state;
                if(value.toBool())
                    state = Qt::Checked;
                else
                    state = Qt::Unchecked;
                connect(((QCheckBox*)valueWidget),SIGNAL(stateChanged(int)),this,SLOT(onValueChanged()));
                ((QCheckBox*)valueWidget)->setCheckState(state);
                break;
            case MOParameter::LIST :
                //if is a list, param should be a MOParameterListed
                valueWidget = new QComboBox(this);
                paramList = dynamic_cast<MOParameterListed*>(parameter);
                if(paramList)
                {
                    //adding list items in qcombobox
                    for(int iValue = 0 ; iValue<paramList->mapList().keys().size();iValue++)
                    {
                        ((QComboBox*)valueWidget)->addItem(
                                    paramList->mapList().values().at(iValue),
                                    paramList->mapList().keys().at(iValue));
                    }
                    // set current index
                    ((QComboBox*)valueWidget)->setCurrentIndex(((QComboBox*)valueWidget)->findData(value));
                    connect(((QComboBox*)valueWidget),SIGNAL(currentIndexChanged(int)),this,SLOT(onValueChanged()));
                }
                break;
            default :
                valueWidget = new QLineEdit(this);
                ((QLineEdit*)valueWidget)->setText(value.toString());
                connect(((QLineEdit*)valueWidget),SIGNAL(textChanged(QString)),this,SLOT(onValueChanged()));
                break;

            }

            curLayout->addWidget(valueWidget,iRow,1);
            valueWidget->setEnabled(_editable);

            // store (to save data when click ok)
            _mapValueWidgets.insert(parameter,valueWidget);
            _paramNames.push_back(parameter->name());
            _paramTypes.push_back(type);

            iRow++;
        }

        if(groups.size()>1)
        {
            curBox->setLayout(curLayout);
            mainLayout->addWidget(curBox);
        }
    }




    if(_editable)
        updateEnabled(); //update

    return mainLayout;
}
Example #4
0
void Dymola::writeParameters(QString &allDsinText,MOParameters *parameters)
{
    QString newLine;

    QStringList lines = allDsinText.split("\n");
    int iLForm = lines.indexOf(QRegExp(".* # lform .*"));
    if(iLForm>-1)
    {
        newLine =  " 0                         # lform    0/1 ASCII/Matlab-binary storage format of results";
        lines.replace(iLForm,newLine);
    }


    MOParameter* pStopTime = parameters->findItem(DymolaParameters::str(DymolaParameters::STOPTIME));
    int iLStopTime = lines.indexOf(QRegExp(".* # StopTime .*"));
    if((iLStopTime>-1) && pStopTime)
    {
        newLine =  "       "
                +pStopTime->getFieldValue(MOParameter::VALUE).toString()
                +"                   # StopTime     Time at which integration stops";
        lines.replace(iLStopTime,newLine);
    }

    MOParameter* pTolerance = parameters->findItem(DymolaParameters::str(DymolaParameters::TOLERANCE));
    int iLTolerance = lines.indexOf(QRegExp(".*  # Tolerance .*"));
    if((iLTolerance>-1) && pTolerance)
    {
        newLine =  "       "
                +pTolerance->getFieldValue(MOParameter::VALUE).toString()
                +"                   # nInterval    Relative precision of signals for \n                            #              simulation, linearization and trimming";
        lines.replace(iLTolerance,newLine);
    }

    MOParameter* pnInterval = parameters->findItem(DymolaParameters::str(DymolaParameters::NINTERVAL));
    int iLnInterval = lines.indexOf(QRegExp(".*  # nInterval .*"));
    if((iLnInterval>-1) && pnInterval)
    {
        newLine =  "       "
                +pnInterval->getFieldValue(MOParameter::VALUE).toString()
                +"                   # nInterval    Number of communication intervals, if > 0";
        lines.replace(iLnInterval,newLine);
    }

    MOParameter* pSolver = parameters->findItem(DymolaParameters::str(DymolaParameters::SOLVER));
    int iLSolver = lines.indexOf(QRegExp(".*  # Algorithm .*"));
    if((iLSolver>-1) && pSolver)
    {
        newLine =  "       "
                +pSolver->getFieldValue(MOParameter::VALUE).toString()
                +"                   # Algorithm    Integration algorithm as integer";
        lines.replace(iLSolver,newLine);
    }

    MOParameter* pFinalFile = parameters->findItem(DymolaParameters::str(DymolaParameters::FINALFILE));
    int iLineLRes = lines.indexOf(QRegExp(".*  # lres     0/1 do not/store results .*"));
    if((iLineLRes>-1) && pFinalFile)
    {
        int lRes;
        switch(pFinalFile->value().toInt())
        {
        case DymolaParameters::DSFINAL :
            lRes = 0;
            break;
        case DymolaParameters::DSRES :
        default :
            lRes = 1;
            break;
        }

        newLine =  "       "
                +QString::number(lRes)
                +"                   # lres     0/1 do not/store results on result file";
        lines.replace(iLineLRes,newLine);
    }


    allDsinText = lines.join("\n");
}
Example #5
0
void OpenModelica::setInputVariablesTxt(QString fileName, MOVector<Variable> *variables,QString modModelName,MOParameters *parameters)
{
    QFileInfo fileinfo = QFileInfo(fileName);
    if (fileinfo.exists())
    {
        QFile file(fileinfo.filePath());
        file.open(QIODevice::ReadOnly);
        QTextStream textRead(&file);
        QString allText = textRead.readAll();
        file.close();
        // change variable values
        QRegExp rxLine;
        int index=0;
        QString newLine;
        QString varName;
        int iCurVar;
        Variable* curVar;
        QStringList fields;

        for(int iV=0;iV<variables->size();iV++)
        {
            curVar = variables->at(iV);
            varName = curVar->name(Variable::SHORT);
            //varName = varName.remove(modModelName+".");
            rxLine.setPattern(sciNumRx()+"\\s*(//[\\w*|\\s*]*//|//)\\s*"+varName);
            index = rxLine.indexIn(allText);

            if(index>-1)
            {
                fields = rxLine.capturedTexts();
                newLine = curVar->getFieldValue(Variable::VALUE).toString() +"\t";
                newLine += fields.at(2)+varName;
                allText = allText.replace(rxLine.cap(0),newLine);
            }
            else
            {
                InfoSender::instance()->send(Info("Warning : unable to set variable value (not found in init file):"+varName,ListInfo::ERROR2));
            }
        }

        // Parameters to write in init file
        /// @deprecated Now OM uses xml input.
        if(parameters)
        {
            QList<OpenModelicaParameters::Parameters> initParameters; // parameters to specify in init file
            initParameters << OpenModelicaParameters::STOPTIME;

            QStringList paramIndicators;
            paramIndicators << "stop value";


            QVariant paramValue;
            QString paramName;
            MOParameter * curParam;
            int iP;
            for(int i=0;i<initParameters.size();i++)
            {
                curParam = parameters->findItem(OpenModelicaParameters::str(initParameters.at(i)));
                if(curParam)
                {
                    paramName = paramIndicators.at(i);
                    paramValue = curParam->getFieldValue(MOParameter::VALUE);
                    rxLine.setPattern(sciNumRx()+"\\s*(//[\\w*|\\s*]*//|//)\\s*"+paramName);
                    index = rxLine.indexIn(allText);

                    if(index>-1)
                    {
                        fields = rxLine.capturedTexts();
                        newLine = paramValue.toString() +"\t";
                        newLine += fields.at(2)+paramName;
                        allText = allText.replace(rxLine.cap(0),newLine);
                    }
                    else
                    {
                        InfoSender::instance()->send(Info("Warning : unable to set parameter value (not found in init file):"+paramName,ListInfo::ERROR2));
                    }
                }
            }
        }


        fileinfo.setFile(fileName);
        file.setFileName(fileinfo.filePath());
        bool ok = file.open(QIODevice::WriteOnly);
        QTextStream textWrite(&file);
        textWrite<<allText;
        file.close();
    }
}