Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:47

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 //
0028 // 
0029 // G4OpenGLQtViewer : Class to provide WindowsNT specific
0030 //                       functionality for OpenGL in GEANT4
0031 //
0032 // 30/06/2014 : M.Kelsey : Change QPixmap objects to pointers
0033 
0034 #ifndef G4OPENGLQTVIEWER_HH
0035 #define G4OPENGLQTVIEWER_HH
0036 
0037 #include "globals.hh"
0038 
0039 #include "G4OpenGLViewer.hh"
0040 #include "G4PhysicalVolumeModel.hh"
0041 #include "G4AutoLock.hh"
0042 
0043 #include <qobject.h>
0044 #include <qpoint.h>
0045 #include <qpixmap.h>
0046 
0047 class G4OpenGLSceneHandler;
0048 class G4UImanager;
0049 class G4Text;
0050 class G4UIcommand;
0051 
0052 #include <QtGlobal>
0053 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0054 #include <QGLWidget>
0055 using G4QGLWidgetType = QGLWidget;
0056 #else
0057 #include <QOpenGLWidget>
0058 using G4QGLWidgetType = QOpenGLWidget;
0059 #endif
0060 
0061 class QDialog;
0062 class QTextEdit;
0063 class QContextMenuEvent;
0064 class QMenu;
0065 class QImage;
0066 class QAction;
0067 class QTabWidget;
0068 class QMouseEvent;
0069 class QKeyEvent;
0070 class QWheelEvent;
0071 class QProcess;
0072 class QTime;
0073 class QElapsedTimer;
0074 class QVBoxLayout;
0075 class QPushButton;
0076 class QSlider;
0077 class QTreeWidgetItem;
0078 class QTreeWidget;
0079 class QColor;
0080 class G4OpenGLSceneHandler;
0081 class G4OpenGLQtMovieDialog;
0082 class QLineEdit;
0083 class G4UIQt;
0084 class QTableWidget;
0085 class QTableWidgetItem;
0086 class QScrollArea;
0087 class QSplitter;
0088 
0089 class G4OpenGLQtViewer: public QObject, virtual public G4OpenGLViewer {
0090 
0091   Q_OBJECT
0092 
0093     typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
0094     typedef std::vector<PVNodeID> PVPath;
0095 
0096 public:
0097   G4OpenGLQtViewer (G4OpenGLSceneHandler& scene);
0098   virtual ~G4OpenGLQtViewer ();
0099 #ifdef G4MULTITHREADED
0100   // In MT mode these functions are called in the following order for each run:
0101   // Called on the master thread before starting the vis sub-thread.
0102   virtual void DoneWithMasterThread ();
0103   // Called on the master thread after starting the vis sub-thread.
0104   virtual void MovingToVisSubThread ();
0105   // Called on the vis sub-thread when waiting for events.
0106   virtual void SwitchToVisSubThread ();
0107   // Called on the vis sub-thread when all events have been processed.
0108   virtual void DoneWithVisSubThread ();
0109   // Called on the vis sub-thread when all events have been processed.
0110   // virtual void MovingToMasterThread ();  Not used in G4OpenGLQtViewer.
0111   // Called on the master thread after the vis sub-thread has terminated.
0112   virtual void SwitchToMasterThread ();
0113 #endif
0114 
0115 private:
0116   G4OpenGLQtViewer (const G4OpenGLQtViewer&);
0117   G4OpenGLQtViewer& operator= (const G4OpenGLQtViewer&);
0118 public:
0119   virtual void updateQWidget()=0;
0120   void updateSceneTreeWidget();
0121   void updateViewerPropertiesTableWidget();
0122   void updatePickInfosWidget(int, int);
0123   QString setEncoderPath(QString path);
0124   QString getEncoderPath();
0125   QString setTempFolderPath(QString path);
0126   QString getTempFolderPath();
0127   QString setSaveFileName(QString path);
0128   QString getSaveFileName();
0129   bool isRecording();
0130   bool isStopped();
0131   bool isPaused();
0132   bool isEncoding();
0133   bool isWaiting();
0134   bool isFailed();
0135   void setWaiting();
0136   bool isBadEncoder();
0137   bool isBadOutput();
0138   bool isBadTmp();
0139   bool isSuccess();
0140   void setBadTmp();
0141   void setBadOutput();
0142   void setBadEncoder();
0143   bool isReadyToEncode();
0144   void resetRecording();
0145   void encodeVideo();
0146   void stopVideo();
0147   void saveVideo();
0148   bool generateMpegEncoderParameters();
0149   void displayRecordingStatus();
0150   void DrawText(const G4Text&);
0151   void ResetView ();
0152   void addPVSceneTreeElement(const G4String& model,
0153                              G4PhysicalVolumeModel* pPVModel,
0154                              int currentPVPOIndex);
0155   void addNonPVSceneTreeElement(const G4String& model,
0156                                 int currentPVPOIndex,
0157                                 const std::string& modelDescription,
0158                                 const G4Visible& visible);
0159   bool isTouchableVisible(int POindex);
0160   void clearTreeWidget();
0161   bool exportImage(std::string name="", int width=-1, int height=-1);
0162 
0163 public:
0164   void G4MousePressEvent(QMouseEvent *event);
0165   void G4wheelEvent (QWheelEvent * event); 
0166   void G4keyPressEvent (QKeyEvent * event); 
0167   void G4keyReleaseEvent (QKeyEvent * event);
0168   void G4MouseDoubleClickEvent();
0169   void G4MouseReleaseEvent(QMouseEvent *evnt);
0170   void G4MouseMoveEvent(QMouseEvent *event);
0171 
0172 protected:
0173   void CreateGLQtContext ();
0174   virtual void CreateMainWindow (G4QGLWidgetType*,const QString&);
0175   void G4manageContextMenuEvent(QContextMenuEvent *e);
0176   void rotateQtScene(float, float);
0177   void rotateQtSceneToggle(float, float);
0178   void moveScene(float, float, float,bool);
0179   void FinishView();
0180   void updateKeyModifierState(const Qt::KeyboardModifiers&);
0181   void displaySceneTreeComponent();
0182   G4Colour getColorForPoIndex(int poIndex);
0183   
0184   // So that privately accumulated vis attributes modifiers may be
0185   // concatenated with the standard vis attributes modifiers for commands
0186   // such as /vis/viewer/set/all and /vis/viewer/save...
0187   const std::vector<G4ModelingParameters::VisAttributesModifier>*
0188   GetPrivateVisAttributesModifiers() const;
0189   bool isCurrentWidget();
0190 
0191 protected:
0192   G4UIQt* fUiQt;
0193   QWidget* fGLWidget;
0194   void savePPMToTemp();
0195   int fRecordFrameNumber;
0196 
0197   bool fHasToRepaint;
0198   bool fUpdateGLLock;
0199   bool fQGLWidgetInitialiseCompleted;
0200   bool fPaintEventLock;
0201 
0202   // Flag to indicate that action was initiated by interaction (mouse
0203   // click) on the scene tree.  It is used and reset in
0204   // G4OpenGLStoredQtViewer::CompareForKernelVisit to prevent rebuild
0205   // in this case.
0206   bool fMouseOnSceneTree;
0207 
0208 private:
0209   enum RECORDING_STEP {WAIT,START,PAUSE,CONTINUE,STOP,READY_TO_ENCODE,ENCODING,FAILED,SUCCESS,BAD_ENCODER,BAD_OUTPUT,BAD_TMP,SAVE}; 
0210 
0211   void createPopupMenu();
0212   void createRadioAction(QAction *,QAction *, const std::string&,unsigned int a=1);
0213   void rescaleImage(int, int);
0214   bool printPDF(const std::string,int,QImage);  
0215   void showMovieParametersDialog();
0216   void initMovieParameters();
0217   QString createTempFolder();
0218   QString removeTempFolder();
0219   void setRecordingStatus(RECORDING_STEP);
0220   void setRecordingInfos(const QString&);
0221   QString getProcessErrorMsg();
0222   QWidget* getParentWidget();
0223   bool parseAndInsertInSceneTree(QTreeWidgetItem *,
0224                                   G4PhysicalVolumeModel* pPVModel,
0225                                  unsigned int fullPathIndex,
0226                                  const QString& parentRoot,
0227                                  unsigned int currentIndex,
0228                                  int currentPVPOIndex);
0229   void setCheckComponent(QTreeWidgetItem* item,bool check);
0230   void createSceneTreeComponent();
0231   void createSceneTreeWidget();
0232   void createViewerPropertiesWidget();
0233   void createPickInfosWidget();
0234   bool parseAndCheckVisibility(QTreeWidgetItem * treeNode,int POindex);
0235   QTreeWidgetItem* createTreeWidgetItem(const PVPath& fullPath,
0236                                      const QString& name,
0237                                      int copyNb,
0238                                      int POIndex,
0239                                      const QString& logicalName,
0240                                      Qt::CheckState state,
0241                                      QTreeWidgetItem * treeNode,
0242                                      const G4Colour& color);
0243   QString getModelShortName(const G4String& modelShortName);
0244   void cloneSceneTree(QTreeWidgetItem* rootItem);
0245   void changeDepthOnSceneTreeItem(double lookForDepth,double currentDepth,QTreeWidgetItem* item);
0246   void updatePositivePoIndexSceneTreeWidgetQuickMap(int POindex,QTreeWidgetItem* item);
0247   void changeQColorForTreeWidgetItem(QTreeWidgetItem* item, const QColor&);
0248 
0249   bool isSameSceneTreeElement(QTreeWidgetItem* parentOldItem,QTreeWidgetItem* parentNewItem);
0250   void changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(QTreeWidgetItem* subItem);
0251   bool isPVVolume(QTreeWidgetItem* item);
0252   QTreeWidgetItem* cloneWidgetItem(QTreeWidgetItem* item);
0253   void clearSceneTreeSelection(QTreeWidgetItem*);
0254   void clearTreeWidgetElements(QTreeWidgetItem* item);
0255 
0256   // Get the tree wigdet item for POindex if exists
0257   QTreeWidgetItem* getTreeWidgetItem(int POindex);
0258 
0259   // Get the old tree wigdet item for POindex if exists
0260   QTreeWidgetItem* getOldTreeWidgetItem(int POindex);
0261 
0262 // parse the scene tree and return a string of status that can be saved
0263   std::string parseSceneTreeAndSaveState();
0264 
0265   std::string parseSceneTreeElementAndSaveState(QTreeWidgetItem* item, unsigned int level);
0266   QString GetCommandParameterList (const G4UIcommand *aCommand);
0267   void changeColorAndTransparency(GLuint index, G4Color color);
0268 
0269 #ifdef G4MULTITHREADED
0270   inline void SetQGLContextVisSubThread(QThread *th) {
0271     fQGLContextVisSubThread = th;
0272   }
0273   inline void SetQGLContextMainThread(QThread *th) {
0274     fQGLContextMainThread = th;
0275   }
0276 #endif
0277   
0278   QMenu *fContextMenu;
0279   QPoint fLastPos1;
0280   QPoint fLastPos2;
0281   QPoint fLastPos3;
0282   QPoint fLastPickPoint;
0283 
0284   // delta of depth move. This delta is put in % of the scene view
0285   G4double fDeltaDepth;
0286   // delta of zoom move. This delta is put in % of the scene view
0287   G4double fDeltaZoom;
0288   // To ensure key event are keep one by one
0289   bool fHoldKeyEvent;
0290   // To ensure move event are keep one by one
0291   bool fHoldMoveEvent;
0292   // To ensure rotate event are keep one by one
0293   bool fHoldRotateEvent;
0294   bool fAutoMove;
0295   QString fEncoderPath;
0296   QString fTempFolderPath;
0297   QString fMovieTempFolderPath;
0298   QString fSaveFileName;
0299   QString fParameterFileName;
0300   QAction *fMouseRotateAction;
0301   QAction *fMouseMoveAction;
0302   QAction *fMousePickAction;
0303   QAction *fMouseZoomInAction;
0304   QAction *fMouseZoomOutAction;
0305   QAction *fFullScreenOn;
0306   QAction *fFullScreenOff;
0307   QAction *fDrawingWireframe;
0308   QAction *fDrawingLineRemoval;
0309   QAction *fDrawingSurfaceRemoval;
0310   QAction *fDrawingLineSurfaceRemoval;
0311   QAction *fProjectionOrtho;
0312   QAction *fProjectionPerspective;
0313   G4OpenGLQtMovieDialog* fMovieParametersDialog;
0314   RECORDING_STEP fRecordingStep;
0315   QProcess *fProcess;
0316 #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
0317   QTime *fLastEventTime;
0318 #else
0319   QElapsedTimer *fLastEventTime;
0320 #endif
0321   int fSpinningDelay;
0322   int fNbMaxFramesPerSec;
0323   float fNbMaxAnglePerSec;
0324   int fLaunchSpinDelay;
0325   QWidget* fUISceneTreeWidget;
0326   QWidget* fUIViewerPropertiesWidget;
0327   QWidget* fUIPickInfosWidget;
0328   bool fNoKeyPress;
0329   bool fAltKeyPress;
0330   bool fControlKeyPress;
0331   bool fShiftKeyPress;
0332   bool fBatchMode;
0333   bool fCheckSceneTreeComponentSignalLock;
0334   bool fViewerPropertiesTableWidgetIsInit;
0335   QTreeWidget* fSceneTreeComponentTreeWidget;
0336   // This is only use to hold the old "expand" value, see file:///Developer/Documentation/Qt/html/qtreewidgetitem.html#setExpanded 
0337   QWidget* fSceneTreeWidget;
0338   bool fPVRootNodeCreate;
0339   QLineEdit* fFilterOutput;
0340   QString fFileSavePath;
0341   int fNbRotation ;
0342   int fTimeRotation;
0343   QString fTouchableVolumes;
0344   QDialog* fShortcutsDialog;
0345   QTableWidget *fViewerPropertiesTableWidget;
0346   QWidget* fPickInfosWidget;
0347   QScrollArea* fPickInfosScrollArea;
0348   int fTreeWidgetInfosIgnoredCommands;
0349   QPushButton * fSceneTreeButtonApply;
0350   QTextEdit *fShortcutsDialogInfos;
0351   QSlider* fSceneTreeDepthSlider;
0352   std::map <int, PVPath > fTreeItemModels;
0353   std::map <int, PVPath > fOldTreeItemModels;
0354 
0355   // quick scene tree map
0356   std::map <int, QTreeWidgetItem*> fPositivePoIndexSceneTreeWidgetQuickMap;
0357   // old scene tree map
0358   std::map <int, QTreeWidgetItem*> fOldPositivePoIndexSceneTreeWidgetQuickMap;
0359   std::vector <QTreeWidgetItem*> fOldNullPoIndexSceneTreeWidgetQuickVector;
0360   // old vis attr color map
0361   std::map <int, QColor> fOldVisAttrColorMap;
0362 
0363   unsigned int fSceneTreeDepth;
0364   QTreeWidgetItem* fModelShortNameItem;
0365   int fNumber;
0366   int fMaxPOindexInserted;
0367 
0368   // quick map index to find next item
0369   std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIterator;
0370   std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIteratorEnd;
0371 
0372   // quick map index to find next item
0373   std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIterator;
0374   std::map <int, QTreeWidgetItem*>::const_iterator fOldLastSceneTreeWidgetAskForIteratorEnd;
0375 
0376   // icons
0377   QPixmap* fTreeIconOpen;
0378   QPixmap* fTreeIconClosed;
0379   QPixmap* fSearchIcon;
0380 
0381   int fLastExportSliderValue;
0382   G4Color fLastHighlightColor;
0383   GLuint fLastHighlightName;
0384   bool fIsDeleting;
0385 
0386 #ifdef G4MULTITHREADED
0387   QThread* fQGLContextVisSubThread;
0388   QThread* fQGLContextMainThread;
0389 #endif
0390 
0391   // safe to use in serial mode
0392   G4AutoLock* lWaitForVisSubThreadQtOpenGLContextInitialized;
0393   G4AutoLock* lWaitForVisSubThreadQtOpenGLContextMoved;
0394 
0395 public Q_SLOTS :
0396   void startPauseVideo();
0397 
0398 protected Q_SLOTS :
0399   void updateToolbarAndMouseContextMenu();
0400 
0401 private Q_SLOTS :
0402   void actionSaveImage();
0403   void actionChangeBackgroundColor();
0404   void actionChangeTextColor();
0405   void actionChangeDefaultColor();
0406   void actionMovieParameters();
0407 
0408   void showShortcuts();
0409   void toggleMouseAction(int);
0410   void toggleSurfaceAction(int);
0411   void toggleProjection(bool);
0412   void toggleTransparency(bool);
0413   void toggleAntialiasing(bool);
0414   void toggleHaloing(bool);
0415   void toggleAux(bool);
0416   void toggleHiddenMarkers(bool);
0417   void toggleFullScreen(bool);
0418   void processEncodeFinished();
0419   void processLookForFinished();
0420   void processEncodeStdout();
0421   void sceneTreeComponentItemChanged(QTreeWidgetItem* item, int id);
0422   void toggleSceneTreeComponentPickingCout(int);
0423   void togglePicking();
0424   void currentTabActivated(int);
0425 
0426   // action trigger by a click on a component scene tree
0427   void sceneTreeComponentSelected();
0428   void changeDepthInSceneTree(int);
0429   void changeSearchSelection();
0430   void changeColorAndTransparency(QTreeWidgetItem* item,int val);
0431   void tableWidgetViewerSetItemChanged(QTableWidgetItem *);
0432 };
0433 
0434 #endif