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