ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIQt.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UIQt.hh
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 #ifndef G4UIQt_h
29 #define G4UIQt_h
30 
31 #if defined(G4UI_BUILD_QT_SESSION) || defined(G4UI_USE_QT)
32 
33 #include <map>
34 
35 #include "G4VBasicShell.hh"
36 #include "G4VInteractiveSession.hh"
37 
38 #include <qobject.h>
39 #include <qmap.h>
40 #include <qstringlist.h>
41 #include <qtabwidget.h>
42 #include <qdockwidget.h>
43 #include <qdialog.h>
44 
45 class QMainWindow;
46 class QLineEdit;
47 class G4UIsession;
48 class QListWidget;
49 class QTreeWidget;
50 class QTreeWidgetItem;
51 class QTextEdit;
52 class QLabel;
53 class QResizeEvent;
54 class QTabWidget;
55 class QStringList;
56 class QSplitter;
57 class QToolBar;
58 class QTableWidget;
59 class QPixmap;
60 class QComboBox;
61 class QCompleter;
62 class QtGlobal;
63 class QStandardItemModel;
64 class QToolButton;
65 
66 // Class description :
67 //
68 // G4UIQt : class to handle a Qt interactive session.
69 // G4UIQt is the Qt version of G4UIterminal.
70 //
71 // A command box is at disposal for entering/recalling Geant4 commands.
72 // A menubar could be customized through the AddMenu, AddButton, AddIcon methods.
73 // Note that there are corresponding Geant4 commands to add a
74 // menus in the menubar and add buttons in a menu.
75 // Ex :
76 // /gui/addMenu test Test
77 // /gui/addButton test Init /run/initialize
78 // /gui/addButton test "Set gun" "/control/execute gun.g4m"
79 // /gui/addButton test "Run one event" "/run/beamOn 1"
80 //
81 // Command completion, by typing "tab" key, is available on the
82 // command line.
83 //
84 // Class description - end :
85 
86 class G4QTabWidget : public QTabWidget {
87 public :
88  G4QTabWidget();
89  G4QTabWidget(QWidget* aParent, int sizeX, int sizeY);
90  void paintEvent ( QPaintEvent * event );
91  inline void setTabSelected(bool a) { fTabSelected = a; };
92  inline void setLastTabCreated(int a) { fLastCreated = a; };
93  inline bool isTabSelected() { return fTabSelected; };
94  bool fTabSelected;
95  int fLastCreated;
96  int fPreferedSizeX;
97  int fPreferedSizeY;
98  inline void setPreferredSize(QSize s) {
99  fPreferedSizeX = s.width() + 6; // tab label height + margin left+right
100  fPreferedSizeY = s.height() + 58; // margin left+right
101  }
102  inline QSize sizeHint () const {
103  return QSize(fPreferedSizeX, fPreferedSizeY);
104  }
105 };
106 
107 class G4UIOutputString {
108  public :
109  G4UIOutputString(QString text,G4String thread = "",G4String outputstream= "info");
110  inline QString GetOutputList() { return " all info warning error ";};
111  QString fText;
112  G4String fThread;
113  G4String fOutputStream; // Error, Warning, Info
114 };
115 
116 
117 class G4UIDockWidget : public QDockWidget {
118 public:
119  G4UIDockWidget(QString txt);
120  void closeEvent(QCloseEvent *);
121 };
122 
123 
124 class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession {
125  Q_OBJECT
126 
127 public: // With description
128  G4UIQt(int,char**);
129  // (argv, argc) or (0, NULL) had to be given.
131  // To enter interactive X loop ; waiting/executing command,...
132  void AddMenu(const char*,const char*);
133  // To add a pulldown menu in the menu bar.
134  // First argument is the name of the menu.
135  // Second argument is the label of the cascade button.
136  // Ex : AddMenu("my_menu","My menu")
137  void AddButton(const char*,const char*,const char*);
138  // To add a push button in a pulldown menu.
139  // First argument is the name of the menu.
140  // Second argument is the label of the button.
141  // Third argument is the Geant4 command executed when the button is fired.
142  // Ex : AddButton("my_menu","Run","/run/beamOn 1");
143  void AddIcon(const char* userLabel, const char* iconFile, const char* command, const char* file_name="");
144  // To add a icon in the toolbar
145  // First argument is the label of the icon.
146  // Second argument is the selected icon type (open save move rotate pick zoom_in zoom_out wireframe solid hidden_line_removal hidden_line_and_surface_removal perspective ortho user_icon).
147  // Third argument is the Geant4 command executed when the button is fired.
148  // Fourth argument is the path to the icon file if "user_icon" selected
149  // Ex : AddButton("change background color","../background.xpm"," /vis/viewer/set/background");
150 
151  void DefaultIcons(bool aVal);
152  // Enable/Disable the default icon ToolBar in Qt
153 
154  bool AddTabWidget(QWidget*,QString);
155  // To add a tab for vis openGL Qt driver
156 
157  inline QTabWidget* GetViewerTabWidget() {
158  return fViewerTabWidget;
159  };
160 
161  QWidget* GetSceneTreeWidget();
162  // Get the scene tree component
163 
164  QWidget* GetViewerPropertiesWidget();
165  // Get the Viewer Properties Widget
166 
167  QWidget* GetPickInfosWidget();
168  // Get the Pick Widget
169 
170  bool IsSplitterReleased();
171 
172  inline bool IsIconMoveSelected() {
173  return fMoveSelected;
174  };
175  inline bool IsIconRotateSelected() {
176  return fRotateSelected;
177  };
178  inline bool IsIconPickSelected() {
179  return fPickSelected;
180  };
181  inline bool IsIconZoomInSelected() {
182  return fZoomInSelected;
183  };
184  inline bool IsIconZoomOutSelected() {
185  return fZoomOutSelected;
186  };
187 
188  void SetIconMoveSelected();
189  void SetIconRotateSelected();
190  void SetIconPickSelected();
191  void SetIconZoomInSelected();
192  void SetIconZoomOutSelected();
193  void SetIconHLHSRSelected();
194  void SetIconHLRSelected();
195  void SetIconSolidSelected();
196  void SetIconWireframeSelected();
197  void SetIconPerspectiveSelected();
198  void SetIconOrthoSelected();
199 
200  inline QMainWindow * GetMainWindow() {
201  return fMainWindow;
202  };
203  // Return the main window
204 
205  inline QPixmap* getSearchIcon() { return fSearchIcon;};
206  // return the "search" icon pixmap
207  inline QPixmap* getClearIcon() { return fClearIcon;};
208  // return the "clear" icon pixmap
209 
210  void SetStartPage(const std::string&);
211  // Set the text on the first page of the viewer. If "", will take the last value as default
212  // Note: Qt Rich text format could be used, see link for example :
213  // https://qt-project.org/doc/qt-4.8/richtext-html-subset.html#table-cell-attributes
214 
215  inline QWidget* GetCoutWidget() {
216  return fCoutDockWidget->widget();
217  };
218  // Return the G4cout widget with filters
219 
220  inline G4UIDockWidget* GetCoutDockWidget() {
221  return fCoutDockWidget;
222  };
223  // Return the cout dockable widget as a QDockWidget
224 
225  inline G4UIDockWidget* GetUserInterfaceWidget() {
226  return fUIDockWidget;
227  };
228  // Return the UserInterface widget (including scene tree, help and History widgets)
229 
230  inline QTabWidget* GetUITabWidget() {
231  return fUITabWidget;
232  }
233  // return the viewer widget including all viewers
234 
235  inline QWidget* GetHistoryWidget() {
236  return fHistoryTBWidget;
237  }
238  // return the history widget
239 
240  inline QWidget* GetHelpWidget() {
241  return fHelpTBWidget;
242  }
243  // return the help widget
244 
245  bool AddViewerTab(QWidget* w, std::string title);
246  // Add a new tab in the viewer, could be used to add your own component
247 
248  bool AddViewerTabFromFile(std::string fileName, std::string title);
249  // Add a new tab in the viewer containing the content of the file in a QLabel
250 
251 public:
252  ~G4UIQt();
253  void Prompt(G4String);
254  void SessionTerminate();
255  virtual void PauseSessionStart(const G4String&);
256  virtual G4int ReceiveG4cout(const G4String&);
257  virtual G4int ReceiveG4cerr(const G4String&);
258  // G4String GetCommand(Widget);
259 
260 private:
261  void SecondaryLoop(G4String); // a VIRER
262  void CreateHelpWidget();
263  void InitHelpTreeAndVisParametersWidget();
264  void FillHelpTree();
265  void UpdateCommandCompleter();
266  void CreateIcons();
267  virtual void ExitHelp() const;
268  void SetDefaultIconsToolbar();
269 
270  void CreateHelpTree(QTreeWidgetItem*,G4UIcommandTree*);
271  QTreeWidgetItem* FindTreeItem(QTreeWidgetItem *,const QString&);
272 
273  QString GetCommandList(const G4UIcommand*);
274  void updateHelpArea(const G4UIcommand*);
275  virtual G4bool GetHelpChoice(G4int&);// have to be implemeted because we heritate from G4VBasicShell
276  bool eventFilter(QObject*,QEvent*);
277  void ActivateCommand(G4String);
278  QMap<int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
279 
280  QWidget* CreateVisParametersTBWidget();
281  QWidget* CreateHelpTBWidget();
282  G4UIDockWidget* CreateCoutTBWidget();
283  QWidget* CreateHistoryTBWidget();
284  G4UIDockWidget* CreateUITabWidget();
285  QWidget* CreateSceneTreeWidget();
286  void CreateViewerWidget();
287  void OpenHelpTreeOnCommand(const QString &);
288  QString GetShortCommandPath(QString);
289  QString GetLongCommandPath(QTreeWidgetItem*);
290  G4bool IsGUICommand(const G4UIcommand*);
291  bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, int, bool isDialog);
292  bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, bool isDialog);
293  void CreateViewerPropertiesDialog();
294  void CreatePickInfosDialog();
295 #ifdef G4MULTITHREADED
296  void UpdateCoutThreadFilter();
297 #endif
298  void FilterAllOutputTextArea();
299  QString FilterOutput(const G4UIOutputString&,const QString&,const QString&);
300  G4String GetThreadPrefix();
301  bool CheckG4EnvironmentVariable(char* txt, char* version);
302  QStandardItemModel* CreateCompleterModel(G4String aCmd);
303  void CreateEmptyViewerPropertiesWidget();
304  void CreateEmptyPickInfosWidget();
305 private:
306 
307  QMainWindow * fMainWindow;
308  QLabel *fCommandLabel;
309  QLineEdit * fCommandArea;
310  QTextEdit *fCoutTBTextArea;
311  QTabWidget* fUITabWidget;
312  std::vector <G4UIOutputString> fG4OutputString;
313  QLineEdit * fCoutFilter;
314  QCompleter* fCompleter;
315  bool fDefaultIcons;
316 
317  QListWidget *fHistoryTBTableList;
318  QTreeWidget *fHelpTreeWidget;
319  QWidget* fHelpTBWidget;
320  QWidget* fHistoryTBWidget;
321  G4UIDockWidget* fCoutDockWidget;
322  G4UIDockWidget* fUIDockWidget;
323  QWidget* fSceneTreeWidget;
324  QWidget* fViewerPropertiesWidget;
325  QWidget* fPickInfosWidget;
326  QLineEdit* fHelpLine;
327  G4QTabWidget* fViewerTabWidget;
328  QString fCoutText;
329  QTextEdit *fStartPage;
330  QSplitter * fHelpVSplitter;
331  QTextEdit* fParameterHelpLabel;
332  QTableWidget* fParameterHelpTable;
333 
334  QToolBar *fToolbarApp;
335  QToolBar *fToolbarUser;
336  QString fStringSeparator;
337  G4String fLastErrMessage;
338  QString fLastOpenPath;
339  QToolButton* fViewModePopupButton;
340  QToolButton* fSurfaceModePopupButton;
341 
342  QPixmap* fSearchIcon;
343  QPixmap* fClearIcon;
344  QPixmap* fSaveIcon;
345  QPixmap* fOpenIcon;
346  QPixmap* fMoveIcon;
347  QPixmap* fRotateIcon;
348  QPixmap* fPickIcon;
349  QPixmap* fZoomInIcon;
350  QPixmap* fZoomOutIcon;
351  QPixmap* fWireframeIcon;
352  QPixmap* fSolidIcon;
353  QPixmap* fHiddenLineRemovalIcon;
354  QPixmap* fHiddenLineAndSurfaceRemovalIcon;
355  QPixmap* fPerspectiveIcon;
356  QPixmap* fOrthoIcon;
357  QPixmap* fCommandIcon;
358  QPixmap* fDirIcon;
359  QPixmap* fRunIcon;
360  QPixmap* fParamIcon;
361  QPixmap* fPickTargetIcon;
362 
363 #ifdef G4MULTITHREADED
364  QComboBox* fThreadsFilterComboBox;
365 #endif
366  std::string fDefaultViewerFirstPageHTMLText;
367 
368  QDialog* fViewerPropertiesDialog;
369  QDialog* fPickInfosDialog;
370  QString fLastCompleteCommand;
371  bool fMoveSelected;
372  bool fRotateSelected;
373  bool fPickSelected;
374  bool fZoomInSelected;
375  bool fZoomOutSelected;
376 
377 private Q_SLOTS :
378  void ExitSession();
379  void ClearButtonCallback();
380  void SaveOutputCallback();
381  void CommandEnteredCallback();
382  void CommandEditedCallback(const QString & text);
383  void ButtonCallback(const QString&);
384  void HelpTreeClicCallback();
385  void HelpTreeDoubleClicCallback();
386  void ShowHelpCallback();
387  void CommandHistoryCallback();
388  void LookForHelpStringCallback();
389  void UpdateTabWidget(int);
390  void ResizeTabWidget( QResizeEvent* );
391  void CoutFilterCallback(const QString&);
392  void ThreadComboBoxCallback(int);
393  void TabCloseCallback(int);
394  void ToolBoxActivated(int);
395  void VisParameterCallback(QWidget*);
396  void ChangeColorCallback(QWidget*);
397  void ChangeCursorAction(const QString&);
398  void ChangeSurfaceStyle(const QString&);
399  void OpenIconCallback(const QString&);
400  void SaveIconCallback(const QString&);
401  void ViewerPropertiesIconCallback(int);
402  void ChangePerspectiveOrtho(const QString&);
403 };
404 
405 #endif
406 
407 #endif
408