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

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