From: nds Date: Tue, 18 Sep 2007 07:22:50 +0000 (+0000) Subject: File from WPdev branch X-Git-Tag: TG_Saint_Valentine-Day~60 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a6a6319bdbd20ca22303950e0bf3ba6e857ce8e5;p=modules%2Fgui.git File from WPdev branch --- diff --git a/src/Plot2d/Makefile.in b/src/Plot2d/Makefile.in new file mode 100755 index 000000000..73af7206c --- /dev/null +++ b/src/Plot2d/Makefile.in @@ -0,0 +1,96 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# 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 : Makefile.in +# Author : Vladimir Klyachin (OCN) +# Module : Plot2d +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@srcdir@/resources + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= Plot2d.h \ + Plot2d_Curve.h \ + Plot2d_FitDataDlg.h \ + Plot2d_Prs.h \ + Plot2d_SetupViewDlg.h \ + Plot2d_ViewFrame.h \ + Plot2d_ViewManager.h \ + Plot2d_ViewModel.h \ + Plot2d_ViewWindow.h \ + Plot2d_SetupCurveDlg.h \ + Plot2d_ToolTip.h + +# .po files to transform in .qm +PO_FILES = Plot2d_images.po \ + Plot2d_msg_en.po + +# Libraries targets +LIB = libPlot2d.la +LIB_SRC= Plot2d_Curve.cxx \ + Plot2d_FitDataDlg.cxx \ + Plot2d_Prs.cxx \ + Plot2d_SetupViewDlg.cxx \ + Plot2d_ViewFrame.cxx \ + Plot2d_ViewManager.cxx \ + Plot2d_ViewModel.cxx \ + Plot2d_ViewWindow.cxx \ + Plot2d_SetupCurveDlg.cxx \ + Plot2d_ToolTip.cxx + +LIB_MOC = \ + Plot2d_FitDataDlg.h \ + Plot2d_SetupViewDlg.h \ + Plot2d_ViewFrame.h \ + Plot2d_ViewManager.h \ + Plot2d_ViewModel.h \ + Plot2d_ViewWindow.h \ + Plot2d_SetupCurveDlg.h \ + Plot2d_ToolTip.h + +RESOURCES_FILES = \ +plot2d_clone.png \ +plot2d_camera_dump.png \ +plot2d_fitall.png \ +plot2d_fitarea.png \ +plot2d_glpan.png \ +plot2d_legend.png \ +plot2d_linear.png \ +plot2d_linear_y.png \ +plot2d_lines.png \ +plot2d_log.png \ +plot2d_log_y.png \ +plot2d_pan.png \ +plot2d_points.png \ +plot2d_settings.png \ +plot2d_splines.png \ +plot2d_zoom.png + +CPPFLAGS+=$(QT_INCLUDES) $(PYTHON_INCLUDES) $(QWT_INCLUDES) + +LDFLAGS+=$(QWT_LIBS) $(QT_MT_LIBS) -lsuit + +@CONCLUDE@ + + diff --git a/src/Plot2d/Plot2d.h b/src/Plot2d/Plot2d.h new file mode 100755 index 000000000..20deb6ec1 --- /dev/null +++ b/src/Plot2d/Plot2d.h @@ -0,0 +1,31 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifdef WNT +#ifdef PLOT2D_EXPORTS +#define PLOT2D_EXPORT __declspec(dllexport) +#else +#define PLOT2D_EXPORT __declspec(dllimport) +#endif +#else +#define PLOT2D_EXPORT +#endif + +#if defined WNT +#pragma warning ( disable: 4251 ) +#endif diff --git a/src/Plot2d/Plot2d_Curve.cxx b/src/Plot2d/Plot2d_Curve.cxx new file mode 100755 index 000000000..bec633fdc --- /dev/null +++ b/src/Plot2d/Plot2d_Curve.cxx @@ -0,0 +1,417 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#include "Plot2d_Curve.h" +#include + +/*! + Constructor +*/ +Plot2d_Curve::Plot2d_Curve() +: myHorTitle( "" ), myVerTitle( "" ), +myHorUnits( "" ), myVerUnits( "" ), +myAutoAssign( true ), myColor( 0,0,0 ), myMarker( Circle ), myLine( Solid ), myLineWidth( 0 ), +myYAxis( QwtPlot::yLeft ) +{ +} + +/*! + Destructor +*/ +Plot2d_Curve::~Plot2d_Curve() +{ +} + +/*! + Copy constructor. Makes deep copy of data. +*/ +Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve ) +{ + myAutoAssign = curve.isAutoAssign(); + myHorTitle = curve.getHorTitle(); + myVerTitle = curve.getVerTitle(); + myHorUnits = curve.getHorUnits(); + myVerUnits = curve.getVerUnits(); + myColor = curve.getColor(); + myMarker = curve.getMarker(); + myLine = curve.getLine(); + myLineWidth = curve.getLineWidth(); + myPoints = curve.getPointList(); +} + +/*! + operator=. Makes deep copy of data. +*/ +Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve ) +{ + myAutoAssign = curve.isAutoAssign(); + myHorTitle = curve.getHorTitle(); + myVerTitle = curve.getVerTitle(); + myHorUnits = curve.getHorUnits(); + myVerUnits = curve.getVerUnits(); + myColor = curve.getColor(); + myMarker = curve.getMarker(); + myLine = curve.getLine(); + myLineWidth = curve.getLineWidth(); + myPoints = curve.getPointList(); + return *this; +} + +/*! + \return title of table +*/ +QString Plot2d_Curve::getTableTitle() const +{ + return QString(); +} + +/*! + Sets curve's horizontal title +*/ +void Plot2d_Curve::setHorTitle( const QString& title ) +{ + myHorTitle = title; +} + +/*! + Gets curve's horizontal title +*/ +QString Plot2d_Curve::getHorTitle() const +{ + return myHorTitle; +} + +/*! + Sets curve's vertical title +*/ +void Plot2d_Curve::setVerTitle( const QString& title ) +{ + myVerTitle = title; +} + +/*! + Gets curve's vertical title +*/ +QString Plot2d_Curve::getVerTitle() const +{ + return myVerTitle; +} + +/*! + Sets curve's horizontal units +*/ +void Plot2d_Curve::setHorUnits( const QString& units ) +{ + myHorUnits = units; +} + +/*! + Gets curve's horizontal units +*/ +QString Plot2d_Curve::getHorUnits() const +{ + return myHorUnits; +} + +/*! + Sets curve's vertical units +*/ +void Plot2d_Curve::setVerUnits( const QString& units ) +{ + myVerUnits = units; +} + +/*! + Gets curve's vertical units +*/ +QString Plot2d_Curve::getVerUnits() const +{ + return myVerUnits; +} + +/*! + Adds one point for curve. +*/ +void Plot2d_Curve::addPoint(double theX, double theY, const QString& txt ) +{ + Plot2d_Point aPoint; + aPoint.x = theX; + aPoint.y = theY; + aPoint.text = txt; + myPoints.append(aPoint); +} + +/*! + Insert one point for curve on some position. +*/ +void Plot2d_Curve::insertPoint(int thePos, double theX, double theY, const QString& txt) +{ + Plot2d_Point aPoint; + aPoint.x = theX; + aPoint.y = theY; + aPoint.text = txt; + + QValueList::iterator aIt; + int aCurrent = 0; + for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { + if (thePos == aCurrent) { + myPoints.insert(aIt, aPoint); + return; + } + aCurrent++; + } + myPoints.append(aPoint); +} + +/*! + Delete one point for curve on some position. +*/ +void Plot2d_Curve::deletePoint(int thePos) +{ + QValueList::iterator aIt; + int aCurrent = 0; + for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { + if (thePos == aCurrent) { + myPoints.remove(aIt); + return; + } + aCurrent++; + } +} + +/*! + Remove all points for curve. +*/ +void Plot2d_Curve::clearAllPoints() +{ + myPoints.clear(); +} + +/*! + Gets curve's data : abscissas of points +*/ +pointList Plot2d_Curve::getPointList() const +{ + return myPoints; +} + +/*! + Sets curve's data. +*/ +void Plot2d_Curve::setData( const double* hData, const double* vData, long size, const QStringList& lst ) +{ + clearAllPoints(); + QStringList::const_iterator anIt = lst.begin(), aLast = lst.end(); + for( long i = 0; i < size; i++, anIt++ ) + addPoint( hData[i], vData[i], anIt==aLast ? QString::null : *anIt ); +} + +/*! + Gets curve's data : abscissas of points +*/ +double* Plot2d_Curve::horData() const +{ + int aNPoints = nbPoints(); + double* aX = new double[aNPoints]; + for (int i = 0; i < aNPoints; i++) { + aX[i] = myPoints[i].x; + } + return aX; +} + +/*! + Gets curve's data : ordinates of points +*/ +double* Plot2d_Curve::verData() const +{ + int aNPoints = nbPoints(); + double* aY = new double[aNPoints]; + for (int i = 0; i < aNPoints; i++) { + aY[i] = myPoints[i].y; + } + return aY; +} + +/*! + Gets curve's data : number of points +*/ +int Plot2d_Curve::nbPoints() const +{ + return myPoints.count(); +} + +/*! + Returns true if curve has no data +*/ +bool Plot2d_Curve::isEmpty() const +{ + return myPoints.isEmpty(); +} + +/*! + Sets curve's AutoAssign flag - in this case attributes will be set automatically +*/ +void Plot2d_Curve::setAutoAssign( bool on ) +{ + myAutoAssign = on; +} + +/*! + Gets curve's AutoAssign flag state +*/ +bool Plot2d_Curve::isAutoAssign() const +{ + return myAutoAssign; +} + +/*! + Sets curve's color ( and resets AutoAssign flag ) +*/ +void Plot2d_Curve::setColor( const QColor& color ) +{ + myColor = color; + myAutoAssign = false; +} + +/*! + Gets curve's color +*/ +QColor Plot2d_Curve::getColor() const +{ + return myColor; +} + +/*! + Sets curve's marker ( and resets AutoAssign flag ) +*/ +void Plot2d_Curve::setMarker( MarkerType marker ) +{ + myMarker = marker; + myAutoAssign = false; +} + +/*! + Gets curve's marker +*/ +Plot2d_Curve::MarkerType Plot2d_Curve::getMarker() const +{ + return myMarker; +} + +/*! + Sets curve's line type and width ( and resets AutoAssign flag ) + NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals. + A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate + algorithm for diagonals. + For horizontal and vertical lines a line width of 0 is the same as a line width of 1. +*/ +void Plot2d_Curve::setLine( LineType line, const int lineWidth ) +{ + myLine = line; + myLineWidth = lineWidth; + if ( myLineWidth < 0 ) myLineWidth = 0; + myAutoAssign = false; +} + +/*! + Gets curve's line type +*/ +Plot2d_Curve::LineType Plot2d_Curve::getLine() const +{ + return myLine; +} + +/*! + Gets curve's line width +*/ +int Plot2d_Curve::getLineWidth() const +{ + return myLineWidth; +} + +/*! + Sets curve's y axis +*/ +void Plot2d_Curve::setYAxis(QwtPlot::Axis theYAxis) +{ + if(theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight) + myYAxis = theYAxis; +} + +/*! + Gets curve's y axis +*/ +QwtPlot::Axis Plot2d_Curve::getYAxis() const +{ + return myYAxis; +} + +/*! + Gets curve's minimal abscissa +*/ +double Plot2d_Curve::getMinX() const +{ + QValueList::const_iterator aIt; + double aMinX = 1e150; + //int aCurrent = 0; + for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { + if ( (*aIt).x < aMinX ) + aMinX = (*aIt).x; + } + return aMinX; +} + +/*! + Gets curve's minimal ordinate +*/ +double Plot2d_Curve::getMinY() const +{ + QValueList::const_iterator aIt; + double aMinY = 1e150; + //int aCurrent = 0; + for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { + if ( (*aIt).y < aMinY ) + aMinY = (*aIt).y; + } + return aMinY; +} + +/*! + Changes text assigned to point of curve + \param ind -- index of point + \param txt -- new text +*/ +void Plot2d_Curve::setText( const int ind, const QString& txt ) +{ + if( ind<0 || ind>=myPoints.count() ) + return; + + myPoints[ind].text = txt; +} + +/*! + \return text assigned to point + \param ind -- index of point +*/ +QString Plot2d_Curve::text( const int ind ) const +{ + if( ind<0 || ind>=myPoints.count() ) + return QString::null; + else + return myPoints[ind].text; +} diff --git a/src/Plot2d/Plot2d_Curve.h b/src/Plot2d/Plot2d_Curve.h new file mode 100755 index 000000000..bd3be97bd --- /dev/null +++ b/src/Plot2d/Plot2d_Curve.h @@ -0,0 +1,112 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifndef PLOT2D_CURVE_H +#define PLOT2D_CURVE_H + +#include "Plot2d.h" +#include +#include +#include + +class QColor; + +typedef struct +{ + double x; + double y; + QString text; +} Plot2d_Point; + +typedef QValueList pointList; + +class PLOT2D_EXPORT Plot2d_Curve +{ +public: + enum MarkerType { None, Circle, Rectangle, Diamond, + DTriangle, UTriangle, LTriangle, RTriangle, + Cross, XCross }; + enum LineType { NoPen, Solid, Dash, Dot, DashDot, DashDotDot }; + + Plot2d_Curve(); + virtual ~Plot2d_Curve(); + Plot2d_Curve( const Plot2d_Curve& curve ); + Plot2d_Curve& operator= ( const Plot2d_Curve& curve ); + + virtual QString getTableTitle() const; + + void setHorTitle( const QString& title ); + QString getHorTitle() const; + void setVerTitle( const QString& title ); + QString getVerTitle() const; + void setHorUnits( const QString& units ); + QString getHorUnits() const; + void setVerUnits( const QString& units ); + QString getVerUnits() const; + void addPoint(double theX, double theY, const QString& = QString::null ); + void insertPoint(int thePos, double theX, double theY, const QString& = QString::null ); + void deletePoint(int thePos); + void clearAllPoints(); + pointList getPointList() const; + + void setData( const double* hData, const double* vData, long size, const QStringList& = QStringList() ); + double* horData() const; + double* verData() const; + + void setText( const int, const QString& ); + QString text( const int ) const; + + int nbPoints() const; + bool isEmpty() const; + + void setAutoAssign( bool on ); + bool isAutoAssign() const; + void setColor( const QColor& color ); + QColor getColor() const; + void setMarker( MarkerType marker ); + MarkerType getMarker() const; + void setLine( LineType line, const int lineWidth = 0 ); + LineType getLine() const; + int getLineWidth() const; + void setYAxis(QwtPlot::Axis theYAxis); + QwtPlot::Axis getYAxis() const; + + // Protection against QwtCurve::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 getMinY() const; + +protected: + bool myAutoAssign; + QString myHorTitle; + QString myVerTitle; + QString myHorUnits; + QString myVerUnits; + QColor myColor; + MarkerType myMarker; + LineType myLine; + int myLineWidth; + QwtPlot::Axis myYAxis; + + pointList myPoints; +}; + +typedef QPtrList curveList; + +#endif diff --git a/src/Plot2d/Plot2d_FitDataDlg.cxx b/src/Plot2d/Plot2d_FitDataDlg.cxx new file mode 100755 index 000000000..9ff544a07 --- /dev/null +++ b/src/Plot2d/Plot2d_FitDataDlg.cxx @@ -0,0 +1,288 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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_FitDataDlg.cxx +// Author : Vadim SANDLER +// Module : SALOME +// $Header$ + +#include "Plot2d_FitDataDlg.h" +#include +#include +#include +#include +#include +#include +#include + +#define SPACING_SIZE 6 +#define MARGIN_SIZE 11 +#define MIN_EDIT_SIZE 100 + +/*! + Constructor +*/ +Plot2d_FitDataDlg::Plot2d_FitDataDlg( QWidget* parent, bool secondAxisY ) + : QDialog( parent ? parent : 0, + "Plot2d_FitDataDlg", + true, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ), + myY2MinEdit( 0 ), myY2MaxEdit( 0 ), mySecondAxisY( secondAxisY ) + +{ + setCaption( tr( "FIT_DATA_TLT" ) ); + setSizeGripEnabled( TRUE ); + QGridLayout* topLayout = new QGridLayout( this ); + topLayout->setSpacing( SPACING_SIZE ); + topLayout->setMargin( MARGIN_SIZE ); + + // 'Range' group + myRangeGrp = new QButtonGroup( this ); + myRangeGrp->setColumnLayout( 0, Qt::Vertical ); + myRangeGrp->layout()->setSpacing( 0 ); + myRangeGrp->layout()->setMargin( 0 ); + QGridLayout* aGridLayout = new QGridLayout( myRangeGrp->layout() ); + aGridLayout->setAlignment( Qt::AlignTop ); + aGridLayout->setMargin( MARGIN_SIZE ); + aGridLayout->setSpacing( SPACING_SIZE ); + + myModeAllRB = new QRadioButton( tr( "FIT_ALL" ), myRangeGrp ); + myModeHorRB = new QRadioButton( tr( "FIT_HORIZONTAL" ), myRangeGrp ); + myModeVerRB = new QRadioButton( tr( "FIT_VERTICAL" ), myRangeGrp ); + + QDoubleValidator* aValidator = new QDoubleValidator( this ); + myXMinEdit = new QLineEdit( myRangeGrp ); + myXMinEdit->setValidator( aValidator ); + myXMinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myXMinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 ); + myXMinEdit->setText( "0.0" ); + + myYMinEdit = new QLineEdit( myRangeGrp ); + myYMinEdit->setValidator( aValidator ); + myYMinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myYMinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 ); + myYMinEdit->setText( "0.0" ); + + myXMaxEdit = new QLineEdit( myRangeGrp ); + myXMaxEdit->setValidator( aValidator ); + myXMaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myXMaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 ); + myXMaxEdit->setText( "0.0" ); + + myYMaxEdit = new QLineEdit( myRangeGrp ); + myYMaxEdit->setValidator( aValidator ); + myYMaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myYMaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 ); + myYMaxEdit->setText( "0.0" ); + + if (mySecondAxisY) { + myY2MinEdit = new QLineEdit( myRangeGrp ); + myY2MinEdit->setValidator( aValidator ); + myY2MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myY2MinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 ); + myY2MinEdit->setText( "0.0" ); + + myY2MaxEdit = new QLineEdit( myRangeGrp ); + myY2MaxEdit->setValidator( aValidator ); + myY2MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myY2MaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 ); + myY2MaxEdit->setText( "0.0" ); + } + + QFrame* aHLine = new QFrame( myRangeGrp ); + aHLine->setFrameStyle( QFrame::HLine | QFrame::Sunken ); + + QHBoxLayout* aModeLayout = new QHBoxLayout; + aModeLayout->setMargin( 0 ); + aModeLayout->setSpacing( SPACING_SIZE ); + aModeLayout->addWidget( myModeAllRB ); + aModeLayout->addWidget( myModeHorRB ); + aModeLayout->addWidget( myModeVerRB ); + + QLabel* horLab = new QLabel( tr( "HORIZONTAL_AXIS" ), myRangeGrp ); + QLabel* verLab = new QLabel( tr( "VERTICAL_AXIS" ), myRangeGrp ); + if (mySecondAxisY) + verLab->setText( tr( "VERTICAL_LEFT_AXIS" ) ); + + QFont font = horLab->font(); font.setBold( true ); + horLab->setFont( font ); verLab->setFont( font ); + + aGridLayout->addMultiCellLayout( aModeLayout, 0, 0, 0, 4 ); + aGridLayout->addMultiCellWidget( aHLine, 1, 1, 0, 4 ); + aGridLayout->addWidget ( horLab, 2, 0 ); + aGridLayout->addWidget ( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ), + 2, 1 ); + aGridLayout->addWidget ( myXMinEdit, 2, 2 ); + aGridLayout->addWidget ( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ), + 2, 3 ); + aGridLayout->addWidget ( myXMaxEdit, 2, 4 ); + aGridLayout->addWidget ( verLab, 3, 0 ); + aGridLayout->addWidget ( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ), + 3, 1 ); + aGridLayout->addWidget ( myYMinEdit, 3, 2 ); + aGridLayout->addWidget ( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ), + 3, 3 ); + aGridLayout->addWidget ( myYMaxEdit, 3, 4 ); + + if (mySecondAxisY) { + QLabel* ver2Lab = new QLabel(tr( "VERTICAL_RIGHT_AXIS" ), myRangeGrp ); + ver2Lab->setFont( font ); + aGridLayout->addWidget ( ver2Lab, 4, 0 ); + aGridLayout->addWidget ( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ), + 4, 1 ); + aGridLayout->addWidget ( myY2MinEdit, 4, 2 ); + aGridLayout->addWidget ( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ), + 4, 3 ); + aGridLayout->addWidget ( myY2MaxEdit, 4, 4 ); + } + + // OK/Cancel buttons + myOkBtn = new QPushButton( tr( "BUT_OK" ), this, "buttonOk" ); + myOkBtn->setAutoDefault( TRUE ); + myOkBtn->setDefault( TRUE ); + myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this, "buttonCancel" ); + myCancelBtn->setAutoDefault( TRUE ); + + topLayout->addMultiCellWidget( myRangeGrp, 0, 0, 0, 2 ); + topLayout->addWidget( myOkBtn, 1, 0 ); + topLayout->setColStretch( 1, 5 ); + topLayout->addWidget( myCancelBtn, 1, 2 ); + + // connect signals + connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); + connect( myRangeGrp, SIGNAL( clicked( int ) ), this, SLOT( onModeChanged( int ) ) ); + + // initial state + myModeAllRB->setChecked( true ); + onModeChanged( 0 ); +} + +/*! + Sets range +*/ +void Plot2d_FitDataDlg::setRange( const double xMin, + const double xMax, + const double yMin, + const double yMax, + const double y2Min, + const double y2Max) +{ + myXMinEdit->setText( QString::number( xMin ) ); + myXMaxEdit->setText( QString::number( xMax ) ); + myYMinEdit->setText( QString::number( yMin ) ); + myYMaxEdit->setText( QString::number( yMax ) ); + if (mySecondAxisY) { + myY2MinEdit->setText( QString::number( y2Min ) ); + myY2MaxEdit->setText( QString::number( y2Max ) ); + } +} + +/*! + Gets range, returns mode (see getMode()) +*/ +int Plot2d_FitDataDlg::getRange( double& xMin, + double& xMax, + double& yMin, + double& yMax, + double& y2Min, + double& y2Max) +{ + xMin = myXMinEdit->text().toDouble(); + xMax = myXMaxEdit->text().toDouble(); + yMin = myYMinEdit->text().toDouble(); + yMax = myYMaxEdit->text().toDouble(); + if (mySecondAxisY) { + y2Min = myY2MinEdit->text().toDouble(); + y2Max = myY2MaxEdit->text().toDouble(); + } + else { + y2Min = 0; + y2Max = 0; + } + int myMode = 0; + if ( myModeAllRB->isChecked() ) + myMode = 0; + if ( myModeHorRB->isChecked() ) + myMode = 1; + if ( myModeVerRB->isChecked() ) + myMode = 2; + return myMode; +} + +/*! + Gets mode : 0 - Fit all; 1 - Fit horizontal, 2 - Fit vertical +*/ +int Plot2d_FitDataDlg::getMode() +{ + int myMode = 0; + if ( myModeAllRB->isChecked() ) + myMode = 0; + if ( myModeHorRB->isChecked() ) + myMode = 1; + if ( myModeVerRB->isChecked() ) + myMode = 2; + return myMode; +} + +/*! + Called when range mode changed +*/ +void Plot2d_FitDataDlg::onModeChanged(int mode) +{ + bool badFocus; + switch( mode ) { + case 0: // fit all mode + myXMinEdit->setEnabled(true); + myXMaxEdit->setEnabled(true); + myYMinEdit->setEnabled(true); + myYMaxEdit->setEnabled(true); + if (mySecondAxisY) { + myY2MinEdit->setEnabled(true); + myY2MaxEdit->setEnabled(true); + } + break; + case 1: // fit horizontal mode + badFocus = myYMinEdit->hasFocus() || myYMaxEdit->hasFocus(); + myXMinEdit->setEnabled(true); + myXMaxEdit->setEnabled(true); + myYMinEdit->setEnabled(false); + myYMaxEdit->setEnabled(false); + if (mySecondAxisY) { + myY2MinEdit->setEnabled(false); + myY2MaxEdit->setEnabled(false); + } + if (badFocus) + myXMinEdit->setFocus(); + break; + case 2: // fit vertical mode + badFocus = myXMinEdit->hasFocus() || myXMaxEdit->hasFocus(); + myXMinEdit->setEnabled(false); + myXMaxEdit->setEnabled(false); + myYMinEdit->setEnabled(true); + myYMaxEdit->setEnabled(true); + if (mySecondAxisY) { + myY2MinEdit->setEnabled(true); + myY2MaxEdit->setEnabled(true); + } + if (badFocus) + myYMinEdit->setFocus(); + break; + } +} + diff --git a/src/Plot2d/Plot2d_FitDataDlg.h b/src/Plot2d/Plot2d_FitDataDlg.h new file mode 100755 index 000000000..ccecaaa32 --- /dev/null +++ b/src/Plot2d/Plot2d_FitDataDlg.h @@ -0,0 +1,75 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifndef PLOT2D_FITDATADLG_H +#define PLOT2D_FITDATADLG_H + +#include "Plot2d.h" +#include + +class QButtonGroup; +class QRadioButton; +class QLineEdit; +class QPushButton; + +class PLOT2D_EXPORT Plot2d_FitDataDlg : public QDialog +{ + Q_OBJECT + +public: +// constuctor + Plot2d_FitDataDlg( QWidget* parent, bool secondAxisY ); + +// sets range + void setRange(const double xMin, + const double xMax, + const double yMin, + const double yMax, + const double y2Min = 0, + const double y2Max = 0); +// gets range, returns mode (see getMode()) + int getRange(double& xMin, + double& xMax, + double& yMin, + double& yMax, + double& y2Min, + double& y2Max); +// gets mode : 0 - Fit all; 1 - Fit horizontal, 2 - Fit vertical + int getMode(); + +protected slots: +// called when range mode changed + void onModeChanged(int); + +private: + QButtonGroup* myRangeGrp; + QRadioButton* myModeAllRB; + QRadioButton* myModeHorRB; + QRadioButton* myModeVerRB; + QLineEdit* myXMinEdit; + QLineEdit* myYMinEdit; + QLineEdit* myY2MinEdit; + QLineEdit* myXMaxEdit; + QLineEdit* myYMaxEdit; + QLineEdit* myY2MaxEdit; + QPushButton* myOkBtn; + QPushButton* myCancelBtn; + bool mySecondAxisY; +}; + +#endif diff --git a/src/Plot2d/Plot2d_Prs.cxx b/src/Plot2d/Plot2d_Prs.cxx new file mode 100755 index 000000000..7c3bd0372 --- /dev/null +++ b/src/Plot2d/Plot2d_Prs.cxx @@ -0,0 +1,99 @@ +// SALOME OCCViewer : build OCC Viewer into Salome desktop +// +// Copyright (C) 2004 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_Prs.cxx +// Author : Sergey ANIKIN +// Module : SALOME +// $Header$ + +#include +#include "Plot2d_Prs.h" + +/*! + Default constructor +*/ +Plot2d_Prs::Plot2d_Prs( bool theDelete ) +: mySecondY( false) +{ + setAutoDel(theDelete); +} + +/*! + Standard constructor +*/ +Plot2d_Prs::Plot2d_Prs( const Plot2d_Curve* obj, bool theDelete ) +: mySecondY( false) +{ + setAutoDel(theDelete); + AddObject( obj ); +} + +/*! + Destructor +*/ +Plot2d_Prs::~Plot2d_Prs() +{ +} + +/*! + Get curves list +*/ +curveList Plot2d_Prs::getCurves() const +{ + return myCurves; +} + +/*! + Add curve +*/ +void Plot2d_Prs::AddObject( const Plot2d_Curve* obj ) +{ + myCurves.append((Plot2d_Curve*)obj); + + if (obj->getYAxis() == QwtPlot::yRight) + mySecondY = true; +} + +/*! + \return 0 if list of the curves is empty [ Reimplemented from SALOME_Prs ] +*/ +bool Plot2d_Prs::IsNull() const +{ + return myCurves.isEmpty(); +} + +/*! + \return 1 if in the list of curves exist at least one curve with axis Qwt::yRight [ Reimplemented from SALOME_Prs ] +*/ +bool Plot2d_Prs::isSecondY() const +{ + return mySecondY; +} + +/*! + \return 0 if list of the curves is empty [ Reimplemented from SALOME_Prs ] +*/ +void Plot2d_Prs::setAutoDel(bool theDel) +{ + myCurves.setAutoDelete(theDel); +} diff --git a/src/Plot2d/Plot2d_Prs.h b/src/Plot2d/Plot2d_Prs.h new file mode 100755 index 000000000..2f98aadeb --- /dev/null +++ b/src/Plot2d/Plot2d_Prs.h @@ -0,0 +1,46 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifndef PLOT2D_PRS_H +#define PLOT2D_PRS_H + +#include "Plot2d.h" +#include "Plot2d_Curve.h" + +class PLOT2D_EXPORT Plot2d_Prs +{ +public: + Plot2d_Prs( bool theDelete = false ); + Plot2d_Prs( const Plot2d_Curve* obj, bool theDelete = false ); + ~Plot2d_Prs(); + + curveList getCurves() const; + void AddObject( const Plot2d_Curve* obj ); + + bool IsNull() const; + + bool isSecondY() const; + + void setAutoDel(bool theDel); + +protected: + curveList myCurves; + bool mySecondY; +}; + +#endif diff --git a/src/Plot2d/Plot2d_SetupCurveDlg.cxx b/src/Plot2d/Plot2d_SetupCurveDlg.cxx new file mode 100644 index 000000000..4873db496 --- /dev/null +++ b/src/Plot2d/Plot2d_SetupCurveDlg.cxx @@ -0,0 +1,217 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +// SALOME Plot2d : implementation of desktop and GUI kernel +// +// File : Plot2d_SetupCurveDlg.cxx +// Author : Vadim SANDLER +// Module : SALOME +// $Header$ + +#include "Plot2d_SetupCurveDlg.h" +#include "SUIT_Tools.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WNT +using namespace std; +#endif + +#define MARGIN_SIZE 11 +#define SPACING_SIZE 6 +#define MIN_COMBO_WIDTH 100 +#define MIN_SPIN_WIDTH 50 +#define MAX_LINE_WIDTH 100 + +/*! + Constructor +*/ +Plot2d_SetupCurveDlg::Plot2d_SetupCurveDlg( QWidget* parent ) + : QDialog( parent, "Plot2d_SetupCurveDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) +{ + setCaption( tr("TLT_SETUP_CURVE") ); + setSizeGripEnabled( TRUE ); + QGridLayout* topLayout = new QGridLayout( this ); + topLayout->setSpacing( SPACING_SIZE ); + topLayout->setMargin( MARGIN_SIZE ); + + QGroupBox* TopGroup = new QGroupBox( this ); + TopGroup->setColumnLayout( 0, Qt::Vertical ); + TopGroup->layout()->setSpacing( 0 ); TopGroup->layout()->setMargin( 0 ); + QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() ); + TopGroupLayout->setAlignment( Qt::AlignTop ); + TopGroupLayout->setSpacing( SPACING_SIZE ); TopGroupLayout->setMargin( MARGIN_SIZE ); + + QLabel* aLineTypeLab = new QLabel( tr( "CURVE_LINE_TYPE_LAB" ), TopGroup ); + myLineCombo = new QComboBox( false, TopGroup ); + myLineCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myLineCombo->setMinimumWidth( MIN_COMBO_WIDTH ); + myLineCombo->insertItem( tr( "NONE_LINE_LBL" ) ); + myLineCombo->insertItem( tr( "SOLID_LINE_LBL" ) ); + myLineCombo->insertItem( tr( "DASH_LINE_LBL" ) ); + myLineCombo->insertItem( tr( "DOT_LINE_LBL" ) ); + myLineCombo->insertItem( tr( "DASHDOT_LINE_LBL" ) ); + myLineCombo->insertItem( tr( "DAHSDOTDOT_LINE_LBL" ) ); + myLineCombo->setCurrentItem( 1 ); // SOLID by default + + QLabel* aLineWidthLab = new QLabel( tr( "CURVE_LINE_WIDTH_LAB" ), TopGroup ); + myLineSpin = new QSpinBox( 0, MAX_LINE_WIDTH, 1, TopGroup ); + myLineSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myLineSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + myLineSpin->setValue( 0 ); // default width is 0 + + QLabel* aMarkerLab = new QLabel( tr( "CURVE_MARKER_TYPE_LAB" ), TopGroup ); + myMarkerCombo = new QComboBox( false, TopGroup ); + myMarkerCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myMarkerCombo->setMinimumWidth( MIN_COMBO_WIDTH ); + myMarkerCombo->insertItem( tr( "NONE_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "CIRCLE_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "RECTANGLE_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "DIAMOND_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "DTRIANGLE_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "UTRIANGLE_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "LTRIANGLE_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "RTRIANGLE_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "CROSS_MARKER_LBL" ) ); + myMarkerCombo->insertItem( tr( "XCROSS_MARKER_LBL" ) ); + myMarkerCombo->setCurrentItem( 1 ); // CIRCLE by default + + QLabel* aColorLab = new QLabel( tr( "CURVE_COLOR_LAB" ), TopGroup ); + myColorBtn = new QToolButton( TopGroup ); + myColorBtn->setMinimumSize(25, 25); + + TopGroupLayout->addWidget( aLineTypeLab, 0, 0 ); + TopGroupLayout->addMultiCellWidget( myLineCombo, 0, 0, 1, 2 ); + TopGroupLayout->addWidget( aLineWidthLab, 1, 0 ); + TopGroupLayout->addMultiCellWidget( myLineSpin, 1, 1, 1, 2 ); + TopGroupLayout->addWidget( aMarkerLab, 2, 0 ); + TopGroupLayout->addMultiCellWidget( myMarkerCombo, 2, 2, 1, 2 ); + TopGroupLayout->addWidget( aColorLab, 3, 0 ); + TopGroupLayout->addWidget( myColorBtn, 3, 1 ); + TopGroupLayout->setColStretch( 2, 5 ); + + QGroupBox* GroupButtons = new QGroupBox( this ); + GroupButtons->setColumnLayout( 0, Qt::Vertical ); + GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 ); + QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setSpacing( SPACING_SIZE ); GroupButtonsLayout->setMargin( MARGIN_SIZE ); + + myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons ); + myOkBtn->setAutoDefault( true ); myOkBtn->setDefault( true ); + myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons ); + myCancelBtn->setAutoDefault( true ); + + GroupButtonsLayout->addWidget( myOkBtn ); + GroupButtonsLayout->addStretch(); + GroupButtonsLayout->addWidget( myCancelBtn ); + + connect( myColorBtn, SIGNAL( clicked() ), this, SLOT( onColorChanged() ) ); + connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); + setColor( QColor( 0, 0, 0 ) ); + + topLayout->addWidget( TopGroup, 0, 0 ); + topLayout->addWidget( GroupButtons, 1, 0 ); + + SUIT_Tools::centerWidget( this, parent ); +} +/*! + Destructor +*/ +Plot2d_SetupCurveDlg::~Plot2d_SetupCurveDlg() +{ +} +/*! + Sets line style and width +*/ +void Plot2d_SetupCurveDlg::setLine( const int line, const int width ) +{ + myLineCombo->setCurrentItem( line ); + myLineSpin->setValue( width ); +} +/*! + Gets line style +*/ +int Plot2d_SetupCurveDlg::getLine() const +{ + return myLineCombo->currentItem(); +} +/*! + Gets line width +*/ +int Plot2d_SetupCurveDlg::getLineWidth() const +{ + return myLineSpin->value(); +} +/*! + Sets marker style +*/ +void Plot2d_SetupCurveDlg::setMarker( const int marker ) +{ + myMarkerCombo->setCurrentItem( marker ); +} +/*! + Gets marker style +*/ +int Plot2d_SetupCurveDlg::getMarker() const +{ + return myMarkerCombo->currentItem(); +} +/*! + Sets color +*/ +void Plot2d_SetupCurveDlg::setColor( const QColor& color ) +{ + QPalette pal = myColorBtn->palette(); + QColorGroup ca = pal.active(); + ca.setColor( QColorGroup::Button, color ); + QColorGroup ci = pal.inactive(); + ci.setColor( QColorGroup::Button, color ); + pal.setActive( ca ); + pal.setInactive( ci ); + myColorBtn->setPalette( pal ); +} +/*! + Gets color +*/ +QColor Plot2d_SetupCurveDlg::getColor() const +{ + return myColorBtn->palette().active().button(); +} +/*! + button slot, invokes color selection dialog box +*/ +void Plot2d_SetupCurveDlg::onColorChanged() +{ + QColor color = QColorDialog::getColor( getColor() ); + if ( color.isValid() ) { + setColor( color ); + } +} + + + + + diff --git a/src/Plot2d/Plot2d_SetupCurveDlg.h b/src/Plot2d/Plot2d_SetupCurveDlg.h new file mode 100644 index 000000000..84d530aa6 --- /dev/null +++ b/src/Plot2d/Plot2d_SetupCurveDlg.h @@ -0,0 +1,72 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +// SALOME Plot2d : implementation of desktop and GUI kernel +// +// File : Plot2d_SetupCurveDlg.h +// Author : Vadim SANDLER +// Module : SALOME + +#ifndef Plot2d_SetupCurveDlg_H +#define Plot2d_SetupCurveDlg_H + +#include "Plot2d.h" + +#include + +/*! + \class Plot2d_SetupCurveDlg + Dialog box for setup Plot2d curve +*/ + +class QPushButton; +class QComboBox; +class QSpinBox; +class QToolButton; + +class PLOT2D_EXPORT Plot2d_SetupCurveDlg : public QDialog +{ + Q_OBJECT + +public: + Plot2d_SetupCurveDlg( QWidget* parent = 0 ); + ~Plot2d_SetupCurveDlg(); + +public: + void setLine( const int line, const int width ); + int getLine() const; + int getLineWidth() const; + void setMarker( const int marker ); + int getMarker() const ; + void setColor( const QColor& color ); + QColor getColor() const; + +protected slots: + void onColorChanged(); + +private: + QPushButton* myOkBtn; + QPushButton* myCancelBtn; + QComboBox* myLineCombo; + QSpinBox* myLineSpin; + QComboBox* myMarkerCombo; + QToolButton* myColorBtn; +}; + +#endif // Plot2d_SetupCurveDlg_H + diff --git a/src/Plot2d/Plot2d_SetupViewDlg.cxx b/src/Plot2d/Plot2d_SetupViewDlg.cxx new file mode 100755 index 000000000..9f1b2f03a --- /dev/null +++ b/src/Plot2d/Plot2d_SetupViewDlg.cxx @@ -0,0 +1,683 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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_SetupViewDlg.cxx +// Author : Vadim SANDLER +// Module : SALOME +// $Header$ + +#include "Plot2d_SetupViewDlg.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MARGIN_SIZE 11 +#define SPACING_SIZE 6 +#define MIN_EDIT_WIDTH 200 +#define MIN_COMBO_WIDTH 100 +#define MIN_SPIN_WIDTH 70 + +/*! + Constructor +*/ +Plot2d_SetupViewDlg::Plot2d_SetupViewDlg( QWidget* parent, bool showDefCheck, bool secondAxisY ) + : QDialog( parent, "Plot2d_SetupViewDlg", true, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) +{ + mySecondAxisY = secondAxisY; + setCaption( tr("TLT_SETUP_PLOT2D_VIEW") ); + setSizeGripEnabled( TRUE ); + QGridLayout* topLayout = new QGridLayout( this ); + topLayout->setSpacing( SPACING_SIZE ); + topLayout->setMargin( MARGIN_SIZE ); + + // main title + myTitleCheck = new QCheckBox( tr( "PLOT2D_ENABLE_MAIN_TITLE" ), this ); + myTitleEdit = new QLineEdit( this ); + myTitleEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myTitleEdit->setMinimumWidth( MIN_EDIT_WIDTH ); + // curve type : points, lines, spline + QLabel* aCurveLab = new QLabel( tr( "PLOT2D_CURVE_TYPE_LBL" ), this ); + myCurveCombo = new QComboBox( false, this ); + myCurveCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myCurveCombo->setMinimumWidth( MIN_COMBO_WIDTH ); + myCurveCombo->insertItem( tr( "PLOT2D_CURVE_TYPE_POINTS" ) ); + myCurveCombo->insertItem( tr( "PLOT2D_CURVE_TYPE_LINES" ) ); + myCurveCombo->insertItem( tr( "PLOT2D_CURVE_TYPE_SPLINE" ) ); + // legend + myLegendCheck = new QCheckBox( tr( "PLOT2D_ENABLE_LEGEND" ), this ); + myLegendCombo = new QComboBox( false, this ); + myLegendCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myLegendCombo->setMinimumWidth( MIN_COMBO_WIDTH ); + myLegendCombo->insertItem( tr( "PLOT2D_LEGEND_POSITION_LEFT" ) ); + myLegendCombo->insertItem( tr( "PLOT2D_LEGEND_POSITION_RIGHT" ) ); + myLegendCombo->insertItem( tr( "PLOT2D_LEGEND_POSITION_TOP" ) ); + myLegendCombo->insertItem( tr( "PLOT2D_LEGEND_POSITION_BOTTOM" ) ); + // marker size + QLabel* aMarkerLab = new QLabel( tr( "PLOT2D_MARKER_SIZE_LBL" ), this ); + myMarkerSpin = new QSpinBox( 0, 100, 1, this ); + myMarkerSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myMarkerSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + + // background color + QLabel* aBGLab = new QLabel( tr( "PLOT2D_BACKGROUND_COLOR_LBL" ), this ); + myBackgroundBtn = new QToolButton( this ); + myBackgroundBtn->setMinimumWidth(20); + + // scale mode + QGroupBox* aScaleGrp = new QGroupBox( tr( "PLOT2D_SCALE_TLT" ), this ); + aScaleGrp->setColumnLayout(0, Qt::Vertical ); + aScaleGrp->layout()->setSpacing( 0 ); aScaleGrp->layout()->setMargin( 0 ); + QGridLayout* aScaleLayout = new QGridLayout( aScaleGrp->layout() ); + aScaleLayout->setMargin( MARGIN_SIZE ); aScaleLayout->setSpacing( SPACING_SIZE ); + + QLabel* xScaleLab = new QLabel( tr( "PLOT2D_SCALE_MODE_HOR" ), aScaleGrp ); + myXModeCombo = new QComboBox( false, aScaleGrp ); + myXModeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myXModeCombo->setMinimumWidth( MIN_COMBO_WIDTH ); + myXModeCombo->insertItem( tr( "PLOT2D_SCALE_MODE_LINEAR" ) ); + myXModeCombo->insertItem( tr( "PLOT2D_SCALE_MODE_LOGARITHMIC" ) ); + QLabel* yScaleLab = new QLabel( tr( "PLOT2D_SCALE_MODE_VER" ), aScaleGrp ); + myYModeCombo = new QComboBox( false, aScaleGrp ); + myYModeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myYModeCombo->setMinimumWidth( MIN_COMBO_WIDTH ); + myYModeCombo->insertItem( tr( "PLOT2D_SCALE_MODE_LINEAR" ) ); + myYModeCombo->insertItem( tr( "PLOT2D_SCALE_MODE_LOGARITHMIC" ) ); + + aScaleLayout->addWidget( xScaleLab, 0, 0 ); + aScaleLayout->addWidget( myXModeCombo, 0, 1 ); + aScaleLayout->addWidget( yScaleLab, 0, 2 ); + aScaleLayout->addWidget( myYModeCombo, 0, 3 ); + + // tab widget for choose properties of axis + QTabWidget* aTabWidget = new QTabWidget( this, "tabWidget" ); + + // widget for parameters on Ox + QWidget* aXWidget = new QWidget(aTabWidget); + QGridLayout* aXLayout = new QGridLayout( aXWidget ); + aXLayout->setSpacing( SPACING_SIZE ); + aXLayout->setMargin( MARGIN_SIZE ); + // axis title + myTitleXCheck = new QCheckBox( tr( "PLOT2D_ENABLE_HOR_TITLE" ), aXWidget ); + myTitleXEdit = new QLineEdit( aXWidget ); + myTitleXEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myTitleXEdit->setMinimumWidth( MIN_EDIT_WIDTH ); + aXLayout->addWidget( myTitleXCheck, 1, 0 ); + aXLayout->addMultiCellWidget( myTitleXEdit, 1, 1, 1, 3 ); + // grid + QGroupBox* aGridGrpX = new QGroupBox( tr( "PLOT2D_GRID_TLT" ), aXWidget ); + aGridGrpX->setColumnLayout(0, Qt::Vertical ); + aGridGrpX->layout()->setSpacing( 0 ); aGridGrpX->layout()->setMargin( 0 ); + QGridLayout* aGridLayoutX = new QGridLayout( aGridGrpX->layout() ); + aGridLayoutX->setMargin( MARGIN_SIZE ); aGridLayoutX->setSpacing( SPACING_SIZE ); + myXGridCheck = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_HOR_MAJOR" ), aGridGrpX ); + QLabel* aXMajLbl = new QLabel( tr( "PLOT2D_MAX_INTERVALS" ), aGridGrpX); + myXGridSpin = new QSpinBox( 1, 100, 1, aGridGrpX ); + myXGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myXGridSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + myXMinGridCheck = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_HOR_MINOR" ), aGridGrpX ); + QLabel* aXMinLbl = new QLabel( tr( "PLOT2D_MAX_INTERVALS" ), aGridGrpX); + myXMinGridSpin = new QSpinBox( 1, 100, 1, aGridGrpX ); + myXMinGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myXMinGridSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + + aGridLayoutX->addWidget( myXGridCheck, 0, 0 ); + aGridLayoutX->addWidget( aXMajLbl, 0, 1 ); + aGridLayoutX->addWidget( myXGridSpin, 0, 2 ); + aGridLayoutX->addWidget( myXMinGridCheck, 1, 0 ); + aGridLayoutX->addWidget( aXMinLbl, 1, 1 ); + aGridLayoutX->addWidget( myXMinGridSpin, 1, 2 ); + aXLayout->addMultiCellWidget( aGridGrpX, 3, 3, 0, 3 ); + + aTabWidget->addTab( aXWidget, tr( "INF_AXES_X" ) ); + + // widget for parameters on Oy + QWidget* aYWidget = new QWidget(aTabWidget); + QGridLayout* aYLayout = new QGridLayout( aYWidget ); + aYLayout->setSpacing( SPACING_SIZE ); + aYLayout->setMargin( MARGIN_SIZE ); + // axis title + myTitleYCheck = new QCheckBox( tr( "PLOT2D_ENABLE_VER_TITLE" ), aYWidget ); + myTitleYEdit = new QLineEdit( aYWidget ); + myTitleYEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myTitleYEdit->setMinimumWidth( MIN_EDIT_WIDTH ); + aYLayout->addWidget( myTitleYCheck, 1, 0 ); + aYLayout->addMultiCellWidget( myTitleYEdit, 1, 1, 1, 3 ); + // grid + QGroupBox* aGridGrpY = new QGroupBox( tr( "PLOT2D_GRID_TLT" ), aYWidget ); + aGridGrpY->setColumnLayout(0, Qt::Vertical ); + aGridGrpY->layout()->setSpacing( 0 ); aGridGrpY->layout()->setMargin( 0 ); + QGridLayout* aGridLayoutY = new QGridLayout( aGridGrpY->layout() ); + aGridLayoutY->setMargin( MARGIN_SIZE ); aGridLayoutY->setSpacing( SPACING_SIZE ); + myYGridCheck = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_VER_MAJOR" ), aGridGrpY ); + QLabel* aYMajLbl = new QLabel( tr( "PLOT2D_MAX_INTERVALS" ), aGridGrpY); + myYGridSpin = new QSpinBox( 1, 100, 1, aGridGrpY ); + myYGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myYGridSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + myYMinGridCheck = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_VER_MINOR" ), aGridGrpY ); + QLabel* aYMinLbl = new QLabel( tr( "PLOT2D_MAX_INTERVALS" ), aGridGrpY); + myYMinGridSpin = new QSpinBox( 1, 100, 1, aGridGrpY ); + myYMinGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myYMinGridSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + + aGridLayoutY->addWidget( myYGridCheck, 0, 0 ); + aGridLayoutY->addWidget( aYMajLbl, 0, 1 ); + aGridLayoutY->addWidget( myYGridSpin, 0, 2 ); + aGridLayoutY->addWidget( myYMinGridCheck, 1, 0 ); + aGridLayoutY->addWidget( aYMinLbl, 1, 1 ); + aGridLayoutY->addWidget( myYMinGridSpin, 1, 2 ); + aYLayout->addMultiCellWidget( aGridGrpY, 3, 3, 0, 3 ); + + aTabWidget->addTab( aYWidget, tr( "INF_AXES_Y_LEFT" ) ); + + // if exist second axis Oy, addition new tab widget for right axis + if (mySecondAxisY) { + // widget for parameters on Oy + QWidget* aYWidget2 = new QWidget(aTabWidget); + QGridLayout* aYLayout2 = new QGridLayout( aYWidget2 ); + aYLayout2->setSpacing( SPACING_SIZE ); + aYLayout2->setMargin( MARGIN_SIZE ); + // axis title + myTitleY2Check = new QCheckBox( tr( "PLOT2D_ENABLE_VER_TITLE" ), aYWidget2 ); + myTitleY2Edit = new QLineEdit( aYWidget2 ); + myTitleY2Edit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myTitleY2Edit->setMinimumWidth( MIN_EDIT_WIDTH ); + aYLayout2->addWidget( myTitleY2Check, 1, 0 ); + aYLayout2->addMultiCellWidget( myTitleY2Edit, 1, 1, 1, 3 ); + // grid + QGroupBox* aGridGrpY2 = new QGroupBox( tr( "PLOT2D_GRID_TLT" ), aYWidget2 ); + aGridGrpY2->setColumnLayout(0, Qt::Vertical ); + aGridGrpY2->layout()->setSpacing( 0 ); aGridGrpY2->layout()->setMargin( 0 ); + QGridLayout* aGridLayoutY2 = new QGridLayout( aGridGrpY2->layout() ); + aGridLayoutY2->setMargin( MARGIN_SIZE ); aGridLayoutY2->setSpacing( SPACING_SIZE ); + myY2GridCheck = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_VER_MAJOR" ), aGridGrpY2 ); + QLabel* aY2MajLbl = new QLabel( tr( "PLOT2D_MAX_INTERVALS" ), aGridGrpY2); + myY2GridSpin = new QSpinBox( 1, 100, 1, aGridGrpY2 ); + myY2GridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myY2GridSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + myY2MinGridCheck = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_VER_MINOR" ), aGridGrpY2 ); + QLabel* aY2MinLbl = new QLabel( tr( "PLOT2D_MAX_INTERVALS" ), aGridGrpY2); + myY2MinGridSpin = new QSpinBox( 1, 100, 1, aGridGrpY2 ); + myY2MinGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myY2MinGridSpin->setMinimumWidth( MIN_SPIN_WIDTH ); + + aGridLayoutY2->addWidget( myY2GridCheck, 0, 0 ); + aGridLayoutY2->addWidget( aY2MajLbl, 0, 1 ); + aGridLayoutY2->addWidget( myY2GridSpin, 0, 2 ); + aGridLayoutY2->addWidget( myY2MinGridCheck, 1, 0 ); + aGridLayoutY2->addWidget( aY2MinLbl, 1, 1 ); + aGridLayoutY2->addWidget( myY2MinGridSpin, 1, 2 ); + aYLayout2->addMultiCellWidget( aGridGrpY2, 3, 3, 0, 3 ); + + aTabWidget->addTab( aYWidget2, tr( "INF_AXES_Y_RIGHT" ) ); + } + else { + myTitleY2Check = 0; + myTitleY2Edit = 0; + myY2GridCheck = 0; + myY2GridSpin = 0; + myY2MinGridCheck = 0; + myY2MinGridSpin = 0; + myY2ModeCombo = 0; + } + aTabWidget->setCurrentPage( 0 ); + /* "Set as default" check box */ + myDefCheck = new QCheckBox( tr( "PLOT2D_SET_AS_DEFAULT_CHECK" ), this ); + /* OK/Cancel buttons */ + myOkBtn = new QPushButton( tr( "BUT_OK" ), this ); + myOkBtn->setAutoDefault( TRUE ); + myOkBtn->setDefault( TRUE ); + myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this ); + myCancelBtn->setAutoDefault( TRUE ); + QHBoxLayout* btnLayout = new QHBoxLayout; + btnLayout->addWidget( myOkBtn ); + btnLayout->addStretch(); + btnLayout->addWidget( myCancelBtn ); + + // layout widgets + topLayout->addWidget( myTitleCheck, 0, 0 ); + topLayout->addMultiCellWidget( myTitleEdit, 0, 0, 1, 3 ); + topLayout->addWidget( aCurveLab, 1, 0 ); + topLayout->addWidget( myCurveCombo, 1, 1 ); + topLayout->addWidget( myLegendCheck, 1, 2 ); + topLayout->addWidget( myLegendCombo, 1, 3 ); + topLayout->addWidget( aMarkerLab, 2, 0 ); + topLayout->addWidget( myMarkerSpin, 2, 1 ); + QHBoxLayout* bgLayout = new QHBoxLayout; + bgLayout->addWidget( myBackgroundBtn ); bgLayout->addStretch(); + topLayout->addWidget( aBGLab, 2, 2 ); + topLayout->addLayout( bgLayout, 2, 3 ); + topLayout->addMultiCellWidget( aScaleGrp, 3, 3, 0, 3 ); + topLayout->addMultiCellWidget( aTabWidget, 4, 4, 0, 3 ); + topLayout->addMultiCellWidget( myDefCheck, 5, 5, 0, 3 ); + topLayout->setRowStretch( 5, 5 ); + + topLayout->addMultiCellLayout( btnLayout, 6, 6, 0, 3 ); + + if ( !showDefCheck ) + myDefCheck->hide(); + + connect( myTitleCheck, SIGNAL( clicked() ), this, SLOT( onMainTitleChecked() ) ); + connect( myTitleXCheck, SIGNAL( clicked() ), this, SLOT( onXTitleChecked() ) ); + connect( myTitleYCheck, SIGNAL( clicked() ), this, SLOT( onYTitleChecked() ) ); + connect( myBackgroundBtn, SIGNAL( clicked() ), this, SLOT( onBackgroundClicked() ) ); + connect( myLegendCheck, SIGNAL( clicked() ), this, SLOT( onLegendChecked() ) ); + connect( myXGridCheck, SIGNAL( clicked() ), this, SLOT( onXGridMajorChecked() ) ); + connect( myYGridCheck, SIGNAL( clicked() ), this, SLOT( onYGridMajorChecked() ) ); + connect( myXMinGridCheck, SIGNAL( clicked() ), this, SLOT( onXGridMinorChecked() ) ); + connect( myYMinGridCheck, SIGNAL( clicked() ), this, SLOT( onYGridMinorChecked() ) ); + + connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); + + if (mySecondAxisY) { + connect( myTitleY2Check, SIGNAL( clicked() ), this, SLOT( onY2TitleChecked() ) ); + connect( myY2GridCheck, SIGNAL( clicked() ), this, SLOT( onY2GridMajorChecked() ) ); + connect( myY2MinGridCheck, SIGNAL( clicked() ), this, SLOT( onY2GridMinorChecked() ) ); + } + + // init fields + setBackgroundColor( Qt::gray ); + onMainTitleChecked(); + onXTitleChecked(); + onYTitleChecked(); + onLegendChecked(); + onXGridMajorChecked(); + onYGridMajorChecked(); + onXGridMinorChecked(); + if (mySecondAxisY) { + onY2TitleChecked(); + onY2GridMajorChecked(); + onY2GridMinorChecked(); + } +} + +/*! + Destructor +*/ +Plot2d_SetupViewDlg::~Plot2d_SetupViewDlg() +{ +} +/*! + Sets main title attributes +*/ +void Plot2d_SetupViewDlg::setMainTitle( bool enable, const QString& title ) +{ + myTitleCheck->setChecked( enable ); + if ( !title.isNull() ) + myTitleEdit->setText( title ); + onMainTitleChecked(); +} +/*! + Returns TRUE if main title is enabled +*/ +bool Plot2d_SetupViewDlg::isMainTitleEnabled() +{ + return myTitleCheck->isChecked(); +} +/*! + Gets main title +*/ +QString Plot2d_SetupViewDlg::getMainTitle() +{ + return myTitleEdit->text(); +} +/*! + Sets horizontal axis title attributes +*/ +void Plot2d_SetupViewDlg::setXTitle( bool enable, const QString& title ) +{ + myTitleXCheck->setChecked( enable ); + if ( !title.isNull() ) + myTitleXEdit->setText( title ); + onXTitleChecked(); +} +/*! + Returns TRUE if horizontal axis title is enabled +*/ +bool Plot2d_SetupViewDlg::isXTitleEnabled() +{ + return myTitleXCheck->isChecked(); +} +/*! + Gets horizontal axis title +*/ +QString Plot2d_SetupViewDlg::getXTitle() +{ + return myTitleXEdit->text(); +} +/*! + Sets vertical left axis title attributes +*/ +void Plot2d_SetupViewDlg::setYTitle( bool enable, const QString& title ) +{ + myTitleYCheck->setChecked( enable ); + if ( !title.isNull() ) + myTitleYEdit->setText( title ); + onYTitleChecked(); +} +/*! + Sets vertical right axis title attributes +*/ +void Plot2d_SetupViewDlg::setY2Title( bool enable, const QString& title ) +{ + myTitleY2Check->setChecked( enable ); + if ( !title.isNull() ) + myTitleY2Edit->setText( title ); + onY2TitleChecked(); +} +/*! + Returns TRUE if vertical left axis title is enabled +*/ +bool Plot2d_SetupViewDlg::isYTitleEnabled() +{ + return myTitleYCheck->isChecked(); +} +/*! + Returns TRUE if vertical right axis title is enabled +*/ +bool Plot2d_SetupViewDlg::isY2TitleEnabled() +{ + return myTitleY2Check->isChecked(); +} +/*! + Gets vertical left axis title +*/ +QString Plot2d_SetupViewDlg::getYTitle() +{ + return myTitleYEdit->text(); +} +/*! + Gets vertical right axis title +*/ +QString Plot2d_SetupViewDlg::getY2Title() +{ + return myTitleY2Edit->text(); +} +/*! + Sets curve type : 0 - points, 1 - lines, 2 - splines +*/ +void Plot2d_SetupViewDlg::setCurveType( const int type ) +{ + myCurveCombo->setCurrentItem( type ); +} +/*! + Gets curve type : 0 - points, 1 - lines, 2 - splines +*/ +int Plot2d_SetupViewDlg::getCurveType() +{ + return myCurveCombo->currentItem(); +} +/*! + Sets legend attributes : pos = 0 - left, 1 - right, 2 - top, 3 - bottom +*/ +void Plot2d_SetupViewDlg::setLegend( bool enable, int pos ) +{ + myLegendCheck->setChecked( enable ); + myLegendCombo->setCurrentItem( pos ); + onLegendChecked(); +} +/*! + Returns TRUE if legend is enabled +*/ +bool Plot2d_SetupViewDlg::isLegendEnabled() +{ + return myLegendCheck->isChecked(); +} +/*! + Returns legend position +*/ +int Plot2d_SetupViewDlg::getLegendPos() +{ + return myLegendCombo->currentItem(); +} +/*! + Sets marker size +*/ +void Plot2d_SetupViewDlg::setMarkerSize( const int size ) +{ + myMarkerSpin->setValue( size ); +} +/*! + Gets marker size +*/ +int Plot2d_SetupViewDlg::getMarkerSize() +{ + return myMarkerSpin->value(); +} +/*! + Sets background color +*/ +void Plot2d_SetupViewDlg::setBackgroundColor( const QColor& color ) +{ + QPalette pal = myBackgroundBtn->palette(); + QColorGroup ca = pal.active(); + ca.setColor( QColorGroup::Button, color ); + QColorGroup ci = pal.inactive(); + ci.setColor( QColorGroup::Button, color ); + pal.setActive( ca ); + pal.setInactive( ci ); + myBackgroundBtn->setPalette( pal ); +} +/*! + Gets background color +*/ +QColor Plot2d_SetupViewDlg::getBackgroundColor() +{ + return myBackgroundBtn->palette().active().button(); +} +/*! + Sets major grid parameters +*/ +void Plot2d_SetupViewDlg::setMajorGrid( bool enableX, const int divX, + bool enableY, const int divY, + bool enableY2, const int divY2 ) +{ + myXGridCheck->setChecked( enableX ); + myXGridSpin->setValue( divX ); + myYGridCheck->setChecked( enableY ); + myYGridSpin->setValue( divY ); + onXGridMajorChecked(); + onYGridMajorChecked(); + if (mySecondAxisY) { + myY2GridCheck->setChecked( enableY2 ); + myY2GridSpin->setValue( divY2 ); + onY2GridMajorChecked(); + } +} +/*! + Gets major grid parameters +*/ +void Plot2d_SetupViewDlg::getMajorGrid( bool& enableX, int& divX, + bool& enableY, int& divY, + bool& enableY2, int& divY2) +{ + enableX = myXGridCheck->isChecked(); + divX = myXGridSpin->value(); + enableY = myYGridCheck->isChecked(); + divY = myYGridSpin->value(); + if (mySecondAxisY) { + enableY2 = myY2GridCheck->isChecked(); + divY2 = myY2GridSpin->value(); + } + else { + enableY2 = false; + divY2 = 1; + } +} +/*! + Sets minor grid parameters +*/ +void Plot2d_SetupViewDlg::setMinorGrid( bool enableX, const int divX, + bool enableY, const int divY, + bool enableY2, const int divY2) +{ + myXMinGridCheck->setChecked( enableX ); + myXMinGridSpin->setValue( divX ); + myYMinGridCheck->setChecked( enableY ); + myYMinGridSpin->setValue( divY ); + onXGridMinorChecked(); + onYGridMinorChecked(); + if (mySecondAxisY) { + myY2MinGridCheck->setChecked( enableY2 ); + myY2MinGridSpin->setValue( divY2 ); + onY2GridMinorChecked(); + } +} +/*! + Gets minor grid parameters +*/ +void Plot2d_SetupViewDlg::getMinorGrid( bool& enableX, int& divX, + bool& enableY, int& divY, + bool& enableY2, int& divY2) +{ + enableX = myXMinGridCheck->isChecked(); + divX = myXMinGridSpin->value(); + enableY = myYMinGridCheck->isChecked(); + divY = myYMinGridSpin->value(); + if (mySecondAxisY) { + enableY2 = myY2MinGridCheck->isChecked(); + divY2 = myY2MinGridSpin->value(); + } + else { + enableY2 = false; + divY2 = 1; + } +} +/*! + Sets scale mode for hor. and ver. axes : 0 - linear, 1 - logarithmic +*/ +void Plot2d_SetupViewDlg::setScaleMode( const int xMode, const int yMode ) +{ + myXModeCombo->setCurrentItem( xMode ); + myYModeCombo->setCurrentItem( yMode ); +} +/*! + Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic +*/ +int Plot2d_SetupViewDlg::getXScaleMode() +{ + return myXModeCombo->currentItem(); +} +/*! + Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic +*/ +int Plot2d_SetupViewDlg::getYScaleMode() +{ + return myYModeCombo->currentItem(); +} +/*! + Slot, called when user clicks "Show main title" check box +*/ +void Plot2d_SetupViewDlg::onMainTitleChecked() +{ + myTitleEdit->setEnabled( myTitleCheck->isChecked() ); +} +/*! + Slot, called when user clicks "Show horizontal axis title" check box +*/ +void Plot2d_SetupViewDlg::onXTitleChecked() +{ + myTitleXEdit->setEnabled( myTitleXCheck->isChecked() ); +} +/*! + Slot, called when user clicks "Show vertical left axis title" check box +*/ +void Plot2d_SetupViewDlg::onYTitleChecked() +{ + myTitleYEdit->setEnabled( myTitleYCheck->isChecked() ); +} +/*! + Slot, called when user clicks "Show vertical right axis title" check box +*/ +void Plot2d_SetupViewDlg::onY2TitleChecked() +{ + myTitleY2Edit->setEnabled( myTitleY2Check->isChecked() ); +} +/*! + Slot, called when user clicks "Change bacground color" button +*/ +void Plot2d_SetupViewDlg::onBackgroundClicked() +{ + QColor color = QColorDialog::getColor( getBackgroundColor() ); + if ( color.isValid() ) { + setBackgroundColor( color ); + } +} +/*! + Slot, called when user clicks "Show Legend" check box +*/ +void Plot2d_SetupViewDlg::onLegendChecked() +{ + myLegendCombo->setEnabled( myLegendCheck->isChecked() ); +} +/*! + Slot, called when user clicks "Enable hor. major grid" check box +*/ +void Plot2d_SetupViewDlg::onXGridMajorChecked() +{ + myXMinGridCheck->setEnabled( myXGridCheck->isChecked() ); +} +/*! + Slot, called when user clicks "Enable ver. major grid" check box +*/ +void Plot2d_SetupViewDlg::onYGridMajorChecked() +{ + myYMinGridCheck->setEnabled( myYGridCheck->isChecked() ); +} +/*! + Slot, called when user clicks "Enable ver. major grid" check box +*/ +void Plot2d_SetupViewDlg::onY2GridMajorChecked() +{ + myY2MinGridCheck->setEnabled( myY2GridCheck->isChecked() ); +} +/*! + Slot, called when user clicks "Enable hor. minor grid" check box +*/ +void Plot2d_SetupViewDlg::onXGridMinorChecked() +{ +} +/*! + Slot, called when user clicks "Enable ver. minor grid" check box +*/ +void Plot2d_SetupViewDlg::onYGridMinorChecked() +{ +} +/*! + Slot, called when user clicks "Enable ver. minor grid" check box +*/ +void Plot2d_SetupViewDlg::onY2GridMinorChecked() +{ +} +/*! + Retursns true if "Set as default" check box is on +*/ +bool Plot2d_SetupViewDlg::isSetAsDefault() +{ + return myDefCheck->isChecked(); +} diff --git a/src/Plot2d/Plot2d_SetupViewDlg.h b/src/Plot2d/Plot2d_SetupViewDlg.h new file mode 100755 index 000000000..37db3d641 --- /dev/null +++ b/src/Plot2d/Plot2d_SetupViewDlg.h @@ -0,0 +1,124 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifndef PLOT2D_SETUPVIEWDLG_H +#define PLOT2D_SETUPVIEWDLG_H + +#include "Plot2d.h" +#include + +class QSpinBox; +class QCheckBox; +class QLineEdit; +class QComboBox; +class QToolButton; +class QPushButton; + +class PLOT2D_EXPORT Plot2d_SetupViewDlg : public QDialog +{ + Q_OBJECT + +public: + Plot2d_SetupViewDlg( QWidget* parent = 0, bool showDefCheck = false, bool secondAxisY = false ); + ~Plot2d_SetupViewDlg(); + + void setMainTitle( bool enable, const QString& title = QString::null ); + bool isMainTitleEnabled(); + QString getMainTitle(); + void setXTitle( bool enable, const QString& title = QString::null ); + bool isXTitleEnabled(); + QString getXTitle(); + void setYTitle( bool enable, const QString& title = QString::null ); + void setY2Title( bool enable, const QString& title = QString::null ); + bool isYTitleEnabled(); + bool isY2TitleEnabled(); + QString getYTitle(); + QString getY2Title(); + void setCurveType( const int type ); + int getCurveType(); + void setLegend( bool enable, int pos ); + bool isLegendEnabled(); + int getLegendPos(); + void setMarkerSize( const int size ); + int getMarkerSize(); + void setBackgroundColor( const QColor& color ); + QColor getBackgroundColor(); + void setMajorGrid( bool enableX, const int xdiv, bool enableY, const int divY, + bool enableY2, const int divY2 ); + void getMajorGrid( bool& enableX, int& xdiv, bool& enableY, int& divY, + bool& enableY2, int& divY2); + void setMinorGrid( bool enableX, const int xdiv, bool enableY, const int divY, + bool enableY2, const int divY2); + void getMinorGrid( bool& enableX, int& xdiv, bool& enableY, int& divY, + bool& enableY2, int& divY2); + void setScaleMode( const int xMode, const int yMode ); + int getXScaleMode(); + int getYScaleMode(); + bool isSetAsDefault(); + +protected slots: + void onMainTitleChecked(); + void onXTitleChecked(); + void onYTitleChecked(); + void onY2TitleChecked(); + void onBackgroundClicked(); + void onLegendChecked(); + void onXGridMajorChecked(); + void onYGridMajorChecked(); + void onY2GridMajorChecked(); + void onXGridMinorChecked(); + void onYGridMinorChecked(); + void onY2GridMinorChecked(); + +private: + QCheckBox* myTitleCheck; + QLineEdit* myTitleEdit; + QCheckBox* myTitleXCheck; + QLineEdit* myTitleXEdit; + QCheckBox* myTitleYCheck; + QCheckBox* myTitleY2Check; + QLineEdit* myTitleYEdit; + QLineEdit* myTitleY2Edit; + QToolButton* myBackgroundBtn; + QCheckBox* myXGridCheck; + QSpinBox* myXGridSpin; + QCheckBox* myYGridCheck; + QCheckBox* myY2GridCheck; + QSpinBox* myYGridSpin; + QSpinBox* myY2GridSpin; + QCheckBox* myXMinGridCheck; + QSpinBox* myXMinGridSpin; + QCheckBox* myYMinGridCheck; + QCheckBox* myY2MinGridCheck; + QSpinBox* myYMinGridSpin; + QSpinBox* myY2MinGridSpin; + QComboBox* myCurveCombo; + QCheckBox* myLegendCheck; + QComboBox* myLegendCombo; + QSpinBox* myMarkerSpin; + QComboBox* myXModeCombo; + QComboBox* myYModeCombo; + QComboBox* myY2ModeCombo; + QCheckBox* myDefCheck; + + QPushButton* myOkBtn; + QPushButton* myCancelBtn; + bool mySecondAxisY; +}; + +#endif diff --git a/src/Plot2d/Plot2d_ToolTip.cxx b/src/Plot2d/Plot2d_ToolTip.cxx new file mode 100644 index 000000000..3cdb1ba8a --- /dev/null +++ b/src/Plot2d/Plot2d_ToolTip.cxx @@ -0,0 +1,93 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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_ToolTip.cxx +// Author: Alexandre SOLOVYOV + +#include +#include +#include + +#include + +#include +#include + +const int maxDist = 3, tip_margin = 10; + + +Plot2d_ToolTip::Plot2d_ToolTip( Plot2d_ViewFrame* frame, Plot2d_Plot2d* plot ) +: QtxToolTip( plot->canvas() ), + myFrame( frame ), + myPlot( plot ) +{ + connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ), + this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) ); +} + +Plot2d_ToolTip::~Plot2d_ToolTip() +{ +} + +void Plot2d_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect ) +{ + int curInd, pInd, dist; + double x, y; + curInd = myPlot->closestCurve( p.x(), p.y(), dist, x, y, pInd ); + + if( dist>maxDist ) + return; + + Plot2d_Curve* c = myFrame->getCurves().find( curInd ); + if( !c ) + return; + + str = c->text( pInd ); + if( !str ) + return; + + QFontMetrics m( f ); + QStringList lst = QStringList::split( "\n", str ); + QStringList::const_iterator anIt = lst.begin(), aLast = lst.end(); + int w = 0, h = 0; + for( ; anIt!=aLast; anIt++ ) + { + if( h>0 ) + h+= m.lineSpacing(); + + QRect r = m.boundingRect( *anIt ); + if( r.width()>w ) + w = r.width(); + h+=r.height(); + } + + txtRect = QRect( p.x(), p.y(), w, h ); + rect = txtRect; +} + +bool Plot2d_ToolTip::eventFilter( QObject* o, QEvent* e ) +{ + bool res = QtxToolTip::eventFilter( o, e ); + if( e && e->type() == QEvent::MouseMove ) + { + QMouseEvent* me = ( QMouseEvent* )e; + if( me->state()==0 ) + return true; + } + return res; +} diff --git a/src/Plot2d/Plot2d_ToolTip.h b/src/Plot2d/Plot2d_ToolTip.h new file mode 100644 index 000000000..a26c46a83 --- /dev/null +++ b/src/Plot2d/Plot2d_ToolTip.h @@ -0,0 +1,50 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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_ToolTip.h +// Author: Alexandre SOLOVYOV + +#ifndef PLOT2D_TOOLTIP_H +#define PLOT2D_TOOLTIP_H + +#include +#include + +class Plot2d_ViewFrame; +class Plot2d_Plot2d; + +class PLOT2D_EXPORT Plot2d_ToolTip : public QtxToolTip +{ + Q_OBJECT + +public: + Plot2d_ToolTip( Plot2d_ViewFrame*, Plot2d_Plot2d* ); + virtual ~Plot2d_ToolTip(); + +public slots: + void onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ); + +protected: + virtual bool eventFilter( QObject*, QEvent* ); + +private: + Plot2d_ViewFrame* myFrame; + Plot2d_Plot2d* myPlot; +}; + +#endif diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx new file mode 100755 index 000000000..00ba07afa --- /dev/null +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -0,0 +1,2050 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#include "Plot2d_ViewFrame.h" + +#include "Plot2d_Prs.h" +#include "Plot2d_Curve.h" +#include "Plot2d_FitDataDlg.h" +#include "Plot2d_ViewWindow.h" +#include "Plot2d_SetupViewDlg.h" +#include "Plot2d_ToolTip.h" + +#include "SUIT_Tools.h" +#include "SUIT_Session.h" +#include "SUIT_MessageBox.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_Application.h" + +#include "qapplication.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#define DEFAULT_LINE_WIDTH 0 // (default) line width +#define DEFAULT_MARKER_SIZE 9 // default marker size +#define MIN_RECT_SIZE 11 // min sensibility area size + +const char* imageZoomCursor[] = { +"32 32 3 1", +". c None", +"a c #000000", +"# c #ffffff", +"................................", +"................................", +".#######........................", +"..aaaaaaa.......................", +"................................", +".............#####..............", +"...........##.aaaa##............", +"..........#.aa.....a#...........", +".........#.a.........#..........", +".........#a..........#a.........", +"........#.a...........#.........", +"........#a............#a........", +"........#a............#a........", +"........#a............#a........", +"........#a............#a........", +".........#...........#.a........", +".........#a..........#a.........", +".........##.........#.a.........", +"........#####.....##.a..........", +".......###aaa#####.aa...........", +"......###aa...aaaaa.......#.....", +".....###aa................#a....", +"....###aa.................#a....", +"...###aa...............#######..", +"....#aa.................aa#aaaa.", +".....a....................#a....", +"..........................#a....", +"...........................a....", +"................................", +"................................", +"................................", +"................................"}; + +const char* imageCrossCursor[] = { + "32 32 3 1", + ". c None", + "a c #000000", + "# c #ffffff", + "................................", + "................................", + "................................", + "................................", + "................................", + "................................", + "................................", + "...............#................", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + ".......#################........", + "........aaaaaaa#aaaaaaaaa.......", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "................a...............", + "................................", + "................................", + "................................", + "................................", + "................................", + "................................", + "................................"}; + + +/*! + Constructor +*/ +Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) + : QWidget (parent, title, 0), + myOperation( NoOpId ), + myCurveType( 1 ), + myShowLegend( true ), myLegendPos( 1 ), + myMarkerSize( DEFAULT_MARKER_SIZE ), + myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ), + myBackground( white ), + myTitleEnabled( true ), myXTitleEnabled( true ), + myYTitleEnabled( true ), myY2TitleEnabled (true), + myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ), + myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ), + myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ), + myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ), + myXMode( 0 ), myYMode( 0 ), mySecondY( false ) +{ + /* Plot 2d View */ + QVBoxLayout* aLayout = new QVBoxLayout( this ); + myPlot = new Plot2d_Plot2d( this ); + new Plot2d_ToolTip( this, myPlot ); + + aLayout->addWidget( myPlot ); + +// createActions(); + + connect( myPlot, SIGNAL( plotMouseMoved( const QMouseEvent& ) ), + this, SLOT( plotMouseMoved( const QMouseEvent& ) ) ); + connect( myPlot, SIGNAL( plotMousePressed( const QMouseEvent& ) ), + this, SLOT( plotMousePressed( const QMouseEvent& ) ) ); + connect( myPlot, SIGNAL( plotMouseReleased( const QMouseEvent& ) ), + this, SLOT( plotMouseReleased( const QMouseEvent& ) ) ); + //connect( myPlot, SIGNAL( legendClicked( long ) ), + // this, SLOT( onLegendClicked( long ) ) ); + + /* Initial Setup - get from the preferences */ + readPreferences(); + + myPlot->setMargin( 5 ); + setCurveType( myCurveType, false ); + setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false ); + setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor, + myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, false ); + + setTitle( myTitleEnabled, myTitle, MainTitle, false ); + setTitle( myXTitleEnabled, myXTitle, XTitle, false ); + setTitle( myYTitleEnabled, myYTitle, YTitle, false ); + + if (mySecondY) + setTitle( myY2TitleEnabled, myY2Title, Y2Title, false ); + setHorScaleMode( myXMode, false ); + setVerScaleMode( myYMode, false ); + setBackgroundColor( myBackground ); + setLegendPos( myLegendPos ); + showLegend( myShowLegend, false ); + myPlot->replot(); + + if ( parent ) { + resize( (int)(0.8 * parent->width()), (int)(0.8 * parent->height()) ); + } + QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); + QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + myXDistance = xMap.d2() - xMap.d1(); + myYDistance = yMap.d2() - yMap.d1(); + myYDistance2 = 0; + if (mySecondY) { + QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight ); + myYDistance2 = yMap2.d2() - yMap2.d1(); + } +} +/*! + Destructor +*/ +Plot2d_ViewFrame::~Plot2d_ViewFrame() +{ +} +/*! + Gets window's central widget +*/ +QWidget* Plot2d_ViewFrame::getViewWidget() +{ + return (QWidget*)myPlot; +} +/*! + Actually this method just re-displays all curves which are presented in the viewer +*/ +void Plot2d_ViewFrame::DisplayAll() +{ + QList clist; + getCurves( clist ); + for ( int i = 0; i < (int)clist.count(); i++ ) { + updateCurve( clist.at( i ), false ); + } + myPlot->replot(); +} +/*! + Removes all curves from the view +*/ +void Plot2d_ViewFrame::EraseAll() +{ + myPlot->clear(); + myCurves.clear(); + myPlot->replot(); +} +/*! + Redraws viewframe contents +*/ +void Plot2d_ViewFrame::Repaint() +{ + myPlot->replot(); +} +/*! + Display presentation +*/ +void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs ) +{ + if ( !prs || prs->IsNull() ) + return; + + if (prs->isSecondY()) { + myPlot->enableAxis(QwtPlot::yRight, true); + mySecondY = true; + } + else { + myPlot->enableAxis(QwtPlot::yRight, false); + mySecondY = false; + } + + // display all curves from presentation + curveList aCurves = prs->getCurves(); + displayCurves( aCurves ); + setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true ); + setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor, + myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true ); +} + +/*! + Erase presentation +*/ +void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool ) +{ + if ( !prs || prs->IsNull() ) + return; + + // erase all curves from presentation + curveList aCurves = prs->getCurves(); + eraseCurves( aCurves ); +} + +/*! + Sets title +*/ +void Plot2d_ViewFrame::setTitle( const QString& title ) +{ + setTitle( myTitleEnabled, title, MainTitle, true ); +} + +/*! + Reads Plot2d view settings from the preferences +*/ +void Plot2d_ViewFrame::readPreferences() +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + + myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType ); + setCurveType( resMgr->integerValue( "Plot2d", "CurveType", myCurveType ) ); + + myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend ); + myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos ); + myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize ); + myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground ); + + myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled ); + myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled ); + myYTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled ); + myY2TitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled ); + + myXGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled ); + myYGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled ); + myY2GridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled ); + + myXGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled ); + myYGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled ); + myY2GridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled ); + + myXGridMaxMajor = resMgr->integerValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor ); + myYGridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor ); + if ( mySecondY ) + myY2GridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorRightGridMax", myY2GridMaxMajor ); + + myXGridMaxMinor = resMgr->integerValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor ); + myYGridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor ); + if ( mySecondY ) + myY2GridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myY2GridMaxMinor ); + + myXMode = resMgr->integerValue( "Plot2d", "HorScaleMode", myXMode ); + myXMode = QMAX( 0, QMIN( 1, myXMode ) ); + + myYMode = resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode ); + myYMode = QMAX( 0, QMIN( 1, myYMode ) ); +} + +/*! + Writes Plot2d view settings to the preferences +*/ +void Plot2d_ViewFrame::writePreferences() +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + + resMgr->setValue( "Plot2d", "CurveType", myCurveType ); + resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend ); + resMgr->setValue( "Plot2d", "LegendPos", myLegendPos ); + resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize ); + resMgr->setValue( "Plot2d", "Background", myBackground ); + resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled ); + resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled ); + resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled ); + if ( mySecondY ) + resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled ); + + resMgr->setValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled ); + resMgr->setValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled ); + resMgr->setValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled ); + resMgr->setValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled ); + + resMgr->setValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor ); + resMgr->setValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor ); + + resMgr->setValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor ); + resMgr->setValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor ); + + resMgr->setValue( "Plot2d", "HorScaleMode", myXMode ); + + if ( mySecondY ) + { + resMgr->setValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled ); + resMgr->setValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled ); + resMgr->setValue( "Plot2d", "VerRightMajorGridMax", myY2GridMaxMajor ); + resMgr->setValue( "Plot2d", "VerRightMinorGridMax", myY2GridMaxMinor ); + } + + resMgr->setValue( "Plot2d", "VerScaleMode", myYMode ); +} + +/*! + Prints mouse cursor coordinates into string +*/ +QString Plot2d_ViewFrame::getInfo( const QPoint& pnt ) +{ + int i; + bool xFound = false, yFound = false; + double xCoord, yCoord; + const QwtScaleDiv* aXscale = myPlot->axisScale( QwtPlot::xBottom ); + for ( i = 0; i < aXscale->majCnt(); i++ ) { + double majXmark = aXscale->majMark( i ); + int xmark = myPlot->transform( QwtPlot::xBottom, majXmark ); + if ( xmark-2 == pnt.x() ) { + xCoord = majXmark; + xFound = true; + break; + } + } + if ( !xFound ) { + for ( i = 0; i < aXscale->minCnt(); i++ ) { + double minXmark = aXscale->minMark( i ); + int xmark = myPlot->transform( QwtPlot::xBottom, minXmark ); + if ( xmark-2 == pnt.x() ) { + xCoord = minXmark; + xFound = true; + break; + } + } + } + const QwtScaleDiv* aYscale = myPlot->axisScale( QwtPlot::yLeft ); + for ( i = 0; i < aYscale->majCnt(); i++ ) { + double majYmark = aYscale->majMark( i ); + int ymark = myPlot->transform( QwtPlot::yLeft, majYmark ); + if ( ymark-2 == pnt.y() ) { + yCoord = majYmark; + yFound = true; + break; + } + } + if ( !yFound ) { + for ( i = 0; i < aYscale->minCnt(); i++ ) { + double minYmark = aYscale->minMark( i ); + int ymark = myPlot->transform( QwtPlot::yLeft, minYmark ); + if ( ymark-2 == pnt.y() ) { + yCoord = minYmark; + yFound = true; + break; + } + } + } + + QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).stripWhiteSpace(); + if ( strX == "-0" ) + strX = "0"; + QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).stripWhiteSpace(); + if ( strY == "-0" ) + strY = "0"; + QString info = ""; + + if (mySecondY) { + bool yFound2 = false; + double yCoord2; + + const QwtScaleDiv* aYscale2 = myPlot->axisScale( QwtPlot::yRight ); + for ( i = 0; i < aYscale2->majCnt(); i++ ) { + double majYmark = aYscale2->majMark( i ); + int ymark = myPlot->transform( QwtPlot::yRight, majYmark ); + if ( ymark-2 == pnt.y() ) { + yCoord2 = majYmark; + yFound2 = true; + break; + } + } + if ( !yFound2 ) { + for ( i = 0; i < aYscale2->minCnt(); i++ ) { + double minYmark = aYscale2->minMark( i ); + int ymark = myPlot->transform( QwtPlot::yRight, minYmark ); + if ( ymark-2 == pnt.y() ) { + yCoord2 = minYmark; + yFound2 = true; + break; + } + } + } + QString strY2 = QString::number( yFound2 ? yCoord2 : + myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).stripWhiteSpace(); + if ( strY2 == "-0" ) + strY2 = "0"; + info = tr("INF_COORDINATES_SOME_Y").arg( strX ).arg( strY ).arg( strY2 ); + } + else + info = tr("INF_COORDINATES").arg( strX ).arg( strY ); + + return info; +} + +/*! + Converts Plot2d_Curve's marker style to Qwt marker style [ static ] +*/ +static QwtSymbol::Style plot2qwtMarker( Plot2d_Curve::MarkerType m ) +{ + QwtSymbol::Style ms = QwtSymbol::None; + switch ( m ) { + case Plot2d_Curve::Circle: + ms = QwtSymbol::Ellipse; break; + case Plot2d_Curve::Rectangle: + ms = QwtSymbol::Rect; break; + case Plot2d_Curve::Diamond: + ms = QwtSymbol::Diamond; break; + case Plot2d_Curve::DTriangle: + ms = QwtSymbol::DTriangle; break; + case Plot2d_Curve::UTriangle: + ms = QwtSymbol::UTriangle; break; + case Plot2d_Curve::LTriangle: // Qwt confuses LTriangle and RTriangle :((( + ms = QwtSymbol::RTriangle; break; + case Plot2d_Curve::RTriangle: // Qwt confuses LTriangle and RTriangle :((( + ms = QwtSymbol::LTriangle; break; + case Plot2d_Curve::Cross: + ms = QwtSymbol::Cross; break; + case Plot2d_Curve::XCross: + ms = QwtSymbol::XCross; break; + case Plot2d_Curve::None: + default: + ms = QwtSymbol::None; break; + } + return ms; +} + +/*! + Converts Qwt marker style to Plot2d_Curve's marker style [ static ] +*/ +static Plot2d_Curve::MarkerType qwt2plotMarker( QwtSymbol::Style m ) +{ + Plot2d_Curve::MarkerType ms = Plot2d_Curve::None; + switch ( m ) { + case QwtSymbol::Ellipse: + ms = Plot2d_Curve::Circle; break; + case QwtSymbol::Rect: + ms = Plot2d_Curve::Rectangle; break; + case QwtSymbol::Diamond: + ms = Plot2d_Curve::Diamond; break; + case QwtSymbol::DTriangle: + ms = Plot2d_Curve::DTriangle; break; + case QwtSymbol::UTriangle: + ms = Plot2d_Curve::UTriangle; break; + case QwtSymbol::RTriangle: // Qwt confuses LTriangle and RTriangle :((( + ms = Plot2d_Curve::LTriangle; break; + case QwtSymbol::LTriangle: // Qwt confuses LTriangle and RTriangle :((( + ms = Plot2d_Curve::RTriangle; break; + case QwtSymbol::Cross: + ms = Plot2d_Curve::Cross; break; + case QwtSymbol::XCross: + ms = Plot2d_Curve::XCross; break; + case QwtSymbol::None: + default: + ms = Plot2d_Curve::None; break; + } + return ms; +} + +/*! + Converts Plot2d_Curve's line style to Qwt line style [ static ] +*/ +static Qt::PenStyle plot2qwtLine( Plot2d_Curve::LineType p ) +{ + Qt::PenStyle ps = Qt::NoPen; + switch ( p ) { + case Plot2d_Curve::Solid: + ps = Qt::SolidLine; break; + case Plot2d_Curve::Dash: + ps = Qt::DashLine; break; + case Plot2d_Curve::Dot: + ps = Qt::DotLine; break; + case Plot2d_Curve::DashDot: + ps = Qt::DashDotLine; break; + case Plot2d_Curve::DashDotDot: + ps = Qt::DashDotDotLine; break; + case Plot2d_Curve::NoPen: + default: + ps = Qt::NoPen; break; + } + return ps; +} + +/*! + Converts Qwt line style to Plot2d_Curve's line style [ static ] +*/ +static Plot2d_Curve::LineType qwt2plotLine( Qt::PenStyle p ) +{ + Plot2d_Curve::LineType ps = Plot2d_Curve::NoPen; + switch ( p ) { + case Qt::SolidLine: + ps = Plot2d_Curve::Solid; break; + case Qt::DashLine: + ps = Plot2d_Curve::Dash; break; + case Qt::DotLine: + ps = Plot2d_Curve::Dot; break; + case Qt::DashDotLine: + ps = Plot2d_Curve::DashDot; break; + case Qt::DashDotDotLine: + ps = Plot2d_Curve::DashDotDot; break; + case Qt::NoPen: + default: + ps = Plot2d_Curve::NoPen; break; + } + return ps; +} + +/*! + Adds curve into view +*/ +void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) +{ + if ( !curve ) + return; + + // san -- Protection against QwtCurve 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 + if ( myXMode && curve->getMinX() <= 0. ) + setHorScaleMode( 0, false ); + if ( myYMode && curve->getMinY() <= 0. ) + setVerScaleMode( 0, false ); + + if ( hasCurve( curve ) ) { + updateCurve( curve, update ); + } + else { + long curveKey = myPlot->insertCurve( curve->getVerTitle() ); + myPlot->setCurveYAxis(curveKey, curve->getYAxis()); + + myCurves.insert( curveKey, curve ); + if ( curve->isAutoAssign() ) { + QwtSymbol::Style typeMarker; + QColor color; + Qt::PenStyle typeLine; + myPlot->getNextMarker( typeMarker, color, typeLine ); + myPlot->setCurvePen( curveKey, QPen( color, DEFAULT_LINE_WIDTH, typeLine ) ); + myPlot->setCurveSymbol( curveKey, QwtSymbol( typeMarker, + QBrush( color ), + QPen( color ), + QSize( myMarkerSize, myMarkerSize ) ) ); + curve->setColor( color ); + curve->setLine( qwt2plotLine( typeLine ) ); + curve->setMarker( qwt2plotMarker( typeMarker ) ); + } + else { + Qt::PenStyle ps = plot2qwtLine( curve->getLine() ); + QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() ); + myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) ); + myPlot->setCurveSymbol( curveKey, QwtSymbol( ms, + QBrush( curve->getColor() ), + QPen( curve->getColor() ), + QSize( myMarkerSize, myMarkerSize ) ) ); + } + if ( myCurveType == 0 ) + myPlot->setCurveStyle( curveKey, QwtCurve::NoCurve ); + else if ( myCurveType == 1 ) + myPlot->setCurveStyle( curveKey, QwtCurve::Lines ); + else if ( myCurveType == 2 ) + myPlot->setCurveStyle( curveKey, QwtCurve::Spline ); + myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() ); + } + updateTitles(); + if ( update ) + myPlot->replot(); +} + +/*! + Adds curves into view +*/ +void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update ) +{ + myPlot->setUpdatesEnabled( false ); + QPtrListIterator it(curves); + Plot2d_Curve* aCurve; + while( (aCurve = it.current()) ) { + displayCurve( aCurve, false ); + ++it; + } + + fitAll(); + myPlot->setUpdatesEnabled( true ); + if ( update ) + myPlot->replot(); +} + +/*! + Erases curve +*/ +void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update ) +{ + if ( !curve ) + return; + int curveKey = hasCurve( curve ); + if ( curveKey ) { + myPlot->removeCurve( curveKey ); + myCurves.remove( curveKey ); + updateTitles(); + if ( update ) + myPlot->replot(); + } +} + +/*! + Erases curves +*/ +void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update ) +{ + QPtrListIterator it(curves); + Plot2d_Curve* aCurve; + while( (aCurve = it.current()) ) { + eraseCurve( aCurve, false ); + ++it; + } +// fitAll(); + if ( update ) + myPlot->replot(); +} + +/*! + Updates curves attributes +*/ +void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update ) +{ + if ( !curve ) + return; + int curveKey = hasCurve( curve ); + if ( curveKey ) { + if ( !curve->isAutoAssign() ) { + Qt::PenStyle ps = plot2qwtLine( curve->getLine() ); + QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() ); + myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) ); + myPlot->setCurveSymbol( curveKey, QwtSymbol( ms, + QBrush( curve->getColor() ), + QPen( curve->getColor() ), + QSize( myMarkerSize, myMarkerSize ) ) ); + myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() ); + } + myPlot->setCurveTitle( curveKey, curve->getVerTitle() ); + myPlot->curve( curveKey )->setEnabled( true ); + if ( update ) + myPlot->replot(); + } +} + +/*! + Returns curve key if is is displayed in the viewer and 0 otherwise +*/ +int Plot2d_ViewFrame::hasCurve( Plot2d_Curve* curve ) +{ + QIntDictIterator it( myCurves ); + for ( ; it.current(); ++it ) { + if ( it.current() == curve ) + return it.currentKey(); + } + return 0; +} + +/*! + Gets lsit of displayed curves +*/ +int Plot2d_ViewFrame::getCurves( QList& clist ) +{ + clist.clear(); + clist.setAutoDelete( false ); + QIntDictIterator it( myCurves ); + for ( ; it.current(); ++it ) { + clist.append( it.current() ); + } + return clist.count(); +} + +/*! + Returns true if the curve is visible +*/ +bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve ) +{ + if(curve) { + int key = hasCurve( curve ); + if ( key ) + return myPlot->curve( key )->enabled(); + } + return false; +} + +/*! + update legend +*/ +void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs ) +{ + if ( !prs || prs->IsNull() ) + return; + curveList aCurves = prs->getCurves(); + + QPtrListIterator it(aCurves); + Plot2d_Curve* aCurve; + while( (aCurve = it.current()) ) { + int curveKey = hasCurve( aCurve ); + if ( curveKey ) + myPlot->setCurveTitle( curveKey, aCurve->getVerTitle() ); + ++it; + } +} + +/*! + Fits the view to see all data +*/ +void Plot2d_ViewFrame::fitAll() +{ + QwtDiMap xMap1 = myPlot->canvasMap( QwtPlot::xBottom ); + + myPlot->setAxisAutoScale( QwtPlot::yLeft ); + myPlot->setAxisAutoScale( QwtPlot::xBottom ); + 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() ) ); + myPlot->setAxisScale( QwtPlot::yLeft, + myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), + myPlot->invTransform( QwtPlot::yLeft, yMap.i2() ) ); + + 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() ) ); + } + myPlot->replot(); +} + +/*! + Fits the view to rectangle area (pixels) +*/ +void Plot2d_ViewFrame::fitArea( const QRect& area ) +{ + QRect rect = area.normalize(); + if ( rect.width() < MIN_RECT_SIZE ) { + rect.setWidth( MIN_RECT_SIZE ); + rect.setLeft( rect.left() - MIN_RECT_SIZE/2 ); + } + if ( rect.height() < MIN_RECT_SIZE ) { + rect.setHeight( MIN_RECT_SIZE ); + rect.setTop( rect.top() - MIN_RECT_SIZE/2 ); + } + myPlot->setAxisScale( QwtPlot::yLeft, + myPlot->invTransform( QwtPlot::yLeft, rect.top() ), + myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) ); + if (mySecondY) + myPlot->setAxisScale( QwtPlot::yRight, + myPlot->invTransform( QwtPlot::yRight, rect.top() ), + myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) ); + myPlot->setAxisScale( QwtPlot::xBottom, + myPlot->invTransform( QwtPlot::xBottom, rect.left() ), + myPlot->invTransform( QwtPlot::xBottom, rect.right() ) ); + myPlot->replot(); +} + +/*! + "Fit Data" command for TUI interface +*/ +void Plot2d_ViewFrame::fitData(const int mode, + const double xMin, const double xMax, + const double yMin, const double yMax, + double y2Min, double y2Max) +{ + if ( mode == 0 || mode == 2 ) { + myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin ); + if (mySecondY) + myPlot->setAxisScale( QwtPlot::yRight, y2Max, y2Min ); + } + if ( mode == 0 || mode == 1 ) + myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax ); + myPlot->replot(); +} + +/*! + Gets current fit ranges for view frame +*/ +void Plot2d_ViewFrame::getFitRanges(double& xMin,double& xMax, + double& yMin, double& yMax, + double& y2Min, double& y2Max) +{ + int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1(); + int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2(); + int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1(); + int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2(); + xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin); + xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax); + yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin); + yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax); + y2Min = 0; + y2Max = 0; + if (mySecondY) { + int iyMin = myPlot->canvasMap( QwtPlot::yRight ).i1(); + int iyMax = myPlot->canvasMap( QwtPlot::yRight ).i2(); + y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin); + y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax); + } +} + +/*! + Tests if it is necessary to start operation on mouse action +*/ +int Plot2d_ViewFrame::testOperation( const QMouseEvent& me ) +{ + int btn = me.button() | me.state(); + const int zoomBtn = ControlButton | LeftButton; + const int panBtn = ControlButton | MidButton; + const int fitBtn = ControlButton | RightButton; + + switch (btn) + { + case zoomBtn: + { + QPixmap zoomPixmap (imageZoomCursor); + QCursor zoomCursor (zoomPixmap); + myPlot->canvas()->setCursor( zoomCursor ); + return ZoomId; + } + case panBtn: + myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) ); + return PanId; + case fitBtn: + myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) ); + return FitAreaId; + default : + return NoOpId; + } +} + +/*! + "Settings" toolbar action slot +*/ +void Plot2d_ViewFrame::onSettings() +{ +#ifdef TEST_AUTOASSIGN + typedef QMap IList; + typedef QMap SList; + IList mars, lins; + SList cols; + cols[ "red-min" ] = 1000; + cols[ "red-max" ] = -1; + cols[ "green-min" ] = 1000; + cols[ "green-max" ] = -1; + cols[ "blue-min" ] = 1000; + cols[ "blue-max" ] = -1; + for ( unsigned i = 0; i < 10000; i++ ) { + QwtSymbol::Style typeMarker; + QColor color; + Qt::PenStyle typeLine; + myPlot->getNextMarker( typeMarker, color, typeLine ); + if ( mars.contains(typeMarker) ) + mars[ typeMarker ] = mars[ typeMarker ]+1; + else + mars[ typeMarker ] = 0; + if ( lins.contains(typeLine) ) + lins[ typeLine ] = lins[ typeLine ]+1; + else + lins[ typeLine ] = 0; + if ( cols[ "red-max" ] < color.red() ) + cols[ "red-max" ] = color.red(); + if ( cols[ "red-min" ] > color.red() ) + cols[ "red-min" ] = color.red(); + if ( cols[ "green-max" ] < color.green() ) + cols[ "green-max" ] = color.green(); + if ( cols[ "green-min" ] > color.green() ) + cols[ "green-min" ] = color.green(); + if ( cols[ "blue-max" ] < color.blue() ) + cols[ "blue-max" ] = color.blue(); + if ( cols[ "blue-min" ] > color.blue() ) + cols[ "blue-min" ] = color.blue(); + } +#endif + + Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY ); + dlg->setMainTitle( myTitleEnabled, myTitle ); + dlg->setXTitle( myXTitleEnabled, myXTitle ); + dlg->setYTitle( myYTitleEnabled, myYTitle ); + if (mySecondY) + dlg->setY2Title( myY2TitleEnabled, myY2Title ); + dlg->setCurveType( myCurveType ); + dlg->setLegend( myShowLegend, myLegendPos ); + dlg->setMarkerSize( myMarkerSize ); + dlg->setBackgroundColor( myBackground ); + dlg->setScaleMode(myXMode, myYMode); + // + dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ), + myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ), + myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) ); + dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ), + myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ), + myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) ); + if ( dlg->exec() == QDialog::Accepted ) { + // horizontal axis title + setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false ); + // vertical left axis title + setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false ); + if (mySecondY) // vertical right axis title + setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false ); + + // main title + setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true ); + // curve type + if ( myCurveType != dlg->getCurveType() ) { + setCurveType( dlg->getCurveType(), false ); + } + // legend + if ( myShowLegend != dlg->isLegendEnabled() ) { + showLegend( dlg->isLegendEnabled(), false ); + } + if ( myLegendPos != dlg->getLegendPos() ) { + setLegendPos( dlg->getLegendPos() ); + } + // marker size + if ( myMarkerSize != dlg->getMarkerSize() ) { + setMarkerSize( dlg->getMarkerSize(), false ); + } + // background color + if ( myBackground != dlg->getBackgroundColor() ) { + setBackgroundColor( dlg->getBackgroundColor() ); + } + // grid + bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled, + aY2GridMajorEnabled, aY2GridMinorEnabled; + int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor, + aY2GridMaxMajor, aY2GridMaxMinor; + dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor, + aY2GridMajorEnabled, aY2GridMaxMajor); + dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor, + aY2GridMinorEnabled, aY2GridMaxMinor); + setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false ); + setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor, + aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false ); + if ( myXMode != dlg->getXScaleMode() ) { + setHorScaleMode( dlg->getXScaleMode() ); + } + if ( myYMode != dlg->getYScaleMode() ) { + setVerScaleMode( dlg->getYScaleMode() ); + } + // update view + myPlot->replot(); + // update preferences + if ( dlg->isSetAsDefault() ) + writePreferences(); + } + delete dlg; +} + +/*! + "Fit Data" command slot +*/ +void Plot2d_ViewFrame::onFitData() +{ + Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY ); + double xMin,xMax,yMin,yMax,y2Min,y2Max; + getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max); + + dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max ); + if ( dlg->exec() == QDialog::Accepted ) { + int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max ); + fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max); + } + delete dlg; +} + +/*! + Change background color +*/ +void Plot2d_ViewFrame::onChangeBackground() +{ + QColor selColor = QColorDialog::getColor ( backgroundColor(), this ); + if ( selColor.isValid() ) { + setBackgroundColor( selColor ); + } +} + +/*! + Sets curve type +*/ +void Plot2d_ViewFrame::setCurveType( int curveType, bool update ) +{ + myCurveType = curveType; + QArray keys = myPlot->curveKeys(); + for ( int i = 0; i < (int)keys.count(); i++ ) { + if ( myCurveType == 0 ) + myPlot->setCurveStyle( keys[i], QwtCurve::Dots );//QwtCurve::NoCurve + else if ( myCurveType == 1 ) + myPlot->setCurveStyle( keys[i], QwtCurve::Lines ); + else if ( myCurveType == 2 ) + myPlot->setCurveStyle( keys[i], QwtCurve::Spline ); + } + if ( update ) + myPlot->replot(); + emit vpCurveChanged(); +} + +/*! + Sets curve title + \param curveKey - curve id + \param title - new title +*/ +void Plot2d_ViewFrame::setCurveTitle( int curveKey, const QString& title ) +{ + if(myPlot) myPlot->setCurveTitle(curveKey, title); +} + +/*! + Shows/hides legend +*/ +void Plot2d_ViewFrame::showLegend( bool show, bool update ) +{ + myShowLegend = show; + myPlot->setAutoLegend( myShowLegend ); + myPlot->enableLegend( myShowLegend ); + if ( update ) + myPlot->replot(); +} + +/*! + Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom +*/ +void Plot2d_ViewFrame::setLegendPos( int pos ) +{ + myLegendPos = pos; + switch( pos ) { + case 0: + myPlot->setLegendPos( Qwt::Left ); + break; + case 1: + myPlot->setLegendPos( Qwt::Right ); + break; + case 2: + myPlot->setLegendPos( Qwt::Top ); + break; + case 3: + myPlot->setLegendPos( Qwt::Bottom ); + break; + } +} + +/*! + Sets new marker size +*/ +void Plot2d_ViewFrame::setMarkerSize( const int size, bool update ) +{ + if ( myMarkerSize != size ) + { + myMarkerSize = size; + QArray keys = myPlot->curveKeys(); + for ( int i = 0; i < (int)keys.count(); i++ ) + { + QwtPlotCurve* crv = myPlot->curve( keys[i] ); + if ( crv ) + { + QwtSymbol aSymbol = crv->symbol(); + aSymbol.setSize( myMarkerSize, myMarkerSize ); + myPlot->setCurveSymbol( keys[i], aSymbol ); + } + } + if ( update ) + myPlot->replot(); + } +} + +/*! + Sets background color +*/ +void Plot2d_ViewFrame::setBackgroundColor( const QColor& color ) +{ + myBackground = color; + //myPlot->setCanvasBackground( myBackground ); + myPlot->canvas()->setPalette( myBackground ); + myPlot->setPalette( myBackground ); + QPalette aPal = myPlot->getLegend()->palette(); + for ( int i = 0; i < QPalette::NColorGroups; i++ ) { + QPalette::ColorGroup cg = (QPalette::ColorGroup)i; + aPal.setColor( cg, QColorGroup::Base, myBackground ); + aPal.setColor( cg, QColorGroup::Background, myBackground ); + } + myPlot->getLegend()->setPalette( aPal ); + Repaint(); +} +/*! + Gets background color +*/ +QColor Plot2d_ViewFrame::backgroundColor() const +{ + return myBackground; +} +/*! + Sets hor.axis grid parameters +*/ +void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax, + bool xMinorEnabled, const int xMinorMax, + bool update ) +{ + myXGridMajorEnabled = xMajorEnabled; + myXGridMinorEnabled = xMinorEnabled; + myXGridMaxMajor = xMajorMax; + myXGridMaxMinor = xMinorMax; + myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor ); + myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor ); + myPlot->setGridXAxis(QwtPlot::xBottom); + myPlot->enableGridX( myXGridMajorEnabled ); + myPlot->enableGridXMin( myXGridMinorEnabled ); + if ( update ) + myPlot->replot(); +} +/*! + Sets ver.axis grid parameters +*/ +void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax, + bool yMinorEnabled, const int yMinorMax, + bool y2MajorEnabled, const int y2MajorMax, + bool y2MinorEnabled, const int y2MinorMax, + bool update ) +{ + myYGridMajorEnabled = yMajorEnabled; + myYGridMinorEnabled = yMinorEnabled; + myYGridMaxMajor = yMajorMax; + myYGridMaxMinor = yMinorMax; + + if (mySecondY) { + myY2GridMajorEnabled = y2MajorEnabled; + myY2GridMinorEnabled = y2MinorEnabled; + myY2GridMaxMajor = y2MajorMax; + myY2GridMaxMinor = y2MinorMax; + } + myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor ); + myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor ); + + if (mySecondY) { + myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor ); + myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor ); + } + + myPlot->setGridYAxis(QwtPlot::yLeft); + + if (mySecondY) { + if (myYGridMajorEnabled) { + myPlot->enableGridYMin(myYGridMinorEnabled); + myPlot->enableGridY( myYGridMajorEnabled); + } + else if (myY2GridMajorEnabled) { + myPlot->setGridYAxis(QwtPlot::yRight); + myPlot->enableGridYMin(myY2GridMinorEnabled); + myPlot->enableGridY(myY2GridMajorEnabled); + } + else { + myPlot->enableGridYMin(false); + myPlot->enableGridY(false); + } + } + else { + myPlot->enableGridY( myYGridMajorEnabled ); + myPlot->enableGridYMin( myYGridMinorEnabled ); + } + if ( update ) + myPlot->replot(); +} + +/*! + Sets title for some axis +*/ +void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title, + ObjectType type, bool update ) +{ + switch (type) { + case MainTitle: + myTitleEnabled = enabled; + myTitle = title; + myPlot->setTitle( myTitleEnabled ? myTitle : QString::null ); + break; + case XTitle: + myXTitleEnabled = enabled; + myXTitle = title; + myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString::null ); + break; + case YTitle: + myYTitleEnabled = enabled; + myYTitle = title; + myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString::null ); + break; + case Y2Title: + myY2TitleEnabled = enabled; + myY2Title = title; + myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString::null ); + break; + } + if ( update ) + myPlot->replot(); +} +/*! + Sets title for some axis +*/ +QString Plot2d_ViewFrame::getTitle( ObjectType type ) const +{ + QString title = ""; + switch (type) { + case MainTitle: + title = myTitle; break; + case XTitle: + title = myXTitle; break; + case YTitle: + title = myYTitle; break; + case Y2Title: + title = myY2Title; break; + } + return title; +} +/*! + Sets font for Plot2d object : title or axis +*/ +void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update) +{ + switch (type) { + case MainTitle: + myPlot->setTitleFont(font); + break; + case XTitle: + myPlot->setAxisTitleFont(QwtPlot::xBottom, font); break; + case YTitle: + myPlot->setAxisTitleFont(QwtPlot::yLeft, font); break; + case Y2Title: + myPlot->setAxisTitleFont(QwtPlot::yRight, font); break; + case XAxis: + myPlot->setAxisFont(QwtPlot::xBottom, font); break; + case YAxis: + myPlot->setAxisFont(QwtPlot::yLeft, font); break; + case Y2Axis: + myPlot->setAxisFont(QwtPlot::yRight, font); break; + } + if ( update ) + myPlot->replot(); +} +/*! + Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic +*/ +void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update ) +{ + // san -- Protection against QwtCurve 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 + if ( mode && !isXLogEnabled() ){ + SUIT_MessageBox::warn1(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"), tr("BUT_OK")); + return; + } + + myXMode = mode; + + myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, myXMode != 0 ); + + if ( update ) + fitAll(); + emit vpModeHorChanged(); +} +/*! + Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic +*/ +void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update ) +{ + // san -- Protection against QwtCurve 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 + if ( mode && !isYLogEnabled() ){ + SUIT_MessageBox::warn1(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"), tr("BUT_OK")); + return; + } + + myYMode = mode; + myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, myYMode != 0 ); + if (mySecondY) + myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, myYMode != 0 ); + + if ( update ) + fitAll(); + emit vpModeVerChanged(); +} + +/*! + Return, scale mode for horizontal axis +*/ +bool Plot2d_ViewFrame::isModeHorLinear() +{ + return (myXMode == 0 ? true : false); +} + +/*! + Return, scale mode for vertical axis +*/ +bool Plot2d_ViewFrame::isModeVerLinear() +{ + return (myYMode == 0 ? true : false); +} +/*! + Slot, called when user presses mouse button +*/ +void Plot2d_ViewFrame::plotMousePressed(const QMouseEvent& me ) +{ + Plot2d_ViewWindow* aParent = dynamic_cast(parent()); + if (aParent) + aParent->putInfo(getInfo(me.pos())); + if ( myOperation == NoOpId ) + myOperation = testOperation( me ); + if ( myOperation != NoOpId ) { + myPnt = me.pos(); + if ( myOperation == FitAreaId ) { + myPlot->setOutlineStyle( Qwt::Rect ); + } + else if ( myOperation == GlPanId ) { + myPlot->setAxisScale( QwtPlot::yLeft, + myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2, + myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2 ); + myPlot->setAxisScale( QwtPlot::xBottom, + myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2, + myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 ); + if (mySecondY) + myPlot->setAxisScale( QwtPlot::yRight, + myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2, + myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2 ); + myPlot->replot(); + } + } + else { + int btn = me.button() | me.state(); + if (btn == RightButton) { + QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress, + me.pos(), btn, me.state()); + // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'. + parent()->eventFilter(this, aEvent); + } + } + setFocus(); +} +/*! + Slot, called when user moves mouse +*/ +void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me ) +{ + int dx = me.pos().x() - myPnt.x(); + int dy = me.pos().y() - myPnt.y(); + + if ( myOperation != NoOpId) { + if ( myOperation == ZoomId ) { + this->incrementalZoom( dx, dy ); + myPnt = me.pos(); + } + else if ( myOperation == PanId ) { + this->incrementalPan( dx, dy ); + myPnt = me.pos(); + } + } + else { + Plot2d_ViewWindow* aParent = dynamic_cast(parent()); + if (aParent) + aParent->putInfo(getInfo(me.pos())); + } +} +/*! + Slot, called when user releases mouse +*/ +void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me ) +{ + if ( myOperation == NoOpId && me.button() == RightButton ) + { + QContextMenuEvent aEvent( QContextMenuEvent::Mouse, + me.pos(), me.globalPos(), + me.state() ); + emit contextMenuRequested( &aEvent ); + } + if ( myOperation == FitAreaId ) { + QRect rect( myPnt, me.pos() ); + fitArea( rect ); + } + myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) ); + myPlot->setOutlineStyle( Qwt::Triangle ); + + Plot2d_ViewWindow* aParent = dynamic_cast(parent()); + if (aParent) + aParent->putInfo(tr("INF_READY")); + myOperation = NoOpId; +} +/*! + Slot, called when user wheeling mouse +*/ +void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event) +{ + double aDelta = event->delta(); + double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.; + + QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); + QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + + myPlot->setAxisScale( QwtPlot::yLeft, + myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), + myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )*aScale ); + myPlot->setAxisScale( QwtPlot::xBottom, + myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ), + myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )*aScale ); + if (mySecondY) { + QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight ); + myPlot->setAxisScale( QwtPlot::yRight, + myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ), + myPlot->invTransform( QwtPlot::yRight, y2Map.i2() )*aScale ); + } + myPlot->replot(); + myPnt = event->pos(); +} +/*! + View operations : Pan view +*/ +void Plot2d_ViewFrame::onViewPan() +{ + QCursor panCursor (Qt::SizeAllCursor); + myPlot->canvas()->setCursor( panCursor ); + myOperation = PanId; + qApp->installEventFilter( this ); +} +/*! + View operations : Zoom view +*/ +void Plot2d_ViewFrame::onViewZoom() +{ + QPixmap zoomPixmap (imageZoomCursor); + QCursor zoomCursor (zoomPixmap); + myPlot->canvas()->setCursor( zoomCursor ); + myOperation = ZoomId; + qApp->installEventFilter( this ); +} +/*! + View operations : Fot All +*/ +void Plot2d_ViewFrame::onViewFitAll() +{ + fitAll(); +} +/*! + View operations : Fit Area +*/ +void Plot2d_ViewFrame::onViewFitArea() +{ + myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) ); + myOperation = FitAreaId; + qApp->installEventFilter( this ); +} +/*! + View operations : Global panning +*/ +void Plot2d_ViewFrame::onViewGlobalPan() +{ + QPixmap globalPanPixmap (imageCrossCursor); + QCursor glPanCursor (globalPanPixmap); + myPlot->canvas()->setCursor( glPanCursor ); + myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false ); + myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false ); + if (mySecondY) + myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false ); + myPlot->replot(); + QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); + QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + + myXDistance = xMap.d2() - xMap.d1(); + myYDistance = yMap.d2() - yMap.d1(); + + if (mySecondY) { + QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight ); + myYDistance2 = yMap2.d2() - yMap2.d1(); + } + fitAll(); + myOperation = GlPanId; + qApp->installEventFilter( this ); +} + +/*! + Precaution for logarithmic X scale +*/ +bool Plot2d_ViewFrame::isXLogEnabled() const +{ + bool allPositive = true; + QIntDictIterator it( myCurves ); + for ( ; allPositive && it.current(); ++it ) { + allPositive = ( it.current()->getMinX() > 0. ); + } + return allPositive; +} + +/*! + Precaution for logarithmic Y scale +*/ +bool Plot2d_ViewFrame::isYLogEnabled() const +{ + bool allPositive = true; + QIntDictIterator it( myCurves ); + for ( ; allPositive && it.current(); ++it ) { + allPositive = ( it.current()->getMinY() > 0. ); + } + return allPositive; +} + +/*! + Constructor +*/ +Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent ) + : QwtPlot( parent ) +{ + // outline + enableOutline( true ); + setOutlineStyle( Qwt::Triangle ); + setOutlinePen( green ); + // legend + setAutoLegend( false ); + setLegendFrameStyle( QFrame::Box | QFrame::Sunken ); + enableLegend( false ); + // grid + enableGridX( false ); + enableGridXMin( false ); + enableGridY( false ); + enableGridYMin( false ); + // auto scaling by default + setAxisAutoScale( QwtPlot::yLeft ); + setAxisAutoScale( QwtPlot::yRight ); + setAxisAutoScale( QwtPlot::xBottom ); +} +/*! + Recalculates and redraws Plot 2d view +*/ +void Plot2d_Plot2d::replot() +{ + updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed + QwtPlot::replot(); +} + +/*! + Checks if two colors are close to each other [ static ] + uses COLOR_DISTANCE variable as max tolerance for comparing of colors +*/ +const long COLOR_DISTANCE = 100; +const int MAX_ATTEMPTS = 10; +static bool closeColors( const QColor& color1, const QColor& color2 ) +{ + long tol = abs( color2.red() - color1.red() ) + + abs( color2.green() - color1.green() ) + + abs( color2.blue() - color1.blue() ); + + return ( tol <= COLOR_DISTANCE ); +} +/*! + Gets new unique marker for item if possible +*/ +void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine ) +{ + bool bOk = false; + int cnt = 1; + while ( !bOk ) { + int aRed = (int)( 256.0 * rand() / RAND_MAX); // generate random color + int aGreen = (int)( 256.0 * rand() / RAND_MAX); // ... + int aBlue = (int)( 256.0 * rand() / RAND_MAX); // ... + int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1; // 9 markers types ( not including empty ) + int aLine = (int)( 5.0 * rand() / RAND_MAX) + 1; // 5 line types ( not including empty ) + + typeMarker = ( QwtSymbol::Style )aMarker; + color = QColor( aRed, aGreen, aBlue ); + typeLine = ( Qt::PenStyle )aLine; + + cnt++; + if ( cnt == MAX_ATTEMPTS ) + bOk = true; + else + bOk = !existMarker( typeMarker, color, typeLine ); + } +/* + static int aMarker = -1; + static int aColor = -1; + static int aLine = -1; + + if ( myColors.isEmpty() ) { + // creating colors list + myColors.append( Qt::white ); + myColors.append( Qt::blue ); + myColors.append( Qt::gray ); + myColors.append( Qt::darkGreen ); + myColors.append( Qt::magenta ); + myColors.append( Qt::darkGray ); + myColors.append( Qt::red ); + myColors.append( Qt::darkBlue ); + myColors.append( Qt::darkYellow ); + myColors.append( Qt::cyan ); + myColors.append( Qt::darkRed ); + myColors.append( Qt::darkCyan ); + myColors.append( Qt::yellow ); + myColors.append( Qt::darkMagenta ); + myColors.append( Qt::green ); + myColors.append( Qt::black ); + } + + int nbMarkers = 11; // QwtSymbol supports 11 marker types + int nbLines = 6; // Qt supports 6 line types + int nbColors = myColors.count(); // number of default colors supported + + aMarker = ( aMarker + 1 ) % nbMarkers; + if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++; + aColor = ( aColor + 1 ) % nbColors; + aLine = ( aLine + 1 ) % nbLines; + if ( aLine == Qt::NoPen ) aLine++; + + typeMarker = ( QwtSymbol::Style )aMarker; + color = myColors[ aColor ]; + typeLine = ( Qt::PenStyle )aLine; + if ( !existMarker( typeMarker, color, typeLine ) ) + return; + + int i, j, k; + for ( i = 0; i < nbMarkers; i++ ) { + aMarker = ( aMarker + 1 ) % nbMarkers; + if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++; + for ( j = 0; j < nbColors; j++ ) { + aColor = ( aColor + 1 ) % nbColors; + for ( k = 0; k < nbLines; k++ ) { + aLine = ( aLine + 1 ) % nbLines; + if ( aLine == Qt::NoPen ) aLine++; + if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) { + typeMarker = ( QwtSymbol::Style )aMarker; + color = myColors[ aColor ]; + typeLine = ( Qt::PenStyle )aLine; + return; + } + } + } + } +*/ +} + +/*! + \return the default layout behavior of the widget +*/ +QSizePolicy Plot2d_Plot2d::sizePolicy() const +{ + return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); +} + +/*! + \return the recommended size for the widget +*/ +QSize Plot2d_Plot2d::sizeHint() const +{ + return QwtPlot::minimumSizeHint(); +} + +/*! + return minimum size for qwt plot +*/ +QSize Plot2d_Plot2d::minimumSizeHint() const +{ + return QSize( 0, 0 ); +// QSize aSize = QwtPlot::minimumSizeHint(); +// return QSize(aSize.width()*3/4, aSize.height()); +} +/*! + Checks if marker belongs to any enitity +*/ +bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ) +{ + // getting all curves + QArray keys = curveKeys(); + //QColor aRgbColor; + + if ( closeColors( color, backgroundColor() ) ) + return true; + for ( int i = 0; i < (int)keys.count(); i++ ) + { + QwtPlotCurve* crv = curve( keys[i] ); + if ( crv ) { + QwtSymbol::Style aStyle = crv->symbol().style(); + QColor aColor = crv->pen().color(); + Qt::PenStyle aLine = crv->pen().style(); +// if ( aStyle == typeMarker && aColor == color && aLine == typeLine ) + if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine ) + return true; + } + } + return false; +} + +/*! + Creates presentation of object + Default implementation is empty +*/ +Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ ) +{ + return 0; +} + +/*! + Copies preferences from other viewframe + \param vf - other view frame +*/ +void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf ) +{ + if( !vf ) + return; + + myCurveType = vf->myCurveType; + myShowLegend = vf->myShowLegend; + myLegendPos = vf->myLegendPos; + myMarkerSize = vf->myMarkerSize; + myBackground = vf->myBackground; + myTitle = vf->myTitle; + myXTitle = vf->myXTitle; + myYTitle = vf->myYTitle; + myY2Title = vf->myY2Title; + myTitleEnabled = vf->myTitleEnabled; + myXTitleEnabled = vf->myXTitleEnabled; + myYTitleEnabled = vf->myYTitleEnabled; + myY2TitleEnabled = vf->myY2TitleEnabled; + myXGridMajorEnabled = vf->myXGridMajorEnabled; + myYGridMajorEnabled = vf->myYGridMajorEnabled; + myY2GridMajorEnabled = vf->myY2GridMajorEnabled; + myXGridMinorEnabled = vf->myXGridMinorEnabled; + myYGridMinorEnabled = vf->myYGridMinorEnabled; + myY2GridMinorEnabled = vf->myY2GridMinorEnabled; + myXGridMaxMajor = vf->myXGridMaxMajor; + myYGridMaxMajor = vf->myYGridMaxMajor; + myY2GridMaxMajor = vf->myY2GridMaxMajor; + myXGridMaxMinor = vf->myXGridMaxMinor; + myYGridMaxMinor = vf->myYGridMaxMinor; + myY2GridMaxMinor = vf->myY2GridMaxMinor; + myXMode = vf->myXMode; + myYMode = vf->myYMode; + mySecondY = vf->mySecondY; +} + +/*! + Updates titles according to curves +*/ +#define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" ) +void Plot2d_ViewFrame::updateTitles() +{ + QIntDictIterator it( myCurves ); + QStringList aXTitles; + QStringList aYTitles; + QStringList aXUnits; + QStringList aYUnits; + QStringList aTables; + int i = 0; + while ( it.current() ) { + // collect titles and units from all curves... + QString xTitle = it.current()->getHorTitle().stripWhiteSpace(); + QString yTitle = it.current()->getVerTitle().stripWhiteSpace(); + QString xUnits = it.current()->getHorUnits().stripWhiteSpace(); + QString yUnits = it.current()->getVerUnits().stripWhiteSpace(); + + aYTitles.append( yTitle ); + if ( aXTitles.find( xTitle ) == aXTitles.end() ) + aXTitles.append( xTitle ); + if ( aXUnits.find( xUnits ) == aXUnits.end() ) + aXUnits.append( xUnits ); + if ( aYUnits.find( yUnits ) == aYUnits.end() ) + aYUnits.append( yUnits ); + + QString aName = it.current()->getTableTitle(); + if( !aName.isEmpty() && aTables.find( aName ) == aTables.end() ) + aTables.append( aName ); + + ++it; + ++i; + } + // ... and update plot 2d view + QString xUnits, yUnits; + if ( aXUnits.count() == 1 && !aXUnits[0].isEmpty() ) + xUnits = BRACKETIZE( aXUnits[0] ); + if ( aYUnits.count() == 1 && !aYUnits[0].isEmpty()) + yUnits = BRACKETIZE( aYUnits[0] ); + QString xTitle, yTitle; + if ( aXTitles.count() == 1 && aXUnits.count() == 1 ) + xTitle = aXTitles[0]; + if ( aYTitles.count() == 1 ) + yTitle = aYTitles[0]; + + if ( !xTitle.isEmpty() && !xUnits.isEmpty() ) + xTitle += " "; + if ( !yTitle.isEmpty() && !yUnits.isEmpty() ) + yTitle += " "; + + setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, true ); + setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, true ); + setTitle( true, aTables.join("; "), MainTitle, true ); +} + +/*! + Outputs content of viewframe to file + \param file - file name + \param format - file format +*/ +bool Plot2d_ViewFrame::print( const QString& file, const QString& format ) const +{ +#ifdef WIN32 + return false; + +#else + bool res = false; + if( myPlot ) + { + QPaintDevice* pd = 0; + if( format=="PS" ) + { + QPrinter* pr = new QPrinter( QPrinter::HighResolution ); + pr->setPageSize( QPrinter::A4 ); + pr->setOutputToFile( true ); + pr->setOutputFileName( file ); + pr->setPrintProgram( "" ); + pd = pr; + } + + if( pd ) + { + myPlot->print( *pd ); + res = true; + delete pd; + } + } + return res; +#endif +} + +/*! + \return string with all visual parameters +*/ +QString Plot2d_ViewFrame::getVisualParameters() +{ + double xmin, xmax, ymin, ymax, y2min, y2max; + getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max ); + QString retStr; + retStr.sprintf( "%d*%d*%d*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", myXMode, + myYMode, mySecondY, xmin, xmax, ymin, ymax, y2min, y2max ); + return retStr; +} + +/*! + Restores all visual parameters from string +*/ +void Plot2d_ViewFrame::setVisualParameters( const QString& parameters ) +{ + QStringList paramsLst = QStringList::split( '*', parameters, true ); + if ( paramsLst.size() == 9 ) { + double xmin, xmax, ymin, ymax, y2min, y2max; + myXMode = paramsLst[0].toInt(); + myYMode = paramsLst[1].toInt(); + mySecondY = (bool)paramsLst[2].toInt(); + xmin = paramsLst[3].toDouble(); + xmax = paramsLst[4].toDouble(); + ymin = paramsLst[5].toDouble(); + ymax = paramsLst[6].toDouble(); + y2min = paramsLst[7].toDouble(); + y2max = paramsLst[8].toDouble(); + + if (mySecondY) + setTitle( myY2TitleEnabled, myY2Title, Y2Title, false ); + setHorScaleMode( myXMode, /*update=*/false ); + setVerScaleMode( myYMode, /*update=*/false ); + + if (mySecondY) { + QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight ); + myYDistance2 = yMap2.d2() - yMap2.d1(); + } + + fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max ); + fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max ); + } +} + +/*! + Incremental zooming operation +*/ +void Plot2d_ViewFrame::incrementalPan( const int incrX, const int incrY ) { + QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); + QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + + myPlot->setAxisScale( QwtPlot::yLeft, + myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-incrY ), + myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-incrY ) ); + myPlot->setAxisScale( QwtPlot::xBottom, + myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-incrX ), + myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-incrX ) ); + if (mySecondY) { + QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight ); + myPlot->setAxisScale( QwtPlot::yRight, + myPlot->invTransform( QwtPlot::yRight, y2Map.i1()-incrY ), + myPlot->invTransform( QwtPlot::yRight, y2Map.i2()-incrY ) ); + } + myPlot->replot(); +} + +/*! + Incremental panning operation +*/ +void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) { + QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); + QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + + myPlot->setAxisScale( QwtPlot::yLeft, + myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), + myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + incrY ) ); + myPlot->setAxisScale( QwtPlot::xBottom, + myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ), + myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - incrX ) ); + if (mySecondY) { + QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight ); + myPlot->setAxisScale( QwtPlot::yRight, + myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ), + myPlot->invTransform( QwtPlot::yRight, y2Map.i2() + incrY ) ); + } + myPlot->replot(); +} + +#define INCREMENT_FOR_OP 10 + +/*! + Performs incremental panning to the left +*/ +void Plot2d_ViewFrame::onPanLeft() +{ + this->incrementalPan( -INCREMENT_FOR_OP, 0 ); +} + +/*! + Performs incremental panning to the right +*/ +void Plot2d_ViewFrame::onPanRight() +{ + this->incrementalPan( INCREMENT_FOR_OP, 0 ); +} + +/*! + Performs incremental panning to the top +*/ +void Plot2d_ViewFrame::onPanUp() +{ + this->incrementalPan( 0, -INCREMENT_FOR_OP ); +} + +/*! + Performs incremental panning to the bottom +*/ +void Plot2d_ViewFrame::onPanDown() +{ + this->incrementalPan( 0, INCREMENT_FOR_OP ); +} + +/*! + Performs incremental zooming in +*/ +void Plot2d_ViewFrame::onZoomIn() +{ + this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP ); +} + +/*! + Performs incremental zooming out +*/ +void Plot2d_ViewFrame::onZoomOut() +{ + this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP ); +} diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h new file mode 100755 index 000000000..6a6aaf171 --- /dev/null +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -0,0 +1,209 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifndef PLOT2D_VIEWFRAME_H +#define PLOT2D_VIEWFRAME_H + +#include "Plot2d_Curve.h" +#include +#include + +class Plot2d_Plot2d; +class Plot2d_Prs; + +typedef QIntDict CurveDict; + +class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget +{ + Q_OBJECT + + enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, + ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId, + LegendId, CurvePointsId, CurveLinesId, CurveSplinesId }; +public: + /* Construction/destruction */ + Plot2d_ViewFrame( QWidget* parent, const QString& title = "" ); + virtual ~Plot2d_ViewFrame(); + + enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis }; + +public: + QWidget* getViewWidget(); + + /* display */ + void DisplayAll(); + void EraseAll(); + void Repaint(); + + void Display( const Plot2d_Prs* ); + void Erase( const Plot2d_Prs*, const bool = false ); + Plot2d_Prs* CreatePrs( const char* entry = 0 ); + + /* operations */ + void updateTitles(); + void setTitle( const QString& title ); + QString getTitle() const { return myTitle; } + void displayCurve( Plot2d_Curve* curve, bool update = false ); + void displayCurves( const curveList& curves, bool update = false ); + void eraseCurve( Plot2d_Curve* curve, bool update = false ); + void eraseCurves( const curveList& curves, bool update = false ); + int getCurves( curveList& clist ); + const CurveDict& getCurves() { return myCurves; } + int hasCurve( Plot2d_Curve* curve ); + bool isVisible( Plot2d_Curve* curve ); + void updateCurve( Plot2d_Curve* curve, bool update = false ); + void updateLegend( const Plot2d_Prs* prs ); + void fitAll(); + void fitArea( const QRect& area ); + void fitData(const int mode, + const double xMin, const double xMax, + const double yMin, const double yMax, + const double y2Min = 0, const double y2Max = 0); + + void getFitRanges(double& xMin, double& xMax, + double& yMin, double& yMax, + double& y2Min, double& y2Max); + + /* view parameters */ + void copyPreferences( Plot2d_ViewFrame* ); + void setCurveType( int curveType, bool update = true ); + int getCurveType() const { return myCurveType; } + void setCurveTitle( int curveKey, const QString& title ); + void showLegend( bool show, bool update = true ); + void setLegendPos( int pos ); + int getLegendPos() const { return myLegendPos; } + void setMarkerSize( const int size, bool update = true ); + int getMarkerSize() const { return myMarkerSize; } + void setBackgroundColor( const QColor& color ); + QColor backgroundColor() const; + void setXGrid( bool xMajorEnabled, const int xMajorMax, + bool xMinorEnabled, const int xMinorMax, bool update = true ); + void setYGrid( bool yMajorEnabled, const int yMajorMax, + bool yMinorEnabled, const int yMinorMax, + bool y2MajorEnabled, const int y2MajorMax, + bool y2MinorEnabled, const int y2MinorMax, bool update = true ); + void setTitle( bool enabled, const QString& title, ObjectType type, bool update = true ); + QString getTitle( ObjectType type ) const; + + void setFont( const QFont& font, ObjectType type, bool update = true ); + void setHorScaleMode( const int mode, bool update = true ); + int getHorScaleMode() const { return myXMode; } + void setVerScaleMode( const int mode, bool update = true ); + int getVerScaleMode() const { return myYMode; } + + bool isModeHorLinear(); + bool isModeVerLinear(); + bool isLegendShow() { return myShowLegend; }; + + // Protection against QwtCurve::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 + bool isXLogEnabled() const; + bool isYLogEnabled() const; + + virtual bool print( const QString& file, const QString& format ) const; + + QString getVisualParameters(); + void setVisualParameters( const QString& parameters ); + + void incrementalPan ( const int incrX, const int incrY ); + void incrementalZoom( const int incrX, const int incrY ); + +protected: + int testOperation( const QMouseEvent& ); + void readPreferences(); + void writePreferences(); + QString getInfo( const QPoint& pnt ); + virtual void wheelEvent( QWheelEvent* ); + +public slots: + void onViewPan(); + void onViewZoom(); + void onViewFitAll(); + void onViewFitArea(); + void onViewGlobalPan(); + void onSettings(); + void onFitData(); + void onChangeBackground(); + + void onPanLeft(); + void onPanRight(); + void onPanUp(); + void onPanDown(); + void onZoomIn(); + void onZoomOut(); + +protected slots: + void plotMousePressed( const QMouseEvent& ); + void plotMouseMoved( const QMouseEvent& ); + void plotMouseReleased( const QMouseEvent& ); + +signals: + void vpModeHorChanged(); + void vpModeVerChanged(); + void vpCurveChanged(); + void contextMenuRequested( QContextMenuEvent *e ); + +protected: + Plot2d_Plot2d* myPlot; + int myOperation; + QPoint myPnt; + CurveDict myCurves; + + int myCurveType; + bool myShowLegend; + int myLegendPos; + int myMarkerSize; + QColor myBackground; + QString myTitle, myXTitle, myYTitle, myY2Title; + bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled; + bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled; + bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled; + int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor; + int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor; + int myXMode, myYMode; + double myXDistance, myYDistance, myYDistance2; + bool mySecondY; +}; + +class Plot2d_Plot2d : public QwtPlot +{ +public: + Plot2d_Plot2d( QWidget* parent ); + + void replot(); + void getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine ); + QwtLegend* getLegend() { +#if QWT_VERSION < 0x040200 + return d_legend; +#else + return legend(); /* mpv: porting to the Qwt 4.2.0 */ +#endif + } + virtual QSize sizeHint() const; + virtual QSizePolicy sizePolicy() const; + virtual QSize minimumSizeHint() const; + +protected: + bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ); + +protected: + QValueList myColors; +}; + +#endif diff --git a/src/Plot2d/Plot2d_ViewManager.cxx b/src/Plot2d/Plot2d_ViewManager.cxx new file mode 100755 index 000000000..7681bd3f2 --- /dev/null +++ b/src/Plot2d/Plot2d_ViewManager.cxx @@ -0,0 +1,85 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#include "Plot2d_ViewManager.h" +#include "Plot2d_ViewModel.h" +#include "Plot2d_ViewWindow.h" + +/*! + Constructor +*/ +Plot2d_ViewManager::Plot2d_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) +: SUIT_ViewManager( study, desk, new Plot2d_Viewer() ) +{ + setTitle( tr( "PLOT2D_VIEW_TITLE" ) ); +} + +/*! + Destructor +*/ +Plot2d_ViewManager::~Plot2d_ViewManager() +{ +} + +/*! + \return corresponding viewer +*/ +Plot2d_Viewer* Plot2d_ViewManager::getPlot2dModel() const +{ + return (Plot2d_Viewer*)myViewModel; +} + +/*! + Adds new view + \param theView - view to be added +*/ +bool Plot2d_ViewManager::insertView( SUIT_ViewWindow* theView ) +{ + bool res = SUIT_ViewManager::insertView( theView ); + if ( res ) + { + Plot2d_ViewWindow* view = (Plot2d_ViewWindow*)theView; + connect( view, SIGNAL( cloneView() ), this, SLOT( onCloneView() ) ); + } + return res; +} + +/*! + Creates new view +*/ +void Plot2d_ViewManager::createView() +{ + createViewWindow(); +} + +/*! + SLOT: called if action "Clone view" is activated, emits signal cloneView() +*/ +void Plot2d_ViewManager::onCloneView() +{ + SUIT_ViewWindow* vw = createViewWindow(); + + Plot2d_ViewWindow *newWnd = 0, *clonedWnd = 0; + if( vw && vw->inherits( "Plot2d_ViewWindow" ) ) + newWnd = ( Plot2d_ViewWindow* )vw; + if( sender() && sender()->inherits( "Plot2d_ViewWindow" ) ) + clonedWnd = ( Plot2d_ViewWindow* )sender(); + + if( newWnd && clonedWnd ) + emit cloneView( clonedWnd->getViewFrame(), newWnd->getViewFrame() ); +} diff --git a/src/Plot2d/Plot2d_ViewManager.h b/src/Plot2d/Plot2d_ViewManager.h new file mode 100755 index 000000000..a26b01cb6 --- /dev/null +++ b/src/Plot2d/Plot2d_ViewManager.h @@ -0,0 +1,52 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifndef PLOT2D_VIEWMANAGER_H +#define PLOT2D_VIEWMANAGER_H + +#include "Plot2d.h" +#include "SUIT_ViewManager.h" + +class SUIT_Desktop; +class Plot2d_Viewer; +class Plot2d_ViewFrame; + +class PLOT2D_EXPORT Plot2d_ViewManager : public SUIT_ViewManager +{ + Q_OBJECT + +public: + Plot2d_ViewManager( SUIT_Study*, SUIT_Desktop* ); + ~Plot2d_ViewManager(); + + Plot2d_Viewer* getPlot2dModel() const; + +protected: + bool insertView(SUIT_ViewWindow* theView); + +public slots: + void createView(); + +protected slots: + void onCloneView(); + +signals: + void cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ); +}; + +#endif diff --git a/src/Plot2d/Plot2d_ViewModel.cxx b/src/Plot2d/Plot2d_ViewModel.cxx new file mode 100755 index 000000000..e689f6ef5 --- /dev/null +++ b/src/Plot2d/Plot2d_ViewModel.cxx @@ -0,0 +1,191 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +// Plot2d_ViewModel.cxx: implementation of the Plot2d_ViewModel class. + +#include "Plot2d_ViewModel.h" +#include "Plot2d_ViewWindow.h" +#include "Plot2d_ViewManager.h" +#include "Plot2d_ViewFrame.h" +#include "Plot2d_Prs.h" + +#include + +/*! + Constructor +*/ +Plot2d_Viewer::Plot2d_Viewer(bool theAutoDel) +:SUIT_ViewModel() +{ + myPrs = 0; + myAutoDel = theAutoDel; +} + +/*! + Destructor +*/ +Plot2d_Viewer::~Plot2d_Viewer() +{ + if (myPrs) + clearPrs(); +} + +/*! + Create new instance of view window on desktop \a theDesktop. + \retval SUIT_ViewWindow* - created view window pointer. +*/ +SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop) +{ + Plot2d_ViewWindow* aPlot2dView = new Plot2d_ViewWindow(theDesktop, this); + if (myPrs) + aPlot2dView->getViewFrame()->Display(myPrs); + return aPlot2dView; +} + +/*! + Adds custom items to popup menu + \param thePopup - popup menu +*/ +void Plot2d_Viewer::contextMenuPopup(QPopupMenu* thePopup) +{ + Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView()); + if ( aView ) + aView->contextMenuPopup(thePopup); + + if (thePopup->count() > 0) thePopup->insertSeparator(); + thePopup->insertItem( tr( "MNU_DUMP_VIEW" ), this, SLOT(onDumpView())); + thePopup->insertItem( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor())); + + if ( aView ) { + if ( !aView->getToolBar()->isVisible() ) { + if (thePopup->count() > 0) thePopup->insertSeparator(); + thePopup->insertItem("Show toolbar", this, SLOT(onShowToolbar())); + } + aView->RefreshDumpImage(); + } +} + +/*! + Sets presentation of viewer + \param thePrs - new presentation +*/ +void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs) +{ + if (myPrs) + clearPrs(); + myPrs = thePrs; + myPrs->setAutoDel(myAutoDel); +} + +/*! + Updates current viewer +*/ +void Plot2d_Viewer::update() +{ + SUIT_ViewManager* aMgr = getViewManager(); + QPtrVector aViews = aMgr->getViews(); + unsigned int aSize = aViews.size(); + for (uint i = 0; i < aSize; i++) { + Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i]; + if (myPrs && aView) + aView->getViewFrame()->Display(myPrs); + } +} + +/*! + Clear viewer presentation +*/ +void Plot2d_Viewer::clearPrs() +{ + SUIT_ViewManager* aMgr = getViewManager(); + QPtrVector aViews = aMgr->getViews(); + unsigned int aSize = aViews.size(); + for (uint i = 0; i < aSize; i++) { + Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i]; + if (myPrs && aView) + aView->getViewFrame()->Erase(myPrs); + } + if (myAutoDel && myPrs) { + delete myPrs; + } + myPrs = 0; +} + +/*! + Sets "auto delete" state of of presentation + \param theDel - new state +*/ +void Plot2d_Viewer::setAutoDel(bool theDel) +{ + myAutoDel = theDel; + if (myPrs) + myPrs->setAutoDel(theDel); +} + +/*! + SLOT: called when action "Change background" is activated +*/ +void Plot2d_Viewer::onChangeBgColor() +{ + Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView()); + if( !aView ) + return; + Plot2d_ViewFrame* aViewFrame = aView->getViewFrame(); + aViewFrame->onChangeBackground(); +} + +/*! + SLOT: called when action "Show toolbar" is activated +*/ +void Plot2d_Viewer::onShowToolbar() { + Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView()); + if ( aView ) + aView->getToolBar()->show(); +} + +/*! + SLOT: called when action "Dump view" is activated +*/ +void Plot2d_Viewer::onDumpView() +{ + Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView()); + if ( aView ) + aView->onDumpView(); +} + +/*! + SLOT: called when action "Clone view" is activated +*/ +void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) +{ +} + +/*! + Sets view manager + \param mgr - new view manager +*/ +void Plot2d_Viewer::setViewManager( SUIT_ViewManager* mgr ) +{ + SUIT_ViewModel::setViewManager( mgr ); + if( mgr && mgr->inherits( "Plot2d_ViewManager" ) ) + { + Plot2d_ViewManager* pmgr = ( Plot2d_ViewManager* )mgr; + connect( pmgr, SIGNAL( cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ), + this, SLOT( onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ) ); + } +} diff --git a/src/Plot2d/Plot2d_ViewModel.h b/src/Plot2d/Plot2d_ViewModel.h new file mode 100755 index 000000000..75445ff9b --- /dev/null +++ b/src/Plot2d/Plot2d_ViewModel.h @@ -0,0 +1,64 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#if !defined(_PLOT2D_VIEWMODEL_H) +#define _PLOT2D_VIEWMODEL_H + +#include "Plot2d.h" +#include "SUIT_ViewModel.h" + +class SUIT_ViewWindow; +class SUIT_Desktop; +class Plot2d_ViewFrame; +class Plot2d_Prs; +class QString; +class QPopupMenu; + +class PLOT2D_EXPORT Plot2d_Viewer: public SUIT_ViewModel +{ + Q_OBJECT + +public: + static QString Type() { return "Plot2d"; } + + Plot2d_Viewer(bool theAutoDel = false); + ~Plot2d_Viewer(); + + virtual void setViewManager( SUIT_ViewManager* ); + virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); + virtual QString getType() const { return Type(); } + virtual void contextMenuPopup(QPopupMenu*); + Plot2d_Prs* getPrs() const { return myPrs; }; + void setPrs(Plot2d_Prs* thePrs); + void update(); + void clearPrs(); + void setAutoDel(bool theDel); + +protected slots: + void onChangeBgColor(); + void onDumpView(); + void onShowToolbar(); + virtual void onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ); + +private: + Plot2d_Prs* myPrs; + bool myAutoDel; +}; + +#endif // !defined(_PLOT2D_VIEWMODEL_H) + diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx new file mode 100755 index 000000000..1fdf78431 --- /dev/null +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -0,0 +1,549 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +// Plot2d_ViewWindow.cxx: implementation of the Plot2d_ViewWindow class. + +#include "Plot2d_ViewWindow.h" +#include "Plot2d_ViewFrame.h" + +#include "SUIT_ViewManager.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" +#include "SUIT_ToolButton.h" +#include "SUIT_Desktop.h" + +#include "QtxAction.h" + +#include +#include +#include +#include + +/*! + Constructor +*/ +Plot2d_ViewWindow::Plot2d_ViewWindow(SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel) +: SUIT_ViewWindow(theDesktop) +{ + myModel = theModel; + + myDumpImage = QImage(); + + myViewFrame = new Plot2d_ViewFrame(this, "plotView"); + setCentralWidget(myViewFrame); + + myToolBar = new QToolBar(this); + myToolBar->setCloseMode(QDockWindow::Undocked); + myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + createActions(); + createToolBar(); + + connect(myViewFrame, SIGNAL(vpModeHorChanged()), this, SLOT(onChangeHorMode())); + connect(myViewFrame, SIGNAL(vpModeVerChanged()), this, SLOT(onChangeVerMode())); + connect(myViewFrame, SIGNAL(vpCurveChanged()), this, SLOT(onChangeCurveMode())); + connect(myViewFrame, SIGNAL(contextMenuRequested( QContextMenuEvent * )), + this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); + +} + +/*! + Destructor +*/ +Plot2d_ViewWindow::~Plot2d_ViewWindow() +{ +} + +/*! + Puts message to status bar + \param theMsg - message text +*/ +void Plot2d_ViewWindow::putInfo(QString theMsg) +{ + QStatusBar* aStatusBar = myDesktop->statusBar(); + aStatusBar->message(theMsg/*, 3000*/); +} + +/*! + Fills popup menu with custom actions + \param popup - popup menu to be filled with +*/ +void Plot2d_ViewWindow::contextMenuPopup( QPopupMenu* thePopup ) +{ + // scaling + QPopupMenu* scalingPopup = new QPopupMenu( thePopup ); + myActionsMap[ PModeXLinearId ]->addTo( scalingPopup ); + myActionsMap[ PModeXLogarithmicId ]->addTo( scalingPopup ); + onChangeHorMode(); + scalingPopup->insertSeparator(); + myActionsMap[ PModeYLinearId ]->addTo( scalingPopup ); + myActionsMap[ PModeYLogarithmicId ]->addTo( scalingPopup ); + thePopup->insertItem( tr( "SCALING_POPUP" ), scalingPopup ); + onChangeVerMode(); + + thePopup->insertItem(tr("TOT_PLOT2D_FITDATA"), myViewFrame, SLOT(onFitData())); + // curve type + QPopupMenu* curTypePopup = new QPopupMenu( thePopup ); + myActionsMap[ CurvPointsId ]->addTo( curTypePopup ); + myActionsMap[ CurvLinesId ]->addTo( curTypePopup ); + myActionsMap[ CurvSplinesId ]->addTo( curTypePopup ); + thePopup->insertItem( tr( "CURVE_TYPE_POPUP" ), curTypePopup ); + + // legend + myActionsMap[ LegendId ]->addTo(thePopup); + // settings + myActionsMap[ CurvSettingsId ]->addTo(thePopup); +} + +/*! + Custom event filter +*/ +bool Plot2d_ViewWindow::eventFilter(QObject* watched, QEvent* e) +{ + if (watched == myViewFrame) { + int aType = e->type(); + switch(aType) { + case QEvent::MouseButtonPress: + emit mousePressed(this, (QMouseEvent*) e); + return true; + + case QEvent::MouseButtonRelease: + emit mouseReleased(this, (QMouseEvent*) e); + return true; + + case QEvent::MouseMove: + emit mouseMoving(this, (QMouseEvent*) e); + return true; + + default: + break; + } + } + return SUIT_ViewWindow::eventFilter(watched, e); +} + +/*! + Create actions for Plot2d view window +*/ +void Plot2d_ViewWindow::createActions() +{ + if ( !myActionsMap.isEmpty() ) + return; + + QtxAction* aAction; + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + + // Dump view + aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ), + tr( "MNU_DUMP_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_DUMP_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView())); + myActionsMap[ DumpId ] = aAction; + + // FitAll + aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ), + tr( "MNU_FITALL" ), 0, this); + aAction->setStatusTip(tr("DSC_FITALL")); + connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll())); + myActionsMap[ FitAllId ] = aAction; + + // FitRect + aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ), + tr( "MNU_FITRECT" ), 0, this); + aAction->setStatusTip(tr("DSC_FITRECT")); + connect(aAction, SIGNAL(activated()), this, SLOT(onFitRect())); + myActionsMap[ FitRectId ] = aAction; + + // Zoom + aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ), + tr( "MNU_ZOOM_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_ZOOM_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onZoom())); + myActionsMap[ ZoomId ] = aAction; + + // Panning + aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ), + tr( "MNU_PAN_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_PAN_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onPanning())); + myActionsMap[ PanId ] = aAction; + + // Global Panning + aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ), + tr( "MNU_GLOBALPAN_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onGlobalPanning())); + myActionsMap[ GlobalPanId ] = aAction; + + // Curve type - points + aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_POINTS"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_POINTS")), + tr("MEN_PLOT2D_CURVES_POINTS"), 0, this); + aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_POINTS")); + connect(aAction, SIGNAL(activated()), this, SLOT(onCurves())); + aAction->setToggleAction(true); + myActionsMap[ CurvPointsId ] = aAction; + + // Curve type - lines + aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_LINES"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_LINES")), + tr("MEN_PLOT2D_CURVES_LINES"), 0, this); + aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_LINES")); + connect(aAction, SIGNAL(activated()), this, SLOT(onCurves())); + aAction->setToggleAction(true); + myActionsMap[ CurvLinesId ] = aAction; + + // Curve type - splines + aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_SPLINES"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_SPLINES")), + tr("MEN_PLOT2D_CURVES_SPLINES"), 0, this); + aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_SPLINES")); + connect(aAction, SIGNAL(activated()), this, SLOT(onCurves())); + aAction->setToggleAction(true); + myActionsMap[ CurvSplinesId ] = aAction; + + // Mode for X (linear or logarithmic) + aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")), + tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this); + aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode())); + myActionsMap[ HorId ] = aAction; + + // Mode for Y (linear or logarithmic) + aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")), + tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this); + aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode())); + myActionsMap[ VerId ] = aAction; + + // Legend + aAction = new QtxAction(tr("TOT_PLOT2D_SHOW_LEGEND"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SHOW_LEGEND")), + tr("MEN_PLOT2D_SHOW_LEGEND"), 0, this); + aAction->setStatusTip(tr("PRP_PLOT2D_SHOW_LEGEND")); + connect(aAction, SIGNAL(activated()), this, SLOT(onLegend())); + aAction->setToggleAction(true); + myActionsMap[ LegendId ] = aAction; + + // Settings + aAction = new QtxAction(tr( "TOT_PLOT2D_SETTINGS"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SETTINGS")), + tr("MEN_PLOT2D_SETTINGS"), 0, this); + aAction->setStatusTip(tr( "PRP_PLOT2D_SETTINGS")); + connect(aAction, SIGNAL(activated()), myViewFrame, SLOT(onSettings())); + myActionsMap[ CurvSettingsId ] = aAction; + + // Clone + aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ), + tr( "MNU_CLONE_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_CLONE_VIEW")); + connect(aAction, SIGNAL(activated()), this, SIGNAL(cloneView())); + myActionsMap[ CloneId ] = aAction; + + /* Popup Actions */ + /* Linear/logarithmic mode */ + // Horizontal axis + aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")), + tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this); + aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR")); + aAction->setToggleAction(true); + myActionsMap[PModeXLinearId] = aAction; + connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode())); + + aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_HOR"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_HOR")), + tr("MEN_PLOT2D_MODE_LOGARITHMIC_HOR"), 0, this); + aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_HOR")); + aAction->setToggleAction(true); + myActionsMap[PModeXLogarithmicId] = aAction; + connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode())); + + // Vertical axis + aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")), + tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this); + aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER")); + aAction->setToggleAction(true); + myActionsMap[PModeYLinearId] = aAction; + connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode())); + + aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_VER"), + aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_VER")), + tr("MEN_PLOT2D_MODE_LOGARITHMIC_VER" ), 0, this); + aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_VER")); + aAction->setToggleAction(true); + myActionsMap[PModeYLogarithmicId] = aAction; + connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode())); + +} + +/*! + Create toolbar for Plot2d view window +*/ +void Plot2d_ViewWindow::createToolBar() +{ + myActionsMap[DumpId]->addTo(myToolBar); + + SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar); + aScaleBtn->AddAction(myActionsMap[FitAllId]); + aScaleBtn->AddAction(myActionsMap[FitRectId]); + aScaleBtn->AddAction(myActionsMap[ZoomId]); + + SUIT_ToolButton* aPanBtn = new SUIT_ToolButton(myToolBar); + aPanBtn->AddAction(myActionsMap[PanId]); + aPanBtn->AddAction(myActionsMap[GlobalPanId]); + + myCurveBtn = new SUIT_ToolButton(myToolBar); + myCurveBtn->AddAction(myActionsMap[CurvPointsId]); + myCurveBtn->AddAction(myActionsMap[CurvLinesId]); + myCurveBtn->AddAction(myActionsMap[CurvSplinesId]); + myActionsMap[CurvLinesId]->setOn(true); + onChangeCurveMode(); + + myActionsMap[HorId]->addTo(myToolBar); + onChangeHorMode(); + myActionsMap[VerId]->addTo(myToolBar); + onChangeVerMode(); + + myActionsMap[LegendId]->addTo(myToolBar); + myActionsMap[CurvSettingsId]->addTo(myToolBar); + myActionsMap[CloneId]->addTo(myToolBar); + onChangeLegendMode(); +} + +/*! + SLOT: called if scale mode for horizontal axis is changed +*/ +void Plot2d_ViewWindow::onChangeHorMode() +{ + bool aLinear = myViewFrame->isModeHorLinear(); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + + myActionsMap[PModeXLinearId]->setOn( aLinear ); + myActionsMap[PModeXLogarithmicId]->setOn( !aLinear ); + + QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" : + "ICON_PLOT2D_MODE_LINEAR_HOR" ) ); + myActionsMap[HorId]->setIconSet( pix ); + myActionsMap[HorId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" : + "TOT_PLOT2D_MODE_LINEAR_HOR" ) ); + myActionsMap[HorId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" : + "PRP_PLOT2D_MODE_LINEAR_HOR" ) ); + + myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() ); +} + +/*! + SLOT: called if scale mode for vertical axis is changed +*/ +void Plot2d_ViewWindow::onChangeVerMode() +{ + bool aLinear = myViewFrame->isModeVerLinear(); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + + myActionsMap[PModeYLinearId]->setOn( aLinear ); + myActionsMap[PModeYLogarithmicId]->setOn( !aLinear ); + + QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_VER" : + "ICON_PLOT2D_MODE_LINEAR_VER" ) ); + myActionsMap[VerId]->setIconSet( pix ); + myActionsMap[VerId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_VER" : + "TOT_PLOT2D_MODE_LINEAR_VER" ) ); + myActionsMap[VerId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_VER" : + "PRP_PLOT2D_MODE_LINEAR_VER" ) ); + + myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() ); +} + +/*! + SLOT: called if curve type is changed +*/ +void Plot2d_ViewWindow::onChangeCurveMode() +{ + int aCurveType = myViewFrame->getCurveType(); + myCurveBtn->SetItem(aCurveType); + + myActionsMap[CurvPointsId]->setOn(aCurveType == 0); + myActionsMap[CurvLinesId]->setOn(aCurveType == 1); + myActionsMap[CurvSplinesId]->setOn(aCurveType == 2); +} + +/*! + SLOT: called if legend mode is changed +*/ +void Plot2d_ViewWindow::onChangeLegendMode() +{ + myActionsMap[ LegendId ]->setOn(myViewFrame->isLegendShow()); +} + +/*! + SLOT: called if action "Fit all" is activated +*/ +void Plot2d_ViewWindow::onFitAll() +{ + myViewFrame->onViewFitAll(); +} + +/*! + SLOT: called if action "Fit rect" is activated +*/ +void Plot2d_ViewWindow::onFitRect() +{ + myViewFrame->onViewFitArea(); +} + +/*! + SLOT: called if action "Zoom" is activated +*/ +void Plot2d_ViewWindow::onZoom() +{ + myViewFrame->onViewZoom(); +} + +/*! + SLOT: called if action "Panning" is activated +*/ +void Plot2d_ViewWindow::onPanning() +{ + myViewFrame->onViewPan(); +} + +/*! + SLOT: called if action "Global panning" is activated +*/ +void Plot2d_ViewWindow::onGlobalPanning() +{ + myViewFrame->onViewGlobalPan(); +} + +/*! + SLOT: called if action of scale mode for horizontal axis changing is activated +*/ +void Plot2d_ViewWindow::onViewHorMode() +{ + if (myViewFrame->isModeHorLinear()) + myViewFrame->setHorScaleMode(1); + else + myViewFrame->setHorScaleMode(0); +} + +/*! + SLOT: called if action of scale mode for vertical axis changing is activated +*/ +void Plot2d_ViewWindow::onViewVerMode() +{ + if (myViewFrame->isModeVerLinear()) + myViewFrame->setVerScaleMode(1); + else + myViewFrame->setVerScaleMode(0); +} + +/*! + SLOT: called if action "Show legend" is activated +*/ +void Plot2d_ViewWindow::onLegend() +{ + myViewFrame->showLegend(!myViewFrame->isLegendShow()); + onChangeLegendMode(); +} + +/*! + SLOT: called if action "Change curve type" is activated +*/ +void Plot2d_ViewWindow::onCurves() +{ + QtxAction* aSender = (QtxAction*) sender(); + if(aSender == myActionsMap[CurvPointsId]) + myViewFrame->setCurveType(0); + else if(aSender == myActionsMap[CurvLinesId]) + myViewFrame->setCurveType(1); + else if(aSender == myActionsMap[CurvSplinesId]) + myViewFrame->setCurveType(2); +} + +/*! + SLOT: called if action "Dump view" is activated +*/ +void Plot2d_ViewWindow::onDumpView() +{ + qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ), TRUE ) ); + SUIT_ViewWindow::onDumpView(); +} + +/*! + \return QImage, containing all scene rendering in window +*/ +QImage Plot2d_ViewWindow::dumpView() +{ + if ( getToolBar()->hasMouse() || myDumpImage.isNull() ) + { + QPixmap px = QPixmap::grabWindow( myViewFrame->winId() ); + return px.convertToImage(); + } + + return myDumpImage; +} + +/*! + Saves scene rendering in window to file + \param fileName - name of file + \param format - string contains name of format (for example, "BMP"(default) or "JPEG", "JPG") +*/ +bool Plot2d_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format ) +{ + bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false; + if( !res ) + res = SUIT_ViewWindow::dumpViewToFormat( img, fileName, format ); + + return res; +} + +/*! + \return filter of image files +*/ +QString Plot2d_ViewWindow::filter() const +{ + return SUIT_ViewWindow::filter() + ";;" + tr( "POSTSCRIPT_FILES" ); +} + +/*! + \return the visual parameters of this view as a formated string + */ +QString Plot2d_ViewWindow::getVisualParameters() +{ + return myViewFrame->getVisualParameters(); +} + +/*! + The method restors visual parameters of this view from a formated string +*/ +void Plot2d_ViewWindow::setVisualParameters( const QString& parameters ) +{ + myViewFrame->setVisualParameters( parameters ); +} + +/*! + \refresh QImage, containing all scene rendering in window +*/ +void Plot2d_ViewWindow::RefreshDumpImage() +{ + QPixmap px = QPixmap::grabWindow( myViewFrame->winId() ); + myDumpImage = px.convertToImage(); +} diff --git a/src/Plot2d/Plot2d_ViewWindow.h b/src/Plot2d/Plot2d_ViewWindow.h new file mode 100755 index 000000000..aa1d4dd62 --- /dev/null +++ b/src/Plot2d/Plot2d_ViewWindow.h @@ -0,0 +1,109 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifndef PLOT2D_VIEWWINDOW_H +#define PLOT2D_VIEWWINDOW_H + +#include "Plot2d.h" +#include + +#include + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +class SUIT_Desktop; +class Plot2d_Viewer; +class Plot2d_ViewFrame; +class QtxAction; +class SUIT_ToolButton; + +class PLOT2D_EXPORT Plot2d_ViewWindow : public SUIT_ViewWindow +{ + Q_OBJECT + +public: + Plot2d_ViewWindow( SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel ); + virtual ~Plot2d_ViewWindow(); + + Plot2d_Viewer* getModel() { return myModel; } + void putInfo(QString theMsg); + Plot2d_ViewFrame* getViewFrame() { return myViewFrame; }; + QToolBar* getToolBar() { return myToolBar; }; + void contextMenuPopup( QPopupMenu* thePopup ); + + virtual QString getVisualParameters(); + virtual void setVisualParameters( const QString& parameters ); + + virtual void RefreshDumpImage(); + +protected: + virtual QImage dumpView(); + virtual QString filter() const; + virtual bool dumpViewToFormat( const QImage&, const QString& fileName, const QString& format ); + +private: + bool eventFilter(QObject* watched, QEvent* e); + + void createActions(); + void createToolBar(); + +public slots: + void onChangeHorMode(); + void onChangeVerMode(); + void onChangeCurveMode(); + void onChangeLegendMode(); + + void onFitAll(); + void onFitRect(); + void onZoom(); + void onPanning(); + void onGlobalPanning(); + void onViewHorMode(); + void onViewVerMode(); + void onLegend(); + void onCurves(); + + void onDumpView(); + +signals: + void cloneView(); + +protected: + enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, HorId, + VerId, LegendId, CurvPointsId, CurvLinesId, CurvSplinesId, CurvSettingsId, CloneId, + PModeXLinearId, PModeXLogarithmicId, PModeYLinearId, PModeYLogarithmicId }; + typedef QMap ActionsMap; + ActionsMap myActionsMap; + +private: + Plot2d_Viewer* myModel; + Plot2d_ViewFrame* myViewFrame; + QToolBar* myToolBar; + + SUIT_ToolButton* myCurveBtn; + + QImage myDumpImage; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif