Geant4  9.6.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$
28 //
29 //
30 // G4OpenGLQtViewer : Class to provide WindowsNT specific
31 // functionality for OpenGL in GEANT4
32 
33 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
34 
35 #ifndef G4OPENGLQTVIEWER_HH
36 #define G4OPENGLQTVIEWER_HH
37 
38 #include "globals.hh"
39 
40 #include "G4OpenGLViewer.hh"
41 #include "G4PhysicalVolumeModel.hh"
42 
43 #include <qobject.h>
44 #include <qpoint.h>
45 
46 class G4OpenGLSceneHandler;
47 class G4UImanager;
48 class G4Text;
49 
50 class QGLWidget;
51 class QDialog;
52 class QTextEdit;
53 class QContextMenuEvent;
54 class QMenu;
55 class QImage;
56 class QAction;
57 class QTabWidget;
58 class QMouseEvent;
59 class QKeyEvent;
60 class QWheelEvent;
61 class QProcess;
62 class QTime;
63 class QVBoxLayout;
64 class QPushButton;
65 class QSlider;
66 class QTreeWidgetItem;
67 class QTreeWidget;
68 class QColor;
69 class G4OpenGLSceneHandler;
70 class G4OpenGLQtMovieDialog;
71 class QLineEdit;
72 class QSignalMapper;
73 class G4UIQt;
74 
75 class G4OpenGLQtViewer: public QObject, virtual public G4OpenGLViewer {
76 
77  Q_OBJECT
78 
80  typedef std::vector<PVNodeID> PVPath;
81 
82 public:
83  G4OpenGLQtViewer (G4OpenGLSceneHandler& scene);
84  virtual ~G4OpenGLQtViewer ();
85 private:
86  G4OpenGLQtViewer (const G4OpenGLQtViewer&);
87  G4OpenGLQtViewer& operator= (const G4OpenGLQtViewer&);
88 public:
89  virtual void updateQWidget()=0;
90  QString setEncoderPath(QString path);
91  QString getEncoderPath();
92  QString setTempFolderPath(QString path);
93  QString getTempFolderPath();
94  QString setSaveFileName(QString path);
95  QString getSaveFileName();
96  bool isRecording();
97  bool isStopped();
98  bool isPaused();
99  bool isEncoding();
100  bool isWaiting();
101  bool isFailed();
102  void setWaiting();
103  bool isBadEncoder();
104  bool isBadOutput();
105  bool isBadTmp();
106  bool isSuccess();
107  void setBadTmp();
108  void setBadOutput();
109  void setBadEncoder();
110  bool isReadyToEncode();
111  void resetRecording();
112  void encodeVideo();
113  void stopVideo();
114  void saveVideo();
115  bool generateMpegEncoderParameters();
116  void displayRecordingStatus();
117  void DrawText(const G4Text&);
118  void ResetView ();
119  void addPVSceneTreeElement(const G4String& model,
120  G4PhysicalVolumeModel* pPVModel,
121  int currentPVPOIndex);
122  void addNonPVSceneTreeElement(const G4String& model,
123  int currentPVPOIndex,
124  const std::string& modelDescription,
125  const G4Visible& visible);
126  bool isTouchableVisible(int POindex);
127  void clearTreeWidget();
128 public:
129  void G4MousePressEvent(QMouseEvent *event);
130  void G4wheelEvent (QWheelEvent * event);
131  void G4keyPressEvent (QKeyEvent * event);
132  void G4MouseDoubleClickEvent();
133  void G4MouseReleaseEvent();
134  void G4MouseMoveEvent(QMouseEvent *event);
135 
136 protected:
137  void CreateGLQtContext ();
138  virtual void CreateMainWindow (QGLWidget*,const QString&);
139  void G4manageContextMenuEvent(QContextMenuEvent *e);
140  void rotateQtScene(float, float);
141  void rotateQtSceneToggle(float, float);
142  void moveScene(float, float, float,bool);
143  void FinishView();
144  void updateKeyModifierState(const Qt::KeyboardModifiers&);
145  void displaySceneTreeComponent();
146  G4Colour getColorForPoIndex(int poIndex);
147 
148 protected:
149  QGLWidget* fWindow;
150  QWidget* fGLWindow;
151  bool hasPendingEvents();
152  void savePPMToTemp();
153  int fRecordFrameNumber;
154 
155  bool fHasToRepaint;
156  bool fReadyToPaint;
157  bool fIsRepainting;
158 
159 private:
160  enum RECORDING_STEP {WAIT,START,PAUSE,CONTINUE,STOP,READY_TO_ENCODE,ENCODING,FAILED,SUCCESS,BAD_ENCODER,BAD_OUTPUT,BAD_TMP,SAVE};
161 
162  void createPopupMenu();
163  void createRadioAction(QAction *,QAction *, const std::string&,unsigned int a=1);
164  void rescaleImage(int, int);
165  bool printPDF(const std::string,int,QImage);
166  void showMovieParametersDialog();
167  void initMovieParameters();
168  QString createTempFolder();
169  QString removeTempFolder();
170  void setRecordingStatus(RECORDING_STEP);
171  void setRecordingInfos(const QString&);
172  QString getProcessErrorMsg();
173  QWidget* getParentWidget();
174  bool parseAndInsertInSceneTree(QTreeWidgetItem *,
175  G4PhysicalVolumeModel* pPVModel,
176  unsigned int fullPathIndex,
177  const QString& parentRoot,
178  unsigned int currentIndex,
179  int currentPVPOIndex);
180  void setCheckComponent(QTreeWidgetItem* item,bool check);
181  void initSceneTreeComponent();
182  bool parseAndCheckVisibility(QTreeWidgetItem * treeNode,int POindex);
183  QTreeWidgetItem* createTreeWidgetItem(const PVPath& fullPath,
184  const QString& name,
185  int copyNb,
186  int POIndex,
187  const QString& logicalName,
188  Qt::CheckState state,
189  QTreeWidgetItem * treeNode,
190  const G4Colour& color);
191  QString getModelShortName(const G4String& modelShortName);
192  void cloneSceneTree(QTreeWidgetItem* rootItem);
193  void changeDepthOnSceneTreeItem(double lookForDepth,double currentDepth,QTreeWidgetItem* item);
194  void updatePositivePoIndexSceneTreeWidgetQuickMap(int POindex,QTreeWidgetItem* item);
195  void changeQColorForTreeWidgetItem(QTreeWidgetItem* item, const QColor&);
196 
197  bool isSameSceneTreeElement(QTreeWidgetItem* parentOldItem,QTreeWidgetItem* parentNewItem);
198  void changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(QTreeWidgetItem* subItem);
199  bool isPVVolume(QTreeWidgetItem* item);
200  QTreeWidgetItem* cloneWidgetItem(QTreeWidgetItem* item);
201  void clearSceneTreeSelection(QTreeWidgetItem*);
202  void clearTreeWidgetElements(QTreeWidgetItem* item);
203 
204  // Get the tree wigdet item for POindex if exists
205  QTreeWidgetItem* getTreeWidgetItem(int POindex);
206 
207  // Get the old tree wigdet item for POindex if exists
208  QTreeWidgetItem* getOldTreeWidgetItem(int POindex);
209 
210 
211  QMenu *fContextMenu;
212  QPoint fLastPos1;
213  QPoint fLastPos2;
214  QPoint fLastPos3;
215 
216  // delta of depth move. This delta is put in % of the scene view
217  G4double fDeltaDepth;
218  // delta of zoom move. This delta is put in % of the scene view
219  G4double fDeltaZoom;
220  // To ensure key event are keep one by one
221  bool fHoldKeyEvent;
222  // To ensure move event are keep one by one
223  bool fHoldMoveEvent;
224  // To ensure rotate event are keep one by one
225  bool fHoldRotateEvent;
226  bool fAutoMove;
227  QString fEncoderPath;
228  QString fTempFolderPath;
229  QString fMovieTempFolderPath;
230  QString fSaveFileName;
231  QString fParameterFileName;
232  QAction *fMouseRotateAction;
233  QAction *fMouseMoveAction;
234  QAction *fMousePickAction;
235  QAction *fMouseZoomInAction;
236  QAction *fMouseZoomOutAction;
237  QAction *fFullScreenOn;
238  QAction *fFullScreenOff;
239  QAction *fDrawingWireframe;
240  QAction *fDrawingLineRemoval;
241  QAction *fDrawingSurfaceRemoval;
242  QAction *fDrawingLineSurfaceRemoval;
243  QAction *fProjectionOrtho;
244  QAction *fProjectionPerspective;
245  G4OpenGLQtMovieDialog* fMovieParametersDialog;
246  RECORDING_STEP fRecordingStep;
247  QProcess *fProcess;
248  QTime *fLastEventTime;
249  int fSpinningDelay;
250  int fNbMaxFramesPerSec;
251  float fNbMaxAnglePerSec;
252  int fLaunchSpinDelay;
253  QTabWidget* fUISceneTreeComponentsTBWidget;
254  bool fNoKeyPress;
255  bool fAltKeyPress;
256  bool fControlKeyPress;
257  bool fShiftKeyPress;
258  bool fBatchMode;
259  bool fCheckSceneTreeComponentSignalLock;
260  QTreeWidget* fSceneTreeComponentTreeWidget;
261  // This is only use to hold the old "expand" value, see file:///Developer/Documentation/Qt/html/qtreewidgetitem.html#setExpanded
262  QTreeWidget* fOldSceneTreeComponentTreeWidget;
263  QWidget* fSceneTreeWidget;
264  bool fPVRootNodeCreate;
265  QLineEdit* fHelpLine;
266 
267 
268  int fNbRotation ;
269  int fTimeRotation;
270  QString fTouchableVolumes;
271  QDialog* fShortcutsDialog;
272  QTextEdit *fTreeInfoDialogInfos;
273  QPushButton * fSceneTreeButtonApply;
274  QTextEdit *fShortcutsDialogInfos;
275  QSlider* fSceneTreeDepthSlider;
276  std::map <int, PVPath > fTreeItemModels;
277  std::map <int, PVPath > fOldTreeItemModels;
278 
279  // quick scene tree map
280  std::map <int, QTreeWidgetItem*> fPositivePoIndexSceneTreeWidgetQuickMap;
281  // old scene tree map
282  std::map <int, QTreeWidgetItem*> fOldPositivePoIndexSceneTreeWidgetQuickMap;
283  std::vector <QTreeWidgetItem*> fOldNullPoIndexSceneTreeWidgetQuickVector;
284  // old vis attr color map
285  std::map <int, QColor> fOldVisAttrColorMap;
286 
287  unsigned int fSceneTreeDepth;
288  QTreeWidgetItem* fModelShortNameItem;
289  int fNumber;
290  int fMaxPOindexInserted;
291  G4UIQt* fUiQt;
292  QSignalMapper *signalMapperMouse;
293  QSignalMapper *signalMapperSurface;
294 
295  // quick map index to find next item
296  std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskFor;
297 
298  // quick map index to find next item
299  std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskFor;
300 
301 
302 public Q_SLOTS :
303  void startPauseVideo();
304 
305 protected Q_SLOTS :
306  void updateToolbarAndMouseContextMenu();
307 
308 private Q_SLOTS :
309  void actionSaveImage();
310  void actionChangeBackgroundColor();
311  void actionChangeTextColor();
312  void actionChangeDefaultColor();
313  void actionMovieParameters();
314 
315  void showShortcuts();
316  void toggleMouseAction(int);
317  void toggleSurfaceAction(int);
318  void toggleRepresentation(bool);
319  void toggleProjection(bool);
320  void toggleTransparency(bool);
321  void toggleAntialiasing(bool);
322  void toggleHaloing(bool);
323  void toggleAux(bool);
324  void toggleHiddenMarkers(bool);
325  void toggleFullScreen(bool);
326  void processEncodeFinished();
327  void processLookForFinished();
328  void processEncodeStdout();
329  void sceneTreeComponentItemChanged(QTreeWidgetItem* item, int id);
330 
331  // action trigger by a click on a component scene tree
332  void sceneTreeComponentSelected();
333  void changeDepthInSceneTree(int);
334  void changeSearchSelection();
335  void changeColorAndTransparency(QTreeWidgetItem* item,int val);
336 };
337 
338 #endif
339 
340 #endif