From 7f28cc9804d75f24ca89a9854c501abc33020bff Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 11 Nov 2010 15:20:45 +0000 Subject: [PATCH] New GraphicsView package --- src/GraphicsView/GraphicsView.h | 34 + src/GraphicsView/GraphicsView_Defs.h | 25 + src/GraphicsView/GraphicsView_Geom.h | 4 + src/GraphicsView/GraphicsView_Object.cxx | 134 +++ src/GraphicsView/GraphicsView_Object.h | 81 ++ src/GraphicsView/GraphicsView_Scene.cxx | 126 ++ src/GraphicsView/GraphicsView_Scene.h | 60 + src/GraphicsView/GraphicsView_Selector.cxx | 138 +++ src/GraphicsView/GraphicsView_Selector.h | 75 ++ src/GraphicsView/GraphicsView_ViewFrame.cxx | 310 +++++ src/GraphicsView/GraphicsView_ViewFrame.h | 90 ++ src/GraphicsView/GraphicsView_ViewManager.cxx | 52 + src/GraphicsView/GraphicsView_ViewManager.h | 48 + src/GraphicsView/GraphicsView_ViewPort.cxx | 1052 +++++++++++++++++ src/GraphicsView/GraphicsView_ViewPort.h | 212 ++++ .../GraphicsView_ViewTransformer.cxx | 289 +++++ .../GraphicsView_ViewTransformer.h | 95 ++ src/GraphicsView/GraphicsView_Viewer.cxx | 445 +++++++ src/GraphicsView/GraphicsView_Viewer.h | 109 ++ .../resources/GraphicsView_images.ts | 41 + .../resources/GraphicsView_msg_en.ts | 88 ++ .../resources/graphics_view_cursor_zoom.png | Bin 0 -> 245 bytes .../resources/graphics_view_dump.png | Bin 0 -> 682 bytes .../resources/graphics_view_fitall.png | Bin 0 -> 816 bytes .../resources/graphics_view_fitarea.png | Bin 0 -> 815 bytes .../resources/graphics_view_fitselect.png | Bin 0 -> 857 bytes .../resources/graphics_view_glpan.png | Bin 0 -> 1086 bytes .../resources/graphics_view_pan.png | Bin 0 -> 982 bytes .../resources/graphics_view_reset.png | Bin 0 -> 918 bytes .../resources/graphics_view_zoom.png | Bin 0 -> 797 bytes src/LightApp/LightApp_Application.cxx | 25 + src/LightApp/LightApp_Application.h | 3 +- src/LightApp/resources/LightApp.ini | 1 + src/LightApp/resources/LightApp.xml | 1 + src/LightApp/resources/LightApp_msg_en.ts | 4 + 35 files changed, 3541 insertions(+), 1 deletion(-) create mode 100644 src/GraphicsView/GraphicsView.h create mode 100644 src/GraphicsView/GraphicsView_Defs.h create mode 100644 src/GraphicsView/GraphicsView_Geom.h create mode 100644 src/GraphicsView/GraphicsView_Object.cxx create mode 100644 src/GraphicsView/GraphicsView_Object.h create mode 100644 src/GraphicsView/GraphicsView_Scene.cxx create mode 100644 src/GraphicsView/GraphicsView_Scene.h create mode 100644 src/GraphicsView/GraphicsView_Selector.cxx create mode 100644 src/GraphicsView/GraphicsView_Selector.h create mode 100644 src/GraphicsView/GraphicsView_ViewFrame.cxx create mode 100644 src/GraphicsView/GraphicsView_ViewFrame.h create mode 100644 src/GraphicsView/GraphicsView_ViewManager.cxx create mode 100644 src/GraphicsView/GraphicsView_ViewManager.h create mode 100644 src/GraphicsView/GraphicsView_ViewPort.cxx create mode 100644 src/GraphicsView/GraphicsView_ViewPort.h create mode 100644 src/GraphicsView/GraphicsView_ViewTransformer.cxx create mode 100644 src/GraphicsView/GraphicsView_ViewTransformer.h create mode 100644 src/GraphicsView/GraphicsView_Viewer.cxx create mode 100644 src/GraphicsView/GraphicsView_Viewer.h create mode 100644 src/GraphicsView/resources/GraphicsView_images.ts create mode 100644 src/GraphicsView/resources/GraphicsView_msg_en.ts create mode 100755 src/GraphicsView/resources/graphics_view_cursor_zoom.png create mode 100644 src/GraphicsView/resources/graphics_view_dump.png create mode 100644 src/GraphicsView/resources/graphics_view_fitall.png create mode 100644 src/GraphicsView/resources/graphics_view_fitarea.png create mode 100755 src/GraphicsView/resources/graphics_view_fitselect.png create mode 100644 src/GraphicsView/resources/graphics_view_glpan.png create mode 100644 src/GraphicsView/resources/graphics_view_pan.png create mode 100644 src/GraphicsView/resources/graphics_view_reset.png create mode 100644 src/GraphicsView/resources/graphics_view_zoom.png diff --git a/src/GraphicsView/GraphicsView.h b/src/GraphicsView/GraphicsView.h new file mode 100644 index 000000000..16c7197c9 --- /dev/null +++ b/src/GraphicsView/GraphicsView.h @@ -0,0 +1,34 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifdef WIN32 + +#ifdef GRAPHICSVIEW_EXPORTS +#define GRAPHICSVIEW_API __declspec(dllexport) +#else +#define GRAPHICSVIEW_API __declspec(dllimport) +#endif + +#else +#define GRAPHICSVIEW_API +#endif // WIN32 + diff --git a/src/GraphicsView/GraphicsView_Defs.h b/src/GraphicsView/GraphicsView_Defs.h new file mode 100644 index 000000000..c9046839d --- /dev/null +++ b/src/GraphicsView/GraphicsView_Defs.h @@ -0,0 +1,25 @@ +#ifndef GRAPHICSVIEW_DEFS_H +#define GRAPHICSVIEW_DEFS_H + +#include + +class GraphicsView_Object; +typedef QList GraphicsView_ObjectList; +typedef QListIterator GraphicsView_ObjectListIterator; + +enum GV_SelectionChangeStatus +{ + GVSCS_Invalid, + GVSCS_Local, + GVSCS_Global +}; + +enum GV_SelectionStatus +{ + GVSS_Invalid, + GVSS_LocalChanged, + GVSS_GlobalChanged, + GVSS_NoChanged +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Geom.h b/src/GraphicsView/GraphicsView_Geom.h new file mode 100644 index 000000000..150b92a27 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Geom.h @@ -0,0 +1,4 @@ +#ifndef GRAPHICSVIEW_GEOM_H +#define GRAPHICSVIEW_GEOM_H + +#endif diff --git a/src/GraphicsView/GraphicsView_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx new file mode 100644 index 000000000..2227fe887 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -0,0 +1,134 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_Object.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_Object.h" + +//======================================================================= +// Name : GraphicsView_Object +// Purpose : Constructor +//======================================================================= +GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent ) +: QGraphicsItemGroup( theParent ), + myIsHighlighted( false ), + myIsSelected( false ) +{ +} + +//======================================================================= +// Name : GraphicsView_Object +// Purpose : Destructor +//======================================================================= +GraphicsView_Object::~GraphicsView_Object() +{ +} + +//================================================================ +// Function : setName +// Purpose : +//================================================================ +void GraphicsView_Object::setName( const QString& theName ) +{ + myName = theName; +} + +//================================================================ +// Function : getRect +// Purpose : +//================================================================ +QRectF GraphicsView_Object::getRect() const +{ + return sceneBoundingRect(); +} + +//================================================================ +// Function : checkHighlight +// Purpose : +//================================================================ +bool GraphicsView_Object::checkHighlight( double theX, double theY ) const +{ + return getRect().contains( theX, theY ); +} + +//================================================================ +// Function : highlight +// Purpose : +//================================================================ +bool GraphicsView_Object::highlight( double theX, double theY ) +{ + if( myIsHighlighted = isVisible() ) + myIsHighlighted = checkHighlight( theX, theY ); + return myIsHighlighted; +} + +//================================================================ +// Function : unhighlight +// Purpose : +//================================================================ +void GraphicsView_Object::unhighlight() +{ + myIsHighlighted = false; +} + +//================================================================ +// Function : select +// Purpose : +//================================================================ +bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect ) +{ + if( myIsSelected = isVisible() ) + { + if( !theRect.isNull() ) + myIsSelected = theRect.contains( getRect() ); + else + myIsSelected = checkHighlight( theX, theY ); + } + return myIsSelected; +} + +//================================================================ +// Function : unselect +// Purpose : +//================================================================ +void GraphicsView_Object::unselect() +{ + myIsSelected = false; +} + +//================================================================ +// Function : move +// Purpose : +//================================================================ +void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce ) +{ + moveBy( theDX, theDY ); + if( theIsAtOnce ) + finishMove(); +} + +//================================================================ +// Function : finishMove +// Purpose : +//================================================================ +bool GraphicsView_Object::finishMove() +{ + return true; +} diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h new file mode 100644 index 000000000..e7100d759 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Object.h @@ -0,0 +1,81 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_Object.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_OBJECT_H +#define GRAPHICSVIEW_OBJECT_H + +#include "GraphicsView.h" + +#include + +/* + Class : GraphicsView_Object + Description : Base class for all objects displayed at the scene +*/ +class GRAPHICSVIEW_API GraphicsView_Object : public QGraphicsItemGroup +{ +public: + GraphicsView_Object( QGraphicsItem* theParent = 0 ); + ~GraphicsView_Object(); + + virtual void compute() = 0; + + const QString& getName() const { return myName; } + void setName( const QString& theName ); + + virtual bool isSelectable() const { return true; } + virtual bool isMovable() const { return true; } + + virtual QRectF getRect() const; + + virtual bool highlight( double theX, double theY ); + virtual void unhighlight(); + virtual bool isHighlighted() const { return myIsHighlighted; } + + virtual bool select( double theX, double theY, const QRectF& theRect ); + virtual void unselect(); + virtual bool isSelected() const { return myIsSelected; } + virtual void setSelected( bool theState ) { myIsSelected = theState; } + + virtual void move( double theDX, double theDY, bool theIsAtOnce = false ); + virtual bool finishMove(); + virtual bool isMovingByXAllowed( double theDX ) { return true; } + virtual bool isMovingByYAllowed( double theDY ) { return true; } + + virtual QRectF getPullingRect() const { return getRect(); } + virtual bool portContains( const QPointF& ) { return false; } + virtual bool startPulling( const QPointF& ) { return false; } + virtual void pull( const QPointF&, GraphicsView_Object* ) {} + virtual void finishPulling() {} + virtual bool isPulling() { return false; } + +protected: + virtual bool checkHighlight( double theX, double theY ) const; + +protected: + QString myName; + + bool myIsHighlighted; + bool myIsSelected; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Scene.cxx b/src/GraphicsView/GraphicsView_Scene.cxx new file mode 100644 index 000000000..2b66a218c --- /dev/null +++ b/src/GraphicsView/GraphicsView_Scene.cxx @@ -0,0 +1,126 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_Scene.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_Scene.h" + +//======================================================================= +// Name : GraphicsView_Scene +// Purpose : Constructor +//======================================================================= +GraphicsView_Scene::GraphicsView_Scene( QObject* theParent ) +: QGraphicsScene( theParent ) +{ +} + +//======================================================================= +// Name : GraphicsView_Scene +// Purpose : Destructor +//======================================================================= +GraphicsView_Scene::~GraphicsView_Scene() +{ +} + +//================================================================ +// 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 : 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..d949cdf60 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Scene.h @@ -0,0 +1,60 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_Scene.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_SCENE_H +#define GRAPHICSVIEW_SCENE_H + +#include "GraphicsView.h" + +#include + +/* + Class : 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(); + +protected: + virtual void mousePressEvent( QGraphicsSceneMouseEvent* ); + virtual void mouseMoveEvent( QGraphicsSceneMouseEvent* ); + virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* ); + virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* ); + virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* ); + + virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* ); + virtual void dragLeaveEvent( QGraphicsSceneDragDropEvent* ); + virtual void dragMoveEvent( QGraphicsSceneDragDropEvent* ); + virtual void dropEvent( QGraphicsSceneDragDropEvent* ); + +signals: + void gsMouseEvent( QGraphicsSceneMouseEvent* ); + void gsWheelEvent( QGraphicsSceneWheelEvent* ); + void gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ); +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Selector.cxx b/src/GraphicsView/GraphicsView_Selector.cxx new file mode 100644 index 000000000..c551c452a --- /dev/null +++ b/src/GraphicsView/GraphicsView_Selector.cxx @@ -0,0 +1,138 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_Selector.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_Selector.h" +#include "GraphicsView_Viewer.h" +#include "GraphicsView_ViewPort.h" +#include "GraphicsView_ViewFrame.h" + +int GraphicsView_Selector::appendKey = Qt::ShiftModifier; + +//======================================================================= +// Name : GraphicsView_Selector +// Purpose : Constructor +//======================================================================= +GraphicsView_Selector::GraphicsView_Selector( GraphicsView_Viewer* theViewer ) +: QObject( 0 ), + myViewer( theViewer ), + myLocked( false ) +{ +} + +//======================================================================= +// Name : GraphicsView_Selector +// Purpose : Destructor +//======================================================================= +GraphicsView_Selector::~GraphicsView_Selector() +{ +} + +//================================================================ +// Function : detect +// Purpose : +//================================================================ +void GraphicsView_Selector::detect( double x, double y ) +{ + if ( myLocked ) + return; + + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + aViewPort->highlight( x, y ); +} + +//================================================================ +// Function : undetectAll +// Purpose : +//================================================================ +void GraphicsView_Selector::undetectAll() +{ + if ( myLocked ) + return; + + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + aViewPort->clearHighlighted(); +} + +//================================================================ +// Function : select +// Purpose : +//================================================================ +void GraphicsView_Selector::select( const QRectF& selRect, bool append ) +{ + if ( myLocked ) + return; + + int selBefore = numSelected(); + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + { + int aStatus = aViewPort->select( selRect, append ); + checkSelection( selBefore, append, aStatus ); + } +} + +//================================================================ +// Function : unselectAll +// Purpose : +//================================================================ +void GraphicsView_Selector::unselectAll() +{ + if ( myLocked ) + return; + + if ( numSelected() > 0 ) + emit selSelectionCancel(); +} + +//================================================================ +// Function : checkSelection +// Purpose : +//================================================================ +void GraphicsView_Selector::checkSelection( int selBefore, bool append, int theStatus ) +{ + int selAfter = numSelected(); + if ( selBefore > 0 && selAfter < 1 ) + emit selSelectionCancel(); + else if ( selAfter > 0 ) + { + switch( theStatus ) + { + case GVSS_LocalChanged: + emit selSelectionDone( GVSCS_Local ); + break; + case GVSS_GlobalChanged: + emit selSelectionDone( GVSCS_Global ); + break; + } + } +} + +//================================================================ +// Function : numSelected +// Purpose : +//================================================================ +int GraphicsView_Selector::numSelected() const +{ + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + return aViewPort->nbSelected(); + return 0; +} + diff --git a/src/GraphicsView/GraphicsView_Selector.h b/src/GraphicsView/GraphicsView_Selector.h new file mode 100644 index 000000000..2eb4e1dcb --- /dev/null +++ b/src/GraphicsView/GraphicsView_Selector.h @@ -0,0 +1,75 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_Selector.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_SELECTOR_H +#define GRAPHICSVIEW_SELECTOR_H + +#include "GraphicsView.h" + +#include "GraphicsView_Defs.h" + +#include +#include + +class GraphicsView_Viewer; + +/* + Class : GraphicsView_Selector + Description : Selector of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_Selector : public QObject +{ + Q_OBJECT + +public: + GraphicsView_Selector( GraphicsView_Viewer* ); + ~GraphicsView_Selector(); + +public: + void lock( bool theState ) { myLocked = theState; } + + static int getAppendKey() { return appendKey; } + static void setAppendKey( int k ) { appendKey = k; } + +public: + virtual void detect( double, double ); + virtual void undetectAll(); + + virtual void select( const QRectF&, bool append = false ); + virtual void unselectAll(); + virtual int numSelected() const; + + virtual void checkSelection( int, bool, int ); + +signals: + void selSelectionDone( GV_SelectionChangeStatus ); + void selSelectionCancel(); + +protected: + GraphicsView_Viewer* myViewer; + bool myLocked; + +private: + static int appendKey; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx new file mode 100644 index 000000000..c04eabbd8 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -0,0 +1,310 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_ViewFrame.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_ViewFrame.h" + +#include "GraphicsView_Viewer.h" +#include "GraphicsView_ViewPort.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//======================================================================= +// Name : GraphicsView_ViewFrame +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Viewer* vw ) +: SUIT_ViewWindow( d ), + myViewer( vw ) +{ + QFrame* aFrame = new QFrame( this ); + setCentralWidget( aFrame ); + + QBoxLayout* aLayout = new QHBoxLayout( aFrame ); + aLayout->setMargin( 0 ); + aLayout->setSpacing( 0 ); + + myViewPort = new GraphicsView_ViewPort( aFrame ); + aLayout->addWidget( myViewPort ); + + createActions(); + createToolBar(); + + connect( myViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ), + this, SLOT( mouseEvent( QGraphicsSceneMouseEvent* ) ) ); + connect( myViewPort, SIGNAL( vpWheelEvent( QGraphicsSceneWheelEvent* ) ), + this, SLOT( wheelEvent( QGraphicsSceneWheelEvent* ) ) ); + connect( myViewPort, SIGNAL( vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ), + this, SLOT( contextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) ); +} + +//======================================================================= +// Name : GraphicsView_ViewFrame +// Purpose : Destructor +//======================================================================= +GraphicsView_ViewFrame::~GraphicsView_ViewFrame() +{ +} + +//================================================================ +// Function : createActions +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::createActions() +{ + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QtxAction* anAction; + + // Dump view + anAction = new QtxAction( tr( "MNU_DUMP_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_DUMP" ) ), + tr( "MNU_DUMP_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) ); + toolMgr()->registerAction( anAction, DumpId ); + + // FitAll + anAction = new QtxAction( tr( "MNU_FITALL" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITALL" ) ), + tr( "MNU_FITALL" ), 0, this ); + anAction->setStatusTip( tr( "DSC_FITALL" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitAll() ) ); + toolMgr()->registerAction( anAction, FitAllId ); + + // FitRect + anAction = new QtxAction( tr( "MNU_FITRECT" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITAREA" ) ), + tr( "MNU_FITRECT" ), 0, this ); + anAction->setStatusTip( tr( "DSC_FITRECT" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitArea() ) ); + toolMgr()->registerAction( anAction, FitRectId ); + + // FitSelect + anAction = new QtxAction( tr( "MNU_FITSELECT" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITSELECT" ) ), + tr( "MNU_FITSELECT" ), 0, this ); + anAction->setStatusTip( tr( "DSC_FITSELECT" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitSelect() ) ); + toolMgr()->registerAction( anAction, FitSelectId ); + + // Zoom + anAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_ZOOM" ) ), + tr( "MNU_ZOOM_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewZoom() ) ); + toolMgr()->registerAction( anAction, ZoomId ); + + // Panning + anAction = new QtxAction( tr( "MNU_PAN_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_PAN" ) ), + tr( "MNU_PAN_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_PAN_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewPan() ) ); + toolMgr()->registerAction( anAction, PanId ); + + // Global Panning + anAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_GLOBALPAN" ) ), + tr( "MNU_GLOBALPAN_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewGlobalPan() ) ); + toolMgr()->registerAction( anAction, GlobalPanId ); + + // Reset (obsolete) + /* + anAction = new QtxAction( tr( "MNU_RESET_VIEW" ), + aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_RESET" ) ), + tr( "MNU_RESET_VIEW" ), 0, this ); + anAction->setStatusTip( tr( "DSC_RESET_VIEW" ) ); + connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewReset() ) ); + toolMgr()->registerAction( anAction, ResetId ); + */ +} + +//================================================================ +// Function : createToolBar +// Purpose : +//================================================================ +void GraphicsView_ViewFrame::createToolBar() +{ + int tid = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL") ); + toolMgr()->append( DumpId, tid ); + + QtxMultiAction* aScaleAction = new QtxMultiAction( this ); + aScaleAction->insertAction( toolMgr()->action( FitAllId ) ); + aScaleAction->insertAction( toolMgr()->action( FitRectId ) ); + aScaleAction->insertAction( toolMgr()->action( FitSelectId ) ); + aScaleAction->insertAction( toolMgr()->action( ZoomId ) ); + toolMgr()->append( aScaleAction, tid ); + + QtxMultiAction* aPanAction = new QtxMultiAction( this ); + aPanAction->insertAction( toolMgr()->action( PanId ) ); + aPanAction->insertAction( toolMgr()->action( GlobalPanId ) ); + toolMgr()->append( aPanAction, tid ); + + toolMgr()->append( toolMgr()->action( ResetId ), tid ); +} + +//================================================================ +// Function : dumpView +// Purpose : +//================================================================ +QImage GraphicsView_ViewFrame::dumpView() +{ + return myViewPort->dumpView(); +} + +//================================================================ +// 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 : 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::Wheel: + 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..346b1f43a --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewFrame.h @@ -0,0 +1,90 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_ViewFrame.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWFRAME_H +#define GRAPHICSVIEW_VIEWFRAME_H + +#include "GraphicsView.h" + +#include + +class QGraphicsSceneContextMenuEvent; +class QGraphicsSceneMouseEvent; +class QGraphicsSceneWheelEvent; + +class 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(); + +protected slots: + void onViewPan(); + void onViewZoom(); + void onViewFitAll(); + void onViewFitArea(); + void onViewFitSelect(); + void onViewGlobalPan(); + void onViewReset(); + +private slots: + void mouseEvent( QGraphicsSceneMouseEvent* ); + void wheelEvent( QGraphicsSceneWheelEvent* ); + void contextMenuEvent( QGraphicsSceneContextMenuEvent* ); + +signals: + void mousePressed( QGraphicsSceneMouseEvent* ); + void mouseMoving( QGraphicsSceneMouseEvent* ); + void mouseReleased( QGraphicsSceneMouseEvent* ); + void mouseDoubleClicked( QGraphicsSceneMouseEvent* ); + void wheeling( QGraphicsSceneWheelEvent* ); + +private: + void createActions(); + void createToolBar(); + +private: + GraphicsView_Viewer* myViewer; + GraphicsView_ViewPort* myViewPort; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewManager.cxx b/src/GraphicsView/GraphicsView_ViewManager.cxx new file mode 100644 index 000000000..355e79f06 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewManager.cxx @@ -0,0 +1,52 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_ViewManager.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_ViewManager.h" +#include "GraphicsView_Viewer.h" + +//======================================================================= +// Name : GraphicsView_ViewManager +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewManager::GraphicsView_ViewManager( SUIT_Study* theStudy, + SUIT_Desktop* theDesktop ) +: SUIT_ViewManager( theStudy, theDesktop, new GraphicsView_Viewer( "GraphicsView" ) ) +{ + setTitle( tr( "GRAPHICS_VIEW_TITLE" ) ); +} + +//======================================================================= +// Name : GraphicsView_ViewManager +// Purpose : Destructor +//======================================================================= +GraphicsView_ViewManager::~GraphicsView_ViewManager() +{ +} + +//================================================================ +// Function : getViewer +// Purpose : +//================================================================ +GraphicsView_Viewer* GraphicsView_ViewManager::getViewer() +{ + return dynamic_cast( getViewModel() ); +} diff --git a/src/GraphicsView/GraphicsView_ViewManager.h b/src/GraphicsView/GraphicsView_ViewManager.h new file mode 100644 index 000000000..9609ac84e --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewManager.h @@ -0,0 +1,48 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_ViewManager.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWMANAGER_H +#define GRAPHICSVIEW_VIEWMANAGER_H + +#include "GraphicsView.h" + +#include + +class GraphicsView_Viewer; + +/* + Class : GraphicsView_ViewManager + Description : View manager of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_ViewManager : public SUIT_ViewManager +{ + Q_OBJECT + +public: + GraphicsView_ViewManager( SUIT_Study* theStudy, + SUIT_Desktop* theDesktop ); + virtual ~GraphicsView_ViewManager(); + + GraphicsView_Viewer* getViewer(); +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx new file mode 100644 index 000000000..27de68643 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -0,0 +1,1052 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_ViewPort.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_ViewPort.h" + +#include "GraphicsView_Object.h" +#include "GraphicsView_Scene.h" +#include "GraphicsView_ViewTransformer.h" + +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" + +#include +#include +#include +#include +#include + +#include + +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; + +//================================================================ +// Function : createCursors +// Purpose : +//================================================================ +void GraphicsView_ViewPort::createCursors () +{ + defCursor = new QCursor( Qt::ArrowCursor ); + handCursor = new QCursor( Qt::PointingHandCursor ); + panCursor = new QCursor( Qt::SizeAllCursor ); + panglCursor = new QCursor( Qt::CrossCursor ); + + SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr(); + zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) ); +} + +//================================================================ +// Function : destroyCursors +// Purpose : +//================================================================ +void GraphicsView_ViewPort::destroyCursors() +{ + delete defCursor; defCursor = 0; + delete handCursor; handCursor = 0; + delete panCursor; panCursor = 0; + delete panglCursor; panglCursor = 0; + delete zoomCursor; zoomCursor = 0; +} + +//======================================================================= +// Name : GraphicsView_ViewPort +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) +: QGraphicsView( theParent ), + myForegroundItem( 0 ), + myIsTransforming( false ), + myHighlightedObject( 0 ), + myHighlightX( 0 ), + myHighlightY( 0 ), + mySelectionIterator( 0 ), + myRectBand( 0 ), + myAreSelectionPointsInitialized( false ), + myIsDragging( false ), + myIsDragPositionInitialized( false ), + myIsPulling( false ), + myPullingObject( 0 ) +{ + // scene + myScene = new GraphicsView_Scene( this ); + setScene( myScene ); + + // background + setBackgroundBrush( QBrush( Qt::white ) ); + + // foreground + myIsForegroundEnabled = false; + myForegroundSize = QSizeF( 100, 30 ); + myForegroundMargin = 0.0; + myForegroundColor = Qt::white; + myForegroundFrameColor = Qt::black; + myForegroundFrameLineWidth = 1.0; + + // render hints (default - TextAntialiasing only) + setRenderHints( QPainter::Antialiasing | + QPainter::TextAntialiasing | + QPainter::SmoothPixmapTransform | + QPainter::HighQualityAntialiasing ); + + 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* ) ) ); + + 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 ) +{ + myScene->addItem( theItem ); +} + +//================================================================ +// Function : removeItem +// Purpose : +//================================================================ +void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem ) +{ + if( GraphicsView_Object* anObject = dynamic_cast( theItem ) ) + { + if( myHighlightedObject == anObject ) + myHighlightedObject = 0; + mySelectedObjects.removeAll( anObject ); + } + myScene->removeItem( theItem ); +} + +//================================================================ +// Function : dumpView +// Purpose : +//================================================================ +QImage GraphicsView_ViewPort::dumpView( bool theWholeScene ) +{ + 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; + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + if( aRect.isNull() ) + aRect = anObject->getRect(); + else + aRect |= anObject->getRect(); + } + } + + if( aRect.isNull() ) + return QImage(); + + // store a list of selected objects + GraphicsView_ObjectList aSelectedObjects = mySelectedObjects; + + // unhighlight and unselect all objects + clearHighlighted(); + clearSelected(); + + // render the scene to an image + QImage anImage( aRect.toRect().size(), QImage::Format_RGB32 ); + QPainter aPainter( &anImage ); + QRectF aTargetRect( 0, 0, aRect.width(), aRect.height() ); + myScene->render( &aPainter, aTargetRect, aRect ); + + // restore selection + GraphicsView_ObjectListIterator aSelectedIter( aSelectedObjects ); + while( aSelectedIter.hasNext() ) + if( GraphicsView_Object* anObject = aSelectedIter.next() ) + { + setSelected( anObject ); + anObject->compute(); + } + + return anImage; +} + +//================================================================ +// 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( -1 ); + + QRectF aRect( QPointF(), 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( -20, -20, 20, 20 ) ); + } + else + { + if( myForegroundItem ) + myForegroundItem->setVisible( false ); + } +} + +//================================================================ +// Function : reset +// Purpose : +//================================================================ +void GraphicsView_ViewPort::reset() +{ + fitAll(); +} + +//================================================================ +// Function : pan +// Purpose : +//================================================================ +void GraphicsView_ViewPort::pan( double theDX, double theDY ) +{ + myIsTransforming = true; + + if( QScrollBar* aHBar = horizontalScrollBar() ) + aHBar->setValue( aHBar->value() - theDX ); + if( QScrollBar* aVBar = verticalScrollBar() ) + aVBar->setValue( aVBar->value() + theDY ); + + myIsTransforming = false; +} + +//================================================================ +// Function : setCenter +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setCenter( double theX, double theY ) +{ + myIsTransforming = true; + + setTransform( myCurrentTransform ); + centerOn( theX, theY ); + + myIsTransforming = false; +} + +//================================================================ +// Function : zoom +// Purpose : +//================================================================ +void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, double theY2 ) +{ + myIsTransforming = true; + + double aDX = theX2 - theX1; + double aDY = theY2 - theY1; + double aZoom = sqrt( aDX * aDX + aDY * aDY ) / 100 + 1; + aZoom = ( aDX > 0 ) ? aZoom : 1 / aZoom; + + QTransform aTransform = transform(); + aTransform.scale( aZoom, aZoom ); + double aM11 = aTransform.m11(); + double aM22 = aTransform.m22(); + if( qMax( aM11, aM22 ) < 400 ) // to prevent a crash at the value of 500 + setTransform( aTransform ); + + myIsTransforming = false; +} + +//================================================================ +// Function : fitRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::fitRect( const QRectF& theRect ) +{ + myIsTransforming = true; + + fitInView( theRect, Qt::KeepAspectRatio ); + + myIsTransforming = false; +} + +//================================================================ +// Function : fitSelect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::fitSelect() +{ + myIsTransforming = true; + + QRectF aGlobalRect; + for( initSelected(); moreSelected(); nextSelected() ) + { + if( GraphicsView_Object* aMovingObject = selectedObject() ) + { + QRectF aRect = aMovingObject->getRect(); + if( aGlobalRect.isNull() ) + aGlobalRect = aRect; + else + aGlobalRect |= aRect; + } + } + + if( !aGlobalRect.isNull() ) + { + double aGap = qMax( aGlobalRect.width(), aGlobalRect.height() ) / 5; + aGlobalRect.adjust( -aGap, -aGap, aGap, aGap ); + fitInView( aGlobalRect, Qt::KeepAspectRatio ); + } + + myIsTransforming = false; +} + +//================================================================ +// Function : fitAll +// Purpose : +//================================================================ +void GraphicsView_ViewPort::fitAll( bool theKeepScale ) +{ + myIsTransforming = true; + + if( theKeepScale ) + myCurrentTransform = transform(); + + fitInView( sceneRect(), Qt::KeepAspectRatio ); + + myIsTransforming = false; +} + +//================================================================ +// Function : currentBlock +// Purpose : +//================================================================ +GraphicsView_ViewPort::BlockStatus GraphicsView_ViewPort::currentBlock() +{ + if( isDragging() && !myDragPosition.isNull() ) + return BlockStatus( BS_Selection ); + + if( myAreSelectionPointsInitialized && ( myFirstSelectionPoint != myLastSelectionPoint ) ) + return BlockStatus( BS_Selection ); + + if( isPulling() ) + return BlockStatus( BS_Selection ); + + return BS_NoBlock; +} + +//================================================================ +// Function : highlight +// Purpose : +//================================================================ +void GraphicsView_ViewPort::highlight( double theX, double theY ) +{ + myHighlightX = theX; + myHighlightY = theY; + + bool anIsHighlighted = false; + bool anIsOnObject = false; + + GraphicsView_Object* aPreviousHighlightedObject = myHighlightedObject; + GraphicsView_Object* aHighlightedObject = 0; + + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + if( anObject->isSelectable() ) + { + QRectF aRect = anObject->getRect(); + if( !aRect.isNull() && aRect.contains( theX, theY ) ) + { + anIsOnObject = true; + anIsHighlighted = anObject->highlight( theX, theY ); + } + + if( anIsHighlighted ) + { + aHighlightedObject = anObject; + break; + } + } + } + } + + if( !anIsOnObject ) + { + anIter = items(); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + anObject->unhighlight(); + + myHighlightedObject = 0; + return; + } + else if( !myHighlightedObject && anIsHighlighted ) + { + myHighlightedObject = aHighlightedObject; + } + else if( myHighlightedObject && !anIsHighlighted ) + { + myHighlightedObject->unhighlight(); + myHighlightedObject = 0; + } + else if( myHighlightedObject && anIsHighlighted ) + { + myHighlightedObject->highlight( theX, theY ); + if( myHighlightedObject != aHighlightedObject ) + { + myHighlightedObject->unhighlight(); + myHighlightedObject = aHighlightedObject; + } + } +} + +//================================================================ +// Function : clearHighlighted +// Purpose : +//================================================================ +void GraphicsView_ViewPort::clearHighlighted() +{ + if( myHighlightedObject ) + { + myHighlightedObject->unhighlight(); + myHighlightedObject = 0; + } +} + +//================================================================ +// Function : select +// Purpose : +//================================================================ +int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend ) +{ + GV_SelectionStatus aStatus = GVSS_Invalid; + if( theRect.isNull() ) // point selection + { + if( myHighlightedObject ) + { + if( mySelectedObjects.count() == 1 && + mySelectedObjects.first() == myHighlightedObject ) + aStatus = GVSS_LocalChanged; + + if( !theIsAppend ) + { + GraphicsView_ObjectListIterator anIter( mySelectedObjects ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + if( myHighlightedObject != anObject ) + anObject->unselect(); + + if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid ) + aStatus = GVSS_GlobalChanged; + mySelectedObjects.clear(); + } + else if( myHighlightedObject->isSelected() && aStatus != GVSS_LocalChanged ) + { + mySelectedObjects.removeAll( myHighlightedObject ); + myHighlightedObject->unselect(); + + if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid ) + aStatus = GVSS_GlobalChanged; + + return aStatus; + } + + if( myHighlightedObject->select( myHighlightX, myHighlightY, QRectF() ) && + mySelectedObjects.indexOf( myHighlightedObject ) == -1 ) + { + mySelectedObjects.append( myHighlightedObject ); + if( aStatus == GVSS_Invalid ) + aStatus = GVSS_GlobalChanged; + } + else if( aStatus == GVSS_LocalChanged ) + aStatus = GVSS_GlobalChanged; + + return aStatus; + } + + if( !myHighlightedObject ) + { + if( !theIsAppend ) + { + GraphicsView_ObjectListIterator anIter( mySelectedObjects ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + if( myHighlightedObject != anObject ) + anObject->unselect(); + + if( !mySelectedObjects.isEmpty() ) + aStatus = GVSS_GlobalChanged; + mySelectedObjects.clear(); + } + return aStatus; + } + + return GVSS_NoChanged; + } + else // rectangle selection + { + aStatus = GVSS_NoChanged; + + bool updateAll = false; + if( !theIsAppend ) + { + if( !mySelectedObjects.isEmpty() ) + aStatus = GVSS_GlobalChanged; + + GraphicsView_ObjectListIterator anIter( mySelectedObjects ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + if( myHighlightedObject != anObject ) + anObject->unselect(); + mySelectedObjects.clear(); + } + + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + if( anObject->isSelectable() ) + { + bool anIsSelected = false; + QRectF aRect = anObject->getRect(); + if( theRect.contains( aRect ) ) + anIsSelected = anObject->select( myHighlightX, myHighlightY, theRect ); + + if( anIsSelected && mySelectedObjects.indexOf( anObject ) == -1 ) + { + mySelectedObjects.append( anObject ); + aStatus = GVSS_GlobalChanged; + } + } + } + } + } + return aStatus; +} + +//================================================================ +// Function : clearSelected +// Purpose : +//================================================================ +void GraphicsView_ViewPort::clearSelected() +{ + GraphicsView_ObjectListIterator anIter( mySelectedObjects ); + while( anIter.hasNext() ) + if( GraphicsView_Object* anObject = anIter.next() ) + anObject->unselect(); + mySelectedObjects.clear(); +} + +//================================================================ +// Function : setSelected +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setSelected( GraphicsView_Object* theObject ) +{ + if( theObject ) + { + theObject->setSelected( true ); + mySelectedObjects.append( theObject ); + } +} + +//================================================================ +// Function : nbSelected +// Purpose : +//================================================================ +int GraphicsView_ViewPort::nbSelected() const +{ + return mySelectedObjects.count(); +} + +//================================================================ +// Function : initSelected +// Purpose : +//================================================================ +void GraphicsView_ViewPort::initSelected() +{ + mySelectionIterator = 0; +} + +//================================================================ +// Function : moreSelected +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::moreSelected() +{ + return mySelectionIterator < nbSelected(); +} + +//================================================================ +// Function : nextSelected +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::nextSelected() +{ + if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() ) + { + mySelectionIterator++; + return true; + } + return false; +} + +//================================================================ +// Function : selectedObject +// Purpose : +//================================================================ +GraphicsView_Object* GraphicsView_ViewPort::selectedObject() +{ + return mySelectedObjects[ mySelectionIterator ]; +} + +//================================================================ +// Function : startSelectByRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::startSelectByRect( int x, int y ) +{ + if( !myAreSelectionPointsInitialized ) + { + myFirstSelectionPoint = QPoint( x, y ); + myLastSelectionPoint = QPoint( x, y ); + myAreSelectionPointsInitialized = true; + } + + if( !myRectBand ) + { + myRectBand = new QRubberBand( QRubberBand::Rectangle, this ); + QPalette palette; + palette.setColor( myRectBand->foregroundRole(), Qt::white ); + myRectBand->setPalette( palette ); + } + myRectBand->hide(); +} + +//================================================================ +// Function : drawSelectByRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::drawSelectByRect( int x, int y ) +{ + if( myAreSelectionPointsInitialized ) + { + myRectBand->hide(); + + myLastSelectionPoint.setX( x ); + myLastSelectionPoint.setY( y ); + + QRect aRect = selectionRect(); + myRectBand->setGeometry( aRect ); + myRectBand->setVisible( aRect.isValid() ); + } +} + +//================================================================ +// Function : isSelectByRect +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::isSelectByRect() const +{ + return myAreSelectionPointsInitialized; +} + +//================================================================ +// Function : finishSelectByRect +// Purpose : +//================================================================ +void GraphicsView_ViewPort::finishSelectByRect() +{ + if( myAreSelectionPointsInitialized ) + { + if( myRectBand ) + { + myRectBand->hide(); + delete myRectBand; + myRectBand = 0; + } + + myAreSelectionPointsInitialized = false; + } +} + +//================================================================ +// Function : selectionRect +// Purpose : +//================================================================ +QRect GraphicsView_ViewPort::selectionRect() +{ + QRect aRect; + if( myAreSelectionPointsInitialized ) + { + aRect.setLeft( qMin( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) ); + aRect.setTop( qMin( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) ); + aRect.setRight( qMax( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) ); + aRect.setBottom( qMax( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) ); + } + return aRect; +} + +//================================================================ +// Function : dragObjects +// Purpose : +//================================================================ +void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e ) +{ + GraphicsView_Object* anObject = getHighlightedObject(); + + if( myDragPosition.isNull() ) + { + myDragPosition = e->scenePos(); + return; + } + + GraphicsView_ObjectList anObjectsToMove; + if( anObject && anObject->isMovable() && ( e->buttons() & Qt::LeftButton ) ) + { + if( anObject->isSelected() ) + { + for( initSelected(); moreSelected(); nextSelected() ) + if( GraphicsView_Object* aMovingObject = selectedObject() ) + if( aMovingObject->isMovable() ) + anObjectsToMove.append( aMovingObject ); + } + else + anObjectsToMove.append( anObject ); + } + else if( nbSelected() && ( e->buttons() & Qt::MidButton ) ) + { + for( initSelected(); moreSelected(); nextSelected() ) + if( GraphicsView_Object* aMovingObject = selectedObject() ) + if( aMovingObject->isMovable() ) + anObjectsToMove.append( aMovingObject ); + } + + if( anObjectsToMove.isEmpty() ) + return; + + double aDX = e->scenePos().x() - myDragPosition.x(); + double aDY = e->scenePos().y() - myDragPosition.y(); + + bool anIsMovingByXAllowed = true, anIsMovingByYAllowed = true; + GraphicsView_ObjectListIterator anIter( anObjectsToMove ); + while( anIter.hasNext() ) + if( GraphicsView_Object* aMovingObject = anIter.next() ) + { + if( !aMovingObject->isMovingByXAllowed( aDX ) ) + anIsMovingByXAllowed = false; + if( !aMovingObject->isMovingByYAllowed( aDY ) ) + anIsMovingByYAllowed = false; + } + + if( !anIsMovingByXAllowed && !anIsMovingByYAllowed ) + return; // myDragPosition shouldn't be changed + + if( !anIsMovingByXAllowed ) + aDX = 0; + + if( !anIsMovingByYAllowed ) + aDY = 0; + + anIter = anObjectsToMove; + while( anIter.hasNext() ) + if( GraphicsView_Object* aMovingObject = anIter.next() ) + aMovingObject->move( aDX, aDY ); + + if( anIsMovingByXAllowed ) + myDragPosition.setX( e->scenePos().x() ); + + if( anIsMovingByYAllowed ) + myDragPosition.setY( e->scenePos().y() ); +} + +//================================================================ +// Function : startPulling +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::startPulling( const QPointF& thePoint ) +{ + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + QRectF aRect = anObject->getPullingRect(); + if( aRect.contains( thePoint ) && anObject->startPulling( thePoint ) ) + { + myIsPulling = true; + myPullingObject = anObject; + setCursor( *getHandCursor() ); + return true; + } + } + } + return false; +} + +//================================================================ +// Function : drawPulling +// Purpose : +//================================================================ +void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint ) +{ + GraphicsView_Object* aLockedObject = 0; + + QListIterator anIter( items() ); + while( anIter.hasNext() ) + { + if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) + { + if( !anObject->isVisible() ) + continue; + + QRectF aRect = anObject->getPullingRect(); + if( aRect.contains( thePoint ) && anObject->portContains( thePoint ) ) + { + aLockedObject = anObject; + break; + } + } + } + + myPullingObject->pull( thePoint, aLockedObject ); +} + +//================================================================ +// Function : finishPulling +// Purpose : +//================================================================ +void GraphicsView_ViewPort::finishPulling() +{ + myIsPulling = false; + myPullingObject->finishPulling(); + setCursor( *getDefaultCursor() ); +} + +//================================================================ +// Function : onMouseEvent +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e ) +{ + emit vpMouseEvent( e ); + + switch( e->type() ) + { + case QEvent::GraphicsSceneMousePress: + { + bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey(); + if( ( getHighlightedObject() && + getHighlightedObject()->isMovable() && + !( anAccel || e->button() == Qt::RightButton ) ) || + ( nbSelected() && !anAccel && e->button() == Qt::MidButton ) ) + myIsDragging = true; + break; + } + case QEvent::GraphicsSceneMouseMove: + { + if( !isPulling() && myIsDragging ) + dragObjects( e ); + break; + } + case QEvent::GraphicsSceneMouseRelease: + { + if( !isPulling() && myIsDragging ) + { + bool anIsMoved = false; + for( initSelected(); moreSelected(); nextSelected() ) + if( GraphicsView_Object* aMovingObject = selectedObject() ) + anIsMoved = aMovingObject->finishMove() || anIsMoved; + + if( GraphicsView_Object* aMovingObject = getHighlightedObject() ) + anIsMoved = aMovingObject->finishMove() || anIsMoved; + + myIsDragging = false; + myDragPosition = QPointF(); + + if( anIsMoved ) + emit vpObjectMoved(); + } + break; + } + case QEvent::GraphicsSceneMouseDoubleClick: + break; // do nothing, just emit the signal + default: + break; + } +} + +//================================================================ +// Function : onWheelEvent +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onWheelEvent( QGraphicsSceneWheelEvent* e ) +{ + emit vpWheelEvent( e ); +} + +//================================================================ +// Function : onContextMenuEvent +// Purpose : +//================================================================ +void GraphicsView_ViewPort::onContextMenuEvent( QGraphicsSceneContextMenuEvent* e ) +{ + emit vpContextMenuEvent( e ); +} diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h new file mode 100644 index 000000000..7cfe0ab35 --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -0,0 +1,212 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_ViewPort.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWPORT_H +#define GRAPHICSVIEW_VIEWPORT_H + +#include "GraphicsView.h" + +#include "GraphicsView_Defs.h" + +#include + +class 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: + enum BlockStatus + { + BS_NoBlock = 0x0000, + BS_Selection = 0x0001, // and highlighting + BS_Dragging = 0x0002 // currently unused + }; + +public: + GraphicsView_ViewPort( QWidget* theParent ); + ~GraphicsView_ViewPort(); + +public: + GraphicsView_Scene* getScene() { return myScene; } + void addItem( QGraphicsItem* theItem ); + void removeItem( QGraphicsItem* theItem ); + + QImage dumpView( bool theWholeScene = false ); + +public: + // 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(); + + // 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 ); + + bool isTransforming() const { return myIsTransforming; } + + // block status + BlockStatus currentBlock(); + + // highlighting + virtual void highlight( double theX, double theY ); + void clearHighlighted(); + + GraphicsView_Object* getHighlightedObject() const { return myHighlightedObject; } + + // selection + virtual int select( const QRectF& theRect, bool theIsAppend ); + void clearSelected(); + void setSelected( GraphicsView_Object* theObject ); + + int nbSelected() const; + void initSelected(); + bool moreSelected(); + bool nextSelected(); + GraphicsView_Object* selectedObject(); + + // rectangle selection + void startSelectByRect( int x, int y ); + void drawSelectByRect( int x, int y ); + void finishSelectByRect(); + bool isSelectByRect() const; + QRect selectionRect(); + + // dragging + bool isDragging() { return myIsDragging; } + + // pulling + bool startPulling( const QPointF& ); + void drawPulling( const QPointF& ); + void finishPulling(); + bool isPulling() const { return myIsPulling; } + +public: + static void createCursors(); + static void destroyCursors(); + static QCursor* getDefaultCursor() { return defCursor; } + static QCursor* getHandCursor() { return handCursor; } + static QCursor* getPanCursor() { return panCursor; } + static QCursor* getPanglCursor() { return panglCursor; } + static QCursor* getZoomCursor() { return zoomCursor; } + +protected slots: + void onMouseEvent( QGraphicsSceneMouseEvent* ); + void onWheelEvent( QGraphicsSceneWheelEvent* ); + void onContextMenuEvent( QGraphicsSceneContextMenuEvent* ); + +signals: + void vpMouseEvent( QGraphicsSceneMouseEvent* ); + void vpWheelEvent( QGraphicsSceneWheelEvent* ); + void vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ); + + void vpObjectMoved(); + +private: + void initialize(); + void cleanup(); + + void dragObjects( QGraphicsSceneMouseEvent* ); + +private: + static int nCounter; + static QCursor* defCursor; + static QCursor* handCursor; + static QCursor* panCursor; + static QCursor* panglCursor; + static QCursor* zoomCursor; + +private: + GraphicsView_Scene* myScene; + + // foreground + bool myIsForegroundEnabled; + QSizeF myForegroundSize; + double myForegroundMargin; + QColor myForegroundColor; + QColor myForegroundFrameColor; + double myForegroundFrameLineWidth; + QGraphicsRectItem* myForegroundItem; + + // transformation + bool myIsTransforming; + QTransform myCurrentTransform; + + // highlighting + GraphicsView_Object* myHighlightedObject; + double myHighlightX; + double myHighlightY; + + // selection + GraphicsView_ObjectList mySelectedObjects; + int mySelectionIterator; + + // rectangle selection + QRubberBand* myRectBand; + QPoint myFirstSelectionPoint; + QPoint myLastSelectionPoint; + bool myAreSelectionPointsInitialized; + + // dragging + int myIsDragging; + QPointF myDragPosition; + bool myIsDragPositionInitialized; + + // pulling + bool myIsPulling; + GraphicsView_Object* myPullingObject; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_ViewTransformer.cxx b/src/GraphicsView/GraphicsView_ViewTransformer.cxx new file mode 100644 index 000000000..0f86a85fa --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewTransformer.cxx @@ -0,0 +1,289 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_ViewTransformer.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_ViewTransformer.h" + +#include "GraphicsView_Scene.h" +#include "GraphicsView_ViewPort.h" +#include "GraphicsView_Viewer.h" + +#include +#include +#include + +int GraphicsView_ViewTransformer::panBtn = Qt::MidButton; +int GraphicsView_ViewTransformer::zoomBtn = Qt::LeftButton; +int GraphicsView_ViewTransformer::fitRectBtn = Qt::LeftButton; +int GraphicsView_ViewTransformer::panGlobalBtn = Qt::LeftButton; +int GraphicsView_ViewTransformer::acccelKey = Qt::ControlModifier; + +//======================================================================= +// Name : GraphicsView_ViewTransformer +// Purpose : Constructor +//======================================================================= +GraphicsView_ViewTransformer::GraphicsView_ViewTransformer( GraphicsView_Viewer* v, int type ) +: QObject( 0 ), + myViewer( v ), + myType( type ), + myMajorBtn( Qt::NoButton ), + myButtonState( 0 ), + myRectBand( 0 ) +{ + if( myType == GraphicsView_Viewer::Pan || + myType == GraphicsView_Viewer::Zoom || + myType == GraphicsView_Viewer::PanGlobal || + myType == GraphicsView_Viewer::FitRect ) + initTransform( true ); +} + +//======================================================================= +// Name : GraphicsView_ViewTransformer +// Purpose : Destructor +//======================================================================= +GraphicsView_ViewTransformer::~GraphicsView_ViewTransformer() +{ + if( myType == GraphicsView_Viewer::Pan || + myType == GraphicsView_Viewer::Zoom || + myType == GraphicsView_Viewer::PanGlobal || + myType == GraphicsView_Viewer::FitRect ) + initTransform( false ); + + endDrawRect(); +} + +//================================================================ +// Function : initTransform +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::initTransform( bool init ) +{ + if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) + { + if( GraphicsView_Scene* aScene = aViewPort->getScene() ) + { + if( init ) + { + mySavedCursor = aViewPort->cursor(); + mySavedMouseTrack = aViewPort->hasMouseTracking(); + aViewPort->setMouseTracking( false ); + aScene->installEventFilter( this ); + } + else + { + aScene->removeEventFilter( this ); + aViewPort->setMouseTracking( mySavedMouseTrack ); + aViewPort->setCursor( mySavedCursor ); + } + } + } +} + +//================================================================ +// Function : exec +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::exec() +{ + GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort(); + if( !aViewPort ) + return; + + switch( myType ) + { + case GraphicsView_Viewer::Zoom: + myMajorBtn = zoomButton(); + aViewPort->setCursor( *aViewPort->getZoomCursor() ); + break; + case GraphicsView_Viewer::Pan: + myMajorBtn = panButton(); + aViewPort->setCursor( *aViewPort->getPanCursor() ); + break; + case GraphicsView_Viewer::PanGlobal: + myMajorBtn = panGlobalButton(); + aViewPort->setCursor( *aViewPort->getPanglCursor() ); + aViewPort->fitAll( true ); + break; + case GraphicsView_Viewer::FitRect: + myMajorBtn = fitRectButton(); + aViewPort->setCursor( *aViewPort->getHandCursor() ); + break; + case GraphicsView_Viewer::Reset: + aViewPort->reset(); + onTransform( Finished ); + break; + case GraphicsView_Viewer::FitAll: + aViewPort->fitAll(); + onTransform( Finished ); + break; + case GraphicsView_Viewer::FitSelect: + aViewPort->fitSelect(); + onTransform( Finished ); + break; + default: break; + } +} + +//================================================================ +// Function : eventFilter +// Purpose : +//================================================================ +bool GraphicsView_ViewTransformer::eventFilter( QObject* o, QEvent* e ) +{ + switch( e->type() ) + { + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseRelease: + { + TransformState state = InProcess; + QGraphicsSceneMouseEvent* me = ( QGraphicsSceneMouseEvent* )e; + + myButtonState = me->buttons(); + if ( e->type() == QEvent::GraphicsSceneMousePress ) + myButtonState |= me->button(); + + if ( e->type() == QEvent::GraphicsSceneMouseRelease ) + myButtonState |= me->button(); + + int mouseOnlyState = ( myButtonState & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) ); + if ( myStart.isNull() ) + { + state = Begin; + myStart = myViewer->getActiveViewPort()->mapFromScene( me->scenePos() ); + myMajorBtn = mouseOnlyState; + } + + if ( e->type() == QEvent::GraphicsSceneMouseRelease ) + state = Finished; + + myCurr = myViewer->getActiveViewPort()->mapFromScene( me->scenePos() ); + onTransform( state ); + return true; + } + default: break; + } + return QObject::eventFilter( o, e ); +} + +//================================================================ +// Function : onTransform +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::onTransform( TransformState state ) +{ + GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort(); + if( !aViewPort || aViewPort->isTransforming() ) + return; + + bool doTrsf = ( myButtonState & myMajorBtn ); + switch ( myType ) + { + case GraphicsView_Viewer::Zoom: + if ( state != Finished && doTrsf ) + { + aViewPort->zoom( myStart.x(), myStart.y(), myCurr.x(), myCurr.y() ); + myStart = myCurr; + } + break; + case GraphicsView_Viewer::Pan: + if ( state != Finished && doTrsf ) + { + aViewPort->pan( myCurr.x() - myStart.x(), myStart.y() - myCurr.y() ); + myStart = myCurr; + } + break; + case GraphicsView_Viewer::PanGlobal: + if ( state == Finished ) + { + QPointF aPoint = aViewPort->mapToScene( myCurr.toPoint() ); + aViewPort->setCenter( aPoint.x(), aPoint.y() ); + } + break; + case GraphicsView_Viewer::FitRect: + if ( doTrsf ) + { + QRectF aRect( qMin( myStart.x(), myCurr.x() ), qMin( myStart.y(), myCurr.y() ), + qAbs( myStart.x() - myCurr.x() ), qAbs( myStart.y() - myCurr.y() ) ); + if ( !aRect.isEmpty() ) + { + switch ( state ) + { + case Finished: + aRect = aViewPort->mapToScene( aRect.toRect() ).boundingRect(); + aViewPort->fitRect( aRect ); + break; + default: + drawRect( aRect ); + break; + } + } + } + break; + default: + break; + } + + if ( state == Finished ) + myViewer->activateTransform( GraphicsView_Viewer::NoTransform ); +} + +//================================================================ +// Function : drawRect +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::drawRect(const QRectF& theRect) +{ + if ( !myRectBand ) + { + myRectBand = new QRubberBand( QRubberBand::Rectangle, myViewer->getActiveViewPort() ); + QPalette palette; + palette.setColor(myRectBand->foregroundRole(), Qt::white); + myRectBand->setPalette(palette); + } + myRectBand->hide(); + + myRectBand->setGeometry( theRect.toRect() ); + myRectBand->setVisible( theRect.isValid() ); +} + +//================================================================ +// Function : endDrawRect +// Purpose : +//================================================================ +void GraphicsView_ViewTransformer::endDrawRect() +{ + if ( myRectBand ) + { + myRectBand->hide(); + delete myRectBand; + myRectBand = 0; + } +} + +//================================================================ +// Function : GraphicsView_ViewTransformer +// Purpose : +//================================================================ +int GraphicsView_ViewTransformer::type() const +{ + return myType; +} diff --git a/src/GraphicsView/GraphicsView_ViewTransformer.h b/src/GraphicsView/GraphicsView_ViewTransformer.h new file mode 100644 index 000000000..ee5aa9e3e --- /dev/null +++ b/src/GraphicsView/GraphicsView_ViewTransformer.h @@ -0,0 +1,95 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_ViewTransformer.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWTRANSFORMER_H +#define GRAPHICSVIEW_VIEWTRANSFORMER_H + +#include "GraphicsView.h" + +#include +#include + +class QRectF; +class QRubberBand; + +class GraphicsView_Viewer; + +/* + Class : GraphicsView_ViewTransformer + Description : View transformer of the graphics view +*/ +class GRAPHICSVIEW_API GraphicsView_ViewTransformer : public QObject +{ +public: + GraphicsView_ViewTransformer( GraphicsView_Viewer*, int type ); + ~GraphicsView_ViewTransformer(); + +public: + int type() const; + + static int accelKey() { return acccelKey; } + static void setAccelKey( int k ) { acccelKey = k; } + + static int zoomButton() { return zoomBtn; } + static void setZoomButton( int b ) { zoomBtn = b; } + + static int panButton() { return panBtn; } + static void setPanButton( int b ) { panBtn = b; } + + static int panGlobalButton() { return panGlobalBtn; } + static void setPanGlobalButton( int b ) { panGlobalBtn = b; } + + static int fitRectButton() { return fitRectBtn; } + static void setFitRectButton( int b ) { fitRectBtn = b; } + + virtual void exec(); + virtual bool eventFilter( QObject*, QEvent* ); + +protected: + enum TransformState { Begin, InProcess, Finished }; + virtual void onTransform( TransformState ); + void initTransform( bool ); + + void drawRect( const QRectF& theRect ); + void endDrawRect(); + +protected: + static int panBtn; + static int zoomBtn; + static int fitRectBtn; + static int panGlobalBtn; + + static int acccelKey; + + GraphicsView_Viewer* myViewer; + int myType; + QCursor mySavedCursor; + bool mySavedMouseTrack; + QPointF myStart; + QPointF myCurr; + int myButtonState; + int myMajorBtn; + + QRubberBand* myRectBand; +}; + +#endif diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx new file mode 100644 index 000000000..927a7177b --- /dev/null +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -0,0 +1,445 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_Viewer.cxx +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#include "GraphicsView_Viewer.h" + +#include "GraphicsView_Selector.h" +#include "GraphicsView_Scene.h" +#include "GraphicsView_ViewFrame.h" +#include "GraphicsView_ViewPort.h" +#include "GraphicsView_ViewTransformer.h" + +#include + +#include +#include +#include +#include +#include + +//======================================================================= +// Name : GraphicsView_Viewer +// Purpose : Constructor +//======================================================================= +GraphicsView_Viewer::GraphicsView_Viewer( const QString& title ) +: SUIT_ViewModel(), + mySelector( 0 ), + myTransformer( 0 ) +{ +} + +//======================================================================= +// 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( mousePressed( QGraphicsSceneMouseEvent* ) ), + this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); + + connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ), + this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); + + connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ), + this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); + + connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ), + this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) ); + + return aViewFrame; +} + +//================================================================ +// Function : contextMenuPopup +// Purpose : +//================================================================ +void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup ) +{ + if( thePopup->actions().count() > 0 ) + thePopup->addSeparator(); + + thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) ); +} + +//================================================================ +// Function : getSelector +// Purpose : +//================================================================ +GraphicsView_Selector* GraphicsView_Viewer::getSelector() +{ + if( !mySelector ) + { + mySelector = new GraphicsView_Selector( this ); + if( mySelector ) + { + connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ), + this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) ); + connect( mySelector, SIGNAL( selSelectionCancel() ), + this, SLOT( onSelectionCancel() ) ); + } + } + return mySelector; +} + +//================================================================ +// Function : getActiveView +// Purpose : +//================================================================ +GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const +{ + if( SUIT_ViewManager* aViewManager = getViewManager() ) + return dynamic_cast( aViewManager->getActiveView() ); + return NULL; +} + +//================================================================ +// Function : getActiveViewPort +// Purpose : +//================================================================ +GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const +{ + if( GraphicsView_ViewFrame* aViewFrame = getActiveView() ) + return aViewFrame->getViewPort(); + return NULL; +} + +//================================================================ +// Function : getActiveScene +// Purpose : +//================================================================ +GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const +{ + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + return dynamic_cast( aViewPort->scene() ); + return NULL; +} + +//================================================================ +// Function : activateTransform +// Purpose : +//================================================================ +void GraphicsView_Viewer::activateTransform( int theType ) +{ + if( theType == NoTransform ) // finish current transform + { + if ( myTransformer ) + { + onTransformationFinished(); + delete myTransformer; + myTransformer = 0; + } + } + else // activate new transform + { + activateTransform( NoTransform ); + myTransformer = createTransformer( theType ); + onTransformationStarted(); + myTransformer->exec(); + } +} + +//================================================================ +// Function : 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 : 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::Wheel: + handleWheel( e ); + break; + default: break; + } +} + +//================================================================ +// 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 + startOperations( e ); +} + +//================================================================ +// Function : handleMouseMove +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e ) +{ + // highlight for selection + bool dragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) ); + if ( !dragged ) + { + if ( getSelector() ) + getSelector()->detect( e->scenePos().x(), e->scenePos().y() ); + } + + updateOperations( e ); // try to activate other operations +} + +//================================================================ +// Function : handleMouseRelease +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e ) +{ + // selection + if( e->button() == Qt::LeftButton && + !( getActiveViewPort()->currentBlock() & GraphicsView_ViewPort::BS_Selection ) ) + { + if ( getSelector() ) + { + bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); + getSelector()->select( QRectF(), append ); + } + } + + finishOperations( e ); // try to finish active operations +} + +//================================================================ +// Function : handleWheel +// Purpose : +//================================================================ +void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e ) +{ + startOperations( e ); +} + +//================================================================ +// 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 : startOperations +// Purpose : +//================================================================ +void GraphicsView_Viewer::startOperations( QGraphicsSceneMouseEvent* e ) +{ + GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + + // Try to start pulling if rectangular selection is performed + if( e->button() == Qt::LeftButton && + !aViewPort->isSelectByRect() && + !aViewPort->isDragging() && + aViewPort->startPulling( e->scenePos() ) ) + { + aViewPort->finishSelectByRect(); + return; + } + + // Start rectangular selection if pulling was not started + if( e->button() == Qt::LeftButton && + !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) && + !aViewPort->getHighlightedObject() ) + { + QPoint p = aViewPort->mapFromScene( e->scenePos() ); + aViewPort->startSelectByRect( p.x(), p.y() ); + } +} + +//================================================================ +// Function : updateOperations +// Purpose : +//================================================================ +bool GraphicsView_Viewer::updateOperations( QGraphicsSceneMouseEvent* e ) +{ + GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + + if( aViewPort->isPulling() ) + { + aViewPort->drawPulling( e->scenePos() ); + return true; + } + + if( e->button() == Qt::LeftButton ) + { + if( !aViewPort->isSelectByRect() && !aViewPort->isDragging() && aViewPort->startPulling( e->scenePos() ) ) + { + aViewPort->finishSelectByRect(); + return true; + } + } + + if( !aViewPort->getHighlightedObject() ) + { + QPoint p = aViewPort->mapFromScene( e->scenePos() ); + aViewPort->drawSelectByRect( p.x(), p.y() ); + return true; + } + return false; +} + +//================================================================ +// Function : finishOperations +// Purpose : +//================================================================ +bool GraphicsView_Viewer::finishOperations( QGraphicsSceneMouseEvent* e ) +{ + GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + + if( aViewPort->isPulling() ) + { + aViewPort->finishPulling(); + // Although operation is finished, FALSE is returned because base class try to + // perform selection in this case. In the other case it is impossible to perform + // selection of pulled port + return false; + } + + 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 ); + return true; + } + } + + return false; +} diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h new file mode 100644 index 000000000..d5650c847 --- /dev/null +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -0,0 +1,109 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: GraphicsView_Viewer.h +// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com) +// + +#ifndef GRAPHICSVIEW_VIEWER_H +#define GRAPHICSVIEW_VIEWER_H + +#include "GraphicsView.h" + +#include "GraphicsView_Defs.h" + +#include + +class QGraphicsSceneMouseEvent; +class QGraphicsSceneWheelEvent; + +class 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, 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 ); + +signals: + void selectionChanged( GV_SelectionChangeStatus ); + +protected: + virtual GraphicsView_ViewTransformer* createTransformer( int ); + + virtual void onTransformationStarted(); + virtual void onTransformationFinished(); + + virtual void startOperations( QGraphicsSceneMouseEvent* ); + virtual bool updateOperations( QGraphicsSceneMouseEvent* ); + virtual bool finishOperations( QGraphicsSceneMouseEvent* ); + virtual void startOperations( QGraphicsSceneWheelEvent* ) {} + +protected slots: + virtual void onMouseEvent( QGraphicsSceneMouseEvent* ); + virtual void onWheelEvent( QGraphicsSceneWheelEvent* ); + + virtual void onSelectionDone( GV_SelectionChangeStatus ); + virtual void onSelectionCancel(); + + virtual void onChangeBgColor(); + +private: + void handleMouseMove( QGraphicsSceneMouseEvent* ); + void handleMousePress( QGraphicsSceneMouseEvent* ); + void handleMouseRelease( QGraphicsSceneMouseEvent* ); + void handleWheel( QGraphicsSceneWheelEvent* ); + +protected: + GraphicsView_Selector* mySelector; + GraphicsView_ViewTransformer* myTransformer; +}; + +#endif diff --git a/src/GraphicsView/resources/GraphicsView_images.ts b/src/GraphicsView/resources/GraphicsView_images.ts new file mode 100644 index 000000000..9de9cd021 --- /dev/null +++ b/src/GraphicsView/resources/GraphicsView_images.ts @@ -0,0 +1,41 @@ + + + @default + + ICON_GV_DUMP + graphics_view_dump.png + + + ICON_GV_ZOOM + graphics_view_zoom.png + + + ICON_GV_PAN + graphics_view_pan.png + + + ICON_GV_GLOBALPAN + graphics_view_glpan.png + + + ICON_GV_CURSOR_ZOOM + graphics_view_cursor_zoom.png + + + ICON_GV_FITALL + graphics_view_fitall.png + + + ICON_GV_FITSELECT + graphics_view_fitselect.png + + + ICON_GV_RESET + graphics_view_reset.png + + + ICON_GV_FITAREA + graphics_view_fitarea.png + + + diff --git a/src/GraphicsView/resources/GraphicsView_msg_en.ts b/src/GraphicsView/resources/GraphicsView_msg_en.ts new file mode 100644 index 000000000..a6f2fe92f --- /dev/null +++ b/src/GraphicsView/resources/GraphicsView_msg_en.ts @@ -0,0 +1,88 @@ + + + + GraphicsView_ViewFrame + + DSC_DUMP_VIEW + Saves the active view in the image file + + + DSC_FITALL + Fit all objects inside the view frame + + + DSC_FITRECT + Fit area within the view frame + + + DSC_FITSELECT + Fit area of selection within the view frame + + + DSC_GLOBALPAN_VIEW + Selection of a new center of the view + + + DSC_PAN_VIEW + Pan the view + + + DSC_RESET_VIEW + Reset view point + + + DSC_ZOOM_VIEW + Zoom the view + + + LBL_TOOLBAR_LABEL + View Operations + + + MNU_DUMP_VIEW + Dump + + + MNU_FITALL + Fit All + + + MNU_FITRECT + Fit Area + + + MNU_FITSELECT + Fit Selection + + + MNU_GLOBALPAN_VIEW + Global Pan + + + MNU_PAN_VIEW + Pan + + + MNU_RESET_VIEW + Reset + + + MNU_ZOOM_VIEW + Zoom + + + + GraphicsView_Viewer + + CHANGE_BGCOLOR + Change background... + + + + GraphicsView_ViewManager + + GRAPHICS_VIEW_TITLE + Graphics scene:%M - viewer:%V + + + diff --git a/src/GraphicsView/resources/graphics_view_cursor_zoom.png b/src/GraphicsView/resources/graphics_view_cursor_zoom.png new file mode 100755 index 0000000000000000000000000000000000000000..0020fea39f8531230eb0c25c662b76ee98f696bd GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnH3?%tPCZz)@&H$ef*9{vs0Ga>)|F^Z8<^g0e zmIV0)GdMiEkp|?5mAFQf1m~xflqVLYGNfmw85QKED;Vh+=o#9^?aKhFU`h9MOJ`zW zkPLd4!Up7Lc)B=-RLn_EP!KOz+h7#dX4;UsjI)PRK$4w})1Y}W<0Lc-a$k!M*zN28VxpF`U#yCAY@F9!>Q{yu)SmYHks0PSS(boFyt=akR{08E}qwEzGB literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_dump.png b/src/GraphicsView/resources/graphics_view_dump.png new file mode 100644 index 0000000000000000000000000000000000000000..b02616f2975e7a3865a236ee75380bdae5ce59f7 GIT binary patch literal 682 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VXMsm#F#`j)FbFd;%$g$s6l6(v z^mSxl*w|O|J8&|PuaN8!GAr-fh{`~)M&uq%*z+h+?Aj!ZYz}<83#0idNZ{NHLm{arOf}-0Di4NZr z4h;-Rj?WrQvR=Mwyy^F?%;4dFDJdx)KR>?&vt5iYrhzo>YRaCjpLk={x^?G1e0dpc zAf2Wt^rJsV!+{}D;>9cZGar846mH{Q?tkd0S>BzF%TD3t{4*BXIQ-IfVA%M8i#s*c zlr1kVj?FMpku6S6PGNSxV@Sx9M(Gn`0zzpIgandKboIMkOJX=8&cMX6ys@Kkl!Hi5Cs~Z*GuUfUrsH3ynxPybcSy{#2e*VG@J6ax= z#n~Osp1^ImwK3)gt3rdprHAi&vk!iGdwaWNpPVI=nU9lGQ{we?u{?kG+WrXQ(cn=9 z+IG10^fX=PhwiSfjl8q1O0@zxr4<@xOt_qoo~}Mam+y-f$9#+0wuLz-jo8f1&D+fL z?z+m40n#|u4mYG61ddHVaiyUq`r4~d9q8ZdYn zozP=;ncaEPUC6S9SjZ)j11xdTOVx|PwNDx OD+W(jKbLh*2~7Z6;rO)x literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_fitall.png b/src/GraphicsView/resources/graphics_view_fitall.png new file mode 100644 index 0000000000000000000000000000000000000000..87e001dd80b2755858d4599857106a0c9c0b3500 GIT binary patch literal 816 zcmV-01JC@4P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ;rb$FWRCwBA{Qv(y12q9a0I`6G?+lD6rgAd;XCy{5 zHhlmA#Dc^@mIHB63}s|w3&>x^7VEp$V z!_S{T8NPo0%wTSB4^{^=10aA{2t*_sGYc!&H9+&gF8uxbH^cX@Ux5bxVEFUvH&_hp zNhkmaASMC^p1OMBJi~90i+=rL`10u!!-sco89u&$$ME^%M~1IozA)UpbP22urU4*; z81W@+U>Ndq^YVU}wt5|dps+B*k8j@@e*E~(@bkwHhQELQGJN^`k)bg^7i72+(46}q zJpciO*M(YIT7fc>k_-*mnGENS9|s!*!oPv8y?^^ALw|iO$gn1uVITkyKn&QD3J3!Y zt1#5l`yc4!^j}9?`#%#C(;-P2+5cJwhW{mHWkKFL1H{Sb`Tzn5YousvYge$bu(Yd+ zi!(g^@BtL?iGTn8T>uOM_2*9>%K?=<1!}&AO)o$IVT2*juu`C5U1~tXo&y8^?Uyf= zSFc{}AhvJ-2p}dj!}3{~naMT`1ONgE>_SkfVWO=i2{i0E$eXW$2^NUUfQEGwYY@l` zP;LPTAh-*gnwp;TadI-eff!amiebp56hHvMT?i_^fL=}k3i1H)bfAI1NHGa!20#G8 u4Wv>5%K#8S$g%vNP}zvfo5&o100RIgKz|e1YHVKs0000aa literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_fitarea.png b/src/GraphicsView/resources/graphics_view_fitarea.png new file mode 100644 index 0000000000000000000000000000000000000000..e83d023a332df9a7d3ed0eb708e13260fb870af9 GIT binary patch literal 815 zcmV+~1JL}5P)Zvh0=!8? zK~xyios>&x6Hyd~zu0NDs70YTKG0afETV$oLIhFjgVtKmO2r4bsVfyxv7#GMx+ypn z*KVtBRD6IBT&PP0->u@KRa=@dHc8XYOs35woqJv6M*Fah_J_me-Z|&voOACSq?AZ0 zv1M@7I#mluDaos)rRC3N3TkX@3@|c7!!V>RgA@7J0XKk`z%5|^$d86$NB}K=P!{OM zFmme{tpN^IR&P64y|a#miNd5hI_;uymBe{-f4fYooV+1{{Y&t8O-ITI3J3Vb1`tf{4H=PrPg{|ek) zS+gBqN_-(179wZ9!1Fv@$6@WpjQ|Jo6&EVGv`8z)7Xl%3U}dUOJ7JPLs`K_}=lEOXtqw zSk`+Wu0n<;>|r<@J~Lg@nwOTB)6v^Y)A6G*ec_^cbIZ%=?@JKv=}7{ez$c(rg{8EK zU?rN?yj<5Y2L_16;}3-p@o1!{EE?&V4R}BjNCQ#ey$bcTzraqFXj*ef*NIvdT|a(2 ziN#`FfUSB}49rl__=qe4UW5tZ3HWj}%JL_k{xDGPLC%it*B3}6+oLABz! tx&&)7*jSAOYQQ{TnVN53)MfmaegTLEj1qkO@u>g+002ovPDHLkV1g{1YhM5W literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_fitselect.png b/src/GraphicsView/resources/graphics_view_fitselect.png new file mode 100755 index 0000000000000000000000000000000000000000..e52598d7b5b26b8fb5c5097dc02fc59ec43606c1 GIT binary patch literal 857 zcmV-f1E&0mP)`6sbB}}ri!6#cjYNKxH+dMXhntu59dfWHkT)PgGfFRb+3KSzb$mip9 zUq{#Hd)l_|Km$r^GRs%6ZqsJgY}ja@JbVxphVq%f;_0&hOgb(bTDI=_@Z;?$t*3xW z6KX}MG|ero{Cw*cH?CYd5^EDPVP0>ah{HFt7n@tQ5^7DTG?PkAMX2z7AJ27Jy?#Bw zuGpZQFenM$i??L7qI*4*IzRDXFs0nP;?wT*Ja%ED2-1rnzQ)s@qxI#OW5=KzXc+n21`lVxy&#y3k9r^ksC^> z5vwq^JGXQZ;+-X=-pC*lf<$#SI-QQCzMKWto|3XNV;DTPZ3eU1o0eq_0#2f;l8VMv z;1v-XL}eOTGavt6Pb}B}16CxHpT@8O)BMpi%>f_}+(}l?Bh}Ohwu1;m5(p9kf@#$! zr#XA;tL|==83x0S!(T%~H?!I70AK-kfL{{nG{I+QKx+_Fe})hOAq2BMz1BCYs>r!6 zt=qN%ydT9&|A(pi`ud|m5Hy;mITShjEs8ua{-VH2U?uQg^u~XR3f2b7&+9NbtuKMe j$jL+CLF7!m$d>;B!^B5bH!%%h00000NkvXXu0mjfuh)e| literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_glpan.png b/src/GraphicsView/resources/graphics_view_glpan.png new file mode 100644 index 0000000000000000000000000000000000000000..28ab547eab2e4614b8061252f5cbb4da079c7666 GIT binary patch literal 1086 zcmV-E1i|}>P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZc>jKeOv$OzL15I`)*h9FA-UC3*1Z~uwm?OTSQ4<0bQ ze(?e}13&j7BtjOg8oBY{u_wj195)S?b{&f6+rwNh(Uq* zK0ZGF9!TB4fBzVey$%pSph#d!NlE$3!NI}s_3KxL7r?*=#V#=XRDg2aKr9Qy%0Mg# zwcu`6R@RnZzkY$$K7Ra|;oiM_44*%L1}7(g00Oy$^}~k`3@Z!_7=WS-7i47_^npo& z_1d*NKskL-Yy$BYAm#zl;o;#2riOWv!1Q5tTw%b52J!EBN z_zMj9Ye2(a0MpVAL405VabQDXA%mWt-g{_beh*a#GW3?PurN#?D4ah51P}|7@?T7UooaWF76FUtY(e=N8Ih<%~* zEa-Xx0ti>}^$+SLM<6zX=4AnBQUWFN&ro@cDgYqB0GrW?VpB4t`v3p{07*qoM6N<$ Eg6tg6&Hw-a literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_pan.png b/src/GraphicsView/resources/graphics_view_pan.png new file mode 100644 index 0000000000000000000000000000000000000000..ec56cacc779342a978f183ecf747860c8b6dafb4 GIT binary patch literal 982 zcmV;{11bE8P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZb!otG-18H_3W&!c>DFz52f`;Yh z=KlYG@Zf(vJw1@2;y}!e&rpB>!e<*(Vq)UoNnv3OZ?0TnIIE=v5_imOsnQ(>_Q@}D9Q|HpzmfY=u#@9*!A5&HlE#0WDiKR^HPSD@Ek zzkbaCa@oa;7a4y4{_O{p(+6UCAm#(&Px|`$DQaqJ3~X#{4Da5(V|e)RA;Yz6*FdiR z0t!=r00NsF6BF}yLQoI`!>?Zq4Bx&nFns>Zz!(z)vWNqS-$A_va>-9lVB{=URRycP zpsdWG&(6-kdhOZ^SVRE?5Q~nE&fmqMp$spM9AUWs@+E@^Q1mI#KqwFe;@8la1=_~I z2J*$jJ9ilVe*DOA?ZXF#7k~dU%-7RnNW63j9QyzP#B$}z6$wUv{}&HSOBrrFdBPyW z&(HAr=TDe{d{D#gLnA=o6)=Lf|NhPJ2I#_XKyN<>8oU@7aj@722p~`x$^o%15O2W} zQ4K(R5QwirT?%sXD=g|(05K?CodF0SP#A)o^9gFhL?B)Zjj^{zMn(Vgg6j zxpU_jK79D#4wN$jVr3vsfvN|&{yoSXfB<5F#?CWnLd}P!GmwE_`1tr3R)vHxJUVoU z;RMiI;U7Ty82F(McnHLu(3}E_l-nS400M{wntfhCo&E)yX#avZ-#{@A45MF<9x;Hz z4lSY{BV~fOP)EH02p|@y4KPE$Kyv_tjEu~^`}glN965WI;l_&>3~!m4VFpeGVn3)0 zVaeeeEFA&_5G?D#4E+fW52hzio+tt7dm^Ah;l~e#JMZ4X4D5u`pP`QU2lWw%{s$01 zxUwNTH0uR`vRkc+3M|{L0pd2OxFS>?3IGToW*i2Bk`pV``xg$qd*=yF8X#vr0J$9M zy07T20tg^xJOwPwRUpGpK{Y>y#^wX4;lH73-~b@N0A_|Q{Wj4Xb^rhX07*qoM6N<$ Ef)-GsSpWb4 literal 0 HcmV?d00001 diff --git a/src/GraphicsView/resources/graphics_view_reset.png b/src/GraphicsView/resources/graphics_view_reset.png new file mode 100644 index 0000000000000000000000000000000000000000..66f81e60471b7b587c37166a4e206b45f74e7fc2 GIT binary patch literal 918 zcmV;H18Mw;P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ<3`s;mRCwBA`2YVu0}KO!sHi9>h~bSaP6`GHAOZXQ009Iu ztVK?a_y6WCKL3CH$@>5IfA;^Iw`2aBnTdlW&7exTp@zi+u{AD30Ro7Lk&#hUNQk5Q z?D;STpjR1~nHj+nii&(-KGfwPzyqZXfLH~Ij{*P!hzW=@vvYJAfQEtvwrzdL@b~Y3 zhTx#>3=Q?CrT~SeL)CtP(l4O+3pN7*0*D2Ojg5^(!JOKflMHLu++jF%N|j;rru$QX z!I2B}0Zi>zGy}h4GY}wvKrZ|XauEp3n0^K5WhREsj&mSx69e%89{T_R1ajfcn>Rmz zIq%;60AXz)^A6B;zi?=K-}sfC-?tzTH62r z+1dZM`}+RpVPyp=a)o&VAb=Q=3jlDg;ox}n@#jy5zyJSR0p*SZ#Xz=e0L9NFXlO8m zC@V8qN=Sg!-~8}_;lk_J40EqvXW0Gtu^UimH$VWPmo_{g8)rH={0C|R3ET$aE+9^W z#_sAO0|T(@KsZfX8>D6hvI_wMh!MSr0=mcm=$i9OU0oSe`1u*u-@C_f=i^5PHYO$p zdueHgKqVyxW?=4l`t>V=_OfLRAAkK40Gja;rXL`H7_pRjAVWa`o#`Ya<56K`#Na9` ziz0vj(z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ;lSxEDRCwBA{Qv(y12q9a05LI882|(j3yAp6z=+{Y zPKN)C$b3dd#y}ty1;mO#{0NBG0DZR%T^~RIu^?$iH}pTm97baxo$2V|nd}h|$RH&v z$MF2=6XU&Gw*&&^{D5-Pfd(IhX#xl!22dE{!$2^nw!8QLxyR4`p9SL6kDmTN`QXX_ zWA`8bZ*#;G5q}bli};<&kW}F_F#1|4FCbe zLcl;aW)@bkYk=l~UHJR=Z-(z*zXA>X!SLtTZ?G6R8lV6mfC#zp)YS{;8GeIY^y?SH zmrtJL&@bUdShR+{AGJO5=h2iF{4FCbeh%aFS!;qhwm-oZ8)$14pg@qY@ zeEZJuHQCMa{8~Mt^J>giRqA}jO>3c z1H=E4va%p=odM!xbbSB;gf&vMwY4kQSXkOs#l;z(e)s?i_{6_||1JOqf%@|&kL7?$ zo&q&r!=@J?fH1-kXjm!Gur4*AVb6g9|Mtt5%Bxqec3{&C%ChKL6d-_@&RKiH#D= b009O7QZ{F9XF19?00000NkvXXu0mjfwM|pG literal 0 HcmV?d00001 diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 757449bc3..9c0206afa 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -129,6 +129,11 @@ #include #endif +#ifndef DISABLE_GRAPHICSVIEWER + #include + #include +#endif + #include #include #include @@ -605,6 +610,9 @@ void LightApp_Application::createActions() #ifndef DISABLE_QXGRAPHVIEWER createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_C ); #endif +#ifndef DISABLE_GRAPHICSVIEWER + createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_R ); +#endif createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ), Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) ); @@ -706,6 +714,11 @@ void LightApp_Application::onNewWindow() case NewQxGraphViewId: type = QxGraph_Viewer::Type(); break; +#endif +#ifndef DISABLE_GRAPHICSVIEWER + case NewGraphicsViewId: + type = GraphicsView_Viewer::Type(); + break; #endif } @@ -828,6 +841,12 @@ void LightApp_Application::updateCommandsStatus() if( a ) a->setEnabled( activeStudy() ); #endif + +#ifndef DISABLE_GRAPHICSVIEWER + a = action( NewGraphicsViewId ); + if( a ) + a->setEnabled( activeStudy() ); +#endif } /*! @@ -1352,6 +1371,12 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType #endif } #endif +#ifndef DISABLE_GRAPHICSVIEWER + if( vmType == GraphicsView_Viewer::Type() ) + { + viewMgr = new GraphicsView_ViewManager( activeStudy(), desktop() ); + } +#endif if ( !viewMgr ) return 0; diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index e13cfadbd..ae6522855 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -77,7 +77,8 @@ public: enum { RenameId = CAM_Application::UserID, CloseId, CloseAllId, GroupAllId, PreferencesId, MRUId, ModulesListId, - NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId, UserID }; + NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId, + NewGraphicsViewId, UserID }; protected: enum { NewStudyId = 1, OpenStudyId }; diff --git a/src/LightApp/resources/LightApp.ini b/src/LightApp/resources/LightApp.ini index d88c79409..30d061b36 100755 --- a/src/LightApp/resources/LightApp.ini +++ b/src/LightApp/resources/LightApp.ini @@ -11,6 +11,7 @@ SUIT = $(GUI_ROOT_DIR)/share/salome/resources/gui STD = $(GUI_ROOT_DIR)/share/salome/resources/gui LightApp = $(GUI_ROOT_DIR)/share/salome/resources/gui Plot2d = $(GUI_ROOT_DIR)/share/salome/resources/gui +GraphicsView = $(GUI_ROOT_DIR)/share/salome/resources/gui GLViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui OCCViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui VTKViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 8bb18a43d..71894f13f 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -36,6 +36,7 @@ + diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index 4ec13897c..1a18fac4d 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -357,6 +357,10 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITASNEW_WINDOW_4 &QxGraph view + + NEW_WINDOW_5 + G&raphics view + OBJ_BROWSER_NAME Object -- 2.39.2