From 53ee1db2dda73dfbd69a6ff6a9795c52c08d24a4 Mon Sep 17 00:00:00 2001 From: san Date: Wed, 16 May 2007 12:23:08 +0000 Subject: [PATCH] Merging from IOLS_SUPERV branch (YACS GUI development) --- adm_local/unix/config_files/Makefile.am | 1 + .../unix/config_files/check_QxGraphViewer.m4 | 25 + configure.ac | 21 + src/LightApp/LightApp_Application.cxx | 26 + src/LightApp/LightApp_Application.h | 4 + src/LightApp/Makefile.am | 5 + src/LightApp/resources/LightApp_msg_en.po | 3 + src/Makefile.am | 3 + src/QxGraph/Makefile.am | 66 ++ src/QxGraph/QxGraph.h | 35 + src/QxGraph/QxGraph_ActiveItem.h | 59 ++ src/QxGraph/QxGraph_Canvas.cxx | 83 +++ src/QxGraph/QxGraph_Canvas.h | 52 ++ src/QxGraph/QxGraph_CanvasView.cxx | 680 ++++++++++++++++++ src/QxGraph/QxGraph_CanvasView.h | 102 +++ src/QxGraph/QxGraph_Def.h | 34 + src/QxGraph/QxGraph_Prs.cxx | 251 +++++++ src/QxGraph/QxGraph_Prs.h | 73 ++ src/QxGraph/QxGraph_ViewManager.cxx | 59 ++ src/QxGraph/QxGraph_ViewManager.h | 48 ++ src/QxGraph/QxGraph_ViewModel.cxx | 157 ++++ src/QxGraph/QxGraph_ViewModel.h | 82 +++ src/QxGraph/QxGraph_ViewWindow.cxx | 288 ++++++++ src/QxGraph/QxGraph_ViewWindow.h | 95 +++ src/QxGraph/resources/QxGraph_images.po | 42 ++ src/QxGraph/resources/QxGraph_msg_en.po | 40 ++ src/QxGraph/resources/view_fitall.png | Bin 0 -> 523 bytes src/QxGraph/resources/view_fitarea.png | Bin 0 -> 511 bytes src/QxGraph/resources/view_glpan.png | Bin 0 -> 540 bytes src/QxGraph/resources/view_pan.png | Bin 0 -> 544 bytes src/QxGraph/resources/view_reset.png | Bin 0 -> 476 bytes src/QxGraph/resources/view_zoom.png | Bin 0 -> 488 bytes src/SalomeApp/resources/SalomeApp.xml | 7 + 33 files changed, 2341 insertions(+) create mode 100644 adm_local/unix/config_files/check_QxGraphViewer.m4 create mode 100755 src/QxGraph/Makefile.am create mode 100644 src/QxGraph/QxGraph.h create mode 100644 src/QxGraph/QxGraph_ActiveItem.h create mode 100644 src/QxGraph/QxGraph_Canvas.cxx create mode 100644 src/QxGraph/QxGraph_Canvas.h create mode 100644 src/QxGraph/QxGraph_CanvasView.cxx create mode 100644 src/QxGraph/QxGraph_CanvasView.h create mode 100644 src/QxGraph/QxGraph_Def.h create mode 100644 src/QxGraph/QxGraph_Prs.cxx create mode 100644 src/QxGraph/QxGraph_Prs.h create mode 100644 src/QxGraph/QxGraph_ViewManager.cxx create mode 100644 src/QxGraph/QxGraph_ViewManager.h create mode 100644 src/QxGraph/QxGraph_ViewModel.cxx create mode 100644 src/QxGraph/QxGraph_ViewModel.h create mode 100644 src/QxGraph/QxGraph_ViewWindow.cxx create mode 100644 src/QxGraph/QxGraph_ViewWindow.h create mode 100644 src/QxGraph/resources/QxGraph_images.po create mode 100644 src/QxGraph/resources/QxGraph_msg_en.po create mode 100755 src/QxGraph/resources/view_fitall.png create mode 100755 src/QxGraph/resources/view_fitarea.png create mode 100755 src/QxGraph/resources/view_glpan.png create mode 100644 src/QxGraph/resources/view_pan.png create mode 100644 src/QxGraph/resources/view_reset.png create mode 100755 src/QxGraph/resources/view_zoom.png diff --git a/adm_local/unix/config_files/Makefile.am b/adm_local/unix/config_files/Makefile.am index 33cf78f20..de8790b70 100644 --- a/adm_local/unix/config_files/Makefile.am +++ b/adm_local/unix/config_files/Makefile.am @@ -36,4 +36,5 @@ check_SupervGraphViewer.m4 \ check_vtk.m4 \ check_VTKViewer.m4 \ check_corba_in_GUI.m4 \ +check_QxGraphViewer.m4 \ README diff --git a/adm_local/unix/config_files/check_QxGraphViewer.m4 b/adm_local/unix/config_files/check_QxGraphViewer.m4 new file mode 100644 index 000000000..1ef9f7314 --- /dev/null +++ b/adm_local/unix/config_files/check_QxGraphViewer.m4 @@ -0,0 +1,25 @@ +# +# Check configure option --disable-qxGraphViewer=[yes|no|DIR] taking into account that +# DISABLE_QXGRAPHVIEWER may be already set during build_configure, +# Set DISABLE_QXGRAPHVIEWER to yes|no +# +# Author : Edawrd AGAPOV (OCC, 2005) +# + +AC_DEFUN([CHECK_QXGRAPHVIEWER],[ + +AC_ARG_WITH(qxGraphViewer, + [ --disable-qxGraphViewer default=no ], + disable_qxGraphViewer="$withval",disable_qxGraphViewer="${DISABLE_QXGRAPHVIEWER}") + +case $disable_qxGraphViewer in + yes) +# AC_MSG_RESULT(************************************************) +# AC_MSG_RESULT(******* DISABLE QxGraphViewer configuration ********) +# AC_MSG_RESULT(************************************************) + DISABLE_QXGRAPHVIEWER="yes" + AC_SUBST(DISABLE_QXGRAPHVIEWER) +esac + + +])dnl diff --git a/configure.ac b/configure.ac index d6ed63709..0b2d4fc0c 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,12 @@ else DISABLE_SALOMEOBJECT="yes" fi +if test "x${enable_qxGraphViewer}" != "xno" ; then + DISABLE_QXGRAPHVIEWER="no" +else + DISABLE_QXGRAPHVIEWER="yes" +fi + dnl dnl Initialize source and build root directories @@ -425,6 +431,15 @@ echo CHECK_SALOMEOBJECT echo "DISABLE_SALOMEOBJECT = "$DISABLE_SALOMEOBJECT +echo +echo --------------------------------------------- +echo Testing QxGraphViewer +echo --------------------------------------------- +echo + +CHECK_QXGRAPHVIEWER +echo "DISABLE_QXGRAPHVIEWER = "$DISABLE_QXGRAPHVIEWER + if test "x${GUI_DISABLE_CORBA}" != "xyes" ; then if test "x${DISABLE_PYCONSOLE}" == "xyes" ; then echo "failed : for full configuration of GUI module necessary enable PyConsole !" @@ -454,6 +469,10 @@ if test "x${GUI_DISABLE_CORBA}" != "xyes" ; then echo "failed : for full configuration of GUI module necessary enable SalomeObject !" exit fi + if test "x${DISABLE_QXGRAPHVIEWER}" == "xyes" ; then + echo "failed : for full configuration of GUI module necessary enable QxGraphViewer !" + exit + fi fi echo @@ -540,6 +559,7 @@ AM_CONDITIONAL(ENABLE_SUPERVGRAPHVIEWER, [test "$DISABLE_SUPERVGRAPHVIEWER" = no AM_CONDITIONAL(ENABLE_OCCVIEWER, [test "$DISABLE_OCCVIEWER" = no]) AM_CONDITIONAL(ENABLE_VTKVIEWER, [test "$DISABLE_VTKVIEWER" = no]) AM_CONDITIONAL(ENABLE_SALOMEOBJECT, [test "$DISABLE_SALOMEOBJECT" = no]) +AM_CONDITIONAL(ENABLE_QXGRAPHVIEWER, [test "$DISABLE_QXGRAPHVIEWER" = no]) echo echo --------------------------------------------- @@ -619,6 +639,7 @@ AC_OUTPUT([ \ ./src/Plot2d/Makefile \ ./src/SPlot2d/Makefile \ ./src/SUPERVGraph/Makefile \ + ./src/QxGraph/Makefile \ ./src/LightApp/Makefile \ ./src/ResExporter/Makefile \ ./src/RegistryDisplay/Makefile \ diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index e91cb94c7..e570efc00 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -109,6 +109,12 @@ // #include //#endif +#ifndef DISABLE_QXGRAPHVIEWER + #include + #include + #include +#endif + #include #include @@ -609,6 +615,9 @@ void LightApp_Application::createActions() #ifndef DISABLE_VTKVIEWER createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), ALT+Key_K ); #endif +#ifndef DISABLE_QXGRAPHVIEWER + createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), ALT+Key_C ); +#endif createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ), @@ -710,6 +719,11 @@ void LightApp_Application::onNewWindow() case NewVTKViewId: type = VTKViewer_Viewer::Type(); break; +#endif +#ifndef DISABLE_QXGRAPHVIEWER + case NewQxGraphViewId: + type = QxGraph_Viewer::Type(); + break; #endif } @@ -908,6 +922,12 @@ void LightApp_Application::updateCommandsStatus() if( a ) a->setEnabled( activeStudy() ); #endif + +#ifndef DISABLE_QXGRAPHVIEWER + a = action( NewQxGraphViewId ); + if( a ) + a->setEnabled( activeStudy() ); +#endif } /*! @@ -1362,6 +1382,12 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType // viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop(), new SUPERVGraph_Viewer() ); // } //#endif +#ifndef DISABLE_QXGRAPHVIEWER + if( vmType == QxGraph_Viewer::Type() ) + { + viewMgr = new QxGraph_ViewManager( activeStudy(), desktop(), new QxGraph_Viewer() ); + } +#endif #ifndef DISABLE_OCCVIEWER if( vmType == OCCViewer_Viewer::Type() ) { diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index b061966ba..9bbecfed7 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -91,6 +91,10 @@ public: NewVTKViewId, #endif +#ifndef DISABLE_QXGRAPHVIEWER + NewQxGraphViewId, +#endif + PreferencesId, MRUId, UserID }; public: LightApp_Application(); diff --git a/src/LightApp/Makefile.am b/src/LightApp/Makefile.am index b15ed5e42..ebaeb0f4b 100755 --- a/src/LightApp/Makefile.am +++ b/src/LightApp/Makefile.am @@ -188,6 +188,11 @@ if ENABLE_SUPERVGRAPHVIEWER else !ENABLE_SUPERVGRAPHVIEWER libLightApp_la_CPPFLAGS+= -DDISABLE_SUPERVGRAPHVIEWER endif +if ENABLE_QXGRAPHVIEWER + libLightApp_la_CPPFLAGS+= -I$(srcdir)/../QxGraph +else !ENABLE_QXGRAPHVIEWER + libLightApp_la_CPPFLAGS+= -DDISABLE_QXGRAPHVIEWER +endif if ENABLE_SALOMEOBJECT diff --git a/src/LightApp/resources/LightApp_msg_en.po b/src/LightApp/resources/LightApp_msg_en.po index f06c47efc..cd3cd7df3 100644 --- a/src/LightApp/resources/LightApp_msg_en.po +++ b/src/LightApp/resources/LightApp_msg_en.po @@ -95,6 +95,9 @@ msgstr "&OCC view" msgid "LightApp_Application::NEW_WINDOW_3" msgstr "VT&K view" +msgid "LightApp_Application::NEW_WINDOW_4" +msgstr "&QxGraph view" + msgid "LightApp_Application::INF_CANCELLED" msgstr "Module activation cancelled" diff --git a/src/Makefile.am b/src/Makefile.am index 1f3b48948..69a213ffb 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -58,6 +58,9 @@ endif if ENABLE_SUPERVGRAPHVIEWER SUBDIRS += SUPERVGraph endif +if ENABLE_QXGRAPHVIEWER + SUBDIRS += QxGraph +endif SUBDIRS += LightApp ResExporter if GUI_ENABLE_CORBA diff --git a/src/QxGraph/Makefile.am b/src/QxGraph/Makefile.am new file mode 100755 index 000000000..b6e64e2c3 --- /dev/null +++ b/src/QxGraph/Makefile.am @@ -0,0 +1,66 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES = libQxGraph.la + +salomeinclude_HEADERS= \ + QxGraph_ActiveItem.h \ + QxGraph_Prs.h \ + QxGraph_Canvas.h \ + QxGraph_CanvasView.h \ + QxGraph_ViewWindow.h \ + QxGraph_ViewManager.h \ + QxGraph_ViewModel.h \ + QxGraph_Def.h \ + QxGraph.h + +dist_libQxGraph_la_SOURCES= \ + QxGraph_Prs.cxx \ + QxGraph_Canvas.cxx \ + QxGraph_CanvasView.cxx \ + QxGraph_ViewWindow.cxx \ + QxGraph_ViewManager.cxx \ + QxGraph_ViewModel.cxx + +MOC_FILES= \ + QxGraph_Canvas_moc.cxx \ + QxGraph_CanvasView_moc.cxx \ + QxGraph_ViewWindow_moc.cxx \ + QxGraph_ViewManager_moc.cxx \ + QxGraph_ViewModel_moc.cxx + +nodist_libQxGraph_la_SOURCES= $(MOC_FILES) + +dist_salomeres_DATA= \ + resources/view_fitall.png \ + resources/view_fitarea.png \ + resources/view_glpan.png \ + resources/view_pan.png \ + resources/view_reset.png \ + resources/view_zoom.png + +nodist_salomeres_DATA= \ + QxGraph_images.qm \ + QxGraph_msg_en.qm + +libQxGraph_la_CPPFLAGS=$(QT_INCLUDES) $(CAS_CPPFLAGS) $(PYTHON_INCLUDES) $(BOOST_CPPFLAGS) \ + -I$(srcdir)/../Qtx -I$(srcdir)/../SUIT +libQxGraph_la_LDFLAGS=$(QT_MT_LIBS) ../SUIT/libsuit.la diff --git a/src/QxGraph/QxGraph.h b/src/QxGraph/QxGraph.h new file mode 100644 index 000000000..e11d0f0af --- /dev/null +++ b/src/QxGraph/QxGraph.h @@ -0,0 +1,35 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifdef WNT +#ifdef QXGRAPH_EXPORTS +#define QXGRAPH_EXPORT __declspec(dllexport) +#else +#define QXGRAPH_EXPORT __declspec(dllimport) +#endif +#else +#define QXGRAPH_EXPORT +#endif + +#ifdef WNT +#pragma warning ( disable:4251 ) +#endif diff --git a/src/QxGraph/QxGraph_ActiveItem.h b/src/QxGraph/QxGraph_ActiveItem.h new file mode 100644 index 000000000..fc9f008e7 --- /dev/null +++ b/src/QxGraph/QxGraph_ActiveItem.h @@ -0,0 +1,59 @@ +// 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 +// +#ifndef QXGRAPH_ACTIVEITEM_H +#define QXGRAPH_ACTIVEITEM_H + +#include "QxGraph.h" + +#include +#include +#include + +class QXGRAPH_EXPORT QxGraph_ActiveItem +{ + public: + QxGraph_ActiveItem() {} + ~QxGraph_ActiveItem() {} + + virtual bool isMoveable() = 0; + virtual void beforeMoving() = 0; + virtual void afterMoving() = 0; + + virtual bool isResizable(QPoint thePoint, int& theCursorType) { return false; } + virtual bool isResizing() { return false; } + virtual void beforeResizing(int theCursorType) {} + virtual void resize(QPoint thePoint) {} + virtual void afterResizing() {} + + virtual void hilight(const QPoint& theMousePos, const bool toHilight = true) = 0; + virtual void select(const QPoint& theMousePos, const bool toSelect = true) = 0; + virtual void showPopup(QWidget* theParent, QMouseEvent* theEvent, const QPoint& theMousePos = QPoint()) = 0; + + virtual QString getToolTipText(const QPoint& theMousePos, QRect& theRect) const = 0; + + virtual bool arePartsOfOtherItem(QxGraph_ActiveItem* theSecondItem) { return false; } + + void setTMatrix(QWMatrix theMatrix) { myTMatrix = theMatrix; } + QWMatrix getTMatrix() const { return myTMatrix; } + + private: + QWMatrix myTMatrix; // canvas view's current transformation matrix +}; + +#endif diff --git a/src/QxGraph/QxGraph_Canvas.cxx b/src/QxGraph/QxGraph_Canvas.cxx new file mode 100644 index 000000000..8eb1afe63 --- /dev/null +++ b/src/QxGraph/QxGraph_Canvas.cxx @@ -0,0 +1,83 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "QxGraph_Canvas.h" +#include "QxGraph_Def.h" +#include "QxGraph_Prs.h" + +#include + +#include + +/*! + Constructor +*/ +QxGraph_Canvas::QxGraph_Canvas(SUIT_ResourceMgr* theMgr) : + QCanvas() +{ + printf("Construct QxGraph_Canvas\n"); + + resize(GRAPH_WIDTH, GRAPH_HEIGHT); + setDoubleBuffering(true); + + QColor aColor = theMgr->colorValue( "QxGraph", "Background", DEF_BACK_COLOR ); + setBackgroundColor(aColor); +} + +/*! + Destructor +*/ +QxGraph_Canvas::~QxGraph_Canvas() +{ + /*QObjectList* aNodeList = queryList("QObject"); + QObjectListIt aIt(*aNodeList); + QObject* anObj; + while ( (anObj = aIt.current()) != 0 ) { + ++aIt; + aNodeList->removeRef(anObj); + delete anObj; + } + delete aNodeList;*/ + + myPrsList.setAutoDelete(true); + myPrsList.clear(); +} + +/*! + Add view +*/ +void QxGraph_Canvas::addView(QCanvasView* theView) +{ + QCanvas::addView(theView); + theView->setPaletteBackgroundColor(backgroundColor().light(120)); +} + +/*! + Get Prs object with index theIndex +*/ +QxGraph_Prs* QxGraph_Canvas::getPrs(int theIndex) +{ + QxGraph_Prs* aRetPrs = 0; + if ( theIndex >= 0 && theIndex < myPrsList.count() ) + aRetPrs = myPrsList.at(theIndex); + return aRetPrs; +} diff --git a/src/QxGraph/QxGraph_Canvas.h b/src/QxGraph/QxGraph_Canvas.h new file mode 100644 index 000000000..a41ea829e --- /dev/null +++ b/src/QxGraph/QxGraph_Canvas.h @@ -0,0 +1,52 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef QXGRAPH_CANVAS_H +#define QXGRAPH_CANVAS_H + +#include "QxGraph.h" + +#include +#include + +class SUIT_ResourceMgr; +class QxGraph_Prs; + +class QXGRAPH_EXPORT QxGraph_Canvas : public QCanvas { + Q_OBJECT + + public: + QxGraph_Canvas(SUIT_ResourceMgr*); + virtual ~QxGraph_Canvas(); + + void addView(QCanvasView* theView); + + QPtrList getPrsList() const { return myPrsList; } + QxGraph_Prs* getPrs(int theIndex = 0); + void addPrs(QxGraph_Prs* thePrs) { myPrsList.append(thePrs); } + + private: + QPtrList myPrsList; + +}; + +#endif diff --git a/src/QxGraph/QxGraph_CanvasView.cxx b/src/QxGraph/QxGraph_CanvasView.cxx new file mode 100644 index 000000000..4e0f848a8 --- /dev/null +++ b/src/QxGraph/QxGraph_CanvasView.cxx @@ -0,0 +1,680 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "QxGraph_CanvasView.h" +#include "QxGraph_Canvas.h" +#include "QxGraph_ViewWindow.h" +#include "QxGraph_ActiveItem.h" +#include "QxGraph_Def.h" + +#include +#include + +const char* imageZoomCursor[] = { +"32 32 3 1", +". c None", +"a c #000000", +"# c #ffffff", +"................................", +"................................", +".#######........................", +"..aaaaaaa.......................", +"................................", +".............#####..............", +"...........##.aaaa##............", +"..........#.aa.....a#...........", +".........#.a.........#..........", +".........#a..........#a.........", +"........#.a...........#.........", +"........#a............#a........", +"........#a............#a........", +"........#a............#a........", +"........#a............#a........", +".........#...........#.a........", +".........#a..........#a.........", +".........##.........#.a.........", +"........#####.....##.a..........", +".......###aaa#####.aa...........", +"......###aa...aaaaa.......#.....", +".....###aa................#a....", +"....###aa.................#a....", +"...###aa...............#######..", +"....#aa.................aa#aaaa.", +".....a....................#a....", +"..........................#a....", +"...........................a....", +"................................", +"................................", +"................................", +"................................"}; + +const char* imageCrossCursor[] = { + "32 32 3 1", + ". c None", + "a c #000000", + "# c #ffffff", + "................................", + "................................", + "................................", + "................................", + "................................", + "................................", + "................................", + "...............#................", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + ".......#################........", + "........aaaaaaa#aaaaaaaaa.......", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "...............#a...............", + "................a...............", + "................................", + "................................", + "................................", + "................................", + "................................", + "................................", + "................................"}; + +/*! + Constructor +*/ +QxGraph_CanvasView::QxGraph_CanvasView(QxGraph_Canvas* theCanvas, QxGraph_ViewWindow* theViewWindow) : + QCanvasView(theCanvas, theViewWindow, 0, Qt::WRepaintNoErase), + myCurrentItem(0), + myHilightedItem(0), + mySelectedItem(0) +{ + printf("Construct QxGraph_CanvasView\n"); + setName("QxGraph_CanvasView"); + + myOperation = NOTHING; + myCursor = cursor(); + mySelectedRect = 0; + + myTimer = new QTimer(this); + connect(myTimer, SIGNAL(timeout()), this, SLOT(onTimeout())); + + viewport()->setMouseTracking(true); +} + +/*! + Destructor +*/ +QxGraph_CanvasView::~QxGraph_CanvasView() +{ +} + +void QxGraph_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent) +{ + myPoint = inverseWorldMatrix().map(theEvent->pos()); + myGlobalPoint = theEvent->globalPos(); + myCurrentItem = 0; + + if ( theEvent->button() == Qt::MidButton && theEvent->state() == Qt::ControlButton + || + myOperation == PANVIEW ) + { // Panning + if ( myOperation != PANVIEW ) { + myOperation = PANVIEW; + myCursor = cursor(); // save old cursor + QCursor panCursor (Qt::SizeAllCursor); + setCursor(panCursor); + } + return; + } + + if ( myOperation == PANGLOBAL ) + { // Global panning + return; + } + + if ( theEvent->button() == Qt::LeftButton && theEvent->state() == Qt::ControlButton + || + myOperation == ZOOMVIEW ) + { // Zoom + if ( myOperation != ZOOMVIEW ) { + myOperation = ZOOMVIEW; + myCursor = cursor(); // save old cursor + QPixmap zoomPixmap (imageZoomCursor); + QCursor zoomCursor (zoomPixmap); + setCursor(zoomCursor); + } + return; + } + + if ( theEvent->button() == Qt::LeftButton ) + { + QCanvasItemList aList = canvas()->collisions(myPoint); + // to move items on canvas view + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + int aCursorType; + if ( anActItem && anActItem->isResizable(myPoint,aCursorType) ) + { // resize itself only active items if it is resizable + anActItem->beforeResizing(aCursorType); + myCurrentItem = *it; + return; + } + else if ( anActItem && anActItem->isMoveable() ) + { // move itself only active items if it is moveable + anActItem->beforeMoving(); + myCurrentItem = *it; + return; + } + } + } +} + +void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent) +{ + QPoint aPoint = inverseWorldMatrix().map(theEvent->pos()); + QPoint aGlobalPoint = theEvent->globalPos(); + + if (myTimer->isActive()) myTimer->stop(); + + if ( myOperation == PANVIEW ) + { // Panning + scrollBy(myGlobalPoint.x() - aGlobalPoint.x(), + myGlobalPoint.y() - aGlobalPoint.y()); + myGlobalPoint = aGlobalPoint; + return; + } + + if ( myOperation == WINDOWFIT ) + { // Fit within rectangle + int aLX, aTY; //left x and top y + if (myPoint.x() < aPoint.x()) aLX = myPoint.x(); + else aLX = aPoint.x(); + if (myPoint.y() < aPoint.y()) aTY = myPoint.y(); + else aTY = aPoint.y(); + QRect aRect(aLX, aTY, abs(myPoint.x()-aPoint.x()), abs(myPoint.y()-aPoint.y())); + QCanvasRectangle* aRect1 = new QCanvasRectangle(aRect, canvas()); + + //hide old selected rectangle + if (mySelectedRect) + mySelectedRect->hide(); + //draw new selected rectangle + QPen pen(Qt::black,1,Qt::SolidLine); + aRect1->setPen(pen); + aRect1->setZ(3); + aRect1->show(); + + mySelectedRect = aRect1; + canvas()->update(); + } + + if ( myOperation == ZOOMVIEW ) + { // Zoom + QWMatrix m = worldMatrix(); + + double dx = aGlobalPoint.x() - myGlobalPoint.x(); + double s = 1. + fabs(dx)*( (m.m11() < 1) ? m.m11() : 1. )/70.; + if (dx < 0) s = 1./s; + + m.scale(s, s); + setWorldMatrix(m); + + // remember the canvas view's current transformation matrix in all canvas items + QCanvasItemList aList = canvas()->allItems(); + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + if ( anActItem ) anActItem->setTMatrix(m); + } + + myGlobalPoint = aGlobalPoint; + return; + } + + if ( myCurrentItem ) + { + QxGraph_ActiveItem* anActItem = dynamic_cast( myCurrentItem ); + if ( anActItem && anActItem->isResizing() ) + { // to resize items on canvas view + anActItem->resize(aPoint); + return; + } + + // to move items on canvas view + if ( myCurrentItem->x() && myCurrentItem->y() ) { + double cx = myCurrentItem->x() - myPoint.x(); + double cy = myCurrentItem->y() - myPoint.y(); + + if (aPoint.x()+cx < 0) aPoint.setX(-(int)cx); + if (aPoint.y()+cy < 0) aPoint.setY(-(int)cy); + } + myCurrentItem->moveBy(aPoint.x() - myPoint.x(), + aPoint.y() - myPoint.y()); + myPoint = aPoint; + canvas()->update(); + + // scroll contents if mouse is outside + QRect r(contentsX(), contentsY(), visibleWidth(), visibleHeight()); + if (!r.contains(theEvent->pos())) { + int dx = 0, dy = 0; + if (theEvent->pos().x() < r.left()) dx = theEvent->pos().x() - r.left(); + if (theEvent->pos().x() > r.right()) dx = theEvent->pos().x() - r.right(); + if (theEvent->pos().y() < r.top()) dy = theEvent->pos().y() - r.top(); + if (theEvent->pos().y() > r.bottom()) dy = theEvent->pos().y() - r.bottom(); + scrollBy(dx, dy); + // start timer to scroll in silent mode + myDX = dx; myDY = dy; + myTimer->start(100); + } + + return; + } + else + { + QCanvasItemList aList = canvas()->collisions(aPoint); + // perform actions for active items + bool isHilightPerformed = false; + + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + + if (!isHilightPerformed && anActItem) { + // hilight + anActItem->hilight(aPoint); + if (anActItem != myHilightedItem) { + if (myHilightedItem) + myHilightedItem->hilight(aPoint, false); + myHilightedItem = anActItem; + } + isHilightPerformed = true; + + // show tooltip + QxGraph_ToolTip* aToolTip = new QxGraph_ToolTip(this); + aToolTip->maybeTip(aPoint); + } + + int aCursorType; + if ( anActItem && anActItem->isResizable(aPoint,aCursorType) ) { + // set resize cursor + QCursor resizeCursor; + switch (aCursorType) + { + case 1: //left + case 3: //right + resizeCursor = QCursor(Qt::SizeHorCursor); + break; + case 2: //top + case 4: //bottom + resizeCursor = QCursor(Qt::SizeVerCursor); + break; + case 5: //left-top + case 7: //right-bottom + resizeCursor = QCursor(Qt::SizeFDiagCursor); + break; + case 6: //right-top + case 8: //left-bottom + resizeCursor = QCursor(Qt::SizeBDiagCursor); + break; + default : + resizeCursor = QCursor(Qt::ArrowCursor); + break; + } + setCursor(resizeCursor); + return; + } + else { + // reset old cursor + setCursor(QCursor(Qt::ArrowCursor)); + return; + } + } + + if (!isHilightPerformed && myHilightedItem) { + myHilightedItem->hilight(aPoint, false); + myHilightedItem = 0; + QToolTip::hide(); //@ temporary solution + } + + if ( cursor().shape() == Qt::SizeVerCursor || cursor().shape() == Qt::SizeHorCursor + || cursor().shape() == Qt::SizeBDiagCursor || cursor().shape() == Qt::SizeFDiagCursor) + setCursor(QCursor(Qt::ArrowCursor)); + } +} + +void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) +{ + QPoint aPoint = inverseWorldMatrix().map(theEvent->pos()); + + if (myTimer->isActive()) myTimer->stop(); + + if (myCurrentItem) + { // to move items on canvas view + QxGraph_ActiveItem* anActItem = dynamic_cast( myCurrentItem ); + if ( anActItem && anActItem->isResizing() ) + { + anActItem->afterResizing(); + // reset old cursor + setCursor(QCursor(Qt::ArrowCursor)); + } + else if ( anActItem && anActItem->isMoveable() ) + anActItem->afterMoving(); + } + myCurrentItem = 0; + + if ( myOperation == PANVIEW ) + { // Panning + myOperation = NOTHING; + viewport()->setMouseTracking(true); + setCursor(myCursor); + } + + if ( myOperation == PANGLOBAL ) + { // Global panning + myOperation = NOTHING; + center( theEvent->x(), theEvent->y() ); + setCursor(myCursor); + } + + if ( myOperation == WINDOWFIT ) + { // Fit within rectangle + myOperation = NOTHING; + + if (mySelectedRect) { + mySelectedRect->hide(); + mySelectedRect = 0; + //canvas()->update(); + } + + //myPoint is the start point for selecting rectangle now + int aLX, aTY; //left x and top y + if (myPoint.x() < aPoint.x()) aLX = myPoint.x(); + else aLX = aPoint.x(); + if (myPoint.y() < aPoint.y()) aTY = myPoint.y(); + else aTY = aPoint.y(); + + //calculate width and height for new view and new zoom factor + double aXzoom = ((double)visibleWidth())/((double)(abs(myPoint.x()-aPoint.x()))); + double aYzoom = ((double)visibleHeight())/((double)(abs(myPoint.y()-aPoint.y()))); + if (aXzoom > aYzoom) aXzoom = aYzoom; + + QWMatrix m; + m.scale(aXzoom, aXzoom); + setWorldMatrix(m); + + // remember the canvas view's current transformation matrix in all canvas items + QCanvasItemList aList = canvas()->allItems(); + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + if ( anActItem ) anActItem->setTMatrix(m); + } + + setContentsPos((int)(aLX*aXzoom), (int)(aTY*aYzoom)); + + canvas()->update(); + + viewport()->setMouseTracking(true); + setCursor(myCursor); + } + + if ( myOperation == ZOOMVIEW ) + { // Zoom + myOperation = NOTHING; + viewport()->setMouseTracking(true); + setCursor(myCursor); + } + + if ( theEvent->button() == RightButton ) + { + // Selection mechanism + QCanvasItemList aList = canvas()->collisions(aPoint); + bool isSelectionPerformed = false; + + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + if (!isSelectionPerformed && anActItem) + { + anActItem->select(aPoint); + if (anActItem != mySelectedItem) + { + if (mySelectedItem && isSelectedItemInCanvas() && + !mySelectedItem->arePartsOfOtherItem(anActItem)) mySelectedItem->select(aPoint, false); + mySelectedItem = anActItem; + + // unhilight hilighted item if selection was performed + if (myHilightedItem) { + myHilightedItem->hilight(aPoint, false); + myHilightedItem = 0; + } + } + isSelectionPerformed = true; + } + } + + if (!isSelectionPerformed) + { + if ( mySelectedItem ) + { + if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false); + mySelectedItem = 0; + } + + // Background popup + printf("Background popup\n"); + QContextMenuEvent aEvent( QContextMenuEvent::Mouse, + theEvent->pos(), theEvent->globalPos(), + theEvent->state() ); + if ( getViewWindow() ) + getViewWindow()->contextPopupEvent(&aEvent); // => emit contextMenuRequested( &aEvent ); + } + else + { // show context popup for the selected item + mySelectedItem->showPopup(viewport(), theEvent, aPoint); + } + } + + if ( theEvent->button() == LeftButton ) + { + // Selection mechanism + QCanvasItemList aList = canvas()->collisions(aPoint); + + if ( aList.empty() && mySelectedItem ) + { + if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false); + mySelectedItem = 0; + } + else + { + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + if (anActItem) + { + anActItem->select(aPoint); + if (anActItem != mySelectedItem) + { + if (mySelectedItem && isSelectedItemInCanvas() && + !mySelectedItem->arePartsOfOtherItem(anActItem)) mySelectedItem->select(aPoint, false); + mySelectedItem = anActItem; + } + break; + } + } + } + } +} + +void QxGraph_CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* theEvent) +{ + +} + +bool QxGraph_CanvasView::isSelectedItemInCanvas() +{ + // check if mySelectedItem is included into the canvas: + // if yes => unselect it + // if no => do nothing + bool anIsInCanvas = false; + QCanvasItemList aListC = canvas()->allItems(); + for (QCanvasItemList::Iterator itC = aListC.begin(); itC != aListC.end(); ++itC) { + QxGraph_ActiveItem* anActItemC = dynamic_cast( *itC ); + if ( anActItemC && anActItemC == mySelectedItem ) { + anIsInCanvas = true; + break; + } + } + return anIsInCanvas; +} + +void QxGraph_CanvasView::activateFitAll() +{ + //myOperation = FITALL; + int w = 0, h = 0; + QCanvasItemList l = canvas()->allItems(); + for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { + QRect r = (*it)->boundingRect(); + if (w < r.right()) w = r.right(); + if (h < r.bottom()) h = r.bottom(); + } + w += GRAPH_MARGIN; h += GRAPH_MARGIN; + double s = ((double)visibleWidth())/((double)w); + double s1 = ((double)visibleHeight())/((double)h); + if (s > s1) s = s1; + + setContentsPos(0,0); + QWMatrix m; + m.scale(s, s); + setWorldMatrix(m); + + // remember the canvas view's current transformation matrix in all canvas items + QCanvasItemList aList = canvas()->allItems(); + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + if ( anActItem ) anActItem->setTMatrix(m); + } + + canvas()->update(); + //myOperation = NOTHING; +} + +void QxGraph_CanvasView::activateFitRect() +{ + myOperation = WINDOWFIT; + viewport()->setMouseTracking(false); + myCursor = cursor(); // save old cursor + QCursor handCursor (Qt::PointingHandCursor); + setCursor(handCursor); +} + +void QxGraph_CanvasView::activateZoom() +{ + myOperation = ZOOMVIEW; + viewport()->setMouseTracking(false); + myCursor = cursor(); // save old cursor + QPixmap zoomPixmap (imageZoomCursor); + QCursor zoomCursor (zoomPixmap); + setCursor(zoomCursor); +} + +void QxGraph_CanvasView::activatePanning() +{ + myOperation = PANVIEW; + viewport()->setMouseTracking(false); + myCursor = cursor(); // save old cursor + QCursor panCursor (Qt::SizeAllCursor); + setCursor(panCursor); +} + +void QxGraph_CanvasView::activateGlobalPanning() +{ + myOperation = PANGLOBAL; + myCursor = cursor(); // save old cursor + QPixmap globalPanPixmap (imageCrossCursor); + QCursor glPanCursor (globalPanPixmap); + setCursor(glPanCursor); +} + +void QxGraph_CanvasView::activateReset() +{ + //myOperation = RESETVIEW; + setContentsPos(0,0); + QWMatrix m; + setWorldMatrix(m); + + // remember the canvas view's current transformation matrix in all canvas items + QCanvasItemList aList = canvas()->allItems(); + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + if ( anActItem ) anActItem->setTMatrix(m); + } + + //myOperation = NOTHING; +} + +void QxGraph_CanvasView::onTimeout() +{ + if (myCurrentItem) { + scrollBy(myDX, myDY); + + double cx, cy; + inverseWorldMatrix().map((double)myDX, (double)myDY, &cx, &cy); + if (myCurrentItem->x()+cx < 0) cx = -myCurrentItem->x(); + if (myCurrentItem->y()+cy < 0) cy = -myCurrentItem->y(); + myCurrentItem->moveBy(cx, cy); + myPoint.setX(myPoint.x()+(int)cx); + myPoint.setY(myPoint.y()+(int)cy); + canvas()->update(); + } +} + +QxGraph_ViewWindow* QxGraph_CanvasView::getViewWindow() const +{ + return dynamic_cast( parent() ); +} + +/*! + Shows tooltip if necessary +*/ +void QxGraph_ToolTip::maybeTip(const QPoint& theMousePos) { + QCanvasItemList aList = ((QCanvasView*)parentWidget())->canvas()->collisions(theMousePos); + + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + if (anActItem) + { + QRect aRect; + QString aText = anActItem->getToolTipText(theMousePos, aRect); + int avX, avY; + QWMatrix aWM = ((QCanvasView*)parentWidget())->worldMatrix(); + ((QCanvasView*)parentWidget())->contentsToViewport((int)(aRect.left()*aWM.m11()), + (int)(aRect.top()*aWM.m22()), + avX, avY); + QRect aTipRect(avX, avY, (int)(aRect.width()*aWM.m11()), (int)(aRect.height()*aWM.m22())); + if (!aText.isEmpty()) + tip(aTipRect, aText); + return; + } + } +} diff --git a/src/QxGraph/QxGraph_CanvasView.h b/src/QxGraph/QxGraph_CanvasView.h new file mode 100644 index 000000000..5bd14f740 --- /dev/null +++ b/src/QxGraph/QxGraph_CanvasView.h @@ -0,0 +1,102 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef QXGRAPH_CANVASVIEW_H +#define QXGRAPH_CANVASVIEW_H + +#include "QxGraph.h" + +#include +#include +#include +#include + +class QxGraph_Canvas; +class QxGraph_ViewWindow; +class QxGraph_ActiveItem; + +class QXGRAPH_EXPORT QxGraph_CanvasView : public QCanvasView { + Q_OBJECT + + public: + enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, PANGLOBAL, + WINDOWFIT, FITALLVIEW, RESETVIEW }; + + QxGraph_CanvasView(QxGraph_Canvas* theCanvas, QxGraph_ViewWindow* theViewWindow); + virtual ~QxGraph_CanvasView(); + + QxGraph_ViewWindow* getViewWindow() const; + + void activateFitAll(); + void activateFitRect(); + void activateZoom(); + void activatePanning(); + void activateGlobalPanning(); + void activateReset(); + + public slots: + void onTimeout(); + //void changeBackground(); + + protected: + void contentsMousePressEvent(QMouseEvent* theEvent); + void contentsMouseMoveEvent(QMouseEvent* theEvent); + void contentsMouseReleaseEvent(QMouseEvent* theEvent); + void contentsMouseDoubleClickEvent(QMouseEvent* theEvent); + + bool isSelectedItemInCanvas(); + + private: + // for moving items + QCanvasItem* myCurrentItem; + QPoint myPoint; + QPoint myGlobalPoint; + + // for control toolbar actions + OperationType myOperation; + QCursor myCursor; + QCanvasRectangle* mySelectedRect; + + // for automatic content scrolling if mouse is outside + QTimer* myTimer; + int myDX; + int myDY; + + // for hilight + QxGraph_ActiveItem* myHilightedItem; + + // for selection + QxGraph_ActiveItem* mySelectedItem; +}; + + +class QxGraph_ToolTip: public QToolTip { + + public: + QxGraph_ToolTip(QWidget* theWidget, QToolTipGroup* theGroup = 0): + QToolTip(theWidget, theGroup) {} + ~QxGraph_ToolTip() { remove(parentWidget()); } + + virtual void maybeTip(const QPoint& theMousePos); +}; + +#endif diff --git a/src/QxGraph/QxGraph_Def.h b/src/QxGraph/QxGraph_Def.h new file mode 100644 index 000000000..88937e325 --- /dev/null +++ b/src/QxGraph/QxGraph_Def.h @@ -0,0 +1,34 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef QXGRAPH_DEF_H +#define QXGRAPH_DEF_H + +#define DEF_BACK_COLOR QColor(144, 208, 211) +#define RECTANGLE_BODY QColor(255,249,147) + +#define GRAPH_WIDTH 1250 +#define GRAPH_HEIGHT 950 + +#define GRAPH_MARGIN 50 + +#endif diff --git a/src/QxGraph/QxGraph_Prs.cxx b/src/QxGraph/QxGraph_Prs.cxx new file mode 100644 index 000000000..c9c6b219d --- /dev/null +++ b/src/QxGraph/QxGraph_Prs.cxx @@ -0,0 +1,251 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "QxGraph_Prs.h" + +#include "QxGraph_Canvas.h" +#include "QxGraph_Def.h" // for debug only + +#include "SUIT_Session.h" // for debug only + +/*! + Constructor +*/ +QxGraph_Prs::QxGraph_Prs(QxGraph_Canvas* theCanvas): + myCanvas(theCanvas), + myDMode(0), + needUpdate(true) +{ + myCanvas->addPrs(this); +} + +/*! + Destructor +*/ +QxGraph_Prs::~QxGraph_Prs() +{ + for ( DMode2ItemList::iterator it1 = myDisplayMap.begin(); + it1 != myDisplayMap.end(); + it1++ ) + { + for ( std::list::iterator it2 = (*it1).second.begin(); + it2 != (*it1).second.end(); + it2++ ) + { + QCanvasItem* anItem = *it2; + if ( anItem ) delete anItem; + } + } + + myDisplayMap.clear(); +} + +/*! + Add item to display in the view with index theDMode +*/ +void QxGraph_Prs::addItem(QCanvasItem* theItem, int theDMode) +{ + if ( theDMode == -1 ) // add item for the current display mode + myDisplayMap[myDMode].push_back(theItem); + else + myDisplayMap[theDMode].push_back(theItem); +} + +/*! + Remove item from the view with index theDMode +*/ +void QxGraph_Prs::removeItem(QCanvasItem* theItem, int theDMode) +{ + if ( theDMode == -1 ) // remove item from the current display mode + myDisplayMap[myDMode].remove(theItem); + else + myDisplayMap[theDMode].remove(theItem); +} + +/*! Adds all the items of this presentation for the current display mode + * to the canvas. + */ +void QxGraph_Prs::show() +{ + if ( isToUpdate() ) + update(); + + for ( std::list::iterator it = myDisplayMap[myDMode].begin(); + it != myDisplayMap[myDMode].end(); + it++ ) + { + QCanvasItem* anItem = *it; + if ( anItem ) + { + anItem->setCanvas( myCanvas ); + anItem->show(); + } + } +} + +/*! Removes all the items belonging to this presentation from the canvas. + */ +void QxGraph_Prs::hide() +{ + for ( DMode2ItemList::iterator it1 = myDisplayMap.begin(); + it1 != myDisplayMap.end(); + it1++ ) + { + for ( std::list::iterator it2 = (*it1).second.begin(); + it2 != (*it1).second.end(); + it2++ ) + { + QCanvasItem* anItem = *it2; + if ( anItem ) + { + anItem->setCanvas( 0 ); + } + } + } +} + +/*! Prepare for full recomputation of the presentation + */ +void QxGraph_Prs::setToUpdate( const bool theFlag ) +{ + needUpdate = theFlag; +} + +/*! Re-fills the presentation with items. + * Base implementation just resets flag. + * It should be called at the end by re-implementations. + */ +void QxGraph_Prs::update() +{ + setToUpdate( false ); +} + +/*! + Add a QCanvasRectangle item for display mode DMode +*/ +QCanvasItem* QxGraph_Prs::addRectangleItem(QRect theRect, int theDMode) +{ + QCanvasRectangle* aRectItem; + if ( myCanvas ) + { + QCanvasRectangle* aRectItem = new QCanvasRectangle(theRect, myCanvas); + aRectItem->setZ(0); + aRectItem->show(); + myCanvas->update(); + + // test drawing features: brush, pen ... + QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY )); + aRectItem->setBrush(aBr); + } + addItem(aRectItem); + return aRectItem; +} + +/*! + Add a QCanvasPolygon item for display mode DMode +*/ +QCanvasItem* QxGraph_Prs::addPolygonItem(QPointArray thePA, int theDMode) +{ + QCanvasPolygon* aPolyItem; + if ( myCanvas ) + { + aPolyItem = new QCanvasPolygon(myCanvas); + aPolyItem->setZ(0); + aPolyItem->setPoints(thePA); + aPolyItem->show(); + myCanvas->update(); + + // test drawing features: brush, pen ... + QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY )); + aPolyItem->setBrush(aBr); + QPen aPen(Qt::black,2); + aPolyItem->setPen(aPen); + } + addItem(aPolyItem); + return aPolyItem; +} + +/*! + Add a QCanvasLine item for display mode DMode +*/ +QCanvasItem* QxGraph_Prs::addLineItem(QPoint theStart, QPoint theEnd, int theDMode) +{ + QCanvasLine* aLineItem; + if ( myCanvas ) + { + aLineItem = new QCanvasLine(myCanvas); + aLineItem->setZ(0); + aLineItem->setPoints(theStart.x(), theStart.y(), theEnd.x(), theEnd.y()); + aLineItem->show(); + myCanvas->update(); + + // test drawing features: brush, pen ... + QPen aPen(Qt::black,2); + aLineItem->setPen(aPen); + } + addItem(aLineItem); + return aLineItem; +} + +/*! + Add a QCanvasEllipse item for display mode DMode +*/ +QCanvasItem* QxGraph_Prs::addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode) +{ + QCanvasEllipse* aEllipseItem; + if ( myCanvas ) + { + aEllipseItem = new QCanvasEllipse(theW, theH, theStartAngle, theAngle, myCanvas); + aEllipseItem->setZ(0); + aEllipseItem->show(); + myCanvas->update(); + + // test drawing features: brush, pen ... + QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY )); + aEllipseItem->setBrush(aBr); + QPen aPen(Qt::black,2); + aEllipseItem->setPen(aPen); + } + addItem(aEllipseItem); + return aEllipseItem; +} + +/*! + Add a QCanvasText item for display mode DMode +*/ +QCanvasItem* QxGraph_Prs::addTextItem(QString theText, int theDMode) +{ + QCanvasText* aTextItem; + if ( myCanvas ) + { + aTextItem = new QCanvasText(theText, myCanvas); + aTextItem->setZ(0); + aTextItem->show(); + myCanvas->update(); + + // test drawing features: font, color, text flags ... + aTextItem->setColor(Qt::darkBlue); + //aTextItem->setFont(QFont("Times"/*"Helvetica"*/, 14, QFont::Normal, true)); + } + addItem(aTextItem); + return aTextItem; +} diff --git a/src/QxGraph/QxGraph_Prs.h b/src/QxGraph/QxGraph_Prs.h new file mode 100644 index 000000000..161610314 --- /dev/null +++ b/src/QxGraph/QxGraph_Prs.h @@ -0,0 +1,73 @@ +// 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 +// +#ifndef QXGRAPH_PRS_H +#define QXGRAPH_PRS_H + +#include + +#include +#include +#include + +class QxGraph_Canvas; + +class QXGRAPH_EXPORT QxGraph_Prs +{ + public: + QxGraph_Prs(QxGraph_Canvas*); + virtual ~QxGraph_Prs(); + + QxGraph_Canvas* getCanvas() const { return myCanvas; } + + void addItem(QCanvasItem* theItem, int theDMode = -1); + void removeItem(QCanvasItem* theItem, int theDMode = -1); + + /* add items for display mode theDMode + if theDMode is equal to -1 add item for the current (active) display mode */ + QCanvasItem* addRectangleItem(QRect theRect, int theDMode = -1); + QCanvasItem* addPolygonItem(QPointArray thePA, int theDMode = -1); + QCanvasItem* addLineItem(QPoint theStart, QPoint theEnd, int theDMode = -1); + QCanvasItem* addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode = -1); + QCanvasItem* addTextItem(QString theText, int theDMode = -1); + + typedef std::map< int, std::list > DMode2ItemList; + + const DMode2ItemList& getDisplayMap() const { return myDisplayMap; } + const std::list& getItems(int theDMode) { return myDisplayMap[theDMode]; } + + void setDMode(int theDMode) { myDMode = theDMode; } + int getDMode() const { return myDMode; } + + virtual void show(); + virtual void hide(); + virtual void setToUpdate( const bool ); + bool isToUpdate() { return needUpdate; } + +protected: + virtual void update(); + +private: + QxGraph_Canvas* myCanvas; + DMode2ItemList myDisplayMap; + + int myDMode; + bool needUpdate; +}; + +#endif diff --git a/src/QxGraph/QxGraph_ViewManager.cxx b/src/QxGraph/QxGraph_ViewManager.cxx new file mode 100644 index 000000000..1480b202c --- /dev/null +++ b/src/QxGraph/QxGraph_ViewManager.cxx @@ -0,0 +1,59 @@ +// 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 +// +#include "QxGraph_ViewManager.h" + +int QxGraph_ViewManager::myMaxId = 0; + +/*! + Constructor +*/ +QxGraph_ViewManager::QxGraph_ViewManager( SUIT_Study* theStudy, + SUIT_Desktop* theDesktop, + SUIT_ViewModel* theViewModel ) + : SUIT_ViewManager( theStudy, theDesktop, theViewModel ) +{ + myId = ++myMaxId; +} + +/*! + Destructor +*/ +QxGraph_ViewManager::~QxGraph_ViewManager() +{ +} + +/*! + Sets view name + \param theView - view to assign name +*/ +void QxGraph_ViewManager::setViewName(SUIT_ViewWindow* theView) +{ + int aPos = myViews.find(theView); + theView->setCaption( QString( "QxGraph scene:%1 - viewer:%2" ).arg( myId ).arg(aPos+1)); +} + +/*! + Fills popup menu with custom actions + \param popup - popup menu to be filled with +*/ +void QxGraph_ViewManager::contextMenuPopup( QPopupMenu* thePopup) +{ + SUIT_ViewManager::contextMenuPopup( thePopup ); + // to be implemented +} diff --git a/src/QxGraph/QxGraph_ViewManager.h b/src/QxGraph/QxGraph_ViewManager.h new file mode 100644 index 000000000..db3ed539e --- /dev/null +++ b/src/QxGraph/QxGraph_ViewManager.h @@ -0,0 +1,48 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef QXGRAPH_VIEWMANAGER_H +#define QXGRAPH_VIEWMANAGER_H + +#include "QxGraph.h" + +#include "QxGraph_ViewModel.h" +#include "SUIT_ViewManager.h" + +class SUIT_Desktop; + +class QXGRAPH_EXPORT QxGraph_ViewManager : public SUIT_ViewManager +{ + Q_OBJECT + +public: + QxGraph_ViewManager( SUIT_Study* theStudy, SUIT_Desktop* theDesktop, SUIT_ViewModel* theViewModel = 0 ); + ~QxGraph_ViewManager(); + + virtual void contextMenuPopup( QPopupMenu* thePopup ); + +protected: + void setViewName(SUIT_ViewWindow* theView); + +private: + static int myMaxId; + int myId; + +}; + +#endif diff --git a/src/QxGraph/QxGraph_ViewModel.cxx b/src/QxGraph/QxGraph_ViewModel.cxx new file mode 100644 index 000000000..df49f0829 --- /dev/null +++ b/src/QxGraph/QxGraph_ViewModel.cxx @@ -0,0 +1,157 @@ +// 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 +// +#include "QxGraph_ViewModel.h" +#include "QxGraph_ViewWindow.h" +#include "QxGraph_Canvas.h" +#include "QxGraph_CanvasView.h" +#include "QxGraph_Def.h" +#include "QxGraph_Prs.h" + +#include "SUIT_Desktop.h" +#include "SUIT_ViewWindow.h" +#include "SUIT_Session.h" + +#include +#include +#include // for addRectangleItem(...) method (can be removed in the future) + +/*! + Constructor +*/ +QxGraph_Viewer::QxGraph_Viewer() + :SUIT_ViewModel(), + myCanvas(0), + myCurrentView(0) +{ + printf("Construct QxGraph_Viewer\n"); + //myCanvases.setAutoDelete(true); + //myCanvasViews.setAutoDelete(true); +} + +/*! + Destructor +*/ +QxGraph_Viewer::~QxGraph_Viewer() +{ + if ( myCanvas ) delete myCanvas; + //if ( !myCanvases.isEmpty() ) myCanvases.clear(); + if ( !myCanvasViews.isEmpty() ) myCanvasViews.clear(); + myCurrentView = 0; +} + +/*! + Start initialization of view window + \param view - view window to be initialized +*/ +void QxGraph_Viewer::initView( QxGraph_ViewWindow* view ) +{ + if ( view ) + { + view->initLayout(); + + /* + // test add items into the current canvas view + QRect aRect(100,200,200,100); + QCanvasItem* aRectItem = aPrs->addRectangleItem(aRect); + //delete aRectItem; + + QPointArray aPA(6); + aPA.putPoints(0, 6, 400,100, 500,70, 600,100, 600,200, 500,230, 400,200); + QCanvasItem* aPolyItem = aPrs->addPolygonItem(aPA); + //delete aPolyItem; + + QPoint aStart(500,300), aEnd(700,250); + QCanvasItem* aLineItem = aPrs->addLineItem(aStart, aEnd); + //delete aLineItem; + + QCanvasItem* aEllipseItem = aPrs->addEllipseItem(200, 100, 30*16, 120*16); + aEllipseItem->setX(400); + aEllipseItem->setY(400); + //delete aEllipseItem; + + QCanvasItem* aTextItem = aPrs->addTextItem("This is a QCanvasText item"); + aTextItem->setX(100); + aTextItem->setY(500); + //delete aTextItem; + */ + } +} + +/*! + Creates new view window + \param theDesktop - main window of application +*/ +SUIT_ViewWindow* QxGraph_Viewer::createView(SUIT_Desktop* theDesktop) +{ + QxGraph_ViewWindow* aRes = new QxGraph_ViewWindow( theDesktop, this ); + initView( aRes ); + return aRes; +} + +/*! + Set view with index theIndex from myCanvasViews as current view + \param theIndex - the index of the view in the list +*/ +void QxGraph_Viewer::setCurrentView(int theIndex) +{ + if ( theIndex >= 0 && theIndex < myCanvasViews.count() ) + { + myCurrentView = myCanvasViews.at(theIndex); + myViewManager->getActiveView()->setCentralWidget(myCurrentView); + } +} + +/*! + Builds popup for QxGraph viewer +*/ +void QxGraph_Viewer::contextMenuPopup(QPopupMenu* thePopup) +{ + printf("QxGraph_Viewer::contextMenuPopup\n"); + thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBgColor() ) ); + + thePopup->insertSeparator(); + + QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView()); + if ( aView && !aView->getToolBar()->isVisible() ) + thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); +} + +/*! + SLOT: called if background color is to be changed changed, passes new color to current canvas view +*/ +void QxGraph_Viewer::onChangeBgColor() +{ + QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView()); + if( !aView ) + return; + QColor aColorActive = aView->backgroundColor(); + + QColor selColor = QColorDialog::getColor( aColorActive, aView); + if ( selColor.isValid() ) + aView->setBackgroundColor(selColor); +} + +/*! + SLOT: called when popup item "Show toolbar" is activated, shows toolbar of active view window +*/ +void QxGraph_Viewer::onShowToolbar() { + QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView()); + if ( aView ) + aView->getToolBar()->show(); +} diff --git a/src/QxGraph/QxGraph_ViewModel.h b/src/QxGraph/QxGraph_ViewModel.h new file mode 100644 index 000000000..e04fcb35e --- /dev/null +++ b/src/QxGraph/QxGraph_ViewModel.h @@ -0,0 +1,82 @@ +// 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 +// +#ifndef QXGRAPH_VIEWMODEL_H +#define QXGRAPH_VIEWMODEL_H + +#include "QxGraph.h" + +#include "SUIT_ViewModel.h" + +class QCanvasItem; // for addRectangleItem(...) method (can be removed in the future) + +class QxGraph_Canvas; +class QxGraph_CanvasView; +class QxGraph_ViewWindow; +class QxGraph_Prs; + +class QXGRAPH_EXPORT QxGraph_Viewer: public SUIT_ViewModel +{ + Q_OBJECT + + public: + static QString Type() { return "QxGraphViewer"; } + + QxGraph_Viewer(); + virtual ~QxGraph_Viewer(); + + virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); + virtual QString getType() const { return Type(); } + + virtual void contextMenuPopup(QPopupMenu*); + + QxGraph_Canvas* getCanvas() const { return myCanvas; } + void setCanvas(QxGraph_Canvas* theCanvas) { myCanvas = theCanvas; } + //QPtrList getCanvases() { return myCanvases; } + //void setCanvases(QPtrList theCanvases) { myCanvases = theCanvases; } + + //void addCanvas(QxGraph_Canvas* theCanvas) { myCanvases.append(theCanvas); } + //void removeCanvas(QxGraph_Canvas* theCanvas) { myCanvases.remove(theCanvas); } + + QPtrList getCanvasViews() { return myCanvasViews; } + void setCanvasViews(QPtrList theViews) { myCanvasViews = theViews; } + + void addView(QxGraph_CanvasView* theView) { myCanvasViews.append(theView); } + void removeView(QxGraph_CanvasView* theView) { myCanvasViews.remove(theView); } + + QxGraph_CanvasView* getCurrentView() const { return myCurrentView; } + void setCurrentView(QxGraph_CanvasView* theView) { myCurrentView = theView; } + void setCurrentView(int theIndex); + + protected: + void initView(QxGraph_ViewWindow* view); + + protected slots: + void onShowToolbar(); + void onChangeBgColor(); + + private: + QxGraph_Canvas* myCanvas; + //QPtrList myCanvases; + QPtrList myCanvasViews; + + QxGraph_CanvasView* myCurrentView; + +}; + +#endif diff --git a/src/QxGraph/QxGraph_ViewWindow.cxx b/src/QxGraph/QxGraph_ViewWindow.cxx new file mode 100644 index 000000000..1e64a8b06 --- /dev/null +++ b/src/QxGraph/QxGraph_ViewWindow.cxx @@ -0,0 +1,288 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "QxGraph_ViewWindow.h" +#include "QxGraph_Def.h" +#include "QxGraph_Canvas.h" +#include "QxGraph_CanvasView.h" + +#include +#include +#include + +//QT Include +#include +#include +//#include + +using namespace std; + +/*! + Constructor +*/ +QxGraph_ViewWindow::QxGraph_ViewWindow( SUIT_Desktop* theDesktop, QxGraph_Viewer* theModel) + : SUIT_ViewWindow( theDesktop ) +{ + printf("Construct QxGraph_ViewWindow\n"); + myViewModel = theModel; +} + +/*! + Initialization +*/ +void QxGraph_ViewWindow::initLayout() +{ + initCanvas(); + initCanvasViews(); + + myToolBar = new QToolBar(this); + myToolBar->setCloseMode(QDockWindow::Undocked); + myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + createActions(); + createToolBar(); +} + +/*! + Canvas initialization +*/ +void QxGraph_ViewWindow::initCanvas() +{ + if ( myViewModel ) + myViewModel->setCanvas( new QxGraph_Canvas(resMgr()) ); + //myViewModel->addCanvas( new QxGraph_Canvas(resMgr()) ); +} + +/*! + Canvas views initialization +*/ +void QxGraph_ViewWindow::initCanvasViews() +{ + if ( myViewModel ) + { + for (int i = 0; i < 2; i++) + { + //QxGraph_Canvas* aCanvas = new QxGraph_Canvas(resMgr()); + //myViewModel->addCanvas( aCanvas ); + + QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this ); + //QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( aCanvas, this ); + myViewModel->addView(aCanvasView); + + aCanvasView->hide(); + } + + // the first view is shown and is the current + myViewModel->getCanvasViews().first()->show(); + myViewModel->setCurrentView( myViewModel->getCanvasViews().first() ); + + /* test for 1 view --> + QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this ); + myViewModel->addView(aCanvasView); + myViewModel->setCurrentView(aCanvasView); + test for 1 view <-- */ + + setCentralWidget( myViewModel->getCurrentView() ); + + /*if ( inherits( "QMainWindow" ) ) { + printf("== > 1\n"); + ( ( QMainWindow* )this )->setCentralWidget( myViewModel->getCurrentView() ); + } + else { + printf("== > 2\n"); + QBoxLayout* layout = new QVBoxLayout( this ); + layout->addWidget( myViewModel->getCurrentView() ); + }*/ + } +} + +/*! + Creates actions of QxGraph view window +*/ +void QxGraph_ViewWindow::createActions() +{ + if (!myActionsMap.isEmpty()) return; + SUIT_ResourceMgr* aResMgr = resMgr(); + QtxAction* aAction; + + // FitAll + aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITALL" ) ), + tr( "MNU_FITALL" ), 0, this); + aAction->setStatusTip(tr("DSC_FITALL")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitAll())); + myActionsMap[ FitAllId ] = aAction; + + // FitRect + aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITAREA" ) ), + tr( "MNU_FITRECT" ), 0, this); + aAction->setStatusTip(tr("DSC_FITRECT")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitArea())); + myActionsMap[ FitRectId ] = aAction; + + // Zoom + aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_ZOOM" ) ), + tr( "MNU_ZOOM_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_ZOOM_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewZoom())); + myActionsMap[ ZoomId ] = aAction; + + // Panning + aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_PAN" ) ), + tr( "MNU_PAN_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_PAN_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewPan())); + myActionsMap[ PanId ] = aAction; + + // Global Panning + aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_GLOBALPAN" ) ), + tr( "MNU_GLOBALPAN_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewGlobalPan())); + myActionsMap[ GlobalPanId ] = aAction; + + // Reset + aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_RESET" ) ), + tr( "MNU_RESET_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_RESET_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewReset())); + myActionsMap[ ResetId ] = aAction; +} + +/*! + Creates toolbar of QxGraph view window +*/ +void QxGraph_ViewWindow::createToolBar() +{ + SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale"); + aScaleBtn->AddAction(myActionsMap[FitAllId]); + aScaleBtn->AddAction(myActionsMap[FitRectId]); + aScaleBtn->AddAction(myActionsMap[ZoomId]); + + SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan"); + aPanningBtn->AddAction(myActionsMap[PanId]); + aPanningBtn->AddAction(myActionsMap[GlobalPanId]); + + myActionsMap[ResetId]->addTo(myToolBar); +} + +/*! + Destructor +*/ +QxGraph_ViewWindow::~QxGraph_ViewWindow() {} + +/*! + Reset the active view +*/ +void QxGraph_ViewWindow::onViewReset() +{ + printf( "QxGraph_ViewWindow::onViewReset\n" ); + if ( myViewModel && myViewModel->getCurrentView() ) + myViewModel->getCurrentView()->activateReset(); +} + +/*! + Sets a new center of the active view +*/ +void QxGraph_ViewWindow::onViewGlobalPan() +{ + printf( "QxGraph_ViewWindow::onViewGlobalPan\n" ); + if ( myViewModel && myViewModel->getCurrentView() ) + myViewModel->getCurrentView()->activateGlobalPanning(); +} + +/*! + Zooms the active view +*/ +void QxGraph_ViewWindow::onViewZoom() +{ + printf( "QxGraph_ViewWindow::onViewZoom\n" ); + if ( myViewModel && myViewModel->getCurrentView() ) + myViewModel->getCurrentView()->activateZoom(); +} + +/*! + Moves the active view +*/ +void QxGraph_ViewWindow::onViewPan() +{ + printf( "QxGraph_ViewWindow::onViewPan\n" ); + if ( myViewModel && myViewModel->getCurrentView() ) + myViewModel->getCurrentView()->activatePanning(); +} + +/*! + Fits all obejcts within a rectangular area of the active view +*/ +void QxGraph_ViewWindow::onViewFitArea() +{ + printf( "QxGraph_ViewWindow::onViewFitArea\n" ); + if ( myViewModel && myViewModel->getCurrentView() ) + myViewModel->getCurrentView()->activateFitRect(); +} + +/*! + Fits all objects in the active view +*/ +void QxGraph_ViewWindow::onViewFitAll() +{ + printf( "QxGraph_ViewWindow::onViewFitAll\n" ); + if ( myViewModel && myViewModel->getCurrentView() ) + myViewModel->getCurrentView()->activateFitAll(); +} + +/*! + Set background of the viewport +*/ +void QxGraph_ViewWindow::setBackgroundColor( const QColor& color ) +{ + if ( myViewModel && myViewModel->getCurrentView()) { + myViewModel->getCurrentView()->canvas()->setBackgroundColor(color); + myViewModel->getCurrentView()->setPaletteBackgroundColor(color.light(120)); + } +} + +/*! + Returns background of the viewport +*/ +QColor QxGraph_ViewWindow::backgroundColor() const +{ + if ( myViewModel && myViewModel->getCurrentView()) + return myViewModel->getCurrentView()->canvas()->backgroundColor(); + return QColor(); +} + +/*! + Custom resize event handler +*/ +void QxGraph_ViewWindow::resizeEvent( QResizeEvent* theEvent ) +{ + // QMainWindow::resizeEvent( theEvent ); + //if ( myView ) myView->resizeView( theEvent ); +} + +/*! + Get resource manager +*/ +SUIT_ResourceMgr* QxGraph_ViewWindow::resMgr() const +{ + return SUIT_Session::session()->resourceMgr(); +} + diff --git a/src/QxGraph/QxGraph_ViewWindow.h b/src/QxGraph/QxGraph_ViewWindow.h new file mode 100644 index 000000000..88fe11bed --- /dev/null +++ b/src/QxGraph/QxGraph_ViewWindow.h @@ -0,0 +1,95 @@ +// SALOME QxGraph : build Supervisor viewer into desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef QXGRAPH_VIEWWINDOW_H +#define QXGRAPH_VIEWWINDOW_H + +#include "QxGraph.h" +#include "QxGraph_ViewModel.h" + +#include "SUIT_ViewWindow.h" + +#include "QtxAction.h" + +#include + +#ifdef WIN32 +#pragma warning ( disable:4251 ) +#endif + +class SUIT_ResourceMgr; + +class QXGRAPH_EXPORT QxGraph_ViewWindow : public SUIT_ViewWindow { + Q_OBJECT + + public: + QxGraph_ViewWindow(SUIT_Desktop* theDesktop, QxGraph_Viewer* theModel); + virtual ~QxGraph_ViewWindow(); + + void setBackgroundColor( const QColor& ); + QColor backgroundColor() const; + + QToolBar* getToolBar() { return myToolBar; } + + SUIT_ResourceMgr* resMgr() const; + + QxGraph_Viewer* getViewModel() const { return myViewModel; } + void setViewModel(QxGraph_Viewer* theViewModel) { myViewModel = theViewModel; } + + virtual void initLayout(); + + void contextPopupEvent(QContextMenuEvent* theEvent) { emit contextMenuRequested( theEvent); } + + public slots: + void onViewFitAll(); + void onViewFitArea(); + void onViewZoom(); + void onViewPan(); + void onViewGlobalPan(); + void onViewReset(); + + protected: + void resizeEvent( QResizeEvent* theEvent ); + + virtual void initCanvas(); + virtual void initCanvasViews(); + + private: + void createActions(); + void createToolBar(); + + //! Actions ID + enum { FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, ResetId }; + typedef QMap ActionsMap; + + ActionsMap myActionsMap; + QToolBar* myToolBar; + + QxGraph_Viewer* myViewModel; + +}; + +#ifdef WIN32 +#pragma warning ( default:4251 ) +#endif + +#endif diff --git a/src/QxGraph/resources/QxGraph_images.po b/src/QxGraph/resources/QxGraph_images.po new file mode 100644 index 000000000..3b59f6125 --- /dev/null +++ b/src/QxGraph/resources/QxGraph_images.po @@ -0,0 +1,42 @@ +// 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: QxGraph_images.po +// Created: 03/02/2007 +// Author: Margarita Karpunina +// Copyright (C) CEA 2007 + + +msgid "ICON_QXGRAPH_FITALL" +msgstr "view_fitall.png" + +msgid "ICON_QXGRAPH_FITAREA" +msgstr "view_fitarea.png" + +msgid "ICON_QXGRAPH_ZOOM" +msgstr "view_zoom.png" + +msgid "ICON_QXGRAPH_PAN" +msgstr "view_pan.png" + +msgid "ICON_QXGRAPH_GLOBALPAN" +msgstr "view_glpan.png" + +msgid "ICON_QXGRAPH_RESET" +msgstr "view_reset.png" + diff --git a/src/QxGraph/resources/QxGraph_msg_en.po b/src/QxGraph/resources/QxGraph_msg_en.po new file mode 100644 index 000000000..670735b24 --- /dev/null +++ b/src/QxGraph/resources/QxGraph_msg_en.po @@ -0,0 +1,40 @@ +// 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: QxGraph_msg_en.po +// Created: 03/02/2007 +// Author: Margarita Karpunina +// Copyright (C) CEA 2007 + +msgid "LBL_TOOLBAR_LABEL" +msgstr "View Operations" + +msgid "DSC_RESET_VIEW" +msgstr "Reset View Point" + +msgid "MNU_RESET_VIEW" +msgstr "Reset" + +msgid "DSC_PAN_VIEW" +msgstr "Panning the view" + +msgid "MNU_PAN_VIEW" +msgstr "Panning" + +msgid "MEN_CHANGE_BACKGROUND" +msgstr "Change background..." diff --git a/src/QxGraph/resources/view_fitall.png b/src/QxGraph/resources/view_fitall.png new file mode 100755 index 0000000000000000000000000000000000000000..c09ff94ad89b32483194de03275ece8844f985da GIT binary patch literal 523 zcmV+m0`&cfP)?PhR9q@fLZN1A`}f&DKuL#6x)fXr>83)#*`Z*DLNWx> zd|z|PU49gYeyKLzz5C?*-n~1GV)|F<_=+jVYW#P)ifeUwvJ$3M?|BI41;baV+C4ze+DhUx>sE#&ay0uli=5tOXJB{D>+os zPG2L#Hrow9Q?}fM{aIbH-4~bqZ$E<>xz@hl54Sx7r~Sb&L^0gNRz zG{hy9;RtH!{S%7=zT0gpVE|wuBsci%&gSzh zE{P0?$>*iRN2v;ihL$e@S@}&<077^hYA7y(Q(+3QD4a`?)?ctH{QyT@0vIgdd#3;Z N002ovPDHLkV1fY3?PhRGdP)2p#HH|33Q%C|O!E6r^~zZh;0?@J zRznD>ih9>Q3RZzetkEITfui?_;cyGVW%sH}v&R{K!#xzoF`uaimYT!$I%KZWv|ZOV z%EEO`wU76_ZgeP}98bo16C};iWJH(%0EV|iWA9{_QFuVB%Eu|IY4j11>$v5gQZa{F z1nKO)cew+pRat1-_G`=amaZ2LD=-vTU~nMovH&X!X&1l>OhyJU>9*7o;uP(oc08j7 z@B~b{?6zEE{;KY9uZ@(|O6evTZV1K(G6p=2X^jN^%3VgvOUhyMr#bycT8p3KYh^rF z;cLiWNLwBPI75B-nQDT{(??YMeDb}NwElus^$S4h`^wgq1%Utn002ovPDHLkV1kOB B=B@w$ literal 0 HcmV?d00001 diff --git a/src/QxGraph/resources/view_glpan.png b/src/QxGraph/resources/view_glpan.png new file mode 100755 index 0000000000000000000000000000000000000000..c23322a4ae4dc6ffdbbac6af7b397fc35554d750 GIT binary patch literal 540 zcmV+%0^|LOP)BjE6vuxTJUoGh6Qn~vN=>^&xI;}l#9IvgP$g6AE(vlcIgp?XHrJ&k{W1Y*5aB-VXic*jlIhC!B7St)|@M2Zv zKenaC)vQ4nzyL&q^HF@Ps8&pMw%bQCPY@B#UY!B(`pt01s9iyYa}JcEAyTRpnOsbG zdA^B<`wS6bur20$HUwG&k~y#jYc1f%#w&@a=HN(Zy|wwH6&}?Ajs&+1Z$#!H!3<5~&m3wL|-GpP>|d z`#Qsx*1O&z27j^3$vh!{%87IY{L3!mjRHSDRoU*ag!^Q@2sb?~ilTXUh^!Z3)6-D= e58(*eCY}K*P2#+!$#_8k00003|H!%haNC+54I`pq#B?&{{PlTD)QF{7N+1D|jfiZ7wH6!NZpvwvwzmPuKswJ; zRjzNwB=e-x0TN2v2K*3gTI*NWS&qw6+|`y{$-Z&L4j|dYO|Z+eb0_C^a$3TmSx%Q9U?o4 iu=O+)-;YPgn)Mr%Jmx0D9RHjE0000)L_t(|oUN3x zY8ycihQAG0%)u3FNMSunLOSCnA%&zW7U@hXk*9D-A1jsZCT1_y$q*wqMpeMCqQ;;t z4sHs;rdaNDj)}4f9yl0o=DwYOW^N6EC$(o!i~C1l;O}~pfh{aRSl%u}fbQw%nWP>X z!rjk1Uc7qA{Hj7#5fMhiF#z+c3dsZ!NdWdTLI7i;?@EU)EU(|bp}cgEfh}x$h1I-b zG#vBwbOylm;}lmq0GhfXmmDc1y@#sW`FnN`fTMR4M1;JEFv)~06$nvo2-66AAK#6J zW6JNY>tS+*lcNdMyyD{Q9Ak)m11`?aY3c^uL|?z zVhdGObfXKj>H7`u*6>9cu9K8pQ*Kx;eKMpbEayAmnZ z0ox(8azA}ONrv?8f#jR(1>SpB_bVXYD7oZFCjSQ%5u^|X3}|%w!?!z@V!r@)0Iy12 SiY3SZ0000P)R=vXa|KZLWj83QE`$^LZRkww0}TLmX=HfmqNPPq2N*whk_Xj$snY8 zUUSLanZyo0AYSg{$NTZzS(MUQb#Y!Ck$rN9RgpuQ&7K0LR35Y_KajzeZ%c~fn35!+ zWS{V~XL+grjmQ&lviz zrUWkmMZZx26Skmst4*RMsB_t&#p8naVLf;aiacwZf@lWrK%dKN2q9Ie-gS@sXFtVU zZG=b%3g1J9BU%VicCWhR%{~4`^iUK-WrPMyS_UwdVrYm{w9DF|VMn%Uf-$7!u&MEb!2y^*cm)hs zP^%%#DetTaV}N~#Mm7VmvRVhLRd%@w21A=K3xrpyc%8_&%Lse(z0s~!6HJZF=<I eF4Jm)Rp}3mY2qUGWh$%y0000 + @@ -106,6 +107,12 @@ +
+ + + + +
-- 2.39.2