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