Changeset 8df74d for src


Ignore:
Timestamp:
Oct 25, 2010, 5:16:19 PM (15 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:
573ca5, b295ca
Parents:
57a6ea1
git-author:
Frederik Heber <heber@…> (10/25/10 17:11:33)
git-committer:
Frederik Heber <heber@…> (10/25/10 17:16:19)
Message:

Split off all ...Query and ...Pipe boilerplate classes.

  • each subclass in the dialog nor resides in its own file in a folder called Query (or Pipe).
  • only submoduled (no header files created, except for templated QtQueryListPipe class)
  • includes have been separated
Location:
src
Files:
89 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r57a6ea1 r8df74d  
    129129                                 
    130130QTUISOURCE = allmocs.moc.cpp \
     131  UIElements/Qt4/Pipe/AtomQtQueryPipe.cpp \
     132  UIElements/Qt4/Pipe/AtomsQtQueryPipe.cpp \
     133  UIElements/Qt4/Pipe/BooleanQtQueryPipe.cpp \
     134  UIElements/Qt4/Pipe/BoxQtQueryPipe.cpp \
     135  UIElements/Qt4/Pipe/DoubleQtQueryPipe.cpp \
     136  UIElements/Qt4/Pipe/ElementsQtQueryPipe.cpp \
     137  UIElements/Qt4/Pipe/EmptyQtQueryPipe.cpp \
     138  UIElements/Qt4/Pipe/ElementQtQueryPipe.cpp \
     139  UIElements/Qt4/Pipe/FileQtQueryPipe.cpp \
     140  UIElements/Qt4/Pipe/IntQtQueryPipe.cpp \
     141  UIElements/Qt4/Pipe/MoleculeQtQueryPipe.cpp \
     142  UIElements/Qt4/Pipe/MoleculesQtQueryPipe.cpp \
     143  UIElements/Qt4/Pipe/StringQtQueryPipe.cpp \
     144  UIElements/Qt4/Pipe/VectorQtQueryPipe.cpp \
     145  UIElements/Qt4/Pipe/VectorsQtQueryPipe.cpp \
     146  UIElements/Qt4/Query/AtomQtQuery.cpp \
     147  UIElements/Qt4/Query/AtomsQtQuery.cpp \
     148  UIElements/Qt4/Query/BooleanQtQuery.cpp \
     149  UIElements/Qt4/Query/BoxQtQuery.cpp \
     150  UIElements/Qt4/Query/DoubleQtQuery.cpp \
     151  UIElements/Qt4/Query/DoublesQtQuery.cpp \
     152  UIElements/Qt4/Query/ElementQtQuery.cpp \
     153  UIElements/Qt4/Query/ElementsQtQuery.cpp \
     154  UIElements/Qt4/Query/EmptyQtQuery.cpp \
     155  UIElements/Qt4/Query/FileQtQuery.cpp \
     156  UIElements/Qt4/Query/IntQtQuery.cpp \
     157  UIElements/Qt4/Query/IntsQtQuery.cpp \
     158  UIElements/Qt4/Query/MoleculeQtQuery.cpp \
     159  UIElements/Qt4/Query/MoleculesQtQuery.cpp \
     160  UIElements/Qt4/Query/StringQtQuery.cpp \
     161  UIElements/Qt4/Query/StringsQtQuery.cpp \
     162  UIElements/Qt4/Query/VectorQtQuery.cpp \
     163  UIElements/Qt4/Query/VectorsQtQuery.cpp \
    131164        UIElements/Qt4/QtMainWindow.cpp \
    132165        UIElements/Qt4/QtDialog.cpp \
     
    138171        UIElements/Views/Qt4/QtStatusBar.cpp
    139172             
    140 QTUIHEADER = ${QTUIMOC_HEADER} UIElements/Qt4/QtUIFactory.hpp
     173QTUIHEADER = \
     174  ${QTUIMOC_HEADER} \
     175  UIElements/Qt4/Pipe/QtQueryListPipe.hpp \
     176  UIElements/Qt4/QtUIFactory.hpp
    141177
    142178QTUI_DEFS =
  • src/UIElements/CommandLineUI/CommandLineDialog.cpp

    r57a6ea1 r8df74d  
    2020#include "Helpers/MemDebug.hpp"
    2121
    22 #include <iostream>
    23 #include <vector>
    24 
    25 #include <Descriptors/AtomDescriptor.hpp>
    26 #include <Descriptors/AtomIdDescriptor.hpp>
    27 #include <Descriptors/MoleculeDescriptor.hpp>
    28 #include <Descriptors/MoleculeIdDescriptor.hpp>
    2922#include "CommandLineUI/CommandLineDialog.hpp"
    3023
    31 #include "Actions/Values.hpp"
    32 
    33 #include "element.hpp"
    34 #include "periodentafel.hpp"
    35 #include "CommandLineParser.hpp"
    36 #include "defs.hpp"
    37 #include "Helpers/Log.hpp"
    38 #include "LinearAlgebra/Matrix.hpp"
    39 #include "periodentafel.hpp"
    40 #include "Helpers/Verbose.hpp"
    41 #include "World.hpp"
    42 #include "Box.hpp"
    43 
    44 #include "atom.hpp"
    45 #include "element.hpp"
    46 #include "molecule.hpp"
    47 #include "LinearAlgebra/Vector.hpp"
    4824
    4925using namespace std;
     
    132108
    133109/************************** Query Infrastructure ************************/
    134 
    135 CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
    136     Dialog::EmptyQuery(title, _description)
    137 {}
    138 
    139 CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
    140 
    141 bool CommandLineDialog::EmptyCommandLineQuery::handle() {
    142   cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
    143   return true;
    144 }
    145 
    146 CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title, string _description) :
    147     Dialog::IntQuery(title, _description)
    148 {}
    149 
    150 CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
    151 
    152 bool CommandLineDialog::IntCommandLineQuery::handle() {
    153   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    154     tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
    155     return true;
    156   } else {
    157     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl);
    158     return false;
    159   }
    160 }
    161 
    162 CommandLineDialog::IntsCommandLineQuery::IntsCommandLineQuery(string title, string _description) :
    163     Dialog::IntsQuery(title, _description)
    164 {}
    165 
    166 CommandLineDialog::IntsCommandLineQuery::~IntsCommandLineQuery() {}
    167 
    168 bool CommandLineDialog::IntsCommandLineQuery::handle() {
    169   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    170     tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
    171     return true;
    172   } else {
    173     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integers for " << getTitle() << "." << endl);
    174     return false;
    175   }
    176 }
    177 
    178 CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title, string _description) :
    179     Dialog::BooleanQuery(title, _description)
    180 {}
    181 
    182 CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
    183 
    184 bool CommandLineDialog::BooleanCommandLineQuery::handle() {
    185   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    186     tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>();
    187     return true;
    188   } else {
    189     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl);
    190     return false;
    191   }
    192 }
    193 
    194 CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title, string _description) :
    195     Dialog::StringQuery(title, _description)
    196 {}
    197 
    198 CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
    199 
    200 bool CommandLineDialog::StringCommandLineQuery::handle() {
    201   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    202     tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
    203     return true;
    204   } else {
    205     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
    206     return false;
    207   }
    208 }
    209 
    210 CommandLineDialog::StringsCommandLineQuery::StringsCommandLineQuery(string title, string _description) :
    211     Dialog::StringsQuery(title, _description)
    212 {}
    213 
    214 CommandLineDialog::StringsCommandLineQuery::~StringsCommandLineQuery() {}
    215 
    216 bool CommandLineDialog::StringsCommandLineQuery::handle() {
    217   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    218     tmp = CommandLineParser::getInstance().vm[getTitle()].as< vector<string> >();
    219     return true;
    220   } else {
    221     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing strings for " << getTitle() << "." << endl);
    222     return false;
    223   }
    224 }
    225 
    226 CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title, string _description) :
    227     Dialog::DoubleQuery(title, _description)
    228 {}
    229 
    230 CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
    231 
    232 bool CommandLineDialog::DoubleCommandLineQuery::handle() {
    233   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    234     tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
    235     return true;
    236   } else {
    237     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl);
    238     return false;
    239   }
    240 }
    241 
    242 CommandLineDialog::DoublesCommandLineQuery::DoublesCommandLineQuery(string title, string _description) :
    243     Dialog::DoublesQuery(title, _description)
    244 {}
    245 
    246 CommandLineDialog::DoublesCommandLineQuery::~DoublesCommandLineQuery() {}
    247 
    248 bool CommandLineDialog::DoublesCommandLineQuery::handle() {
    249   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    250     tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<double> >();
    251     return true;
    252   } else {
    253     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing doubles for " << getTitle() << "." << endl);
    254     return false;
    255   }
    256 }
    257 
    258 CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, string _description) :
    259     Dialog::AtomQuery(title, _description)
    260 {}
    261 
    262 CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {}
    263 
    264 bool CommandLineDialog::AtomCommandLineQuery::handle() {
    265   int IdxOfAtom = -1;
    266   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    267     IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>();
    268     tmp = World::getInstance().getAtom(AtomById(IdxOfAtom));
    269     return true;
    270   } else {
    271     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl);
    272     return false;
    273   }
    274 }
    275 
    276 CommandLineDialog::AtomsCommandLineQuery::AtomsCommandLineQuery(string title, string _description) :
    277     Dialog::AtomsQuery(title, _description)
    278 {}
    279 
    280 CommandLineDialog::AtomsCommandLineQuery::~AtomsCommandLineQuery() {}
    281 
    282 bool CommandLineDialog::AtomsCommandLineQuery::handle() {
    283   std::vector<int> IdxOfAtom;
    284   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    285     IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
    286     for (std::vector<int>::iterator iter = IdxOfAtom.begin(); iter != IdxOfAtom.end(); ++iter) {
    287       temp = World::getInstance().getAtom(AtomById(*iter));
    288       if (temp)
    289         tmp.push_back(temp);
    290     }
    291     return true;
    292   } else {
    293     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atoms for " << getTitle() << "." << endl);
    294     return false;
    295   }
    296 }
    297 
    298 CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, string _description) :
    299     Dialog::MoleculeQuery(title, _description)
    300 {}
    301 
    302 CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
    303 
    304 bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
    305   int IdxOfMol = -1;
    306   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    307     IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
    308     tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
    309     return true;
    310   } else {
    311     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl);
    312     return false;
    313   }
    314 }
    315 
    316 CommandLineDialog::MoleculesCommandLineQuery::MoleculesCommandLineQuery(string title, string _description) :
    317     Dialog::MoleculesQuery(title, _description)
    318 {}
    319 
    320 CommandLineDialog::MoleculesCommandLineQuery::~MoleculesCommandLineQuery() {}
    321 
    322 bool CommandLineDialog::MoleculesCommandLineQuery::handle() {
    323   std::vector<int> IdxOfMol;
    324   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    325     IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
    326     for (std::vector<int>::iterator iter = IdxOfMol.begin(); iter != IdxOfMol.end(); ++iter) {
    327       temp = World::getInstance().getMolecule(MoleculeById(*iter));
    328       if (temp)
    329         tmp.push_back(temp);
    330     }
    331     return true;
    332   } else {
    333     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecules for " << getTitle() << "." << endl);
    334     return false;
    335   }
    336 }
    337 
    338 CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, bool _check, string _description) :
    339     Dialog::VectorQuery(title,_check, _description)
    340 {}
    341 
    342 CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
    343 {}
    344 
    345 bool CommandLineDialog::VectorCommandLineQuery::handle() {
    346   VectorValue temp;
    347   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    348     temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
    349     tmp[0] = temp.x;
    350     tmp[1] = temp.y;
    351     tmp[2] = temp.z;
    352     if ((check) && (!World::getInstance().getDomain().isInside(tmp))) {
    353       DoeLog(1) && (eLog() << Verbose(1) << "Vector " << tmp << " would be outside of box domain." << endl);
    354       return false;
    355     }
    356     return true;
    357   } else {
    358     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl);
    359     return false;
    360   }
    361 }
    362 
    363 CommandLineDialog::VectorsCommandLineQuery::VectorsCommandLineQuery(string title, bool _check, string _description) :
    364     Dialog::VectorsQuery(title,_check, _description)
    365 {}
    366 
    367 CommandLineDialog::VectorsCommandLineQuery::~VectorsCommandLineQuery()
    368 {}
    369 
    370 bool CommandLineDialog::VectorsCommandLineQuery::handle() {
    371   std::vector<VectorValue> temporary;
    372   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    373     temporary = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<VectorValue> >();
    374     for(std::vector<VectorValue>::iterator iter = temporary.begin(); iter != temporary.end(); ++iter) {
    375       temp[0] = (*iter).x;
    376       temp[1] = (*iter).y;
    377       temp[2] = (*iter).z;
    378       if ((!check) || (World::getInstance().getDomain().isInside(temp)))
    379         tmp.push_back(temp);
    380       else
    381         DoeLog(1) && (eLog() << Verbose(1) << "Vector " << temp << " would be outside of box domain." << endl);
    382     }
    383     return true;
    384   } else {
    385     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vectors for " << getTitle() << "." << endl);
    386     return false;
    387   }
    388 }
    389 
    390 CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, string _description) :
    391     Dialog::BoxQuery(title, _description)
    392 {}
    393 
    394 CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery()
    395 {}
    396 
    397 bool CommandLineDialog::BoxCommandLineQuery::handle() {
    398   BoxValue temp;
    399   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    400     temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >();
    401     Matrix M;
    402     M.set(0,0, temp.xx);
    403     M.set(0,1, temp.yx);
    404     M.set(0,2, temp.zx);
    405     M.set(1,0, temp.yx);
    406     M.set(1,1, temp.yy);
    407     M.set(1,2, temp.zy);
    408     M.set(2,0, temp.zx);
    409     M.set(2,1, temp.zy);
    410     M.set(2,2, temp.zz);
    411     tmp.setM(M);
    412     return true;
    413   } else {
    414     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl);
    415     return false;
    416   }
    417 }
    418 
    419 CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, string _description) :
    420     Dialog::ElementQuery(title, _description)
    421 {}
    422 
    423 CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
    424 {}
    425 
    426 bool CommandLineDialog::ElementCommandLineQuery::handle() {
    427   // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
    428   periodentafel *periode = World::getInstance().getPeriode();
    429   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    430     int Z = CommandLineParser::getInstance().vm[getTitle()].as< int >();
    431     tmp = periode->FindElement(Z);
    432     ASSERT(tmp != NULL, "Invalid element specified in ElementCommandLineQuery");
    433     return true;
    434   } else {
    435     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl);
    436     return false;
    437   }
    438 }
    439 
    440 CommandLineDialog::ElementsCommandLineQuery::ElementsCommandLineQuery(string title, string _description) :
    441     Dialog::ElementsQuery(title, _description)
    442 {}
    443 
    444 CommandLineDialog::ElementsCommandLineQuery::~ElementsCommandLineQuery()
    445 {}
    446 
    447 bool CommandLineDialog::ElementsCommandLineQuery::handle() {
    448   // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
    449   periodentafel *periode = World::getInstance().getPeriode();
    450   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    451     vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
    452     for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) {
    453       temp = periode->FindElement(*ZRunner);
    454       ASSERT(temp != NULL, "Invalid element specified in ElementCommandLineQuery");
    455       tmp.push_back(temp);
    456     }
    457     return true;
    458   } else {
    459     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing elements for " << getTitle() << "." << endl);
    460     return false;
    461   }
    462 }
    463 
    464 CommandLineDialog::FileCommandLineQuery::FileCommandLineQuery(string title, string _description) :
    465     Dialog::FileQuery(title, _description)
    466 {}
    467 
    468 CommandLineDialog::FileCommandLineQuery::~FileCommandLineQuery() {}
    469 
    470 bool CommandLineDialog::FileCommandLineQuery::handle() {
    471   if (CommandLineParser::getInstance().vm.count(getTitle())) {
    472     tmp = CommandLineParser::getInstance().vm[getTitle()].as< boost::filesystem::path >();
    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 
     110/*       ---> shifted to folder Query                                   */
     111/************************************************************************/
  • src/UIElements/Dialog.cpp

    r57a6ea1 r8df74d  
    2323#include "Actions/ValueStorage.hpp"
    2424
     25#include "Helpers/Log.hpp"
    2526#include "Helpers/Verbose.hpp"
    26 #include "atom.hpp"
    27 #include "Box.hpp"
    28 #include "element.hpp"
    29 #include "molecule.hpp"
    30 #include "LinearAlgebra/BoxVector.hpp"
    31 #include "LinearAlgebra/Vector.hpp"
    32 #include "LinearAlgebra/Matrix.hpp"
     27
     28class Atom;
     29class Box;
     30class element;
     31class Matrix;
     32class molecule;
     33class Vector;
    3334
    3435using namespace std;
     
    185186}
    186187
    187 /****************** Query types Infrastructure **************************/
    188 
    189 // Base class
    190 Dialog::Query::Query(string _title, string _description) :
    191     title(_title),
    192     description(_description)
    193 {}
    194 
    195 Dialog::Query::~Query() {}
    196 
    197 const std::string Dialog::Query::getTitle() const{
    198   return title;
    199 }
    200 
    201 const std::string Dialog::Query::getDescription() const{
    202   return description;
    203 }
    204 // empty Queries
    205 
    206 Dialog::EmptyQuery::EmptyQuery(string title, std::string description) :
    207     Query(title, description)
    208 {}
    209 
    210 Dialog::EmptyQuery::~EmptyQuery() {}
    211 
    212 void Dialog::EmptyQuery::setResult() {
    213 }
    214 
    215 // Int Queries
    216 
    217 Dialog::IntQuery::IntQuery(string title, std::string description) :
    218     Query(title, description)
    219 {}
    220 
    221 Dialog::IntQuery::~IntQuery() {}
    222 
    223 void Dialog::IntQuery::setResult() {
    224   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    225 }
    226 
    227 // Ints Queries
    228 
    229 Dialog::IntsQuery::IntsQuery(string title, std::string description) :
    230     Query(title, description)
    231 {}
    232 
    233 Dialog::IntsQuery::~IntsQuery() {}
    234 
    235 void Dialog::IntsQuery::setResult() {
    236   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    237 }
    238 
    239 // Bool Queries
    240 
    241 Dialog::BooleanQuery::BooleanQuery(string title,std::string description) :
    242     Query(title, description)
    243 {}
    244 
    245 Dialog::BooleanQuery::~BooleanQuery() {}
    246 
    247 void Dialog::BooleanQuery::setResult() {
    248   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    249 }
    250 
    251 // String Queries
    252 
    253 Dialog::StringQuery::StringQuery(string title,std::string _description) :
    254     Query(title, _description)
    255 {}
    256 
    257 Dialog::StringQuery::~StringQuery() {};
    258 
    259 void Dialog::StringQuery::setResult() {
    260   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    261 }
    262 
    263 // Strings Queries
    264 
    265 Dialog::StringsQuery::StringsQuery(string title,std::string _description) :
    266     Query(title, _description)
    267 {}
    268 
    269 Dialog::StringsQuery::~StringsQuery() {};
    270 
    271 void Dialog::StringsQuery::setResult() {
    272   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    273 }
    274 
    275 // Double Queries
    276 
    277 Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) :
    278     Query(title, _description)
    279 {}
    280 
    281 Dialog::DoubleQuery::~DoubleQuery() {};
    282 
    283 void Dialog::DoubleQuery::setResult() {
    284   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    285 }
    286 
    287 // Doubles Queries
    288 
    289 Dialog::DoublesQuery::DoublesQuery(string title, std::string _description) :
    290     Query(title, _description)
    291 {}
    292 
    293 Dialog::DoublesQuery::~DoublesQuery() {};
    294 
    295 void Dialog::DoublesQuery::setResult() {
    296   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    297 }
    298 
    299 
    300 // Atom Queries
    301 
    302 Dialog::AtomQuery::AtomQuery(string title, std::string _description) :
    303     Query(title, _description),
    304     tmp(0)
    305 {}
    306 
    307 Dialog::AtomQuery::~AtomQuery() {}
    308 
    309 void Dialog::AtomQuery::setResult() {
    310   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    311 }
    312 
    313 // Atoms Queries
    314 
    315 Dialog::AtomsQuery::AtomsQuery(string title, std::string _description) :
    316     Query(title, _description),
    317     tmp(0)
    318 {}
    319 
    320 Dialog::AtomsQuery::~AtomsQuery() {}
    321 
    322 void Dialog::AtomsQuery::setResult() {
    323   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    324 }
    325 
    326 // Molecule Queries
    327 
    328 Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) :
    329     Query(title, _description),
    330     tmp(0)
    331 {}
    332 
    333 Dialog::MoleculeQuery::~MoleculeQuery() {}
    334 
    335 void Dialog::MoleculeQuery::setResult() {
    336   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    337 }
    338 
    339 // Molecules Queries
    340 
    341 Dialog::MoleculesQuery::MoleculesQuery(string title, std::string _description) :
    342     Query(title, _description),
    343     tmp(0)
    344 {}
    345 
    346 Dialog::MoleculesQuery::~MoleculesQuery() {}
    347 
    348 void Dialog::MoleculesQuery::setResult() {
    349   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    350 }
    351 
    352 // Vector Queries
    353 
    354 Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) :
    355   Query(title, _description),
    356   check(_check)
    357 {}
    358 
    359 Dialog::VectorQuery::~VectorQuery()
    360 {}
    361 
    362 void Dialog::VectorQuery::setResult() {
    363   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    364 }
    365 
    366 // Vectors Queries
    367 
    368 Dialog::VectorsQuery::VectorsQuery(std::string title,bool _check, std::string _description) :
    369   Query(title, _description),
    370   check(_check)
    371 {}
    372 
    373 Dialog::VectorsQuery::~VectorsQuery()
    374 {}
    375 
    376 void Dialog::VectorsQuery::setResult() {
    377   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    378 }
    379 
    380 // Box Queries
    381 
    382 Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) :
    383   Query(title, _description)
    384 {}
    385 
    386 Dialog::BoxQuery::~BoxQuery()
    387 {}
    388 
    389 void Dialog::BoxQuery::setResult() {
    390   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    391 }
    392 
    393 // Element Queries
    394 Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) :
    395   Query(title, _description)
    396   {}
    397 
    398 Dialog::ElementQuery::~ElementQuery(){}
    399 
    400 void Dialog::ElementQuery::setResult(){
    401   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    402 }
    403 
    404 // Elements Queries
    405 Dialog::ElementsQuery::ElementsQuery(std::string title, std::string _description) :
    406   Query(title, _description)
    407   {}
    408 
    409 Dialog::ElementsQuery::~ElementsQuery(){}
    410 
    411 void Dialog::ElementsQuery::setResult(){
    412   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    413 }
    414 
    415 // File Queries
    416 Dialog::FileQuery::FileQuery(std::string title, std::string _description) :
    417   Query(title, _description)
    418   {}
    419 
    420 Dialog::FileQuery::~FileQuery(){}
    421 
    422 void Dialog::FileQuery::setResult(){
    423   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    424 }
     188/************************** Query Infrastructure ************************/
     189/*       ---> shifted to folder Query                                   */
     190/************************************************************************/
  • src/UIElements/Makefile.am

    r57a6ea1 r8df74d  
    4141  ${TEXTUISOURCE} \
    4242  ${VIEWSOURCE} \
     43  Query/AtomQuery.cpp \
     44  Query/AtomsQuery.cpp \
     45  Query/BooleanQuery.cpp \
     46  Query/BoxQuery.cpp \
     47  Query/DoubleQuery.cpp \
     48  Query/DoublesQuery.cpp \
     49  Query/ElementQuery.cpp \
     50  Query/ElementsQuery.cpp \
     51  Query/EmptyQuery.cpp \
     52  Query/FileQuery.cpp \
     53  Query/IntQuery.cpp \
     54  Query/IntsQuery.cpp \
     55  Query/MoleculeQuery.cpp \
     56  Query/MoleculesQuery.cpp \
     57  Query/Query.cpp \
     58  Query/StringQuery.cpp \
     59  Query/StringsQuery.cpp \
     60  Query/VectorQuery.cpp \
     61  Query/VectorsQuery.cpp \
    4362  Dialog.cpp \
    4463  MainWindow.cpp
     
    5473
    5574TEXTUISOURCE = \
     75  TextUI/Query/AtomsTextQuery.cpp \
     76  TextUI/Query/AtomTextQuery.cpp \
     77  TextUI/Query/BooleanTextQuery.cpp \
     78  TextUI/Query/BoxTextQuery.cpp \
     79  TextUI/Query/DoubleTextQuery.cpp \
     80  TextUI/Query/DoublesTextQuery.cpp \
     81  TextUI/Query/ElementTextQuery.cpp \
     82  TextUI/Query/ElementsTextQuery.cpp \
     83  TextUI/Query/EmptyTextQuery.cpp \
     84  TextUI/Query/FileTextQuery.cpp \
     85  TextUI/Query/IntTextQuery.cpp \
     86  TextUI/Query/IntsTextQuery.cpp \
     87  TextUI/Query/MoleculesTextQuery.cpp \
     88  TextUI/Query/MoleculeTextQuery.cpp \
     89  TextUI/Query/StringTextQuery.cpp \
     90  TextUI/Query/StringsTextQuery.cpp \
     91  TextUI/Query/VectorTextQuery.cpp \
     92  TextUI/Query/VectorsTextQuery.cpp \
    5693  TextUI/TextDialog.cpp \
    5794  TextUI/TextStatusIndicator.cpp \
     
    65102
    66103COMMANDLINEUISOURCE = \
     104  CommandLineUI/Query/AtomCommandLineQuery.cpp \
     105  CommandLineUI/Query/AtomsCommandLineQuery.cpp \
     106  CommandLineUI/Query/BooleanCommandLineQuery.cpp \
     107  CommandLineUI/Query/BoxCommandLineQuery.cpp \
     108  CommandLineUI/Query/DoubleCommandLineQuery.cpp \
     109  CommandLineUI/Query/DoublesCommandLineQuery.cpp \
     110  CommandLineUI/Query/ElementCommandLineQuery.cpp \
     111  CommandLineUI/Query/ElementsCommandLineQuery.cpp \
     112  CommandLineUI/Query/EmptyCommandLineQuery.cpp \
     113  CommandLineUI/Query/FileCommandLineQuery.cpp \
     114  CommandLineUI/Query/IntCommandLineQuery.cpp \
     115  CommandLineUI/Query/IntsCommandLineQuery.cpp \
     116  CommandLineUI/Query/MoleculeCommandLineQuery.cpp \
     117  CommandLineUI/Query/MoleculesCommandLineQuery.cpp \
     118  CommandLineUI/Query/StringCommandLineQuery.cpp \
     119  CommandLineUI/Query/StringsCommandLineQuery.cpp \
     120  CommandLineUI/Query/VectorCommandLineQuery.cpp \
     121  CommandLineUI/Query/VectorsCommandLineQuery.cpp \
    67122  CommandLineUI/CommandLineDialog.cpp \
    68123  CommandLineUI/CommandLineStatusIndicator.cpp \
  • src/UIElements/Qt4/QtDialog.cpp

    r57a6ea1 r8df74d  
    2020#include "UIElements/Qt4/QtDialog.hpp"
    2121
    22 #include <boost/lexical_cast.hpp>
    23 
    24 #include <string>
    25 #include <sstream>
    26 #include <limits>
    27 
    28 #include <QtGui/QDoubleSpinBox>
     22#include <QtGui/QDialogButtonBox>
     23#include <Qt/qpushbutton.h>
    2924#include <Qt/qboxlayout.h>
    30 #include <Qt/qcombobox.h>
    31 #include <Qt/qdialogbuttonbox.h>
    32 #include <Qt/qlabel.h>
    33 #include <Qt/qlineedit.h>
    34 #include <Qt/qlistwidget.h>
    35 #include <Qt/qpushbutton.h>
    36 #include <Qt/qspinbox.h>
    37 #include <Qt/qtablewidget.h>
    38 
    39 #include <boost/lexical_cast.hpp>
    4025
    4126#include "Helpers/MemDebug.hpp"
    42 
    43 #include "World.hpp"
    44 #include "periodentafel.hpp"
    45 #include "atom.hpp"
    46 #include "element.hpp"
    47 #include "molecule.hpp"
    48 #include "Descriptors/AtomIdDescriptor.hpp"
    49 #include "Descriptors/MoleculeIdDescriptor.hpp"
    50 #include "LinearAlgebra/Matrix.hpp"
    51 #include "Box.hpp"
    5227
    5328
     
    189164}
    190165
    191 /************************** Query Objects *******************************/
     166/************************** Query Infrastructure ************************/
     167/*       ---> shifted to folder Query                                   */
     168/************************************************************************/
    192169
    193 QtDialog::BoxQtQuery::BoxQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
    194     Dialog::BoxQuery(_title),
    195     parent(_parent)
    196 {
    197   thisLayout = new QHBoxLayout();
    198   titleLabel = new QLabel(QString(getTitle().c_str()));
    199 
    200   // init input table
    201   inputTable = new QTableWidget(3,3, _dialog);
    202   QStringList CoordinateList;
    203   CoordinateList << "x" << "y" << "z";
    204   inputTable->setHorizontalHeaderLabels(CoordinateList);
    205   inputTable->setVerticalHeaderLabels(CoordinateList);
    206 
    207   pipe = new BoxQtQueryPipe(tmp,_dialog, inputTable);
    208 
    209   // fill the box with current matrix
    210   const Matrix &domain = World::getInstance().getDomain().getM();
    211   for (int i=0;i<3;i++)
    212     for (int j=0;j<3;j++) {
    213       QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(domain.at(i,j)));
    214       inputTable->setItem(i,j,newItem);
    215       pipe->update(i,j);
    216     }
    217 
    218   parent->addLayout(thisLayout);
    219   thisLayout->addWidget(titleLabel);
    220   thisLayout->addWidget(inputTable);
    221 
    222   connect(inputTable,SIGNAL(cellChanged(int,int)),pipe,SLOT(update(int,int)));
    223 }
    224 
    225 QtDialog::BoxQtQuery::~BoxQtQuery()
    226 {
    227   delete pipe;
    228 }
    229 
    230 bool QtDialog::BoxQtQuery::handle() {
    231   return true;
    232 }
    233 
    234 
    235 QtDialog::AtomQtQuery::AtomQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
    236     Dialog::AtomQuery(_title),
    237     parent(_parent)
    238 {
    239   thisLayout = new QHBoxLayout();
    240   titleLabel = new QLabel(QString(getTitle().c_str()));
    241   inputBox = new QComboBox();
    242   inputBox->insertItem(-1, QString("no atom"));
    243   std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    244   for (std::vector<atom *>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter)
    245     inputBox->insertItem((*iter)->getNr(),QString::fromStdString((*iter)->getName()));
    246 
    247   parent->addLayout(thisLayout);
    248   thisLayout->addWidget(titleLabel);
    249   thisLayout->addWidget(inputBox);
    250 
    251   pipe = new AtomQtQueryPipe(&tmp,_dialog, inputBox);
    252   pipe->update(inputBox->currentIndex());
    253   connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
    254 }
    255 
    256 QtDialog::AtomQtQuery::~AtomQtQuery()
    257 {
    258   delete pipe;
    259 }
    260 
    261 bool QtDialog::AtomQtQuery::handle() {
    262   return true;
    263 }
    264 
    265 
    266 QtDialog::AtomsQtQuery::AtomsQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
    267     Dialog::AtomsQuery(_title),
    268     parent(_parent)
    269 {
    270   QHBoxLayout * thisHLayout = new QHBoxLayout();
    271   QVBoxLayout * thisV1Layout = new QVBoxLayout();
    272   QVBoxLayout * thisV2Layout = new QVBoxLayout();
    273 
    274   QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
    275   QLabel *inputLabel = new QLabel("Enter to add");
    276   QListWidget* inputList = new QListWidget();
    277   inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
    278   std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    279   for (std::vector<atom *>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter)
    280     inputBox->insertItem((*iter)->getNr(),QString((*iter)->getNr()));
    281 
    282   QLineEdit* inputBox = new QLineEdit();
    283   inputLabel->setBuddy(inputBox);
    284   titleLabel->setBuddy(inputList);
    285   QPushButton* AddButton = new QPushButton("Add");
    286   AddButton->setEnabled(false);
    287   QPushButton* RemoveButton = new QPushButton("Remove");
    288   RemoveButton->setEnabled(false);
    289 
    290   thisV1Layout->addWidget(titleLabel);
    291   thisV1Layout->addWidget(inputList);
    292   thisV2Layout->addWidget(inputLabel);
    293   thisV2Layout->addWidget(inputBox);
    294   thisV2Layout->addWidget(AddButton);
    295   thisV2Layout->addWidget(RemoveButton);
    296   parent->addLayout(thisHLayout);
    297   thisHLayout->addLayout(thisV1Layout);
    298   thisHLayout->addLayout(thisV2Layout);
    299 
    300   pipe = new AtomsQtQueryPipe(&tmp,_dialog,inputList);
    301   connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
    302   connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(add()));
    303   connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(remove()));
    304 }
    305 
    306 QtDialog::AtomsQtQuery::~AtomsQtQuery()
    307 {
    308   delete pipe;
    309 }
    310 
    311 bool QtDialog::AtomsQtQuery::handle() {
    312   return true;
    313 }
    314 
    315 QtDialog::IntQtQuery::IntQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
    316     Dialog::IntQuery(_title),
    317     parent(_parent)
    318 {
    319   thisLayout = new QHBoxLayout();
    320   titleLabel = new QLabel(QString(getTitle().c_str()));
    321   inputBox = new QSpinBox();
    322   inputBox->setValue(0);
    323   parent->addLayout(thisLayout);
    324   thisLayout->addWidget(titleLabel);
    325   thisLayout->addWidget(inputBox);
    326 
    327   pipe = new IntQtQueryPipe(&tmp,_dialog);
    328   pipe->update(inputBox->value());
    329   connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
    330 }
    331 
    332 QtDialog::IntQtQuery::~IntQtQuery()
    333 {
    334   delete pipe;
    335 }
    336 
    337 bool QtDialog::IntQtQuery::handle() {
    338   return true;
    339 }
    340 
    341 
    342 QtDialog::IntsQtQuery::IntsQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
    343     Dialog::IntsQuery(_title),
    344     parent(_parent)
    345 {
    346   QHBoxLayout * thisHLayout = new QHBoxLayout();
    347   QVBoxLayout * thisV1Layout = new QVBoxLayout();
    348   QVBoxLayout * thisV2Layout = new QVBoxLayout();
    349 
    350   QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
    351   QLabel *inputLabel = new QLabel("Enter to add");
    352   QListWidget* inputList = new QListWidget();
    353   inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
    354   QLineEdit* inputBox = new QLineEdit();
    355   inputLabel->setBuddy(inputBox);
    356   titleLabel->setBuddy(inputList);
    357   QPushButton* AddButton = new QPushButton("Add");
    358   AddButton->setEnabled(false);
    359   QPushButton* RemoveButton = new QPushButton("Remove");
    360   RemoveButton->setEnabled(false);
    361 
    362   thisV1Layout->addWidget(titleLabel);
    363   thisV1Layout->addWidget(inputList);
    364   thisV2Layout->addWidget(inputLabel);
    365   thisV2Layout->addWidget(inputBox);
    366   thisV2Layout->addWidget(AddButton);
    367   thisV2Layout->addWidget(RemoveButton);
    368   parent->addLayout(thisHLayout);
    369   thisHLayout->addLayout(thisV1Layout);
    370   thisHLayout->addLayout(thisV2Layout);
    371 
    372   pipe = new QtQueryListPipe<int>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
    373   connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
    374   connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
    375   connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
    376   connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));
    377 }
    378 
    379 QtDialog::IntsQtQuery::~IntsQtQuery()
    380 {
    381   delete pipe;
    382 }
    383 
    384 bool QtDialog::IntsQtQuery::handle() {
    385   return true;
    386 }
    387 
    388 
    389 QtDialog::DoubleQtQuery::DoubleQtQuery(string title,QBoxLayout *_parent,QtDialog *_dialog) :
    390     Dialog::DoubleQuery(title),
    391     parent(_parent)
    392 {
    393   thisLayout = new QHBoxLayout();
    394   titleLabel = new QLabel(QString(getTitle().c_str()));
    395   inputBox = new QDoubleSpinBox();
    396   inputBox->setValue(0);
    397   inputBox->setRange(-numeric_limits<double>::max(),numeric_limits<double>::max());
    398   inputBox->setDecimals(3);
    399   parent->addLayout(thisLayout);
    400   thisLayout->addWidget(titleLabel);
    401   thisLayout->addWidget(inputBox);
    402 
    403   pipe = new DoubleQtQueryPipe(&tmp,_dialog);
    404   pipe->update(inputBox->value());
    405   connect(inputBox,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
    406 }
    407 
    408 QtDialog::DoubleQtQuery::~DoubleQtQuery()
    409 {
    410   delete pipe;
    411 }
    412 
    413 bool QtDialog::DoubleQtQuery::handle() {
    414   return true;
    415 }
    416 
    417 
    418 QtDialog::DoublesQtQuery::DoublesQtQuery(string title,QBoxLayout *_parent,QtDialog *_dialog) :
    419     Dialog::DoublesQuery(title),
    420     parent(_parent)
    421 {
    422   QHBoxLayout * thisHLayout = new QHBoxLayout();
    423   QVBoxLayout * thisV1Layout = new QVBoxLayout();
    424   QVBoxLayout * thisV2Layout = new QVBoxLayout();
    425 
    426   QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
    427   QLabel *inputLabel = new QLabel("Enter to add");
    428   QListWidget* inputList = new QListWidget();
    429   inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
    430   QLineEdit* inputBox = new QLineEdit();
    431   inputLabel->setBuddy(inputBox);
    432   titleLabel->setBuddy(inputList);
    433   QPushButton* AddButton = new QPushButton("Add");
    434   AddButton->setEnabled(false);
    435   QPushButton* RemoveButton = new QPushButton("Remove");
    436   RemoveButton->setEnabled(false);
    437 
    438   thisV1Layout->addWidget(titleLabel);
    439   thisV1Layout->addWidget(inputList);
    440   thisV2Layout->addWidget(inputLabel);
    441   thisV2Layout->addWidget(inputBox);
    442   thisV2Layout->addWidget(AddButton);
    443   thisV2Layout->addWidget(RemoveButton);
    444   parent->addLayout(thisHLayout);
    445   thisHLayout->addLayout(thisV1Layout);
    446   thisHLayout->addLayout(thisV2Layout);
    447 
    448   pipe = new QtQueryListPipe<double>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
    449   connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
    450   connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
    451   connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
    452   connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
    453 
    454 QtDialog::DoublesQtQuery::~DoublesQtQuery()
    455 {
    456   delete pipe;
    457 }
    458 
    459 bool QtDialog::DoublesQtQuery::handle() {
    460   return true;
    461 }
    462 
    463 
    464 QtDialog::StringQtQuery::StringQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
    465     Dialog::StringQuery(_title),
    466     parent(_parent)
    467 {
    468   thisLayout = new QHBoxLayout();
    469   titleLabel = new QLabel(QString(getTitle().c_str()));
    470   inputBox = new QLineEdit();
    471   parent->addLayout(thisLayout);
    472   thisLayout->addWidget(titleLabel);
    473   thisLayout->addWidget(inputBox);
    474 
    475   pipe = new StringQtQueryPipe(&tmp,_dialog);
    476   pipe->update(inputBox->text());
    477   connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
    478 }
    479 
    480 QtDialog::StringQtQuery::~StringQtQuery()
    481 {
    482   delete pipe;
    483 }
    484 
    485 // All values besides the empty std::string are valid
    486 bool QtDialog::StringQtQuery::handle()
    487 {
    488   return tmp!="";
    489 }
    490 
    491 QtDialog::StringsQtQuery::StringsQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
    492     Dialog::StringsQuery(_title),
    493     parent(_parent)
    494 {
    495   QHBoxLayout * thisHLayout = new QHBoxLayout();
    496   QVBoxLayout * thisV1Layout = new QVBoxLayout();
    497   QVBoxLayout * thisV2Layout = new QVBoxLayout();
    498 
    499   QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
    500   QLabel *inputLabel = new QLabel("Enter to add");
    501   QListWidget* inputList = new QListWidget();
    502   inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
    503   QLineEdit* inputBox = new QLineEdit();
    504   inputLabel->setBuddy(inputBox);
    505   titleLabel->setBuddy(inputList);
    506   QPushButton* AddButton = new QPushButton("Add");
    507   AddButton->setEnabled(false);
    508   QPushButton* RemoveButton = new QPushButton("Remove");
    509   RemoveButton->setEnabled(false);
    510 
    511   thisV1Layout->addWidget(titleLabel);
    512   thisV1Layout->addWidget(inputList);
    513   thisV2Layout->addWidget(inputLabel);
    514   thisV2Layout->addWidget(inputBox);
    515   thisV2Layout->addWidget(AddButton);
    516   thisV2Layout->addWidget(RemoveButton);
    517   parent->addLayout(thisHLayout);
    518   thisHLayout->addLayout(thisV1Layout);
    519   thisHLayout->addLayout(thisV2Layout);
    520 
    521   pipe = new QtQueryListPipe<std::string>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
    522   connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
    523   connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
    524   connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
    525   connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
    526 
    527 QtDialog::StringsQtQuery::~StringsQtQuery()
    528 {
    529   delete pipe;
    530 }
    531 
    532 // All values besides the empty std::string are valid
    533 bool QtDialog::StringsQtQuery::handle()
    534 {
    535   // dissect by ","
    536   std::string::iterator olditer = temp.begin();
    537   for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
    538     if (*iter == ' ') {
    539       tmp.push_back(string(iter, olditer));
    540       olditer = iter;
    541     }
    542   }
    543   if (olditer != temp.begin())  // insert last part also
    544     tmp.push_back(string(olditer, temp.end()));
    545 
    546   return temp!="";
    547 }
    548 
    549 QtDialog::MoleculeQtQuery::MoleculeQtQuery(string _title, QBoxLayout *_parent,QtDialog *_dialog) :
    550     Dialog::MoleculeQuery(_title),
    551     parent(_parent)
    552 {
    553   thisLayout = new QHBoxLayout();
    554   titleLabel = new QLabel(QString(getTitle().c_str()));
    555   inputBox = new QComboBox();
    556   // add all molecules to the combo box
    557   vector<molecule*> molecules = World::getInstance().getAllMolecules();
    558   for(vector<molecule*>::iterator iter  = molecules.begin();
    559       iter != molecules.end();
    560       ++iter) {
    561     std::stringstream sstr;
    562     sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
    563     inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
    564   }
    565   parent->addLayout(thisLayout);
    566   thisLayout->addWidget(titleLabel);
    567   thisLayout->addWidget(inputBox);
    568 
    569   pipe = new MoleculeQtQueryPipe(&tmp,_dialog,inputBox);
    570   pipe->update(inputBox->currentIndex());
    571   connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
    572 }
    573 
    574 QtDialog::MoleculeQtQuery::~MoleculeQtQuery()
    575 {
    576   delete pipe;
    577 }
    578 
    579 // Handling is easy, since the GUI makes it impossible to select invalid values
    580 bool QtDialog::MoleculeQtQuery::handle()
    581 {
    582   return true;
    583 }
    584 
    585 QtDialog::MoleculesQtQuery::MoleculesQtQuery(string _title, QBoxLayout *_parent,QtDialog *_dialog) :
    586     Dialog::MoleculesQuery(_title),
    587     parent(_parent)
    588 {
    589   thisLayout = new QHBoxLayout();
    590   titleLabel = new QLabel(QString(getTitle().c_str()));
    591   inputBox = new QComboBox();
    592   // add all molecules to the combo box
    593   vector<molecule*> molecules = World::getInstance().getAllMolecules();
    594   for(vector<molecule*>::iterator iter  = molecules.begin();
    595       iter != molecules.end();
    596       ++iter) {
    597     std::stringstream sstr;
    598     sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
    599     inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
    600   }
    601   parent->addLayout(thisLayout);
    602   thisLayout->addWidget(titleLabel);
    603   thisLayout->addWidget(inputBox);
    604 
    605   pipe = new MoleculesQtQueryPipe(&tmp,_dialog,inputBox);
    606   pipe->update(inputBox->currentIndex());
    607   connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
    608 }
    609 
    610 QtDialog::MoleculesQtQuery::~MoleculesQtQuery()
    611 {
    612   delete pipe;
    613 }
    614 
    615 // Handling is easy, since the GUI makes it impossible to select invalid values
    616 bool QtDialog::MoleculesQtQuery::handle()
    617 {
    618   return true;
    619 }
    620 
    621 QtDialog::VectorQtQuery::VectorQtQuery(std::string title, bool _check,QBoxLayout *_parent,QtDialog *_dialog) :
    622     Dialog::VectorQuery(title,_check),
    623     parent(_parent)
    624 {
    625   mainLayout= new QHBoxLayout();
    626   titleLabel = new QLabel(QString(getTitle().c_str()));
    627   mainLayout->addWidget(titleLabel);
    628   subLayout = new QVBoxLayout();
    629   mainLayout->addLayout(subLayout);
    630   QComboBox* inputBox = new QComboBox();
    631   coordLayout = new QHBoxLayout();
    632   subLayout->addLayout(coordLayout);
    633   coordLabel = new QLabel(QString("x,y,z"));
    634   coordLayout->addWidget(coordLabel);
    635   coordInput = new QDoubleSpinBox();
    636 //  coordInput->setRange(0,M.at(i,i));
    637   coordInput->setDecimals(3);
    638   coordLayout->addWidget(coordInput);
    639   pipe = new VectorQtQueryPipe(&(tmp),_dialog,inputBox);
    640   //pipe->update(coordInput->value());
    641   connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
    642   parent->addLayout(mainLayout);
    643 }
    644 
    645 QtDialog::VectorQtQuery::~VectorQtQuery()
    646 {}
    647 
    648 bool QtDialog::VectorQtQuery::handle() {
    649   return true;
    650 }
    651 
    652 
    653 QtDialog::VectorsQtQuery::VectorsQtQuery(std::string title, bool _check,QBoxLayout *_parent,QtDialog *_dialog) :
    654     Dialog::VectorsQuery(title,_check),
    655     parent(_parent)
    656 {
    657   mainLayout= new QHBoxLayout();
    658   titleLabel = new QLabel(QString(getTitle().c_str()));
    659   mainLayout->addWidget(titleLabel);
    660   subLayout = new QVBoxLayout();
    661   mainLayout->addLayout(subLayout);
    662   QComboBox* inputBox = new QComboBox();
    663   coordLayout = new QHBoxLayout();
    664   subLayout->addLayout(coordLayout);
    665   coordLabel = new QLabel(QString("x,y,z"));
    666   coordLayout->addWidget(coordLabel);
    667   coordInput = new QDoubleSpinBox();
    668 //  coordInput->setRange(0,M.at(i,i));
    669   coordInput->setDecimals(3);
    670   coordLayout->addWidget(coordInput);
    671   pipe = new VectorsQtQueryPipe(&(tmp),_dialog,inputBox);
    672   //pipe->update(coordInput->value());
    673   connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
    674   parent->addLayout(mainLayout);
    675 }
    676 
    677 QtDialog::VectorsQtQuery::~VectorsQtQuery()
    678 {}
    679 
    680 bool QtDialog::VectorsQtQuery::handle() {
    681   return true;
    682 }
    683 
    684 
    685 QtDialog::ElementQtQuery::ElementQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
    686     Dialog::ElementQuery(_title),
    687     parent(_parent)
    688 {
    689   periodentafel *periode = World::getInstance().getPeriode();
    690   thisLayout = new QHBoxLayout();
    691   titleLabel = new QLabel(QString(getTitle().c_str()));
    692   inputBox = new QComboBox();
    693   for(periodentafel::const_iterator iter = periode->begin();
    694       iter!=periode->end();
    695       ++iter)
    696   {
    697     std::stringstream sstr;
    698     sstr << (*iter).first << "\t" << (*iter).second->getName();
    699     inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
    700   }
    701   parent->addLayout(thisLayout);
    702   thisLayout->addWidget(titleLabel);
    703   thisLayout->addWidget(inputBox);
    704 
    705   pipe = new ElementQtQueryPipe(&tmp,_dialog,inputBox);
    706   pipe->update(inputBox->currentIndex());
    707   connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
    708 }
    709 
    710 QtDialog::ElementQtQuery::~ElementQtQuery()
    711 {
    712   delete pipe;
    713 }
    714 
    715 bool QtDialog::ElementQtQuery::handle(){
    716   return true;
    717 }
    718 
    719 
    720 QtDialog::ElementsQtQuery::ElementsQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
    721     Dialog::ElementsQuery(_title),
    722     parent(_parent)
    723 {
    724   periodentafel *periode = World::getInstance().getPeriode();
    725   thisLayout = new QHBoxLayout();
    726   titleLabel = new QLabel(QString(getTitle().c_str()));
    727   inputBox = new QComboBox();
    728   for(periodentafel::const_iterator iter = periode->begin();
    729       iter!=periode->end();
    730       ++iter)
    731   {
    732     std::stringstream sstr;
    733     sstr << (*iter).first << "\t" << (*iter).second->getName();
    734     inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
    735   }
    736   parent->addLayout(thisLayout);
    737   thisLayout->addWidget(titleLabel);
    738   thisLayout->addWidget(inputBox);
    739 
    740   pipe = new ElementsQtQueryPipe(&tmp,_dialog,inputBox);
    741   pipe->update(inputBox->currentIndex());
    742   connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
    743 }
    744 
    745 QtDialog::ElementsQtQuery::~ElementsQtQuery()
    746 {
    747   delete pipe;
    748 }
    749 
    750 bool QtDialog::ElementsQtQuery::handle(){
    751   return true;
    752 }
    753 
    754 QtDialog::EmptyQtQuery::EmptyQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
    755     Dialog::EmptyQuery(_title),
    756     parent(_parent)
    757 {
    758   titleLabel = new QLabel(QString(getTitle().c_str()));
    759 
    760   parent->addLayout(thisLayout);
    761   thisLayout->addWidget(titleLabel);
    762 
    763   pipe = new EmptyQtQueryPipe(_dialog,titleLabel);
    764 }
    765 
    766 QtDialog::EmptyQtQuery::~EmptyQtQuery()
    767 {
    768   delete pipe;
    769 }
    770 
    771 bool QtDialog::EmptyQtQuery::handle(){
    772   return true;
    773 }
    774 
    775 
    776 QtDialog::BooleanQtQuery::BooleanQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
    777     Dialog::BooleanQuery(_title),
    778     parent(_parent)
    779 {
    780   titleLabel = new QLabel(QString(getTitle().c_str()),_dialog);
    781   booleanComboBox = new QComboBox(_dialog);
    782   booleanComboBox->insertItem(1, QString("true"));
    783   booleanComboBox->insertItem(0, QString("false"));
    784 
    785   parent->addLayout(thisLayout);
    786   thisLayout->addWidget(titleLabel);
    787   thisLayout->addWidget(booleanComboBox);
    788 
    789   pipe = new BooleanQtQueryPipe(&tmp,_dialog,booleanComboBox);
    790   connect(booleanComboBox, SIGNAL(currentIndexChanged()), pipe, SLOT(update()));
    791 }
    792 
    793 QtDialog::BooleanQtQuery::~BooleanQtQuery()
    794 {
    795   delete pipe;
    796 }
    797 
    798 bool QtDialog::BooleanQtQuery::handle(){
    799   return true;
    800 }
    801 
    802 
    803 QtDialog::FileQtQuery::FileQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
    804     Dialog::FileQuery(_title),
    805     parent(_parent)
    806 {
    807 
    808   filenameLineEdit = new QLineEdit(_dialog);
    809   filenameLineEdit->setText(QString());
    810   filenameLineEdit->setReadOnly(true);
    811 
    812   filenameLabel = new QLabel(QString("Input file:"));
    813   filenameLabel->setBuddy(filenameLineEdit);
    814 
    815   filedialogButton = new QPushButton("&Choose", _dialog);
    816 
    817   pipe = new FileQtQueryPipe(&tmp,_dialog,filenameLineEdit,filedialogButton);
    818 
    819   thisLayout = new QHBoxLayout();
    820   parent->addLayout(thisLayout);
    821   thisLayout->addWidget(filenameLabel);
    822   thisLayout->addWidget(filenameLineEdit);
    823   thisLayout->addWidget(filedialogButton);
    824 
    825   QObject::connect(filedialogButton,SIGNAL(clicked()),pipe,SLOT(showFileDialog()));
    826 }
    827 
    828 QtDialog::FileQtQuery::~FileQtQuery()
    829 {
    830   delete pipe;
    831 }
    832 
    833 bool QtDialog::FileQtQuery::handle(){
    834   return true;
    835 }
    836 
    837 /*************************** Plumbing *******************************/
    838 
    839 
    840 template<typename T> QtQueryListPipe<T>::QtQueryListPipe(std::vector<T> *_content, QtDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) :
    841   content(_content),
    842   dialog(_dialog),
    843   inputBox(_inputBox),
    844   inputList(_inputList),
    845   AddButton(_AddButton),
    846   RemoveButton(_RemoveButton)
    847 {}
    848 
    849 template<typename T> QtQueryListPipe<T>::~QtQueryListPipe()
    850 {}
    851 
    852 template<typename T> void QtQueryListPipe<T>::IntegerEntered(const QString&)
    853 {
    854   AddButton->setEnabled(true);
    855 }
    856 
    857 template<typename T> void QtQueryListPipe<T>::IntegerSelected()
    858 {
    859   if (inputList->selectedItems().empty())
    860     RemoveButton->setEnabled(false);
    861   else
    862     RemoveButton->setEnabled(true);
    863 }
    864 
    865 template<typename T> void QtQueryListPipe<T>::AddInteger() {
    866   // type-check
    867   std::string text = inputBox->text().toStdString();
    868   int number = 0;
    869   try {
    870     number = boost::lexical_cast<int>(text);
    871   } catch (boost::bad_lexical_cast&) {
    872     return;
    873   };
    874   // add item to both
    875   inputList->addItem(QString(number));
    876   AddValue(number);
    877 }
    878 
    879 template<typename T> void QtQueryListPipe<T>::AddValue(T item) {
    880   content->push_back(item);
    881 
    882   dialog->update();
    883 }
    884 
    885 template<typename T> void QtQueryListPipe<T>::RemoveInteger() {
    886   QList<QListWidgetItem *> items = inputList->selectedItems();
    887   for (QList<QListWidgetItem *>::iterator iter = items.begin(); !items.empty(); iter = items.begin()) {
    888     // obtain which position item has (by making it current item)
    889     inputList->setCurrentItem(*iter);
    890     // remove
    891     QtQueryListPipe<T>::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call
    892     inputList->removeItemWidget(*iter);
    893   }
    894 }
    895 
    896 template<typename T> void QtQueryListPipe<T>::RemoveRow(int row) {
    897   int counter = 0;
    898   typename std::vector<T>::iterator iter = content->begin();
    899   for (; iter != content->end(); ++iter)
    900     if (counter++ == row)
    901       break;
    902   if (iter != content->end())
    903       content->erase(iter);
    904 }
    905 
    906 
    907 StringQtQueryPipe::StringQtQueryPipe(string *_content, QtDialog *_dialog) :
    908   content(_content),
    909   dialog(_dialog)
    910 {}
    911 
    912 StringQtQueryPipe::~StringQtQueryPipe()
    913 {}
    914 
    915 void StringQtQueryPipe::update(const QString& newText) {
    916   content->assign(newText.toStdString());
    917   dialog->update();
    918 }
    919 
    920 IntQtQueryPipe::IntQtQueryPipe(int *_content, QtDialog *_dialog) :
    921   content(_content),
    922   dialog(_dialog)
    923 {}
    924 
    925 IntQtQueryPipe::~IntQtQueryPipe()
    926 {}
    927 
    928 void IntQtQueryPipe::update(int newInt) {
    929   (*content) = newInt;
    930   dialog->update();
    931 }
    932 
    933 DoubleQtQueryPipe::DoubleQtQueryPipe(double *_content, QtDialog *_dialog) :
    934   content(_content),
    935   dialog(_dialog)
    936 {}
    937 
    938 DoubleQtQueryPipe::~DoubleQtQueryPipe()
    939 {}
    940 
    941 void DoubleQtQueryPipe::update(double newDbl) {
    942   (*content) = newDbl;
    943   dialog->update();
    944 }
    945 
    946 VectorQtQueryPipe::VectorQtQueryPipe(Vector *_content, QtDialog *_dialog, QComboBox *_theBox) :
    947   content(_content),
    948   dialog(_dialog),
    949   theBox(_theBox)
    950 {}
    951 
    952 VectorQtQueryPipe::~VectorQtQueryPipe()
    953 {}
    954 
    955 void VectorQtQueryPipe::update() {
    956   dialog->update();
    957 }
    958 
    959 VectorsQtQueryPipe::VectorsQtQueryPipe(std::vector<Vector> *_content, QtDialog *_dialog, QComboBox *_theBox) :
    960   content(_content),
    961   dialog(_dialog),
    962   theBox(_theBox)
    963 {}
    964 
    965 VectorsQtQueryPipe::~VectorsQtQueryPipe()
    966 {}
    967 
    968 void VectorsQtQueryPipe::update() {
    969   dialog->update();
    970 }
    971 
    972 BoxQtQueryPipe::BoxQtQueryPipe(Box &_content, QtDialog *_dialog, QTableWidget *_inputTable) :
    973   content(_content),
    974   dialog(_dialog),
    975   inputTable(_inputTable)
    976 {
    977   tmpM = new Matrix();
    978   tmpM->zero();
    979 }
    980 
    981 BoxQtQueryPipe::~BoxQtQueryPipe()
    982 {
    983   delete tmpM;
    984 }
    985 
    986 void BoxQtQueryPipe::update(int row, int column)
    987 {
    988   tmpM->at(row, column) = inputTable->item(row, column)->text().toDouble();
    989   content.setM(*tmpM);
    990   dialog->update();
    991 }
    992 
    993 
    994 AtomQtQueryPipe::AtomQtQueryPipe(atom **_content, QtDialog *_dialog, QComboBox *_theBox) :
    995   content(_content),
    996   dialog(_dialog),
    997   theBox(_theBox)
    998 {}
    999 
    1000 AtomQtQueryPipe::~AtomQtQueryPipe()
    1001 {}
    1002 
    1003 void AtomQtQueryPipe::update(int newIndex) {
    1004   QVariant data = theBox->itemData(newIndex);
    1005   int idx = data.toInt();
    1006   (*content) = World::getInstance().getAtom(AtomById(idx));
    1007   dialog->update();
    1008 }
    1009 
    1010 
    1011 AtomsQtQueryPipe::AtomsQtQueryPipe(std::vector<atom *>*_content, QtDialog *_dialog, QListWidget *_theList) :
    1012   content(_content),
    1013   dialog(_dialog),
    1014   theList(_theList)
    1015 {}
    1016 
    1017 AtomsQtQueryPipe::~AtomsQtQueryPipe()
    1018 {}
    1019 
    1020 void AtomsQtQueryPipe::update() {
    1021   // clear target and put all atoms therein
    1022   (*content).clear();
    1023   for (std::set<atom *>::iterator iter = currentList.begin(); iter != currentList.end(); ++iter)
    1024     (*content).push_back(*iter);
    1025   dialog->update();
    1026 }
    1027 
    1028 void AtomsQtQueryPipe::add() {
    1029   QList<QListWidgetItem *> items = theList->selectedItems();
    1030   for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
    1031     const int index = (*iter)->text().toInt();
    1032     atom *Walker = World::getInstance().getAtom(AtomById(index));
    1033     if (Walker) {
    1034       (*content).push_back(Walker);
    1035       currentList.insert(Walker);
    1036       if (lookup.find(index) != lookup.end())
    1037         lookup.insert(pair<int, atom*>(index, Walker));
    1038     }
    1039   }
    1040   update();
    1041 }
    1042 
    1043 void AtomsQtQueryPipe::remove() {
    1044   QList<QListWidgetItem *> items = theList->selectedItems();
    1045   for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
    1046     const int index = (*iter)->text().toInt();
    1047     atom *Walker = World::getInstance().getAtom(AtomById(index));
    1048     if (Walker) {
    1049       currentList.erase(Walker);
    1050     }
    1051   }
    1052   update();
    1053 }
    1054 
    1055 
    1056 MoleculeQtQueryPipe::MoleculeQtQueryPipe(molecule **_content, QtDialog *_dialog, QComboBox *_theBox) :
    1057   content(_content),
    1058   dialog(_dialog),
    1059   theBox(_theBox)
    1060 {}
    1061 
    1062 MoleculeQtQueryPipe::~MoleculeQtQueryPipe()
    1063 {}
    1064 
    1065 void MoleculeQtQueryPipe::update(int newIndex) {
    1066   QVariant data = theBox->itemData(newIndex);
    1067   int idx = data.toInt();
    1068   (*content) = World::getInstance().getMolecule(MoleculeById(idx));
    1069   dialog->update();
    1070 }
    1071 
    1072 
    1073 MoleculesQtQueryPipe::MoleculesQtQueryPipe(std::vector<molecule *>*_content, QtDialog *_dialog, QComboBox *_theBox) :
    1074   content(_content),
    1075   dialog(_dialog),
    1076   theBox(_theBox)
    1077 {}
    1078 
    1079 MoleculesQtQueryPipe::~MoleculesQtQueryPipe()
    1080 {}
    1081 
    1082 void MoleculesQtQueryPipe::update(int newIndex) {
    1083   QVariant data = theBox->itemData(newIndex);
    1084   int idx = data.toInt();
    1085   molecule *mol = World::getInstance().getMolecule(MoleculeById(idx));
    1086   if (mol)
    1087     (*content).push_back(mol);
    1088   dialog->update();
    1089 }
    1090 
    1091 ElementQtQueryPipe::ElementQtQueryPipe(const element **_content, QtDialog *_dialog, QComboBox *_theBox) :
    1092   content(_content),
    1093   dialog(_dialog),
    1094   theBox(_theBox)
    1095 {}
    1096 
    1097 ElementQtQueryPipe::~ElementQtQueryPipe()
    1098 {}
    1099 
    1100 void ElementQtQueryPipe::update(int newIndex) {
    1101   QVariant data = theBox->itemData(newIndex);
    1102   int idx = data.toInt();
    1103   *content = World::getInstance().getPeriode()->FindElement(idx);
    1104   dialog->update();
    1105 }
    1106 
    1107 ElementsQtQueryPipe::ElementsQtQueryPipe(std::vector<const element *>*_content, QtDialog *_dialog, QComboBox *_theBox) :
    1108   content(_content),
    1109   dialog(_dialog),
    1110   theBox(_theBox)
    1111 {}
    1112 
    1113 ElementsQtQueryPipe::~ElementsQtQueryPipe()
    1114 {}
    1115 
    1116 void ElementsQtQueryPipe::update(int newIndex) {
    1117   QVariant data = theBox->itemData(newIndex);
    1118   int idx = data.toInt();
    1119   const element *elemental = World::getInstance().getPeriode()->FindElement(idx);
    1120   if(elemental)
    1121     (*content).push_back(elemental);
    1122   dialog->update();
    1123 }
    1124 
    1125 EmptyQtQueryPipe::EmptyQtQueryPipe(QtDialog *_dialog, QLabel *_textLabel) :
    1126   dialog(_dialog),
    1127   textLabel(_textLabel)
    1128 {}
    1129 
    1130 EmptyQtQueryPipe::~EmptyQtQueryPipe()
    1131 {}
    1132 
    1133 void EmptyQtQueryPipe::update() {
    1134   dialog->update();
    1135 }
    1136 
    1137 BooleanQtQueryPipe::BooleanQtQueryPipe(const bool *_content, QtDialog *_dialog, QComboBox *_booleanComboBox) :
    1138   content(_content),
    1139   dialog(_dialog),
    1140   booleanComboBox(_booleanComboBox)
    1141 {}
    1142 
    1143 BooleanQtQueryPipe::~BooleanQtQueryPipe()
    1144 {}
    1145 
    1146 void BooleanQtQueryPipe::update() {
    1147   dialog->update();
    1148 }
    1149 
    1150 FileQtQueryPipe::FileQtQueryPipe(boost::filesystem::path *_content, QtDialog *_dialog, QLineEdit *_filenameLineEdit, QPushButton *_filedialogButton) :
    1151   content(_content),
    1152   dialog(_dialog),
    1153   filenameLineEdit(_filenameLineEdit),
    1154   filedialogButton(_filedialogButton)
    1155 {
    1156   theFileDialog = NULL;
    1157 }
    1158 
    1159 FileQtQueryPipe::~FileQtQueryPipe()
    1160 {
    1161   if (theFileDialog != NULL)
    1162     delete theFileDialog;
    1163 }
    1164 
    1165 void FileQtQueryPipe::update() {
    1166   QStringList ListOfFilenames = theFileDialog->selectedFiles();
    1167   std::cout << "Selected File is " << ListOfFilenames.at(0).toStdString() << std::endl;
    1168   (*content) = ListOfFilenames.at(0).toStdString();
    1169   filenameLineEdit->setText(QString::fromStdString((*content).string()));
    1170   dialog->update();
    1171 }
    1172 
    1173 void FileQtQueryPipe::showFileDialog() {
    1174   filedialogButton->setFlat(true);
    1175   if (theFileDialog == NULL) {
    1176     theFileDialog = new QFileDialog(NULL, tr("Open input file"), QString(), tr("ParallelCarParrinello (*.conf);;MassivelyParallelQuantumChemistry (*.mpqc);;ParticleDataBase (*.pdb);;XYZ (*.xyz)"));
    1177     theFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
    1178     theFileDialog->setFileMode(QFileDialog::ExistingFile);
    1179     theFileDialog->setViewMode(QFileDialog::List);
    1180   }
    1181   theFileDialog->exec();
    1182 
    1183   update();
    1184   filedialogButton->setFlat(false);
    1185 }
    1186 
    1187 
    1188 
     170/*************************** Pipe Infrastructure ************************/
     171/*       ---> shifted to folder Pipe                                    */
     172/************************************************************************/
  • src/UIElements/Qt4/QtDialog.hpp

    r57a6ea1 r8df74d  
    206206      QBoxLayout *thisLayout;
    207207      QLabel *titleLabel;
    208       QComboBox *inputBox;
     208      QLabel *inputLabel;
     209      QListWidget *inputList;
    209210
    210211      AtomsQtQueryPipe *pipe;
  • src/UIElements/TextUI/TextDialog.cpp

    r57a6ea1 r8df74d  
    2020#include "Helpers/MemDebug.hpp"
    2121
    22 #include <iostream>
    23 
    24 #include <Descriptors/AtomDescriptor.hpp>
    25 #include <Descriptors/AtomIdDescriptor.hpp>
    26 #include <Descriptors/MoleculeDescriptor.hpp>
    27 #include <Descriptors/MoleculeIdDescriptor.hpp>
    28 #include <boost/lexical_cast.hpp>
    2922#include "TextUI/TextDialog.hpp"
    30 
    31 #include "World.hpp"
    32 #include "periodentafel.hpp"
    33 #include "Helpers/Log.hpp"
    34 #include "Helpers/Verbose.hpp"
    35 
    36 #include "atom.hpp"
    37 #include "element.hpp"
    38 #include "molecule.hpp"
    39 #include "LinearAlgebra/Vector.hpp"
    40 #include "LinearAlgebra/Matrix.hpp"
    41 #include "Box.hpp"
    42 
    43 #include <boost/lexical_cast.hpp>
    44 #include <boost/filesystem.hpp>
    4523
    4624using namespace std;
     
    131109
    132110/************************** Query Infrastructure ************************/
     111/*       ---> shifted to folder Query                                   */
     112/************************************************************************/
    133113
    134 TextDialog::EmptyTextQuery::EmptyTextQuery(string title, std::string _description) :
    135     Dialog::EmptyQuery(title,_description)
    136 {}
    137 
    138 TextDialog::EmptyTextQuery::~EmptyTextQuery() {}
    139 
    140 bool TextDialog::EmptyTextQuery::handle() {
    141   cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
    142   return true;
    143 }
    144 
    145 TextDialog::IntTextQuery::IntTextQuery(string title, std::string _description) :
    146     Dialog::IntQuery(title,_description)
    147 {}
    148 
    149 TextDialog::IntTextQuery::~IntTextQuery() {}
    150 
    151 bool TextDialog::IntTextQuery::handle() {
    152   bool badInput = false;
    153   do{
    154     badInput = false;
    155     Log() << Verbose(0) << getTitle();
    156     cin >> tmp;
    157     if(cin.fail()){
    158       badInput=true;
    159       cin.clear();
    160       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    161       Log() << Verbose(0) << "Input was not a number!" << endl;
    162     }
    163   } while(badInput);
    164   // clear the input buffer of anything still in the line
    165   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    166   return true;
    167 }
    168 
    169 TextDialog::IntsTextQuery::IntsTextQuery(string title, std::string _description) :
    170     Dialog::IntsQuery(title,_description)
    171 {}
    172 
    173 TextDialog::IntsTextQuery::~IntsTextQuery() {}
    174 
    175 bool TextDialog::IntsTextQuery::handle() {
    176   Log() << Verbose(0) << getTitle();
    177   std::string line;
    178   getline(cin,line);
    179   // dissect by " "
    180   std::string::iterator olditer = line.begin();
    181   for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
    182     if (*iter == ' ') {
    183       std::istringstream stream(string(iter, olditer));
    184       stream >> temp;
    185       tmp.push_back(temp);
    186       olditer = iter;
    187     }
    188   }
    189   if (olditer != line.begin()) { // insert last part also
    190     std::istringstream stream(string(olditer, line.end()));
    191     stream >> temp;
    192     tmp.push_back(temp);
    193   }
    194 
    195   return true;
    196 }
    197 
    198 TextDialog::BooleanTextQuery::BooleanTextQuery(string title, std::string _description) :
    199     Dialog::BooleanQuery(title,_description)
    200 {}
    201 
    202 TextDialog::BooleanTextQuery::~BooleanTextQuery() {}
    203 
    204 bool TextDialog::BooleanTextQuery::handle() {
    205   bool badInput = false;
    206   char input = ' ';
    207   do{
    208     badInput = false;
    209     Log() << Verbose(0) << getTitle();
    210     cin >> input;
    211     if ((input == 'y' ) || (input == 'Y')) {
    212       tmp = true;
    213     } else if ((input == 'n' ) || (input == 'N')) {
    214       tmp = false;
    215     } else {
    216       badInput=true;
    217       cin.clear();
    218       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    219       Log() << Verbose(0) << "Input was not of [yYnN]!" << endl;
    220     }
    221   } while(badInput);
    222   // clear the input buffer of anything still in the line
    223   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    224   return true;
    225 }
    226 
    227 TextDialog::StringTextQuery::StringTextQuery(string title, std::string _description) :
    228     Dialog::StringQuery(title,_description)
    229 {}
    230 
    231 TextDialog::StringTextQuery::~StringTextQuery() {}
    232 
    233 bool TextDialog::StringTextQuery::handle() {
    234   Log() << Verbose(0) << getTitle();
    235   getline(cin,tmp);
    236   return true;
    237 }
    238 
    239 TextDialog::StringsTextQuery::StringsTextQuery(string title, std::string _description) :
    240     Dialog::StringsQuery(title,_description)
    241 {}
    242 
    243 TextDialog::StringsTextQuery::~StringsTextQuery() {}
    244 
    245 bool TextDialog::StringsTextQuery::handle() {
    246   Log() << Verbose(0) << getTitle();
    247   getline(cin,temp);
    248   // dissect by " "
    249   std::string::iterator olditer = temp.begin();
    250   for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
    251     if (*iter == ' ') {
    252       tmp.push_back(string(iter, olditer));
    253       olditer = iter;
    254     }
    255   }
    256   if (olditer != temp.begin())  // insert last part also
    257     tmp.push_back(string(olditer, temp.end()));
    258 
    259   return true;
    260 }
    261 
    262 TextDialog::DoubleTextQuery::DoubleTextQuery(string title, std::string _description) :
    263     Dialog::DoubleQuery(title,_description)
    264 {}
    265 
    266 TextDialog::DoubleTextQuery::~DoubleTextQuery() {}
    267 
    268 bool TextDialog::DoubleTextQuery::handle() {
    269   bool badInput = false;
    270   do{
    271     badInput = false;
    272     Log() << Verbose(0) << getTitle();
    273     cin >> tmp;
    274     if(cin.fail()){
    275       badInput = true;
    276       cin.clear();
    277       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    278       Log() << Verbose(0) << "Input was not a number!" << endl;
    279     }
    280   }while(badInput);
    281   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    282   return true;
    283 }
    284 
    285 
    286 TextDialog::DoublesTextQuery::DoublesTextQuery(string title, std::string _description) :
    287     Dialog::DoublesQuery(title,_description)
    288 {}
    289 
    290 TextDialog::DoublesTextQuery::~DoublesTextQuery() {}
    291 
    292 bool TextDialog::DoublesTextQuery::handle() {
    293   Log() << Verbose(0) << getTitle();
    294   std::string line;
    295   getline(cin,line);
    296   // dissect by " "
    297   std::string::iterator olditer = line.begin();
    298   for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
    299     if (*iter == ' ') {
    300       std::istringstream stream(string(iter, olditer));
    301       stream >> temp;
    302       tmp.push_back(temp);
    303       olditer = iter;
    304     }
    305   }
    306   if (olditer != line.begin()) { // insert last part also
    307     std::istringstream stream(string(olditer, line.end()));
    308     stream >> temp;
    309     tmp.push_back(temp);
    310   }
    311 
    312   return true;
    313 }
    314 
    315 TextDialog::AtomTextQuery::AtomTextQuery(string title, std::string _description) :
    316     Dialog::AtomQuery(title,_description)
    317 {}
    318 
    319 TextDialog::AtomTextQuery::~AtomTextQuery() {}
    320 
    321 bool TextDialog::AtomTextQuery::handle() {
    322   int idxOfAtom=-1;
    323   bool badInput = false;
    324   do{
    325     badInput = false;
    326     Log() << Verbose(0) << getTitle();
    327     cin >> idxOfAtom;
    328     if(cin.fail()){
    329       badInput = true;
    330       cin.clear();
    331       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    332       Log() << Verbose(0) << "Input was not a number!" << endl;
    333       continue;
    334     }
    335 
    336     tmp = World::getInstance().getAtom(AtomById(idxOfAtom));
    337     if(!tmp && idxOfAtom!=-1){
    338       Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
    339       badInput = true;
    340     }
    341 
    342   } while(badInput);
    343   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    344   return (idxOfAtom!=-1);
    345 }
    346 
    347 
    348 TextDialog::AtomsTextQuery::AtomsTextQuery(string title, std::string _description) :
    349     Dialog::AtomsQuery(title,_description)
    350 {}
    351 
    352 TextDialog::AtomsTextQuery::~AtomsTextQuery() {}
    353 
    354 bool TextDialog::AtomsTextQuery::handle() {
    355   int idxOfAtom=-1;
    356   Log() << Verbose(0) << getTitle();
    357   std::string line;
    358   getline(cin,line);
    359   // dissect by " "
    360   std::string::iterator olditer = line.begin();
    361   for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
    362     if (*iter == ' ') {
    363       std::istringstream stream(string(iter, olditer));
    364       stream >> idxOfAtom;
    365       temp = World::getInstance().getAtom(AtomById(idxOfAtom));
    366       if(!temp && idxOfAtom!=-1){
    367         Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
    368         break;
    369       }
    370       tmp.push_back(temp);
    371       olditer = iter;
    372     }
    373   }
    374   if (olditer != line.begin()) { // insert last part also
    375     std::istringstream stream(string(olditer, line.end()));
    376     stream >> idxOfAtom;
    377     temp = World::getInstance().getAtom(AtomById(idxOfAtom));
    378     if(!temp && idxOfAtom!=-1) {
    379       Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
    380       tmp.push_back(temp);
    381     }
    382   }
    383 
    384   return (idxOfAtom!=-1);
    385 }
    386 
    387 TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, std::string _description) :
    388     Dialog::MoleculeQuery(title,_description)
    389 {}
    390 
    391 TextDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
    392 
    393 bool TextDialog::MoleculeTextQuery::handle() {
    394   int idxOfMol=0;
    395   bool badInput = false;
    396   do{
    397     badInput = false;
    398     Log() << Verbose(0) << getTitle();
    399     cin >> idxOfMol;
    400     if(cin.fail()){
    401       badInput = true;
    402       cin.clear();
    403       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    404       Log() << Verbose(0) << "Input was not a number!" << endl;
    405       continue;
    406     }
    407 
    408     tmp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
    409     if(!tmp && idxOfMol!=-1){
    410       Log() << Verbose(0) << "Invalid Molecule Index" << endl;
    411       badInput = true;
    412     }
    413 
    414   } while(badInput);
    415   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    416   return (idxOfMol!=-1);
    417 }
    418 
    419 
    420 TextDialog::MoleculesTextQuery::MoleculesTextQuery(string title, std::string _description) :
    421     Dialog::MoleculesQuery(title,_description)
    422 {}
    423 
    424 TextDialog::MoleculesTextQuery::~MoleculesTextQuery() {}
    425 
    426 bool TextDialog::MoleculesTextQuery::handle() {
    427   int idxOfMol=-1;
    428   Log() << Verbose(0) << getTitle();
    429   std::string line;
    430   getline(cin,line);
    431   // dissect by " "
    432   std::string::iterator olditer = line.begin();
    433   for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
    434     if (*iter == ' ') {
    435       std::istringstream stream(string(iter, olditer));
    436       stream >> idxOfMol;
    437       temp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
    438       if(!temp && idxOfMol!=-1){
    439         Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl;
    440         break;
    441       }
    442       tmp.push_back(temp);
    443       olditer = iter;
    444     }
    445   }
    446   if (olditer != line.begin()) { // insert last part also
    447     std::istringstream stream(string(olditer, line.end()));
    448     stream >> idxOfMol;
    449     temp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
    450     if(!temp && idxOfMol!=-1){
    451       Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl;
    452       tmp.push_back(temp);
    453     }
    454   }
    455 
    456   return (idxOfMol!=-1);
    457 }
    458 
    459 TextDialog::VectorTextQuery::VectorTextQuery(std::string title, bool _check, std::string _description) :
    460     Dialog::VectorQuery(title,_check,_description)
    461 {}
    462 
    463 TextDialog::VectorTextQuery::~VectorTextQuery()
    464 {}
    465 
    466 bool TextDialog::VectorTextQuery::handle() {
    467   std::cout << getTitle();
    468   const Matrix &M = World::getInstance().getDomain().getM();
    469   char coords[3] = {'x', 'y', 'z'};
    470   for (int i=0;i<3;i++)
    471     std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
    472 
    473   std::string line;
    474   getline(cin,line);
    475 
    476   // dissect by ","
    477   double coord = 0.;
    478   int counter = 0;
    479   std::string::iterator olditer = line.begin();
    480   for(string::iterator iter = line.begin(); (iter != line.end()) && (counter != 3); ++iter) {
    481     if (*iter == ',') {
    482       std::istringstream stream(string(iter, olditer));
    483       stream >> coord;
    484       tmp[counter++] = coord;
    485       olditer = iter;
    486     }
    487   }
    488   if ((olditer != line.begin()) && (counter != 3)) { // insert last part also
    489     std::istringstream stream(string(olditer, line.end()));
    490     stream >> coord;
    491     tmp[counter++] = coord;
    492   }
    493 
    494   // check vector
    495   return World::getInstance().getDomain().isInside(tmp);
    496 }
    497 
    498 TextDialog::VectorsTextQuery::VectorsTextQuery(std::string title, bool _check, std::string _description) :
    499     Dialog::VectorsQuery(title,_check,_description)
    500 {}
    501 
    502 TextDialog::VectorsTextQuery::~VectorsTextQuery()
    503 {}
    504 
    505 bool TextDialog::VectorsTextQuery::handle() {
    506   std::cout << getTitle();
    507   char coords[3] = {'x', 'y', 'z'};
    508   const Matrix &M = World::getInstance().getDomain().getM();
    509   for (int i=0;i<3;i++)
    510     std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
    511 
    512   std::string line;
    513   getline(cin,line);
    514 
    515   // dissect by ","
    516   double coord = 0.;
    517   std::string::iterator olditerspace = line.begin();
    518   std::string::iterator olditercomma = line.begin();
    519   int counter = 0;
    520   for(string::iterator vectoriter = line.begin(); vectoriter != line.end(); ++vectoriter) {
    521     if (*vectoriter == ',')
    522       counter++;
    523     if ((*vectoriter == ' ') && (counter == 2)) {
    524       counter = 0;
    525       for(string::iterator componentiter = olditerspace; (componentiter != vectoriter) && (counter !=3); ++componentiter) {
    526         if (*componentiter == ',') {
    527           std::istringstream stream(string(componentiter, olditercomma));
    528           stream >> coord;
    529           temp[counter++] = coord;
    530           olditercomma = componentiter;
    531         }
    532       }
    533       if ((olditercomma != line.begin()) && (counter != 3)) { // insert last part also
    534         std::istringstream stream(string(olditercomma, vectoriter));
    535         stream >> coord;
    536         temp[counter++] = coord;
    537       }
    538       if (World::getInstance().getDomain().isInside(temp))
    539         tmp.push_back(temp);
    540       olditerspace = vectoriter;
    541     }
    542   }
    543 
    544   return true;
    545 }
    546 
    547 TextDialog::BoxTextQuery::BoxTextQuery(std::string title, std::string _description) :
    548     Dialog::BoxQuery(title,_description)
    549 {}
    550 
    551 TextDialog::BoxTextQuery::~BoxTextQuery()
    552 {}
    553 
    554 bool TextDialog::BoxTextQuery::handle() {
    555   Log() << Verbose(0) << getTitle();
    556 
    557   double temp[6];
    558   std::string coords[6] = {"xx","yx","yy", "zx", "zy", "zz"};
    559   for (int i=0;i<6;i++) {
    560     Log() << Verbose(0) << coords[i] << ": ";
    561     cin >> temp[i];
    562   }
    563   Matrix M;
    564   M.set(0,0, temp[0]);
    565   M.set(0,1, temp[1]);
    566   M.set(0,2, temp[2]);
    567   M.set(1,0, temp[1]);
    568   M.set(1,1, temp[3]);
    569   M.set(1,2, temp[4]);
    570   M.set(2,0, temp[2]);
    571   M.set(2,1, temp[4]);
    572   M.set(2,2, temp[5]);
    573   tmp.setM(M);
    574   return true;
    575 }
    576 
    577 TextDialog::ElementTextQuery::ElementTextQuery(std::string title, std::string _description) :
    578     Dialog::ElementQuery(title,_description)
    579 {}
    580 
    581 TextDialog::ElementTextQuery::~ElementTextQuery()
    582 {}
    583 
    584 bool TextDialog::ElementTextQuery::handle() {
    585   bool badInput=false;
    586   bool aborted = false;
    587   const element * temp = NULL;
    588   do{
    589     badInput = false;
    590     Log() << Verbose(0) << getTitle();
    591 
    592     // try to read as Atomic number
    593     int Z;
    594     cin >> Z;
    595     if(!cin.fail()){
    596       if(Z==-1){
    597         aborted = true;
    598       }
    599       else{
    600         temp = World::getInstance().getPeriode()->FindElement(Z);
    601         if(!temp){
    602           Log() << Verbose(0) << "No element with this atomic number!" << endl;
    603           badInput = true;
    604         }
    605       }
    606       continue;
    607     }
    608     else{
    609       cin.clear();
    610     }
    611 
    612     // Try to read as shorthand
    613     // the last buffer content was not removed, so we read the
    614     // same thing again, this time as a std::string
    615     std::string shorthand;
    616     cin >> shorthand;
    617     if(!cin.fail()){
    618       if(shorthand.empty()){
    619         aborted = true;
    620       }
    621       else{
    622         temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
    623         if(!temp){
    624           Log() << Verbose(0) << "No element with this shorthand!" << endl;
    625           badInput = true;
    626         }
    627       }
    628     }
    629     else{
    630       Log() << Verbose(0) << "Could not read input. Try Again." << endl;
    631       cin.clear();
    632       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    633       badInput = true;
    634     }
    635 
    636   }while(badInput);
    637   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    638   return !aborted;
    639 }
    640 
    641 TextDialog::ElementsTextQuery::ElementsTextQuery(std::string title, std::string _description) :
    642     Dialog::ElementsQuery(title,_description)
    643 {}
    644 
    645 TextDialog::ElementsTextQuery::~ElementsTextQuery()
    646 {}
    647 
    648 bool TextDialog::ElementsTextQuery::handle() {
    649   std::string shorthand;
    650   int Z=-1;
    651   Log() << Verbose(0) << getTitle();
    652   std::string line;
    653   getline(cin,line);
    654   // dissect by " "
    655   std::string::iterator olditer = line.begin();
    656   for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
    657     if (*iter == ' ') {
    658       std::istringstream stream(string(iter, olditer));
    659       stream >> shorthand;
    660       try {
    661         Z = lexical_cast<int>(shorthand);
    662         temp = World::getInstance().getPeriode()->FindElement(Z);
    663       } catch (bad_lexical_cast) {
    664         temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
    665       };
    666       if(!temp && Z!=-1){
    667         Log() << Verbose(0) << "Invalid Element" << shorthand << endl;
    668         break;
    669       }
    670       tmp.push_back(temp);
    671       olditer = iter;
    672     }
    673   }
    674   if (olditer != line.begin()) { // insert last part also
    675     std::istringstream stream(string(olditer, line.end()));
    676     stream >> shorthand;
    677     try {
    678       Z = lexical_cast<int>(shorthand);
    679       temp = World::getInstance().getPeriode()->FindElement(Z);
    680     } catch (bad_lexical_cast) {
    681       temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
    682     };
    683     if(!temp && Z!=-1) {
    684       Log() << Verbose(0) << "Invalid Element" << shorthand << endl;
    685       tmp.push_back(temp);
    686     }
    687   }
    688 
    689   return (Z!=-1);
    690 }
    691 
    692 TextDialog::FileTextQuery::FileTextQuery(string title, std::string _description) :
    693     Dialog::FileQuery(title,_description)
    694 {}
    695 
    696 TextDialog::FileTextQuery::~FileTextQuery() {}
    697 
    698 bool TextDialog::FileTextQuery::handle() {
    699   Log() << Verbose(0) << getTitle();
    700   std::string tempstring;
    701   getline(cin,tempstring);
    702   tmp = tempstring;
    703   return true;
    704 }
    705 
Note: See TracChangeset for help on using the changeset viewer.