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

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