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
00034 #ifdef G4UI_BUILD_XAW_SESSION
00035
00036 #include <X11/Intrinsic.h>
00037 #include <X11/StringDefs.h>
00038 #include <X11/Shell.h>
00039
00040 #include <Xaw/Dialog.h>
00041 #include <Xaw/Command.h>
00042
00043 #include "G4UIXaw.hh"
00044 #include "G4UImanager.hh"
00045 #include "G4StateManager.hh"
00046 #include "G4UIcommandTree.hh"
00047 #include "G4UIcommandStatus.hh"
00048 #include "G4Xt.hh"
00049
00050 static G4bool ConvertStringToInt(const char*,int&);
00051
00052 static G4bool exitSession = true;
00053 static G4bool exitPause = true;
00054 static G4bool exitHelp = true;
00055
00056 G4UIXaw::G4UIXaw (
00057 int argc
00058 ,char** argv
00059 )
00060 :fHelp(false)
00061 ,fHelpChoice(0)
00062
00064 {
00065 G4UImanager* UI = G4UImanager::GetUIpointer();
00066 if(UI!=NULL) UI->SetSession(this);
00067
00068 G4Xt* interactorManager = G4Xt::getInstance (argc,argv,(char*)"Xaw");
00069 Widget top = (Widget)interactorManager->GetMainInteractor();
00070
00071 shell = XtAppCreateShell ("G4UIXaw","G4UIXaw",topLevelShellWidgetClass,XtDisplay(top),NULL,0);
00072
00073 Arg args[2];
00074 XtSetArg (args[0],XtNlabel,"G4 command");
00075 XtSetArg (args[1],XtNvalue,"");
00076 dialog = XtCreateManagedWidget ("dialog",dialogWidgetClass,shell,args,2);
00077
00078 XawDialogAddButton (dialog,"Ok",Callback,(XtPointer)this);
00079
00080 XtRealizeWidget (shell);
00081 }
00082
00083 G4UIXaw::~G4UIXaw (
00084 )
00085
00087 {
00088 XtDestroyWidget (shell);
00089 G4UImanager* UI = G4UImanager::GetUIpointer();
00090 if(UI!=NULL) UI->SetSession(NULL);
00091 }
00092
00093 G4UIsession* G4UIXaw::SessionStart (
00094 )
00095
00097 {
00098 G4Xt* interactorManager = G4Xt::getInstance ();
00099 Prompt ("session");
00100 exitSession = false;
00101 interactorManager->DisableSecondaryLoop ();
00102 void* event;
00103 while((event = interactorManager->GetEvent())!=NULL) {
00104 interactorManager->DispatchEvent(event);
00105 if(exitSession==true) break;
00106 }
00107 interactorManager->EnableSecondaryLoop ();
00108 return this;
00109 }
00110
00111 void G4UIXaw::Prompt (
00112 G4String aPrompt
00113 )
00114
00116 {
00117 Arg args[1];
00118 XtSetArg (args[0],XtNlabel,aPrompt.data());
00119 XtSetValues (dialog,args,1);
00120 }
00121
00122 void G4UIXaw::SessionTerminate (
00123 )
00124
00126 {
00127 }
00128
00129 void G4UIXaw::PauseSessionStart (
00130 G4String a_state
00131 )
00132
00134 {
00135 if(a_state=="G4_pause> ") {
00136 SecondaryLoop ("Pause, type continue to exit this state");
00137 }
00138
00139 if(a_state=="EndOfEvent") {
00140
00141 SecondaryLoop ("End of event, type continue to exit this state");
00142 }
00143 }
00144
00145 void G4UIXaw::SecondaryLoop (
00146 G4String a_prompt
00147 )
00148
00150 {
00151 G4Xt* interactorManager = G4Xt::getInstance ();
00152 Prompt (a_prompt);
00153 exitPause = false;
00154 void* event;
00155 while((event = interactorManager->GetEvent())!=NULL) {
00156 interactorManager->DispatchEvent(event);
00157 if(exitPause==true) break;
00158 }
00159 Prompt ("session");
00160 }
00161
00162 Widget G4UIXaw::GetDialog (
00163 )
00164
00166 {
00167 return dialog;
00168 }
00169
00170 G4bool G4UIXaw::GetHelpChoice(
00171 G4int& aInt
00172 )
00173
00175 {
00176 fHelp = true;
00177
00178 G4Xt* interactorManager = G4Xt::getInstance ();
00179 Prompt("Help");
00180 exitHelp = false;
00181 void* event;
00182 while((event = interactorManager->GetEvent())!=NULL) {
00183 interactorManager->DispatchEvent(event);
00184 if(exitHelp==true) break;
00185 }
00186 Prompt("session");
00187
00188 if(fHelp==false) return false;
00189 aInt = fHelpChoice;
00190 fHelp = false;
00191 return true;
00192 }
00193
00194 void G4UIXaw::ExitHelp(
00195 )
00196
00198 {
00199 }
00200
00201
00202
00203 void G4UIXaw::Callback (
00204 Widget a_widget
00205 ,XtPointer a_tag
00206 ,XtPointer a_data
00207 )
00208
00210 {
00211 G4UIXaw* This = (G4UIXaw*)a_tag;
00212 Widget dialog = This->GetDialog();
00213 char* value = XawDialogGetValueString(dialog);
00214 if(value==NULL) return;
00215 G4String command (value);
00216
00217 if(This->fHelp==true) {
00218 exitHelp = true;
00219 This->fHelp = ConvertStringToInt(command.data(),This->fHelpChoice);
00220 } else {
00221 This->ApplyShellCommand (command,exitSession,exitPause);
00222 }
00223
00224 Arg args[1];
00225 XtSetArg (args[0],XtNvalue,"");
00226 XtSetValues (dialog,args,1);
00227
00228 a_widget = NULL;
00229 a_data = NULL;
00230 }
00232 G4bool ConvertStringToInt(
00233 const char* aString
00234 ,int& aInt
00235 )
00238 {
00239 aInt = 0;
00240 if(aString==NULL) return false;
00241 char* s;
00242 long value = strtol(aString,&s,10);
00243 if(s==aString) return false;
00244 aInt = value;
00245 return true;
00246 }
00247
00248 #endif