ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIWt.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UIWt.hh
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 G4UIWt_h
29 #define G4UIWt_h
30 
31 #if defined(G4UI_BUILD_WT_SESSION) || defined(G4UI_USE_WT)
32 
33 #include <map>
34 
35 #include "G4VBasicShell.hh"
36 #include "G4VInteractiveSession.hh"
37 
38 #include <Wt/WObject>
39 #include <Wt/WWidget>
40 #include <Wt/WPushButton>
41 #include <Wt/WTree>
42 #include <Wt/WTreeNode>
43 #include <Wt/WMenu>
44 #include <Wt/WTabWidget>
45 #include <Wt/WStringListModel>
46 
47 
48 
49 class G4UIsession;
50 
51 // Class description :
52 //
53 // G4UIWt : class to handle a Wt interactive session.
54 // G4UIWt is the Wt version of G4UIterminal.
55 //
56 // A command box is at disposal for entering/recalling Geant4 commands.
57 // A menubar could be customized through the AddMenu, AddButton, AddIcon methods.
58 // Note that there are corresponding Geant4 commands to add a
59 // menus in the menubar and add buttons in a menu.
60 // Ex :
61 // /gui/addMenu test Test
62 // /gui/addButton test Init /run/initialize
63 // /gui/addButton test "Set gun" "/control/execute gun.g4m"
64 // /gui/addButton test "Run one event" "/run/beamOn 1"
65 //
66 // Command completion, by typing "tab" key, is available on the
67 // command line.
68 //
69 // Class description - end :
70 
71 class G4WTabWidget : public Wt::WTabWidget {
72  public :
73  G4WTabWidget();
74  G4WTabWidget(Wt::WContainerWidget*&);
75  inline void setTabSelected(bool a) { tabSelected = a; };
76  inline void setLastTabCreated(int a) { lastCreated = a; };
77  inline bool isTabSelected() { return tabSelected; };
78  bool tabSelected;
79  int lastCreated;
80  int incTabPaint;
81 
82 };
83 
84 
85 class G4UIWt : public Wt::WObject, public G4VBasicShell, public G4VInteractiveSession {
86 
87 public: // With description
88  G4UIWt(int,char**);
89  // (argv, argc) or (0, NULL) had to be given.
91  // To enter interactive Wt loop ; waiting/executing command,...
92  void AddMenu(const char*,const char*);
93  // To add a pulldown menu in the menu bar.
94  // First argument is the name of the menu.
95  // Second argument is the label of the cascade button.
96  // Ex : AddMenu("my_menu","My menu")
97  void AddButton(const char*,const char*,const char*);
98  // To add a push button in a pulldown menu.
99  // First argument is the name of the menu.
100  // Second argument is the label of the button.
101  // Third argument is the Geant4 command executed when the button is fired.
102  // Ex : AddButton("my_menu","Run","/run/beamOn 1");
103  void AddIcon(const char* userLabel, const char* iconFile, const char* command, const char* file_name="");
104  // To add a icon in the toolbar
105  // First argument is the label of the icon.
106  // 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).
107  // Third argument is the Geant4 command executed when the button is fired.
108  // Fourth argument is the path to the icon file if "user_icon" selected
109  // Ex : AddButton("change background color","../background.xpm"," /vis/viewer/set/background");
110 
111  bool AddTabWidget( Wt::WWidget*, Wt::WString,int,int);
112  // To add a tab for vis openGL Qt driver
113 
114  Wt::WTabWidget* GetSceneTreeComponentsTBWidget();
115  // Get the viewComponent
116 
117  bool IsSplitterReleased();
118 
119  inline bool IsIconMoveSelected() {
120  return fMoveSelected;
121  };
122  inline bool IsIconRotateSelected() {
123  return fRotateSelected;
124  };
125  inline bool IsIconPickSelected() {
126  return fPickSelected;
127  };
128  inline bool IsIconZoomInSelected() {
129  return fZoomInSelected;
130  };
131  inline bool IsIconZoomOutSelected() {
132  return fZoomOutSelected;
133  };
134 
135  /* void SetIconMoveSelected();
136  void SetIconRotateSelected();
137  void SetIconPickSelected();
138  void SetIconZoomInSelected();
139  void SetIconZoomOutSelected();
140  void SetIconHLHSRSelected();
141  void SetIconHLRSelected();
142  void SetIconSolidSelected();
143  void SetIconWireframeSelected();
144  void SetIconPerspectiveSelected();
145  void SetIconOrthoSelected();
146  */
147 
148  inline Wt::WContainerWidget * GetMainWindow() {
149  return fMainWindow;
150  };
151 
152 public:
153  ~G4UIWt();
154  void Prompt(G4String);
155  void SessionTerminate();
156  virtual void PauseSessionStart(const G4String&);
157  virtual G4int ReceiveG4cout(const G4String&);
158  virtual G4int ReceiveG4cerr(const G4String&);
159  // G4String GetCommand(Widget);
160 
161 private:
162  void SecondaryLoop(G4String); // a VIRER
163  void CreateHelpWidget();
164  void InitHelpTreeAndVisParametersWidget();
165  void FillHelpTree();
166  virtual void ExitHelp() const;
167 
168  void CreateHelpTree( Wt::WTreeNode*,G4UIcommandTree*);
169  Wt::WTreeNode* FindTreeItem( Wt::WTreeNode *,const std::string&);
170 
171  Wt::WString GetCommandList(const G4UIcommand*);
172 
173  virtual G4bool GetHelpChoice(G4int&);// have to be implemeted because we heritate from G4VBasicShell
174  bool eventFilter(Wt::WObject*,Wt::WEvent*);
175  void ActivateCommand(G4String);
176  // QMap<int,Wt::WString> LookForHelpStringInChildTree(G4UIcommandTree *,const Wt::WString&);
177 
178  Wt::WContainerWidget* CreateVisParametersTBWidget();
179  Wt::WWidget* CreateHelpTBWidget();
180  Wt::WWidget* CreateCoutTBWidget();
181  Wt::WWidget* CreateHistoryTBWidget();
182  Wt::WWidget* CreateUITabWidget();
183  Wt::WWidget* CreateSceneTreeComponentsTBWidget();
184  Wt::WContainerWidget* CreateRightSplitterWidget();
185  Wt::WContainerWidget* CreateLeftSplitterWidget();
186  void OpenHelpTreeOnCommand(const Wt::WString &);
187  Wt::WString GetShortCommandPath(const std::string & );
188  Wt::WString GetLongCommandPath( Wt::WTreeNode*);
189  G4bool IsGUICommand(const G4UIcommand*);
190  bool CreateVisCommandGroupAndToolBox(G4UIcommand*, Wt::WWidget*, int, bool isDialog);
191  bool CreateCommandWidget(G4UIcommand* command, Wt::WContainerWidget* parent, bool isDialog);
192 
193 private:
194 
195  Wt::WContainerWidget * fMainWindow;
196  Wt::WLabel *fCommandLabel;
197  Wt::WLineEdit * fCommandArea;
198  Wt::WTextArea *fCoutTBTextArea;
199  Wt::WTextArea *fHelpArea;
200  Wt::WTabWidget* fUITabWidget;
201  Wt::WStringListModel fG4cout;
202  Wt::WLineEdit * fCoutFilter;
203 
204  Wt::WSelectionBox *fHistoryTBTableList;
205  Wt::WTree *fHelpTreeWidget;
206  Wt::WPanel* fHelpTBWidget;
207  Wt::WPanel* fHistoryTBWidget;
208  Wt::WPanel* fCoutTBWidget;
209  Wt::WTabWidget* fSceneTreeComponentsTBWidget;
210  Wt::WLineEdit* fHelpLine;
211  G4WTabWidget* fViewerTabWidget;
212  Wt::WString fCoutText;
213  Wt::WLabel *fEmptyViewerTabLabel;
214  Wt::WContainerWidget* fMainSplitterWidget;
215  Wt::WContainerWidget* fRightSplitterWidget;
216  Wt::WContainerWidget* fLeftSplitterWidget;
217  Wt::WContainerWidget* fHelpVSplitter;
218 
219  Wt::WToolBar *fToolbarApp;
220  Wt::WToolBar *fToolbarUser;
221  Wt::WString fStringSeparator;
222  G4String fLastErrMessage;
223  Wt::WString fLastOpenPath;
224 
225  bool fMoveSelected;
226  bool fRotateSelected;
227  bool fPickSelected;
228  bool fZoomInSelected;
229  bool fZoomOutSelected;
230  G4bool fExitSession;
231  G4bool fExitPause;
232 
233 
234  private :
235  void ExitSession();
236  void ClearButtonCallback();
237  void CommandEnteredCallback();
238  void CommandEditedCallback(const Wt::WString & text);
239  void ButtonCallback(const char*);
240  void HelpTreeClicCallback();
241  void HelpTreeDoubleClicCallback();
242  void ShowHelpCallback();
243  void CommandHistoryCallback();
244  void LookForHelpStringCallback();
245  void CurrentChangedTabWidgetCallback(int);
246  void CoutFilterCallback(const Wt::WString&);
247  void TabCloseCallback(int);
248  void ToolBoxActivated(int);
249  void VisParameterCallback(Wt::WContainerWidget*);
250  void ChangeColorCallback(Wt::WContainerWidget*);
251  void ChangeCursorStyle(const Wt::WString&);
252  void ChangeSurfaceStyle(const Wt::WString&);
253  void OpenIconCallback(const Wt::WString&);
254  void SaveIconCallback(const Wt::WString&);
255  void ChangePerspectiveOrthoCallback(const Wt::WString&);
256 
257 };
258 
259 #endif
260 
261 #endif
262