Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenGLQtViewer.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29// G4OpenGLQtViewer : Class to provide WindowsNT specific
30// functionality for OpenGL in GEANT4
31//
32// 30/06/2014 : M.Kelsey : Change QPixmap objects to pointers
33
34#ifndef G4OPENGLQTVIEWER_HH
35#define G4OPENGLQTVIEWER_HH
36
37#include "globals.hh"
38
39#include "G4OpenGLViewer.hh"
41#include "G4AutoLock.hh"
42
43#include <qobject.h>
44#include <qpoint.h>
45#include <qpixmap.h>
46
48class G4UImanager;
49class G4Text;
50class G4UIcommand;
51
52#include <QtGlobal>
53#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
54#include <QGLWidget>
55using G4QGLWidgetType = QGLWidget;
56#else
57#include <QOpenGLWidget>
58using G4QGLWidgetType = QOpenGLWidget;
59#endif
60
61class QDialog;
62class QTextEdit;
63class QContextMenuEvent;
64class QMenu;
65class QImage;
66class QAction;
67class QTabWidget;
68class QMouseEvent;
69class QKeyEvent;
70class QWheelEvent;
71class QProcess;
72class QTime;
73class QElapsedTimer;
74class QVBoxLayout;
75class QPushButton;
76class QSlider;
77class QTreeWidgetItem;
78class QTreeWidget;
79class QColor;
82class QLineEdit;
83class G4UIQt;
84class QTableWidget;
85class QTableWidgetItem;
86class QScrollArea;
87class QSplitter;
88
89class G4OpenGLQtViewer: public QObject, virtual public G4OpenGLViewer {
90
91 Q_OBJECT
92
94 typedef std::vector<PVNodeID> PVPath;
95
96public:
98 virtual ~G4OpenGLQtViewer ();
99#ifdef G4MULTITHREADED
100 // For switching threads in MT mode
101 // Note: the order of calling of MovingToVisSubThread and SwitchToVisSubThread
102 // is undefined, so we have to use mutexes to ensure required information,
103 // namely the vis sub-thread address, is available before moving objects.
104 // To summarise, the order of calling is
105 // DoneWithMasterThread
106 // MovingToVisSubThread ) or ( SwitchToVisSubThread
107 // SwitchToVisSubThread ) ( MovingToVisSubThread
108 // DoneWithVisSubThread
109 // MovingToMasterThread
110 // SwitchToMasterThread
111 // Called on the master thread before starting the vis sub-thread.
112 virtual void DoneWithMasterThread ();
113 // Called on the master thread after starting the vis sub-thread.
114 virtual void MovingToVisSubThread ();
115 // Called on the vis sub-thread when waiting for events.
116 virtual void SwitchToVisSubThread ();
117 // Called on the vis sub-thread when all events have been processed.
118 virtual void DoneWithVisSubThread ();
119 // Called on the vis sub-thread when all events have been processed.
120 // virtual void MovingToMasterThread (); Not used in G4OpenGLQtViewer.
121 // Called on the master thread after the vis sub-thread has terminated.
122 virtual void SwitchToMasterThread ();
123#endif
124
125private:
127 G4OpenGLQtViewer& operator= (const G4OpenGLQtViewer&);
128public:
129 virtual G4bool ReadyToDraw();
130 virtual void updateQWidget()=0;
133 void updatePickInfosWidget(int, int);
134 QString setEncoderPath(QString path);
135 QString getEncoderPath();
136 QString setTempFolderPath(QString path);
137 QString getTempFolderPath();
138 QString setSaveFileName(QString path);
139 QString getSaveFileName();
140 bool isRecording();
141 bool isStopped();
142 bool isPaused();
143 bool isEncoding();
144 bool isWaiting();
145 bool isFailed();
146 void setWaiting();
147 bool isBadEncoder();
148 bool isBadOutput();
149 bool isBadTmp();
150 bool isSuccess();
151 void setBadTmp();
152 void setBadOutput();
153 void setBadEncoder();
154 bool isReadyToEncode();
155 void resetRecording();
156 void encodeVideo();
157 void stopVideo();
158 void saveVideo();
161 void DrawText(const G4Text&);
162 void ResetView ();
163 void addPVSceneTreeElement(const G4String& model,
164 G4PhysicalVolumeModel* pPVModel,
165 int currentPVPOIndex);
166 void addNonPVSceneTreeElement(const G4String& model,
167 int currentPVPOIndex,
168 const std::string& modelDescription,
169 const G4Visible& visible);
170 bool isTouchableVisible(int POindex);
171 void clearTreeWidget();
172 bool exportImage(std::string name="", int width=-1, int height=-1);
173 G4bool GetWindowSize(unsigned int& a_w, unsigned int& a_h);
174 G4bool GetRenderAreaSize(unsigned int& a_w, unsigned int& a_h);
175
176public:
177 void G4MousePressEvent(QMouseEvent *event);
178 void G4wheelEvent (QWheelEvent * event);
179 void G4keyPressEvent (QKeyEvent * event);
180 void G4keyReleaseEvent (QKeyEvent * event);
182 void G4MouseReleaseEvent(QMouseEvent *evnt);
183 void G4MouseMoveEvent(QMouseEvent *event);
184
185protected:
187 virtual void CreateMainWindow (G4QGLWidgetType*,const QString&);
188 void G4manageContextMenuEvent(QContextMenuEvent *e);
189 void rotateQtScene(float, float);
190 void rotateQtSceneToggle(float, float);
191 void moveScene(float, float, float,bool);
192 void FinishView();
193 void updateKeyModifierState(const Qt::KeyboardModifiers&);
195 G4Colour getColorForPoIndex(int poIndex);
196
197 // So that privately accumulated vis attributes modifiers may be
198 // concatenated with the standard vis attributes modifiers for commands
199 // such as /vis/viewer/set/all and /vis/viewer/save...
200 const std::vector<G4ModelingParameters::VisAttributesModifier>*
202 bool isCurrentWidget();
203
204protected:
206 QWidget* fGLWidget;
207 void savePPMToTemp();
209
210#if QT_VERSION < 0x060000
215#endif
216
217 // Flag to indicate that action was initiated by interaction (mouse
218 // click) on the scene tree. It is used and reset in
219 // G4OpenGLStoredQtViewer::CompareForKernelVisit to prevent rebuild
220 // in this case.
222
223private:
224 enum RECORDING_STEP {WAIT,START,PAUSE,CONTINUE,STOP,READY_TO_ENCODE,ENCODING,FAILED,SUCCESS,BAD_ENCODER,BAD_OUTPUT,BAD_TMP,SAVE};
225
226 void createPopupMenu();
227 void createRadioAction(QAction *,QAction *, const std::string&,unsigned int a=1);
228 void rescaleImage(int, int);
229 bool printPDF(const std::string,int,QImage);
230 void showMovieParametersDialog();
231 void initMovieParameters();
232 QString createTempFolder();
233 QString removeTempFolder();
234 void setRecordingStatus(RECORDING_STEP);
235 void setRecordingInfos(const QString&);
236 QString getProcessErrorMsg();
237 QWidget* getParentWidget();
238 bool parseAndInsertInSceneTree(QTreeWidgetItem *,
239 G4PhysicalVolumeModel* pPVModel,
240 unsigned int fullPathIndex,
241 const QString& parentRoot,
242 unsigned int currentIndex,
243 int currentPVPOIndex);
244 void setCheckComponent(QTreeWidgetItem* item,bool check);
245 void createSceneTreeComponent();
246 void createSceneTreeWidget();
247 void createViewerPropertiesWidget();
248 void createPickInfosWidget();
249 bool parseAndCheckVisibility(QTreeWidgetItem * treeNode,int POindex);
250 QTreeWidgetItem* createTreeWidgetItem(const PVPath& fullPath,
251 const QString& name,
252 int copyNb,
253 int POIndex,
254 const QString& logicalName,
255 Qt::CheckState state,
256 QTreeWidgetItem * treeNode,
257 const G4Colour& color);
258 QString getModelShortName(const G4String& modelShortName);
259 void cloneSceneTree(QTreeWidgetItem* rootItem);
260 void changeDepthOnSceneTreeItem(double lookForDepth,double currentDepth,QTreeWidgetItem* item);
261 void updatePositivePoIndexSceneTreeWidgetQuickMap(int POindex,QTreeWidgetItem* item);
262 void changeQColorForTreeWidgetItem(QTreeWidgetItem* item, const QColor&);
263
264 bool isSameSceneTreeElement(QTreeWidgetItem* parentOldItem,QTreeWidgetItem* parentNewItem);
265 void changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(QTreeWidgetItem* subItem);
266 bool isPVVolume(QTreeWidgetItem* item);
267 QTreeWidgetItem* cloneWidgetItem(QTreeWidgetItem* item);
268 void clearSceneTreeSelection(QTreeWidgetItem*);
269 void clearTreeWidgetElements(QTreeWidgetItem* item);
270
271 // Get the tree wigdet item for POindex if exists
272 QTreeWidgetItem* getTreeWidgetItem(int POindex);
273
274 // Get the old tree wigdet item for POindex if exists
275 QTreeWidgetItem* getOldTreeWidgetItem(int POindex);
276
277// parse the scene tree and return a string of status that can be saved
278 std::string parseSceneTreeAndSaveState();
279
280 std::string parseSceneTreeElementAndSaveState(QTreeWidgetItem* item, unsigned int level);
281 QString GetCommandParameterList (const G4UIcommand *aCommand);
282 void changeColorAndTransparency(GLuint index, G4Color color);
283
284 QMenu *fContextMenu;
285 QPoint fLastPos1;
286 QPoint fLastPos2;
287 QPoint fLastPos3;
288 QPoint fLastPickPoint;
289
290 // delta of depth move. This delta is put in % of the scene view
291 G4double fDeltaDepth;
292 // delta of zoom move. This delta is put in % of the scene view
293 G4double fDeltaZoom;
294 // To ensure key event are keep one by one
295 bool fHoldKeyEvent;
296 // To ensure move event are keep one by one
297 bool fHoldMoveEvent;
298 // To ensure rotate event are keep one by one
299 bool fHoldRotateEvent;
300 bool fAutoMove;
301 QString fEncoderPath;
302 QString fTempFolderPath;
303 QString fMovieTempFolderPath;
304 QString fSaveFileName;
305 QString fParameterFileName;
306 QAction *fMouseRotateAction;
307 QAction *fMouseMoveAction;
308 QAction *fMousePickAction;
309 QAction *fMouseZoomInAction;
310 QAction *fMouseZoomOutAction;
311 QAction *fFullScreenOn;
312 QAction *fFullScreenOff;
313 QAction *fDrawingWireframe;
314 QAction *fDrawingLineRemoval;
315 QAction *fDrawingSurfaceRemoval;
316 QAction *fDrawingLineSurfaceRemoval;
317 QAction *fProjectionOrtho;
318 QAction *fProjectionPerspective;
319 G4OpenGLQtMovieDialog* fMovieParametersDialog;
320 RECORDING_STEP fRecordingStep;
321 QProcess *fProcess;
322#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
323 QTime *fLastEventTime;
324#else
325 QElapsedTimer *fLastEventTime;
326#endif
327 int fSpinningDelay;
328 int fNbMaxFramesPerSec;
329 float fNbMaxAnglePerSec;
330 int fLaunchSpinDelay;
331 QWidget* fUISceneTreeWidget;
332 QWidget* fUIViewerPropertiesWidget;
333 QWidget* fUIPickInfosWidget;
334 bool fNoKeyPress;
335 bool fAltKeyPress;
336 bool fControlKeyPress;
337 bool fShiftKeyPress;
338 bool fBatchMode;
339 bool fCheckSceneTreeComponentSignalLock;
340 bool fViewerPropertiesTableWidgetIsInit;
341 QTreeWidget* fSceneTreeComponentTreeWidget;
342 // This is only use to hold the old "expand" value, see file:///Developer/Documentation/Qt/html/qtreewidgetitem.html#setExpanded
343 QWidget* fSceneTreeWidget;
344 bool fPVRootNodeCreate;
345 QLineEdit* fFilterOutput;
346 QString fFileSavePath;
347 int fNbRotation ;
348 int fTimeRotation;
349 QString fTouchableVolumes;
350 QDialog* fShortcutsDialog;
351 QTableWidget *fViewerPropertiesTableWidget;
352 QWidget* fPickInfosWidget;
353 QScrollArea* fPickInfosScrollArea;
354 int fTreeWidgetInfosIgnoredCommands;
355 QPushButton * fSceneTreeButtonApply;
356 QTextEdit *fShortcutsDialogInfos;
357 QSlider* fSceneTreeDepthSlider;
358 std::map <int, PVPath > fTreeItemModels;
359 std::map <int, PVPath > fOldTreeItemModels;
360
361 // quick scene tree map
362 std::map <int, QTreeWidgetItem*> fPositivePoIndexSceneTreeWidgetQuickMap;
363 // old scene tree map
364 std::map <int, QTreeWidgetItem*> fOldPositivePoIndexSceneTreeWidgetQuickMap;
365 std::vector <QTreeWidgetItem*> fOldNullPoIndexSceneTreeWidgetQuickVector;
366 // old vis attr color map
367 std::map <int, QColor> fOldVisAttrColorMap;
368
369 unsigned int fSceneTreeDepth;
370 QTreeWidgetItem* fModelShortNameItem;
371 int fNumber;
372 int fMaxPOindexInserted;
373
374 // quick map index to find next item
375 std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIterator;
376 std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIteratorEnd;
377
378 // quick map index to find next item
379 std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIterator;
380 std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIteratorEnd;
381
382 // icons
383 QPixmap* fTreeIconOpen;
384 QPixmap* fTreeIconClosed;
385 QPixmap* fSearchIcon;
386
387 int fLastExportSliderValue;
388 G4Color fLastHighlightColor;
389 GLuint fLastHighlightName;
390 bool fIsDeleting;
391
392#ifdef G4MULTITHREADED
393 QThread* fQGLContextVisSubThread;
394 QThread* fQGLContextMainThread;
395#endif
396
397public Q_SLOTS :
398 void startPauseVideo();
399
400protected Q_SLOTS :
402
403private Q_SLOTS :
404 void actionSaveImage();
405 void actionChangeBackgroundColor();
406 void actionChangeTextColor();
407 void actionChangeDefaultColor();
408 void actionMovieParameters();
409
410 void showShortcuts();
411 void toggleMouseAction(int);
412 void toggleSurfaceAction(int);
413 void toggleProjection(bool);
414 void toggleTransparency(bool);
415 void toggleAntialiasing(bool);
416 void toggleHaloing(bool);
417 void toggleAux(bool);
418 void toggleHiddenMarkers(bool);
419 void toggleFullScreen(bool);
420 void processEncodeFinished();
421 void processLookForFinished();
422 void processEncodeStdout();
423 void sceneTreeComponentItemChanged(QTreeWidgetItem* item, int id);
424 void toggleSceneTreeComponentPickingCout(int);
425 void togglePicking();
426 void currentTabActivated(int);
427
428 // action trigger by a click on a component scene tree
429 void sceneTreeComponentSelected();
430 void changeDepthInSceneTree(int);
431 void changeSearchSelection();
432 void changeColorAndTransparency(QTreeWidgetItem* item,int val);
433 void tableWidgetViewerSetItemChanged(QTableWidgetItem *);
434};
435
436#endif
G4Colour G4Color
Definition G4Color.hh:41
QOpenGLWidget G4QGLWidgetType
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
void G4MouseReleaseEvent(QMouseEvent *evnt)
virtual G4bool ReadyToDraw()
void rotateQtSceneToggle(float, float)
void G4MouseMoveEvent(QMouseEvent *event)
void G4keyPressEvent(QKeyEvent *event)
void updateViewerPropertiesTableWidget()
void addNonPVSceneTreeElement(const G4String &model, int currentPVPOIndex, const std::string &modelDescription, const G4Visible &visible)
void G4MousePressEvent(QMouseEvent *event)
void G4wheelEvent(QWheelEvent *event)
G4OpenGLQtViewer(G4OpenGLSceneHandler &scene)
bool isTouchableVisible(int POindex)
void moveScene(float, float, float, bool)
void G4manageContextMenuEvent(QContextMenuEvent *e)
G4bool GetWindowSize(unsigned int &a_w, unsigned int &a_h)
void rotateQtScene(float, float)
bool exportImage(std::string name="", int width=-1, int height=-1)
void updateToolbarAndMouseContextMenu()
void CreateGLQtContext()
void updateKeyModifierState(const Qt::KeyboardModifiers &)
void G4keyReleaseEvent(QKeyEvent *event)
virtual void CreateMainWindow(G4QGLWidgetType *, const QString &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
G4Colour getColorForPoIndex(int poIndex)
void updatePickInfosWidget(int, int)
virtual ~G4OpenGLQtViewer()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void DrawText(const G4Text &)
QString setEncoderPath(QString path)
G4bool GetRenderAreaSize(unsigned int &a_w, unsigned int &a_h)
virtual void updateQWidget()=0
QString setSaveFileName(QString path)
void addPVSceneTreeElement(const G4String &model, G4PhysicalVolumeModel *pPVModel, int currentPVPOIndex)
const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers() const
QString setTempFolderPath(QString path)
friend class G4OpenGLSceneHandler
G4OpenGLViewer(G4OpenGLSceneHandler &scene)
virtual void DoneWithMasterThread()
Definition G4VViewer.hh:124
virtual void SwitchToMasterThread()
Definition G4VViewer.hh:139
virtual void SwitchToVisSubThread()
Definition G4VViewer.hh:130
virtual void MovingToVisSubThread()
Definition G4VViewer.hh:127
virtual void DoneWithVisSubThread()
Definition G4VViewer.hh:133