Import Geant4 0.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-01 15:25:35 +02:00
parent 54d6b71f95
commit b97f8d0df7
3237 changed files with 807095 additions and 0 deletions
@@ -0,0 +1,108 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
#include <rw/ctoken.h>
#include "G4UIdirectory.hh"
#include "G4UIcommand.hh"
#include "G4VInteractiveSession.hh"
#include "G4InteractorMessenger.hh"
static G4bool GetValues (G4String,int,G4String*);
G4InteractorMessenger::G4InteractorMessenger (
G4VInteractiveSession* a_session
)
{
session = a_session;
G4UIparameter* parameter;
interactorDirectory = new G4UIdirectory("/interactor/");
interactorDirectory->SetGuidance("UI interactors commands.");
// /interactor/addMenu :
addMenu = new G4UIcommand("/interactor/addMenu",this);
addMenu->SetGuidance("Add a menu to menu bar.");
parameter = new G4UIparameter("Name",'s',false);
parameter->SetDefaultValue("dummy");
addMenu->SetParameter (parameter);
parameter = new G4UIparameter("Label",'s',false);
parameter->SetDefaultValue("dummy");
addMenu->SetParameter (parameter);
// /interactor/addButton :
addButton = new G4UIcommand("/interactor/addButton",this);
addButton->SetGuidance("Add a button to menu.");
parameter = new G4UIparameter("Menu",'s',false);
parameter->SetDefaultValue("dummy");
addButton->SetParameter (parameter);
parameter = new G4UIparameter("Label",'s',false);
parameter->SetDefaultValue("dummy");
addButton->SetParameter (parameter);
parameter = new G4UIparameter("Command",'s',false);
parameter->SetDefaultValue("");
addButton->SetParameter (parameter);
}
G4InteractorMessenger::~G4InteractorMessenger()
{
delete addButton;
delete addMenu;
delete interactorDirectory;
}
void G4InteractorMessenger::SetNewValue (
G4UIcommand* command
,G4String newValue
)
{
int paramn = command->GetParameterEntries();
G4String* params = new G4String [paramn];
if(GetValues(newValue,paramn,params)==true) {
if(command==addMenu) {
session->AddMenu(params[0],params[1]);
} else if(command==addButton) {
session->AddButton(params[0],params[1],params[2]);
}
}
delete [] params;
}
G4bool GetValues (
G4String newValue
,int paramn
,G4String* params
)
{
RWCTokenizer newValueToken( newValue );
G4String aToken;
for( int i=0; i<paramn;i++ ) {
aToken = newValueToken();
if( aToken(0)=='"' ) {
while( aToken(aToken.length()-1) != '"' ) {
G4String additionalToken = newValueToken();
if( additionalToken.isNull() ) {
return false;
}
aToken += " ";
aToken += additionalToken;
}
aToken = aToken.strip(G4String::both,'"');
}
if( aToken.isNull() ) {
return false;
} else {
params[i] = aToken;
}
}
return true;
}
@@ -0,0 +1,143 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4VBasicShell.cc,v 2.2 1998/07/12 03:00:20 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
#include "G4VBasicShell.hh"
#include "G4StateManager.hh"
#include "G4UIcommandTree.hh"
#include "G4UIcommand.hh"
#include "G4UIcommandStatus.hh"
#include "G4UImanager.hh"
#ifdef WIN32
# include <Strstrea.h>
#else
# include <strstream.h>
#endif
G4VBasicShell::G4VBasicShell()
{
currentDirectory = "/";
}
G4VBasicShell::~G4VBasicShell()
{;}
G4String G4VBasicShell::ModifyToFullPathCommand(const char* aCommandLine)
{
G4String rawCommandLine = aCommandLine;
if(rawCommandLine.isNull()||rawCommandLine(0)=='\0') return rawCommandLine;
G4String commandLine = rawCommandLine.strip(G4String::both);
G4String commandString;
G4String parameterString;
int i = commandLine.index(" ");
if( i != RW_NPOS )
{
commandString = commandLine(0,i);
parameterString = " ";
parameterString += commandLine(i+1,commandLine.length()-(i+1));
}
else
{ commandString = commandLine; }
G4String fullPathCommandLine
= ModifyPath( commandString )+parameterString;
return fullPathCommandLine;
}
G4String G4VBasicShell::GetCurrentWorkingDirectory()
{
return currentDirectory;
}
G4bool G4VBasicShell::ChangeDirectory(const char* newDir)
{
G4String aNewPrefix = newDir;
G4String newPrefix = aNewPrefix.strip(G4String::both);
G4String newDirectory = ModifyPath( newPrefix );
if( newDirectory( newDirectory.length() - 1 ) != '/' )
{ newDirectory += "/"; }
if( FindDirectory( newDirectory ) == NULL )
{ return false; }
currentDirectory = newDirectory;
return true;
}
G4UIcommandTree* G4VBasicShell::FindDirectory(const char* dirName)
{
G4String aDirName = dirName;
G4String theDir = aDirName.strip(G4String::both);
G4String targetDir = ModifyPath( theDir );
if( targetDir( targetDir.length()-1 ) != '/' )
{ targetDir += "/"; }
G4UIcommandTree* comTree = G4UImanager::GetUIpointer()->GetTree();
if( targetDir == "/" )
{ return comTree; }
int idx = 1;
while( idx < targetDir.length()-1 )
{
int i = targetDir.index("/",idx);
comTree = comTree->GetTree(targetDir(0,i+1));
if( comTree == NULL )
{ return NULL; }
idx = i+1;
}
return comTree;
}
G4UIcommand* G4VBasicShell::FindCommand(const char* commandName)
{
G4String rawCommandLine = commandName;
G4String commandLine = rawCommandLine.strip(G4String::both);
G4String commandString;
int i = commandLine.index(" ");
if( i != RW_NPOS )
{ commandString = commandLine(0,i); }
else
{ commandString = commandLine; }
G4String targetCom = ModifyPath(commandString);
return G4UImanager::GetUIpointer()->GetTree()->FindPath(targetCom);
}
G4String G4VBasicShell::ModifyPath(G4String tempPath)
{
G4String newPath = currentDirectory;
if( tempPath(0) == '/' ) // full path is given
{ newPath = tempPath; }
else if( tempPath(0) != '.' ) // add current prefix
{ newPath += tempPath; }
else if( tempPath(0,2) == "./" ) // add current prefix
{ newPath += tempPath(2,tempPath.length()-2); }
else // swim up with ".."
{
while( 1 )
{
if( tempPath(0,2) == ".." )
{
if( newPath != "/" )
{
G4String tmpString = newPath(0,newPath.length()-1);
newPath = newPath(0,tmpString.last('/')+1);
}
if( tempPath == ".." || tempPath == "../" )
{ break; }
tempPath = tempPath(3,tempPath.length()-3);
}
else
{
newPath += tempPath;
break;
}
}
}
return newPath;
}
@@ -0,0 +1,73 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
#include "G4InteractorMessenger.hh"
#include "G4VInteractiveSession.hh"
static unsigned InteractorsHashFun (const G4String& name) {
return name.hash();
}
/***************************************************************************/
G4VInteractiveSession::G4VInteractiveSession (
)
:interactors(InteractorsHashFun)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
messenger = new G4InteractorMessenger(this);
}
/***************************************************************************/
G4VInteractiveSession::~G4VInteractiveSession()
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
delete messenger;
}
/***************************************************************************/
void G4VInteractiveSession::AddMenu (
const char* a_name
,const char* a_label
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
}
/***************************************************************************/
void G4VInteractiveSession::AddButton (
const char* a_menu
,const char* a_label
,const char* a_command
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
}
/***************************************************************************/
void G4VInteractiveSession::AddInteractor (
G4String a_name
,G4Interactor a_interactor
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
interactors[a_name] = a_interactor;
}
/***************************************************************************/
G4Interactor G4VInteractiveSession::GetInteractor (
G4String a_name
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4Interactor value;
if(interactors.findValue(a_name,value)==false) return NULL;
return value;
}
@@ -0,0 +1,383 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4VInteractorManager.cc,v 2.3 1998/08/07 12:39:53 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G.Barrand
#include <stdlib.h>
#include <string.h>
#include "G4VInteractorManager.hh"
#define NewString(str) \
((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
/***************************************************************************/
G4VInteractorManager::G4VInteractorManager (
)
:argc(0)
,argv(NULL)
,mainInteractor(NULL)
,dispatchern(0)
,dispatchers(NULL)
,preActionn(0)
,preActions(NULL)
,postActionn(0)
,postActions(NULL)
,shelln(0)
,shells(NULL)
,secondaryLoopEnabled(TRUE)
,alreadyInSecondaryLoop(FALSE)
,exitSecondaryLoop(0)
,parentInteractor(NULL)
,createdInteractor(NULL)
,creationString(NULL)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
}
/***************************************************************************/
G4VInteractorManager::~G4VInteractorManager (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(argv!=NULL) {
for(int argi=0;argi<argc;argi++) {
if(argv[argi]!=NULL) free(argv[argi]);
}
free (argv);
}
argv = NULL;
argc = 0;
if(dispatchers!=NULL) free(dispatchers);
dispatchers = NULL;
dispatchern = 0;
if(preActions!=NULL) free(preActions);
preActions = NULL;
preActionn = 0;
if(postActions!=NULL) free(postActions);
postActions = NULL;
postActionn = 0;
if(shells!=NULL) free(shells);
shells = NULL;
shelln = 0;
secondaryLoopEnabled = TRUE;
alreadyInSecondaryLoop = FALSE;
exitSecondaryLoop = 0;
}
/***************************************************************************/
void G4VInteractorManager::SetArguments (
int a_argc
,char** a_argv
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
// Free previous values.
if(argv!=NULL) {
for(int argi=0;argi<argc;argi++) {
if(argv[argi]!=NULL) free(argv[argi]);
}
free(argv);
}
argv = NULL;
argc = 0;
// Set new values.
if(a_argc!=0) {
argv = (char**)malloc(a_argc * sizeof(char*));
if(argv!=NULL) {
argc = a_argc;
for(int argi=0;argi<a_argc;argi++) {
argv[argi] = (char*)NewString (a_argv[argi]);
}
}
}
}
/***************************************************************************/
char** G4VInteractorManager::GetArguments (
int* a_argc
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_argc!=NULL) *a_argc = argc;
return argv;
}
/***************************************************************************/
void G4VInteractorManager::SetMainInteractor (
G4Interactor a_main
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
mainInteractor = a_main;
}
/***************************************************************************/
G4Interactor G4VInteractorManager::GetMainInteractor (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return mainInteractor;
}
/***************************************************************************/
void G4VInteractorManager::EnableSecondaryLoop (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
secondaryLoopEnabled = TRUE;
}
/***************************************************************************/
void G4VInteractorManager::DisableSecondaryLoop (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
secondaryLoopEnabled = FALSE;
}
/***************************************************************************/
void G4VInteractorManager::AddDispatcher (
G4DispatchFunction a_dispatcher
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_dispatcher==NULL) return;
for(int count=0;count<dispatchern;count++) {
if(dispatchers[count]==a_dispatcher) return; // Done.
}
if(dispatchern==0) dispatchers = (G4DispatchFunction*)malloc( sizeof(G4DispatchFunction));
else dispatchers = (G4DispatchFunction*)realloc(dispatchers,
(dispatchern+1) * sizeof(G4DispatchFunction));
if(dispatchers==NULL) return;
dispatchers[dispatchern] = a_dispatcher;
dispatchern++;
}
/***************************************************************************/
void G4VInteractorManager::RemoveDispatcher (
G4DispatchFunction a_dispatcher
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
for(int count=0;count<dispatchern;count++) {
if(dispatchers[count]==a_dispatcher) {
dispatchers[count] = NULL;
return; // A dispatcher appears once in the List.
}
}
}
/***************************************************************************/
void G4VInteractorManager::DispatchEvent (
void* a_event
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
for(int count=0;count<dispatchern;count++) {
if(
(dispatchers[count]!=NULL) &&
(dispatchers[count](a_event)==TRUE)
)
break;
}
}
/***************************************************************************/
void G4VInteractorManager::AddSecondaryLoopPreAction (
G4SecondaryLoopAction a_preAction
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_preAction==NULL) return;
for(int count=0;count<preActionn;count++) {
if(preActions[count]==a_preAction) return; // Done.
}
if(preActionn==0)
preActions = (G4SecondaryLoopAction*)malloc( sizeof(G4SecondaryLoopAction));
else
preActions = (G4SecondaryLoopAction*)realloc(preActions,
(preActionn+1) * sizeof(G4SecondaryLoopAction));
if(preActions==NULL) return;
preActions[preActionn] = a_preAction;
preActionn++;
}
/***************************************************************************/
void G4VInteractorManager::SecondaryLoopPreActions (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
for(int count=0;count<preActionn;count++) {
if(preActions[count]!=NULL) preActions[count]();
}
}
/***************************************************************************/
void G4VInteractorManager::AddSecondaryLoopPostAction (
G4SecondaryLoopAction a_postAction
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_postAction==NULL) return;
for(int count=0;count<postActionn;count++) {
if(postActions[count]==a_postAction) return; // Done.
}
if(postActionn==0)
postActions = (G4SecondaryLoopAction*)malloc( sizeof(G4SecondaryLoopAction));
else
postActions = (G4SecondaryLoopAction*)realloc(postActions,
(postActionn+1) * sizeof(G4SecondaryLoopAction));
if(postActions==NULL) return;
postActions[postActionn] = a_postAction;
postActionn++;
}
/***************************************************************************/
void G4VInteractorManager::SecondaryLoopPostActions (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
for(int count=0;count<postActionn;count++) {
if(postActions[count]!=NULL) postActions[count]();
}
}
/***************************************************************************/
void G4VInteractorManager::SecondaryLoop (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(Inited()==FALSE) return;
if(secondaryLoopEnabled==FALSE) return;
if (alreadyInSecondaryLoop==FALSE) {
alreadyInSecondaryLoop = TRUE;
exitSecondaryLoop = 0;
SecondaryLoopPreActions ();
// for(int count=0;count<shelln;count++) XWidgetUniconify(shells[count]);
void* event;
while(1) {
event = GetEvent();
if(event==NULL) break;
DispatchEvent (event);
if(exitSecondaryLoop!=0) break;
}
SecondaryLoopPostActions ();
}
}
/***************************************************************************/
void G4VInteractorManager::RequireExitSecondaryLoop (
int a_code
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(secondaryLoopEnabled==FALSE) return;
if(a_code==0) a_code = 1;
exitSecondaryLoop = a_code;
alreadyInSecondaryLoop = FALSE;
// for(int count=0;count<shelln;count++) XWidgetIconify(shells[count]);
// if(shelln!=0) XSync(XtDisplay(topWidget),False);
}
/***************************************************************************/
int G4VInteractorManager::GetExitSecondaryLoopCode (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return exitSecondaryLoop;
}
/***************************************************************************/
void G4VInteractorManager::AddShell (
G4Interactor a_shell
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_shell==NULL) return;
for(int count=0;count<shelln;count++) {
if(shells[count]==a_shell) return; // Done.
}
if(shelln==0) shells = (G4Interactor*)malloc( sizeof(G4Interactor));
else shells = (G4Interactor*)realloc(shells, (shelln+1) * sizeof(G4Interactor));
if(shells==NULL) return;
shells[shelln] = a_shell;
shelln++;
}
/***************************************************************************/
void G4VInteractorManager::RemoveShell (
G4Interactor a_shell
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
for(int count=0;count<shelln;count++) {
if(shells[count]==a_shell) {
shells[count] = NULL;
return; // A shell appears once in the List.
}
}
}
/***************************************************************************/
void G4VInteractorManager::SetParentInteractor (
G4Interactor a_interactor
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
parentInteractor = a_interactor;
}
/***************************************************************************/
G4Interactor G4VInteractorManager::GetParentInteractor (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return parentInteractor;
}
/***************************************************************************/
void G4VInteractorManager::SetCreatedInteractor (
G4Interactor a_interactor
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
createdInteractor = a_interactor;
}
/***************************************************************************/
G4Interactor G4VInteractorManager::GetCreatedInteractor (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return createdInteractor;
}
/***************************************************************************/
void G4VInteractorManager::SetCreationString (
char* a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
creationString = a_string;
}
/***************************************************************************/
char* G4VInteractorManager::GetCreationString (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return creationString;
}
+173
View File
@@ -0,0 +1,173 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4Win32.cc,v 2.5 1998/09/19 14:45:38 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G.Barrand
#if defined(G4INTY_BUILD_WIN32) || defined(G4INTY_USE_WIN32)
#include <stdlib.h>
#include "G4ios.hh"
#include "G4UImanager.hh"
#include "G4Win32.hh"
static char className[] = "G4Win32";
G4Win32* G4Win32::instance = NULL;
static G4bool Win32Inited = FALSE;
static HINSTANCE hInstance = NULL;
static HINSTANCE hPrevInstance = NULL;
static LPTSTR lpszCmdLine = NULL;
static int nCmdShow = 0;
static HWND topWindow = NULL;
/***************************************************************************/
G4Win32* G4Win32::getInstance (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return G4Win32::getInstance(NULL,NULL,NULL,0);
}
/***************************************************************************/
G4Win32* G4Win32::getInstance (
HANDLE a_hInstance
,HANDLE a_hPrevInstance
,LPSTR a_lpszCmdLine
,int a_nCmdShow
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if (instance==NULL) {
instance = new G4Win32(a_hInstance,
a_hPrevInstance,
a_lpszCmdLine,
a_nCmdShow);
}
return instance;
}
/***************************************************************************/
G4Win32::G4Win32 (
HANDLE a_hInstance
,HANDLE a_hPrevInstance
,LPSTR a_lpszCmdLine
,int a_nCmdShow
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(Win32Inited==FALSE) { // Should be Done once.
hInstance = a_hInstance;
hPrevInstance = a_hPrevInstance;
lpszCmdLine = a_lpszCmdLine;
nCmdShow = a_nCmdShow;
if(hInstance==NULL) {
G4cout << "G4Win32::G4Win32 : NULL hInstance given." <<endl;
}
if(hPrevInstance==NULL) {
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)DefWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = className;
wc.lpszClassName = className;
::RegisterClass (&wc);
}
topWindow = ::CreateWindow(className,className,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);
if(topWindow==NULL) {
G4cout << "G4Win32 : Unable to create Win32 window." << endl;
}
Win32Inited = TRUE;
}
AddDispatcher ((G4DispatchFunction)G4Win32::dispatchWin32Event);
SetMainInteractor (topWindow);
}
/***************************************************************************/
G4Win32::~G4Win32 (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(this==instance) {
instance = NULL;
}
}
/***************************************************************************/
G4bool G4Win32::Inited (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return Win32Inited;
}
/***************************************************************************/
void* G4Win32::GetEvent (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
static MSG event;
BOOL status = ::GetMessage(&event, NULL, 0, 0);
if(status==FALSE) return NULL;
return &event;
}
/***************************************************************************/
void G4Win32::FlushAndWaitExecution (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
}
/***************************************************************************/
void G4Win32::getWinMainArguments (
HANDLE* a_hInstance
,HANDLE* a_hPrevInstance
,LPSTR* a_lpszCmdLine
,int* a_nCmdShow
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_hInstance!=NULL) *a_hInstance = hInstance;
if(a_hPrevInstance!=NULL) *a_hPrevInstance = hPrevInstance;
if(a_lpszCmdLine!=NULL) *a_lpszCmdLine = lpszCmdLine;
if(a_nCmdShow!=NULL) *a_nCmdShow = nCmdShow;
}
/***************************************************************************/
G4bool G4Win32::dispatchWin32Event (
void* a_event
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
::TranslateMessage((MSG*)a_event);
::DispatchMessage ((MSG*)a_event);
return TRUE;
}
#endif //HAS_WIN32
+214
View File
@@ -0,0 +1,214 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4Xt.cc,v 2.5 1998/08/25 12:23:53 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G.Barrand
#if defined(G4INTY_BUILD_XT) || defined(G4INTY_USE_XT)
#include <stdlib.h>
#include <string.h>
#include "G4ios.hh"
#include "G4Xt.hh"
#define NewString(str) \
((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
static void XWidgetIconify (Widget);
static void XWidgetUniconify (Widget);
static void XDisplaySetWindowToNormalState (Display*,Window);
G4Xt* G4Xt::instance = NULL;
static G4bool XtInited = FALSE;
static int argn = 0;
static char** args = NULL;
static Widget topWidget = NULL;
/***************************************************************************/
G4Xt* G4Xt::getInstance (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return G4Xt::getInstance (0,NULL,"Geant4");
}
/***************************************************************************/
G4Xt* G4Xt::getInstance (
int a_argn
,char** a_args
,char* a_class
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if (instance==NULL) {
instance = new G4Xt(a_argn,a_args,a_class);
}
return instance;
}
/***************************************************************************/
G4Xt::G4Xt (
int a_argn
,char** a_args
,char* a_class
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(XtInited==FALSE) { //Xt should be Inited once !
if(a_argn!=0) { //Save args.
args = (char**)malloc(a_argn * sizeof(char*));
if(args!=NULL) {
argn = a_argn;
for(int argi=0;argi<a_argn;argi++) {
args[argi] = (char*)NewString (a_args[argi]);
}
}
}
#if XtSpecificationRelease == 4
Cardinal argc;
argc = (Cardinal)a_argn;
#else
int argc;
argc = a_argn;
#endif
XtAppContext appContext;
topWidget = XtAppInitialize (&appContext,a_class,
NULL,(Cardinal)0,
&argc,a_args,NULL,
NULL,(Cardinal)0);
if(topWidget==NULL) {
G4cout << "G4Xt : Unable to init Xt." << endl;
}
// Restore a_args. XtAppInitialize corrupts the given ones !!!
if( (a_argn!=0) && (args!=NULL)) {
for(int argi=0;argi<a_argn;argi++) {
if(args[argi]!=NULL)
strcpy(a_args[argi],args[argi]);
else
a_args[argi] = NULL;
}
}
// If topWidget not realized, pbs with Inventor shells.
XtSetMappedWhenManaged (topWidget,False);
XtRealizeWidget (topWidget);
XtInited = TRUE;
}
SetArguments (argn,args);
SetMainInteractor (topWidget);
AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
}
/***************************************************************************/
G4Xt::~G4Xt (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(this==instance) {
instance = NULL;
}
}
/***************************************************************************/
G4bool G4Xt::Inited (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return XtInited;
}
/***************************************************************************/
void* G4Xt::GetEvent (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
static XEvent event;
if(topWidget==NULL) return NULL;
XtAppContext appContext = XtWidgetToApplicationContext(topWidget);
XtAppNextEvent (appContext, &event);
return &event;
}
/***************************************************************************/
void G4Xt::PutStringInResourceDatabase (
char* a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(topWidget==NULL) return;
if(a_string==NULL) return;
Display* dpy = XtDisplay(topWidget);
XrmDatabase dbres = XrmGetStringDatabase (a_string);
if(dbres==NULL) return;
XrmDatabase database = XrmGetDatabase (dpy);
if(database!=NULL) {
XrmMergeDatabases (dbres,&database);
} else {
XrmSetDatabase (dpy,dbres);
}
}
/***************************************************************************/
void G4Xt::FlushAndWaitExecution (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(topWidget==NULL) return;
XSync(XtDisplay(topWidget),False);
}
/***************************************************************************/
/******* From OPACS Xx/v3 package ******************************************/
/***************************************************************************/
/***************************************************************************/
void XWidgetIconify (
Widget This
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(This==NULL) return;
if(!XtIsRealized(This)) return;
XIconifyWindow(XtDisplay(This),XtWindow(This),XScreenNumberOfScreen(XtScreen(This)));
}
/***************************************************************************/
void XWidgetUniconify (
Widget This
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(This==NULL) return;
if(!XtIsRealized(This)) return;
XDisplaySetWindowToNormalState (XtDisplay(This),XtWindow(This));
}
/***************************************************************************/
void XDisplaySetWindowToNormalState (
Display* This
,Window a_window
)
/***************************************************************************/
/*
Used to deiconify a window.
*/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
XWMHints wh;
if(This==NULL) return;
if(a_window==0L) return;
wh.initial_state = NormalState;
wh.flags = StateHint;
XSetWMHints (This,a_window,&wh);
XMapWindow (This,a_window);
}
#endif