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

Last change on this file since 695 was 653, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.9 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
94
95void MHexagon::Draw(Option_t *option )
96{
97 // Draw this ellipse with its current attributes
98 AppendPad(option) ;
99}
100
101void MHexagon::DrawHexagon( Float_t x, Float_t y, Float_t d )
102{
103 // Draw this ellipse with new coordinate
104
105 MHexagon *newhexagon = new MHexagon(x, y, d ) ;
106 TAttLine::Copy(*newhexagon) ;
107 TAttFill::Copy(*newhexagon) ;
108
109 newhexagon->SetBit (kCanDelete) ;
110 newhexagon->AppendPad() ;
111}
112
113void MHexagon::ExecuteEvent(Int_t event, Int_t px, Int_t py ) {
114 // This is the first test of implementing a clickable interface
115 // for one pixel
116
117 switch ( event ) {
118
119 case kButton1Down:
120
121 printf ("\n kButton1Down \n" ) ;
122 SetFillColor(2) ;
123 gPad->Modified() ;
124 break;
125
126 case kButton1Double:
127 SetFillColor(0) ;
128 gPad->Modified() ;
129 break;
130 // case kMouseEnter:
131 // printf ("\n Mouse inside object \n" ) ;
132 // break;
133 }
134
135}
136
137
138
139void MHexagon::ls( Option_t *)
140{
141 // list this hexagon with its attributes
142 TROOT::IndentLevel() ;
143 printf ("%s: X= %f Y= %f R= %f \n", GetName(), fX, fY, fD ) ;
144}
145
146void MHexagon::Paint(Option_t * )
147{
148 // paint this hexagon with its attribute
149
150 PaintHexagon(fX, fY, fD ) ;
151}
152
153
154void MHexagon::PaintHexagon (Float_t inX, Float_t inY, Float_t inD )
155{
156 // draw this hexagon with the coordinates
157
158 const Int_t np = 6 ;
159
160 const Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 } ;
161 const Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 } ;
162
163 static Float_t x[np+1], y[np+1] ;
164
165 TAttLine::Modify() ; // Change line attributes only if neccessary
166 TAttFill::Modify() ; // Change fill attributes only if neccessary
167
168 // calculate the positions of the pixel corners
169
170 for ( Int_t i=0; i<=np; i++ ) {
171 x[i] = inX + dx[i]* inD ;
172 y[i] = inY + dy[i]* inD ;
173 }
174
175 // paint the pixel (hopefully)
176
177 if ( GetFillColor() ) gPad->PaintFillArea(np, x, y) ;
178 if ( GetLineStyle() ) gPad->PaintPolyLine(np+1, x, y) ;
179
180}
181
182void MHexagon::Print( Option_t * )
183{
184 // print/dump this hexagon with its attributes
185 printf ("Ellipse: X= %f Y= %f R= %f ", fX, fY, fD ) ;
186
187 if ( GetLineColor() != 1 ) printf (" Color=%d", GetLineColor() ) ;
188 if ( GetLineStyle() != 1 ) printf (" Color=%d", GetLineStyle() ) ;
189 if ( GetLineWidth() != 1 ) printf (" Color=%d", GetLineWidth() ) ;
190
191 if ( GetFillColor() != 0 ) printf (" FillColor=%d", GetFillColor() ) ;
192
193 printf ("\n") ;
194}
195
196
197
198
199
200
Note: See TracBrowser for help on using the repository browser.