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

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