/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2011 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * InputAction.cpp * * Created on: May 8, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "CodePatterns/Log.hpp" #include "molecule.hpp" #include "MoleculeListClass.hpp" #include "Parser/FormatParserStorage.hpp" #include "CodePatterns/Verbose.hpp" #include "World.hpp" #include #include #include #include "Actions/WorldAction/InputAction.hpp" using namespace MoleCuilder; // and construct the stuff #include "InputAction.def" #include "Action_impl_pre.hpp" /** =========== define the function ====================== */ Action::state_ptr WorldInputAction::performCall() { // MoleculeListClass *molecules = World::getInstance().getMolecules(); // molecule *mol = NULL; boost::filesystem::ifstream test; FormatParserStorage &parsers = FormatParserStorage::getInstance(); // obtain information getParametersfromValueStorage(); LOG(0, "Config file given " << params.filename << "."); // using the filename as prefix for all parsers std::string FilenameSuffix; std::string FilenamePrefix; if (params.filename.has_filename()) { // get suffix #if BOOST_VERSION >= 104600 FilenameSuffix = params.filename.extension().string().substr(1); // remove the prefixed "." FilenamePrefix = params.filename.stem().string(); #else FilenameSuffix = params.filename.extension().substr(1); // remove the prefixed "." FilenamePrefix = params.filename.stem(); #endif LOG(1, "Setting config file name prefix to " << FilenamePrefix << "."); parsers.SetOutputPrefixForAll(FilenamePrefix); } else { ELOG(1, "Input file does not have a suffix, cannot recognize format."); return Action::failure; } // parsing file if present if (!boost::filesystem::exists(params.filename)) { LOG(1, "Specified config file " << params.filename << " not found."); // DONT FAIL: it's just empty and we use the name. // return Action::failure; // nonetheless, add to output formats parsers.setOutputFormat( parsers.getTypeFromSuffix(FilenameSuffix) ); } else { LOG(1, "Specified config file found, parsing ... "); // parse the file test.open(params.filename); parsers.load(test, FilenameSuffix); parsers.setOutputFormat( parsers.getTypeFromSuffix(FilenameSuffix) ); test.close(); // set file name of last molecule MoleculeList::const_iterator iter = World::getInstance().getMolecules()->ListOfMolecules.end(); iter--; (*iter)->SetNameFromFilename(FilenamePrefix.c_str()); LOG(0, "Chemical formula is " << (*iter)->getFormula()); } return Action::success; } Action::state_ptr WorldInputAction::performUndo(Action::state_ptr _state) { // ParserLoadXyzState *state = assert_cast(_state.get()); return Action::failure; // string newName = state->mol->getName(); // state->mol->setName(state->lastName); // // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); } Action::state_ptr WorldInputAction::performRedo(Action::state_ptr _state){ return Action::failure; } bool WorldInputAction::canUndo() { return false; } bool WorldInputAction::shouldUndo() { return false; } /** =========== end of function ====================== */