Changeset 913 for trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc
- Timestamp:
- 08/23/01 14:40:17 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc
r912 r913 11 11 #include <TArc.h> 12 12 #include <TLine.h> 13 #include <TText.h> 13 14 #include <TList.h> 14 15 #include <TCanvas.h> … … 94 95 } 95 96 97 void MGSkyPosition::InitText() 98 { 99 fText = new TText(105, 105, ""); 100 fText->SetFillStyle(4000); // transparent 101 fText->SetTextAlign(33); // right, top 102 fText->SetTextColor(10); // white 103 fText->Draw(); 104 105 fList->Add(fText); 106 } 107 96 108 void MGSkyPosition::DrawCoordinateSystem() 97 109 { … … 105 117 arc.DrawArc(0, 0, 22.5); 106 118 119 // 120 // FIXME? Use TAxis? 121 // 107 122 TLine line; 108 123 line.SetLineColor(1); // black … … 110 125 line.DrawLine(-95, 0, 95, 0); 111 126 line.DrawLine( 0, -95, 0, 95); 127 128 TText text; 129 text.SetTextAlign(22); // centered, centered (s.TAttText) 130 text.SetTextColor(13); // dark gray 131 text.DrawText(0.71*22.5, 0.71*22.5, "22.5\xb0"); 132 text.DrawText(0.71*45.0, 0.71*45.0, "45\xb0"); 133 text.DrawText(0.71*67.5, 0.71*67.5, "67.5\xb0"); 134 text.DrawText(0.71*90.0, 0.71*90.0, "90\xb0"); 135 136 text.SetTextAlign(22); // centered, centered (s.TAttText) 137 text.SetTextColor(1); // black 138 139 text.DrawText(0, 102, "N (0\xb0)"); 140 text.DrawText(0, -102, "S (180\xb0)"); 141 142 text.SetTextAngle(270); 143 text.DrawText( 102, 0, "E (90\xb0)"); 144 145 text.SetTextAngle(90); 146 text.DrawText(-102, 0, "W (270\xb0)"); 112 147 } 113 148 … … 133 168 } 134 169 135 MGSkyPosition::MGSkyPosition(const TGWindow* p, const Int_t w, const Int_t h) 136 : TRootEmbeddedCanvas("SkyPosition", p, w-1, h-1, kRaisedFrame),//, 0) //234, 76, kFixedSize) 137 fModified(kFALSE) 138 { 139 fCanvas = GetCanvas(); 140 141 fCanvas->SetFillColor(39); // s. TAttFill 142 fCanvas->Range(-100, -100, 100, 100); 143 144 fList = new TList; 145 fList->SetOwner(); 146 170 MGSkyPosition::MGSkyPosition(const TGWindow* p, const UInt_t w) 171 : MGEmbeddedCanvas("SkyPosition", p, w, 110) 172 { 147 173 DrawCoordinateSystem(); 174 InitPlanets(); 148 175 InitPosition(); 149 InitPlanets(); 150 151 Resize(w, h); //GetDefaultSize()); // ??? 152 MapSubwindows(); 176 InitText(); 177 InitCanvas(); 153 178 } 154 179 155 180 MGSkyPosition::~MGSkyPosition() 156 181 { 157 delete fList;158 182 delete fSlalib; 159 183 … … 161 185 } 162 186 163 void MGSkyPosition::SetLin1( int x, int y)187 void MGSkyPosition::SetLin1(Float_t x, Float_t y) 164 188 { 165 189 fLin1a->SetX2(x); … … 169 193 } 170 194 171 void MGSkyPosition::SetLin2( int x1, int y1, int x2, int y2)195 void MGSkyPosition::SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2) 172 196 { 173 197 fLin2->SetX1(x1); … … 177 201 } 178 202 179 void MGSkyPosition:: DrawPosition(Float_t zd, Float_t az)203 void MGSkyPosition::UpdatePosition(Float_t zd, Float_t az) 180 204 { 181 205 static int X=~0; … … 187 211 const float c = cos(rad); 188 212 189 const int x = (int)(s*zd); 190 const int y = (int)(c*zd); 191 192 if (X==x && Y==y) 213 const float x = s*zd; 214 const float y = c*zd; 215 216 const int pixx = (int)(x/fPix); 217 const int pixy = (int)(y/fPix); 218 219 if (X==pixx && Y==pixy) 193 220 return; 194 221 195 X = x;196 Y = y;197 198 const int dx = (int)(s*4);199 const int dy = (int)(c*4);200 201 SetLin1(s*95 , c*95);222 X = pixx; 223 Y = pixy; 224 225 const float dx = s*4.; 226 const float dy = c*4.; 227 228 SetLin1(s*95., c*95.); 202 229 SetLin2(x+dy, y-dx, x-dy, y+dx); 203 230 204 fModified = kTRUE; 205 } 231 SetModified(); 232 } 233 234 void MGSkyPosition::UpdateText(Float_t x, Float_t y) 235 { 236 static int X = ~0; 237 static int Y = ~0; 238 239 int xd = (int)floor(x); 240 int yd = (int)floor(y); 241 x *= 60.; 242 y *= 60.; 243 244 int fx = (int)floor(x*10.); 245 int fy = (int)floor(y*10.); 246 247 if (X==fx && Y==fy) 248 return; 249 250 X = fx; 251 Y = fy; 252 253 float/*int*/ xm = /*(int)floor*/(fmod(fabs(x), 60.)); 254 float/*int*/ ym = /*(int)floor*/(fmod(fabs(y), 60.)); 255 256 char txt[100]; 257 sprintf(txt, "Zd=%d\xb0%02.1f'\nAz=%d\xb0%02.1f'", 258 xd, xm, yd, ym); 259 260 fText->SetText(fText->GetX(), fText->GetY(), txt); 261 262 SetModified(); 263 } 264 206 265 207 266 void MGSkyPosition::Update(ZdAz &pos) … … 212 271 fSlalib->SetMjd2Now(); 213 272 214 DrawPlanet(kESun, fSun); 215 DrawPlanet(kEMoon, fMoon); 216 DrawPlanet(kEJupiter, fJupiter); 217 DrawPlanet(kEVenus, fVenus); 218 DrawPlanet(kEMars, fMars); 219 220 DrawPosition(pos.Zd(), pos.Az()); 221 222 if (!fModified) 223 return; 224 225 // FIXME: Sometimes (if the canvas couldn't be created correctly: 226 // X11 Pixmap error) Update hangs the Gui system. 227 228 fCanvas->Modified(); 229 fCanvas->Update(); 230 231 fModified = kFALSE; 232 } 233 234 void MGSkyPosition::DrawPlanet(Int_t planet, TArc *arc) 273 UpdatePlanet(kESun, fSun); 274 UpdatePlanet(kEMoon, fMoon); 275 UpdatePlanet(kEJupiter, fJupiter); 276 UpdatePlanet(kEVenus, fVenus); 277 UpdatePlanet(kEMars, fMars); 278 279 UpdatePosition(pos.Zd(), pos.Az()); 280 UpdateText(pos.Zd(), pos.Az()); 281 282 UpdateCanvas(); 283 } 284 285 void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc) 235 286 { 236 287 // … … 249 300 const float deg = 360.0/D2PI*zdaz.Zd(); 250 301 251 const int x = (int)(s*deg); 252 const int y = (int)(c*deg); 253 254 if (fX[planet]==x && fY[planet]==y) 302 const float x = s*deg; 303 const float y = c*deg; 304 305 const int pixx = (int)(x/fPix); 306 const int pixy = (int)(y/fPix); 307 308 if (fX[planet]==pixx && fY[planet]==pixy) 255 309 return; 256 310 257 fX[planet] = x;258 fY[planet] = y;311 fX[planet] = pixx; 312 fY[planet] = pixy; 259 313 260 314 // … … 264 318 arc->SetY1(y); 265 319 266 fModified = kTRUE;320 SetModified(); 267 321 268 322 if (planet!=kESun) … … 272 326 cout << " Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl; 273 327 274 fSunL[0]->SetX1(x- 4); fSunL[0]->SetX2(x+4);275 fSunL[1]->SetX1(x- 3); fSunL[1]->SetX2(x+3);276 fSunL[2]->SetX1(x- 3); fSunL[2]->SetX2(x+3);277 fSunL[3]->SetX1(x ); fSunL[3]->SetX2(x);278 279 fSunL[0]->SetY1(y ); fSunL[0]->SetY2(y);280 fSunL[1]->SetY1(y- 3); fSunL[1]->SetY2(y+3);281 fSunL[2]->SetY1(y+ 3); fSunL[2]->SetY2(y-3);282 fSunL[3]->SetY1(y- 4); fSunL[3]->SetY2(y+4);283 } 328 fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5); 329 fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5); 330 fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5); 331 fSunL[3]->SetX1(x); fSunL[3]->SetX2(x); 332 333 fSunL[0]->SetY1(y); fSunL[0]->SetY2(y); 334 fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5); 335 fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5); 336 fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5); 337 }
Note:
See TracChangeset
for help on using the changeset viewer.