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[ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

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