Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 101105 2016-11-07 08:09:26Z 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 updateSceneTreeWidget();
115  void updateViewerPropertiesTableWidget();
116  void updatePickInfosWidget(int, int);
117  QString setEncoderPath(QString path);
118  QString getEncoderPath();
119  QString setTempFolderPath(QString path);
120  QString getTempFolderPath();
121  QString setSaveFileName(QString path);
122  QString getSaveFileName();
123  bool isRecording();
124  bool isStopped();
125  bool isPaused();
126  bool isEncoding();
127  bool isWaiting();
128  bool isFailed();
129  void setWaiting();
130  bool isBadEncoder();
131  bool isBadOutput();
132  bool isBadTmp();
133  bool isSuccess();
134  void setBadTmp();
135  void setBadOutput();
136  void setBadEncoder();
137  bool isReadyToEncode();
138  void resetRecording();
139  void encodeVideo();
140  void stopVideo();
141  void saveVideo();
142  bool generateMpegEncoderParameters();
143  void displayRecordingStatus();
144  void DrawText(const G4Text&);
145  void ResetView ();
146  void addPVSceneTreeElement(const G4String& model,
147  G4PhysicalVolumeModel* pPVModel,
148  int currentPVPOIndex);
149  void addNonPVSceneTreeElement(const G4String& model,
150  int currentPVPOIndex,
151  const std::string& modelDescription,
152  const G4Visible& visible);
153  bool isTouchableVisible(int POindex);
154  void clearTreeWidget();
155  bool exportImage(std::string name="", int width=-1, int height=-1);
156 
157 public:
158  void G4MousePressEvent(QMouseEvent *event);
159  void G4wheelEvent (QWheelEvent * event);
160  void G4keyPressEvent (QKeyEvent * event);
161  void G4keyReleaseEvent (QKeyEvent * event);
162  void G4MouseDoubleClickEvent();
163  void G4MouseReleaseEvent(QMouseEvent *evnt);
164  void G4MouseMoveEvent(QMouseEvent *event);
165 
166 protected:
167  void CreateGLQtContext ();
168  virtual void CreateMainWindow (QGLWidget*,const QString&);
169  void G4manageContextMenuEvent(QContextMenuEvent *e);
170  void rotateQtScene(float, float);
171  void rotateQtSceneToggle(float, float);
172  void moveScene(float, float, float,bool);
173  void FinishView();
174  void updateKeyModifierState(const Qt::KeyboardModifiers&);
175  void displaySceneTreeComponent();
176  G4Colour getColorForPoIndex(int poIndex);
177 
178  // So that privately accumulated vis attributes modifiers may be
179  // concatenated with the standard vis attributes modifiers for commands
180  // such as /vis/viewer/set/all and /vis/viewer/save...
181  const std::vector<G4ModelingParameters::VisAttributesModifier>*
182  GetPrivateVisAttributesModifiers() const;
183  bool isCurrentWidget();
184 
185 protected:
186  QWidget* fGLWidget;
187  bool hasPendingEvents();
188  void savePPMToTemp();
189  int fRecordFrameNumber;
190 
191  bool fHasToRepaint;
192  bool fUpdateGLLock;
193  bool fQGLWidgetInitialiseCompleted;
194  bool fPaintEventLock;
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.
200  bool fMouseOnSceneTree;
201 
202 private:
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  QTime *fLastEventTime;
311  int fSpinningDelay;
312  int fNbMaxFramesPerSec;
313  float fNbMaxAnglePerSec;
314  int fLaunchSpinDelay;
315  QWidget* fUISceneTreeWidget;
316  QWidget* fUIViewerPropertiesWidget;
317  QWidget* fUIPickInfosWidget;
318  bool fNoKeyPress;
319  bool fAltKeyPress;
320  bool fControlKeyPress;
321  bool fShiftKeyPress;
322  bool fBatchMode;
323  bool fCheckSceneTreeComponentSignalLock;
324  bool fViewerPropertiesTableWidgetIsInit;
325  QTreeWidget* fSceneTreeComponentTreeWidget;
326  // This is only use to hold the old "expand" value, see file:///Developer/Documentation/Qt/html/qtreewidgetitem.html#setExpanded
327  QWidget* fSceneTreeWidget;
328  bool fPVRootNodeCreate;
329  QLineEdit* fFilterOutput;
330  QString fFileSavePath;
331  int fNbRotation ;
332  int fTimeRotation;
333  QString fTouchableVolumes;
334  QDialog* fShortcutsDialog;
335  QTableWidget *fViewerPropertiesTableWidget;
336  QWidget* fPickInfosWidget;
337  QScrollArea* fPickInfosScrollArea;
338  int fTreeWidgetInfosIgnoredCommands;
339  QPushButton * fSceneTreeButtonApply;
340  QTextEdit *fShortcutsDialogInfos;
341  QSlider* fSceneTreeDepthSlider;
342  std::map <int, PVPath > fTreeItemModels;
343  std::map <int, PVPath > fOldTreeItemModels;
344 
345  // quick scene tree map
346  std::map <int, QTreeWidgetItem*> fPositivePoIndexSceneTreeWidgetQuickMap;
347  // old scene tree map
348  std::map <int, QTreeWidgetItem*> fOldPositivePoIndexSceneTreeWidgetQuickMap;
349  std::vector <QTreeWidgetItem*> fOldNullPoIndexSceneTreeWidgetQuickVector;
350  // old vis attr color map
351  std::map <int, QColor> fOldVisAttrColorMap;
352 
353  unsigned int fSceneTreeDepth;
354  QTreeWidgetItem* fModelShortNameItem;
355  int fNumber;
356  int fMaxPOindexInserted;
357  G4UIQt* fUiQt;
358  QSignalMapper *fSignalMapperMouse;
359  QSignalMapper *fSignalMapperSurface;
360  QSignalMapper *fSignalMapperPicking;
361 
362  // quick map index to find next item
363  std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIterator;
364  std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIteratorEnd;
365 
366  // quick map index to find next item
367  std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIterator;
368  std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIteratorEnd;
369 
370  // icons
371  QPixmap* fTreeIconOpen;
372  QPixmap* fTreeIconClosed;
373  QPixmap* fSearchIcon;
374 
375  int fLastExportSliderValue;
376  G4Color fLastHighlightColor;
377  GLuint fLastHighlightName;
378  bool fIsDeleting;
379 
380 #ifdef G4MULTITHREADED
381  QThread* fQGLContextVisSubThread;
382  QThread* fQGLContextMainThread;
383 #endif
384 
385 public Q_SLOTS :
386  void startPauseVideo();
387 
388 protected Q_SLOTS :
389  void updateToolbarAndMouseContextMenu();
390 
391 private Q_SLOTS :
392  void actionSaveImage();
393  void actionChangeBackgroundColor();
394  void actionChangeTextColor();
395  void actionChangeDefaultColor();
396  void actionMovieParameters();
397 
398  void showShortcuts();
399  void toggleMouseAction(int);
400  void toggleSurfaceAction(int);
401  void toggleProjection(bool);
402  void toggleTransparency(bool);
403  void toggleAntialiasing(bool);
404  void toggleHaloing(bool);
405  void toggleAux(bool);
406  void toggleHiddenMarkers(bool);
407  void toggleFullScreen(bool);
408  void processEncodeFinished();
409  void processLookForFinished();
410  void processEncodeStdout();
411  void sceneTreeComponentItemChanged(QTreeWidgetItem* item, int id);
412  void toggleSceneTreeComponentPickingCout(int);
413  void togglePicking();
414  void currentTabActivated(int);
415 
416  // action trigger by a click on a component scene tree
417  void sceneTreeComponentSelected();
418  void changeDepthInSceneTree(int);
419  void changeSearchSelection();
420  void changeColorAndTransparency(QTreeWidgetItem* item,int val);
421  void tableWidgetViewerSetItemChanged(QTableWidgetItem *);
422 };
423 
424 #endif
425 
426 #endif
const XML_Char * name
Definition: expat.h:151
Definition: G4Text.hh:73
struct encoding ENCODING
Definition: xmltok.h:126
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
#define width
G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID
std::vector< PVNodeID > PVPath
double G4double
Definition: G4Types.hh:76
const XML_Char XML_Content * model
Definition: expat.h:151