Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UIQt.hh
Go to the documentation of this file.
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#include "G4VBasicShell.hh"
33#include "G4SceneTreeItem.hh"
34
35#include <qdialog.h>
36#include <qdockwidget.h>
37#include <qmap.h>
38#include <qobject.h>
39#include <qtabwidget.h>
40#include <qtreewidget.h>
41
42class QMainWindow;
43class QLineEdit;
44class G4UIsession;
45class QListWidget;
46class QTreeWidgetItem;
47class QTextEdit;
48class QTextBrowser;
49class QLabel;
50class QResizeEvent;
51class QTabWidget;
52class QSplitter;
53class QToolBar;
54class QTableWidget;
55class QPixmap;
56class QComboBox;
57class QCompleter;
58class QtGlobal;
59class QStandardItemModel;
60class QToolButton;
61
62// Class description :
63//
64// G4UIQt : class to handle a Qt interactive session.
65// G4UIQt is the Qt version of G4UIterminal.
66//
67// A command box is at disposal for entering/recalling Geant4 commands.
68// A menubar could be customized through the AddMenu, AddButton, AddIcon methods.
69// Note that there are corresponding Geant4 commands to add a
70// menus in the menubar and add buttons in a menu.
71// Ex :
72// /gui/addMenu test Test
73// /gui/addButton test Init /run/initialize
74// /gui/addButton test "Set gun" "/control/execute gun.g4m"
75// /gui/addButton test "Run one event" "/run/beamOn 1"
76//
77// Command completion, by typing "tab" key, is available on the
78// command line.
79//
80// Class description - end :
81
82class G4QTabWidget : public QTabWidget
83{
84 public:
86 G4QTabWidget(QWidget* aParent, G4int sizeX, G4int sizeY);
87 void paintEvent(QPaintEvent* event) override;
88 inline void setTabSelected(G4bool a) { fTabSelected = a; };
89 inline void setLastTabCreated(G4int a) { fLastCreated = a; };
90 inline bool isTabSelected() { return fTabSelected; };
95 inline void setPreferredSize(QSize s)
96 {
97 fPreferedSizeX = s.width() + 6; // tab label height + margin left+right
98 fPreferedSizeY = s.height() + 58; // margin left+right
99 }
100 inline QSize sizeHint() const override { return QSize(fPreferedSizeX, fPreferedSizeY); }
101};
102
104{
105 public:
106 G4UIOutputString(QString text, G4String thread = "", G4String outputstream = "info");
107 inline QString GetOutputList() { return " all info warning error "; };
108 QString fText;
110 G4String fOutputStream; // Error, Warning, Info
111};
112
113class G4UIDockWidget : public QDockWidget
114{
115 public:
116 G4UIDockWidget(QString txt);
117 void closeEvent(QCloseEvent*) override;
118};
119
120class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession
121{
122 Q_OBJECT
123
124 public: // With description
125 // (argv, argc) or (0, NULL) had to be given.
126 G4UIQt(G4int, char**);
127
128 // To enter interactive X loop ; waiting/executing command,...
129 G4UIsession* SessionStart() override;
130
131 // To add a pulldown menu in the menu bar.
132 // First argument is the name of the menu.
133 // Second argument is the label of the cascade button.
134 // Ex : AddMenu("my_menu","My menu")
135 void AddMenu(const char*, const char*) override;
136
137 // To add a push button in a pulldown menu.
138 // First argument is the name of the menu.
139 // Second argument is the label of the button.
140 // Third argument is the Geant4 command executed when the button is fired.
141 // Ex : AddButton("my_menu","Run","/run/beamOn 1");
142 void AddButton(const char*, const char*, const char*) override;
143
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
147 // wireframe solid hidden_line_removal hidden_line_and_surface_removal perspective ortho
148 // user_icon). Third argument is the Geant4 command executed when the button is fired. Fourth
149 // argument is the path to the icon file if "user_icon" selected Ex : AddButton("change background
150 // color","../background.xpm"," /vis/viewer/set/background");
151 void AddIcon(const char* userLabel, const char* iconFile, const char* command,
152 const char* file_name = "") override;
153
154 // Specify an output style - used by /gui/outputStyle
155 // First argument destination ("cout" etc or "all")
156 // Second argument is the required style - see guidance
157 void SetOutputStyle(const char* destination, const char* style) override;
158
159 // Enable/Disable the native Menu Bar in Qt
160 void NativeMenu(G4bool aVal) override;
161
162 // Clear Menu Bar, remove all actions
163 void ClearMenu() override;
164
165 // Enable/Disable the default icon ToolBar in Qt
166 void DefaultIcons(G4bool aVal) override;
167
168 // To add a tab for vis openGL Qt driver
169 G4bool AddTabWidget(QWidget*, QString);
170
171 inline QTabWidget* GetViewerTabWidget() { return fViewerTabWidget; };
172
173 // Get the "old" scene tree component
174 QWidget* GetSceneTreeWidget();
175
176 // Get the Viewer Properties Widget
177 QWidget* GetViewerPropertiesWidget();
178
179 // Get the Pick Widget
180 QWidget* GetPickInfosWidget();
181
183
184 inline G4bool IsIconMoveSelected() { return fMoveSelected; };
185 inline G4bool IsIconRotateSelected() { return fRotateSelected; };
186 inline G4bool IsIconPickSelected() { return fPickSelected; };
187 inline G4bool IsIconZoomInSelected() { return fZoomInSelected; };
188 inline G4bool IsIconZoomOutSelected() { return fZoomOutSelected; };
189
190 void SetIconMoveSelected();
192 void SetIconPickSelected();
196 void SetIconHLRSelected();
201
202 // Return the main window
203 inline QMainWindow* GetMainWindow() { return fMainWindow; };
204
205 // return the "search" icon pixmap
206 inline QPixmap* getSearchIcon() { return fSearchIcon; };
207
208 // return the "clear" icon pixmap
209 inline QPixmap* getClearIcon() { return fClearIcon; };
210
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 void SetStartPage(const std::string&);
215
216 // Return the G4cout widget with filters
217 inline QWidget* GetCoutWidget() { return fCoutDockWidget->widget(); };
218
219 // Return the cout dockable widget as a QDockWidget
220 inline G4UIDockWidget* GetCoutDockWidget() { return fCoutDockWidget; };
221
222 // Return the UserInterface widget (including scene tree, help and History widgets)
223 inline G4UIDockWidget* GetUserInterfaceWidget() { return fUIDockWidget; };
224
225 // return the viewer widget including all viewers
226 inline QTabWidget* GetUITabWidget() { return fUITabWidget; }
227
228 // return the history widget
229 inline QWidget* GetHistoryWidget() { return fHistoryTBWidget; }
230
231 // return the help widget
232 inline QWidget* GetHelpWidget() { return fHelpTBWidget; }
233
234 // Add a new tab in the viewer, could be used to add your own component
235 G4bool AddViewerTab(QWidget* w, std::string title);
236
237 // Add a new tab in the viewer containing the content of the file in a QLabel
238 G4bool AddViewerTabFromFile(std::string fileName, std::string title);
239
240 // Update "new" scene tree
241 void UpdateSceneTree(const G4SceneTreeItem&) override;
242
243public:
244 ~G4UIQt() override;
245 void Prompt(G4String);
246 void SessionTerminate();
247 void PauseSessionStart(const G4String&) override;
248 G4int ReceiveG4debug(const G4String&) override;
249 G4int ReceiveG4cout(const G4String&) override;
250 G4int ReceiveG4cerr(const G4String&) override;
251 // G4String GetCommand(Widget);
252
253 private:
254 void SecondaryLoop(G4String); // a VIRER
255 void CreateHelpWidget();
256 void InitHelpTreeAndVisParametersWidget();
257 void FillHelpTree();
258 void UpdateCommandCompleter();
259 void CreateIcons();
260 void ExitHelp() const override;
261 void SetDefaultIconsToolbar();
262
263 void CreateHelpTree(QTreeWidgetItem*, G4UIcommandTree*);
264 QTreeWidgetItem* FindTreeItem(QTreeWidgetItem*, const QString&);
265
266 // Create the "mother" widget
267 QWidget* CreateSceneTreeWidget();
268
269 // Classes/structs and functions for the "new" scene tree
270 // UpdateSceneTree is in "public" section above.
271 // Create and connect the new tree widget
272 void CreateNewSceneTreeWidget();
273 // Build Physical Volume tree of touchables
274 void BuildPVQTree(const G4SceneTreeItem& g4stItem, QTreeWidgetItem* qtwItem);
275 // Callbacks on new scene tree items
276 void SceneTreeItemClicked(QTreeWidgetItem*);
277 void SceneTreeItemDoubleClicked(QTreeWidgetItem*);
278 void SceneTreeItemExpanded(QTreeWidgetItem*);
279 void SceneTreeItemCollapsed(QTreeWidgetItem*);
280 // Class for trapping special mouse events on new scene tree
281 struct NewSceneTreeItemTreeWidget: public QTreeWidget {
282 void mousePressEvent(QMouseEvent*) override;
283 void ActWithoutParameter(const G4String& action, G4SceneTreeItem*);
284 void ActWithABool(const G4String& action, G4SceneTreeItem*, G4bool);
285 void ActWithAnInteger(const G4String& action, G4SceneTreeItem*);
286 void ActWithADouble(const G4String& action, G4SceneTreeItem*);
287 void ActWithAString(const G4String& action, G4SceneTreeItem*);
288 };
289
290 QString GetCommandList(const G4UIcommand*);
291 void updateHelpArea(const G4UIcommand*);
292 G4bool GetHelpChoice(
293 G4int&) override; // have to be implemeted because we heritate from G4VBasicShell
294 bool eventFilter(QObject*, QEvent*) override;
295 void ActivateCommand(G4String);
296#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
297 QMap<G4int, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
298#else
299 QMultiMap<G4int, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
300#endif
301 QWidget* CreateVisParametersTBWidget();
302 QWidget* CreateHelpTBWidget();
303 G4UIDockWidget* CreateCoutTBWidget();
304 QWidget* CreateHistoryTBWidget();
305 G4UIDockWidget* CreateUITabWidget();
306 void CreateViewerWidget();
307 void OpenHelpTreeOnCommand(const QString&);
308 QString GetShortCommandPath(QString);
309 QString GetLongCommandPath(QTreeWidgetItem*);
310 G4bool IsGUICommand(const G4UIcommand*);
311 G4bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, G4int, G4bool isDialog);
312 G4bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, G4bool isDialog);
313 void CreateViewerPropertiesDialog();
314 void CreatePickInfosDialog();
315#ifdef G4MULTITHREADED
316 void UpdateCoutThreadFilter();
317#endif
318 void FilterAllOutputTextArea();
319 QString FilterOutput(const G4UIOutputString&, const QString&, const QString&);
320 G4String GetThreadPrefix();
321 G4bool CheckG4EnvironmentVariable(char* txt, char* version);
322 QStandardItemModel* CreateCompleterModel(G4String aCmd);
323 void CreateEmptyViewerPropertiesWidget();
324 void CreateEmptyPickInfosWidget();
325
326 private:
327 QMainWindow* fMainWindow;
328 QLabel* fCommandLabel;
329 QLineEdit* fCommandArea;
330 QTextEdit* fCoutTBTextArea;
331 QTabWidget* fUITabWidget;
332 std::vector<G4UIOutputString> fG4OutputString;
333 QLineEdit* fCoutFilter;
334 QCompleter* fCompleter;
335 G4bool fDefaultIcons;
336
337 QListWidget* fHistoryTBTableList;
338 QTreeWidget* fHelpTreeWidget;
339 QWidget* fHelpTBWidget;
340 QWidget* fHistoryTBWidget;
341 G4UIDockWidget* fCoutDockWidget;
342 G4UIDockWidget* fUIDockWidget;
343 QWidget* fSceneTreeWidget;
344 QWidget* fNewSceneTreeWidget;
345 NewSceneTreeItemTreeWidget* fNewSceneTreeItemTreeWidget;
346 QWidget* fViewerPropertiesWidget;
347 QWidget* fPickInfosWidget;
348 QLineEdit* fHelpLine;
349 G4QTabWidget* fViewerTabWidget;
350 QString fCoutText;
351 QTextBrowser* fStartPage;
352 QSplitter* fHelpVSplitter;
353 QTextEdit* fParameterHelpLabel;
354 QTableWidget* fParameterHelpTable;
355
356 QToolBar* fToolbarApp;
357 QToolBar* fToolbarUser;
358 QString fStringSeparator;
359 G4String fLastErrMessage;
360 QString fLastOpenPath;
361
362 QPixmap* fSearchIcon;
363 QPixmap* fClearIcon;
364 QPixmap* fSaveIcon;
365 QPixmap* fOpenIcon;
366 QPixmap* fMoveIcon;
367 QPixmap* fRotateIcon;
368 QPixmap* fPickIcon;
369 QPixmap* fZoomInIcon;
370 QPixmap* fZoomOutIcon;
371 QPixmap* fWireframeIcon;
372 QPixmap* fSolidIcon;
373 QPixmap* fHiddenLineRemovalIcon;
374 QPixmap* fHiddenLineAndSurfaceRemovalIcon;
375 QPixmap* fPerspectiveIcon;
376 QPixmap* fOrthoIcon;
377 QPixmap* fCommandIcon;
378 QPixmap* fDirIcon;
379 QPixmap* fRunIcon;
380 QPixmap* fParamIcon;
381 QPixmap* fPickTargetIcon;
382 QPixmap* fExitIcon;
383
384#ifdef G4MULTITHREADED
385 QComboBox* fThreadsFilterComboBox;
386#endif
387 std::string fDefaultViewerFirstPageHTMLText;
388
389 QDialog* fViewerPropertiesDialog;
390 QDialog* fPickInfosDialog;
391 QString fLastCompleteCommand;
392 G4bool fMoveSelected;
393 G4bool fRotateSelected;
394 G4bool fPickSelected;
395 G4bool fZoomInSelected;
396 G4bool fZoomOutSelected;
397
398 private Q_SLOTS:
399 void ExitSession();
400 void ClearButtonCallback();
401 void SaveOutputCallback();
402 void CommandEnteredCallback();
403 void CommandEditedCallback(const QString& text);
404 void ButtonCallback(const QString&);
405 void HelpTreeClicCallback();
406 void HelpTreeDoubleClicCallback();
407 void ShowHelpCallback();
408 void CommandHistoryCallback();
409 void LookForHelpStringCallback();
410 void UpdateTabWidget(int);
411 void ResizeTabWidget(QResizeEvent*);
412 void CoutFilterCallback(const QString&);
413 void ThreadComboBoxCallback(int);
414 void TabCloseCallback(int);
415 void ToolBoxActivated(int);
416 void VisParameterCallback(QWidget*);
417 void ChangeColorCallback(QWidget*);
418 void ChangeCursorAction(const QString&);
419 void ChangeSurfaceStyle(const QString&);
420 void OpenIconCallback(const QString&);
421 void SaveIconCallback(const QString&);
422 void ViewerPropertiesIconCallback(int);
423 void ChangePerspectiveOrtho(const QString&);
424};
425
426#endif
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
void setLastTabCreated(G4int a)
Definition G4UIQt.hh:89
void paintEvent(QPaintEvent *event) override
Definition G4UIQt.cc:5470
void setTabSelected(G4bool a)
Definition G4UIQt.hh:88
G4int fLastCreated
Definition G4UIQt.hh:92
void setPreferredSize(QSize s)
Definition G4UIQt.hh:95
G4int fPreferedSizeX
Definition G4UIQt.hh:93
QSize sizeHint() const override
Definition G4UIQt.hh:100
G4int fPreferedSizeY
Definition G4UIQt.hh:94
bool isTabSelected()
Definition G4UIQt.hh:90
G4bool fTabSelected
Definition G4UIQt.hh:91
void closeEvent(QCloseEvent *) override
Definition G4UIQt.cc:5498
G4UIDockWidget(QString txt)
Definition G4UIQt.cc:5496
G4String fOutputStream
Definition G4UIQt.hh:110
QString fText
Definition G4UIQt.hh:108
G4String fThread
Definition G4UIQt.hh:109
G4UIOutputString(QString text, G4String thread="", G4String outputstream="info")
Definition G4UIQt.cc:5423
QString GetOutputList()
Definition G4UIQt.hh:107
G4bool IsSplitterReleased()
QMainWindow * GetMainWindow()
Definition G4UIQt.hh:203
void SetIconPickSelected()
Definition G4UIQt.cc:5149
G4bool AddTabWidget(QWidget *, QString)
Definition G4UIQt.cc:2283
QWidget * GetViewerPropertiesWidget()
Definition G4UIQt.cc:2223
void SetIconOrthoSelected()
Definition G4UIQt.cc:5384
void UpdateSceneTree(const G4SceneTreeItem &) override
Definition G4UIQt.cc:1510
G4UIsession * SessionStart() override
Definition G4UIQt.cc:2355
void SetStartPage(const std::string &)
Definition G4UIQt.cc:2311
QWidget * GetCoutWidget()
Definition G4UIQt.hh:217
G4bool IsIconRotateSelected()
Definition G4UIQt.hh:185
G4bool IsIconZoomInSelected()
Definition G4UIQt.hh:187
G4bool AddViewerTabFromFile(std::string fileName, std::string title)
Definition G4UIQt.cc:2255
~G4UIQt() override
Definition G4UIQt.cc:274
G4bool IsIconMoveSelected()
Definition G4UIQt.hh:184
G4int ReceiveG4cout(const G4String &) override
Definition G4UIQt.cc:2553
void SetIconZoomInSelected()
Definition G4UIQt.cc:5184
void PauseSessionStart(const G4String &) override
Definition G4UIQt.cc:2418
void AddMenu(const char *, const char *) override
Definition G4UIQt.cc:2793
QPixmap * getSearchIcon()
Definition G4UIQt.hh:206
G4bool IsIconZoomOutSelected()
Definition G4UIQt.hh:188
QWidget * GetSceneTreeWidget()
Definition G4UIQt.cc:2219
G4int ReceiveG4cerr(const G4String &) override
Definition G4UIQt.cc:2654
void AddButton(const char *, const char *, const char *) override
Definition G4UIQt.cc:2810
G4UIDockWidget * GetUserInterfaceWidget()
Definition G4UIQt.hh:223
void SetOutputStyle(const char *destination, const char *style) override
Definition G4UIQt.cc:3093
void SetIconZoomOutSelected()
Definition G4UIQt.cc:5219
G4UIDockWidget * GetCoutDockWidget()
Definition G4UIQt.hh:220
void SetIconHLRSelected()
Definition G4UIQt.cc:5308
void ClearMenu() override
Definition G4UIQt.cc:3110
void SetIconPerspectiveSelected()
Definition G4UIQt.cc:5363
QPixmap * getClearIcon()
Definition G4UIQt.hh:209
QTabWidget * GetViewerTabWidget()
Definition G4UIQt.hh:171
void NativeMenu(G4bool aVal) override
Definition G4UIQt.cc:3102
QWidget * GetPickInfosWidget()
Definition G4UIQt.cc:2233
void DefaultIcons(G4bool aVal) override
Definition G4UIQt.cc:287
void SetIconSolidSelected()
Definition G4UIQt.cc:5254
QWidget * GetHelpWidget()
Definition G4UIQt.hh:232
G4int ReceiveG4debug(const G4String &) override
Definition G4UIQt.cc:2464
void SetIconRotateSelected()
Definition G4UIQt.cc:5119
void SessionTerminate()
Definition G4UIQt.cc:2403
G4bool IsIconPickSelected()
Definition G4UIQt.hh:186
QTabWidget * GetUITabWidget()
Definition G4UIQt.hh:226
void Prompt(G4String)
Definition G4UIQt.cc:2396
void SetIconWireframeSelected()
Definition G4UIQt.cc:5281
void SetIconMoveSelected()
Definition G4UIQt.cc:5089
G4bool AddViewerTab(QWidget *w, std::string title)
Definition G4UIQt.cc:2243
G4UIQt(G4int, char **)
Definition G4UIQt.cc:118
void AddIcon(const char *userLabel, const char *iconFile, const char *command, const char *file_name="") override
Definition G4UIQt.cc:2864
void SetIconHLHSRSelected()
Definition G4UIQt.cc:5335
QWidget * GetHistoryWidget()
Definition G4UIQt.hh:229