Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:55

0001 #include <iostream>
0002 using namespace std;
0003 
0004 #include "MEPlotWindow.hh"
0005 
0006 #include "MusEcalGUI.hh"
0007 #include "MEClickableCanvas.hh"
0008 #include <TMath.h>
0009 #include <TRootEmbeddedCanvas.h>
0010 
0011 ClassImp(MEPlotWindow);
0012 
0013 MEPlotWindow::MEPlotWindow( const TGWindow *p, MusEcalGUI* main, const char* name, UInt_t w, UInt_t h,      const char* str1,
0014                 const char* str2,
0015                 const char* str3,
0016                 const char* str4
0017                 )
0018 : _gui( main ), _name(name), _printName(name)
0019 {
0020   unsigned width  = w;
0021   unsigned height = h;
0022   unsigned margin = 2;
0023 
0024   fClose = kTRUE;
0025   
0026   fMain = new TGTransientFrame( p, main, width, height );
0027   fMain->Connect("CloseWindow()", "MEPlotWindow", this, "DoClose()");
0028   fMain->DontCallClose();
0029   fMain->SetCleanup(kDeepCleanup);
0030   
0031   fMain->ChangeOptions( (fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame );
0032   
0033   fHFrame  = new TGHorizontalFrame( fMain, width, height );
0034   
0035   //  fEcanvas = new TRootEmbeddedCanvas( name, fHFrame, width-margin, height-margin );
0036   //  fEcanvas = new MEClickableCanvas( name, fHFrame, width-margin, height-margin, main );
0037   fEcanvas = new MEClickableCanvas( name, fHFrame, width-margin, height-margin, this );
0038   
0039   TGLayoutHints* fL = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY,5,5,5,0);
0040   fHFrame->AddFrame( fEcanvas, fL );
0041   fMain->AddFrame( fHFrame );
0042   
0043   fMain->SetWindowName( name );
0044   TGDimension size = fMain->GetDefaultSize();
0045   fMain->Resize(size);
0046 
0047   fMain->SetWMPosition(100,100);
0048    
0049   fMain->MapSubwindows();
0050   fMain->MapWindow();
0051 
0052   SetCanvas( fEcanvas->GetCanvas(), str1, str2, str3, str4 );
0053 }
0054 
0055 void 
0056 MEPlotWindow::setPrintName( TString printName )
0057 {
0058   _printName = printName;
0059 }
0060 
0061 void
0062 MEPlotWindow::write()
0063 {
0064   TString fn_ = _printName;
0065   // fn_ += ".ps";
0066   fPad->Print( fn_ );
0067 }
0068 
0069 MEPlotWindow::~MEPlotWindow()
0070 {
0071   _gui->_window.erase( _name );
0072 
0073   fMain->DeleteWindow();   
0074 
0075   //  _gui->setPad();
0076   //  _gui->_curPad = _gui->fPad;
0077 
0078 }
0079 
0080 void 
0081 MEPlotWindow::CloseWindow()
0082 {
0083   delete this;
0084 }
0085 
0086 void 
0087 MEPlotWindow::DoClose()
0088 {
0089   if (fClose)
0090     CloseWindow();
0091   else {
0092     fClose = kTRUE;
0093     TTimer::SingleShot(150, "MEPlotWindow", this, "CloseWindow()");
0094   }
0095 }
0096 
0097 void 
0098 MEPlotWindow::setPxAndPy( int px, int py ) 
0099 { 
0100   MECanvasHolder::setPxAndPy( px, py );
0101   _gui->windowClicked( this );
0102 }
0103 
0104 // XtoPad does not convert user coordinates to NDC !! (it takes care only of lin/log user coordinates 
0105 // to pad coordinates. If linear coordinates   double x = pad->XtoPad(y); returns y otherwise it returns log(y). To convert from user coordinates to NDC, to, eg 
0106 
0107 //    Double_t dpx  = gPad->GetX2() - gPad->GetX1();
0108 //    Double_t dpy  = gPad->GetY2() - gPad->GetY1();
0109 //    Double_t xp1  = gPad->GetX1();
0110 //    Double_t yp1  = gPad->GetY1();
0111 
0112 
0113 //   Double_t xndc = (x-xp1)/dpx 
0114 //   Double_t yndc = (y-yp1)/dpy