From 0643bac8a9ca106cd27305ce4b052c5de04f2c6e Mon Sep 17 00:00:00 2001 From: vtn Date: Mon, 28 Jul 2014 21:42:04 +0400 Subject: [PATCH] 0002080: External 20671 Script improvement. Added double values to NB_MARKERS command. --- src/Plot2d/Plot2d_Curve.cxx | 4 +- src/Plot2d/Plot2d_Curve.h | 6 +-- src/Plot2d/Plot2d_SetupCurvesDlg.cxx | 8 ++-- src/Plot2d/Plot2d_SetupCurvesDlg.h | 4 +- src/Plot2d/Plot2d_ViewFrame.cxx | 60 ++++++++++++++++------------ src/Plot2d/Plot2d_ViewFrame.h | 10 ++--- 6 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/Plot2d/Plot2d_Curve.cxx b/src/Plot2d/Plot2d_Curve.cxx index d1ab1755c..33d177f94 100755 --- a/src/Plot2d/Plot2d_Curve.cxx +++ b/src/Plot2d/Plot2d_Curve.cxx @@ -330,7 +330,7 @@ Plot2d::MarkerType Plot2d_Curve::getMarker() const /*! Sets number of markers per step ( and resets AutoAssign flag ). */ -void Plot2d_Curve::setNbMarkers( const int nbMarkers ) +void Plot2d_Curve::setNbMarkers( const double nbMarkers ) { myNbMarkers = nbMarkers; myAutoAssign = false; @@ -339,7 +339,7 @@ void Plot2d_Curve::setNbMarkers( const int nbMarkers ) /*! Gets number of markers per step ( and resets AutoAssign flag ). */ -int Plot2d_Curve::getNbMarkers() const +double Plot2d_Curve::getNbMarkers() const { return myNbMarkers; } diff --git a/src/Plot2d/Plot2d_Curve.h b/src/Plot2d/Plot2d_Curve.h index 0b9819971..f8e05e39c 100755 --- a/src/Plot2d/Plot2d_Curve.h +++ b/src/Plot2d/Plot2d_Curve.h @@ -86,8 +86,8 @@ public: void setMarker( Plot2d::MarkerType ); Plot2d::MarkerType getMarker() const; - void setNbMarkers( const int ); - int getNbMarkers() const; + void setNbMarkers( const double ); + double getNbMarkers() const; void setLine( Plot2d::LineType, const int = 0 ); Plot2d::LineType getLine() const; @@ -120,7 +120,7 @@ protected: QString myVerUnits; QColor myColor; Plot2d::MarkerType myMarker; - int myNbMarkers; + double myNbMarkers; Plot2d::LineType myLine; int myLineWidth; QwtPlot::Axis myYAxis; diff --git a/src/Plot2d/Plot2d_SetupCurvesDlg.cxx b/src/Plot2d/Plot2d_SetupCurvesDlg.cxx index e48d39d07..58d0f9d5c 100755 --- a/src/Plot2d/Plot2d_SetupCurvesDlg.cxx +++ b/src/Plot2d/Plot2d_SetupCurvesDlg.cxx @@ -247,7 +247,7 @@ void Plot2d_SetupCurvesDlg::setText( const int theRow, void Plot2d_SetupCurvesDlg::SetParameters( const QVector< int >& theMarker, const QVector< QString >& theText, const QVector< QColor >& theColor, - const QVector< int >& theNbMarkers ) + const QVector< double >& theNbMarkers ) { int nbRows = qMax( qMax( theMarker.size(), theText.size()), qMax( theColor.size(), theNbMarkers.size() ) ); @@ -320,7 +320,7 @@ void Plot2d_SetupCurvesDlg::SetParameters( const QVector< int >& theMarker, void Plot2d_SetupCurvesDlg::GetParameters( QVector< int >& theMarkers, QVector< QString >& theTexts, QVector< QColor >& theColors, - QVector< int >& theNbMarkers ) const + QVector< double >& theNbMarkers ) const { int nbRows = myTable->rowCount(); @@ -352,7 +352,7 @@ void Plot2d_SetupCurvesDlg::GetParameters( QVector< int >& theMarkers, it = myTable->item( i, NB_MARKERS_COL ); QString aStr = it ? it->text() : ""; bool isOk = false; - int nbMarkers = aStr.toInt( &isOk ); + double nbMarkers = aStr.toDouble( &isOk ); if ( isOk ) theNbMarkers[ i ] = nbMarkers; else @@ -382,7 +382,7 @@ bool Plot2d_SetupCurvesDlg::acceptData() const QTableWidgetItem* it = myTable->item( i, NB_MARKERS_COL ); QString aStr = it ? it->text() : ""; bool isOk = false; - int nbMarkers = aStr.toInt( &isOk ); + double nbMarkers = aStr.toDouble( &isOk ); if ( !isOk || nbMarkers<= 0 ) { SUIT_MessageBox::information( (QWidget*)this, tr( "PLOT2D_INSUFFICIENT_DATA" ), diff --git a/src/Plot2d/Plot2d_SetupCurvesDlg.h b/src/Plot2d/Plot2d_SetupCurvesDlg.h index c7fb1c1c8..b2df05d08 100755 --- a/src/Plot2d/Plot2d_SetupCurvesDlg.h +++ b/src/Plot2d/Plot2d_SetupCurvesDlg.h @@ -54,12 +54,12 @@ public: void SetParameters( const QVector< int >& theMarker, const QVector< QString >& theText, const QVector< QColor >& theColor, - const QVector< int >& theNbMarkers ); + const QVector< double >& theNbMarkers ); void GetParameters( QVector< int >& theMarker, QVector< QString >& theText, QVector< QColor >& theColor, - QVector< int >& theNbMarkers ) const; + QVector< double >& theNbMarkers ) const; const QList< int >& GetRemovedIndexes() const; diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index b7c609afa..dbae00e07 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -1074,7 +1074,7 @@ void Plot2d_ViewFrame::onCurvesSettings() QVector< int > aMarkers( nbCurves ); QVector< QString > aTexts( nbCurves ); QVector< QColor > aColors( nbCurves ); - QVector< int > nbMarkers( nbCurves ); + QVector< double > nbMarkers( nbCurves ); QList< Plot2d_Curve* > aCurves; @@ -1091,7 +1091,7 @@ void Plot2d_ViewFrame::onCurvesSettings() if ( aText.isEmpty() ) aText = aCurve->getVerTitle(); QColor aColor = aCurve->getColor(); - int nbMarker = aCurve->getNbMarkers(); + double nbMarker = aCurve->getNbMarkers(); aMarkers[ i ] = aMarkerType; aTexts[ i ] = aText; @@ -1148,14 +1148,14 @@ void Plot2d_ViewFrame::onCurvesSettings() isHorTitle = false; } QColor anOldColor = aCurve->getColor(); - int anOldNbMarker = aCurve->getNbMarkers(); + double anOldNbMarker = aCurve->getNbMarkers(); // new values Plot2d::MarkerType aMarker = (Plot2d::MarkerType)aMarkers[ i ]; QString aText = aTexts[ i ]; QColor aColor = aColors[ i ]; - int nbMarker = nbMarkers[ i ]; + double nbMarker = nbMarkers[ i ]; bool toUpdate = false; @@ -1910,7 +1910,7 @@ Plot2d_PlotCurve::~Plot2d_PlotCurve() (for example) then markers are displayed for steps and two markers are displayed between side by side steps. */ -void Plot2d_PlotCurve::setNbMarkers( const int theNbMarkers ) +void Plot2d_PlotCurve::setNbMarkers( const double theNbMarkers ) { myNbMarkers = theNbMarkers; } @@ -1921,7 +1921,7 @@ void Plot2d_PlotCurve::setNbMarkers( const int theNbMarkers ) (for example) then markers are displayed for steps and two markers are displayed between side by side steps. */ -int Plot2d_PlotCurve::nbMarkers() const +double Plot2d_PlotCurve::nbMarkers() const { return myNbMarkers; } @@ -1945,34 +1945,44 @@ void Plot2d_PlotCurve::drawSymbols( QPainter *p, const QwtSymbol &symbol, } else { + double aTail = 0.0; for ( int i = from; i <= to; i++ ) { - const int u = xMap.transform(x(i)); - const int v = yMap.transform(y(i)); + double u1 = xMap.transform( x( i ) ); + double v1 = yMap.transform( y( i ) ); - rect.moveCenter( QPoint( u, v ) ); - symbol.draw( p, rect ); + if ( i == to && myNbMarkers > 0 ) + { + rect.moveCenter( QPoint( u1, v1 ) ); + symbol.draw( p, rect ); + } - // draw markers between current and previous step - if ( myNbMarkers > 1 && i >= 1 ) + if ( i > from && myNbMarkers > 0 ) { - int u_1 = xMap.transform( x( i - 1 ) ); - int v_1 = yMap.transform( y( i - 1 ) ); + double u0 = xMap.transform( x( i - 1 ) ); + double v0 = yMap.transform( y( i - 1 ) ); - if ( u_1 == u ) + if ( u1 == u0 && v1 == v0 ) continue; - double k = ( (double)( v_1 - v ) ) / ( u_1 - u ); - double b = v - k * u; - double step = ( (double)( u - u_1 ) ) / myNbMarkers; - for ( int ind = 1; ind < myNbMarkers; ind++ ) - { - int X = (int)( u_1 + step * ind ); - int Y = (int)( k * X + b ); + double dX = ( u1 - u0 ) / myNbMarkers; + double dY = ( v1 - v0 ) / myNbMarkers; + + double u = u0 + dX * aTail; + double v = v0 + dY * aTail; - rect.moveCenter( QPoint( X, Y ) ); + while ( aTail >= 0 && u <= u1 && v <= v1 ) + { + rect.moveCenter( QPoint( u, v ) ); symbol.draw( p, rect ); + + u += dX; + v += dY; + + aTail += 1; } + + aTail -= myNbMarkers; } } } @@ -2204,7 +2214,7 @@ Plot2d_Curve* Plot2d_Plot2d::getClosestCurve( QPoint p, double& distance, int& i (for example) then markers are displayed for steps and two markers are displayed between side by side steps. */ -bool Plot2d_Plot2d::setCurveNbMarkers( Plot2d_Curve* curve, const int nb ) +bool Plot2d_Plot2d::setCurveNbMarkers( Plot2d_Curve* curve, const double nb ) { Plot2d_PlotCurve* aPlotCurve = dynamic_cast( myCurves.findKey( curve ) ); @@ -2224,7 +2234,7 @@ bool Plot2d_Plot2d::setCurveNbMarkers( Plot2d_Curve* curve, const int nb ) (for example) then markers are displayed for steps and two markers are displayed between side by side steps. */ -int Plot2d_Plot2d::curveNbMarkers( Plot2d_Curve* curve ) const +double Plot2d_Plot2d::curveNbMarkers( Plot2d_Curve* curve ) const { Plot2d_PlotCurve* aPlotCurve = dynamic_cast( myCurves.findKey( curve ) ); diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 0e52ba67e..30b7424cb 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -259,8 +259,8 @@ public: int xAxis = xBottom, int yAxis = yLeft ); - bool setCurveNbMarkers( Plot2d_Curve* curve, const int nb ); - int curveNbMarkers( Plot2d_Curve* curve ) const; + bool setCurveNbMarkers( Plot2d_Curve* curve, const double nb ); + double curveNbMarkers( Plot2d_Curve* curve ) const; void setZoomBase( const bool doReplot = true ); @@ -291,8 +291,8 @@ public: Plot2d_PlotCurve( const QString &title ); virtual ~Plot2d_PlotCurve(); - void setNbMarkers( const int ); - int nbMarkers() const; + void setNbMarkers( const double ); + double nbMarkers() const; protected: @@ -301,7 +301,7 @@ protected: int from, int to) const; private: - int myNbMarkers; + double myNbMarkers; }; #endif -- 2.39.2