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