00001
00002
00003 char *curve_cpp = "$Id: sxy_curve.cpp,v 1.8 2003/01/17 17:43:13 clinio Exp $";
00004
00005
00006
00007 #include <assert.h>
00008 #include <float.h>
00009
00010 #include <xy.h>
00011
00012 #include "sxy_chart.h"
00013 #include "sxy_curve.h"
00014
00015
00016
00017 #define MAX_MASKS 16
00018 #define MAX_SERIES 32
00019
00020
00021
00022
00023
00024 void SXYCurve::remountCurve(void) {
00025 destroyMasks();
00026 destroySeries();
00027 destroyLegend();
00028
00029 createLegend();
00030 createSeries();
00031 createMasks();
00032 }
00033
00034
00035
00036 void SXYCurve::unsetAxis(void) {
00037 SXYChart* cht = getChart();
00038 assert(cht);
00039 if (cht) cht->removeCurve(this);
00040 destroyMasks();
00041 destroySeries();
00042 destroyLegend();
00043 x_axis = NULL;
00044 y_axis = NULL;
00045 }
00046
00047
00048
00049 void SXYCurve::setAxis(SXYAxis* x, SXYAxis* y) {
00050 SXYChart* old_cht = getChart();
00051 x_axis = x;
00052 y_axis = y;
00053 checkAxesConsistency();
00054 SXYChart* new_cht = getChart();
00055 if (old_cht) old_cht->removeCurve(this);
00056 new_cht->insertCurve(this);
00057 remountCurve();
00058 }
00059
00060
00061
00062 SXYCurve::SXYCurve(void) {
00063 title = NULL;
00064 color = CD_BLACK;
00065 x_axis = NULL;
00066 y_axis = NULL;
00067
00068 masks_vector = NULL;
00069 series_vector = NULL;
00070
00071 null_series = NULL;
00072
00073 xy_legend_text = NULL;
00074 xy_legend_mask = NULL;
00075 }
00076
00077
00078
00079 SXYCurve::~SXYCurve() {
00080 if (title != NULL) free(title);
00081 title = NULL;
00082 }
00083
00084
00085
00086 unsigned int SXYCurve::tryPointEditionCallback( unsigned int mask,
00087 unsigned int series, unsigned int n) {
00088 return 0;
00089 }
00090
00091
00092
00093 void SXYCurve::movingPointCallback( unsigned int mask, unsigned int series,
00094 unsigned int n, double x, double y) {
00095 }
00096
00097
00098
00099 unsigned int SXYCurve::editedPointCallback( unsigned int mask,
00100 unsigned int series, unsigned int n, double x, double y) {
00101 return 0;
00102 }
00103
00104
00105
00106 void SXYCurve::setTitleCallback(void) {
00107 }
00108
00109
00110
00111 void SXYCurve::setColorCallback(void) {
00112 unsigned int num_masks = getNumMasks();
00113 for( unsigned int m = 0; m < num_masks; m++ ) {
00114 XYCartesianMask* msk = getMask(m);
00115 msk->color(getColor());
00116 }
00117 }
00118
00119
00120
00121 void SXYCurve::setColor(long int col) {
00122 color = col;
00123 if (xy_legend_mask) xy_legend_mask->color( color );
00124 setColorCallback();
00125 }
00126
00127
00128
00129 long int SXYCurve::getColor(void) {
00130 return color;
00131 }
00132
00133
00134
00135 void SXYCurve::setTitle(const char* txt) {
00136 assert(txt);
00137 if (title != NULL) free(title);
00138 title = strdup(txt);
00139 assert(title);
00140 if (xy_legend_text) xy_legend_text->text(title);
00141 setTitleCallback();
00142 }
00143
00144
00145
00146 char* SXYCurve::getTitle(void) {
00147 return title;
00148 }
00149
00150
00151
00152 SXYChart* SXYCurve::getChart(void) {
00153 if (!x_axis || !y_axis) return NULL;
00154 SXYChart* cht = x_axis->getChart();
00155 return cht;
00156 }
00157
00158
00159
00160 SXYSeries* SXYCurve::getSeries(unsigned int s) {
00161 assert(series_vector);
00162 return series_vector->getElement(s);
00163 }
00164
00165
00166
00167 XYCartesianMask* SXYCurve::getMask(unsigned int m) {
00168 assert(masks_vector);
00169 return masks_vector->getElement(m);
00170 }
00171
00172
00173
00174 unsigned int SXYCurve::getNumSeries(void) {
00175 if (!series_vector) return 0;
00176 return series_vector->getLength();
00177 }
00178
00179
00180
00181 unsigned int SXYCurve::getNumMasks(void) {
00182 if (!masks_vector) return 0;
00183 return masks_vector->getLength();
00184 }
00185
00186
00187
00188 void SXYCurve::detachMask(XYCartesianMask* mask) {
00189 checkAxesConsistency();
00190 SXYChart* cht = getChart();
00191 XYCartesian* xy_graph = cht->getXyGraph();
00192 xy_graph->remove(mask);
00193 }
00194
00195
00196
00197 SXYAxis* SXYCurve::getHorizontalAxis(void) {
00198 return x_axis;
00199 }
00200
00201
00202
00203 SXYAxis* SXYCurve::getVerticalAxis(void) {
00204 return y_axis;
00205 }
00206
00207
00208
00209 void SXYCurve::attachMask(XYCartesianMask* mask) {
00210 checkAxesConsistency();
00211 SXYChart* cht = getChart();
00212 XYCartesian* xy_graph = cht->getXyGraph();
00213 xy_graph->insert(mask);
00214 }
00215
00216
00217
00218 void SXYCurve::removeSeries(SXYSeries* series) {
00219 assert(series_vector);
00220 series_vector->removeElement(series);
00221 }
00222
00223
00224
00225 void SXYCurve::removeMask(XYCartesianMask* mask) {
00226 assert(masks_vector);
00227 masks_vector->removeElement(mask);
00228 }
00229
00230
00231
00232 void SXYCurve::insertSeries(SXYSeries* series) {
00233 assert(series_vector);
00234 series_vector->insertElement(series);
00235 }
00236
00237
00238
00239 void SXYCurve::insertMask(XYCartesianMask* mask) {
00240 assert(masks_vector);
00241 masks_vector->insertElement(mask);
00242 }
00243
00244
00245
00246 void SXYCurve::createLegend(void) {
00247 xy_legend_text = new XYRasterText( title ? title : "", XY_BLACK,
00248 SXYChart::getFontSizeReference()-1, XYRasterText::helvetica,
00249 XYRasterText::plain, XYRasterText::north,
00250 XYRasterText::horizontal );
00251 assert( xy_legend_text );
00252
00253 null_series = new SXYNullSeries();
00254 assert( null_series );
00255
00256 xy_legend_mask = new XYCartesianLineMask( null_series,
00257 x_axis->getXyAxis(), y_axis->getXyAxis(), color, 3,
00258 XYObject::continuous, xytrue );
00259 assert( xy_legend_mask );
00260 attachMask(xy_legend_mask);
00261
00262 xy_legend_mask->name( xy_legend_text );
00263 }
00264
00265
00266
00267 void SXYCurve::destroyLegend(void) {
00268 if (xy_legend_text != NULL) delete xy_legend_text;
00269 xy_legend_text = NULL;
00270
00271 if (xy_legend_mask != NULL) {
00272 detachMask(xy_legend_mask);
00273 delete xy_legend_mask;
00274 }
00275 xy_legend_mask = NULL;
00276
00277 if (null_series != NULL) delete null_series;
00278 null_series = NULL;
00279 }
00280
00281
00282
00283 void SXYCurve::setMaskVisibility(unsigned int m, int flag) {
00284 XYCartesianMask* msk = getMask(m);
00285 msk->visible(flag ? xytrue : xyfalse);
00286 }
00287
00288
00289
00290 int SXYCurve::getMaskVisibility(unsigned int m) {
00291 XYCartesianMask* msk = getMask(m);
00292 return msk->visible() == xyfalse ? 0 : 1;
00293 }
00294
00295
00296
00297 unsigned int SXYCurve::getPointFromSeries(unsigned int s, unsigned int n,
00298 double& x, double& y) {
00299 SXYSeries *srs = getSeries(s);
00300 return srs->getPoint(n, x, y);
00301 }
00302
00303
00304
00305 void SXYCurve::createMasks(void) {
00306 unsigned int num_masks = getNumMasksCallback();
00307 masks_vector = new SXYVector<XYCartesianMask*>(MAX_MASKS, NULL);
00308 for (unsigned int m = 0; m < num_masks; m++) {
00309 int s = mapMaskToSeriesCallback(m);
00310 SXYSeries *srs = getSeries(s);
00311 assert(srs);
00312
00313 XYCartesianMask* msk = createMaskCallback(m);
00314 assert(msk);
00315 msk->series(srs);
00316 msk->x_axis(getHorizontalAxis()->getXyAxis());
00317 msk->y_axis(getVerticalAxis()->getXyAxis());
00318 msk->visible(xytrue);
00319 msk->color(getColor());
00320
00321 insertMask(msk);
00322 attachMask(msk);
00323 setMaskVisibility(m,1);
00324 }
00325 }
00326
00327
00328
00329 void SXYCurve::createSeries(void) {
00330 unsigned int num_series = getNumSeriesCallback();
00331 series_vector = new SXYVector<SXYSeries*>(MAX_SERIES, NULL);
00332 for (unsigned int s = 0; s < num_series; s++) {
00333 SXYSeries *srs = createSeriesCallback(s);
00334 assert(srs);
00335 insertSeries(srs);
00336 }
00337 }
00338
00339
00340
00341 void SXYCurve::destroySeries(void) {
00342 for (unsigned int s = 0; s < getNumSeries(); s++) {
00343 SXYSeries *srs = getSeries(s);
00344 assert(srs);
00345 removeSeries(srs);
00346 destroySeriesCallback(s, srs);
00347 srs = NULL;
00348 }
00349 if (series_vector) delete series_vector;
00350 series_vector = NULL;
00351 }
00352
00353
00354
00355 void SXYCurve::destroyMasks(void) {
00356 for (unsigned int m = 0; m < getNumMasks(); m++) {
00357 XYCartesianMask* msk = getMask(m);
00358 assert(msk);
00359 removeMask(msk);
00360 detachMask(msk);
00361 destroyMaskCallback(m, msk);
00362 msk = NULL;
00363 }
00364 if (masks_vector) delete masks_vector;
00365 masks_vector = NULL;
00366 }
00367
00368
00369
00370 void SXYCurve::getLimits(double& xmin, double& xmax,
00371 double& ymin, double& ymax) {
00372 SXYSeries::getSeveralLimits(series_vector, xmin, xmax, ymin, ymax);
00373 }
00374
00375
00376
00377 void SXYCurve::checkAxesConsistency(void) {
00378 assert(x_axis);
00379 assert(y_axis);
00380 SXYChart* cht1 = x_axis->getChart();
00381 SXYChart* cht2 = y_axis->getChart();
00382 assert(cht1 && cht2);
00383 assert(cht1 == cht2);
00384 }
00385
00386
00387
00388