From 3f001aaa41ea29b54de780d808f6cc8833b86a25 Mon Sep 17 00:00:00 2001 From: ana Date: Wed, 26 Oct 2011 12:09:30 +0000 Subject: [PATCH] Implementation of the "21384: [CEA 508] Plot2d Allow user to rescale curve" isuue. --- src/Plot2d/Makefile.am | 3 + src/Plot2d/Plot2d_Object.cxx | 33 +++++- src/Plot2d/Plot2d_Object.h | 5 + src/Plot2d/Plot2d_SetupCurveScaleDlg.cxx | 138 +++++++++++++++++++++++ src/Plot2d/Plot2d_SetupCurveScaleDlg.h | 58 ++++++++++ src/Plot2d/resources/Plot2d_msg_en.ts | 11 ++ 6 files changed, 242 insertions(+), 6 deletions(-) create mode 100755 src/Plot2d/Plot2d_SetupCurveScaleDlg.cxx create mode 100755 src/Plot2d/Plot2d_SetupCurveScaleDlg.h diff --git a/src/Plot2d/Makefile.am b/src/Plot2d/Makefile.am index 350af593e..7281b669d 100755 --- a/src/Plot2d/Makefile.am +++ b/src/Plot2d/Makefile.am @@ -44,6 +44,7 @@ salomeinclude_HEADERS = \ Plot2d_ViewModel.h \ Plot2d_ViewWindow.h \ Plot2d_SetupCurveDlg.h \ + Plot2d_SetupCurveScaleDlg.h \ Plot2d_ToolTip.h dist_libPlot2d_la_SOURCES = \ @@ -60,6 +61,7 @@ dist_libPlot2d_la_SOURCES = \ Plot2d_ViewModel.cxx \ Plot2d_ViewWindow.cxx \ Plot2d_SetupCurveDlg.cxx \ + Plot2d_SetupCurveScaleDlg.cxx \ Plot2d_ToolTip.cxx MOC_FILES = \ @@ -70,6 +72,7 @@ MOC_FILES = \ Plot2d_ViewModel_moc.cxx \ Plot2d_ViewWindow_moc.cxx \ Plot2d_SetupCurveDlg_moc.cxx \ + Plot2d_SetupCurveScaleDlg_moc.cxx \ Plot2d_ToolTip_moc.cxx nodist_libPlot2d_la_SOURCES = $(MOC_FILES) diff --git a/src/Plot2d/Plot2d_Object.cxx b/src/Plot2d/Plot2d_Object.cxx index c018e99f5..6f07e7042 100755 --- a/src/Plot2d/Plot2d_Object.cxx +++ b/src/Plot2d/Plot2d_Object.cxx @@ -78,7 +78,8 @@ Plot2d_Object::Plot2d_Object() myName( "" ), myXAxis( QwtPlot::xBottom ), myYAxis( QwtPlot::yLeft ), - myIsSelected(false) + myIsSelected(false), + myScale ( 1.0 ) { } @@ -103,6 +104,7 @@ Plot2d_Object::Plot2d_Object( const Plot2d_Object& object ) myXAxis = object.getXAxis(); myYAxis = object.getYAxis(); myPoints = object.getPointList(); + myScale = object.getScale(); } /*! @@ -119,6 +121,7 @@ Plot2d_Object& Plot2d_Object::operator=( const Plot2d_Object& object ) myXAxis = object.getXAxis(); myYAxis = object.getYAxis(); myPoints = object.getPointList(); + myScale = object.getScale(); return *this; } @@ -146,7 +149,10 @@ void Plot2d_Object::updatePlotItem( QwtPlotItem* theItem ) theItem->attach( aPlot ); } } - theItem->setTitle( !getName().isEmpty() ? getName() : getVerTitle() ); + QString name = !getName().isEmpty() ? getName() : getVerTitle(); + if( myScale != 1.0 ) + name = name + QString("( *%1 )").arg(myScale); + theItem->setTitle( name ); } /*! @@ -236,6 +242,21 @@ QString Plot2d_Object::getName() const return myName; } +/*! + Sets object's scale factor + */ +void Plot2d_Object::setScale( double theScale ) +{ + myScale = theScale; +} +/*! + Gets object's scale factor + */ +double Plot2d_Object::getScale() const +{ + return myScale; +} + /*! Adds one point for object. */ @@ -337,7 +358,7 @@ double* Plot2d_Object::verData() const int aNPoints = nbPoints(); double* aY = new double[aNPoints]; for (int i = 0; i < aNPoints; i++) { - aY[i] = myPoints[i].y; + aY[i] = myScale * myPoints[i].y; } return aY; } @@ -352,7 +373,7 @@ long Plot2d_Object::getData( double** theX, double** theY ) const *theY = new double[aNPoints]; for (int i = 0; i < aNPoints; i++) { (*theX)[i] = myPoints[i].x; - (*theY)[i] = myPoints[i].y; + (*theY)[i] = myScale * myPoints[i].y; } return aNPoints; } @@ -475,7 +496,7 @@ double Plot2d_Object::getMinY() const double aMinY = 1e150; pointList::const_iterator aIt; for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) - aMinY = qMin( aMinY, (*aIt).y ); + aMinY = qMin( aMinY, myScale * (*aIt).y ); return aMinY; } @@ -487,7 +508,7 @@ double Plot2d_Object::getMaxY() const double aMaxY = -1e150; pointList::const_iterator aIt; for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) - aMaxY = qMax( aMaxY, (*aIt).y ); + aMaxY = qMax( aMaxY, myScale * (*aIt).y ); return aMaxY; } diff --git a/src/Plot2d/Plot2d_Object.h b/src/Plot2d/Plot2d_Object.h index 5a2fffb66..bc7a5babc 100755 --- a/src/Plot2d/Plot2d_Object.h +++ b/src/Plot2d/Plot2d_Object.h @@ -71,6 +71,9 @@ public: void setName( const QString& ); QString getName() const; + void setScale( double ); + double getScale() const; + void addPoint( double, double, const QString& = QString() ); void addPoint( const Plot2d_Point& ); void insertPoint( int, double, double, const QString& = QString() ); @@ -131,6 +134,8 @@ protected: QwtPlot::Axis myXAxis; QwtPlot::Axis myYAxis; + double myScale; + pointList myPoints; bool myIsSelected; diff --git a/src/Plot2d/Plot2d_SetupCurveScaleDlg.cxx b/src/Plot2d/Plot2d_SetupCurveScaleDlg.cxx new file mode 100755 index 000000000..903af1a38 --- /dev/null +++ b/src/Plot2d/Plot2d_SetupCurveScaleDlg.cxx @@ -0,0 +1,138 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : Plot2d_SetupCurveScaleDlg.cxx +// +#include "Plot2d_SetupCurveScaleDlg.h" + +#include + +#include +#include +#include +#include +#include + +#include + +const int MARGIN_SIZE = 11; +const int SPACING_SIZE = 6; +const int MIN_COMBO_WIDTH = 100; +const int MIN_SPIN_WIDTH = 50; + +/*! + \class Plot2d_SetupCurveScaleDlg + \brief Dialog box for modifying 2d curve scale factor. +*/ + +/*! + \brief Constructor. + \param parent parent widget +*/ +Plot2d_SetupCurveScaleDlg::Plot2d_SetupCurveScaleDlg( /*curveList lst, */QWidget* parent ) +: QDialog( parent ) +{ + setModal( true ); + setWindowTitle( tr("TLT_SETUP_CURVE_SCALE") ); + setSizeGripEnabled( true ); + + /************************************************************************/ + QGroupBox* GroupC1 = new QGroupBox( this ); + QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 ); + GroupC1Layout->setSpacing( SPACING_SIZE ); + GroupC1Layout->setMargin( MARGIN_SIZE ); + + QLabel* aScaleLab = new QLabel( tr( "CURVE_SCALE_FACTOR" ), GroupC1 ); + myValueSpin = new QtxDoubleSpinBox( GroupC1 ); + myValueSpin->setMinimum( 0.01 ); + myValueSpin->setSingleStep( 0.1 ); + myValueSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + + GroupC1Layout->addWidget( aScaleLab ); + GroupC1Layout->addWidget( myValueSpin ); + + /************************************************************************/ + QGroupBox* GroupButtons = new QGroupBox( this ); + QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons ); + GroupButtonsLayout->setSpacing( SPACING_SIZE ); + GroupButtonsLayout->setMargin( MARGIN_SIZE ); + + myOkBtn = new QPushButton( tr( "BUT_OK" ), this ); + myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this ); + + GroupButtonsLayout->addWidget( myOkBtn ); + GroupButtonsLayout->addSpacing( 10 ); + GroupButtonsLayout->addWidget( myCancelBtn ); + + /************************************************************************/ + QVBoxLayout* topLayout = new QVBoxLayout( this ); + topLayout->setSpacing( SPACING_SIZE ); + topLayout->setMargin( MARGIN_SIZE ); + topLayout->addWidget( GroupC1 ); + topLayout->addWidget( GroupButtons ); + + // default settings + setScale( 1.0 ); // no scale + + // connections + connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); + + SUIT_Tools::centerWidget( this, parent ); +} + +/*! + \brief Destructor. +*/ +Plot2d_SetupCurveScaleDlg::~Plot2d_SetupCurveScaleDlg() +{ +} + +/*! + \brief Set scale factor. + \param coef scale factor + \sa getScale() +*/ +void Plot2d_SetupCurveScaleDlg::setScale( const double coef ) +{ + if ( coef > myValueSpin->maximum() ){ + myValueSpin->setMaximum( coef ); + } + myValueSpin->setValue( coef ); +} + +/*! + \brief Get scale factor. + \return chosen scale factor + \sa setScale() +*/ +double Plot2d_SetupCurveScaleDlg::getScale() const +{ + return myValueSpin->value(); +} +/*! + \brief Clear value in the "Scale factor" spinbox. +*/ +void Plot2d_SetupCurveScaleDlg::setUndefinedValue() { + myValueSpin->setCleared(true); + myValueSpin->setSpecialValueText(""); +} \ No newline at end of file diff --git a/src/Plot2d/Plot2d_SetupCurveScaleDlg.h b/src/Plot2d/Plot2d_SetupCurveScaleDlg.h new file mode 100755 index 000000000..5575c4f17 --- /dev/null +++ b/src/Plot2d/Plot2d_SetupCurveScaleDlg.h @@ -0,0 +1,58 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : Plot2d_SetupCurveScaleDlg.h +// +#ifndef PLOT2D_SETUPCURVESCALEDLG_H +#define PLOT2D_SETUPCURVESCALEDLG_H + +#include "Plot2d.h" + +#include + +class QPushButton; +class QLabel; + +class QtxDoubleSpinBox; + +class PLOT2D_EXPORT Plot2d_SetupCurveScaleDlg : public QDialog +{ + Q_OBJECT + +public: + Plot2d_SetupCurveScaleDlg( /*curveList,*/ QWidget* = 0 ); + ~Plot2d_SetupCurveScaleDlg(); + +public: + void setScale( const double ); + double getScale() const; + + void setUndefinedValue(); + +private: + QPushButton* myOkBtn; + QPushButton* myCancelBtn; + QtxDoubleSpinBox* myValueSpin; +}; + +#endif // PLOT2D_SETUPCURVESCALEDLG_H + diff --git a/src/Plot2d/resources/Plot2d_msg_en.ts b/src/Plot2d/resources/Plot2d_msg_en.ts index 3a0ad346b..81a5ede48 100644 --- a/src/Plot2d/resources/Plot2d_msg_en.ts +++ b/src/Plot2d/resources/Plot2d_msg_en.ts @@ -588,4 +588,15 @@ Logarithmic scale for ordinate axis is not allowed. Background color + + Plot2d_SetupCurveScaleDlg + + TLT_SETUP_CURVE_SCALE + Curve(s) scale + + + CURVE_SCALE_FACTOR + Scale factor + + -- 2.39.2