예제 #1
0
void Server::connectionReceived(){
    QTcpSocket *clientConnection = this->nextPendingConnection();
    clientContainer->append(clientConnection);

    connect(clientConnection, SIGNAL(readyRead()),
            this,             SLOT(textRead()), Qt::DirectConnection);

    connect(clientConnection, SIGNAL(disconnected()),
            this,             SLOT(disconnected()));
}
예제 #2
0
void NewRecordUser::check()
{
	textRead();
	if (emptyLine())
	{
		if (Site::checkUrl(m_url))
		{
			addMessage();
		}
		else 
		{
			ui->lineError->setText(Scale::coded("URL не работает."));
		}
	}
	else
	{
		ui->lineError->setText(Scale::coded("Заполни все поля, товарищ!"));
	}
}
예제 #3
0
파일: Dymola.cpp 프로젝트: cephdon/OMOptim
bool Dymola::setVariablesToDsin(QString fileName, QString modelName,MOVector<Variable> *variables,MOParameters *parameters,QString & errMsg)
{

    //Reading Preamble
    QFileInfo fileinfo = QFileInfo(fileName);
    QFile file(fileinfo.filePath());
    if(!file.open(QIODevice::ReadOnly))
    {
        errMsg = "Failed to open "+fileName;
        return false;
    }
    else
    {
        QTextStream textRead(&file);
        QString allText = textRead.readAll();
        file.close();

        // change preamble
        writeParameters(allText,parameters);

        // change variable values
        QRegExp rxLine;
        int index=0;
        QString newLine1,newLine2;
        QString varName;
        int iCurVar;
        Variable* curVar;
        QStringList fields;
        QString smallText;
        QStringList capLines;
        int index2;
        int prec=MOSettings::value("MaxDigitsDsin").toInt(); //number of decimals
        QString value;
        for(int iV=0;iV<variables->size();iV++)
        {
            InfoSender::instance()->debug("Setting variable "+ varName+" in "+fileName);

            curVar = variables->at(iV);
            varName = curVar->name(Variable::SHORT);
            //varName = varName.remove(modelName+".");
            rxLine.setPattern(sciNumRx()+"\\s+"+sciNumRx()+"\\s+"+sciNumRx()+"\\s+"+sciNumRx()+"\\s+"+sciNumRx()+"\\s+"+sciNumRx()+"\\s*#\\s*("+varName+")\\s*");

            // extracting only text around varname
            // to speed-up regexp research (too long without)
            index2 = allText.indexOf(varName);
            smallText.clear();
            while(index2>-1)
            {
                smallText += allText.mid(index2-300,310+varName.size()); // must capture end of line chars -> 310>300
                index2 = allText.indexOf(varName,index2+1);
            }

            index = rxLine.indexIn(smallText);
            if(index>-1)
            {


                char format = 'E';

                value = QString::number(curVar->getFieldValue(Variable::VALUE).toDouble(),format,prec);
                fields = rxLine.capturedTexts();
                capLines = rxLine.cap(0).split("\n",QString::SkipEmptyParts);
                newLine1 = fields.at(1)+"\t"+ value +"\t";
                newLine1 += fields.at(3)+"\t"+fields.at(4);
                newLine2 = fields.at(5)+"\t"+fields.at(6)+"\t"+" # "+fields.at(7);
                // if variable def were on two lines
                if((capLines.size()>1)&& capLines.at(1).contains(QRegExp("\\S")))
                {
                    InfoSender::instance()->debug("found variable. 2 lines. Total text captured:  "+rxLine.cap(0));
                    allText = allText.replace(rxLine.cap(0),newLine1+"\n"+newLine2+"\n");
                    InfoSender::instance()->debug("New Text :  "+newLine1+"\n"+newLine2);
                }
                else
                {
                    InfoSender::instance()->debug("found variable. 1 line. Total text captured:  "+rxLine.cap(0));
                    // if variable def were on only one line
                    allText = allText.replace(rxLine.cap(0),newLine1+"\t"+newLine2+"\n");
                    InfoSender::instance()->debug("New Text :  "+newLine1+"\t"+newLine2);
                }
            }
            else
            {
                InfoSender::instance()->send(Info("Unable to set variable value (not found in init file):"+varName,ListInfo::ERROR2));
            }
        }

        fileinfo.setFile(fileName);
        file.setFileName(fileinfo.filePath());
        bool ok = file.open(QIODevice::WriteOnly);
        if(!ok)
        {
           errMsg = "Unable to open file for writing :" + fileinfo.absoluteFilePath();
           return false;
        }

        QTextStream textWrite(&file);
        textWrite<<allText;
        file.close();
    }
}
예제 #4
0
static int
ipdbRead(IPDB * const pdbP,
         FILE * const fileP,
         bool   const verbose) {

    int retval;

    ipdb_clear(pdbP);

    pdbP->p = ipdb_pdbhead_alloc(NULL);

    if (pdbP->p == NULL)
        retval = ENOMEM;
    else {
        int status;

        status = pdbheadRead(pdbP->p, fileP);

        if (status != 0)
            retval = status;
        else {
            pdbP->i = ipdb_image_alloc(pdbP->p->name, IMG_GRAY, 0, 0);
            if (pdbP->i == NULL)
                retval = ENOMEM;
            else {
                int status;
                status = rechdrRead(pdbP->i->r, fileP);
                if (status != 0)
                    retval = status;
                else {
                    if (pdbP->p->num_recs > 1) {
                        pdbP->t = ipdb_text_alloc(NULL);
                        if (pdbP->t == NULL)
                            retval = ENOMEM;
                        else {
                            int status;
                            status = rechdrRead(pdbP->t->r, fileP);
                            if (status != 0)
                                retval = status;
                            else
                                retval = 0;
                        }
                    } else
                        retval = 0;
                    
                    if (retval == 0) {
                        uint32_t const offset =
                            pdbP->t == NULL ?
                            UNKNOWN_OFFSET : pdbP->t->r->offset - 1;

                        int status;

                        status = imageRead(pdbP->i, offset, fileP, verbose);
                        if (status != 0)
                            retval = status;
                        else {
                            if (pdbP->t != NULL) {
                                int status;
                                
                                status = textRead(pdbP->t, fileP);
                                if (status != 0)
                                    retval = status;
                            }
                        }
                    }
                }
            }
        }
    }
    return retval;
}
예제 #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();
    }
}