From f8418d6cb7ab14ad2563bf2aa8fa70b4451c9173 Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 15 Aug 2013 07:27:51 +0000 Subject: [PATCH] Presentation for polyline object. --- src/HYDROGUI/CMakeLists.txt | 4 + src/HYDROGUI/HYDROGUI_Displayer.cxx | 5 + src/HYDROGUI/HYDROGUI_Prs.cxx | 31 +++++ src/HYDROGUI/HYDROGUI_Prs.h | 10 ++ src/HYDROGUI/HYDROGUI_PrsImage.cxx | 29 +---- src/HYDROGUI/HYDROGUI_PrsImage.h | 2 - src/HYDROGUI/HYDROGUI_PrsPolyline.cxx | 119 ++++++++++++++++++++ src/HYDROGUI/HYDROGUI_PrsPolyline.h | 63 +++++++++++ src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx | 61 ++++++++++ src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h | 56 +++++++++ 10 files changed, 354 insertions(+), 26 deletions(-) create mode 100644 src/HYDROGUI/HYDROGUI_PrsPolyline.cxx create mode 100644 src/HYDROGUI/HYDROGUI_PrsPolyline.h create mode 100644 src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx create mode 100644 src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index c4cd4f02..f5f3459a 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -23,6 +23,8 @@ set(PROJECT_HEADERS HYDROGUI_PrsImage.h HYDROGUI_PrsImageDriver.h HYDROGUI_PrsImageFrame.h + HYDROGUI_PrsPolyline.h + HYDROGUI_PrsPolylineDriver.h HYDROGUI_ShowHideOp.h HYDROGUI_Tool.h HYDROGUI_TwoImagesDlg.h @@ -53,6 +55,8 @@ set(PROJECT_SOURCES HYDROGUI_PrsImage.cxx HYDROGUI_PrsImageDriver.cxx HYDROGUI_PrsImageFrame.cxx + HYDROGUI_PrsPolyline.cxx + HYDROGUI_PrsPolylineDriver.cxx HYDROGUI_ShowHideOp.cxx HYDROGUI_Tool.cxx HYDROGUI_TwoImagesDlg.cxx diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index 2947e10a..a99292ae 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -26,6 +26,7 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_Prs.h" #include "HYDROGUI_PrsImageDriver.h" +#include "HYDROGUI_PrsPolylineDriver.h" #include "HYDROGUI_Tool.h" #include @@ -240,6 +241,10 @@ HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Object aDriver = new HYDROGUI_PrsImageDriver(); myPrsDriversMap[ aKind ] = aDriver; break; + case KIND_POLYLINE: + aDriver = new HYDROGUI_PrsPolylineDriver(); + myPrsDriversMap[ aKind ] = aDriver; + break; default: break; } diff --git a/src/HYDROGUI/HYDROGUI_Prs.cxx b/src/HYDROGUI/HYDROGUI_Prs.cxx index f0a9f554..1ed451e3 100644 --- a/src/HYDROGUI/HYDROGUI_Prs.cxx +++ b/src/HYDROGUI/HYDROGUI_Prs.cxx @@ -22,6 +22,10 @@ #include "HYDROGUI_Prs.h" +#include + +#include + //======================================================================= // name : HYDROGUI_Prs // Purpose : Constructor @@ -31,6 +35,7 @@ HYDROGUI_Prs::HYDROGUI_Prs( const Handle(HYDROData_Object)& theObject ) myObject( theObject ), myIsToUpdate( false ) { + myHighlightCursor = new QCursor( Qt::PointingHandCursor ); } //======================================================================= @@ -39,4 +44,30 @@ HYDROGUI_Prs::HYDROGUI_Prs( const Handle(HYDROData_Object)& theObject ) //======================================================================= HYDROGUI_Prs::~HYDROGUI_Prs() { + if( myHighlightCursor ) + { + delete myHighlightCursor; + myHighlightCursor = 0; + } +} + +//================================================================ +// Function : addTo +// Purpose : +//================================================================ +void HYDROGUI_Prs::addTo( GraphicsView_ViewPort* theViewPort ) +{ + GraphicsView_Object::addTo( theViewPort ); + + double aZValue = 0; + GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() ); + while( anIter.hasNext() ) + { + if( HYDROGUI_Prs* aPrs = dynamic_cast( anIter.next() ) ) + { + double aZValueRef = aPrs->zValue(); + aZValue = qMax( aZValue, aZValueRef ); + } + } + setZValue( aZValue + 1 ); } diff --git a/src/HYDROGUI/HYDROGUI_Prs.h b/src/HYDROGUI/HYDROGUI_Prs.h index 8c39308d..6219f48b 100644 --- a/src/HYDROGUI/HYDROGUI_Prs.h +++ b/src/HYDROGUI/HYDROGUI_Prs.h @@ -43,9 +43,19 @@ public: bool getIsToUpdate() const { return myIsToUpdate; } void setIsToUpdate( bool theState ) { myIsToUpdate = theState; } +public: + // from GraphicsView_Object + virtual void addTo( GraphicsView_ViewPort* theViewPort ); + +protected: + QCursor* getHighlightCursor() const { return myHighlightCursor; } + private: Handle(HYDROData_Object) myObject; bool myIsToUpdate; + +private: + QCursor* myHighlightCursor; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_PrsImage.cxx b/src/HYDROGUI/HYDROGUI_PrsImage.cxx index d92d0e37..4e8471e1 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImage.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsImage.cxx @@ -39,7 +39,6 @@ HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject myIsTransformationPointPreview( false ), myTransformationPointMode( None ) { - myHighlightCursor = new QCursor( Qt::PointingHandCursor ); myTransformationPointCursor = new QCursor( Qt::CrossCursor ); } @@ -49,12 +48,6 @@ HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject //======================================================================= HYDROGUI_PrsImage::~HYDROGUI_PrsImage() { - if( myHighlightCursor ) - { - delete myHighlightCursor; - myHighlightCursor = 0; - } - if( myTransformationPointCursor ) { delete myTransformationPointCursor; @@ -155,20 +148,8 @@ void HYDROGUI_PrsImage::compute() //================================================================ void HYDROGUI_PrsImage::addTo( GraphicsView_ViewPort* theViewPort ) { - GraphicsView_Object::addTo( theViewPort ); + HYDROGUI_Prs::addTo( theViewPort ); theViewPort->addItem( myPrsImageFrame ); - - double aZValue = 0; - GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() ); - while( anIter.hasNext() ) - { - if( HYDROGUI_PrsImage* aPrs = dynamic_cast( anIter.next() ) ) - { - double aZValueRef = aPrs->zValue(); - aZValue = qMax( aZValue, aZValueRef ); - } - } - setZValue( aZValue + 1 ); } //================================================================ @@ -177,7 +158,7 @@ void HYDROGUI_PrsImage::addTo( GraphicsView_ViewPort* theViewPort ) //================================================================ void HYDROGUI_PrsImage::removeFrom( GraphicsView_ViewPort* theViewPort ) { - GraphicsView_Object::removeFrom( theViewPort ); + HYDROGUI_Prs::removeFrom( theViewPort ); theViewPort->removeItem( myPrsImageFrame ); } @@ -220,7 +201,7 @@ bool HYDROGUI_PrsImage::select( double theX, double theY, const QRectF& theRect return true; } - bool anIsSelected = GraphicsView_Object::select( theX, theY, theRect ); + bool anIsSelected = HYDROGUI_Prs::select( theX, theY, theRect ); myPrsImageFrame->updateVisibility(); return anIsSelected; } @@ -231,7 +212,7 @@ bool HYDROGUI_PrsImage::select( double theX, double theY, const QRectF& theRect //================================================================ void HYDROGUI_PrsImage::unselect() { - GraphicsView_Object::unselect(); + HYDROGUI_Prs::unselect(); myPrsImageFrame->updateVisibility(); } @@ -241,7 +222,7 @@ void HYDROGUI_PrsImage::unselect() //================================================================ void HYDROGUI_PrsImage::setSelected( bool theState ) { - GraphicsView_Object::setSelected( theState ); + HYDROGUI_Prs::setSelected( theState ); myPrsImageFrame->updateVisibility(); } diff --git a/src/HYDROGUI/HYDROGUI_PrsImage.h b/src/HYDROGUI/HYDROGUI_PrsImage.h index 651c787c..c09ad692 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImage.h +++ b/src/HYDROGUI/HYDROGUI_PrsImage.h @@ -83,7 +83,6 @@ protected: void computeTransformationPoints(); protected: - QCursor* getHighlightCursor() const { return myHighlightCursor; } QCursor* getTransformationPointCursor() const { return myTransformationPointCursor; } protected: @@ -97,7 +96,6 @@ protected: TransformationPointMap myTransformationPointMap; private: - QCursor* myHighlightCursor; QCursor* myTransformationPointCursor; }; diff --git a/src/HYDROGUI/HYDROGUI_PrsPolyline.cxx b/src/HYDROGUI/HYDROGUI_PrsPolyline.cxx new file mode 100644 index 00000000..66005576 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PrsPolyline.cxx @@ -0,0 +1,119 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_PrsPolyline.h" + +//======================================================================= +// name : HYDROGUI_PrsPolyline +// Purpose : Constructor +//======================================================================= +HYDROGUI_PrsPolyline::HYDROGUI_PrsPolyline( const Handle(HYDROData_Object)& theObject ) +: HYDROGUI_Prs( theObject ), + myPolylineItem( 0 ) +{ +} + +//======================================================================= +// name : HYDROGUI_PrsPolyline +// Purpose : Destructor +//======================================================================= +HYDROGUI_PrsPolyline::~HYDROGUI_PrsPolyline() +{ +} + +//================================================================ +// Function : setPath +// Purpose : +//================================================================ +void HYDROGUI_PrsPolyline::setPath( const QPainterPath& thePath ) +{ + myPath = thePath; +} + +//================================================================ +// Function : getPath +// Purpose : +//================================================================ +QPainterPath HYDROGUI_PrsPolyline::getPath() const +{ + return myPath; +} + +//================================================================ +// Function : boundingRect +// Purpose : +//================================================================ +QRectF HYDROGUI_PrsPolyline::boundingRect() const +{ + return myPolylineItem->boundingRect(); +} + +//================================================================ +// Function : compute +// Purpose : +//================================================================ +void HYDROGUI_PrsPolyline::compute() +{ + if( !myPolylineItem ) + { + myPolylineItem = new QGraphicsPathItem( this ); + addToGroup( myPolylineItem ); + } + myPolylineItem->setPath( myPath ); +} + +//================================================================ +// Function : checkHighlight +// Purpose : +//================================================================ +bool HYDROGUI_PrsPolyline::checkHighlight( double theX, double theY, QCursor& theCursor ) const +{ + // to do + return false; +} + +//================================================================ +// Function : select +// Purpose : +//================================================================ +bool HYDROGUI_PrsPolyline::select( double theX, double theY, const QRectF& theRect ) +{ + return GraphicsView_Object::select( theX, theY, theRect ); +} + +//================================================================ +// Function : unselect +// Purpose : +//================================================================ +void HYDROGUI_PrsPolyline::unselect() +{ + GraphicsView_Object::unselect(); +} + +//================================================================ +// Function : setSelected +// Purpose : +//================================================================ +void HYDROGUI_PrsPolyline::setSelected( bool theState ) +{ + GraphicsView_Object::setSelected( theState ); +} diff --git a/src/HYDROGUI/HYDROGUI_PrsPolyline.h b/src/HYDROGUI/HYDROGUI_PrsPolyline.h new file mode 100644 index 00000000..47dc3b23 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PrsPolyline.h @@ -0,0 +1,63 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_PRSPOLYLINE_H +#define HYDROGUI_PRSPOLYLINE_H + +#include "HYDROGUI_Prs.h" + +/* + Class : HYDROGUI_PrsPolyline + Description : Presentation for polyline object +*/ +class HYDROGUI_PrsPolyline : public HYDROGUI_Prs +{ +public: + HYDROGUI_PrsPolyline( const Handle(HYDROData_Object)& theObject ); + virtual ~HYDROGUI_PrsPolyline(); + +public: + void setPath( const QPainterPath& thePath ); + QPainterPath getPath() const; + +public: + // from QGraphicsItem + virtual QRectF boundingRect() const; + + // from GraphicsView_Object + virtual void compute(); + + virtual bool isMovable() const { return false; } + + virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const; + + virtual bool select( double theX, double theY, const QRectF& theRect ); + virtual void unselect(); + virtual void setSelected( bool theState ); + +protected: + QGraphicsPathItem* myPolylineItem; + + QPainterPath myPath; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx b/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx new file mode 100644 index 00000000..da1481e8 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.cxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_PrsPolylineDriver.h" + +#include "HYDROGUI_PrsPolyline.h" + +#include + +HYDROGUI_PrsPolylineDriver::HYDROGUI_PrsPolylineDriver() +:HYDROGUI_PrsDriver() +{ +} + +HYDROGUI_PrsPolylineDriver::~HYDROGUI_PrsPolylineDriver() +{ +} + +bool HYDROGUI_PrsPolylineDriver::Update( const Handle(HYDROData_Object)& theObj, + HYDROGUI_Prs*& thePrs ) +{ + HYDROGUI_PrsDriver::Update( theObj, thePrs ); + + if( theObj.IsNull() ) + return false; + + Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( theObj ); + if( aPolyline.IsNull() ) + return false; + + if( !thePrs ) + thePrs = new HYDROGUI_PrsPolyline( theObj ); + + HYDROGUI_PrsPolyline* aPrsPolyline = (HYDROGUI_PrsPolyline*)thePrs; + + aPrsPolyline->setName( aPolyline->GetName() ); + aPrsPolyline->setPath( aPolyline->painterPathLinear() ); + + aPrsPolyline->compute(); + + return true; +} diff --git a/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h b/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h new file mode 100644 index 00000000..de6dde19 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PrsPolylineDriver.h @@ -0,0 +1,56 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_PRSPOLYLINEDRIVER_H +#define HYDROGUI_PRSPOLYLINEDRIVER_H + +#include + +/** + * \class HYDROGUI_PrsPolylineDriver + * \brief Presentation driver for polyline objects. + */ +class HYDROGUI_PrsPolylineDriver : public HYDROGUI_PrsDriver +{ +public: + /** + * \brief Constructor. + */ + HYDROGUI_PrsPolylineDriver(); + + /** + * \brief Destructor. + */ + virtual ~HYDROGUI_PrsPolylineDriver(); + +public: + /** + * \brief Update or create the polyline presentation on a basis of data object. + * \param theObj data object + * \param thePrs presentation + * \return status of the operation + */ + virtual bool Update( const Handle(HYDROData_Object)& theObj, + HYDROGUI_Prs*& thePrs ); +}; + +#endif -- 2.39.2