| 1 | /*
 | 
|---|
| 2 |  * CommandLineWindow.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: May 8, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include <boost/bind.hpp>
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "CommandLineUI/CommandLineWindow.hpp"
 | 
|---|
| 11 | #include "CommandLineUI/CommandLineStatusIndicator.hpp"
 | 
|---|
| 12 | 
 | 
|---|
| 13 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| 14 | #include "Actions/AnalysisAction/PairCorrelationAction.hpp"
 | 
|---|
| 15 | #include "Actions/AnalysisAction/PairCorrelationToPointAction.hpp"
 | 
|---|
| 16 | #include "Actions/AnalysisAction/PairCorrelationToSurfaceAction.hpp"
 | 
|---|
| 17 | #include "Actions/AtomAction/AddAction.hpp"
 | 
|---|
| 18 | #include "Actions/AtomAction/ChangeElementAction.hpp"
 | 
|---|
| 19 | #include "Actions/AtomAction/RemoveAction.hpp"
 | 
|---|
| 20 | #include "Actions/CmdAction/BondLengthTableAction.hpp"
 | 
|---|
| 21 | #include "Actions/CmdAction/ElementDbAction.hpp"
 | 
|---|
| 22 | #include "Actions/CmdAction/FastParsingAction.hpp"
 | 
|---|
| 23 | #include "Actions/CmdAction/HelpAction.hpp"
 | 
|---|
| 24 | #include "Actions/CmdAction/VerboseAction.hpp"
 | 
|---|
| 25 | #include "Actions/CmdAction/VersionAction.hpp"
 | 
|---|
| 26 | #include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
 | 
|---|
| 27 | #include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
 | 
|---|
| 28 | #include "Actions/MoleculeAction/BondFileAction.hpp"
 | 
|---|
| 29 | #include "Actions/MoleculeAction/ChangeNameAction.hpp"
 | 
|---|
| 30 | #include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
 | 
|---|
| 31 | #include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp"
 | 
|---|
| 32 | #include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
 | 
|---|
| 33 | #include "Actions/MoleculeAction/SaveBondsAction.hpp"
 | 
|---|
| 34 | #include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
 | 
|---|
| 35 | #include "Actions/MoleculeAction/VerletIntegrationAction.hpp"
 | 
|---|
| 36 | #include "Actions/ParserAction/LoadXyzAction.hpp"
 | 
|---|
| 37 | #include "Actions/ParserAction/SaveXyzAction.hpp"
 | 
|---|
| 38 | #include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
 | 
|---|
| 39 | #include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
 | 
|---|
| 40 | #include "Actions/WorldAction/AddEmptyBoundaryAction.hpp"
 | 
|---|
| 41 | #include "Actions/WorldAction/BoundInBoxAction.hpp"
 | 
|---|
| 42 | #include "Actions/WorldAction/CenterInBoxAction.hpp"
 | 
|---|
| 43 | #include "Actions/WorldAction/CenterOnEdgeAction.hpp"
 | 
|---|
| 44 | #include "Actions/WorldAction/ChangeBoxAction.hpp"
 | 
|---|
| 45 | #include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
 | 
|---|
| 46 | #include "Actions/WorldAction/RepeatBoxAction.hpp"
 | 
|---|
| 47 | #include "Actions/WorldAction/ScaleBoxAction.hpp"
 | 
|---|
| 48 | #include "Actions/WorldAction/SetDefaultNameAction.hpp"
 | 
|---|
| 49 | #include "Actions/WorldAction/SetGaussianBasisAction.hpp"
 | 
|---|
| 50 | #include "CommandLineParser.hpp"
 | 
|---|
| 51 | 
 | 
|---|
| 52 | #include <iostream>
 | 
|---|
| 53 | 
 | 
|---|
| 54 | using namespace std;
 | 
|---|
| 55 | 
 | 
|---|
| 56 | // TODO: see what code can be moved to a base class for Graphic and CommandLine Windows
 | 
|---|
| 57 | CommandLineWindow::CommandLineWindow()
 | 
|---|
| 58 | {
 | 
|---|
| 59 |   // create and register all command line callable actions
 | 
|---|
| 60 |   populateAnalysisActions();
 | 
|---|
| 61 |   populateAtomActions();
 | 
|---|
| 62 |   populateCmdActions();
 | 
|---|
| 63 |   populateFragmentationActions();
 | 
|---|
| 64 |   populateMoleculeActions();
 | 
|---|
| 65 |   populateParserActions();
 | 
|---|
| 66 |   populateTesselationActions();
 | 
|---|
| 67 |   populateWorldActions();
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   // Add status indicators etc...
 | 
|---|
| 70 |   statusIndicator = new CommandLineStatusIndicator();
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | CommandLineWindow::~CommandLineWindow()
 | 
|---|
| 74 | {
 | 
|---|
| 75 | //  // go through all possible actions
 | 
|---|
| 76 | //  for(std::map<const std::string,Action*>::iterator ActionRunner = ActionRegistry::getInstance().getBeginIter(); ActionRegistry::getInstance().getBeginIter() != ActionRegistry::getInstance().getEndIter(); ActionRunner = ActionRegistry::getInstance().getBeginIter()) {
 | 
|---|
| 77 | //    ActionRegistry::getInstance().unregisterAction(ActionRunner->second);
 | 
|---|
| 78 | //    delete(ActionRunner->second);
 | 
|---|
| 79 | //  }
 | 
|---|
| 80 | 
 | 
|---|
| 81 |   delete statusIndicator;
 | 
|---|
| 82 | }
 | 
|---|
| 83 | 
 | 
|---|
| 84 | void CommandLineWindow::display() {
 | 
|---|
| 85 |   // go through all possible actions
 | 
|---|
| 86 |   for(std::map<const std::string,Action*>::iterator ActionRunner = ActionRegistry::getInstance().getBeginIter(); ActionRunner != ActionRegistry::getInstance().getEndIter(); ActionRunner++) {
 | 
|---|
| 87 |     // check whether action is present in command line
 | 
|---|
| 88 |     if (CommandLineParser::getInstance().vm.count(ActionRunner->first)) {
 | 
|---|
| 89 |       ActionRunner->second->call();
 | 
|---|
| 90 |     }
 | 
|---|
| 91 |   }
 | 
|---|
| 92 | }
 | 
|---|
| 93 | 
 | 
|---|
| 94 | void CommandLineWindow::populateAnalysisActions()
 | 
|---|
| 95 | {
 | 
|---|
| 96 |   new AnalysisPairCorrelationAction();
 | 
|---|
| 97 |   new AnalysisPairCorrelationToPointAction();
 | 
|---|
| 98 |   new AnalysisPairCorrelationToSurfaceAction();
 | 
|---|
| 99 | }
 | 
|---|
| 100 | 
 | 
|---|
| 101 | void CommandLineWindow::populateAtomActions()
 | 
|---|
| 102 | {
 | 
|---|
| 103 |   new AtomAddAction();
 | 
|---|
| 104 |   new AtomChangeElementAction();
 | 
|---|
| 105 |   new AtomRemoveAction();
 | 
|---|
| 106 | }
 | 
|---|
| 107 | 
 | 
|---|
| 108 | void CommandLineWindow::populateCmdActions()
 | 
|---|
| 109 | {
 | 
|---|
| 110 |   new CommandLineBondLengthTableAction();
 | 
|---|
| 111 |   new CommandLineElementDbAction();
 | 
|---|
| 112 |   new CommandLineFastParsingAction();
 | 
|---|
| 113 |   new CommandLineHelpAction();
 | 
|---|
| 114 |   new CommandLineVerboseAction();
 | 
|---|
| 115 |   new CommandLineVersionAction();
 | 
|---|
| 116 | }
 | 
|---|
| 117 | 
 | 
|---|
| 118 | void CommandLineWindow::populateFragmentationActions()
 | 
|---|
| 119 | {
 | 
|---|
| 120 |   new FragmentationDepthFirstSearchAction();
 | 
|---|
| 121 | }
 | 
|---|
| 122 | 
 | 
|---|
| 123 | void CommandLineWindow::populateMoleculeActions()
 | 
|---|
| 124 | {
 | 
|---|
| 125 |   new MoleculeBondFileAction();
 | 
|---|
| 126 |   new MoleculeChangeNameAction();
 | 
|---|
| 127 |   new MoleculeFillWithMoleculeAction();
 | 
|---|
| 128 |   new MoleculeLinearInterpolationofTrajectoriesAction();
 | 
|---|
| 129 |   new MoleculeSaveAdjacencyAction();
 | 
|---|
| 130 |   new MoleculeSaveBondsAction();
 | 
|---|
| 131 |   new MoleculeSaveTemperatureAction();
 | 
|---|
| 132 |   new MoleculeVerletIntegrationAction();
 | 
|---|
| 133 | }
 | 
|---|
| 134 | 
 | 
|---|
| 135 | void CommandLineWindow::populateParserActions()
 | 
|---|
| 136 | {
 | 
|---|
| 137 |   new ParserLoadXyzAction();
 | 
|---|
| 138 |   new ParserSaveXyzAction();
 | 
|---|
| 139 | }
 | 
|---|
| 140 | 
 | 
|---|
| 141 | void CommandLineWindow::populateTesselationActions()
 | 
|---|
| 142 | {
 | 
|---|
| 143 |   new TesselationConvexEnvelopeAction();
 | 
|---|
| 144 |   new TesselationNonConvexEnvelopeAction();
 | 
|---|
| 145 | }
 | 
|---|
| 146 | 
 | 
|---|
| 147 | void CommandLineWindow::populateWorldActions()
 | 
|---|
| 148 | {
 | 
|---|
| 149 |   new WorldAddEmptyBoundaryAction();
 | 
|---|
| 150 |   new WorldBoundInBoxAction();
 | 
|---|
| 151 |   new WorldCenterInBoxAction();
 | 
|---|
| 152 |   new WorldCenterOnEdgeAction();
 | 
|---|
| 153 |   new WorldChangeBoxAction();
 | 
|---|
| 154 |   new WorldRemoveSphereOfAtomsAction();
 | 
|---|
| 155 |   new WorldRepeatBoxAction();
 | 
|---|
| 156 |   new WorldScaleBoxAction();
 | 
|---|
| 157 |   new WorldSetDefaultNameAction();
 | 
|---|
| 158 |   new WorldSetGaussianBasisAction();
 | 
|---|
| 159 | }
 | 
|---|