Geant4  10.02.p02
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 97681 2016-06-07 08:59:17Z 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* GetCoutDockWidget() {
204  return fCoutDockWidget;
205  };
206  // Return the cout dockable widget as a QDockWidget
207 
208  inline G4UIDockWidget* GetUserInterfaceWidget() {
209  return fUIDockWidget;
210  };
211  // Return the UserInterface widget (including scene tree, help and History widgets)
212 
213  inline QTabWidget* GetViewersWidget() {
214  return fUITabWidget;
215  }
216  // return the viewer widget including all viewers
217 
218  inline QWidget* GetHistoryWidget() {
219  return fHistoryTBWidget;
220  }
221  // return the history widget
222 
223  inline QWidget* GetHelpWidget() {
224  return fHelpTBWidget;
225  }
226  // return the help widget
227 
228  bool AddViewerTab(QWidget* w, std::string title);
229  // Add a new tab in the viewer, could be used to add your own component
230 
231  bool AddViewerTabFromFile(std::string fileName, std::string title);
232  // Add a new tab in the viewer containing the content of the file in a QLabel
233 
234 public:
235  ~G4UIQt();
236  void Prompt(G4String);
237  void SessionTerminate();
238  virtual void PauseSessionStart(const G4String&);
239  virtual G4int ReceiveG4cout(const G4String&);
240  virtual G4int ReceiveG4cerr(const G4String&);
241  // G4String GetCommand(Widget);
242 
243 private:
244  void SecondaryLoop(G4String); // a VIRER
245  void CreateHelpWidget();
246  void InitHelpTreeAndVisParametersWidget();
247  void FillHelpTree();
248  virtual void ExitHelp() const;
249 
250  void CreateHelpTree(QTreeWidgetItem*,G4UIcommandTree*);
251  QTreeWidgetItem* FindTreeItem(QTreeWidgetItem *,const QString&);
252 
253  QString GetCommandList(const G4UIcommand*);
254  void updateHelpArea(const G4UIcommand*);
255  virtual G4bool GetHelpChoice(G4int&);// have to be implemeted because we heritate from G4VBasicShell
256  bool eventFilter(QObject*,QEvent*);
257  void ActivateCommand(G4String);
258  QMap<int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
259 
260  QWidget* CreateVisParametersTBWidget();
261  QWidget* CreateHelpTBWidget();
262  G4UIDockWidget* CreateCoutTBWidget();
263  QWidget* CreateHistoryTBWidget();
264  G4UIDockWidget* CreateUITabWidget();
265  QWidget* CreateSceneTreeComponentsTBWidget();
266  void CreateViewerWidget();
267  void OpenHelpTreeOnCommand(const QString &);
268  QString GetShortCommandPath(QString);
269  QString GetLongCommandPath(QTreeWidgetItem*);
270  G4bool IsGUICommand(const G4UIcommand*);
271  bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, int, bool isDialog);
272  bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, bool isDialog);
273 #ifdef G4MULTITHREADED
274  void UpdateCoutThreadFilter();
275 #endif
276  void FilterAllOutputTextArea();
277  QString FilterOutput(const G4UIOutputString&,const QString&,const QString&);
278  G4String GetThreadPrefix();
279 private:
280 
281  QMainWindow * fMainWindow;
282  QLabel *fCommandLabel;
283  QLineEdit * fCommandArea;
284  QTextEdit *fCoutTBTextArea;
285  QTabWidget* fUITabWidget;
286  std::vector <G4UIOutputString> fG4OutputString;
287  QLineEdit * fCoutFilter;
288 
289  QListWidget *fHistoryTBTableList;
290  QTreeWidget *fHelpTreeWidget;
291  QWidget* fHelpTBWidget;
292  QWidget* fHistoryTBWidget;
293  G4UIDockWidget* fCoutDockWidget;
294  G4UIDockWidget* fUIDockWidget;
295  QTabWidget* fSceneTreeComponentsTBWidget;
296  QLineEdit* fHelpLine;
297  G4QTabWidget* fViewerTabWidget;
298  QString fCoutText;
299  QTextEdit *fStartPage;
300  QSplitter * fHelpVSplitter;
301  QTextEdit* fParameterHelpLabel;
302  QTableWidget* fParameterHelpTable;
303 
304  QToolBar *fToolbarApp;
305  QToolBar *fToolbarUser;
306  QString fStringSeparator;
307  G4String fLastErrMessage;
308  QString fLastOpenPath;
309 
310  QPixmap* fSearchIcon;
311  QPixmap* fClearIcon;
312  QComboBox* fThreadsFilterComboBox;
313  std::string fDefaultViewerFirstPageHTMLText;
314 
315  bool fMoveSelected;
316  bool fRotateSelected;
317  bool fPickSelected;
318  bool fZoomInSelected;
319  bool fZoomOutSelected;
320 
321 private Q_SLOTS :
322  void ExitSession();
323  void ClearButtonCallback();
324  void CommandEnteredCallback();
325  void CommandEditedCallback(const QString & text);
326  void ButtonCallback(const QString&);
327  void HelpTreeClicCallback();
328  void HelpTreeDoubleClicCallback();
329  void ShowHelpCallback();
330  void CommandHistoryCallback();
331  void LookForHelpStringCallback();
332  void UpdateTabWidget(int);
333  void ResizeTabWidget( QResizeEvent* );
334  void CoutFilterCallback(const QString&);
335  void ThreadComboBoxCallback(int);
336  void TabCloseCallback(int);
337  void ToolBoxActivated(int);
338  void VisParameterCallback(QWidget*);
339  void ChangeColorCallback(QWidget*);
340  void ChangeCursorStyle(const QString&);
341  void ChangeSurfaceStyle(const QString&);
342  void OpenIconCallback(const QString&);
343  void SaveIconCallback(const QString&);
344  void ChangePerspectiveOrtho(const QString&);
345 };
346 
347 #endif
348 
349 #endif
350 
virtual G4bool GetHelpChoice(G4int &)=0
virtual void ExitHelp() const =0
const G4double w[NPOINTSGL]
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:168
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 *)