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