Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:16

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