From a01ad3cf8d7c39540b742a458b6359f8cd4e5af9 Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 20 Jun 2013 07:31:27 +0000 Subject: [PATCH] Initial integration of the GraphicsView package. --- adm_local/unix/config_files/Makefile.am | 1 + .../unix/config_files/check_GraphicsView.m4 | 25 + configure.ac | 17 + src/GraphicsView/GraphicsView.h | 34 + src/GraphicsView/GraphicsView_Defs.h | 25 + src/GraphicsView/GraphicsView_Geom.h | 4 + src/GraphicsView/GraphicsView_Object.cxx | 140 ++ src/GraphicsView/GraphicsView_Object.h | 95 ++ src/GraphicsView/GraphicsView_Scene.cxx | 195 +++ src/GraphicsView/GraphicsView_Scene.h | 77 + src/GraphicsView/GraphicsView_Selector.cxx | 138 ++ src/GraphicsView/GraphicsView_Selector.h | 75 + src/GraphicsView/GraphicsView_ViewFrame.cxx | 360 ++++ src/GraphicsView/GraphicsView_ViewFrame.h | 101 ++ src/GraphicsView/GraphicsView_ViewManager.cxx | 52 + src/GraphicsView/GraphicsView_ViewManager.h | 48 + src/GraphicsView/GraphicsView_ViewPort.cxx | 1496 +++++++++++++++++ src/GraphicsView/GraphicsView_ViewPort.h | 295 ++++ .../GraphicsView_ViewTransformer.cxx | 293 ++++ .../GraphicsView_ViewTransformer.h | 95 ++ src/GraphicsView/GraphicsView_Viewer.cxx | 504 ++++++ src/GraphicsView/GraphicsView_Viewer.h | 118 ++ src/GraphicsView/Makefile.am | 82 + .../resources/GraphicsView_images.ts | 41 + .../resources/GraphicsView_msg_en.ts | 88 + .../resources/GraphicsView_msg_fr.ts | 89 + .../resources/graphics_view_cursor_zoom.png | Bin 0 -> 245 bytes .../resources/graphics_view_dump.png | Bin 0 -> 682 bytes .../resources/graphics_view_fitall.png | Bin 0 -> 816 bytes .../resources/graphics_view_fitarea.png | Bin 0 -> 815 bytes .../resources/graphics_view_fitselect.png | Bin 0 -> 857 bytes .../resources/graphics_view_glpan.png | Bin 0 -> 1086 bytes .../resources/graphics_view_pan.png | Bin 0 -> 982 bytes .../resources/graphics_view_reset.png | Bin 0 -> 918 bytes .../resources/graphics_view_zoom.png | Bin 0 -> 797 bytes src/LightApp/LightApp_Application.cxx | 25 + src/LightApp/LightApp_Application.h | 2 +- src/LightApp/Makefile.am | 8 + src/LightApp/resources/LightApp.ini | 1 + src/LightApp/resources/LightApp.xml | 1 + src/LightApp/resources/LightApp_msg_en.ts | 2 +- src/LightApp/resources/LightApp_msg_fr.ts | 2 +- src/Makefile.am | 11 +- 43 files changed, 4535 insertions(+), 5 deletions(-) create mode 100644 adm_local/unix/config_files/check_GraphicsView.m4 create mode 100644 src/GraphicsView/GraphicsView.h create mode 100644 src/GraphicsView/GraphicsView_Defs.h create mode 100644 src/GraphicsView/GraphicsView_Geom.h create mode 100644 src/GraphicsView/GraphicsView_Object.cxx create mode 100644 src/GraphicsView/GraphicsView_Object.h create mode 100644 src/GraphicsView/GraphicsView_Scene.cxx create mode 100644 src/GraphicsView/GraphicsView_Scene.h create mode 100644 src/GraphicsView/GraphicsView_Selector.cxx create mode 100644 src/GraphicsView/GraphicsView_Selector.h create mode 100644 src/GraphicsView/GraphicsView_ViewFrame.cxx create mode 100644 src/GraphicsView/GraphicsView_ViewFrame.h create mode 100644 src/GraphicsView/GraphicsView_ViewManager.cxx create mode 100644 src/GraphicsView/GraphicsView_ViewManager.h create mode 100644 src/GraphicsView/GraphicsView_ViewPort.cxx create mode 100644 src/GraphicsView/GraphicsView_ViewPort.h create mode 100644 src/GraphicsView/GraphicsView_ViewTransformer.cxx create mode 100644 src/GraphicsView/GraphicsView_ViewTransformer.h create mode 100644 src/GraphicsView/GraphicsView_Viewer.cxx create mode 100644 src/GraphicsView/GraphicsView_Viewer.h create mode 100644 src/GraphicsView/Makefile.am create mode 100644 src/GraphicsView/resources/GraphicsView_images.ts create mode 100644 src/GraphicsView/resources/GraphicsView_msg_en.ts create mode 100644 src/GraphicsView/resources/GraphicsView_msg_fr.ts create mode 100755 src/GraphicsView/resources/graphics_view_cursor_zoom.png create mode 100644 src/GraphicsView/resources/graphics_view_dump.png create mode 100644 src/GraphicsView/resources/graphics_view_fitall.png create mode 100644 src/GraphicsView/resources/graphics_view_fitarea.png create mode 100755 src/GraphicsView/resources/graphics_view_fitselect.png create mode 100644 src/GraphicsView/resources/graphics_view_glpan.png create mode 100644 src/GraphicsView/resources/graphics_view_pan.png create mode 100644 src/GraphicsView/resources/graphics_view_reset.png create mode 100644 src/GraphicsView/resources/graphics_view_zoom.png diff --git a/adm_local/unix/config_files/Makefile.am b/adm_local/unix/config_files/Makefile.am index 52588fee1..c21475c58 100644 --- a/adm_local/unix/config_files/Makefile.am +++ b/adm_local/unix/config_files/Makefile.am @@ -25,6 +25,7 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am dist_admlocalm4_DATA = \ check_disable_Corba.m4 \ check_GLViewer.m4 \ +check_GraphicsView.m4 \ check_GUI.m4 \ check_msg2qm.m4 \ check_OCCViewer.m4 \ diff --git a/adm_local/unix/config_files/check_GraphicsView.m4 b/adm_local/unix/config_files/check_GraphicsView.m4 new file mode 100644 index 000000000..9082b9424 --- /dev/null +++ b/adm_local/unix/config_files/check_GraphicsView.m4 @@ -0,0 +1,25 @@ +# +# Check configure option --disable-graphicsView=[yes|no|DIR] taking into account that +# DISABLE_GRAPHICSVIEW may be already set during build_configure, +# Set DISABLE_GRAPHICSVIEW to yes|no +# +# Author : Kirill Afonshin (DTN, 2010) +# + +AC_DEFUN([CHECK_GRAPHICSVIEW],[ + +AC_ARG_WITH(graphicsView, + [ --disable-graphicsView default=no ], + disable_graphicsView="$withval",disable_graphicsView="${DISABLE_GRAPHICSVIEW}") + +case $disable_graphicsView in + yes) +# AC_MSG_RESULT(************************************************) +# AC_MSG_RESULT(***** DISABLE GraphicsView configuration *****) +# AC_MSG_RESULT(************************************************) + DISABLE_GRAPHICSVIEW="yes" + AC_SUBST(DISABLE_GRAPHICSVIEW) +esac + + +])dnl diff --git a/configure.ac b/configure.ac index 58e06d45c..c502ee202 100644 --- a/configure.ac +++ b/configure.ac @@ -68,6 +68,12 @@ else DISABLE_GLVIEWER="yes" fi +if test "x${enable_graphicsView}" != "xno" ; then + DISABLE_GRAPHICSVIEW="no" +else + DISABLE_GRAPHICSVIEW="yes" +fi + if test "x${enable_plot2dViewer}" != "xno" ; then DISABLE_PLOT2DVIEWER="no" else @@ -393,6 +399,15 @@ echo CHECK_GLVIEWER echo "DISABLE_GLVIEWER = "$DISABLE_GLVIEWER +echo +echo --------------------------------------------- +echo Testing GraphicsView +echo --------------------------------------------- +echo + +CHECK_GRAPHICSVIEW +echo "DISABLE_GRAPHICSVIEW = "$DISABLE_GRAPHICSVIEW + echo echo --------------------------------------------- echo Testing Plot2dViewer @@ -569,6 +584,7 @@ fi AM_CONDITIONAL(GUI_ENABLE_CORBA, [test "$GUI_DISABLE_CORBA" = no]) AM_CONDITIONAL(ENABLE_PYCONSOLE, [test "$DISABLE_PYCONSOLE" = no]) AM_CONDITIONAL(ENABLE_GLVIEWER, [test "$DISABLE_GLVIEWER" = no]) +AM_CONDITIONAL(ENABLE_GRAPHICSVIEW, [test "$DISABLE_GRAPHICSVIEW" = no]) AM_CONDITIONAL(ENABLE_PLOT2DVIEWER, [test "$DISABLE_PLOT2DVIEWER" = no]) AM_CONDITIONAL(ENABLE_SUPERVGRAPHVIEWER, [test "$DISABLE_SUPERVGRAPHVIEWER" = no]) AM_CONDITIONAL(ENABLE_OCCVIEWER, [test "$DISABLE_OCCVIEWER" = no]) @@ -644,6 +660,7 @@ AC_OUTPUT([ \ src/OBJECT/Makefile \ src/ViewerTools/Makefile \ src/GLViewer/Makefile \ + src/GraphicsView/Makefile \ src/VTKViewer/Makefile \ src/SVTK/Makefile \ src/OCCViewer/Makefile \ diff --git a/src/GraphicsView/GraphicsView.h b/src/GraphicsView/GraphicsView.h new file mode 100644 index 000000000..16c7197c9 --- /dev/null +++ b/src/GraphicsView/GraphicsView.h @@ -0,0 +1,34 @@ +// 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: GraphicsView.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifdef WIN32 + +#ifdef GRAPHICSVIEW_EXPORTS +#define GRAPHICSVIEW_API __declspec(dllexport) +#else +#define GRAPHICSVIEW_API __declspec(dllimport) +#endif + +#else +#define GRAPHICSVIEW_API +#endif // WIN32 + diff --git a/src/GraphicsView/GraphicsView_Defs.h b/src/GraphicsView/GraphicsView_Defs.h new file mode 100644 index 000000000..c9046839d --- /dev/null +++ b/src/GraphicsView/GraphicsView_Defs.h @@ -0,0 +1,25 @@ +#ifndef GRAPHICSVIEW_DEFS_H +#define GRAPHICSVIEW_DEFS_H + +#include + +class GraphicsView_Object; +typedef QList GraphicsView_ObjectList; +typedef QListIterator GraphicsView_ObjectListIterator; + +enum GV_SelectionChangeStatus +{ + GVSCS_Invalid, + GVSCS_Local, + GVSCS_Global +}; + +enum GV_SelectionStatus +{ + GVSS_Invalid, + GVSS_LocalChanged, + GVSS_GlobalChanged, + GVSS_NoChanged +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Geom.h b/src/GraphicsView/GraphicsView_Geom.h new file mode 100644 index 000000000..150b92a27 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Geom.h @@ -0,0 +1,4 @@ +#ifndef GRAPHICSVIEW_GEOM_H +#define GRAPHICSVIEW_GEOM_H + +#endif diff --git a/src/GraphicsView/GraphicsView_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx new file mode 100644 index 000000000..33200c30d --- /dev/null +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -0,0 +1,140 @@ +// 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: GraphicsView_Object.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_Object.h" + +#include "GraphicsView_Scene.h" + +//======================================================================= +// Name : GraphicsView_Object +// Purpose : Constructor +//======================================================================= +GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent ) +: QGraphicsItemGroup( theParent ), + myPriority( 0 ), + myIsOnTop( false ), + myIsHighlighted( false ), + myIsSelected( false ) +{ +} + +//======================================================================= +// Name : GraphicsView_Object +// Purpose : Destructor +//======================================================================= +GraphicsView_Object::~GraphicsView_Object() +{ +} + +//================================================================ +// Function : setName +// Purpose : +//================================================================ +void GraphicsView_Object::setName( const QString& theName ) +{ + myName = theName; +} + +//================================================================ +// Function : getRect +// Purpose : +//================================================================ +QRectF GraphicsView_Object::getRect() const +{ + return sceneBoundingRect(); +} + +//================================================================ +// Function : checkHighlight +// Purpose : +//================================================================ +bool GraphicsView_Object::checkHighlight( double theX, double theY ) const +{ + return getRect().contains( theX, theY ); +} + +//================================================================ +// Function : highlight +// Purpose : +//================================================================ +bool GraphicsView_Object::highlight( double theX, double theY ) +{ + if( myIsHighlighted = isVisible() ) + myIsHighlighted = checkHighlight( theX, theY ); + return myIsHighlighted; +} + +//================================================================ +// Function : unhighlight +// Purpose : +//================================================================ +void GraphicsView_Object::unhighlight() +{ + myIsHighlighted = false; +} + +//================================================================ +// Function : select +// Purpose : +//================================================================ +bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect ) +{ + if( myIsSelected = isVisible() ) + { + if( !theRect.isNull() ) + myIsSelected = theRect.contains( getRect() ); + else + myIsSelected = checkHighlight( theX, theY ); + } + return myIsSelected; +} + +//================================================================ +// Function : unselect +// Purpose : +//================================================================ +void GraphicsView_Object::unselect() +{ + myIsSelected = false; +} + +//================================================================ +// Function : move +// Purpose : +//================================================================ +void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce ) +{ + moveBy( theDX, theDY ); + if( theIsAtOnce ) + finishMove(); +} + +//================================================================ +// Function : finishMove +// Purpose : +//================================================================ +bool GraphicsView_Object::finishMove() +{ + if( GraphicsView_Scene* aScene = dynamic_cast( scene() ) ) + aScene->processRectChanged(); + return true; +} diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h new file mode 100644 index 000000000..5fd908c34 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Object.h @@ -0,0 +1,95 @@ +// 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: GraphicsView_Object.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_OBJECT_H +#define GRAPHICSVIEW_OBJECT_H + +#include "GraphicsView.h" + +#include + +/* + Class : GraphicsView_Object + Description : Base class for all objects displayed at the scene +*/ +class GRAPHICSVIEW_API GraphicsView_Object : public QGraphicsItemGroup +{ +public: + GraphicsView_Object( QGraphicsItem* theParent = 0 ); + ~GraphicsView_Object(); + + virtual void compute() = 0; + + const QString& getName() const { return myName; } + virtual void setName( const QString& theName ); + + virtual int getPriority() const { return myPriority; } + + virtual bool isOnTop() const { return myIsOnTop; } + virtual void setIsOnTop( bool theIsOnTop ) { myIsOnTop = theIsOnTop; } + + virtual bool isSelectable() const { return true; } + virtual bool isMovable() const { return true; } + + virtual QRectF getRect() const; + + virtual bool highlight( double theX, double theY ); + virtual void unhighlight(); + virtual bool isHighlighted() const { return myIsHighlighted; } + + virtual bool select( double theX, double theY, const QRectF& theRect ); + virtual void unselect(); + virtual bool isSelected() const { return myIsSelected; } + virtual void setSelected( bool theState ) { myIsSelected = theState; } + + virtual void move( double theDX, double theDY, bool theIsAtOnce = false ); + virtual bool finishMove(); + virtual bool isMovingByXAllowed( double theDX ) { return true; } + virtual bool isMovingByYAllowed( double theDY ) { return true; } + + virtual bool updateScale( bool theIsScaleUp, bool theIsCtrl ) { return false; } + + virtual QRectF getPullingRect() const { return getRect(); } + virtual bool portContains( const QPointF& ) { return false; } + virtual bool startPulling( const QPointF& ) { return false; } + virtual void pull( const QPointF&, GraphicsView_Object* ) {} + virtual void finishPulling() {} + virtual bool isPulling() { return false; } + + virtual bool handleMousePress( QGraphicsSceneMouseEvent* ) { return false; } + virtual bool handleMouseMove( QGraphicsSceneMouseEvent* ) { return false; } + virtual bool handleMouseRelease( QGraphicsSceneMouseEvent* ) { return false; } + +protected: + virtual bool checkHighlight( double theX, double theY ) const; + +protected: + QString myName; + + int myPriority; + bool myIsOnTop; + + bool myIsHighlighted; + bool myIsSelected; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Scene.cxx b/src/GraphicsView/GraphicsView_Scene.cxx new file mode 100644 index 000000000..39fe05733 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Scene.cxx @@ -0,0 +1,195 @@ +// 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: GraphicsView_Scene.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_Scene.h" + +#include +#include + +//#define VIEWER_DEBUG + +//======================================================================= +// Name : GraphicsView_Scene +// Purpose : Constructor +//======================================================================= +GraphicsView_Scene::GraphicsView_Scene( QObject* theParent ) +: QGraphicsScene( theParent ) +{ +#ifdef VIEWER_DEBUG + mySceneRectItem = new QGraphicsRectItem(); + mySceneRectItem->setPen( QPen( Qt::red, 0.0 ) ); + + addItem( mySceneRectItem ); + + connect( this, SIGNAL( sceneRectChanged( const QRectF& ) ), + this, SLOT( onSceneRectChanged( const QRectF& ) ) ); +#endif +} + +//======================================================================= +// Name : GraphicsView_Scene +// Purpose : Destructor +//======================================================================= +GraphicsView_Scene::~GraphicsView_Scene() +{ +} + +//================================================================ +// Function : processRectChanged +// Purpose : +//================================================================ +void GraphicsView_Scene::processRectChanged() +{ + emit gsBoundingRectChanged(); +} + +//================================================================ +// Function : onSceneRectChanged +// Purpose : +//================================================================ +void GraphicsView_Scene::onSceneRectChanged( const QRectF& theRect ) +{ +#ifdef VIEWER_DEBUG + mySceneRectItem->setRect( theRect ); +#endif +} + +//================================================================ +// Function : keyPressEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::keyPressEvent( QKeyEvent* e ) +{ + emit gsKeyEvent( e ); + QGraphicsScene::keyPressEvent( e ); +} + +//================================================================ +// Function : keyReleaseEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::keyReleaseEvent( QKeyEvent* e ) +{ + emit gsKeyEvent( e ); + QGraphicsScene::keyReleaseEvent( e ); +} + +//================================================================ +// Function : mousePressEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e ) +{ + emit gsMouseEvent( e ); + QGraphicsScene::mousePressEvent( e ); +} + +//================================================================ +// Function : mouseMoveEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::mouseMoveEvent( QGraphicsSceneMouseEvent* e ) +{ + emit gsMouseEvent( e ); + QGraphicsScene::mouseMoveEvent( e ); +} + +//================================================================ +// Function : mouseReleaseEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e ) +{ + emit gsMouseEvent( e ); + QGraphicsScene::mouseReleaseEvent( e ); +} + +//================================================================ +// Function : mouseDoubleClickEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e ) +{ + emit gsMouseEvent( e ); + QGraphicsScene::mouseDoubleClickEvent( e ); +} + +//================================================================ +// Function : wheelEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::wheelEvent( QGraphicsSceneWheelEvent* e ) +{ + emit gsWheelEvent( e ); + + // accept the event to prevent calling QAbstractScrollArea::wheelEvent() + // from QGraphicsView::wheelEvent(), which will change values of scroll-bars + e->accept(); + + //QGraphicsScene::wheelEvent( e ); // don't uncomment +} + +//================================================================ +// Function : contextMenuEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::contextMenuEvent( QGraphicsSceneContextMenuEvent* e ) +{ + emit gsContextMenuEvent( e ); + QGraphicsScene::contextMenuEvent( e ); +} + +//================================================================ +// Function : dragEnterEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::dragEnterEvent( QGraphicsSceneDragDropEvent* e ) +{ + //QGraphicsScene::dragEnterEvent( e ); // don't uncomment +} + +//================================================================ +// Function : dragLeaveEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::dragLeaveEvent( QGraphicsSceneDragDropEvent* e ) +{ + //QGraphicsScene::dragLeaveEvent( e ); // don't uncomment +} + +//================================================================ +// Function : dragMoveEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::dragMoveEvent( QGraphicsSceneDragDropEvent* e ) +{ + //QGraphicsScene::dragMoveEvent( e ); // don't uncomment +} + +//================================================================ +// Function : dropEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::dropEvent( QGraphicsSceneDragDropEvent* e ) +{ + //QGraphicsScene::dropEvent( e ); // don't uncomment +} diff --git a/src/GraphicsView/GraphicsView_Scene.h b/src/GraphicsView/GraphicsView_Scene.h new file mode 100644 index 000000000..bd9f8d6b1 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Scene.h @@ -0,0 +1,77 @@ +// 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: GraphicsView_Scene.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_SCENE_H +#define GRAPHICSVIEW_SCENE_H + +#include "GraphicsView.h" + +#include + +class QGraphicsRectItem; + +/* + Class : GraphicsView_Scene + Description : Scene of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_Scene : public QGraphicsScene +{ + Q_OBJECT + +public: + GraphicsView_Scene( QObject* theParent = 0 ); + ~GraphicsView_Scene(); + +public: + void processRectChanged(); + +protected slots: + void onSceneRectChanged( const QRectF& theRect ); // for debug + +protected: + virtual void keyPressEvent( QKeyEvent* ); + virtual void keyReleaseEvent( QKeyEvent* ); + virtual void mousePressEvent( QGraphicsSceneMouseEvent* ); + virtual void mouseMoveEvent( QGraphicsSceneMouseEvent* ); + virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* ); + virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* ); + virtual void wheelEvent( QGraphicsSceneWheelEvent* ); + virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* ); + + virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* ); + virtual void dragLeaveEvent( QGraphicsSceneDragDropEvent* ); + virtual void dragMoveEvent( QGraphicsSceneDragDropEvent* ); + virtual void dropEvent( QGraphicsSceneDragDropEvent* ); + +signals: + void gsKeyEvent( QKeyEvent* ); + void gsMouseEvent( QGraphicsSceneMouseEvent* ); + void gsWheelEvent( QGraphicsSceneWheelEvent* ); + void gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ); + + void gsBoundingRectChanged(); + +private: + QGraphicsRectItem* mySceneRectItem; // for debug +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Selector.cxx b/src/GraphicsView/GraphicsView_Selector.cxx new file mode 100644 index 000000000..c551c452a --- /dev/null +++ b/src/GraphicsView/GraphicsView_Selector.cxx @@ -0,0 +1,138 @@ +// 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: GraphicsView_Selector.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_Selector.h" +#include "GraphicsView_Viewer.h" +#include "GraphicsView_ViewPort.h" +#include "GraphicsView_ViewFrame.h" + +int GraphicsView_Selector::appendKey = Qt::ShiftModifier; + +//======================================================================= +// Name : GraphicsView_Selector +// Purpose : Constructor +//======================================================================= +GraphicsView_Selector::GraphicsView_Selector( GraphicsView_Viewer* theViewer ) +: QObject( 0 ), + myViewer( theViewer ), + myLocked( false ) +{ +} + +//======================================================================= +// Name : GraphicsView_Selector +// Purpose : Destructor +//======================================================================= +GraphicsView_Selector::~GraphicsView_Selector() +{ +} + +//================================================================ +// Function : detect +// Purpose : +//================================================================ +void GraphicsView_Selector::detect( double x, double y ) +{ + if ( myLocked ) + return; + + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + aViewPort->highlight( x, y ); +} + +//================================================================ +// Function : undetectAll +// Purpose : +//================================================================ +void GraphicsView_Selector::undetectAll() +{ + if ( myLocked ) + return; + + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + aViewPort->clearHighlighted(); +} + +//================================================================ +// Function : select +// Purpose : +//================================================================ +void GraphicsView_Selector::select( const QRectF& selRect, bool append ) +{ + if ( myLocked ) + return; + + int selBefore = numSelected(); + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + { + int aStatus = aViewPort->select( selRect, append ); + checkSelection( selBefore, append, aStatus ); + } +} + +//================================================================ +// Function : unselectAll +// Purpose : +//================================================================ +void GraphicsView_Selector::unselectAll() +{ + if ( myLocked ) + return; + + if ( numSelected() > 0 ) + emit selSelectionCancel(); +} + +//================================================================ +// Function : checkSelection +// Purpose : +//================================================================ +void GraphicsView_Selector::checkSelection( int selBefore, bool append, int theStatus ) +{ + int selAfter = numSelected(); + if ( selBefore > 0 && selAfter < 1 ) + emit selSelectionCancel(); + else if ( selAfter > 0 ) + { + switch( theStatus ) + { + case GVSS_LocalChanged: + emit selSelectionDone( GVSCS_Local ); + break; + case GVSS_GlobalChanged: + emit selSelectionDone( GVSCS_Global ); + break; + } + } +} + +//================================================================ +// Function : numSelected +// Purpose : +//================================================================ +int GraphicsView_Selector::numSelected() const +{ + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + return aViewPort->nbSelected(); + return 0; +} + diff --git a/src/GraphicsView/GraphicsView_Selector.h b/src/GraphicsView/GraphicsView_Selector.h new file mode 100644 index 000000000..2eb4e1dcb --- /dev/null +++ b/src/GraphicsView/GraphicsView_Selector.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 +// +// File: GraphicsView_Selector.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_SELECTOR_H +#define GRAPHICSVIEW_SELECTOR_H + +#include "GraphicsView.h" + +#include "GraphicsView_Defs.h" + +#include +#include + +class GraphicsView_Viewer; + +/* + Class : GraphicsView_Selector + Description : Selector of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_Selector : public QObject +{ + Q_OBJECT + +public: + GraphicsView_Selector( GraphicsView_Viewer* ); + ~GraphicsView_Selector(); + +public: + void lock( bool theState ) { myLocked = theState; } + + static int getAppendKey() { return appendKey; } + static void setAppendKey( int k ) { appendKey = k; } + +public: + virtual void detect( double, double ); + virtual void undetectAll(); + + virtual void select( const QRectF&, bool append = false ); + virtual void unselectAll(); + virtual int numSelected() const; + + virtual void checkSelection( int, bool, int ); + +signals: + void selSelectionDone( GV_SelectionChangeStatus ); + void selSelectionCancel(); + +protected: + GraphicsView_Viewer* myViewer; + bool myLocked; + +private: + static int appendKey; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx new file mode 100644 index 000000000..459e10a8c --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -0,0 +1,360 @@ +// 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: GraphicsView_ViewFrame.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_ViewFrame.h" + +#include "GraphicsView_Viewer.h" +#include "GraphicsView_ViewPort.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//======================================================================= +// Name : GraphicsView_ViewFrame +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Viewer* vw ) +: SUIT_ViewWindow( d ), + myViewer( vw ) +{ + QFrame* aFrame = new QFrame( this ); + setCentralWidget( aFrame ); + + QBoxLayout* aLayout = new QHBoxLayout( aFrame ); + aLayout->setMargin( 0 ); + aLayout->setSpacing( 0 ); + + myViewPort = new GraphicsView_ViewPort( aFrame ); + aLayout->addWidget( myViewPort ); + + createActions(); + myToolBarId = createToolBar(); + + connect( myViewPort, SIGNAL( vpKeyEvent( QKeyEvent* ) ), + this, SLOT( keyEvent( QKeyEvent* ) ) ); + connect( myViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ), + this, SLOT( mouseEvent( QGraphicsSceneMouseEvent* ) ) ); + connect( myViewPort, SIGNAL( vpWheelEvent( QGraphicsSceneWheelEvent* ) ), + this, SLOT( wheelEvent( QGraphicsSceneWheelEvent* ) ) ); + connect( myViewPort, SIGNAL( vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ), + this, SLOT( contextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) ); +} + +//======================================================================= +// Name : GraphicsView_ViewFrame +// Purpose : Destructor +//======================================================================= +GraphicsView_ViewFrame::~GraphicsView_ViewFrame() +{ +} + +//================================================================ +// Function : createActions +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::createActions() +{ + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QtxAction* anAction; + + // Dump view + anAction = new QtxAction( tr( "MNU_DUMP_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_DUMP" ) ), + tr( "MNU_DUMP_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) ); + toolMgr()->registerAction( anAction, DumpId ); + + // FitAll + anAction = new QtxAction( tr( "MNU_FITALL" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITALL" ) ), + tr( "MNU_FITALL" ), 0, this ); + anAction->setStatusTip( tr( "DSC_FITALL" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitAll() ) ); + toolMgr()->registerAction( anAction, FitAllId ); + + // FitRect + anAction = new QtxAction( tr( "MNU_FITRECT" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITAREA" ) ), + tr( "MNU_FITRECT" ), 0, this ); + anAction->setStatusTip( tr( "DSC_FITRECT" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitArea() ) ); + toolMgr()->registerAction( anAction, FitRectId ); + + // FitSelect + anAction = new QtxAction( tr( "MNU_FITSELECT" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITSELECT" ) ), + tr( "MNU_FITSELECT" ), 0, this ); + anAction->setStatusTip( tr( "DSC_FITSELECT" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitSelect() ) ); + toolMgr()->registerAction( anAction, FitSelectId ); + + // Zoom + anAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_ZOOM" ) ), + tr( "MNU_ZOOM_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewZoom() ) ); + toolMgr()->registerAction( anAction, ZoomId ); + + // Panning + anAction = new QtxAction( tr( "MNU_PAN_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_PAN" ) ), + tr( "MNU_PAN_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_PAN_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewPan() ) ); + toolMgr()->registerAction( anAction, PanId ); + + // Global Panning + anAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_GLOBALPAN" ) ), + tr( "MNU_GLOBALPAN_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewGlobalPan() ) ); + toolMgr()->registerAction( anAction, GlobalPanId ); + + // Reset (obsolete) + /* + anAction = new QtxAction( tr( "MNU_RESET_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_RESET" ) ), + tr( "MNU_RESET_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_RESET_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewReset() ) ); + toolMgr()->registerAction( anAction, ResetId ); + */ +} + +//================================================================ +// Function : createToolBar +// Purpose : +//================================================================ +int GraphicsView_ViewFrame::createToolBar() +{ + int tid = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL") ); + toolMgr()->append( DumpId, tid ); + + myScaleAction = new QtxMultiAction( this ); + myScaleAction->insertAction( toolMgr()->action( FitAllId ) ); + myScaleAction->insertAction( toolMgr()->action( FitRectId ) ); + myScaleAction->insertAction( toolMgr()->action( FitSelectId ) ); + myScaleAction->insertAction( toolMgr()->action( ZoomId ) ); + toolMgr()->append( myScaleAction, tid ); + + myPanAction = new QtxMultiAction( this ); + myPanAction->insertAction( toolMgr()->action( PanId ) ); + myPanAction->insertAction( toolMgr()->action( GlobalPanId ) ); + toolMgr()->append( myPanAction, tid ); + + toolMgr()->append( toolMgr()->action( ResetId ), tid ); + + return tid; +} + +//================================================================ +// Function : dumpView +// Purpose : +//================================================================ +QImage GraphicsView_ViewFrame::dumpView() +{ + return myViewPort->dumpView(); +} + +//================================================================ +// Function : expandToolBarActions +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::expandToolBarActions() +{ + QList anExpandableActions; + anExpandableActions.append( myScaleAction ); + anExpandableActions.append( myPanAction ); + + QListIterator anIter( anExpandableActions ); + while( anIter.hasNext() ) + { + if( QtxMultiAction* aMultiAction = anIter.next() ) + { + QList aLocalActions = aMultiAction->actions(); + QListIterator aLocalIter( aLocalActions ); + while( aLocalIter.hasNext() ) + if( QAction* anAction = aLocalIter.next() ) + toolMgr()->append( anAction, myToolBarId ); + + int anId = toolMgr()->actionId( aMultiAction ); + toolMgr()->remove( anId, myToolBarId ); + } + } +} + +//================================================================ +// Function : onViewPan +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::onViewPan() +{ + myViewer->activateTransform( GraphicsView_Viewer::Pan ); +} + +//================================================================ +// Function : onViewZoom +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::onViewZoom() +{ + myViewer->activateTransform( GraphicsView_Viewer::Zoom ); +} + +//================================================================ +// Function : onViewFitAll +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::onViewFitAll() +{ + myViewer->activateTransform( GraphicsView_Viewer::FitAll ); +} + +//================================================================ +// Function : onViewFitArea +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::onViewFitArea() +{ + myViewer->activateTransform( GraphicsView_Viewer::FitRect ); +} + +//================================================================ +// Function : onViewFitSelect +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::onViewFitSelect() +{ + myViewer->activateTransform( GraphicsView_Viewer::FitSelect ); +} + +//================================================================ +// Function : onViewGlobalPan +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::onViewGlobalPan() +{ + myViewer->activateTransform( GraphicsView_Viewer::PanGlobal ); +} + +//================================================================ +// Function : onViewReset +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::onViewReset() +{ + myViewer->activateTransform( GraphicsView_Viewer::Reset ); +} + +//================================================================ +// Function : keyEvent +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::keyEvent( QKeyEvent* e ) +{ + switch ( e->type() ) + { + case QEvent::KeyPress: + emit keyPressed( e ); + break; + case QEvent::KeyRelease: + emit keyReleased( e ); + break; + default: + break; + } +} + +//================================================================ +// Function : mouseEvent +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::mouseEvent( QGraphicsSceneMouseEvent* e ) +{ + switch ( e->type() ) + { + case QEvent::GraphicsSceneMousePress: + emit mousePressed( e ); + break; + case QEvent::GraphicsSceneMouseMove: + emit mouseMoving( e ); + break; + case QEvent::GraphicsSceneMouseRelease: + emit mouseReleased( e ); + break; + case QEvent::GraphicsSceneMouseDoubleClick: + emit mouseDoubleClicked( e ); + break; + default: + break; + } +} + +//================================================================ +// Function : wheelEvent +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::wheelEvent( QGraphicsSceneWheelEvent* e ) +{ + switch ( e->type() ) + { + case QEvent::GraphicsSceneWheel: + emit wheeling( e ); + break; + default: + break; + } +} + +//================================================================ +// Function : contextMenuEvent +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::contextMenuEvent( QGraphicsSceneContextMenuEvent* e ) +{ + QPoint aPos = myViewPort->mapFromScene( e->scenePos() ); + QContextMenuEvent* anEvent = new QContextMenuEvent( (QContextMenuEvent::Reason)e->reason(), + aPos, e->screenPos(), e->modifiers() ); + emit contextMenuRequested( anEvent ); + delete anEvent; +} diff --git a/src/GraphicsView/GraphicsView_ViewFrame.h b/src/GraphicsView/GraphicsView_ViewFrame.h new file mode 100644 index 000000000..d7f86f4a8 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewFrame.h @@ -0,0 +1,101 @@ +// 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: GraphicsView_ViewFrame.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWFRAME_H +#define GRAPHICSVIEW_VIEWFRAME_H + +#include "GraphicsView.h" + +#include + +class QGraphicsSceneContextMenuEvent; +class QGraphicsSceneMouseEvent; +class QGraphicsSceneWheelEvent; + +class QtxMultiAction; + +class SUIT_Desktop; + +class GraphicsView_Viewer; +class GraphicsView_ViewPort; + +/* + Class : GraphicsView_ViewFrame + Description : View frame of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_ViewFrame : public SUIT_ViewWindow +{ + Q_OBJECT + +public: + enum { DumpId, FitAllId, FitRectId, FitSelectId, ZoomId, PanId, GlobalPanId, ResetId }; + +public: + GraphicsView_ViewFrame( SUIT_Desktop*, GraphicsView_Viewer* ); + ~GraphicsView_ViewFrame(); + +public: + GraphicsView_Viewer* getViewer() const { return myViewer; } + GraphicsView_ViewPort* getViewPort() const { return myViewPort; } + + virtual QImage dumpView(); + + void expandToolBarActions(); + + protected slots: + void onViewPan(); + void onViewZoom(); + void onViewFitAll(); + void onViewFitArea(); + void onViewFitSelect(); + void onViewGlobalPan(); + void onViewReset(); + +private slots: + void keyEvent( QKeyEvent* ); + void mouseEvent( QGraphicsSceneMouseEvent* ); + void wheelEvent( QGraphicsSceneWheelEvent* ); + void contextMenuEvent( QGraphicsSceneContextMenuEvent* ); + +signals: + void keyPressed( QKeyEvent* ); + void keyReleased( QKeyEvent* ); + void mousePressed( QGraphicsSceneMouseEvent* ); + void mouseMoving( QGraphicsSceneMouseEvent* ); + void mouseReleased( QGraphicsSceneMouseEvent* ); + void mouseDoubleClicked( QGraphicsSceneMouseEvent* ); + void wheeling( QGraphicsSceneWheelEvent* ); + +private: + void createActions(); + int createToolBar(); + +private: + GraphicsView_Viewer* myViewer; + GraphicsView_ViewPort* myViewPort; + + int myToolBarId; + QtxMultiAction* myScaleAction; + QtxMultiAction* myPanAction; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewManager.cxx b/src/GraphicsView/GraphicsView_ViewManager.cxx new file mode 100644 index 000000000..355e79f06 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewManager.cxx @@ -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 +// +// File: GraphicsView_ViewManager.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_ViewManager.h" +#include "GraphicsView_Viewer.h" + +//======================================================================= +// Name : GraphicsView_ViewManager +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewManager::GraphicsView_ViewManager( SUIT_Study* theStudy, + SUIT_Desktop* theDesktop ) +: SUIT_ViewManager( theStudy, theDesktop, new GraphicsView_Viewer( "GraphicsView" ) ) +{ + setTitle( tr( "GRAPHICS_VIEW_TITLE" ) ); +} + +//======================================================================= +// Name : GraphicsView_ViewManager +// Purpose : Destructor +//======================================================================= +GraphicsView_ViewManager::~GraphicsView_ViewManager() +{ +} + +//================================================================ +// Function : getViewer +// Purpose : +//================================================================ +GraphicsView_Viewer* GraphicsView_ViewManager::getViewer() +{ + return dynamic_cast( getViewModel() ); +} diff --git a/src/GraphicsView/GraphicsView_ViewManager.h b/src/GraphicsView/GraphicsView_ViewManager.h new file mode 100644 index 000000000..9609ac84e --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewManager.h @@ -0,0 +1,48 @@ +// 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: GraphicsView_ViewManager.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWMANAGER_H +#define GRAPHICSVIEW_VIEWMANAGER_H + +#include "GraphicsView.h" + +#include + +class GraphicsView_Viewer; + +/* + Class : GraphicsView_ViewManager + Description : View manager of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_ViewManager : public SUIT_ViewManager +{ + Q_OBJECT + +public: + GraphicsView_ViewManager( SUIT_Study* theStudy, + SUIT_Desktop* theDesktop ); + virtual ~GraphicsView_ViewManager(); + + GraphicsView_Viewer* getViewer(); +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx new file mode 100644 index 000000000..be6e03b84 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -0,0 +1,1496 @@ +// 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: GraphicsView_ViewPort.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_ViewPort.h" + +#include "GraphicsView_Object.h" +#include "GraphicsView_Scene.h" +#include "GraphicsView_ViewTransformer.h" + +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +int GraphicsView_ViewPort::nCounter = 0; +QCursor* GraphicsView_ViewPort::defCursor = 0; +QCursor* GraphicsView_ViewPort::handCursor = 0; +QCursor* GraphicsView_ViewPort::panCursor = 0; +QCursor* GraphicsView_ViewPort::panglCursor = 0; +QCursor* GraphicsView_ViewPort::zoomCursor = 0; + +//======================================================================= +// Name : GraphicsView_ViewPort::NameLabel +// Purpose : Wrapper for label, which can ignore move events sent from +// QGraphicsView::scrollContentsBy() method, which, +// in its turn, called from GraphicsView_ViewPort::pan() +//======================================================================= +class GraphicsView_ViewPort::NameLabel : public QLabel +{ +public: + NameLabel( QWidget* theParent ) + : + QLabel( theParent ), + myAcceptMoveEvents( false ) + { + } + ~NameLabel() {} + + void setAcceptMoveEvents( bool theFlag ) + { + myAcceptMoveEvents = theFlag; + } + +protected: + virtual void moveEvent( QMoveEvent* theEvent ) + { + if( myAcceptMoveEvents ) + QLabel::moveEvent( theEvent ); + else // return the label to the initial position + { + myAcceptMoveEvents = true; + move( theEvent->oldPos() ); + myAcceptMoveEvents = false; + } + } + +private: + bool myAcceptMoveEvents; +}; + +//================================================================ +// Function : createCursors +// Purpose : +//================================================================ +void GraphicsView_ViewPort::createCursors () +{ + defCursor = new QCursor( Qt::ArrowCursor ); + handCursor = new QCursor( Qt::PointingHandCursor ); + panCursor = new QCursor( Qt::SizeAllCursor ); + panglCursor = new QCursor( Qt::CrossCursor ); + + SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr(); + zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) ); +} + +//================================================================ +// Function : destroyCursors +// Purpose : +//================================================================ +void GraphicsView_ViewPort::destroyCursors() +{ + delete defCursor; defCursor = 0; + delete handCursor; handCursor = 0; + delete panCursor; panCursor = 0; + delete panglCursor; panglCursor = 0; + delete zoomCursor; zoomCursor = 0; +} + +//======================================================================= +// Name : GraphicsView_ViewPort +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) +: QGraphicsView( theParent ), + myNameLabel( 0 ), + myNamePosition( NP_None ), + myNameLayout( 0 ), + myForegroundItem( 0 ), + myGridItem( 0 ), + myIsTransforming( false ), + myHighlightedObject( 0 ), + myHighlightX( 0 ), + myHighlightY( 0 ), + mySelectionIterator( 0 ), + myRectBand( 0 ), + myAreSelectionPointsInitialized( false ), + myIsDragging( false ), + myIsDragPositionInitialized( false ), + myIsPulling( false ), + myPullingObject( 0 ) +{ + // scene + myScene = new GraphicsView_Scene( this ); + setScene( myScene ); + + mySceneGap = 20; + myFitAllGap = 40; + myIsTraceBoundingRectEnabled = true; + + // interaction flags + myInteractionFlags = AllFlags; + + // background + setBackgroundBrush( QBrush( Qt::white ) ); + + // foreground + myIsForegroundEnabled = false; + myForegroundSize = QSizeF( 100, 30 ); + myForegroundMargin = 0.0; + myForegroundColor = Qt::white; + myForegroundFrameColor = Qt::black; + myForegroundFrameLineWidth = 1.0; + + // grid + myIsGridEnabled = false; + myGridCellSize = 100; + myGridLineStyle = Qt::DotLine; + myGridLineColor = Qt::darkGray; + + // default index method (BspTreeIndex) leads to + // crashes in QGraphicsView::paintEvent() method + myScene->setItemIndexMethod( QGraphicsScene::NoIndex ); + + // render hints (default - TextAntialiasing only) + setRenderHints( QPainter::Antialiasing | + QPainter::TextAntialiasing | + QPainter::SmoothPixmapTransform | + QPainter::HighQualityAntialiasing ); + + connect( myScene, SIGNAL( gsKeyEvent( QKeyEvent* ) ), + this, SLOT( onKeyEvent( QKeyEvent* ) ) ); + connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ), + this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); + connect( myScene, SIGNAL( gsWheelEvent( QGraphicsSceneWheelEvent* ) ), + this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) ); + connect( myScene, SIGNAL( gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ), + this, SLOT( onContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) ); + + connect( myScene, SIGNAL( gsBoundingRectChanged() ), + this, SLOT( onBoundingRectChanged() ) ); + + initialize(); +} + +//======================================================================= +// Name : GraphicsView_ViewPort +// Purpose : Destructor +//======================================================================= +GraphicsView_ViewPort::~GraphicsView_ViewPort() +{ + cleanup(); + + if( myScene ) + { + delete myScene; + myScene = 0; + } +} + +//================================================================ +// Function : initialize +// Purpose : +//================================================================ +void GraphicsView_ViewPort::initialize() +{ + if ( nCounter++ == 0 ) + createCursors(); + + setMouseTracking( true ); + setFocusPolicy( Qt::StrongFocus ); +} + +//================================================================ +// Function : cleanup +// Purpose : +//================================================================ +void GraphicsView_ViewPort::cleanup() +{ + if ( --nCounter == 0 ) + destroyCursors(); +} + +//================================================================ +// Function : addItem +// Purpose : +//================================================================ +void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem ) +{ + if( GraphicsView_Object* anObject = dynamic_cast( theItem ) ) + { + int aPriority = anObject->getPriority(); + GraphicsView_ObjectList::iterator anIter, anIterEnd = myObjects.end(); + for( anIter = myObjects.begin(); anIter != anIterEnd; anIter++ ) + { + if( GraphicsView_Object* anObjectRef = *anIter ) + { + if( anObjectRef->getPriority() > aPriority ) + break; + } + } + myObjects.insert( anIter, anObject ); + } + myScene->addItem( theItem ); + onBoundingRectChanged(); +} + +//================================================================ +// Function : removeItem +// Purpose : +//================================================================ +void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem ) +{ + if( GraphicsView_Object* anObject = dynamic_cast( theItem ) ) + { + if( myHighlightedObject == anObject ) + myHighlightedObject = 0; + mySelectedObjects.removeAll( anObject ); + myObjects.removeAll( anObject ); + } + myScene->removeItem( theItem ); + onBoundingRectChanged(); +} + +//================================================================ +// Function : getObjects +// Purpose : +//================================================================ +GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( bool theIsSortSelected ) const +{ + if( !theIsSortSelected ) + return myObjects; + + // to append selected objects after their non-selected siblings with similar priority + int aCurrentPriority = -1; + GraphicsView_ObjectList aSelectedObjects; + GraphicsView_ObjectList aTopmostObjects; + + GraphicsView_ObjectList aList; + GraphicsView_ObjectListIterator anIter( myObjects ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = anIter.next() ) + { + if( anObject->isOnTop() ) + { + aTopmostObjects.append( anObject ); + continue; + } + + int aPriority = anObject->getPriority(); + if( aPriority > aCurrentPriority ) + { + if( !aSelectedObjects.isEmpty() ) + { + aList.append( aSelectedObjects ); + aSelectedObjects.clear(); + } + aCurrentPriority = aPriority; + } + + if( anObject->isSelected() ) + aSelectedObjects.append( anObject ); + else + aList.append( anObject ); + } + } + + // for selected objects with highest priority, + // which were not pushed to the result list yet + if( !aSelectedObjects.isEmpty() ) + { + aList.append( aSelectedObjects ); + aSelectedObjects.clear(); + } + + aList.append( aTopmostObjects ); + + return aList; +} + +//================================================================ +// Function : objectsBoundingRect +// Purpose : +//================================================================ +QRectF GraphicsView_ViewPort::objectsBoundingRect( bool theOnlyVisible ) const +{ + QRectF aRect; + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + if( theOnlyVisible && !anObject->isVisible() ) + continue; + + QRectF anObjectRect = anObject->getRect(); + if( !anObjectRect.isNull() ) + { + if( aRect.isNull() ) + aRect = anObject->getRect(); + else + aRect |= anObject->getRect(); + } + } + } + return aRect; +} + +//================================================================ +// Function : dumpView +// Purpose : +//================================================================ +QImage GraphicsView_ViewPort::dumpView( bool theWholeScene, + QSizeF theSize ) +{ + if( !theWholeScene ) // just grab the view contents + { + QPixmap aPixmap = QPixmap::grabWindow( viewport()->winId() ); + return aPixmap.toImage(); + } + + // get a bounding rect of all presented objects + // (itemsBoundingRect() method is unsuitable) + QRectF aRect = objectsBoundingRect(); + if( aRect.isNull() ) + return QImage(); + + QRectF aTargetRect( 0, 0, aRect.width(), aRect.height() ); + if( theSize.isValid() ) + { + double aRatioX = theSize.width() / aTargetRect.width(); + double aRatioY = theSize.height() / aTargetRect.height(); + double aRatio = qMin( aRatioX, aRatioY ); + aTargetRect.setWidth( aTargetRect.width() * aRatio ); + aTargetRect.setHeight( aTargetRect.height() * aRatio ); + } + + // render the scene to an image + QImage anImage( aTargetRect.toRect().size(), QImage::Format_RGB32 ); + QPainter aPainter( &anImage ); + aPainter.setRenderHints( renderHints() ); + + myScene->render( &aPainter, aTargetRect, aRect ); + + return anImage; +} + +//================================================================ +// Function : setSceneGap +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setSceneGap( double theSceneGap ) +{ + mySceneGap = theSceneGap; + onBoundingRectChanged(); +} + +//================================================================ +// Function : setFitAllGap +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setFitAllGap( double theFitAllGap ) +{ + myFitAllGap = theFitAllGap; +} + +//================================================================ +// Function : setTraceBoundingRectEnabled +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setTraceBoundingRectEnabled( bool theState ) +{ + myIsTraceBoundingRectEnabled = theState; +} + +//================================================================ +// Function : setInteractionFlags +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setInteractionFlags( const int theFlags ) +{ + myInteractionFlags |= theFlags; +} + +//================================================================ +// Function : clearInteractionFlags +// Purpose : +//================================================================ +void GraphicsView_ViewPort::clearInteractionFlags( const int theFlags ) +{ + myInteractionFlags &= ~theFlags; +} + +//================================================================ +// Function : testInteractionFlags +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::testInteractionFlags( const int theFlags ) const +{ + return ( myInteractionFlags & theFlags ) == theFlags; +} + +//================================================================ +// Function : setViewNameEnabled +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setViewNamePosition( NamePosition thePosition, + bool theIsForced ) +{ + if( theIsForced && !myNameLabel ) + myNameLabel = new NameLabel( viewport() ); + + if( !myNameLabel ) + return; + + if( thePosition == NP_None ) + { + myNameLabel->setVisible( false ); + return; + } + + if( myNameLayout ) + delete myNameLayout; + + myNameLayout = new QGridLayout( viewport() ); + myNameLayout->setMargin( 10 ); + myNameLayout->setSpacing( 0 ); + + int aRow = 0, aColumn = 0; + switch( thePosition ) + { + case NP_TopLeft: aRow = 0; aColumn = 0; break; + case NP_TopRight: aRow = 0; aColumn = 1; break; + case NP_BottomLeft: aRow = 1; aColumn = 0; break; + case NP_BottomRight: aRow = 1; aColumn = 1; break; + default: break; + } + + myNameLayout->addWidget( myNameLabel, aRow, aColumn ); + myNameLayout->setRowStretch( 1 - aRow, 1 ); + myNameLayout->setColumnStretch( 1 - aColumn, 1 ); + + myNameLabel->setVisible( true ); +} + +//================================================================ +// Function : setViewName +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setViewName( const QString& theName ) +{ + if( myNameLabel ) + myNameLabel->setText( theName ); +} + +//================================================================ +// Function : backgroundColor +// Purpose : +//================================================================ +QColor GraphicsView_ViewPort::backgroundColor() const +{ + return backgroundBrush().color(); +} + +//================================================================ +// Function : setBackgroundColor +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setBackgroundColor( const QColor& theColor ) +{ + setBackgroundBrush( QBrush( theColor ) ); +} + +//================================================================ +// Function : setForegroundEnabled +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setForegroundEnabled( bool theState ) +{ + myIsForegroundEnabled = theState; +} + +//================================================================ +// Function : setForegroundSize +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setForegroundSize( const QSizeF& theSize ) +{ + myForegroundSize = theSize; +} + +//================================================================ +// Function : setForegroundMargin +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setForegroundMargin( double theMargin ) +{ + myForegroundMargin = theMargin; +} + +//================================================================ +// Function : setForegroundColor +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setForegroundColor( const QColor& theColor ) +{ + myForegroundColor = theColor; +} + +//================================================================ +// Function : setForegroundFrameColor +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setForegroundFrameColor( const QColor& theColor ) +{ + myForegroundFrameColor = theColor; +} + +//================================================================ +// Function : setForegroundFrameLineWidth +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setForegroundFrameLineWidth( double theLineWidth ) +{ + myForegroundFrameLineWidth = theLineWidth; +} + +//================================================================ +// Function : updateForeground +// Purpose : +//================================================================ +void GraphicsView_ViewPort::updateForeground() +{ + if( myIsForegroundEnabled ) + { + if( !myForegroundItem ) + myForegroundItem = myScene->addRect( QRectF(), QPen(), QBrush( Qt::white ) ); + myForegroundItem->setZValue( -2 ); + + QPointF aPoint = QPointF(); + QRectF aRect( aPoint, myForegroundSize ); + aRect.adjust( -myForegroundMargin, -myForegroundMargin, + myForegroundMargin, myForegroundMargin ); + myForegroundItem->setRect( aRect ); + + QBrush aBrush = myForegroundItem->brush(); + aBrush.setColor( myForegroundColor ); + myForegroundItem->setBrush( aBrush ); + + QPen aPen = myForegroundItem->pen(); + aPen.setColor( myForegroundFrameColor ); + aPen.setWidthF( myForegroundFrameLineWidth ); + myForegroundItem->setPen( aPen ); + + myForegroundItem->setVisible( true ); + + myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) ); + } + else + { + if( myForegroundItem ) + myForegroundItem->setVisible( false ); + } + + updateGrid(); // foreground size could be changed +} + +//================================================================ +// Function : setGridEnabled +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setGridEnabled( bool theState ) +{ + myIsGridEnabled = theState; +} + +//================================================================ +// Function : setGridCellSize +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setGridCellSize( int theCellSize ) +{ + myGridCellSize = theCellSize; +} + +//================================================================ +// Function : setGridLineStyle +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setGridLineStyle( int theLineStyle ) +{ + myGridLineStyle = theLineStyle; +} + +//================================================================ +// Function : setGridLineColor +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setGridLineColor( const QColor& theLineColor ) +{ + myGridLineColor = theLineColor; +} + +//================================================================ +// Function : updateGrid +// Purpose : +//================================================================ +void GraphicsView_ViewPort::updateGrid() +{ + if( myIsGridEnabled ) + { + if( !myGridItem ) + myGridItem = myScene->addPath( QPainterPath() ); + myGridItem->setZValue( -1 ); + + double aWidth = myForegroundSize.width(); + double aHeight = myForegroundSize.height(); + + int aGridNbX = int( aWidth / myGridCellSize ) + 1; + int aGridNbY = int( aHeight / myGridCellSize ) + 1; + + int anIndex; + QPainterPath aPath; + for( anIndex = 0; anIndex < aGridNbX; anIndex++ ) + { + double x = myGridCellSize * (double)anIndex; + aPath.moveTo( x, 0 ); + aPath.lineTo( x, aHeight ); + } + for( anIndex = 0; anIndex < aGridNbY; anIndex++ ) + { + double y = myGridCellSize * (double)anIndex; + aPath.moveTo( 0, y ); + aPath.lineTo( aWidth, y ); + } + myGridItem->setPath( aPath ); + + QPen aPen = myGridItem->pen(); + aPen.setStyle( (Qt::PenStyle)myGridLineStyle ); + aPen.setColor( myGridLineColor ); + myGridItem->setPen( aPen ); + + myGridItem->setVisible( true ); + } + else + { + if( myGridItem ) + myGridItem->setVisible( false ); + } +} + +//================================================================ +// Function : reset +// Purpose : +//================================================================ +void GraphicsView_ViewPort::reset() +{ + fitAll(); +} + +//================================================================ +// Function : pan +// Purpose : +//================================================================ +void GraphicsView_ViewPort::pan( double theDX, double theDY ) +{ + myIsTransforming = true; + + if( myNameLabel ) + myNameLabel->setAcceptMoveEvents( false ); + + if( QScrollBar* aHBar = horizontalScrollBar() ) + aHBar->setValue( aHBar->value() - theDX ); + if( QScrollBar* aVBar = verticalScrollBar() ) + aVBar->setValue( aVBar->value() + theDY ); + + if( myNameLabel ) + myNameLabel->setAcceptMoveEvents( true ); + + myIsTransforming = false; +} + +//================================================================ +// Function : setCenter +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setCenter( double theX, double theY ) +{ + myIsTransforming = true; + + setTransform( myCurrentTransform ); + centerOn( theX, theY ); + + myIsTransforming = false; +} + +//================================================================ +// Function : zoom +// Purpose : +//================================================================ +void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, double theY2 ) +{ + myIsTransforming = true; + + double aDX = theX2 - theX1; + double aDY = theY2 - theY1; + double aZoom = sqrt( aDX * aDX + aDY * aDY ) / 100 + 1; + aZoom = ( aDX > 0 ) ? aZoom : 1 / aZoom; + + QTransform aTransform = transform(); + aTransform.scale( aZoom, aZoom ); + double aM11 = aTransform.m11(); + double aM22 = aTransform.m22(); + // increasing of diagonal coefficients (>300) leads to a crash sometimes + // at the values of 100 some primitives are drawn incorrectly + if( qMax( aM11, aM22 ) < 100 ) + setTransform( aTransform ); + + myIsTransforming = false; +} + +//================================================================ +// Function : fitRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::fitRect( const QRectF& theRect ) +{ + myIsTransforming = true; + + fitInView( theRect, Qt::KeepAspectRatio ); + + myIsTransforming = false; +} + +//================================================================ +// Function : fitSelect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::fitSelect() +{ + myIsTransforming = true; + + QRectF aGlobalRect; + for( initSelected(); moreSelected(); nextSelected() ) + { + if( GraphicsView_Object* aMovingObject = selectedObject() ) + { + QRectF aRect = aMovingObject->getRect(); + if( aGlobalRect.isNull() ) + aGlobalRect = aRect; + else + aGlobalRect |= aRect; + } + } + + if( !aGlobalRect.isNull() ) + { + double aGap = qMax( aGlobalRect.width(), aGlobalRect.height() ) / 5; + aGlobalRect.adjust( -aGap, -aGap, aGap, aGap ); + fitInView( aGlobalRect, Qt::KeepAspectRatio ); + } + + myIsTransforming = false; +} + +//================================================================ +// Function : fitAll +// Purpose : +//================================================================ +void GraphicsView_ViewPort::fitAll( bool theKeepScale ) +{ + myIsTransforming = true; + + if( theKeepScale ) + myCurrentTransform = transform(); + + double aGap = myFitAllGap; + QRectF aRect = objectsBoundingRect( true ); + fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio ); + + myIsTransforming = false; +} + +//================================================================ +// Function : fitWidth +// Purpose : +//================================================================ +void GraphicsView_ViewPort::fitWidth() +{ + myIsTransforming = true; + + double aGap = myFitAllGap; + QRectF aRect = objectsBoundingRect( true ); + + double aTop = aRect.top(); + double aLeft = aRect.left(); + double aMargin = 10; + + aRect.setY( aRect.center().y() ); + aRect.setHeight( aMargin ); + + fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio ); + ensureVisible( aLeft, aTop, aMargin, aMargin, 0, aGap ); + + myIsTransforming = false; +} + +//================================================================ +// Function : currentBlock +// Purpose : +//================================================================ +GraphicsView_ViewPort::BlockStatus GraphicsView_ViewPort::currentBlock() +{ + if( isDragging() && !myDragPosition.isNull() ) + return BlockStatus( BS_Selection ); + + if( myAreSelectionPointsInitialized && ( myFirstSelectionPoint != myLastSelectionPoint ) ) + return BlockStatus( BS_Selection ); + + if( isPulling() ) + return BlockStatus( BS_Selection ); + + return BS_NoBlock; +} + +//================================================================ +// Function : highlight +// Purpose : +//================================================================ +void GraphicsView_ViewPort::highlight( double theX, double theY ) +{ + myHighlightX = theX; + myHighlightY = theY; + + bool anIsHighlighted = false; + bool anIsOnObject = false; + + GraphicsView_Object* aPreviousHighlightedObject = myHighlightedObject; + GraphicsView_Object* aHighlightedObject = 0; + + GraphicsView_ObjectList aList = getObjects( true ); + GraphicsView_ObjectListIterator anIter( aList ); + anIter.toBack(); // objects with higher priority have to be checked earlier + while( anIter.hasPrevious() ) + { + if( GraphicsView_Object* anObject = anIter.previous() ) + { + if( anObject->isVisible() && anObject->isSelectable() ) + { + QRectF aRect = anObject->getRect(); + if( !aRect.isNull() && aRect.contains( theX, theY ) ) + { + anIsOnObject = true; + anIsHighlighted = anObject->highlight( theX, theY ); + } + + if( anIsHighlighted ) + { + aHighlightedObject = anObject; + break; + } + } + } + } + + if( !anIsOnObject ) + { + anIter = aList; + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + anObject->unhighlight(); + + myHighlightedObject = 0; + return; + } + else if( !myHighlightedObject && anIsHighlighted ) + { + myHighlightedObject = aHighlightedObject; + } + else if( myHighlightedObject && !anIsHighlighted ) + { + myHighlightedObject->unhighlight(); + myHighlightedObject = 0; + } + else if( myHighlightedObject && anIsHighlighted ) + { + myHighlightedObject->highlight( theX, theY ); + if( myHighlightedObject != aHighlightedObject ) + { + myHighlightedObject->unhighlight(); + myHighlightedObject = aHighlightedObject; + } + } +} + +//================================================================ +// Function : clearHighlighted +// Purpose : +//================================================================ +void GraphicsView_ViewPort::clearHighlighted() +{ + if( myHighlightedObject ) + { + myHighlightedObject->unhighlight(); + myHighlightedObject = 0; + } +} + +//================================================================ +// Function : select +// Purpose : +//================================================================ +int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend ) +{ + GV_SelectionStatus aStatus = GVSS_Invalid; + if( theRect.isNull() ) // point selection + { + if( myHighlightedObject ) + { + if( mySelectedObjects.count() == 1 && + mySelectedObjects.first() == myHighlightedObject ) + aStatus = GVSS_LocalChanged; + + if( !theIsAppend ) + { + GraphicsView_ObjectListIterator anIter( mySelectedObjects ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + if( myHighlightedObject != anObject ) + anObject->unselect(); + + if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid ) + aStatus = GVSS_GlobalChanged; + mySelectedObjects.clear(); + } + else if( myHighlightedObject->isSelected() && aStatus != GVSS_LocalChanged ) + { + mySelectedObjects.removeAll( myHighlightedObject ); + myHighlightedObject->unselect(); + + if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid ) + aStatus = GVSS_GlobalChanged; + + return aStatus; + } + + if( myHighlightedObject->select( myHighlightX, myHighlightY, QRectF() ) && + mySelectedObjects.indexOf( myHighlightedObject ) == -1 ) + { + mySelectedObjects.append( myHighlightedObject ); + if( aStatus == GVSS_Invalid ) + aStatus = GVSS_GlobalChanged; + } + else if( aStatus == GVSS_LocalChanged ) + aStatus = GVSS_GlobalChanged; + + return aStatus; + } + + if( !myHighlightedObject ) + { + if( !theIsAppend ) + { + GraphicsView_ObjectListIterator anIter( mySelectedObjects ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + if( myHighlightedObject != anObject ) + anObject->unselect(); + + if( !mySelectedObjects.isEmpty() ) + aStatus = GVSS_GlobalChanged; + mySelectedObjects.clear(); + } + return aStatus; + } + + return GVSS_NoChanged; + } + else // rectangle selection + { + aStatus = GVSS_NoChanged; + + bool updateAll = false; + if( !theIsAppend ) + { + if( !mySelectedObjects.isEmpty() ) + aStatus = GVSS_GlobalChanged; + + GraphicsView_ObjectListIterator anIter( mySelectedObjects ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + if( myHighlightedObject != anObject ) + anObject->unselect(); + mySelectedObjects.clear(); + } + + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + if( anObject->isVisible() && anObject->isSelectable() ) + { + bool anIsSelected = false; + QRectF aRect = anObject->getRect(); + if( theRect.contains( aRect ) ) + anIsSelected = anObject->select( myHighlightX, myHighlightY, theRect ); + + if( anIsSelected && mySelectedObjects.indexOf( anObject ) == -1 ) + { + mySelectedObjects.append( anObject ); + aStatus = GVSS_GlobalChanged; + } + } + } + } + } + return aStatus; +} + +//================================================================ +// Function : clearSelected +// Purpose : +//================================================================ +void GraphicsView_ViewPort::clearSelected() +{ + GraphicsView_ObjectListIterator anIter( mySelectedObjects ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + anObject->unselect(); + mySelectedObjects.clear(); +} + +//================================================================ +// Function : setSelected +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setSelected( GraphicsView_Object* theObject ) +{ + if( theObject ) + { + theObject->setSelected( true ); + mySelectedObjects.append( theObject ); + } +} + +//================================================================ +// Function : nbSelected +// Purpose : +//================================================================ +int GraphicsView_ViewPort::nbSelected() const +{ + return mySelectedObjects.count(); +} + +//================================================================ +// Function : initSelected +// Purpose : +//================================================================ +void GraphicsView_ViewPort::initSelected() +{ + mySelectionIterator = 0; +} + +//================================================================ +// Function : moreSelected +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::moreSelected() +{ + return mySelectionIterator < nbSelected(); +} + +//================================================================ +// Function : nextSelected +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::nextSelected() +{ + if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() ) + { + mySelectionIterator++; + return true; + } + return false; +} + +//================================================================ +// Function : selectedObject +// Purpose : +//================================================================ +GraphicsView_Object* GraphicsView_ViewPort::selectedObject() +{ + if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() ) + return mySelectedObjects[ mySelectionIterator ]; + return 0; +} + +//================================================================ +// Function : startSelectByRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::startSelectByRect( int x, int y ) +{ + if( !myAreSelectionPointsInitialized ) + { + myFirstSelectionPoint = QPoint( x, y ); + myLastSelectionPoint = QPoint( x, y ); + myAreSelectionPointsInitialized = true; + } + + if( !myRectBand ) + { + myRectBand = new QRubberBand( QRubberBand::Rectangle, this ); + QPalette palette; + palette.setColor( myRectBand->foregroundRole(), Qt::white ); + myRectBand->setPalette( palette ); + } + myRectBand->hide(); +} + +//================================================================ +// Function : drawSelectByRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::drawSelectByRect( int x, int y ) +{ + if( myAreSelectionPointsInitialized ) + { + myRectBand->hide(); + + myLastSelectionPoint.setX( x ); + myLastSelectionPoint.setY( y ); + + QRect aRect = selectionRect(); + myRectBand->setGeometry( aRect ); + myRectBand->setVisible( aRect.isValid() ); + } +} + +//================================================================ +// Function : isSelectByRect +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::isSelectByRect() const +{ + return myAreSelectionPointsInitialized; +} + +//================================================================ +// Function : finishSelectByRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::finishSelectByRect() +{ + if( myAreSelectionPointsInitialized ) + { + if( myRectBand ) + { + myRectBand->hide(); + delete myRectBand; + myRectBand = 0; + } + + myAreSelectionPointsInitialized = false; + } +} + +//================================================================ +// Function : selectionRect +// Purpose : +//================================================================ +QRect GraphicsView_ViewPort::selectionRect() +{ + QRect aRect; + if( myAreSelectionPointsInitialized ) + { + aRect.setLeft( qMin( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) ); + aRect.setTop( qMin( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) ); + aRect.setRight( qMax( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) ); + aRect.setBottom( qMax( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) ); + } + return aRect; +} + +//================================================================ +// Function : dragObjects +// Purpose : +//================================================================ +void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e ) +{ + GraphicsView_Object* anObject = getHighlightedObject(); + + if( myDragPosition.isNull() ) + { + myDragPosition = e->scenePos(); + return; + } + + GraphicsView_ObjectList anObjectsToMove; + if( anObject && anObject->isMovable() && ( e->buttons() & Qt::LeftButton ) ) + { + if( anObject->isSelected() ) + { + for( initSelected(); moreSelected(); nextSelected() ) + if( GraphicsView_Object* aMovingObject = selectedObject() ) + if( aMovingObject->isMovable() ) + anObjectsToMove.append( aMovingObject ); + } + else + anObjectsToMove.append( anObject ); + } + else if( nbSelected() && ( e->buttons() & Qt::MidButton ) ) + { + for( initSelected(); moreSelected(); nextSelected() ) + if( GraphicsView_Object* aMovingObject = selectedObject() ) + if( aMovingObject->isMovable() ) + anObjectsToMove.append( aMovingObject ); + } + + if( anObjectsToMove.isEmpty() ) + return; + + double aDX = e->scenePos().x() - myDragPosition.x(); + double aDY = e->scenePos().y() - myDragPosition.y(); + + bool anIsMovingByXAllowed = true, anIsMovingByYAllowed = true; + GraphicsView_ObjectListIterator anIter( anObjectsToMove ); + while( anIter.hasNext() ) + if( GraphicsView_Object* aMovingObject = anIter.next() ) + { + if( !aMovingObject->isMovingByXAllowed( aDX ) ) + anIsMovingByXAllowed = false; + if( !aMovingObject->isMovingByYAllowed( aDY ) ) + anIsMovingByYAllowed = false; + } + + if( !anIsMovingByXAllowed && !anIsMovingByYAllowed ) + return; // myDragPosition shouldn't be changed + + if( !anIsMovingByXAllowed ) + aDX = 0; + + if( !anIsMovingByYAllowed ) + aDY = 0; + + anIter = anObjectsToMove; + while( anIter.hasNext() ) + if( GraphicsView_Object* aMovingObject = anIter.next() ) + aMovingObject->move( aDX, aDY ); + + if( anIsMovingByXAllowed ) + myDragPosition.setX( e->scenePos().x() ); + + if( anIsMovingByYAllowed ) + myDragPosition.setY( e->scenePos().y() ); +} + +//================================================================ +// Function : startPulling +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::startPulling( const QPointF& thePoint ) +{ + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + QRectF aRect = anObject->getPullingRect(); + if( aRect.contains( thePoint ) && anObject->startPulling( thePoint ) ) + { + myIsPulling = true; + myPullingObject = anObject; + setCursor( *getHandCursor() ); + return true; + } + } + } + return false; +} + +//================================================================ +// Function : drawPulling +// Purpose : +//================================================================ +void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint ) +{ + GraphicsView_Object* aLockedObject = 0; + + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + if( !anObject->isVisible() ) + continue; + + QRectF aRect = anObject->getPullingRect(); + if( aRect.contains( thePoint ) && anObject->portContains( thePoint ) ) + { + aLockedObject = anObject; + break; + } + } + } + + myPullingObject->pull( thePoint, aLockedObject ); +} + +//================================================================ +// Function : finishPulling +// Purpose : +//================================================================ +void GraphicsView_ViewPort::finishPulling() +{ + myIsPulling = false; + myPullingObject->finishPulling(); + setCursor( *getDefaultCursor() ); +} + +//================================================================ +// Function : onBoundingRectChanged +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onBoundingRectChanged() +{ + if( myIsTraceBoundingRectEnabled ) + { + QRectF aRect = objectsBoundingRect(); + myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) ); + } +} + +//================================================================ +// Function : onKeyEvent +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onKeyEvent( QKeyEvent* e ) +{ + emit vpKeyEvent( e ); +} + +//================================================================ +// Function : onMouseEvent +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e ) +{ + emit vpMouseEvent( e ); + + bool anIsHandled = false; + switch( e->type() ) + { + case QEvent::GraphicsSceneMousePress: + { + if( testInteractionFlags( EditFlags ) && nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMousePress( e ); + + if( !anIsHandled && testInteractionFlags( Dragging ) ) + { + bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey(); + if( ( getHighlightedObject() && + getHighlightedObject()->isMovable() && + !( anAccel || e->button() == Qt::RightButton ) ) || + ( nbSelected() && !anAccel && e->button() == Qt::MidButton ) ) + myIsDragging = true; + } + break; + } + case QEvent::GraphicsSceneMouseMove: + { + if( testInteractionFlags( EditFlags ) && nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMousePress( e ); + + if( !anIsHandled && !isPulling() && myIsDragging ) + dragObjects( e ); + break; + } + case QEvent::GraphicsSceneMouseRelease: + { + if( testInteractionFlags( EditFlags ) && nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMousePress( e ); + + if( !anIsHandled && !isPulling() && myIsDragging ) + { + emit vpObjectBeforeMoving(); + + bool anIsMoved = false; + for( initSelected(); moreSelected(); nextSelected() ) + if( GraphicsView_Object* aMovingObject = selectedObject() ) + anIsMoved = aMovingObject->finishMove() || anIsMoved; + + if( GraphicsView_Object* aMovingObject = getHighlightedObject() ) + anIsMoved = aMovingObject->finishMove() || anIsMoved; + + myIsDragging = false; + myDragPosition = QPointF(); + + emit vpObjectAfterMoving( anIsMoved ); + } + break; + } + case QEvent::GraphicsSceneMouseDoubleClick: + break; // do nothing, just emit the signal + default: + break; + } +} + +//================================================================ +// Function : onWheelEvent +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onWheelEvent( QGraphicsSceneWheelEvent* e ) +{ + emit vpWheelEvent( e ); +} + +//================================================================ +// Function : onContextMenuEvent +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onContextMenuEvent( QGraphicsSceneContextMenuEvent* e ) +{ + emit vpContextMenuEvent( e ); +} + +//================================================================ +// Function : scrollContentsBy +// Purpose : +//================================================================ +void GraphicsView_ViewPort::scrollContentsBy( int theDX, int theDY ) +{ + if( myNameLabel ) + myNameLabel->setAcceptMoveEvents( false ); + + QGraphicsView::scrollContentsBy( theDX, theDY ); + + if( myNameLabel ) + myNameLabel->setAcceptMoveEvents( true ); +} diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h new file mode 100644 index 000000000..93b606d8a --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -0,0 +1,295 @@ +// 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: GraphicsView_ViewPort.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWPORT_H +#define GRAPHICSVIEW_VIEWPORT_H + +#include "GraphicsView.h" + +#include "GraphicsView_Defs.h" + +#include + +class QGridLayout; +class QRubberBand; + +class GraphicsView_Object; +class GraphicsView_Scene; + +/* + Class : GraphicsView_ViewPort + Description : View port of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_ViewPort : public QGraphicsView +{ + Q_OBJECT + +public: + class NameLabel; + + enum InteractionFlags + { + Highlighting = 0x0001, // not implemented yet + Selecting = 0x0002, // not implemented yet + Dragging = 0x0004, + Pulling = 0x0008, + WheelScaling = 0x0010, + EditFlags = Dragging | Pulling | WheelScaling, + AllFlags = Highlighting | Selecting | Dragging | Pulling | WheelScaling + }; + + enum BlockStatus + { + BS_NoBlock = 0x0000, + BS_Selection = 0x0001, // and highlighting + BS_Dragging = 0x0002 // currently unused + }; + + enum NamePosition + { + NP_None = 0, + NP_TopLeft = 1, + NP_TopRight = 2, + NP_BottomLeft = 3, + NP_BottomRight = 4 + }; + +public: + GraphicsView_ViewPort( QWidget* theParent ); + ~GraphicsView_ViewPort(); + +public: + GraphicsView_Scene* getScene() { return myScene; } + void addItem( QGraphicsItem* theItem ); + void removeItem( QGraphicsItem* theItem ); + + GraphicsView_ObjectList getObjects( bool theIsSortSelected = false ) const; + + QRectF objectsBoundingRect( bool theOnlyVisible = false ) const; + + QImage dumpView( bool theWholeScene = false, + QSizeF theSize = QSizeF() ); + +public: + // scene + void setSceneGap( double theSceneGap ); + void setFitAllGap( double theFitAllGap ); + void setTraceBoundingRectEnabled( bool theState ); + + // interaction flags + void setInteractionFlags( const int ); + void clearInteractionFlags( const int ); + bool testInteractionFlags( const int ) const; + + // view name + void setViewNamePosition( NamePosition thePosition, + bool theIsForced = false ); + void setViewName( const QString& theName ); + + // background / foreground + QColor backgroundColor() const; + void setBackgroundColor( const QColor& theColor ); + + bool isForegroundEnabled() const { return myIsForegroundEnabled; } + void setForegroundEnabled( bool theState ); + + QSizeF foregroundSize() const { return myForegroundSize; } + void setForegroundSize( const QSizeF& theRect ); + + double foregroundMargin() const { return myForegroundMargin; } + void setForegroundMargin( double theMargin ); + + QColor foregroundColor() const { return myForegroundColor; } + void setForegroundColor( const QColor& theColor ); + + QColor foregroundFrameColor() const { return myForegroundFrameColor; } + void setForegroundFrameColor( const QColor& theColor ); + + double foregroundFrameLineWidth() const { return myForegroundFrameLineWidth; } + void setForegroundFrameLineWidth( double theLineWidth ); + + void updateForeground(); + + // grid + void setGridEnabled( bool theState ); + void setGridCellSize( int theCellSize ); + void setGridLineStyle( int theLineStyle ); + void setGridLineColor( const QColor& theLineColor ); + void updateGrid(); + + // transformation + void reset(); + void pan( double theDX, double theDY ); + void setCenter( double theX, double theY ); + void zoom( double theX1, double theY1, double theX2, double theY2 ); + void fitRect( const QRectF& theRect ); + void fitSelect(); + void fitAll( bool theKeepScale = false ); + void fitWidth(); + + bool isTransforming() const { return myIsTransforming; } + + // block status + BlockStatus currentBlock(); + + // highlighting + virtual void highlight( double theX, double theY ); + void clearHighlighted(); + + GraphicsView_Object* getHighlightedObject() const { return myHighlightedObject; } + + // selection + virtual int select( const QRectF& theRect, bool theIsAppend ); + void clearSelected(); + void setSelected( GraphicsView_Object* theObject ); + + int nbSelected() const; + void initSelected(); + bool moreSelected(); + bool nextSelected(); + GraphicsView_Object* selectedObject(); + + const GraphicsView_ObjectList& getSelectedObjects() const { return mySelectedObjects; } + + + // rectangle selection + void startSelectByRect( int x, int y ); + void drawSelectByRect( int x, int y ); + void finishSelectByRect(); + bool isSelectByRect() const; + QRect selectionRect(); + + // dragging + bool isDragging() { return myIsDragging; } + + // pulling + bool startPulling( const QPointF& ); + void drawPulling( const QPointF& ); + void finishPulling(); + bool isPulling() const { return myIsPulling; } + +public: + static void createCursors(); + static void destroyCursors(); + static QCursor* getDefaultCursor() { return defCursor; } + static QCursor* getHandCursor() { return handCursor; } + static QCursor* getPanCursor() { return panCursor; } + static QCursor* getPanglCursor() { return panglCursor; } + static QCursor* getZoomCursor() { return zoomCursor; } + +public slots: + void onBoundingRectChanged(); + +protected slots: + void onKeyEvent( QKeyEvent* ); + void onMouseEvent( QGraphicsSceneMouseEvent* ); + void onWheelEvent( QGraphicsSceneWheelEvent* ); + void onContextMenuEvent( QGraphicsSceneContextMenuEvent* ); + +protected: + virtual void scrollContentsBy( int theDX, int theDY ); + +signals: + void vpKeyEvent( QKeyEvent* ); + void vpMouseEvent( QGraphicsSceneMouseEvent* ); + void vpWheelEvent( QGraphicsSceneWheelEvent* ); + void vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ); + + void vpObjectBeforeMoving(); + void vpObjectAfterMoving( bool ); + +private: + void initialize(); + void cleanup(); + + void dragObjects( QGraphicsSceneMouseEvent* ); + +private: + static int nCounter; + static QCursor* defCursor; + static QCursor* handCursor; + static QCursor* panCursor; + static QCursor* panglCursor; + static QCursor* zoomCursor; + +private: + // scene + GraphicsView_Scene* myScene; + double mySceneGap; + double myFitAllGap; + bool myIsTraceBoundingRectEnabled; + GraphicsView_ObjectList myObjects; + + // interaction flags + int myInteractionFlags; + + // view name + NameLabel* myNameLabel; + NamePosition myNamePosition; + QGridLayout* myNameLayout; + + // foreground + bool myIsForegroundEnabled; + QSizeF myForegroundSize; + double myForegroundMargin; + QColor myForegroundColor; + QColor myForegroundFrameColor; + double myForegroundFrameLineWidth; + QGraphicsRectItem* myForegroundItem; + + // grid + bool myIsGridEnabled; + int myGridCellSize; + int myGridLineStyle; + QColor myGridLineColor; + QGraphicsPathItem* myGridItem; + + // transformation + bool myIsTransforming; + QTransform myCurrentTransform; + + // highlighting + GraphicsView_Object* myHighlightedObject; + double myHighlightX; + double myHighlightY; + + // selection + GraphicsView_ObjectList mySelectedObjects; + int mySelectionIterator; + + // rectangle selection + QRubberBand* myRectBand; + QPoint myFirstSelectionPoint; + QPoint myLastSelectionPoint; + bool myAreSelectionPointsInitialized; + + // dragging + int myIsDragging; + QPointF myDragPosition; + bool myIsDragPositionInitialized; + + // pulling + bool myIsPulling; + GraphicsView_Object* myPullingObject; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewTransformer.cxx b/src/GraphicsView/GraphicsView_ViewTransformer.cxx new file mode 100644 index 000000000..06e794a2f --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewTransformer.cxx @@ -0,0 +1,293 @@ +// 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: GraphicsView_ViewTransformer.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_ViewTransformer.h" + +#include "GraphicsView_Scene.h" +#include "GraphicsView_ViewPort.h" +#include "GraphicsView_Viewer.h" + +#include +#include +#include + +int GraphicsView_ViewTransformer::panBtn = Qt::MidButton; +int GraphicsView_ViewTransformer::zoomBtn = Qt::LeftButton; +int GraphicsView_ViewTransformer::fitRectBtn = Qt::LeftButton; +int GraphicsView_ViewTransformer::panGlobalBtn = Qt::LeftButton; +int GraphicsView_ViewTransformer::acccelKey = Qt::ControlModifier; + +//======================================================================= +// Name : GraphicsView_ViewTransformer +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewTransformer::GraphicsView_ViewTransformer( GraphicsView_Viewer* v, int type ) +: QObject( 0 ), + myViewer( v ), + myType( type ), + myMajorBtn( Qt::NoButton ), + myButtonState( 0 ), + myRectBand( 0 ) +{ + if( myType == GraphicsView_Viewer::Pan || + myType == GraphicsView_Viewer::Zoom || + myType == GraphicsView_Viewer::PanGlobal || + myType == GraphicsView_Viewer::FitRect ) + initTransform( true ); +} + +//======================================================================= +// Name : GraphicsView_ViewTransformer +// Purpose : Destructor +//======================================================================= +GraphicsView_ViewTransformer::~GraphicsView_ViewTransformer() +{ + if( myType == GraphicsView_Viewer::Pan || + myType == GraphicsView_Viewer::Zoom || + myType == GraphicsView_Viewer::PanGlobal || + myType == GraphicsView_Viewer::FitRect ) + initTransform( false ); + + endDrawRect(); +} + +//================================================================ +// Function : initTransform +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::initTransform( bool init ) +{ + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + { + if( GraphicsView_Scene* aScene = aViewPort->getScene() ) + { + if( init ) + { + mySavedCursor = aViewPort->cursor(); + mySavedMouseTrack = aViewPort->hasMouseTracking(); + aViewPort->setMouseTracking( false ); + aScene->installEventFilter( this ); + } + else + { + aScene->removeEventFilter( this ); + aViewPort->setMouseTracking( mySavedMouseTrack ); + aViewPort->setCursor( mySavedCursor ); + } + } + } +} + +//================================================================ +// Function : exec +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::exec() +{ + GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort(); + if( !aViewPort ) + return; + + switch( myType ) + { + case GraphicsView_Viewer::Zoom: + myMajorBtn = zoomButton(); + aViewPort->setCursor( *aViewPort->getZoomCursor() ); + break; + case GraphicsView_Viewer::Pan: + myMajorBtn = panButton(); + aViewPort->setCursor( *aViewPort->getPanCursor() ); + break; + case GraphicsView_Viewer::PanGlobal: + myMajorBtn = panGlobalButton(); + aViewPort->setCursor( *aViewPort->getPanglCursor() ); + aViewPort->fitAll( true ); + break; + case GraphicsView_Viewer::FitRect: + myMajorBtn = fitRectButton(); + aViewPort->setCursor( *aViewPort->getHandCursor() ); + break; + case GraphicsView_Viewer::Reset: + aViewPort->reset(); + onTransform( Finished ); + break; + case GraphicsView_Viewer::FitAll: + aViewPort->fitAll(); + onTransform( Finished ); + break; + case GraphicsView_Viewer::FitSelect: + aViewPort->fitSelect(); + onTransform( Finished ); + break; + case GraphicsView_Viewer::FitWidth: + aViewPort->fitWidth(); + onTransform( Finished ); + break; + default: break; + } +} + +//================================================================ +// Function : eventFilter +// Purpose : +//================================================================ +bool GraphicsView_ViewTransformer::eventFilter( QObject* o, QEvent* e ) +{ + switch( e->type() ) + { + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseRelease: + { + TransformState state = InProcess; + QGraphicsSceneMouseEvent* me = ( QGraphicsSceneMouseEvent* )e; + + myButtonState = me->buttons(); + if ( e->type() == QEvent::GraphicsSceneMousePress ) + myButtonState |= me->button(); + + if ( e->type() == QEvent::GraphicsSceneMouseRelease ) + myButtonState |= me->button(); + + int mouseOnlyState = ( myButtonState & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) ); + if ( myStart.isNull() ) + { + state = Begin; + myStart = myViewer->getActiveViewPort()->mapFromScene( me->scenePos() ); + myMajorBtn = mouseOnlyState; + } + + if ( e->type() == QEvent::GraphicsSceneMouseRelease ) + state = Finished; + + myCurr = myViewer->getActiveViewPort()->mapFromScene( me->scenePos() ); + onTransform( state ); + return true; + } + default: break; + } + return QObject::eventFilter( o, e ); +} + +//================================================================ +// Function : onTransform +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::onTransform( TransformState state ) +{ + GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort(); + if( !aViewPort || aViewPort->isTransforming() ) + return; + + bool doTrsf = ( myButtonState & myMajorBtn ); + switch ( myType ) + { + case GraphicsView_Viewer::Zoom: + if ( state != Finished && doTrsf ) + { + aViewPort->zoom( myStart.x(), myStart.y(), myCurr.x(), myCurr.y() ); + myStart = myCurr; + } + break; + case GraphicsView_Viewer::Pan: + if ( state != Finished && doTrsf ) + { + aViewPort->pan( myCurr.x() - myStart.x(), myStart.y() - myCurr.y() ); + myStart = myCurr; + } + break; + case GraphicsView_Viewer::PanGlobal: + if ( state == Finished ) + { + QPointF aPoint = aViewPort->mapToScene( myCurr.toPoint() ); + aViewPort->setCenter( aPoint.x(), aPoint.y() ); + } + break; + case GraphicsView_Viewer::FitRect: + if ( doTrsf ) + { + QRectF aRect( qMin( myStart.x(), myCurr.x() ), qMin( myStart.y(), myCurr.y() ), + qAbs( myStart.x() - myCurr.x() ), qAbs( myStart.y() - myCurr.y() ) ); + if ( !aRect.isEmpty() ) + { + switch ( state ) + { + case Finished: + aRect = aViewPort->mapToScene( aRect.toRect() ).boundingRect(); + aViewPort->fitRect( aRect ); + break; + default: + drawRect( aRect ); + break; + } + } + } + break; + default: + break; + } + + if ( state == Finished ) + myViewer->activateTransform( GraphicsView_Viewer::NoTransform ); +} + +//================================================================ +// Function : drawRect +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::drawRect(const QRectF& theRect) +{ + if ( !myRectBand ) + { + myRectBand = new QRubberBand( QRubberBand::Rectangle, myViewer->getActiveViewPort() ); + QPalette palette; + palette.setColor(myRectBand->foregroundRole(), Qt::white); + myRectBand->setPalette(palette); + } + myRectBand->hide(); + + myRectBand->setGeometry( theRect.toRect() ); + myRectBand->setVisible( theRect.isValid() ); +} + +//================================================================ +// Function : endDrawRect +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::endDrawRect() +{ + if ( myRectBand ) + { + myRectBand->hide(); + delete myRectBand; + myRectBand = 0; + } +} + +//================================================================ +// Function : GraphicsView_ViewTransformer +// Purpose : +//================================================================ +int GraphicsView_ViewTransformer::type() const +{ + return myType; +} diff --git a/src/GraphicsView/GraphicsView_ViewTransformer.h b/src/GraphicsView/GraphicsView_ViewTransformer.h new file mode 100644 index 000000000..ee5aa9e3e --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewTransformer.h @@ -0,0 +1,95 @@ +// 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: GraphicsView_ViewTransformer.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWTRANSFORMER_H +#define GRAPHICSVIEW_VIEWTRANSFORMER_H + +#include "GraphicsView.h" + +#include +#include + +class QRectF; +class QRubberBand; + +class GraphicsView_Viewer; + +/* + Class : GraphicsView_ViewTransformer + Description : View transformer of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_ViewTransformer : public QObject +{ +public: + GraphicsView_ViewTransformer( GraphicsView_Viewer*, int type ); + ~GraphicsView_ViewTransformer(); + +public: + int type() const; + + static int accelKey() { return acccelKey; } + static void setAccelKey( int k ) { acccelKey = k; } + + static int zoomButton() { return zoomBtn; } + static void setZoomButton( int b ) { zoomBtn = b; } + + static int panButton() { return panBtn; } + static void setPanButton( int b ) { panBtn = b; } + + static int panGlobalButton() { return panGlobalBtn; } + static void setPanGlobalButton( int b ) { panGlobalBtn = b; } + + static int fitRectButton() { return fitRectBtn; } + static void setFitRectButton( int b ) { fitRectBtn = b; } + + virtual void exec(); + virtual bool eventFilter( QObject*, QEvent* ); + +protected: + enum TransformState { Begin, InProcess, Finished }; + virtual void onTransform( TransformState ); + void initTransform( bool ); + + void drawRect( const QRectF& theRect ); + void endDrawRect(); + +protected: + static int panBtn; + static int zoomBtn; + static int fitRectBtn; + static int panGlobalBtn; + + static int acccelKey; + + GraphicsView_Viewer* myViewer; + int myType; + QCursor mySavedCursor; + bool mySavedMouseTrack; + QPointF myStart; + QPointF myCurr; + int myButtonState; + int myMajorBtn; + + QRubberBand* myRectBand; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx new file mode 100644 index 000000000..c8982adf0 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -0,0 +1,504 @@ +// 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: GraphicsView_Viewer.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_Viewer.h" + +#include "GraphicsView_Object.h" +#include "GraphicsView_Selector.h" +#include "GraphicsView_Scene.h" +#include "GraphicsView_ViewFrame.h" +#include "GraphicsView_ViewPort.h" +#include "GraphicsView_ViewTransformer.h" + +#include + +#include +#include +#include +#include +#include +#include + +//======================================================================= +// Name : GraphicsView_Viewer +// Purpose : Constructor +//======================================================================= +GraphicsView_Viewer::GraphicsView_Viewer( const QString& title ) +: SUIT_ViewModel(), + mySelector( 0 ), + myTransformer( 0 ), + myIsInitialized( false ), + myIsImmediateSelectionEnabled( false ) +{ +} + +//======================================================================= +// Name : GraphicsView_Viewer +// Purpose : Destructor +//======================================================================= +GraphicsView_Viewer::~GraphicsView_Viewer() +{ + delete mySelector; +} + +//================================================================ +// Function : createView +// Purpose : +//================================================================ +SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop ) +{ + GraphicsView_ViewFrame* aViewFrame = new GraphicsView_ViewFrame( theDesktop, this ); + + connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ), + this, SLOT( onKeyEvent( QKeyEvent* ) ) ); + + connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ), + this, SLOT( onKeyEvent( QKeyEvent* ) ) ); + + connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ), + this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); + + connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ), + this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); + + connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ), + this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); + + connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ), + this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) ); + + return aViewFrame; +} + +//================================================================ +// Function : contextMenuPopup +// Purpose : +//================================================================ +void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup ) +{ + if( thePopup->actions().count() > 0 ) + thePopup->addSeparator(); + + thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) ); +} + +//================================================================ +// Function : getSelector +// Purpose : +//================================================================ +GraphicsView_Selector* GraphicsView_Viewer::getSelector() +{ + if( !mySelector ) + { + mySelector = new GraphicsView_Selector( this ); + if( mySelector ) + { + connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ), + this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) ); + connect( mySelector, SIGNAL( selSelectionCancel() ), + this, SLOT( onSelectionCancel() ) ); + } + } + return mySelector; +} + +//================================================================ +// Function : getActiveView +// Purpose : +//================================================================ +GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const +{ + if( SUIT_ViewManager* aViewManager = getViewManager() ) + return dynamic_cast( aViewManager->getActiveView() ); + return NULL; +} + +//================================================================ +// Function : getActiveViewPort +// Purpose : +//================================================================ +GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const +{ + if( GraphicsView_ViewFrame* aViewFrame = getActiveView() ) + return aViewFrame->getViewPort(); + return NULL; +} + +//================================================================ +// Function : getActiveScene +// Purpose : +//================================================================ +GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + return dynamic_cast( aViewPort->scene() ); + return NULL; +} + +//================================================================ +// Function : activateTransform +// Purpose : +//================================================================ +void GraphicsView_Viewer::activateTransform( int theType ) +{ + if( theType == NoTransform ) // finish current transform + { + if ( myTransformer ) + { + onTransformationFinished(); + delete myTransformer; + myTransformer = 0; + } + } + else // activate new transform + { + activateTransform( NoTransform ); + myTransformer = createTransformer( theType ); + onTransformationStarted(); + myTransformer->exec(); + } +} + +//================================================================ +// Function : setIsInitialized +// Purpose : +//================================================================ +void GraphicsView_Viewer::setIsInitialized( bool theFlag ) +{ + myIsInitialized = theFlag; +} + +//================================================================ +// Function : setIsImmediateSelectionEnabled +// Purpose : +//================================================================ +void GraphicsView_Viewer::setIsImmediateSelectionEnabled( bool theFlag ) +{ + myIsImmediateSelectionEnabled = theFlag; +} + +//================================================================ +// Function : createTransformer +// Purpose : +//================================================================ +GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType ) +{ + return new GraphicsView_ViewTransformer( this, theType ); +} + +//================================================================ +// Function : onTransformationStarted +// Purpose : +//================================================================ +void GraphicsView_Viewer::onTransformationStarted() +{ + if( GraphicsView_Selector* aSelector = getSelector() ) + { + aSelector->undetectAll(); + aSelector->lock( true ); // disable selection + } + + // watch events: any mouse/key event outside the + // viewport will be considered as the end of transform + if( myTransformer ) + qApp->installEventFilter( this ); +} + +//================================================================ +// Function : onTransformationFinished +// Purpose : +//================================================================ +void GraphicsView_Viewer::onTransformationFinished() +{ + if( GraphicsView_Selector* aSelector = getSelector() ) + aSelector->lock( false ); // enable selection + + // stop watching events + if( myTransformer ) + qApp->removeEventFilter( this ); +} + +//================================================================ +// Function : onKeyEvent +// Purpose : +//================================================================ +void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e ) +{ + switch( e->type() ) + { + case QEvent::KeyPress: + handleKeyPress( e ); + break; + case QEvent::KeyRelease: + handleKeyRelease( e ); + break; + default: break; + } +} + +//================================================================ +// Function : onMouseEvent +// Purpose : +//================================================================ +void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e ) +{ + switch( e->type() ) + { + case QEvent::GraphicsSceneMousePress: + handleMousePress( e ); + break; + case QEvent::GraphicsSceneMouseMove: + handleMouseMove( e ); + break; + case QEvent::GraphicsSceneMouseRelease: + handleMouseRelease( e ); + break; + default: break; + } +} + +//================================================================ +// Function : onWheelEvent +// Purpose : +//================================================================ +void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e ) +{ + switch( e->type() ) + { + case QEvent::GraphicsSceneWheel: + handleWheel( e ); + break; + default: break; + } +} + +//================================================================ +// Function : handleKeyPress +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e ) +{ +} + +//================================================================ +// Function : handleKeyRelease +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* e ) +{ +} + +//================================================================ +// Function : handleMousePress +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e ) +{ + // test accel for transforms + if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() ) + { + Qt::MouseButton bs = e->button(); + if ( bs == GraphicsView_ViewTransformer::zoomButton() ) + activateTransform( Zoom ); + else if ( bs == GraphicsView_ViewTransformer::panButton() ) + activateTransform( Pan ); + } + else // checking for other operations before selection in release event + { + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + if( e->button() == Qt::RightButton && + isImmediateSelectionEnabled() && + aViewPort->nbSelected() < 1 ) + { + // If the 'immediate selection' mode is enabled, + // try to perform selection before invoking context menu + bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); + getSelector()->select( QRectF(), append ); + } + else if( e->button() == Qt::LeftButton && + aViewPort->testInteractionFlags( GraphicsView_ViewPort::Pulling ) && + !aViewPort->isSelectByRect() && + !aViewPort->isDragging() && + aViewPort->startPulling( e->scenePos() ) ) + { + // Try to start pulling if rectangular selection is performed + aViewPort->finishSelectByRect(); + } + else if( e->button() == Qt::LeftButton && + !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) && + !aViewPort->getHighlightedObject() ) + { + // Start rectangular selection if pulling was not started + QPoint p = aViewPort->mapFromScene( e->scenePos() ); + aViewPort->startSelectByRect( p.x(), p.y() ); + } + } + } +} + +//================================================================ +// Function : handleMouseMove +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e ) +{ + // highlight for selection + bool dragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) ); + if ( !dragged ) + { + if ( getSelector() ) + getSelector()->detect( e->scenePos().x(), e->scenePos().y() ); + } + + // try to activate other operations + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + if( aViewPort->isPulling() ) + { + aViewPort->drawPulling( e->scenePos() ); + } + else if( e->button() == Qt::LeftButton && + aViewPort->testInteractionFlags( GraphicsView_ViewPort::Pulling ) && + !aViewPort->isSelectByRect() && + !aViewPort->isDragging() && + aViewPort->startPulling( e->scenePos() ) ) + { + aViewPort->finishSelectByRect(); + } + else if( !aViewPort->getHighlightedObject() ) + { + QPoint p = aViewPort->mapFromScene( e->scenePos() ); + aViewPort->drawSelectByRect( p.x(), p.y() ); + } + } +} + +//================================================================ +// Function : handleMouseRelease +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e ) +{ + // selection + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + if( e->button() == Qt::LeftButton && + !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) ) + { + if ( getSelector() ) + { + bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); + getSelector()->select( QRectF(), append ); + } + } + } + + // try to finish active operations + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + if( aViewPort->isPulling() ) + { + aViewPort->finishPulling(); + } + else if( !aViewPort->getHighlightedObject() ) + { + QRect aSelRect = aViewPort->selectionRect(); + aViewPort->finishSelectByRect(); + if ( getSelector() && !aSelRect.isNull() ) + { + bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); + QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect(); + getSelector()->select( aRect, append ); + } + } + } +} + +//================================================================ +// Function : handleWheel +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e ) +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + if( aViewPort->testInteractionFlags( GraphicsView_ViewPort::WheelScaling ) ) + { + bool anIsScaleUp = e->delta() > 0; + bool anIsCtrl = e->modifiers() & Qt::ControlModifier; + + bool anIsScaleChanged = false; + for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() ) + if( GraphicsView_Object* anObject = aViewPort->selectedObject() ) + anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged; + + if( anIsScaleChanged ) + { + emit wheelScaleChanged(); + aViewPort->onBoundingRectChanged(); + } + } + } +} + +//================================================================ +// Function : onSelectionDone +// Purpose : +//================================================================ +void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus ) +{ + emit selectionChanged( theStatus ); +} + +//================================================================ +// Function : onChangeBgColor +// Purpose : +//================================================================ +void GraphicsView_Viewer::onChangeBgColor() +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + QColor aColor = aViewPort->isForegroundEnabled() ? + aViewPort->foregroundColor() : aViewPort->backgroundColor(); + aColor = QColorDialog::getColor( aColor, aViewPort ); + if ( aColor.isValid() ) + { + if( aViewPort->isForegroundEnabled() ) + { + aViewPort->setForegroundColor( aColor ); + aViewPort->updateForeground(); + } + else + aViewPort->setBackgroundColor( aColor ); + } + } +} + +//================================================================ +// Function : onSelectionCancel +// Purpose : +//================================================================ +void GraphicsView_Viewer::onSelectionCancel() +{ + emit selectionChanged( GVSCS_Invalid ); +} diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h new file mode 100644 index 000000000..477d40c50 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -0,0 +1,118 @@ +// 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: GraphicsView_Viewer.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWER_H +#define GRAPHICSVIEW_VIEWER_H + +#include "GraphicsView.h" + +#include "GraphicsView_Defs.h" + +#include + +class QGraphicsSceneMouseEvent; +class QGraphicsSceneWheelEvent; +class QKeyEvent; + +class SUIT_ViewWindow; + +class GraphicsView_Selector; +class GraphicsView_Scene; +class GraphicsView_ViewTransformer; +class GraphicsView_ViewFrame; +class GraphicsView_ViewPort; + +/* + Class : GraphicsView_Viewer + Description : View model of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_Viewer: public SUIT_ViewModel +{ + Q_OBJECT + +public: + enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect, + Zoom, PanGlobal, Pan, FitWidth, UserTransform = 100 }; +public: + GraphicsView_Viewer( const QString& title ); + ~GraphicsView_Viewer(); + +public: + virtual SUIT_ViewWindow* createView( SUIT_Desktop* ); + + virtual QString getType() const { return Type(); } + static QString Type() { return "GraphicsView"; } + + virtual void contextMenuPopup( QMenu* ); + +public: + GraphicsView_Selector* getSelector(); + + GraphicsView_ViewFrame* getActiveView() const; + GraphicsView_ViewPort* getActiveViewPort() const; + GraphicsView_Scene* getActiveScene() const; + + void activateTransform( int ); + + bool isInitialized() const { return myIsInitialized; } + void setIsInitialized( bool ); + + bool isImmediateSelectionEnabled() const { return myIsImmediateSelectionEnabled; } + void setIsImmediateSelectionEnabled( bool ); + +signals: + void selectionChanged( GV_SelectionChangeStatus ); + void wheelScaleChanged(); + +protected: + virtual GraphicsView_ViewTransformer* createTransformer( int ); + + virtual void onTransformationStarted(); + virtual void onTransformationFinished(); + +protected slots: + virtual void onKeyEvent( QKeyEvent* ); + virtual void onMouseEvent( QGraphicsSceneMouseEvent* ); + virtual void onWheelEvent( QGraphicsSceneWheelEvent* ); + + virtual void onSelectionDone( GV_SelectionChangeStatus ); + virtual void onSelectionCancel(); + + virtual void onChangeBgColor(); + +private: + void handleKeyPress( QKeyEvent* ); + void handleKeyRelease( QKeyEvent* ); + void handleMouseMove( QGraphicsSceneMouseEvent* ); + void handleMousePress( QGraphicsSceneMouseEvent* ); + void handleMouseRelease( QGraphicsSceneMouseEvent* ); + void handleWheel( QGraphicsSceneWheelEvent* ); + +protected: + GraphicsView_Selector* mySelector; + GraphicsView_ViewTransformer* myTransformer; + + bool myIsInitialized; + bool myIsImmediateSelectionEnabled; +}; + +#endif diff --git a/src/GraphicsView/Makefile.am b/src/GraphicsView/Makefile.am new file mode 100644 index 000000000..cecfd8bef --- /dev/null +++ b/src/GraphicsView/Makefile.am @@ -0,0 +1,82 @@ +# 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 +# + +# File : Makefile.in +# Author : Vladimir Klyachin (OCN) +# Module : caf +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES = libGraphicsView.la + +salomeinclude_HEADERS = \ +GraphicsView_Defs.h \ +GraphicsView_Geom.h \ +GraphicsView.h \ +GraphicsView_Object.h \ +GraphicsView_Scene.h \ +GraphicsView_Selector.h \ +GraphicsView_Viewer.h \ +GraphicsView_ViewFrame.h \ +GraphicsView_ViewManager.h \ +GraphicsView_ViewPort.h \ +GraphicsView_ViewTransformer.h + +dist_libGraphicsView_la_SOURCES = \ +GraphicsView_Object.cxx \ +GraphicsView_Scene.cxx \ +GraphicsView_Selector.cxx \ +GraphicsView_Viewer.cxx \ +GraphicsView_ViewFrame.cxx \ +GraphicsView_ViewManager.cxx \ +GraphicsView_ViewPort.cxx \ +GraphicsView_ViewTransformer.cxx + +MOC_FILES = \ +GraphicsView_ViewManager_moc.cxx \ +GraphicsView_Viewer_moc.cxx \ +GraphicsView_ViewFrame_moc.cxx \ +GraphicsView_Selector_moc.cxx \ +GraphicsView_ViewPort_moc.cxx \ +GraphicsView_Scene_moc.cxx + +nodist_libGraphicsView_la_SOURCES = $(MOC_FILES) + +dist_salomeres_DATA = \ +resources/graphics_view_cursor_zoom.png \ +resources/graphics_view_dump.png \ +resources/graphics_view_fitall.png \ +resources/graphics_view_fitarea.png \ +resources/graphics_view_fitselect.png \ +resources/graphics_view_glpan.png \ +resources/graphics_view_pan.png \ +resources/graphics_view_reset.png \ +resources/graphics_view_zoom.png + +nodist_salomeres_DATA = \ + GraphicsView_images.qm \ + GraphicsView_msg_en.qm \ + GraphicsView_msg_fr.qm + +libGraphicsView_la_CPPFLAGS = $(QT_INCLUDES) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx +libGraphicsView_la_LDFLAGS = $(QT_MT_LIBS) +libGraphicsView_la_LIBADD = ../SUIT/libsuit.la diff --git a/src/GraphicsView/resources/GraphicsView_images.ts b/src/GraphicsView/resources/GraphicsView_images.ts new file mode 100644 index 000000000..9de9cd021 --- /dev/null +++ b/src/GraphicsView/resources/GraphicsView_images.ts @@ -0,0 +1,41 @@ + + + @default + + ICON_GV_DUMP + graphics_view_dump.png + + + ICON_GV_ZOOM + graphics_view_zoom.png + + + ICON_GV_PAN + graphics_view_pan.png + + + ICON_GV_GLOBALPAN + graphics_view_glpan.png + + + ICON_GV_CURSOR_ZOOM + graphics_view_cursor_zoom.png + + + ICON_GV_FITALL + graphics_view_fitall.png + + + ICON_GV_FITSELECT + graphics_view_fitselect.png + + + ICON_GV_RESET + graphics_view_reset.png + + + ICON_GV_FITAREA + graphics_view_fitarea.png + + + diff --git a/src/GraphicsView/resources/GraphicsView_msg_en.ts b/src/GraphicsView/resources/GraphicsView_msg_en.ts new file mode 100644 index 000000000..a6f2fe92f --- /dev/null +++ b/src/GraphicsView/resources/GraphicsView_msg_en.ts @@ -0,0 +1,88 @@ + + + + GraphicsView_ViewFrame + + DSC_DUMP_VIEW + Saves the active view in the image file + + + DSC_FITALL + Fit all objects inside the view frame + + + DSC_FITRECT + Fit area within the view frame + + + DSC_FITSELECT + Fit area of selection within the view frame + + + DSC_GLOBALPAN_VIEW + Selection of a new center of the view + + + DSC_PAN_VIEW + Pan the view + + + DSC_RESET_VIEW + Reset view point + + + DSC_ZOOM_VIEW + Zoom the view + + + LBL_TOOLBAR_LABEL + View Operations + + + MNU_DUMP_VIEW + Dump + + + MNU_FITALL + Fit All + + + MNU_FITRECT + Fit Area + + + MNU_FITSELECT + Fit Selection + + + MNU_GLOBALPAN_VIEW + Global Pan + + + MNU_PAN_VIEW + Pan + + + MNU_RESET_VIEW + Reset + + + MNU_ZOOM_VIEW + Zoom + + + + GraphicsView_Viewer + + CHANGE_BGCOLOR + Change background... + + + + GraphicsView_ViewManager + + GRAPHICS_VIEW_TITLE + Graphics scene:%M - viewer:%V + + + diff --git a/src/GraphicsView/resources/GraphicsView_msg_fr.ts b/src/GraphicsView/resources/GraphicsView_msg_fr.ts new file mode 100644 index 000000000..aa507e0d0 --- /dev/null +++ b/src/GraphicsView/resources/GraphicsView_msg_fr.ts @@ -0,0 +1,89 @@ + + + + + GraphicsView_ViewFrame + + DSC_DUMP_VIEW + Sauver la scène actuelle au fichier image + + + DSC_FITALL + Redimensionner la scène pour montrer tous les objets + + + DSC_FITRECT + Redimensionner la scène pour ne montrer que sa partie choisie par l'encadré + + + DSC_FITSELECT + Redimensionner la scène pour montrer la sélection. + + + DSC_GLOBALPAN_VIEW + Sélection d'un nouveau centre de la vue + + + DSC_PAN_VIEW + Redimensionner la vue + + + DSC_RESET_VIEW + Restaurer le point de vue + + + DSC_ZOOM_VIEW + Zoom + + + LBL_TOOLBAR_LABEL + Opérations de visualisation + + + MNU_DUMP_VIEW + Sauver la scène + + + MNU_FITALL + Montrer tous + + + MNU_FITRECT + Montrer l'encadré + + + MNU_FITSELECT + Ajuster la sélection + + + MNU_GLOBALPAN_VIEW + Panoramique Globale + + + MNU_PAN_VIEW + Redimensionner la vue + + + MNU_RESET_VIEW + Restaurer + + + MNU_ZOOM_VIEW + Zoom + + + + GraphicsView_Viewer + + CHANGE_BGCOLOR + Changer l'arrière-plan... + + + + GraphicsView_ViewManager + + GRAPHICS_VIEW_TITLE + Graphique scène:%M - visualisation:%V + + + diff --git a/src/GraphicsView/resources/graphics_view_cursor_zoom.png b/src/GraphicsView/resources/graphics_view_cursor_zoom.png new file mode 100755 index 0000000000000000000000000000000000000000..0020fea39f8531230eb0c25c662b76ee98f696bd GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnH3?%tPCZz)@&H$ef*9{vs0Ga>)|F^Z8<^g0e zmIV0)GdMiEkp|?5mAFQf1m~xflqVLYGNfmw85QKED;Vh+=o#9^?aKhFU`h9MOJ`zW zkPLd4!Up7Lc)B=-RLn_EP!KOz+h7#dX4;UsjI)PRK$4w})1Y}W<0Lc-a$k!M*zN28VxpF`U#yCAY@F9!>Q{yu)SmYHks0PSS(boFyt=akR{08E}qwEzGB literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_dump.png b/src/GraphicsView/resources/graphics_view_dump.png new file mode 100644 index 0000000000000000000000000000000000000000..b02616f2975e7a3865a236ee75380bdae5ce59f7 GIT binary patch literal 682 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VXMsm#F#`j)FbFd;%$g$s6l6(v z^mSxl*w|O|J8&|PuaN8!GAr-fh{`~)M&uq%*z+h+?Aj!ZYz}<83#0idNZ{NHLm{arOf}-0Di4NZr z4h;-Rj?WrQvR=Mwyy^F?%;4dFDJdx)KR>?&vt5iYrhzo>YRaCjpLk={x^?G1e0dpc zAf2Wt^rJsV!+{}D;>9cZGar846mH{Q?tkd0S>BzF%TD3t{4*BXIQ-IfVA%M8i#s*c zlr1kVj?FMpku6S6PGNSxV@Sx9M(Gn`0zzpIgandKboIMkOJX=8&cMX6ys@Kkl!Hi5Cs~Z*GuUfUrsH3ynxPybcSy{#2e*VG@J6ax= z#n~Osp1^ImwK3)gt3rdprHAi&vk!iGdwaWNpPVI=nU9lGQ{we?u{?kG+WrXQ(cn=9 z+IG10^fX=PhwiSfjl8q1O0@zxr4<@xOt_qoo~}Mam+y-f$9#+0wuLz-jo8f1&D+fL z?z+m40n#|u4mYG61ddHVaiyUq`r4~d9q8ZdYn zozP=;ncaEPUC6S9SjZ)j11xdTOVx|PwNDx OD+W(jKbLh*2~7Z6;rO)x literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_fitall.png b/src/GraphicsView/resources/graphics_view_fitall.png new file mode 100644 index 0000000000000000000000000000000000000000..87e001dd80b2755858d4599857106a0c9c0b3500 GIT binary patch literal 816 zcmV-01JC@4P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ;rb$FWRCwBA{Qv(y12q9a0I`6G?+lD6rgAd;XCy{5 zHhlmA#Dc^@mIHB63}s|w3&>x^7VEp$V z!_S{T8NPo0%wTSB4^{^=10aA{2t*_sGYc!&H9+&gF8uxbH^cX@Ux5bxVEFUvH&_hp zNhkmaASMC^p1OMBJi~90i+=rL`10u!!-sco89u&$$ME^%M~1IozA)UpbP22urU4*; z81W@+U>Ndq^YVU}wt5|dps+B*k8j@@e*E~(@bkwHhQELQGJN^`k)bg^7i72+(46}q zJpciO*M(YIT7fc>k_-*mnGENS9|s!*!oPv8y?^^ALw|iO$gn1uVITkyKn&QD3J3!Y zt1#5l`yc4!^j}9?`#%#C(;-P2+5cJwhW{mHWkKFL1H{Sb`Tzn5YousvYge$bu(Yd+ zi!(g^@BtL?iGTn8T>uOM_2*9>%K?=<1!}&AO)o$IVT2*juu`C5U1~tXo&y8^?Uyf= zSFc{}AhvJ-2p}dj!}3{~naMT`1ONgE>_SkfVWO=i2{i0E$eXW$2^NUUfQEGwYY@l` zP;LPTAh-*gnwp;TadI-eff!amiebp56hHvMT?i_^fL=}k3i1H)bfAI1NHGa!20#G8 u4Wv>5%K#8S$g%vNP}zvfo5&o100RIgKz|e1YHVKs0000aa literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_fitarea.png b/src/GraphicsView/resources/graphics_view_fitarea.png new file mode 100644 index 0000000000000000000000000000000000000000..e83d023a332df9a7d3ed0eb708e13260fb870af9 GIT binary patch literal 815 zcmV+~1JL}5P)Zvh0=!8? zK~xyios>&x6Hyd~zu0NDs70YTKG0afETV$oLIhFjgVtKmO2r4bsVfyxv7#GMx+ypn z*KVtBRD6IBT&PP0->u@KRa=@dHc8XYOs35woqJv6M*Fah_J_me-Z|&voOACSq?AZ0 zv1M@7I#mluDaos)rRC3N3TkX@3@|c7!!V>RgA@7J0XKk`z%5|^$d86$NB}K=P!{OM zFmme{tpN^IR&P64y|a#miNd5hI_;uymBe{-f4fYooV+1{{Y&t8O-ITI3J3Vb1`tf{4H=PrPg{|ek) zS+gBqN_-(179wZ9!1Fv@$6@WpjQ|Jo6&EVGv`8z)7Xl%3U}dUOJ7JPLs`K_}=lEOXtqw zSk`+Wu0n<;>|r<@J~Lg@nwOTB)6v^Y)A6G*ec_^cbIZ%=?@JKv=}7{ez$c(rg{8EK zU?rN?yj<5Y2L_16;}3-p@o1!{EE?&V4R}BjNCQ#ey$bcTzraqFXj*ef*NIvdT|a(2 ziN#`FfUSB}49rl__=qe4UW5tZ3HWj}%JL_k{xDGPLC%it*B3}6+oLABz! tx&&)7*jSAOYQQ{TnVN53)MfmaegTLEj1qkO@u>g+002ovPDHLkV1g{1YhM5W literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_fitselect.png b/src/GraphicsView/resources/graphics_view_fitselect.png new file mode 100755 index 0000000000000000000000000000000000000000..e52598d7b5b26b8fb5c5097dc02fc59ec43606c1 GIT binary patch literal 857 zcmV-f1E&0mP)`6sbB}}ri!6#cjYNKxH+dMXhntu59dfWHkT)PgGfFRb+3KSzb$mip9 zUq{#Hd)l_|Km$r^GRs%6ZqsJgY}ja@JbVxphVq%f;_0&hOgb(bTDI=_@Z;?$t*3xW z6KX}MG|ero{Cw*cH?CYd5^EDPVP0>ah{HFt7n@tQ5^7DTG?PkAMX2z7AJ27Jy?#Bw zuGpZQFenM$i??L7qI*4*IzRDXFs0nP;?wT*Ja%ED2-1rnzQ)s@qxI#OW5=KzXc+n21`lVxy&#y3k9r^ksC^> z5vwq^JGXQZ;+-X=-pC*lf<$#SI-QQCzMKWto|3XNV;DTPZ3eU1o0eq_0#2f;l8VMv z;1v-XL}eOTGavt6Pb}B}16CxHpT@8O)BMpi%>f_}+(}l?Bh}Ohwu1;m5(p9kf@#$! zr#XA;tL|==83x0S!(T%~H?!I70AK-kfL{{nG{I+QKx+_Fe})hOAq2BMz1BCYs>r!6 zt=qN%ydT9&|A(pi`ud|m5Hy;mITShjEs8ua{-VH2U?uQg^u~XR3f2b7&+9NbtuKMe j$jL+CLF7!m$d>;B!^B5bH!%%h00000NkvXXu0mjfuh)e| literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_glpan.png b/src/GraphicsView/resources/graphics_view_glpan.png new file mode 100644 index 0000000000000000000000000000000000000000..28ab547eab2e4614b8061252f5cbb4da079c7666 GIT binary patch literal 1086 zcmV-E1i|}>P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZc>jKeOv$OzL15I`)*h9FA-UC3*1Z~uwm?OTSQ4<0bQ ze(?e}13&j7BtjOg8oBY{u_wj195)S?b{&f6+rwNh(Uq* zK0ZGF9!TB4fBzVey$%pSph#d!NlE$3!NI}s_3KxL7r?*=#V#=XRDg2aKr9Qy%0Mg# zwcu`6R@RnZzkY$$K7Ra|;oiM_44*%L1}7(g00Oy$^}~k`3@Z!_7=WS-7i47_^npo& z_1d*NKskL-Yy$BYAm#zl;o;#2riOWv!1Q5tTw%b52J!EBN z_zMj9Ye2(a0MpVAL405VabQDXA%mWt-g{_beh*a#GW3?PurN#?D4ah51P}|7@?T7UooaWF76FUtY(e=N8Ih<%~* zEa-Xx0ti>}^$+SLM<6zX=4AnBQUWFN&ro@cDgYqB0GrW?VpB4t`v3p{07*qoM6N<$ Eg6tg6&Hw-a literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_pan.png b/src/GraphicsView/resources/graphics_view_pan.png new file mode 100644 index 0000000000000000000000000000000000000000..ec56cacc779342a978f183ecf747860c8b6dafb4 GIT binary patch literal 982 zcmV;{11bE8P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZb!otG-18H_3W&!c>DFz52f`;Yh z=KlYG@Zf(vJw1@2;y}!e&rpB>!e<*(Vq)UoNnv3OZ?0TnIIE=v5_imOsnQ(>_Q@}D9Q|HpzmfY=u#@9*!A5&HlE#0WDiKR^HPSD@Ek zzkbaCa@oa;7a4y4{_O{p(+6UCAm#(&Px|`$DQaqJ3~X#{4Da5(V|e)RA;Yz6*FdiR z0t!=r00NsF6BF}yLQoI`!>?Zq4Bx&nFns>Zz!(z)vWNqS-$A_va>-9lVB{=URRycP zpsdWG&(6-kdhOZ^SVRE?5Q~nE&fmqMp$spM9AUWs@+E@^Q1mI#KqwFe;@8la1=_~I z2J*$jJ9ilVe*DOA?ZXF#7k~dU%-7RnNW63j9QyzP#B$}z6$wUv{}&HSOBrrFdBPyW z&(HAr=TDe{d{D#gLnA=o6)=Lf|NhPJ2I#_XKyN<>8oU@7aj@722p~`x$^o%15O2W} zQ4K(R5QwirT?%sXD=g|(05K?CodF0SP#A)o^9gFhL?B)Zjj^{zMn(Vgg6j zxpU_jK79D#4wN$jVr3vsfvN|&{yoSXfB<5F#?CWnLd}P!GmwE_`1tr3R)vHxJUVoU z;RMiI;U7Ty82F(McnHLu(3}E_l-nS400M{wntfhCo&E)yX#avZ-#{@A45MF<9x;Hz z4lSY{BV~fOP)EH02p|@y4KPE$Kyv_tjEu~^`}glN965WI;l_&>3~!m4VFpeGVn3)0 zVaeeeEFA&_5G?D#4E+fW52hzio+tt7dm^Ah;l~e#JMZ4X4D5u`pP`QU2lWw%{s$01 zxUwNTH0uR`vRkc+3M|{L0pd2OxFS>?3IGToW*i2Bk`pV``xg$qd*=yF8X#vr0J$9M zy07T20tg^xJOwPwRUpGpK{Y>y#^wX4;lH73-~b@N0A_|Q{Wj4Xb^rhX07*qoM6N<$ Ef)-GsSpWb4 literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_reset.png b/src/GraphicsView/resources/graphics_view_reset.png new file mode 100644 index 0000000000000000000000000000000000000000..66f81e60471b7b587c37166a4e206b45f74e7fc2 GIT binary patch literal 918 zcmV;H18Mw;P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ<3`s;mRCwBA`2YVu0}KO!sHi9>h~bSaP6`GHAOZXQ009Iu ztVK?a_y6WCKL3CH$@>5IfA;^Iw`2aBnTdlW&7exTp@zi+u{AD30Ro7Lk&#hUNQk5Q z?D;STpjR1~nHj+nii&(-KGfwPzyqZXfLH~Ij{*P!hzW=@vvYJAfQEtvwrzdL@b~Y3 zhTx#>3=Q?CrT~SeL)CtP(l4O+3pN7*0*D2Ojg5^(!JOKflMHLu++jF%N|j;rru$QX z!I2B}0Zi>zGy}h4GY}wvKrZ|XauEp3n0^K5WhREsj&mSx69e%89{T_R1ajfcn>Rmz zIq%;60AXz)^A6B;zi?=K-}sfC-?tzTH62r z+1dZM`}+RpVPyp=a)o&VAb=Q=3jlDg;ox}n@#jy5zyJSR0p*SZ#Xz=e0L9NFXlO8m zC@V8qN=Sg!-~8}_;lk_J40EqvXW0Gtu^UimH$VWPmo_{g8)rH={0C|R3ET$aE+9^W z#_sAO0|T(@KsZfX8>D6hvI_wMh!MSr0=mcm=$i9OU0oSe`1u*u-@C_f=i^5PHYO$p zdueHgKqVyxW?=4l`t>V=_OfLRAAkK40Gja;rXL`H7_pRjAVWa`o#`Ya<56K`#Na9` ziz0vj(z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ;lSxEDRCwBA{Qv(y12q9a05LI882|(j3yAp6z=+{Y zPKN)C$b3dd#y}ty1;mO#{0NBG0DZR%T^~RIu^?$iH}pTm97baxo$2V|nd}h|$RH&v z$MF2=6XU&Gw*&&^{D5-Pfd(IhX#xl!22dE{!$2^nw!8QLxyR4`p9SL6kDmTN`QXX_ zWA`8bZ*#;G5q}bli};<&kW}F_F#1|4FCbe zLcl;aW)@bkYk=l~UHJR=Z-(z*zXA>X!SLtTZ?G6R8lV6mfC#zp)YS{;8GeIY^y?SH zmrtJL&@bUdShR+{AGJO5=h2iF{4FCbeh%aFS!;qhwm-oZ8)$14pg@qY@ zeEZJuHQCMa{8~Mt^J>giRqA}jO>3c z1H=E4va%p=odM!xbbSB;gf&vMwY4kQSXkOs#l;z(e)s?i_{6_||1JOqf%@|&kL7?$ zo&q&r!=@J?fH1-kXjm!Gur4*AVb6g9|Mtt5%Bxqec3{&C%ChKL6d-_@&RKiH#D= b009O7QZ{F9XF19?00000NkvXXu0mjfwM|pG literal 0 HcmV?d00001 diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 8dd648f27..0fb976ed1 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -154,6 +154,11 @@ #include #endif +#ifndef DISABLE_GRAPHICSVIEWER + #include + #include +#endif + #define VISIBILITY_COLUMN_WIDTH 25 @@ -669,6 +674,9 @@ void LightApp_Application::createActions() // createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_C ); createActionForViewer( NewQxSceneViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_S ); #endif +#ifndef DISABLE_GRAPHICSVIEWER + createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_R ); +#endif createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ), Qt::ALT+Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) ); @@ -786,6 +794,11 @@ void LightApp_Application::onNewWindow() case NewQxSceneViewId: type = QxScene_Viewer::Type(); break; +#endif +#ifndef DISABLE_GRAPHICSVIEWER + case NewGraphicsViewId: + type = GraphicsView_Viewer::Type(); + break; #endif } @@ -912,6 +925,12 @@ void LightApp_Application::updateCommandsStatus() if( a ) a->setEnabled( activeStudy() ); #endif + +#ifndef DISABLE_GRAPHICSVIEWER + a = action( NewGraphicsViewId ); + if( a ) + a->setEnabled( activeStudy() ); +#endif } /*! @@ -1486,6 +1505,12 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType #endif } #endif +#ifndef DISABLE_GRAPHICSVIEWER + if( vmType == GraphicsView_Viewer::Type() ) + { + viewMgr = new GraphicsView_ViewManager( activeStudy(), desktop() ); + } +#endif if ( !viewMgr ) return 0; diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index af4370a15..dc0e829f6 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -85,7 +85,7 @@ public: CloseId, CloseAllId, GroupAllId, PreferencesId, MRUId, ModulesListId, NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId, - NewQxSceneViewId = NewQxGraphViewId, StyleId, FullScreenId, + NewQxSceneViewId = NewQxGraphViewId, NewGraphicsViewId, StyleId, FullScreenId, UserID }; protected: diff --git a/src/LightApp/Makefile.am b/src/LightApp/Makefile.am index 392e24768..146825ad3 100755 --- a/src/LightApp/Makefile.am +++ b/src/LightApp/Makefile.am @@ -216,6 +216,11 @@ if ENABLE_GLVIEWER else !ENABLE_GLVIEWER libLightApp_la_CPPFLAGS += -DDISABLE_GLVIEWER endif +if ENABLE_GRAPHICSVIEW + libLightApp_la_CPPFLAGS += -I$(srcdir)/../GraphicsView +else !ENABLE_GRAPHICSVIEW + libLightApp_la_CPPFLAGS += -DDISABLE_GRAPHICSVIEWER +endif if ENABLE_SUPERVGRAPHVIEWER libLightApp_la_CPPFLAGS += -I$(srcdir)/../SUPERVGraph else !ENABLE_SUPERVGRAPHVIEWER @@ -270,6 +275,9 @@ endif if ENABLE_GLVIEWER libLightApp_la_LIBADD += ../GLViewer/libGLViewer.la endif +if ENABLE_GRAPHICSVIEW + libLightApp_la_LIBADD += ../GraphicsView/libGraphicsView.la +endif if ENABLE_PLOT2DVIEWER libLightApp_la_LIBADD += ../Plot2d/libPlot2d.la if ENABLE_SALOMEOBJECT diff --git a/src/LightApp/resources/LightApp.ini b/src/LightApp/resources/LightApp.ini index b181e0523..29237e9dc 100755 --- a/src/LightApp/resources/LightApp.ini +++ b/src/LightApp/resources/LightApp.ini @@ -34,5 +34,6 @@ STD = $(GUI_ROOT_DIR)/share/salome/resources/gui LightApp = $(GUI_ROOT_DIR)/share/salome/resources/gui Plot2d = $(GUI_ROOT_DIR)/share/salome/resources/gui GLViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui +GraphicsView = $(GUI_ROOT_DIR)/share/salome/resources/gui OCCViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui VTKViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 44f50f58c..cd5c06820 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -64,6 +64,7 @@ + diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index 065b1bfe3..9fa968f9b 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -500,7 +500,7 @@ The changes will be applied on the next application session. NEW_WINDOW_5 - Qx&Scene 2D view + G&raphics view CREATING_NEW_WINDOW diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index cf5a1fc0a..e01e780dd 100755 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -500,7 +500,7 @@ Les modifications seront appliquées à la prochaine session. NEW_WINDOW_5 - Scène Qx&Scene + Scène G&raphics CREATING_NEW_WINDOW diff --git a/src/Makefile.am b/src/Makefile.am index f49f706c3..b419ac73c 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,6 +45,13 @@ if ENABLE_GLVIEWER SUBDIRS_GLVIEWER = GLViewer endif +## +# Graphics viewer +## +if ENABLE_GRAPHICSVIEW + SUBDIRS_GRAPHICSVIEW = GraphicsView +endif + ## # VTK viewer ## @@ -120,11 +127,11 @@ if ENABLE_PYCONSOLE SUBDIRS_PY_LIGHT = SALOME_SWIG SALOME_PY SALOME_PYQT endif -SUBDIRS = $(SUBDIRS_COMMON) $(SUBDIRS_OBJECT) $(SUBDIRS_VIEWERTOOLS) $(SUBDIRS_GLVIEWER) $(SUBDIRS_VTKVIEWER) \ +SUBDIRS = $(SUBDIRS_COMMON) $(SUBDIRS_OBJECT) $(SUBDIRS_VIEWERTOOLS) $(SUBDIRS_GLVIEWER) $(SUBDIRS_GRAPHICSVIEW) $(SUBDIRS_VTKVIEWER) \ $(SUBDIRS_OCCVIEWER) $(SUBDIRS_PLOT2DVIEWER) $(SUBDIRS_SUPERVGRAPHVIEWER) $(SUBDIRS_QXGRAPHVIEWER) \ $(SUBDIRS_PYCONSOLE) $(SUBDIRS_LIGHT) $(SUBDIRS_CORBA) $(SUBDIRS_PY_LIGHT) DIST_SUBDIRS = CASCatch Qtx Style DDS QDS ObjBrowser SUIT SUITApp STD CAF CAM LogWindow Prs Event OpenGLUtils \ - OBJECT ViewerTools GLViewer VTKViewer SVTK OCCViewer SOCC Plot2d SPlot2d SUPERVGraph QxGraph QxScene \ + OBJECT ViewerTools GLViewer GraphicsView VTKViewer SVTK OCCViewer SOCC Plot2d SPlot2d SUPERVGraph QxGraph QxScene \ PyInterp PyConsole LightApp ResExporter TOOLSGUI Session SalomeApp GuiHelpers TreeData \ SALOME_SWIG SALOME_PY SALOME_PYQT GUI_PY -- 2.39.2