source: src/Parser/FormatParser_common.cpp@ 440ac3

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 440ac3 was 54bdaa, checked in by Frederik Heber <heber@…>, 9 years ago

Qt4 instance use new lastChanged..Id() in place of lastChanged().

  • also changed in FormatParser_common.
  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. 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 * FormatParser_common_common.cpp
25 *
26 * Created on: Mar 1, 2010
27 * Author: metzler
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 <iostream>
38
39#include "CodePatterns/Observer/Notification.hpp"
40#include "World.hpp"
41#include "ChangeTracker.hpp"
42#include "FormatParser_common.hpp"
43
44using namespace std;
45
46/**
47 * Constructor.
48 */
49FormatParser_common::FormatParser_common(FormatParser_Parameters *_parameters) :
50 Observer("FormatParser_common"),
51 saveStream(NULL)
52{
53 parameters = _parameters;
54 ChangeTracker::getInstance().signOn(this);
55 World::getInstance().signOn(this, World::AtomInserted);
56 World::getInstance().signOn(this, World::AtomRemoved);
57}
58
59/**
60 * Destructor.
61 */
62FormatParser_common::~FormatParser_common()
63{
64 ChangeTracker::getInstance().signOff(this);
65 World::getInstance().signOff(this, World::AtomInserted);
66 World::getInstance().signOff(this, World::AtomRemoved);
67 if (parameters != NULL)
68 delete parameters;
69 // clear id translation maps
70 LocaltoGobalIdMap.clear();
71 GlobaltoLocalIdMap.clear();
72
73 // flush stream properly (is maintained in FormatParserStorage)
74 if (saveStream != NULL) {
75 saveStream->flush();
76 saveStream = NULL;
77 }
78}
79
80/**
81 * Update operation which can be invoked by the observable (which should be the
82 * change tracker here).
83 */
84void FormatParser_common::update(Observable *publisher) {
85 if (saveStream != NULL) { // only store when a saveStream is given
86 std::vector<const atom *> atoms = const_cast<const World &>(World::getInstance()).
87 getAllAtoms();
88 save(saveStream, atoms);
89 }
90}
91
92/**
93 * With this, each format parser is informed about specific changes in the World.
94 */
95void FormatParser_common::recieveNotification(Observable *publisher, Notification_ptr notification) {
96 switch (notification->getChannelNo()) {
97 case World::AtomInserted:
98 AtomInserted(World::getInstance().lastChangedAtomId());
99 break;
100 case World::AtomRemoved:
101 AtomRemoved(World::getInstance().lastChangedAtomId());
102 break;
103 default:
104 ASSERT(0,
105 "FormatParser_common::recieveNotification() - unknown notification "
106 +toString(notification->getChannelNo())+" received.");
107 break;
108 }
109}
110
111/**
112 * The observable can tell when it dies.
113 */
114void FormatParser_common::subjectKilled(Observable *publisher) {}
115
116/**
117 * Sets the output stream for save, so the save() method can be invoked on update
118 * automatically.
119 *
120 * \param ostream where to save the World's state
121 */
122void FormatParser_common::setOstream(ostream* output)
123{
124 saveStream = output;
125}
126
127/** Function to be called when beginning to parse a new file.
128 *
129 * Resets internal translation maps.
130 *
131 */
132void FormatParser_common::resetIdAssociations()
133{
134 LocaltoGobalIdMap.clear();
135 GlobaltoLocalIdMap.clear();
136}
137
138/** Installs an association between a local id from a parsed file and the
139 * global, unique one.
140 *
141 * @param local local atom id
142 * @param global global atom id
143 */
144void FormatParser_common::associateLocaltoGlobalId(const int local, const int global)
145{
146 ASSERT(LocaltoGobalIdMap.count(local) == 0,
147 "FormatParser_common::associateLocaltoGlobalId() - local id "
148 +toString(local)+" is already contained.");
149 ASSERT(GlobaltoLocalIdMap.count(global) == 0,
150 "FormatParser_common::associateLocaltoGlobalId() - global id "
151 +toString(global)+" is already contained.");
152 LocaltoGobalIdMap[local] = global;
153 GlobaltoLocalIdMap[global] = local;
154}
155
156/** Getter for the global id to a given \a local one.
157 *
158 * @param local local atom id
159 * @return global atom id, -1 if unknown
160 */
161int FormatParser_common::getGlobalId(const int local) const
162{
163 IdtoIdMap::const_iterator iter = LocaltoGobalIdMap.find(local);
164 if(iter == LocaltoGobalIdMap.end())
165 return -1;
166 return iter->second;
167}
168
169/** Getter for the local id to a given \a global one.
170 *
171 * @param global global atom id
172 * @return local atom id, -1 if unknown
173 */
174int FormatParser_common::getLocalId(const int global) const
175{
176 IdtoIdMap::const_iterator iter = GlobaltoLocalIdMap.find(global);
177 if(iter == GlobaltoLocalIdMap.end())
178 return -1;
179 return iter->second;
180}
Note: See TracBrowser for help on using the repository browser.