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

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