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

View2D.cxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include <algorithm>
00009 #include "EventDisplayBase/View2D.h"
00010 #include "EventDisplayBase/Functors.h"
00011 using namespace evdb;
00012 
00013 //......................................................................
00014 
00015 View2D::View2D() 
00016 { 
00017   fNextMarker     = fMarkerL.end();
00018   fNextPolyMarker = fPolyMarkerL.end();
00019   fNextLine       = fLineL.end();
00020   fNextPolyLine   = fPolyLineL.end();
00021   fNextArc        = fArcL.end();
00022   fNextBox        = fBoxL.end();
00023   fNextText       = fTextL.end();
00024 
00025   this->AddMarker(0.0,0.0,2,1,0.1);
00026   this->AddPolyMarker(1,2,20,0.1);
00027   this->AddLine(0.0,0.0,1.0,1.0);
00028   this->AddPolyLine(1,2,1,1);
00029   this->AddArc(0.0,0.0,1.0);
00030   this->AddBox(0.0,1.0,0.0,1.0);
00031   this->AddText(0.0,0.0,"");
00032   this->Clear();
00033 }
00034 
00035 //......................................................................
00036 
00037 View2D::~View2D() 
00038 {
00039   for_each(fMarkerL.begin(),    fMarkerL.end(),    delete_marker());
00040   for_each(fPolyMarkerL.begin(),fPolyMarkerL.end(),delete_polymarker());
00041   for_each(fLineL.begin(),      fLineL.end(),      delete_line());
00042   for_each(fPolyLineL.begin(),  fPolyLineL.end(),  delete_polyline());
00043   for_each(fArcL.begin(),       fArcL.end(),       delete_arc());
00044   for_each(fBoxL.begin(),       fBoxL.end(),       delete_box());
00045   for_each(fTextL.begin(),      fTextL.end(),      delete_text());
00046 }
00047 
00048 //......................................................................
00049 
00050 void View2D::Draw()
00051 {
00052   for_each(fArcL.begin(),       fNextArc,       draw_tobject());
00053   for_each(fBoxL.begin(),       fNextBox,       draw_tobject());
00054   for_each(fPolyLineL.begin(),  fNextPolyLine,  draw_tobject());
00055   for_each(fLineL.begin(),      fNextLine,      draw_tobject());
00056   for_each(fMarkerL.begin(),    fNextMarker,    draw_tobject());
00057   for_each(fPolyMarkerL.begin(),fNextPolyMarker,draw_tobject());
00058   for_each(fTextL.begin(),      fNextText,      draw_tobject());
00059 }
00060 
00061 //......................................................................
00062 
00063 void View2D::Clear() 
00064 {
00065   // To clear, just reset the next positions to use for inserts to the
00066   // begining of the lists. Keep all the memory around as it it very likely
00067   // we will reuse it
00068   fNextMarker     = fMarkerL.begin();
00069   fNextPolyMarker = fPolyMarkerL.begin();
00070   fNextLine       = fLineL.begin();
00071   fNextPolyLine   = fPolyLineL.begin();
00072   fNextArc        = fArcL.begin();
00073   fNextBox        = fBoxL.begin();
00074   fNextText       = fTextL.begin();
00075 }
00076 
00077 //......................................................................
00078 
00079 TMarker& View2D::AddMarker(double x, double y, int c, int st, double sz)
00080 {
00081   TMarker* m = 0;
00082   if (fNextMarker == fMarkerL.end()) {
00083     // Grow the list...
00084     m = new TMarker(x,y,st);
00085     m->SetBit(kCanDelete,kFALSE);
00086     m->SetMarkerColor(c);
00087     m->SetMarkerSize(sz);
00088     if (fNextMarker == fMarkerL.begin()) fMarkerL.push_front(m);
00089     else                                 fMarkerL.push_back(m);
00090     fNextMarker = fMarkerL.end();
00091   }
00092   else {
00093     // Reuse the marker at the current position
00094     m = *fNextMarker;
00095     m->SetX(x);
00096     m->SetY(y);
00097     m->SetMarkerSize(sz);
00098     m->SetMarkerColor(c);
00099     m->SetMarkerStyle(st);
00100     ++fNextMarker;
00101   }
00102   // Return the marker just added so users can twiddle it
00103   return *m;
00104 }
00105 
00106 //......................................................................
00107 
00108 TPolyMarker& View2D::AddPolyMarker(int n, int c, int st, double sz)
00109 {
00110   TPolyMarker* pm = 0;
00111   if (fNextPolyMarker == fPolyMarkerL.end()) {
00112     // Grow the list...
00113     pm = new TPolyMarker(n);
00114     pm->SetBit(kCanDelete,kFALSE);
00115     pm->SetMarkerColor(c);
00116     pm->SetMarkerStyle(st);
00117     pm->SetMarkerSize(sz);
00118     fPolyMarkerL.push_back(pm);
00119     fNextPolyMarker = fPolyMarkerL.end();
00120   }
00121   else {
00122     // Reuse the polymarker at the current position
00123     pm = *fNextPolyMarker;
00124     pm->SetPolyMarker(n); // reset elements in PolyMarket
00125     pm->SetMarkerColor(c);
00126     pm->SetMarkerSize(sz);
00127     pm->SetMarkerStyle(st);
00128     ++fNextPolyMarker;
00129   }
00130   // Return the marker just added so users can twiddle it (ie. add points)
00131   return *pm;
00132 }
00133 
00134 //......................................................................
00135 
00136 TLine& View2D::AddLine(double x1, double y1, double x2, double y2)
00137 {
00138   TLine* ln = 0;
00139   if (fNextLine == fLineL.end()) {
00140     // Grow the list...
00141     ln = new TLine(x1,y1,x2,y2);
00142     ln->SetBit(kCanDelete,kFALSE);
00143     fLineL.push_back(ln);
00144     fNextLine = fLineL.end();
00145   }
00146   else {
00147     // Reuse the polyline at the current position
00148     ln = *fNextLine;
00149     ln->SetX1(x1);
00150     ln->SetY1(y1);
00151     ln->SetX2(x2);
00152     ln->SetY2(y2);
00153     ++fNextLine;
00154   }
00155   // Return the marker just added so users can twiddle it (ie. add points)
00156   return *ln;
00157 }
00158 
00159 //......................................................................
00160 
00161 TPolyLine& View2D::AddPolyLine(int n, int c, int w, int s)
00162 {
00163   TPolyLine* pl = 0;
00164   if (fNextPolyLine == fPolyLineL.end()) {
00165     // Grow the list...
00166     pl = new TPolyLine(n);
00167     pl->SetBit(kCanDelete,kFALSE);
00168     pl->SetLineColor(c);
00169     pl->SetLineWidth(w);
00170     pl->SetLineStyle(s);
00171     fPolyLineL.push_back(pl);
00172     fNextPolyLine = fPolyLineL.end();
00173   }
00174   else {
00175     // Reuse the polyline at the current position
00176     pl = *fNextPolyLine;
00177     pl->SetPolyLine(n); // reset elements in PolyLine
00178     pl->SetLineColor(c);
00179     pl->SetLineWidth(w);
00180     pl->SetLineStyle(s);
00181     ++fNextPolyLine;
00182   }
00183   // Return the marker just added so users can twiddle it (ie. add points)
00184   return *pl;
00185 }
00186 
00187 //......................................................................
00188 
00189 TArc& View2D::AddArc(double x, double y, double r, double p1, double p2) 
00190 {
00191   TArc* a = 0;
00192   if (fNextArc == fArcL.end()) {
00193     // Grow the list...
00194     a = new TArc(x,y,r,p1,p2);
00195     a->SetBit(kCanDelete,kFALSE);
00196     fArcL.push_back(a);
00197     fNextArc = fArcL.end();
00198   }
00199   else {
00200     // Reuse the arc at the current position
00201     a = *fNextArc;
00202     a->SetX1(x);
00203     a->SetY1(y);
00204     a->SetR1(r);
00205     a->SetR2(r);
00206     a->SetPhimin(p1);
00207     a->SetPhimax(p2);
00208     ++fNextArc;
00209   }
00210   // Return the marker just added so users can twiddle it (ie. add points)
00211   return *a;
00212 }
00213 
00214 //......................................................................
00215 
00216 TBox& View2D::AddBox(double x1, double y1, double x2, double y2)
00217 {
00218   TBox* b = 0;
00219   if (fNextBox == fBoxL.end()) {
00220     // Grow the list...
00221     b = new TBox(x1,y1,x2,y2);
00222     b->SetBit(kCanDelete,kFALSE);
00223     fBoxL.push_back(b);
00224     fNextBox = fBoxL.end();
00225   }
00226   else {
00227     // Reuse the arc at the current position
00228     b = *fNextBox;
00229     b->SetX1(x1);
00230     b->SetY1(y1);
00231     b->SetX2(x2);
00232     b->SetY2(y2);
00233     ++fNextBox;
00234   }
00235   // Return the box just added so users can twiddle it
00236   return *b;
00237 }
00238 
00239 //......................................................................
00240 
00241 TText& View2D::AddText(double x, double y, const char* text)
00242 {
00243   TText* itxt = 0;
00244   if (fNextText == fTextL.end()) {
00245     // Grow the list...
00246     itxt = new TText(x,y,text);
00247     itxt->SetBit(kCanDelete,kFALSE);
00248     fTextL.push_back(itxt);
00249     fNextText = fTextL.end();
00250   }
00251   else {
00252     // Reuse the text at the current position
00253     itxt = *fNextText;
00254     itxt->SetText(x,y,text);
00255     ++fNextText;
00256   }
00257 
00258   // Return the marker just added so users can twiddle it
00259   return *itxt;
00260 }
00261 

Generated on Thu Sep 4 02:05:29 2008 for NOvA Offline by doxygen 1.3.5