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

Last change on this file since 603 was 589, checked in by harald, 24 years ago
Added some file for the Display and for the Geometry description.
File size: 4.9 KB
Line 
1#include <stdlib.h>
2#include <fstream.h>
3#include <iostream.h>
4
5#include "TROOT.h"
6#include "TVirtualPad.h"
7#include "TMath.h"
8
9#include "MHexagon.h"
10
11
12ClassImp(MHexagon)
13
14 //
15 // The class MHexagon is needed for the Event Display of
16 // MAGIC.
17
18
19
20MHexagon::MHexagon() : TObject(), TAttLine(), TAttFill()
21{
22 // default constructor for MHexagon
23
24}
25
26MHexagon::MHexagon(Float_t x, Float_t y, Float_t d ) : TObject(), TAttLine(), TAttFill(0, 1001)
27{
28 // normal constructor for MHexagon
29 fX = x ;
30 fY = y ;
31 fD = d ;
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}
45
46void MHexagon::Copy( TObject &obj )
47{
48 // copy this hexagon to hexagon
49
50 TObject::Copy ( obj ) ;
51 TAttLine::Copy (((MHexagon&) obj ) ) ;
52 TAttFill::Copy (((MHexagon&) obj ) ) ;
53
54 ((MHexagon&) obj).fX = fX ;
55 ((MHexagon&) obj).fY = fY ;
56 ((MHexagon&) obj).fD = fD ;
57}
58Int_t MHexagon::DistancetoPrimitive( Int_t px, Int_t py )
59{
60 // compute the distance of a point (px,py) to the Hexagon
61 // this functions needed for graphical primitives, that
62 // means without this function you are not able to interact
63 // with the graphical primitive with the mouse!!!
64 //
65 // All calcutations are running in pixel coordinates
66
67 // compute the distance of the Point to the center of the Hexagon
68
69 Int_t pxhex = gPad->XtoAbsPixel( fX ) ;
70 Int_t pyhex = gPad->YtoAbsPixel( fY ) ;
71
72 Double_t DistPointHexagon = TMath::Sqrt( Double_t ((pxhex-px)*(pxhex-px) + (pyhex-py)*(pyhex-py))) ;
73 Double_t cosa = TMath::Abs(px-pxhex) / DistPointHexagon ;
74 Double_t sina = TMath::Abs(py-pyhex) / DistPointHexagon ;
75
76 // comput the distance to pixel border
77
78 Double_t dx = fD * cosa / 2 ;
79 Double_t dy = fD * sina / 2 ;
80
81 Double_t xborder = fX + dx ;
82 Double_t yborder = fY + dy ;
83
84 Int_t pxborder = gPad->XtoAbsPixel( xborder ) ;
85 Int_t pyborder = gPad->YtoAbsPixel( yborder ) ;
86
87 Double_t DistBorderHexagon = TMath::Sqrt( Double_t ((pxborder-pxhex)*(pxborder-pxhex)+(pyborder-pyhex)*(pyborder-pyhex))) ;
88
89
90 // compute the distance from the border of Pixel
91 // here in the first implementation is just circle inside
92
93 if ( DistBorderHexagon < DistPointHexagon )
94 return 999999 ;
95 else
96 // return Int_t ( DistBorderHexagon - DistPointHexagon ) ;
97 return 0 ;
98}
99
100
101void MHexagon::Draw(Option_t *option )
102{
103 // Draw this ellipse with its current attributes
104 AppendPad(option) ;
105}
106
107void MHexagon::DrawHexagon( Float_t x, Float_t y, Float_t d )
108{
109 // Draw this ellipse with new coordinate
110
111 MHexagon *newhexagon = new MHexagon(x, y, d ) ;
112 TAttLine::Copy(*newhexagon) ;
113 TAttFill::Copy(*newhexagon) ;
114
115 newhexagon->SetBit (kCanDelete) ;
116 newhexagon->AppendPad() ;
117}
118
119void MHexagon::ExecuteEvent(Int_t event, Int_t px, Int_t py ) {
120 // This is the first test of implementing a clickable interface
121 // for one pixel
122
123 switch ( event ) {
124
125 case kButton1Down:
126
127 printf ("\n kButton1Down \n" ) ;
128 SetFillColor(2) ;
129 gPad->Modified() ;
130 break;
131
132 case kButton1Double:
133 SetFillColor(0) ;
134 gPad->Modified() ;
135 break;
136 // case kMouseEnter:
137 // printf ("\n Mouse inside object \n" ) ;
138 // break;
139 }
140
141}
142
143
144
145void MHexagon::ls( Option_t *)
146{
147 // list this hexagon with its attributes
148 TROOT::IndentLevel() ;
149 printf ("%s: X= %f Y= %f R= %f \n", GetName, fX, fY, fD ) ;
150}
151
152void MHexagon::Paint(Option_t * )
153{
154 // paint this hexagon with its attribute
155
156 PaintHexagon(fX, fY, fD ) ;
157}
158
159
160void MHexagon::PaintHexagon (Float_t inX, Float_t inY, Float_t inD )
161{
162 // draw this hexagon with the coordinates
163
164 const Int_t np = 6 ;
165
166 Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 } ;
167 Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 } ;
168
169 static Float_t x[np+1], y[np+1] ;
170
171 TAttLine::Modify() ; // Change line attributes only if neccessary
172 TAttFill::Modify() ; // Change fill attributes only if neccessary
173
174 // calculate the positions of the pixel corners
175
176 for ( Int_t i=0; i<=np; i++ ) {
177 x[i] = inX + dx[i]* inD ;
178 y[i] = inY + dy[i]* inD ;
179 }
180
181 // paint the pixel (hopefully)
182
183 if ( GetFillColor() ) gPad->PaintFillArea(np, x, y) ;
184 if ( GetLineStyle() ) gPad->PaintPolyLine(np+1, x, y) ;
185
186}
187
188void MHexagon::Print( Option_t * )
189{
190 // print/dump this hexagon with its attributes
191 printf ("Ellipse: X= %f Y= %f R= %f ", fX, fY, fD ) ;
192
193 if ( GetLineColor() != 1 ) printf (" Color=%d", GetLineColor() ) ;
194 if ( GetLineStyle() != 1 ) printf (" Color=%d", GetLineStyle() ) ;
195 if ( GetLineWidth() != 1 ) printf (" Color=%d", GetLineWidth() ) ;
196
197 if ( GetFillColor() != 0 ) printf (" FillColor=%d", GetFillColor() ) ;
198
199 printf ("\n") ;
200}
201
202
203
204
205
206
Note: See TracBrowser for help on using the repository browser.