dist_admlocalm4_DATA = \
check_disable_Corba.m4 \
check_GLViewer.m4 \
+check_GraphicsView.m4 \
check_GUI.m4 \
check_msg2qm.m4 \
check_OCCViewer.m4 \
--- /dev/null
+#
+# Check configure option --disable-graphicsView=[yes|no|DIR] taking into account that
+# DISABLE_GRAPHICSVIEW may be already set during build_configure,
+# Set DISABLE_GRAPHICSVIEW to yes|no
+#
+# Author : Kirill Afonshin (DTN, 2010)
+#
+
+AC_DEFUN([CHECK_GRAPHICSVIEW],[
+
+AC_ARG_WITH(graphicsView,
+ [ --disable-graphicsView default=no ],
+ disable_graphicsView="$withval",disable_graphicsView="${DISABLE_GRAPHICSVIEW}")
+
+case $disable_graphicsView in
+ yes)
+# AC_MSG_RESULT(************************************************)
+# AC_MSG_RESULT(***** DISABLE GraphicsView configuration *****)
+# AC_MSG_RESULT(************************************************)
+ DISABLE_GRAPHICSVIEW="yes"
+ AC_SUBST(DISABLE_GRAPHICSVIEW)
+esac
+
+
+])dnl
DISABLE_GLVIEWER="yes"
fi
+if test "x${enable_graphicsView}" != "xno" ; then
+ DISABLE_GRAPHICSVIEW="no"
+else
+ DISABLE_GRAPHICSVIEW="yes"
+fi
+
if test "x${enable_plot2dViewer}" != "xno" ; then
DISABLE_PLOT2DVIEWER="no"
else
CHECK_GLVIEWER
echo "DISABLE_GLVIEWER = "$DISABLE_GLVIEWER
+echo
+echo ---------------------------------------------
+echo Testing GraphicsView
+echo ---------------------------------------------
+echo
+
+CHECK_GRAPHICSVIEW
+echo "DISABLE_GRAPHICSVIEW = "$DISABLE_GRAPHICSVIEW
+
echo
echo ---------------------------------------------
echo Testing Plot2dViewer
AM_CONDITIONAL(GUI_ENABLE_CORBA, [test "$GUI_DISABLE_CORBA" = no])
AM_CONDITIONAL(ENABLE_PYCONSOLE, [test "$DISABLE_PYCONSOLE" = no])
AM_CONDITIONAL(ENABLE_GLVIEWER, [test "$DISABLE_GLVIEWER" = no])
+AM_CONDITIONAL(ENABLE_GRAPHICSVIEW, [test "$DISABLE_GRAPHICSVIEW" = no])
AM_CONDITIONAL(ENABLE_PLOT2DVIEWER, [test "$DISABLE_PLOT2DVIEWER" = no])
AM_CONDITIONAL(ENABLE_SUPERVGRAPHVIEWER, [test "$DISABLE_SUPERVGRAPHVIEWER" = no])
AM_CONDITIONAL(ENABLE_OCCVIEWER, [test "$DISABLE_OCCVIEWER" = no])
src/OBJECT/Makefile \
src/ViewerTools/Makefile \
src/GLViewer/Makefile \
+ src/GraphicsView/Makefile \
src/VTKViewer/Makefile \
src/SVTK/Makefile \
src/OCCViewer/Makefile \
--- /dev/null
+// 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
+
--- /dev/null
+#ifndef GRAPHICSVIEW_DEFS_H
+#define GRAPHICSVIEW_DEFS_H
+
+#include <QList>
+
+class GraphicsView_Object;
+typedef QList<GraphicsView_Object*> GraphicsView_ObjectList;
+typedef QListIterator<GraphicsView_Object*> GraphicsView_ObjectListIterator;
+
+enum GV_SelectionChangeStatus
+{
+ GVSCS_Invalid,
+ GVSCS_Local,
+ GVSCS_Global
+};
+
+enum GV_SelectionStatus
+{
+ GVSS_Invalid,
+ GVSS_LocalChanged,
+ GVSS_GlobalChanged,
+ GVSS_NoChanged
+};
+
+#endif
--- /dev/null
+#ifndef GRAPHICSVIEW_GEOM_H
+#define GRAPHICSVIEW_GEOM_H
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Object.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_Object.h"
+
+#include "GraphicsView_Scene.h"
+
+//=======================================================================
+// Name : GraphicsView_Object
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent )
+: QGraphicsItemGroup( theParent ),
+ myPriority( 0 ),
+ myIsOnTop( false ),
+ myIsHighlighted( false ),
+ myIsSelected( false )
+{
+}
+
+//=======================================================================
+// Name : GraphicsView_Object
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_Object::~GraphicsView_Object()
+{
+}
+
+//================================================================
+// Function : setName
+// Purpose :
+//================================================================
+void GraphicsView_Object::setName( const QString& theName )
+{
+ myName = theName;
+}
+
+//================================================================
+// Function : getRect
+// Purpose :
+//================================================================
+QRectF GraphicsView_Object::getRect() const
+{
+ return sceneBoundingRect();
+}
+
+//================================================================
+// Function : checkHighlight
+// Purpose :
+//================================================================
+bool GraphicsView_Object::checkHighlight( double theX, double theY ) const
+{
+ return getRect().contains( theX, theY );
+}
+
+//================================================================
+// Function : highlight
+// Purpose :
+//================================================================
+bool GraphicsView_Object::highlight( double theX, double theY )
+{
+ if( myIsHighlighted = isVisible() )
+ myIsHighlighted = checkHighlight( theX, theY );
+ return myIsHighlighted;
+}
+
+//================================================================
+// Function : unhighlight
+// Purpose :
+//================================================================
+void GraphicsView_Object::unhighlight()
+{
+ myIsHighlighted = false;
+}
+
+//================================================================
+// Function : select
+// Purpose :
+//================================================================
+bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect )
+{
+ if( myIsSelected = isVisible() )
+ {
+ if( !theRect.isNull() )
+ myIsSelected = theRect.contains( getRect() );
+ else
+ myIsSelected = checkHighlight( theX, theY );
+ }
+ return myIsSelected;
+}
+
+//================================================================
+// Function : unselect
+// Purpose :
+//================================================================
+void GraphicsView_Object::unselect()
+{
+ myIsSelected = false;
+}
+
+//================================================================
+// Function : move
+// Purpose :
+//================================================================
+void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce )
+{
+ moveBy( theDX, theDY );
+ if( theIsAtOnce )
+ finishMove();
+}
+
+//================================================================
+// Function : finishMove
+// Purpose :
+//================================================================
+bool GraphicsView_Object::finishMove()
+{
+ if( GraphicsView_Scene* aScene = dynamic_cast<GraphicsView_Scene*>( scene() ) )
+ aScene->processRectChanged();
+ return true;
+}
--- /dev/null
+// 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 <QGraphicsItemGroup>
+
+/*
+ Class : GraphicsView_Object
+ Description : Base class for all objects displayed at the scene
+*/
+class GRAPHICSVIEW_API GraphicsView_Object : public QGraphicsItemGroup
+{
+public:
+ GraphicsView_Object( QGraphicsItem* theParent = 0 );
+ ~GraphicsView_Object();
+
+ virtual void compute() = 0;
+
+ const QString& getName() const { return myName; }
+ virtual void setName( const QString& theName );
+
+ virtual int getPriority() const { return myPriority; }
+
+ virtual bool isOnTop() const { return myIsOnTop; }
+ virtual void setIsOnTop( bool theIsOnTop ) { myIsOnTop = theIsOnTop; }
+
+ virtual bool isSelectable() const { return true; }
+ virtual bool isMovable() const { return true; }
+
+ virtual QRectF getRect() const;
+
+ virtual bool highlight( double theX, double theY );
+ virtual void unhighlight();
+ virtual bool isHighlighted() const { return myIsHighlighted; }
+
+ virtual bool select( double theX, double theY, const QRectF& theRect );
+ virtual void unselect();
+ virtual bool isSelected() const { return myIsSelected; }
+ virtual void setSelected( bool theState ) { myIsSelected = theState; }
+
+ virtual void move( double theDX, double theDY, bool theIsAtOnce = false );
+ virtual bool finishMove();
+ virtual bool isMovingByXAllowed( double theDX ) { return true; }
+ virtual bool isMovingByYAllowed( double theDY ) { return true; }
+
+ virtual bool updateScale( bool theIsScaleUp, bool theIsCtrl ) { return false; }
+
+ virtual QRectF getPullingRect() const { return getRect(); }
+ virtual bool portContains( const QPointF& ) { return false; }
+ virtual bool startPulling( const QPointF& ) { return false; }
+ virtual void pull( const QPointF&, GraphicsView_Object* ) {}
+ virtual void finishPulling() {}
+ virtual bool isPulling() { return false; }
+
+ virtual bool handleMousePress( QGraphicsSceneMouseEvent* ) { return false; }
+ virtual bool handleMouseMove( QGraphicsSceneMouseEvent* ) { return false; }
+ virtual bool handleMouseRelease( QGraphicsSceneMouseEvent* ) { return false; }
+
+protected:
+ virtual bool checkHighlight( double theX, double theY ) const;
+
+protected:
+ QString myName;
+
+ int myPriority;
+ bool myIsOnTop;
+
+ bool myIsHighlighted;
+ bool myIsSelected;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Scene.cxx
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_Scene.h"
+
+#include <QGraphicsRectItem>
+#include <QGraphicsSceneWheelEvent>
+
+//#define VIEWER_DEBUG
+
+//=======================================================================
+// Name : GraphicsView_Scene
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_Scene::GraphicsView_Scene( QObject* theParent )
+: QGraphicsScene( theParent )
+{
+#ifdef VIEWER_DEBUG
+ mySceneRectItem = new QGraphicsRectItem();
+ mySceneRectItem->setPen( QPen( Qt::red, 0.0 ) );
+
+ addItem( mySceneRectItem );
+
+ connect( this, SIGNAL( sceneRectChanged( const QRectF& ) ),
+ this, SLOT( onSceneRectChanged( const QRectF& ) ) );
+#endif
+}
+
+//=======================================================================
+// Name : GraphicsView_Scene
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_Scene::~GraphicsView_Scene()
+{
+}
+
+//================================================================
+// Function : processRectChanged
+// Purpose :
+//================================================================
+void GraphicsView_Scene::processRectChanged()
+{
+ emit gsBoundingRectChanged();
+}
+
+//================================================================
+// Function : onSceneRectChanged
+// Purpose :
+//================================================================
+void GraphicsView_Scene::onSceneRectChanged( const QRectF& theRect )
+{
+#ifdef VIEWER_DEBUG
+ mySceneRectItem->setRect( theRect );
+#endif
+}
+
+//================================================================
+// Function : keyPressEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::keyPressEvent( QKeyEvent* e )
+{
+ emit gsKeyEvent( e );
+ QGraphicsScene::keyPressEvent( e );
+}
+
+//================================================================
+// Function : keyReleaseEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::keyReleaseEvent( QKeyEvent* e )
+{
+ emit gsKeyEvent( e );
+ QGraphicsScene::keyReleaseEvent( e );
+}
+
+//================================================================
+// Function : mousePressEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit gsMouseEvent( e );
+ QGraphicsScene::mousePressEvent( e );
+}
+
+//================================================================
+// Function : mouseMoveEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::mouseMoveEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit gsMouseEvent( e );
+ QGraphicsScene::mouseMoveEvent( e );
+}
+
+//================================================================
+// Function : mouseReleaseEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit gsMouseEvent( e );
+ QGraphicsScene::mouseReleaseEvent( e );
+}
+
+//================================================================
+// Function : mouseDoubleClickEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit gsMouseEvent( e );
+ QGraphicsScene::mouseDoubleClickEvent( e );
+}
+
+//================================================================
+// Function : wheelEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::wheelEvent( QGraphicsSceneWheelEvent* e )
+{
+ emit gsWheelEvent( e );
+
+ // accept the event to prevent calling QAbstractScrollArea::wheelEvent()
+ // from QGraphicsView::wheelEvent(), which will change values of scroll-bars
+ e->accept();
+
+ //QGraphicsScene::wheelEvent( e ); // don't uncomment
+}
+
+//================================================================
+// Function : contextMenuEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
+{
+ emit gsContextMenuEvent( e );
+ QGraphicsScene::contextMenuEvent( e );
+}
+
+//================================================================
+// Function : dragEnterEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::dragEnterEvent( QGraphicsSceneDragDropEvent* e )
+{
+ //QGraphicsScene::dragEnterEvent( e ); // don't uncomment
+}
+
+//================================================================
+// Function : dragLeaveEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::dragLeaveEvent( QGraphicsSceneDragDropEvent* e )
+{
+ //QGraphicsScene::dragLeaveEvent( e ); // don't uncomment
+}
+
+//================================================================
+// Function : dragMoveEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::dragMoveEvent( QGraphicsSceneDragDropEvent* e )
+{
+ //QGraphicsScene::dragMoveEvent( e ); // don't uncomment
+}
+
+//================================================================
+// Function : dropEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::dropEvent( QGraphicsSceneDragDropEvent* e )
+{
+ //QGraphicsScene::dropEvent( e ); // don't uncomment
+}
--- /dev/null
+// 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 <QGraphicsScene>
+
+class QGraphicsRectItem;
+
+/*
+ Class : GraphicsView_Scene
+ Description : Scene of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_Scene : public QGraphicsScene
+{
+ Q_OBJECT
+
+public:
+ GraphicsView_Scene( QObject* theParent = 0 );
+ ~GraphicsView_Scene();
+
+public:
+ void processRectChanged();
+
+protected slots:
+ void onSceneRectChanged( const QRectF& theRect ); // for debug
+
+protected:
+ virtual void keyPressEvent( QKeyEvent* );
+ virtual void keyReleaseEvent( QKeyEvent* );
+ virtual void mousePressEvent( QGraphicsSceneMouseEvent* );
+ virtual void mouseMoveEvent( QGraphicsSceneMouseEvent* );
+ virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* );
+ virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* );
+ virtual void wheelEvent( QGraphicsSceneWheelEvent* );
+ virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+ virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* );
+ virtual void dragLeaveEvent( QGraphicsSceneDragDropEvent* );
+ virtual void dragMoveEvent( QGraphicsSceneDragDropEvent* );
+ virtual void dropEvent( QGraphicsSceneDragDropEvent* );
+
+signals:
+ void gsKeyEvent( QKeyEvent* );
+ void gsMouseEvent( QGraphicsSceneMouseEvent* );
+ void gsWheelEvent( QGraphicsSceneWheelEvent* );
+ void gsContextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+ void gsBoundingRectChanged();
+
+private:
+ QGraphicsRectItem* mySceneRectItem; // for debug
+};
+
+#endif
--- /dev/null
+// 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;
+}
+
--- /dev/null
+// 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 <QObject>
+#include <QRectF>
+
+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
--- /dev/null
+// 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 <QtxAction.h>
+#include <QtxActionToolMgr.h>
+#include <QtxMultiAction.h>
+#include <QtxToolBar.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+
+#include <QColor>
+#include <QFrame>
+#include <QFileDialog>
+#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsSceneWheelEvent>
+#include <QHBoxLayout>
+#include <QImage>
+#include <QMouseEvent>
+#include <QString>
+#include <QWheelEvent>
+
+//=======================================================================
+// Name : GraphicsView_ViewFrame
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Viewer* vw )
+: SUIT_ViewWindow( d ),
+ myViewer( vw )
+{
+ QFrame* aFrame = new QFrame( this );
+ setCentralWidget( aFrame );
+
+ QBoxLayout* aLayout = new QHBoxLayout( aFrame );
+ aLayout->setMargin( 0 );
+ aLayout->setSpacing( 0 );
+
+ myViewPort = new GraphicsView_ViewPort( aFrame );
+ aLayout->addWidget( myViewPort );
+
+ createActions();
+ myToolBarId = createToolBar();
+
+ connect( myViewPort, SIGNAL( vpKeyEvent( QKeyEvent* ) ),
+ this, SLOT( keyEvent( QKeyEvent* ) ) );
+ connect( myViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( mouseEvent( QGraphicsSceneMouseEvent* ) ) );
+ connect( myViewPort, SIGNAL( vpWheelEvent( QGraphicsSceneWheelEvent* ) ),
+ this, SLOT( wheelEvent( QGraphicsSceneWheelEvent* ) ) );
+ connect( myViewPort, SIGNAL( vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ),
+ this, SLOT( contextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) );
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewFrame
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_ViewFrame::~GraphicsView_ViewFrame()
+{
+}
+
+//================================================================
+// Function : createActions
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::createActions()
+{
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ QtxAction* anAction;
+
+ // Dump view
+ anAction = new QtxAction( tr( "MNU_DUMP_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_DUMP" ) ),
+ tr( "MNU_DUMP_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) );
+ toolMgr()->registerAction( anAction, DumpId );
+
+ // FitAll
+ anAction = new QtxAction( tr( "MNU_FITALL" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITALL" ) ),
+ tr( "MNU_FITALL" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_FITALL" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitAll() ) );
+ toolMgr()->registerAction( anAction, FitAllId );
+
+ // FitRect
+ anAction = new QtxAction( tr( "MNU_FITRECT" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITAREA" ) ),
+ tr( "MNU_FITRECT" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_FITRECT" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitArea() ) );
+ toolMgr()->registerAction( anAction, FitRectId );
+
+ // FitSelect
+ anAction = new QtxAction( tr( "MNU_FITSELECT" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITSELECT" ) ),
+ tr( "MNU_FITSELECT" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_FITSELECT" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitSelect() ) );
+ toolMgr()->registerAction( anAction, FitSelectId );
+
+ // Zoom
+ anAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_ZOOM" ) ),
+ tr( "MNU_ZOOM_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewZoom() ) );
+ toolMgr()->registerAction( anAction, ZoomId );
+
+ // Panning
+ anAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_PAN" ) ),
+ tr( "MNU_PAN_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewPan() ) );
+ toolMgr()->registerAction( anAction, PanId );
+
+ // Global Panning
+ anAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_GLOBALPAN" ) ),
+ tr( "MNU_GLOBALPAN_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewGlobalPan() ) );
+ toolMgr()->registerAction( anAction, GlobalPanId );
+
+ // Reset (obsolete)
+ /*
+ anAction = new QtxAction( tr( "MNU_RESET_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_RESET" ) ),
+ tr( "MNU_RESET_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_RESET_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewReset() ) );
+ toolMgr()->registerAction( anAction, ResetId );
+ */
+}
+
+//================================================================
+// Function : createToolBar
+// Purpose :
+//================================================================
+int GraphicsView_ViewFrame::createToolBar()
+{
+ int tid = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL") );
+ toolMgr()->append( DumpId, tid );
+
+ myScaleAction = new QtxMultiAction( this );
+ myScaleAction->insertAction( toolMgr()->action( FitAllId ) );
+ myScaleAction->insertAction( toolMgr()->action( FitRectId ) );
+ myScaleAction->insertAction( toolMgr()->action( FitSelectId ) );
+ myScaleAction->insertAction( toolMgr()->action( ZoomId ) );
+ toolMgr()->append( myScaleAction, tid );
+
+ myPanAction = new QtxMultiAction( this );
+ myPanAction->insertAction( toolMgr()->action( PanId ) );
+ myPanAction->insertAction( toolMgr()->action( GlobalPanId ) );
+ toolMgr()->append( myPanAction, tid );
+
+ toolMgr()->append( toolMgr()->action( ResetId ), tid );
+
+ return tid;
+}
+
+//================================================================
+// Function : dumpView
+// Purpose :
+//================================================================
+QImage GraphicsView_ViewFrame::dumpView()
+{
+ return myViewPort->dumpView();
+}
+
+//================================================================
+// Function : expandToolBarActions
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::expandToolBarActions()
+{
+ QList<QtxMultiAction*> anExpandableActions;
+ anExpandableActions.append( myScaleAction );
+ anExpandableActions.append( myPanAction );
+
+ QListIterator<QtxMultiAction*> anIter( anExpandableActions );
+ while( anIter.hasNext() )
+ {
+ if( QtxMultiAction* aMultiAction = anIter.next() )
+ {
+ QList<QAction*> aLocalActions = aMultiAction->actions();
+ QListIterator<QAction*> aLocalIter( aLocalActions );
+ while( aLocalIter.hasNext() )
+ if( QAction* anAction = aLocalIter.next() )
+ toolMgr()->append( anAction, myToolBarId );
+
+ int anId = toolMgr()->actionId( aMultiAction );
+ toolMgr()->remove( anId, myToolBarId );
+ }
+ }
+}
+
+//================================================================
+// Function : onViewPan
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewPan()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::Pan );
+}
+
+//================================================================
+// Function : onViewZoom
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewZoom()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::Zoom );
+}
+
+//================================================================
+// Function : onViewFitAll
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewFitAll()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::FitAll );
+}
+
+//================================================================
+// Function : onViewFitArea
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewFitArea()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::FitRect );
+}
+
+//================================================================
+// Function : onViewFitSelect
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewFitSelect()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::FitSelect );
+}
+
+//================================================================
+// Function : onViewGlobalPan
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewGlobalPan()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::PanGlobal );
+}
+
+//================================================================
+// Function : onViewReset
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewReset()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::Reset );
+}
+
+//================================================================
+// Function : keyEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::keyEvent( QKeyEvent* e )
+{
+ switch ( e->type() )
+ {
+ case QEvent::KeyPress:
+ emit keyPressed( e );
+ break;
+ case QEvent::KeyRelease:
+ emit keyReleased( e );
+ break;
+ default:
+ break;
+ }
+}
+
+//================================================================
+// Function : mouseEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::mouseEvent( QGraphicsSceneMouseEvent* e )
+{
+ switch ( e->type() )
+ {
+ case QEvent::GraphicsSceneMousePress:
+ emit mousePressed( e );
+ break;
+ case QEvent::GraphicsSceneMouseMove:
+ emit mouseMoving( e );
+ break;
+ case QEvent::GraphicsSceneMouseRelease:
+ emit mouseReleased( e );
+ break;
+ case QEvent::GraphicsSceneMouseDoubleClick:
+ emit mouseDoubleClicked( e );
+ break;
+ default:
+ break;
+ }
+}
+
+//================================================================
+// Function : wheelEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::wheelEvent( QGraphicsSceneWheelEvent* e )
+{
+ switch ( e->type() )
+ {
+ case QEvent::GraphicsSceneWheel:
+ emit wheeling( e );
+ break;
+ default:
+ break;
+ }
+}
+
+//================================================================
+// Function : contextMenuEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
+{
+ QPoint aPos = myViewPort->mapFromScene( e->scenePos() );
+ QContextMenuEvent* anEvent = new QContextMenuEvent( (QContextMenuEvent::Reason)e->reason(),
+ aPos, e->screenPos(), e->modifiers() );
+ emit contextMenuRequested( anEvent );
+ delete anEvent;
+}
--- /dev/null
+// 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 <SUIT_ViewWindow.h>
+
+class QGraphicsSceneContextMenuEvent;
+class QGraphicsSceneMouseEvent;
+class QGraphicsSceneWheelEvent;
+
+class QtxMultiAction;
+
+class SUIT_Desktop;
+
+class GraphicsView_Viewer;
+class GraphicsView_ViewPort;
+
+/*
+ Class : GraphicsView_ViewFrame
+ Description : View frame of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_ViewFrame : public SUIT_ViewWindow
+{
+ Q_OBJECT
+
+public:
+ enum { DumpId, FitAllId, FitRectId, FitSelectId, ZoomId, PanId, GlobalPanId, ResetId };
+
+public:
+ GraphicsView_ViewFrame( SUIT_Desktop*, GraphicsView_Viewer* );
+ ~GraphicsView_ViewFrame();
+
+public:
+ GraphicsView_Viewer* getViewer() const { return myViewer; }
+ GraphicsView_ViewPort* getViewPort() const { return myViewPort; }
+
+ virtual QImage dumpView();
+
+ void expandToolBarActions();
+
+ protected slots:
+ void onViewPan();
+ void onViewZoom();
+ void onViewFitAll();
+ void onViewFitArea();
+ void onViewFitSelect();
+ void onViewGlobalPan();
+ void onViewReset();
+
+private slots:
+ void keyEvent( QKeyEvent* );
+ void mouseEvent( QGraphicsSceneMouseEvent* );
+ void wheelEvent( QGraphicsSceneWheelEvent* );
+ void contextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+signals:
+ void keyPressed( QKeyEvent* );
+ void keyReleased( QKeyEvent* );
+ void mousePressed( QGraphicsSceneMouseEvent* );
+ void mouseMoving( QGraphicsSceneMouseEvent* );
+ void mouseReleased( QGraphicsSceneMouseEvent* );
+ void mouseDoubleClicked( QGraphicsSceneMouseEvent* );
+ void wheeling( QGraphicsSceneWheelEvent* );
+
+private:
+ void createActions();
+ int createToolBar();
+
+private:
+ GraphicsView_Viewer* myViewer;
+ GraphicsView_ViewPort* myViewPort;
+
+ int myToolBarId;
+ QtxMultiAction* myScaleAction;
+ QtxMultiAction* myPanAction;
+};
+
+#endif
--- /dev/null
+// 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<GraphicsView_Viewer*>( getViewModel() );
+}
--- /dev/null
+// 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 <SUIT_ViewManager.h>
+
+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
--- /dev/null
+// 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 <QCursor>
+#include <QGraphicsSceneMouseEvent>
+#include <QGridLayout>
+#include <QLabel>
+#include <QMoveEvent>
+#include <QRectF>
+#include <QRubberBand>
+#include <QScrollBar>
+
+#include <math.h>
+
+int GraphicsView_ViewPort::nCounter = 0;
+QCursor* GraphicsView_ViewPort::defCursor = 0;
+QCursor* GraphicsView_ViewPort::handCursor = 0;
+QCursor* GraphicsView_ViewPort::panCursor = 0;
+QCursor* GraphicsView_ViewPort::panglCursor = 0;
+QCursor* GraphicsView_ViewPort::zoomCursor = 0;
+
+//=======================================================================
+// Name : GraphicsView_ViewPort::NameLabel
+// Purpose : Wrapper for label, which can ignore move events sent from
+// QGraphicsView::scrollContentsBy() method, which,
+// in its turn, called from GraphicsView_ViewPort::pan()
+//=======================================================================
+class GraphicsView_ViewPort::NameLabel : public QLabel
+{
+public:
+ NameLabel( QWidget* theParent )
+ :
+ QLabel( theParent ),
+ myAcceptMoveEvents( false )
+ {
+ }
+ ~NameLabel() {}
+
+ void setAcceptMoveEvents( bool theFlag )
+ {
+ myAcceptMoveEvents = theFlag;
+ }
+
+protected:
+ virtual void moveEvent( QMoveEvent* theEvent )
+ {
+ if( myAcceptMoveEvents )
+ QLabel::moveEvent( theEvent );
+ else // return the label to the initial position
+ {
+ myAcceptMoveEvents = true;
+ move( theEvent->oldPos() );
+ myAcceptMoveEvents = false;
+ }
+ }
+
+private:
+ bool myAcceptMoveEvents;
+};
+
+//================================================================
+// Function : createCursors
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::createCursors ()
+{
+ defCursor = new QCursor( Qt::ArrowCursor );
+ handCursor = new QCursor( Qt::PointingHandCursor );
+ panCursor = new QCursor( Qt::SizeAllCursor );
+ panglCursor = new QCursor( Qt::CrossCursor );
+
+ SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr();
+ zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) );
+}
+
+//================================================================
+// Function : destroyCursors
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::destroyCursors()
+{
+ delete defCursor; defCursor = 0;
+ delete handCursor; handCursor = 0;
+ delete panCursor; panCursor = 0;
+ delete panglCursor; panglCursor = 0;
+ delete zoomCursor; zoomCursor = 0;
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewPort
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent )
+: QGraphicsView( theParent ),
+ myNameLabel( 0 ),
+ myNamePosition( NP_None ),
+ myNameLayout( 0 ),
+ myForegroundItem( 0 ),
+ myGridItem( 0 ),
+ myIsTransforming( false ),
+ myHighlightedObject( 0 ),
+ myHighlightX( 0 ),
+ myHighlightY( 0 ),
+ mySelectionIterator( 0 ),
+ myRectBand( 0 ),
+ myAreSelectionPointsInitialized( false ),
+ myIsDragging( false ),
+ myIsDragPositionInitialized( false ),
+ myIsPulling( false ),
+ myPullingObject( 0 )
+{
+ // scene
+ myScene = new GraphicsView_Scene( this );
+ setScene( myScene );
+
+ mySceneGap = 20;
+ myFitAllGap = 40;
+ myIsTraceBoundingRectEnabled = true;
+
+ // interaction flags
+ myInteractionFlags = AllFlags;
+
+ // background
+ setBackgroundBrush( QBrush( Qt::white ) );
+
+ // foreground
+ myIsForegroundEnabled = false;
+ myForegroundSize = QSizeF( 100, 30 );
+ myForegroundMargin = 0.0;
+ myForegroundColor = Qt::white;
+ myForegroundFrameColor = Qt::black;
+ myForegroundFrameLineWidth = 1.0;
+
+ // grid
+ myIsGridEnabled = false;
+ myGridCellSize = 100;
+ myGridLineStyle = Qt::DotLine;
+ myGridLineColor = Qt::darkGray;
+
+ // default index method (BspTreeIndex) leads to
+ // crashes in QGraphicsView::paintEvent() method
+ myScene->setItemIndexMethod( QGraphicsScene::NoIndex );
+
+ // render hints (default - TextAntialiasing only)
+ setRenderHints( QPainter::Antialiasing |
+ QPainter::TextAntialiasing |
+ QPainter::SmoothPixmapTransform |
+ QPainter::HighQualityAntialiasing );
+
+ connect( myScene, SIGNAL( gsKeyEvent( QKeyEvent* ) ),
+ this, SLOT( onKeyEvent( QKeyEvent* ) ) );
+ connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+ connect( myScene, SIGNAL( gsWheelEvent( QGraphicsSceneWheelEvent* ) ),
+ this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
+ connect( myScene, SIGNAL( gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ),
+ this, SLOT( onContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) );
+
+ connect( myScene, SIGNAL( gsBoundingRectChanged() ),
+ this, SLOT( onBoundingRectChanged() ) );
+
+ initialize();
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewPort
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_ViewPort::~GraphicsView_ViewPort()
+{
+ cleanup();
+
+ if( myScene )
+ {
+ delete myScene;
+ myScene = 0;
+ }
+}
+
+//================================================================
+// Function : initialize
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::initialize()
+{
+ if ( nCounter++ == 0 )
+ createCursors();
+
+ setMouseTracking( true );
+ setFocusPolicy( Qt::StrongFocus );
+}
+
+//================================================================
+// Function : cleanup
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::cleanup()
+{
+ if ( --nCounter == 0 )
+ destroyCursors();
+}
+
+//================================================================
+// Function : addItem
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem )
+{
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( theItem ) )
+ {
+ int aPriority = anObject->getPriority();
+ GraphicsView_ObjectList::iterator anIter, anIterEnd = myObjects.end();
+ for( anIter = myObjects.begin(); anIter != anIterEnd; anIter++ )
+ {
+ if( GraphicsView_Object* anObjectRef = *anIter )
+ {
+ if( anObjectRef->getPriority() > aPriority )
+ break;
+ }
+ }
+ myObjects.insert( anIter, anObject );
+ }
+ myScene->addItem( theItem );
+ onBoundingRectChanged();
+}
+
+//================================================================
+// Function : removeItem
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem )
+{
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( theItem ) )
+ {
+ if( myHighlightedObject == anObject )
+ myHighlightedObject = 0;
+ mySelectedObjects.removeAll( anObject );
+ myObjects.removeAll( anObject );
+ }
+ myScene->removeItem( theItem );
+ onBoundingRectChanged();
+}
+
+//================================================================
+// Function : getObjects
+// Purpose :
+//================================================================
+GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( bool theIsSortSelected ) const
+{
+ if( !theIsSortSelected )
+ return myObjects;
+
+ // to append selected objects after their non-selected siblings with similar priority
+ int aCurrentPriority = -1;
+ GraphicsView_ObjectList aSelectedObjects;
+ GraphicsView_ObjectList aTopmostObjects;
+
+ GraphicsView_ObjectList aList;
+ GraphicsView_ObjectListIterator anIter( myObjects );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = anIter.next() )
+ {
+ if( anObject->isOnTop() )
+ {
+ aTopmostObjects.append( anObject );
+ continue;
+ }
+
+ int aPriority = anObject->getPriority();
+ if( aPriority > aCurrentPriority )
+ {
+ if( !aSelectedObjects.isEmpty() )
+ {
+ aList.append( aSelectedObjects );
+ aSelectedObjects.clear();
+ }
+ aCurrentPriority = aPriority;
+ }
+
+ if( anObject->isSelected() )
+ aSelectedObjects.append( anObject );
+ else
+ aList.append( anObject );
+ }
+ }
+
+ // for selected objects with highest priority,
+ // which were not pushed to the result list yet
+ if( !aSelectedObjects.isEmpty() )
+ {
+ aList.append( aSelectedObjects );
+ aSelectedObjects.clear();
+ }
+
+ aList.append( aTopmostObjects );
+
+ return aList;
+}
+
+//================================================================
+// Function : objectsBoundingRect
+// Purpose :
+//================================================================
+QRectF GraphicsView_ViewPort::objectsBoundingRect( bool theOnlyVisible ) const
+{
+ QRectF aRect;
+ QListIterator<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ {
+ if( theOnlyVisible && !anObject->isVisible() )
+ continue;
+
+ QRectF anObjectRect = anObject->getRect();
+ if( !anObjectRect.isNull() )
+ {
+ if( aRect.isNull() )
+ aRect = anObject->getRect();
+ else
+ aRect |= anObject->getRect();
+ }
+ }
+ }
+ return aRect;
+}
+
+//================================================================
+// Function : dumpView
+// Purpose :
+//================================================================
+QImage GraphicsView_ViewPort::dumpView( bool theWholeScene,
+ QSizeF theSize )
+{
+ if( !theWholeScene ) // just grab the view contents
+ {
+ QPixmap aPixmap = QPixmap::grabWindow( viewport()->winId() );
+ return aPixmap.toImage();
+ }
+
+ // get a bounding rect of all presented objects
+ // (itemsBoundingRect() method is unsuitable)
+ QRectF aRect = objectsBoundingRect();
+ if( aRect.isNull() )
+ return QImage();
+
+ QRectF aTargetRect( 0, 0, aRect.width(), aRect.height() );
+ if( theSize.isValid() )
+ {
+ double aRatioX = theSize.width() / aTargetRect.width();
+ double aRatioY = theSize.height() / aTargetRect.height();
+ double aRatio = qMin( aRatioX, aRatioY );
+ aTargetRect.setWidth( aTargetRect.width() * aRatio );
+ aTargetRect.setHeight( aTargetRect.height() * aRatio );
+ }
+
+ // render the scene to an image
+ QImage anImage( aTargetRect.toRect().size(), QImage::Format_RGB32 );
+ QPainter aPainter( &anImage );
+ aPainter.setRenderHints( renderHints() );
+
+ myScene->render( &aPainter, aTargetRect, aRect );
+
+ return anImage;
+}
+
+//================================================================
+// Function : setSceneGap
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setSceneGap( double theSceneGap )
+{
+ mySceneGap = theSceneGap;
+ onBoundingRectChanged();
+}
+
+//================================================================
+// Function : setFitAllGap
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setFitAllGap( double theFitAllGap )
+{
+ myFitAllGap = theFitAllGap;
+}
+
+//================================================================
+// Function : setTraceBoundingRectEnabled
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setTraceBoundingRectEnabled( bool theState )
+{
+ myIsTraceBoundingRectEnabled = theState;
+}
+
+//================================================================
+// Function : setInteractionFlags
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setInteractionFlags( const int theFlags )
+{
+ myInteractionFlags |= theFlags;
+}
+
+//================================================================
+// Function : clearInteractionFlags
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::clearInteractionFlags( const int theFlags )
+{
+ myInteractionFlags &= ~theFlags;
+}
+
+//================================================================
+// Function : testInteractionFlags
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::testInteractionFlags( const int theFlags ) const
+{
+ return ( myInteractionFlags & theFlags ) == theFlags;
+}
+
+//================================================================
+// Function : setViewNameEnabled
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setViewNamePosition( NamePosition thePosition,
+ bool theIsForced )
+{
+ if( theIsForced && !myNameLabel )
+ myNameLabel = new NameLabel( viewport() );
+
+ if( !myNameLabel )
+ return;
+
+ if( thePosition == NP_None )
+ {
+ myNameLabel->setVisible( false );
+ return;
+ }
+
+ if( myNameLayout )
+ delete myNameLayout;
+
+ myNameLayout = new QGridLayout( viewport() );
+ myNameLayout->setMargin( 10 );
+ myNameLayout->setSpacing( 0 );
+
+ int aRow = 0, aColumn = 0;
+ switch( thePosition )
+ {
+ case NP_TopLeft: aRow = 0; aColumn = 0; break;
+ case NP_TopRight: aRow = 0; aColumn = 1; break;
+ case NP_BottomLeft: aRow = 1; aColumn = 0; break;
+ case NP_BottomRight: aRow = 1; aColumn = 1; break;
+ default: break;
+ }
+
+ myNameLayout->addWidget( myNameLabel, aRow, aColumn );
+ myNameLayout->setRowStretch( 1 - aRow, 1 );
+ myNameLayout->setColumnStretch( 1 - aColumn, 1 );
+
+ myNameLabel->setVisible( true );
+}
+
+//================================================================
+// Function : setViewName
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setViewName( const QString& theName )
+{
+ if( myNameLabel )
+ myNameLabel->setText( theName );
+}
+
+//================================================================
+// Function : backgroundColor
+// Purpose :
+//================================================================
+QColor GraphicsView_ViewPort::backgroundColor() const
+{
+ return backgroundBrush().color();
+}
+
+//================================================================
+// Function : setBackgroundColor
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setBackgroundColor( const QColor& theColor )
+{
+ setBackgroundBrush( QBrush( theColor ) );
+}
+
+//================================================================
+// Function : setForegroundEnabled
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundEnabled( bool theState )
+{
+ myIsForegroundEnabled = theState;
+}
+
+//================================================================
+// Function : setForegroundSize
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundSize( const QSizeF& theSize )
+{
+ myForegroundSize = theSize;
+}
+
+//================================================================
+// Function : setForegroundMargin
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundMargin( double theMargin )
+{
+ myForegroundMargin = theMargin;
+}
+
+//================================================================
+// Function : setForegroundColor
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundColor( const QColor& theColor )
+{
+ myForegroundColor = theColor;
+}
+
+//================================================================
+// Function : setForegroundFrameColor
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundFrameColor( const QColor& theColor )
+{
+ myForegroundFrameColor = theColor;
+}
+
+//================================================================
+// Function : setForegroundFrameLineWidth
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundFrameLineWidth( double theLineWidth )
+{
+ myForegroundFrameLineWidth = theLineWidth;
+}
+
+//================================================================
+// Function : updateForeground
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::updateForeground()
+{
+ if( myIsForegroundEnabled )
+ {
+ if( !myForegroundItem )
+ myForegroundItem = myScene->addRect( QRectF(), QPen(), QBrush( Qt::white ) );
+ myForegroundItem->setZValue( -2 );
+
+ QPointF aPoint = QPointF();
+ QRectF aRect( aPoint, myForegroundSize );
+ aRect.adjust( -myForegroundMargin, -myForegroundMargin,
+ myForegroundMargin, myForegroundMargin );
+ myForegroundItem->setRect( aRect );
+
+ QBrush aBrush = myForegroundItem->brush();
+ aBrush.setColor( myForegroundColor );
+ myForegroundItem->setBrush( aBrush );
+
+ QPen aPen = myForegroundItem->pen();
+ aPen.setColor( myForegroundFrameColor );
+ aPen.setWidthF( myForegroundFrameLineWidth );
+ myForegroundItem->setPen( aPen );
+
+ myForegroundItem->setVisible( true );
+
+ myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) );
+ }
+ else
+ {
+ if( myForegroundItem )
+ myForegroundItem->setVisible( false );
+ }
+
+ updateGrid(); // foreground size could be changed
+}
+
+//================================================================
+// Function : setGridEnabled
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setGridEnabled( bool theState )
+{
+ myIsGridEnabled = theState;
+}
+
+//================================================================
+// Function : setGridCellSize
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setGridCellSize( int theCellSize )
+{
+ myGridCellSize = theCellSize;
+}
+
+//================================================================
+// Function : setGridLineStyle
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setGridLineStyle( int theLineStyle )
+{
+ myGridLineStyle = theLineStyle;
+}
+
+//================================================================
+// Function : setGridLineColor
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setGridLineColor( const QColor& theLineColor )
+{
+ myGridLineColor = theLineColor;
+}
+
+//================================================================
+// Function : updateGrid
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::updateGrid()
+{
+ if( myIsGridEnabled )
+ {
+ if( !myGridItem )
+ myGridItem = myScene->addPath( QPainterPath() );
+ myGridItem->setZValue( -1 );
+
+ double aWidth = myForegroundSize.width();
+ double aHeight = myForegroundSize.height();
+
+ int aGridNbX = int( aWidth / myGridCellSize ) + 1;
+ int aGridNbY = int( aHeight / myGridCellSize ) + 1;
+
+ int anIndex;
+ QPainterPath aPath;
+ for( anIndex = 0; anIndex < aGridNbX; anIndex++ )
+ {
+ double x = myGridCellSize * (double)anIndex;
+ aPath.moveTo( x, 0 );
+ aPath.lineTo( x, aHeight );
+ }
+ for( anIndex = 0; anIndex < aGridNbY; anIndex++ )
+ {
+ double y = myGridCellSize * (double)anIndex;
+ aPath.moveTo( 0, y );
+ aPath.lineTo( aWidth, y );
+ }
+ myGridItem->setPath( aPath );
+
+ QPen aPen = myGridItem->pen();
+ aPen.setStyle( (Qt::PenStyle)myGridLineStyle );
+ aPen.setColor( myGridLineColor );
+ myGridItem->setPen( aPen );
+
+ myGridItem->setVisible( true );
+ }
+ else
+ {
+ if( myGridItem )
+ myGridItem->setVisible( false );
+ }
+}
+
+//================================================================
+// Function : reset
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::reset()
+{
+ fitAll();
+}
+
+//================================================================
+// Function : pan
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::pan( double theDX, double theDY )
+{
+ myIsTransforming = true;
+
+ if( myNameLabel )
+ myNameLabel->setAcceptMoveEvents( false );
+
+ if( QScrollBar* aHBar = horizontalScrollBar() )
+ aHBar->setValue( aHBar->value() - theDX );
+ if( QScrollBar* aVBar = verticalScrollBar() )
+ aVBar->setValue( aVBar->value() + theDY );
+
+ if( myNameLabel )
+ myNameLabel->setAcceptMoveEvents( true );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : setCenter
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setCenter( double theX, double theY )
+{
+ myIsTransforming = true;
+
+ setTransform( myCurrentTransform );
+ centerOn( theX, theY );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : zoom
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, double theY2 )
+{
+ myIsTransforming = true;
+
+ double aDX = theX2 - theX1;
+ double aDY = theY2 - theY1;
+ double aZoom = sqrt( aDX * aDX + aDY * aDY ) / 100 + 1;
+ aZoom = ( aDX > 0 ) ? aZoom : 1 / aZoom;
+
+ QTransform aTransform = transform();
+ aTransform.scale( aZoom, aZoom );
+ double aM11 = aTransform.m11();
+ double aM22 = aTransform.m22();
+ // increasing of diagonal coefficients (>300) leads to a crash sometimes
+ // at the values of 100 some primitives are drawn incorrectly
+ if( qMax( aM11, aM22 ) < 100 )
+ setTransform( aTransform );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : fitRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::fitRect( const QRectF& theRect )
+{
+ myIsTransforming = true;
+
+ fitInView( theRect, Qt::KeepAspectRatio );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : fitSelect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::fitSelect()
+{
+ myIsTransforming = true;
+
+ QRectF aGlobalRect;
+ for( initSelected(); moreSelected(); nextSelected() )
+ {
+ if( GraphicsView_Object* aMovingObject = selectedObject() )
+ {
+ QRectF aRect = aMovingObject->getRect();
+ if( aGlobalRect.isNull() )
+ aGlobalRect = aRect;
+ else
+ aGlobalRect |= aRect;
+ }
+ }
+
+ if( !aGlobalRect.isNull() )
+ {
+ double aGap = qMax( aGlobalRect.width(), aGlobalRect.height() ) / 5;
+ aGlobalRect.adjust( -aGap, -aGap, aGap, aGap );
+ fitInView( aGlobalRect, Qt::KeepAspectRatio );
+ }
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : fitAll
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::fitAll( bool theKeepScale )
+{
+ myIsTransforming = true;
+
+ if( theKeepScale )
+ myCurrentTransform = transform();
+
+ double aGap = myFitAllGap;
+ QRectF aRect = objectsBoundingRect( true );
+ fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : fitWidth
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::fitWidth()
+{
+ myIsTransforming = true;
+
+ double aGap = myFitAllGap;
+ QRectF aRect = objectsBoundingRect( true );
+
+ double aTop = aRect.top();
+ double aLeft = aRect.left();
+ double aMargin = 10;
+
+ aRect.setY( aRect.center().y() );
+ aRect.setHeight( aMargin );
+
+ fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio );
+ ensureVisible( aLeft, aTop, aMargin, aMargin, 0, aGap );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : currentBlock
+// Purpose :
+//================================================================
+GraphicsView_ViewPort::BlockStatus GraphicsView_ViewPort::currentBlock()
+{
+ if( isDragging() && !myDragPosition.isNull() )
+ return BlockStatus( BS_Selection );
+
+ if( myAreSelectionPointsInitialized && ( myFirstSelectionPoint != myLastSelectionPoint ) )
+ return BlockStatus( BS_Selection );
+
+ if( isPulling() )
+ return BlockStatus( BS_Selection );
+
+ return BS_NoBlock;
+}
+
+//================================================================
+// Function : highlight
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::highlight( double theX, double theY )
+{
+ myHighlightX = theX;
+ myHighlightY = theY;
+
+ bool anIsHighlighted = false;
+ bool anIsOnObject = false;
+
+ GraphicsView_Object* aPreviousHighlightedObject = myHighlightedObject;
+ GraphicsView_Object* aHighlightedObject = 0;
+
+ GraphicsView_ObjectList aList = getObjects( true );
+ GraphicsView_ObjectListIterator anIter( aList );
+ anIter.toBack(); // objects with higher priority have to be checked earlier
+ while( anIter.hasPrevious() )
+ {
+ if( GraphicsView_Object* anObject = anIter.previous() )
+ {
+ if( anObject->isVisible() && anObject->isSelectable() )
+ {
+ QRectF aRect = anObject->getRect();
+ if( !aRect.isNull() && aRect.contains( theX, theY ) )
+ {
+ anIsOnObject = true;
+ anIsHighlighted = anObject->highlight( theX, theY );
+ }
+
+ if( anIsHighlighted )
+ {
+ aHighlightedObject = anObject;
+ break;
+ }
+ }
+ }
+ }
+
+ if( !anIsOnObject )
+ {
+ anIter = aList;
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ anObject->unhighlight();
+
+ myHighlightedObject = 0;
+ return;
+ }
+ else if( !myHighlightedObject && anIsHighlighted )
+ {
+ myHighlightedObject = aHighlightedObject;
+ }
+ else if( myHighlightedObject && !anIsHighlighted )
+ {
+ myHighlightedObject->unhighlight();
+ myHighlightedObject = 0;
+ }
+ else if( myHighlightedObject && anIsHighlighted )
+ {
+ myHighlightedObject->highlight( theX, theY );
+ if( myHighlightedObject != aHighlightedObject )
+ {
+ myHighlightedObject->unhighlight();
+ myHighlightedObject = aHighlightedObject;
+ }
+ }
+}
+
+//================================================================
+// Function : clearHighlighted
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::clearHighlighted()
+{
+ if( myHighlightedObject )
+ {
+ myHighlightedObject->unhighlight();
+ myHighlightedObject = 0;
+ }
+}
+
+//================================================================
+// Function : select
+// Purpose :
+//================================================================
+int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend )
+{
+ GV_SelectionStatus aStatus = GVSS_Invalid;
+ if( theRect.isNull() ) // point selection
+ {
+ if( myHighlightedObject )
+ {
+ if( mySelectedObjects.count() == 1 &&
+ mySelectedObjects.first() == myHighlightedObject )
+ aStatus = GVSS_LocalChanged;
+
+ if( !theIsAppend )
+ {
+ GraphicsView_ObjectListIterator anIter( mySelectedObjects );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ if( myHighlightedObject != anObject )
+ anObject->unselect();
+
+ if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid )
+ aStatus = GVSS_GlobalChanged;
+ mySelectedObjects.clear();
+ }
+ else if( myHighlightedObject->isSelected() && aStatus != GVSS_LocalChanged )
+ {
+ mySelectedObjects.removeAll( myHighlightedObject );
+ myHighlightedObject->unselect();
+
+ if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid )
+ aStatus = GVSS_GlobalChanged;
+
+ return aStatus;
+ }
+
+ if( myHighlightedObject->select( myHighlightX, myHighlightY, QRectF() ) &&
+ mySelectedObjects.indexOf( myHighlightedObject ) == -1 )
+ {
+ mySelectedObjects.append( myHighlightedObject );
+ if( aStatus == GVSS_Invalid )
+ aStatus = GVSS_GlobalChanged;
+ }
+ else if( aStatus == GVSS_LocalChanged )
+ aStatus = GVSS_GlobalChanged;
+
+ return aStatus;
+ }
+
+ if( !myHighlightedObject )
+ {
+ if( !theIsAppend )
+ {
+ GraphicsView_ObjectListIterator anIter( mySelectedObjects );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ if( myHighlightedObject != anObject )
+ anObject->unselect();
+
+ if( !mySelectedObjects.isEmpty() )
+ aStatus = GVSS_GlobalChanged;
+ mySelectedObjects.clear();
+ }
+ return aStatus;
+ }
+
+ return GVSS_NoChanged;
+ }
+ else // rectangle selection
+ {
+ aStatus = GVSS_NoChanged;
+
+ bool updateAll = false;
+ if( !theIsAppend )
+ {
+ if( !mySelectedObjects.isEmpty() )
+ aStatus = GVSS_GlobalChanged;
+
+ GraphicsView_ObjectListIterator anIter( mySelectedObjects );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ if( myHighlightedObject != anObject )
+ anObject->unselect();
+ mySelectedObjects.clear();
+ }
+
+ QListIterator<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ {
+ if( anObject->isVisible() && anObject->isSelectable() )
+ {
+ bool anIsSelected = false;
+ QRectF aRect = anObject->getRect();
+ if( theRect.contains( aRect ) )
+ anIsSelected = anObject->select( myHighlightX, myHighlightY, theRect );
+
+ if( anIsSelected && mySelectedObjects.indexOf( anObject ) == -1 )
+ {
+ mySelectedObjects.append( anObject );
+ aStatus = GVSS_GlobalChanged;
+ }
+ }
+ }
+ }
+ }
+ return aStatus;
+}
+
+//================================================================
+// Function : clearSelected
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::clearSelected()
+{
+ GraphicsView_ObjectListIterator anIter( mySelectedObjects );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ anObject->unselect();
+ mySelectedObjects.clear();
+}
+
+//================================================================
+// Function : setSelected
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setSelected( GraphicsView_Object* theObject )
+{
+ if( theObject )
+ {
+ theObject->setSelected( true );
+ mySelectedObjects.append( theObject );
+ }
+}
+
+//================================================================
+// Function : nbSelected
+// Purpose :
+//================================================================
+int GraphicsView_ViewPort::nbSelected() const
+{
+ return mySelectedObjects.count();
+}
+
+//================================================================
+// Function : initSelected
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::initSelected()
+{
+ mySelectionIterator = 0;
+}
+
+//================================================================
+// Function : moreSelected
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::moreSelected()
+{
+ return mySelectionIterator < nbSelected();
+}
+
+//================================================================
+// Function : nextSelected
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::nextSelected()
+{
+ if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() )
+ {
+ mySelectionIterator++;
+ return true;
+ }
+ return false;
+}
+
+//================================================================
+// Function : selectedObject
+// Purpose :
+//================================================================
+GraphicsView_Object* GraphicsView_ViewPort::selectedObject()
+{
+ if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() )
+ return mySelectedObjects[ mySelectionIterator ];
+ return 0;
+}
+
+//================================================================
+// Function : startSelectByRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::startSelectByRect( int x, int y )
+{
+ if( !myAreSelectionPointsInitialized )
+ {
+ myFirstSelectionPoint = QPoint( x, y );
+ myLastSelectionPoint = QPoint( x, y );
+ myAreSelectionPointsInitialized = true;
+ }
+
+ if( !myRectBand )
+ {
+ myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
+ QPalette palette;
+ palette.setColor( myRectBand->foregroundRole(), Qt::white );
+ myRectBand->setPalette( palette );
+ }
+ myRectBand->hide();
+}
+
+//================================================================
+// Function : drawSelectByRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::drawSelectByRect( int x, int y )
+{
+ if( myAreSelectionPointsInitialized )
+ {
+ myRectBand->hide();
+
+ myLastSelectionPoint.setX( x );
+ myLastSelectionPoint.setY( y );
+
+ QRect aRect = selectionRect();
+ myRectBand->setGeometry( aRect );
+ myRectBand->setVisible( aRect.isValid() );
+ }
+}
+
+//================================================================
+// Function : isSelectByRect
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::isSelectByRect() const
+{
+ return myAreSelectionPointsInitialized;
+}
+
+//================================================================
+// Function : finishSelectByRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::finishSelectByRect()
+{
+ if( myAreSelectionPointsInitialized )
+ {
+ if( myRectBand )
+ {
+ myRectBand->hide();
+ delete myRectBand;
+ myRectBand = 0;
+ }
+
+ myAreSelectionPointsInitialized = false;
+ }
+}
+
+//================================================================
+// Function : selectionRect
+// Purpose :
+//================================================================
+QRect GraphicsView_ViewPort::selectionRect()
+{
+ QRect aRect;
+ if( myAreSelectionPointsInitialized )
+ {
+ aRect.setLeft( qMin( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) );
+ aRect.setTop( qMin( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) );
+ aRect.setRight( qMax( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) );
+ aRect.setBottom( qMax( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) );
+ }
+ return aRect;
+}
+
+//================================================================
+// Function : dragObjects
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e )
+{
+ GraphicsView_Object* anObject = getHighlightedObject();
+
+ if( myDragPosition.isNull() )
+ {
+ myDragPosition = e->scenePos();
+ return;
+ }
+
+ GraphicsView_ObjectList anObjectsToMove;
+ if( anObject && anObject->isMovable() && ( e->buttons() & Qt::LeftButton ) )
+ {
+ if( anObject->isSelected() )
+ {
+ for( initSelected(); moreSelected(); nextSelected() )
+ if( GraphicsView_Object* aMovingObject = selectedObject() )
+ if( aMovingObject->isMovable() )
+ anObjectsToMove.append( aMovingObject );
+ }
+ else
+ anObjectsToMove.append( anObject );
+ }
+ else if( nbSelected() && ( e->buttons() & Qt::MidButton ) )
+ {
+ for( initSelected(); moreSelected(); nextSelected() )
+ if( GraphicsView_Object* aMovingObject = selectedObject() )
+ if( aMovingObject->isMovable() )
+ anObjectsToMove.append( aMovingObject );
+ }
+
+ if( anObjectsToMove.isEmpty() )
+ return;
+
+ double aDX = e->scenePos().x() - myDragPosition.x();
+ double aDY = e->scenePos().y() - myDragPosition.y();
+
+ bool anIsMovingByXAllowed = true, anIsMovingByYAllowed = true;
+ GraphicsView_ObjectListIterator anIter( anObjectsToMove );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* aMovingObject = anIter.next() )
+ {
+ if( !aMovingObject->isMovingByXAllowed( aDX ) )
+ anIsMovingByXAllowed = false;
+ if( !aMovingObject->isMovingByYAllowed( aDY ) )
+ anIsMovingByYAllowed = false;
+ }
+
+ if( !anIsMovingByXAllowed && !anIsMovingByYAllowed )
+ return; // myDragPosition shouldn't be changed
+
+ if( !anIsMovingByXAllowed )
+ aDX = 0;
+
+ if( !anIsMovingByYAllowed )
+ aDY = 0;
+
+ anIter = anObjectsToMove;
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* aMovingObject = anIter.next() )
+ aMovingObject->move( aDX, aDY );
+
+ if( anIsMovingByXAllowed )
+ myDragPosition.setX( e->scenePos().x() );
+
+ if( anIsMovingByYAllowed )
+ myDragPosition.setY( e->scenePos().y() );
+}
+
+//================================================================
+// Function : startPulling
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::startPulling( const QPointF& thePoint )
+{
+ QListIterator<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( 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<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ {
+ if( !anObject->isVisible() )
+ continue;
+
+ QRectF aRect = anObject->getPullingRect();
+ if( aRect.contains( thePoint ) && anObject->portContains( thePoint ) )
+ {
+ aLockedObject = anObject;
+ break;
+ }
+ }
+ }
+
+ myPullingObject->pull( thePoint, aLockedObject );
+}
+
+//================================================================
+// Function : finishPulling
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::finishPulling()
+{
+ myIsPulling = false;
+ myPullingObject->finishPulling();
+ setCursor( *getDefaultCursor() );
+}
+
+//================================================================
+// Function : onBoundingRectChanged
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::onBoundingRectChanged()
+{
+ if( myIsTraceBoundingRectEnabled )
+ {
+ QRectF aRect = objectsBoundingRect();
+ myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) );
+ }
+}
+
+//================================================================
+// Function : onKeyEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::onKeyEvent( QKeyEvent* e )
+{
+ emit vpKeyEvent( e );
+}
+
+//================================================================
+// Function : onMouseEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit vpMouseEvent( e );
+
+ bool anIsHandled = false;
+ switch( e->type() )
+ {
+ case QEvent::GraphicsSceneMousePress:
+ {
+ if( testInteractionFlags( EditFlags ) && nbSelected() )
+ for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
+ if( GraphicsView_Object* anObject = selectedObject() )
+ anIsHandled = anObject->handleMousePress( e );
+
+ if( !anIsHandled && testInteractionFlags( Dragging ) )
+ {
+ bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey();
+ if( ( getHighlightedObject() &&
+ getHighlightedObject()->isMovable() &&
+ !( anAccel || e->button() == Qt::RightButton ) ) ||
+ ( nbSelected() && !anAccel && e->button() == Qt::MidButton ) )
+ myIsDragging = true;
+ }
+ break;
+ }
+ case QEvent::GraphicsSceneMouseMove:
+ {
+ if( testInteractionFlags( EditFlags ) && nbSelected() )
+ for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
+ if( GraphicsView_Object* anObject = selectedObject() )
+ anIsHandled = anObject->handleMousePress( e );
+
+ if( !anIsHandled && !isPulling() && myIsDragging )
+ dragObjects( e );
+ break;
+ }
+ case QEvent::GraphicsSceneMouseRelease:
+ {
+ if( testInteractionFlags( EditFlags ) && nbSelected() )
+ for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
+ if( GraphicsView_Object* anObject = selectedObject() )
+ anIsHandled = anObject->handleMousePress( e );
+
+ if( !anIsHandled && !isPulling() && myIsDragging )
+ {
+ emit vpObjectBeforeMoving();
+
+ bool anIsMoved = false;
+ for( initSelected(); moreSelected(); nextSelected() )
+ if( GraphicsView_Object* aMovingObject = selectedObject() )
+ anIsMoved = aMovingObject->finishMove() || anIsMoved;
+
+ if( GraphicsView_Object* aMovingObject = getHighlightedObject() )
+ anIsMoved = aMovingObject->finishMove() || anIsMoved;
+
+ myIsDragging = false;
+ myDragPosition = QPointF();
+
+ emit vpObjectAfterMoving( anIsMoved );
+ }
+ break;
+ }
+ case QEvent::GraphicsSceneMouseDoubleClick:
+ break; // do nothing, just emit the signal
+ default:
+ break;
+ }
+}
+
+//================================================================
+// Function : onWheelEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::onWheelEvent( QGraphicsSceneWheelEvent* e )
+{
+ emit vpWheelEvent( e );
+}
+
+//================================================================
+// Function : onContextMenuEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::onContextMenuEvent( QGraphicsSceneContextMenuEvent* e )
+{
+ emit vpContextMenuEvent( e );
+}
+
+//================================================================
+// Function : scrollContentsBy
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::scrollContentsBy( int theDX, int theDY )
+{
+ if( myNameLabel )
+ myNameLabel->setAcceptMoveEvents( false );
+
+ QGraphicsView::scrollContentsBy( theDX, theDY );
+
+ if( myNameLabel )
+ myNameLabel->setAcceptMoveEvents( true );
+}
--- /dev/null
+// 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 <QGraphicsView>
+
+class QGridLayout;
+class QRubberBand;
+
+class GraphicsView_Object;
+class GraphicsView_Scene;
+
+/*
+ Class : GraphicsView_ViewPort
+ Description : View port of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_ViewPort : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ class NameLabel;
+
+ enum InteractionFlags
+ {
+ Highlighting = 0x0001, // not implemented yet
+ Selecting = 0x0002, // not implemented yet
+ Dragging = 0x0004,
+ Pulling = 0x0008,
+ WheelScaling = 0x0010,
+ EditFlags = Dragging | Pulling | WheelScaling,
+ AllFlags = Highlighting | Selecting | Dragging | Pulling | WheelScaling
+ };
+
+ enum BlockStatus
+ {
+ BS_NoBlock = 0x0000,
+ BS_Selection = 0x0001, // and highlighting
+ BS_Dragging = 0x0002 // currently unused
+ };
+
+ enum NamePosition
+ {
+ NP_None = 0,
+ NP_TopLeft = 1,
+ NP_TopRight = 2,
+ NP_BottomLeft = 3,
+ NP_BottomRight = 4
+ };
+
+public:
+ GraphicsView_ViewPort( QWidget* theParent );
+ ~GraphicsView_ViewPort();
+
+public:
+ GraphicsView_Scene* getScene() { return myScene; }
+ void addItem( QGraphicsItem* theItem );
+ void removeItem( QGraphicsItem* theItem );
+
+ GraphicsView_ObjectList getObjects( bool theIsSortSelected = false ) const;
+
+ QRectF objectsBoundingRect( bool theOnlyVisible = false ) const;
+
+ QImage dumpView( bool theWholeScene = false,
+ QSizeF theSize = QSizeF() );
+
+public:
+ // scene
+ void setSceneGap( double theSceneGap );
+ void setFitAllGap( double theFitAllGap );
+ void setTraceBoundingRectEnabled( bool theState );
+
+ // interaction flags
+ void setInteractionFlags( const int );
+ void clearInteractionFlags( const int );
+ bool testInteractionFlags( const int ) const;
+
+ // view name
+ void setViewNamePosition( NamePosition thePosition,
+ bool theIsForced = false );
+ void setViewName( const QString& theName );
+
+ // background / foreground
+ QColor backgroundColor() const;
+ void setBackgroundColor( const QColor& theColor );
+
+ bool isForegroundEnabled() const { return myIsForegroundEnabled; }
+ void setForegroundEnabled( bool theState );
+
+ QSizeF foregroundSize() const { return myForegroundSize; }
+ void setForegroundSize( const QSizeF& theRect );
+
+ double foregroundMargin() const { return myForegroundMargin; }
+ void setForegroundMargin( double theMargin );
+
+ QColor foregroundColor() const { return myForegroundColor; }
+ void setForegroundColor( const QColor& theColor );
+
+ QColor foregroundFrameColor() const { return myForegroundFrameColor; }
+ void setForegroundFrameColor( const QColor& theColor );
+
+ double foregroundFrameLineWidth() const { return myForegroundFrameLineWidth; }
+ void setForegroundFrameLineWidth( double theLineWidth );
+
+ void updateForeground();
+
+ // grid
+ void setGridEnabled( bool theState );
+ void setGridCellSize( int theCellSize );
+ void setGridLineStyle( int theLineStyle );
+ void setGridLineColor( const QColor& theLineColor );
+ void updateGrid();
+
+ // transformation
+ void reset();
+ void pan( double theDX, double theDY );
+ void setCenter( double theX, double theY );
+ void zoom( double theX1, double theY1, double theX2, double theY2 );
+ void fitRect( const QRectF& theRect );
+ void fitSelect();
+ void fitAll( bool theKeepScale = false );
+ void fitWidth();
+
+ bool isTransforming() const { return myIsTransforming; }
+
+ // block status
+ BlockStatus currentBlock();
+
+ // highlighting
+ virtual void highlight( double theX, double theY );
+ void clearHighlighted();
+
+ GraphicsView_Object* getHighlightedObject() const { return myHighlightedObject; }
+
+ // selection
+ virtual int select( const QRectF& theRect, bool theIsAppend );
+ void clearSelected();
+ void setSelected( GraphicsView_Object* theObject );
+
+ int nbSelected() const;
+ void initSelected();
+ bool moreSelected();
+ bool nextSelected();
+ GraphicsView_Object* selectedObject();
+
+ const GraphicsView_ObjectList& getSelectedObjects() const { return mySelectedObjects; }
+
+
+ // rectangle selection
+ void startSelectByRect( int x, int y );
+ void drawSelectByRect( int x, int y );
+ void finishSelectByRect();
+ bool isSelectByRect() const;
+ QRect selectionRect();
+
+ // dragging
+ bool isDragging() { return myIsDragging; }
+
+ // pulling
+ bool startPulling( const QPointF& );
+ void drawPulling( const QPointF& );
+ void finishPulling();
+ bool isPulling() const { return myIsPulling; }
+
+public:
+ static void createCursors();
+ static void destroyCursors();
+ static QCursor* getDefaultCursor() { return defCursor; }
+ static QCursor* getHandCursor() { return handCursor; }
+ static QCursor* getPanCursor() { return panCursor; }
+ static QCursor* getPanglCursor() { return panglCursor; }
+ static QCursor* getZoomCursor() { return zoomCursor; }
+
+public slots:
+ void onBoundingRectChanged();
+
+protected slots:
+ void onKeyEvent( QKeyEvent* );
+ void onMouseEvent( QGraphicsSceneMouseEvent* );
+ void onWheelEvent( QGraphicsSceneWheelEvent* );
+ void onContextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+protected:
+ virtual void scrollContentsBy( int theDX, int theDY );
+
+signals:
+ void vpKeyEvent( QKeyEvent* );
+ void vpMouseEvent( QGraphicsSceneMouseEvent* );
+ void vpWheelEvent( QGraphicsSceneWheelEvent* );
+ void vpContextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+ void vpObjectBeforeMoving();
+ void vpObjectAfterMoving( bool );
+
+private:
+ void initialize();
+ void cleanup();
+
+ void dragObjects( QGraphicsSceneMouseEvent* );
+
+private:
+ static int nCounter;
+ static QCursor* defCursor;
+ static QCursor* handCursor;
+ static QCursor* panCursor;
+ static QCursor* panglCursor;
+ static QCursor* zoomCursor;
+
+private:
+ // scene
+ GraphicsView_Scene* myScene;
+ double mySceneGap;
+ double myFitAllGap;
+ bool myIsTraceBoundingRectEnabled;
+ GraphicsView_ObjectList myObjects;
+
+ // interaction flags
+ int myInteractionFlags;
+
+ // view name
+ NameLabel* myNameLabel;
+ NamePosition myNamePosition;
+ QGridLayout* myNameLayout;
+
+ // foreground
+ bool myIsForegroundEnabled;
+ QSizeF myForegroundSize;
+ double myForegroundMargin;
+ QColor myForegroundColor;
+ QColor myForegroundFrameColor;
+ double myForegroundFrameLineWidth;
+ QGraphicsRectItem* myForegroundItem;
+
+ // grid
+ bool myIsGridEnabled;
+ int myGridCellSize;
+ int myGridLineStyle;
+ QColor myGridLineColor;
+ QGraphicsPathItem* myGridItem;
+
+ // transformation
+ bool myIsTransforming;
+ QTransform myCurrentTransform;
+
+ // highlighting
+ GraphicsView_Object* myHighlightedObject;
+ double myHighlightX;
+ double myHighlightY;
+
+ // selection
+ GraphicsView_ObjectList mySelectedObjects;
+ int mySelectionIterator;
+
+ // rectangle selection
+ QRubberBand* myRectBand;
+ QPoint myFirstSelectionPoint;
+ QPoint myLastSelectionPoint;
+ bool myAreSelectionPointsInitialized;
+
+ // dragging
+ int myIsDragging;
+ QPointF myDragPosition;
+ bool myIsDragPositionInitialized;
+
+ // pulling
+ bool myIsPulling;
+ GraphicsView_Object* myPullingObject;
+};
+
+#endif
--- /dev/null
+// 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 <QGraphicsSceneMouseEvent>
+#include <QRectF>
+#include <QRubberBand>
+
+int GraphicsView_ViewTransformer::panBtn = Qt::MidButton;
+int GraphicsView_ViewTransformer::zoomBtn = Qt::LeftButton;
+int GraphicsView_ViewTransformer::fitRectBtn = Qt::LeftButton;
+int GraphicsView_ViewTransformer::panGlobalBtn = Qt::LeftButton;
+int GraphicsView_ViewTransformer::acccelKey = Qt::ControlModifier;
+
+//=======================================================================
+// Name : GraphicsView_ViewTransformer
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_ViewTransformer::GraphicsView_ViewTransformer( GraphicsView_Viewer* v, int type )
+: QObject( 0 ),
+ myViewer( v ),
+ myType( type ),
+ myMajorBtn( Qt::NoButton ),
+ myButtonState( 0 ),
+ myRectBand( 0 )
+{
+ if( myType == GraphicsView_Viewer::Pan ||
+ myType == GraphicsView_Viewer::Zoom ||
+ myType == GraphicsView_Viewer::PanGlobal ||
+ myType == GraphicsView_Viewer::FitRect )
+ initTransform( true );
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewTransformer
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_ViewTransformer::~GraphicsView_ViewTransformer()
+{
+ if( myType == GraphicsView_Viewer::Pan ||
+ myType == GraphicsView_Viewer::Zoom ||
+ myType == GraphicsView_Viewer::PanGlobal ||
+ myType == GraphicsView_Viewer::FitRect )
+ initTransform( false );
+
+ endDrawRect();
+}
+
+//================================================================
+// Function : initTransform
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::initTransform( bool init )
+{
+ if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
+ {
+ if( GraphicsView_Scene* aScene = aViewPort->getScene() )
+ {
+ if( init )
+ {
+ mySavedCursor = aViewPort->cursor();
+ mySavedMouseTrack = aViewPort->hasMouseTracking();
+ aViewPort->setMouseTracking( false );
+ aScene->installEventFilter( this );
+ }
+ else
+ {
+ aScene->removeEventFilter( this );
+ aViewPort->setMouseTracking( mySavedMouseTrack );
+ aViewPort->setCursor( mySavedCursor );
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : exec
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::exec()
+{
+ GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort();
+ if( !aViewPort )
+ return;
+
+ switch( myType )
+ {
+ case GraphicsView_Viewer::Zoom:
+ myMajorBtn = zoomButton();
+ aViewPort->setCursor( *aViewPort->getZoomCursor() );
+ break;
+ case GraphicsView_Viewer::Pan:
+ myMajorBtn = panButton();
+ aViewPort->setCursor( *aViewPort->getPanCursor() );
+ break;
+ case GraphicsView_Viewer::PanGlobal:
+ myMajorBtn = panGlobalButton();
+ aViewPort->setCursor( *aViewPort->getPanglCursor() );
+ aViewPort->fitAll( true );
+ break;
+ case GraphicsView_Viewer::FitRect:
+ myMajorBtn = fitRectButton();
+ aViewPort->setCursor( *aViewPort->getHandCursor() );
+ break;
+ case GraphicsView_Viewer::Reset:
+ aViewPort->reset();
+ onTransform( Finished );
+ break;
+ case GraphicsView_Viewer::FitAll:
+ aViewPort->fitAll();
+ onTransform( Finished );
+ break;
+ case GraphicsView_Viewer::FitSelect:
+ aViewPort->fitSelect();
+ onTransform( Finished );
+ break;
+ case GraphicsView_Viewer::FitWidth:
+ aViewPort->fitWidth();
+ onTransform( Finished );
+ break;
+ default: break;
+ }
+}
+
+//================================================================
+// Function : eventFilter
+// Purpose :
+//================================================================
+bool GraphicsView_ViewTransformer::eventFilter( QObject* o, QEvent* e )
+{
+ switch( e->type() )
+ {
+ case QEvent::GraphicsSceneMouseMove:
+ case QEvent::GraphicsSceneMousePress:
+ case QEvent::GraphicsSceneMouseRelease:
+ {
+ TransformState state = InProcess;
+ QGraphicsSceneMouseEvent* me = ( QGraphicsSceneMouseEvent* )e;
+
+ myButtonState = me->buttons();
+ if ( e->type() == QEvent::GraphicsSceneMousePress )
+ myButtonState |= me->button();
+
+ if ( e->type() == QEvent::GraphicsSceneMouseRelease )
+ myButtonState |= me->button();
+
+ int mouseOnlyState = ( myButtonState & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
+ if ( myStart.isNull() )
+ {
+ state = Begin;
+ myStart = myViewer->getActiveViewPort()->mapFromScene( me->scenePos() );
+ myMajorBtn = mouseOnlyState;
+ }
+
+ if ( e->type() == QEvent::GraphicsSceneMouseRelease )
+ state = Finished;
+
+ myCurr = myViewer->getActiveViewPort()->mapFromScene( me->scenePos() );
+ onTransform( state );
+ return true;
+ }
+ default: break;
+ }
+ return QObject::eventFilter( o, e );
+}
+
+//================================================================
+// Function : onTransform
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::onTransform( TransformState state )
+{
+ GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort();
+ if( !aViewPort || aViewPort->isTransforming() )
+ return;
+
+ bool doTrsf = ( myButtonState & myMajorBtn );
+ switch ( myType )
+ {
+ case GraphicsView_Viewer::Zoom:
+ if ( state != Finished && doTrsf )
+ {
+ aViewPort->zoom( myStart.x(), myStart.y(), myCurr.x(), myCurr.y() );
+ myStart = myCurr;
+ }
+ break;
+ case GraphicsView_Viewer::Pan:
+ if ( state != Finished && doTrsf )
+ {
+ aViewPort->pan( myCurr.x() - myStart.x(), myStart.y() - myCurr.y() );
+ myStart = myCurr;
+ }
+ break;
+ case GraphicsView_Viewer::PanGlobal:
+ if ( state == Finished )
+ {
+ QPointF aPoint = aViewPort->mapToScene( myCurr.toPoint() );
+ aViewPort->setCenter( aPoint.x(), aPoint.y() );
+ }
+ break;
+ case GraphicsView_Viewer::FitRect:
+ if ( doTrsf )
+ {
+ QRectF aRect( qMin( myStart.x(), myCurr.x() ), qMin( myStart.y(), myCurr.y() ),
+ qAbs( myStart.x() - myCurr.x() ), qAbs( myStart.y() - myCurr.y() ) );
+ if ( !aRect.isEmpty() )
+ {
+ switch ( state )
+ {
+ case Finished:
+ aRect = aViewPort->mapToScene( aRect.toRect() ).boundingRect();
+ aViewPort->fitRect( aRect );
+ break;
+ default:
+ drawRect( aRect );
+ break;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ if ( state == Finished )
+ myViewer->activateTransform( GraphicsView_Viewer::NoTransform );
+}
+
+//================================================================
+// Function : drawRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::drawRect(const QRectF& theRect)
+{
+ if ( !myRectBand )
+ {
+ myRectBand = new QRubberBand( QRubberBand::Rectangle, myViewer->getActiveViewPort() );
+ QPalette palette;
+ palette.setColor(myRectBand->foregroundRole(), Qt::white);
+ myRectBand->setPalette(palette);
+ }
+ myRectBand->hide();
+
+ myRectBand->setGeometry( theRect.toRect() );
+ myRectBand->setVisible( theRect.isValid() );
+}
+
+//================================================================
+// Function : endDrawRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::endDrawRect()
+{
+ if ( myRectBand )
+ {
+ myRectBand->hide();
+ delete myRectBand;
+ myRectBand = 0;
+ }
+}
+
+//================================================================
+// Function : GraphicsView_ViewTransformer
+// Purpose :
+//================================================================
+int GraphicsView_ViewTransformer::type() const
+{
+ return myType;
+}
--- /dev/null
+// 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 <QCursor>
+#include <QObject>
+
+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
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Viewer.cxx
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_Viewer.h"
+
+#include "GraphicsView_Object.h"
+#include "GraphicsView_Selector.h"
+#include "GraphicsView_Scene.h"
+#include "GraphicsView_ViewFrame.h"
+#include "GraphicsView_ViewPort.h"
+#include "GraphicsView_ViewTransformer.h"
+
+#include <SUIT_ViewManager.h>
+
+#include <QApplication>
+#include <QColorDialog>
+#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsSceneWheelEvent>
+#include <QKeyEvent>
+#include <QMenu>
+
+//=======================================================================
+// Name : GraphicsView_Viewer
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_Viewer::GraphicsView_Viewer( const QString& title )
+: SUIT_ViewModel(),
+ mySelector( 0 ),
+ myTransformer( 0 ),
+ myIsInitialized( false ),
+ myIsImmediateSelectionEnabled( false )
+{
+}
+
+//=======================================================================
+// Name : GraphicsView_Viewer
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_Viewer::~GraphicsView_Viewer()
+{
+ delete mySelector;
+}
+
+//================================================================
+// Function : createView
+// Purpose :
+//================================================================
+SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
+{
+ GraphicsView_ViewFrame* aViewFrame = new GraphicsView_ViewFrame( theDesktop, this );
+
+ connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
+ this, SLOT( onKeyEvent( QKeyEvent* ) ) );
+
+ connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ),
+ this, SLOT( onKeyEvent( QKeyEvent* ) ) );
+
+ connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+
+ connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+
+ connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+
+ connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
+ this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
+
+ return aViewFrame;
+}
+
+//================================================================
+// Function : contextMenuPopup
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup )
+{
+ if( thePopup->actions().count() > 0 )
+ thePopup->addSeparator();
+
+ thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
+}
+
+//================================================================
+// Function : getSelector
+// Purpose :
+//================================================================
+GraphicsView_Selector* GraphicsView_Viewer::getSelector()
+{
+ if( !mySelector )
+ {
+ mySelector = new GraphicsView_Selector( this );
+ if( mySelector )
+ {
+ connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ),
+ this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) );
+ connect( mySelector, SIGNAL( selSelectionCancel() ),
+ this, SLOT( onSelectionCancel() ) );
+ }
+ }
+ return mySelector;
+}
+
+//================================================================
+// Function : getActiveView
+// Purpose :
+//================================================================
+GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const
+{
+ if( SUIT_ViewManager* aViewManager = getViewManager() )
+ return dynamic_cast<GraphicsView_ViewFrame*>( 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<GraphicsView_Scene*>( aViewPort->scene() );
+ return NULL;
+}
+
+//================================================================
+// Function : activateTransform
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::activateTransform( int theType )
+{
+ if( theType == NoTransform ) // finish current transform
+ {
+ if ( myTransformer )
+ {
+ onTransformationFinished();
+ delete myTransformer;
+ myTransformer = 0;
+ }
+ }
+ else // activate new transform
+ {
+ activateTransform( NoTransform );
+ myTransformer = createTransformer( theType );
+ onTransformationStarted();
+ myTransformer->exec();
+ }
+}
+
+//================================================================
+// Function : setIsInitialized
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::setIsInitialized( bool theFlag )
+{
+ myIsInitialized = theFlag;
+}
+
+//================================================================
+// Function : setIsImmediateSelectionEnabled
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::setIsImmediateSelectionEnabled( bool theFlag )
+{
+ myIsImmediateSelectionEnabled = theFlag;
+}
+
+//================================================================
+// Function : createTransformer
+// Purpose :
+//================================================================
+GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType )
+{
+ return new GraphicsView_ViewTransformer( this, theType );
+}
+
+//================================================================
+// Function : onTransformationStarted
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onTransformationStarted()
+{
+ if( GraphicsView_Selector* aSelector = getSelector() )
+ {
+ aSelector->undetectAll();
+ aSelector->lock( true ); // disable selection
+ }
+
+ // watch events: any mouse/key event outside the
+ // viewport will be considered as the end of transform
+ if( myTransformer )
+ qApp->installEventFilter( this );
+}
+
+//================================================================
+// Function : onTransformationFinished
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onTransformationFinished()
+{
+ if( GraphicsView_Selector* aSelector = getSelector() )
+ aSelector->lock( false ); // enable selection
+
+ // stop watching events
+ if( myTransformer )
+ qApp->removeEventFilter( this );
+}
+
+//================================================================
+// Function : onKeyEvent
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e )
+{
+ switch( e->type() )
+ {
+ case QEvent::KeyPress:
+ handleKeyPress( e );
+ break;
+ case QEvent::KeyRelease:
+ handleKeyRelease( e );
+ break;
+ default: break;
+ }
+}
+
+//================================================================
+// Function : onMouseEvent
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
+{
+ switch( e->type() )
+ {
+ case QEvent::GraphicsSceneMousePress:
+ handleMousePress( e );
+ break;
+ case QEvent::GraphicsSceneMouseMove:
+ handleMouseMove( e );
+ break;
+ case QEvent::GraphicsSceneMouseRelease:
+ handleMouseRelease( e );
+ break;
+ default: break;
+ }
+}
+
+//================================================================
+// Function : onWheelEvent
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
+{
+ switch( e->type() )
+ {
+ case QEvent::GraphicsSceneWheel:
+ handleWheel( e );
+ break;
+ default: break;
+ }
+}
+
+//================================================================
+// Function : handleKeyPress
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e )
+{
+}
+
+//================================================================
+// Function : handleKeyRelease
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* e )
+{
+}
+
+//================================================================
+// Function : handleMousePress
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
+{
+ // test accel for transforms
+ if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
+ {
+ Qt::MouseButton bs = e->button();
+ if ( bs == GraphicsView_ViewTransformer::zoomButton() )
+ activateTransform( Zoom );
+ else if ( bs == GraphicsView_ViewTransformer::panButton() )
+ activateTransform( Pan );
+ }
+ else // checking for other operations before selection in release event
+ {
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ if( e->button() == Qt::RightButton &&
+ isImmediateSelectionEnabled() &&
+ aViewPort->nbSelected() < 1 )
+ {
+ // If the 'immediate selection' mode is enabled,
+ // try to perform selection before invoking context menu
+ bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
+ getSelector()->select( QRectF(), append );
+ }
+ else if( e->button() == Qt::LeftButton &&
+ aViewPort->testInteractionFlags( GraphicsView_ViewPort::Pulling ) &&
+ !aViewPort->isSelectByRect() &&
+ !aViewPort->isDragging() &&
+ aViewPort->startPulling( e->scenePos() ) )
+ {
+ // Try to start pulling if rectangular selection is performed
+ aViewPort->finishSelectByRect();
+ }
+ else if( e->button() == Qt::LeftButton &&
+ !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
+ !aViewPort->getHighlightedObject() )
+ {
+ // Start rectangular selection if pulling was not started
+ QPoint p = aViewPort->mapFromScene( e->scenePos() );
+ aViewPort->startSelectByRect( p.x(), p.y() );
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : handleMouseMove
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
+{
+ // highlight for selection
+ bool dragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
+ if ( !dragged )
+ {
+ if ( getSelector() )
+ getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
+ }
+
+ // try to activate other operations
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ if( aViewPort->isPulling() )
+ {
+ aViewPort->drawPulling( e->scenePos() );
+ }
+ else if( e->button() == Qt::LeftButton &&
+ aViewPort->testInteractionFlags( GraphicsView_ViewPort::Pulling ) &&
+ !aViewPort->isSelectByRect() &&
+ !aViewPort->isDragging() &&
+ aViewPort->startPulling( e->scenePos() ) )
+ {
+ aViewPort->finishSelectByRect();
+ }
+ else if( !aViewPort->getHighlightedObject() )
+ {
+ QPoint p = aViewPort->mapFromScene( e->scenePos() );
+ aViewPort->drawSelectByRect( p.x(), p.y() );
+ }
+ }
+}
+
+//================================================================
+// Function : handleMouseRelease
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
+{
+ // selection
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ if( e->button() == Qt::LeftButton &&
+ !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
+ {
+ if ( getSelector() )
+ {
+ bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
+ getSelector()->select( QRectF(), append );
+ }
+ }
+ }
+
+ // try to finish active operations
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ if( aViewPort->isPulling() )
+ {
+ aViewPort->finishPulling();
+ }
+ else if( !aViewPort->getHighlightedObject() )
+ {
+ QRect aSelRect = aViewPort->selectionRect();
+ aViewPort->finishSelectByRect();
+ if ( getSelector() && !aSelRect.isNull() )
+ {
+ bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
+ QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect();
+ getSelector()->select( aRect, append );
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : handleWheel
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ if( aViewPort->testInteractionFlags( GraphicsView_ViewPort::WheelScaling ) )
+ {
+ bool anIsScaleUp = e->delta() > 0;
+ bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
+
+ bool anIsScaleChanged = false;
+ for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
+ if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
+ anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
+
+ if( anIsScaleChanged )
+ {
+ emit wheelScaleChanged();
+ aViewPort->onBoundingRectChanged();
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : onSelectionDone
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
+{
+ emit selectionChanged( theStatus );
+}
+
+//================================================================
+// Function : onChangeBgColor
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onChangeBgColor()
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ QColor aColor = aViewPort->isForegroundEnabled() ?
+ aViewPort->foregroundColor() : aViewPort->backgroundColor();
+ aColor = QColorDialog::getColor( aColor, aViewPort );
+ if ( aColor.isValid() )
+ {
+ if( aViewPort->isForegroundEnabled() )
+ {
+ aViewPort->setForegroundColor( aColor );
+ aViewPort->updateForeground();
+ }
+ else
+ aViewPort->setBackgroundColor( aColor );
+ }
+ }
+}
+
+//================================================================
+// Function : onSelectionCancel
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onSelectionCancel()
+{
+ emit selectionChanged( GVSCS_Invalid );
+}
--- /dev/null
+// 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 <SUIT_ViewModel.h>
+
+class QGraphicsSceneMouseEvent;
+class QGraphicsSceneWheelEvent;
+class QKeyEvent;
+
+class SUIT_ViewWindow;
+
+class GraphicsView_Selector;
+class GraphicsView_Scene;
+class GraphicsView_ViewTransformer;
+class GraphicsView_ViewFrame;
+class GraphicsView_ViewPort;
+
+/*
+ Class : GraphicsView_Viewer
+ Description : View model of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_Viewer: public SUIT_ViewModel
+{
+ Q_OBJECT
+
+public:
+ enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect,
+ Zoom, PanGlobal, Pan, FitWidth, UserTransform = 100 };
+public:
+ GraphicsView_Viewer( const QString& title );
+ ~GraphicsView_Viewer();
+
+public:
+ virtual SUIT_ViewWindow* createView( SUIT_Desktop* );
+
+ virtual QString getType() const { return Type(); }
+ static QString Type() { return "GraphicsView"; }
+
+ virtual void contextMenuPopup( QMenu* );
+
+public:
+ GraphicsView_Selector* getSelector();
+
+ GraphicsView_ViewFrame* getActiveView() const;
+ GraphicsView_ViewPort* getActiveViewPort() const;
+ GraphicsView_Scene* getActiveScene() const;
+
+ void activateTransform( int );
+
+ bool isInitialized() const { return myIsInitialized; }
+ void setIsInitialized( bool );
+
+ bool isImmediateSelectionEnabled() const { return myIsImmediateSelectionEnabled; }
+ void setIsImmediateSelectionEnabled( bool );
+
+signals:
+ void selectionChanged( GV_SelectionChangeStatus );
+ void wheelScaleChanged();
+
+protected:
+ virtual GraphicsView_ViewTransformer* createTransformer( int );
+
+ virtual void onTransformationStarted();
+ virtual void onTransformationFinished();
+
+protected slots:
+ virtual void onKeyEvent( QKeyEvent* );
+ virtual void onMouseEvent( QGraphicsSceneMouseEvent* );
+ virtual void onWheelEvent( QGraphicsSceneWheelEvent* );
+
+ virtual void onSelectionDone( GV_SelectionChangeStatus );
+ virtual void onSelectionCancel();
+
+ virtual void onChangeBgColor();
+
+private:
+ void handleKeyPress( QKeyEvent* );
+ void handleKeyRelease( QKeyEvent* );
+ void handleMouseMove( QGraphicsSceneMouseEvent* );
+ void handleMousePress( QGraphicsSceneMouseEvent* );
+ void handleMouseRelease( QGraphicsSceneMouseEvent* );
+ void handleWheel( QGraphicsSceneWheelEvent* );
+
+protected:
+ GraphicsView_Selector* mySelector;
+ GraphicsView_ViewTransformer* myTransformer;
+
+ bool myIsInitialized;
+ bool myIsImmediateSelectionEnabled;
+};
+
+#endif
--- /dev/null
+# Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+# File : Makefile.in
+# Author : Vladimir Klyachin (OCN)
+# Module : caf
+#
+include $(top_srcdir)/adm_local/unix/make_common_starter.am
+
+lib_LTLIBRARIES = libGraphicsView.la
+
+salomeinclude_HEADERS = \
+GraphicsView_Defs.h \
+GraphicsView_Geom.h \
+GraphicsView.h \
+GraphicsView_Object.h \
+GraphicsView_Scene.h \
+GraphicsView_Selector.h \
+GraphicsView_Viewer.h \
+GraphicsView_ViewFrame.h \
+GraphicsView_ViewManager.h \
+GraphicsView_ViewPort.h \
+GraphicsView_ViewTransformer.h
+
+dist_libGraphicsView_la_SOURCES = \
+GraphicsView_Object.cxx \
+GraphicsView_Scene.cxx \
+GraphicsView_Selector.cxx \
+GraphicsView_Viewer.cxx \
+GraphicsView_ViewFrame.cxx \
+GraphicsView_ViewManager.cxx \
+GraphicsView_ViewPort.cxx \
+GraphicsView_ViewTransformer.cxx
+
+MOC_FILES = \
+GraphicsView_ViewManager_moc.cxx \
+GraphicsView_Viewer_moc.cxx \
+GraphicsView_ViewFrame_moc.cxx \
+GraphicsView_Selector_moc.cxx \
+GraphicsView_ViewPort_moc.cxx \
+GraphicsView_Scene_moc.cxx
+
+nodist_libGraphicsView_la_SOURCES = $(MOC_FILES)
+
+dist_salomeres_DATA = \
+resources/graphics_view_cursor_zoom.png \
+resources/graphics_view_dump.png \
+resources/graphics_view_fitall.png \
+resources/graphics_view_fitarea.png \
+resources/graphics_view_fitselect.png \
+resources/graphics_view_glpan.png \
+resources/graphics_view_pan.png \
+resources/graphics_view_reset.png \
+resources/graphics_view_zoom.png
+
+nodist_salomeres_DATA = \
+ GraphicsView_images.qm \
+ GraphicsView_msg_en.qm \
+ GraphicsView_msg_fr.qm
+
+libGraphicsView_la_CPPFLAGS = $(QT_INCLUDES) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx
+libGraphicsView_la_LDFLAGS = $(QT_MT_LIBS)
+libGraphicsView_la_LIBADD = ../SUIT/libsuit.la
--- /dev/null
+<!DOCTYPE TS><TS>
+<context>
+ <name>@default</name>
+ <message>
+ <source>ICON_GV_DUMP</source>
+ <translation>graphics_view_dump.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_ZOOM</source>
+ <translation>graphics_view_zoom.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_PAN</source>
+ <translation>graphics_view_pan.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_GLOBALPAN</source>
+ <translation>graphics_view_glpan.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_CURSOR_ZOOM</source>
+ <translation>graphics_view_cursor_zoom.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_FITALL</source>
+ <translation>graphics_view_fitall.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_FITSELECT</source>
+ <translation>graphics_view_fitselect.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_RESET</source>
+ <translation>graphics_view_reset.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_FITAREA</source>
+ <translation>graphics_view_fitarea.png</translation>
+ </message>
+</context>
+</TS>
--- /dev/null
+<!DOCTYPE TS>
+<TS>
+ <context>
+ <name>GraphicsView_ViewFrame</name>
+ <message>
+ <source>DSC_DUMP_VIEW</source>
+ <translation>Saves the active view in the image file</translation>
+ </message>
+ <message>
+ <source>DSC_FITALL</source>
+ <translation>Fit all objects inside the view frame</translation>
+ </message>
+ <message>
+ <source>DSC_FITRECT</source>
+ <translation>Fit area within the view frame</translation>
+ </message>
+ <message>
+ <source>DSC_FITSELECT</source>
+ <translation>Fit area of selection within the view frame</translation>
+ </message>
+ <message>
+ <source>DSC_GLOBALPAN_VIEW</source>
+ <translation>Selection of a new center of the view</translation>
+ </message>
+ <message>
+ <source>DSC_PAN_VIEW</source>
+ <translation>Pan the view</translation>
+ </message>
+ <message>
+ <source>DSC_RESET_VIEW</source>
+ <translation>Reset view point</translation>
+ </message>
+ <message>
+ <source>DSC_ZOOM_VIEW</source>
+ <translation>Zoom the view</translation>
+ </message>
+ <message>
+ <source>LBL_TOOLBAR_LABEL</source>
+ <translation>View Operations</translation>
+ </message>
+ <message>
+ <source>MNU_DUMP_VIEW</source>
+ <translation>Dump</translation>
+ </message>
+ <message>
+ <source>MNU_FITALL</source>
+ <translation>Fit All</translation>
+ </message>
+ <message>
+ <source>MNU_FITRECT</source>
+ <translation>Fit Area</translation>
+ </message>
+ <message>
+ <source>MNU_FITSELECT</source>
+ <translation>Fit Selection</translation>
+ </message>
+ <message>
+ <source>MNU_GLOBALPAN_VIEW</source>
+ <translation>Global Pan</translation>
+ </message>
+ <message>
+ <source>MNU_PAN_VIEW</source>
+ <translation>Pan</translation>
+ </message>
+ <message>
+ <source>MNU_RESET_VIEW</source>
+ <translation>Reset</translation>
+ </message>
+ <message>
+ <source>MNU_ZOOM_VIEW</source>
+ <translation>Zoom</translation>
+ </message>
+ </context>
+ <context>
+ <name>GraphicsView_Viewer</name>
+ <message>
+ <source>CHANGE_BGCOLOR</source>
+ <translation>Change background...</translation>
+ </message>
+ </context>
+ <context>
+ <name>GraphicsView_ViewManager</name>
+ <message>
+ <source>GRAPHICS_VIEW_TITLE</source>
+ <translation>Graphics scene:%M - viewer:%V</translation>
+ </message>
+ </context>
+</TS>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.0" language="fr" sourcelanguage="en">
+<context>
+ <name>GraphicsView_ViewFrame</name>
+ <message>
+ <source>DSC_DUMP_VIEW</source>
+ <translation type="unfinished">Sauver la scène actuelle au fichier image</translation>
+ </message>
+ <message>
+ <source>DSC_FITALL</source>
+ <translation type="unfinished">Redimensionner la scène pour montrer tous les objets </translation>
+ </message>
+ <message>
+ <source>DSC_FITRECT</source>
+ <translation type="unfinished">Redimensionner la scène pour ne montrer que sa partie choisie par l'encadré</translation>
+ </message>
+ <message>
+ <source>DSC_FITSELECT</source>
+ <translation type="unfinished">Redimensionner la scène pour montrer la sélection.</translation>
+ </message>
+ <message>
+ <source>DSC_GLOBALPAN_VIEW</source>
+ <translation type="unfinished">Sélection d'un nouveau centre de la vue</translation>
+ </message>
+ <message>
+ <source>DSC_PAN_VIEW</source>
+ <translation type="unfinished">Redimensionner la vue</translation>
+ </message>
+ <message>
+ <source>DSC_RESET_VIEW</source>
+ <translation type="unfinished">Restaurer le point de vue</translation>
+ </message>
+ <message>
+ <source>DSC_ZOOM_VIEW</source>
+ <translation type="unfinished">Zoom</translation>
+ </message>
+ <message>
+ <source>LBL_TOOLBAR_LABEL</source>
+ <translation type="unfinished">Opérations de visualisation</translation>
+ </message>
+ <message>
+ <source>MNU_DUMP_VIEW</source>
+ <translation type="unfinished">Sauver la scène</translation>
+ </message>
+ <message>
+ <source>MNU_FITALL</source>
+ <translation type="unfinished">Montrer tous</translation>
+ </message>
+ <message>
+ <source>MNU_FITRECT</source>
+ <translation type="unfinished">Montrer l'encadré</translation>
+ </message>
+ <message>
+ <source>MNU_FITSELECT</source>
+ <translation type="unfinished">Ajuster la sélection</translation>
+ </message>
+ <message>
+ <source>MNU_GLOBALPAN_VIEW</source>
+ <translation type="unfinished">Panoramique Globale</translation>
+ </message>
+ <message>
+ <source>MNU_PAN_VIEW</source>
+ <translation type="unfinished">Redimensionner la vue</translation>
+ </message>
+ <message>
+ <source>MNU_RESET_VIEW</source>
+ <translation type="unfinished">Restaurer</translation>
+ </message>
+ <message>
+ <source>MNU_ZOOM_VIEW</source>
+ <translation>Zoom</translation>
+ </message>
+</context>
+<context>
+ <name>GraphicsView_Viewer</name>
+ <message>
+ <source>CHANGE_BGCOLOR</source>
+ <translation type="unfinished">Changer l'arrière-plan...</translation>
+ </message>
+</context>
+<context>
+ <name>GraphicsView_ViewManager</name>
+ <message>
+ <source>GRAPHICS_VIEW_TITLE</source>
+ <translation type="unfinished">Graphique scène:%M - visualisation:%V</translation>
+ </message>
+</context>
+</TS>
#include <QxScene_ViewWindow.h>
#endif
+#ifndef DISABLE_GRAPHICSVIEWER
+ #include <GraphicsView_Viewer.h>
+ #include <GraphicsView_ViewManager.h>
+#endif
+
#define VISIBILITY_COLUMN_WIDTH 25
// createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_C );
createActionForViewer( NewQxSceneViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_S );
#endif
+#ifndef DISABLE_GRAPHICSVIEWER
+ createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_R );
+#endif
createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
Qt::ALT+Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) );
case NewQxSceneViewId:
type = QxScene_Viewer::Type();
break;
+#endif
+#ifndef DISABLE_GRAPHICSVIEWER
+ case NewGraphicsViewId:
+ type = GraphicsView_Viewer::Type();
+ break;
#endif
}
if( a )
a->setEnabled( activeStudy() );
#endif
+
+#ifndef DISABLE_GRAPHICSVIEWER
+ a = action( NewGraphicsViewId );
+ if( a )
+ a->setEnabled( activeStudy() );
+#endif
}
/*!
#endif
}
#endif
+#ifndef DISABLE_GRAPHICSVIEWER
+ if( vmType == GraphicsView_Viewer::Type() )
+ {
+ viewMgr = new GraphicsView_ViewManager( activeStudy(), desktop() );
+ }
+#endif
if ( !viewMgr )
return 0;
CloseId, CloseAllId, GroupAllId,
PreferencesId, MRUId, ModulesListId,
NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId,
- NewQxSceneViewId = NewQxGraphViewId, StyleId, FullScreenId,
+ NewQxSceneViewId = NewQxGraphViewId, NewGraphicsViewId, StyleId, FullScreenId,
UserID };
protected:
else !ENABLE_GLVIEWER
libLightApp_la_CPPFLAGS += -DDISABLE_GLVIEWER
endif
+if ENABLE_GRAPHICSVIEW
+ libLightApp_la_CPPFLAGS += -I$(srcdir)/../GraphicsView
+else !ENABLE_GRAPHICSVIEW
+ libLightApp_la_CPPFLAGS += -DDISABLE_GRAPHICSVIEWER
+endif
if ENABLE_SUPERVGRAPHVIEWER
libLightApp_la_CPPFLAGS += -I$(srcdir)/../SUPERVGraph
else !ENABLE_SUPERVGRAPHVIEWER
if ENABLE_GLVIEWER
libLightApp_la_LIBADD += ../GLViewer/libGLViewer.la
endif
+if ENABLE_GRAPHICSVIEW
+ libLightApp_la_LIBADD += ../GraphicsView/libGraphicsView.la
+endif
if ENABLE_PLOT2DVIEWER
libLightApp_la_LIBADD += ../Plot2d/libPlot2d.la
if ENABLE_SALOMEOBJECT
LightApp = $(GUI_ROOT_DIR)/share/salome/resources/gui
Plot2d = $(GUI_ROOT_DIR)/share/salome/resources/gui
GLViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui
+GraphicsView = $(GUI_ROOT_DIR)/share/salome/resources/gui
OCCViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui
VTKViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui
<parameter name="Plot2d" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="SPlot2d" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="GLViewer" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
+ <parameter name="GraphicsView" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="OCCViewer" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="VTKViewer" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="QxSceneViewer" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
</message>
<message>
<source>NEW_WINDOW_5</source>
- <translation>Qx&Scene 2D view</translation>
+ <translation>G&raphics view</translation>
</message>
<message>
<source>CREATING_NEW_WINDOW</source>
</message>
<message>
<source>NEW_WINDOW_5</source>
- <translation>Scène Qx&Scene</translation>
+ <translation>Scène G&raphics</translation>
</message>
<message>
<source>CREATING_NEW_WINDOW</source>
SUBDIRS_GLVIEWER = GLViewer
endif
+##
+# Graphics viewer
+##
+if ENABLE_GRAPHICSVIEW
+ SUBDIRS_GRAPHICSVIEW = GraphicsView
+endif
+
##
# VTK viewer
##
SUBDIRS_PY_LIGHT = SALOME_SWIG SALOME_PY SALOME_PYQT
endif
-SUBDIRS = $(SUBDIRS_COMMON) $(SUBDIRS_OBJECT) $(SUBDIRS_VIEWERTOOLS) $(SUBDIRS_GLVIEWER) $(SUBDIRS_VTKVIEWER) \
+SUBDIRS = $(SUBDIRS_COMMON) $(SUBDIRS_OBJECT) $(SUBDIRS_VIEWERTOOLS) $(SUBDIRS_GLVIEWER) $(SUBDIRS_GRAPHICSVIEW) $(SUBDIRS_VTKVIEWER) \
$(SUBDIRS_OCCVIEWER) $(SUBDIRS_PLOT2DVIEWER) $(SUBDIRS_SUPERVGRAPHVIEWER) $(SUBDIRS_QXGRAPHVIEWER) \
$(SUBDIRS_PYCONSOLE) $(SUBDIRS_LIGHT) $(SUBDIRS_CORBA) $(SUBDIRS_PY_LIGHT)
DIST_SUBDIRS = CASCatch Qtx Style DDS QDS ObjBrowser SUIT SUITApp STD CAF CAM LogWindow Prs Event OpenGLUtils \
- OBJECT ViewerTools GLViewer VTKViewer SVTK OCCViewer SOCC Plot2d SPlot2d SUPERVGraph QxGraph QxScene \
+ OBJECT ViewerTools GLViewer GraphicsView VTKViewer SVTK OCCViewer SOCC Plot2d SPlot2d SUPERVGraph QxGraph QxScene \
PyInterp PyConsole LightApp ResExporter TOOLSGUI Session SalomeApp GuiHelpers TreeData \
SALOME_SWIG SALOME_PY SALOME_PYQT GUI_PY