source: trunk/MagicSoft/Cosy/gui/MGCoordinate.cc@ 8125

Last change on this file since 8125 was 7794, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 6.4 KB
Line 
1//
2// This File contains the definition of the MGCoordinate-class
3//
4// Author: Thomas Bretz
5// Version: V1.0 (1-8-2000)
6
7#include "MGCoordinate.h"
8
9#include <stdlib.h> // atoi
10#include <iostream.h> // cout
11
12#include <TSystem.h>
13#include <TGLabel.h>
14#include <TGTextEntry.h>
15
16#include "slalib.h"
17#include "slamac.h"
18
19ClassImp(MGCoordinate);
20
21enum {
22 IDM_kDeg,
23 IDM_kMin,
24 IDM_kSec
25};
26
27MGCoordinate::MGCoordinate(const TGWindow* p, const Int_t type=kETypeDeg,
28 const Int_t flag, const char *txt,
29 const Int_t deg, const UInt_t min, const UInt_t sec)
30: TGFrame(p, 119, flag==1?76:46-(TString(txt).IsNull()?23:0), kSunkenFrame|kFixedSize), fSign('+'), fDeg(deg), fMin(min), fSec(sec), fLabel(0)
31{
32 fList = new MGList;
33
34 const Int_t offset = TString(txt).IsNull() ? 23 : 0;
35
36 // p = pointer to MainFrame (not owner)
37 if (flag==1)
38 {
39 fTextEntryDeg = new TGTextEntry(this, "****", IDM_kDeg);
40 fTextEntryMin = new TGTextEntry(this, "***", IDM_kMin);
41 fTextEntrySec = new TGTextEntry(this, "***", IDM_kSec);
42 // fTextEntryDeg->SetAlignment(kTextCenterX);
43 // fTextEntryMin->SetAlignment(kTextCenterX);
44 // fTextEntrySec->SetAlignment(kTextCenterX);
45 fTextEntryDeg->Move( 7, 26-offset);
46 fTextEntryMin->Move(47, 26-offset);
47 fTextEntrySec->Move(81, 26-offset);
48 fTextEntryDeg->MapWindow();
49 fTextEntryMin->MapWindow();
50 fTextEntrySec->MapWindow();
51 fList->Add(fTextEntrySec);
52 fList->Add(fTextEntryMin);
53 fList->Add(fTextEntryDeg);
54
55 Set(fTextEntryDeg, fDeg);
56 Set(fTextEntryMin, fMin);
57 Set(fTextEntrySec, fSec);
58 }
59
60 const int ypos = (flag==1?56:26)-offset;
61
62 fLabelDeg = new TGLabel(this, "*****");
63 fLabelMin = new TGLabel(this, "****");
64 fLabelSec = new TGLabel(this, "****");
65 fLabelDeg->SetTextJustify(kTextRight);
66 fLabelMin->SetTextJustify(kTextRight);
67 fLabelSec->SetTextJustify(kTextRight);
68 fLabelDeg->Move(13, ypos);
69 fLabelMin->Move(53, ypos);
70 fLabelSec->Move(87, ypos);
71 fLabelDeg->MapWindow();
72 fLabelMin->MapWindow();
73 fLabelSec->MapWindow();
74 fList->Add(fLabelSec);
75 fList->Add(fLabelDeg);
76 fList->Add(fLabelMin);
77
78 Set(fLabelDeg, fDeg);
79 Set(fLabelMin, fMin);
80 Set(fLabelSec, fSec);
81
82 if (!TString(txt).IsNull())
83 {
84 fLabel = new TGLabel(this, txt);
85 fLabel->SetTextJustify(kTextLeft);
86 fLabel->Move(4, 4);
87 fLabel->MapWindow();
88 fList->Add(fLabel);
89 }
90
91 TGLabel *label;
92
93 const char *deg = type==kETypeDeg ? "\xb0" : "h";
94 const char *min = type==kETypeDeg ? "'" : "m";
95 const char *sec = type==kETypeDeg ? "\"" : "s";
96
97 if (flag==1)
98 {
99 label = new TGLabel(this, deg);
100 label->SetTextJustify(kTextLeft);
101 label->Move(37, 29-offset);
102 label->MapWindow();
103 fList->Add(label);
104
105 label = new TGLabel(this, min);
106 label->SetTextJustify(kTextLeft);
107 label->Move(71, 29-offset);
108 label->MapWindow();
109 fList->Add(label);
110
111 label = new TGLabel(this, sec);
112 label->SetTextJustify(kTextLeft);
113 label->Move(107, 29-offset);
114 label->MapWindow();
115 fList->Add(label);
116 }
117
118 label = new TGLabel(this, deg);
119 label->SetTextJustify(kTextLeft);
120 label->Move(39, ypos);
121 label->MapWindow();
122 fList->Add(label);
123
124 label = new TGLabel(this, min);
125 label->SetTextJustify(kTextLeft);
126 label->Move(73, ypos);
127 label->MapWindow();
128 fList->Add(label);
129
130 label = new TGLabel(this, sec);
131 label->SetTextJustify(kTextLeft);
132 label->Move(107, ypos);
133 label->MapWindow();
134 fList->Add(label);
135
136 MapWindow();
137}
138
139MGCoordinate::~MGCoordinate()
140{
141 delete fList;
142}
143
144Double_t MGCoordinate::GetVal() const
145{
146 const Int_t sgn = fSign=='-' ? -1 : 1;
147
148 return (Double_t)sgn*(60*(60*fDeg+fMin)+fSec)/3600;
149}
150
151void MGCoordinate::Print()
152{
153 if (fLabel)
154 cout << fLabel->GetText()->GetString() << " ";
155 cout << fSign << fDeg << "\xb0 " << fMin << "' " << fSec << "\"" << endl;
156}
157
158void MGCoordinate::Set(TGLabel *label, Int_t val)
159{
160 char txt[20];
161
162 sprintf(txt, "%s%d", label == fLabelDeg && fSign=='-'?"-":"", val);
163
164 label->SetText(new TGString(txt));
165}
166
167void MGCoordinate::Set(TGTextEntry *entry, Int_t val)
168{
169 char txt[20];
170
171 sprintf(txt, "%s%d", entry == fTextEntryDeg && fSign=='-'?"-":"", val);
172
173 entry->SetText(txt);
174}
175
176void MGCoordinate::SetVal(const Double_t d)
177{
178 int dms[4];
179 char sign;
180
181 //** ndp int number of decimal places of arcseconds
182 //** angle double angle in radians
183 //** sign char* '+' or '-'
184 //** idmsf int[4] degrees, arcminutes, arcseconds, fraction
185
186 slaDr2af(0, d*D2PI/360.0, &sign, dms);
187
188 fSign = sign;
189 fDeg = dms[0];
190 fMin = dms[1];
191 fSec = dms[2];
192
193 Set(fLabelDeg, fDeg);
194 Set(fLabelMin, fMin);
195 Set(fLabelSec, fSec);
196
197 // Set(fTextEntryDeg, fDeg);
198 // Set(fTextEntryMin, fMin);
199 // Set(fTextEntrySec, fSec);
200}
201
202
203Bool_t MGCoordinate::Set(TGLabel *label, Int_t &val, TGTextEntry *entry)
204{
205 TString text = entry->GetText();
206
207 Int_t newval = abs(atoi(text));
208
209 Bool_t ok = (entry == fTextEntryDeg || (newval>=0 && newval<60));
210
211 if (entry==fTextEntryDeg)
212 fSign = text.Contains("-") ? '-' : '+';
213
214 if (ok)
215 {
216 val = newval;
217 Set(label, val);
218 }
219
220 Set(entry, val);
221
222 return ok;
223}
224
225Bool_t MGCoordinate::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
226{
227 if (GET_MSG(msg)!=kC_TEXTENTRY || GET_SUBMSG(msg)!=kTE_ENTER)
228 return kTRUE;
229
230 // kC_TEXTENTRY = 4,
231 // kTE_TEXTCHANGED = 1,
232 // kTE_ENTER = 2,
233
234 switch (mp1)
235 {
236 case IDM_kDeg:
237 if (!Set(fLabelDeg, fDeg, fTextEntryDeg))
238 fTextEntryDeg->SelectAll();
239 else
240 {
241 fTextEntryMin->SetFocus();
242 fTextEntryMin->SelectAll();
243 }
244 return kTRUE;
245
246 case IDM_kMin:
247 if(!Set(fLabelMin, fMin, fTextEntryMin))
248 fTextEntryMin->SelectAll();
249 else
250 {
251 fTextEntrySec->SetFocus();
252 fTextEntrySec->SelectAll();
253 }
254 return kTRUE;
255
256 case IDM_kSec:
257 if (!Set(fLabelSec, fSec, fTextEntrySec))
258 fTextEntrySec->SelectAll();
259 else
260 {
261 fTextEntryDeg->SetFocus();
262 fTextEntryDeg->SelectAll();
263 }
264 return kTRUE;
265 }
266
267 return kTRUE;
268}
269
Note: See TracBrowser for help on using the repository browser.