Geant4 11.4.0
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 QSlider;
48class QTextEdit;
49class QTextBrowser;
50class QLabel;
51class QResizeEvent;
52class QTabWidget;
53class QSplitter;
54class QToolBar;
55class QTableWidget;
56class QPixmap;
57class QComboBox;
58class QCompleter;
59class QtGlobal;
60class QStandardItemModel;
61class QToolButton;
62class QRadioButton;
63
64// Class description :
65//
66// G4UIQt : class to handle a Qt interactive session.
67// G4UIQt is the Qt version of G4UIterminal.
68//
69// A command box is at disposal for entering/recalling Geant4 commands.
70// A menubar could be customized through the AddMenu, AddButton, AddIcon methods.
71// Note that there are corresponding Geant4 commands to add a
72// menus in the menubar and add buttons in a menu.
73// Ex :
74// /gui/addMenu test Test
75// /gui/addButton test Init /run/initialize
76// /gui/addButton test "Set gun" "/control/execute gun.g4m"
77// /gui/addButton test "Run one event" "/run/beamOn 1"
78//
79// Command completion, by typing "tab" key, is available on the
80// command line.
81//
82// Class description - end :
83
84#if QT_VERSION < 0x060000
85class G4QTabWidget : public QTabWidget
86{
87 public:
89 G4QTabWidget(QWidget* aParent, G4int sizeX, G4int sizeY);
90 void paintEvent(QPaintEvent* event) override;
91 inline void setTabSelected(G4bool a) { fTabSelected = a; };
92 inline void setLastTabCreated(G4int a) { fLastCreated = a; };
93 inline bool isTabSelected() { return fTabSelected; };
98 inline void setPreferredSize(QSize size)
99 {
100 fPreferedSizeX = size.width() + 6; // tab label height + margin left+right
101 fPreferedSizeY = size.height() + 58; // margin left+right
102 }
103 inline QSize sizeHint() const override { return QSize(fPreferedSizeX, fPreferedSizeY); }
104};
105#endif
106
108{
109 public:
110 G4UIOutputString(const QString& text, const G4String& thread = "", const G4String& outputstream = "info");
111 inline QString GetOutputList() { return " all info warning error "; };
112 QString fText;
114 G4String fOutputStream; // Error, Warning, Info
115};
116
117class G4UIDockWidget : public QDockWidget
118{
119 public:
120 G4UIDockWidget(const QString& txt);
121 void closeEvent(QCloseEvent*) override;
122};
123
124class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession
125{
126 Q_OBJECT
127
128 public: // With description
129 // (argv, argc) or (0, NULL) had to be given.
130 G4UIQt(G4int, char**);
131
132 // To enter interactive X loop ; waiting/executing command,...
133 G4UIsession* SessionStart() override;
134
135 // To add a pulldown menu in the menu bar.
136 // First argument is the name of the menu.
137 // Second argument is the label of the cascade button.
138 // Ex : AddMenu("my_menu","My menu")
139 void AddMenu(const char*, const char*) override;
140
141 // To add a push button in a pulldown menu.
142 // First argument is the name of the menu.
143 // Second argument is the label of the button.
144 // Third argument is the Geant4 command executed when the button is fired.
145 // Ex : AddButton("my_menu","Run","/run/beamOn 1");
146 void AddButton(const char*, const char*, const char*) override;
147
148 // To add a icon in the toolbar
149 // First argument is the label of the icon.
150 // Second argument is the selected icon type (open save move rotate pick zoom_in zoom_out
151 // wireframe solid hidden_line_removal hidden_line_and_surface_removal perspective ortho
152 // user_icon). Third argument is the Geant4 command executed when the button is fired. Fourth
153 // argument is the path to the icon file if "user_icon" selected Ex : AddButton("change background
154 // color","../background.xpm"," /vis/viewer/set/background");
155 void AddIcon(const char* userLabel, const char* iconFile, const char* command,
156 const char* file_name = "") override;
157
158 // Specify an output style - used by /gui/outputStyle
159 // First argument destination ("cout" etc or "all")
160 // Second argument is the required style - see guidance
161 void SetOutputStyle(const char* destination, const char* style) override;
162
163 // Enable/Disable the native Menu Bar in Qt
164 void NativeMenu(G4bool aVal) override;
165
166 // Clear Menu Bar, remove all actions
167 void ClearMenu() override;
168
169 // Enable/Disable the default icon ToolBar in Qt
170 void DefaultIcons(G4bool aVal) override;
171
172 // To add a tab for vis openGL Qt driver
173 G4bool AddTabWidget(QWidget*, QString);
174
175 inline QTabWidget* GetViewerTabWidget() { return fViewerTabWidget; };
176
177 // Get the "old" scene tree component
178 QWidget* GetSceneTreeWidget();
179
180 // Get the Viewer Properties Widget
181 QWidget* GetViewerPropertiesWidget();
182
183 // Get the Pick Widget
184 QWidget* GetPickInfosWidget();
185
187
188 inline G4bool IsIconMoveSelected() { return fMoveSelected; };
189 inline G4bool IsIconRotateSelected() { return fRotateSelected; };
190 inline G4bool IsIconPickSelected() { return fPickSelected; };
191 inline G4bool IsIconZoomInSelected() { return fZoomInSelected; };
192 inline G4bool IsIconZoomOutSelected() { return fZoomOutSelected; };
193
194 void SetIconMoveSelected();
196 void TogglePickSelection();
200 void SetIconHLRSelected();
206
207 // Return the main window
208 inline QMainWindow* GetMainWindow() { return fMainWindow; };
209
210 // return the "search" icon pixmap
211 inline QPixmap* getSearchIcon() { return fSearchIcon; };
212
213 // return the "clear" icon pixmap
214 inline QPixmap* getClearIcon() { return fClearIcon; };
215
216 // Set the text on the first page of the viewer. If "", will take the last value as default
217 // Note: Qt Rich text format could be used, see link for example :
218 // https://qt-project.org/doc/qt-4.8/richtext-html-subset.html#table-cell-attributes
219 void SetStartPage(const std::string&);
220
221 // Return the G4cout widget with filters
222 inline QWidget* GetCoutWidget() { return fCoutDockWidget->widget(); };
223
224 // Return the cout dockable widget as a QDockWidget
225 inline G4UIDockWidget* GetCoutDockWidget() { return fCoutDockWidget; };
226
227 // Return the UserInterface widget (including scene tree, help and History widgets)
228 inline G4UIDockWidget* GetUserInterfaceWidget() { return fUIDockWidget; };
229
230 // return the viewer widget including all viewers
231 inline QTabWidget* GetUITabWidget() { return fUITabWidget; }
232
233 // return the history widget
234 inline QWidget* GetHistoryWidget() { return fHistoryTBWidget; }
235
236 // return the help widget
237 inline QWidget* GetHelpWidget() { return fHelpTBWidget; }
238
239 // Add a new tab in the viewer, could be used to add your own component
240 G4bool AddViewerTab(QWidget* w, std::string title);
241
242 // Add a new tab in the viewer containing the content of the file in a QLabel
243 G4bool AddViewerTabFromFile(std::string fileName, std::string title);
244
245 // Update "new" scene tree
246 void UpdateSceneTree(const G4SceneTreeItem&) override;
247
248 // Update control widgets
249 void UpdateDrawingStyle(G4int style) override;
250 void UpdateProjectionStyle(G4int style) override;
251 void UpdateTransparencySlider(G4double depth, G4int option) override;
252
253
254public:
255 ~G4UIQt() override;
256 void Prompt(const G4String&);
257 void SessionTerminate();
258 void PauseSessionStart(const G4String&) override;
259 G4int ReceiveG4debug(const G4String&) override;
260 G4int ReceiveG4cout(const G4String&) override;
261 G4int ReceiveG4cerr(const G4String&) override;
262 // G4String GetCommand(Widget);
263
264private:
265 void SecondaryLoop(const G4String&); // a VIRER
266 void CreateHelpWidget();
267 void InitHelpTreeAndVisParametersWidget();
268 void FillHelpTree();
269 void UpdateCommandCompleter();
270 void CreateIcons();
271 void ExitHelp() const override;
272 void SetDefaultIconsToolbar();
273
274 void CreateHelpTree(QTreeWidgetItem*, G4UIcommandTree*);
275 QTreeWidgetItem* FindTreeItem(QTreeWidgetItem*, const QString&);
276
277 // Create the "mother" widget
278 QWidget* CreateSceneTreeWidget();
279
280 // Classes/structs and functions for the "new" scene tree
281 // UpdateSceneTree is in "public" section above.
282 // Create and connect the new tree widget
283 void CreateNewSceneTreeWidget();
284 // Build Physical Volume tree of touchables
285 void BuildPVQTree(const G4SceneTreeItem& g4stItem, QTreeWidgetItem* qtwItem);
286 // Callbacks on new scene tree items
287 void SceneTreeItemClicked(QTreeWidgetItem*);
288 void SceneTreeItemDoubleClicked(QTreeWidgetItem*);
289 void SceneTreeItemExpanded(QTreeWidgetItem*);
290 void SceneTreeItemCollapsed(QTreeWidgetItem*);
291 void SliderValueChanged(G4int value);
292 void SliderReleased();
293 void SliderRadioButtonClicked(G4int buttonNo);
294 // Class for trapping special mouse events on new scene tree
295 struct NewSceneTreeItemTreeWidget: public QTreeWidget {
296 void mousePressEvent(QMouseEvent*) override;
297 void ActWithoutParameter(const G4String& action, G4SceneTreeItem*);
298 void ActWithABool(const G4String& action, G4SceneTreeItem*, G4bool);
299 void ActWithAnInteger(const G4String& action, G4SceneTreeItem*);
300 void ActWithADouble(const G4String& action, G4SceneTreeItem*);
301 void ActWithAString(const G4String& action, G4SceneTreeItem*);
302 };
303
304 QString GetCommandList(const G4UIcommand*);
305 void updateHelpArea(const G4UIcommand*);
306 G4bool GetHelpChoice(
307 G4int&) override; // have to be implemeted because we heritate from G4VBasicShell
308 bool eventFilter(QObject*, QEvent*) override;
309 void ActivateCommand(G4String);
310#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
311 QMap<G4int, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
312#else
313 QMultiMap<G4int, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
314#endif
315 QWidget* CreateVisParametersTBWidget();
316 QWidget* CreateHelpTBWidget();
317 QWidget* CreateTimeWindowWidget();
318 G4UIDockWidget* CreateCoutTBWidget();
319 QWidget* CreateHistoryTBWidget();
320 G4UIDockWidget* CreateUITabWidget();
321 void CreateViewerWidget();
322 void OpenHelpTreeOnCommand(const QString&);
323 QString GetShortCommandPath(QString&);
324 QString GetLongCommandPath(QTreeWidgetItem*);
325 G4bool IsGUICommand(const G4UIcommand*);
326 G4bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, G4int, G4bool isDialog);
327 G4bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, G4bool isDialog);
328 void CreateViewerPropertiesDialog();
329 void CreatePickInfosDialog();
330#ifdef G4MULTITHREADED
331 void UpdateCoutThreadFilter();
332#endif
333 void FilterAllOutputTextArea();
334 QString FilterOutput(const G4UIOutputString&, const QString&, const QString&);
335 G4String GetThreadPrefix();
336 G4bool CheckG4EnvironmentVariable(char* txt, char* version);
337 QStandardItemModel* CreateCompleterModel(const G4String& aCmd);
338 void CreateEmptyViewerPropertiesWidget();
339 void CreateEmptyPickInfosWidget();
340
341 private:
342 QMainWindow* fMainWindow;
343 QLabel* fCommandLabel;
344 QLineEdit* fCommandArea;
345 QTextEdit* fCoutTBTextArea;
346 QTabWidget* fUITabWidget;
347 std::vector<G4UIOutputString> fG4OutputString;
348 QLineEdit* fCoutFilter;
349 QCompleter* fCompleter;
350 G4bool fDefaultIcons;
351
352 QListWidget* fHistoryTBTableList;
353 QTreeWidget* fHelpTreeWidget;
354 QWidget* fHelpTBWidget;
355 QWidget* fTimeWindowWidget;
356 QWidget* fHistoryTBWidget;
357 G4UIDockWidget* fCoutDockWidget;
358 G4UIDockWidget* fUIDockWidget;
359 QWidget* fSceneTreeWidget;
360 QWidget* fNewSceneTreeWidget;
361 NewSceneTreeItemTreeWidget* fNewSceneTreeItemTreeWidget;
362 G4int fMaxPVDepth;
363 QSlider* fNewSceneTreeSlider;
364 QRadioButton* fUnwrapButtonWidget;
365 QRadioButton* fFadeButtonWidget;
366 QRadioButton* fXrayButtonWidget;
367 QWidget* fViewerPropertiesWidget;
368 QWidget* fPickInfosWidget;
369 QLineEdit* fHelpLine;
370#if QT_VERSION < 0x060000
371 G4QTabWidget* fViewerTabWidget;
372#else
373 QTabWidget* fViewerTabWidget;
374#endif
375 QString fCoutText;
376 QTextBrowser* fStartPage;
377 QSplitter* fHelpVSplitter;
378 QTextEdit* fParameterHelpLabel;
379 QTableWidget* fParameterHelpTable;
380
381 QToolBar* fToolbarApp;
382 QToolBar* fToolbarUser;
383 QString fStringSeparator;
384 G4String fLastErrMessage;
385 QString fLastOpenPath;
386
387 QPixmap* fSearchIcon;
388 QPixmap* fClearIcon;
389 QPixmap* fSaveIcon;
390 QPixmap* fOpenIcon;
391 QPixmap* fMoveIcon;
392 QPixmap* fRotateIcon;
393 QPixmap* fPickIcon;
394 QPixmap* fZoomInIcon;
395 QPixmap* fZoomOutIcon;
396 QPixmap* fWireframeIcon;
397 QPixmap* fSolidIcon;
398 QPixmap* fPointCloudIcon;
399 QPixmap* fHiddenLineRemovalIcon;
400 QPixmap* fHiddenLineAndSurfaceRemovalIcon;
401 QPixmap* fPerspectiveIcon;
402 QPixmap* fOrthoIcon;
403 QPixmap* fCommandIcon;
404 QPixmap* fDirIcon;
405 QPixmap* fRunIcon;
406 QPixmap* fParamIcon;
407 QPixmap* fPickTargetIcon;
408 QPixmap* fExitIcon;
409 QPixmap* fResetCameraIcon;
410 QPixmap* fResetTargetPointIcon;
411
412#ifdef G4MULTITHREADED
413 QComboBox* fThreadsFilterComboBox;
414#endif
415 std::string fDefaultViewerFirstPageHTMLText;
416
417 QDialog* fViewerPropertiesDialog;
418 QDialog* fPickInfosDialog;
419 QString fLastCompleteCommand;
420 G4bool fMoveSelected;
421 G4bool fRotateSelected;
422 G4bool fPickSelected;
423 G4bool fZoomInSelected;
424 G4bool fZoomOutSelected;
425
426 private Q_SLOTS:
427 void ExitSession();
428 void ClearButtonCallback();
429 void SaveOutputCallback();
430 void CommandEnteredCallback();
431 void CommandEditedCallback(const QString& text);
432 void ButtonCallback(const QString&);
433 void HelpTreeClicCallback();
434 void HelpTreeDoubleClicCallback();
435 void ShowHelpCallback();
436 void CommandHistoryCallback();
437 void LookForHelpStringCallback();
438 void UpdateTabWidget(int);
439 void ResizeTabWidget(QResizeEvent*);
440 void CoutFilterCallback(const QString&);
441 void ThreadComboBoxCallback(int);
442 void TabCloseCallback(int);
443 void ToolBoxActivated(int);
444 void VisParameterCallback(QWidget*);
445 void ChangeColorCallback(QWidget*);
446 void ChangeCursorAction(const QString&);
447 void ChangeSurfaceStyle(const QString&);
448 void OpenIconCallback(const QString&);
449 void SaveIconCallback(const QString&);
450 void ViewerPropertiesIconCallback(int);
451 void ChangePerspectiveOrtho(const QString&);
452 void ResetCameraCallback();
453
454};
455
456#endif
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
void setLastTabCreated(G4int a)
Definition G4UIQt.hh:92
void paintEvent(QPaintEvent *event) override
Definition G4UIQt.cc:6500
void setTabSelected(G4bool a)
Definition G4UIQt.hh:91
G4int fLastCreated
Definition G4UIQt.hh:95
G4int fPreferedSizeX
Definition G4UIQt.hh:96
QSize sizeHint() const override
Definition G4UIQt.hh:103
G4int fPreferedSizeY
Definition G4UIQt.hh:97
bool isTabSelected()
Definition G4UIQt.hh:93
void setPreferredSize(QSize size)
Definition G4UIQt.hh:98
G4bool fTabSelected
Definition G4UIQt.hh:94
void closeEvent(QCloseEvent *) override
Definition G4UIQt.cc:6529
G4UIDockWidget(const QString &txt)
Definition G4UIQt.cc:6527
G4String fOutputStream
Definition G4UIQt.hh:114
QString fText
Definition G4UIQt.hh:112
G4String fThread
Definition G4UIQt.hh:113
G4UIOutputString(const QString &text, const G4String &thread="", const G4String &outputstream="info")
Definition G4UIQt.cc:6427
QString GetOutputList()
Definition G4UIQt.hh:111
G4bool IsSplitterReleased()
QMainWindow * GetMainWindow()
Definition G4UIQt.hh:208
G4bool AddTabWidget(QWidget *, QString)
Definition G4UIQt.cc:3215
QWidget * GetViewerPropertiesWidget()
Definition G4UIQt.cc:3155
void SetIconOrthoSelected()
Definition G4UIQt.cc:6386
void UpdateSceneTree(const G4SceneTreeItem &) override
Definition G4UIQt.cc:1707
G4UIsession * SessionStart() override
Definition G4UIQt.cc:3317
void SetStartPage(const std::string &)
Definition G4UIQt.cc:3256
QWidget * GetCoutWidget()
Definition G4UIQt.hh:222
void UpdateDrawingStyle(G4int style) override
Definition G4UIQt.cc:1761
G4bool IsIconRotateSelected()
Definition G4UIQt.hh:189
G4bool IsIconZoomInSelected()
Definition G4UIQt.hh:191
G4bool AddViewerTabFromFile(std::string fileName, std::string title)
Definition G4UIQt.cc:3187
~G4UIQt() override
Definition G4UIQt.cc:284
G4bool IsIconMoveSelected()
Definition G4UIQt.hh:188
G4int ReceiveG4cout(const G4String &) override
Definition G4UIQt.cc:3515
void SetIconZoomInSelected()
Definition G4UIQt.cc:6151
void PauseSessionStart(const G4String &) override
Definition G4UIQt.cc:3380
void AddMenu(const char *, const char *) override
Definition G4UIQt.cc:3755
QPixmap * getSearchIcon()
Definition G4UIQt.hh:211
G4bool IsIconZoomOutSelected()
Definition G4UIQt.hh:192
void UpdateProjectionStyle(G4int style) override
Definition G4UIQt.cc:1784
QWidget * GetSceneTreeWidget()
Definition G4UIQt.cc:3151
G4int ReceiveG4cerr(const G4String &) override
Definition G4UIQt.cc:3616
void AddButton(const char *, const char *, const char *) override
Definition G4UIQt.cc:3772
G4UIDockWidget * GetUserInterfaceWidget()
Definition G4UIQt.hh:228
void SetOutputStyle(const char *destination, const char *style) override
Definition G4UIQt.cc:4061
void SetIconZoomOutSelected()
Definition G4UIQt.cc:6182
G4UIDockWidget * GetCoutDockWidget()
Definition G4UIQt.hh:225
void SetIconHLRSelected()
Definition G4UIQt.cc:6273
void ClearMenu() override
Definition G4UIQt.cc:4078
void SetIconPerspectiveSelected()
Definition G4UIQt.cc:6365
void UpdateTransparencySlider(G4double depth, G4int option) override
Definition G4UIQt.cc:1792
QPixmap * getClearIcon()
Definition G4UIQt.hh:214
QTabWidget * GetViewerTabWidget()
Definition G4UIQt.hh:175
void NativeMenu(G4bool aVal) override
Definition G4UIQt.cc:4070
QWidget * GetPickInfosWidget()
Definition G4UIQt.cc:3165
void DefaultIcons(G4bool aVal) override
Definition G4UIQt.cc:297
void SetIconSolidSelected()
Definition G4UIQt.cc:6213
QWidget * GetHelpWidget()
Definition G4UIQt.hh:237
G4int ReceiveG4debug(const G4String &) override
Definition G4UIQt.cc:3426
void SetIconRotateSelected()
Definition G4UIQt.cc:6106
void Prompt(const G4String &)
Definition G4UIQt.cc:3358
void SessionTerminate()
Definition G4UIQt.cc:3365
G4bool IsIconPickSelected()
Definition G4UIQt.hh:190
QTabWidget * GetUITabWidget()
Definition G4UIQt.hh:231
void SetIconCoudPointSelected()
Definition G4UIQt.cc:6334
void SetIconWireframeSelected()
Definition G4UIQt.cc:6243
void SetIconMoveSelected()
Definition G4UIQt.cc:6080
G4bool AddViewerTab(QWidget *w, std::string title)
Definition G4UIQt.cc:3175
void TogglePickSelection()
Definition G4UIQt.cc:6132
G4UIQt(G4int, char **)
Definition G4UIQt.cc:125
void AddIcon(const char *userLabel, const char *iconFile, const char *command, const char *file_name="") override
Definition G4UIQt.cc:3826
void SetIconHLHSRSelected()
Definition G4UIQt.cc:6303
QWidget * GetHistoryWidget()
Definition G4UIQt.hh:234
virtual void ExitHelp() const =0