/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * Dialog.cpp * * Created on: Jan 5, 2010 * Author: crueger */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Dialog.hpp" #include "CodePatterns/Log.hpp" #include "CodePatterns/Verbose.hpp" #include "Parameters/ParameterExceptions.hpp" class Atom; class element; class RealSpaceMatrix; class molecule; class Vector; using namespace std; Dialog::Dialog() { } Dialog::~Dialog() { list::iterator iter; for(iter=queries.begin();iter!=queries.end();iter++){ delete (*iter); } } void Dialog::registerQuery(Query *query){ queries.push_back(query); } bool Dialog::display(){ handleAll(); if(checkAll()){ setAll(); return true; } else{ return false; } } void Dialog::handleAll(){ list::iterator iter; for(iter=queries.begin(); iter!=queries.end(); iter++){ try{ (*iter)->handle(); }catch(...){ // if any query fails (is canceled), we can end the handling process ELOG(1, "The following query failed: " << (**iter).getTitle() << "."); break; } } } bool Dialog::checkAll(){ list::iterator iter; bool retval = true; for(iter=queries.begin(); iter!=queries.end(); iter++){ retval &= (*iter)->isValid(); // if any query fails (is canceled), we can end the handling process if(!retval) { ELOG(1, "The following query failed: " << (**iter).getTitle() << "."); break; } } return retval; } void Dialog::setAll(){ list::iterator iter; for(iter=queries.begin(); iter!=queries.end(); iter++) { try { (*iter)->setResult(); } catch (ParameterException &e) { if( const std::string *name=boost::get_error_info(e) ) ELOG(1, "The following parameter value is not valid: " << *name << "."); break; } } } bool Dialog::hasQueries(){ return queries.size(); } /*template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryEmpty(param, token, description); }*/ template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryBoolean(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryInt(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryInts(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryUnsignedInt(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryUnsignedInts(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryDouble(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryDoubles(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryString(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryStrings(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryAtom(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryAtoms(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryMolecule(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryMolecules(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryVector(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryVectors(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryRealSpaceMatrix(param, token, description); } template <> void Dialog::query(Parameter ¶m, const char *token, std::string description) { queryElement(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryElements(param, token, description); } template <> void Dialog::query< boost::filesystem::path >(Parameter ¶m, const char *token, std::string description) { queryFile(param, token, description); } template <> void Dialog::query< std::vector >(Parameter > ¶m, const char *token, std::string description) { queryFiles(param, token, description); } template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter ¶m, const char *token, std::string description) { queryRandomNumberDistribution_Parameters(param, token, description); } /************************** Query Infrastructure ************************/ /* ---> shifted to folder Query */ /************************************************************************/