1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
// Copyright (C) 1999-2016
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include "contour.h"
#include "base.h"
#include "context.h"
// ContourLevel
ContourLevel::ContourLevel(Base* pp, double lev, const char* cc, int ww,
int dd, int* dl)
{
parent_ = pp;
gc_ = parent_->contourGC;
level_ = lev;
colorName_ = dupstr(cc);
color_ = parent_->getColor(colorName_);
lineWidth_ = ww;
dash_ = dd;
dlist_[0] = dl[0];
dlist_[1] = dl[1];
previous_ = NULL;
next_ = NULL;
}
ContourLevel::~ContourLevel()
{
if (colorName_)
delete [] colorName_;
}
void ContourLevel::list(ostream& str, FitsImage* fits,
Coord::CoordSystem sys, Coord::SkyFrame sky)
{
if (lcontour_.head()) {
str << "level=" << level_ << ' ';
if (strncmp("green", colorName_, 5) || dash_ != 0 ||
dlist_[0] != 8 || dlist_[1] != 3 || lineWidth_ != 1) {
if (strncmp("green", colorName_, 5))
str << "color=" << colorName_ << ' ';
if (lineWidth_ != 1)
str << "width=" << lineWidth_ << ' ';
if (dash_ != 0)
str << "dash=" << dash_ << ' ';
if (dlist_[0] != 8 || dlist_[1] != 3)
str << "dashlist=" << dlist_[0] << ' ' << dlist_[1] << ' ';
}
str << endl;
do
lcontour_.current()->list(str, fits, sys, sky);
while (lcontour_.next());
}
}
void ContourLevel::render(Pixmap pmap, Coord::InternalSystem sys,
const BBox& bbox)
{
if (lcontour_.head()) {
do
lcontour_.current()->render(pmap, sys, bbox);
while (lcontour_.next());
}
}
void ContourLevel::ps(int mode)
{
if (lcontour_.head()) {
do
lcontour_.current()->ps(mode);
while (lcontour_.next());
}
}
void ContourLevel::updateCoords(const Matrix& mx)
{
if (lcontour_.head()) {
do
lcontour_.current()->updateCoords(mx);
while (lcontour_.next());
}
}
void ContourLevel::setColor(const char* clr)
{
if (colorName_)
delete [] colorName_;
colorName_ = dupstr(clr);
color_ = parent_->getColor(colorName_);
}
#ifdef MAC_OSX_TK
void ContourLevel::macosx()
{
if (lcontour_.head()) {
do
lcontour_.current()->macosx();
while (lcontour_.next());
}
}
#endif
#ifdef __WIN32
void ContourLevel::win32()
{
if (lcontour_.head()) {
do
lcontour_.current()->win32();
while (lcontour_.next());
}
}
#endif
// Contour
Contour::Contour(ContourLevel* cc)
{
parent_ = cc;
base_ = cc->parent_;
previous_ = NULL;
next_ = NULL;
}
Contour::~Contour()
{
}
void Contour::list(ostream& str, FitsImage* fits,
Coord::CoordSystem sys, Coord::SkyFrame sky)
{
if (lvertex_.head())
str << '(' << endl;
do {
str << ' ';
fits->listFromRef(str, lvertex_.current()->vector, sys, sky, Coord::DEGREES);
str << endl;
}
while (lvertex_.next());
str << ')' << endl;
}
void Contour::render(Pixmap pmap, Coord::InternalSystem sys, const BBox& bbox)
{
// bbox is in sys coords
if (lvertex_.head()) {
XSetForeground(base_->display, parent_->gc_, parent_->color_);
int ww = parent_->lineWidth_>=1 ? parent_->lineWidth_ : 1;
if (!parent_->dash_)
XSetLineAttributes(base_->display, parent_->gc_,
ww, LineSolid, CapButt, JoinMiter);
else {
char dl[2];
dl[0] = parent_->dlist_[0];
dl[1] = parent_->dlist_[1];
XSetDashes(base_->display, parent_->gc_, 0, dl, 2);
XSetLineAttributes(base_->display, parent_->gc_,
ww, LineOnOffDash, CapButt, JoinMiter);
}
Vector u1 = lvertex_.current()->vector;
while (lvertex_.next()) {
Vector u2 = lvertex_.current()->vector;
Vector v1 = base_->mapFromRef(u1,sys);
Vector v2 = base_->mapFromRef(u2,sys);
if (bbox.isIn(v1) || bbox.isIn(v2))
XDrawLine(base_->display, pmap, parent_->gc_,
(int)v1[0], (int)v1[1], (int)v2[0], (int)v2[1]);
u1 = u2;
}
}
}
void Contour::ps(int mode)
{
if (!lvertex_.head())
return;
ostringstream str;
switch ((Widget::PSColorSpace)mode) {
case Widget::BW:
case Widget::GRAY:
psColorGray(base_->getXColor(parent_->colorName_), str);
str << " setgray";
break;
case Widget::RGB:
psColorRGB(base_->getXColor(parent_->colorName_), str);
str << " setrgbcolor";
break;
case Widget::CMYK:
psColorCMYK(base_->getXColor(parent_->colorName_), str);
str << " setcmykcolor";
break;
}
str << endl;
if (!parent_->dash_)
str << parent_->lineWidth_ << " setlinewidth" << endl << "[] 0 setdash";
else {
str << parent_->lineWidth_ << " setlinewidth" << endl
<< '[' << parent_->dlist_[0] << ' ' << parent_->dlist_[1]
<< "] 0 setdash";
}
str << endl;
Vector v1 = base_->mapFromRef(lvertex_.current()->vector,Coord::CANVAS);
str << "newpath " << endl
<< v1.TkCanvasPs(base_->canvas) << " moveto" << endl;
while (lvertex_.next()) {
Vector vv = base_->mapFromRef(lvertex_.current()->vector,Coord::CANVAS);
str << vv.TkCanvasPs(base_->canvas) << " lineto" << endl;
}
str << "stroke" << endl << ends;
Tcl_AppendResult(base_->interp, str.str().c_str(), NULL);
}
void Contour::updateCoords(const Matrix& mx)
{
if (lvertex_.head()) {
do {
Vector& vv = lvertex_.current()->vector;
vv *= mx;
}
while (lvertex_.next());
}
}
#ifdef MAC_OSX_TK
void Contour::macosx()
{
if (lvertex_.head()) {
macosxColor(base_->getXColor(parent_->colorName_));
macosxWidth(parent_->lineWidth_);
if (parent_->dash_) {
float dl[2];
dl[0] = parent_->dlist_[0];
dl[1] = parent_->dlist_[1];
macosxDash(dl,2);
}
else
macosxDash(NULL,0);
Vector u1 = lvertex_.current()->vector;
while (lvertex_.next()) {
Vector u2 = lvertex_.current()->vector;
Vector v1 = base_->mapFromRef(u1,Coord::CANVAS);
Vector v2 = base_->mapFromRef(u2,Coord::CANVAS);
macosxDrawLine(v1,v2);
u1 = u2;
}
}
}
#endif
#ifdef __WIN32
void Contour::win32()
{
if (lvertex_.head()) {
win32Color(base_->getXColor(parent_->colorName_));
win32Width(parent_->lineWidth_);
if (parent_->dash_) {
float dl[2];
dl[0] = parent_->dlist_[0];
dl[1] = parent_->dlist_[1];
win32Dash(dl,2);
}
else
win32Dash(NULL,0);
Vector u1 = lvertex_.current()->vector;
while (lvertex_.next()) {
Vector u2 = lvertex_.current()->vector;
Vector v1 = base_->mapFromRef(u1,Coord::CANVAS);
Vector v2 = base_->mapFromRef(u2,Coord::CANVAS);
win32DrawLine(v1,v2);
u1 = u2;
}
}
}
#endif
|