Geant4-11
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:
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:
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);
210 void initMovieParameters();
211 QString createTempFolder();
212 QString removeTempFolder();
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);
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);
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
273 QPoint fLastPos1;
274 QPoint fLastPos2;
275 QPoint fLastPos3;
277
278 // delta of depth move. This delta is put in % of the scene view
280 // delta of zoom move. This delta is put in % of the scene view
282 // To ensure key event are keep one by one
284 // To ensure move event are keep one by one
286 // To ensure rotate event are keep one by one
309 QProcess *fProcess;
310#if QT_VERSION < 0x050e00
312#else
313 QElapsedTimer *fLastEventTime;
314#endif
330 // This is only use to hold the old "expand" value, see file:///Developer/Documentation/Qt/html/qtreewidgetitem.html#setExpanded
333 QLineEdit* fFilterOutput;
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;
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
378 QPixmap* fSearchIcon;
379
384
385#ifdef G4MULTITHREADED
386 QThread* fQGLContextVisSubThread;
387 QThread* fQGLContextMainThread;
388#endif
389
390 // safe to use in serial mode
393
394public Q_SLOTS :
395 void startPauseVideo();
396
397protected Q_SLOTS :
399
400private Q_SLOTS :
401 void actionSaveImage();
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);
419 void processEncodeStdout();
420 void sceneTreeComponentItemChanged(QTreeWidgetItem* item, int id);
422 void togglePicking();
423 void currentTabActivated(int);
424
425 // action trigger by a click on a component scene tree
427 void changeDepthInSceneTree(int);
429 void changeColorAndTransparency(QTreeWidgetItem* item,int val);
430 void tableWidgetViewerSetItemChanged(QTableWidgetItem *);
431};
432
433#endif
double G4double
Definition: G4Types.hh:83
void toggleFullScreen(bool)
void toggleSurfaceAction(int)
QTreeWidgetItem * getOldTreeWidgetItem(int POindex)
void G4MouseReleaseEvent(QMouseEvent *evnt)
std::map< int, QTreeWidgetItem * >::const_iterator fOldLastSceneTreeWidgetAskForIteratorEnd
QWidget * fUISceneTreeWidget
QTreeWidget * fSceneTreeComponentTreeWidget
bool parseAndCheckVisibility(QTreeWidgetItem *treeNode, int POindex)
G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID
QString getProcessErrorMsg()
std::map< int, QColor > fOldVisAttrColorMap
void changeColorAndTransparency(GLuint index, G4Color color)
QLineEdit * fFilterOutput
RECORDING_STEP fRecordingStep
bool isPVVolume(QTreeWidgetItem *item)
std::map< int, PVPath > fOldTreeItemModels
QTreeWidgetItem * createTreeWidgetItem(const PVPath &fullPath, const QString &name, int copyNb, int POIndex, const QString &logicalName, Qt::CheckState state, QTreeWidgetItem *treeNode, const G4Colour &color)
void rotateQtSceneToggle(float, float)
QAction * fMouseRotateAction
void G4MouseMoveEvent(QMouseEvent *event)
std::map< int, QTreeWidgetItem * >::const_iterator fLastSceneTreeWidgetAskForIteratorEnd
QScrollArea * fPickInfosScrollArea
void setCheckComponent(QTreeWidgetItem *item, bool check)
void tableWidgetViewerSetItemChanged(QTableWidgetItem *)
void G4keyPressEvent(QKeyEvent *event)
void updateViewerPropertiesTableWidget()
void addNonPVSceneTreeElement(const G4String &model, int currentPVPOIndex, const std::string &modelDescription, const G4Visible &visible)
G4AutoLock * lWaitForVisSubThreadQtOpenGLContextMoved
G4OpenGLQtViewer & operator=(const G4OpenGLQtViewer &)
QAction * fDrawingLineSurfaceRemoval
void toggleHaloing(bool)
QSignalMapper * fSignalMapperPicking
void changeDepthInSceneTree(int)
void G4MousePressEvent(QMouseEvent *event)
void G4wheelEvent(QWheelEvent *event)
QString GetCommandParameterList(const G4UIcommand *aCommand)
void cloneSceneTree(QTreeWidgetItem *rootItem)
std::map< int, PVPath > fTreeItemModels
QAction * fMouseZoomOutAction
QWidget * fSceneTreeWidget
QAction * fProjectionPerspective
bool fCheckSceneTreeComponentSignalLock
QString getModelShortName(const G4String &modelShortName)
G4OpenGLQtViewer(G4OpenGLSceneHandler &scene)
void toggleSceneTreeComponentPickingCout(int)
QAction * fDrawingLineRemoval
bool isTouchableVisible(int POindex)
void moveScene(float, float, float, bool)
QWidget * fUIPickInfosWidget
unsigned int fSceneTreeDepth
QSignalMapper * fSignalMapperMouse
bool printPDF(const std::string, int, QImage)
QTreeWidgetItem * cloneWidgetItem(QTreeWidgetItem *item)
void rescaleImage(int, int)
G4OpenGLQtViewer(const G4OpenGLQtViewer &)
void G4manageContextMenuEvent(QContextMenuEvent *e)
QTreeWidgetItem * fModelShortNameItem
QTextEdit * fShortcutsDialogInfos
std::map< int, QTreeWidgetItem * >::const_iterator fLastSceneTreeWidgetAskForIterator
QAction * fDrawingSurfaceRemoval
std::string parseSceneTreeElementAndSaveState(QTreeWidgetItem *item, unsigned int level)
std::vector< QTreeWidgetItem * > fOldNullPoIndexSceneTreeWidgetQuickVector
QAction * fMousePickAction
void toggleMouseAction(int)
void changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(QTreeWidgetItem *subItem)
QTableWidget * fViewerPropertiesTableWidget
void actionChangeBackgroundColor()
void rotateQtScene(float, float)
bool exportImage(std::string name="", int width=-1, int height=-1)
std::vector< PVNodeID > PVPath
void toggleProjection(bool)
void currentTabActivated(int)
QWidget * fPickInfosWidget
void updateToolbarAndMouseContextMenu()
std::map< int, QTreeWidgetItem * > fOldPositivePoIndexSceneTreeWidgetQuickMap
void CreateGLQtContext()
QDialog * fShortcutsDialog
void updateKeyModifierState(const Qt::KeyboardModifiers &)
void G4keyReleaseEvent(QKeyEvent *event)
void clearTreeWidgetElements(QTreeWidgetItem *item)
void clearSceneTreeSelection(QTreeWidgetItem *)
G4Colour getColorForPoIndex(int poIndex)
void toggleHiddenMarkers(bool)
void setRecordingStatus(RECORDING_STEP)
void createRadioAction(QAction *, QAction *, const std::string &, unsigned int a=1)
void updatePositivePoIndexSceneTreeWidgetQuickMap(int POindex, QTreeWidgetItem *item)
void updatePickInfosWidget(int, int)
QAction * fMouseMoveAction
virtual ~G4OpenGLQtViewer()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void toggleAntialiasing(bool)
void DrawText(const G4Text &)
QWidget * fUIViewerPropertiesWidget
void createViewerPropertiesWidget()
QTreeWidgetItem * getTreeWidgetItem(int POindex)
QString setEncoderPath(QString path)
virtual void CreateMainWindow(QGLWidget *, const QString &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void toggleTransparency(bool)
QAction * fProjectionOrtho
bool fViewerPropertiesTableWidgetIsInit
void sceneTreeComponentItemChanged(QTreeWidgetItem *item, int id)
QSlider * fSceneTreeDepthSlider
QSignalMapper * fSignalMapperSurface
QPushButton * fSceneTreeButtonApply
QAction * fDrawingWireframe
G4OpenGLQtMovieDialog * fMovieParametersDialog
bool generateMpegEncoderParameters()
QWidget * getParentWidget()
void setRecordingInfos(const QString &)
virtual void updateQWidget()=0
QString setSaveFileName(QString path)
void changeDepthOnSceneTreeItem(double lookForDepth, double currentDepth, QTreeWidgetItem *item)
QAction * fMouseZoomInAction
void addPVSceneTreeElement(const G4String &model, G4PhysicalVolumeModel *pPVModel, int currentPVPOIndex)
void changeQColorForTreeWidgetItem(QTreeWidgetItem *item, const QColor &)
std::map< int, QTreeWidgetItem * > fPositivePoIndexSceneTreeWidgetQuickMap
const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers() const
std::string parseSceneTreeAndSaveState()
bool parseAndInsertInSceneTree(QTreeWidgetItem *, G4PhysicalVolumeModel *pPVModel, unsigned int fullPathIndex, const QString &parentRoot, unsigned int currentIndex, int currentPVPOIndex)
std::map< int, QTreeWidgetItem * >::const_iterator fOldLastSceneTreeWidgetAskForIterator
G4AutoLock * lWaitForVisSubThreadQtOpenGLContextInitialized
QString setTempFolderPath(QString path)
bool isSameSceneTreeElement(QTreeWidgetItem *parentOldItem, QTreeWidgetItem *parentNewItem)
Definition: G4Text.hh:72
const char * name(G4int ptype)