source: src/UIElements/Views/Qt4/QtTimeLine.cpp@ 8c5e2a

Candidate_v1.6.1 ChemicalSpaceEvaluator Gui_displays_atomic_force_velocity PythonUI_with_named_parameters TremoloParser_IncreasedPrecision
Last change on this file since 8c5e2a was 8c5e2a, checked in by Frederik Heber <frederik.heber@…>, 7 years ago

FIX: QTimeLine now exactly controls world time.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 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 * QtTimeLine.cpp
25 *
26 * Created on: Jul 11, 2013
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35// make sure Qt includes come before MemDebug
36#include "QtTimeLine.hpp"
37
38//#include "CodePatterns/MemDebug.hpp"
39
40#include "CodePatterns/Assert.hpp"
41#include "CodePatterns/Log.hpp"
42
43#include "Actions/WorldAction/SetWorldTimeAction.hpp"
44#include "Atom/atom.hpp"
45#include "Atom/AtomObserver.hpp"
46#include "WorldTime.hpp"
47
48QtTimeLine::QtTimeLine(QWidget * _parent) :
49 QSlider (Qt::Horizontal, _parent),
50 Observer("QtTimeLine"),
51 atomobserver_enlisted(false),
52 worldtime_enlisted(false)
53{
54 // set initial values
55 QSlider::setMinimum(0);
56 QSlider::setMaximum(0);
57 QSlider::setValue(0);
58 QSlider::setTickInterval(1);
59 QSlider::setSingleStep(1);
60 QSlider::setTracking(true);
61
62 // sign on to observable
63 WorldTime::getInstance().signOn(this, WorldTime::TimeChanged);
64 worldtime_enlisted = true;
65 AtomObserver::getInstance().signOn(this, AtomObservable::TrajectoryChanged);
66 atomobserver_enlisted = true;
67
68 // connect to QSlider's valueChanged() signal
69 bool result = connect(this,SIGNAL(valueChanged(int)),this,SLOT(StepUpdate(int)));
70 if (!result)
71 ELOG(0, "Could not connect to QSlider::valueChanged.");
72}
73
74QtTimeLine::~QtTimeLine()
75{
76 if (worldtime_enlisted)
77 WorldTime::getInstance().signOff(this, WorldTime::TimeChanged);
78 if (atomobserver_enlisted)
79 AtomObserver::getInstance().signOff(this, AtomObservable::TrajectoryChanged);
80}
81
82void QtTimeLine::paintEvent(QPaintEvent * event)
83{
84 boost::recursive_mutex::scoped_lock lock(refill_mutex);
85
86 QSlider::paintEvent(event);
87}
88
89void QtTimeLine::subjectKilled(Observable *publisher)
90{
91 // as long as we are enlisted to only one channel, we have nothing to worry.
92 // Otherwise we should also signOn to global changes for subjectKilled() and
93 // sign off from the channels
94 if (static_cast<AtomObserver *>(publisher) == AtomObserver::getPointer()) {
95 atomobserver_enlisted = false;
96 } else if (static_cast<WorldTime *>(publisher) == WorldTime::getPointer()) {
97 worldtime_enlisted = false;
98 }
99}
100
101void QtTimeLine::update(Observable *publisher)
102{
103 ELOG(0, "We are not enlisted for general updates.");
104}
105
106void QtTimeLine::recieveNotification(Observable *publisher, Notification_ptr notification)
107{
108 boost::recursive_mutex::scoped_lock lock(refill_mutex);
109
110 if (static_cast<WorldTime *>(publisher) == WorldTime::getPointer()) {
111 const int timestep = WorldTime::getTime();
112 // check whether we are beyond maximum
113 if (timestep > QSlider::maximum())
114 QSlider::setMaximum(timestep);
115 // set slider position to new time step
116 QSlider::setValue( timestep );
117 } else
118 //if (static_cast<AtomObserver *>(publisher) == AtomObserver::getPointer())
119 {
120 // calculate max trajectory (need dynamic_cast due to virtual base)
121 const atom *_atom = dynamic_cast<const atom *>(publisher);
122 const int MaxTrajectory = _atom->getTrajectorySize()-1;
123 if (MaxTrajectory > QSlider::maximum())
124 QSlider::setMaximum(MaxTrajectory);
125 }
126}
127
128void QtTimeLine::StepUpdate(int position)
129{
130 boost::recursive_mutex::scoped_lock lock(refill_mutex);
131
132 if (WorldTime::getTime() != (unsigned int)position)
133 MoleCuilder::WorldSetWorldTime(position);
134}
Note: See TracBrowser for help on using the repository browser.