G4UIXaw.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // G.Barrand
00030 
00031 //#define DEBUG
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,"");             // Needed to have a text Area.
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     // Picking with feed back in event data Done here !!!
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   //a_widget     = NULL;  Not used (1st argument).  Comment out to avoid compiler warnings. (JA)
00238   //a_data       = NULL;  Not used (3rd argument).  Comment out to avoid compiler warnings. (JA)
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

Generated on Mon May 27 17:50:07 2013 for Geant4 by  doxygen 1.4.7