File indexing completed on 2026-04-05 07:52:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef G4UIQT_HH
0029 #define G4UIQT_HH
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 QSlider;
0048 class QTextEdit;
0049 class QTextBrowser;
0050 class QLabel;
0051 class QResizeEvent;
0052 class QTabWidget;
0053 class QSplitter;
0054 class QToolBar;
0055 class QTableWidget;
0056 class QPixmap;
0057 class QComboBox;
0058 class QCompleter;
0059 class QtGlobal;
0060 class QStandardItemModel;
0061 class QToolButton;
0062 class QRadioButton;
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 #if QT_VERSION < 0x060000
0085 class G4QTabWidget : public QTabWidget
0086 {
0087 public:
0088 G4QTabWidget();
0089 G4QTabWidget(QWidget* aParent, G4int sizeX, G4int sizeY);
0090 void paintEvent(QPaintEvent* event) override;
0091 inline void setTabSelected(G4bool a) { fTabSelected = a; };
0092 inline void setLastTabCreated(G4int a) { fLastCreated = a; };
0093 inline bool isTabSelected() { return fTabSelected; };
0094 G4bool fTabSelected;
0095 G4int fLastCreated;
0096 G4int fPreferedSizeX;
0097 G4int fPreferedSizeY;
0098 inline void setPreferredSize(QSize size)
0099 {
0100 fPreferedSizeX = size.width() + 6;
0101 fPreferedSizeY = size.height() + 58;
0102 }
0103 inline QSize sizeHint() const override { return QSize(fPreferedSizeX, fPreferedSizeY); }
0104 };
0105 #endif
0106
0107 class G4UIOutputString
0108 {
0109 public:
0110 G4UIOutputString(const QString& text, const G4String& thread = "", const G4String& outputstream = "info");
0111 inline QString GetOutputList() { return " all info warning error "; };
0112 QString fText;
0113 G4String fThread;
0114 G4String fOutputStream;
0115 };
0116
0117 class G4UIDockWidget : public QDockWidget
0118 {
0119 public:
0120 G4UIDockWidget(const QString& txt);
0121 void closeEvent(QCloseEvent*) override;
0122 };
0123
0124 class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession
0125 {
0126 Q_OBJECT
0127
0128 public:
0129
0130 G4UIQt(G4int, char**);
0131
0132
0133 G4UIsession* SessionStart() override;
0134
0135
0136
0137
0138
0139 void AddMenu(const char*, const char*) override;
0140
0141
0142
0143
0144
0145
0146 void AddButton(const char*, const char*, const char*) override;
0147
0148
0149
0150
0151
0152
0153
0154
0155 void AddIcon(const char* userLabel, const char* iconFile, const char* command,
0156 const char* file_name = "") override;
0157
0158
0159
0160
0161 void SetOutputStyle(const char* destination, const char* style) override;
0162
0163
0164 void NativeMenu(G4bool aVal) override;
0165
0166
0167 void ClearMenu() override;
0168
0169
0170 void DefaultIcons(G4bool aVal) override;
0171
0172
0173 G4bool AddTabWidget(QWidget*, QString);
0174
0175 inline QTabWidget* GetViewerTabWidget() { return fViewerTabWidget; };
0176
0177
0178 QWidget* GetSceneTreeWidget();
0179
0180
0181 QWidget* GetViewerPropertiesWidget();
0182
0183
0184 QWidget* GetPickInfosWidget();
0185
0186 G4bool IsSplitterReleased();
0187
0188 inline G4bool IsIconMoveSelected() { return fMoveSelected; };
0189 inline G4bool IsIconRotateSelected() { return fRotateSelected; };
0190 inline G4bool IsIconPickSelected() { return fPickSelected; };
0191 inline G4bool IsIconZoomInSelected() { return fZoomInSelected; };
0192 inline G4bool IsIconZoomOutSelected() { return fZoomOutSelected; };
0193
0194 void SetIconMoveSelected();
0195 void SetIconRotateSelected();
0196 void TogglePickSelection();
0197 void SetIconZoomInSelected();
0198 void SetIconZoomOutSelected();
0199 void SetIconHLHSRSelected();
0200 void SetIconHLRSelected();
0201 void SetIconSolidSelected();
0202 void SetIconWireframeSelected();
0203 void SetIconCoudPointSelected();
0204 void SetIconPerspectiveSelected();
0205 void SetIconOrthoSelected();
0206
0207
0208 inline QMainWindow* GetMainWindow() { return fMainWindow; };
0209
0210
0211 inline QPixmap* getSearchIcon() { return fSearchIcon; };
0212
0213
0214 inline QPixmap* getClearIcon() { return fClearIcon; };
0215
0216
0217
0218
0219 void SetStartPage(const std::string&);
0220
0221
0222 inline QWidget* GetCoutWidget() { return fCoutDockWidget->widget(); };
0223
0224
0225 inline G4UIDockWidget* GetCoutDockWidget() { return fCoutDockWidget; };
0226
0227
0228 inline G4UIDockWidget* GetUserInterfaceWidget() { return fUIDockWidget; };
0229
0230
0231 inline QTabWidget* GetUITabWidget() { return fUITabWidget; }
0232
0233
0234 inline QWidget* GetHistoryWidget() { return fHistoryTBWidget; }
0235
0236
0237 inline QWidget* GetHelpWidget() { return fHelpTBWidget; }
0238
0239
0240 G4bool AddViewerTab(QWidget* w, std::string title);
0241
0242
0243 G4bool AddViewerTabFromFile(std::string fileName, std::string title);
0244
0245
0246 void UpdateSceneTree(const G4SceneTreeItem&) override;
0247
0248
0249 void UpdateDrawingStyle(G4int style) override;
0250 void UpdateProjectionStyle(G4int style) override;
0251 void UpdateTransparencySlider(G4double depth, G4int option) override;
0252
0253
0254 public:
0255 ~G4UIQt() override;
0256 void Prompt(const G4String&);
0257 void SessionTerminate();
0258 void PauseSessionStart(const G4String&) override;
0259 G4int ReceiveG4debug(const G4String&) override;
0260 G4int ReceiveG4cout(const G4String&) override;
0261 G4int ReceiveG4cerr(const G4String&) override;
0262
0263
0264 private:
0265 void SecondaryLoop(const G4String&);
0266 void CreateHelpWidget();
0267 void InitHelpTreeAndVisParametersWidget();
0268 void FillHelpTree();
0269 void UpdateCommandCompleter();
0270 void CreateIcons();
0271 void ExitHelp() const override;
0272 void SetDefaultIconsToolbar();
0273
0274 void CreateHelpTree(QTreeWidgetItem*, G4UIcommandTree*);
0275 QTreeWidgetItem* FindTreeItem(QTreeWidgetItem*, const QString&);
0276
0277
0278 QWidget* CreateSceneTreeWidget();
0279
0280
0281
0282
0283 void CreateNewSceneTreeWidget();
0284
0285 void BuildPVQTree(const G4SceneTreeItem& g4stItem, QTreeWidgetItem* qtwItem);
0286
0287 void SceneTreeItemClicked(QTreeWidgetItem*);
0288 void SceneTreeItemDoubleClicked(QTreeWidgetItem*);
0289 void SceneTreeItemExpanded(QTreeWidgetItem*);
0290 void SceneTreeItemCollapsed(QTreeWidgetItem*);
0291 void SliderValueChanged(G4int value);
0292 void SliderReleased();
0293 void SliderRadioButtonClicked(G4int buttonNo);
0294
0295 struct NewSceneTreeItemTreeWidget: public QTreeWidget {
0296 void mousePressEvent(QMouseEvent*) override;
0297 void ActWithoutParameter(const G4String& action, G4SceneTreeItem*);
0298 void ActWithABool(const G4String& action, G4SceneTreeItem*, G4bool);
0299 void ActWithAnInteger(const G4String& action, G4SceneTreeItem*);
0300 void ActWithADouble(const G4String& action, G4SceneTreeItem*);
0301 void ActWithAString(const G4String& action, G4SceneTreeItem*);
0302 };
0303
0304 QString GetCommandList(const G4UIcommand*);
0305 void updateHelpArea(const G4UIcommand*);
0306 G4bool GetHelpChoice(
0307 G4int&) override;
0308 bool eventFilter(QObject*, QEvent*) override;
0309 void ActivateCommand(G4String);
0310
0311 QMultiMap<G4double, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
0312 G4double ComputeStringMatchScore(const QString&, const QString&);
0313 QWidget* CreateVisParametersTBWidget();
0314 QWidget* CreateHelpTBWidget();
0315 QWidget* CreateTimeWindowWidget();
0316 G4UIDockWidget* CreateCoutTBWidget();
0317 QWidget* CreateHistoryTBWidget();
0318 G4UIDockWidget* CreateUITabWidget();
0319 void CreateViewerWidget();
0320 void OpenHelpTreeOnCommand(const QString&);
0321 QString GetShortCommandPath(QString&);
0322 QString GetLongCommandPath(QTreeWidgetItem*);
0323 G4bool IsGUICommand(const G4UIcommand*);
0324 G4bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, G4int, G4bool isDialog);
0325 G4bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, G4bool isDialog);
0326 void CreateViewerPropertiesDialog();
0327 void CreatePickInfosDialog();
0328 #ifdef G4MULTITHREADED
0329 void UpdateCoutThreadFilter();
0330 #endif
0331 void FilterAllOutputTextArea();
0332 QString FilterOutput(const G4UIOutputString&, const QString&, const QString&);
0333 G4String GetThreadPrefix();
0334 G4bool CheckG4EnvironmentVariable(char* txt, char* version);
0335 QStandardItemModel* CreateCompleterModel(const G4String& aCmd);
0336 void CreateEmptyViewerPropertiesWidget();
0337 void CreateEmptyPickInfosWidget();
0338
0339 private:
0340 QMainWindow* fMainWindow;
0341 QLabel* fCommandLabel;
0342 QLineEdit* fCommandArea;
0343 QTextEdit* fCoutTBTextArea;
0344 QTabWidget* fUITabWidget;
0345 std::vector<G4UIOutputString> fG4OutputString;
0346 QLineEdit* fCoutFilter;
0347 QCompleter* fCompleter;
0348 G4bool fDefaultIcons;
0349
0350 QListWidget* fHistoryTBTableList;
0351 QTreeWidget* fHelpTreeWidget;
0352 QWidget* fHelpTBWidget;
0353 QWidget* fTimeWindowWidget;
0354 QWidget* fHistoryTBWidget;
0355 G4UIDockWidget* fCoutDockWidget;
0356 G4UIDockWidget* fUIDockWidget;
0357 QWidget* fSceneTreeWidget;
0358 QWidget* fNewSceneTreeWidget;
0359 NewSceneTreeItemTreeWidget* fNewSceneTreeItemTreeWidget;
0360 G4int fMaxPVDepth;
0361 QSlider* fNewSceneTreeSlider;
0362 QRadioButton* fUnwrapButtonWidget;
0363 QRadioButton* fFadeButtonWidget;
0364 QRadioButton* fXrayButtonWidget;
0365 QWidget* fViewerPropertiesWidget;
0366 QWidget* fPickInfosWidget;
0367 QLineEdit* fHelpLine;
0368 #if QT_VERSION < 0x060000
0369 G4QTabWidget* fViewerTabWidget;
0370 #else
0371 QTabWidget* fViewerTabWidget;
0372 #endif
0373 QString fCoutText;
0374 QTextBrowser* fStartPage;
0375 QSplitter* fHelpVSplitter;
0376 QTextEdit* fParameterHelpLabel;
0377 QTableWidget* fParameterHelpTable;
0378
0379 QToolBar* fToolbarApp;
0380 QToolBar* fToolbarUser;
0381 QString fStringSeparator;
0382 G4String fLastErrMessage;
0383 QString fLastOpenPath;
0384
0385 QPixmap* fSearchIcon;
0386 QPixmap* fClearIcon;
0387 QPixmap* fSaveIcon;
0388 QPixmap* fOpenIcon;
0389 QPixmap* fMoveIcon;
0390 QPixmap* fRotateIcon;
0391 QPixmap* fPickIcon;
0392 QPixmap* fZoomInIcon;
0393 QPixmap* fZoomOutIcon;
0394 QPixmap* fWireframeIcon;
0395 QPixmap* fSolidIcon;
0396 QPixmap* fPointCloudIcon;
0397 QPixmap* fHiddenLineRemovalIcon;
0398 QPixmap* fHiddenLineAndSurfaceRemovalIcon;
0399 QPixmap* fPerspectiveIcon;
0400 QPixmap* fOrthoIcon;
0401 QPixmap* fCommandIcon;
0402 QPixmap* fDirIcon;
0403 QPixmap* fRunIcon;
0404 QPixmap* fParamIcon;
0405 QPixmap* fPickTargetIcon;
0406 QPixmap* fExitIcon;
0407 QPixmap* fResetCameraIcon;
0408 QPixmap* fResetTargetPointIcon;
0409
0410 #ifdef G4MULTITHREADED
0411 QComboBox* fThreadsFilterComboBox;
0412 #endif
0413 std::string fDefaultViewerFirstPageHTMLText;
0414
0415 QDialog* fViewerPropertiesDialog;
0416 QDialog* fPickInfosDialog;
0417 QString fLastCompleteCommand;
0418 G4bool fMoveSelected;
0419 G4bool fRotateSelected;
0420 G4bool fPickSelected;
0421 G4bool fZoomInSelected;
0422 G4bool fZoomOutSelected;
0423
0424 private Q_SLOTS:
0425 void ExitSession();
0426 void ClearButtonCallback();
0427 void SaveOutputCallback();
0428 void CommandEnteredCallback();
0429 void CommandEditedCallback(const QString& text);
0430 void ButtonCallback(const QString&);
0431 void HelpTreeClicCallback();
0432 void HelpTreeDoubleClicCallback();
0433 void ShowHelpCallback();
0434 void CommandHistoryCallback();
0435 void LookForHelpStringCallback();
0436 void UpdateTabWidget(int);
0437 void ResizeTabWidget(QResizeEvent*);
0438 void CoutFilterCallback(const QString&);
0439 void ThreadComboBoxCallback(int);
0440 void TabCloseCallback(int);
0441 void ToolBoxActivated(int);
0442 void VisParameterCallback(QWidget*);
0443 void ChangeColorCallback(QWidget*);
0444 void ChangeCursorAction(const QString&);
0445 void ChangeSurfaceStyle(const QString&);
0446 void OpenIconCallback(const QString&);
0447 void SaveIconCallback(const QString&);
0448 void ViewerPropertiesIconCallback(int);
0449 void ChangePerspectiveOrtho(const QString&);
0450 void ResetCameraCallback();
0451
0452 };
0453
0454 #endif