Пример #1
0
//-----------------------------------------------------------------------------
// utility for platform::hasSubDirectory() and platform::dumpDirectories()
// ensures that the entry is a directory, and isnt on the ignore lists.
inline bool isGoodDirectory(const char* path)
{
   char name[80];
   getDirectoryName(path, name);
   return (Platform::isDirectory(path)                          // is a dir
           && dStrcmp(name,".") != 0                 // not here
           && dStrcmp(name,"..") != 0                // not parent
           && !Platform::isExcludedDirectory(name)); // not excluded
}
Пример #2
0
Project_sV::Project_sV()
{

//TODO: scoping problem
    m_projDir = getDirectoryName();

    init();

    int tid;
    for(tid=0;tid<4;tid++) {
      worker[tid]=0;
      thread[tid]=0;
    }
}
Пример #3
0
//slot appelé en cliquant sur le bouton ok de la premiere fenêtre
// qui a pour fonction d'ouvrir la seconde fenêtre
void FunctionForm::openConnectionForm(){

    resize(800,500);

    //which function has been choosen?
    functionChosen = choix->currentText();

    //destroyers of the previous widgets
    choix->~QComboBox();
    Yes->~QPushButton();
    Cancel->~QPushButton();
    buttonLayout->~QHBoxLayout();

    //which number is the function choosen in the tab?
    for (int i=0; i< (int)ConnectionSettings::tabFunction.size() ; i++ ){
        if(functionChosen == ConnectionSettings::tabFunction[i]->getNameFunction()){
            indexFctChosen = i;
        }
    }
    //in case there is no argument to launch the function
    if(ConnectionSettings::tabFunction[indexFctChosen]->getNbArgument()=="0"){
        this->launchCompute();
    }else{

    //for each argument of the chosen function, create fields as per the argument type
    for(int i=0 ; i< ConnectionSettings::tabFunction[indexFctChosen]->getNbArgument().toInt() ; i++){

        switch(ConnectionSettings::argTypeList.indexOf(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()))
            {
            case 0 :   //"Text"
                {
            //qline edit : champ texte simple
                tabLineEdit.push_back(new QLineEdit);

                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefix : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }

                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
            case 1:   //"Integer"
                {
            //qspinbox : fenetre ou on ne peut mettre qu'un entier
                tabLineEdit.push_back(new QSpinBox);
                reinterpret_cast<QSpinBox*>(tabLineEdit[i])->setMaximum(10000);

                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefix : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
        case 2:   //"Real"
            {
            //qspinbox : fenetre ou on ne peut mettre qu'un réel
            tabLineEdit.push_back(new QDoubleSpinBox);
            reinterpret_cast<QDoubleSpinBox*>(tabLineEdit[i])->setDecimals(15);
            reinterpret_cast<QDoubleSpinBox*>(tabLineEdit[i])->setRange(-10000,10000);

            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefix : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }
            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}
            case 3:   //"Boolean"
                {
            //Qcombobox :liste de choix : vrai ou faux
                tabLineEdit.push_back(new QComboBox);
                    reinterpret_cast<QComboBox*> (tabLineEdit[i])->addItem("true");
                    reinterpret_cast<QComboBox*> (tabLineEdit[i])->addItem("false");

                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefix : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
            case 4:   //"Process Sequence"
                {
            //qline edit : simple champ texte
            //structure : le séparateur est l'espace
                tabLineEdit.push_back(new QLineEdit);

                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefix : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));


                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
        case 5:   //"Process Set"
            {
            //qline edit : simple champ texte
            //structure : le séparateur est l'espace
            tabLineEdit.push_back(new QLineEdit);

            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefix : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }
            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));


            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}

        case 6:   //"File .ph"
                {
            //champ texte + bouton parcourir (juste fichier .ph)
            //le bouton alimente le champ texte
                tabLineEdit.push_back(new QLineEdit);
                tabButtonFilePH.push_back(new QPushButton("Browse"));
                connect(tabButtonFilePH[indexFilePH], SIGNAL(clicked()), this, SLOT(getNamePH()));


                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any Prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefix : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);
                    tabQHBox[i]->addWidget(tabButtonFilePH[indexFilePH]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                        tabButtonFilePH[indexFilePH]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);

                indexFilePH+=1;
            break;}
        case 7:   //"File"
            {
            //champ texte + bouton parcourir (tt type de fichier)
            //le bouton alimente le champ texte
            tabLineEdit.push_back(new QLineEdit);
            tabButtonFile.push_back(new QPushButton("Browse"));
            connect(tabButtonFile[indexFile], SIGNAL(clicked()), this, SLOT(getName()));


            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefix : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }
            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);
                tabQHBox[i]->addWidget(tabButtonFile[indexFile]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                    tabButtonFile[indexFile]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);

            indexFile+=1;
        break;}

        case 8:   //"Folder"
            //champ texte + bouton parcourir (juste des dossiers)
            //le bouton alimente le champ texte
                {
                tabLineEdit.push_back(new QLineEdit);
                tabButtonDirec.push_back(new QPushButton("Browse"));
                connect(tabButtonDirec[indexDirec], SIGNAL(clicked()), this, SLOT(getDirectoryName()));


                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefix : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);
                    tabQHBox[i]->addWidget(tabButtonDirec[indexDirec]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                        tabButtonDirec[indexDirec]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);

                indexDirec+=1;
            break;}
            case 9:   //"Choice"
                {
            //Qcombo box : liste de choix alimentée par l'utilisateur averti (info ds xmlComputationSettings.xml)
                tabLineEdit.push_back(new QComboBox);
                for(int m=0; m<(int)ConnectionSettings::tabChoix[indexFctChosen]->at(i)->size() ; m++){
                    reinterpret_cast<QComboBox*>(tabLineEdit[i])->addItem(ConnectionSettings::tabChoix[indexFctChosen]->at(i)->at(m)->getChoixNom());
                }

                tabQFormLayout.push_back(new QFormLayout);
                tabQFormLayout[i]->addRow("Choice : ", tabLineEdit[i]);

                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
        case 10:   //"File not existing"
        {
            //champ texte + bouton parcourir (juste des dossiers)
            //le bouton alimente le champ texte
            //l'utilisateur n'a plus qu'à mettre un nom de fichier (celui qu'il veut créer)
        tabLineEdit.push_back(new QLineEdit);
        tabButtonFileNotExisting.push_back(new QPushButton("Browse"));
        connect(tabButtonFileNotExisting[indexFileNotExisting], SIGNAL(clicked()), this, SLOT(getDirectoryNameFileNotExisting()));


        tabQFormLayout.push_back(new QFormLayout);
            if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
            }else{
                tabQFormLayout[i]->addRow("Prefix : "+
                    ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
            }
        tabQcheckBox.push_back(new QCheckBox("Taken into account"));
        tabQHBox.push_back(new QHBoxLayout);
            tabQHBox[i]->addWidget(tabQcheckBox[i]);
            tabQHBox[i]->addLayout(tabQFormLayout[i]);
            tabQHBox[i]->addWidget(tabButtonFileNotExisting[indexFileNotExisting]);

            if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                tabQcheckBox[i]->setChecked(true);
                tabQcheckBox[i]->setEnabled(false);
            }else{
                tabLineEdit[i]->setEnabled(false);
                tabButtonFileNotExisting[indexFileNotExisting]->setEnabled(false);
            }
        connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

        tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                            +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                            +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
        tabGroupBox[i]->setLayout(tabQHBox[i]);

        indexFileNotExisting+=1;
    break;}
        case 11:   //"Argument"
            {
            //qline edit : champ texte alimenté par l'utilisateur avertit (fichier xmlComputationSetting.xml)
            //champ grisé : modification  interdite
            tabLineEdit.push_back(new QLineEdit);
            reinterpret_cast<QLineEdit*>(tabLineEdit[i])->setText(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf());
            tabLineEdit[i]->setEnabled(false);

            tabQFormLayout.push_back(new QFormLayout);
            tabQFormLayout[i]->addRow("Argument : ", tabLineEdit[i]);

            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}
        case 12:   //"Current File"
            {
            //qline edit : champ texte alimenté par le fichier ouvert
            //champ grisé : modification  interdite
            tabLineEdit.push_back(new QLineEdit);
            reinterpret_cast<QLineEdit*>(tabLineEdit[i])->setText(MainWindow::mwThis->pathCurrentWindow());
            tabLineEdit[i]->setEnabled(false);

            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefix : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }

            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}
            }
        totalLayout->addWidget(tabGroupBox[i]);
        }

    //creation des boutons
    Ok = new QPushButton("&Ok");
    back = new QPushButton("&Back");
    buttonLayout2 = new QHBoxLayout;
    buttonLayout2->addWidget(Ok);
    buttonLayout2->addWidget(back);
    totalLayout->addLayout(buttonLayout2);

    connect(Ok, SIGNAL(clicked()), this, SLOT(testEmpty()));
    connect(back, SIGNAL(clicked()), this, SLOT(fctBack()));
}
}
Пример #4
0
int main (int argc, char *argv[])
{

  if(argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-H")))
  {
    printf("Ponies for Linux/GTK+ by rabbit\n");
    printf("Command list:\n");
    printf("No Parameters: Run with the settings used from last run\n");
    printf("-h: Display this help\n");
    printf("file path: Set new file path to look for pony gif files\n");
    printf("ponyname: Sets to run one of the pony type listed\n");
    return 0;
  }

  for(int i = 1; i < argc; i++)
    if(*argv[i] == '/')
      setPonyDirectory(argv[i]);

  char* ponyDirectory = NULL;
  char* ponyHomeFile = NULL;

  ponyHomeFile = malloc((strlen(getenv("HOME"))+ 9) * sizeof(char));
  if(!ponyHomeFile)
  {
    printf("Could not allocate memory for ponyHomeFile\n");
    return 0;
  }
  strcpy(ponyHomeFile, getenv("HOME"));
  strcat(ponyHomeFile,"/.ponies");
  ponyDirectory = getPonyDirectory();

  if(!ponyDirectory)
  {
    free(ponyHomeFile);
    printf("Error locating pony directory\n");
    return 0;
  }

  //Initialize GTK+ and set up loggers
  GError* error = NULL;
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  //For command line commands later, require input on inital load
  //Normally would close, but hard coded in for easier testing
  int numberOfPonies = 0;
  if(argc == 1)
  {
    //Read in from ~/.ponies file to find saved settings
    FILE* ifp = NULL;
    char buffer[256];
    ifp = fopen(ponyHomeFile,"r");
    if(!ifp)
    {
      free(ponyHomeFile);
      free(ponyDirectory);
      printf("Could not open file for reading\n");
      return 0;
    }
    //fread(buffer, sizeof(char), 256, ifp);
    while(fgets(buffer, 256, ifp))
      if(buffer[0] != '\n')
        numberOfPonies++;

    fclose(ifp);
    numberOfPonies--;//First line is directory
  }
  //Not default arguments
  else
  {
    for(int i = 1; i < argc; i++)
    {
      if(*argv[i] == '/')
        continue;
      numberOfPonies++;
    }
  }

  //Seed the randomizer
  srand(time(0));

  //Number of ponies
  pony ponyArray[numberOfPonies];

  char buffer[256];
  FILE* ifp = NULL;
  ifp = fopen(ponyHomeFile,"r");
  if(!ifp)
  {
    printf("Could not open ~/.ponies\n");
    free(ponyDirectory);
    free(ponyHomeFile);
    return 0;
  }
  fgets(buffer, 256, ifp);//throw away first line

  //0 Ponies
  if(!numberOfPonies)
  {
    free(ponyDirectory);
    free(ponyHomeFile);
    printf("No ponies in the ~/.ponies file! Add some ponies!\n");
    printf("allowable ponies are: ");
    for(int i = 0; i <= Zecora; i++)
      printf("%s ", getDirectoryName(i));
    return 0;
  }


  //Make pony windows
  for( int i = 0; i < numberOfPonies; i++)
  {
    fgets(buffer, 256, ifp);
    char* temp = NULL;
    temp = strchr(buffer, '\n');
    if(temp)
      buffer[temp - buffer] = '\0';
    ponyArray[i].name = ponyNameFromString(buffer);
    ponyArray[i].direction = DirNone;
    ponyArray[i].dragActive = 0;
    ponyArray[i].speed = SpeedStopped;
    ponyArray[i].animation = AnimIdle;
    ponyArray[i].active = 1;
    ponyArray[i].facing = FaceLeft;
    //Create animation from file, default is idle_left
    char* initialPicturePath;
    initialPicturePath = malloc((strlen(ponyDirectory) +
                                 strlen(getDirectoryName(ponyArray[i].name)) +
                                 14) * sizeof(char));
    if(!initialPicturePath)
    {
      printf("Unable to allocate memory for directory");
      continue;
    }
    strcpy(initialPicturePath, ponyDirectory);
    strcat(initialPicturePath, getDirectoryName(ponyArray[i].name));
    strcat(initialPicturePath, "/idle_left.gif");
    ponyArray[i].pictureanim = gdk_pixbuf_animation_new_from_file
                              (initialPicturePath, &error);
    free(initialPicturePath);
    ponyArray[i].image = gtk_image_new_from_animation(ponyArray[i].pictureanim);
    ponyArray[i].pictureanimit = gdk_pixbuf_animation_get_iter
                                  (ponyArray[i].pictureanim, NULL);
    ponyArray[i].win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    //Resize everytime the gif updates
    g_timeout_add(gdk_pixbuf_animation_iter_get_delay_time(ponyArray[i].
                  pictureanimit),(GSourceFunc)updateWinSize, &ponyArray[i]);
    //Name the window the name of the pony being animated
    gtk_window_set_title(GTK_WINDOW(ponyArray[i].win),
                        getPonyName(ponyArray[i].name));
    //Size down the window before showing it
    gtk_window_set_default_size(GTK_WINDOW(ponyArray[i].win),
                                gdk_pixbuf_animation_get_width(ponyArray[i].
                                pictureanim), gdk_pixbuf_animation_get_height
                                (ponyArray[i].pictureanim));
    //Remove the titlebar
    gtk_window_set_decorated(GTK_WINDOW(ponyArray[i].win), FALSE);

    //Set up the signals
    ponyArray[i].clickEventID = g_signal_connect(G_OBJECT(ponyArray[i].win),
                                "button_press_event", G_CALLBACK(click_event),
                                &ponyArray[i]);
    ponyArray[i].enterEventID = g_signal_connect(G_OBJECT(ponyArray[i].win),
                                "enter-notify-event", G_CALLBACK(enter_event),
                                &ponyArray[i]);
    ponyArray[i].leaveEventID = g_signal_connect(G_OBJECT(ponyArray[i].win),
                                "leave-notify-event", G_CALLBACK(enter_event),
                                &ponyArray[i]);
    gtk_widget_add_events(ponyArray[i].win, GDK_BUTTON_PRESS_MASK);
    gtk_container_add(GTK_CONTAINER(ponyArray[i].win), GTK_WIDGET(ponyArray[i].
                                                                  image));

    //Get rid of taskbar item
    gtk_window_set_skip_taskbar_hint(GTK_WINDOW(ponyArray[i].win), TRUE);
    //Make it so it can't be selected
    gtk_window_set_accept_focus(GTK_WINDOW(ponyArray[i].win), FALSE);
    gtk_widget_realize(ponyArray[i].win);
    //Always on top
    gtk_window_set_keep_above(GTK_WINDOW(ponyArray[i].win), TRUE);
    updateWinSize(&ponyArray[i]);

    if(error != NULL)
      break;
  }
  free(ponyDirectory);
  free(ponyHomeFile);

  //Quit out if there were any errors and give a message
  if( error != NULL)
  {
      printf("%s\n",error->message);
      return 0;
  }



  //Make it transparent?
  /*cr = gdk_cairo_create(win->window);
  cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0);
  cairo_set_operator( cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint(cr);
  gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(image));*/

  //Main loop
  for( int i = 0; i < numberOfPonies; i++)
    gtk_widget_show_all(ponyArray[i].win);
  gtk_main();
  return 0;
}
Пример #5
0
static int nc_getattr(const char *path, struct stat *attr) {
	int res = 0;
	memset(attr, 0, sizeof(struct stat));
	if (strcmp(path, "/") == 0) {
		attr->st_mode = S_IFDIR | 0755;
		attr->st_nlink = 2;
	} else {
		int count;
		sqlite3 *db;
		int rc;
		rc = sqlite3_open(dbf, &db);
		if (rc != SQLITE_OK) {
			showError("unable to open database");
			return 1;
		}
		sqlite3_stmt *stmt;

		/* directory */
		rc = sqlite3_prepare_v2(db, "SELECT count(*) FROM directory WHERE name=?;", -1, &stmt, NULL);
		if (rc != SQLITE_OK) {
			showError(sqlite3_errmsg(db));
			sqlite3_finalize(stmt);
			sqlite3_close(db);
			return 1;
		}
		rc = sqlite3_bind_text(stmt, 1, path, strlen(path), SQLITE_STATIC);
		if (rc != SQLITE_OK) {
			showError(sqlite3_errmsg(db));
			sqlite3_finalize(stmt);
			sqlite3_close(db);
			return 1;
		}

		rc = sqlite3_step(stmt);
		if (rc != SQLITE_ROW) {
			showError(sqlite3_errmsg(db));
			sqlite3_finalize(stmt);
			sqlite3_close(db);
			return 1;
		}
		count = sqlite3_column_int(stmt, 0);
		sqlite3_finalize(stmt);
		if (count > 0) {
			attr->st_mode = S_IFDIR | 0555;
			attr->st_nlink = 2;
		} else {
			/* file */
			rc = sqlite3_prepare_v2(db, "SELECT count(*) FROM directory AS d, file AS f WHERE d.id=f.directory AND d.name=? AND f.name=?;", -1, &stmt, NULL);
			if (rc != SQLITE_OK) {
				showError(sqlite3_errmsg(db));
				sqlite3_finalize(stmt);
				sqlite3_close(db);
				return 1;
			}
			char *dirname = getDirectoryName(path);
			rc = sqlite3_bind_text(stmt, 1, dirname, strlen(dirname), SQLITE_STATIC);
			if (rc != SQLITE_OK) {
				showError(sqlite3_errmsg(db));
				free(dirname);
				sqlite3_finalize(stmt);
				sqlite3_close(db);
				return 1;
			}
			char *filename = getFilename(path);
			rc = sqlite3_bind_text(stmt, 2, filename, strlen(filename), SQLITE_STATIC);
			if (rc != SQLITE_OK) {
				showError(sqlite3_errmsg(db));
				free(filename);
				free(dirname);
				sqlite3_finalize(stmt);
				sqlite3_close(db);
				return 1;
			}

			rc = sqlite3_step(stmt);
			if (rc != SQLITE_ROW) {
				showError(sqlite3_errmsg(db));
				free(filename);
				free(dirname);
				sqlite3_finalize(stmt);
				sqlite3_close(db);
				return 1;
			}

			free(filename);
			free(dirname);

			count = sqlite3_column_int(stmt, 0);
			sqlite3_finalize(stmt);
			if (count > 0) {
				attr->st_mode = S_IFREG | 0444;
				attr->st_nlink = 1;
				attr->st_size = 0;              /* get from info-field */
			} else {
//				res = -ENOENT;

				attr->st_mode = S_IFDIR | 0755;
				attr->st_nlink = 2;
			}
		}
		sqlite3_close(db);
	}

	return res;
}
Пример #6
0
void FunctionForm::openConnectionForm(){

    resize(800,500);

    //which function has been choosen?
    functionChosen = choix->currentText();

    //destroyers of the previous widgets
    choix->~QComboBox();
    Yes->~QPushButton();
    Cancel->~QPushButton();
    buttonLayout->~QHBoxLayout();

    //which number is the function choosen in the tab?
    for (int i=0; i< (int)ConnectionSettings::tabFunction.size() ; i++ ){
        if(functionChosen == ConnectionSettings::tabFunction[i]->getNameFunction()){
            indexFctChosen = i;
        }
    }
    //in case there is no argument to launch the function
    if(ConnectionSettings::tabFunction[indexFctChosen]->getNbArgument()=="0"){
        this->launchCompute();
    }else{

    //for each argument of the chosen function, create fields as per the argument type
    for(int i=0 ; i< ConnectionSettings::tabFunction[indexFctChosen]->getNbArgument().toInt() ; i++){

        switch(ConnectionSettings::argTypeList.indexOf(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()))
            {
            case 0 :   //"Text"
                {
                tabLineEdit.push_back(new QLineEdit);

                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefixe : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }

                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
            case 1:   //"Integer"
                {
                tabLineEdit.push_back(new QSpinBox);
                reinterpret_cast<QSpinBox*>(tabLineEdit[i])->setMaximum(10000);

                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefixe : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
        case 2:   //"Real"
            {
            tabLineEdit.push_back(new QDoubleSpinBox);
            reinterpret_cast<QDoubleSpinBox*>(tabLineEdit[i])->setDecimals(15);
            reinterpret_cast<QDoubleSpinBox*>(tabLineEdit[i])->setRange(-10000,10000);

            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefixe : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }
            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}
            case 3:   //"Boolean"
                {
                tabLineEdit.push_back(new QComboBox);
                    reinterpret_cast<QComboBox*> (tabLineEdit[i])->addItem("true");
                    reinterpret_cast<QComboBox*> (tabLineEdit[i])->addItem("false");

                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefixe : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
            case 4:   //"Process List"
                {
                tabLineEdit.push_back(new QLineEdit);

                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefixe : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));


                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
        case 5:   //"Process Group"
            {
            tabLineEdit.push_back(new QLineEdit);

            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefixe : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }
            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));


            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}

        case 6:   //"File .ph"
                {
                tabLineEdit.push_back(new QLineEdit);
                tabButtonFilePH.push_back(new QPushButton("Browse"));
                connect(tabButtonFilePH[indexFilePH], SIGNAL(clicked()), this, SLOT(getNamePH()));


                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any Prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefixe : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);
                    tabQHBox[i]->addWidget(tabButtonFilePH[indexFilePH]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                        tabButtonFilePH[indexFilePH]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);

                indexFilePH+=1;
            break;}
        case 7:   //"File"
            {
            tabLineEdit.push_back(new QLineEdit);
            tabButtonFile.push_back(new QPushButton("Browse"));
            connect(tabButtonFile[indexFile], SIGNAL(clicked()), this, SLOT(getName()));


            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefixe : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }
            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);
                tabQHBox[i]->addWidget(tabButtonFile[indexFile]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                    tabButtonFile[indexFile]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);

            indexFile+=1;
        break;}

        case 8:   //"Folder"
                {
                tabLineEdit.push_back(new QLineEdit);
                tabButtonDirec.push_back(new QPushButton("Browse"));
                connect(tabButtonDirec[indexDirec], SIGNAL(clicked()), this, SLOT(getDirectoryName()));


                tabQFormLayout.push_back(new QFormLayout);
                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                        tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                    }else{
                        tabQFormLayout[i]->addRow("Prefixe : "+
                            ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                    }
                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);
                    tabQHBox[i]->addWidget(tabButtonDirec[indexDirec]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                        tabButtonDirec[indexDirec]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);

                indexDirec+=1;
            break;}
            case 9:   //"Choice"
                {
                tabLineEdit.push_back(new QComboBox);
                for(int m=0; m<(int)ConnectionSettings::tabChoix[indexFctChosen]->at(i)->size() ; m++){
                    reinterpret_cast<QComboBox*>(tabLineEdit[i])->addItem(ConnectionSettings::tabChoix[indexFctChosen]->at(i)->at(m)->getChoixNom());
                }

                tabQFormLayout.push_back(new QFormLayout);
                tabQFormLayout[i]->addRow("Choice : ", tabLineEdit[i]);

                tabQcheckBox.push_back(new QCheckBox("Taken into account"));
                tabQHBox.push_back(new QHBoxLayout);
                    tabQHBox[i]->addWidget(tabQcheckBox[i]);
                    tabQHBox[i]->addLayout(tabQFormLayout[i]);

                    if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                        tabQcheckBox[i]->setChecked(true);
                        tabQcheckBox[i]->setEnabled(false);
                    }else{
                        tabLineEdit[i]->setEnabled(false);
                    }
                connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

                tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                    +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                    +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
                tabGroupBox[i]->setLayout(tabQHBox[i]);
            break;}
        case 10:   //"File not existing"
            {
            tabLineEdit.push_back(new QLineEdit);

            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefixe : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }

            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}
        case 11:   //"Argument"
            {
            tabLineEdit.push_back(new QLineEdit);
            reinterpret_cast<QLineEdit*>(tabLineEdit[i])->setText(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf());
            tabLineEdit[i]->setEnabled(false);

            tabQFormLayout.push_back(new QFormLayout);
            tabQFormLayout[i]->addRow("Argument : ", tabLineEdit[i]);

            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}
        case 12:   //"Current File"
            {
            tabLineEdit.push_back(new QLineEdit);
            reinterpret_cast<QLineEdit*>(tabLineEdit[i])->setText(MainWindow::mwThis->pathCurrentWindow());
            tabLineEdit[i]->setEnabled(false);

            tabQFormLayout.push_back(new QFormLayout);
                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf()==""){
                    tabQFormLayout[i]->addRow("Without any prefix", tabLineEdit[i]);
                }else{
                    tabQFormLayout[i]->addRow("Prefixe : "+
                        ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgSuf(), tabLineEdit[i]);
                }

            tabQcheckBox.push_back(new QCheckBox("Taken into account"));
            tabQHBox.push_back(new QHBoxLayout);
                tabQHBox[i]->addWidget(tabQcheckBox[i]);
                tabQHBox[i]->addLayout(tabQFormLayout[i]);

                if(ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgFac()=="0"){ //if argument is not fac
                    tabQcheckBox[i]->setChecked(true);
                    tabQcheckBox[i]->setEnabled(false);
                }else{
                    tabLineEdit[i]->setEnabled(false);
                }
            connect(this->tabQcheckBox[i], SIGNAL(stateChanged(int)), this, SLOT(enableForm(int)));

            tabGroupBox.push_back(new QGroupBox("Argument "+ QString::number(i+1)+
                                +" : (Type : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgType()
                                +") Caption : " + ConnectionSettings::tabArgument[indexFctChosen]->at(i)->getArgOutline()));
            tabGroupBox[i]->setLayout(tabQHBox[i]);
        break;}
            }
        totalLayout->addWidget(tabGroupBox[i]);
        }

    Ok = new QPushButton("&Ok");
    back = new QPushButton("&Back");
    buttonLayout2 = new QHBoxLayout;
    buttonLayout2->addWidget(Ok);
    buttonLayout2->addWidget(back);
    totalLayout->addLayout(buttonLayout2);

    connect(Ok, SIGNAL(clicked()), this, SLOT(testEmpty()));
    connect(back, SIGNAL(clicked()), this, SLOT(fctBack()));
}
}
Пример #7
0
// lmfile (landmarks file) - This is a text file with format:
// i1 j1 k1
// i2 j2 k2
// i3 j3 k3
// where 
// (i1, j1, k1) are the coordinates of the AC
// (i2, j2, k2) are the coordinates of the PC, and
// (i3, j3, k3) are the coordinates of the RP.
// subfile (subject file) - 3D T1W volume of type short in NIFTI format
// TPIL - output 4x4 rigid-body transformation matrix that would transform
// subfile into a standardized PIL orientation
void new_PIL_transform(const char *subfile,const char *lmfile,char *orient,float *TPIL, int SAVE_MRX_FLAG)
{
   float Qavg[3]; // average of rows of Q
   float Pavg[3]; // average of rows of P
   float TPIL0[16]; // transforms the original image to MSP/AC-PC aligned PIL orientation
   int n; // number of landmarks
   float *LM;  // (3 x n) matrix of detected landmarks
   float *invT;
   char filename[1024];
   SHORTIM subimPIL; 
   nifti_1_header PILbraincloud_hdr;
   // subfile without the directory structure and extension
   char subfile_prefix[1024]; 
   char imagedir[1024]; 
   char modelfile[1024]="";

   if( niftiFilename(subfile_prefix, subfile)==0 ) exit(0);
   getDirectoryName(subfile, imagedir);

   getARTHOME();

   // initial TPIL0 using old PIL transformation
   char opt_CENTER_AC_old;   
   opt_CENTER_AC_old = opt_CENTER_AC; // record opt_CENTER_AC
   opt_CENTER_AC = NO; // temporarily set opt_CENTER_AC to NO
   standard_PIL_transformation(subfile, lmfile, orient, 0, TPIL0);
   opt_CENTER_AC = opt_CENTER_AC_old; // restore opt_CENTER_AC

   /////////////////////////////////////////////////////////
   // Read input volume from subfile
   SHORTIM subim; 
   nifti_1_header subim_hdr;  

   subim.v = (short *)read_nifti_image(subfile, &subim_hdr);

   if(subim.v==NULL)
   {
      printf("Error reading %s, aborting ...\n", subfile);
      exit(1);
   }

   set_dim(subim, subim_hdr);
   /////////////////////////////////////////////////////////

   /////////////////////////////////////////////////////////
   // Reslice subim to PIL space 
   sprintf(filename,"%s/PILbrain.nii",ARTHOME);
   PILbraincloud_hdr=read_NIFTI_hdr(filename);

   set_dim(subimPIL, PILbraincloud_hdr);
   invT = inv4(TPIL0);
   resliceImage(subim, subimPIL, invT, LIN);
   free(invT);

   // Detect 8 landmarks on the MSP on the subimPIL volume
   sprintf(modelfile,"%s/orion.mdl",ARTHOME);

   LM=detect_landmarks(subimPIL, modelfile, n);

   convert_to_xyz(LM, n, subimPIL);
 
   // This block outputs the locations of the detected landmarks 
   // in (i,j,k) coordinates of the native space of the input volume
   if(opt_txt)
   {
      FILE *fp;
      float landmark[4];
      invT = inv4(TPIL0);
      sprintf(filename,"%s/%s_orion.txt",imagedir,subfile_prefix);
      fp=fopen(filename,"w");
      if(fp==NULL) file_open_error(filename);
      for(int i=0; i<n; i++)
      {
         landmark[0]=LM[0*n + i];
         landmark[1]=LM[1*n + i];
         landmark[2]=LM[2*n + i];
         landmark[3]=1;
         multi(invT,4,4,landmark,4,1,landmark);
         convert_to_ijk(landmark, 1, subim);
         fprintf(fp,"%5.1f %5.1f %5.1f\n",landmark[0], landmark[1], landmark[2]);
      }
      fclose(fp);
      free(invT);
   }

   float *P;
   float *Q; // Image using Q insted of P' in Eq. (1) of Arun et al. 1987
   float TLM[16];

   Q =  (float *)calloc(3*n,sizeof(float));
   P =  (float *)calloc(3*n,sizeof(float));
   for(int i=0; i<3*n; i++) P[i]=LM[i];

   delete subimPIL.v;
   /////////////////////////////////////////////////////////

   // read Q
   {
      FILE *fp;
      int r, r2;
      int cm[3];

      fp=fopen(modelfile, "r");
      if(fp==NULL) file_open_error(modelfile);

      fread(&n, sizeof(int), 1, fp);
      fread(&r, sizeof(int), 1, fp);
      fread(&r2, sizeof(int), 1, fp);
      SPH refsph(r);

      for(int i=0; i<n; i++)
      {
         fread(cm, sizeof(int), 3, fp);
         fread(refsph.v, sizeof(float), refsph.n, fp);
         Q[0*n + i]=cm[0];
         Q[1*n + i]=cm[1];
         Q[2*n + i]=cm[2];
      }

      fclose(fp);

      convert_to_xyz(Q, n, subimPIL);
   }

   Procrustes(Q, Qavg, n, P, Pavg, TLM);

   multi(TLM,4,4,TPIL0,4,4,TPIL);

   // create the *LM.ppm image
   if(opt_ppm || opt_png)
   {
      int *lmx, *lmy;
      float lm[4]; 

      invT = inv4(TPIL);
      resliceImage(subim, subimPIL, invT, LIN);
      free(invT);

      lmx = (int *)calloc(n,sizeof(int));
      lmy = (int *)calloc(n,sizeof(int));

      for(int i=0; i<n; i++)
      {
         lm[0] = P[i] + Pavg[0];
         lm[1] = P[n+i] + Pavg[1];
         lm[2] = P[2*n+i] + Pavg[2];
         lm[3] = 1.0;

         multi(TLM,4,4,lm,4,1,lm);

         convert_to_ijk(lm, 1, subimPIL);

         lmx[i]=(int)( lm[0] + 0.5 );
         lmy[i]=(int)( lm[1] + 0.5 );
      }

      sprintf(filename,"%s/%s_orion.ppm",imagedir, subfile_prefix);
      mspPPM(subimPIL, lmx, lmy, n, filename);

      delete lmx;
      delete lmy;
      delete subimPIL.v;
   }

  if(opt_CENTER_AC)
  {
    float ac[4]; 
    float Ttmp[16];

    ac[0] = P[1] + Pavg[0];  // landmark #1 is AC
    ac[1] = P[n+1] + Pavg[1];
    ac[2] = P[2*n+1] + Pavg[2];
    ac[3] = 1.0;

    multi(TLM,4,4,ac,4,1,ac);

    Ttmp[0]=1.0;  Ttmp[1]=0.0;  Ttmp[2]=0.0;  Ttmp[3]=-ac[0];  // makes ac the center of the FOV
    Ttmp[4]=0.0;  Ttmp[5]=1.0;  Ttmp[6]=0.0;  Ttmp[7]=-ac[1];  // ac[1] should be equal to pc[1]
    Ttmp[8]=0.0;  Ttmp[9]=0.0;  Ttmp[10]=1.0; Ttmp[11]=0;
    Ttmp[12]=0.0; Ttmp[13]=0.0; Ttmp[14]=0.0; Ttmp[15]=1.0;

    multi(Ttmp,4,4,TPIL,4,4,TPIL);
  }

  // save the PIL transformation in <subfile_prefix>_PIL.mrx
  if(SAVE_MRX_FLAG == 1)
  {
    FILE *fp;
    sprintf(filename,"%s/%s_PIL.mrx",imagedir, subfile_prefix);
    fp=fopen(filename,"w");
    if(fp==NULL) file_open_error(filename);
    printMatrix(TPIL,4,4,"",fp);
    fclose(fp);
  }

   {
      float ssd1=0.0;
      float ssd3=0.0;
      float x[4], y[4];
      
      x[3]=y[3]=1.0;

      for(int i=0; i<n; i++)
      {
         x[0] = Q[i] + Qavg[0];
         x[1] = Q[i+n] + Qavg[1];
         x[2] = Q[i+2*n] + Qavg[2];

         y[0] = P[i]+Pavg[0];
         y[1] = P[i+n]+Pavg[1];
         y[2] = P[i+2*n]+Pavg[2];

         ssd1 += (x[0]-y[0])*(x[0]-y[0]); 
         ssd1 += (x[1]-y[1])*(x[1]-y[1]); 
         ssd1 += (x[2]-y[2])*(x[2]-y[2]); 

         multi(TLM,4,4,y,4,1,y);
         ssd3 += (x[0]-y[0])*(x[0]-y[0]); 
         ssd3 += (x[1]-y[1])*(x[1]-y[1]); 
         ssd3 += (x[2]-y[2])*(x[2]-y[2]); 
      }
      //if(opt_v) printf("SSD (MSP + AC/PC transformation) = %f\n",ssd1);
      //if(opt_v) printf("SSD (MSP + AC/PC + LM transformation) = %f\n",ssd3);
   }

   delete subim.v;
   free(P);
   free(Q);
}