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