From: mkr Date: Thu, 6 Nov 2008 14:07:22 +0000 (+0000) Subject: Fix for IPAL17690 : Plot 2D grid/axial marks. X-Git-Tag: V4_1_4~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c2fe3ad9c10500506f5b708a2be5e6e4e6011699;p=modules%2Fgui.git Fix for IPAL17690 : Plot 2D grid/axial marks. --- diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index afa7baa03..325435af3 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -151,7 +151,7 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ), myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ), myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ), - myXMode( 0 ), myYMode( 0 ), mySecondY( false ) + myXMode( 0 ), myYMode( 0 ), mySecondY( false ), myIsRescaled( false ) { /* Plot 2d View */ QVBoxLayout* aLayout = new QVBoxLayout( this ); @@ -170,6 +170,8 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) this, SLOT( plotMouseReleased( const QMouseEvent& ) ) ); connect( myPlot, SIGNAL( legendClicked( long ) ), this, SIGNAL( legendClicked( long ) ) ); + connect( myPlot, SIGNAL( rescale() ), + this, SLOT( rescale() ) ); /* Initial Setup - get from the preferences */ readPreferences(); @@ -801,26 +803,26 @@ void Plot2d_ViewFrame::fitAll() myPlot->setAxisAutoScale( QwtPlot::yLeft ); myPlot->setAxisAutoScale( QwtPlot::xBottom ); - myPlot->replot(); + //myPlot->replot(); // for existing grid QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); myPlot->setAxisScale( QwtPlot::xBottom, - myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ), - myPlot->invTransform( QwtPlot::xBottom, xMap.i2() ) ); + QString::number(myPlot->invTransform( QwtPlot::xBottom, xMap.i1() )).toDouble(), + QString::number(myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )).toDouble() ); myPlot->setAxisScale( QwtPlot::yLeft, - myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), - myPlot->invTransform( QwtPlot::yLeft, yMap.i2() ) ); + QString::number(myPlot->invTransform( QwtPlot::yLeft, yMap.i1() )).toDouble(), + QString::number(myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )).toDouble() ); if (mySecondY) { myPlot->setAxisAutoScale( QwtPlot::yRight ); myPlot->replot(); QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight ); myPlot->setAxisScale( QwtPlot::yRight, - myPlot->invTransform( QwtPlot::yRight, yMap2.i1() ), - myPlot->invTransform( QwtPlot::yRight, yMap2.i2() ) ); + QString::number(myPlot->invTransform( QwtPlot::yRight, yMap2.i1() )).toDouble(), + QString::number(myPlot->invTransform( QwtPlot::yRight, yMap2.i2() )).toDouble() ); } myPlot->replot(); } @@ -1478,6 +1480,28 @@ void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me ) aParent->putInfo(tr("INF_READY")); myOperation = NoOpId; } + +/*! + Slot, rescales axis on the first show of view frame in order to take into account the correct canvas map +*/ +void Plot2d_ViewFrame::rescale() +{ + if ( myPlot && !myIsRescaled ) { + myIsRescaled = true; + + QwtDiMap map; + int axis[3] = { QwtPlot::xBottom, QwtPlot::yLeft, QwtPlot::yRight }; + double dMin, dMax; + for ( int i = 0; i < 3; i++ ) + if ( i < 2 || i == 2 && mySecondY ) { + map = myPlot->canvasMap(axis[i]); + dMin = myPlot->invTransform(axis[i], map.i1()); dMax = myPlot->invTransform(axis[i], map.i2()); + myPlot->setAxisScale( axis[i], QString::number(dMin).toDouble(), QString::number(dMax).toDouble() ); + } + myPlot->replot(); + } +} + /*! Slot, called when user wheeling mouse */ @@ -1780,6 +1804,18 @@ bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor return false; } +/*! + Emits rescale() signal on the first drawing of the QwtPlotCanvas. +*/ +void Plot2d_Plot2d::drawCanvas(QPainter *painter) +{ + if ( Plot2d_ViewFrame* aVF = dynamic_cast(parentWidget()) ) + if ( !aVF->isRescaled() ) + emit rescale(); + + QwtPlot::drawCanvas(painter); +} + /*! Sets the flag saying that QwtPlot geometry has been fully defined. */ diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 1ca3f197f..558790db7 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -125,6 +125,8 @@ public: void incrementalPan ( const int incrX, const int incrY ); void incrementalZoom( const int incrX, const int incrY ); + bool isRescaled() const { return myIsRescaled; } + protected: int testOperation( const QMouseEvent& ); void readPreferences(); @@ -156,6 +158,7 @@ protected slots: void plotMousePressed( const QMouseEvent& ); void plotMouseMoved( const QMouseEvent& ); void plotMouseReleased( const QMouseEvent& ); + void rescale(); signals: void vpModeHorChanged(); @@ -184,6 +187,7 @@ protected: int myXMode, myYMode; double myXDistance, myYDistance, myYDistance2; bool mySecondY; + bool myIsRescaled; }; class Plot2d_Plot2d : public QwtPlot @@ -210,8 +214,12 @@ public: public slots: virtual void polish(); +signals: + void rescale(); + protected: - bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ); + bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ); + virtual void drawCanvas(QPainter *); protected: QValueList myColors;