source: src/Actions/SelectionAction/AllAtomsInsideSphereAction.cpp@ bbbad5

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 bbbad5 was 1cc87e, checked in by Frederik Heber <heber@…>, 14 years ago

Added select-atoms-inside-sphere/cuboid and unselect-..

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