Geant4.10
 All Data Structures 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 77479 2013-11-25 10:01:22Z gcosmo $
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  // So that privately accumulated vis attributes modifiers may be
149  // concatenated with the standard vis attributes modifiers for commands
150  // such as /vis/viewer/set/all and /vis/viewer/save...
151  const std::vector<G4ModelingParameters::VisAttributesModifier>*
152  GetPrivateVisAttributesModifiers() const;
153 
154 protected:
155  QGLWidget* fWindow;
156  QWidget* fGLWindow;
157  bool hasPendingEvents();
158  void savePPMToTemp();
159  int fRecordFrameNumber;
160 
161  bool fHasToRepaint;
162  bool fReadyToPaint;
163  bool fIsRepainting;
164 
165 private:
166  enum RECORDING_STEP {WAIT,START,PAUSE,CONTINUE,STOP,READY_TO_ENCODE,ENCODING,FAILED,SUCCESS,BAD_ENCODER,BAD_OUTPUT,BAD_TMP,SAVE};
167 
168  void createPopupMenu();
169  void createRadioAction(QAction *,QAction *, const std::string&,unsigned int a=1);
170  void rescaleImage(int, int);
171  bool printPDF(const std::string,int,QImage);
172  void showMovieParametersDialog();
173  void initMovieParameters();
174  QString createTempFolder();
175  QString removeTempFolder();
176  void setRecordingStatus(RECORDING_STEP);
177  void setRecordingInfos(const QString&);
178  QString getProcessErrorMsg();
179  QWidget* getParentWidget();
180  bool parseAndInsertInSceneTree(QTreeWidgetItem *,
181  G4PhysicalVolumeModel* pPVModel,
182  unsigned int fullPathIndex,
183  const QString& parentRoot,
184  unsigned int currentIndex,
185  int currentPVPOIndex);
186  void setCheckComponent(QTreeWidgetItem* item,bool check);
187  void initSceneTreeComponent();
188  bool parseAndCheckVisibility(QTreeWidgetItem * treeNode,int POindex);
189  QTreeWidgetItem* createTreeWidgetItem(const PVPath& fullPath,
190  const QString& name,
191  int copyNb,
192  int POIndex,
193  const QString& logicalName,
194  Qt::CheckState state,
195  QTreeWidgetItem * treeNode,
196  const G4Colour& color);
197  QString getModelShortName(const G4String& modelShortName);
198  void cloneSceneTree(QTreeWidgetItem* rootItem);
199  void changeDepthOnSceneTreeItem(double lookForDepth,double currentDepth,QTreeWidgetItem* item);
200  void updatePositivePoIndexSceneTreeWidgetQuickMap(int POindex,QTreeWidgetItem* item);
201  void changeQColorForTreeWidgetItem(QTreeWidgetItem* item, const QColor&);
202 
203  bool isSameSceneTreeElement(QTreeWidgetItem* parentOldItem,QTreeWidgetItem* parentNewItem);
204  void changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(QTreeWidgetItem* subItem);
205  bool isPVVolume(QTreeWidgetItem* item);
206  QTreeWidgetItem* cloneWidgetItem(QTreeWidgetItem* item);
207  void clearSceneTreeSelection(QTreeWidgetItem*);
208  void clearTreeWidgetElements(QTreeWidgetItem* item);
209 
210  // Get the tree wigdet item for POindex if exists
211  QTreeWidgetItem* getTreeWidgetItem(int POindex);
212 
213  // Get the old tree wigdet item for POindex if exists
214  QTreeWidgetItem* getOldTreeWidgetItem(int POindex);
215 
216 // parse the scene tree and return a string of status that can be saved
217  std::string parseSceneTreeAndSaveState();
218 
219  std::string parseSceneTreeElementAndSaveState(QTreeWidgetItem* item, unsigned int level);
220 
221  QMenu *fContextMenu;
222  QPoint fLastPos1;
223  QPoint fLastPos2;
224  QPoint fLastPos3;
225 
226  // delta of depth move. This delta is put in % of the scene view
227  G4double fDeltaDepth;
228  // delta of zoom move. This delta is put in % of the scene view
229  G4double fDeltaZoom;
230  // To ensure key event are keep one by one
231  bool fHoldKeyEvent;
232  // To ensure move event are keep one by one
233  bool fHoldMoveEvent;
234  // To ensure rotate event are keep one by one
235  bool fHoldRotateEvent;
236  bool fAutoMove;
237  QString fEncoderPath;
238  QString fTempFolderPath;
239  QString fMovieTempFolderPath;
240  QString fSaveFileName;
241  QString fParameterFileName;
242  QAction *fMouseRotateAction;
243  QAction *fMouseMoveAction;
244  QAction *fMousePickAction;
245  QAction *fMouseZoomInAction;
246  QAction *fMouseZoomOutAction;
247  QAction *fFullScreenOn;
248  QAction *fFullScreenOff;
249  QAction *fDrawingWireframe;
250  QAction *fDrawingLineRemoval;
251  QAction *fDrawingSurfaceRemoval;
252  QAction *fDrawingLineSurfaceRemoval;
253  QAction *fProjectionOrtho;
254  QAction *fProjectionPerspective;
255  G4OpenGLQtMovieDialog* fMovieParametersDialog;
256  RECORDING_STEP fRecordingStep;
257  QProcess *fProcess;
258  QTime *fLastEventTime;
259  int fSpinningDelay;
260  int fNbMaxFramesPerSec;
261  float fNbMaxAnglePerSec;
262  int fLaunchSpinDelay;
263  QTabWidget* fUISceneTreeComponentsTBWidget;
264  bool fNoKeyPress;
265  bool fAltKeyPress;
266  bool fControlKeyPress;
267  bool fShiftKeyPress;
268  bool fBatchMode;
269  bool fCheckSceneTreeComponentSignalLock;
270  QTreeWidget* fSceneTreeComponentTreeWidget;
271  // This is only use to hold the old "expand" value, see file:///Developer/Documentation/Qt/html/qtreewidgetitem.html#setExpanded
272  QTreeWidget* fOldSceneTreeComponentTreeWidget;
273  QWidget* fSceneTreeWidget;
274  bool fPVRootNodeCreate;
275  QLineEdit* fHelpLine;
276  QString fFileSavePath;
277  QString fDefaultSaveFileFormat;
278 
279  int fNbRotation ;
280  int fTimeRotation;
281  QString fTouchableVolumes;
282  QDialog* fShortcutsDialog;
283  QTextEdit *fTreeInfoDialogInfos;
284  QPushButton * fSceneTreeButtonApply;
285  QTextEdit *fShortcutsDialogInfos;
286  QSlider* fSceneTreeDepthSlider;
287  std::map <int, PVPath > fTreeItemModels;
288  std::map <int, PVPath > fOldTreeItemModels;
289 
290  // quick scene tree map
291  std::map <int, QTreeWidgetItem*> fPositivePoIndexSceneTreeWidgetQuickMap;
292  // old scene tree map
293  std::map <int, QTreeWidgetItem*> fOldPositivePoIndexSceneTreeWidgetQuickMap;
294  std::vector <QTreeWidgetItem*> fOldNullPoIndexSceneTreeWidgetQuickVector;
295  // old vis attr color map
296  std::map <int, QColor> fOldVisAttrColorMap;
297 
298  unsigned int fSceneTreeDepth;
299  QTreeWidgetItem* fModelShortNameItem;
300  int fNumber;
301  int fMaxPOindexInserted;
302  G4UIQt* fUiQt;
303  QSignalMapper *signalMapperMouse;
304  QSignalMapper *signalMapperSurface;
305 
306  // quick map index to find next item
307  std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIterator;
308  std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIteratorEnd;
309 
310  // quick map index to find next item
311  std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIterator;
312  std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIteratorEnd;
313 
314 
315 public Q_SLOTS :
316  void startPauseVideo();
317 
318 protected Q_SLOTS :
319  void updateToolbarAndMouseContextMenu();
320 
321 private Q_SLOTS :
322  void actionSaveImage();
323  void actionChangeBackgroundColor();
324  void actionChangeTextColor();
325  void actionChangeDefaultColor();
326  void actionMovieParameters();
327 
328  void showShortcuts();
329  void toggleMouseAction(int);
330  void toggleSurfaceAction(int);
331  void toggleProjection(bool);
332  void toggleTransparency(bool);
333  void toggleAntialiasing(bool);
334  void toggleHaloing(bool);
335  void toggleAux(bool);
336  void toggleHiddenMarkers(bool);
337  void toggleFullScreen(bool);
338  void processEncodeFinished();
339  void processLookForFinished();
340  void processEncodeStdout();
341  void sceneTreeComponentItemChanged(QTreeWidgetItem* item, int id);
342 
343  // action trigger by a click on a component scene tree
344  void sceneTreeComponentSelected();
345  void changeDepthInSceneTree(int);
346  void changeSearchSelection();
347  void changeColorAndTransparency(QTreeWidgetItem* item,int val);
348 };
349 
350 #endif
351 
352 #endif
Definition: G4Text.hh:73
struct encoding ENCODING
Definition: xmltok.h:126
const XML_Char * name
G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID
const XML_Char XML_Content * model
std::vector< PVNodeID > PVPath
double G4double
Definition: G4Types.hh:76