#include "Plot2d_Curve.h"
#include <QColor>
+#include <float.h>
+
/*!
Constructor
*/
return myPoints;
}
+/*!
+ Gets curve's data : abscissas of points
+*/
+pointList& Plot2d_Curve::getPointList()
+{
+ return myPoints;
+}
+
/*!
Sets curve's data.
*/
return aMaxY;
}
+/*!
+ Gets curve's minimal positive abscissa
+*/
+double Plot2d_Curve::getMinPositiveX() const
+{
+ pointList::const_iterator aIt;
+ double aMinX = 1e150;
+ //int aCurrent = 0;
+ for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
+ if ( (*aIt).x < aMinX && (*aIt).x > DBL_MIN )
+ aMinX = (*aIt).x;
+ }
+ return aMinX;
+}
+
+/*!
+ Gets curve's minimal positive ordinate
+*/
+double Plot2d_Curve::getMinPositiveY() const
+{
+ pointList::const_iterator aIt;
+ double aMinY = 1e150;
+ //int aCurrent = 0;
+ for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
+ if ( (*aIt).y < aMinY && (*aIt).y > DBL_MIN )
+ aMinY = (*aIt).y;
+ }
+ return aMinY;
+}
+
/*!
Changes text assigned to point of curve
\param ind -- index of point
#include <qwt_curve_fitter.h>
#include <iostream>
+#include <float.h>
#include <stdlib.h>
#include <QPrinter>
#define FITALL_EVENT ( QEvent::User + 9999 )
+#define NEGLIGIBLE_VALUE 1e-6
+
const char* imageZoomCursor[] = {
"32 32 3 1",
". c None",
if ( update )
myPlot->replot();
}
+/*!
+ Remove the curve's non-positive values or replace them by a negligible small value
+ (to make it possible to enable logarithmic scale mode).
+*/
+void Plot2d_ViewFrame::cutCurveNonPositiveValues( const bool theIsXAxis,
+ const bool theIsReplaceWithSmallValues )
+{
+ const CurveDict& aCurves = myPlot->getCurves();
+ CurveDict::ConstIterator it, itEnd = aCurves.end();
+
+ double aSmallValue = NEGLIGIBLE_VALUE;
+ if( theIsReplaceWithSmallValues )
+ {
+ // first, calculate the value the non-positive values will be cut to
+ for( it = aCurves.begin(); it != itEnd; it++ )
+ {
+ if( Plot2d_Curve* aCurve = it.value() )
+ {
+ double aMinPositiveValue = theIsXAxis ?
+ aCurve->getMinPositiveX() : aCurve->getMinPositiveY();
+
+ if( aMinPositiveValue < aSmallValue )
+ {
+ double aLog = log10( aMinPositiveValue );
+ double aFloor = floor( aLog );
+ aSmallValue = pow( 10, aFloor );
+ }
+ }
+ }
+ }
+
+ for( it = aCurves.begin(); it != itEnd; it++ )
+ {
+ if( Plot2d_Curve* aCurve = it.value() )
+ {
+ pointList& aPointList = aCurve->getPointList();
+ pointList::iterator pIt, pItEnd = aPointList.end();
+ for( pIt = aPointList.begin(); pIt != pItEnd; )
+ {
+ Plot2d_Point& aPoint = *pIt;
+ double& value = theIsXAxis ? aPoint.x : aPoint.y;
+ if( value < DBL_MIN )
+ {
+ if( theIsReplaceWithSmallValues )
+ value = aSmallValue;
+ else // remove value
+ {
+ pIt = aPointList.erase( pIt );
+ continue; // do not increment the iterator
+ }
+ }
+ pIt++;
+ }
+ updateCurve( aCurve, false );
+ }
+ }
+}
/*!
Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
*/
// it crashes if switched to X/Y logarithmic mode, when one or more points have
// non-positive X/Y coordinate
if ( mode && !isXLogEnabled() ){
- SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
- return;
+ int answer = SUIT_MessageBox::question(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"),
+ tr("REMOVE_POINTS"), tr("REPLACE_VALUES"),
+ tr("CANCEL"), 2, 2);
+ if( answer == 0 )
+ cutCurveNonPositiveValues( true, false );
+ else if( answer == 1 )
+ cutCurveNonPositiveValues( true, true );
+ else
+ return;
}
myXMode = mode;
// it crashes if switched to X/Y logarithmic mode, when one or more points have
// non-positive X/Y coordinate
if ( mode && !isYLogEnabled() ){
- SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
- return;
+ int answer = SUIT_MessageBox::question(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"),
+ tr("REMOVE_POINTS"), tr("REPLACE_VALUES"),
+ tr("CANCEL"), 2, 2);
+ if( answer == 0 )
+ cutCurveNonPositiveValues( false, false );
+ else if( answer == 1 )
+ cutCurveNonPositiveValues( false, true );
+ else
+ return;
}
myYMode = mode;
<message>
<source>WRN_XLOG_NOT_ALLOWED</source>
<translation>Some points with non-positive abscissa values have been detected.
-Logarithmic scale for abscissa axis is not allowed.</translation>
+Do you want to remove these points from the curve presentation or
+to replace the non-positive values with negligible positive values?</translation>
</message>
<message>
<source>WRN_YLOG_NOT_ALLOWED</source>
<translation>Some points with non-positive ordinate values have been detected.
-Logarithmic scale for ordinate axis is not allowed.</translation>
+Do you want to remove these points from the curve presentation or
+to replace the non-positive values with negligible positive values?</translation>
+ </message>
+ <message>
+ <source>REMOVE_POINTS</source>
+ <translation>Remove points</translation>
+ </message>
+ <message>
+ <source>REPLACE_VALUES</source>
+ <translation>Replace values</translation>
</message>
<message>
<source>DSC_FITRECT</source>