Geant4  10.01.p03
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 // $Id: G4UIQt.hh 86866 2014-11-19 14:43:02Z gcosmo $
28 //
29 #ifndef G4UIQt_h
30 #define G4UIQt_h
31 
32 #if defined(G4UI_BUILD_QT_SESSION) || defined(G4UI_USE_QT)
33 
34 #include <map>
35 
36 #include "G4VBasicShell.hh"
37 #include "G4VInteractiveSession.hh"
38 
39 #include <qobject.h>
40 #include <qmap.h>
41 #include <qstringlist.h>
42 #include <qtabwidget.h>
43 #include <qdockwidget.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 
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 class G4QTabWidget : public QTabWidget {
83 public :
84  G4QTabWidget();
85  G4QTabWidget(QWidget* aParent, int sizeX, int sizeY);
86  void paintEvent ( QPaintEvent * event );
87  inline void setTabSelected(bool a) { fTabSelected = a; };
88  inline void setLastTabCreated(int a) { fLastCreated = a; };
89  inline bool isTabSelected() { return fTabSelected; };
90  bool fTabSelected;
91  int fLastCreated;
92  int fPreferedSizeX;
93  int fPreferedSizeY;
94  inline void setPreferredSize(QSize s) {
95  fPreferedSizeX = s.width() + 6; // tab label height + margin left+right
96  fPreferedSizeY = s.height() + 58; // margin left+right
97  }
98  inline QSize sizeHint () const {
99  return QSize(fPreferedSizeX, fPreferedSizeY);
100  }
101 };
102 
103 class G4UIOutputString {
104  public :
105  G4UIOutputString(QString text,G4String thread = "",G4String outputstream= "info");
106  inline QString GetOutputList() { return " all info warning error ";};
107  QString fText;
108  G4String fThread;
109  G4String fOutputStream; // Error, Warning, Info
110 };
111 
112 
113 class G4UIDockWidget : public QDockWidget {
114 public:
115  G4UIDockWidget(QString txt);
116  void closeEvent(QCloseEvent *);
117 };
118 
119 
120 class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession {
121  Q_OBJECT
122 
123 public: // With description
124  G4UIQt(int,char**);
125  // (argv, argc) or (0, NULL) had to be given.
127  // To enter interactive X loop ; waiting/executing command,...
128  void AddMenu(const char*,const char*);
129  // To add a pulldown menu in the menu bar.
130  // First argument is the name of the menu.
131  // Second argument is the label of the cascade button.
132  // Ex : AddMenu("my_menu","My menu")
133  void AddButton(const char*,const char*,const char*);
134  // To add a push button in a pulldown menu.
135  // First argument is the name of the menu.
136  // Second argument is the label of the button.
137  // Third argument is the Geant4 command executed when the button is fired.
138  // Ex : AddButton("my_menu","Run","/run/beamOn 1");
139  void AddIcon(const char* userLabel, const char* iconFile, const char* command, const char* file_name="");
140  // To add a icon in the toolbar
141  // First argument is the label of the icon.
142  // 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).
143  // Third argument is the Geant4 command executed when the button is fired.
144  // Fourth argument is the path to the icon file if "user_icon" selected
145  // Ex : AddButton("change background color","../background.xpm"," /vis/viewer/set/background");
146 
147  bool AddTabWidget(QWidget*,QString);
148  // To add a tab for vis openGL Qt driver
149 
150  QTabWidget* GetSceneTreeComponentsTBWidget();
151  // Get the viewComponent
152 
153  bool IsSplitterReleased();
154 
155  inline bool IsIconMoveSelected() {
156  return fMoveSelected;
157  };
158  inline bool IsIconRotateSelected() {
159  return fRotateSelected;
160  };
161  inline bool IsIconPickSelected() {
162  return fPickSelected;
163  };
164  inline bool IsIconZoomInSelected() {
165  return fZoomInSelected;
166  };
167  inline bool IsIconZoomOutSelected() {
168  return fZoomOutSelected;
169  };
170 
171  void SetIconMoveSelected();
172  void SetIconRotateSelected();
173  void SetIconPickSelected();
174  void SetIconZoomInSelected();
175  void SetIconZoomOutSelected();
176  void SetIconHLHSRSelected();
177  void SetIconHLRSelected();
178  void SetIconSolidSelected();
179  void SetIconWireframeSelected();
180  void SetIconPerspectiveSelected();
181  void SetIconOrthoSelected();
182 
183  inline QMainWindow * GetMainWindow() {
184  return fMainWindow;
185  };
186  // Return the main window
187 
188  inline QPixmap* getSearchIcon() { return fSearchIcon;};
189  // return the "search" icon pixmap
190  inline QPixmap* getClearIcon() { return fClearIcon;};
191  // return the "clear" icon pixmap
192 
193  void SetStartPage(const std::string&);
194  // Set the text on the first page of the viewer. If "", will take the last value as default
195  // Note: Qt Rich text format could be used, see link for example :
196  // https://qt-project.org/doc/qt-4.8/richtext-html-subset.html#table-cell-attributes
197 
198  inline QWidget* GetCoutWidget() {
199  return fCoutDockWidget->widget();
200  };
201  // Return the G4cout widget with filters
202 
203  inline G4UIDockWidget* GetUserInterfaceWidget() {
204  return fUIDockWidget;
205  };
206  // Return the UserInterface widget (including scene tree, help and History widgets)
207 
208  inline QTabWidget* GetViewersWidget() {
209  return fUITabWidget;
210  }
211  // return the viewer widget including all viewers
212 
213  inline QWidget* GetHistoryWidget() {
214  return fHistoryTBWidget;
215  }
216  // return the history widget
217 
218  inline QWidget* GetHelpWidget() {
219  return fHelpTBWidget;
220  }
221  // return the help widget
222 
223  bool AddViewerTab(QWidget* w, std::string title);
224  // Add a new tab in the viewer, could be used to add your own component
225 
226  bool AddViewerTabFromFile(std::string fileName, std::string title);
227  // Add a new tab in the viewer containing the content of the file in a QLabel
228 
229 public:
230  ~G4UIQt();
231  void Prompt(G4String);
232  void SessionTerminate();
233  virtual void PauseSessionStart(const G4String&);
234  virtual G4int ReceiveG4cout(const G4String&);
235  virtual G4int ReceiveG4cerr(const G4String&);
236  // G4String GetCommand(Widget);
237 
238 private:
239  void SecondaryLoop(G4String); // a VIRER
240  void CreateHelpWidget();
241  void InitHelpTreeAndVisParametersWidget();
242  void FillHelpTree();
243  virtual void ExitHelp() const;
244 
245  void CreateHelpTree(QTreeWidgetItem*,G4UIcommandTree*);
246  QTreeWidgetItem* FindTreeItem(QTreeWidgetItem *,const QString&);
247 
248  QString GetCommandList(const G4UIcommand*);
249  void updateHelpArea(const G4UIcommand*);
250  virtual G4bool GetHelpChoice(G4int&);// have to be implemeted because we heritate from G4VBasicShell
251  bool eventFilter(QObject*,QEvent*);
252  void ActivateCommand(G4String);
253  QMap<int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
254 
255  QWidget* CreateVisParametersTBWidget();
256  QWidget* CreateHelpTBWidget();
257  G4UIDockWidget* CreateCoutTBWidget();
258  QWidget* CreateHistoryTBWidget();
259  G4UIDockWidget* CreateUITabWidget();
260  QWidget* CreateSceneTreeComponentsTBWidget();
261  QWidget* CreateViewerWidget();
262  void OpenHelpTreeOnCommand(const QString &);
263  QString GetShortCommandPath(QString);
264  QString GetLongCommandPath(QTreeWidgetItem*);
265  G4bool IsGUICommand(const G4UIcommand*);
266  bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, int, bool isDialog);
267  bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, bool isDialog);
268 #ifdef G4MULTITHREADED
269  void UpdateCoutThreadFilter();
270 #endif
271  void FilterAllOutputTextArea();
272  QString FilterOutput(const G4UIOutputString&,const QString&,const QString&);
273  G4String GetThreadPrefix();
274 private:
275 
276  QMainWindow * fMainWindow;
277  QLabel *fCommandLabel;
278  QLineEdit * fCommandArea;
279  QTextEdit *fCoutTBTextArea;
280  QTabWidget* fUITabWidget;
281  std::vector <G4UIOutputString> fG4OutputString;
282  QLineEdit * fCoutFilter;
283 
284  QListWidget *fHistoryTBTableList;
285  QTreeWidget *fHelpTreeWidget;
286  QWidget* fHelpTBWidget;
287  QWidget* fHistoryTBWidget;
288  G4UIDockWidget* fCoutDockWidget;
289  G4UIDockWidget* fUIDockWidget;
290  QTabWidget* fSceneTreeComponentsTBWidget;
291  QLineEdit* fHelpLine;
292  G4QTabWidget* fViewerTabWidget;
293  QString fCoutText;
294  QTextEdit *fStartPage;
295  QSplitter * fHelpVSplitter;
296  QTextEdit* fParameterHelpLabel;
297  QTableWidget* fParameterHelpTable;
298 
299  QToolBar *fToolbarApp;
300  QToolBar *fToolbarUser;
301  QString fStringSeparator;
302  G4String fLastErrMessage;
303  QString fLastOpenPath;
304 
305  QPixmap* fSearchIcon;
306  QPixmap* fClearIcon;
307  QComboBox* fThreadsFilterComboBox;
308  std::string fDefaultViewerFirstPageHTMLText;
309 
310  bool fMoveSelected;
311  bool fRotateSelected;
312  bool fPickSelected;
313  bool fZoomInSelected;
314  bool fZoomOutSelected;
315 
316 private Q_SLOTS :
317  void ExitSession();
318  void ClearButtonCallback();
319  void CommandEnteredCallback();
320  void CommandEditedCallback(const QString & text);
321  void ButtonCallback(const QString&);
322  void HelpTreeClicCallback();
323  void HelpTreeDoubleClicCallback();
324  void ShowHelpCallback();
325  void CommandHistoryCallback();
326  void LookForHelpStringCallback();
327  void UpdateTabWidget(int);
328  void ResizeTabWidget( QResizeEvent* );
329  void CoutFilterCallback(const QString&);
330  void ThreadComboBoxCallback(int);
331  void TabCloseCallback(int);
332  void ToolBoxActivated(int);
333  void VisParameterCallback(QWidget*);
334  void ChangeColorCallback(QWidget*);
335  void ChangeCursorStyle(const QString&);
336  void ChangeSurfaceStyle(const QString&);
337  void OpenIconCallback(const QString&);
338  void SaveIconCallback(const QString&);
339  void ChangePerspectiveOrtho(const QString&);
340 };
341 
342 #endif
343 
344 #endif
345 
virtual G4bool GetHelpChoice(G4int &)=0
virtual void ExitHelp() const =0
virtual G4int ReceiveG4cout(const G4String &coutString)
Definition: G4UIsession.cc:42
virtual void AddMenu(const char *, const char *)
G4double a
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
virtual void PauseSessionStart(const G4String &Prompt)=0
static const double s
Definition: G4SIunits.hh:150
bool G4bool
Definition: G4Types.hh:79
virtual G4UIsession * SessionStart()=0
virtual void AddButton(const char *, const char *, const char *)
virtual G4int ReceiveG4cerr(const G4String &cerrString)
Definition: G4UIsession.cc:48
virtual void AddIcon(const char *, const char *, const char *, const char *)