Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

omgexperimentdesigner.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tim Sutton   *
00003  *   tim@linfiniti.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 //local includes
00022 #include "omgexperimentdesigner.h"
00023 #include "omglayerselector.h"
00024 #include "omgalgorithmmanager.h"
00025 #include "omglocalitiesoptions.h"
00026 #include <omgui.h> //provides anciliary helper functions like getting app paths
00027 #include <omgmodellerpluginregistry.h>
00028 #include <omglayerset.h>
00029 #include <omgpluginmessenger.h>
00030 //Qt includes 
00031 #include <QDate>
00032 #include <QDir>
00033 #include <QString>
00034 #include <QPluginLoader>
00035 #include <QFileDialog>
00036 #include <QFileInfoList>
00037 //std c++ stuff
00038 #include <cassert>
00039 
00040 OmgExperimentDesigner::OmgExperimentDesigner(QWidget* parent, Qt::WFlags fl)
00041     : QDialog(parent,fl)
00042 {
00043   //required by Qt4 to initialise the ui
00044   setupUi(this);
00045   //a flag so we can remind user once only if they are missing ids in their occ file;
00046   mFirstNonIdRecord=true;
00047   QDate myDate = QDate::currentDate();
00048   leExperimentName->setText(tr(""));
00049   leExperimentDescription->setText(tr("New Experiment created on ") 
00050       + myDate.longDayName(myDate.dayOfWeek()) 
00051       + ", " 
00052       + QString::number(myDate.day())
00053       + " " 
00054       + myDate.longMonthName(myDate.month()) 
00055       + ", " 
00056       + QString::number(myDate.year()));
00057 
00058   //when the user clicks on teh addItems tool in the omglistTaxa widget
00059   //they should be prompted to load a file of occurrence data
00060 
00061   connect(omglistTaxa, SIGNAL(addItemClicked()),
00062       this, SLOT(toolSelectLocalitiesFileClicked()));
00063   connect(omglistTaxa, SIGNAL(configureClicked()),
00064       this, SLOT(toolConfigureLocalitiesClicked()));
00065 
00066   //
00067   // First populate the algs combo
00068   //
00069   //iterate through the algorithm sets adding a row for each to the table
00070   mAlgorithmSet = OmgAlgorithmSet::getFromActivePlugin();
00071   mAlgorithmSet.loadAlgorithms(Omgui::userAlgorithmProfilesDirPath());
00072   //qDebug(myAlgorithmSet.toXml().toLocal8Bit());
00073   //iterate through the algorithm sets adding a row for each to the table
00074   //first empty the table
00075   omglistAlgorithms->clear();
00076 
00077   //see which items were checked the last time the user was here
00078   QSettings mySettings;
00079   QString myPluginName = mySettings.value("openModeller/modellerPluginType", "Local Modeller Plugin" ).toString();
00080   QStringList myList = mySettings.value("openModeller/experimentDesigner/" + myPluginName + "/selectedAlgorithms").toStringList();
00081   for (int i=0; i < mAlgorithmSet.count(); i++)
00082   {
00083     OmgAlgorithm myAlgorithm = mAlgorithmSet[i];
00084     // Add details to the new row
00085     QListWidgetItem *mypNameItem = new QListWidgetItem(myAlgorithm.name());
00086     mypNameItem->setData(Qt::UserRole,myAlgorithm.guid());
00087     //display the text in red if the origin of the alg is from the adapter
00088     //rather than the users xml alg profile store
00089     OmgAlgorithm::Origin myOrigin = myAlgorithm.origin();
00090     QIcon myIcon;
00091     if (myOrigin==OmgAlgorithm::USERPROFILE)
00092     {
00093       myIcon.addFile(":/algorithmTypeUser.png");
00094     }
00095     else if (myOrigin==OmgAlgorithm::ADAPTERPROFILE)
00096     {
00097       myIcon.addFile(":/algorithmTypeSystem.png");
00098     }
00099     else if (myOrigin==OmgAlgorithm::UNDEFINED)
00100     {
00101       mypNameItem->setTextColor(Qt::yellow);
00102     }
00103     mypNameItem->setIcon(myIcon);
00104     if (myList.contains(myAlgorithm.name()))
00105     {
00106       omglistAlgorithms->addItem(mypNameItem, true);
00107     }
00108     else
00109     {
00110       omglistAlgorithms->addItem(mypNameItem, false);
00111     }
00112   }
00113 
00114   //
00115   // Now the list of available projections
00116   // Note this way is much much faster than using an iterator!
00117   //
00118   OmgSpatialReferenceSystem mySRS;
00119   mWktMap = mySRS.getWktMap();
00120   QList<QString> myKeys = mWktMap.keys();
00121   cboCoordinateSystem->addItems(static_cast<QStringList>(myKeys));
00122 
00123   //
00124   //populate model creation and projection layerset combos
00125   //
00126 
00127   Omgui::LayerSetMap myLayerSetMap = Omgui::getAvailableLayerSets();
00128   QMapIterator<QString, OmgLayerSet> myIterator(myLayerSetMap);
00129   while (myIterator.hasNext()) 
00130   {
00131     myIterator.next();
00132     OmgLayerSet myLayerSet = myIterator.value();
00133     QString myGuid = myLayerSet.guid();
00134     QString myName = myLayerSet.name();
00135     //display an icon indicating if the layerset is local or remote (e.g. terralib)
00136     QIcon myIcon;
00137     myIcon.addFile(":/localdata.png");
00138     cboModelLayerSet->addItem(myIcon,myName,myGuid);
00139     cboProjectionLayerSet->addItem(myIcon,myName,myGuid);
00140   }
00141   //tweak the omglistTaxa list a bit
00142   //omglistTaxa->hideOptionsTool();
00143   //and the alg list
00144   omglistAlgorithms->hideOptionsTool();
00145   omglistAlgorithms->hideAddItemTool();
00146 
00148   readSettings();
00149 }
00150 
00151 
00152 OmgExperimentDesigner::~OmgExperimentDesigner()
00153 {
00154 }
00155 
00156 void OmgExperimentDesigner::on_pbnCancel_clicked()
00157 {
00158   QDialog::reject();
00159 }
00160 
00161 
00162 void OmgExperimentDesigner::on_pbnOk_clicked()
00163 {
00164   //first do some sanity checking....
00165   if (leExperimentName->text().isEmpty())
00166   {
00167     QMessageBox::warning( this,tr("openModeller Desktop"),tr("Please give this experiment a valid name!"));
00168     return;
00169   }
00170   
00171   QString myWorkDirName = QDir::convertSeparators(Omgui::getModelOutputDir()) 
00172     + QDir::separator() 
00173     + leExperimentName->text()
00174     + QDir::separator(); 
00175   QDir myWorkDir(myWorkDirName );
00176   if (myWorkDir.exists())
00177   {
00178     QMessageBox::warning( this,tr("openModeller Desktop"),tr("An experiment directory with this name already exists!"));
00179     return;
00180   }
00181   if (mWktMap[cboCoordinateSystem->currentText()].isEmpty())
00182   {
00183     QMessageBox::warning( this,tr("openModeller Desktop"),tr("Please select a valid coordinate system."));
00184     return;
00185   }
00186   if(omglistTaxa->checkedItemCount() < 1)
00187   {
00188     QMessageBox::warning( this,tr("openModeller Desktop"),tr("Please select one or more taxa before attempting to run the experiment"));
00189     return;
00190   }
00191   if (cboModelLayerSet->count()==0)
00192   {
00193     QMessageBox::warning( this,tr("openModeller Desktop"),tr("Please create a layer set using the Layer Set Manager and then select one layer set for the model creation process before attempting to run the experiment"));
00194     return;
00195   }
00196   if (cboProjectionLayerSet->count()==0)
00197   {
00198     QMessageBox::warning( this,tr("openModeller Desktop"),tr("Please create a layer set for model projection using the Layer Set Manager and then select one layer set for the model projection process before attempting to run the experiment"));
00199     return;
00200   }
00201   if (cboOutputFormatLayer->currentText().isEmpty())
00202   {
00203     QMessageBox::warning( this,tr("openModeller Desktop"),tr("Please select an output format layer before attempting to run the model"));
00204     return;
00205   }
00206   //qDebug("Writing settings...");
00207   writeSettings();
00208   
00209   OmgExperiment *  mypExperiment = getExperiment();
00210   //then ok is pressed in progress monitor we can close up shop here
00211   //we are going to pass the experiment to the main window. its the main windows job to delete it
00212   emit experimentCreated(mypExperiment);
00213   done(1);
00214 }
00215 
00216 OmgExperiment * OmgExperimentDesigner::getExperiment()
00217 {
00218   QSettings mySettings;
00219   emit logMessage("Creating experiment");
00220   //set up the experiment
00221   OmgExperiment * mypExperiment = new OmgExperiment();
00222   mypExperiment->setName(leExperimentName->text());
00223   mypExperiment->setDescription(leExperimentDescription->text());
00224 
00225   //Initialise the modeller adapter
00226 
00227   /* This is the Abstract plugin type. Depending on the users
00228    * options, it will be initialised to either the OmgModellerLocalPlugin
00229    * or OmgModellerWebServices plugin (or possibly other plugin types in 
00230    * the future) 
00231    */
00232   //qDebug("Experiment designer calling OmGui to get the modeller plugin");
00233   mpModellerPlugin = OmgModellerPluginRegistry::instance()->getPlugin();
00234   //qDebug("Experiment designer testing if returned modeller plugin is ok");
00235   if(!mpModellerPlugin)
00236   {
00237     //this is bad! TODO notify user he has no useable adapters
00238     //TODO handle this more gracefully than asserting!
00239     //qDebug("Experiment designer Error no valid modelling adapters could be loaded");
00240     QMessageBox::critical( this,tr("openModeller Desktop"),tr("No modelling plugins could be found.\nPlease report this problem to you system administrator or the openModeller developers."));
00241     //assert ("Undefined adapter type in __FILE__  , line  __LINE__");
00242     close();
00243   }
00244   else
00245   {
00246     //qDebug("Plugin is good to go....");
00247   }
00248   mypExperiment->setModellerPlugin(mpModellerPlugin);
00249   
00250   //
00251   // To build the experiment we have two (nested) loops
00252   // The outer loop walks the list of checked algorithm profiles
00253   // while the inner loop walks the list of check taxa
00254   // Thus the experiment consists of CheckedAlgs * CheckedTaxa models
00255   //
00256   
00257   //get the alg properties first
00258   //
00259   //QString myAlgGuid=cboModelAlgorithm->itemData(cboModelAlgorithm->currentIndex()).toString();
00260   //this loop is for debug purposes only!
00261   int myAlgorithmCount = omglistAlgorithms->checkedItemCount();
00262   QStringList myAlgorithmList = omglistAlgorithms->checkedDataItems();
00263   for (int i=0; i < myAlgorithmCount; i++)
00264   {
00265     //qDebug("Getting algorithm for GUID             : " + myAlgorithmList.at(i).toLocal8Bit());
00266     OmgAlgorithm myAlgorithm = mAlgorithmSet.getAlgorithm( myAlgorithmList.at(i) );
00267     //qDebug("myAlgorithms GUID (should match above!): " + myAlgorithm.guid().toLocal8Bit());
00268 
00269     int myTaxaCount = omglistTaxa->checkedItemCount();
00270     QStringList myTaxaList = omglistTaxa->checkedItems();
00271     for ( int myCounter = 0; myCounter < myTaxaCount; myCounter++ )
00272     {
00273       emit experimentProgress(myCounter);
00274       QApplication::processEvents();
00275       OmgModel *  mypModel = new OmgModel();
00276       //calling setguid with no parameters will cause a new guid to be allocated
00277       //I dont think this is needed anymore since I change omgguid's ctor
00278       mypModel->setGuid(); 
00279 
00280       QString myRasterFormat = mySettings.value("outputFormat","GreyTiff").toString();
00281       mypModel->setModelRasterFormat(myRasterFormat);
00282       mypModel->setCoordinateSystemName( cboCoordinateSystem->currentText());
00283       mypModel->setCoordinateSystem( mWktMap[cboCoordinateSystem->currentText()]);
00284       QString myLoaderType = mySettings.value("localities/loaderType","FILE").toString();
00285       if (myLoaderType=="FILE") //read locs from a single file with many taxa
00286       {
00287         QString myTaxon = myTaxaList.at(myCounter);
00288         emit logMessage ("Adding " + myTaxon.toLocal8Bit() + " to experiment");
00289         mypModel->setSpeciesFile(mSpeciesFileName);
00290         mypModel->setTaxonName(myTaxon);
00291       }
00292       else //list entries are file names from the dir
00293       {
00294         QString myFileName = myTaxaList.at(myCounter);
00295         //we need to find out the first
00296         QString myPrefix = 
00297           mySettings.value("openModeller/experimentDesigner/localitiesFileDirectory", "").toString();
00298         mypModel->setSpeciesFile(myPrefix + QDir::separator() + myFileName);
00299         QStringList mySpeciesList = getSpeciesList(myPrefix + QDir::separator() + myFileName);
00300         if (mySpeciesList.size()<1)
00301         {
00302           continue;
00303         }
00304         QString myTaxon=mySpeciesList.at(0);
00305         mypModel->setTaxonName(myTaxon);
00306         emit logMessage ("Adding " + myFileName.toLocal8Bit() + " to experiment");
00307       }
00308       mypModel->setOutputFormatLayerName(cboOutputFormatLayer->currentText());
00309       Omgui::LayerSetMap myLayerSetMap = Omgui::getAvailableLayerSets();
00310       OmgLayerSet myModelLayerSet = myLayerSetMap[cboModelLayerSet->currentText()];
00311       OmgLayerSet myProjectionLayerSet = myLayerSetMap[cboProjectionLayerSet->currentText()];
00312       mypModel->setCreationLayerSet(myModelLayerSet);
00313       mypModel->setProjectionLayerSet(myProjectionLayerSet);
00314       mypModel->setAlgorithm(myAlgorithm);    
00315       mypModel->loadLocalities();
00316       //options for locality uniqueness
00317 
00318       QString myFilter = 
00319         mySettings.value("localities/localitiesFilterType","NO_FILTER").toString();
00320       if (myFilter=="NO_FILTER")
00321       {
00322          mypModel->setLocalitiesFilterType(OmgModel::NO_FILTER);
00323       }
00324       else if(myFilter=="SPATIALLY_UNIQUE")
00325       {
00326          mypModel->setLocalitiesFilterType(OmgModel::SPATIALLY_UNIQUE);
00327       }
00328       else //environmentally unique
00329       {
00330          mypModel->setLocalitiesFilterType(OmgModel::ENVIRONMENTALLY_UNIQUE);
00331       }
00332       //qDebug(mypModel->toXml().toLocal8Bit());
00333       mypExperiment->addModel(mypModel);
00334     }
00335   }
00336   emit experimentMaximum(omglistTaxa->checkedItemCount() * myAlgorithmCount);
00337   //qDebug("Created experiment successfully");
00338   return mypExperiment;
00339 }
00340 void OmgExperimentDesigner::setStatus(QString theStatus)
00341 {
00342   //qDebug( theStatus.toAscii() );
00343 }
00344 
00345 void OmgExperimentDesigner::toolConfigureLocalitiesClicked()
00346 {
00347   OmgLocalitiesOptions myOptions;
00348   myOptions.exec();
00349 
00350 }
00351 
00352 void OmgExperimentDesigner::toolSelectLocalitiesFileClicked()
00353 {
00354   QSettings mySettings;
00355   QString myLoaderType = mySettings.value("localities/loaderType","FILE").toString();
00356   if (myLoaderType=="FILE") //read locs from a single file with many taxa
00357   {
00358     QString myFileTypeQString;
00359     QString myTextFileFilterString="Text File (*.txt)";
00360     QString myFileName = QFileDialog::getOpenFileName(
00361         this,
00362         "Select localities text file" , //caption
00363         mySettings.value("openModeller/experimentDesigner/localitiesFileDirectory", "").toString(), //initial dir
00364         myTextFileFilterString,  //filters to select
00365         &myFileTypeQString //the pointer to store selected filter
00366         );
00367     //std::cout << "Selected filetype filter is : " << myFileTypeQString.toAscii() << std::endl;
00368     if (myFileName.isEmpty()) return;
00369     setSpeciesList(myFileName);
00370 
00371     //store directory where localities file is for next time
00372     QFileInfo myFileInfo(myFileName);
00373     mySettings.setValue("openModeller/experimentDesigner/localitiesFileDirectory", myFileInfo.dir().path()+QString("/") );
00374   }
00375   else //read files from a dir
00376   {
00377     omglistTaxa->clear();
00378     QString myDirName = QFileDialog::getExistingDirectory(this, 
00379         tr("Select Directory"),
00380         mySettings.value("openModeller/experimentDesigner/localitiesFileDirectory", "").toString(),
00381         QFileDialog::ShowDirsOnly);
00382     if (myDirName.isEmpty()) return;
00383     setSpeciesList(myDirName);
00384     mySettings.setValue("openModeller/experimentDesigner/localitiesFileDirectory", myDirName + QString("/") );
00385 
00386   }
00387 } //end of on_pbnSelectLocalitiesFile_clicked
00388 
00389 
00390 void OmgExperimentDesigner::setSpeciesList(QString theFileName)
00391 {
00392   QSettings mySettings;
00393   QString myLoaderType = mySettings.value("localities/loaderType","FILE").toString();
00394   if (myLoaderType=="FILE") //read locs from a single file with many taxa
00395   {
00396     mSpeciesFileName=theFileName;
00397     //clear the existing entries in the taxon combo first
00398     omglistTaxa->clear();
00399     //
00400     // Now that we have the localities text file, we need to parse it and find
00401     // all unique instances of taxon names and populate the taxon combo...
00402     //
00403     QStringList myTaxonList = getSpeciesList(theFileName);;
00404     //sort the taxon list alpabetically descending order
00405     //Qt4 built in sort does in ascending order so I wrote my own sort
00406     myTaxonList = Omgui::sortList(myTaxonList);
00407     //now find the uniqe entries in the qstringlist and
00408     //add each entry to the taxon combo
00409     QString myLastTaxon="";
00410     QStringList::Iterator myIterator= myTaxonList.begin();
00411     while( myIterator!= myTaxonList.end() )
00412     {
00413       QString myCurrentTaxon=*myIterator;
00414       if (myCurrentTaxon!=myLastTaxon)
00415       {
00416         omglistTaxa->addItem(myCurrentTaxon,true);
00417       }
00418       myLastTaxon=*myIterator;
00419       ++myIterator;
00420     }
00421   }
00422   else //read files from a dir
00423   {
00424     omglistTaxa->clear();
00425     QDir myDir(theFileName);
00426     myDir.setFilter( QDir::Files | QDir::Readable );
00427     myDir.setSorting( QDir::Name );
00428     QStringList myFilters;
00429     myFilters << "*.txt";
00430     myDir.setNameFilters( myFilters );
00431 
00432     QFileInfoList myList = myDir.entryInfoList();
00433     if (myList.size()==0)
00434     {
00435       QMessageBox::warning( this,tr("openModeller OmgExperimentDesigner Warning"),
00436           tr("No valid localities files were found. "
00437             "Make sure that your localities files have a .txt extension "
00438             "and are in the format:\n"
00439             "ID <tab> Taxon name <tab> longitude <tab> latitude"));
00440       mFirstNonIdRecord=false;
00441     }
00442     for (int myCount = 0; myCount < myList.size(); ++myCount) 
00443     {
00444       QFileInfo myFileInfo = myList.at(myCount);
00445       if (!myFileInfo.fileName().endsWith(".txt"))
00446       {
00447         continue;
00448       }
00449       omglistTaxa->addItem(myFileInfo.fileName(),true);
00450     }
00451     //show how many files you have
00452     //lblFileCount->setText("("+QString::number(lstLocalitiesFiles->count())+")");
00453   }
00454 } //end of setSpeciesList
00455 
00456 QStringList OmgExperimentDesigner::getSpeciesList(QString theFileName)
00457 {
00458   QStringList myTaxonList;
00459   QFile myQFile( theFileName );
00460   if ( myQFile.open( QIODevice::ReadOnly ) )
00461   {
00462     //now we parse the loc file, checking each line for its taxon
00463     QTextStream myQTextStream( &myQFile );
00464     QString myCurrentLine;
00465     unsigned int myCounter=0;
00466     while ( !myQTextStream.atEnd() )
00467     {
00468       myCurrentLine = myQTextStream.readLine(); // line of text excluding '\n'
00469       if (myCurrentLine.startsWith("#"))
00470       {
00471         continue;
00472       }
00473       //split on word boundaries ignoring empty parts
00474       QStringList myList = myCurrentLine.split(QRegExp("[\t]"));
00475       //qDebug("Read line : " + myList.join(" -- ").toLocal8Bit());
00476       if (myList.size() < 4)
00477       {
00478         continue;
00479       }
00480       else //new file format with at least 4 columns
00481       {
00482         QString myId=myList.at(0).simplified();
00483         QString myTaxonName=myList.at(1).simplified();
00484         if (myTaxonName!= "")
00485         {
00486           //make sure there are only single spaces separating words.
00487           myTaxonName=myTaxonName.replace( QRegExp(" {2,}"), " " );
00488           myTaxonList.append(myTaxonName);
00489           ++myCounter;
00490         }
00491       }
00492     }
00493     myQFile.close();
00494   }
00495   else
00496   {
00497     QMessageBox::warning( this,QString("openModeller OmgExperimentDesigner Error"),QString("The localities file is not readable. Check you have the neccessary file permissions and try again."));
00498   }
00499   return myTaxonList;
00500 }
00501 
00502 bool OmgExperimentDesigner::checkLayersMatch()
00503 {
00505   //if (lstProjectionLayers->count()==lstModelLayers->count())
00506   //{
00507     return true;
00508   //}
00509   //else
00510   //{
00511   //  return false;
00512   //}
00513 }//checkLayersMatch
00514 void OmgExperimentDesigner::on_toolFormatLayer_clicked()
00515 {
00516   QSettings mySettings;
00517   QString myBaseDir = mySettings.value("openModeller/experimentDesigner/formatLayersDirectory","c:/tmp").toString(); //initial dir
00518   OmgLayerSelector * myOmgLayerSelector = new OmgLayerSelector(myBaseDir, this);
00519   myOmgLayerSelector->setSelectionMode(QAbstractItemView::SingleSelection);
00520   if(myOmgLayerSelector->exec())
00521   {
00522     QStringList myList=myOmgLayerSelector->getSelectedLayers();
00523     //sort on descending alphabetical order
00524     myList = Omgui::sortList(myList);
00525     if (myList.size()<1)
00526     {
00527       //do nothing
00528       return;
00529     }
00530     else
00531     {
00532       cboOutputFormatLayer->insertItem(0, myList[0]);
00533     }
00534     mySettings.setValue("openModeller/experimentDesigner/formatLayersDirectory",myOmgLayerSelector->getBaseDir());
00535   }
00536 }
00537 
00538 void OmgExperimentDesigner::readSettings()
00539 {
00540   QSettings mySettings;
00541   QString myPluginName = mySettings.value("openModeller/modellerPluginType", "Local Modeller Plugin" ).toString();
00542 
00543   //select the last model creation layer set used by getting the name from qsettings
00544   QString myLayerSetName = mySettings.value("openModeller/experimentDesigner/" +
00545       myPluginName + "/modelLayerSet").toString();
00546   setComboToDefault( cboModelLayerSet, myLayerSetName, false);
00547   //select the last projection layer set used by getting the name from qsettings
00548   myLayerSetName = mySettings.value("openModeller/experimentDesigner/" + 
00549       myPluginName + "/projectionLayerSet").toString();
00550   setComboToDefault( cboProjectionLayerSet, myLayerSetName,false);
00551   //set the coordinate system to the same as the last time run
00552   QString myCoordSystem = mySettings.value("openModeller/experimentDesigner/coordSystem","Lat/Long WGS84").toString();
00553   setComboToDefault( cboCoordinateSystem, myCoordSystem, false);
00554   //set the localities filename
00555   QString myLoaderType = mySettings.value("localities/loaderType","FILE").toString();
00556   if (myLoaderType=="FILE") //read locs from a single file with many taxa
00557   {
00558     QString myFileName = mySettings.value("openModeller/experimentDesigner/localitiesFileName").toString();
00559     if (!myFileName.isEmpty())
00560     {
00561       setSpeciesList(myFileName);
00562     }
00563   }
00564   else //multiple files in a dir
00565   {
00566     QString myDirName = mySettings.value("openModeller/experimentDesigner/localitiesFileDirectory").toString();
00567     if (!myDirName.isEmpty())
00568     {
00569       setSpeciesList(myDirName);
00570     }
00571   }
00572   // Restore the output format
00573   QString myOutputFormat = mySettings.value("openModeller/experimentDesigner/" + 
00574       myPluginName + "/outputFormatFile").toString();
00575   setComboToDefault( cboOutputFormatLayer,myOutputFormat,true);
00576 }
00577 
00578 void OmgExperimentDesigner::writeSettings()
00579 {
00580   QSettings mySettings;
00581   QString myPluginName = mySettings.value("openModeller/modellerPluginType", "Local Modeller Plugin" ).toString();
00582   mySettings.setValue("openModeller/experimentDesigner/localitiesFileName", mSpeciesFileName);
00583   mySettings.setValue("openModeller/experimentDesigner/" + myPluginName + "/modelLayerSet",
00584       cboModelLayerSet->currentText());
00585   mySettings.setValue("openModeller/experimentDesigner/" + myPluginName + "/projectionLayerSet",
00586       cboProjectionLayerSet->currentText());
00587   mySettings.setValue("openModeller/experimentDesigner/coordSystem",cboCoordinateSystem->currentText());
00588   mySettings.setValue("openModeller/experimentDesigner/" + myPluginName + "/outputFormatFile",cboOutputFormatLayer->currentText());
00589   mySettings.setValue("openModeller/experimentDesigner/" + myPluginName + "/selectedAlgorithms",omglistAlgorithms->checkedItems());
00590 }
00591 
00592 /* update the layer formats combo when a model layer set is changed */
00593 void OmgExperimentDesigner::on_cboModelLayerSet_currentIndexChanged(int theIndex)
00594 {
00595   refreshMapFormatCombo();
00596 }
00597 
00598 /* update the layer formats combo when a projection  layer set is changed */
00599 void OmgExperimentDesigner::on_cboProjectionLayerSet_currentIndexChanged(int theIndex)
00600 {
00601   refreshMapFormatCombo();
00602 }
00603 
00604 void OmgExperimentDesigner::refreshMapFormatCombo()
00605 {
00606   Omgui::LayerSetMap myLayerSetMap = Omgui::getAvailableLayerSets();
00607   OmgLayerSet myModelLayerSet = myLayerSetMap[cboModelLayerSet->currentText()];
00608   OmgLayerSet myProjectionLayerSet = myLayerSetMap[cboProjectionLayerSet->currentText()];
00609   QStringList myNameList = myModelLayerSet.nameList();
00610   myNameList << myProjectionLayerSet.nameList();
00611   myNameList = Omgui::sortList(myNameList);
00612   myNameList = Omgui::uniqueList(myNameList);
00613   cboOutputFormatLayer->clear();
00614   cboOutputFormatLayer->insertItems(0,myNameList);
00615 }
00616 QStringList OmgExperimentDesigner::getListWidgetEntries(const QListWidget * theListWidget)
00617 {
00618   QStringList myList;
00619   for ( int myCounter = 0; myCounter < theListWidget->count(); myCounter++ )
00620   {
00621     myList.append(theListWidget->item(myCounter)->text());
00622   }
00623   return myList;
00624 }
00625 
00626 bool OmgExperimentDesigner::setComboToDefault(QComboBox * thepCombo, QString theDefault, bool theAddItemFlag)
00627 {
00628   if (!theDefault.isEmpty())
00629   {
00630     //loop through list looking for a match
00631     for ( int myCounter = 0; myCounter < thepCombo->count(); myCounter++ )
00632     {
00633       thepCombo->setCurrentIndex(myCounter);
00634       if (thepCombo->currentText()==theDefault)
00635       {
00636         break;
00637       }
00638     }
00639     if (theAddItemFlag)
00640     {
00641       //if we get this far then no match was found and we should insert our
00642       //default as a new combo list entry
00643       thepCombo->insertItem(theDefault);
00644       thepCombo->setCurrentIndex(thepCombo->count()-1);
00645     }
00646   }
00647   else
00648   {
00649     return false;
00650   }
00651   return true;
00652 }

Generated on Mon Apr 28 15:07:10 2008 for openModellerDesktop by  doxygen 1.4.1-20050210