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

G4VInteractorManager.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: G4VInteractorManager.cc,v 1.13 2006/06/29 19:10:24 gunter Exp $
00028 // GEANT4 tag $Name: geant4-08-01-patch-01 $
00029 //
00030 // G.Barrand
00031 
00032 #include <stdlib.h>
00033 #include <string.h>
00034 
00035 #include <algorithm>
00036 
00037 #include "G4VInteractorManager.hh"
00038 
00039 #define NewString(str)  \
00040  ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
00041 
00042 /***************************************************************************/
00043 G4VInteractorManager::G4VInteractorManager (
00044 )
00045 :argc(0)
00046 ,argv(NULL)
00047 ,mainInteractor(NULL)
00048 ,secondaryLoopEnabled(TRUE)
00049 ,alreadyInSecondaryLoop(FALSE)
00050 ,exitSecondaryLoop(0)
00051 ,parentInteractor(NULL)
00052 ,createdInteractor(NULL)
00053 ,creationString(NULL)
00054 /***************************************************************************/
00056 {
00057 }
00058 /***************************************************************************/
00059 G4VInteractorManager::~G4VInteractorManager (
00060 ) 
00061 /***************************************************************************/
00063 {
00064   if(argv!=NULL) {
00065     for(G4int argi=0;argi<argc;argi++) {
00066       if(argv[argi]!=NULL) free(argv[argi]);
00067     }
00068     free (argv);
00069   }
00070   argv = NULL;
00071   argc = 0;
00072   dispatchers.clear();
00073   preActions.clear();
00074   postActions.clear();
00075   shells.clear();
00076   secondaryLoopEnabled = TRUE;
00077   alreadyInSecondaryLoop = FALSE;
00078   exitSecondaryLoop = 0;
00079 }
00080 /***************************************************************************/
00081 void G4VInteractorManager::SetArguments (
00082  G4int  a_argc
00083 ,char** a_argv
00084 )
00085 /***************************************************************************/
00087 {
00088   // Free previous values.
00089   if(argv!=NULL) {
00090     for(G4int argi=0;argi<argc;argi++) {
00091       if(argv[argi]!=NULL) free(argv[argi]);
00092     }
00093     free(argv);
00094   }
00095   argv = NULL;
00096   argc = 0;
00097   // Set new values.
00098   if(a_argc!=0) {
00099     argv = (char**)malloc(a_argc * sizeof(char*));
00100     if(argv!=NULL) {
00101       argc = a_argc;
00102       for(G4int argi=0;argi<a_argc;argi++) {
00103         argv[argi] = (char*)NewString (a_argv[argi]);
00104       }
00105     }
00106   }
00107 }
00108 /***************************************************************************/
00109 char** G4VInteractorManager::GetArguments (
00110  G4int* a_argc
00111 )
00112 /***************************************************************************/
00114 {
00115   if(a_argc!=NULL) *a_argc = argc;
00116   return argv;
00117 }
00118 /***************************************************************************/
00119 void G4VInteractorManager::SetMainInteractor (
00120  G4Interactor a_main
00121 )
00122 /***************************************************************************/
00124 {
00125   mainInteractor = a_main;
00126 }
00127 /***************************************************************************/
00128 G4Interactor G4VInteractorManager::GetMainInteractor (
00129 )
00130 /***************************************************************************/
00132 {
00133   return mainInteractor;
00134 }
00135 /***************************************************************************/
00136 void G4VInteractorManager::EnableSecondaryLoop (
00137 )
00138 /***************************************************************************/
00140 {
00141   secondaryLoopEnabled = TRUE;
00142 }
00143 /***************************************************************************/
00144 void G4VInteractorManager::DisableSecondaryLoop (
00145 )
00146 /***************************************************************************/
00148 {
00149   secondaryLoopEnabled = FALSE;
00150 }
00151 /***************************************************************************/
00152 void G4VInteractorManager::AddDispatcher (
00153  G4DispatchFunction a_dispatcher
00154 )
00155 /***************************************************************************/
00157 {
00158   if(a_dispatcher==NULL) return;
00159   if(std::find(dispatchers.begin(),dispatchers.end(),a_dispatcher)!=dispatchers.end()) return;
00160   dispatchers.push_back(a_dispatcher);
00161 }
00162 /***************************************************************************/
00163 void G4VInteractorManager::RemoveDispatcher (
00164  G4DispatchFunction a_dispatcher
00165 )
00166 /***************************************************************************/
00168 {
00169   std::vector<G4DispatchFunction>::iterator it;
00170   for (it = dispatchers.begin(); it != dispatchers.end(); it++) {
00171     if (*it == a_dispatcher) {
00172       dispatchers.erase(it);
00173       break;
00174     }
00175   }
00176 }
00177 /***************************************************************************/
00178 void G4VInteractorManager::DispatchEvent (
00179  void* a_event
00180 )
00181 /***************************************************************************/
00183 {
00184   G4int dispatchern = dispatchers.size();
00185   G4DispatchFunction func;
00186   for(G4int count=0;count<dispatchern;count++) {
00187     func = dispatchers[count];
00188     if(func!=NULL) {
00189       if(func(a_event)==true) return;
00190     }
00191   }
00192 }
00193 /***************************************************************************/
00194 void G4VInteractorManager::AddSecondaryLoopPreAction (
00195  G4SecondaryLoopAction a_preAction
00196 )
00197 /***************************************************************************/
00199 {
00200   if(a_preAction==NULL) return;
00201   if(std::find(preActions.begin(),preActions.end(),a_preAction)!=preActions.end()) return;
00202   preActions.push_back(a_preAction);
00203 }
00204 /***************************************************************************/
00205 void G4VInteractorManager::SecondaryLoopPreActions (
00206 )
00207 /***************************************************************************/
00209 {
00210   G4int preActionn = preActions.size();
00211   for(G4int count=0;count<preActionn;count++) {
00212     if(preActions[count]!=NULL) preActions[count]();
00213   }
00214 }
00215 /***************************************************************************/
00216 void G4VInteractorManager::AddSecondaryLoopPostAction (
00217  G4SecondaryLoopAction a_postAction
00218 )
00219 /***************************************************************************/
00221 {
00222   if(a_postAction==NULL) return;
00223   if(std::find(postActions.begin(),postActions.end(),a_postAction)!=postActions.end()) return;
00224   postActions.push_back(a_postAction);
00225 }
00226 /***************************************************************************/
00227 void G4VInteractorManager::SecondaryLoopPostActions (
00228 )
00229 /***************************************************************************/
00231 {
00232   G4int postActionn = postActions.size();
00233   for(G4int count=0;count<postActionn;count++) {
00234     if(postActions[count]!=NULL) postActions[count]();
00235   }
00236 }
00237 /***************************************************************************/
00238 void G4VInteractorManager::SecondaryLoop (
00239 ) 
00240 /***************************************************************************/
00242 {
00243   if(Inited()==FALSE) return;
00244 
00245   if(secondaryLoopEnabled==FALSE) return;
00246   
00247   if (alreadyInSecondaryLoop==FALSE) {
00248     G4cout << "------------------------------------------" << G4endl;
00249     G4cout << "You have entered a viewer secondary X event loop." << G4endl;
00250     G4cout << "Quit it with an 'Escape' viewer button" << G4endl;
00251     alreadyInSecondaryLoop   = TRUE;
00252     exitSecondaryLoop        = 0;
00253     SecondaryLoopPreActions  ();
00254     //for(G4int count=0;count<shelln;count++) XWidgetUniconify(shells[count]);
00255     void*                    event;
00256     while(1) {
00257       event = GetEvent();
00258       if(event==NULL) break;
00259       DispatchEvent  (event);
00260       if(exitSecondaryLoop!=0) break;
00261     }
00262     G4cout << "Secondary X event loop exited." << G4endl;
00263     SecondaryLoopPostActions ();
00264     }
00265 }
00266 /***************************************************************************/
00267 void G4VInteractorManager::RequireExitSecondaryLoop (
00268  G4int a_code
00269 ) 
00270 /***************************************************************************/
00272 {
00273   if(secondaryLoopEnabled==FALSE) return;
00274   if(a_code==0)            a_code = 1;
00275   exitSecondaryLoop        = a_code;
00276   alreadyInSecondaryLoop   = FALSE;
00277   // for(G4int count=0;count<shelln;count++) XWidgetIconify(shells[count]);
00278   // if(shelln!=0)            XSync(XtDisplay(topWidget),False);
00279 }
00280 /***************************************************************************/
00281 G4int G4VInteractorManager::GetExitSecondaryLoopCode (
00282 ) 
00283 /***************************************************************************/
00285 {
00286   return exitSecondaryLoop;
00287 }
00288 /***************************************************************************/
00289 void G4VInteractorManager::AddShell (
00290  G4Interactor a_shell
00291 )
00292 /***************************************************************************/
00294 {
00295   if(a_shell==NULL) return;
00296   if(std::find(shells.begin(),shells.end(),a_shell)!=shells.end()) return;
00297   shells.push_back(a_shell);
00298 }
00299 /***************************************************************************/
00300 void G4VInteractorManager::RemoveShell (
00301  G4Interactor a_shell
00302 )
00303 /***************************************************************************/
00305 {  
00306   std::vector<G4Interactor>::iterator it;
00307   for (it = shells.begin(); it != shells.end(); it++) {
00308     if (*it == a_shell) {
00309       shells.erase(it);
00310       break;
00311     }
00312   }
00313 }
00314 /***************************************************************************/
00315 void G4VInteractorManager::SetParentInteractor (
00316  G4Interactor a_interactor
00317 )
00318 /***************************************************************************/
00320 {
00321   parentInteractor = a_interactor;
00322 }
00323 /***************************************************************************/
00324 G4Interactor G4VInteractorManager::GetParentInteractor (
00325 )
00326 /***************************************************************************/
00328 {
00329   return parentInteractor;
00330 }
00331 /***************************************************************************/
00332 void G4VInteractorManager::SetCreatedInteractor (
00333  G4Interactor a_interactor
00334 )
00335 /***************************************************************************/
00337 {
00338   createdInteractor = a_interactor;
00339 }
00340 /***************************************************************************/
00341 G4Interactor G4VInteractorManager::GetCreatedInteractor (
00342 )
00343 /***************************************************************************/
00345 {
00346   return createdInteractor;
00347 }
00348 /***************************************************************************/
00349 void G4VInteractorManager::SetCreationString (
00350  char* a_string
00351 )
00352 /***************************************************************************/
00354 {
00355   creationString = a_string;
00356 }
00357 /***************************************************************************/
00358 char* G4VInteractorManager::GetCreationString (
00359 )
00360 /***************************************************************************/
00362 {
00363   return creationString;
00364 }
00365 

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