Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:27:19

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