From: ouv Date: Tue, 6 Aug 2013 09:44:11 +0000 (+0000) Subject: Adding ImageComposer and GraphicsView packages (from BR_GraphicsView branch). X-Git-Tag: BR_hydro_v_0_1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6de830cfbc2ad938731747c4ad4cead463d1af84;p=modules%2Fgui.git Adding ImageComposer and GraphicsView packages (from BR_GraphicsView branch). --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a7845d74c..85d8a0824 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ OPTION(SALOME_USE_VTKVIEWER "Enable VTK visualization (Mandatory in classic conf OPTION(SALOME_USE_SALOMEOBJECT "Enable Salome Object (Mandatory in classic configurations)" ON) OPTION(SALOME_USE_OCCVIEWER "Enable OCC visualization (Mandatory in classic configurations)" ON) OPTION(SALOME_USE_GLVIEWER "Enable OpenGL visualization (Mandatory in classic configurations)" ON) +OPTION(SALOME_USE_GRAPHICSVIEW "Enable GraphicsView visualization (Mandatory in classic configurations)" ON) OPTION(SALOME_USE_PLOT2DVIEWER "Enable Plot2D visualization (Mandatory in classic configurations)" ON) OPTION(SALOME_USE_PYCONSOLE "Enable Python GUI interface (Mandatory in classic configurations)" ON) OPTION(SALOME_USE_SUPERVGRAPHVIEWER "Enable Supervision visualization (Mandatory in classic configurations)" ON) diff --git a/adm_local/cmake_files/FindGUI.cmake b/adm_local/cmake_files/FindGUI.cmake index 4136dcd53..3147be3e8 100644 --- a/adm_local/cmake_files/FindGUI.cmake +++ b/adm_local/cmake_files/FindGUI.cmake @@ -25,6 +25,7 @@ FIND_LIBRARY(CASCatch CASCatch ${GUI_ROOT_DIR}/lib/salome) FIND_LIBRARY(DDS DDS ${GUI_ROOT_DIR}/lib/salome) FIND_LIBRARY(Event Event ${GUI_ROOT_DIR}/lib/salome) FIND_LIBRARY(GLViewer GLViewer ${GUI_ROOT_DIR}/lib/salome) +FIND_LIBRARY(GraphicsView GraphicsView ${GUI_ROOT_DIR}/lib/salome) FIND_LIBRARY(LightApp LightApp ${GUI_ROOT_DIR}/lib/salome) FIND_LIBRARY(LogWindow LogWindow ${GUI_ROOT_DIR}/lib/salome) FIND_LIBRARY(ObjBrowser ObjBrowser ${GUI_ROOT_DIR}/lib/salome) @@ -61,3 +62,4 @@ FIND_LIBRARY(vtkEDFOverloads vtkEDFOverloads ${GUI_ROOT_DIR}/lib/paraview) FIND_LIBRARY(vtkTools vtkTools ${GUI_ROOT_DIR}/lib/salome) FIND_LIBRARY(SalomeGuiHelpers SalomeGuiHelpers ${GUI_ROOT_DIR}/lib/salome) FIND_LIBRARY(SalomeTreeData SalomeTreeData ${GUI_ROOT_DIR}/lib/salome) +FIND_LIBRARY(ImageComposer ImageComposer ${GUI_ROOT_DIR}/lib/salome) diff --git a/configure.ac b/configure.ac index 58e06d45c..ed5d989ed 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 \ @@ -660,6 +677,7 @@ AC_OUTPUT([ \ src/TOOLSGUI/Makefile \ src/Event/Makefile \ src/OpenGLUtils/Makefile \ + src/ImageComposer/Makefile \ src/Session/Makefile \ src/SalomeApp/Makefile \ src/SalomeApp/Test/Makefile \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6d2b582a7..36b5dca36 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ SET(SUBDIRS_COMMON Prs Event OpenGLUtils + ImageComposer GUI_PY ) @@ -53,6 +54,13 @@ IF(SALOME_USE_GLVIEWER) SET(SUBDIRS_GLVIEWER GLViewer) ENDIF(SALOME_USE_GLVIEWER) +## +# GL viewer +## +IF(SALOME_USE_GRAPHICSVIEW) + SET(SUBDIRS_GRAPHICSVIEW GraphicsView) +ENDIF(SALOME_USE_GRAPHICSVIEW) + ## # VTK viewer ## @@ -148,6 +156,7 @@ SET(SUBDIRS ${SUBDIRS_OBJECT} ${SUBDIRS_VIEWERTOOLS} ${SUBDIRS_GLVIEWER} + ${SUBDIRS_GRAPHICSVIEW} ${SUBDIRS_VTKVIEWER} ${SUBDIRS_OCCVIEWER} ${SUBDIRS_PLOT2DVIEWER} diff --git a/src/GraphicsView/CMakeLists.txt b/src/GraphicsView/CMakeLists.txt new file mode 100755 index 000000000..573cfc4d5 --- /dev/null +++ b/src/GraphicsView/CMakeLists.txt @@ -0,0 +1,72 @@ +# Copyright (C) 2012-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/UseQT4EXT.cmake) + +INCLUDE_DIRECTORIES( + ${QT_INCLUDES} + ${CMAKE_CURRENT_SOURCE_DIR}/../Qtx + ${CMAKE_CURRENT_SOURCE_DIR}/../SUIT + ${CMAKE_CURRENT_SOURCE_DIR}/../ImageComposer +) + +SET(COMMON_LIBS + ${QT_LIBRARIES} + suit + ImageComposer +) + +SET(GUI_HEADERS + GraphicsView_Scene.h + GraphicsView_Selector.h + GraphicsView_ViewFrame.h + GraphicsView_ViewManager.h + GraphicsView_ViewPort.h + GraphicsView_Viewer.h +) + +QT4_WRAP_CPP(GUI_HEADERS_MOC ${GUI_HEADERS}) + +SET(GraphicsView_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 +) + +SET(GUITS_SOURCES + resources/GraphicsView_images.ts + resources/GraphicsView_msg_en.ts + resources/GraphicsView_msg_fr.ts +) + +ADD_LIBRARY(GraphicsView ${GraphicsView_SOURCES} ${GUI_HEADERS_MOC}) +TARGET_LINK_LIBRARIES(GraphicsView ${COMMON_LIBS}) +INSTALL(TARGETS GraphicsView DESTINATION ${GUI_salomelib_LIBS}) + +FILE(GLOB COMMON_HEADERS_H "${CMAKE_CURRENT_SOURCE_DIR}/*.h") +INSTALL(FILES ${COMMON_HEADERS_H} DESTINATION ${GUI_salomeinclude_HEADERS}) +QT4_INSTALL_TS_RESOURCES("${GUITS_SOURCES}" "${GUI_salomeres_DATA}") + +FILE(GLOB GUIPNG_DATA "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.png") +INSTALL(FILES ${GUIPNG_DATA} DESTINATION ${GUI_salomeres_DATA}) diff --git a/src/GraphicsView/GraphicsView.h b/src/GraphicsView/GraphicsView.h new file mode 100644 index 000000000..aa3b17e8b --- /dev/null +++ b/src/GraphicsView/GraphicsView.h @@ -0,0 +1,34 @@ +// 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 +// + +#ifdef WIN32 + +#if defined GRAPHICSVIEW_EXPORTS || defined 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..f88779d62 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Defs.h @@ -0,0 +1,47 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef 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_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx new file mode 100644 index 000000000..c00f15f0f --- /dev/null +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -0,0 +1,192 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "GraphicsView_Object.h" + +#include "GraphicsView_Scene.h" +#include "GraphicsView_ViewPort.h" + +//======================================================================= +// Name : GraphicsView_Object +// Purpose : Constructor +//======================================================================= +GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent ) +: QGraphicsItemGroup( theParent ), + myPriority( 0 ), + myIsOnTop( false ), + myIsHighlighted( false ), + myIsSelected( false ), + myIsMoving( false ) +{ +} + +//======================================================================= +// Name : GraphicsView_Object +// Purpose : Destructor +//======================================================================= +GraphicsView_Object::~GraphicsView_Object() +{ + QListIterator aChildIter( children() ); + while( aChildIter.hasNext() ) + { + if( QGraphicsItem* aChild = aChildIter.next() ) + { + removeFromGroup( aChild ); + if( QGraphicsScene* aScene = aChild->scene() ) + aScene->removeItem( aChild ); + delete aChild; + aChild = 0; + } + } +} + +//================================================================ +// Function : addTo +// Purpose : +//================================================================ +void GraphicsView_Object::addTo( GraphicsView_ViewPort* theViewPort ) +{ + if( QGraphicsScene* aScene = theViewPort->scene() ) + aScene->addItem( this ); +} + +//================================================================ +// Function : removeFrom +// Purpose : +//================================================================ +void GraphicsView_Object::removeFrom( GraphicsView_ViewPort* theViewPort ) +{ + if( QGraphicsScene* aScene = theViewPort->scene() ) + aScene->removeItem( this ); +} + +//================================================================ +// 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, QCursor& theCursor ) const +{ + return !getRect().isNull() && getRect().contains( theX, theY ); +} + +//================================================================ +// Function : highlight +// Purpose : +//================================================================ +bool GraphicsView_Object::highlight( double theX, double theY ) +{ + QCursor aCursor; + if( myIsHighlighted = isVisible() ) + myIsHighlighted = checkHighlight( theX, theY, aCursor ); + 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 ) +{ + QCursor aCursor; + if( myIsSelected = isVisible() ) + { + if( !theRect.isNull() ) + myIsSelected = theRect.contains( getRect() ); + else + myIsSelected = checkHighlight( theX, theY, aCursor ); + } + return myIsSelected; +} + +//================================================================ +// Function : unselect +// Purpose : +//================================================================ +void GraphicsView_Object::unselect() +{ + myIsSelected = false; +} + +//================================================================ +// Function : move +// Purpose : +//================================================================ +void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce ) +{ + if( theIsAtOnce ) + { + finishMove( true ); + return; + } + + myIsMoving = true; + moveBy( theDX, theDY ); +} + +//================================================================ +// Function : finishMove +// Purpose : +//================================================================ +bool GraphicsView_Object::finishMove( bool theStatus ) +{ + myIsMoving = false; + if( theStatus ) + if( GraphicsView_Scene* aScene = dynamic_cast( scene() ) ) + aScene->processRectChanged(); + return true; +} + +//================================================================ +// Function : setViewTransform +// Purpose : +//================================================================ +void GraphicsView_Object::setViewTransform( const QTransform& theTransform ) +{ + myViewTransform = theTransform; +} diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h new file mode 100644 index 000000000..61c0fdbfd --- /dev/null +++ b/src/GraphicsView/GraphicsView_Object.h @@ -0,0 +1,113 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef GRAPHICSVIEW_OBJECT_H +#define GRAPHICSVIEW_OBJECT_H + +#include "GraphicsView.h" + +#include "GraphicsView_Defs.h" + +#include + +class GraphicsView_ViewPort; + +/* + 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; + + virtual void addTo( GraphicsView_ViewPort* theViewPort ); + virtual void removeFrom( GraphicsView_ViewPort* theViewPort ); + + 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 hasSpecificZValue() const { return false; } + + virtual bool isSelectable() const { return true; } + virtual bool isMovable() const { return true; } + + virtual QRectF getRect() const; + + virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) 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( bool theStatus ); + virtual bool isMoving() const { return myIsMoving; } + 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*, + const GraphicsView_ObjectList& ) {} + virtual void finishPulling( bool, const GraphicsView_ObjectList& ) {} + virtual bool isPulling() { return false; } + + virtual bool handleMousePress( QGraphicsSceneMouseEvent* ) { return false; } + virtual bool handleMouseMove( QGraphicsSceneMouseEvent* ) { return false; } + virtual bool handleMouseRelease( QGraphicsSceneMouseEvent* ) { return false; } + + virtual QTransform getViewTransform() const { return myViewTransform; } + virtual void setViewTransform( const QTransform& theTransform ); + +protected: + QString myName; + + int myPriority; + bool myIsOnTop; + + bool myIsHighlighted; + bool myIsSelected; + + bool myIsMoving; + + QTransform myViewTransform; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Scene.cxx b/src/GraphicsView/GraphicsView_Scene.cxx new file mode 100644 index 000000000..c8d371a32 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Scene.cxx @@ -0,0 +1,208 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "GraphicsView_Scene.h" + +#include +#include +#include + +#define VIEWER_DEBUG // testing ImageViewer + +//======================================================================= +// 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 + + // testing ImageViewer + setSceneRect( -2000, -2000, 4000, 4000 ); + + QGraphicsLineItem* aHorLineItem = new QGraphicsLineItem( -2000, 0, 2000, 0 ); + aHorLineItem->setPen( QPen( Qt::red ) ); + addItem( aHorLineItem ); + + QGraphicsLineItem* aVerLineItem = new QGraphicsLineItem( 0, -2000, 0, 2000 ); + aVerLineItem->setPen( QPen( Qt::red ) ); + addItem( aVerLineItem ); +} + +//======================================================================= +// 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..d9c2b34c8 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Scene.h @@ -0,0 +1,77 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef 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..4719c3a52 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Selector.cxx @@ -0,0 +1,138 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "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..06c09ecc6 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Selector.h @@ -0,0 +1,75 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef 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..89f9e0b31 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -0,0 +1,363 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "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* ) ) ); + + connect( myViewPort, SIGNAL( vpSketchingFinished( QPainterPath ) ), + this, SIGNAL( sketchingFinished( QPainterPath ) ) ); +} + +//======================================================================= +// 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..8e3ffe60a --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewFrame.h @@ -0,0 +1,103 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef 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* ); + + void sketchingFinished( QPainterPath ); + +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..fac0e9185 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewManager.cxx @@ -0,0 +1,52 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "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..6cdb8e68c --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewManager.h @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef 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..7dc569701 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -0,0 +1,1764 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "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 + +#define FOREGROUND_Z_VALUE -2 +#define GRID_Z_VALUE -1 +#define SKETCH_Z_VALUE 3000 + +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; +QCursor* GraphicsView_ViewPort::sketchCursor = 0; + +//======================================================================= +// Name : GraphicsView_ViewPort::ViewLabel +// 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::ViewLabel : public QLabel +{ +public: + ViewLabel( QWidget* theParent ) + : QLabel( theParent ), + myAcceptMoveEvents( false ) + { + } + ~ViewLabel() {} + + 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" ) ) ); + + sketchCursor = new QCursor( Qt::CrossCursor ); +} + +//================================================================ +// 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; + delete sketchCursor; sketchCursor = 0; +} + +//======================================================================= +// Name : GraphicsView_ViewPort +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) +: QGraphicsView( theParent ), + myInteractionFlags( 0 ), + myViewLabel( 0 ), + myViewLabelPosition( VLP_None ), + myViewLabelLayout( 0 ), + myIsMousePositionEnabled( false ), + myForegroundItem( 0 ), + myGridItem( 0 ), + myIsTransforming( false ), + myHighlightedObject( 0 ), + myHighlightX( 0 ), + myHighlightY( 0 ), + myIsHighlighting( false ), + mySelectionIterator( 0 ), + myRectBand( 0 ), + myAreSelectionPointsInitialized( false ), + mySketchingItem( 0 ), + myIsPrepareToSketch( false ), + myIsSketching( false ), + myIsSketchingByPath( false ), + myIsDragging( false ), + myIsDragPositionInitialized( false ), + myIsPulling( false ), + myPullingObject( 0 ), + myStoredCursor( Qt::ArrowCursor ) +{ + // scene + myScene = new GraphicsView_Scene( this ); + setScene( myScene ); + + mySceneGap = 20; + myFitAllGap = 40; + + // interaction flags + setInteractionFlags( EditFlags ); + //setInteractionFlag( TraceBoundingRect ); + //setInteractionFlag( DraggingByMiddleButton ); + //setInteractionFlag( ImmediateContextMenu ); + //setInteractionFlag( ImmediateSelection ); // testing ImageViewer + //setInteractionFlag( Sketching ); // testing ImageViewer + + // 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 ); + anObject->setViewTransform( transform() ); + anObject->addTo( this ); + } + else + 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 ); + anObject->removeFrom( this ); + } + else + myScene->removeItem( theItem ); + onBoundingRectChanged(); +} + +//================================================================ +// Function : getObjects +// Purpose : +//================================================================ +GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( SortType theSortType ) const +{ + if( theSortType == SelectedFirst ) + { + // 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; + } + + if( theSortType == SortByZLevel ) // double loop, needs to be optimized + { + GraphicsView_ObjectList aList; + + GraphicsView_ObjectListIterator anIter( myObjects ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = anIter.next() ) + { + double aZValue = anObject->zValue(); + GraphicsView_ObjectList::iterator anIter1, anIter1End = aList.end(); + for( anIter1 = aList.begin(); anIter1 != anIter1End; anIter1++ ) + if( GraphicsView_Object* anObjectRef = *anIter1 ) + if( anObjectRef->zValue() > aZValue ) + break; + aList.insert( anIter1, anObject ); + } + } + return aList; + } + + return myObjects; // theSortType == NoSorting +} + +//================================================================ +// 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 : interactionFlags +// Purpose : +//================================================================ +int GraphicsView_ViewPort::interactionFlags() const +{ + return myInteractionFlags; +} + +//================================================================ +// Function : hasInteractionFlag +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::hasInteractionFlag( InteractionFlag theFlag ) +{ + return ( interactionFlags() & theFlag ) == theFlag; +} + +//================================================================ +// Function : setInteractionFlag +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setInteractionFlag( InteractionFlag theFlag, + bool theIsEnabled ) +{ + if( theIsEnabled ) + setInteractionFlags( myInteractionFlags | theFlag ); + else + setInteractionFlags( myInteractionFlags & ~theFlag ); +} + +//================================================================ +// Function : setInteractionFlags +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setInteractionFlags( InteractionFlags theFlags ) +{ + myInteractionFlags = theFlags; +} + +//================================================================ +// Function : setViewLabelPosition +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setViewLabelPosition( ViewLabelPosition thePosition, + bool theIsForced ) +{ + if( theIsForced && !myViewLabel ) + myViewLabel = new ViewLabel( viewport() ); + + if( !myViewLabel ) + return; + + if( thePosition == VLP_None ) + { + myViewLabel->setVisible( false ); + return; + } + + if( myViewLabelLayout ) + delete myViewLabelLayout; + + myViewLabelLayout = new QGridLayout( viewport() ); + myViewLabelLayout->setMargin( 10 ); + myViewLabelLayout->setSpacing( 0 ); + + int aRow = 0, aColumn = 0; + switch( thePosition ) + { + case VLP_TopLeft: aRow = 0; aColumn = 0; break; + case VLP_TopRight: aRow = 0; aColumn = 1; break; + case VLP_BottomLeft: aRow = 1; aColumn = 0; break; + case VLP_BottomRight: aRow = 1; aColumn = 1; break; + default: break; + } + + myViewLabelLayout->addWidget( myViewLabel, aRow, aColumn ); + myViewLabelLayout->setRowStretch( 1 - aRow, 1 ); + myViewLabelLayout->setColumnStretch( 1 - aColumn, 1 ); + + myViewLabel->setVisible( true ); +} + +//================================================================ +// Function : setViewLabelText +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setViewLabelText( const QString& theText ) +{ + if( myViewLabel ) + myViewLabel->setText( theText ); +} + +//================================================================ +// Function : setMousePositionEnabled +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setMousePositionEnabled( bool theState ) +{ + myIsMousePositionEnabled = theState; + + if( theState ) + { + setViewLabelPosition( VLP_BottomLeft, true ); + + int aMouseX = 0, aMouseY = 0; + setViewLabelText( QString( "(%1, %2)" ).arg( aMouseX ).arg( aMouseY ) ); + } + else + setViewLabelPosition( VLP_None ); +} + +//================================================================ +// 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( FOREGROUND_Z_VALUE ); + + 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( GRID_Z_VALUE ); + + 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( myViewLabel ) + myViewLabel->setAcceptMoveEvents( false ); + + if( QScrollBar* aHBar = horizontalScrollBar() ) + aHBar->setValue( aHBar->value() - theDX ); + if( QScrollBar* aVBar = verticalScrollBar() ) + aVBar->setValue( aVBar->value() + theDY ); + + if( myViewLabel ) + myViewLabel->setAcceptMoveEvents( true ); + + myIsTransforming = false; + + applyTransform(); +} + +//================================================================ +// Function : setCenter +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setCenter( double theX, double theY ) +{ + myIsTransforming = true; + + setTransform( myCurrentTransform ); + centerOn( theX, theY ); + + myIsTransforming = false; + + applyTransform(); +} + +//================================================================ +// 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; + + applyTransform(); +} + +//================================================================ +// Function : fitRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::fitRect( const QRectF& theRect ) +{ + myIsTransforming = true; + + fitInView( theRect, Qt::KeepAspectRatio ); + + myIsTransforming = false; + + applyTransform(); +} + +//================================================================ +// 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; + + applyTransform(); +} + +//================================================================ +// 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; + + applyTransform(); +} + +//================================================================ +// 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; + + applyTransform(); +} + +//================================================================ +// Function : applyTransform +// Purpose : +//================================================================ +void GraphicsView_ViewPort::applyTransform() +{ + GraphicsView_ObjectListIterator anIter( getObjects() ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + anObject->setViewTransform( transform() ); +} + +//================================================================ +// 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 ) +{ + myIsHighlighting = true; + myHighlightX = theX; + myHighlightY = theY; + + bool anIsHighlighted = false; + bool anIsOnObject = false; + + GraphicsView_Object* aPreviousHighlightedObject = myHighlightedObject; + GraphicsView_Object* aHighlightedObject = 0; + + QCursor aCursor; + + GraphicsView_ObjectList aList = getObjects( SortByZLevel ); + 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() ) + { + if( anObject->checkHighlight( theX, theY, aCursor ) ) + { + anIsOnObject = true; + anIsHighlighted = anObject->highlight( theX, theY ); + } + + if( anIsHighlighted ) + { + aHighlightedObject = anObject; + break; + } + } + } + } + + setCursor( aCursor ); + + 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 ) +{ + if( !myIsHighlighting ) + return GVSS_NoChanged; + + 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 ) && myIsHighlighting ) + 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 : prepareToSketch +// Purpose : +//================================================================ +void GraphicsView_ViewPort::prepareToSketch( bool theStatus ) +{ + myIsPrepareToSketch = theStatus; + if( theStatus ) + setCursor( *getSketchCursor() ); +} + +//================================================================ +// Function : isPrepareToSketch +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::isPrepareToSketch() +{ + return myIsPrepareToSketch; +} + +//================================================================ +// Function : startSketching +// Purpose : +//================================================================ +void GraphicsView_ViewPort::startSketching( const QPointF& thePoint, + bool theIsPath ) +{ + prepareToSketch( false ); + + if( !mySketchingItem ) + { + mySketchingItem = new QGraphicsPathItem(); + mySketchingItem->setZValue( SKETCH_Z_VALUE ); + + QPen aPen = mySketchingItem->pen(); + aPen.setStyle( Qt::DotLine ); + mySketchingItem->setPen( aPen ); + + addItem( mySketchingItem ); + } + + mySketchingPoint = thePoint; + + QPainterPath aPath; + aPath.moveTo( mySketchingPoint ); + mySketchingItem->setPath( aPath ); + mySketchingItem->setVisible( true ); + + myIsSketching = true; + myIsSketchingByPath = theIsPath; +} + +//================================================================ +// Function : drawSketching +// Purpose : +//================================================================ +void GraphicsView_ViewPort::drawSketching( const QPointF& thePoint ) +{ + bool anIsPath = false; + if( mySketchingItem && isSketching( &anIsPath ) ) + { + QPainterPath aPath = mySketchingItem->path(); + if( anIsPath ) // arbitrary path + aPath.lineTo( thePoint ); + else // rectangle + { + // make a valid rectangle + double x1 = mySketchingPoint.x(), y1 = mySketchingPoint.y(); + double x2 = thePoint.x(), y2 = thePoint.y(); + QPointF aPoint1( qMin( x1, x2 ), qMin( y1, y2 ) ); + QPointF aPoint2( qMax( x1, x2 ), qMax( y1, y2 ) ); + QRectF aRect( aPoint1, aPoint2 ); + + aPath = QPainterPath(); + aPath.addRect( aRect ); + } + mySketchingItem->setPath( aPath ); + } +} + +//================================================================ +// Function : finishSketching +// Purpose : +//================================================================ +void GraphicsView_ViewPort::finishSketching( bool theStatus ) +{ + prepareToSketch( false ); + + mySketchingItem->setVisible( false ); + myIsSketching = false; + + setCursor( *getDefaultCursor() ); + + if( theStatus ) + { + QPainterPath aPath = mySketchingItem->path(); + emit vpSketchingFinished( aPath ); + } +} + +//================================================================ +// Function : isSketching +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::isSketching( bool* theIsPath ) const +{ + if( theIsPath ) + *theIsPath = myIsSketchingByPath; + return myIsSketching; +} + +//================================================================ +// 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( hasInteractionFlag( DraggingByMiddleButton ) && + 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() ); // testing ImageViewer + 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, getSelectedObjects() ); +} + +//================================================================ +// Function : finishPulling +// Purpose : +//================================================================ +void GraphicsView_ViewPort::finishPulling( bool theStatus ) +{ + myIsPulling = false; + myPullingObject->finishPulling( theStatus, getSelectedObjects() ); + setCursor( *getDefaultCursor() ); +} + +//================================================================ +// Function : cancelCurrentOperation +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::cancelCurrentOperation() +{ + myIsHighlighting = false; + + if( isDragging() ) + { + for( initSelected(); moreSelected(); nextSelected() ) + if( GraphicsView_Object* aMovingObject = selectedObject() ) + aMovingObject->finishMove( false ); + + if( GraphicsView_Object* aMovingObject = getHighlightedObject() ) + aMovingObject->finishMove( false ); + + myIsDragging = false; + myDragPosition = QPointF(); + //setCursor( myStoredCursor ); + setCursor( *getDefaultCursor() ); + + return true; + } + + if( isPulling() ) + { + finishPulling( false ); + return true; + } + + if( isSketching() || isPrepareToSketch() ) + { + finishSketching( false ); + return true; + } + + return false; +} + +//================================================================ +// Function : onBoundingRectChanged +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onBoundingRectChanged() +{ + if( hasInteractionFlag( TraceBoundingRect ) ) + { + 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( hasInteractionFlag( EditFlags ) && nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMousePress( e ); + + if( !anIsHandled && hasInteractionFlag( Dragging ) ) + { + bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey(); + if( ( getHighlightedObject() && + getHighlightedObject()->isMovable() && + !( anAccel || e->button() != Qt::LeftButton ) ) || + ( hasInteractionFlag( DraggingByMiddleButton ) && + nbSelected() && !anAccel && e->button() == Qt::MidButton ) ) + { + myIsDragging = true; + myStoredCursor = cursor(); + setCursor( Qt::ClosedHandCursor ); + } + } + break; + } + case QEvent::GraphicsSceneMouseMove: + { + if( hasInteractionFlag( EditFlags ) && nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMouseMove( e ); + + if( !anIsHandled && !isPulling() && myIsDragging ) + dragObjects( e ); + break; + } + case QEvent::GraphicsSceneMouseRelease: + { + if( hasInteractionFlag( EditFlags ) && nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMouseRelease( e ); + + if( !anIsHandled && !isPulling() && myIsDragging ) + { + emit vpObjectBeforeMoving(); + + bool anIsMoved = false; + for( initSelected(); moreSelected(); nextSelected() ) + if( GraphicsView_Object* aMovingObject = selectedObject() ) + anIsMoved = aMovingObject->finishMove( true ) || anIsMoved; + + if( GraphicsView_Object* aMovingObject = getHighlightedObject() ) + anIsMoved = aMovingObject->finishMove( true ) || anIsMoved; + + myIsDragging = false; + myDragPosition = QPointF(); + setCursor( myStoredCursor ); + + emit vpObjectAfterMoving( anIsMoved ); + } + break; + } + case QEvent::GraphicsSceneMouseDoubleClick: + break; // do nothing, just emit the signal + default: + break; + } + + if( myIsMousePositionEnabled ) + { + int aMouseX = (int)e->scenePos().x(); + int aMouseY = (int)e->scenePos().y(); + setViewLabelText( QString( "(%1, %2)" ).arg( aMouseX ).arg( aMouseY ) ); + } +} + +//================================================================ +// 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( myViewLabel ) + myViewLabel->setAcceptMoveEvents( false ); + + QGraphicsView::scrollContentsBy( theDX, theDY ); + + if( myViewLabel ) + myViewLabel->setAcceptMoveEvents( true ); +} diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h new file mode 100644 index 000000000..1066373a4 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -0,0 +1,337 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef 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 ViewLabel; + + enum InteractionFlag + { + // main flags + Dragging = 0x0001, + Pulling = 0x0002, + WheelScaling = 0x0004, + EditFlags = Dragging | Pulling | WheelScaling, + // advanced flags + TraceBoundingRect = 0x0008, + DraggingByMiddleButton = 0x0010, + ImmediateContextMenu = 0x0020, + ImmediateSelection = 0x0040, + Sketching = 0x0080 + }; + Q_DECLARE_FLAGS( InteractionFlags, InteractionFlag ) + + enum BlockStatus + { + BS_NoBlock = 0x0000, + BS_Selection = 0x0001, // and highlighting + BS_Dragging = 0x0002 // currently unused + }; + + enum ViewLabelPosition + { + VLP_None = 0, + VLP_TopLeft = 1, + VLP_TopRight = 2, + VLP_BottomLeft = 3, + VLP_BottomRight = 4 + }; + +public: + GraphicsView_ViewPort( QWidget* theParent ); + ~GraphicsView_ViewPort(); + +public: + GraphicsView_Scene* getScene() { return myScene; } + void addItem( QGraphicsItem* theItem ); + void removeItem( QGraphicsItem* theItem ); + + enum SortType { NoSorting, SelectedFirst, SortByZLevel }; + GraphicsView_ObjectList getObjects( SortType theSortType = NoSorting ) 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 ); + + // interaction flags + int interactionFlags() const; + bool hasInteractionFlag( InteractionFlag theFlag ); + void setInteractionFlag( InteractionFlag theFlag, + bool theIsEnabled = true ); + void setInteractionFlags( InteractionFlags theFlags ); + + // view label + void setViewLabelPosition( ViewLabelPosition thePosition, + bool theIsForced = false ); + void setViewLabelText( const QString& theText ); + + // displaying mouse position (currently, overlaps with view label feature) + void setMousePositionEnabled( bool theState ); + + // 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; } + + void applyTransform(); + + // 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(); + + // sketching + void prepareToSketch( bool theStatus ); + bool isPrepareToSketch(); + void startSketching( const QPointF& thePoint, + bool theIsPath ); + void drawSketching( const QPointF& thePoint ); + void finishSketching( bool theStatus ); + bool isSketching( bool* theIsPath = 0 ) const; + + // dragging + bool isDragging() { return myIsDragging; } + + // pulling + bool startPulling( const QPointF& ); + void drawPulling( const QPointF& ); + void finishPulling( bool theStatus ); + bool isPulling() const { return myIsPulling; } + + // other + bool cancelCurrentOperation(); + +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; } + static QCursor* getSketchCursor() { return sketchCursor; } + +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 vpSketchingFinished( QPainterPath ); + + 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; + static QCursor* sketchCursor; + +private: + // scene + GraphicsView_Scene* myScene; + double mySceneGap; + double myFitAllGap; + GraphicsView_ObjectList myObjects; + + // interaction flags + InteractionFlags myInteractionFlags; + + // view label + ViewLabel* myViewLabel; + ViewLabelPosition myViewLabelPosition; + QGridLayout* myViewLabelLayout; + + // displaying mouse position (currently, overlaps with view label feature) + bool myIsMousePositionEnabled; + + // 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; + bool myIsHighlighting; + + // selection + GraphicsView_ObjectList mySelectedObjects; + int mySelectionIterator; + + // rectangle selection + QRubberBand* myRectBand; + QPoint myFirstSelectionPoint; + QPoint myLastSelectionPoint; + bool myAreSelectionPointsInitialized; + + // sketching + QGraphicsPathItem* mySketchingItem; + QPointF mySketchingPoint; + bool myIsPrepareToSketch; + bool myIsSketching; + bool myIsSketchingByPath; + + // dragging + int myIsDragging; + QPointF myDragPosition; + bool myIsDragPositionInitialized; + + // pulling + bool myIsPulling; + GraphicsView_Object* myPullingObject; + + // cursor + QCursor myStoredCursor; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS( GraphicsView_ViewPort::InteractionFlags ) + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewTransformer.cxx b/src/GraphicsView/GraphicsView_ViewTransformer.cxx new file mode 100644 index 000000000..47b545fde --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewTransformer.cxx @@ -0,0 +1,293 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "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..7848cdbd1 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewTransformer.h @@ -0,0 +1,95 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef 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..ddaa95713 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -0,0 +1,902 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "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 +#include + +// testing ImageViewer +/* +#include "GraphicsView_PrsImage.h" +#include "GraphicsView_PrsPropDlg.h" +#include +*/ + +//======================================================================= +// Name : GraphicsView_Viewer +// Purpose : Constructor +//======================================================================= +GraphicsView_Viewer::GraphicsView_Viewer( const QString& title ) +: SUIT_ViewModel(), + mySelector( 0 ), + myTransformer( 0 ), + myIsInitialized( 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* ) ) ); + + connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ), + this, SLOT( onSketchingFinished( QPainterPath ) ) ); + + return aViewFrame; +} + +//================================================================ +// Function : contextMenuPopup +// Purpose : +//================================================================ +void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup ) +{ + if( thePopup->actions().count() > 0 ) + thePopup->addSeparator(); + + // testing ImageViewer + /* + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + int aNbSelected = aViewPort->nbSelected(); + if( aNbSelected == 0 ) + { + thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) ); + thePopup->addSeparator(); + + thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) ); + thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) ); + } + else + { + thePopup->addAction( tr( "BRING_TO_FRONT" ), this, SLOT( onBringToFront() ) ); + thePopup->addAction( tr( "SEND_TO_BACK" ), this, SLOT( onSendToBack() ) ); + thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) ); + thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) ); + thePopup->addSeparator(); + + if( aNbSelected == 1 ) + { + thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) ); + thePopup->addSeparator(); + } + + thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) ); + } + 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 : 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 ) +{ + if( e->key() == Qt::Key_Escape ) + { + // Cancel current operation + bool anIsCancelled = false; + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + anIsCancelled = aViewPort->cancelCurrentOperation(); + + // Unselect all objects (if there is no operation to cancel) + if( !anIsCancelled ) + { + aViewPort->finishSelectByRect(); + aViewPort->clearSelected(); + } + } + + // Emit unselection signal + if( !anIsCancelled ) + if( GraphicsView_Selector* aSelector = getSelector() ) + aSelector->unselectAll(); + } +} + +//================================================================ +// 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() ) + { + bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); + if( e->button() == Qt::LeftButton && + aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) && + aViewPort->isPrepareToSketch() ) + { + // Use 'append' flag for sketching by arbitrary path + aViewPort->startSketching( e->scenePos(), append ); + } + else if( e->button() == Qt::LeftButton && + aViewPort->hasInteractionFlag( 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() ); + } + else if( e->button() != Qt::MidButton && !append && + aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) && + aViewPort->nbSelected() < 2 ) + { + // Do not perform 'immediate selection' if the multiple objects are already selected + getSelector()->select( QRectF(), append ); + } + else if( e->button() == Qt::RightButton && + aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) && + aViewPort->nbSelected() < 1 ) + { + // If the 'immediate context menu' mode is enabled, + // try to perform selection before invoking context menu + getSelector()->select( QRectF(), append ); + } + } + } +} + +//================================================================ +// Function : handleMouseMove +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e ) +{ + GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + + // highlight for selection + bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) ); + bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch(); + if ( !anIsDragged && !anIsPrepareToSketch ) + { + if ( getSelector() ) + getSelector()->detect( e->scenePos().x(), e->scenePos().y() ); + } + + // try to activate other operations + if( aViewPort ) + { + if( aViewPort->isPulling() ) + { + aViewPort->drawPulling( e->scenePos() ); + } + else if( aViewPort->isSketching() ) + { + aViewPort->drawSketching( e->scenePos() ); + } + else if( e->button() == Qt::LeftButton && + aViewPort->hasInteractionFlag( 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( true ); + } + else if( aViewPort->isSketching() ) + { + aViewPort->finishSketching( true ); + } + 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->hasInteractionFlag( 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 : onSketchingFinished +// Purpose : +//================================================================ +void GraphicsView_Viewer::onSketchingFinished( QPainterPath thePath ) +{ + // testing ImageViewer + //onTestCropOperatorPerform( thePath ); +} + +//================================================================ +// 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 ); +} + +/* +//================================================================ +// Function : onAddImage +// Purpose : +//================================================================ +void GraphicsView_Viewer::onAddImage() +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + QString aFileName = QFileDialog::getOpenFileName(); + if( aFileName.isEmpty() ) + return; + + GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage(); + + QImage anImage( aFileName ); + aPrs->setImage( anImage ); + + aPrs->compute(); + + aViewPort->addItem( aPrs ); + aViewPort->fitAll(); + } +} + +//================================================================ +// Function : onRemoveImages +// Purpose : +//================================================================ +void GraphicsView_Viewer::onRemoveImages() +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() ); + while( anIter.hasNext() ) + { + if( GraphicsView_PrsImage* aPrs = dynamic_cast( anIter.next() ) ) + { + aViewPort->removeItem( aPrs ); + delete aPrs; + } + } + } +} + +//================================================================ +// Function : onBringToFront +// Purpose : +//================================================================ +void GraphicsView_Viewer::onBringToFront() +{ + processQueueOperation( BringToFront ); +} + +//================================================================ +// Function : onSendToBack +// Purpose : +//================================================================ +void GraphicsView_Viewer::onSendToBack() +{ + processQueueOperation( SendToBack ); +} + +//================================================================ +// Function : onBringForward +// Purpose : +//================================================================ +void GraphicsView_Viewer::onBringForward() +{ + processQueueOperation( BringForward ); +} + +//================================================================ +// Function : onSendBackward +// Purpose : +//================================================================ +void GraphicsView_Viewer::onSendBackward() +{ + processQueueOperation( SendBackward ); +} + +//================================================================ +// Function : processQueueOperation +// Purpose : +//================================================================ +void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation ) +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects(); + + GraphicsView_ObjectList aSortedList; + + GraphicsView_ObjectList aList = aViewPort->getObjects(); + GraphicsView_ObjectListIterator anIter( aList ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = anIter.next() ) + { + if( !anObject->hasSpecificZValue() ) + { + double aZValue = anObject->zValue(); + GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end(); + for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ ) + if( GraphicsView_Object* anObjectRef = *anIter1 ) + if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue ) + break; + aSortedList.insert( anIter1, anObject ); + } + } + } + + QList anIndicesToMove; + + int anIndex = 0; + anIter = aSortedList; + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = anIter.next() ) + if( aSelectedList.contains( anObject ) ) + anIndicesToMove.append( anIndex ); + anIndex++; + } + + bool anIsReverse = theOperation == BringToFront || theOperation == BringForward; + QListIterator anIndicesIter( anIndicesToMove ); + if( anIsReverse ) + anIndicesIter.toBack(); + + int aShiftForMultiple = 0; + int anObjectCount = aSortedList.count(); + while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() ) + { + int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next(); + int aNewIndex = anIndex; + switch( theOperation ) + { + case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break; + case SendToBack: aNewIndex = aShiftForMultiple; break; + case BringForward: aNewIndex = anIndex + 1; break; + case SendBackward: aNewIndex = anIndex - 1; break; + } + aShiftForMultiple++; + + if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 ) + break; + + aSortedList.move( anIndex, aNewIndex ); + } + + double aZValue = 1.0; + anIter = aSortedList; + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = anIter.next() ) + { + anObject->setZValue( aZValue ); + aZValue += 1.0; + } + } + } +} + +//================================================================ +// Function : onPrsProperties +// Purpose : +//================================================================ +void GraphicsView_Viewer::onPrsProperties() +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + aViewPort->initSelected(); + if( GraphicsView_Object* anObject = aViewPort->selectedObject() ) + { + if( GraphicsView_PrsImage* aPrs = dynamic_cast( anObject ) ) + { + double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle; + aPrs->getPosition( aPosX, aPosY ); + aPrs->getScaling( aScaleX, aScaleY ); + aPrs->getRotationAngle( aRotationAngle ); + + double aZValue = aPrs->zValue(); + double anOpacity = aPrs->opacity(); + + bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio(); + bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation(); + + GraphicsView_PrsPropDlg aDlg( aViewPort ); + aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle, + aZValue, anOpacity, anIsLockAspectRatio, + anIsSmoothTransformation ); + if( aDlg.exec() ) + { + aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle, + aZValue, anOpacity, anIsLockAspectRatio, + anIsSmoothTransformation ); + + aPrs->setPosition( aPosX, aPosY ); + aPrs->setScaling( aScaleX, aScaleY ); + aPrs->setRotationAngle( aRotationAngle ); + + aPrs->setZValue( aZValue ); + aPrs->setOpacity( anOpacity ); + + aPrs->setIsLockAspectRatio( anIsLockAspectRatio ); + aPrs->setIsSmoothTransformation( anIsSmoothTransformation ); + + aPrs->compute(); + } + } + } + } +} + +//================================================================ +// Function : onTestFuseOperator +// Purpose : +//================================================================ +void GraphicsView_Viewer::onTestFuseOperator() +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + GraphicsView_ObjectList aList = aViewPort->getObjects(); + if( aList.count() < 3 ) + return; + + GraphicsView_PrsImage* anObj1 = dynamic_cast( aList[0] ); + GraphicsView_PrsImage* anObj2 = dynamic_cast( aList[2] ); + + ImageComposer_Image anImage1; + anImage1 = anObj1->getImage(); + anImage1.setTransform( anObj1->getTransform() ); + + ImageComposer_Image anImage2; + anImage2 = anObj2->getImage(); + anImage2.setTransform( anObj2->getTransform() ); + + ImageComposer_Image aResult = anImage1 | anImage2; + GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage(); + aResPrs->setImage( aResult ); + + double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle; + anObj1->getPosition( aPosX, aPosY ); + anObj1->getScaling( aScaleX, aScaleY ); + anObj1->getRotationAngle( aRotationAngle ); + + aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() ); + aResPrs->setScaling( aScaleX, aScaleY ); + aResPrs->setRotationAngle( aRotationAngle ); + + aResPrs->compute(); + + aViewPort->addItem( aResPrs ); + aViewPort->removeItem( anObj1 ); + aViewPort->removeItem( anObj2 ); + } +} + +//================================================================ +// Function : onTestCropOperatorPrepare +// Purpose : +//================================================================ +void GraphicsView_Viewer::onTestCropOperatorPrepare() +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + aViewPort->prepareToSketch( true ); +} + +//================================================================ +// Function : onTestCropOperatorPerform +// Purpose : +//================================================================ +void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath ) +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + GraphicsView_ObjectList aList = aViewPort->getObjects(); + if( aList.count() < 1 ) + return; + + GraphicsView_PrsImage* anObj = dynamic_cast( aList[0] ); + + ImageComposer_Image anImage; + anImage = anObj->getImage(); + anImage.setTransform( anObj->getTransform() ); + + ImageComposer_Image aResult = anImage & thePath; + GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage(); + aResPrs->setImage( aResult ); + + double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle; + anObj->getPosition( aPosX, aPosY ); + anObj->getScaling( aScaleX, aScaleY ); + anObj->getRotationAngle( aRotationAngle ); + + aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() ); + aResPrs->setScaling( aScaleX, aScaleY ); + aResPrs->setRotationAngle( aRotationAngle ); + + aResPrs->compute(); + + aViewPort->addItem( aResPrs ); + aViewPort->removeItem( anObj ); + } +} +*/ diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h new file mode 100644 index 000000000..ff4c048c4 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -0,0 +1,136 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef GRAPHICSVIEW_VIEWER_H +#define GRAPHICSVIEW_VIEWER_H + +#include "GraphicsView.h" + +#include "GraphicsView_Defs.h" + +#include + +#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 ); + +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 onSketchingFinished( QPainterPath ); + + virtual void onSelectionDone( GV_SelectionChangeStatus ); + virtual void onSelectionCancel(); + + virtual void onChangeBgColor(); + + // testing ImageViewer + /* + void onAddImage(); + void onRemoveImages(); + void onBringToFront(); + void onSendToBack(); + void onBringForward(); + void onSendBackward(); + void onPrsProperties(); + void onTestFuseOperator(); + void onTestCropOperatorPrepare(); + void onTestCropOperatorPerform( QPainterPath thePath ); + */ + +private: + void handleKeyPress( QKeyEvent* ); + void handleKeyRelease( QKeyEvent* ); + void handleMouseMove( QGraphicsSceneMouseEvent* ); + void handleMousePress( QGraphicsSceneMouseEvent* ); + void handleMouseRelease( QGraphicsSceneMouseEvent* ); + void handleWheel( QGraphicsSceneWheelEvent* ); + + // testing ImageViewer + enum QueueOperation { BringToFront, SendToBack, BringForward, SendBackward }; + void processQueueOperation( const QueueOperation ); + +protected: + GraphicsView_Selector* mySelector; + GraphicsView_ViewTransformer* myTransformer; + + bool myIsInitialized; +}; + +#endif diff --git a/src/GraphicsView/Makefile.am b/src/GraphicsView/Makefile.am new file mode 100644 index 000000000..410be324f --- /dev/null +++ b/src/GraphicsView/Makefile.am @@ -0,0 +1,75 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES = libGraphicsView.la + +salomeinclude_HEADERS = \ +GraphicsView_Defs.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_rotate.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 -I$(srcdir)/../ImageComposer +libGraphicsView_la_LDFLAGS = $(QT_MT_LIBS) +libGraphicsView_la_LIBADD = ../SUIT/libsuit.la ../ImageComposer/libImageComposer.la diff --git a/src/GraphicsView/resources/GraphicsView_images.ts b/src/GraphicsView/resources/GraphicsView_images.ts new file mode 100644 index 000000000..ca607b209 --- /dev/null +++ b/src/GraphicsView/resources/GraphicsView_images.ts @@ -0,0 +1,45 @@ + + + @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 + + + ICON_GV_ROTATE + graphics_view_rotate.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..919919eba --- /dev/null +++ b/src/GraphicsView/resources/GraphicsView_msg_en.ts @@ -0,0 +1,124 @@ + + + + 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... + + + ADD_IMAGE + Add image + + + REMOVE_IMAGES + Remove image(s) + + + BRING_TO_FRONT + Bring to front + + + SEND_TO_BACK + Send to back + + + BRING_FORWARD + Bring forward + + + SEND_BACKWARD + Send backward + + + PROPERTIES + Properties + + + TEST_FUSE_OPERATOR + Test Fuse operator + + + TEST_CROP_OPERATOR + Test Crop operator + + + + 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 000000000..0020fea39 Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_cursor_zoom.png differ diff --git a/src/GraphicsView/resources/graphics_view_dump.png b/src/GraphicsView/resources/graphics_view_dump.png new file mode 100644 index 000000000..b02616f29 Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_dump.png differ diff --git a/src/GraphicsView/resources/graphics_view_fitall.png b/src/GraphicsView/resources/graphics_view_fitall.png new file mode 100644 index 000000000..87e001dd8 Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_fitall.png differ diff --git a/src/GraphicsView/resources/graphics_view_fitarea.png b/src/GraphicsView/resources/graphics_view_fitarea.png new file mode 100644 index 000000000..e83d023a3 Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_fitarea.png differ diff --git a/src/GraphicsView/resources/graphics_view_fitselect.png b/src/GraphicsView/resources/graphics_view_fitselect.png new file mode 100755 index 000000000..e52598d7b Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_fitselect.png differ diff --git a/src/GraphicsView/resources/graphics_view_glpan.png b/src/GraphicsView/resources/graphics_view_glpan.png new file mode 100644 index 000000000..28ab547ea Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_glpan.png differ diff --git a/src/GraphicsView/resources/graphics_view_pan.png b/src/GraphicsView/resources/graphics_view_pan.png new file mode 100644 index 000000000..ec56cacc7 Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_pan.png differ diff --git a/src/GraphicsView/resources/graphics_view_reset.png b/src/GraphicsView/resources/graphics_view_reset.png new file mode 100644 index 000000000..66f81e604 Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_reset.png differ diff --git a/src/GraphicsView/resources/graphics_view_rotate.png b/src/GraphicsView/resources/graphics_view_rotate.png new file mode 100755 index 000000000..3f180b40c Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_rotate.png differ diff --git a/src/GraphicsView/resources/graphics_view_zoom.png b/src/GraphicsView/resources/graphics_view_zoom.png new file mode 100644 index 000000000..386c966d1 Binary files /dev/null and b/src/GraphicsView/resources/graphics_view_zoom.png differ diff --git a/src/ImageComposer/CMakeLists.txt b/src/ImageComposer/CMakeLists.txt new file mode 100755 index 000000000..cda4cd568 --- /dev/null +++ b/src/ImageComposer/CMakeLists.txt @@ -0,0 +1,53 @@ +# Copyright (C) 2012-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/UseQT4EXT.cmake) + +INCLUDE_DIRECTORIES( + ${QT_INCLUDES} +) + +SET(COMMON_LIBS + ${QT_LIBRARIES} +) + +SET(ImageComposer_SOURCES + ImageComposer_ColorMaskOperator.cxx + ImageComposer_CropOperator.cxx + ImageComposer_CutOperator.cxx + ImageComposer_FuseOperator.cxx + ImageComposer_Image.cxx + ImageComposer_Operator.cxx +) + +ADD_LIBRARY(ImageComposer ${ImageComposer_SOURCES}) +TARGET_LINK_LIBRARIES(ImageComposer ${COMMON_LIBS}) +INSTALL(TARGETS ImageComposer DESTINATION ${GUI_salomelib_LIBS}) + +SET(COMMON_HEADERS_H + ImageComposer.h + ImageComposer_ColorMaskOperator.h + ImageComposer_CropOperator.h + ImageComposer_CutOperator.h + ImageComposer_FuseOperator.h + ImageComposer_Image.h + ImageComposer_Operator.h +) + +INSTALL(FILES ${COMMON_HEADERS_H} DESTINATION ${GUI_salomeinclude_HEADERS}) diff --git a/src/ImageComposer/ImageComposer.h b/src/ImageComposer/ImageComposer.h new file mode 100644 index 000000000..0192e35d5 --- /dev/null +++ b/src/ImageComposer/ImageComposer.h @@ -0,0 +1,12 @@ + +#ifdef WIN32 + + #if defined IMAGE_COMPOSER_EXPORTS || defined ImageComposer_EXPORTS + #define IMAGE_COMPOSER_API __declspec( dllexport ) + #else + #define IMAGE_COMPOSER_API __declspec( dllimport ) + #endif + +#else + #define IMAGE_COMPOSER_API +#endif diff --git a/src/ImageComposer/ImageComposer_ColorMaskOperator.cxx b/src/ImageComposer/ImageComposer_ColorMaskOperator.cxx new file mode 100644 index 000000000..8f0f64b25 --- /dev/null +++ b/src/ImageComposer/ImageComposer_ColorMaskOperator.cxx @@ -0,0 +1,115 @@ + +#include "ImageComposer_ColorMaskOperator.h" +#include "ImageComposer_Image.h" +#include +#include +#include +#include + +/** + Constructor +*/ +ImageComposer_ColorMaskOperator::ImageComposer_ColorMaskOperator() +: ImageComposer_Operator(), + myRefColor( Qt::black ), myIsMakeTransparent( false ), + myRGBThreshold( 0 ), myAlphaThreshold( 0 ) +{ +} + +/** +*/ +ImageComposer_ColorMaskOperator::~ImageComposer_ColorMaskOperator() +{ +} + +/** + Set operator arguments + @param theRefColor the color to the searched (the color for mask) + @param isMakeTransparent the boolean flag controlling if the pixels with matching color + should be made transparent or one with non-matching color + @param theRGBThreshold the threshold for RGB components + @param theAlphaThreshold the threshold for Alpha component +*/ +void ImageComposer_ColorMaskOperator::setArgs( const QColor& theRefColor, + bool isMakeTransparent, + int theRGBThreshold, + int theAlphaThreshold ) +{ + myRefColor = theRefColor; + myIsMakeTransparent = isMakeTransparent; + myRGBThreshold = theRGBThreshold; + myAlphaThreshold = theAlphaThreshold; +} + +/** +*/ +QString ImageComposer_ColorMaskOperator::name() const +{ + return "colormask"; +} + +/** +*/ +QRectF ImageComposer_ColorMaskOperator::calcResultBoundingRect( const QRectF& theImage1Bounds, + const QRectF& ) const +{ + return theImage1Bounds; +} + +/** +*/ +void ImageComposer_ColorMaskOperator::drawResult( QPainter& thePainter, + const ImageComposer_Image& theImage1, + const ImageComposer_Image& ) const +{ + QImage anImage = theImage1.convertToFormat( QImage::Format_ARGB32 ); + int aRMin = myRefColor.red() - myRGBThreshold; + int aRMax = myRefColor.red() + myRGBThreshold; + int aGMin = myRefColor.green() - myRGBThreshold; + int aGMax = myRefColor.green() + myRGBThreshold; + int aBMin = myRefColor.blue() - myRGBThreshold; + int aBMax = myRefColor.blue() + myRGBThreshold; + int anAMin = myRefColor.alpha() - myAlphaThreshold; + int anAMax = myRefColor.alpha() + myAlphaThreshold; + + QRgb aTransparent = TRANSPARENT.rgba(); + + for( int y = 0, aMaxY = anImage.height(); y < aMaxY; y++ ) + for( int x = 0, aMaxX = anImage.width(); x < aMaxX; x++ ) + { + QRgb* aLine = ( QRgb* )anImage.scanLine( y ); + int aRed = qRed( aLine[x] ); + int aGreen = qGreen( aLine[x] ); + int aBlue = qBlue( aLine[x] ); + int anAlpha = qAlpha( aLine[x] ); + bool isInRange = ( anAMin <= anAlpha && anAlpha <= anAMax ) + && ( aRMin <= aRed && aRed <= aRMax ) + && ( aGMin <= aGreen && aGreen <= aGMax ) + && ( aBMin <= aBlue && aBlue <= aBMax ); + if( myIsMakeTransparent == isInRange ) + aLine[x] = aTransparent; + } + + ImageComposer_Image aResult; + aResult = anImage; + aResult.setTransform( theImage1.transform() ); + aResult.draw( thePainter ); +} + +void ImageComposer_ColorMaskOperator::storeArgs( QDataStream& theStream ) const +{ + ImageComposer_Operator::storeArgs( theStream ); + theStream << myRefColor; + theStream << myIsMakeTransparent; + theStream << myRGBThreshold; + theStream << myAlphaThreshold; +} + +void ImageComposer_ColorMaskOperator::restoreArgs( QDataStream& theStream ) +{ + ImageComposer_Operator::restoreArgs( theStream ); + theStream >> myRefColor; + theStream >> myIsMakeTransparent; + theStream >> myRGBThreshold; + theStream >> myAlphaThreshold; +} diff --git a/src/ImageComposer/ImageComposer_ColorMaskOperator.h b/src/ImageComposer/ImageComposer_ColorMaskOperator.h new file mode 100644 index 000000000..fec0c9025 --- /dev/null +++ b/src/ImageComposer/ImageComposer_ColorMaskOperator.h @@ -0,0 +1,44 @@ + +#ifndef IMAGE_COMPOSER_COLOR_MASK_OPERATOR_HEADER +#define IMAGE_COMPOSER_COLOR_MASK_OPERATOR_HEADER + +#include "ImageComposer_Operator.h" +#include + +/** + \class ImageComposer_ColorMaskOperator + Implementation of the color mask operator +*/ +class IMAGE_COMPOSER_API ImageComposer_ColorMaskOperator : public ImageComposer_Operator +{ +public: + ImageComposer_ColorMaskOperator(); + virtual ~ImageComposer_ColorMaskOperator(); + + void setArgs( const QColor& theRefColor, + bool isMakeTransparent, + int theRGBThreshold, + int theAlphaThreshold ); + + virtual QString name() const; + +protected: + virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds, + const QRectF& theImage2Bounds ) const; + virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const; + + virtual void storeArgs( QDataStream& theStream ) const; + virtual void restoreArgs( QDataStream& theStream ); + +private: + friend class ImageComposerTests_TestOperators; + + QColor myRefColor; ///< the color to the searched (the color for mask) + bool myIsMakeTransparent; ///< the boolean flag controlling if the pixels with matching color + ///< should be made transparent or one with non-matching color + int myRGBThreshold; ///< the threshold for RGB components + int myAlphaThreshold; ///< the threshold for Alpha component +}; + +#endif diff --git a/src/ImageComposer/ImageComposer_CropOperator.cxx b/src/ImageComposer/ImageComposer_CropOperator.cxx new file mode 100644 index 000000000..915205d27 --- /dev/null +++ b/src/ImageComposer/ImageComposer_CropOperator.cxx @@ -0,0 +1,108 @@ + +#include "ImageComposer_CropOperator.h" +#include "ImageComposer_Image.h" +#include +#include + +/** + Constructor +*/ +ImageComposer_CropOperator::ImageComposer_CropOperator() +: ImageComposer_Operator() +{ +} + +/** +*/ +ImageComposer_CropOperator::~ImageComposer_CropOperator() +{ +} + +/** + Set operator arguments + @param theBackground the background color for result image + @param theRect the cropping rectangle (in the global CS) +*/ +void ImageComposer_CropOperator::setArgs( const QColor& theBackground, const QRect& theRect ) +{ + ImageComposer_Operator::setArgs( theBackground ); + myClipPath = QPainterPath(); + myClipPath.addRect( theRect ); +} + +/** + Set operator arguments + @param theBackground the background color for result image + @param thePath the cropping path (in the global CS) +*/ +void ImageComposer_CropOperator::setArgs( const QColor& theBackground, const QPainterPath& thePath ) +{ + ImageComposer_Operator::setArgs( theBackground ); + myClipPath = thePath; +} + +/** + Return clipping path + @return clipping path +*/ +QPainterPath ImageComposer_CropOperator::clipPath() const +{ + return myClipPath; +} + +/** +*/ +QString ImageComposer_CropOperator::name() const +{ + return "crop"; +} + +/** +*/ +QRectF ImageComposer_CropOperator::calcResultBoundingRect( const QRectF&, const QRectF& ) const +{ + return myImgClipPath.boundingRect(); +} + +/** +*/ +void ImageComposer_CropOperator::drawResult( QPainter& thePainter, + const ImageComposer_Image& theImage1, + const ImageComposer_Image& ) const +{ + QRectF aBounds = myImgClipPath.boundingRect(); + QTransform aTranslate; + aTranslate.translate( -aBounds.left(), -aBounds.top() ); + QPainterPath aClipPath = aTranslate.map( myImgClipPath ); + thePainter.setClipPath( aClipPath ); + theImage1.draw( thePainter ); + //thePainter.fillPath( aClipPath, Qt::red ); +} + +/** +*/ +ImageComposer_Image ImageComposer_CropOperator::process( const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const +{ + QRect anImageRect( 0, 0, theImage1.width(), theImage1.height() ); + QPainterPath anImageBoundsPath; + anImageBoundsPath.addPolygon( theImage1.transform().mapToPolygon( anImageRect ) ); + + const_cast( this )->myImgClipPath = + theImage1.transform().inverted().map( myClipPath.intersected( anImageBoundsPath ) ); + + return ImageComposer_Operator::process( theImage1, theImage2 ); +} + + +void ImageComposer_CropOperator::storeArgs( QDataStream& theStream ) const +{ + ImageComposer_Operator::storeArgs( theStream ); + theStream << myClipPath; +} + +void ImageComposer_CropOperator::restoreArgs( QDataStream& theStream ) +{ + ImageComposer_Operator::restoreArgs( theStream ); + theStream >> myClipPath; +} diff --git a/src/ImageComposer/ImageComposer_CropOperator.h b/src/ImageComposer/ImageComposer_CropOperator.h new file mode 100644 index 000000000..1a2525efe --- /dev/null +++ b/src/ImageComposer/ImageComposer_CropOperator.h @@ -0,0 +1,44 @@ + +#ifndef IMAGE_COMPOSER_CROP_OPERATOR_HEADER +#define IMAGE_COMPOSER_CROP_OPERATOR_HEADER + +#include "ImageComposer_Operator.h" +#include +#include + +/** + \class ImageComposer_CropOperator + Implementation of the cropping operator +*/ +class IMAGE_COMPOSER_API ImageComposer_CropOperator : public ImageComposer_Operator +{ +public: + ImageComposer_CropOperator(); + virtual ~ImageComposer_CropOperator(); + + void setArgs( const QColor& theBackground, const QRect& ); + void setArgs( const QColor& theBackground, const QPainterPath& ); + + QPainterPath clipPath() const; + + virtual QString name() const; + virtual ImageComposer_Image process( const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const; + +protected: + virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds, + const QRectF& theImage2Bounds ) const; + virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const; + + virtual void storeArgs( QDataStream& theStream ) const; + virtual void restoreArgs( QDataStream& theStream ); + +private: + friend class ImageComposerTests_TestOperators; + + QPainterPath myClipPath; ///< the clipping path specified initially + QPainterPath myImgClipPath; ///< the clipping path mapped to first image's local CS +}; + +#endif diff --git a/src/ImageComposer/ImageComposer_CutOperator.cxx b/src/ImageComposer/ImageComposer_CutOperator.cxx new file mode 100644 index 000000000..3ecf2265e --- /dev/null +++ b/src/ImageComposer/ImageComposer_CutOperator.cxx @@ -0,0 +1,45 @@ + +#include "ImageComposer_CutOperator.h" +#include "ImageComposer_Image.h" +#include +#include +#include + +/** + Constructor +*/ +ImageComposer_CutOperator::ImageComposer_CutOperator() + : ImageComposer_Operator() +{ +} + +/** +*/ +ImageComposer_CutOperator::~ImageComposer_CutOperator() +{ +} + +/** +*/ +QString ImageComposer_CutOperator::name() const +{ + return "cut"; +} + +/** +*/ +QRectF ImageComposer_CutOperator::calcResultBoundingRect( const QRectF& theImage1Bounds, + const QRectF& ) const +{ + return theImage1Bounds; +} + +/** +*/ +void ImageComposer_CutOperator::drawResult( QPainter& thePainter, + const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const +{ + theImage1.draw( thePainter ); + theImage2.draw( thePainter ); +} diff --git a/src/ImageComposer/ImageComposer_CutOperator.h b/src/ImageComposer/ImageComposer_CutOperator.h new file mode 100644 index 000000000..d85923c41 --- /dev/null +++ b/src/ImageComposer/ImageComposer_CutOperator.h @@ -0,0 +1,27 @@ + +#ifndef IMAGE_COMPOSER_CUT_OPERATOR_HEADER +#define IMAGE_COMPOSER_CUT_OPERATOR_HEADER + +#include "ImageComposer_Operator.h" +#include + +/** + \class ImageComposer_CutOperator + Implementation of the cutting operator +*/ +class IMAGE_COMPOSER_API ImageComposer_CutOperator : public ImageComposer_Operator +{ +public: + ImageComposer_CutOperator(); + virtual ~ImageComposer_CutOperator(); + + virtual QString name() const; + +protected: + virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds, + const QRectF& theImage2Bounds ) const; + virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const; +}; + +#endif diff --git a/src/ImageComposer/ImageComposer_FuseOperator.cxx b/src/ImageComposer/ImageComposer_FuseOperator.cxx new file mode 100644 index 000000000..b68ad1741 --- /dev/null +++ b/src/ImageComposer/ImageComposer_FuseOperator.cxx @@ -0,0 +1,45 @@ + +#include "ImageComposer_FuseOperator.h" +#include "ImageComposer_Image.h" +#include +#include +#include + +/** + Constructor +*/ +ImageComposer_FuseOperator::ImageComposer_FuseOperator() + : ImageComposer_Operator() +{ +} + +/** +*/ +ImageComposer_FuseOperator::~ImageComposer_FuseOperator() +{ +} + +/** +*/ +QString ImageComposer_FuseOperator::name() const +{ + return "fuse"; +} + +/** +*/ +QRectF ImageComposer_FuseOperator::calcResultBoundingRect( const QRectF& theImage1Bounds, + const QRectF& theImage2Bounds ) const +{ + return theImage1Bounds.united( theImage2Bounds ); +} + +/** +*/ +void ImageComposer_FuseOperator::drawResult( QPainter& thePainter, + const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const +{ + theImage1.draw( thePainter ); + theImage2.draw( thePainter ); +} diff --git a/src/ImageComposer/ImageComposer_FuseOperator.h b/src/ImageComposer/ImageComposer_FuseOperator.h new file mode 100644 index 000000000..857ad54e9 --- /dev/null +++ b/src/ImageComposer/ImageComposer_FuseOperator.h @@ -0,0 +1,27 @@ + +#ifndef IMAGE_COMPOSER_FUSE_OPERATOR_HEADER +#define IMAGE_COMPOSER_FUSE_OPERATOR_HEADER + +#include "ImageComposer_Operator.h" +#include + +/** + \class ImageComposer_FuseOperator + Implementation of the fusing operator +*/ +class IMAGE_COMPOSER_API ImageComposer_FuseOperator : public ImageComposer_Operator +{ +public: + ImageComposer_FuseOperator(); + virtual ~ImageComposer_FuseOperator(); + + virtual QString name() const; + +protected: + virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds, + const QRectF& theImage2Bounds ) const; + virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const; +}; + +#endif diff --git a/src/ImageComposer/ImageComposer_Image.cxx b/src/ImageComposer/ImageComposer_Image.cxx new file mode 100644 index 000000000..a7b1a7e6f --- /dev/null +++ b/src/ImageComposer/ImageComposer_Image.cxx @@ -0,0 +1,179 @@ + +#include "ImageComposer_Image.h" +#include "ImageComposer_CropOperator.h" +#include "ImageComposer_CutOperator.h" +#include "ImageComposer_FuseOperator.h" +#include + +QColor ImageComposer_Image::myDefaultBackground = TRANSPARENT; + +/** + Constructor +*/ +ImageComposer_Image::ImageComposer_Image() +{ +} + +/** + Destructor +*/ +ImageComposer_Image::~ImageComposer_Image() +{ +} + +/** + Get current image transformation + @return current image transformation +*/ +QTransform ImageComposer_Image::transform() const +{ + return myTransform; +} + +/** + Change current image transformation + @param theTransform a new image transformation +*/ +void ImageComposer_Image::setTransform( const QTransform& theTransform ) +{ + myTransform = theTransform; +} + +/** + Change current image transformation + @param theDx the image translation along X axis of the global CS + @param theDy the image translation along Y axis of the global CS + @param theRotationDeg the image rotation in degrees around the image center +*/ +void ImageComposer_Image::setLocalTransform( qreal theDx, qreal theDy, qreal theRotationDeg ) +{ + QTransform aTr; + aTr.translate( width()*0.5, height()*0.5 ); + aTr.rotate( theRotationDeg ); + aTr.translate( -width()*0.5, -height()*0.5 ); + aTr.translate( theDx, theDy ); + myTransform = aTr; +} + +/** + Get image's bounding rectangle in the global CS + @return image's bounding rectangle in the global CS +*/ +QRectF ImageComposer_Image::boundingRect() const +{ + QRect aRect( 0, 0, width(), height() ); + return myTransform.mapToPolygon( aRect ).boundingRect(); +} + +/** + Draw the image using the given painter + @param thePainter the painter for image drawing +*/ +void ImageComposer_Image::draw( QPainter& thePainter ) const +{ + thePainter.save(); + thePainter.setTransform( myTransform, true ); + thePainter.drawImage( 0, 0, *this ); + thePainter.restore(); +} + +/** + Operator of another image assignment + @param theImage the image to assign + @return the assigned image +*/ +const ImageComposer_Image& ImageComposer_Image::operator = ( const ImageComposer_Image& theImage ) +{ + myTransform = theImage.myTransform; + QImage::operator = ( ( const QImage& ) theImage ); + return theImage; +} + +/** + Operator of another image assignment + @param theImage the image to assign + @return the assigned image +*/ +const QImage& ImageComposer_Image::operator = ( const QImage& theImage ) +{ + QImage::operator = ( ( const QImage& ) theImage ); + return theImage; +} + +/** + Apply the given operator to the image + @param theOperator the operator to be applied + @param theImage the additional image to compose (optional) + @return the result image +*/ +ImageComposer_Image ImageComposer_Image::apply( const ImageComposer_Operator& theOperator, + const ImageComposer_Image& theImage ) const +{ + return theOperator.process( *this, theImage ); +} + +/** + Get default background color used for image operators + @return default background color +*/ +QColor ImageComposer_Image::defaultBackground() +{ + return myDefaultBackground; +} + +/** + Change default background color used for image operators + @param theDefaultBackground a new default background color +*/ +void ImageComposer_Image::setDefaultBackground( const QColor& theDefaultBackground ) +{ + myDefaultBackground = theDefaultBackground; +} + +/** + Operator of image cropping by a rectangle + @param theRect the rectangle for cropping + @return cropped image +*/ +ImageComposer_Image ImageComposer_Image::operator & ( const QRect& theRect ) const +{ + ImageComposer_CropOperator anOp; + anOp.setArgs( myDefaultBackground, theRect ); + return apply( anOp ); +} + +/** + Operator of image cropping by a path + @param thePath the path for cropping + @return cropped image +*/ +ImageComposer_Image ImageComposer_Image::operator & ( const QPainterPath& thePath ) const +{ + ImageComposer_CropOperator anOp; + anOp.setArgs( myDefaultBackground, thePath ); + return apply( anOp ); +} + +/** + Operator of image cutting by another image + @param theImage the image for cutting + @return cut image +*/ +ImageComposer_Image ImageComposer_Image::operator & ( const ImageComposer_Image& theImage ) const +{ + ImageComposer_CutOperator anOp; + anOp.setArgs( myDefaultBackground ); + return apply( anOp, theImage ); +} + +/** + Operator of image fusing with another image + @param theImage the image for fusing + @return fused image +*/ +ImageComposer_Image ImageComposer_Image::operator | ( const ImageComposer_Image& theImage ) const +{ + ImageComposer_FuseOperator anOp; + anOp.setArgs( myDefaultBackground ); + return apply( anOp, theImage ); +} diff --git a/src/ImageComposer/ImageComposer_Image.h b/src/ImageComposer/ImageComposer_Image.h new file mode 100644 index 000000000..fe3db0186 --- /dev/null +++ b/src/ImageComposer/ImageComposer_Image.h @@ -0,0 +1,46 @@ + +#ifndef IMAGE_COMPOSER_IMAGE_HEADER +#define IMAGE_COMPOSER_IMAGE_HEADER + +#include +#include "ImageComposer.h" + +class ImageComposer_Operator; + +/** + \class ImageComposer_Image + Implementation of image in the global coordinate system +*/ +class IMAGE_COMPOSER_API ImageComposer_Image : public QImage +{ +public: + ImageComposer_Image(); + ~ImageComposer_Image(); + + void draw( QPainter& thePainter ) const; + + QTransform transform() const; + void setTransform( const QTransform& ); + void setLocalTransform( qreal theDx, qreal theDy, qreal theRotationDeg ); + + QRectF boundingRect() const; + + const ImageComposer_Image& operator = ( const ImageComposer_Image& theImage ); + const QImage& operator = ( const QImage& theImage ); + + ImageComposer_Image apply( const ImageComposer_Operator& theOperator, + const ImageComposer_Image& theImage = ImageComposer_Image() ) const; + + static QColor defaultBackground(); + static void setDefaultBackground( const QColor& ); + ImageComposer_Image operator & ( const QRect& ) const; + ImageComposer_Image operator & ( const QPainterPath& ) const; + ImageComposer_Image operator & ( const ImageComposer_Image& ) const; + ImageComposer_Image operator | ( const ImageComposer_Image& ) const; + +private: + QTransform myTransform; ///< the image transformation in the global CS + static QColor myDefaultBackground; ///< the default background color to be used in operators +}; + +#endif diff --git a/src/ImageComposer/ImageComposer_Operator.cxx b/src/ImageComposer/ImageComposer_Operator.cxx new file mode 100644 index 000000000..7a9fde0ad --- /dev/null +++ b/src/ImageComposer/ImageComposer_Operator.cxx @@ -0,0 +1,123 @@ + +#include "ImageComposer_Operator.h" +#include "ImageComposer_Image.h" +#include +#include + +/** + Constructor +*/ +ImageComposer_Operator::ImageComposer_Operator() +: myBackground( TRANSPARENT ) +{ +} + +/** + Destructor +*/ +ImageComposer_Operator::~ImageComposer_Operator() +{ +} + +/** + Set operator arguments + @param theBackground the background color for result image +*/ +void ImageComposer_Operator::setArgs( const QColor& theBackground ) +{ + myBackground = theBackground; +} + +/** + Return name of the operator + @return name of the operator +*/ +QString ImageComposer_Operator::name() const +{ + return ""; +} + +/** + Perform the composing of images + @param theImage1 the first image to compose + @param theImage2 the second image to compose + @return the result image +*/ +ImageComposer_Image ImageComposer_Operator::process( const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const +{ + ImageComposer_Image anImage1 = theImage1; + ImageComposer_Image anImage2 = theImage2; + QTransform aInvTransform = anImage1.transform().inverted(); + anImage1.setTransform( anImage1.transform() * aInvTransform ); + if( !anImage2.isNull() ) + anImage2.setTransform( anImage2.transform() * aInvTransform ); + + QRectF aBounds1 = anImage1.boundingRect(); + QRectF aBounds2; + if( !anImage2.isNull() ) + aBounds2 = anImage2.boundingRect(); + QRectF aBounds = calcResultBoundingRect( aBounds1, aBounds2 ); + + QTransform aTranslate; + aTranslate.translate( -aBounds.left(), -aBounds.top() ); + anImage1.setTransform( anImage1.transform() * aTranslate ); + anImage2.setTransform( anImage2.transform() * aTranslate ); + + QPixmap aResultImage( int(aBounds.width()), int(aBounds.height()) ); + aResultImage.fill( myBackground ); + + QPainter aPainter( &aResultImage ); + aPainter.setRenderHint( QPainter::SmoothPixmapTransform, true ); + aPainter.setRenderHint( QPainter::Antialiasing, true ); + aPainter.setRenderHint( QPainter::HighQualityAntialiasing, true ); + + drawResult( aPainter, anImage1, anImage2 ); + + ImageComposer_Image aResult; + aResult = aResultImage.toImage(); + QTransform aResultTransform = theImage1.transform(); + aResultTransform.translate( aBounds.left(), aBounds.top() ); + aResult.setTransform( aResultTransform ); + return aResult; +} + +/** + Get the operator's arguments in the form of a binary array + @return the binary array with arguments +*/ +QByteArray ImageComposer_Operator::getBinArgs() const +{ + QByteArray aData; + QDataStream aStream( &aData, QIODevice::WriteOnly ); + storeArgs( aStream ); + return aData; +} + +/** + Set the operator's arguments in the form of a binary array + @param theData the binary array with arguments +*/ +void ImageComposer_Operator::setBinArgs( const QByteArray& theData ) +{ + QDataStream aStream( theData ); + restoreArgs( aStream ); +} + +/** + Store the operator's arguments to the stream + @param theStream the stream for storing +*/ +void ImageComposer_Operator::storeArgs( QDataStream& theStream ) const +{ + theStream << myBackground; +} + +/** + Restore the operator's arguments from the stream + @param theStream the stream for restoring +*/ +void ImageComposer_Operator::restoreArgs( QDataStream& theStream ) +{ + theStream >> myBackground; +} diff --git a/src/ImageComposer/ImageComposer_Operator.h b/src/ImageComposer/ImageComposer_Operator.h new file mode 100644 index 000000000..a90b48536 --- /dev/null +++ b/src/ImageComposer/ImageComposer_Operator.h @@ -0,0 +1,62 @@ + +#ifndef IMAGE_COMPOSER_OPERATOR_HEADER +#define IMAGE_COMPOSER_OPERATOR_HEADER + +#include "ImageComposer.h" +#include + +class QString; +class QRectF; +class QPainter; +class QTransform; +class ImageComposer_Image; + +const QColor TRANSPARENT( 255, 255, 255, 0 ); + +/** + \class ImageComposer_Operator + Implementation of the base abstract operation for image composing +*/ +class IMAGE_COMPOSER_API ImageComposer_Operator +{ +public: + ImageComposer_Operator(); + virtual ~ImageComposer_Operator(); + + void setArgs( const QColor& theBackground ); + QByteArray getBinArgs() const; + void setBinArgs( const QByteArray& ); + + virtual QString name() const; + virtual ImageComposer_Image process( const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const; + +protected: + /** + Calculate bounding rectangle for the result image + @param theImage1Bounds bounding rectangle of the first image + @param theImage2Bounds bounding rectangle of the second image + @return calculated bounding rectangle + */ + virtual QRectF calcResultBoundingRect( const QRectF& theImage1Bounds, + const QRectF& theImage2Bounds ) const = 0; + + /** + Draw result image using the given painter + @param thePainter the painter on the result image + @param theImage1 the first image to compose + @param theImage2 the second image to compose + */ + virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1, + const ImageComposer_Image& theImage2 ) const = 0; + + virtual void storeArgs( QDataStream& theStream ) const; + virtual void restoreArgs( QDataStream& theStream ); + +private: + friend class ImageComposerTests_TestOperators; + + QColor myBackground; ///< the background color for result image +}; + +#endif diff --git a/src/ImageComposer/Makefile.am b/src/ImageComposer/Makefile.am new file mode 100644 index 000000000..889c70cc5 --- /dev/null +++ b/src/ImageComposer/Makefile.am @@ -0,0 +1,42 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES = libImageComposer.la + +salomeinclude_HEADERS = \ +ImageComposer.h \ +ImageComposer_ColorMaskOperator.h \ +ImageComposer_CropOperator.h \ +ImageComposer_CutOperator.h \ +ImageComposer_FuseOperator.h \ +ImageComposer_Image.h \ +ImageComposer_Operator.h + +dist_libImageComposer_la_SOURCES = \ +ImageComposer_ColorMaskOperator.cxx \ +ImageComposer_CropOperator.cxx \ +ImageComposer_CutOperator.cxx \ +ImageComposer_FuseOperator.cxx \ +ImageComposer_Image.cxx \ +ImageComposer_Operator.cxx + +libImageComposer_la_CPPFLAGS = $(QT_INCLUDES) +libImageComposer_la_LDFLAGS = $(QT_MT_LIBS) diff --git a/src/LightApp/CMakeLists.txt b/src/LightApp/CMakeLists.txt index 5cfebdd16..023d1b2bd 100755 --- a/src/LightApp/CMakeLists.txt +++ b/src/LightApp/CMakeLists.txt @@ -200,6 +200,16 @@ ELSE(SALOME_USE_GLVIEWER) ADD_DEFINITIONS("-DDISABLE_GLVIEWER") ENDIF(SALOME_USE_GLVIEWER) +IF(SALOME_USE_GRAPHICSVIEW) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../GraphicsView) + SET(COMMON_HEADERS_H ${COMMON_HEADERS_H} LightApp_GVSelector.h) + SET(LightApp_SOURCES ${LightApp_SOURCES} LightApp_GVSelector.cxx) + SET(GUI_HEADERS ${GUI_HEADERS} LightApp_GVSelector.h) + SET(COMMON_LIBS ${COMMON_LIBS} GraphicsView) +ELSE(SALOME_USE_GRAPHICSVIEW) + ADD_DEFINITIONS("-DDISABLE_GRAPHICSVIEW") +ENDIF(SALOME_USE_GRAPHICSVIEW) + IF(SALOME_USE_PLOT2DVIEWER) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../Plot2d) ADD_DEFINITIONS(${QWT_DEFINITIONS}) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 8dd648f27..3d1e6339a 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -154,6 +154,12 @@ #include #endif +#ifndef DISABLE_GRAPHICSVIEW + #include + #include + #include "LightApp_GVSelector.h" +#endif + #define VISIBILITY_COLUMN_WIDTH 25 @@ -669,6 +675,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_GRAPHICSVIEW + 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 +795,11 @@ void LightApp_Application::onNewWindow() case NewQxSceneViewId: type = QxScene_Viewer::Type(); break; +#endif +#ifndef DISABLE_GRAPHICSVIEW + case NewGraphicsViewId: + type = GraphicsView_Viewer::Type(); + break; #endif } @@ -912,6 +926,12 @@ void LightApp_Application::updateCommandsStatus() if( a ) a->setEnabled( activeStudy() ); #endif + +#ifndef DISABLE_GRAPHICSVIEW + a = action( NewGraphicsViewId ); + if( a ) + a->setEnabled( activeStudy() ); +#endif } /*! @@ -1486,6 +1506,13 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType #endif } #endif +#ifndef DISABLE_GRAPHICSVIEW + if( vmType == GraphicsView_Viewer::Type() ) + { + viewMgr = new GraphicsView_ViewManager( activeStudy(), desktop() ); + new LightApp_GVSelector( (GraphicsView_Viewer*)viewMgr->getViewModel(), mySelMgr ); + } +#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/LightApp_GVSelector.cxx b/src/LightApp/LightApp_GVSelector.cxx new file mode 100644 index 000000000..a19aa1c57 --- /dev/null +++ b/src/LightApp/LightApp_GVSelector.cxx @@ -0,0 +1,63 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "LightApp_GVSelector.h" + +#include "LightApp_DataOwner.h" + +#include +#include +#include + +LightApp_GVSelector::LightApp_GVSelector( GraphicsView_Viewer* theViewer, + SUIT_SelectionMgr* theSelMgr ) +: SUIT_Selector( theSelMgr, theViewer ), + myViewer( theViewer ) +{ + connect( theViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ), + this, SLOT( onSelectionChanged( GV_SelectionChangeStatus ) ) ); +} + +LightApp_GVSelector::~LightApp_GVSelector() +{ +} + +QString LightApp_GVSelector::type() const +{ + return GraphicsView_Viewer::Type(); +} + +void LightApp_GVSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const +{ + if( GraphicsView_ViewPort* aViewport = myViewer->getActiveViewPort() ) + for( aViewport->initSelected(); aViewport->moreSelected(); aViewport->nextSelected() ) + theList.append( new LightApp_DataOwner( aViewport->selectedObject()->getName() ) ); +} + +void LightApp_GVSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) +{ +} + +void LightApp_GVSelector::onSelectionChanged( GV_SelectionChangeStatus ) +{ + selectionChanged(); +} diff --git a/src/LightApp/LightApp_GVSelector.h b/src/LightApp/LightApp_GVSelector.h new file mode 100644 index 000000000..f9dfffe13 --- /dev/null +++ b/src/LightApp/LightApp_GVSelector.h @@ -0,0 +1,56 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef LIGHTAPP_GVSELECTOR_H +#define LIGHTAPP_GVSELECTOR_H + +#include "LightApp.h" + +#include +#include +#include +#include + +class GraphicsView_Viewer; + +class LIGHTAPP_EXPORT LightApp_GVSelector : public QObject, public SUIT_Selector +{ + Q_OBJECT + +public: + LightApp_GVSelector( GraphicsView_Viewer*, SUIT_SelectionMgr* ); + virtual ~LightApp_GVSelector(); + + virtual QString type() const; + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); + +protected slots: + void onSelectionChanged( GV_SelectionChangeStatus ); + +protected: + GraphicsView_Viewer* myViewer; +}; + +#endif diff --git a/src/LightApp/Makefile.am b/src/LightApp/Makefile.am index 392e24768..e82031f1f 100755 --- a/src/LightApp/Makefile.am +++ b/src/LightApp/Makefile.am @@ -79,6 +79,9 @@ endif if ENABLE_GLVIEWER salomeinclude_HEADERS += LightApp_GLSelector.h endif +if ENABLE_GRAPHICSVIEW + salomeinclude_HEADERS += LightApp_GVSelector.h +endif if ENABLE_PLOT2DVIEWER salomeinclude_HEADERS += LightApp_Plot2dSelector.h endif @@ -128,6 +131,9 @@ endif if ENABLE_GLVIEWER dist_libLightApp_la_SOURCES += LightApp_GLSelector.cxx endif +if ENABLE_GRAPHICSVIEW + dist_libLightApp_la_SOURCES += LightApp_GVSelector.cxx +endif if ENABLE_PLOT2DVIEWER dist_libLightApp_la_SOURCES += LightApp_Plot2dSelector.cxx endif @@ -162,6 +168,9 @@ endif if ENABLE_GLVIEWER MOC_FILES += LightApp_GLSelector_moc.cxx endif +if ENABLE_GRAPHICSVIEW + MOC_FILES += LightApp_GVSelector_moc.cxx +endif if ENABLE_PLOT2DVIEWER MOC_FILES += LightApp_Plot2dSelector_moc.cxx endif @@ -216,6 +225,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_GRAPHICSVIEW +endif if ENABLE_SUPERVGRAPHVIEWER libLightApp_la_CPPFLAGS += -I$(srcdir)/../SUPERVGraph else !ENABLE_SUPERVGRAPHVIEWER @@ -270,6 +284,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.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/Makefile.am b/src/Makefile.am index f49f706c3..9907e6de8 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,7 +29,7 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am # Common packages ## -SUBDIRS_COMMON = CASCatch Qtx Style DDS QDS ObjBrowser SUIT SUITApp STD CAF CAM LogWindow Prs Event OpenGLUtils GUI_PY +SUBDIRS_COMMON = CASCatch Qtx Style DDS QDS ObjBrowser SUIT SUITApp STD CAF CAM LogWindow Prs Event OpenGLUtils ImageComposer GUI_PY ## # SALOME object @@ -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 \ +DIST_SUBDIRS = CASCatch Qtx Style DDS QDS ObjBrowser SUIT SUITApp STD CAF CAM LogWindow Prs Event OpenGLUtils ImageComposer \ + 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 diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index bdc987b59..3b6a196af 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -1794,6 +1794,16 @@ QWidget* QtxWorkstack::activeWindow() const return myWin; } +/*! + \brief Set active widget + \param wid widget to activate +*/ +void QtxWorkstack::setActiveWindow( QWidget* wid ) +{ + if( activeArea() ) + activeArea()->setActiveWidget( wid ); +} + /*! \brief Split workstack. diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index 9394fed1a..5028325dc 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -93,6 +93,7 @@ public: QWidgetList splitWindowList() const; QWidget* activeWindow() const; + void setActiveWindow( QWidget* ); int accel( const int ) const; void setAccel( const int, const int );