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

Last change on this file since 984 was 959, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.5 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 <iostream.h>
33
34#include <TVirtualPad.h> // gPad
35
36#include "MGeomPix.h" // GetX
37
38ClassImp(MHexagon);
39
40// ------------------------------------------------------------------------
41//
42// default constructor for MHexagon
43//
44MHexagon::MHexagon()
45{
46}
47
48// ------------------------------------------------------------------------
49//
50// normal constructor for MHexagon
51//
52MHexagon::MHexagon(Float_t x, Float_t y, Float_t d)
53: TAttFill(0, 1001), fX(x), fY(y), fD(d)
54{
55}
56
57// ------------------------------------------------------------------------
58//
59// normal constructor for MHexagon
60//
61MHexagon::MHexagon(MGeomPix &pix)
62: TAttFill(0, 1001)
63{
64 fX = pix.GetX();
65 fY = pix.GetY();
66 fD = pix.GetR();
67}
68
69// ------------------------------------------------------------------------
70//
71// copy constructor for MHexagon
72//
73MHexagon::MHexagon(const MHexagon &hexagon)
74{
75 ((MHexagon&) hexagon).Copy(*this);
76}
77
78// ------------------------------------------------------------------------
79//
80// default destructor for MHexagon
81//
82MHexagon::~MHexagon()
83{
84}
85
86// ------------------------------------------------------------------------
87//
88// copy this hexagon to hexagon
89//
90void MHexagon::Copy(TObject &obj)
91{
92 MHexagon &hex = (MHexagon&) obj;
93
94 TObject::Copy(obj);
95 TAttLine::Copy(hex);
96 TAttFill::Copy(hex);
97
98 hex.fX = fX;
99 hex.fY = fY;
100 hex.fD = fD;
101}
102
103// ------------------------------------------------------------------------
104//
105// compute the distance of a point (px,py) to the Hexagon
106// this functions needed for graphical primitives, that
107// means without this function you are not able to interact
108// with the graphical primitive with the mouse!!!
109//
110// All calcutations are running in pixel coordinates
111//
112Int_t MHexagon::DistancetoPrimitive(Int_t px, Int_t py)
113{
114 //
115 // compute the distance of the Point to the center of the Hexagon
116 //
117 const Int_t pxhex = gPad->XtoAbsPixel(fX);
118 const Int_t pyhex = gPad->YtoAbsPixel(fY);
119
120 const Double_t disthex = TMath::Sqrt((Double_t)((pxhex-px)*(pxhex-px) + (pyhex-py)*(pyhex-py)));
121
122 const Double_t cosa = TMath::Abs(px-pxhex) / disthex;
123 const Double_t sina = TMath::Abs(py-pyhex) / disthex;
124
125 //
126 // comput the distance to pixel border
127 //
128 const Double_t dx = fD * cosa / 2;
129 const Double_t dy = fD * sina / 2;
130
131 const Double_t xborder = fX + dx;
132 const Double_t yborder = fY + dy;
133
134 const Int_t pxborder = gPad->XtoAbsPixel(xborder);
135 const Int_t pyborder = gPad->YtoAbsPixel(yborder);
136
137 const Double_t distborder = TMath::Sqrt((Double_t)((pxborder-pxhex)*(pxborder-pxhex)+(pyborder-pyhex)*(pyborder-pyhex)));
138
139 //
140 // compute the distance from the border of Pixel
141 // here in the first implementation is just circle inside
142 //
143 return distborder < disthex ? 999999 : 0;
144}
145
146// ------------------------------------------------------------------------
147//
148// Draw this ellipse with new coordinate
149//
150void MHexagon::DrawHexagon(Float_t x, Float_t y, Float_t d)
151{
152 MHexagon *newhexagon = new MHexagon(x, y, d);
153
154 TAttLine::Copy(*newhexagon);
155 TAttFill::Copy(*newhexagon);
156
157 newhexagon->SetBit(kCanDelete);
158 newhexagon->AppendPad();
159}
160
161// ------------------------------------------------------------------------
162//
163// This is the first test of implementing a clickable interface
164// for one pixel
165//
166void MHexagon::ExecuteEvent(Int_t event, Int_t px, Int_t py)
167{
168
169 switch (event)
170 {
171 case kButton1Down:
172 cout << endl << "kButton1Down" << endl;
173 SetFillColor(2);
174 gPad->Modified();
175 break;
176
177 case kButton1Double:
178 SetFillColor(0);
179 gPad->Modified();
180 break;
181 // case kMouseEnter:
182 // printf ("\n Mouse inside object \n" ) ;
183 // break;
184 }
185}
186
187// ------------------------------------------------------------------------
188//
189// list this hexagon with its attributes
190//
191void MHexagon::ls(Option_t *)
192{
193 TROOT::IndentLevel();
194 Print();
195}
196
197// ------------------------------------------------------------------------
198//
199// paint this hexagon with its attribute
200//
201void MHexagon::Paint(Option_t *)
202{
203 PaintHexagon(fX, fY, fD);
204}
205
206// ------------------------------------------------------------------------
207//
208// draw this hexagon with the coordinates
209//
210void MHexagon::PaintHexagon(Float_t inX, Float_t inY, Float_t inD)
211{
212
213 const Int_t np = 6;
214
215 const Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 };
216 const Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 };
217
218 static Float_t x[np+1], y[np+1];
219
220 TAttLine::Modify(); // Change line attributes only if neccessary
221 TAttFill::Modify(); // Change fill attributes only if neccessary
222
223 // calculate the positions of the pixel corners
224
225 for (Int_t i=0; i<=np; i++)
226 {
227 x[i] = inX + dx[i]* inD;
228 y[i] = inY + dy[i]* inD;
229 }
230
231 // paint the pixel (hopefully)
232
233 if (GetFillColor())
234 gPad->PaintFillArea(np, x, y);
235
236 if (GetLineStyle())
237 gPad->PaintPolyLine(np+1, x, y);
238
239}
240
241// ------------------------------------------------------------------------
242//
243// print/dump this hexagon with its attributes
244//
245void MHexagon::Print(Option_t *)
246{
247 cout << GetName() << ": X=" << fX << " Y=" << fY << "R=" << fD << endl;
248
249 cout << " Color=" << GetLineColor() << endl;
250 cout << " Style=" << GetLineStyle() << endl;
251 cout << " Width=" << GetLineWidth() << endl;
252 cout << " FillColor=" << GetFillColor() << endl;
253}
Note: See TracBrowser for help on using the repository browser.