From ddb5823aecb55f4e1378512da6ced4282e0dec44 Mon Sep 17 00:00:00 2001 From: mkr Date: Wed, 30 May 2007 06:54:54 +0000 Subject: [PATCH] Porting to Qt4. --- src/Makefile.am | 2 +- src/VTKViewer/VTKViewer.pro | 78 +++++++++++++++++++ src/VTKViewer/VTKViewer_InteractorStyle.cxx | 48 ++++++++---- src/VTKViewer/VTKViewer_InteractorStyle.h | 10 ++- src/VTKViewer/VTKViewer_RenderWindow.cxx | 15 ++-- src/VTKViewer/VTKViewer_RenderWindow.h | 2 +- .../VTKViewer_RenderWindowInteractor.cxx | 35 +++++---- .../VTKViewer_RenderWindowInteractor.h | 8 +- src/VTKViewer/VTKViewer_ViewModel.cxx | 31 ++++---- src/VTKViewer/VTKViewer_ViewModel.h | 6 +- src/VTKViewer/VTKViewer_ViewWindow.cxx | 16 ++-- src/src.pro | 1 + 12 files changed, 182 insertions(+), 70 deletions(-) create mode 100644 src/VTKViewer/VTKViewer.pro diff --git a/src/Makefile.am b/src/Makefile.am index 687fde263..3c72ce588 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -44,7 +44,7 @@ if ENABLE_VTKVIEWER # VSR: this is the original packages list # SUBDIRS += VTKViewer # VSR: already migrated to Qt4 packages - SUBDIRS += + SUBDIRS += VTKViewer if ENABLE_SALOMEOBJECT # VSR: this is the original packages list # SUBDIRS += SVTK diff --git a/src/VTKViewer/VTKViewer.pro b/src/VTKViewer/VTKViewer.pro new file mode 100644 index 000000000..7070bacee --- /dev/null +++ b/src/VTKViewer/VTKViewer.pro @@ -0,0 +1,78 @@ +TEMPLATE = lib +TARGET = VTKViewer +DESTDIR = ../../lib +MOC_DIR = ../../moc +OBJECTS_DIR = ../../obj/$$TARGET + +VTKHOME = $$(VTKHOME) +VTK_INCLUDES = $${VTKHOME}/include/vtk + +VTK_LIBS = -L$${VTKHOME}/lib/vtk -L$${VTKHOME}/lib/vtk/python -lvtkCommon -lvtkGraphics -lvtkImaging -lvtkFiltering -lvtkIO -lvtkRendering -lvtkHybrid -lvtkParallel -lvtkWidgets -lGL -L/usr/X11R6/lib -lGLU -L/usr/X11R6/lib -lX11 -lXt + +CASROOT = $$(CASROOT) +CAS_CPPFLAGS = $${CASROOT}/inc + +CAS_KERNEL = -L$${CASROOT}/Linux/lib -lTKernel + +INCLUDEPATH += ../../include $${VTK_INCLUDES} $${CAS_CPPFLAGS} ../Qtx ../SUIT +LIBS += -L../../lib -lqtx -lsuit $${VTK_LIBS} $${CAS_KERNEL} + +CONFIG -= debug release debug_and_release +CONFIG += qt thread debug dll shared + +win32:DEFINES += WIN32 +DEFINES += VTKVIEWER_EXPORTS OCC_VERSION_MAJOR=6 OCC_VERSION_MINOR=1 OCC_VERSION_MAINTENANCE=1 LIN LINTEL CSFDB No_exception HAVE_CONFIG_H HAVE_LIMITS_H HAVE_WOK_CONFIG_H OCC_CONVERT_SIGNALS + +HEADERS = VTKViewer.h +HEADERS += VTKViewer_CellLocationsArray.h +HEADERS += VTKViewer_Actor.h +HEADERS += VTKViewer_ExtractUnstructuredGrid.h +HEADERS += VTKViewer_ConvexTool.h +HEADERS += VTKViewer_Filter.h +HEADERS += VTKViewer_GeometryFilter.h +HEADERS += VTKViewer_AppendFilter.h +HEADERS += VTKViewer_Algorithm.h +HEADERS += VTKViewer_InteractorStyle.h +HEADERS += VTKViewer_RenderWindow.h +HEADERS += VTKViewer_RenderWindowInteractor.h +HEADERS += VTKViewer_ShrinkFilter.h +HEADERS += VTKViewer_TransformFilter.h +HEADERS += VTKViewer_Transform.h +HEADERS += VTKViewer_Trihedron.h +HEADERS += VTKViewer_Utilities.h +HEADERS += VTKViewer_ViewManager.h +HEADERS += VTKViewer_ViewModel.h +HEADERS += VTKViewer_ViewWindow.h +HEADERS += VTKViewer_Functor.h + +SOURCES = VTKViewer_CellLocationsArray.cxx +SOURCES += VTKViewer_Actor.cxx +SOURCES += VTKViewer_ExtractUnstructuredGrid.cxx +SOURCES += VTKViewer_Filter.cxx +SOURCES += VTKViewer_GeometryFilter.cxx +SOURCES += VTKViewer_AppendFilter.cxx +SOURCES += VTKViewer_InteractorStyle.cxx +SOURCES += VTKViewer_RenderWindow.cxx +SOURCES += VTKViewer_RenderWindowInteractor.cxx +SOURCES += VTKViewer_ShrinkFilter.cxx +SOURCES += VTKViewer_Transform.cxx +SOURCES += VTKViewer_TransformFilter.cxx +SOURCES += VTKViewer_Trihedron.cxx +SOURCES += VTKViewer_Utilities.cxx +SOURCES += VTKViewer_ViewManager.cxx +SOURCES += VTKViewer_ViewModel.cxx +SOURCES += VTKViewer_ConvexTool.cxx +SOURCES += VTKViewer_ViewWindow.cxx + +TRANSLATIONS = resources/VTKViewer_images.ts \ + resources/VTKViewer_msg_en.ts + +ICONS = resources/*.png + +includes.files = $$HEADERS +includes.path = ../../include + +resources.files = $$ICONS resources/*.qm +resources.path = ../../resources + +INSTALLS += includes resources diff --git a/src/VTKViewer/VTKViewer_InteractorStyle.cxx b/src/VTKViewer/VTKViewer_InteractorStyle.cxx index 04a02f180..8e7e64b3b 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyle.cxx +++ b/src/VTKViewer/VTKViewer_InteractorStyle.cxx @@ -50,8 +50,8 @@ #include #include -#include -#include +#include +#include #include @@ -100,6 +100,8 @@ VTKViewer_InteractorStyle::VTKViewer_InteractorStyle() myPreSelectionActor->GetProperty()->SetLineWidth(5); myPreSelectionActor->GetProperty()->SetPointSize(5); + myRectBand = 0; + OnSelectionModeChanged(); } @@ -108,6 +110,7 @@ VTKViewer_InteractorStyle::VTKViewer_InteractorStyle() VTKViewer_InteractorStyle::~VTKViewer_InteractorStyle() { m_ViewWnd->RemoveActor(myPreSelectionActor); + endDrawRect(); } @@ -519,13 +522,13 @@ const char* imageRotateCursor[] = { /*! Loads cursors for viewer operations - zoom, pan, etc...*/ void VTKViewer_InteractorStyle::loadCursors() { - myDefCursor = QCursor(ArrowCursor); - myHandCursor = QCursor(PointingHandCursor); - myPanCursor = QCursor(SizeAllCursor); + myDefCursor = QCursor(Qt::ArrowCursor); + myHandCursor = QCursor(Qt::PointingHandCursor); + myPanCursor = QCursor(Qt::SizeAllCursor); myZoomCursor = QCursor(QPixmap(imageZoomCursor)); myRotateCursor = QCursor(QPixmap(imageRotateCursor)); mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!! - myGlobalPanCursor = QCursor(CrossCursor); + myGlobalPanCursor = QCursor(Qt::CrossCursor); myCursorState = false; } @@ -773,6 +776,28 @@ void VTKViewer_InteractorStyle::setCursor(const int operation) } } +/*! + Draws rectangle by starting and current points +*/ +void VTKViewer_InteractorStyle::drawRect() +{ + if ( !myRectBand ) + myRectBand = new QRubberBand( QRubberBand::Rectangle, myGUIWindow ); + myRectBand->hide(); + + QRect aRect(myPoint, myOtherPoint); + myRectBand->setGeometry( aRect ); + myRectBand->setVisible( aRect.isValid() ); +} + +/*! + \brief Delete rubber band on the end on the dragging operation. +*/ +void VTKViewer_InteractorStyle::endDrawRect() +{ + delete myRectBand; + myRectBand = 0; +} /*! called when viewer operation started (!put necessary initialization here!)*/ void VTKViewer_InteractorStyle::onStartOperation() @@ -784,10 +809,7 @@ void VTKViewer_InteractorStyle::onStartOperation() case VTK_INTERACTOR_STYLE_CAMERA_SELECT: case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(myGUIWindow); - p.setPen(Qt::lightGray); - p.setRasterOp(Qt::XorROP); - p.drawRect(QRect(myPoint, myOtherPoint)); + drawRect(); break; } case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: @@ -1160,12 +1182,8 @@ void VTKViewer_InteractorStyle::onOperation(QPoint mousePos) } case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(myGUIWindow); - p.setPen(Qt::lightGray); - p.setRasterOp(Qt::XorROP); - p.drawRect(QRect(myPoint, myOtherPoint)); myOtherPoint = mousePos; - p.drawRect(QRect(myPoint, myOtherPoint)); + drawRect(); break; } } diff --git a/src/VTKViewer/VTKViewer_InteractorStyle.h b/src/VTKViewer/VTKViewer_InteractorStyle.h index b867f64b3..baaa4988a 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyle.h +++ b/src/VTKViewer/VTKViewer_InteractorStyle.h @@ -33,8 +33,10 @@ class vtkCell; class vtkRenderWindowInteractor; -#include -#include +#include +#include + +class QRubberBand; #include @@ -159,6 +161,8 @@ class VTKVIEWER_EXPORT VTKViewer_InteractorStyle : public QObject, public vtkInt virtual void onCursorMove(QPoint mousePos); virtual void setCursor(const int operation); + void drawRect(); + void endDrawRect(); protected: QCursor myDefCursor; @@ -181,6 +185,8 @@ class VTKVIEWER_EXPORT VTKViewer_InteractorStyle : public QObject, public vtkInt std::map myFilters; + QRubberBand* myRectBand; //!< selection rectangle rubber band + /** @name members from old version*/ //@{ double DeltaElevation; diff --git a/src/VTKViewer/VTKViewer_RenderWindow.cxx b/src/VTKViewer/VTKViewer_RenderWindow.cxx index 0ca9f7be7..a0d7e7195 100755 --- a/src/VTKViewer/VTKViewer_RenderWindow.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindow.cxx @@ -18,9 +18,9 @@ // #include "VTKViewer_RenderWindow.h" -#include -#include -#include +#include +#include +#include #include #include @@ -40,13 +40,14 @@ *\param name - render window name. */ VTKViewer_RenderWindow::VTKViewer_RenderWindow(QWidget* parent, const char* name) : -QWidget(parent, name, - Qt::WStyle_NoBorder | Qt::WDestructiveClose | - Qt::WResizeNoErase | Qt::WRepaintNoErase) +QWidget(parent, Qt::FramelessWindowHint ) { + setObjectName( name ); + setAttribute( Qt::WA_DeleteOnClose ); + myRW = vtkRenderWindow::New(); #ifndef WIN32 - myRW->SetDisplayId((void*)x11Display()); + myRW->SetDisplayId((void*)(QX11Info::display())); #endif myRW->SetWindowId((void*)winId()); myRW->DoubleBufferOn(); diff --git a/src/VTKViewer/VTKViewer_RenderWindow.h b/src/VTKViewer/VTKViewer_RenderWindow.h index e85b1c549..6ce1b4309 100755 --- a/src/VTKViewer/VTKViewer_RenderWindow.h +++ b/src/VTKViewer/VTKViewer_RenderWindow.h @@ -23,7 +23,7 @@ #include -#include +#include class VTKVIEWER_EXPORT VTKViewer_RenderWindow : public QWidget { diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx index 9445c5b15..261ba9c37 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx @@ -54,7 +54,10 @@ #include // QT Includes -#include +#include +#include +#include +#include /*! Create new instance of VTKViewer_RenderWindowInteractor*/ VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() @@ -324,7 +327,8 @@ int VTKViewer_RenderWindowInteractor::CreateTimer(int vtkNotUsed(timertype)) /// /// Start a one-shot timer for 10ms. /// - mTimer->start(10, TRUE) ; + mTimer->setSingleShot(TRUE) ; + mTimer->start(10) ; return 1 ; } @@ -383,8 +387,8 @@ void VTKViewer_RenderWindowInteractor::LeftButtonPressed(const QMouseEvent *even if( ! this->Enabled ) { return ; } - myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton), - (event->state() & ShiftButton), + myInteractorStyle->OnLeftButtonDown((event->modifiers() & Qt::ControlModifier), + (event->modifiers() & Qt::ShiftModifier), event->x(), event->y()); } @@ -396,8 +400,8 @@ void VTKViewer_RenderWindowInteractor::LeftButtonReleased(const QMouseEvent *eve if( ! this->Enabled ) { return ; } - myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), + myInteractorStyle->OnLeftButtonUp( (event->modifiers() & Qt::ControlModifier), + (event->modifiers() & Qt::ShiftModifier), event->x(), event->y() ) ; } @@ -409,8 +413,8 @@ void VTKViewer_RenderWindowInteractor::MiddleButtonPressed(const QMouseEvent *ev if( ! this->Enabled ) { return ; } - myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton), - (event->state() & ShiftButton), + myInteractorStyle->OnMiddleButtonDown((event->modifiers() & Qt::ControlModifier), + (event->modifiers() & Qt::ShiftModifier), event->x(), event->y() ) ; } @@ -422,8 +426,8 @@ void VTKViewer_RenderWindowInteractor::MiddleButtonReleased(const QMouseEvent *e if( ! this->Enabled ) { return ; } - myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), + myInteractorStyle->OnMiddleButtonUp( (event->modifiers() & Qt::ControlModifier), + (event->modifiers() & Qt::ShiftModifier), event->x(), event->y() ) ; } @@ -435,8 +439,8 @@ void VTKViewer_RenderWindowInteractor::RightButtonPressed(const QMouseEvent *eve if( ! this->Enabled ) { return ; } - myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton), - (event->state() & ShiftButton), + myInteractorStyle->OnRightButtonDown( (event->modifiers() & Qt::ControlModifier), + (event->modifiers() & Qt::ShiftModifier), event->x(), event->y() ) ; } @@ -449,14 +453,13 @@ void VTKViewer_RenderWindowInteractor::RightButtonReleased(const QMouseEvent *ev return ; } bool isOperation = myInteractorStyle->CurrentState() != VTK_INTERACTOR_STYLE_CAMERA_NONE; - myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), + myInteractorStyle->OnRightButtonUp( (event->modifiers() & Qt::ControlModifier), + (event->modifiers() & Qt::ShiftModifier), event->x(), event->y() ); if ( !isOperation ) { QContextMenuEvent aEvent( QContextMenuEvent::Mouse, - event->pos(), event->globalPos(), - event->state() ); + event->pos(), event->globalPos() ); emit contextMenuRequested( &aEvent ); } } diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.h b/src/VTKViewer/VTKViewer_RenderWindowInteractor.h index 435e5b4b8..22fb37307 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.h +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.h @@ -22,8 +22,12 @@ #include "VTKViewer.h" #include "VTKViewer_Actor.h" -#include -#include +#include + +class QTimer; +class QMouseEvent; +class QKeyEvent; +class QContextMenuEvent; // Open CASCADE Includes #include diff --git a/src/VTKViewer/VTKViewer_ViewModel.cxx b/src/VTKViewer/VTKViewer_ViewModel.cxx index f611972ae..1c6715863 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.cxx +++ b/src/VTKViewer/VTKViewer_ViewModel.cxx @@ -25,11 +25,10 @@ #include "SUIT_Desktop.h" #include "SUIT_Session.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include bool _InitializeVtkWarningsCall() { @@ -90,16 +89,16 @@ void VTKViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager) } /*!Insert context into popup menu.*/ -void VTKViewer_Viewer::contextMenuPopup(QPopupMenu* thePopup) +void VTKViewer_Viewer::contextMenuPopup(QMenu* thePopup) { - thePopup->insertItem( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); - thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) ); + thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); + thePopup->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) ); - thePopup->insertSeparator(); + thePopup->addSeparator(); VTKViewer_ViewWindow* aView = (VTKViewer_ViewWindow*)(myViewManager->getActiveView()); if ( aView && !aView->getToolBar()->isVisible() ) - thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); + thePopup->addAction( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); } /*!On mouse press event.*/ @@ -112,13 +111,13 @@ void VTKViewer_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) return; switch(event->button()) { - case LeftButton: + case Qt::LeftButton: rwi->LeftButtonPressed(event) ; break ; - case MidButton: + case Qt::MidButton: rwi->MiddleButtonPressed(event) ; break ; - case RightButton: + case Qt::RightButton: rwi->RightButtonPressed(event) ; break; default: @@ -146,13 +145,13 @@ void VTKViewer_Viewer::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) return; switch(event->button()) { - case LeftButton: + case Qt::LeftButton: rwi->LeftButtonReleased(event) ; break ; - case MidButton: + case Qt::MidButton: rwi->MiddleButtonReleased(event) ; break ; - case RightButton: + case Qt::RightButton: rwi->RightButtonReleased(event) ; break; default: diff --git a/src/VTKViewer/VTKViewer_ViewModel.h b/src/VTKViewer/VTKViewer_ViewModel.h index 06cab857f..460c58fc2 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.h +++ b/src/VTKViewer/VTKViewer_ViewModel.h @@ -22,7 +22,9 @@ #include "VTKViewer.h" #include "SUIT_ViewModel.h" -#include +#include + +class QMouseEvent; class SUIT_ViewWindow; class SUIT_Desktop; @@ -41,7 +43,7 @@ public: virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); virtual void setViewManager(SUIT_ViewManager* theViewManager); - virtual void contextMenuPopup( QPopupMenu* ); + virtual void contextMenuPopup( QMenu* ); /*!Gets type of viewer.*/ virtual QString getType() const { return Type(); } diff --git a/src/VTKViewer/VTKViewer_ViewWindow.cxx b/src/VTKViewer/VTKViewer_ViewWindow.cxx index 0e1ab38bb..51e65e284 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.cxx +++ b/src/VTKViewer/VTKViewer_ViewWindow.cxx @@ -32,8 +32,8 @@ #include "SUIT_Tools.h" #include "SUIT_ResourceMgr.h" -#include -#include +#include +#include #include #include @@ -55,7 +55,7 @@ VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop, myRenderWindow = new VTKViewer_RenderWindow( this, "RenderWindow" ); setCentralWidget(myRenderWindow); - myRenderWindow->setFocusPolicy( StrongFocus ); + myRenderWindow->setFocusPolicy( Qt::StrongFocus ); myRenderWindow->setFocus(); myRenderWindow->getRenderWindow()->AddRenderer( myRenderer ); @@ -89,8 +89,8 @@ VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop, setCentralWidget( myRenderWindow ); myToolBar = new QToolBar(this); - myToolBar->setCloseMode(QDockWindow::Undocked); - myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + //myToolBar->setCloseMode(QDockWindow::Undocked); + myToolBar->setWindowTitle(tr("LBL_TOOLBAR_LABEL")); createActions(); createToolBar(); @@ -414,7 +414,7 @@ QColor VTKViewer_ViewWindow::backgroundColor() const myRenderer->GetBackground( backint ); return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)); } - return SUIT_ViewWindow::backgroundColor(); + return palette().color( backgroundRole() );//SUIT_ViewWindow::backgroundColor(); } /*!Repaint window. If \a theUpdateTrihedron is true - recalculate trihedron.*/ @@ -557,7 +557,7 @@ void VTKViewer_ViewWindow::onTrihedronShow() QImage VTKViewer_ViewWindow::dumpView() { QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() ); - return px.convertToImage(); + return px.toImage(); } /*! The method returns the visual parameters of this view as a formated string @@ -584,7 +584,7 @@ QString VTKViewer_ViewWindow::getVisualParameters() */ void VTKViewer_ViewWindow::setVisualParameters( const QString& parameters ) { - QStringList paramsLst = QStringList::split( '*', parameters, true ); + QStringList paramsLst = parameters.split( '*' ); if ( paramsLst.size() == 13 ) { double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; pos[0] = paramsLst[0].toDouble(); diff --git a/src/src.pro b/src/src.pro index a610dcbcc..3ef5689f0 100644 --- a/src/src.pro +++ b/src/src.pro @@ -14,6 +14,7 @@ SUBDIRS += PyInterp SUBDIRS += PyConsole SUBDIRS += Prs SUBDIRS += OBJECT +SUBDIRS += VTKViewer SUBDIRS += OCCViewer SUBDIRS += Event -- 2.39.2