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
+21
View File
@@ -0,0 +1,21 @@
# $Id: GNUmakefile,v 2.2 1998/07/07 16:57:27 allison Exp $
# -------------------------------------------------------------
# GNUmakefile for interfaces/basic library. John Allison, 6/7/98.
name := G4UIbasic
ifndef G4INSTALL
G4INSTALL = ../../..
endif
include $(G4INSTALL)/config/architecture.gmk
include $(G4INSTALL)/config/G4UI_BUILD.gmk
include $(G4INSTALL)/config/interactivity.gmk
G4TMPDIR = $(G4TMP)/$(G4SYSTEM)/$(name)
CPPFLAGS += -I$(G4BASE)/global/management/include
CPPFLAGS += -I$(G4BASE)/interfaces/common/include
CPPFLAGS += -I$(G4BASE)/intercoms/include
include $(G4INSTALL)/config/common.gmk
@@ -0,0 +1,61 @@
// 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: G4UIWin32.hh,v 2.5 1998/10/23 14:39:02 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UIWin32_h
#define G4UIWin32_h
#if defined(G4UI_BUILD_WIN32_SESSION) || defined(G4UI_USE_WIN32)
#include <rw/tvhdict.h>
#include "G4VBasicShell.hh"
#include "G4VInteractiveSession.hh"
#include "G4Win32.hh"
class G4VInteractorManager;
class G4UIWin32 : public G4VBasicShell, public G4VInteractiveSession {
public:
G4UIWin32 (HINSTANCE,HINSTANCE,LPSTR,int);
~G4UIWin32 ();
G4UIsession* SessionStart ();
void Prompt (G4String);
void SessionTerminate ();
void PauseSessionStart (G4String);
G4int ReceiveG4cout(G4String);
G4int ReceiveG4cerr(G4String);
void ApplyShellCommand (G4String);
void AddMenu (const char*,const char*);
void AddButton (const char*,const char*,const char*);
G4String GetCommand (int);
void TextAppendString(char*);
private:
void SecondaryLoop (G4String);
void ExecuteCommand (G4String);
void ShowCurrent (G4String);
void ChangeDirectoryCommand (G4String);
void ListDirectory (G4String);
G4VInteractorManager* interactorManager;
HWND mainWindow;
HWND textWindow,editWindow;
HMENU menuBar,defaultMenu;
RWTValHashDictionary<int,G4String> commands;
void* textBuffer;
int textRows,textCols;
static LRESULT CALLBACK MainWindowProc(HWND,UINT,WPARAM,LPARAM);
static LRESULT CALLBACK TextWindowProc(HWND,UINT,WPARAM,LPARAM);
};
#endif
#endif
@@ -0,0 +1,48 @@
// 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: G4UIXaw.hh,v 2.3 1998/09/19 14:45:24 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UIXaw_h
#define G4UIXaw_h
#if defined(G4UI_BUILD_XAW_SESSION) || defined(G4UI_USE_XAW)
#include <X11/Intrinsic.h>
#include "G4VBasicShell.hh"
class G4UIsession;
class G4UImanager;
class G4UIXaw : public G4VBasicShell
{
public:
G4UIXaw(int,char**);
~G4UIXaw();
G4UIsession* SessionStart ();
void Prompt (G4String);
void SessionTerminate ();
void PauseSessionStart (G4String);
void ApplyShellCommand (G4String);
Widget GetDialog ();
private:
void SecondaryLoop (G4String);
void ExecuteCommand (G4String);
void ShowCurrent (G4String);
void ChangeDirectoryCommand (G4String);
void ListDirectory (G4String);
private:
Widget shell,dialog;
};
#endif
#endif
+54
View File
@@ -0,0 +1,54 @@
// 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: G4UIXm.hh,v 2.5 1998/10/23 14:39:04 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UIXm_h
#define G4UIXm_h
#if defined(G4UI_BUILD_XM_SESSION) || defined(G4UI_USE_XM)
#include <rw/tvhdict.h>
#include <X11/Intrinsic.h>
#include "G4VBasicShell.hh"
#include "G4VInteractiveSession.hh"
class G4UIsession;
class G4UIXm : public G4VBasicShell, public G4VInteractiveSession {
public:
G4UIXm(int,char**);
~G4UIXm();
G4UIsession* SessionStart();
void Prompt(G4String);
void SessionTerminate();
void PauseSessionStart(G4String);
G4int ReceiveG4cout(G4String);
G4int ReceiveG4cerr(G4String);
void ApplyShellCommand(G4String);
void AddMenu(const char*,const char*);
void AddButton(const char*,const char*,const char*);
G4String GetCommand(Widget);
private:
void SecondaryLoop(G4String);
void ExecuteCommand(G4String);
void ShowCurrent(G4String);
void ChangeDirectoryCommand(G4String);
void ListDirectory(G4String);
private:
Widget shell,command,menuBar,text;
RWTValHashDictionary<Widget,G4String> commands;
};
#endif
#endif
@@ -0,0 +1,49 @@
// 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: G4UIterminal.hh,v 2.2 1998/07/12 03:00:10 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UIterminal_h
#define G4UIterminal_h 1
#include "G4VBasicShell.hh"
#include "G4UImanager.hh"
#include <fstream.h>
class G4UIterminal : public G4VBasicShell
{
public:
G4UIterminal();
~G4UIterminal();
G4UIsession * SessionStart();
void PauseSessionStart(G4String);
G4int ReceiveG4cout(G4String coutString);
G4int ReceiveG4cerr(G4String cerrString);
private:
G4UImanager * UI;
G4String promptCharacter;
G4bool iExit;
G4bool iCont;
private:
void ExecuteCommand(G4String);
G4String GetCommand();
void ChangeDirectoryCommand(G4String);
void ListDirectory(G4String);
void TerminalHelp(G4String);
void ShowCurrent(G4String);
};
#endif
+723
View File
@@ -0,0 +1,723 @@
// 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: G4UIWin32.cc,v 2.6 1998/10/23 14:39:11 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G.Barrand
//#define DEBUG
#ifdef G4UI_BUILD_WIN32_SESSION
#include <string.h>
#include <windows.h>
#include <windowsx.h>
#include <wingdi.h>
#include <Strstrea.h>
#include "G4UImanager.hh"
#include "G4StateManager.hh"
#include "G4UIcommandTree.hh"
#include "G4UIcommandStatus.hh"
#include "G4Win32.hh"
#include "G4UIWin32.hh"
#define TEXT_MAX_LINES 300
class TextBuffer {
public:
TextBuffer():linei(0),linen(TEXT_MAX_LINES),endOfPage(0),heightOfPage(12) {
lines = new G4String[linen];
}
~TextBuffer() {
delete [] lines;
}
int GetNumberOfLines () {
return linei;
}
void SetHeightOfPage (int a_height) {
heightOfPage = a_height;
}
void SetEndOfPage (int a_value) {
if( (a_value<0) || (a_value>=linei)) {
endOfPage = linei-1;
} else {
endOfPage = a_value;
}
}
int GetEndOfPage () {
return endOfPage;
}
void IncrementEndOfPage () {
endOfPage++;
if(endOfPage>=linei) endOfPage = linei-1;
}
void DecrementEndOfPage () {
endOfPage--;
if(endOfPage<0) endOfPage = 0;
}
void JumpDownEndOfPage () {
endOfPage += heightOfPage;
if(endOfPage>=linei) endOfPage = linei-1;
}
void JumpUpEndOfPage () {
endOfPage -= heightOfPage;
if(endOfPage<0) endOfPage = 0;
}
G4bool AppendString (char* a_string) {
G4bool value = false;
if( (a_string==NULL) || (a_string[0]=='\0') ) return value;
int length = strlen(a_string);
if(a_string[length-1]=='\n') {
lines[linei] += a_string;
lines[linei] = lines[linei].strip(G4String::trailing,'\n');
linei++;
value = true;
} else {
lines[linei] += a_string;
}
if(linei>=linen) {
for(int count=0;count<linen;count++) {
lines[count] = "";
}
linei = 0;
}
if(value==true) endOfPage = linei-1;
return value;
}
void Draw (HDC a_hdc,RECT* a_rect) {
TEXTMETRIC tm;
GetTextMetrics (a_hdc,&tm);
short charWidth = tm.tmAveCharWidth;
short charHeight = tm.tmHeight + tm.tmExternalLeading;
for(int row=0;row<heightOfPage;row++) {
int rowi = endOfPage - row;
short y = a_rect->bottom - charHeight * (row + 1);
if((rowi>=0)&&(rowi<linei)) {
const char* string = lines[rowi].data();
if(string!=NULL) {
TextOut (a_hdc,0,y,(char*)string,strlen((char*)string));
}
}
}
}
private:
G4String* lines;
int linen;
int linei;
int endOfPage,heightOfPage;
};
static char mainClassName[] = "G4UIWin32";
static char textClassName[] = "G4UIWin32/Text";
static G4bool exitSession = true;
static G4bool exitPause = true;
static G4UIsession* tmpSession = NULL;
static FARPROC oldEditWindowProc;
static LRESULT CALLBACK EditWindowProc(HWND,UINT,WPARAM,LPARAM);
static int actionIdentifier = 0;
static unsigned CommandsHashFun(const int& identifier) {
return (unsigned)identifier;
}
/***************************************************************************/
G4UIWin32::G4UIWin32 (
HANDLE a_hInstance
,HANDLE a_hPrevInstance
,LPSTR a_lpszCmdLine
,int a_nCmdShow
)
:mainWindow(NULL)
,textWindow(NULL)
,editWindow(NULL)
,menuBar(NULL)
,commands(CommandsHashFun)
,textBuffer(NULL)
,textCols(80)
,textRows(12)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI!=NULL) UI->SetSession(this);
interactorManager = G4Win32::getInstance (a_hInstance,a_hPrevInstance,
a_lpszCmdLine,a_nCmdShow);
static G4bool Done = FALSE;
if(Done==FALSE) {
if(a_hPrevInstance==NULL) {
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)G4UIWin32::MainWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = a_hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = mainClassName;
wc.lpszClassName = mainClassName;
::RegisterClass (&wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)G4UIWin32::TextWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = a_hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = textClassName;
wc.lpszClassName = textClassName;
::RegisterClass (&wc);
}
Done = TRUE;
}
/*
*/
menuBar = CreateMenu();
defaultMenu = CreatePopupMenu();
AppendMenu(menuBar,MF_POPUP,(UINT)defaultMenu,"Geant4");
textBuffer = new TextBuffer();
tmpSession = this;
mainWindow = ::CreateWindow(mainClassName,mainClassName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
0,0,
NULL,menuBar,a_hInstance,NULL);
tmpSession = NULL;
::SetWindowLong(mainWindow,GWL_USERDATA,LONG(this));
::SetForegroundWindow(mainWindow);
::ShowWindow(mainWindow,SW_SHOWDEFAULT);
::UpdateWindow(mainWindow);
if(UI!=NULL) UI->SetCoutDestination(this);
}
/***************************************************************************/
G4UIWin32::~G4UIWin32 (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI!=NULL) {
UI->SetSession(NULL);
UI->SetCoutDestination(NULL);
}
delete textBuffer;
::DestroyWindow(mainWindow);
}
/***************************************************************************/
G4UIsession* G4UIWin32::SessionStart (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(interactorManager==NULL) return this;
Prompt ("session");
exitSession = false;
interactorManager->DisableSecondaryLoop ();
void* event;
while((event = interactorManager->GetEvent())!=NULL) {
interactorManager->DispatchEvent(event);
if(exitSession==true) break;
}
interactorManager->EnableSecondaryLoop ();
return this;
}
/***************************************************************************/
void G4UIWin32::Prompt (
G4String a_prompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
}
/***************************************************************************/
void G4UIWin32::SessionTerminate (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
}
/***************************************************************************/
void G4UIWin32::PauseSessionStart (
G4String a_state
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_state=="G4_pause> ") {
SecondaryLoop ("Pause, type continue to exit this state");
}
if(a_state=="EndOfEvent") {
// Picking with feed back in event data Done here !!!
SecondaryLoop ("End of event, type continue to exit this state");
}
}
/***************************************************************************/
void G4UIWin32::SecondaryLoop (
G4String a_prompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(interactorManager==NULL) return;
Prompt (a_prompt);
exitPause = false;
void* event;
while((event = interactorManager->GetEvent())!=NULL) {
interactorManager->DispatchEvent(event);
if(exitPause==true) break;
}
Prompt ("session");
}
/***************************************************************************/
void G4UIWin32::ApplyShellCommand (
G4String a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
G4String command = a_string.strip(G4String::leading);
if( command(0) == '#' ) {
G4cout << command << endl;
} else if( command == "ls" || command(0,3) == "ls " ) {
ListDirectory( command );
} else if( command == "pwd" ) {
G4cout << "Current Working Directory : "
<< GetCurrentWorkingDirectory() << endl;
} else if( command(0,2) == "cd" ) {
ChangeDirectoryCommand ( command );
} else if( command(0,4) == "help" ) {
//TerminalHelp( command );
G4cout << "Not implemented." << endl;
} else if( command(0) == '?' ) {
ShowCurrent( command );
} else if( command(0,4) == "hist" ) {
G4int nh = UI->GetNumberOfHistory();
for(int i=0;i<nh;i++) {
G4cout << i << ": " << UI->GetPreviousCommand(i) << endl;
}
} else if( command(0) == '!' ) {
G4String ss = command(1,command.length()-1);
G4int vl;
const char* tt = ss;
istrstream is((char*)tt);
is >> vl;
G4int nh = UI->GetNumberOfHistory();
if(vl>=0 && vl<nh) {
G4String prev = UI->GetPreviousCommand(vl);
G4cout << prev << endl;
ExecuteCommand (ModifyToFullPathCommand(prev));
} else {
G4cerr << "history " << vl << " is not found." << endl;
}
} else if( command(0,4) == "exit" ) {
if( exitPause == false) { //In a secondary loop.
G4cout << "You are now processing RUN." << endl;
G4cout << "Please abort it using \"/run/abort\" command first" << endl;
G4cout << " and use \"continue\" command until the application" << endl;
G4cout << " becomes to Idle." << endl;
} else {
exitSession = true;
}
} else if( command(0,4) == "cont" ) {
exitPause = true;
} else {
ExecuteCommand (ModifyToFullPathCommand(a_string));
}
}
/***************************************************************************/
void G4UIWin32::ExecuteCommand (
G4String aCommand
)
/***************************************************************************/
// Should be put in G4VBasicShell.
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(aCommand.length()<2) return;
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
int commandStatus = UI->ApplyCommand(aCommand);
switch(commandStatus) {
case fCommandSucceeded:
break;
case fCommandNotFound:
G4cerr << "command not found" << endl;
break;
case fIllegalApplicationState:
G4cerr << "illegal application state -- command refused" << endl;
break;
case fParameterOutOfRange:
case fParameterUnreadable:
case fParameterOutOfCandidates:
default:
G4cerr << "command refused (" << commandStatus << ")" << endl;
}
}
/***************************************************************************/
G4int G4UIWin32::ReceiveG4cout (
G4String a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
TextAppendString((char*)a_string.data());
return 0;
}
/***************************************************************************/
G4int G4UIWin32::ReceiveG4cerr (
G4String a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
TextAppendString((char*)a_string.data());
return 0;
}
/***************************************************************************/
void G4UIWin32::ShowCurrent (
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
G4String comString = newCommand(1,newCommand.length()-1);
G4String theCommand = ModifyToFullPathCommand(comString);
G4String curV = UI->GetCurrentValues(theCommand);
if( ! curV.isNull() ) {
G4cout << "Current value(s) of the parameter(s) : " << curV << endl;
}
}
/***************************************************************************/
void G4UIWin32::ChangeDirectoryCommand (
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4String prefix;
if( newCommand.length() <= 3 ) {
prefix = "/";
} else {
G4String aNewPrefix = newCommand(3,newCommand.length()-3);
prefix = aNewPrefix.strip(G4String::both);
}
if(!ChangeDirectory(prefix)) {
G4cout << "directory <" << prefix << "> not found." << endl;
}
}
/***************************************************************************/
void G4UIWin32::ListDirectory(
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4String targetDir;
if( newCommand.length() <= 3 ) {
targetDir = "./";
} else {
G4String newPrefix = newCommand(3,newCommand.length()-3);
targetDir = newPrefix.strip(G4String::both);
}
G4UIcommandTree* commandTree = FindDirectory( targetDir );
if( commandTree == NULL ) {
G4cout << "Directory <" << targetDir << "> is not found." << endl;
} else {
commandTree->ListCurrent();
}
}
/***************************************************************************/
void G4UIWin32::AddMenu (
const char* a_name
,const char* a_label
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_name==NULL) return;
if(defaultMenu!=NULL) {
DeleteMenu (menuBar,0,MF_BYPOSITION);
defaultMenu = NULL;
}
HMENU hMenu = CreatePopupMenu();
AppendMenu(menuBar,MF_POPUP,(UINT)hMenu,a_label);
AddInteractor(a_name,(G4Interactor)hMenu);
DrawMenuBar(mainWindow);
}
/***************************************************************************/
void G4UIWin32::AddButton (
const char* a_menu
,const char* a_label
,const char* a_command
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_menu==NULL) return;
if(a_label==NULL) return;
if(a_command==NULL) return;
HMENU hMenu = (HMENU)GetInteractor(a_menu);
actionIdentifier++;
commands[actionIdentifier] = a_command;
AppendMenu (hMenu,MF_STRING,actionIdentifier,a_label);
}
/***************************************************************************/
G4String G4UIWin32::GetCommand (
int a_id
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return commands[a_id];
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
LRESULT CALLBACK G4UIWin32::MainWindowProc (
HWND a_window
,UINT a_message
,WPARAM a_wParam
,LPARAM a_lParam
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
static short charWidth,charHeight;
switch (a_message) {
case WM_CREATE:{
HDC hdc;
TEXTMETRIC tm;
RECT rect;
GetWindowRect (a_window,&rect);
hdc = GetDC (a_window);
GetTextMetrics (hdc,&tm);
charWidth = tm.tmAveCharWidth;
charHeight = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC (a_window,hdc);
G4UIWin32* This = (G4UIWin32*)tmpSession;
This->textWindow = CreateWindow (textClassName,NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL,
0,0,
This->textCols * charWidth,
This->textRows * charHeight,
a_window,NULL,
GetWindowInstance(a_window),
NULL);
::SetWindowLong (This->textWindow,GWL_USERDATA,LONG(This));
This->editWindow = CreateWindow ("edit",NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
0,This->textRows * charHeight,
This->textCols * charWidth,charHeight,
a_window,(HMENU)1,
GetWindowInstance(a_window),
NULL);
oldEditWindowProc = (FARPROC)GetWindowLong(This->editWindow,GWL_WNDPROC);
SetWindowLong (This->editWindow,GWL_WNDPROC,(LONG)EditWindowProc);
MoveWindow (a_window,
rect.left,rect.top,
2 * GetSystemMetrics(SM_CXFRAME) +
This->textCols * charWidth,
GetSystemMetrics(SM_CYCAPTION) +
2 * GetSystemMetrics(SM_CYFRAME) +
This->textRows * charHeight + charHeight,
TRUE);
}return 0;
case WM_SIZE:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
if(This!=NULL) {
// Client size :
int width = LOWORD(a_lParam);
int height = HIWORD(a_lParam);
int editHeight = /*2 * GetSystemMetrics(SM_CYBORDER) + */ charHeight;
MoveWindow (This->textWindow,
0,0,
width,height - editHeight,
FALSE);
MoveWindow (This->editWindow,
0,height - editHeight,
width,charHeight,
FALSE);
((TextBuffer*)This->textBuffer)->SetHeightOfPage(height/charHeight);
}
}return 0;
case WM_SETFOCUS:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
SetFocus (This->editWindow);
}return 0;
case WM_COMMAND:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
if(This!=NULL) {
G4String command = This->GetCommand(a_wParam);
This->ApplyShellCommand (command);
}
}return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return (DefWindowProc(a_window,a_message,a_wParam,a_lParam));
}
/***************************************************************************/
LRESULT CALLBACK G4UIWin32::TextWindowProc (
HWND a_window
,UINT a_message
,WPARAM a_wParam
,LPARAM a_lParam
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
switch (a_message) {
case WM_PAINT:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
if(This!=NULL) {
TextBuffer* textBuffer = (TextBuffer*)This->textBuffer;
RECT rect;
GetClientRect (a_window,&rect);
PAINTSTRUCT ps;
HDC hdc = BeginPaint(a_window,&ps);
textBuffer->Draw(hdc,&rect);
EndPaint(a_window,&ps);
}
}return 0;
case WM_VSCROLL:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
if(This!=NULL) {
TextBuffer* textBuffer = (TextBuffer*)This->textBuffer;
int what = LOWORD(a_wParam);
switch(what) {
case SB_LINEUP:
textBuffer->DecrementEndOfPage();
break;
case SB_LINEDOWN:
textBuffer->IncrementEndOfPage();
break;
case SB_PAGEUP:
textBuffer->JumpUpEndOfPage();
break;
case SB_PAGEDOWN:
textBuffer->JumpDownEndOfPage();
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
textBuffer->SetEndOfPage(HIWORD(a_wParam));
break;
default:
return 0;
}
int eop = textBuffer->GetEndOfPage();
SetScrollPos(a_window,SB_VERT,eop,TRUE);
InvalidateRect(a_window,NULL,TRUE);
}}return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return (DefWindowProc(a_window,a_message,a_wParam,a_lParam));
}
/***************************************************************************/
LRESULT CALLBACK EditWindowProc (
HWND a_window
,UINT a_message
,WPARAM a_wParam
,LPARAM a_lParam
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
switch (a_message) {
case WM_KEYDOWN:
switch(a_wParam){
case VK_RETURN:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(
GetParent(a_window),GWL_USERDATA);
char buffer[128];
GetWindowText (a_window,buffer,128);
G4String command (buffer);
SetWindowText (a_window,"");
This->ApplyShellCommand (command);
}break;
}
}
return CallWindowProc(oldEditWindowProc,
a_window,a_message,
a_wParam,a_lParam);
}
/***************************************************************************/
void G4UIWin32::TextAppendString (
char* a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if( (a_string==NULL) || (a_string[0]=='\0') ) return;
if(textWindow==NULL) return;
if(((TextBuffer*)textBuffer)->AppendString(a_string)==true) {
// The appending triggers and end of line, and then updates window :
RECT rect;
GetClientRect(textWindow,&rect);
InvalidateRect(textWindow,NULL,TRUE); //To erase background.
PAINTSTRUCT ps;
HDC hdc = GetDC(textWindow);
((TextBuffer*)textBuffer)->Draw(hdc,&rect);
ReleaseDC (textWindow,hdc);
int linen = ((TextBuffer*)textBuffer)->GetNumberOfLines();
SetScrollRange(textWindow,SB_VERT,0,linen-1,TRUE);
SetScrollPos(textWindow,SB_VERT,linen-1,TRUE);
}
}
#endif
+348
View File
@@ -0,0 +1,348 @@
// 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: G4UIXaw.cc,v 2.4 1998/09/19 14:45:28 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G.Barrand
//#define DEBUG
#ifdef G4UI_BUILD_XAW_SESSION
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <Xaw/Dialog.h>
#include <Xaw/Command.h>
#include "G4UIXaw.hh"
#include "G4UImanager.hh"
#include "G4StateManager.hh"
#include "G4UIcommandTree.hh"
#include "G4UIcommandStatus.hh"
#include "G4Xt.hh"
static void Callback (Widget,XtPointer,XtPointer);
static G4bool exitSession = true;
static G4bool exitPause = true;
/***************************************************************************/
G4UIXaw::G4UIXaw (
int argc
,char** argv
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI!=NULL) UI->SetSession(this);
G4Xt* interactorManager = G4Xt::getInstance (argc,argv,"Xaw");
Widget top = (Widget)interactorManager->GetMainInteractor();
shell = XtAppCreateShell ("G4UIXaw","G4UIXaw",topLevelShellWidgetClass,XtDisplay(top),NULL,0);
Arg args[2];
XtSetArg (args[0],XtNlabel,"G4 command");
XtSetArg (args[1],XtNvalue,""); // Needed to have a text Area.
dialog = XtCreateManagedWidget ("dialog",dialogWidgetClass,shell,args,2);
XawDialogAddButton (dialog,"Ok",Callback,(XtPointer)this);
XtRealizeWidget (shell);
}
/***************************************************************************/
G4UIXaw::~G4UIXaw (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
XtDestroyWidget (shell);
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI!=NULL) UI->SetSession(NULL);
}
/***************************************************************************/
G4UIsession* G4UIXaw::SessionStart (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4Xt* interactorManager = G4Xt::getInstance ();
Prompt ("session");
exitSession = false;
interactorManager->DisableSecondaryLoop ();
void* event;
while((event = interactorManager->GetEvent())!=NULL) {
interactorManager->DispatchEvent(event);
if(exitSession==true) break;
}
interactorManager->EnableSecondaryLoop ();
return this;
}
/***************************************************************************/
void G4UIXaw::Prompt (
G4String aPrompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
Arg args[1];
XtSetArg (args[0],XtNlabel,aPrompt.data());
XtSetValues (dialog,args,1);
}
/***************************************************************************/
void G4UIXaw::SessionTerminate (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
}
/***************************************************************************/
void G4UIXaw::PauseSessionStart (
G4String a_state
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_state=="G4_pause> ")
{
SecondaryLoop ("Pause, type continue to exit this state");
}
if(a_state=="EndOfEvent")
{
// Picking with feed back in event data Done here !!!
SecondaryLoop ("End of event, type continue to exit this state");
}
}
/***************************************************************************/
void G4UIXaw::SecondaryLoop (
G4String a_prompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4Xt* interactorManager = G4Xt::getInstance ();
Prompt (a_prompt);
exitPause = false;
void* event;
while((event = interactorManager->GetEvent())!=NULL) {
interactorManager->DispatchEvent(event);
if(exitPause==true) break;
}
Prompt ("session");
}
/***************************************************************************/
void G4UIXaw::ApplyShellCommand (
G4String a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
G4String command = a_string.strip(G4String::leading);
if( command(0) == '#' ) {
G4cout << command << endl;
} else if( command(0,2) == "ls" ) {
ListDirectory( command );
} else if( command == "pwd" ) {
G4cout << "Current Working Directory : "
<< GetCurrentWorkingDirectory() << endl;
} else if( command(0,2) == "cd" ) {
ChangeDirectoryCommand ( command );
} else if( command(0,4) == "help" ) {
//TerminalHelp( command );
G4cout << "Not implemented." << endl;
} else if( command(0) == '?' ) {
ShowCurrent( command );
} else if( command(0,4) == "hist" ) {
G4int nh = UI->GetNumberOfHistory();
for(int i=0;i<nh;i++) {
G4cout << i << ": " << UI->GetPreviousCommand(i) << endl;
}
} else if( command(0) == '!' ) {
G4String ss = command(1,command.length()-1);
G4int vl;
const char* tt = ss;
istrstream is((char*)tt);
is >> vl;
G4int nh = UI->GetNumberOfHistory();
if(vl>=0 && vl<nh) {
G4String prev = UI->GetPreviousCommand(vl);
G4cout << prev << endl;
ExecuteCommand (ModifyToFullPathCommand(prev));
} else {
G4cerr << "history " << vl << " is not found." << endl;
}
} else if( command(0,4) == "exit" ) {
if( exitPause == false) { //In a secondary loop.
G4cout << "You are now processing RUN." << endl;
G4cout << "Please abort it using \"/run/abort\" command first" << endl;
G4cout << " and use \"continue\" command until the application" << endl;
G4cout << " becomes to Idle." << endl;
} else {
exitSession = true;
}
} else if( command(0,4) == "cont" ) {
exitPause = true;
} else {
ExecuteCommand (ModifyToFullPathCommand(a_string));
}
}
/***************************************************************************/
void G4UIXaw::ExecuteCommand (
G4String aCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(aCommand.length()<2) return;
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
int commandStatus = UI->ApplyCommand(aCommand);
switch(commandStatus) {
case fCommandSucceeded:
break;
case fCommandNotFound:
G4cerr << "command not found" << endl;
break;
case fIllegalApplicationState:
G4cerr << "illegal application state -- command refused" << endl;
break;
case fParameterOutOfRange:
case fParameterUnreadable:
case fParameterOutOfCandidates:
default:
G4cerr << "command refused (" << commandStatus << ")" << endl;
}
}
/***************************************************************************/
void G4UIXaw::ShowCurrent (
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
G4String comString = newCommand(1,newCommand.length()-1);
G4String theCommand = ModifyToFullPathCommand(comString);
G4String curV = UI->GetCurrentValues(theCommand);
if( ! curV.isNull() ) {
G4cout << "Current value(s) of the parameter(s) : " << curV << endl;
}
}
/***************************************************************************/
void G4UIXaw::ChangeDirectoryCommand (
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4String prefix;
if( newCommand.length() <= 3 ) {
prefix = "/";
} else {
G4String aNewPrefix = newCommand(3,newCommand.length()-3);
prefix = aNewPrefix.strip(G4String::both);
}
if(!ChangeDirectory(prefix)) {
G4cout << "directory <" << prefix << "> not found." << endl;
}
}
/***************************************************************************/
void G4UIXaw::ListDirectory(
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4String targetDir;
if( newCommand.length() <= 3 ) {
targetDir = "./";
} else {
G4String newPrefix = newCommand(3,newCommand.length()-3);
targetDir = newPrefix.strip(G4String::both);
}
G4UIcommandTree* commandTree = FindDirectory( targetDir );
if( commandTree == NULL ) {
G4cout << "Directory <" << targetDir << "> is not found." << endl;
} else {
commandTree->ListCurrent();
}
}
/***************************************************************************/
Widget G4UIXaw::GetDialog (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return dialog;
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
static void Callback (
Widget a_widget
,XtPointer a_tag
,XtPointer a_data
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UIXaw* This = (G4UIXaw*)a_tag;
Widget dialog = This->GetDialog();
char* value = XawDialogGetValueString(dialog);
if(value==NULL) return;
G4String command (value);
This->ApplyShellCommand (command);
Arg args[1];
XtSetArg (args[0],XtNvalue,"");
XtSetValues (dialog,args,1);
a_widget = NULL;
a_data = NULL;
}
#endif
+550
View File
@@ -0,0 +1,550 @@
// 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: G4UIXm.cc,v 2.7 1998/10/23 14:39:13 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G.Barrand
//#define DEBUG
#ifdef G4UI_BUILD_XM_SESSION
#ifdef WIN32
#include <Strstrea.h>
#else
#include <strstream.h>
#endif
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <Xm/Xm.h>
#include <Xm/Command.h>
#include <Xm/RowColumn.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/CascadeB.h>
#include <Xm/Text.h>
#include "G4UIXm.hh"
#include "G4UImanager.hh"
#include "G4StateManager.hh"
#include "G4UIcommandTree.hh"
#include "G4UIcommandStatus.hh"
#include "G4Xt.hh"
static void XmTextAppendString (Widget,char*);
static void commandCallback (Widget,XtPointer,XtPointer);
static void buttonCallback (Widget,XtPointer,XtPointer);
static void clearButtonCallback (Widget,XtPointer,XtPointer);
static char* XmConvertCompoundStringToString (XmString,int);
static G4bool exitSession = true;
static G4bool exitPause = true;
static unsigned CommandsHashFun (const Widget& interactor) {
// Is it correct to return a pointer ?
return (unsigned)(unsigned long)interactor;
}
/***************************************************************************/
G4UIXm::G4UIXm (
int argc
,char** argv
)
:shell(NULL)
,command(NULL)
,menuBar(NULL)
,text(NULL)
,commands(CommandsHashFun)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI!=NULL) UI->SetSession(this);
G4Xt* interactorManager = G4Xt::getInstance (argc,argv,"Xm");
Widget top = (Widget)interactorManager->GetMainInteractor();
shell = XtAppCreateShell ("G4UIXm","G4UIXm",
topLevelShellWidgetClass,XtDisplay(top),
NULL,0);
Widget form = XmCreateForm (shell,"form",NULL,0);
XtManageChild (form);
Arg args[9];
XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
menuBar = XmCreateMenuBar (form,"menuBar",args,3);
XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE);
XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
XtSetArg(args[3],XmNbottomAttachment,XmATTACH_FORM);
command = XmCreateCommand (form,"command",args,4);
XtManageChild (command);
XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE);
XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
XtSetArg(args[4],XmNbottomWidget ,command);
XmString cps = XmStringLtoRCreate("Clear",XmSTRING_DEFAULT_CHARSET);
XtSetArg (args[5],XmNlabelString,cps);
Widget clearButton = XmCreatePushButton(form,"clearButton",args,6);
XmStringFree (cps);
XtManageChild (clearButton);
XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
XtSetArg(args[1],XmNtopWidget ,menuBar);
XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
XtSetArg(args[4],XmNbottomAttachment,XmATTACH_WIDGET);
XtSetArg(args[5],XmNbottomWidget ,clearButton);
XtSetArg(args[6],XmNeditMode ,XmMULTI_LINE_EDIT);
XtSetArg(args[7],XmNrows ,12);
XtSetArg(args[8],XmNcolumns ,80);
text = XmCreateScrolledText (form,"text",args,9);
XtManageChild (text);
XtAddCallback(clearButton,XmNactivateCallback,
clearButtonCallback,(XtPointer)text);
XtAddCallback(command,XmNcommandEnteredCallback,
commandCallback,(XtPointer)this);
XtRealizeWidget(shell);
XtMapWidget(shell);
if(UI!=NULL) UI->SetCoutDestination(this);
}
/***************************************************************************/
G4UIXm::~G4UIXm(
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI!=NULL) {
UI->SetSession(NULL);
UI->SetCoutDestination(NULL);
}
XtDestroyWidget(shell);
}
/***************************************************************************/
G4UIsession* G4UIXm::SessionStart (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4Xt* interactorManager = G4Xt::getInstance ();
Prompt("session");
exitSession = false;
interactorManager->DisableSecondaryLoop ();
void* event;
while((event = interactorManager->GetEvent())!=NULL) {
interactorManager->DispatchEvent(event);
if(exitSession==true) break;
}
interactorManager->EnableSecondaryLoop ();
return this;
}
/***************************************************************************/
void G4UIXm::Prompt (
G4String aPrompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
Arg args[1];
char* str = (char*)XtNewString(aPrompt.data());
XmString cps = XmStringLtoRCreate(str,XmSTRING_DEFAULT_CHARSET);
XtFree(str);
XtSetArg(args[0],XmNpromptString,cps);
XtSetValues(command,args,1);
XmStringFree(cps);
}
/***************************************************************************/
void G4UIXm::SessionTerminate (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
}
/***************************************************************************/
void G4UIXm::PauseSessionStart (
G4String a_state
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_state=="G4_pause> ") {
SecondaryLoop ("Pause, type continue to exit this state");
}
if(a_state=="EndOfEvent") {
// Picking with feed back in event data Done here !!!
SecondaryLoop ("End of event, type continue to exit this state");
}
}
/***************************************************************************/
void G4UIXm::SecondaryLoop (
G4String a_prompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4Xt* interactorManager = G4Xt::getInstance ();
Prompt(a_prompt);
exitPause = false;
void* event;
while((event = interactorManager->GetEvent())!=NULL) {
interactorManager->DispatchEvent(event);
if(exitPause==true) break;
}
Prompt("session");
}
/***************************************************************************/
void G4UIXm::ApplyShellCommand (
G4String a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
G4String command = a_string.strip(G4String::leading);
if( command(0) == '#' ) {
G4cout << command << endl;
} else if( command == "ls" || command(0,3) == "ls " ) {
ListDirectory( command );
} else if( command == "pwd" ) {
G4cout << "Current Working Directory : "
<< GetCurrentWorkingDirectory() << endl;
} else if( command(0,2) == "cd" ) {
ChangeDirectoryCommand ( command );
} else if( command(0,4) == "help" ) {
//TerminalHelp( command );
G4cout << "Not implemented." << endl;
} else if( command(0) == '?' ) {
ShowCurrent( command );
} else if( command(0,4) == "hist" ) {
G4int nh = UI->GetNumberOfHistory();
for(int i=0;i<nh;i++) {
G4cout << i << ": " << UI->GetPreviousCommand(i) << endl;
}
} else if( command(0) == '!' ) {
G4String ss = command(1,command.length()-1);
G4int vl;
const char* tt = ss;
istrstream is((char*)tt);
is >> vl;
G4int nh = UI->GetNumberOfHistory();
if(vl>=0 && vl<nh) {
G4String prev = UI->GetPreviousCommand(vl);
G4cout << prev << endl;
ExecuteCommand (ModifyToFullPathCommand(prev));
} else {
G4cerr << "history " << vl << " is not found." << endl;
}
} else if( command(0,4) == "exit" ) {
if( exitPause == false) { //In a secondary loop.
G4cout << "You are now processing RUN." << endl;
G4cout << "Please abort it using \"/run/abort\" command first" << endl;
G4cout << " and use \"continue\" command until the application" << endl;
G4cout << " becomes to Idle." << endl;
} else {
exitSession = true;
}
} else if( command(0,4) == "cont" ) {
exitPause = true;
} else {
ExecuteCommand (ModifyToFullPathCommand(a_string));
}
}
/***************************************************************************/
void G4UIXm::ExecuteCommand (
G4String aCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(aCommand.length()<2) return;
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
int commandStatus = UI->ApplyCommand(aCommand);
switch(commandStatus) {
case fCommandSucceeded:
break;
case fCommandNotFound:
G4cerr << "command not found" << endl;
break;
case fIllegalApplicationState:
G4cerr << "illegal application state -- command refused" << endl;
break;
case fParameterOutOfRange:
case fParameterUnreadable:
case fParameterOutOfCandidates:
default:
G4cerr << "command refused (" << commandStatus << ")" << endl;
}
}
/***************************************************************************/
G4int G4UIXm::ReceiveG4cout (
G4String a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
XmTextAppendString(text,(char*)a_string.data());
return 0;
}
/***************************************************************************/
G4int G4UIXm::ReceiveG4cerr (
G4String a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
XmTextAppendString(text,(char*)a_string.data());
return 0;
}
/***************************************************************************/
void G4UIXm::ShowCurrent (
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL) return;
G4String comString = newCommand(1,newCommand.length()-1);
G4String theCommand = ModifyToFullPathCommand(comString);
G4String curV = UI->GetCurrentValues(theCommand);
if( ! curV.isNull() ) {
G4cout << "Current value(s) of the parameter(s) : " << curV << endl;
}
}
/***************************************************************************/
void G4UIXm::ChangeDirectoryCommand (
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4String prefix;
if( newCommand.length() <= 3 ) {
prefix = "/";
} else {
G4String aNewPrefix = newCommand(3,newCommand.length()-3);
prefix = aNewPrefix.strip(G4String::both);
}
if(!ChangeDirectory(prefix)) {
G4cout << "directory <" << prefix << "> not found." << endl;
}
}
/***************************************************************************/
void G4UIXm::ListDirectory(
G4String newCommand
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4String targetDir;
if( newCommand.length() <= 3 ) {
targetDir = "./";
} else {
G4String newPrefix = newCommand(3,newCommand.length()-3);
targetDir = newPrefix.strip(G4String::both);
}
G4UIcommandTree* commandTree = FindDirectory( targetDir );
if( commandTree == NULL ) {
G4cout << "Directory <" << targetDir << "> is not found." << endl;
} else {
commandTree->ListCurrent();
}
}
/***************************************************************************/
void G4UIXm::AddMenu (
const char* a_name
,const char* a_label
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(menuBar==NULL) return;
if(a_name==NULL) return;
if(a_label==NULL) return;
XtManageChild (menuBar);
// Pulldown menu :
Widget widget;
widget = XmCreatePulldownMenu (menuBar,(char*)a_name,NULL,0);
AddInteractor (a_name,(G4Interactor)widget);
// Cascade button :
Arg args[2];
XmString cps = XmStringLtoRCreate((char*)a_label,XmSTRING_DEFAULT_CHARSET);
XtSetArg (args[0],XmNlabelString,cps);
XtSetArg (args[1],XmNsubMenuId,widget);
widget = XmCreateCascadeButton (menuBar,(char*)a_name,args,2);
XmStringFree (cps);
XtManageChild (widget);
}
/***************************************************************************/
void G4UIXm::AddButton (
const char* a_menu
,const char* a_label
,const char* a_command
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_menu==NULL) return;
if(a_label==NULL) return;
if(a_command==NULL) return;
Widget parent = (Widget)GetInteractor(a_menu);
if(parent==NULL) return;
Widget widget = XmCreatePushButton(parent,(char*)a_label,NULL,0);
XtManageChild (widget);
XtAddCallback (widget,XmNactivateCallback,buttonCallback,(XtPointer)this);
commands[widget] = a_command;
}
/***************************************************************************/
G4String G4UIXm::GetCommand (
Widget a_widget
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
return commands[a_widget];
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
void commandCallback (
Widget a_widget
,XtPointer a_tag
,XtPointer a_data
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UIXm* This = (G4UIXm*)a_tag;
XmString cps = ((XmCommandCallbackStruct*)a_data)->value;
char* ss = XmConvertCompoundStringToString(cps,0);
G4String command (ss);
XtFree (ss);
This->ApplyShellCommand (command);
a_widget = NULL;
a_tag = NULL;
}
/***************************************************************************/
void clearButtonCallback (
Widget a_widget
,XtPointer a_tag
,XtPointer
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
XmTextSetString((Widget)a_tag,"");
}
/***************************************************************************/
void buttonCallback (
Widget a_widget
,XtPointer a_tag
,XtPointer
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
G4UIXm* This = (G4UIXm*)a_tag;
G4String ss = This->GetCommand (a_widget);
//printf ("debug : execute:\n%s\n",ss.data());
This->ApplyShellCommand (ss);
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
char* XmConvertCompoundStringToString (
XmString a_cps
,int a_number
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(a_cps==NULL) return NULL;
char* ss = NULL;
XmStringContext context;
XmStringInitContext(&context,a_cps);
int icount = 0;
Boolean Done = False;
while(Done==False) {
char* text = NULL;
XmStringCharSet charset = NULL;
XmStringDirection direct;
Boolean sep;
if(XmStringGetNextSegment(context,&text,&charset,&direct,&sep)==True) {
XtFree(charset);
if(sep==True) Done = True;
if(icount==a_number) {
ss = text;
break;
}
icount++;
XtFree(text);
}
else
Done = True;
}
XmStringFreeContext(context);
return ss;
}
/***************************************************************************/
void XmTextAppendString (
Widget This
,char* a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
if(This==NULL) return;
if(!XtIsSubclass(This,xmTextWidgetClass)) return;
if(a_string==NULL) return;
XmTextPosition lastpos = XmTextGetLastPosition(This);
XmTextReplace(This,lastpos,lastpos,a_string);
XmTextSetInsertionPosition(This,XmTextGetLastPosition(This));
}
#endif
+316
View File
@@ -0,0 +1,316 @@
// 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: G4UIterminal.cc,v 2.9 1998/12/09 07:55:43 yhajime Exp $
// GEANT4 tag $Name: geant4-00 $
//
#include "G4UIterminal.hh"
#include "G4StateManager.hh"
#include "G4UIcommandTree.hh"
#include "G4UIcommand.hh"
#include "G4UIcommandStatus.hh"
#include "G4ios.hh"
#ifdef WIN32
# include <Strstrea.h>
#else
# include <strstream.h>
#endif
G4UIterminal::G4UIterminal()
{
UI = G4UImanager::GetUIpointer();
UI->SetSession(this);
UI->SetCoutDestination(this);
G4StateManager * statM = G4StateManager::GetStateManager();
promptCharacter = statM->GetStateString(statM->GetCurrentState())
+ G4String("> ");
iExit = false;
iCont = false;
}
G4UIterminal::~G4UIterminal()
{
if( G4UImanager::GetUIpointer() != 0)
{
UI->SetSession(NULL);
UI->SetCoutDestination(NULL);
// G4cout << "Terminal session deleted" << endl;
}
}
G4UIsession * G4UIterminal::SessionStart()
{
iExit = true;
G4StateManager * statM = G4StateManager::GetStateManager();
promptCharacter = statM->GetStateString(statM->GetCurrentState())
+ G4String("> ");
G4String newCommand = GetCommand();
while( iExit )
{
ExecuteCommand(newCommand);
promptCharacter = statM->GetStateString(statM->GetCurrentState())
+ G4String("> ");
newCommand = GetCommand();
}
return NULL;
}
void G4UIterminal::PauseSessionStart(G4String msg)
{
promptCharacter = msg;
iCont = true;
G4String newCommand = GetCommand();
while( iCont )
{
ExecuteCommand(newCommand);
newCommand = GetCommand();
}
}
G4int G4UIterminal::ReceiveG4cout(G4String coutString)
{
cout << coutString << flush;
return 0;
}
G4int G4UIterminal::ReceiveG4cerr(G4String cerrString)
{
cerr << cerrString << flush;
return 0;
}
void G4UIterminal::ExecuteCommand(G4String aCommand)
{
if(aCommand.length()<2) return;
int commandStatus = UI->ApplyCommand(aCommand);
switch(commandStatus)
{
case fCommandSucceeded:
break;
case fCommandNotFound:
G4cerr << "command <" << aCommand << "> not found" << endl;
if ( aCommand.index("@@") != RW_NPOS) {
G4cout << "@@G4UIterminal" << endl;
}
break;
case fIllegalApplicationState:
G4cerr << "illegal application state -- command refused" << endl;
break;
case fParameterOutOfRange:
case fParameterUnreadable:
case fParameterOutOfCandidates:
default:
G4cerr << "command refused (" << commandStatus << ")" << endl;
}
}
G4String G4UIterminal::GetCommand()
{
G4String newCommand;
G4String nullString;
while( 1 )
{
G4cout << promptCharacter;
G4cout.flush();
newCommand.readLine( cin );
if (!cin.good()) { cin.clear(); newCommand = nullString; iExit=false; break; }
while( newCommand(newCommand.length()-1) == '_' )
{
G4String newLine;
newCommand.remove(newCommand.length()-1);
newLine.readLine( cin );
if (!cin.good()) { cin.clear(); newCommand = nullString; iExit=false; break; }
newCommand.append(newLine);
}
G4String nC = newCommand.strip(G4String::leading);
// -------------------- nC.toUpper();
if( nC(0) == '#' )
{ G4cout << nC << endl; }
else if( nC == "ls" || nC(0,3) == "ls " )
{ ListDirectory( nC ); }
else if( nC == "pwd" )
{
G4cout << "Current Working Directory : "
<< GetCurrentWorkingDirectory() << endl;
}
else if( nC == "cd" || nC(0,3) == "cd " )
{ ChangeDirectoryCommand( nC ); }
else if( nC == "help" || nC(0,5) == "help " )
{ TerminalHelp( nC ); }
else if( nC(0) == '?' )
{ ShowCurrent( nC ); }
else if( nC == "hist" || nC == "history" )
{
G4int nh = UI->GetNumberOfHistory();
for(int i=0;i<nh;i++)
{ G4cout << i << ": " << UI->GetPreviousCommand(i) << endl; }
}
else if( nC(0) == '!' )
{
G4String ss = nC(1,nC.length()-1);
G4int vl;
const char* tt = ss;
istrstream is((char*)tt);
is >> vl;
G4int nh = UI->GetNumberOfHistory();
if(vl>=0 && vl<nh)
{
newCommand = UI->GetPreviousCommand(vl);
G4cout << newCommand << endl;
break;
}
else
{ G4cerr << "history " << vl << " is not found." << endl; }
}
else if( nC == "exit" )
{
if( iCont )
{
G4cout << "You are now processing RUN." << endl;
G4cout << "Please abort it using \"/run/abort\" command first" << endl;
G4cout << " and use \"continue\" command until the application" << endl;
G4cout << " becomes to Idle." << endl;
}
else
{
iExit = false;
newCommand = nullString;
break;
}
}
else if( nC == "cont" || nC == "continue" )
{
iCont = false;
newCommand = nullString;
break;
}
else
{ break; }
}
return ModifyToFullPathCommand(newCommand);
}
void G4UIterminal::ShowCurrent( G4String newCommand )
{
G4String comString = newCommand(1,newCommand.length()-1);
G4String theCommand = ModifyToFullPathCommand(comString);
G4String curV = UI->GetCurrentValues(theCommand);
if( ! curV.isNull() )
{ G4cout << "Current value(s) of the parameter(s) : " << curV << endl; }
}
void G4UIterminal::ChangeDirectoryCommand( G4String newCommand )
{
G4String prefix;
if( newCommand.length() <= 3 )
{ prefix = "/"; }
else
{
G4String aNewPrefix = newCommand(3,newCommand.length()-3);
prefix = aNewPrefix.strip(G4String::both);
}
if(!ChangeDirectory(prefix))
{ G4cout << "directory <" << prefix << "> not found." << endl; }
}
void G4UIterminal::ListDirectory( G4String newCommand )
{
G4String targetDir;
if( newCommand.length() <= 3 )
{ targetDir = GetCurrentWorkingDirectory(); }
else
{
G4String newPrefix = newCommand(3,newCommand.length()-3);
targetDir = newPrefix.strip(G4String::both);
}
G4UIcommandTree* commandTree
= FindDirectory(ModifyToFullPathCommand(targetDir));
if( commandTree == NULL )
{ G4cout << "Directory <" << targetDir << "> is not found." << endl; }
else
{ commandTree->ListCurrent(); }
}
void G4UIterminal::TerminalHelp(G4String newCommand)
{
G4UIcommandTree * treeTop = UI->GetTree();
int i = newCommand.index(" ");
if( i != RW_NPOS )
{
G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
newValue.strip(G4String::both);
G4String targetCom = ModifyToFullPathCommand( newValue );
G4UIcommand* theCommand = treeTop->FindPath( targetCom );
if( theCommand != NULL )
{
theCommand->List();
return;
}
else
{
G4cout << "Command <" << newValue << " is not found." << endl;
return;
}
}
G4UIcommandTree * floor[10];
floor[0] = treeTop;
int iFloor = 0;
int prefixIndex = 1;
G4String prefix = GetCurrentWorkingDirectory();
while( prefixIndex < prefix.length()-1 )
{
int ii = prefix.index("/",prefixIndex);
floor[iFloor+1] =
floor[iFloor]->GetTree(prefix(0,ii+1));
prefixIndex = ii+1;
iFloor++;
}
floor[iFloor]->ListCurrentWithNum();
// 1998 Oct 2 non-number input
while(1){
G4cout << endl << "Type the number ( 0:end, -n:n level back ) : "<<flush;
cin >> i;
if(!cin.good()){
cin.clear();
cin.ignore(30,'\n');
G4cout << endl << "Not a number, once more" << endl; continue;}
else if( i < 0 ){
iFloor += i;
if( iFloor < 0 ) iFloor = 0;
floor[iFloor]->ListCurrentWithNum(); continue;}
else if(i == 0) { break;}
else if( i > 0 ) {
int n_tree = floor[iFloor]->GetTreeEntry();
if( i > n_tree )
{
if( i <= n_tree + floor[iFloor]->GetCommandEntry() )
{
floor[iFloor]->GetCommand(i-n_tree)->List();
//iFloor++;
}
}
else
{
floor[iFloor+1] = floor[iFloor]->GetTree(i);
iFloor++;
floor[iFloor]->ListCurrentWithNum();
}
}
//G4cout << endl << "Type the number ( 0:end, -n:n level back ) : ";
}
G4cout << "Exit from HELP." << endl << endl;
G4cout << endl;
// cin.flush();
char temp[100];
cin.getline( temp, 100 );
}