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

Last change on this file since 855 was 849, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.7 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 MHexagon &hex = (MHexagon&) obj;
74
75 TObject::Copy(obj);
76 TAttLine::Copy(hex);
77 TAttFill::Copy(hex);
78
79 hex.fX = fX ;
80 hex.fY = fY ;
81 hex.fD = fD ;
82}
83Int_t MHexagon::DistancetoPrimitive( Int_t px, Int_t py )
84{
85 // compute the distance of a point (px,py) to the Hexagon
86 // this functions needed for graphical primitives, that
87 // means without this function you are not able to interact
88 // with the graphical primitive with the mouse!!!
89 //
90 // All calcutations are running in pixel coordinates
91
92 // compute the distance of the Point to the center of the Hexagon
93
94 const Int_t pxhex = gPad->XtoAbsPixel( fX ) ;
95 const Int_t pyhex = gPad->YtoAbsPixel( fY ) ;
96
97 const Double_t DistPointHexagon = TMath::Sqrt( Double_t ((pxhex-px)*(pxhex-px) + (pyhex-py)*(pyhex-py))) ;
98 const Double_t cosa = TMath::Abs(px-pxhex) / DistPointHexagon ;
99 const Double_t sina = TMath::Abs(py-pyhex) / DistPointHexagon ;
100
101 // comput the distance to pixel border
102
103 const Double_t dx = fD * cosa / 2 ;
104 const Double_t dy = fD * sina / 2 ;
105
106 const Double_t xborder = fX + dx ;
107 const Double_t yborder = fY + dy ;
108
109 const Int_t pxborder = gPad->XtoAbsPixel( xborder ) ;
110 const Int_t pyborder = gPad->YtoAbsPixel( yborder ) ;
111
112 const Double_t DistBorderHexagon = TMath::Sqrt( Double_t ((pxborder-pxhex)*(pxborder-pxhex)+(pyborder-pyhex)*(pyborder-pyhex))) ;
113
114
115 // compute the distance from the border of Pixel
116 // here in the first implementation is just circle inside
117
118 return DistBorderHexagon < DistPointHexagon ? 999999 : 0;
119}
120
121void MHexagon::DrawHexagon( Float_t x, Float_t y, Float_t d )
122{
123 // Draw this ellipse with new coordinate
124
125 MHexagon *newhexagon = new MHexagon(x, y, d ) ;
126 TAttLine::Copy(*newhexagon) ;
127 TAttFill::Copy(*newhexagon) ;
128
129 newhexagon->SetBit (kCanDelete) ;
130 newhexagon->AppendPad() ;
131}
132
133void MHexagon::ExecuteEvent(Int_t event, Int_t px, Int_t py ) {
134 // This is the first test of implementing a clickable interface
135 // for one pixel
136
137 switch ( event ) {
138
139 case kButton1Down:
140
141 printf ("\n kButton1Down \n" ) ;
142 SetFillColor(2) ;
143 gPad->Modified() ;
144 break;
145
146 case kButton1Double:
147 SetFillColor(0) ;
148 gPad->Modified() ;
149 break;
150 // case kMouseEnter:
151 // printf ("\n Mouse inside object \n" ) ;
152 // break;
153 }
154
155}
156
157
158
159void MHexagon::ls( Option_t *)
160{
161 // list this hexagon with its attributes
162 TROOT::IndentLevel() ;
163 printf ("%s: X= %f Y= %f R= %f \n", GetName(), fX, fY, fD ) ;
164}
165
166void MHexagon::Paint(Option_t * )
167{
168 // paint this hexagon with its attribute
169
170 PaintHexagon(fX, fY, fD ) ;
171}
172
173
174void MHexagon::PaintHexagon (Float_t inX, Float_t inY, Float_t inD )
175{
176 // draw this hexagon with the coordinates
177
178 const Int_t np = 6 ;
179
180 const Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 } ;
181 const Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 } ;
182
183 static Float_t x[np+1], y[np+1] ;
184
185 TAttLine::Modify() ; // Change line attributes only if neccessary
186 TAttFill::Modify() ; // Change fill attributes only if neccessary
187
188 // calculate the positions of the pixel corners
189
190 for ( Int_t i=0; i<=np; i++ ) {
191 x[i] = inX + dx[i]* inD ;
192 y[i] = inY + dy[i]* inD ;
193 }
194
195 // paint the pixel (hopefully)
196
197 if ( GetFillColor() ) gPad->PaintFillArea(np, x, y) ;
198 if ( GetLineStyle() ) gPad->PaintPolyLine(np+1, x, y) ;
199
200}
201
202void MHexagon::Print( Option_t * )
203{
204 // print/dump this hexagon with its attributes
205 printf ("Ellipse: X= %f Y= %f R= %f ", fX, fY, fD ) ;
206
207 if ( GetLineColor() != 1 ) printf (" Color=%d", GetLineColor() ) ;
208 if ( GetLineStyle() != 1 ) printf (" Color=%d", GetLineStyle() ) ;
209 if ( GetLineWidth() != 1 ) printf (" Color=%d", GetLineWidth() ) ;
210
211 if ( GetFillColor() != 0 ) printf (" FillColor=%d", GetFillColor() ) ;
212
213 printf ("\n") ;
214}
215
216
217
218
219
220
Note: See TracBrowser for help on using the repository browser.