Qwt User's Guide: qwt_scale_map.cpp Source File

- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# qwt_scale_map.cpp

    00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
    00002  * Qwt Widget Library
    00003  * Copyright (C) 1997   Josef Wilgen
    00004  * Copyright (C) 2002   Uwe Rathmann
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the Qwt License, Version 1.0
    00008  *****************************************************************************/
    00009
    00010 #include "qwt_scale_map.h"
    00011
    00012 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMin = 1.0e-150;
    00013 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMax = 1.0e150;
    00014
    00016 QwtScaleTransformation::QwtScaleTransformation(Type type):
    00017     d_type(type)
    00018 {
    00019 }
    00020
    00021 QwtScaleTransformation::~QwtScaleTransformation()
    00022 {
    00023 }
    00024
    00025 QwtScaleTransformation *QwtScaleTransformation::copy() const
    00026 {
    00027     return new QwtScaleTransformation(d_type);
    00028 }
    00029
    00047 double QwtScaleTransformation::xForm(
    00048     double s, double s1, double s2, double p1, double p2) const
    00049 {
    00050     if ( d_type == Log10 )
    00051         return p1 + (p2 - p1) / log(s2 / s1) * log(s / s1);
    00052     else
    00053         return p1 + (p2 - p1) / (s2 - s1) * (s - s1);
    00054 }
    00055
    00070 double QwtScaleTransformation::invXForm(double p, double p1, double p2,
    00071     double s1, double s2) const
    00072 {
    00073     if ( d_type == Log10 )
    00074         return exp((p - p1) / (p2 - p1) * log(s2 / s1)) * s1;
    00075     else
    00076         return s1 + (s2 - s1) / (p2 - p1) * (p - p1);
    00077 }
    00078
    00084 QwtScaleMap::QwtScaleMap():
    00085     d_s1(0.0),
    00086     d_s2(1.0),
    00087     d_p1(0.0),
    00088     d_p2(1.0),
    00089     d_cnv(1.0)
    00090 {
    00091     d_transformation = new QwtScaleTransformation(
    00092         QwtScaleTransformation::Linear);
    00093 }
    00094
    00095 QwtScaleMap::QwtScaleMap(const QwtScaleMap& other):
    00096     d_s1(other.d_s1),
    00097     d_s2(other.d_s2),
    00098     d_p1(other.d_p1),
    00099     d_p2(other.d_p2),
    00100     d_cnv(other.d_cnv)
    00101 {
    00102     d_transformation = other.d_transformation->copy();
    00103 }
    00104
    00108 QwtScaleMap::~QwtScaleMap()
    00109 {
    00110     delete d_transformation;
    00111 }
    00112
    00113 QwtScaleMap &QwtScaleMap::operator=(const QwtScaleMap &other)
    00114 {
    00115     d_s1 = other.d_s1;
    00116     d_s2 = other.d_s2;
    00117     d_p1 = other.d_p1;
    00118     d_p2 = other.d_p2;
    00119     d_cnv = other.d_cnv;
    00120
    00121     delete d_transformation;
    00122     d_transformation = other.d_transformation->copy();
    00123
    00124     return *this;
    00125 }
    00126
    00130 void QwtScaleMap::setTransformation(
    00131     QwtScaleTransformation *transformation)
    00132 {
    00133     if ( transformation == NULL )
    00134         return;
    00135
    00136     delete d_transformation;
    00137     d_transformation = transformation;
    00138     setScaleInterval(d_s1, d_s2);
    00139 }
    00140
    00142 const QwtScaleTransformation *QwtScaleMap::transformation() const
    00143 {
    00144     return d_transformation;
    00145 }
    00146
    00153 void QwtScaleMap::setScaleInterval(double s1, double s2)
    00154 {
    00155     if (d_transformation->type() == QwtScaleTransformation::Log10 )
    00156     {
    00157         if (s1 < LogMin)
    00158            s1 = LogMin;
    00159         else if (s1 > LogMax)
    00160            s1 = LogMax;
    00161
    00162         if (s2 < LogMin)
    00163            s2 = LogMin;
    00164         else if (s2 > LogMax)
    00165            s2 = LogMax;
    00166     }
    00167
    00168     d_s1 = s1;
    00169     d_s2 = s2;
    00170
    00171     if ( d_transformation->type() != QwtScaleTransformation::Other )
    00172         newFactor();
    00173 }
    00174
    00180 void QwtScaleMap::setPaintInterval(int p1, int p2)
    00181 {
    00182     d_p1 = p1;
    00183     d_p2 = p2;
    00184
    00185     if ( d_transformation->type() != QwtScaleTransformation::Other )
    00186         newFactor();
    00187 }
    00188
    00194 void QwtScaleMap::setPaintXInterval(double p1, double p2)
    00195 {
    00196     d_p1 = p1;
    00197     d_p2 = p2;
    00198
    00199     if ( d_transformation->type() != QwtScaleTransformation::Other )
    00200         newFactor();
    00201 }
    00202
    00206 void QwtScaleMap::newFactor()
    00207 {
    00208     d_cnv = 0.0;
    00209 #if 1
    00210     if (d_s2 == d_s1)
    00211         return;
    00212 #endif
    00213
    00214     switch( d_transformation->type() )
    00215     {
    00216         case QwtScaleTransformation::Linear:
    00217             d_cnv = (d_p2 - d_p1) / (d_s2 - d_s1);
    00218             break;
    00219         case QwtScaleTransformation::Log10:
    00220             d_cnv = (d_p2 - d_p1) / log(d_s2 / d_s1);
    00221             break;
    00222         default:;
    00223     }
    00224 }