source: src/Actions/GeometryAction/GeometryPlaneToVectorAction.cpp@ 3c9ac3

Action_Thermostats Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph Fix_Verbose_Codepatterns ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters Recreated_GuiChecks StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since 3c9ac3 was 987145, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Added four GeometryActions to convert atom positions into vectors.

  • added reverse switch to distance and plane to vector Actions.
  • InputToVector has coordinates to differentiate from position option. This eases use with CommandLineParser where option names need to be unique.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2017 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * GeometryPlaneToVectorAction.cpp
25 *
26 * Created on: Mar 28, 2017
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35//#include "CodePatterns/MemDebug.hpp"
36
37#include "CodePatterns/Log.hpp"
38
39#include <string>
40
41#include "LinearAlgebra/Plane.hpp"
42
43#include "Atom/atom.hpp"
44#include "Geometry/GeometryObject.hpp"
45#include "Geometry/GeometryRegistry.hpp"
46#include "World.hpp"
47
48#include "Actions/GeometryAction/GeometryPlaneToVectorAction.hpp"
49
50using namespace MoleCuilder;
51
52// and construct the stuff
53#include "../GeometryAction/GeometryPlaneToVectorAction.def"
54#include "Action_impl_pre.hpp"
55/** =========== define the function ====================== */
56ActionState::ptr GeometryPlaneToVectorAction::performCall() {
57 // check preconditions
58 World& world = World::getInstance();
59 if (world.countSelectedAtoms() != 3) {
60 STATUS("There must be exactly three atoms selected for GeometryAction PlaneToVector.");
61 return Action::failure;
62 }
63 if (GeometryRegistry::getInstance().isPresentByName(params.name.get())) {
64 STATUS("Name "+params.name.get()+" already present in registry.");
65 return Action::failure;
66 }
67
68 World::AtomSelectionIterator iter = world.beginAtomSelection();
69 const atom * const Walker = (iter++)->second;
70 const atom * const OtherWalker = (iter++)->second;
71 const atom * const AnotherWalker = (iter++)->second;
72 ASSERT( iter == world.endAtomSelection(),
73 "GeometryDistanceToVectorAction::performCall() - selection iter not at end?");
74 Vector PlaneNormal;
75 try {
76 const Plane AtomPlane(Walker->getPosition(), OtherWalker->getPosition(), AnotherWalker->getPosition());
77 PlaneNormal = AtomPlane.getNormal();
78 } catch (LinearDependenceException &e) {
79 ELOG(2, "The selected atomic positions are linearly dependent.");
80 return Action::failure;
81 }
82 PlaneNormal *= (params.reverse.get() ? -1. : 1.);
83 const GeometryObject vec(PlaneNormal, params.name.get());
84 LOG(4, "DEBUG: Adding geometry object " << vec << " with norm " << PlaneNormal.Norm());
85 GeometryRegistry::getInstance().addGeometry(vec);
86
87 GeometryPlaneToVectorState *UndoState = new GeometryPlaneToVectorState(PlaneNormal, params);
88 return ActionState::ptr(UndoState);
89}
90
91ActionState::ptr GeometryPlaneToVectorAction::performUndo(ActionState::ptr _state) {
92// GeometryPlaneToVectorState *state = assert_cast<GeometryPlaneToVectorState*>(_state.get());
93
94 GeometryRegistry::getInstance().removeGeometry(params.name.get());
95
96 return ActionState::ptr(_state);
97}
98
99ActionState::ptr GeometryPlaneToVectorAction::performRedo(ActionState::ptr _state){
100 GeometryPlaneToVectorState *state = assert_cast<GeometryPlaneToVectorState*>(_state.get());
101
102 const GeometryObject vec(state->PlaneNormal, params.name.get());
103 LOG(4, "DEBUG: Adding geometry object " << vec);
104 GeometryRegistry::getInstance().addGeometry(vec);
105
106 return ActionState::ptr(_state);
107}
108
109bool GeometryPlaneToVectorAction::canUndo() {
110 return true;
111}
112
113bool GeometryPlaneToVectorAction::shouldUndo() {
114 return true;
115}
116/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.