Changeset 959 for trunk/MagicSoft/Mars/mgui/MHexagon.cc
- Timestamp:
- 10/02/01 14:46:56 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mgui/MHexagon.cc
r849 r959 30 30 #include "MHexagon.h" 31 31 32 #include <iostream.h> 33 32 34 #include <TVirtualPad.h> // gPad 33 35 34 36 #include "MGeomPix.h" // GetX 35 37 36 ClassImp(MHexagon) 37 38 MHexagon::MHexagon() 39 { 40 // default constructor for MHexagon 41 38 ClassImp(MHexagon); 39 40 // ------------------------------------------------------------------------ 41 // 42 // default constructor for MHexagon 43 // 44 MHexagon::MHexagon() 45 { 46 } 47 48 // ------------------------------------------------------------------------ 49 // 50 // normal constructor for MHexagon 51 // 52 MHexagon::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 // 61 MHexagon::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 // 73 MHexagon::MHexagon(const MHexagon &hexagon) 74 { 75 ((MHexagon&) hexagon).Copy(*this); 42 76 } 43 77 44 MHexagon::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 50 MHexagon::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 59 MHexagon::MHexagon( const MHexagon &hexagon) 60 { 61 // copy constructor for MHexagon 62 ((MHexagon&) hexagon).Copy(*this) ; 63 } 64 78 // ------------------------------------------------------------------------ 79 // 80 // default destructor for MHexagon 81 // 65 82 MHexagon::~MHexagon() 66 { 67 // default destructor for MHexagon 68 } 69 70 void MHexagon::Copy( TObject &obj ) 71 { 72 // copy this hexagon to hexagon 83 { 84 } 85 86 // ------------------------------------------------------------------------ 87 // 88 // copy this hexagon to hexagon 89 // 90 void MHexagon::Copy(TObject &obj) 91 { 73 92 MHexagon &hex = (MHexagon&) obj; 74 93 … … 77 96 TAttFill::Copy(hex); 78 97 79 hex.fX = fX ; 80 hex.fY = fY ; 81 hex.fD = fD ; 82 } 83 Int_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 121 void MHexagon::DrawHexagon( Float_t x, Float_t y, Float_t d ) 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 // 112 Int_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 // 150 void MHexagon::DrawHexagon(Float_t x, Float_t y, Float_t d) 122 151 { 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 133 void 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 159 void 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 166 void MHexagon::Paint(Option_t * ) 167 { 168 // paint this hexagon with its attribute 169 170 PaintHexagon(fX, fY, fD ) ; 171 } 172 173 174 void MHexagon::PaintHexagon (Float_t inX, Float_t inY, Float_t inD ) 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 // 166 void 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 // 191 void MHexagon::ls(Option_t *) 192 { 193 TROOT::IndentLevel(); 194 Print(); 195 } 196 197 // ------------------------------------------------------------------------ 198 // 199 // paint this hexagon with its attribute 200 // 201 void MHexagon::Paint(Option_t *) 202 { 203 PaintHexagon(fX, fY, fD); 204 } 205 206 // ------------------------------------------------------------------------ 207 // 208 // draw this hexagon with the coordinates 209 // 210 void MHexagon::PaintHexagon(Float_t inX, Float_t inY, Float_t inD) 175 211 { 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 202 void 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 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 // 245 void 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 TracChangeset
for help on using the changeset viewer.