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

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