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

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