Changeset 6f5dfe for src


Ignore:
Timestamp:
Oct 22, 2010, 4:13:36 PM (14 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
bd2390, db7cb0
Parents:
e4decc
Message:

Added boost::filesystem usage for input files.

  • parameters for Action input now have type boost::filesystem.
  • rewritten Actions to use boost::filesystems
  • in the progress of writing FileQtQuery to present a file dialog.
Location:
src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MapOfActions.cpp

    re4decc r6f5dfe  
    3131#include <boost/optional.hpp>
    3232#include <boost/program_options.hpp>
     33#include <boost/filesystem.hpp>
    3334
    3435#include <iostream>
     
    367368  TypeMap["fill-void"] = &typeid(std::string);
    368369  TypeMap["fragment-mol"] = &typeid(std::string);
    369   TypeMap["input"] = &typeid(std::string);
     370  TypeMap["input"] = &typeid(boost::filesystem::path);
    370371  TypeMap["linear-interpolate"] = &typeid(std::string);
    371372  TypeMap["molecular-volume"] = &typeid(molecule);
     
    825826}
    826827
     828void MapOfActions::queryCurrentValue(const char * name, boost::filesystem::path&_T)
     829{
     830  std::string tmp;
     831  if (typeid( boost::filesystem::path ) == *TypeMap[name]) {
     832    if (CurrentValue.find(name) == CurrentValue.end())
     833      throw MissingValueException(__FILE__, __LINE__);
     834    std::istringstream stream(CurrentValue[name]);
     835    CurrentValue.erase(name);
     836    if (!stream.fail()) {
     837      stream >> tmp >> ws;
     838      _T = tmp;
     839    }
     840  } else
     841    throw IllegalTypeException(__FILE__,__LINE__);
     842}
     843
    827844
    828845void MapOfActions::setCurrentValue(const char * name, class atom * &_T)
     
    927944      stream << (*iter)->getId() << " ";
    928945    }
     946    CurrentValue[name] = stream.str();
     947  } else
     948    throw IllegalTypeException(__FILE__,__LINE__);
     949}
     950
     951void MapOfActions::setCurrentValue(const char * name, boost::filesystem::path &_T)
     952{
     953  if (typeid( boost::filesystem::path ) == *TypeMap[name]) {
     954    std::ostringstream stream;
     955    stream << _T.string();
    929956    CurrentValue[name] = stream.str();
    930957  } else
  • src/Actions/MapOfActions.hpp

    re4decc r6f5dfe  
    99#define MAPOFACTIONS_HPP_
    1010
     11#include <boost/filesystem.hpp>
     12#include <boost/lexical_cast.hpp>
    1113#include <boost/program_options.hpp>
    12 #include <boost/lexical_cast.hpp>
    1314
    1415#include <map>
     
    3132
    3233namespace po = boost::program_options;
     34namespace fs = boost::filesystem;
    3335
    3436using boost::lexical_cast;
     
    173175  void queryCurrentValue(const char * name, std::vector<const element *>&_T);
    174176  void queryCurrentValue(const char * name, std::vector<molecule *>&_T);
     177  void queryCurrentValue(const char * name, fs::path&_T);
    175178  template<typename T> void queryCurrentValue(const char * name, T &_T)
    176179  {
     
    208211  void setCurrentValue(const char * name, std::vector<const element *>&_T);
    209212  void setCurrentValue(const char * name, std::vector<molecule *>&_T);
     213  void setCurrentValue(const char * name, fs::path&_T);
    210214  template<class T> void setCurrentValue(const char * name, T &_T)
    211215  {
  • src/Actions/WorldAction/InputAction.cpp

    re4decc r6f5dfe  
    3030#include <string>
    3131
     32#include <boost/filesystem/fstream.hpp>
     33
    3234using namespace std;
    3335
     
    3941/** =========== define the function ====================== */
    4042Action::state_ptr WorldInputAction::performCall() {
    41   MoleculeListClass *molecules = World::getInstance().getMolecules();
    42   molecule *mol = NULL;
    43   std::ifstream test;
     43//  MoleculeListClass *molecules = World::getInstance().getMolecules();
     44//  molecule *mol = NULL;
     45  boost::filesystem::ifstream test;
    4446
    4547  // obtain information
    4648  getParametersfromValueStorage();
    4749
    48   DoLog(0) && (Log() << Verbose(0) << "Config file given." << endl);
    49   if (params.filename.find('.') != string::npos) {
    50     std::string FilenamePrefix = params.filename.substr(0,params.filename.find_last_of('.'));
    51     std::string FilenameSuffix = params.filename.substr(params.filename.find_last_of('.')+1, params.filename.length());
    52     DoLog(1) && (Log() << Verbose(1) << "Setting config file name prefix to " << FilenamePrefix << "." << endl);
    53     test.open(params.filename.c_str());
    54     if (test == NULL) {
    55       DoLog(1) && (Log() << Verbose(1) << "Specified config file " << params.filename << " not found." << endl);
     50  DoLog(0) && (Log() << Verbose(0) << "Config file given " << params.filename << "." << endl);
     51  if (!boost::filesystem::exists(params.filename)) {
     52    DoLog(1) && (Log() << Verbose(1) << "Specified config file " << params.filename << " not found." << endl);
     53    return Action::failure;
     54  } else {
     55    DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... ");
     56    if (params.filename.has_filename()) {
     57      // get suffix
     58      std::string FilenameSuffix = params.filename.extension();
     59      std::string FilenamePrefix = params.filename.stem();
     60      DoLog(1) && (Log() << Verbose(1) << "Setting config file name prefix to " << FilenamePrefix << "." << endl);
     61      FormatParserStorage::getInstance().SetOutputPrefixForAll(FilenamePrefix);
     62
     63      // parse the file
     64      test.open(params.filename);
     65      FormatParserStorage::getInstance().get(test, FilenameSuffix);
     66      test.close();
     67//
     68//      // set mol to first active molecule
     69//      if (molecules->ListOfMolecules.size() != 0) {
     70//        for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
     71//          if ((*ListRunner)->ActiveFlag) {
     72//            mol = *ListRunner;
     73//            break;
     74//          }
     75//      }
     76//      if (mol == NULL) {
     77//        mol = World::getInstance().createMolecule();
     78//        mol->ActiveFlag = true;
     79//        molecules->insert(mol);
     80//      }
     81//      mol->SetNameFromFilename(params.filename.substr(0,params.filename.find('.')).c_str());
     82      return Action::success;
    5683    } else {
    57       DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... ");
    58       FormatParserStorage::getInstance().get((std::istream &)test, FilenameSuffix);
    59       test.close();
     84      DoeLog(1) && (eLog() << Verbose(1) << "Input file does not have a suffix, cannot recognize format." << endl);
     85      return Action::failure;
    6086    }
    61     FormatParserStorage::getInstance().SetOutputPrefixForAll(FilenamePrefix);
    62     // set mol to first active molecule
    63     if (molecules->ListOfMolecules.size() != 0) {
    64       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
    65         if ((*ListRunner)->ActiveFlag) {
    66           mol = *ListRunner;
    67           break;
    68         }
    69     }
    70     if (mol == NULL) {
    71       mol = World::getInstance().createMolecule();
    72       mol->ActiveFlag = true;
    73       molecules->insert(mol);
    74     }
    75     mol->SetNameFromFilename(params.filename.substr(0,params.filename.find('.')).c_str());
    76   } else {
    77     DoeLog(1) && (eLog() << Verbose(1) << "Input file does not have a suffix, cannot recognize format." << endl);
    7887  }
    79   return Action::success;
    8088}
    8189
  • src/Actions/WorldAction/InputAction.def

    re4decc r6f5dfe  
    77
    88// all includes and forward declarations necessary for non-integral types below
    9 
     9#include <boost/filesystem.hpp>
    1010
    1111// i.e. there is an integer with variable name Z that can be found in
    1212// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1313// "undefine" if no parameters are required
    14 #define paramtypes (std::string)
     14#define paramtypes (boost::filesystem::path)
    1515#define paramtokens (WorldInputAction::NAME)
    1616#define paramreferences (filename)
  • src/UIElements/CommandLineUI/CommandLineDialog.cpp

    re4decc r6f5dfe  
    125125void CommandLineDialog::queryElements(const char* title, string _description){
    126126  registerQuery(new ElementsCommandLineQuery(title, _description));
     127}
     128
     129void CommandLineDialog::queryFile(const char* title, string _description){
     130  registerQuery(new FileCommandLineQuery(title, _description));
    127131}
    128132
     
    457461  }
    458462}
     463
     464CommandLineDialog::FileCommandLineQuery::FileCommandLineQuery(string title, string _description) :
     465    Dialog::FileQuery(title, _description)
     466{}
     467
     468CommandLineDialog::FileCommandLineQuery::~FileCommandLineQuery() {}
     469
     470bool CommandLineDialog::FileCommandLineQuery::handle() {
     471  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     472    tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
     473    return true;
     474  } else {
     475    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
     476    return false;
     477  }
     478}
     479
  • src/UIElements/CommandLineUI/CommandLineDialog.hpp

    re4decc r6f5dfe  
    4444  virtual void queryElement(const char*, std::string = "");
    4545  virtual void queryElements(const char*, std::string = "");
     46  virtual void queryFile(const char*, std::string = "");
    4647
    4748protected:
     
    165166    virtual bool handle();
    166167  };
     168
     169  class FileCommandLineQuery : public Dialog::FileQuery {
     170  public:
     171    FileCommandLineQuery(std::string title, std::string _description = "");
     172    virtual ~FileCommandLineQuery();
     173    virtual bool handle();
     174  };
    167175};
    168176
  • src/UIElements/Dialog.cpp

    re4decc r6f5dfe  
    180180}
    181181
     182template <> void Dialog::query< boost::filesystem::path >(const char *token, std::string description)
     183{
     184  queryFile(token, description);
     185}
     186
    182187/****************** Query types Infrastructure **************************/
    183188
     
    407412  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    408413}
     414
     415// File Queries
     416Dialog::FileQuery::FileQuery(std::string title, std::string _description) :
     417  Query(title, _description)
     418  {}
     419
     420Dialog::FileQuery::~FileQuery(){}
     421
     422void Dialog::FileQuery::setResult(){
     423  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     424}
  • src/UIElements/Dialog.hpp

    re4decc r6f5dfe  
    1212#include<list>
    1313#include<vector>
     14
     15#include <boost/filesystem.hpp>
    1416
    1517#include "Box.hpp"
     
    5759  virtual void queryElement(const char*, std::string = "")=0;
    5860  virtual void queryElements(const char*, std::string = "")=0;
     61  virtual void queryFile(const char*, std::string = "")=0;
    5962
    6063  virtual bool display();
     
    271274  };
    272275
     276  class FileQuery : public Query {
     277  public:
     278    FileQuery(std::string title, std::string _description = "");
     279    virtual ~FileQuery();
     280    virtual bool handle()=0;
     281    virtual void setResult();
     282  protected:
     283    boost::filesystem::path tmp;
     284  };
     285
    273286void registerQuery(Query* query);
    274287
  • src/UIElements/QT4/QTDialog.cpp

    re4decc r6f5dfe  
    179179  // TODO
    180180  ASSERT(false, "Not implemented yet");
     181}
     182
     183void QTDialog::queryFile(const char* title, std::string){
     184  registerQuery(new FileQTQuery(title,inputLayout,this));
    181185}
    182186
     
    622626}
    623627
     628QTDialog::FileQTQuery::FileQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
     629    Dialog::FileQuery(_title),
     630    parent(_parent)
     631{
     632
     633  filenameLineEdit = new QLineEdit(_dialog);
     634  filenameLineEdit->setText(QString());
     635  filenameLineEdit->setReadOnly(true);
     636
     637  filedialogButton = new QPushButton("&Choose", _dialog);
     638
     639  pipe = new FileQTQueryPipe(tmp,_dialog,filenameLineEdit,filedialogButton);
     640
     641  thisLayout = new QHBoxLayout();
     642  parent->addLayout(thisLayout);
     643  thisLayout->addWidget(filenameLineEdit);
     644  thisLayout->addWidget(filedialogButton);
     645
     646  QObject::connect(filedialogButton,SIGNAL(clicked()),pipe,SLOT(showFileDialog()));
     647}
     648
     649QTDialog::FileQTQuery::~FileQTQuery()
     650{
     651  delete pipe;
     652}
     653
     654bool QTDialog::FileQTQuery::handle(){
     655  return true;
     656}
     657
    624658/*************************** Plumbing *******************************/
    625659
     
    862896}
    863897
    864 
     898FileQTQueryPipe::FileQTQueryPipe(const boost::filesystem::path &_content, QTDialog *_dialog, QLineEdit *_filenameLineEdit, QPushButton *_filedialogButton) :
     899  content(_content),
     900  dialog(_dialog),
     901  filenameLineEdit(_filenameLineEdit),
     902  filedialogButton(_filedialogButton)
     903{}
     904
     905FileQTQueryPipe::~FileQTQueryPipe()
     906{}
     907
     908void FileQTQueryPipe::update() {
     909  QStringList ListOfFilenames = theFileDialog->selectedFiles();
     910  std::cout << "Selected File is " << ListOfFilenames.at(0).toStdString() << std::endl;
     911  content = ListOfFilenames.at(0).toStdString();
     912  dialog->update();
     913}
     914
     915void FileQTQueryPipe::showFileDialog() {
     916  filedialogButton->setFlat(true);
     917  if (theFileDialog == NULL) {
     918    theFileDialog = new QFileDialog(NULL, tr("Open input file"), QString(), tr("ParallelCarParrinello (*.conf);;MassivelyParallelQuantumChemistry (*.mpqc);;ParticleDataBase (*.pdb);;XYZ (*.xyz)"));
     919    theFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
     920    theFileDialog->setFileMode(QFileDialog::ExistingFile);
     921    theFileDialog->setViewMode(QFileDialog::List);
     922  }
     923  theFileDialog->show();
     924
     925  filenameLineEdit->setText(QString());
     926  filedialogButton->setFlat(false);
     927}
     928
     929
     930
  • src/UIElements/QT4/QTDialog.hpp

    re4decc r6f5dfe  
    1111#include "UIElements/Dialog.hpp"
    1212#include <QtGui/QDialog>
     13#include <QtGui/QFileDialog>
     14
     15#include <boost/filesystem.hpp>
    1316
    1417class QBoxLayout;
     
    3740class VectorQTQueryPipe;
    3841class VectorsQTQueryPipe;
     42class FileQTQueryPipe;
    3943
    4044class QTDialog : public QDialog, public Dialog
     
    6266  virtual void queryElement(const char*,std::string = "");
    6367  virtual void queryElements(const char*,std::string = "");
     68  virtual void queryFile(const char*,std::string = "");
    6469
    6570  virtual bool display();
     
    271276
    272277      ElementsQTQueryPipe *pipe;
     278    };
     279
     280    class FileQTQuery : public Dialog::FileQuery {
     281    public:
     282      FileQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog);
     283      virtual ~FileQTQuery();
     284      virtual bool handle();
     285    private:
     286      QBoxLayout *parent;
     287      QBoxLayout *thisLayout;
     288      QLineEdit *filenameLineEdit;
     289      QPushButton *filedialogButton;
     290
     291      FileQTQueryPipe *pipe;
    273292    };
    274293
     
    477496  QComboBox *theBox;
    478497};
     498
     499class FileQTQueryPipe : public QWidget {
     500  Q_OBJECT
     501public:
     502  FileQTQueryPipe(const boost::filesystem::path &_content, QTDialog *_dialog, QLineEdit *_filenameLineEdit, QPushButton *_filedialogButton);
     503  virtual ~FileQTQueryPipe();
     504
     505public slots:
     506  void update();
     507  void showFileDialog();
     508
     509private:
     510  boost::filesystem::path content;
     511  QTDialog *dialog;
     512  QLineEdit *filenameLineEdit;
     513  QPushButton *filedialogButton;
     514  QFileDialog *theFileDialog;
     515};
     516
    479517#endif /* QTDIALOG_HPP_ */
  • src/UIElements/TextUI/TextDialog.cpp

    re4decc r6f5dfe  
    4242
    4343#include <boost/lexical_cast.hpp>
     44#include <boost/filesystem.hpp>
    4445
    4546using namespace std;
     
    123124void TextDialog::queryElements(const char* title, std::string description){
    124125  registerQuery(new ElementsTextQuery(title,description));
     126}
     127
     128void TextDialog::queryFile(const char* title, std::string description){
     129  registerQuery(new FileTextQuery(title,description));
    125130}
    126131
     
    684689  return (Z!=-1);
    685690}
     691
     692TextDialog::FileTextQuery::FileTextQuery(string title, std::string _description) :
     693    Dialog::FileQuery(title,_description)
     694{}
     695
     696TextDialog::FileTextQuery::~FileTextQuery() {}
     697
     698bool TextDialog::FileTextQuery::handle() {
     699  Log() << Verbose(0) << getTitle();
     700  std::string tempstring;
     701  getline(cin,tempstring);
     702  tmp = tempstring;
     703  return true;
     704}
     705
  • src/UIElements/TextUI/TextDialog.hpp

    re4decc r6f5dfe  
    4141  virtual void queryElement(const char*, std::string = "");
    4242  virtual void queryElements(const char*, std::string = "");
     43  virtual void queryFile(const char*, std::string = "");
    4344
    4445protected:
     
    162163    virtual bool handle();
    163164  };
     165
     166  class FileTextQuery : public Dialog::FileQuery {
     167  public:
     168    FileTextQuery(std::string title, std::string _description = NULL);
     169    virtual ~FileTextQuery();
     170    virtual bool handle();
     171  };
    164172};
    165173
  • src/unittests/DummyUI.hpp

    re4decc r6f5dfe  
    3535  virtual void queryElement(const char*, std::string = ""){}
    3636  virtual void queryElements(const char*, std::string = ""){}
     37  virtual void queryFile(const char*, std::string = ""){}
    3738};
    3839
Note: See TracChangeset for help on using the changeset viewer.