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