source: src/Actions/SelectionAction/AllAtomsInsideSphereAction.cpp@ 31fb1d

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
Last change on this file since 31fb1d was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * AllAtomsInsideSphereAction.cpp
3 *
4 * Created on: Aug 9, 2010
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "Helpers/MemDebug.hpp"
14
15#include "Actions/SelectionAction/AllAtomsInsideSphereAction.hpp"
16#include "Actions/ActionRegistry.hpp"
17#include "Descriptors/AtomDescriptor.hpp"
18#include "Descriptors/AtomShapeDescriptor.hpp"
19#include "atom.hpp"
20#include "Helpers/Log.hpp"
21#include "Helpers/Verbose.hpp"
22#include "LinearAlgebra/Vector.hpp"
23#include "Shapes/BaseShapes.hpp"
24#include "Shapes/Shape.hpp"
25#include "Shapes/ShapeOps.hpp"
26#include "World.hpp"
27
28#include <iostream>
29#include <string>
30
31using namespace std;
32
33#include "UIElements/UIFactory.hpp"
34#include "UIElements/Dialog.hpp"
35#include "Actions/ValueStorage.hpp"
36
37
38// memento to remember the state when undoing
39
40class SelectionAllAtomsInsideSphereState : public ActionState {
41public:
42 SelectionAllAtomsInsideSphereState(std::vector<atom*> _selectedAtoms, const Vector &_position, const double _radius) :
43 selectedAtoms(_selectedAtoms),
44 position(_position),
45 radius(_radius)
46 {}
47 std::vector<atom*> selectedAtoms;
48 Vector position;
49 double radius;
50};
51
52const char SelectionAllAtomsInsideSphereAction::NAME[] = "select-atoms-inside-sphere";
53
54SelectionAllAtomsInsideSphereAction::SelectionAllAtomsInsideSphereAction() :
55 Action(NAME)
56{}
57
58SelectionAllAtomsInsideSphereAction::~SelectionAllAtomsInsideSphereAction()
59{}
60
61void SelectionAllAtomsInsideSphere(const Vector &position, const double radius) {
62 ValueStorage::getInstance().setCurrentValue(SelectionAllAtomsInsideSphereAction::NAME, radius);
63 ValueStorage::getInstance().setCurrentValue("position", position);
64 ActionRegistry::getInstance().getActionByName(SelectionAllAtomsInsideSphereAction::NAME)->call(Action::NonInteractive);
65};
66
67Dialog* SelectionAllAtomsInsideSphereAction::fillDialog(Dialog *dialog) {
68 ASSERT(dialog,"No Dialog given when filling action dialog");
69
70 dialog->queryDouble(NAME, ValueStorage::getInstance().getDescription(NAME));
71 dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
72
73 return dialog;
74}
75
76Action::state_ptr SelectionAllAtomsInsideSphereAction::performCall() {
77 std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
78 double radius = 0.;
79 Vector position;
80
81 ValueStorage::getInstance().queryCurrentValue(NAME, radius);
82 ValueStorage::getInstance().queryCurrentValue("position", position);
83
84 DoLog(1) && (Log() << Verbose(1) << "Selecting all atoms inside a sphere at " << position << " with radius " << radius << "." << endl);
85 Shape s = translate(resize(Sphere(),radius),position);
86 World::getInstance().selectAllAtoms(AtomByShape(s));
87 return Action::state_ptr(new SelectionAllAtomsInsideSphereState(selectedAtoms, position, radius));
88}
89
90Action::state_ptr SelectionAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) {
91 SelectionAllAtomsInsideSphereState *state = assert_cast<SelectionAllAtomsInsideSphereState*>(_state.get());
92
93 World::getInstance().clearAtomSelection();
94 for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
95 World::getInstance().selectAtom(*iter);
96
97 return Action::state_ptr(new SelectionAllAtomsInsideSphereState(state->selectedAtoms, state->position, state->radius));
98}
99
100Action::state_ptr SelectionAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){
101 SelectionAllAtomsInsideSphereState *state = assert_cast<SelectionAllAtomsInsideSphereState*>(_state.get());
102
103 Shape s = translate(resize(Sphere(),state->radius),state->position);
104 World::getInstance().selectAllAtoms(AtomByShape(s));
105
106 return Action::state_ptr(new SelectionAllAtomsInsideSphereState(state->selectedAtoms, state->position, state->radius));
107}
108
109bool SelectionAllAtomsInsideSphereAction::canUndo() {
110 return true;
111}
112
113bool SelectionAllAtomsInsideSphereAction::shouldUndo() {
114 return true;
115}
116
117const string SelectionAllAtomsInsideSphereAction::getName() {
118 return NAME;
119}
Note: See TracBrowser for help on using the repository browser.