Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Midad/MultiPage/GfxStrip.cxx

Go to the documentation of this file.
00001 #include "GfxStrip.h"
00002 #include "GfxStripList.h"
00003 #include "GfxStripListCfg.h"
00004 #include "ViewState.h"
00005 #include <Midad/Base/Mint.h>
00006 #include <Midad/Util/Util.h>
00007 
00008 #include <UgliGeometry/UgliGeomHandle.h>
00009 #include <UgliGeometry/UgliStripHandle.h>
00010 
00011 #include <RecoBase/CandStripHandle.h>
00012 
00013 #include <TEllipse.h>
00014 #include <TBox.h>
00015 #include <TPad.h>
00016 
00017 #include <iostream>
00018 using namespace std;
00019 
00020 ClassImp(GfxStrip)
00021 
00022 #if 0
00023 GfxStrip::GfxStrip()
00024     : fStrip(0)
00025       ,fParent(0)
00026       ,fImp(0)
00027 {
00028 }
00029 #endif
00030 GfxStrip::GfxStrip(const CandStripHandle& csh, GfxStripList& parent)
00031     : fStrip(&csh)
00032       ,fParent(&parent)
00033       ,fImp(0)
00034 {
00035 }
00036 GfxStrip::GfxStrip(const GfxStrip& rhs)
00037     : TObject()
00038     , fStrip(rhs.fStrip), fParent(rhs.fParent), fImp(0)
00039 {
00040 }
00041 GfxStrip& GfxStrip::operator=(const GfxStrip& rhs)
00042 {
00043     if (this == &rhs) return *this;
00044     fStrip = rhs.fStrip;
00045     fParent = rhs.fParent;
00046     fImp = 0;
00047     return *this;
00048 }
00049 
00050 GfxStrip::~GfxStrip()
00051 {
00052     this->Clear();
00053 }
00054 
00055 void GfxStrip::Clear(const Option_t*)
00056 {
00057     if (fImp) delete fImp; fImp = 0;
00058 }
00059 
00060 bool GfxStrip::GetRealCoords(double& cx, double& cy, double& dx, double& dy)
00061 {
00062     UgliGeomHandle ugh(*fStrip->GetVldContext());
00063     UgliStripHandle ush = ugh.GetStripHandle(fStrip->GetStripEndId());
00064     if (!ush.IsValid()) return false;
00065 
00066     cx = ush.GlobalPos(0).Z();
00067     cy = ush.GetTPos();
00068     dx = ush.GetHalfThickness();
00069     dy = ush.GetHalfWidth();
00070     return true;
00071 }
00072 bool GfxStrip::GetDiscreteCoords(double& cx, double& cy, double& dx, double& dy)
00073 {
00074     PlexStripEndId seid = fStrip->GetStripEndId();
00075     cx = seid.GetPlane();
00076     cy = seid.GetStrip();
00077     dx = 0.5;
00078     dy = 0.5;
00079     return true;
00080 }
00081 
00082 float GfxStrip::GetRelativeValue(GfxStripListCfg::MeasureScale_t ms)
00083 {
00084     if (ms == GfxStripListCfg::kCharge) {
00085         RangeDouble& qrange = fParent->GetMint().GetChargeRange();
00086         double den = qrange.Min() - qrange.Max();
00087         if (den > 0)
00088             return (fStrip->GetCharge() - qrange.Min()) / den;
00089     }
00090     else {                      // time
00091         RangeDouble& trange = fParent->GetMint().GetTimeRange();
00092         double den = trange.Max() - trange.Min();
00093         if (den > 0)
00094             return (fStrip->GetTime() - trange.Min()) / den;
00095     }
00096     return 1.0;
00097 }
00098 
00099 void GfxStrip::ModifyCoords(double& cx, double& cy, double& dx, double& dy)
00100 {
00101     int strip_sign = 0;
00102     StripEnd::StripEnd_t end = fStrip->GetStripEndId().GetEnd();
00103     if (end == StripEnd::kNegative) strip_sign = -1;
00104     if (end == StripEnd::kPositive) strip_sign = +1;
00105 
00106     GfxStripListCfg& cfg = fParent->GetCfg();
00107     
00108     // Scale down size of strip
00109     GfxStripListCfg::SizeBy_t sb = cfg.GetSizeBy();
00110     double size_scale = this->GetRelativeValue(cfg.GetSizeIs());
00111 
00112     size_scale *= cfg.GetSizeFactor();
00113 
00114     switch (sb) {
00115     case GfxStripListCfg::kFixed:
00116         // nothing
00117         break;
00118     case GfxStripListCfg::kLinear:
00119         dx *= size_scale;
00120         dy *= size_scale;
00121         break;
00122     case GfxStripListCfg::kLogLinear:
00123         dx *= logify_relative(size_scale);
00124         dy *= logify_relative(size_scale);
00125         break;
00126     case GfxStripListCfg::kLogArea:
00127         dx *= logify_relative(sqrt(size_scale));
00128         dy *= logify_relative(sqrt(size_scale));
00129         break;
00130     case GfxStripListCfg::kArea: default:
00131         dx *= sqrt(size_scale);
00132         dy *= sqrt(size_scale);
00133         break;
00134     }
00135 
00136     // modify for any odd shape
00137     GfxStripListCfg::StripEnd_t si = cfg.GetStripEnd();
00138     switch (si) {
00139     case GfxStripListCfg::kHalf:
00140         dy *= strip_sign * 0.5;
00141         cy += dy;
00142         break;
00143     case GfxStripListCfg::kBowTie:
00144         dx *= strip_sign * 0.5;
00145         dy *= strip_sign * 0.5;
00146         cx += dx;
00147         cy += dy;
00148         break;
00149     case GfxStripListCfg::kFull: 
00150         // fall through
00151     case GfxStripListCfg::kBit:
00152         // fall through
00153     default:
00154         // do nothing
00155         break;
00156     }    
00157 }
00158 
00159 bool GfxStrip::SetColor()
00160 {
00161     int color = fParent->GetStripColor(*fStrip);
00162     if (!color) {
00163         return false;
00164     }
00165 
00166 #if 0
00167     TAttFill* att_fill = dynamic_cast<TAttFill*>(fImp);
00168     if (!att_fill) return false;
00169     att_fill->SetFillColor(color);
00170 #else
00171     TAttLine* att_line = dynamic_cast<TAttLine*>(fImp);
00172     if (!att_line) return false;
00173     att_line->SetLineColor(color);
00174     return true;
00175 #endif
00176 }
00177 
00178 void GfxStrip::Configure()
00179 {
00180 
00181     // here we make our imp.
00182     this->Clear();
00183 
00184     GfxStripListCfg& cfg = fParent->GetCfg();
00185 
00186     fCx = fCy = fDx = fDy = 0.0;
00187 
00188 
00189     switch (fParent->GetViewState()->GetSpatialMetric()) {
00190     case ViewState::metric_is_continuous:
00191         this->GetRealCoords(fCx,fCy,fDx,fDy);
00192         break;
00193     case ViewState::metric_is_discreet: default:
00194         this->GetDiscreteCoords(fCx,fCy,fDx,fDy);
00195         break;
00196     }
00197 
00198 
00199     double dx = fDx, dy = fDy;
00200     if (cfg.GetScaleIs() == GfxStripListCfg::kAbsolute) {
00201         fDx = 1.0;
00202         fDy = 4.0;
00203         this->ModifyCoords(fCx,fCy,fDx,fDy);
00204         this->RelToAbs(dx,dy);
00205     }
00206     else {
00207         this->ModifyCoords(fCx,fCy,fDx,fDy);
00208     }
00209     switch (cfg.GetShapeIs()) {
00210     case GfxStripListCfg::kEllipse: 
00211         fImp = new TEllipse(fCx,fCy,dx,dy);
00212         break;
00213     default:
00214         fImp = new TBox(fCx+dx,fCy+dy,fCx-dx,fCy-dy);
00215         break;
00216     }
00217 
00218     TAttFill* att_fill = dynamic_cast<TAttFill*>(fImp);
00219     if (att_fill) {
00220         att_fill->SetFillStyle(0);
00221     } 
00222 
00223 //    cerr << "GfxStrip::Configure (" << cx << "," << cy << ")\n";
00224 
00225 }
00226 
00227 
00228 void GfxStrip::ExecuteEvent(int event, int px, int py)
00229 {
00230     fParent->ExecuteEventStrip(event,px,py,this);
00231 }
00232 void GfxStrip::Paint(Option_t* option)
00233 {
00234     if (!fImp) return;
00235 
00236     if (!this->SetColor()) return;
00237 
00238     GfxStripListCfg& cfg = fParent->GetCfg();
00239     if (cfg.GetScaleIs() == GfxStripListCfg::kAbsolute) {
00240         double dx, dy;
00241         this->RelToAbs(dx,dy);
00242 
00243         switch (cfg.GetShapeIs()) {
00244         case GfxStripListCfg::kEllipse: {
00245             TEllipse* el= dynamic_cast<TEllipse*>(fImp);
00246             el->SetR1(dx);
00247             el->SetR2(dy);
00248             el->Paint(option);
00249             break;
00250         }
00251         default:
00252             TBox* box = dynamic_cast<TBox*>(fImp);
00253             box->SetX1(fCx+dx);
00254             box->SetY1(fCy+dy);
00255             box->SetX2(fCx-dx);
00256             box->SetY2(fCy-dy);
00257             box->Paint();
00258             break;
00259         }
00260     }
00261     else {
00262         fImp->Paint(option);
00263     }
00264 }
00265 int GfxStrip::DistancetoPrimitive(int px, int py)
00266 {
00267     if (fImp) return fImp->DistancetoPrimitive(px,py);
00268     return 0xdead;
00269 }
00270 
00271 void GfxStrip::RelToAbs(double& dx, double& dy)
00272 {
00273     dx = gPad->AbsPixeltoX((int)fDx) - gPad->AbsPixeltoX(0);
00274     dy = gPad->AbsPixeltoY((int)fDy) - gPad->AbsPixeltoY(0);
00275 //    cerr << Form("dx=%f(%f)  dy=%f(%f)",fDx,dx,fDy,dy) << endl;
00276 }
00277 
00278 void GfxStrip::ConfigGui(void)
00279 {
00280     if (!fParent) return;
00281     GfxStripListCfg& cfg = fParent->GetCfg();
00282     cfg.GuiConfig();
00283 
00284 }

Generated on Mon Feb 15 11:06:46 2010 for loon by  doxygen 1.3.9.1