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

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