source: src/Actions/MapOfActions.cpp@ c1012b

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 Candidate_v1.7.0 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
Last change on this file since c1012b was 2a6a2c, checked in by Frederik Heber <heber@…>, 15 years ago

Removed MapOfActions::populateActions().

  • Action prototypes are now instantiated within the object file, as they register automatically with the ActionRegistry and can henceforth be used.
    • new define INSTANCE with a sort of unique name.
    • instance is const and hence not to be used directly.
    • MapOfActions::populateActions() removed in CommandLineWindow, QtMainWindow and TextWindow classes.
    • NOTE: this hopefully remedies the problem of forgetting to add new Actions.
  • Registry does not cleanup() in its destructor, but function may be called from derived class if desired.
    • All Action prototypes are destroyed at end of program and hence cleanup() would cause memory corruption.
  • Property mode set to 100644
File size: 51.0 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[97ebf8]8/*
9 * MapOfActions.cpp
10 *
11 * Created on: 10.05.2010
12 * Author: heber
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[112b09]20#include "Helpers/MemDebug.hpp"
21
[97ebf8]22using namespace std;
23
24#include "Actions/MapOfActions.hpp"
[d02e07]25#include "Descriptors/AtomIdDescriptor.hpp"
26#include "Descriptors/MoleculeIdDescriptor.hpp"
[97ebf8]27#include "Helpers/Assert.hpp"
[4e145c]28#include "Patterns/Singleton_impl.hpp"
[97ebf8]29
[a8188d]30#include <boost/filesystem.hpp>
[0286bc]31#include <boost/lexical_cast.hpp>
32#include <boost/optional.hpp>
33#include <boost/program_options.hpp>
34
[986ed3]35#include <iostream>
36
[ab9a27]37#include "atom.hpp"
[d02e07]38#include "Box.hpp"
[97ebf8]39#include "CommandLineParser.hpp"
[ab9a27]40#include "element.hpp"
[952f38]41#include "Helpers/Log.hpp"
[57f243]42#include "LinearAlgebra/Matrix.hpp"
[ab9a27]43#include "molecule.hpp"
[d02e07]44#include "periodentafel.hpp"
[72f611]45#include "LinearAlgebra/BoxVector.hpp"
[57f243]46#include "LinearAlgebra/Vector.hpp"
[952f38]47#include "Helpers/Verbose.hpp"
[97ebf8]48
[326bbe]49#include "Actions/ActionRegistry.hpp"
[0286bc]50#include "Actions/Values.hpp"
51
52void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
53{
54 VectorValue VV;
[b540f3]55 std::vector<std::string> components;
56
57 // split comma-separated values
58 if (values.size() != 1) {
59 cerr << "Not one vector but " << components.size() << " given " << endl;
60 throw boost::program_options::validation_error("Unequal to one vector given");
61 }
62 std::string argument(values.at(0));
63 std::string::iterator Aiter = argument.begin();
64 std::string::iterator Biter = argument.begin();
65 for (; Aiter != argument.end(); ++Aiter) {
66 if (*Aiter == ',') {
67 components.push_back(string(Biter,Aiter));
68 do {
69 Aiter++;
70 } while (*Aiter == ' ' || *Aiter == '\t');
71 Biter = Aiter;
72 }
73 }
74 components.push_back(string(Biter,argument.end()));
75
76 if (components.size() != 3) {
77 cerr << "Specified vector does not have three components but " << components.size() << endl;
[0286bc]78 throw boost::program_options::validation_error("Specified vector does not have three components");
79 }
[b540f3]80 VV.x = boost::lexical_cast<double>(components.at(0));
81 VV.y = boost::lexical_cast<double>(components.at(1));
82 VV.z = boost::lexical_cast<double>(components.at(2));
[0286bc]83 v = boost::any(VectorValue(VV));
84}
85
86void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
87{
88 BoxValue BV;
[b540f3]89 std::vector<std::string> components;
90
91 // split comma-separated values
92 if (values.size() != 1) {
93 cerr << "Not one vector but " << components.size() << " given " << endl;
94 throw boost::program_options::validation_error("Unequal to one vector given");
95 }
96 std::string argument(values.at(0));
97 std::string::iterator Aiter = argument.begin();
98 std::string::iterator Biter = argument.begin();
99 for (; Aiter != argument.end(); ++Aiter) {
100 if (*Aiter == ',') {
101 components.push_back(string(Biter,Aiter));
102 do {
103 Aiter++;
104 } while (*Aiter == ' ' || *Aiter == '\t');
105 Biter = Aiter;
106 }
107 }
108 components.push_back(string(Biter,argument.end()));
109
110 if (components.size() != 6) {
111 cerr << "Specified vector does not have three components but " << components.size() << endl;
[0286bc]112 throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
113 }
[b540f3]114 BV.xx = boost::lexical_cast<double>(components.at(0));
[8467df]115 BV.yx = boost::lexical_cast<double>(components.at(1));
116 BV.yy = boost::lexical_cast<double>(components.at(2));
117 BV.zx = boost::lexical_cast<double>(components.at(3));
118 BV.zy = boost::lexical_cast<double>(components.at(4));
[b540f3]119 BV.zz = boost::lexical_cast<double>(components.at(5));
[0286bc]120 v = boost::any(BoxValue(BV));
121}
122
[bd2390]123void validate(boost::any& v, const std::vector<std::string>& values, boost::filesystem::path *, int)
124{
125 boost::filesystem::path filename;
126 std::vector<std::string> components;
127
128 std::cout << "boost::filesystem::path validator used." << std::endl;
129
130 // split comma-separated values
131 if (values.size() != 1) {
132 cerr << "Not one file but " << components.size() << " given " << endl;
133 throw boost::program_options::validation_error("Unequal to one file given");
134 }
135 filename = values.at(0);
136 v = boost::any(boost::filesystem::path(filename));
137}
138
[97ebf8]139/** Constructor of class MapOfActions.
140 *
141 */
142MapOfActions::MapOfActions()
143{
144 // initialise lookup map
145 CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
146 CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
147 CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
148 CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
149
150 // keys for actions
151 DescriptionMap["add-atom"] = "add atom of specified element";
152 DescriptionMap["bond-table"] = "setting name of the bond length table file";
153 DescriptionMap["bond-file"] = "name of the bond file";
154 DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
155 DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
156 DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
157 DescriptionMap["center-in-box"] = "center all atoms in the domain";
158 DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
159 DescriptionMap["change-element"] = "change the element of an atom";
160 DescriptionMap["change-molname"] = "change the name of a molecule";
[e212ff]161 DescriptionMap["clear-atom-selection"] = "clear the atom selection";
[2218d94]162 DescriptionMap["clear-molecule-selection"] = "clear the molecule selection";
[c449d9]163 DescriptionMap["construct-bondgraph"] = "construct the bond graph of the selected atoms";
[97ebf8]164 DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
[1a7fd2]165 DescriptionMap["copy-molecule"] = "copies a molecule with all atoms and bonds";
[97ebf8]166 DescriptionMap["default-molname"] = "set the default name of new molecules";
167 DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
168 DescriptionMap["element-db"] = "setting the path where the element databases can be found";
169 DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
[eee966]170 DescriptionMap["fill-molecule"] = "fill around molecules' surface with a filler molecule";
171 DescriptionMap["fill-void"] = "fill void space of box with a filler molecule";
[97ebf8]172 DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
[7230be]173 DescriptionMap["help"] = "help screen";
[4f7f34e]174 DescriptionMap["input"] = "specify input files";
[97ebf8]175 DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
176 DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
[b9c847]177 DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
178 DescriptionMap["output"] = "write output files";
179 DescriptionMap["set-output"] = "specify output formats";
[e65de8]180 DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements";
[97ebf8]181 DescriptionMap["parse-xyz"] = "parse xyz file into World";
[e65de8]182 DescriptionMap["point-correlation"] = "pair correlation analysis between element and point";
[97ebf8]183 DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
[446bc1]184 DescriptionMap["redo"] = "redo last action";
[97ebf8]185 DescriptionMap["remove-atom"] = "remove a specified atom";
186 DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
[22c44bf]187 DescriptionMap["rotate-origin"] = "rotate selected atoms by a specific angle around origin";
[eaf4ae]188 DescriptionMap["rotate-self"] = "rotates molecules by a specific angle around own center of gravity";
[97ebf8]189 DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
190 DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
191 DescriptionMap["save-bonds"] = "name of the bonds file to write to";
192 DescriptionMap["save-temperature"] = "name of the temperature file to write to";
[326bbe]193 DescriptionMap["SaveXyz"] = "save world as xyz file";
[2a92ff]194 DescriptionMap["scale-box"] = "scale box and atomic positions inside";
[4e4c4d]195 DescriptionMap["select-all-atoms"] = "select all atoms";
196 DescriptionMap["select-all-molecules"] = "select all molecules";
[51769f]197 DescriptionMap["select-atom-by-element"] = "select an atom by element";
[4e4c4d]198 DescriptionMap["select-atom-by-id"] = "select an atom by index";
[1cc87e]199 DescriptionMap["select-atoms-inside-cuboid"] = "select all atoms inside a cuboid";
200 DescriptionMap["select-atoms-inside-sphere"] = "select all atoms inside a sphere";
[4e4c4d]201 DescriptionMap["select-molecule-by-id"] = "select a molecule by index";
[51769f]202 DescriptionMap["select-molecule-by-formula"] = "select a molecule by chemical formula";
[481e92]203 DescriptionMap["select-molecule-of-atom"] = "select a molecule to which a given atom belongs";
[770287]204 DescriptionMap["select-molecules-atoms"] = "select all atoms of a molecule";
[b9c847]205 DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
206 DescriptionMap["set-output"] = "specify output formats";
[6866aa]207 DescriptionMap["subgraph-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
[e65de8]208 DescriptionMap["surface-correlation"] = "pair correlation analysis between element and surface";
[97ebf8]209 DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
[34c338]210 DescriptionMap["translate-atoms"] = "translate all selected atoms by given vector";
[446bc1]211 DescriptionMap["undo"] = "undo last action";
[4e4c4d]212 DescriptionMap["unselect-all-atoms"] = "unselect all atoms";
213 DescriptionMap["unselect-all-molecules"] = "unselect all molecules";
[51769f]214 DescriptionMap["unselect-atom-by-element"] = "unselect an atom by element";
[4e4c4d]215 DescriptionMap["unselect-atom-by-id"] = "unselect an atom by index";
[1cc87e]216 DescriptionMap["unselect-atoms-inside-cuboid"] = "unselect all atoms inside a cuboid";
217 DescriptionMap["unselect-atoms-inside-sphere"] = "unselect all atoms inside a sphere";
[51769f]218 DescriptionMap["unselect-molecule-by-formula"] = "unselect a molecule by chemical formula";
[4e4c4d]219 DescriptionMap["unselect-molecule-by-id"] = "unselect a molecule by index";
[75a80f]220 DescriptionMap["unselect-molecule-of-atom"] = "unselect a molecule to which a given atom belongs";
[381c5f]221 DescriptionMap["unselect-molecules-atoms"] = "unselect all atoms of a molecule";
[97ebf8]222 DescriptionMap["verbose"] = "set verbosity level";
223 DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
224 DescriptionMap["version"] = "show version";
[7230be]225 DescriptionMap["warranty"] = "statement concerning warranty of the software";
[97ebf8]226 // keys for values
[31fb1d]227 DescriptionMap["angle-x"] = "angle of a rotation around x axis";
228 DescriptionMap["angle-y"] = "angle of a rotation around y axis";
229 DescriptionMap["angle-z"] = "angle of a rotation around z axis";
[97ebf8]230 DescriptionMap["bin-output-file"] = "name of the bin output file";
231 DescriptionMap["bin-end"] = "start of the last bin";
232 DescriptionMap["bin-start"] = "start of the first bin";
233 DescriptionMap["bin-width"] = "width of the bins";
[f6bd32]234 DescriptionMap["convex-file"] = "filename of the non-convex envelope";
[97ebf8]235 DescriptionMap["distance"] = "distance in space";
236 DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
[0286bc]237 DescriptionMap["DoRotate"] = "whether to rotate or just report angles";
[58bbd3]238 DescriptionMap["element"] = "single element";
239 DescriptionMap["elements"] = "set of elements";
[a02462]240 DescriptionMap["end-step"] = "last or end step";
241 DescriptionMap["id-mapping"] = "whether the identity shall be used in mapping atoms onto atoms or some closest distance measure shall be used";
[97ebf8]242 DescriptionMap["input"] = "name of input file";
243 DescriptionMap["length"] = "length in space";
244 DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
245 DescriptionMap["MaxDistance"] = "maximum distance in space";
246 DescriptionMap["molecule-by-id"] = "index of a molecule";
[f6bd32]247 DescriptionMap["nonconvex-file"] = "filename of the non-convex envelope";
[e4b5de]248 DescriptionMap["order"] = "order of a discretization, dissection, ...";
[97ebf8]249 DescriptionMap["output-file"] = "name of the output file";
250 DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
251 DescriptionMap["position"] = "position in R^3 space";
[a02462]252 DescriptionMap["start-step"] = "first or start step";
[97ebf8]253
254 // short forms for the actions
255 ShortFormMap["add-atom"] = "a";
256 ShortFormMap["bond-table"] = "g";
257 ShortFormMap["bond-file"] = "A";
258 ShortFormMap["boundary"] = "c";
[6ca1f7]259 ShortFormMap["change-box"] = "B";
[97ebf8]260 ShortFormMap["center-edge"] = "O";
261 ShortFormMap["center-in-box"] = "b";
262 ShortFormMap["change-element"] = "E";
[b9c847]263// ShortFormMap["convex-envelope"] = "x";
[97ebf8]264 ShortFormMap["default-molname"] = "X";
265 ShortFormMap["depth-first-search"] = "D";
266 ShortFormMap["element-db"] = "e";
267 ShortFormMap["fastparsing"] = "n";
268 ShortFormMap["fill-molecule"] = "F";
269 ShortFormMap["fragment-mol"] = "f";
270 ShortFormMap["help"] = "h";
271 ShortFormMap["input"] = "i";
272 ShortFormMap["linear-interpolate"] = "L";
273 ShortFormMap["nonconvex-envelope"] = "N";
[cd8e55]274// ShortFormMap["output"] = "o";
[e65de8]275// ShortFormMap["pair-correlation"] = "C";
[97ebf8]276 ShortFormMap["parse-xyz"] = "p";
277 ShortFormMap["remove-atom"] = "r";
278 ShortFormMap["repeat-box"] = "d";
279 ShortFormMap["rotate-to-pas"] = "m";
280 ShortFormMap["save-adjacency"] = "J";
281 ShortFormMap["save-bonds"] = "j";
282 ShortFormMap["save-temperature"] = "S";
283 ShortFormMap["scale-box"] = "s";
284 ShortFormMap["set-basis"] = "M";
[b9c847]285 ShortFormMap["set-output"] = "o";
[6866aa]286 ShortFormMap["subgraph-dissect"] = "I";
[48ab70a]287 ShortFormMap["suspend-in-water"] = "u";
[34c338]288 ShortFormMap["translate-atoms"] = "t";
[6670a97]289 ShortFormMap["verbose"] = "v";
[97ebf8]290 ShortFormMap["verlet-integrate"] = "P";
[6670a97]291 ShortFormMap["version"] = "V";
[97ebf8]292
293 // value types for the actions
[e5c0a1]294 TypeMap["add-atom"] = &typeid(const element);
[ab9a27]295 TypeMap["bond-file"] = &typeid(std::string);
296 TypeMap["bond-table"] = &typeid(std::string);
297 TypeMap["boundary"] = &typeid(VectorValue);
298 TypeMap["center-in-box"] = &typeid(BoxValue);
299 TypeMap["change-box"] = &typeid(BoxValue);
[e5c0a1]300 TypeMap["change-element"] = &typeid(const element);
[ab9a27]301 TypeMap["change-molname"] = &typeid(std::string);
[e212ff]302 TypeMap["clear-atom-selection"] = &typeid(void);
[2218d94]303 TypeMap["clear-molecule-selection"] = &typeid(void);
[c449d9]304 TypeMap["construct-bondgraph"] = &typeid(void);
[1d9b7d2]305 TypeMap["convex-envelope"] = &typeid(void);
[1a7fd2]306 TypeMap["copy-molecule"] = &typeid(molecule);
[ab9a27]307 TypeMap["default-molname"] = &typeid(std::string);
308 TypeMap["depth-first-search"] = &typeid(double);
309 TypeMap["element-db"] = &typeid(std::string);
310 TypeMap["fastparsing"] = &typeid(bool);
311 TypeMap["fill-molecule"] = &typeid(std::string);
[eee966]312 TypeMap["fill-void"] = &typeid(std::string);
[ab9a27]313 TypeMap["fragment-mol"] = &typeid(std::string);
[6f5dfe]314 TypeMap["input"] = &typeid(boost::filesystem::path);
[ab9a27]315 TypeMap["linear-interpolate"] = &typeid(std::string);
316 TypeMap["molecular-volume"] = &typeid(molecule);
[1d9b7d2]317 TypeMap["nonconvex-envelope"] = &typeid(double);
[ab9a27]318 TypeMap["output"] = &typeid(void);
319 TypeMap["parse-xyz"] = &typeid(std::string);
[e65de8]320 TypeMap["pair-correlation"] = &typeid(void);
321 TypeMap["point-correlation"] = &typeid(void);
[b76394]322 TypeMap["principal-axis-system"] = &typeid(void);
[446bc1]323 TypeMap["redo"] = &typeid(void);
[120088]324 TypeMap["remove-atom"] = &typeid(void);
[ab9a27]325 TypeMap["repeat-box"] = &typeid(VectorValue);
[eaf4ae]326 TypeMap["rotate-origin"] = &typeid(double);
327 TypeMap["rotate-self"] = &typeid(double);
328 TypeMap["rotate-to-pas"] = &typeid(VectorValue);
[ab9a27]329 TypeMap["save-adjacency"] = &typeid(std::string);
330 TypeMap["save-bonds"] = &typeid(std::string);
331 TypeMap["save-temperature"] = &typeid(std::string);
332 TypeMap["scale-box"] = &typeid(VectorValue);
[770287]333 TypeMap["select-all-atoms"] = &typeid(void);
334 TypeMap["select-all-molecules"] = &typeid(void);
[51769f]335 TypeMap["select-atom-by-element"] = &typeid(const element);
[770287]336 TypeMap["select-atom-by-id"] = &typeid(atom);
[1cc87e]337 TypeMap["select-atoms-inside-cuboid"] = &typeid(VectorValue);
338 TypeMap["select-atoms-inside-sphere"] = &typeid(double);
[51769f]339 TypeMap["select-molecule-by-formula"] = &typeid(std::string);
[770287]340 TypeMap["select-molecule-by-id"] = &typeid(molecule);
[481e92]341 TypeMap["select-molecule-of-atom"] = &typeid(atom);
[770287]342 TypeMap["select-molecules-atoms"] = &typeid(molecule);
[ab9a27]343 TypeMap["set-basis"] = &typeid(std::string);
344 TypeMap["set-output"] = &typeid(std::vector<std::string>);
345 TypeMap["subgraph-dissect"] = &typeid(void);
[e65de8]346 TypeMap["surface-correlation"] = &typeid(void);
[ab9a27]347 TypeMap["suspend-in-water"] = &typeid(double);
[34c338]348 TypeMap["translate-atoms"] = &typeid(VectorValue);
[446bc1]349 TypeMap["undo"] = &typeid(void);
[770287]350 TypeMap["unselect-all-atoms"] = &typeid(void);
351 TypeMap["unselect-all-molecules"] = &typeid(void);
[51769f]352 TypeMap["unselect-atom-by-element"] = &typeid(const element);
[770287]353 TypeMap["unselect-atom-by-id"] = &typeid(atom);
[1cc87e]354 TypeMap["unselect-atoms-inside-cuboid"] = &typeid(VectorValue);
355 TypeMap["unselect-atoms-inside-sphere"] = &typeid(double);
[51769f]356 TypeMap["unselect-molecule-by-formula"] = &typeid(std::string);
[770287]357 TypeMap["unselect-molecule-by-id"] = &typeid(molecule);
[75a80f]358 TypeMap["unselect-molecule-of-atom"] = &typeid(atom);
[381c5f]359 TypeMap["unselect-molecules-atoms"] = &typeid(molecule);
[ab9a27]360 TypeMap["verlet-integrate"] = &typeid(std::string);
361 TypeMap["verbose"] = &typeid(int);
[e30ce8]362
[97ebf8]363 // value types for the values
[31fb1d]364 TypeMap["angle-x"] = &typeid(double);
365 TypeMap["angle-y"] = &typeid(double);
366 TypeMap["angle-z"] = &typeid(double);
[ab9a27]367 TypeMap["bin-output-file"] = &typeid(std::string);
368 TypeMap["bin-end"] = &typeid(double);
369 TypeMap["bin-start"] = &typeid(double);
370 TypeMap["bin-width"] = &typeid(double);
371 TypeMap["convex-file"] = &typeid(std::string);
372 TypeMap["distance"] = &typeid(double);
373 TypeMap["distances"] = &typeid(VectorValue);
374 TypeMap["DoRotate"] = &typeid(bool);
[e5c0a1]375 TypeMap["element"] = &typeid(const element);
376 TypeMap["elements"] = &typeid(std::vector<const element *>);
[ab9a27]377 TypeMap["end-step"] = &typeid(int);
378 TypeMap["id-mapping"] = &typeid(bool);
379 TypeMap["length"] = &typeid(double);
380 TypeMap["lengths"] = &typeid(VectorValue);
381 TypeMap["MaxDistance"] = &typeid(double);
[e65de8]382 TypeMap["molecule-by-id"] = &typeid(molecule);
[ab9a27]383 TypeMap["nonconvex-file"] = &typeid(std::string);
384 TypeMap["order"] = &typeid(int);
385 TypeMap["output-file"] = &typeid(std::string);
386 TypeMap["periodic"] = &typeid(bool);
387 TypeMap["position"] = &typeid(VectorValue);
388 TypeMap["start-step"] = &typeid(int);
389
[0b0a20]390 TypeEnumMap[&typeid(void)] = None;
391 TypeEnumMap[&typeid(bool)] = Boolean;
[ab9a27]392 TypeEnumMap[&typeid(int)] = Integer;
[bd2390]393 TypeEnumMap[&typeid(boost::filesystem::path)] = File;
[0b0a20]394 TypeEnumMap[&typeid(std::vector<int>)] = ListOfIntegers;
[ab9a27]395 TypeEnumMap[&typeid(double)] = Double;
[0b0a20]396 TypeEnumMap[&typeid(std::vector<double>)] = ListOfDoubles;
[ab9a27]397 TypeEnumMap[&typeid(std::string)] = String;
[0b0a20]398 TypeEnumMap[&typeid(std::vector<std::string>)] = ListOfStrings;
399 TypeEnumMap[&typeid(VectorValue)] = Vector;
[39b639]400 TypeEnumMap[&typeid(std::vector<VectorValue>)] = ListOfVectors;
[0b0a20]401 TypeEnumMap[&typeid(BoxValue)] = Box;
402 TypeEnumMap[&typeid(molecule)] = Molecule;
403 TypeEnumMap[&typeid(std::vector<molecule *>)] = ListOfMolecules;
[ab9a27]404 TypeEnumMap[&typeid(atom)] = Atom;
[0b0a20]405 TypeEnumMap[&typeid(std::vector<atom *>)] = ListOfAtoms;
[e5c0a1]406 TypeEnumMap[&typeid(const element)] = Element;
407 TypeEnumMap[&typeid(std::vector<const element *>)] = ListOfElements;
[97ebf8]408
[e30ce8]409 // default values for any action that needs one (always string!)
[a8188d]410 CurrentValueMap["bin-width"] = "0.5";
411 CurrentValueMap["fastparsing"] = "0";
412 CurrentValueMap["periodic"] = "0";
[e30ce8]413
[326bbe]414 // put action into each menu category
[b2531f]415 MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis");
[5b5c4d]416 MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Atoms");
417 MenuDescription["command"] = pair<std::string,std::string>("Configuration", "configuration options");
[b2531f]418 MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation");
[5b5c4d]419 MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Molecules");
420 MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Input/Output");
421 MenuDescription["selection"] = pair<std::string,std::string>("Select atoms/molecules", "Selection");
422 MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselation");
423 MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Globals");
[b2531f]424
[326bbe]425 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") );
426 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") );
[e65de8]427 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "point-correlation") );
428 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "surface-correlation") );
[326bbe]429 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") );
[e30ce8]430
[326bbe]431 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") );
432 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") );
433 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") );
[34c338]434 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "translate-atoms") );
[326bbe]435
436 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") );
437 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") );
438 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") );
[7230be]439 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "help") );
[326bbe]440 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") );
441 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") );
[7230be]442 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "warranty") );
[326bbe]443
[c449d9]444 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "construct-bondgraph") );
[326bbe]445 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") );
446 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") );
447 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") );
448
449 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") );
[1a7fd2]450 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "copy-molecule") );
[326bbe]451 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") );
452 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") );
[eee966]453 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-void") );
[326bbe]454 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") );
[eaf4ae]455 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-origin") );
456 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-self") );
[326bbe]457 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") );
458 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") );
459 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") );
460 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") );
461 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") );
462 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") );
463
464 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") );
465 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") );
466
[e212ff]467 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "clear-atom-selection") );
[2218d94]468 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "clear-molecule-selection") );
[e212ff]469 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-all-atoms") );
470 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-all-molecules") );
[51769f]471 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-atom-by-element") );
[5b5c4d]472 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-atom-by-id") );
[1cc87e]473 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-atoms-inside-cuboid") );
474 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-atoms-inside-sphere") );
[5b5c4d]475 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-molecule-by-id") );
[51769f]476 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-molecule-by-formula") );
[481e92]477 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-molecule-of-atom") );
[770287]478 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-molecules-atoms") );
[e212ff]479 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-all-atoms") );
480 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-all-molecules") );
[51769f]481 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-atom-by-element") );
[5b5c4d]482 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-atom-by-id") );
[1cc87e]483 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-atoms-inside-cuboid") );
484 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-atoms-inside-sphere") );
[51769f]485 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-molecule-by-formula") );
[5b5c4d]486 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-molecule-by-id") );
[75a80f]487 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-molecule-of-atom") );
[381c5f]488 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-molecules-atoms") );
[5b5c4d]489
[326bbe]490 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") );
491 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") );
492
493 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") );
494 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") );
495 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") );
496 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") );
497 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") );
498 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") );
499 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") );
500 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") );
501 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") );
502 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") );
503 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") );
[b9c847]504 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") );
[326bbe]505
506 // put actions into command line category
[f0a3ec]507 generic.insert("add-atom");
[f4bd01]508 generic.insert("bond-file");
[39af9f]509 generic.insert("bond-table");
[116f37]510 generic.insert("boundary");
[97ebf8]511// generic.insert("bound-in-box");
[584a2a]512 generic.insert("center-edge");
[158c594]513 generic.insert("center-in-box");
[6ca1f7]514 generic.insert("change-box");
[97ebf8]515// generic.insert("change-molname");
[e212ff]516 generic.insert("change-element");
517 generic.insert("clear-atom-selection");
[2218d94]518 generic.insert("clear-molecule-selection");
[c449d9]519 generic.insert("construct-bondgraph");
[f6bd32]520 generic.insert("convex-envelope");
[1a7fd2]521 generic.insert("copy-molecule");
[387b36]522 generic.insert("default-molname");
[8540f0]523 generic.insert("depth-first-search");
[198494]524 generic.insert("element-db");
[f821d6]525 generic.insert("fastparsing");
[0286bc]526 generic.insert("fill-molecule");
[eee966]527 generic.insert("fill-void");
[e4b5de]528 generic.insert("fragment-mol");
[97ebf8]529 generic.insert("help");
[4f7f34e]530 generic.insert("input");
531 generic.insert("linear-interpolate");
[97ebf8]532// generic.insert("molecular-volume");
[980dd6]533 generic.insert("nonconvex-envelope");
[4f7f34e]534 generic.insert("output");
[58bbd3]535 generic.insert("pair-correlation");
[a1e929]536 generic.insert("parse-xyz");
[e65de8]537 generic.insert("point-correlation");
[97ebf8]538// generic.insert("principal-axis-system");
[446bc1]539 generic.insert("redo");
[d55743e]540 generic.insert("remove-atom");
[0286bc]541 generic.insert("repeat-box");
[eaf4ae]542 generic.insert("rotate-origin");
543 generic.insert("rotate-self");
[2b5574]544 generic.insert("rotate-to-pas");
[77de81]545 generic.insert("save-adjacency");
546 generic.insert("save-bonds");
[a307af]547 generic.insert("save-temperature");
[2a92ff]548 generic.insert("scale-box");
[e472eab]549 generic.insert("select-all-atoms");
550 generic.insert("select-all-molecules");
[51769f]551 generic.insert("select-atom-by-element");
[e472eab]552 generic.insert("select-atom-by-id");
[1cc87e]553 generic.insert("select-atoms-inside-cuboid");
554 generic.insert("select-atoms-inside-sphere");
[e472eab]555 generic.insert("select-molecule-by-id");
[51769f]556 generic.insert("select-molecule-by-formula");
[481e92]557 generic.insert("select-molecule-of-atom");
[770287]558 generic.insert("select-molecules-atoms");
[bdaacd]559 generic.insert("set-basis");
[b9c847]560 generic.insert("set-output");
[6866aa]561 generic.insert("subgraph-dissect");
[e65de8]562 generic.insert("surface-correlation");
[48ab70a]563 generic.insert("suspend-in-water");
[34c338]564 generic.insert("translate-atoms");
[446bc1]565 generic.insert("undo");
[e472eab]566 generic.insert("unselect-all-atoms");
567 generic.insert("unselect-all-molecules");
[51769f]568 generic.insert("unselect-atom-by-element");
[e472eab]569 generic.insert("unselect-atom-by-id");
[1cc87e]570 generic.insert("unselect-atoms-inside-cuboid");
571 generic.insert("unselect-atoms-inside-sphere");
[51769f]572 generic.insert("unselect-molecule-by-formula");
[e472eab]573 generic.insert("unselect-molecule-by-id");
[75a80f]574 generic.insert("unselect-molecule-of-atom");
[381c5f]575 generic.insert("unselect-molecules-atoms");
[97ebf8]576 generic.insert("verbose");
[aacce8]577 generic.insert("verlet-integrate");
[97ebf8]578 generic.insert("version");
[7230be]579 generic.insert("warranty");
[97ebf8]580
581 // positional arguments
[f6bd32]582 generic.insert("input");
[0286bc]583
584 // hidden arguments
[31fb1d]585 hidden.insert("angle-x");
586 hidden.insert("angle-y");
587 hidden.insert("angle-z");
[533838]588 hidden.insert("bin-end");
589 hidden.insert("bin-output-file");
590 hidden.insert("bin-start");
591 hidden.insert("bin-width");
592 hidden.insert("convex-file");
593 hidden.insert("distance");
594 hidden.insert("DoRotate");
595 hidden.insert("distances");
596 hidden.insert("element");
597 hidden.insert("elements");
598 hidden.insert("end-step");
599 hidden.insert("id-mapping");
600 hidden.insert("lengths");
601 hidden.insert("MaxDistance");
[e65de8]602 hidden.insert("molecule-by-id");
[533838]603 hidden.insert("nonconvex-file");
604 hidden.insert("order");
605 hidden.insert("output-file");
606 hidden.insert("periodic");
607 hidden.insert("position");
608 hidden.insert("start-step");
[97ebf8]609}
610
611/** Destructor of class MapOfActions.
612 *
613 */
614MapOfActions::~MapOfActions()
615{
616 DescriptionMap.clear();
617}
618
[03c902]619bool MapOfActions::isCurrentValuePresent(const char *name) const
620{
[a8188d]621 return (CurrentValueMap.find(name) != CurrentValueMap.end());
[03c902]622}
623
[d02e07]624void MapOfActions::queryCurrentValue(const char * name, class atom * &_T)
625{
626 int atomID = -1;
[4e145c]627 if (typeid( atom ) == *TypeMap[name]) {
[a8188d]628 if (CurrentValueMap.find(name) == CurrentValueMap.end())
[4e145c]629 throw MissingValueException(__FILE__, __LINE__);
[a8188d]630 atomID = lexical_cast<int>(CurrentValueMap[name].c_str());
631 CurrentValueMap.erase(name);
[4e145c]632 } else
[d02e07]633 throw IllegalTypeException(__FILE__,__LINE__);
634 _T = World::getInstance().getAtom(AtomById(atomID));
635}
636
[e5c0a1]637void MapOfActions::queryCurrentValue(const char * name, const element * &_T) {
[d02e07]638 int Z = -1;
[e5c0a1]639 if (typeid(const element ) == *TypeMap[name]) {
[a8188d]640 if (CurrentValueMap.find(name) == CurrentValueMap.end())
[4e145c]641 throw MissingValueException(__FILE__, __LINE__);
[a8188d]642 Z = lexical_cast<int>(CurrentValueMap[name].c_str());
643 CurrentValueMap.erase(name);
[4e145c]644 } else
[d02e07]645 throw IllegalTypeException(__FILE__,__LINE__);
646 _T = World::getInstance().getPeriode()->FindElement(Z);
647}
648
649void MapOfActions::queryCurrentValue(const char * name, class molecule * &_T) {
650 int molID = -1;
[4e145c]651 if (typeid( molecule ) == *TypeMap[name]) {
[a8188d]652 if (CurrentValueMap.find(name) == CurrentValueMap.end())
[4e145c]653 throw MissingValueException(__FILE__, __LINE__);
[a8188d]654 molID = lexical_cast<int>(CurrentValueMap[name].c_str());
655 CurrentValueMap.erase(name);
[4e145c]656 } else
[d02e07]657 throw IllegalTypeException(__FILE__,__LINE__);
658 _T = World::getInstance().getMolecule(MoleculeById(molID));
659}
660
661void MapOfActions::queryCurrentValue(const char * name, class Box &_T) {
662 Matrix M;
663 double tmp;
664 if (typeid( BoxValue ) == *TypeMap[name]) {
[a8188d]665 if (CurrentValueMap.find(name) == CurrentValueMap.end())
[4e145c]666 throw MissingValueException(__FILE__, __LINE__);
[a8188d]667 std::istringstream stream(CurrentValueMap[name]);
[d02e07]668 stream >> tmp;
669 M.set(0,0,tmp);
670 stream >> tmp;
671 M.set(0,1,tmp);
672 M.set(1,0,tmp);
673 stream >> tmp;
674 M.set(0,2,tmp);
675 M.set(2,0,tmp);
676 stream >> tmp;
677 M.set(1,1,tmp);
678 stream >> tmp;
679 M.set(1,2,tmp);
680 M.set(2,1,tmp);
681 stream >> tmp;
682 M.set(2,2,tmp);
[39b639]683 _T = M;
[a8188d]684 CurrentValueMap.erase(name);
[d02e07]685 } else
686 throw IllegalTypeException(__FILE__,__LINE__);
687}
688
689void MapOfActions::queryCurrentValue(const char * name, class Vector &_T) {
690 if (typeid( VectorValue ) == *TypeMap[name]) {
[a8188d]691 std::istringstream stream(CurrentValueMap[name]);
692 CurrentValueMap.erase(name);
[d02e07]693 stream >> _T[0];
694 stream >> _T[1];
695 stream >> _T[2];
696 } else
697 throw IllegalTypeException(__FILE__,__LINE__);
698}
699
[72f611]700void MapOfActions::queryCurrentValue(const char * name, class BoxVector &_T) {
701 if (typeid( VectorValue ) == *TypeMap[name]) {
[a8188d]702 std::istringstream stream(CurrentValueMap[name]);
703 CurrentValueMap.erase(name);
[72f611]704 stream >> _T[0];
705 stream >> _T[1];
706 stream >> _T[2];
707 } else
708 throw IllegalTypeException(__FILE__,__LINE__);
709}
710
[0b0a20]711void MapOfActions::queryCurrentValue(const char * name, std::vector<atom *>&_T)
712{
713 int atomID = -1;
714 atom *Walker = NULL;
715 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
[a8188d]716 if (CurrentValueMap.find(name) == CurrentValueMap.end())
[0b0a20]717 throw MissingValueException(__FILE__, __LINE__);
[a8188d]718 std::istringstream stream(CurrentValueMap[name]);
719 CurrentValueMap.erase(name);
[0b0a20]720 while (!stream.fail()) {
[e65de8]721 stream >> atomID >> ws;
[0b0a20]722 Walker = World::getInstance().getAtom(AtomById(atomID));
723 if (Walker != NULL)
724 _T.push_back(Walker);
[e65de8]725 atomID = -1;
726 Walker = NULL;
[0b0a20]727 }
728 } else
729 throw IllegalTypeException(__FILE__,__LINE__);
730}
731
[e5c0a1]732void MapOfActions::queryCurrentValue(const char * name, std::vector<const element *>&_T)
[d02e07]733{
734 int Z = -1;
[e5c0a1]735 const element *elemental = NULL;
736 if (typeid( std::vector<const element *> ) == *TypeMap[name]) {
[a8188d]737 if (CurrentValueMap.find(name) == CurrentValueMap.end())
[4e145c]738 throw MissingValueException(__FILE__, __LINE__);
[a8188d]739 std::istringstream stream(CurrentValueMap[name]);
740 CurrentValueMap.erase(name);
[d02e07]741 while (!stream.fail()) {
[e65de8]742 stream >> Z >> ws;
[d02e07]743 elemental = World::getInstance().getPeriode()->FindElement(Z);
744 if (elemental != NULL)
745 _T.push_back(elemental);
[e65de8]746 Z = -1;
[d02e07]747 }
748 } else
749 throw IllegalTypeException(__FILE__,__LINE__);
750}
751
[0b0a20]752void MapOfActions::queryCurrentValue(const char * name, std::vector<molecule *>&_T)
[3e54d0]753{
[0b0a20]754 int molID = -1;
755 molecule *mol = NULL;
756 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
[a8188d]757 if (CurrentValueMap.find(name) == CurrentValueMap.end())
[4e145c]758 throw MissingValueException(__FILE__, __LINE__);
[a8188d]759 std::istringstream stream(CurrentValueMap[name]);
760 CurrentValueMap.erase(name);
[3e54d0]761 while (!stream.fail()) {
[e65de8]762 stream >> molID >> ws;
[0b0a20]763 mol = World::getInstance().getMolecule(MoleculeById(molID));
764 if (mol != NULL)
765 _T.push_back(mol);
[e65de8]766 molID = -1;
767 mol = NULL;
[3e54d0]768 }
769 } else
770 throw IllegalTypeException(__FILE__,__LINE__);
771}
772
[6f5dfe]773void MapOfActions::queryCurrentValue(const char * name, boost::filesystem::path&_T)
774{
775 std::string tmp;
776 if (typeid( boost::filesystem::path ) == *TypeMap[name]) {
[a8188d]777 if (CurrentValueMap.find(name) == CurrentValueMap.end())
[6f5dfe]778 throw MissingValueException(__FILE__, __LINE__);
[a8188d]779 std::istringstream stream(CurrentValueMap[name]);
780 CurrentValueMap.erase(name);
[6f5dfe]781 if (!stream.fail()) {
782 stream >> tmp >> ws;
783 _T = tmp;
784 }
785 } else
786 throw IllegalTypeException(__FILE__,__LINE__);
787}
788
[d02e07]789void MapOfActions::setCurrentValue(const char * name, class atom * &_T)
790{
791 if (typeid( atom ) == *TypeMap[name]) {
792 std::ostringstream stream;
793 stream << _T->getId();
[a8188d]794 CurrentValueMap[name] = stream.str();
[d02e07]795 } else
796 throw IllegalTypeException(__FILE__,__LINE__);
797}
798
[e5c0a1]799void MapOfActions::setCurrentValue(const char * name, const element * &_T)
[d02e07]800{
[e5c0a1]801 if (typeid(const element ) == *TypeMap[name]) {
[d02e07]802 std::ostringstream stream;
[83f176]803 stream << _T->getAtomicNumber();
[a8188d]804 CurrentValueMap[name] = stream.str();
[d02e07]805 } else
806 throw IllegalTypeException(__FILE__,__LINE__);
807}
808
809void MapOfActions::setCurrentValue(const char * name, class molecule * &_T)
810{
811 if (typeid( molecule ) == *TypeMap[name]) {
812 std::ostringstream stream;
813 stream << _T->getId();
[a8188d]814 CurrentValueMap[name] = stream.str();
[d02e07]815 } else
816 throw IllegalTypeException(__FILE__,__LINE__);
817}
818
819void MapOfActions::setCurrentValue(const char * name, class Box &_T)
820{
821 const Matrix &M = _T.getM();
[39b639]822 if (typeid( BoxValue ) == *TypeMap[name]) {
[d02e07]823 std::ostringstream stream;
824 stream << M.at(0,0) << " ";
825 stream << M.at(0,1) << " ";
826 stream << M.at(0,2) << " ";
827 stream << M.at(1,1) << " ";
828 stream << M.at(1,2) << " ";
829 stream << M.at(2,2) << " ";
[a8188d]830 CurrentValueMap[name] = stream.str();
[d02e07]831 } else
832 throw IllegalTypeException(__FILE__,__LINE__);
833}
834
835void MapOfActions::setCurrentValue(const char * name, class Vector &_T)
836{
[39b639]837 if (typeid( VectorValue ) == *TypeMap[name]){
[d02e07]838 std::ostringstream stream;
839 stream << _T[0] << " ";
840 stream << _T[1] << " ";
841 stream << _T[2] << " ";
[a8188d]842 CurrentValueMap[name] = stream.str();
[d02e07]843 } else
844 throw IllegalTypeException(__FILE__,__LINE__);
845}
846
[72f611]847void MapOfActions::setCurrentValue(const char * name, class BoxVector &_T)
848{
849 if (typeid( VectorValue ) == *TypeMap[name]){
850 std::ostringstream stream;
851 stream << _T[0] << " ";
852 stream << _T[1] << " ";
853 stream << _T[2] << " ";
[a8188d]854 CurrentValueMap[name] = stream.str();
[72f611]855 } else
856 throw IllegalTypeException(__FILE__,__LINE__);
857}
858
[0b0a20]859void MapOfActions::setCurrentValue(const char * name, std::vector<atom *>&_T)
860{
861 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
862 std::ostringstream stream;
863 for (std::vector<atom *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
864 stream << (*iter)->getId() << " ";
865 }
[a8188d]866 CurrentValueMap[name] = stream.str();
[0b0a20]867 } else
868 throw IllegalTypeException(__FILE__,__LINE__);
869}
870
[e5c0a1]871void MapOfActions::setCurrentValue(const char * name, std::vector<const element *>&_T)
[d02e07]872{
[e5c0a1]873 if (typeid( std::vector<const element *> ) == *TypeMap[name]) {
[d02e07]874 std::ostringstream stream;
[e5c0a1]875 for (std::vector<const element *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
[83f176]876 stream << (*iter)->getAtomicNumber() << " ";
[d02e07]877 }
[a8188d]878 CurrentValueMap[name] = stream.str();
[d02e07]879 } else
880 throw IllegalTypeException(__FILE__,__LINE__);
881}
882
[0b0a20]883void MapOfActions::setCurrentValue(const char * name, std::vector<molecule *>&_T)
[3e54d0]884{
[0b0a20]885 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
[3e54d0]886 std::ostringstream stream;
[0b0a20]887 for (std::vector<molecule *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
888 stream << (*iter)->getId() << " ";
[3e54d0]889 }
[a8188d]890 CurrentValueMap[name] = stream.str();
[3e54d0]891 } else
892 throw IllegalTypeException(__FILE__,__LINE__);
893}
894
[6f5dfe]895void MapOfActions::setCurrentValue(const char * name, boost::filesystem::path &_T)
896{
897 if (typeid( boost::filesystem::path ) == *TypeMap[name]) {
898 std::ostringstream stream;
899 stream << _T.string();
[a8188d]900 CurrentValueMap[name] = stream.str();
[6f5dfe]901 } else
902 throw IllegalTypeException(__FILE__,__LINE__);
[2a6a2c]903 }
[326bbe]904
[97ebf8]905/** Adds all options to the CommandLineParser.
906 *
907 */
908void MapOfActions::AddOptionsToParser()
909{
910 // add other options
911 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
912 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
913 if (hasValue(*OptionRunner)) {
[e65de8]914 DoLog(1) && (Log() << Verbose(1) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner]->name() << " to CommandLineParser." << endl);
[ab9a27]915 switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
[97ebf8]916 default:
917 case None:
918 ListRunner->second->add_options()
919 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
920 ;
921 break;
922 case Boolean:
923 ListRunner->second->add_options()
[e30ce8]924 (getKeyAndShortForm(*OptionRunner).c_str(),
[a8188d]925 CurrentValueMap.find(*OptionRunner) != CurrentValueMap.end() ?
926 po::value< bool >()->default_value(lexical_cast<int>(CurrentValueMap[*OptionRunner].c_str())) :
[e30ce8]927 po::value< bool >(),
928 getDescription(*OptionRunner).c_str())
[97ebf8]929 ;
930 break;
[0286bc]931 case Box:
932 ListRunner->second->add_options()
933 (getKeyAndShortForm(*OptionRunner).c_str(),
[39b639]934 po::value<BoxValue>(),
[0286bc]935 getDescription(*OptionRunner).c_str())
936 ;
937 break;
[bd2390]938 case File:
939 ListRunner->second->add_options()
940 (getKeyAndShortForm(*OptionRunner).c_str(),
941 po::value< boost::filesystem::path >(),
942 getDescription(*OptionRunner).c_str())
943 ;
944 break;
[97ebf8]945 case Integer:
946 ListRunner->second->add_options()
[e30ce8]947 (getKeyAndShortForm(*OptionRunner).c_str(),
[a8188d]948 CurrentValueMap.find(*OptionRunner) != CurrentValueMap.end() ?
949 po::value< int >()->default_value(lexical_cast<int>(CurrentValueMap[*OptionRunner].c_str())) :
[e30ce8]950 po::value< int >(),
951 getDescription(*OptionRunner).c_str())
[97ebf8]952 ;
953 break;
[0b0a20]954 case ListOfIntegers:
[97ebf8]955 ListRunner->second->add_options()
[e30ce8]956 (getKeyAndShortForm(*OptionRunner).c_str(),
957 po::value< vector<int> >()->multitoken(),
958 getDescription(*OptionRunner).c_str())
[97ebf8]959 ;
960 break;
961 case Double:
962 ListRunner->second->add_options()
[e30ce8]963 (getKeyAndShortForm(*OptionRunner).c_str(),
[a8188d]964 CurrentValueMap.find(*OptionRunner) != CurrentValueMap.end() ?
965 po::value< double >()->default_value(lexical_cast<double>(CurrentValueMap[*OptionRunner].c_str())) :
[e30ce8]966 po::value< double >(),
967 getDescription(*OptionRunner).c_str())
[97ebf8]968 ;
969 break;
970 case ListOfDoubles:
971 ListRunner->second->add_options()
[e30ce8]972 (getKeyAndShortForm(*OptionRunner).c_str(),
973 po::value< vector<double> >()->multitoken(),
974 getDescription(*OptionRunner).c_str())
[97ebf8]975 ;
976 break;
977 case String:
978 ListRunner->second->add_options()
[e30ce8]979 (getKeyAndShortForm(*OptionRunner).c_str(),
[a8188d]980 CurrentValueMap.find(*OptionRunner) != CurrentValueMap.end() ?
981 po::value< std::string >()->default_value(CurrentValueMap[*OptionRunner]) :
[e30ce8]982 po::value< std::string >(),
983 getDescription(*OptionRunner).c_str())
[97ebf8]984 ;
985 break;
[0b0a20]986 case ListOfStrings:
[cd8e55]987 ListRunner->second->add_options()
988 (getKeyAndShortForm(*OptionRunner).c_str(),
989 po::value< vector<std::string> >()->multitoken(),
990 getDescription(*OptionRunner).c_str())
991 ;
992 break;
[0b0a20]993 case Vector:
[97ebf8]994 ListRunner->second->add_options()
[e30ce8]995 (getKeyAndShortForm(*OptionRunner).c_str(),
[0b0a20]996 po::value<VectorValue>(),
[e30ce8]997 getDescription(*OptionRunner).c_str())
[97ebf8]998 ;
999 break;
[0b0a20]1000 case ListOfVectors:
[97ebf8]1001 ListRunner->second->add_options()
[e30ce8]1002 (getKeyAndShortForm(*OptionRunner).c_str(),
[0b0a20]1003 po::value< vector<VectorValue> >()->multitoken(),
[e30ce8]1004 getDescription(*OptionRunner).c_str())
[97ebf8]1005 ;
1006 break;
1007 case Molecule:
1008 ListRunner->second->add_options()
[e30ce8]1009 (getKeyAndShortForm(*OptionRunner).c_str(),
[a8188d]1010 CurrentValueMap.find(*OptionRunner) != CurrentValueMap.end() ?
1011 po::value< int >()->default_value(lexical_cast<int>(CurrentValueMap[*OptionRunner].c_str())) :
[e30ce8]1012 po::value< int >(),
1013 getDescription(*OptionRunner).c_str())
[97ebf8]1014 ;
1015 break;
1016 case ListOfMolecules:
1017 ListRunner->second->add_options()
[e30ce8]1018 (getKeyAndShortForm(*OptionRunner).c_str(),
1019 po::value< vector<int> >()->multitoken(),
1020 getDescription(*OptionRunner).c_str())
[97ebf8]1021 ;
1022 break;
1023 case Atom:
1024 ListRunner->second->add_options()
[e30ce8]1025 (getKeyAndShortForm(*OptionRunner).c_str(),
[a8188d]1026 CurrentValueMap.find(*OptionRunner) != CurrentValueMap.end() ?
1027 po::value< int >()->default_value(lexical_cast<int>(CurrentValueMap[*OptionRunner].c_str())) :
[e30ce8]1028 po::value< int >(),
1029 getDescription(*OptionRunner).c_str())
[97ebf8]1030 ;
1031 break;
1032 case ListOfAtoms:
1033 ListRunner->second->add_options()
[e30ce8]1034 (getKeyAndShortForm(*OptionRunner).c_str(),
1035 po::value< vector<int> >()->multitoken(),
1036 getDescription(*OptionRunner).c_str())
[97ebf8]1037 ;
1038 break;
1039 case Element:
1040 ListRunner->second->add_options()
[e30ce8]1041 (getKeyAndShortForm(*OptionRunner).c_str(),
[39b639]1042 po::value< int >(),
[e30ce8]1043 getDescription(*OptionRunner).c_str())
[97ebf8]1044 ;
1045 break;
1046 case ListOfElements:
1047 ListRunner->second->add_options()
[e30ce8]1048 (getKeyAndShortForm(*OptionRunner).c_str(),
1049 po::value< vector<int> >()->multitoken(),
1050 getDescription(*OptionRunner).c_str())
[97ebf8]1051 ;
1052 break;
1053 }
1054 } else {
[0b0a20]1055 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
[97ebf8]1056 ListRunner->second->add_options()
1057 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
1058 ;
1059 }
1060 }
1061 }
1062}
1063
1064/** Getter for MapOfActions:DescriptionMap.
1065 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
1066 * \param actionname name of the action to lookup
1067 * \return Description of the action
1068 */
[4885f85]1069const std::string MapOfActions::getDescription(string actionname)
[97ebf8]1070{
1071 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
1072 return DescriptionMap[actionname];
1073}
1074
1075/** Specific Getter for a MapOfActions:ShortFormMap.
1076 * If action has a short for, then combination is as "actionname,ShortForm" (this is
1077 * the desired format for boost::program_options). If no short form exists in the map,
1078 * just actionname will be returned
1079 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
1080 * \param actionname name of the action to lookup
1081 * \return actionname,ShortForm or Description of the action
1082 */
[4885f85]1083const std::string MapOfActions::getKeyAndShortForm(string actionname)
[97ebf8]1084{
1085 stringstream output;
1086 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
1087 output << actionname;
1088 if (ShortFormMap.find(actionname) != DescriptionMap.end())
1089 output << "," << ShortFormMap[actionname];
1090 return output.str();
1091}
1092
1093/** Getter for MapOfActions:ShortFormMap.
1094 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
1095 * \param actionname name of the action to lookup
1096 * \return ShortForm of the action
1097 */
[4885f85]1098const std::string MapOfActions::getShortForm(string actionname)
[97ebf8]1099{
[4885f85]1100 if (ShortFormMap.find(actionname) != ShortFormMap.end())
1101 return ShortFormMap[actionname];
1102 else
1103 return std::string();
1104}
1105
1106/** Getter for MapOfActions:CurrentValueMap.
1107 * Note that we assert when action does not exist in CommandLineParser::CurrentValueMap.
1108 * \param actionname name of the action to lookup
1109 * \return CurrentValueMap of the action
1110 */
1111const std::string MapOfActions::getCurrentValue(string actionname)
1112{
1113 if (CurrentValueMap.find(actionname) != CurrentValueMap.end())
1114 return CurrentValueMap[actionname];
1115 else
1116 return std::string();
[97ebf8]1117}
1118
1119/** Returns whether the given action needs a value or not.
1120 * \param actionname name of the action to look up
1121 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
1122 */
1123bool MapOfActions::hasValue(string actionname)
1124{
1125 return (TypeMap.find(actionname) != TypeMap.end());
1126}
1127
[4885f85]1128/** Getter for MapOfActions::TypeMap::name.
1129 * \param actionname name of the action to look up
1130 * \return name of type of the action
1131 */
1132const std::string MapOfActions::getValueType(string actionname)
1133{
1134 return TypeMap[actionname]->name();
1135}
1136
[97ebf8]1137/** Getter for MapOfActions::TypeMap.
1138 * \param actionname name of the action to look up
1139 * \return type of the action
1140 */
[4885f85]1141const std::type_info * MapOfActions::getType(string actionname)
[97ebf8]1142{
[4885f85]1143 return TypeMap[actionname];
[97ebf8]1144}
1145
1146/** Searches whether action is registered with CommandLineParser.
1147 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
1148 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
1149 * by this function.
1150 * \param shortform command short form to look for
1151 * \return true - action has been registered, false - action has not been registered.
1152 */
1153bool MapOfActions::isShortFormPresent(string shortform)
1154{
1155 bool result = false;
1156 string actionname;
1157 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
1158 if (ShortFormRunner->second == shortform) {
1159 actionname = ShortFormRunner->first;
1160 break;
1161 }
1162 result = result || (generic.find(actionname) != generic.end());
1163 result = result || (config.find(actionname) != config.end());
1164 result = result || (hidden.find(actionname) != hidden.end());
1165 result = result || (visible.find(actionname) != visible.end());
1166 result = result || (inputfile.find(actionname) != inputfile.end());
1167 return result;
1168}
1169
[7e6b00]1170/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
1171 * \return map from short form of action to name of action
1172 */
1173map <std::string, std::string> MapOfActions::getShortFormToActionMap()
1174{
1175 map <std::string, std::string> result;
1176
1177 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
1178 result[iter->second] = iter->first;
1179
1180 return result;
1181}
[97ebf8]1182
1183
1184CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.