Geant4 11.2.2
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 // In MT mode these functions are called in the following order for each run:
101 // Called on the master thread before starting the vis sub-thread.
102 virtual void DoneWithMasterThread ();
103 // Called on the master thread after starting the vis sub-thread.
104 virtual void MovingToVisSubThread ();
105 // Called on the vis sub-thread when waiting for events.
106 virtual void SwitchToVisSubThread ();
107 // Called on the vis sub-thread when all events have been processed.
108 virtual void DoneWithVisSubThread ();
109 // Called on the vis sub-thread when all events have been processed.
110 // virtual void MovingToMasterThread (); Not used in G4OpenGLQtViewer.
111 // Called on the master thread after the vis sub-thread has terminated.
112 virtual void SwitchToMasterThread ();
113#endif
114
115private:
117 G4OpenGLQtViewer& operator= (const G4OpenGLQtViewer&);
118public:
119 virtual void updateQWidget()=0;
122 void updatePickInfosWidget(int, int);
123 QString setEncoderPath(QString path);
124 QString getEncoderPath();
125 QString setTempFolderPath(QString path);
126 QString getTempFolderPath();
127 QString setSaveFileName(QString path);
128 QString getSaveFileName();
129 bool isRecording();
130 bool isStopped();
131 bool isPaused();
132 bool isEncoding();
133 bool isWaiting();
134 bool isFailed();
135 void setWaiting();
136 bool isBadEncoder();
137 bool isBadOutput();
138 bool isBadTmp();
139 bool isSuccess();
140 void setBadTmp();
141 void setBadOutput();
142 void setBadEncoder();
143 bool isReadyToEncode();
144 void resetRecording();
145 void encodeVideo();
146 void stopVideo();
147 void saveVideo();
150 void DrawText(const G4Text&);
151 void ResetView ();
152 void addPVSceneTreeElement(const G4String& model,
153 G4PhysicalVolumeModel* pPVModel,
154 int currentPVPOIndex);
155 void addNonPVSceneTreeElement(const G4String& model,
156 int currentPVPOIndex,
157 const std::string& modelDescription,
158 const G4Visible& visible);
159 bool isTouchableVisible(int POindex);
160 void clearTreeWidget();
161 bool exportImage(std::string name="", int width=-1, int height=-1);
162
163public:
164 void G4MousePressEvent(QMouseEvent *event);
165 void G4wheelEvent (QWheelEvent * event);
166 void G4keyPressEvent (QKeyEvent * event);
167 void G4keyReleaseEvent (QKeyEvent * event);
169 void G4MouseReleaseEvent(QMouseEvent *evnt);
170 void G4MouseMoveEvent(QMouseEvent *event);
171
172protected:
174 virtual void CreateMainWindow (G4QGLWidgetType*,const QString&);
175 void G4manageContextMenuEvent(QContextMenuEvent *e);
176 void rotateQtScene(float, float);
177 void rotateQtSceneToggle(float, float);
178 void moveScene(float, float, float,bool);
179 void FinishView();
180 void updateKeyModifierState(const Qt::KeyboardModifiers&);
182 G4Colour getColorForPoIndex(int poIndex);
183
184 // So that privately accumulated vis attributes modifiers may be
185 // concatenated with the standard vis attributes modifiers for commands
186 // such as /vis/viewer/set/all and /vis/viewer/save...
187 const std::vector<G4ModelingParameters::VisAttributesModifier>*
189 bool isCurrentWidget();
190
191protected:
193 QWidget* fGLWidget;
194 void savePPMToTemp();
196
201
202 // Flag to indicate that action was initiated by interaction (mouse
203 // click) on the scene tree. It is used and reset in
204 // G4OpenGLStoredQtViewer::CompareForKernelVisit to prevent rebuild
205 // in this case.
207
208private:
209 enum RECORDING_STEP {WAIT,START,PAUSE,CONTINUE,STOP,READY_TO_ENCODE,ENCODING,FAILED,SUCCESS,BAD_ENCODER,BAD_OUTPUT,BAD_TMP,SAVE};
210
211 void createPopupMenu();
212 void createRadioAction(QAction *,QAction *, const std::string&,unsigned int a=1);
213 void rescaleImage(int, int);
214 bool printPDF(const std::string,int,QImage);
215 void showMovieParametersDialog();
216 void initMovieParameters();
217 QString createTempFolder();
218 QString removeTempFolder();
219 void setRecordingStatus(RECORDING_STEP);
220 void setRecordingInfos(const QString&);
221 QString getProcessErrorMsg();
222 QWidget* getParentWidget();
223 bool parseAndInsertInSceneTree(QTreeWidgetItem *,
224 G4PhysicalVolumeModel* pPVModel,
225 unsigned int fullPathIndex,
226 const QString& parentRoot,
227 unsigned int currentIndex,
228 int currentPVPOIndex);
229 void setCheckComponent(QTreeWidgetItem* item,bool check);
230 void createSceneTreeComponent();
231 void createSceneTreeWidget();
232 void createViewerPropertiesWidget();
233 void createPickInfosWidget();
234 bool parseAndCheckVisibility(QTreeWidgetItem * treeNode,int POindex);
235 QTreeWidgetItem* createTreeWidgetItem(const PVPath& fullPath,
236 const QString& name,
237 int copyNb,
238 int POIndex,
239 const QString& logicalName,
240 Qt::CheckState state,
241 QTreeWidgetItem * treeNode,
242 const G4Colour& color);
243 QString getModelShortName(const G4String& modelShortName);
244 void cloneSceneTree(QTreeWidgetItem* rootItem);
245 void changeDepthOnSceneTreeItem(double lookForDepth,double currentDepth,QTreeWidgetItem* item);
246 void updatePositivePoIndexSceneTreeWidgetQuickMap(int POindex,QTreeWidgetItem* item);
247 void changeQColorForTreeWidgetItem(QTreeWidgetItem* item, const QColor&);
248
249 bool isSameSceneTreeElement(QTreeWidgetItem* parentOldItem,QTreeWidgetItem* parentNewItem);
250 void changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(QTreeWidgetItem* subItem);
251 bool isPVVolume(QTreeWidgetItem* item);
252 QTreeWidgetItem* cloneWidgetItem(QTreeWidgetItem* item);
253 void clearSceneTreeSelection(QTreeWidgetItem*);
254 void clearTreeWidgetElements(QTreeWidgetItem* item);
255
256 // Get the tree wigdet item for POindex if exists
257 QTreeWidgetItem* getTreeWidgetItem(int POindex);
258
259 // Get the old tree wigdet item for POindex if exists
260 QTreeWidgetItem* getOldTreeWidgetItem(int POindex);
261
262// parse the scene tree and return a string of status that can be saved
263 std::string parseSceneTreeAndSaveState();
264
265 std::string parseSceneTreeElementAndSaveState(QTreeWidgetItem* item, unsigned int level);
266 QString GetCommandParameterList (const G4UIcommand *aCommand);
267 void changeColorAndTransparency(GLuint index, G4Color color);
268
269#ifdef G4MULTITHREADED
270 inline void SetQGLContextVisSubThread(QThread *th) {
271 fQGLContextVisSubThread = th;
272 }
273 inline void SetQGLContextMainThread(QThread *th) {
274 fQGLContextMainThread = th;
275 }
276#endif
277
278 QMenu *fContextMenu;
279 QPoint fLastPos1;
280 QPoint fLastPos2;
281 QPoint fLastPos3;
282 QPoint fLastPickPoint;
283
284 // delta of depth move. This delta is put in % of the scene view
285 G4double fDeltaDepth;
286 // delta of zoom move. This delta is put in % of the scene view
287 G4double fDeltaZoom;
288 // To ensure key event are keep one by one
289 bool fHoldKeyEvent;
290 // To ensure move event are keep one by one
291 bool fHoldMoveEvent;
292 // To ensure rotate event are keep one by one
293 bool fHoldRotateEvent;
294 bool fAutoMove;
295 QString fEncoderPath;
296 QString fTempFolderPath;
297 QString fMovieTempFolderPath;
298 QString fSaveFileName;
299 QString fParameterFileName;
300 QAction *fMouseRotateAction;
301 QAction *fMouseMoveAction;
302 QAction *fMousePickAction;
303 QAction *fMouseZoomInAction;
304 QAction *fMouseZoomOutAction;
305 QAction *fFullScreenOn;
306 QAction *fFullScreenOff;
307 QAction *fDrawingWireframe;
308 QAction *fDrawingLineRemoval;
309 QAction *fDrawingSurfaceRemoval;
310 QAction *fDrawingLineSurfaceRemoval;
311 QAction *fProjectionOrtho;
312 QAction *fProjectionPerspective;
313 G4OpenGLQtMovieDialog* fMovieParametersDialog;
314 RECORDING_STEP fRecordingStep;
315 QProcess *fProcess;
316#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
317 QTime *fLastEventTime;
318#else
319 QElapsedTimer *fLastEventTime;
320#endif
321 int fSpinningDelay;
322 int fNbMaxFramesPerSec;
323 float fNbMaxAnglePerSec;
324 int fLaunchSpinDelay;
325 QWidget* fUISceneTreeWidget;
326 QWidget* fUIViewerPropertiesWidget;
327 QWidget* fUIPickInfosWidget;
328 bool fNoKeyPress;
329 bool fAltKeyPress;
330 bool fControlKeyPress;
331 bool fShiftKeyPress;
332 bool fBatchMode;
333 bool fCheckSceneTreeComponentSignalLock;
334 bool fViewerPropertiesTableWidgetIsInit;
335 QTreeWidget* fSceneTreeComponentTreeWidget;
336 // This is only use to hold the old "expand" value, see file:///Developer/Documentation/Qt/html/qtreewidgetitem.html#setExpanded
337 QWidget* fSceneTreeWidget;
338 bool fPVRootNodeCreate;
339 QLineEdit* fFilterOutput;
340 QString fFileSavePath;
341 int fNbRotation ;
342 int fTimeRotation;
343 QString fTouchableVolumes;
344 QDialog* fShortcutsDialog;
345 QTableWidget *fViewerPropertiesTableWidget;
346 QWidget* fPickInfosWidget;
347 QScrollArea* fPickInfosScrollArea;
348 int fTreeWidgetInfosIgnoredCommands;
349 QPushButton * fSceneTreeButtonApply;
350 QTextEdit *fShortcutsDialogInfos;
351 QSlider* fSceneTreeDepthSlider;
352 std::map <int, PVPath > fTreeItemModels;
353 std::map <int, PVPath > fOldTreeItemModels;
354
355 // quick scene tree map
356 std::map <int, QTreeWidgetItem*> fPositivePoIndexSceneTreeWidgetQuickMap;
357 // old scene tree map
358 std::map <int, QTreeWidgetItem*> fOldPositivePoIndexSceneTreeWidgetQuickMap;
359 std::vector <QTreeWidgetItem*> fOldNullPoIndexSceneTreeWidgetQuickVector;
360 // old vis attr color map
361 std::map <int, QColor> fOldVisAttrColorMap;
362
363 unsigned int fSceneTreeDepth;
364 QTreeWidgetItem* fModelShortNameItem;
365 int fNumber;
366 int fMaxPOindexInserted;
367
368 // quick map index to find next item
369 std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIterator;
370 std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIteratorEnd;
371
372 // quick map index to find next item
373 std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIterator;
374 std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIteratorEnd;
375
376 // icons
377 QPixmap* fTreeIconOpen;
378 QPixmap* fTreeIconClosed;
379 QPixmap* fSearchIcon;
380
381 int fLastExportSliderValue;
382 G4Color fLastHighlightColor;
383 GLuint fLastHighlightName;
384 bool fIsDeleting;
385
386#ifdef G4MULTITHREADED
387 QThread* fQGLContextVisSubThread;
388 QThread* fQGLContextMainThread;
389#endif
390
391 // safe to use in serial mode
392 G4AutoLock* lWaitForVisSubThreadQtOpenGLContextInitialized;
393 G4AutoLock* lWaitForVisSubThreadQtOpenGLContextMoved;
394
395public Q_SLOTS :
396 void startPauseVideo();
397
398protected Q_SLOTS :
400
401private Q_SLOTS :
402 void actionSaveImage();
403 void actionChangeBackgroundColor();
404 void actionChangeTextColor();
405 void actionChangeDefaultColor();
406 void actionMovieParameters();
407
408 void showShortcuts();
409 void toggleMouseAction(int);
410 void toggleSurfaceAction(int);
411 void toggleProjection(bool);
412 void toggleTransparency(bool);
413 void toggleAntialiasing(bool);
414 void toggleHaloing(bool);
415 void toggleAux(bool);
416 void toggleHiddenMarkers(bool);
417 void toggleFullScreen(bool);
418 void processEncodeFinished();
419 void processLookForFinished();
420 void processEncodeStdout();
421 void sceneTreeComponentItemChanged(QTreeWidgetItem* item, int id);
422 void toggleSceneTreeComponentPickingCout(int);
423 void togglePicking();
424 void currentTabActivated(int);
425
426 // action trigger by a click on a component scene tree
427 void sceneTreeComponentSelected();
428 void changeDepthInSceneTree(int);
429 void changeSearchSelection();
430 void changeColorAndTransparency(QTreeWidgetItem* item,int val);
431 void tableWidgetViewerSetItemChanged(QTableWidgetItem *);
432};
433
434#endif
QOpenGLWidget G4QGLWidgetType
double G4double
Definition G4Types.hh:83
void G4MouseReleaseEvent(QMouseEvent *evnt)
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)
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)
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)