CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
controller.h
1 /****************************************************************************
2  * Copyright (c) 2014, Joel Kivelä, Erkki Koskenkorva, Oskari Leppäaho,
3  * Mika Lehtinen and Petri Partanen.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ****************************************************************************/
30 #ifndef CONTROLLER_H
31 #define CONTROLLER_H
32 
33 #include <map>
34 
35 #include <QDir>
36 #include <QObject>
37 #include <QSettings>
38 
39 #include "analysiscontroller.h"
40 #include "userinterface.h"
41 #include "metadata.h"
42 
43 namespace cavapa_gui
44 {
45 
50 enum class State
51 {
52  Start,
53  NewMeasurement,
54  CalculationInProgress,
55  CalculationCancelled,
56  CalculationStopped,
57  CalculationCompleted,
58  CalculationPaused,
59  MeasurementOpened,
60 };
61 
68 class Controller: public QObject
69 {
70  Q_OBJECT
71 private:
72  AnalysisController analysisCtrl;
73  GeneralSettings generalSettings;
74  std::vector<UserInterface*> interfaces;
75  std::vector<SourceID> activeSources;
76  std::map<SourceID, SourceSettings> allSourceSettings;
77  std::vector<cavapa::CalibrationPoint> calibPoints;
78  Metadata metadata;
79  static QString dateFormat;
80  State state = State::Start;
81 
87  inline void applySourceSettings(const SourceSettings& settings,
88  SourceID source);
89 
93  void cancelCalculation();
94 
99  inline QDir getResultsDirectory() const;
100 
105  inline UserInterface* getSenderAsInterface() const;
106 
111  std::string getUserName();
112 
117  int loadCameras();
118 
123  bool loadMetadataVideos();
124 
130  bool loadSavedVideos();
131 
137  void loadSource(SourceID source);
138 
142  void removeAllSources();
143 
149  bool removeSource(SourceID source);
150 
154  void saveResults();
155 
163  template<typename... T>
164  bool stateIsAnyOf(T... states)
165  {
166  for (auto s :
167  {
168  states...
169  })
170  {
171  if (s == state)
172  {
173  return true;
174  }
175  }
176  return false;
177  }
178 
179 private slots:
184  void calculationCancelRequested();
185 
189  void calculationCompleted();
190 
195  void calculationContinueRequested();
196 
201  void calculationPauseRequested();
202 
207  void calculationStartRequested();
208 
213  void calculationStopRequested();
214 
219  void calibrationPointsReady(
220  const std::vector<cavapa::CalibrationPoint>& points);
221 
227  void exportRequested(const ExportOptions& options);
228 
233  void generalSettingsChanged(const GeneralSettings& settings);
234 
240  void graphPositionSelected(FrameTime time);
241 
245  void interfaceClosed();
246 
252  void locationChanged(int x, int y);
253 
260  void markersReady(const std::vector<GraphMarker>& markers);
261 
267  void metadataOpened(const std::string& path);
268 
274  void metadataReady(const Metadata& metadata);
275 
280  void newMeasurementRequested();
281 
287  void openMeasurementRequested(const std::string& path);
288 
293  void redoMeasurementRequested();
294 
298  void refreshRequested();
299 
307  void showMessage(const std::string& message,
308  ErrorLevel level = ErrorLevel::INFO);
309 
316  void sizeChanged(int width, int height, bool fullscreen);
317 
323  void sourceAddRequested(const std::string& path);
324 
329  void sourcePauseRequested(SourceID source);
330 
335  void sourcePlayRequested(SourceID source);
336 
342  void sourceRemoveRequested(SourceID source);
343 
350  void sourceSeekRequested(SourceID source, FrameTime position);
351 
358  void sourceSettingsChanged(SourceID source,
359  const SourceSettings& settings);
360 
366  void sourceStepForward(SourceID source);
367 
373  void sourceStepBackward(SourceID source);
374 
382  void statisticsRequested(FrameTime start, FrameTime stop, int points);
383 
390  void updated(const std::vector<FrameCapture>& frames,
391  const FrameStats& statistics);
392 
393 public:
397  Controller();
398 
403  void addInterface(UserInterface* cInterface);
404 
408  void startInterfaces();
409 
410 public slots:
416  void aboutToQuitApp();
417 
421  void run();
422 
423 signals:
427  void finished();
428 };
429 } //namespace cavapa_gui
430 
431 #endif // CONTROLLER_H
void aboutToQuitApp()
Warns the object for application termination.
Definition: controller.cpp:83
void finished()
Emitted when all the interfaces have been closed.
State
The State enum lists the possible application main states when performing a measurement.
Definition: controller.h:50
Structure for holding frame statistics on activity.
Definition: common.h:285
Controller()
Constructs the Controller object.
Definition: controller.cpp:55
unsigned int SourceID
Used to indicate unique source ID-numbers.
Definition: common.h:229
void addInterface(UserInterface *cInterface)
Adds a new interface to the controller.
Definition: controller.cpp:89
The Controller class handles the messages between UserInterface and AnalysisController.
Definition: controller.h:68
Represents the metadata associated with a measurement.
Definition: metadata.h:91
Base class of the CAVAPA calculations.
Definition: analysiscontroller.h:70
void startInterfaces()
Starts all the user interfaces.
Definition: controller.cpp:1172
Represents the settings for a video source.
Definition: sourcesettings.h:46
void run()
Launches all the registered interfaces.
Definition: controller.cpp:1204
Represents the general settings of the application.
Definition: generalsettings.h:43
std::uint64_t FrameTime
Used to store milliseconds interval in frame times.
Definition: common.h:138
The structure holds CSV export options.
Definition: common.h:183
ErrorLevel
Error level indicator.
Definition: common.h:77
The UserInterface class defines the methods and signals that a user interface needs to have...
Definition: userinterface.h:52