File: cbgrid.C

package info (click to toggle)
saods9 8.0.1+repack-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 20,052 kB
  • sloc: cpp: 67,186; tcl: 65,707; ansic: 3,983; xml: 1,375; sh: 468; makefile: 120; perl: 68
file content (211 lines) | stat: -rw-r--r-- 5,121 bytes parent folder | download | duplicates (2)
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
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#include "cbgrid.h"
#include "colorbarbase.h"
#include "util.h"

extern "C" {
  #include "ast.h"
}

extern Grid2dBase* astGrid2dPtr;

CBGrid::CBGrid(Widget* p, int cc, double* ll) 
  : Grid2dBase(p), cnt_(cc), lut_(ll)
{
  ColorbarBaseOptions* opts = 
    (ColorbarBaseOptions*)(((ColorbarBase*)parent_)->options);

  ostringstream str;

  // basics
  str << "Grid=0, DrawAxes=0, MinTickLen(1)=0, MinTickLen(2)=0, Colour(ticks)=0, Width(ticks)=.5, Style(ticks)=0, Border=1, Colour(border)=0, Width(border)=.5, Style(border)=0, Labelling=exterior, Colour(numlab)=0, TextLab=0, DrawTitle=0";

  if (!opts->orientation) {
    // horizontal
    str << ", Edge(1)=top, Edge(2)=left, LabelUp(1)=1, MajTickLen(1)=-.15, MajTickLen(2)=0, NumLab(1)=1, NumLab(2)=0, NumLabGap(1)=.5";
  }
  else {
    // vertical
    str << ", Edge(1)=bottom, Edge(2)=right, LabelUp(2)=1, MajTickLen(1)=0, MajTickLen(2)=-.15, NumLab(1)=0, NumLab(2)=1, NumLabGap(2)=.5";
  }

  // font
  {
    char* fn = opts->font;
    int fz = opts->fontSize;
    char* fw = opts->fontWeight;
    char* fs = opts->fontSlant;
    int ff;
    if (!(strncmp(fn,"times",4) || strncmp(fw,"normal",4) || strncmp(fs,"roman",4)))
      ff = 1;
    else if (!(strncmp(fn,"helvetica",4) || strncmp(fw,"normal",4) || strncmp(fs,"roman",4)))
      ff = 2;
    else if (!(strncmp(fn,"courier",4) || strncmp(fw,"normal",4) || strncmp(fs,"roman",4)))
      ff = 4;
    else if (!(strncmp(fn,"times",4) || strncmp(fw,"bold",4) || strncmp(fs,"roman",4)))
      ff = 11;
    else if (!(strncmp(fn,"helvetica",4) || strncmp(fw,"bold",4) || strncmp(fs,"roman",4)))
      ff = 12;
    else if (!(strncmp(fn,"courier",4) || strncmp(fw,"bold",4) || strncmp(fs,"roman",4)))
      ff = 14;
    else if (!(strncmp(fn,"times",4) || strncmp(fw,"normal",4) || strncmp(fs,"italic",4)))
      ff = 21;
    else if (!(strncmp(fn,"helvetica",4) || strncmp(fw,"normal",4) || strncmp(fs,"italic",4)))
      ff = 22;
    else if (!(strncmp(fn,"courier",4) || strncmp(fw,"normal",4) || strncmp(fs,"italic",4)))
      ff = 24;
    else if (!(strncmp(fn,"times",4) || strncmp(fw,"bold",4) || strncmp(fs,"italic",4)))
      ff = 31;
    else if (!(strncmp(fn,"helvetica",4) || strncmp(fw,"bold",4) || strncmp(fs,"italic",4)))
      ff = 32;
    else if (!(strncmp(fn,"courier",4) || strncmp(fw,"bold",4) || strncmp(fs,"italic",4)))
      ff = 34;
    else
      ff = 1;
    str << ", Font(numlab)=" << ff << ", Size(numlab)=" << fz << ends;
  }

  option_ = dupstr(str.str().c_str());
}

int CBGrid::render()
{
  pixmap_ = ((ColorbarBase*)parent_)->pixmap;
  gridGC_ = ((ColorbarBase*)parent_)->gridGC_;
  return doit(X11);
}

int CBGrid::ps(int mode, int x, int y)
{
  matrix_ =  Translate(x,y);
  mode_ = mode;

  return doit(PS);
}

#ifdef MAC_OSX_TK
int CBGrid::macosx(int x, int y)
{
  matrix_ =  Translate(x,y);

  return doit(MACOSX);
}
#endif

#ifdef __WIN32
int CBGrid::win32(int x, int y)
{
  matrix_ =  Translate(x,y);

  return doit(GWIN32);
}
#endif

int CBGrid::doit(RenderMode rm)
{
  ColorbarBaseOptions* opts = 
    (ColorbarBaseOptions*)(((ColorbarBase*)parent_)->options);

  astClearStatus; // just to make sure
  astBegin; // start memory management

  AstFrameSet* frameSet = NULL;
  AstCmpMap* cmp = NULL;
  AstLutMap* aa = NULL;
  AstUnitMap* bb = NULL;
  AstPlot* plot = NULL;

  if (!(frameSet = astFrameSet(astFrame(2,"Domain=WIDGET"),"")))
    goto error;

  if (!(bb = astUnitMap(1,"%s", "")))
    goto error;

  if (!opts->orientation) {
    if (!(aa = astLutMap(cnt_, lut_, 0, double(opts->width)/(cnt_-1), "%s", "")))
      goto error;
    if (!(cmp = astCmpMap(aa, bb, 0, "%s", "")))
      goto error;
  }
  else {
    if (!(aa = astLutMap(cnt_, lut_, 0, double(opts->height)/(cnt_-1), "%s", "")))
      goto error;
    if (!(cmp = astCmpMap(bb, aa, 0, "%s", "")))
      goto error;
  }

  astAddFrame(frameSet, AST__CURRENT, cmp, astFrame(2, "Domain=LUT"));

  astSet(frameSet,"Title=%s", " ");

  if (0) {
    int status = astStatus;
    astClearStatus;
    astShow(frameSet);
    astSetStatus(status);
  }

  // create astPlot
  float gbox[4];
  double pbox[4];

  int ww,hh,zz;
  if (!opts->orientation) {
    ww = opts->width;
    hh = opts->size;
  }
  else {
    ww = opts->size;
    hh = opts->height;
  }
  zz =0;

  switch (rm) {
  case X11:
    ww -= 1;
    hh -= 1;
    break;
  case PS:
    zz = 1;
    break;
  case MACOSX:
    break;
  case GWIN32:
    break;
  }

  if (!opts->orientation) {
    gbox[0] = pbox[0] = 0;
    gbox[1] = pbox[1] = zz;
    gbox[2] = pbox[2] = ww;
    gbox[3] = pbox[3] = hh;
  }
  else {
    gbox[0] = 0;
    gbox[1] = zz;
    gbox[2] = ww;
    gbox[3] = hh;

    pbox[0] = zz;
    pbox[1] = hh;
    pbox[2] = ww;
    pbox[3] = 0;
  }

  plot = astPlot(frameSet, gbox, pbox, "%s", option_);

  // and now create astGrid
  astGrid2dPtr = this;
  renderMode_ = rm;
  astGrid(plot);

  astEnd; // now, clean up memory
  return 1;

error:
  astEnd;
  return 0;
}