Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:52:11

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 #ifndef G4UIQT_HH
0029 #define G4UIQT_HH
0030 
0031 #include "G4VBasicShell.hh"
0032 #include "G4VInteractiveSession.hh"
0033 #include "G4SceneTreeItem.hh"
0034 
0035 #include <qdialog.h>
0036 #include <qdockwidget.h>
0037 #include <qmap.h>
0038 #include <qobject.h>
0039 #include <qtabwidget.h>
0040 #include <qtreewidget.h>
0041 
0042 class QMainWindow;
0043 class QLineEdit;
0044 class G4UIsession;
0045 class QListWidget;
0046 class QTreeWidgetItem;
0047 class QSlider;
0048 class QTextEdit;
0049 class QTextBrowser;
0050 class QLabel;
0051 class QResizeEvent;
0052 class QTabWidget;
0053 class QSplitter;
0054 class QToolBar;
0055 class QTableWidget;
0056 class QPixmap;
0057 class QComboBox;
0058 class QCompleter;
0059 class QtGlobal;
0060 class QStandardItemModel;
0061 class QToolButton;
0062 class QRadioButton;
0063 
0064 // Class description :
0065 //
0066 //  G4UIQt : class to handle a Qt interactive session.
0067 // G4UIQt is the Qt version of G4UIterminal.
0068 //
0069 //  A command box is at disposal for entering/recalling Geant4 commands.
0070 //  A menubar could be customized through the AddMenu, AddButton, AddIcon methods.
0071 //  Note that there are corresponding Geant4 commands to add a
0072 // menus in the menubar and add buttons in a menu.
0073 //  Ex :
0074 //    /gui/addMenu   test Test
0075 //    /gui/addButton test Init /run/initialize
0076 //    /gui/addButton test "Set gun" "/control/execute gun.g4m"
0077 //    /gui/addButton test "Run one event" "/run/beamOn 1"
0078 //
0079 //  Command completion, by typing "tab" key, is available on the
0080 // command line.
0081 //
0082 // Class description - end :
0083 
0084 #if QT_VERSION < 0x060000
0085 class G4QTabWidget : public QTabWidget
0086 {
0087  public:
0088   G4QTabWidget();
0089   G4QTabWidget(QWidget* aParent, G4int sizeX, G4int sizeY);
0090   void paintEvent(QPaintEvent* event) override;
0091   inline void setTabSelected(G4bool a) { fTabSelected = a; };
0092   inline void setLastTabCreated(G4int a) { fLastCreated = a; };
0093   inline bool isTabSelected() { return fTabSelected; };
0094   G4bool fTabSelected;
0095   G4int fLastCreated;
0096   G4int fPreferedSizeX;
0097   G4int fPreferedSizeY;
0098   inline void setPreferredSize(QSize size)
0099   {
0100     fPreferedSizeX = size.width() + 6;  // tab label height + margin left+right
0101     fPreferedSizeY = size.height() + 58;  // margin left+right
0102   }
0103   inline QSize sizeHint() const override { return QSize(fPreferedSizeX, fPreferedSizeY); }
0104 };
0105 #endif
0106 
0107 class G4UIOutputString
0108 {
0109  public:
0110   G4UIOutputString(const QString& text, const G4String& thread = "", const G4String& outputstream = "info");
0111   inline QString GetOutputList() { return " all info warning error "; };
0112   QString fText;
0113   G4String fThread;
0114   G4String fOutputStream;  // Error, Warning, Info
0115 };
0116 
0117 class G4UIDockWidget : public QDockWidget
0118 {
0119  public:
0120   G4UIDockWidget(const QString& txt);
0121   void closeEvent(QCloseEvent*) override;
0122 };
0123 
0124 class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession
0125 {
0126   Q_OBJECT
0127 
0128  public:  // With description
0129   // (argv, argc) or (0, NULL) had to be given.
0130   G4UIQt(G4int, char**);
0131 
0132   // To enter interactive X loop ; waiting/executing command,...
0133   G4UIsession* SessionStart() override;
0134 
0135   // To add a pulldown menu in the menu bar.
0136   // First argument is the name of the menu.
0137   // Second argument is the label of the cascade button.
0138   // Ex : AddMenu("my_menu","My menu")
0139   void AddMenu(const char*, const char*) override;
0140 
0141   // To add a push button in a pulldown menu.
0142   // First argument is the name of the menu.
0143   // Second argument is the label of the button.
0144   // Third argument is the Geant4 command executed when the button is fired.
0145   // Ex : AddButton("my_menu","Run","/run/beamOn 1");
0146   void AddButton(const char*, const char*, const char*) override;
0147 
0148   // To add a icon in the toolbar
0149   // First argument is the label of the icon.
0150   // Second argument is the selected icon type (open save move rotate pick zoom_in zoom_out
0151   // wireframe solid hidden_line_removal hidden_line_and_surface_removal perspective ortho
0152   // user_icon). Third argument is the Geant4 command executed when the button is fired. Fourth
0153   // argument is the path to the icon file if "user_icon" selected Ex : AddButton("change background
0154   // color","../background.xpm"," /vis/viewer/set/background");
0155   void AddIcon(const char* userLabel, const char* iconFile, const char* command,
0156     const char* file_name = "") override;
0157 
0158   // Specify an output style - used by /gui/outputStyle
0159   // First argument destination ("cout" etc or "all")
0160   // Second argument is the required style - see guidance
0161   void SetOutputStyle(const char* destination, const char* style) override;
0162 
0163   // Enable/Disable the native Menu Bar in Qt
0164   void NativeMenu(G4bool aVal) override;
0165 
0166   // Clear Menu Bar, remove all actions
0167   void ClearMenu() override;
0168 
0169   // Enable/Disable the default icon ToolBar in Qt
0170   void DefaultIcons(G4bool aVal) override;
0171 
0172   // To add a tab for vis openGL Qt driver
0173   G4bool AddTabWidget(QWidget*, QString);
0174 
0175   inline QTabWidget* GetViewerTabWidget() { return fViewerTabWidget; };
0176 
0177   // Get the "old" scene tree component
0178   QWidget* GetSceneTreeWidget();
0179 
0180   // Get the Viewer Properties Widget
0181   QWidget* GetViewerPropertiesWidget();
0182 
0183   // Get the Pick Widget
0184   QWidget* GetPickInfosWidget();
0185 
0186   G4bool IsSplitterReleased();
0187 
0188   inline G4bool IsIconMoveSelected() { return fMoveSelected; };
0189   inline G4bool IsIconRotateSelected() { return fRotateSelected; };
0190   inline G4bool IsIconPickSelected() { return fPickSelected; };
0191   inline G4bool IsIconZoomInSelected() { return fZoomInSelected; };
0192   inline G4bool IsIconZoomOutSelected() { return fZoomOutSelected; };
0193 
0194   void SetIconMoveSelected();
0195   void SetIconRotateSelected();
0196   void TogglePickSelection();
0197   void SetIconZoomInSelected();
0198   void SetIconZoomOutSelected();
0199   void SetIconHLHSRSelected();
0200   void SetIconHLRSelected();
0201   void SetIconSolidSelected();
0202   void SetIconWireframeSelected();
0203   void SetIconCoudPointSelected();
0204   void SetIconPerspectiveSelected();
0205   void SetIconOrthoSelected();
0206 
0207   // Return the main window
0208   inline QMainWindow* GetMainWindow() { return fMainWindow; };
0209 
0210   // return the "search" icon pixmap
0211   inline QPixmap* getSearchIcon() { return fSearchIcon; };
0212 
0213   // return the "clear" icon pixmap
0214   inline QPixmap* getClearIcon() { return fClearIcon; };
0215 
0216   // Set the text on the first page of the viewer. If "", will take the last value as default
0217   // Note: Qt Rich text format could be used, see link for example :
0218   // https://qt-project.org/doc/qt-4.8/richtext-html-subset.html#table-cell-attributes
0219   void SetStartPage(const std::string&);
0220 
0221   // Return the G4cout widget with filters
0222   inline QWidget* GetCoutWidget() { return fCoutDockWidget->widget(); };
0223 
0224   // Return the cout dockable widget as a QDockWidget
0225   inline G4UIDockWidget* GetCoutDockWidget() { return fCoutDockWidget; };
0226 
0227   // Return the UserInterface widget (including scene tree, help and History widgets)
0228   inline G4UIDockWidget* GetUserInterfaceWidget() { return fUIDockWidget; };
0229 
0230   // return the viewer widget including all viewers
0231   inline QTabWidget* GetUITabWidget() { return fUITabWidget; }
0232 
0233   // return the history widget
0234   inline QWidget* GetHistoryWidget() { return fHistoryTBWidget; }
0235 
0236   // return the help widget
0237   inline QWidget* GetHelpWidget() { return fHelpTBWidget; }
0238 
0239   // Add a new tab in the viewer, could be used to add your own component
0240   G4bool AddViewerTab(QWidget* w, std::string title);
0241 
0242   // Add a new tab in the viewer containing the content of the file in a QLabel
0243   G4bool AddViewerTabFromFile(std::string fileName, std::string title);
0244 
0245   // Update "new" scene tree
0246   void UpdateSceneTree(const G4SceneTreeItem&) override;
0247 
0248   // Update control widgets
0249   void UpdateDrawingStyle(G4int style) override;
0250   void UpdateProjectionStyle(G4int style) override;
0251   void UpdateTransparencySlider(G4double depth, G4int option) override;
0252 
0253 
0254 public:
0255   ~G4UIQt() override;
0256   void Prompt(const G4String&);
0257   void SessionTerminate();
0258   void PauseSessionStart(const G4String&) override;
0259   G4int ReceiveG4debug(const G4String&) override;
0260   G4int ReceiveG4cout(const G4String&) override;
0261   G4int ReceiveG4cerr(const G4String&) override;
0262   //   G4String GetCommand(Widget);
0263 
0264 private:
0265   void SecondaryLoop(const G4String&);  // a VIRER
0266   void CreateHelpWidget();
0267   void InitHelpTreeAndVisParametersWidget();
0268   void FillHelpTree();
0269   void UpdateCommandCompleter();
0270   void CreateIcons();
0271   void ExitHelp() const override;
0272   void SetDefaultIconsToolbar();
0273 
0274   void CreateHelpTree(QTreeWidgetItem*, G4UIcommandTree*);
0275   QTreeWidgetItem* FindTreeItem(QTreeWidgetItem*, const QString&);
0276 
0277   // Create the "mother" widget
0278   QWidget* CreateSceneTreeWidget();
0279 
0280   // Classes/structs and functions for the "new" scene tree
0281   // UpdateSceneTree is in "public" section above.
0282   // Create and connect the new tree widget
0283   void CreateNewSceneTreeWidget();
0284   // Build Physical Volume tree of touchables
0285   void BuildPVQTree(const G4SceneTreeItem& g4stItem, QTreeWidgetItem* qtwItem);
0286   // Callbacks on new scene tree items
0287   void SceneTreeItemClicked(QTreeWidgetItem*);
0288   void SceneTreeItemDoubleClicked(QTreeWidgetItem*);
0289   void SceneTreeItemExpanded(QTreeWidgetItem*);
0290   void SceneTreeItemCollapsed(QTreeWidgetItem*);
0291   void SliderValueChanged(G4int value);
0292   void SliderReleased();
0293   void SliderRadioButtonClicked(G4int buttonNo);
0294   // Class for trapping special mouse events on new scene tree
0295   struct NewSceneTreeItemTreeWidget: public QTreeWidget {
0296     void mousePressEvent(QMouseEvent*) override;
0297     void ActWithoutParameter(const G4String& action, G4SceneTreeItem*);
0298     void ActWithABool(const G4String& action, G4SceneTreeItem*, G4bool);
0299     void ActWithAnInteger(const G4String& action, G4SceneTreeItem*);
0300     void ActWithADouble(const G4String& action, G4SceneTreeItem*);
0301     void ActWithAString(const G4String& action, G4SceneTreeItem*);
0302   };
0303 
0304   QString GetCommandList(const G4UIcommand*);
0305   void updateHelpArea(const G4UIcommand*);
0306   G4bool GetHelpChoice(
0307     G4int&) override;  // have to be implemeted because we heritate from G4VBasicShell
0308   bool eventFilter(QObject*, QEvent*) override;
0309   void ActivateCommand(G4String);
0310 
0311   QMultiMap<G4double, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
0312   G4double ComputeStringMatchScore(const QString&, const QString&);
0313   QWidget* CreateVisParametersTBWidget();
0314   QWidget* CreateHelpTBWidget();
0315   QWidget* CreateTimeWindowWidget();
0316   G4UIDockWidget* CreateCoutTBWidget();
0317   QWidget* CreateHistoryTBWidget();
0318   G4UIDockWidget* CreateUITabWidget();
0319   void CreateViewerWidget();
0320   void OpenHelpTreeOnCommand(const QString&);
0321   QString GetShortCommandPath(QString&);
0322   QString GetLongCommandPath(QTreeWidgetItem*);
0323   G4bool IsGUICommand(const G4UIcommand*);
0324   G4bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, G4int, G4bool isDialog);
0325   G4bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, G4bool isDialog);
0326   void CreateViewerPropertiesDialog();
0327   void CreatePickInfosDialog();
0328 #ifdef G4MULTITHREADED
0329   void UpdateCoutThreadFilter();
0330 #endif
0331   void FilterAllOutputTextArea();
0332   QString FilterOutput(const G4UIOutputString&, const QString&, const QString&);
0333   G4String GetThreadPrefix();
0334   G4bool CheckG4EnvironmentVariable(char* txt, char* version);
0335   QStandardItemModel* CreateCompleterModel(const G4String& aCmd);
0336   void CreateEmptyViewerPropertiesWidget();
0337   void CreateEmptyPickInfosWidget();
0338 
0339  private:
0340   QMainWindow* fMainWindow;
0341   QLabel* fCommandLabel;
0342   QLineEdit* fCommandArea;
0343   QTextEdit* fCoutTBTextArea;
0344   QTabWidget* fUITabWidget;
0345   std::vector<G4UIOutputString> fG4OutputString;
0346   QLineEdit* fCoutFilter;
0347   QCompleter* fCompleter;
0348   G4bool fDefaultIcons;
0349 
0350   QListWidget* fHistoryTBTableList;
0351   QTreeWidget* fHelpTreeWidget;
0352   QWidget* fHelpTBWidget;
0353   QWidget* fTimeWindowWidget;
0354   QWidget* fHistoryTBWidget;
0355   G4UIDockWidget* fCoutDockWidget;
0356   G4UIDockWidget* fUIDockWidget;
0357   QWidget* fSceneTreeWidget;
0358   QWidget* fNewSceneTreeWidget;
0359   NewSceneTreeItemTreeWidget* fNewSceneTreeItemTreeWidget;
0360   G4int fMaxPVDepth;
0361   QSlider* fNewSceneTreeSlider;
0362   QRadioButton* fUnwrapButtonWidget;
0363   QRadioButton* fFadeButtonWidget;
0364   QRadioButton* fXrayButtonWidget;
0365   QWidget* fViewerPropertiesWidget;
0366   QWidget* fPickInfosWidget;
0367   QLineEdit* fHelpLine;
0368 #if QT_VERSION < 0x060000
0369   G4QTabWidget* fViewerTabWidget;
0370 #else
0371   QTabWidget* fViewerTabWidget;
0372 #endif
0373   QString fCoutText;
0374   QTextBrowser* fStartPage;
0375   QSplitter* fHelpVSplitter;
0376   QTextEdit* fParameterHelpLabel;
0377   QTableWidget* fParameterHelpTable;
0378 
0379   QToolBar* fToolbarApp;
0380   QToolBar* fToolbarUser;
0381   QString fStringSeparator;
0382   G4String fLastErrMessage;
0383   QString fLastOpenPath;
0384 
0385   QPixmap* fSearchIcon;
0386   QPixmap* fClearIcon;
0387   QPixmap* fSaveIcon;
0388   QPixmap* fOpenIcon;
0389   QPixmap* fMoveIcon;
0390   QPixmap* fRotateIcon;
0391   QPixmap* fPickIcon;
0392   QPixmap* fZoomInIcon;
0393   QPixmap* fZoomOutIcon;
0394   QPixmap* fWireframeIcon;
0395   QPixmap* fSolidIcon;
0396   QPixmap* fPointCloudIcon;
0397   QPixmap* fHiddenLineRemovalIcon;
0398   QPixmap* fHiddenLineAndSurfaceRemovalIcon;
0399   QPixmap* fPerspectiveIcon;
0400   QPixmap* fOrthoIcon;
0401   QPixmap* fCommandIcon;
0402   QPixmap* fDirIcon;
0403   QPixmap* fRunIcon;
0404   QPixmap* fParamIcon;
0405   QPixmap* fPickTargetIcon;
0406   QPixmap* fExitIcon;
0407   QPixmap* fResetCameraIcon;
0408   QPixmap* fResetTargetPointIcon;
0409 
0410 #ifdef G4MULTITHREADED
0411   QComboBox* fThreadsFilterComboBox;
0412 #endif
0413   std::string fDefaultViewerFirstPageHTMLText;
0414 
0415   QDialog* fViewerPropertiesDialog;
0416   QDialog* fPickInfosDialog;
0417   QString fLastCompleteCommand;
0418   G4bool fMoveSelected;
0419   G4bool fRotateSelected;
0420   G4bool fPickSelected;
0421   G4bool fZoomInSelected;
0422   G4bool fZoomOutSelected;
0423 
0424  private Q_SLOTS:
0425   void ExitSession();
0426   void ClearButtonCallback();
0427   void SaveOutputCallback();
0428   void CommandEnteredCallback();
0429   void CommandEditedCallback(const QString& text);
0430   void ButtonCallback(const QString&);
0431   void HelpTreeClicCallback();
0432   void HelpTreeDoubleClicCallback();
0433   void ShowHelpCallback();
0434   void CommandHistoryCallback();
0435   void LookForHelpStringCallback();
0436   void UpdateTabWidget(int);
0437   void ResizeTabWidget(QResizeEvent*);
0438   void CoutFilterCallback(const QString&);
0439   void ThreadComboBoxCallback(int);
0440   void TabCloseCallback(int);
0441   void ToolBoxActivated(int);
0442   void VisParameterCallback(QWidget*);
0443   void ChangeColorCallback(QWidget*);
0444   void ChangeCursorAction(const QString&);
0445   void ChangeSurfaceStyle(const QString&);
0446   void OpenIconCallback(const QString&);
0447   void SaveIconCallback(const QString&);
0448   void ViewerPropertiesIconCallback(int);
0449   void ChangePerspectiveOrtho(const QString&);
0450   void ResetCameraCallback();
0451 
0452 };
0453 
0454 #endif