// myFrame.cpp #include "myFrame.h" // #include "ex3LinkDef.h" #include "TTimer.h" #include "TStopWatch.h" #include //using namespace std; TTimer* timer_fast = 0; //!< external request reaction counter MyMainFrame::MyMainFrame(const TGWindow* p, UInt_t w, UInt_t h, MyTop *parParent) { TGMainFrame(p, w, h); fParent = parParent; // Creates widgets of the example fEcanvas = new TRootEmbeddedCanvas("Ecanvas", this, 200, 200); AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 1)); TGHorizontalFrame* hframe = new TGHorizontalFrame(this, 200, 40); TGTextButton* draw = new TGTextButton(hframe, "&Draw"); draw->Connect("Clicked()", "MyMainFrame", this, "DoDraw()"); hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); TGTextButton* start = new TGTextButton(hframe, "&Start"); start->Connect("Clicked()", "MyMainFrame", this, "SendRequest(=1)"); hframe->AddFrame(start, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); TGTextButton* stop = new TGTextButton(hframe, "&Stop"); stop->Connect("Clicked()", "MyMainFrame", this, "SendRequest(=2)"); hframe->AddFrame(stop, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); TGTextButton* clear = new TGTextButton(hframe, "&Clear"); clear->Connect("Clicked()", "MyMainFrame", this, "SendRequest(=3)"); hframe->AddFrame(clear, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); // TGTextButton* exit = new TGTextButton(hframe, "&Exit ","gApplication->Terminate()"); TGTextButton* exit = new TGTextButton(hframe, "&Exit "); exit->Connect("Clicked()", "MyMainFrame", this, "doClose()"); hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2)); // Sets window name and shows the main frame SetWindowName("Simple Example"); MapSubwindows(); Resize(GetDefaultSize()); MapWindow(); } void MyMainFrame::DoDraw() { // Draws function graphics in randomly chosen interval TF1* f1 = new TF1("f1", "sin(x)/x", 0, gRandom->Rndm() * 10); f1->SetFillColor(19); f1->SetFillStyle(1); f1->SetLineWidth(3); f1->Draw(); TCanvas* fCanvas = fEcanvas->GetCanvas(); fCanvas->cd(); fCanvas->Update(); } MyMainFrame::~MyMainFrame() { // Clean up used widgets: frames, buttons, layouthints } void MyMainFrame::doClose() { std::cout << "-I- MyMainFrame::doClose" << std::endl; fParent->SpecSignal(); gApplication->Terminate(0); } //void MyMainFrame::SetParent( MyTop *par_parent) //{ // fParent= par_parent; //} __declspec(dllexport) void MyMainFrame::SendRequest(int parRequest) { std::cout << "-I- MyMainFrame::SendRequest " << parRequest << std::endl; fParent->SetRequest(parRequest); } MyTop::MyTop(const TGWindow* p, UInt_t height, UInt_t width) { std::cout << "-I- MyTop::MyTop" << std::endl; fMain = new MyMainFrame(p, width, height, this) ; fMain->SetParent(this); Init(); } MyTop::~MyTop() { delete fMain; } void MyTop::Init() { fTime_value=0; fSteps_value=1; fRequest = 0; if (timer_fast) { timer_fast->TurnOff(); TQObject::Disconnect(timer_fast); } else timer_fast = new TTimer(200); timer_fast->Connect("Timeout()", "MyTop", this, "FastReaction()"); timer_fast->Start(); HANDLE fMutex = CreateMutex(NULL, TRUE, (LPCSTR)"MyTopMutex"); } void MyTop::FastReaction() { // std::cout << "-I- MyTop::FastReaction " << fRequest << std::endl; if (fRequest) { try { switch (fRequest) { case ES_SimpleStart: fRequest = 0; SimpleStart(); break; case ES_SimpleStop: fRequest = 0; SimpleStop(); break; case ES_Clear: fRequest = 0; Clear(); break; default: // std::cout << "-I- MyTop::FastReaction default " << fRequest << std::endl; break; } } catch (...) { std::cout << "-E- MyTop::FastReaction Exception" << std::endl; } } } void MyTop::SpecSignal() { std::cout << "-I- MyTop::SpecSignal" << std::endl; } void MyTop::SimpleStart() { std::cout << "-I- MyTop::SimpleStart" << std::endl; } void MyTop::SimpleStop() { std::cout << "-I- MyTop::SimpleStop" << std::endl; } void MyTop::Clear() { std::cout << "-I- MyTop::Clear" << std::endl; } //void MyTop::SetRequest(int parRequest) //{ // fRequest = parRequest; //}