From 323590a5f9d83a3a228405d660ea3217c1627d2a Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 4 Mar 2008 06:45:19 +0000 Subject: [PATCH] Expantion of kind of objects are showed in view. The most part of curve was moved from Plot2d_Curve class to Plot2d_Object and Plot2d_Curve class inherits Plot2d_Object. --- src/Plot2d/Plot2d_Curve.cxx | 425 +++++++++-------------- src/Plot2d/Plot2d_Curve.h | 83 +---- src/Plot2d/Plot2d_Prs.cxx | 32 +- src/Plot2d/Plot2d_Prs.h | 20 +- src/Plot2d/Plot2d_ToolTip.cxx | 9 +- src/Plot2d/Plot2d_ToolTip.h | 4 +- src/Plot2d/Plot2d_ViewFrame.cxx | 565 +++++++++++++++---------------- src/Plot2d/Plot2d_ViewFrame.h | 59 ++-- src/Plot2d/Plot2d_ViewWindow.cxx | 10 +- 9 files changed, 527 insertions(+), 680 deletions(-) diff --git a/src/Plot2d/Plot2d_Curve.cxx b/src/Plot2d/Plot2d_Curve.cxx index 0116e249a..38b7a358a 100755 --- a/src/Plot2d/Plot2d_Curve.cxx +++ b/src/Plot2d/Plot2d_Curve.cxx @@ -21,28 +21,20 @@ // #include "Plot2d_Curve.h" -#include + +#define DEFAULT_LINE_WIDTH 0 // (default) line width +#define DEFAULT_MARKER_SIZE 9 // default marker size /*! Constructor */ Plot2d_Curve::Plot2d_Curve() -: myHorTitle( "" ), myVerTitle( "" ), - myHorUnits( "" ), myVerUnits( "" ), - myName( "" ), - myAutoAssign( true ), - myColor( 0,0,0 ), +: Plot2d_Object(), + myColor( 0,0,0 ), + myMarkerSize( 0 ), myMarker( Plot2d::Circle ), myLine( Plot2d::Solid ), - myLineWidth( 0 ), - myYAxis( QwtPlot::yLeft ) -{ -} - -/*! - Destructor -*/ -Plot2d_Curve::~Plot2d_Curve() + myLineWidth( 0 ) { } @@ -50,18 +42,12 @@ Plot2d_Curve::~Plot2d_Curve() Copy constructor. Makes deep copy of data. */ Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve ) +: Plot2d_Object( curve ) { - myAutoAssign = curve.isAutoAssign(); - myHorTitle = curve.getHorTitle(); - myVerTitle = curve.getVerTitle(); - myHorUnits = curve.getHorUnits(); - myVerUnits = curve.getVerUnits(); - myName = curve.getName(); myColor = curve.getColor(); myMarker = curve.getMarker(); myLine = curve.getLine(); myLineWidth = curve.getLineWidth(); - myPoints = curve.getPointList(); } /*! @@ -83,219 +69,59 @@ Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve ) 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; -} - -/*! - Sets curve's name +/** + * */ -void Plot2d_Curve::setName( const QString& theName ) -{ - myName = theName; -} -/*! - Gets curve's name - */ -QString Plot2d_Curve::getName() const -{ - return myName; -} - -/*! - Adds one point for curve. -*/ -void Plot2d_Curve::addPoint(double theX, double theY, const QString& txt ) +int Plot2d_Curve::rtti() { - Plot2d_Point aPoint; - aPoint.x = theX; - aPoint.y = theY; - aPoint.text = txt; - myPoints.append(aPoint); + return QwtPlotItem::Rtti_PlotCurve; } /*! - Insert one point for curve on some position. + Displays curve in the given plot. */ -void Plot2d_Curve::insertPoint(int thePos, double theX, double theY, const QString& txt) +QwtPlotItem* Plot2d_Curve::createPlotItem() { - Plot2d_Point aPoint; - aPoint.x = theX; - aPoint.y = theY; - aPoint.text = txt; - - QList::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); + QwtPlotCurve* aCurve = new QwtPlotCurve(); + updatePlotItem( aCurve ); + return aCurve; } -/*! - Delete one point for curve on some position. -*/ -void Plot2d_Curve::deletePoint(int thePos) -{ - if ( thePos >= 0 && thePos < myPoints.count() ) - myPoints.removeAt( thePos ); -} - -/*! - Remove all points for curve. -*/ -void Plot2d_Curve::clearAllPoints() +/** + * Auto fill parameters of object by plot view + */ +void Plot2d_Curve::autoFill( const QwtPlot* thePlot ) { - myPoints.clear(); -} + QwtSymbol::Style typeMarker; + QColor color; + Qt::PenStyle typeLine; + getNextMarker( thePlot, typeMarker, color, typeLine ); -/*! - Gets curve's data : abscissas of points -*/ -pointList Plot2d_Curve::getPointList() const -{ - return myPoints; + setColor( color ); + setLine( Plot2d::qwt2plotLine( typeLine ), DEFAULT_LINE_WIDTH ); + setMarker( Plot2d::qwt2plotMarker( typeMarker ) ); } /*! - 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() : *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 + * Updates curve fields + */ +void Plot2d_Curve::updatePlotItem( QwtPlotItem* theItem ) { - int aNPoints = nbPoints(); - double* aY = new double[aNPoints]; - for (int i = 0; i < aNPoints; i++) { - aY[i] = myPoints[i].y; - } - return aY; -} + if ( theItem->rtti() != rtti() ) + return; + QwtPlotCurve* aCurve = dynamic_cast( theItem ); + if ( !aCurve ) + return; -/*! - Gets curve's data : number of points -*/ -int Plot2d_Curve::nbPoints() const -{ - return myPoints.count(); -} + Qt::PenStyle ps = Plot2d::plot2qwtLine( getLine() ); + QwtSymbol::Style ms = Plot2d::plot2qwtMarker( getMarker() ); -/*! - 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; + aCurve->setPen( QPen( getColor(), getLineWidth(), ps ) ); + aCurve->setSymbol( QwtSymbol( ms, QBrush( getColor() ), + QPen( getColor() ), + QSize( myMarkerSize, myMarkerSize ) ) ); + aCurve->setData( horData(), verData(), nbPoints() ); + aCurve->setTitle( !getName().isEmpty() ? getName() : getVerTitle() ); } /*! @@ -315,6 +141,14 @@ QColor Plot2d_Curve::getColor() const return myColor; } +/*! + Sets new marker size +*/ +void Plot2d_Curve::setMarkerSize( const int theSize ) +{ + myMarkerSize = theSize; +} + /*! Sets curve's marker ( and resets AutoAssign flag ) */ @@ -331,7 +165,6 @@ Plot2d::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. @@ -364,73 +197,117 @@ int Plot2d_Curve::getLineWidth() const } /*! - Sets curve's y axis + Gets new unique marker for item if possible */ -void Plot2d_Curve::setYAxis(QwtPlot::Axis theYAxis) +const int MAX_ATTEMPTS = 10; +void Plot2d_Curve::getNextMarker( const QwtPlot* thePlot, QwtSymbol::Style& typeMarker, + QColor& color, Qt::PenStyle& typeLine ) { - if(theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight) - myYAxis = theYAxis; -} + 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 ) -/*! - Gets curve's y axis -*/ -QwtPlot::Axis Plot2d_Curve::getYAxis() const -{ - return myYAxis; -} + typeMarker = ( QwtSymbol::Style )aMarker; + color = QColor( aRed, aGreen, aBlue ); + typeLine = ( Qt::PenStyle )aLine; -/*! - Gets curve's minimal abscissa -*/ -double Plot2d_Curve::getMinX() const -{ - QList::const_iterator aIt; - double aMinX = 1e150; - //int aCurrent = 0; - for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { - if ( (*aIt).x < aMinX ) - aMinX = (*aIt).x; + cnt++; + if ( cnt == MAX_ATTEMPTS ) + bOk = true; + else + bOk = !existMarker( thePlot, typeMarker, color, typeLine ); } - return aMinX; -} - -/*! - Gets curve's minimal ordinate -*/ -double Plot2d_Curve::getMinY() const -{ - QList::const_iterator aIt; - double aMinY = 1e150; - //int aCurrent = 0; - for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { - if ( (*aIt).y < aMinY ) - aMinY = (*aIt).y; +/* + 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 ); } - 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() ) + 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( thePlot, typeMarker, color, typeLine ) ) return; - myPoints[ind].text = txt; + 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 text assigned to point - \param ind -- index of point + Checks if marker belongs to any enitity */ -QString Plot2d_Curve::text( const int ind ) const +bool Plot2d_Curve::existMarker( const QwtPlot* thePlot, const QwtSymbol::Style typeMarker, + const QColor& color, const Qt::PenStyle typeLine ) { - if( ind<0 || ind>=myPoints.count() ) - return QString(); - else - return myPoints[ind].text; + QColor aColor = thePlot->palette().color( QPalette::Background ); + if ( closeColors( color, aColor ) ) + return true; + QwtPlotItemList anItems = thePlot->itemList(); + QwtPlotItemIterator anIt = anItems.begin(), aLast = anItems.end(); + QwtPlotItem* anItem; + for( ; anIt != aLast; anIt++ ) { + anItem = *anIt; + if( anItem && anItem->rtti() == rtti() ) { + QwtPlotCurve* crv = dynamic_cast( anItem ); + if ( crv ) { + QwtSymbol::Style aStyle = crv->symbol().style(); + QColor aColor = crv->pen().color(); + Qt::PenStyle aLine = crv->pen().style(); + if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine ) + return true; + } + } + } + return false; } diff --git a/src/Plot2d/Plot2d_Curve.h b/src/Plot2d/Plot2d_Curve.h index e73f5a192..f8d975061 100755 --- a/src/Plot2d/Plot2d_Curve.h +++ b/src/Plot2d/Plot2d_Curve.h @@ -24,67 +24,29 @@ #define PLOT2D_CURVE_H #include "Plot2d.h" +#include -#include -#include +#include -class QColor; - -typedef struct -{ - double x; - double y; - QString text; -} Plot2d_Point; - -typedef QList pointList; - -class PLOT2D_EXPORT Plot2d_Curve +class PLOT2D_EXPORT Plot2d_Curve : public Plot2d_Object { public: Plot2d_Curve(); - virtual ~Plot2d_Curve(); Plot2d_Curve( const Plot2d_Curve& ); - Plot2d_Curve& operator= ( const Plot2d_Curve& ); - - virtual QString getTableTitle() const; - - void setHorTitle( const QString& ); - QString getHorTitle() const; - void setVerTitle( const QString& ); - QString getVerTitle() const; - - void setHorUnits( const QString& ); - QString getHorUnits() const; - void setVerUnits( const QString& ); - QString getVerUnits() const; - - void setName( const QString& ); - QString getName() const; - void addPoint( double, double, const QString& = QString() ); - void insertPoint( int, double, double, const QString& = QString() ); - void deletePoint( int ); - void clearAllPoints(); - pointList getPointList() const; - - void setData( const double*, const double*, - long, 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; + virtual ~Plot2d_Curve() {}; + Plot2d_Curve& operator= ( const Plot2d_Curve& ); - void setAutoAssign( bool ); - bool isAutoAssign() const; + virtual int rtti(); + virtual QwtPlotItem* createPlotItem(); + virtual void autoFill( const QwtPlot* ); + virtual void updatePlotItem( QwtPlotItem* ); void setColor( const QColor& ); QColor getColor() const; + void setMarkerSize( const int ); + void setMarker( Plot2d::MarkerType ); Plot2d::MarkerType getMarker() const; @@ -92,29 +54,18 @@ public: Plot2d::LineType getLine() const; int getLineWidth() const; - void setYAxis( QwtPlot::Axis ); - 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: + void getNextMarker( const QwtPlot*, QwtSymbol::Style&, + QColor&, Qt::PenStyle& ); + bool existMarker( const QwtPlot*, const QwtSymbol::Style, + const QColor&, const Qt::PenStyle ); protected: - bool myAutoAssign; - QString myHorTitle; - QString myVerTitle; - QString myHorUnits; - QString myVerUnits; - QString myName; QColor myColor; + int myMarkerSize; Plot2d::MarkerType myMarker; Plot2d::LineType myLine; int myLineWidth; - QwtPlot::Axis myYAxis; - - pointList myPoints; }; typedef QList curveList; diff --git a/src/Plot2d/Plot2d_Prs.cxx b/src/Plot2d/Plot2d_Prs.cxx index 8c9d24109..70df4769d 100755 --- a/src/Plot2d/Plot2d_Prs.cxx +++ b/src/Plot2d/Plot2d_Prs.cxx @@ -40,7 +40,7 @@ Plot2d_Prs::Plot2d_Prs( bool theDelete ) /*! Standard constructor */ -Plot2d_Prs::Plot2d_Prs( const Plot2d_Curve* obj, bool theDelete ) +Plot2d_Prs::Plot2d_Prs( const Plot2d_Object* obj, bool theDelete ) : mySecondY( false), myIsAutoDel( theDelete ) { AddObject( obj ); @@ -52,7 +52,7 @@ Plot2d_Prs::Plot2d_Prs( const Plot2d_Curve* obj, bool theDelete ) Plot2d_Prs::~Plot2d_Prs() { if ( myIsAutoDel ) - qDeleteAll( myCurves ); + qDeleteAll( myObjects ); } /*! @@ -60,15 +60,35 @@ Plot2d_Prs::~Plot2d_Prs() */ curveList Plot2d_Prs::getCurves() const { - return myCurves; + curveList aCurves; + + QList::const_iterator it = myObjects.begin(); + Plot2d_Object* anObj; + Plot2d_Curve* aCurve; + for ( ; it != myObjects.end(); ++it ) { + anObj = *it; + if ( anObj && anObj->rtti() == QwtPlotItem::Rtti_PlotCurve ) { + aCurve = dynamic_cast( anObj ); + aCurves.append( aCurve ); + } + } + return aCurves; +} + +/*! + Get objects list +*/ +objectList Plot2d_Prs::getObjects() const +{ + return myObjects; } /*! Add curve */ -void Plot2d_Prs::AddObject( const Plot2d_Curve* obj ) +void Plot2d_Prs::AddObject( const Plot2d_Object* obj ) { - myCurves.append((Plot2d_Curve*)obj); + myObjects.append((Plot2d_Object*)obj); if (obj->getYAxis() == QwtPlot::yRight) mySecondY = true; @@ -79,7 +99,7 @@ void Plot2d_Prs::AddObject( const Plot2d_Curve* obj ) */ bool Plot2d_Prs::IsNull() const { - return myCurves.isEmpty(); + return myObjects.isEmpty(); } /*! diff --git a/src/Plot2d/Plot2d_Prs.h b/src/Plot2d/Plot2d_Prs.h index a4fba43b0..c64c2a6fa 100755 --- a/src/Plot2d/Plot2d_Prs.h +++ b/src/Plot2d/Plot2d_Prs.h @@ -21,27 +21,29 @@ #include "Plot2d.h" #include "Plot2d_Curve.h" +#include "Plot2d_Object.h" class PLOT2D_EXPORT Plot2d_Prs { public: Plot2d_Prs( bool theDelete = false ); - Plot2d_Prs( const Plot2d_Curve* obj, bool theDelete = false ); + Plot2d_Prs( const Plot2d_Object* obj, bool theDelete = false ); ~Plot2d_Prs(); - curveList getCurves() const; - void AddObject( const Plot2d_Curve* obj ); + curveList getCurves() const; // obsolete + objectList getObjects() const; + void AddObject( const Plot2d_Object* obj ); - bool IsNull() const; + bool IsNull() const; - bool isSecondY() const; + bool isSecondY() const; - void setAutoDel(bool theDel); + void setAutoDel(bool theDel); protected: - curveList myCurves; - bool mySecondY; - bool myIsAutoDel; + objectList myObjects; + bool mySecondY; + bool myIsAutoDel; }; #endif diff --git a/src/Plot2d/Plot2d_ToolTip.cxx b/src/Plot2d/Plot2d_ToolTip.cxx index bf94e310f..ff55ac62b 100644 --- a/src/Plot2d/Plot2d_ToolTip.cxx +++ b/src/Plot2d/Plot2d_ToolTip.cxx @@ -33,10 +33,9 @@ const int maxDist = 3, tip_margin = 10; -Plot2d_ToolTip::Plot2d_ToolTip( Plot2d_ViewFrame* frame, Plot2d_Plot2d* plot ) -: QtxToolTip( plot->canvas() ), - myFrame( frame ), - myPlot( plot ) +Plot2d_ToolTip::Plot2d_ToolTip( Plot2d_ViewFrame* frame ) +: QtxToolTip( frame->getPlotCanvas() ), + myFrame( frame ) { connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ), this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) ); @@ -51,7 +50,7 @@ void Plot2d_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect int pInd; double dist; - Plot2d_Curve* c = myPlot->getClosestCurve( p, dist, pInd ); + Plot2d_Curve* c = myFrame->getClosestCurve( p, dist, pInd ); if( !c || dist>maxDist ) return; diff --git a/src/Plot2d/Plot2d_ToolTip.h b/src/Plot2d/Plot2d_ToolTip.h index c2f2d785f..dc36c834d 100644 --- a/src/Plot2d/Plot2d_ToolTip.h +++ b/src/Plot2d/Plot2d_ToolTip.h @@ -26,14 +26,13 @@ #include class Plot2d_ViewFrame; -class Plot2d_Plot2d; class PLOT2D_EXPORT Plot2d_ToolTip : public QtxToolTip { Q_OBJECT public: - Plot2d_ToolTip( Plot2d_ViewFrame*, Plot2d_Plot2d* ); + Plot2d_ToolTip( Plot2d_ViewFrame* ); virtual ~Plot2d_ToolTip(); virtual bool eventFilter( QObject*, QEvent* ); @@ -43,7 +42,6 @@ public slots: private: Plot2d_ViewFrame* myFrame; - Plot2d_Plot2d* myPlot; }; #endif diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index c829164d6..fef319331 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -61,7 +61,7 @@ #include -#define DEFAULT_LINE_WIDTH 0 // (default) line width +//#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 @@ -153,8 +153,8 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) myCurveType( 1 ), myShowLegend( true ), myLegendPos( 1 ), myMarkerSize( DEFAULT_MARKER_SIZE ), - myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ), myBackground( Qt::white ), + myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ), myTitleEnabled( true ), myXTitleEnabled( true ), myYTitleEnabled( true ), myY2TitleEnabled (true), myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ), @@ -167,7 +167,7 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) /* Plot 2d View */ QVBoxLayout* aLayout = new QVBoxLayout( this ); myPlot = new Plot2d_Plot2d( this ); - new Plot2d_ToolTip( this, myPlot ); + new Plot2d_ToolTip( this ); aLayout->addWidget( myPlot ); @@ -229,10 +229,10 @@ QWidget* Plot2d_ViewFrame::getViewWidget() */ void Plot2d_ViewFrame::DisplayAll() { - QList clist; - getCurves( clist ); - for ( int i = 0; i < (int)clist.count(); i++ ) { - updateCurve( clist.at( i ), false ); + QList olist; + getObjects( olist ); + for ( int i = 0; i < (int)olist.count(); i++ ) { + updateObject( olist.at( i ), false ); } myPlot->replot(); } @@ -242,7 +242,7 @@ void Plot2d_ViewFrame::DisplayAll() void Plot2d_ViewFrame::EraseAll() { myPlot->clear(); - myPlot->getCurves().clear(); + myObjects.clear(); myPlot->replot(); } /*! @@ -270,8 +270,8 @@ void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs ) } // display all curves from presentation - curveList aCurves = prs->getCurves(); - displayCurves( aCurves ); + objectList anObjects = prs->getObjects(); + displayObjects( anObjects ); setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true ); setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor, myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true ); @@ -286,8 +286,8 @@ void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool ) return; // erase all curves from presentation - curveList aCurves = prs->getCurves(); - eraseCurves( aCurves ); + objectList anObjects = prs->getObjects(); + eraseObjects( anObjects ); } bool Plot2d_ViewFrame::eventFilter( QObject* watched, QEvent* e ) @@ -531,53 +531,129 @@ QString Plot2d_ViewFrame::getInfo( const QPoint& pnt ) */ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) { - if ( !curve ) - return; + displayObject( curve, update ); +} - // san -- Protection against QwtCurve bug in Qwt 0.4.x: +/*! + Adds curves into view +*/ +void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update ) +{ + objectList olist; + QList::const_iterator it = curves.begin(); + for ( ; it != curves.end(); it++ ) + olist.append( *it ); + + displayObjects( olist, update ); +} + +/*! + Erases curve +*/ +void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update ) +{ + eraseObject( curve, update ); +} + +/*! + Erases curves +*/ +void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update ) +{ + objectList olist; + QList::const_iterator it = curves.begin(); + for ( ; it != curves.end(); it++ ) + olist.append( *it ); + + eraseObjects( olist, update ); +} + +/*! + Updates curves attributes +*/ +void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update ) +{ + updateObject( curve, update ); +} + +/*! + Gets lsit of displayed curves +*/ +int Plot2d_ViewFrame::getCurves( curveList& clist ) +{ + clist.clear(); + + CurveDict aCurves = getCurves(); + CurveDict::iterator it = aCurves.begin(); + for ( ; it != aCurves.end(); it++ ) + clist.append( it.value() ); + return clist.count(); +} + +/*! + Gets lsit of displayed curves +*/ +int Plot2d_ViewFrame::getObjects( objectList& olist ) +{ + olist.clear(); + + ObjectDict::iterator it = myObjects.begin(); + for ( ; it != myObjects.end(); it++ ) + olist.append( it.value() ); + return olist.count(); +} + +CurveDict Plot2d_ViewFrame::getCurves() +{ + ObjectDict::iterator it = myObjects.begin(), aLast = myObjects.end(); + CurveDict aCurves; + QwtPlotItem* anItem; + for ( ; it != aLast; it++ ) { + anItem = it.key(); + if ( anItem && anItem->rtti() == QwtPlotItem::Rtti_PlotCurve ) { + QwtPlotCurve* aPCurve = dynamic_cast( anItem ); + Plot2d_Curve* aCurve = dynamic_cast( it.value() ); + if ( aPCurve && aCurve ) + aCurves.insert( aPCurve, aCurve ); + } + } + return aCurves; +} + +/*! + Adds object into view +*/ +void Plot2d_ViewFrame::displayObject( Plot2d_Object* object, bool update ) +{ + if ( !object ) + return; + // san -- Protection against QwtObject 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. ) + if ( myXMode && object->getMinX() <= 0. ) setHorScaleMode( 0, false ); - if ( myYMode && curve->getMinY() <= 0. ) + if ( myYMode && object->getMinY() <= 0. ) setVerScaleMode( 0, false ); - if ( hasPlotCurve( curve ) ) { - updateCurve( curve, update ); + if ( hasPlotObject( object ) ) { + updateObject( object, update ); } else { - QwtPlotCurve* aPCurve = new QwtPlotCurve( !curve->getName().isEmpty() ? - curve->getName() : curve->getVerTitle() ); - aPCurve->attach( myPlot ); + if ( object->isAutoAssign() ) + object->autoFill( myPlot ); + QwtPlotItem* anItem = object->createPlotItem(); + anItem->attach( myPlot ); + myObjects.insert( anItem, object ); //myPlot->setCurveYAxis(curveKey, curve->getYAxis()); - myPlot->getCurves().insert( aPCurve, curve ); - if ( curve->isAutoAssign() ) { - QwtSymbol::Style typeMarker; - QColor color; - Qt::PenStyle typeLine; - - myPlot->getNextMarker( typeMarker, color, typeLine ); - aPCurve->setPen( QPen( color, DEFAULT_LINE_WIDTH, typeLine ) ); - aPCurve->setSymbol( QwtSymbol( typeMarker, - QBrush( color ), - QPen( color ), - QSize( myMarkerSize, myMarkerSize ) ) ); - curve->setColor( color ); - curve->setLine( Plot2d::qwt2plotLine( typeLine ) ); - curve->setMarker( Plot2d::qwt2plotMarker( typeMarker ) ); - } - else { - Qt::PenStyle ps = Plot2d::plot2qwtLine( curve->getLine() ); - QwtSymbol::Style ms = Plot2d::plot2qwtMarker( curve->getMarker() ); - aPCurve->setPen( QPen( curve->getColor(), curve->getLineWidth(), ps ) ); - aPCurve->setSymbol( QwtSymbol( ms, - QBrush( curve->getColor() ), - QPen( curve->getColor() ), - QSize( myMarkerSize, myMarkerSize ) ) ); + if ( object->rtti() == QwtPlotItem::Rtti_PlotCurve ) { + Plot2d_Curve* aCurve = dynamic_cast( object ); + if ( aCurve ) { + aCurve->setMarkerSize( myMarkerSize ); + aCurve->updatePlotItem( anItem ); + setCurveType( getPlotCurve( aCurve ), myCurveType ); + } } - setCurveType( aPCurve, myCurveType ); - aPCurve->setData( curve->horData(), curve->verData(), curve->nbPoints() ); } updateTitles(); if ( update ) @@ -585,16 +661,16 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) } /*! - Adds curves into view + Adds objects into view */ -void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update ) +void Plot2d_ViewFrame::displayObjects( const objectList& objects, bool update ) { //myPlot->setUpdatesEnabled( false ); // call this function deprecate update of legend - QList::const_iterator it = curves.begin(); - Plot2d_Curve* aCurve; - for (; it != curves.end(); ++it ) { - aCurve = *it; - displayCurve( aCurve, false ); + QList::const_iterator it = objects.begin(); + Plot2d_Object* anObject; + for (; it != objects.end(); ++it ) { + anObject = *it; + displayObject( anObject, false ); } fitAll(); //myPlot->setUpdatesEnabled( true ); @@ -604,17 +680,17 @@ void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update ) } /*! - Erases curve + Erases object */ -void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update ) +void Plot2d_ViewFrame::eraseObject( Plot2d_Object* object, bool update ) { - if ( !curve ) + if ( !object ) return; - if ( hasPlotCurve( curve ) ) { - QwtPlotCurve* aPCurve = getPlotCurve( curve ); - aPCurve->hide(); - aPCurve->detach(); - myPlot->getCurves().remove( aPCurve ); + if ( hasPlotObject( object ) ) { + QwtPlotItem* anObject = getPlotObject( object ); + anObject->hide(); + anObject->detach(); + myObjects.remove( anObject ); updateTitles(); if ( update ) myPlot->replot(); @@ -622,15 +698,15 @@ void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update ) } /*! - Erases curves + Erases objects */ -void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update ) +void Plot2d_ViewFrame::eraseObjects( const objectList& objects, bool update ) { - QList::const_iterator it = curves.begin(); - Plot2d_Curve* aCurve; - for (; it != curves.end(); ++it ) { - aCurve = *it; - eraseCurve( aCurve, false ); + QList::const_iterator it = objects.begin(); + Plot2d_Object* anObject; + for (; it != objects.end(); ++it ) { + anObject = *it; + eraseObject( anObject, false ); } // fitAll(); if ( update ) @@ -638,58 +714,39 @@ void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update ) } /*! - Updates curves attributes + Updates objects attributes */ -void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update ) +void Plot2d_ViewFrame::updateObject( Plot2d_Object* object, bool update ) { - if ( !curve ) + if ( !object ) return; - if ( hasPlotCurve( curve ) ) { - QwtPlotCurve* aPCurve = getPlotCurve( curve ); - if ( !curve->isAutoAssign() ) { - Qt::PenStyle ps = Plot2d::plot2qwtLine( curve->getLine() ); - QwtSymbol::Style ms = Plot2d::plot2qwtMarker( curve->getMarker() ); - aPCurve->setPen ( QPen( curve->getColor(), curve->getLineWidth(), ps ) ); - aPCurve->setSymbol( QwtSymbol( ms, - QBrush( curve->getColor() ), - QPen( curve->getColor() ), - QSize( myMarkerSize, myMarkerSize ) ) ); - aPCurve->setData( curve->horData(), curve->verData(), curve->nbPoints() ); - } - aPCurve->setTitle( !curve->getName().isEmpty() ? curve->getName() : - curve->getVerTitle() ); - aPCurve->setVisible( true ); + if ( hasPlotObject( object ) ) { + QwtPlotItem* anItem = getPlotObject( object ); + if ( !anItem ) + return; + object->updatePlotItem( anItem ); + anItem->setVisible( true ); if ( update ) myPlot->replot(); } } /*! - Gets lsit of displayed curves + Returns true if the curve is visible */ -int Plot2d_ViewFrame::getCurves( curveList& clist ) -{ - clist.clear(); - - CurveDict::iterator it = myPlot->getCurves().begin(); - for ( ; it != myPlot->getCurves().end(); it++ ) - clist.append( it.value() ); - return clist.count(); -} - -const CurveDict& Plot2d_ViewFrame::getCurves() +bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve ) { - return myPlot->getCurves(); + return isVisible( dynamic_cast( curve ) ); } /*! Returns true if the curve is visible */ -bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve ) +bool Plot2d_ViewFrame::isVisible( Plot2d_Object* object ) { - if(curve) { - if ( hasPlotCurve( curve ) ) { - return getPlotCurve( curve )->isVisible(); + if ( object ) { + if ( hasPlotObject( object ) ) { + return getPlotObject( object )->isVisible(); } } return false; @@ -702,15 +759,14 @@ void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs ) { if ( !prs || prs->IsNull() ) return; - curveList aCurves = prs->getCurves(); - - QList::iterator it = aCurves.begin(); - Plot2d_Curve* aCurve; - for (; it != aCurves.end(); ++it ) { - aCurve = *it; - if ( hasPlotCurve( aCurve ) ) - getPlotCurve( aCurve )->setTitle( !aCurve->getName().isEmpty() ? - aCurve->getName() : aCurve->getVerTitle() ); + + ObjectDict::iterator it = myObjects.begin(); + Plot2d_Object* anObj; + for (; it != myObjects.end(); ++it ) { + anObj = *it; + if ( hasPlotObject( anObj ) ) + getPlotObject( anObj )->setTitle( !anObj->getName().isEmpty() ? + anObj->getName() : anObj->getVerTitle() ); } } @@ -866,7 +922,7 @@ void Plot2d_ViewFrame::onSettings() QwtSymbol::Style typeMarker; QColor color; Qt::PenStyle typeLine; - myPlot->getNextMarker( typeMarker, color, typeLine ); + ///myPlot->getNextMarker( typeMarker, color, typeLine ); if ( mars.contains(typeMarker) ) mars[ typeMarker ] = mars[ typeMarker ]+1; else @@ -998,8 +1054,9 @@ void Plot2d_ViewFrame::onChangeBackground() void Plot2d_ViewFrame::setCurveType( int curveType, bool update ) { myCurveType = curveType; - CurveDict::iterator it = myPlot->getCurves().begin(); - for ( ; it != myPlot->getCurves().end(); it++ ) { + CurveDict aCurves = getCurves(); + CurveDict::iterator it = aCurves.begin(); + for ( ; it != aCurves.end(); it++ ) { QwtPlotCurve* crv = it.key(); if ( crv ) setCurveType( crv, myCurveType ); @@ -1015,9 +1072,19 @@ void Plot2d_ViewFrame::setCurveType( int curveType, bool update ) \param title - new title */ void Plot2d_ViewFrame::setCurveTitle( Plot2d_Curve* curve, const QString& title ) +{ + setObjectTitle( curve, title ); +} + +/*! + Sets object title + \param object - object id + \param title - new title +*/ +void Plot2d_ViewFrame::setObjectTitle( Plot2d_Object* object, const QString& title ) { - if ( curve && hasPlotCurve( curve ) ) - getPlotCurve( curve )->setTitle( title ); + if ( object && hasPlotObject( object ) ) + getPlotObject( object )->setTitle( title ); } /*! @@ -1072,8 +1139,9 @@ void Plot2d_ViewFrame::setMarkerSize( const int size, bool update ) if ( myMarkerSize != size ) { myMarkerSize = size; - CurveDict::iterator it = myPlot->getCurves().begin(); - for ( ; it != myPlot->getCurves().end(); it++ ) { + CurveDict aCurves = getCurves(); + CurveDict::iterator it = aCurves.begin(); + for ( ; it != aCurves.end(); it++ ) { QwtPlotCurve* crv = it.key(); if ( crv ) { @@ -1219,6 +1287,8 @@ void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title, myY2Title = title; myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString() ); break; + default: + break; } if ( update ) myPlot->replot(); @@ -1238,6 +1308,8 @@ QString Plot2d_ViewFrame::getTitle( ObjectType type ) const title = myYTitle; break; case Y2Title: title = myY2Title; break; + default: + break; } return title; } @@ -1441,8 +1513,9 @@ void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event) */ QwtPlotCurve* Plot2d_ViewFrame::getPlotCurve( Plot2d_Curve* curve ) { - CurveDict::iterator it = myPlot->getCurves().begin(); - for ( ; it != myPlot->getCurves().end(); it++ ) { + CurveDict aCurves = getCurves(); + CurveDict::iterator it = aCurves.begin(); + for ( ; it != aCurves.end(); it++ ) { if ( it.value() == curve ) return it.key(); } @@ -1453,14 +1526,40 @@ QwtPlotCurve* Plot2d_ViewFrame::getPlotCurve( Plot2d_Curve* curve ) */ bool Plot2d_ViewFrame::hasPlotCurve( Plot2d_Curve* curve ) { - CurveDict::iterator it = myPlot->getCurves().begin(); - for ( ; it != myPlot->getCurves().end(); it++ ) { + CurveDict aCurves = getCurves(); + CurveDict::iterator it = aCurves.begin(); + for ( ; it != aCurves.end(); it++ ) { if ( it.value() == curve ) return true; } return false; } +/*! + Returns qwt plot curve if it is existed in map of curves and 0 otherwise +*/ +QwtPlotItem* Plot2d_ViewFrame::getPlotObject( Plot2d_Object* object ) +{ + ObjectDict::iterator it = myObjects.begin(); + for ( ; it != myObjects.end(); it++ ) { + if ( it.value() == object ) + return it.key(); + } + return 0; +} +/*! + Returns true if qwt plot curve is existed in map of curves and false otherwise +*/ +bool Plot2d_ViewFrame::hasPlotObject( Plot2d_Object* object ) +{ + ObjectDict::iterator it = myObjects.begin(); + for ( ; it != myObjects.end(); it++ ) { + if ( it.value() == object ) + return true; + } + return false; +} + /*! Sets curve type */ @@ -1551,8 +1650,8 @@ void Plot2d_ViewFrame::onViewGlobalPan() bool Plot2d_ViewFrame::isXLogEnabled() const { bool allPositive = true; - CurveDict::const_iterator it = myPlot->getCurves().begin(); - for ( ; allPositive && it != myPlot->getCurves().end(); it++ ) + ObjectDict::const_iterator it = myObjects.begin(); + for ( ; allPositive && it != myObjects.end(); it++ ) allPositive = ( it.value()->getMinX() > 0. ); return allPositive; } @@ -1563,8 +1662,8 @@ bool Plot2d_ViewFrame::isXLogEnabled() const bool Plot2d_ViewFrame::isYLogEnabled() const { bool allPositive = true; - CurveDict::const_iterator it = myPlot->getCurves().begin(); - for ( ; allPositive && it != myPlot->getCurves().end(); it++ ) + ObjectDict::const_iterator it = myObjects.begin(); + for ( ; allPositive && it != myObjects.end(); it++ ) allPositive = ( it.value()->getMinY() > 0. ); return allPositive; } @@ -1641,106 +1740,6 @@ void Plot2d_Plot2d::replot() 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 */ @@ -1780,48 +1779,6 @@ void Plot2d_Plot2d::setPickerMousePattern( int button, int state ) myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1, button, state ); } -/*! - return closest curve if it exist, else 0 -*/ -Plot2d_Curve* Plot2d_Plot2d::getClosestCurve( QPoint p, double& distance, int& index ) -{ - CurveDict::iterator it = getCurves().begin(); - QwtPlotCurve* aCurve; - for ( ; it != getCurves().end(); it++ ) { - aCurve = it.key(); - if ( !aCurve ) - continue; - index = aCurve->closestPoint( p, &distance ); - if ( index > -1 ) - return it.value(); - } - return 0; -} - -/*! - Checks if marker belongs to any enitity -*/ -bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ) -{ - QColor aColor = palette().color( QPalette::Background ); - if ( closeColors( color, aColor ) ) - return true; - - CurveDict::iterator it = myCurves.begin(); - for ( ; it != myCurves.end(); it++ ) { - QwtPlotCurve* crv = it.key(); - 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; -} - /*! Sets the flag saying that QwtPlot geometry has been fully defined. */ @@ -1886,8 +1843,7 @@ void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf ) #define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" ) void Plot2d_ViewFrame::updateTitles() { - CurveDict::iterator it = myPlot->getCurves().begin(); - //QIntDictIterator it( myCurves ); + ObjectDict::iterator it = myObjects.begin(); QStringList aXTitles; QStringList aYTitles; QStringList aXUnits; @@ -1895,14 +1851,14 @@ void Plot2d_ViewFrame::updateTitles() QStringList aTables; int i = 0; - Plot2d_Curve* aCurve; - for ( ; it != myPlot->getCurves().end(); it++ ) { + Plot2d_Object* anObject; + for ( ; it != myObjects.end(); it++ ) { // collect titles and units from all curves... - aCurve = it.value(); - QString xTitle = aCurve->getHorTitle().trimmed(); - QString yTitle = aCurve->getVerTitle().trimmed(); - QString xUnits = aCurve->getHorUnits().trimmed(); - QString yUnits = aCurve->getVerUnits().trimmed(); + anObject = it.value(); + QString xTitle = anObject->getHorTitle().trimmed(); + QString yTitle = anObject->getVerTitle().trimmed(); + QString xUnits = anObject->getHorUnits().trimmed(); + QString yUnits = anObject->getVerUnits().trimmed(); aYTitles.append( yTitle ); if ( !aXTitles.contains( xTitle ) ) @@ -1912,7 +1868,7 @@ void Plot2d_ViewFrame::updateTitles() if ( !aYUnits.contains( yUnits ) ) aYUnits.append( yUnits ); - QString aName = aCurve->getTableTitle(); + QString aName = anObject->getTableTitle(); if( !aName.isEmpty() && !aTables.contains( aName ) ) aTables.append( aName ); ++i; @@ -1974,6 +1930,15 @@ bool Plot2d_ViewFrame::print( const QString& file, const QString& format ) const #endif } +/** + * Print Plot2d window + */ +void Plot2d_ViewFrame::printPlot( QPainter* p, const QRect& rect, + const QwtPlotPrintFilter& filter ) const +{ + myPlot->print( p, rect, filter ); +} + /*! \return string with all visual parameters */ @@ -2061,6 +2026,34 @@ void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) { myPlot->replot(); } +/** + * + */ +QwtPlotCanvas* Plot2d_ViewFrame::getPlotCanvas() +{ + return myPlot ? myPlot->canvas() : 0; +} + +/*! + return closest curve if it exist, else 0 +*/ +Plot2d_Curve* Plot2d_ViewFrame::getClosestCurve( QPoint p, double& distance, + int& index ) +{ + CurveDict aCurves = getCurves(); + CurveDict::iterator it = aCurves.begin(); + QwtPlotCurve* aCurve; + for ( ; it != aCurves.end(); it++ ) { + aCurve = it.key(); + if ( !aCurve ) + continue; + index = aCurve->closestPoint( p, &distance ); + if ( index > -1 ) + return it.value(); + } + return 0; +} + #define INCREMENT_FOR_OP 10 /*! @@ -2121,13 +2114,3 @@ void Plot2d_ViewFrame::customEvent( QEvent* ce ) if ( ce->type() == FITALL_EVENT ) fitAll(); } - -/*! - Gets plot -*/ -Plot2d_Plot2d* Plot2d_ViewFrame::getPlot() const -{ - return myPlot; -} - - diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 755592506..0ca3e1f77 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -32,7 +32,8 @@ class QwtPlotCurve; class QwtPlotGrid; class QwtPlotZoomer; -typedef QMultiHash CurveDict; +typedef QMultiHash CurveDict; // obsolete +typedef QMultiHash ObjectDict; class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget { @@ -66,14 +67,29 @@ public: 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(); - bool isVisible( Plot2d_Curve* curve ); - void updateCurve( Plot2d_Curve* curve, bool update = false ); + + // obsolete operation on curves + void displayCurve( Plot2d_Curve* curve, bool update = false ); // obsolete + void displayCurves( const curveList& curves, bool update = false ); // obsolete + void eraseCurve( Plot2d_Curve* curve, bool update = false ); // obsolete + void eraseCurves( const curveList& curves, bool update = false ); // obsolete + int getCurves( curveList& clist ); // obsolete + CurveDict getCurves(); // osolete + bool isVisible( Plot2d_Curve* curve ); // obsolete + void updateCurve( Plot2d_Curve* curve, bool update = false ); // osolete + + // operations on objects + void displayObject( Plot2d_Object* curve, bool update = false ); + void displayObjects( const objectList& objects, bool update = false ); + void eraseObject( Plot2d_Object* object, bool update = false ); + void eraseObjects( const objectList& objects, bool update = false ); + + int getObjects( objectList& clist ); + bool isVisible( Plot2d_Object* curve ); + void updateObject( Plot2d_Object* object, bool update = false ); + + + // operations on view frame void updateLegend( const Plot2d_Prs* prs ); void fitAll(); void fitArea( const QRect& area ); @@ -90,7 +106,8 @@ public: void copyPreferences( Plot2d_ViewFrame* ); void setCurveType( int curveType, bool update = true ); int getCurveType() const { return myCurveType; } - void setCurveTitle( Plot2d_Curve* curve, const QString& title ); + void setCurveTitle( Plot2d_Curve* curve, const QString& title ); // obsolete + void setObjectTitle( Plot2d_Object* curve, const QString& title ); void showLegend( bool show, bool update = true ); void setLegendPos( int pos ); int getLegendPos() const { return myLegendPos; } @@ -124,6 +141,8 @@ public: bool isYLogEnabled() const; virtual bool print( const QString& file, const QString& format ) const; + void printPlot( QPainter* p, const QRect& rect, + const QwtPlotPrintFilter& = QwtPlotPrintFilter() ) const; QString getVisualParameters(); void setVisualParameters( const QString& parameters ); @@ -131,14 +150,22 @@ public: void incrementalPan ( const int incrX, const int incrY ); void incrementalZoom( const int incrX, const int incrY ); + QwtPlotCanvas* getPlotCanvas(); + Plot2d_Curve* getClosestCurve( QPoint p, double& distance, int& index ); + protected: int testOperation( const QMouseEvent& ); void readPreferences(); void writePreferences(); QString getInfo( const QPoint& pnt ); virtual void wheelEvent( QWheelEvent* ); - QwtPlotCurve* getPlotCurve( Plot2d_Curve* curve ); - bool hasPlotCurve( Plot2d_Curve* curve ); + // obsolete methods on curves + QwtPlotCurve* getPlotCurve( Plot2d_Curve* curve ); // obsolete + bool hasPlotCurve( Plot2d_Curve* curve ); // obsolete + // methods on objects + QwtPlotItem* getPlotObject( Plot2d_Object* object ); + bool hasPlotObject( Plot2d_Object* object ); + void setCurveType( QwtPlotCurve* curve, int curveType ); public slots: @@ -189,6 +216,7 @@ protected: int myXMode, myYMode; double myXDistance, myYDistance, myYDistance2; bool mySecondY; + ObjectDict myObjects; }; class Plot2d_Plot2d : public QwtPlot @@ -200,7 +228,6 @@ public: void setLogScale( int axisId, bool log10 ); void replot(); - void getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine ); QwtLegend* getLegend() { #if QWT_VERSION < 0x040200 return d_legend; @@ -216,17 +243,11 @@ public: bool polished() const { return myIsPolished; } QwtPlotGrid* grid() { return myGrid; }; - CurveDict& getCurves() { return myCurves; } - Plot2d_Curve* getClosestCurve( QPoint p, double& distance, int& index ); public slots: virtual void polish(); protected: - bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ); - -protected: - CurveDict myCurves; QwtPlotGrid* myGrid; QList myColors; bool myIsPolished; diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx index ed6ec0cdf..82e49719e 100755 --- a/src/Plot2d/Plot2d_ViewWindow.cxx +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -635,10 +635,6 @@ void Plot2d_ViewWindow::onPrintView() if ( !myViewFrame ) return; - Plot2d_Plot2d* aPlot = myViewFrame->getPlot(); - if ( !aPlot ) - return; - // stored settings for further starts static QString aPrinterName; static int aColorMode = -1; @@ -715,7 +711,7 @@ void Plot2d_ViewWindow::onPrintView() // Iterate through, store temporary their parameters and assign // parameters proper for printing - CurveDict& aCurveDict = aPlot->getCurves(); + CurveDict aCurveDict = myViewFrame->getCurves(); CurveDict::iterator it; for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ ) { @@ -744,13 +740,13 @@ void Plot2d_ViewWindow::onPrintView() } } - aPlot->print( &aPainter, QRect( 0, 0, W, H ) ); + myViewFrame->printPlot( &aPainter, QRect( 0, 0, W, H ) ); aPainter.end(); // restore old pens and symbols if ( needColorCorrection && !aCurvToPen.isEmpty() ) { - CurveDict& aCurveDict = aPlot->getCurves(); + CurveDict aCurveDict = myViewFrame->getCurves(); CurveDict::iterator it; for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ ) { -- 2.39.2