source: src/Actions/SelectionAction/AllAtomsInsideCuboidAction.cpp@ 2b7d1b

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 2b7d1b was 31fb1d, checked in by Frederik Heber <heber@…>, 14 years ago

(un)select-atoms-inside-cuboid: cuboid may be rotated.

  • Matrix::rotate() sets contents to arbitrary rotation matrix.
  • BUGFIX: Matrix::transpose() was working only for symmetric matrices.
  • TEST: unit test cases for rotation() and transpose().
  • new options "angle-x", "angle-y", "angle-z"
  • (un)select-atoms-inside-cuboid: have these as optional arguments.
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * AllAtomsInsideCuboidAction.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/AllAtomsInsideCuboidAction.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/Matrix.hpp"
23#include "LinearAlgebra/Vector.hpp"
24#include "Shapes/BaseShapes.hpp"
25#include "Shapes/Shape.hpp"
26#include "Shapes/ShapeOps.hpp"
27#include "World.hpp"
28
29#include <iostream>
30#include <string>
31
32using namespace std;
33
34#include "UIElements/UIFactory.hpp"
35#include "UIElements/Dialog.hpp"
36#include "Actions/ValueStorage.hpp"
37
38
39// memento to remember the state when undoing
40
41class SelectionAllAtomsInsideCuboidState : public ActionState {
42public:
43 SelectionAllAtomsInsideCuboidState(std::vector<atom*> _selectedAtoms, const Vector &_position, const Vector &_extension, const double _Xangle, const double _Yangle, const double _Zangle) :
44 selectedAtoms(_selectedAtoms),
45 position(_position),
46 extension(_extension),
47 Xangle(_Xangle),
48 Yangle(_Yangle),
49 Zangle(_Zangle)
50 {}
51 std::vector<atom*> selectedAtoms;
52 Vector position;
53 Vector extension;
54 double Xangle;
55 double Yangle;
56 double Zangle;
57};
58
59const char SelectionAllAtomsInsideCuboidAction::NAME[] = "select-atoms-inside-cuboid";
60
61SelectionAllAtomsInsideCuboidAction::SelectionAllAtomsInsideCuboidAction() :
62 Action(NAME)
63{}
64
65SelectionAllAtomsInsideCuboidAction::~SelectionAllAtomsInsideCuboidAction()
66{}
67
68void SelectionAllAtomsInsideCuboid(const Vector &position, const Vector &extension) {
69 ValueStorage::getInstance().setCurrentValue(SelectionAllAtomsInsideCuboidAction::NAME, extension);
70 ValueStorage::getInstance().setCurrentValue("position", position);
71 ActionRegistry::getInstance().getActionByName(SelectionAllAtomsInsideCuboidAction::NAME)->call(Action::NonInteractive);
72};
73
74void SelectionAllAtomsInsideCuboid(const Vector &position, const Vector &extension, const double Xangle, const double Yangle, const double Zangle) {
75 ValueStorage::getInstance().setCurrentValue(SelectionAllAtomsInsideCuboidAction::NAME, extension);
76 ValueStorage::getInstance().setCurrentValue("position", position);
77 ValueStorage::getInstance().setCurrentValue("angle-x", Xangle);
78 ValueStorage::getInstance().setCurrentValue("angle-y", Yangle);
79 ValueStorage::getInstance().setCurrentValue("angle-z", Zangle);
80 ActionRegistry::getInstance().getActionByName(SelectionAllAtomsInsideCuboidAction::NAME)->call(Action::NonInteractive);
81};
82
83Dialog* SelectionAllAtomsInsideCuboidAction::fillDialog(Dialog *dialog) {
84 ASSERT(dialog,"No Dialog given when filling action dialog");
85
86 dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
87 dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
88
89 return dialog;
90}
91
92Action::state_ptr SelectionAllAtomsInsideCuboidAction::performCall() {
93 std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
94 Vector position;
95 Vector extension;
96 double Xangle = 0.;
97 double Yangle = 0.;
98 double Zangle = 0.;
99 Matrix RotationMatrix;
100
101 ValueStorage::getInstance().queryCurrentValue("position", position);
102 ValueStorage::getInstance().queryCurrentValue(NAME, extension);
103 // check whether a rotation is given.
104 if (ValueStorage::getInstance().queryCurrentValue("angle-x", Xangle, true))
105 Xangle = 0.;
106 if (ValueStorage::getInstance().queryCurrentValue("angle-y", Yangle, true))
107 Yangle = 0.;
108 if (ValueStorage::getInstance().queryCurrentValue("angle-z", Zangle, true))
109 Zangle = 0.;
110 RotationMatrix.rotation(Xangle, Yangle, Zangle);
111
112 DoLog(1) && (Log() << Verbose(1) << "Selecting all atoms inside a rotated " << RotationMatrix << " cuboid at " << position << " and extension of " << extension << "." << endl);
113 Shape s = translate(transform(stretch(Cuboid(),extension),RotationMatrix),position);
114 World::getInstance().selectAllAtoms(AtomByShape(s));
115 return Action::state_ptr(new SelectionAllAtomsInsideCuboidState(selectedAtoms, position, extension, Xangle, Yangle, Zangle));
116}
117
118Action::state_ptr SelectionAllAtomsInsideCuboidAction::performUndo(Action::state_ptr _state) {
119 SelectionAllAtomsInsideCuboidState *state = assert_cast<SelectionAllAtomsInsideCuboidState*>(_state.get());
120
121 World::getInstance().clearAtomSelection();
122 for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
123 World::getInstance().selectAtom(*iter);
124
125 return Action::state_ptr(_state);
126}
127
128Action::state_ptr SelectionAllAtomsInsideCuboidAction::performRedo(Action::state_ptr _state){
129 SelectionAllAtomsInsideCuboidState *state = assert_cast<SelectionAllAtomsInsideCuboidState*>(_state.get());
130 Matrix RotationMatrix;
131
132 RotationMatrix.rotation(state->Xangle, state->Yangle, state->Zangle);
133 Shape s = translate(transform(stretch(Cuboid(),state->extension),RotationMatrix),state->position);
134 World::getInstance().selectAllAtoms(AtomByShape(s));
135
136 return Action::state_ptr(_state);
137}
138
139bool SelectionAllAtomsInsideCuboidAction::canUndo() {
140 return true;
141}
142
143bool SelectionAllAtomsInsideCuboidAction::shouldUndo() {
144 return true;
145}
146
147const string SelectionAllAtomsInsideCuboidAction::getName() {
148 return NAME;
149}
Note: See TracBrowser for help on using the repository browser.