VPTissue Reference Manual
QtViewer.h
Go to the documentation of this file.
1 #ifndef VIEW_QT_VIEWER_H_INCLUDED
2 #define VIEW_QT_VIEWER_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
23 #include "common/QtPreferences.h"
24 
25 #include "sim/event/SimEventType.h"
26 #include "gui/ViewerWindow.h"
27 #include "../mesh_drawer/MeshDrawer.h"
28 
29 #include <QGraphicsScene>
30 #include <functional>
31 #include <memory>
32 #include <string>
33 
34 class QWidget;
35 
36 namespace SimPT_Shell {
37 
42 {
43 public:
44  QtViewer(const std::shared_ptr<SimShell::Ws::MergedPreferences>& p,
45  QWidget*, std::function<void()> on_close);
46 
47  virtual ~QtViewer();
48 
49  template <typename EventType>
50  void Update(const EventType&);
51 
52 private:
54 
55 private:
56  std::shared_ptr<prefs_type> m_preferences;
57  std::shared_ptr<QGraphicsScene> m_canvas;
58  MeshDrawer m_drawer;
59 };
60 
61 template <typename EventType>
62 void QtViewer::Update(const EventType& e)
63 {
64  auto et = e.GetType();
65  auto step = e.GetStep();
66 
67  const bool check = (et == SimPT_Sim::Event::SimEventType::Forced)
68  || (et == SimPT_Sim::Event::SimEventType::Initialized)
69  || (et == SimPT_Sim::Event::SimEventType::Stepped && (m_preferences->m_stride != 0 && (step % m_preferences->m_stride == 0)))
70  || (et == SimPT_Sim::Event::SimEventType::Done && m_preferences->m_stride == 0);
71 
72  if (check) {
73  std::string s = std::string("background-color:") + m_preferences->m_background_color + ";";
74  setStyleSheet(s.c_str());
75  m_canvas->clear();
76  m_drawer.Draw(e.GetSource(), m_canvas.get());
77  }
78 }
79 
80 } // namespace
81 
82 #endif // end_of_include_guard
Graphical viewer showing the mesh at a certain simulation step.
Definition: QtViewer.h:41
Class drawing a simulator/mesh onto a QGraphicsScene.
Definition: MeshDrawer.h:34
Namespace for SimPT shell package.
Definition: Client.cpp:50
Definition for SimEventType.
A window containing visual output of a viewer.
Definition: ViewerWindow.h:34
Interface/Implementation for QtPreferences.
void Draw(std::shared_ptr< SimPT_Sim::SimInterface > sim, QGraphicsScene *scene)
Draws the mesh to QGraphicsScene.
Definition: MeshDrawer.cpp:64
Interface for ViewerWindow.
Preferences observer.
see the online Qt documentation
Listener for SimShell::Event::MergedPreferencesChanged events.