Geant4  10.01.p03
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 86360 2014-11-10 08:34:16Z 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  void SwitchToVisSubThread();
95  void SwitchToMasterThread();
96 #endif
97 
98 private:
99  G4OpenGLQtViewer (const G4OpenGLQtViewer&);
100  G4OpenGLQtViewer& operator= (const G4OpenGLQtViewer&);
101 public:
102  virtual void updateQWidget()=0;
103  void updateSceneTreeComponentTreeWidgetInfos();
104  QString setEncoderPath(QString path);
105  QString getEncoderPath();
106  QString setTempFolderPath(QString path);
107  QString getTempFolderPath();
108  QString setSaveFileName(QString path);
109  QString getSaveFileName();
110  bool isRecording();
111  bool isStopped();
112  bool isPaused();
113  bool isEncoding();
114  bool isWaiting();
115  bool isFailed();
116  void setWaiting();
117  bool isBadEncoder();
118  bool isBadOutput();
119  bool isBadTmp();
120  bool isSuccess();
121  void setBadTmp();
122  void setBadOutput();
123  void setBadEncoder();
124  bool isReadyToEncode();
125  void resetRecording();
126  void encodeVideo();
127  void stopVideo();
128  void saveVideo();
129  bool generateMpegEncoderParameters();
130  void displayRecordingStatus();
131  void DrawText(const G4Text&);
132  void ResetView ();
133  void addPVSceneTreeElement(const G4String& model,
134  G4PhysicalVolumeModel* pPVModel,
135  int currentPVPOIndex);
136  void addNonPVSceneTreeElement(const G4String& model,
137  int currentPVPOIndex,
138  const std::string& modelDescription,
139  const G4Visible& visible);
140  bool isTouchableVisible(int POindex);
141  void clearTreeWidget();
142  bool exportImage(std::string name="", int width=-1, int height=-1);
143 
144 public:
145  void G4MousePressEvent(QMouseEvent *event);
146  void G4wheelEvent (QWheelEvent * event);
147  void G4keyPressEvent (QKeyEvent * event);
148  void G4keyReleaseEvent (QKeyEvent * event);
149  void G4MouseDoubleClickEvent();
150  void G4MouseReleaseEvent(QMouseEvent *evnt);
151  void G4MouseMoveEvent(QMouseEvent *event);
152 
153 protected:
154  void CreateGLQtContext ();
155  virtual void CreateMainWindow (QGLWidget*,const QString&);
156  void G4manageContextMenuEvent(QContextMenuEvent *e);
157  void rotateQtScene(float, float);
158  void rotateQtSceneToggle(float, float);
159  void moveScene(float, float, float,bool);
160  void FinishView();
161  void updateKeyModifierState(const Qt::KeyboardModifiers&);
162  void displaySceneTreeComponent();
163  G4Colour getColorForPoIndex(int poIndex);
164 
165  // So that privately accumulated vis attributes modifiers may be
166  // concatenated with the standard vis attributes modifiers for commands
167  // such as /vis/viewer/set/all and /vis/viewer/save...
168  const std::vector<G4ModelingParameters::VisAttributesModifier>*
169  GetPrivateVisAttributesModifiers() const;
170 
171 protected:
172  QWidget* fGLWidget;
173  bool hasPendingEvents();
174  void savePPMToTemp();
175  int fRecordFrameNumber;
176 
177  bool fHasToRepaint;
178  bool fUpdateGLLock;
179  bool fQGLWidgetInitialiseCompleted;
180  bool fPaintEventLock;
181 
182 private:
183  enum RECORDING_STEP {WAIT,START,PAUSE,CONTINUE,STOP,READY_TO_ENCODE,ENCODING,FAILED,SUCCESS,BAD_ENCODER,BAD_OUTPUT,BAD_TMP,SAVE};
184 
185  void createPopupMenu();
186  void createRadioAction(QAction *,QAction *, const std::string&,unsigned int a=1);
187  void rescaleImage(int, int);
188  bool printPDF(const std::string,int,QImage);
189  void showMovieParametersDialog();
190  void initMovieParameters();
191  QString createTempFolder();
192  QString removeTempFolder();
193  void setRecordingStatus(RECORDING_STEP);
194  void setRecordingInfos(const QString&);
195  QString getProcessErrorMsg();
196  QWidget* getParentWidget();
197  bool parseAndInsertInSceneTree(QTreeWidgetItem *,
198  G4PhysicalVolumeModel* pPVModel,
199  unsigned int fullPathIndex,
200  const QString& parentRoot,
201  unsigned int currentIndex,
202  int currentPVPOIndex);
203  void setCheckComponent(QTreeWidgetItem* item,bool check);
204  void initSceneTreeComponent();
205  void initViewerPropertiesComponent();
206  void initPickingComponent();
207  bool parseAndCheckVisibility(QTreeWidgetItem * treeNode,int POindex);
208  QTreeWidgetItem* createTreeWidgetItem(const PVPath& fullPath,
209  const QString& name,
210  int copyNb,
211  int POIndex,
212  const QString& logicalName,
213  Qt::CheckState state,
214  QTreeWidgetItem * treeNode,
215  const G4Colour& color);
216  QString getModelShortName(const G4String& modelShortName);
217  void cloneSceneTree(QTreeWidgetItem* rootItem);
218  void changeDepthOnSceneTreeItem(double lookForDepth,double currentDepth,QTreeWidgetItem* item);
219  void updatePositivePoIndexSceneTreeWidgetQuickMap(int POindex,QTreeWidgetItem* item);
220  void changeQColorForTreeWidgetItem(QTreeWidgetItem* item, const QColor&);
221 
222  bool isSameSceneTreeElement(QTreeWidgetItem* parentOldItem,QTreeWidgetItem* parentNewItem);
223  void changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(QTreeWidgetItem* subItem);
224  bool isPVVolume(QTreeWidgetItem* item);
225  QTreeWidgetItem* cloneWidgetItem(QTreeWidgetItem* item);
226  void clearSceneTreeSelection(QTreeWidgetItem*);
227  void clearTreeWidgetElements(QTreeWidgetItem* item);
228 
229  // Get the tree wigdet item for POindex if exists
230  QTreeWidgetItem* getTreeWidgetItem(int POindex);
231 
232  // Get the old tree wigdet item for POindex if exists
233  QTreeWidgetItem* getOldTreeWidgetItem(int POindex);
234 
235 // parse the scene tree and return a string of status that can be saved
236  std::string parseSceneTreeAndSaveState();
237 
238  std::string parseSceneTreeElementAndSaveState(QTreeWidgetItem* item, unsigned int level);
239  QString GetCommandParameterList (const G4UIcommand *aCommand);
240  void changeColorAndTransparency(GLuint index, G4Color color);
241 
242  QMenu *fContextMenu;
243  QPoint fLastPos1;
244  QPoint fLastPos2;
245  QPoint fLastPos3;
246 
247  // delta of depth move. This delta is put in % of the scene view
248  G4double fDeltaDepth;
249  // delta of zoom move. This delta is put in % of the scene view
250  G4double fDeltaZoom;
251  // To ensure key event are keep one by one
252  bool fHoldKeyEvent;
253  // To ensure move event are keep one by one
254  bool fHoldMoveEvent;
255  // To ensure rotate event are keep one by one
256  bool fHoldRotateEvent;
257  bool fAutoMove;
258  QString fEncoderPath;
259  QString fTempFolderPath;
260  QString fMovieTempFolderPath;
261  QString fSaveFileName;
262  QString fParameterFileName;
263  QAction *fMouseRotateAction;
264  QAction *fMouseMoveAction;
265  QAction *fMousePickAction;
266  QAction *fMouseZoomInAction;
267  QAction *fMouseZoomOutAction;
268  QAction *fFullScreenOn;
269  QAction *fFullScreenOff;
270  QAction *fDrawingWireframe;
271  QAction *fDrawingLineRemoval;
272  QAction *fDrawingSurfaceRemoval;
273  QAction *fDrawingLineSurfaceRemoval;
274  QAction *fProjectionOrtho;
275  QAction *fProjectionPerspective;
276  G4OpenGLQtMovieDialog* fMovieParametersDialog;
277  RECORDING_STEP fRecordingStep;
278  QProcess *fProcess;
279  QTime *fLastEventTime;
280  int fSpinningDelay;
281  int fNbMaxFramesPerSec;
282  float fNbMaxAnglePerSec;
283  int fLaunchSpinDelay;
284  QTabWidget* fUISceneTreeComponentsTBWidget;
285  bool fNoKeyPress;
286  bool fAltKeyPress;
287  bool fControlKeyPress;
288  bool fShiftKeyPress;
289  bool fBatchMode;
290  bool fCheckSceneTreeComponentSignalLock;
291  QTreeWidget* fSceneTreeComponentTreeWidget;
292  // This is only use to hold the old "expand" value, see file:///Developer/Documentation/Qt/html/qtreewidgetitem.html#setExpanded
293  QTreeWidget* fOldSceneTreeComponentTreeWidget;
294  QWidget* fSceneTreeWidget;
295  bool fPVRootNodeCreate;
296  QLineEdit* fFilterOutput;
297  QString fFileSavePath;
298  QPushButton* fSceneTreeViewerButton;
299  QPushButton* fViewerPropertiesButton;
300  QPushButton* fViewerPickingButton;
301  int fNbRotation ;
302  int fTimeRotation;
303  QString fTouchableVolumes;
304  QDialog* fShortcutsDialog;
305  QTableWidget *fSceneTreeComponentTreeWidgetInfos;
306  QWidget* fSceneTreeComponentPickingInfos;
307  QWidget* fSceneTreeViewerInfos;
308  QScrollArea* fSceneTreeComponentPickingScrollArea;
309  int fTreeWidgetInfosIgnoredCommands;
310  QPushButton * fSceneTreeButtonApply;
311  QTextEdit *fShortcutsDialogInfos;
312  QSlider* fSceneTreeDepthSlider;
313  std::map <int, PVPath > fTreeItemModels;
314  std::map <int, PVPath > fOldTreeItemModels;
315 
316  // quick scene tree map
317  std::map <int, QTreeWidgetItem*> fPositivePoIndexSceneTreeWidgetQuickMap;
318  // old scene tree map
319  std::map <int, QTreeWidgetItem*> fOldPositivePoIndexSceneTreeWidgetQuickMap;
320  std::vector <QTreeWidgetItem*> fOldNullPoIndexSceneTreeWidgetQuickVector;
321  // old vis attr color map
322  std::map <int, QColor> fOldVisAttrColorMap;
323 
324  unsigned int fSceneTreeDepth;
325  QTreeWidgetItem* fModelShortNameItem;
326  int fNumber;
327  int fMaxPOindexInserted;
328  G4UIQt* fUiQt;
329  QSignalMapper *fSignalMapperMouse;
330  QSignalMapper *fSignalMapperSurface;
331  QSignalMapper *fSignalMapperPicking;
332 
333  // quick map index to find next item
334  std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIterator;
335  std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIteratorEnd;
336 
337  // quick map index to find next item
338  std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIterator;
339  std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIteratorEnd;
340 
341  // icons
342  QPixmap* fTreeIconOpen;
343  QPixmap* fTreeIconClosed;
344  QPixmap* fSearchIcon;
345 
346  int fLastExportSliderValue;
347  G4Color fLastHighlightColor;
348  GLuint fLastHighlightName;
349  bool fIsDeleting;
350 
351 public Q_SLOTS :
352  void startPauseVideo();
353 
354 protected Q_SLOTS :
355  void updateToolbarAndMouseContextMenu();
356 
357 private Q_SLOTS :
358  void actionSaveImage();
359  void actionChangeBackgroundColor();
360  void actionChangeTextColor();
361  void actionChangeDefaultColor();
362  void actionMovieParameters();
363 
364  void showShortcuts();
365  void toggleMouseAction(int);
366  void toggleSurfaceAction(int);
367  void toggleProjection(bool);
368  void toggleTransparency(bool);
369  void toggleAntialiasing(bool);
370  void toggleHaloing(bool);
371  void toggleAux(bool);
372  void toggleHiddenMarkers(bool);
373  void toggleFullScreen(bool);
374  void processEncodeFinished();
375  void processLookForFinished();
376  void processEncodeStdout();
377  void sceneTreeComponentItemChanged(QTreeWidgetItem* item, int id);
378  void toggleSceneTreeViewerInfos();
379  void toggleSceneTreeComponentTreeWidgetInfos();
380  void toggleSceneTreeComponentPickingInfos();
381  void toggleSceneTreeComponentPickingCout(int);
382  void togglePicking();
383 
384  // action trigger by a click on a component scene tree
385  void sceneTreeComponentSelected();
386  void changeDepthInSceneTree(int);
387  void changeSearchSelection();
388  void changeColorAndTransparency(QTreeWidgetItem* item,int val);
389  void tableWidgetViewerSetItemChanged(QTableWidgetItem *);
390 };
391 
392 #endif
393 
394 #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