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

Last change on this file since 763 was 732, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 5.7 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 UInt_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 return (Double_t)(60*(60*fDeg+fMin)+fSec)/3600;
134}
135
136void MGCoordinate::Print()
137{
138 cout << fLabel->GetText()->GetString() << " " << fDeg << "\xb0 " << fMin << "' " << fSec << "\"" << endl;
139}
140
141void MGCoordinate::Set(TGLabel *label, UInt_t val)
142{
143 char txt[20];
144
145 sprintf(txt, "%d", val);
146
147 label->SetText(new TGString(txt));
148}
149
150void MGCoordinate::Set(TGTextEntry *entry, UInt_t val)
151{
152 char txt[20];
153
154 sprintf(txt, "%d", val);
155
156 entry->SetText(txt);
157}
158
159void MGCoordinate::SetVal(const Double_t d)
160{
161 int dms[4];
162 char sign;
163
164 //** ndp int number of decimal places of arcseconds
165 //** angle double angle in radians
166 //** sign char* '+' or '-'
167 //** idmsf int[4] degrees, arcminutes, arcseconds, fraction
168
169 slaDr2af(0, d*D2PI/360.0, &sign, dms);
170
171
172 fDeg = sign=='-'?-dms[0]:dms[0];
173 fMin = dms[1];
174 fSec = dms[2];
175
176 Set(fLabelDeg, fDeg);
177 Set(fLabelMin, fMin);
178 Set(fLabelSec, fSec);
179
180 // Set(fTextEntryDeg, fDeg);
181 // Set(fTextEntryMin, fMin);
182 // Set(fTextEntrySec, fSec);
183}
184
185
186Bool_t MGCoordinate::Set(TGLabel *label, UInt_t &val, TGTextEntry *entry)
187{
188 UInt_t newval = atoi(entry->GetText());
189
190 Bool_t ok = (entry == fTextEntryDeg || newval<60);
191
192 if (ok)
193 {
194 val = newval;
195 Set(label, val);
196 }
197
198 Set(entry, val);
199
200 return ok;
201}
202
203Bool_t MGCoordinate::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
204{
205 if (GET_MSG(msg)!=kC_TEXTENTRY || GET_SUBMSG(msg)!=kTE_ENTER)
206 return kTRUE;
207
208 // kC_TEXTENTRY = 4,
209 // kTE_TEXTCHANGED = 1,
210 // kTE_ENTER = 2,
211
212 switch (mp1)
213 {
214 case IDM_kDeg:
215 if (!Set(fLabelDeg, fDeg, fTextEntryDeg))
216 fTextEntryDeg->SelectAll();
217 else
218 {
219 fTextEntryMin->SetFocus();
220 fTextEntryMin->SelectAll();
221 }
222 return kTRUE;
223
224 case IDM_kMin:
225 if(!Set(fLabelMin, fMin, fTextEntryMin))
226 fTextEntryMin->SelectAll();
227 else
228 {
229 fTextEntrySec->SetFocus();
230 fTextEntrySec->SelectAll();
231 }
232 return kTRUE;
233
234 case IDM_kSec:
235 if (!Set(fLabelSec, fSec, fTextEntrySec))
236 fTextEntrySec->SelectAll();
237 else
238 {
239 fTextEntryDeg->SetFocus();
240 fTextEntryDeg->SelectAll();
241 }
242 return kTRUE;
243 }
244
245 return kTRUE;
246}
247
Note: See TracBrowser for help on using the repository browser.