source: src/UIElements/Qt4/InstanceBoard/ObservedMaximumAtomTrajectorySize.cpp

Candidate_v1.7.1 stable v1.7.1
Last change on this file was c8cb0d, checked in by Frederik Heber <frederik.heber@…>, 5 days ago

Streamlines channel creation in Observables.

  • CodePatterns is now version 1.3.4.
  • we no longer need to add the channels manually in the cstor of a class that derives from Observable. Instead, we just need to pass the maximum number of channels (as they are typically enumerated anyway) and they are generated and added.
  • added mutex protection when inserting.
  • adjusted class Relay to forward similar convenience cstors.
  • adjusted all call sites in molecuilder.
  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2025 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 * ObservedMaximumAtomTrajectorySize.cpp
25 *
26 * Created on: Nov 10, 2025
27 * Author: heber
28 */
29
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "ObservedMaximumAtomTrajectorySize.hpp"
37
38//#include "CodePatterns/MemDebug.hpp"
39
40#include "CodePatterns/Assert.hpp"
41#include "CodePatterns/Log.hpp"
42#include "CodePatterns/Observer/Channels.hpp"
43#include "CodePatterns/Observer/Notification.hpp"
44#include "CodePatterns/Singleton_impl.hpp"
45
46#include "Atom/atom.hpp"
47#include "Atom/AtomObserver.hpp"
48
49ObservedMaximumAtomTrajectorySize::ObservedMaximumAtomTrajectorySize() :
50 Observable("ObservedMaximumAtomTrajectorySize", NotificationType_MAX),
51 maximumAtomTrajectorySize(0),
52 atomObserver_signedOn(false)
53{
54 AtomObserver::getInstance().signOn(this, AtomObservable::TrajectoryChanged);
55 atomObserver_signedOn = true;
56}
57
58ObservedMaximumAtomTrajectorySize::~ObservedMaximumAtomTrajectorySize()
59{
60 if (atomObserver_signedOn) {
61 AtomObserver::getInstance().signOff(this, AtomObservable::TrajectoryChanged);
62 }
63}
64
65const int ObservedMaximumAtomTrajectorySize::GetMaximumAtomTrajectorySize() const
66{
67 return maximumAtomTrajectorySize;
68}
69
70void ObservedMaximumAtomTrajectorySize::update(Observable *publisher)
71{
72 ASSERT(0, "ObservedMaximumAtomTrajectorySize::update() - we are not subscribed to general updates.");
73}
74
75void ObservedMaximumAtomTrajectorySize::subjectKilled(Observable *publisher)
76{
77 if (static_cast<AtomObserver *>(publisher) == AtomObserver::getPointer()) {
78 atomObserver_signedOn = false;
79 }
80}
81
82void ObservedMaximumAtomTrajectorySize::recieveNotification(Observable *publisher, Notification_ptr notification)
83{
84
85 const atom *walker = dynamic_cast<const atom *>(publisher);
86 if (walker != NULL) {
87 switch (notification->getChannelNo()) {
88 case AtomObservable::TrajectoryChanged:
89 {
90 OBSERVE;
91 NOTIFY(MaximumChanged);
92 LOG(3, "DEBUG: ObservedMaximumAtomTrajectorySize got TrajectoryChanged for atom " << walker->getId());
93 maximumAtomTrajectorySize = walker->getTrajectorySize()-1;
94 break;
95 }
96 default:
97 {
98 ASSERT(0, "ObservedMaximumAtomTrajectorySize::recieveNotification() - received unsubscribed notification channel.");
99 break;
100 }
101 }
102 } else {
103 ASSERT(0, "ObservedMaximumAtomTrajectorySize::recieveNotification() - received notification from unsubscribed source.");
104 }
105}
106
107CONSTRUCT_SINGLETON(ObservedMaximumAtomTrajectorySize)
Note: See TracBrowser for help on using the repository browser.