Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

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: G4UIXaw.cc,v 1.6 2006/06/29 19:09:47 gunter Exp $
00028 // GEANT4 tag $Name: geant4-08-01-patch-01 $
00029 //
00030 // G.Barrand
00031 
00032 //#define DEBUG
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,"");             // Needed to have a text Area.
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     // Picking with feed back in event data Done here !!!
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

Generated on Fri Jun 22 11:07:02 2007 by doxygen 1.3.4