Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIXaw.cc
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$
28 //
29 // G.Barrand
30 
31 //#define DEBUG
32 
33 #ifdef G4UI_BUILD_XAW_SESSION
34 
35 #include <X11/Intrinsic.h>
36 #include <X11/StringDefs.h>
37 #include <X11/Shell.h>
38 
39 #include <Xaw/Dialog.h>
40 #include <Xaw/Command.h>
41 
42 #include "G4UIXaw.hh"
43 #include "G4UImanager.hh"
44 #include "G4StateManager.hh"
45 #include "G4UIcommandTree.hh"
46 #include "G4UIcommandStatus.hh"
47 #include "G4Xt.hh"
48 
49 static G4bool ConvertStringToInt(const char*,int&);
50 
51 static G4bool exitSession = true;
52 static G4bool exitPause = true;
53 static G4bool exitHelp = true;
54 /***************************************************************************/
55 G4UIXaw::G4UIXaw (
56  int argc
57 ,char** argv
58 )
59 :fHelp(false)
60 ,fHelpChoice(0)
61 /***************************************************************************/
63 {
64  static G4bool warned = false;
65  if (!warned) {
66  warned = true;
67  G4cout <<
68  "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
69  "\n!!!!! Xaw is deprecated and will be removed in the next major release."
70  "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
71  << G4endl;
72  }
73 
75  if(UI!=NULL) UI->SetSession(this);
76 
77  G4Xt* interactorManager = G4Xt::getInstance (argc,argv,(char*)"Xaw");
78  Widget top = (Widget)interactorManager->GetMainInteractor();
79 
80  shell = XtAppCreateShell ("G4UIXaw","G4UIXaw",topLevelShellWidgetClass,XtDisplay(top),NULL,0);
81 
82  Arg args[2];
83  XtSetArg (args[0],XtNlabel,"G4 command");
84  XtSetArg (args[1],XtNvalue,""); // Needed to have a text Area.
85  dialog = XtCreateManagedWidget ("dialog",dialogWidgetClass,shell,args,2);
86 
87  XawDialogAddButton (dialog,"Ok",Callback,(XtPointer)this);
88 
89  XtRealizeWidget (shell);
90 }
91 /***************************************************************************/
92 G4UIXaw::~G4UIXaw (
93 )
94 /***************************************************************************/
96 {
97  XtDestroyWidget (shell);
99  if(UI!=NULL) UI->SetSession(NULL);
100 }
101 /***************************************************************************/
102 G4UIsession* G4UIXaw::SessionStart (
103 )
104 /***************************************************************************/
106 {
107  G4Xt* interactorManager = G4Xt::getInstance ();
108  Prompt ("session");
109  exitSession = false;
110  interactorManager->DisableSecondaryLoop ();
111  void* event;
112  while((event = interactorManager->GetEvent())!=NULL) {
113  interactorManager->DispatchEvent(event);
114  if(exitSession==true) break;
115  }
116  interactorManager->EnableSecondaryLoop ();
117  return this;
118 }
119 /***************************************************************************/
120 void G4UIXaw::Prompt (
121 const G4String& aPrompt
122 )
123 /***************************************************************************/
125 {
126  Arg args[1];
127  XtSetArg (args[0],XtNlabel,aPrompt.data());
128  XtSetValues (dialog,args,1);
129 }
130 /***************************************************************************/
131 void G4UIXaw::SessionTerminate (
132 )
133 /***************************************************************************/
135 {
136 }
137 /***************************************************************************/
138 void G4UIXaw::PauseSessionStart (
139 const G4String& a_state
140 )
141 /***************************************************************************/
143 {
144  if(a_state=="G4_pause> ") {
145  SecondaryLoop ("Pause, type continue to exit this state");
146  }
147 
148  if(a_state=="EndOfEvent") {
149  // Picking with feed back in event data Done here !!!
150  SecondaryLoop ("End of event, type continue to exit this state");
151  }
152 }
153 /***************************************************************************/
154 void G4UIXaw::SecondaryLoop (
155  G4String a_prompt
156 )
157 /***************************************************************************/
159 {
160  G4Xt* interactorManager = G4Xt::getInstance ();
161  Prompt (a_prompt);
162  exitPause = false;
163  void* event;
164  while((event = interactorManager->GetEvent())!=NULL) {
165  interactorManager->DispatchEvent(event);
166  if(exitPause==true) break;
167  }
168  Prompt ("session");
169 }
170 /***************************************************************************/
171 Widget G4UIXaw::GetDialog (
172 )
173 /***************************************************************************/
175 {
176  return dialog;
177 }
178 /***************************************************************************/
179 G4bool G4UIXaw::GetHelpChoice(
180  G4int& aInt
181 )
182 /***************************************************************************/
184 {
185  fHelp = true;
186  //
187  G4Xt* interactorManager = G4Xt::getInstance ();
188  Prompt("Help");
189  exitHelp = false;
190  void* event;
191  while((event = interactorManager->GetEvent())!=NULL) {
192  interactorManager->DispatchEvent(event);
193  if(exitHelp==true) break;
194  }
195  Prompt("session");
196  //
197  if(fHelp==false) return false;
198  aInt = fHelpChoice;
199  fHelp = false;
200  return true;
201 }
202 /***************************************************************************/
203 void G4UIXaw::ExitHelp(
204 ) const
205 /***************************************************************************/
207 {
208 }
209 /***************************************************************************/
210 /***************************************************************************/
211 /***************************************************************************/
212 void G4UIXaw::Callback (
213  Widget
214 ,XtPointer a_tag
215 ,XtPointer
216 )
217 /***************************************************************************/
219 {
220  G4UIXaw* This = (G4UIXaw*)a_tag;
221  Widget dialog = This->GetDialog();
222  char* value = XawDialogGetValueString(dialog);
223  if(value==NULL) return;
224  G4String command (value);
225 
226  if(This->fHelp==true) {
227  exitHelp = true;
228  This->fHelp = ConvertStringToInt(command.data(),This->fHelpChoice);
229  } else {
230  This->ApplyShellCommand (command,exitSession,exitPause);
231  }
232 
233  Arg args[1];
234  XtSetArg (args[0],XtNvalue,"");
235  XtSetValues (dialog,args,1);
236 
237  //a_widget = NULL; Not used (1st argument). Comment out to avoid compiler warnings. (JA)
238  //a_data = NULL; Not used (3rd argument). Comment out to avoid compiler warnings. (JA)
239 }
241 G4bool ConvertStringToInt(
242  const char* aString
243 ,int& aInt
244 )
247 {
248  aInt = 0;
249  if(aString==NULL) return false;
250  char* s;
251  long value = strtol(aString,&s,10);
252  if(s==aString) return false;
253  aInt = value;
254  return true;
255 }
256 
257 #endif