header file: #ifndef __G4RunText__ #define __G4RunText__ #include #include #include #include #include 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();} virtual void CloseWindow(); 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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(); // Not needed ! } G4RunText::~G4RunText() { //gVirtualX->UnmapWindow(GetId()); // Not needed ! //gSystem->ProcessEvents(); // Not needed ! 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(); // Not needed ! gApplication->Terminate(); } void G4RunText::CloseWindow() { delete this; gApplication->Terminate(0); } 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"<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)