Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 09:03:41

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