Hi,
I want to run to use both Geant4 and root to make a gui. So i install G4UIRoot made by I. Gonzales. I add my own class which is a TransientFrame with a few buttons : Execute, Clear, Exit. Exit button is connect to function SendClose Message(). When I click on Exit it crashes and i have the following error message :
Error in : BadWindow (invalid Window parameter) (XID : 56623637, XREQ : 61).
I don’t understand it.
Here is the code for the class i add.
header file:
#ifndef G4RunText
#define G4RunText
#include <TGTextEntry.h>
#include <TGFrame.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TApplication.h>
class TGTextEntry;
class TGButton;
class TGTextView;
class TGLabel;
class TGMenuBar;
class TGPopupMenu;
class TGCanvas;
class TGListTree;
class TApplication;
class G4UImanager;
class G4RunText : public TGTransientFrame {
public:
G4RunText(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options = kVerticalFrame);
virtual ~G4RunText();
void ExecuteRun();
void ExitRun();
void ClearInputTextLine() {fInputTextEntry->Clear();}
TGCompositeFrame* BuildRunButtonFrame(const TGWindow* p);
TGCompositeFrame* BuildRunInputLine(const TGWindow* w);
private:
TGLayoutHints* fLRunButtonFrame;
TGLayoutHints* fButtonsr;
TGLayoutHints* fLRunInputEntry;
TGLayoutHints* Linputline;
TGLayoutHints* fLInputRunLabel;
TGTextEntry* fInputTextEntry;
TGCompositeFrame* fRunButtonFrame;
TGCompositeFrame* fRunInputFrame;
TGTextButton* fExecuteRunButton;
TGTextButton* fExitRunButton;
TGTextButton* fClearRunButton;
TGLabel* fInputRunLabel;
G4UImanager* UI;
ClassDef(G4RunText,0)
};
#endif
source file :
#include “G4RunText.hh”
#include “G4RootMainFrame.hh”
#include “G4String.hh”
#include “G4UIcommand.hh”
#include “G4UIcommandTree.hh”
#include “G4UImanager.hh”
#include “G4UIcommand.hh”
#include “G4UIcommandStatus.hh”
#include “globals.hh”
#include <stdlib.h>
#include
#include
#include <TGClient.h>
#include <TRootHelpDialog.h>
#include <TGLabel.h>
#include <TGMenu.h>
#include <TGButton.h>
#include <TGTextView.h>
#include <TGCanvas.h>
#include <TGListTree.h>
#include <TGFileDialog.h>
#include <TGSplitter.h>
#include <TSystem.h>
#include <TVirtualX.h>
#include <TApplication.h>
#include <TBuffer.h>
using namespace std;
enum AliRunMessageTypes {
kM_EXECUTE_RUN,
kM_EXIT_RUN,
kM_CLEAR_RUN
};
G4RunText::G4RunText(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options) : TGTransientFrame(p, main, w, h, options)
{
fLRunInputEntry = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsTop, 10, 10, 10, 10);
fRunInputFrame = BuildRunInputLine(this);
AddFrame(fRunInputFrame, fLRunInputEntry);
fLRunButtonFrame = new TGLayoutHints(kLHintsCenterX | kLHintsBottom,
0, 0, 0, 0);
fRunButtonFrame = BuildRunButtonFrame(this);
AddFrame(fRunButtonFrame, fLRunButtonFrame);
MapSubwindows();
SetWindowName(“choix du nombre d’evenements”);
Layout();
//Resize(GetDefaultSize());
MapWindow();
gSystem->ProcessEvents();
}
G4RunText::~G4RunText()
{
gVirtualX->UnmapWindow(GetId());
gSystem->ProcessEvents();
if (fExecuteRunButton)
delete fExecuteRunButton;
if (fExitRunButton)
delete fExitRunButton;
if (fClearRunButton)
delete fClearRunButton;
if (fLRunInputEntry)
delete fLRunInputEntry;
if (fButtonsr)
delete fButtonsr;
if (Linputline)
delete Linputline;
if(fRunButtonFrame)
delete fRunButtonFrame;
if (fRunInputFrame)
delete fRunInputFrame;
if (fInputTextEntry)
delete fInputTextEntry;
gSystem->ProcessEvents();
}
void G4RunText::ExecuteRun()
{
UI = G4UImanager::GetUIpointer();
G4String aCommand = "/run/beamOn ";
UI->ApplyCommand(aCommand+fInputTextEntry->GetText());
}
void G4RunText::ExitRun()
{
cout<<“vous devez fermer la fenetre avec la croix ou bien cliquer au prealable sur le bouton Execute”<<endl;
//gApplication->Terminate(0);
//delete this;
}
TGCompositeFrame* G4RunText::BuildRunButtonFrame(const TGWindow* p)
{
TGCompositeFrame *buttonr = new TGCompositeFrame(p, 100, 100, kHorizontalFrame);
fButtonsr = new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2);
fExecuteRunButton = new TGTextButton(buttonr, “&Execute”, kM_EXECUTE_RUN);
fExecuteRunButton->Associate(this);
fExecuteRunButton->SetToolTipText(“Execute Events”);
fExecuteRunButton->Connect(“Clicked()”, “G4RunText”, this, “ExecuteRun()”);
buttonr->AddFrame(fExecuteRunButton, fButtonsr);
fClearRunButton = new TGTextButton(buttonr, “&Clear”, kM_CLEAR_RUN);
fClearRunButton->Associate(this);
fClearRunButton->SetToolTipText(“Clear Text Entry Line”);
fClearRunButton->Connect(“Clicked()”, “G4RunText”, this, “ClearInputTextLine()”);
buttonr->AddFrame(fClearRunButton, fButtonsr);
fExitRunButton = new TGTextButton(buttonr, “&Exit”, kM_EXIT_RUN);
fExitRunButton->Associate(this);
fExitRunButton->SetToolTipText(“Close Run Window”);
buttonr->AddFrame(fExitRunButton, fButtonsr);
//fExitRunButton->Connect(“Clicked()”, “G4RunText”, this, “ExitRun()”);
fExitRunButton->Connect(“Clicked()”, “G4RunText”, this, “SendCloseMessage()”);
return buttonr;
}
TGCompositeFrame* G4RunText::BuildRunInputLine(const TGWindow* w) {
TGCompositeFrame *inputline = new TGCompositeFrame(w, 100, 100, kVerticalFrame);
Linputline = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsBottom | kLHintsTop, 2, 2, 2, 2);
fInputTextEntry = new TGTextEntry(inputline, new TGTextBuffer(20));
inputline->AddFrame(fInputTextEntry, Linputline);
fInputRunLabel = new TGLabel(inputline, “Rentrez le nombre d’evenements que vous voulez simuler”);
fLInputRunLabel = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsBottom | kLHintsTop, 2, 2, 2, 2);
inputline->AddFrame(fInputRunLabel,fLInputRunLabel);
return inputline;
}
ClassImpQ(G4RunText)
Thanks,
Fabien