source: trunk/MagicSoft/Mars/mgui/MHexagon.cc@ 733

Last change on this file since 733 was 698, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.8 KB
Line 
1//
2// The class MHexagon is needed for the Event Display of
3// MAGIC.
4//
5#include "MHexagon.h"
6
7#include <TVirtualPad.h> // gPad
8
9#include "MGeomPix.h" // GetX
10
11ClassImp(MHexagon)
12
13MHexagon::MHexagon()
14{
15 // default constructor for MHexagon
16
17}
18
19MHexagon::MHexagon(Float_t x, Float_t y, Float_t d )
20 : TAttFill(0, 1001), fX(x), fY(y), fD(d)
21{
22 // normal constructor for MHexagon
23}
24
25MHexagon::MHexagon(MGeomPix &pix)
26 : TAttFill(0, 1001)
27{
28 // normal constructor for MHexagon
29 fX = pix.GetX();
30 fY = pix.GetY();
31 fD = pix.GetR();
32}
33
34MHexagon::MHexagon( const MHexagon &hexagon)
35{
36 // copy constructor for MHexagon
37 ((MHexagon&) hexagon).Copy(*this) ;
38}
39
40MHexagon::~MHexagon()
41{
42 // default destructor for MHexagon
43}
44
45void MHexagon::Copy( TObject &obj )
46{
47 // copy this hexagon to hexagon
48 TObject::Copy ( obj ) ;
49 TAttLine::Copy (((MHexagon&) obj ) ) ;
50 TAttFill::Copy (((MHexagon&) obj ) ) ;
51
52 ((MHexagon&) obj).fX = fX ;
53 ((MHexagon&) obj).fY = fY ;
54 ((MHexagon&) obj).fD = fD ;
55}
56Int_t MHexagon::DistancetoPrimitive( Int_t px, Int_t py )
57{
58 // compute the distance of a point (px,py) to the Hexagon
59 // this functions needed for graphical primitives, that
60 // means without this function you are not able to interact
61 // with the graphical primitive with the mouse!!!
62 //
63 // All calcutations are running in pixel coordinates
64
65 // compute the distance of the Point to the center of the Hexagon
66
67 const Int_t pxhex = gPad->XtoAbsPixel( fX ) ;
68 const Int_t pyhex = gPad->YtoAbsPixel( fY ) ;
69
70 const Double_t DistPointHexagon = TMath::Sqrt( Double_t ((pxhex-px)*(pxhex-px) + (pyhex-py)*(pyhex-py))) ;
71 const Double_t cosa = TMath::Abs(px-pxhex) / DistPointHexagon ;
72 const Double_t sina = TMath::Abs(py-pyhex) / DistPointHexagon ;
73
74 // comput the distance to pixel border
75
76 const Double_t dx = fD * cosa / 2 ;
77 const Double_t dy = fD * sina / 2 ;
78
79 const Double_t xborder = fX + dx ;
80 const Double_t yborder = fY + dy ;
81
82 const Int_t pxborder = gPad->XtoAbsPixel( xborder ) ;
83 const Int_t pyborder = gPad->YtoAbsPixel( yborder ) ;
84
85 const Double_t DistBorderHexagon = TMath::Sqrt( Double_t ((pxborder-pxhex)*(pxborder-pxhex)+(pyborder-pyhex)*(pyborder-pyhex))) ;
86
87
88 // compute the distance from the border of Pixel
89 // here in the first implementation is just circle inside
90
91 return DistBorderHexagon < DistPointHexagon ? 999999 : 0;
92}
93
94void MHexagon::DrawHexagon( Float_t x, Float_t y, Float_t d )
95{
96 // Draw this ellipse with new coordinate
97
98 MHexagon *newhexagon = new MHexagon(x, y, d ) ;
99 TAttLine::Copy(*newhexagon) ;
100 TAttFill::Copy(*newhexagon) ;
101
102 newhexagon->SetBit (kCanDelete) ;
103 newhexagon->AppendPad() ;
104}
105
106void MHexagon::ExecuteEvent(Int_t event, Int_t px, Int_t py ) {
107 // This is the first test of implementing a clickable interface
108 // for one pixel
109
110 switch ( event ) {
111
112 case kButton1Down:
113
114 printf ("\n kButton1Down \n" ) ;
115 SetFillColor(2) ;
116 gPad->Modified() ;
117 break;
118
119 case kButton1Double:
120 SetFillColor(0) ;
121 gPad->Modified() ;
122 break;
123 // case kMouseEnter:
124 // printf ("\n Mouse inside object \n" ) ;
125 // break;
126 }
127
128}
129
130
131
132void MHexagon::ls( Option_t *)
133{
134 // list this hexagon with its attributes
135 TROOT::IndentLevel() ;
136 printf ("%s: X= %f Y= %f R= %f \n", GetName(), fX, fY, fD ) ;
137}
138
139void MHexagon::Paint(Option_t * )
140{
141 // paint this hexagon with its attribute
142
143 PaintHexagon(fX, fY, fD ) ;
144}
145
146
147void MHexagon::PaintHexagon (Float_t inX, Float_t inY, Float_t inD )
148{
149 // draw this hexagon with the coordinates
150
151 const Int_t np = 6 ;
152
153 const Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 } ;
154 const Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 } ;
155
156 static Float_t x[np+1], y[np+1] ;
157
158 TAttLine::Modify() ; // Change line attributes only if neccessary
159 TAttFill::Modify() ; // Change fill attributes only if neccessary
160
161 // calculate the positions of the pixel corners
162
163 for ( Int_t i=0; i<=np; i++ ) {
164 x[i] = inX + dx[i]* inD ;
165 y[i] = inY + dy[i]* inD ;
166 }
167
168 // paint the pixel (hopefully)
169
170 if ( GetFillColor() ) gPad->PaintFillArea(np, x, y) ;
171 if ( GetLineStyle() ) gPad->PaintPolyLine(np+1, x, y) ;
172
173}
174
175void MHexagon::Print( Option_t * )
176{
177 // print/dump this hexagon with its attributes
178 printf ("Ellipse: X= %f Y= %f R= %f ", fX, fY, fD ) ;
179
180 if ( GetLineColor() != 1 ) printf (" Color=%d", GetLineColor() ) ;
181 if ( GetLineStyle() != 1 ) printf (" Color=%d", GetLineStyle() ) ;
182 if ( GetLineWidth() != 1 ) printf (" Color=%d", GetLineWidth() ) ;
183
184 if ( GetFillColor() != 0 ) printf (" FillColor=%d", GetFillColor() ) ;
185
186 printf ("\n") ;
187}
188
189
190
191
192
193
Note: See TracBrowser for help on using the repository browser.