pref->addPreference( tr( "PREF_VIEWER_SELECTION" ), plot2dGroup,
LightApp_Preferences::Color, "Plot2d", "SelectionColor" );
+ pref->addPreference( tr( "PREF_DEVIATION_COLOR" ), plot2dGroup,
+ LightApp_Preferences::Color, "Plot2d", "DeviationMarkerColor" );
+
+ int deviationMarkerLw = pref->addPreference( tr( "PREF_DEVIATION_MARKER_LW" ), plot2dGroup,
+ LightApp_Preferences::IntSpin, "Plot2d", "DeviationMarkerLineWidth" );
+ pref->setItemProperty( "min", 1, deviationMarkerLw );
+ pref->setItemProperty( "max", 5, deviationMarkerLw );
+
+ int deviationMarkerTs = pref->addPreference( tr( "PREF_DEVIATION_MARKER_TS" ), plot2dGroup,
+ LightApp_Preferences::IntSpin, "Plot2d", "DeviationMarkerTickSize" );
+
+ pref->setItemProperty( "min", 1, deviationMarkerTs );
+ pref->setItemProperty( "max", 5, deviationMarkerTs );
+
int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
<!-- Plot2d viewer preferences -->
<parameter name="Background" value="255, 255, 255" />
<parameter name="SelectionColor" value="80, 80, 80" />
+ <parameter name="DeviationMarkerColor" value="0, 0, 255" />
+ <parameter name="DeviationMarkerLineWidth" value="1" />
+ <parameter name="DeviationMarkerTickSize" value="2" />
<parameter name="CurveType" value="1" />
<parameter name="HorScaleMode" value="0" />
<parameter name="LegendPos" value="1" />
<source>PREF_GROUP_PLOT2DVIEWER</source>
<translation>Plot2d Viewer</translation>
</message>
+ <message>
+ <source>PREF_DEVIATION_COLOR</source>
+ <translation>Deviation marker color</translation>
+ </message>
+ <message>
+ <source>PREF_DEVIATION_MARKER_LW</source>
+ <translation>Deviation marker line width</translation>
+ </message>
+ <message>
+ <source>PREF_DEVIATION_MARKER_TS</source>
+ <translation>Deviation marker tick size</translation>
+ </message>
<message>
<source>MEN_DESK_MRU</source>
<translation>Most Recently Used</translation>
Constructor
*/
Plot2d_Point::Plot2d_Point()
- : x( 0. ), y( 0. )
+ : x( 0. ), y( 0. ), deviationPtr(0)
{
}
Constructor
*/
Plot2d_Point::Plot2d_Point( double theX, double theY, const QString& theText )
- : x( theX ), y( theY ), text( theText )
+ : x( theX ), y( theY ), text( theText ), deviationPtr(0)
{
}
+/*!
+ Destructor.
+*/
+Plot2d_Point::~Plot2d_Point() {
+ clearDeviation();
+}
+
+/*!
+ Free memory allocated for the deviation data.
+*/
+void Plot2d_Point::clearDeviation() {
+ if(deviationPtr)
+ delete deviationPtr;
+ deviationPtr = 0;
+}
+
+/*!
+ Return true in case if deviation data is assigned to the point.
+*/
+bool Plot2d_Point::hasDeviation() const {
+ return !(deviationPtr == 0);
+}
+
+/*!
+ Assign deviation data to the point.
+*/
+void Plot2d_Point::setDeviation(double min, double max) {
+ clearDeviation();
+ deviationPtr = new double[2];
+ deviationPtr[0] = min;deviationPtr[1] = max;
+}
+
+/*!
+ Return true in case if deviation data is assigned to the point
+ and store deviation data in the input parameters.
+*/
+bool Plot2d_Point::deviation(double& min, double& max) const {
+ if(hasDeviation()) {
+ min = deviationPtr[0];
+ max = deviationPtr[1];
+ }
+ return false;
+}
+
+/*!
+ Return minimal deviation value.
+*/
+double Plot2d_Point::minDeviation() const {
+ if(hasDeviation())
+ return deviationPtr[0];
+ return 0.;
+}
+
+/*!
+ Return minimal deviation value.
+*/
+double Plot2d_Point::maxDeviation() const {
+ if(hasDeviation())
+ return deviationPtr[1];
+ return 0.;
+}
+
+
/*!
\brief Convert Plot2d marker type to Qwt marker type.
class QPainter;
class QwtPlot;
+// Properties on the deviation marker.
+#define PLOT2D_DEVIATION_COLOR "DEVIATION_COLOR"
+#define PLOT2D_DEVIATION_LW "DEVIATION_LW"
+#define PLOT2D_DEVIATION_TS "DEVIATION_TS"
+
struct PLOT2D_EXPORT Plot2d_Point
{
double x;
double y;
+ double* deviationPtr;
QString text;
Plot2d_Point();
- Plot2d_Point( double theX, double theY, const QString& theText = QString() );
+ Plot2d_Point( double theX, double theY, const QString& theText = QString() );
+ ~Plot2d_Point();
+ bool deviation(double& min, double& max) const;
+ bool hasDeviation() const;
+ void setDeviation(double min, double max);
+ void clearDeviation();
+ double minDeviation() const;
+ double maxDeviation() const;
};
typedef QList<Plot2d_Point> pointList;
QPen( getColor() ),
QSize( getMarkerSize() , getMarkerSize() )));
- double *x, *y;
+ double *x, *y, *min, *max;
long nb = getData( &x, &y );
- aCurve->setData( x, y, nb );
+ if(nb > 0 && x && y) {
+ aCurve->setData( x, y, nb );
+ delete x;
+ delete y;
+ QList<int> idx;
+ getDeviationData(min, max, idx);
+ if(idx.size() > 0 && min && max) {
+ aCurve->setDeviationData(min,max,idx);
+ delete min;
+ delete max;
+ } else {
+ aCurve->clearDeviationData();
+ }
+ }
}
/*!
{
return myLineWidth;
}
+/*!
+ Sets deviation data on the curve.
+*/
+void Plot2d_Curve::setDeviationData( const double* min, const double* max,const QList<int>& idx) {
+ for( int i = 0; i < idx.size(); i++ ) {
+ if(idx[i] < myPoints.size()) {
+ myPoints[idx[i]].setDeviation(min[i], max[i]);
+ }
+ }
+}
+
+/*!
+ Gets object's data
+*/
+void Plot2d_Curve::getDeviationData( double*& theMin, double*& theMax, QList<int>& idx) const
+{
+ int aNb = 0;
+ idx.clear();
+ for (int i = 0; i < nbPoints(); i++)
+ if(myPoints[i].hasDeviation())
+ aNb++;
+ if(aNb) {
+ double min, max;
+ theMin = new double[aNb];
+ theMax = new double[aNb];
+ for (int i = 0; i < nbPoints(); i++)
+ if(myPoints[i].hasDeviation()) {
+ myPoints[i].deviation(min,max);
+ theMin[i] = min;
+ theMax[i] = max;
+ idx.push_back(i);
+ }
+ }
+}
+
+/*!
+ Clear deviation data on the curve.
+*/
+void Plot2d_Curve::clearDeviationData() {
+ for( int i=0; i < myPoints.size(); i++ )
+ myPoints[i].clearDeviation();
+}
+
+/*!
+ Gets object's minimal ordinate
+*/
+double Plot2d_Curve::getMinY() const
+{
+ double aMinY = 1e150;
+ pointList::const_iterator aIt;
+ double coeff = 0.0;
+ for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
+ coeff = (*aIt).minDeviation();
+ aMinY = qMin( aMinY, myScale * (*aIt).y - coeff );
+ }
+ return aMinY;
+}
+/*!
+ Gets object's maximal ordinate
+*/
+double Plot2d_Curve::getMaxY() const
+{
+ double aMaxY = -1e150;
+ pointList::const_iterator aIt;
+ double coeff = 0.0;
+ for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
+ coeff = (*aIt).maxDeviation();
+ aMaxY = qMax( aMaxY, myScale * (*aIt).y + coeff );
+ }
+ return aMaxY;
+}
\ No newline at end of file
void setMarker( Plot2d::MarkerType, const int );
void setMarker( Plot2d::MarkerType );
- void setMarkerStyle( QwtSymbol::Style style);
+ void setMarkerStyle( QwtSymbol::Style style);
Plot2d::MarkerType getMarker() const;
QwtSymbol::Style getMarkerStyle() const;
void setMarkerSize( const int );
Plot2d::LineType getLine() const;
void setLineWidth( const int );
int getLineWidth() const;
+ void setDeviationData( const double*, const double*, const QList<int>&);
+ void getDeviationData( double*&, double*&, QList<int>& ) const;
+ void clearDeviationData();
+
+ virtual double getMinY() const;
+ virtual double getMaxY() const;
+
protected:
// Protection against QwtObject::drawLines() bug in Qwt 0.4.x:
// it crashes if switched to X/Y logarithmic mode, when one or more points have
// non-positive X/Y coordinate
- double getMinX() const;
- double getMaxX() const;
- double getMinY() const;
- double getMaxY() const;
+ virtual double getMinX() const;
+ virtual double getMaxX() const;
+ virtual double getMinY() const;
+ virtual double getMaxY() const;
void setSelected(const bool);
bool isSelected() const;
#include <QPainter>
#include <QPalette>
#include <QLayout>
+#include <QLine>
+#include <QVariant>
#include <qwt_plot.h>
#include <qwt_painter.h>
#include <qwt_scale_map.h>
}
return col;
}
+/*
+ * Internal class to store deviation data on the curve.
+ */
+class Plot2d_QwtPlotCurve::Plot2d_DeviationData {
+public:
+ Plot2d_DeviationData::Plot2d_DeviationData(const double *min, const double *max,const QList<int>& idx)
+ {
+ foreach(int index,idx) {
+ myMin[index] = min[index];
+ myMax[index] = max[index];
+ }
+ }
+ ~Plot2d_DeviationData(){}
+
+ size_t size() const
+ {
+ return qwtMin(myMin.size(), myMax.size());
+ }
+ bool values(size_t i, double &min, double &max) {
+ if(myMin.contains(i) && myMax.contains(i)) {
+ min = myMin[i];
+ max = myMax[i];
+ return true;
+ }
+ return false;
+ }
+private:
+ QMap<int,double> myMin;
+ QMap<int,double> myMax;
+};
+
/*!
Constructor of Plot2d_QwtPlotCurve
Plot2d_SelectableItem(),
QwtPlotCurve( title ),
myYAxis( yAxis ),
- myYAxisIdentifierEnabled( false )
-{
+ myYAxisIdentifierEnabled( false ),
+ myDeviationData(0)
+{
}
/*!
*/
Plot2d_QwtPlotCurve::~Plot2d_QwtPlotCurve()
{
+ clearDeviationData();
}
/*!
{
return new Plot2d_QwtLegendItem;
}
+
+/*!
+ Redefined method, which draw a set of points of a curve.
+*/
+void Plot2d_QwtPlotCurve::draw(QPainter *painter,
+ const QwtScaleMap &xMap, const QwtScaleMap &yMap,
+ int from, int to) const
+{
+ if (to < 0)
+ to = dataSize() - 1;
+ QwtPlotCurve::draw(painter, xMap, yMap, from, to);
+
+ //draw deviation data
+ if(hasDeviationData()) {
+ painter->save();
+ int lineW = deviationMarkerLineWidth();
+ int tickSz = deviationMarkerTickSize() + qRound(lineW/2);
+ double min, max, xi, yi;
+ int xp, ytop, ybtm, tickl, tickr;
+ QColor c = isSelected() ? Plot2d_Object::selectionColor() : deviationMarkerColor();
+ QPen p = QPen(c, lineW, Qt::SolidLine);
+ painter->setPen(p);
+ for (int i = from; i <= to; i++) {
+ if(!myDeviationData->values(i,min,max)) continue;
+ xi = x(i);
+ yi = y(i);
+ xp = xMap.transform(xi);
+ ytop = yMap.transform(yi + max);
+ ybtm = yMap.transform(yi - min);
+ tickl = xp - tickSz;
+ tickr = xp + tickSz;
+ painter->drawLine(tickl,ytop,tickr,ytop);
+ painter->drawLine(xp,ytop,xp,ybtm);
+ painter->drawLine(tickl,ybtm,tickr,ybtm);
+ }
+ painter->restore();
+ }
+}
+
+/*!
+ * Return color of the deviation marker.
+ */
+QColor Plot2d_QwtPlotCurve::deviationMarkerColor() const {
+ QColor c(0, 0, 127);
+ if(plot()) {
+ QVariant var = plot()->property(PLOT2D_DEVIATION_COLOR);
+ if(var.isValid())
+ c = var.value<QColor>();
+ }
+ return c;
+}
+/*!
+ * Return line width of the deviation marker.
+ */
+int Plot2d_QwtPlotCurve::deviationMarkerLineWidth() const {
+ int lw = 1;
+ if(plot()) {
+ QVariant var = plot()->property(PLOT2D_DEVIATION_LW);
+ if(var.isValid())
+ lw = var.toInt();
+ }
+ return lw;
+}
+
+/*!
+ * Return tick size of the deviation marker.
+ */
+int Plot2d_QwtPlotCurve::deviationMarkerTickSize() const {
+ int ts = 2;
+ if(plot()) {
+ QVariant var = plot()->property(PLOT2D_DEVIATION_TS);
+ if(var.isValid())
+ ts = var.toInt();
+ }
+ return ts;
+}
+
+/*!
+ * Sets deviation data for the plot item.
+ */
+void Plot2d_QwtPlotCurve::setDeviationData(const double* min, const double* max,const QList<int> &idx) {
+ clearDeviationData();
+ myDeviationData = new Plot2d_DeviationData(min,max,idx);
+}
+
+/*!
+ * Return true if deviation is assigned to the plot item,
+ false otherwise.
+ */
+bool Plot2d_QwtPlotCurve::hasDeviationData() const {
+ return myDeviationData != 0;
+}
+
+/*!
+ * Remove deviation data from the plot item.
+ */
+void Plot2d_QwtPlotCurve::clearDeviationData()
+{
+ if(myDeviationData)
+ delete myDeviationData;
+ myDeviationData = 0;
+}
+
+
+
/*!
Constructor.
*/
}
}
return aRes;
-}
+}
\ No newline at end of file
public:
virtual void setYAxisIdentifierEnabled( const bool );
+ virtual void draw(QPainter *p,
+ const QwtScaleMap &xMap,
+ const QwtScaleMap &yMap,
+ int from, int to) const;
+
+ void setDeviationData(const double* min, const double* max, const QList<int> &idx);
+ bool hasDeviationData() const;
+ void clearDeviationData();
+
protected:
virtual void updateLegend( QwtLegend* ) const;
virtual QWidget* legendItem() const;
+ QColor deviationMarkerColor() const;
+ int deviationMarkerLineWidth() const;
+ int deviationMarkerTickSize() const;
+
private:
- QwtPlot::Axis myYAxis;
- bool myYAxisIdentifierEnabled;
+ QwtPlot::Axis myYAxis;
+ bool myYAxisIdentifierEnabled;
+
+ class Plot2d_DeviationData;
+ Plot2d_DeviationData* myDeviationData;
};
class PLOT2D_EXPORT Plot2d_HistogramQwtItem: public QwtPlotItem
QLabel* aBGLab = new QLabel( tr( "PLOT2D_BACKGROUND_COLOR_LBL" ), this );
myBackgroundBtn = new QtxColorButton( this );
+ //Deviation marker parameters
+ QGroupBox* aDeviationGrp = new QGroupBox( tr( "PLOT2D_DEVIATION_MARKER_TLT" ), this );
+ QHBoxLayout* aDeviationLayout = new QHBoxLayout(aDeviationGrp);
+
+ //Deviation marker parameters : Line width
+ QLabel* aDeviationLwLbl = new QLabel( tr( "PLOT2D_DEVIATION_LW_LBL" ), aDeviationGrp );
+ myDeviationLw = new QSpinBox( aDeviationGrp );
+ myDeviationLw->setMinimum( 1 );
+ myDeviationLw->setMaximum( 5 );
+ myDeviationLw->setSingleStep( 1 );
+ myDeviationLw->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+
+ //Deviation marker parameters : Line width
+ QLabel* aDeviationTsLbl = new QLabel( tr( "PLOT2D_DEVIATION_TS_LBL" ), aDeviationGrp );
+ myDeviationTs = new QSpinBox( aDeviationGrp );
+ myDeviationTs->setMinimum( 1 );
+ myDeviationTs->setMaximum( 5 );
+ myDeviationTs->setSingleStep( 1 );
+ myDeviationTs->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+
+ //Deviation marker parameters : Color
+ QLabel* aDeviationClLbl = new QLabel( tr( "PLOT2D_DEVIATION_CL_LBL" ), aDeviationGrp );
+ myDeviationCl = new QtxColorButton( aDeviationGrp );
+
+ aDeviationLayout->addWidget( aDeviationLwLbl );
+ aDeviationLayout->addWidget( myDeviationLw );
+ aDeviationLayout->addWidget( aDeviationTsLbl );
+ aDeviationLayout->addWidget( myDeviationTs );
+ aDeviationLayout->addWidget( aDeviationClLbl );
+ aDeviationLayout->addWidget( myDeviationCl );
+
// normalize mode
QGroupBox* aNormalizeGrp = new QGroupBox( tr( "PLOT2D_NORMALIZE_TLT" ), this );
QGridLayout* aNormalizeLayout = new QGridLayout( aNormalizeGrp );
bgLayout->addWidget( myBackgroundBtn ); bgLayout->addStretch();
topLayout->addWidget( aBGLab, 3, 2 );
topLayout->addLayout( bgLayout, 3, 3 );
- topLayout->addWidget( aNormalizeGrp, 4, 0, 1, 4 );
- topLayout->addWidget( aScaleGrp, 5, 0, 1, 4 );
- topLayout->addWidget( aTabWidget, 6, 0, 1, 4 );
- topLayout->addWidget( myDefCheck, 7, 0, 1, 4 );
- topLayout->setRowStretch( 7, 5 );
-
- topLayout->addLayout( btnLayout, 8, 0, 1, 4 );
+ topLayout->addWidget( aDeviationGrp, 4, 0, 1, 4 );
+ topLayout->addWidget( aNormalizeGrp, 5, 0, 1, 4 );
+ topLayout->addWidget( aScaleGrp, 6, 0, 1, 4 );
+ topLayout->addWidget( aTabWidget, 7, 0, 1, 4 );
+ topLayout->addWidget( myDefCheck, 8, 0, 1, 4 );
+ topLayout->setRowStretch( 9, 5 );
+
+ topLayout->addLayout( btnLayout, 10, 0, 1, 4 );
if ( !showDefCheck )
myDefCheck->hide();
{
return myMarkerSpin->value();
}
+/*!
+ \brief Set deviation marker line width.
+ \param width marker line width
+ \sa getDeviationMarkerLw()
+*/
+void Plot2d_SetupViewDlg::setDeviationMarkerLw( const int width ){
+ myDeviationLw->setValue(width);
+}
+
+/*!
+ \brief Get deviation marker line width.
+ \return marker line width
+ \sa setMarkerSize()
+*/
+int Plot2d_SetupViewDlg::getDeviationMarkerLw() const {
+ return myDeviationLw->value();
+}
+
+/*!
+ \brief Set deviation marker tick size.
+ \param size marker tick size
+ \sa getDeviationMarkerTs()
+*/
+void Plot2d_SetupViewDlg::setDeviationMarkerTs( const int size) {
+ myDeviationTs->setValue(size);
+}
+
+/*!
+ \brief Get deviation marker tick size.
+ \return marker tick size
+ \sa setDeviationMarkerTs()
+*/
+int Plot2d_SetupViewDlg::getDeviationMarkerTs() const {
+ return myDeviationTs->value();
+}
+
+/*!
+ \brief Set color of the deviation marker.
+ \param color marker color
+ \sa getDeviationMarkerCl()
+*/
+void Plot2d_SetupViewDlg::setDeviationMarkerCl( const QColor& col) {
+ myDeviationCl->setColor( col );
+}
+
+/*!
+ \brief Get color of the deviation marker.
+ \return marker color
+ \sa setDeviationMarkerCl()
+*/
+QColor Plot2d_SetupViewDlg::getDeviationMarkerCl() const {
+ return myDeviationCl->color();
+}
/*!
\brief Set background color.
int getXScaleMode();
int getYScaleMode();
+ void setDeviationMarkerLw( const int);
+ int getDeviationMarkerLw() const;
+
+ void setDeviationMarkerTs( const int);
+ int getDeviationMarkerTs() const;
+
+ void setDeviationMarkerCl( const QColor&);
+ QColor getDeviationMarkerCl() const;
+
bool isSetAsDefault();
protected slots:
QPushButton* myOkBtn;
QPushButton* myCancelBtn;
QPushButton* myHelpBtn;
+ QSpinBox* myDeviationLw;
+ QSpinBox* myDeviationTs;
+ QtxColorButton* myDeviationCl;
bool mySecondAxisY;
};
setNormLMaxMode( resMgr->booleanValue( "Plot2d", "VerNormLMaxMode", myNormLMax ) );
setNormRMinMode( resMgr->booleanValue( "Plot2d", "VerNormRMinMode", myNormRMin ) );
setNormRMaxMode( resMgr->booleanValue( "Plot2d", "VerNormRMaxMode", myNormRMax ) );
+ QColor c = resMgr->colorValue( "Plot2d", "DeviationMarkerColor", QColor(0,0,255));
+ myPlot->setProperty(PLOT2D_DEVIATION_COLOR, c);
+ myPlot->setProperty(PLOT2D_DEVIATION_LW,
+ resMgr->integerValue( "Plot2d", "DeviationMarkerLineWidth", 1));
+ myPlot->setProperty(PLOT2D_DEVIATION_TS,
+ resMgr->integerValue( "Plot2d", "DeviationMarkerTickSize", 2));
+
}
/*!
dlg->setLMaxNormMode(myNormLMax);
dlg->setRMinNormMode(myNormRMin);
dlg->setRMaxNormMode(myNormRMax);
+
+ QVariant v = myPlot->property(PLOT2D_DEVIATION_LW);
+ int lw = v.isValid() ? v.toInt() : 1;
+
+ v = myPlot->property(PLOT2D_DEVIATION_TS);
+ int ts = v.isValid() ? v.toInt() : 2;
+
+ v = myPlot->property(PLOT2D_DEVIATION_COLOR);
+ QColor cl = v.isValid() ? v.value<QColor>() : QColor(0,0,255);
+
+ dlg->setDeviationMarkerLw(lw);
+ dlg->setDeviationMarkerTs(ts);
+ dlg->setDeviationMarkerCl(cl);
+
//
dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
setNormRMaxMode( dlg->getRMaxNormMode() );
}
+ myPlot->setProperty(PLOT2D_DEVIATION_COLOR,
+ dlg->getDeviationMarkerCl());
+ myPlot->setProperty(PLOT2D_DEVIATION_LW,
+ dlg->getDeviationMarkerLw());
+ myPlot->setProperty(PLOT2D_DEVIATION_TS,
+ dlg->getDeviationMarkerTs());
+
+
// update view
myPlot->replot();
// update preferences
<source>PLOT2D_BACKGROUND_COLOR_LBL</source>
<translation>Background color:</translation>
</message>
+ <message>
+ <source>PLOT2D_DEVIATION_MARKER_TLT</source>
+ <translation>Deviation marker</translation>
+ </message>
+ <message>
+ <source>PLOT2D_DEVIATION_LW_LBL</source>
+ <translation>Line width</translation>
+ </message>
+ <message>
+ <source>PLOT2D_DEVIATION_TS_LBL</source>
+ <translation>Tick size</translation>
+ </message>
+ <message>
+ <source>PLOT2D_DEVIATION_CL_LBL</source>
+ <translation>Color</translation>
+ </message>
<message>
<source>WRN_XLOG_NOT_ALLOWED</source>
<translation>Some points with non-positive abscissa values have been detected.