00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stdlib.h>
00012
00013 #include "cd.h"
00014 #include "wd.h"
00015 #include "xyobj.h"
00016 #include "xypos.h"
00017
00018 const char* xy_id_xypos_cpp="$Id: xypos.cpp,v 1.14 1999/07/14 13:04:11 camilo Exp $";
00019
00020 void XYPosition::set (XYCoordinate x, XYCoordinate y)
00021 {
00022 *_x = x;
00023 *_y = y;
00024 }
00025
00026 void XYPosition::getX (int* xr, const XYObject* org) const
00027 {
00028
00029 int x1, x2, y1, y2;
00030 if (org)
00031 org -> getViewport(x1, x2, y1, y2);
00032
00033 double x, y;
00034
00035 switch (_x ->type())
00036 {
00037 case XYCoordinate::pixel:
00038
00039 _x -> get(xr);
00040
00041 return;
00042
00043 case XYCoordinate::world:
00044
00045 _x -> get(&x);
00046 if (org)
00047 *xr = x1 + (int) (x * (x2 - x1));
00048
00049 return;
00050
00051 default:
00052 if (_x -> reference() == 0)
00053 {
00054 *xr = 0;
00055 return;
00056 }
00057
00058 const XYObject* ref = _x -> reference();
00059
00060
00061 ref -> position(&x, &y);
00062
00063 int dir = _x -> direction();
00064
00065 if (x && (dir == XYCoordinate::left || dir == XYCoordinate::right))
00066 {
00067 XYPosition* t = (XYPosition *) this;
00068
00069
00070 int bx1, bx2, by1, by2;
00071 ref -> boundingBox (bx1, by1, bx2, by2);
00072
00073
00074 int oldtype = _x -> type();
00075
00076
00077
00078 t -> _x -> type(XYCoordinate::pixel);
00079
00080
00081 t -> _x -> set(0);
00082
00083
00084 int obx1, obx2, oby1, oby2;
00085 org -> boundingBox (obx1, oby1, obx2, oby2);
00086
00087
00088 t -> _x -> type(oldtype);
00089
00090
00091 if (dir == XYCoordinate::left)
00092 *xr = bx1 - _x -> gap() - obx2;
00093 else
00094 *xr = bx2 + _x -> gap() - (obx1 - 1);
00095
00096 return;
00097 }
00098 }
00099 }
00100
00101 void XYPosition::getX (double* xr, const XYObject* org) const
00102 {
00103 org -> setWindow();
00104
00105
00106 int x1, x2, y1, y2;
00107 if (org)
00108 org -> getViewport(x1, x2, y1, y2);
00109
00110 int x, y;
00111
00112 switch (_x -> type())
00113 {
00114 case XYCoordinate::pixel:
00115
00116 _x -> get(&x);
00117 if (org)
00118 *xr = ((double)(x - x1) / (double)(x2 - x1));
00119
00120 return;
00121
00122 case XYCoordinate::world:
00123
00124 _x -> get(xr);
00125
00126 return;
00127
00128 default:
00129 if (_x -> reference() == 0)
00130 {
00131 *xr = 0.0;
00132 return;
00133 }
00134
00135 const XYObject* ref = _x -> reference();
00136
00137
00138 ref -> position(&x, &y);
00139
00140 int dir = _x -> direction();
00141
00142 if (x && (dir == XYCoordinate::left || dir == XYCoordinate::right))
00143 {
00144 XYPosition* t = (XYPosition *) this;
00145
00146
00147 int bx1, bx2, by1, by2;
00148 ref -> boundingBox (bx1, by1, bx2, by2);
00149
00150
00151 int oldtype = _x -> type();
00152
00153
00154
00155 t -> _x -> type(XYCoordinate::pixel);
00156
00157
00158 t -> _x -> set(0);
00159
00160
00161 int obx1, obx2, oby1, oby2;
00162 org -> boundingBox (obx1, oby1, obx2, oby2);
00163
00164
00165 t -> _x -> type(oldtype);
00166
00167
00168 if (dir == XYCoordinate::left)
00169 *xr = ((double) ((bx1 - _x -> gap() - obx2) - x1)
00170 / (double)(x2 - x1));
00171 else
00172 *xr = ((double) ((bx2 + _x -> gap() - (obx1 - 1)) - x1)
00173 / (double)(x2 - x1));
00174
00175 return;
00176 }
00177 }
00178 }
00179
00180 void XYPosition::getX (XYCoordinate*) const
00181 {
00182 }
00183
00184 void XYPosition::getY (int* yr, const XYObject* org) const
00185 {
00186 org -> setWindow();
00187
00188
00189 int x1, x2, y1, y2;
00190 if (org)
00191 org -> getViewport(x1, x2, y1, y2);
00192
00193 double x, y;
00194
00195 switch (_y -> type())
00196 {
00197 case XYCoordinate::pixel:
00198
00199 _y -> get(yr);
00200
00201 return;
00202
00203 case XYCoordinate::world:
00204
00205 _y -> get(&y);
00206 if (org)
00207 *yr = y1 + (int) (y * (y2 - y1));
00208
00209 return;
00210
00211 default:
00212 if (_y -> reference() == 0)
00213 {
00214 *yr = 0;
00215 return;
00216 }
00217
00218 const XYObject* ref = _y -> reference();
00219
00220
00221 ref -> position(&x, &y);
00222
00223 int dir = _y -> direction();
00224
00225 if (y && (dir == XYCoordinate::bottom || dir == XYCoordinate::top))
00226 {
00227 XYPosition* t = (XYPosition *) this;
00228
00229
00230 int bx1, bx2, by1, by2;
00231 ref -> boundingBox (bx1, by1, bx2, by2);
00232
00233
00234 int oldtype = _y -> type();
00235
00236
00237
00238 t -> _y -> type(XYCoordinate::pixel);
00239
00240
00241 t -> _y -> set(0);
00242
00243
00244 int obx1, obx2, oby1, oby2;
00245 org -> boundingBox (obx1, oby1, obx2, oby2);
00246
00247
00248 t -> _y -> type(oldtype);
00249
00250
00251 if (dir == XYCoordinate::bottom)
00252 *yr = by1 - _y -> gap() - oby2;
00253 else
00254 *yr = by2 + _y -> gap() - (oby1 - 1);
00255
00256 return;
00257 }
00258 }
00259 }
00260
00261 void XYPosition::getY (double* yr, const XYObject* org) const
00262 {
00263
00264 int x1, x2, y1, y2;
00265 if (org)
00266 org -> getViewport(x1, x2, y1, y2);
00267
00268 int x, y;
00269 switch (_y -> type())
00270 {
00271 case XYCoordinate::pixel:
00272
00273 _y -> get(&y);
00274 if (org)
00275 *yr = ((double)(y - y1) / (double)(y2 - y1));
00276
00277 return;
00278
00279 case XYCoordinate::world:
00280
00281 _y -> get(yr);
00282
00283 return;
00284
00285 default:
00286 if (_y -> reference() == 0)
00287 {
00288 *yr = 0.0;
00289 return;
00290 }
00291
00292 const XYObject* ref = _y -> reference();
00293
00294
00295 ref -> position(&x, &y);
00296
00297 int dir = _y -> direction();
00298
00299 if (y && (dir == XYCoordinate::bottom || dir == XYCoordinate::top))
00300 {
00301 XYPosition* t = (XYPosition *) this;
00302
00303
00304 int bx1, bx2, by1, by2;
00305 ref -> boundingBox (bx1, by1, bx2, by2);
00306
00307
00308 int oldtype = _y -> type();
00309
00310
00311
00312 t -> _y -> type(XYCoordinate::pixel);
00313
00314
00315 t -> _y -> set(0);
00316
00317
00318 int obx1, obx2, oby1, oby2;
00319 org -> boundingBox (obx1, oby1, obx2, oby2);
00320
00321
00322 t -> _y -> type(oldtype);
00323
00324
00325 if (dir == XYCoordinate::bottom)
00326 *yr = ((double) ((by1 - _y -> gap() - oby2) - y1)
00327 / (double)(y2 - y1));
00328 else
00329 *yr = ((double) ((by2 + _y -> gap() - (oby1 - 1)) - y1)
00330 / (double)(y2 - y1));
00331
00332 return;
00333 }
00334 }
00335 }
00336
00337 void XYPosition::getY (XYCoordinate*) const
00338 {
00339 }
00340
00341