source: src/Actions/SelectionAction/NotAllAtomsInsideCuboidAction.cpp@ 9cd807

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 9cd807 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.4 KB
Line 
1/*
2 * NotAllAtomsInsideCuboidAction.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/NotAllAtomsInsideCuboidAction.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 SelectionNotAllAtomsInsideCuboidState : public ActionState {
42public:
43 SelectionNotAllAtomsInsideCuboidState(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 SelectionNotAllAtomsInsideCuboidAction::NAME[] = "unselect-atoms-inside-cuboid";
60
61SelectionNotAllAtomsInsideCuboidAction::SelectionNotAllAtomsInsideCuboidAction() :
62 Action(NAME)
63{}
64
65SelectionNotAllAtomsInsideCuboidAction::~SelectionNotAllAtomsInsideCuboidAction()
66{}
67
68void SelectionNotAllAtomsInsideCuboid(const Vector &position, const Vector &extension) {
69 ValueStorage::getInstance().setCurrentValue(SelectionNotAllAtomsInsideCuboidAction::NAME, extension);
70 ValueStorage::getInstance().setCurrentValue("position", position);
71 ActionRegistry::getInstance().getActionByName(SelectionNotAllAtomsInsideCuboidAction::NAME)->call(Action::NonInteractive);
72};
73
74void SelectionNotAllAtomsInsideCuboid(const Vector &position, const Vector &extension, const double Xangle, const double Yangle, const double Zangle) {
75 ValueStorage::getInstance().setCurrentValue(SelectionNotAllAtomsInsideCuboidAction::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(SelectionNotAllAtomsInsideCuboidAction::NAME)->call(Action::NonInteractive);
81};
82
83Dialog* SelectionNotAllAtomsInsideCuboidAction::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 SelectionNotAllAtomsInsideCuboidAction::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) << "Unselecting 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
115 World::getInstance().unselectAllAtoms(AtomByShape(s));
116 return Action::state_ptr(new SelectionNotAllAtomsInsideCuboidState(selectedAtoms, position, extension, Xangle, Yangle, Zangle));
117}
118
119Action::state_ptr SelectionNotAllAtomsInsideCuboidAction::performUndo(Action::state_ptr _state) {
120 SelectionNotAllAtomsInsideCuboidState *state = assert_cast<SelectionNotAllAtomsInsideCuboidState*>(_state.get());
121
122 World::getInstance().clearAtomSelection();
123 for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
124 World::getInstance().selectAtom(*iter);
125
126 return Action::state_ptr(_state);
127}
128
129Action::state_ptr SelectionNotAllAtomsInsideCuboidAction::performRedo(Action::state_ptr _state){
130 SelectionNotAllAtomsInsideCuboidState *state = assert_cast<SelectionNotAllAtomsInsideCuboidState*>(_state.get());
131 Matrix RotationMatrix;
132
133 RotationMatrix.rotation(state->Xangle, state->Yangle, state->Zangle);
134 Shape s = translate(transform(stretch(Cuboid(),state->extension),RotationMatrix),state->position);
135 World::getInstance().unselectAllAtoms(AtomByShape(s));
136
137 return Action::state_ptr(_state);
138}
139
140bool SelectionNotAllAtomsInsideCuboidAction::canUndo() {
141 return true;
142}
143
144bool SelectionNotAllAtomsInsideCuboidAction::shouldUndo() {
145 return true;
146}
147
148const string SelectionNotAllAtomsInsideCuboidAction::getName() {
149 return NAME;
150}
Note: See TracBrowser for help on using the repository browser.