00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef G4UI_BUILD_XAW_SESSION
00034
00035 #include <X11/Intrinsic.h>
00036 #include <X11/StringDefs.h>
00037 #include <X11/Shell.h>
00038
00039 #include <Xaw/Dialog.h>
00040 #include <Xaw/Command.h>
00041
00042 #include "G4UIXaw.hh"
00043 #include "G4UImanager.hh"
00044 #include "G4StateManager.hh"
00045 #include "G4UIcommandTree.hh"
00046 #include "G4UIcommandStatus.hh"
00047 #include "G4Xt.hh"
00048
00049 static G4bool ConvertStringToInt(const char*,int&);
00050
00051 static G4bool exitSession = true;
00052 static G4bool exitPause = true;
00053 static G4bool exitHelp = true;
00054
00055 G4UIXaw::G4UIXaw (
00056 int argc
00057 ,char** argv
00058 )
00059 :fHelp(false)
00060 ,fHelpChoice(0)
00061
00063 {
00064 static G4bool warned = false;
00065 if (!warned) {
00066 warned = true;
00067 G4cout <<
00068 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
00069 "\n!!!!! Xaw is deprecated and will be removed in the next major release."
00070 "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
00071 << G4endl;
00072 }
00073
00074 G4UImanager* UI = G4UImanager::GetUIpointer();
00075 if(UI!=NULL) UI->SetSession(this);
00076
00077 G4Xt* interactorManager = G4Xt::getInstance (argc,argv,(char*)"Xaw");
00078 Widget top = (Widget)interactorManager->GetMainInteractor();
00079
00080 shell = XtAppCreateShell ("G4UIXaw","G4UIXaw",topLevelShellWidgetClass,XtDisplay(top),NULL,0);
00081
00082 Arg args[2];
00083 XtSetArg (args[0],XtNlabel,"G4 command");
00084 XtSetArg (args[1],XtNvalue,"");
00085 dialog = XtCreateManagedWidget ("dialog",dialogWidgetClass,shell,args,2);
00086
00087 XawDialogAddButton (dialog,"Ok",Callback,(XtPointer)this);
00088
00089 XtRealizeWidget (shell);
00090 }
00091
00092 G4UIXaw::~G4UIXaw (
00093 )
00094
00096 {
00097 XtDestroyWidget (shell);
00098 G4UImanager* UI = G4UImanager::GetUIpointer();
00099 if(UI!=NULL) UI->SetSession(NULL);
00100 }
00101
00102 G4UIsession* G4UIXaw::SessionStart (
00103 )
00104
00106 {
00107 G4Xt* interactorManager = G4Xt::getInstance ();
00108 Prompt ("session");
00109 exitSession = false;
00110 interactorManager->DisableSecondaryLoop ();
00111 void* event;
00112 while((event = interactorManager->GetEvent())!=NULL) {
00113 interactorManager->DispatchEvent(event);
00114 if(exitSession==true) break;
00115 }
00116 interactorManager->EnableSecondaryLoop ();
00117 return this;
00118 }
00119
00120 void G4UIXaw::Prompt (
00121 const G4String& aPrompt
00122 )
00123
00125 {
00126 Arg args[1];
00127 XtSetArg (args[0],XtNlabel,aPrompt.data());
00128 XtSetValues (dialog,args,1);
00129 }
00130
00131 void G4UIXaw::SessionTerminate (
00132 )
00133
00135 {
00136 }
00137
00138 void G4UIXaw::PauseSessionStart (
00139 const G4String& a_state
00140 )
00141
00143 {
00144 if(a_state=="G4_pause> ") {
00145 SecondaryLoop ("Pause, type continue to exit this state");
00146 }
00147
00148 if(a_state=="EndOfEvent") {
00149
00150 SecondaryLoop ("End of event, type continue to exit this state");
00151 }
00152 }
00153
00154 void G4UIXaw::SecondaryLoop (
00155 G4String a_prompt
00156 )
00157
00159 {
00160 G4Xt* interactorManager = G4Xt::getInstance ();
00161 Prompt (a_prompt);
00162 exitPause = false;
00163 void* event;
00164 while((event = interactorManager->GetEvent())!=NULL) {
00165 interactorManager->DispatchEvent(event);
00166 if(exitPause==true) break;
00167 }
00168 Prompt ("session");
00169 }
00170
00171 Widget G4UIXaw::GetDialog (
00172 )
00173
00175 {
00176 return dialog;
00177 }
00178
00179 G4bool G4UIXaw::GetHelpChoice(
00180 G4int& aInt
00181 )
00182
00184 {
00185 fHelp = true;
00186
00187 G4Xt* interactorManager = G4Xt::getInstance ();
00188 Prompt("Help");
00189 exitHelp = false;
00190 void* event;
00191 while((event = interactorManager->GetEvent())!=NULL) {
00192 interactorManager->DispatchEvent(event);
00193 if(exitHelp==true) break;
00194 }
00195 Prompt("session");
00196
00197 if(fHelp==false) return false;
00198 aInt = fHelpChoice;
00199 fHelp = false;
00200 return true;
00201 }
00202
00203 void G4UIXaw::ExitHelp(
00204 ) const
00205
00207 {
00208 }
00209
00210
00211
00212 void G4UIXaw::Callback (
00213 Widget
00214 ,XtPointer a_tag
00215 ,XtPointer
00216 )
00217
00219 {
00220 G4UIXaw* This = (G4UIXaw*)a_tag;
00221 Widget dialog = This->GetDialog();
00222 char* value = XawDialogGetValueString(dialog);
00223 if(value==NULL) return;
00224 G4String command (value);
00225
00226 if(This->fHelp==true) {
00227 exitHelp = true;
00228 This->fHelp = ConvertStringToInt(command.data(),This->fHelpChoice);
00229 } else {
00230 This->ApplyShellCommand (command,exitSession,exitPause);
00231 }
00232
00233 Arg args[1];
00234 XtSetArg (args[0],XtNvalue,"");
00235 XtSetValues (dialog,args,1);
00236
00237
00238
00239 }
00241 G4bool ConvertStringToInt(
00242 const char* aString
00243 ,int& aInt
00244 )
00247 {
00248 aInt = 0;
00249 if(aString==NULL) return false;
00250 char* s;
00251 long value = strtol(aString,&s,10);
00252 if(s==aString) return false;
00253 aInt = value;
00254 return true;
00255 }
00256
00257 #endif