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

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