X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVTKViewer%2FVTKViewer_ViewModel.cxx;h=14f244025174060da08b9692d180eb7b09c24ec5;hb=0f9dfaa83b994c9d7fdd893f418395fad145f388;hp=b762a6a5e0e7119cfa13d965f0828cee2b0ca461;hpb=08209796122a4ed12a8bf21b4b2e3e54119e6f4b;p=modules%2Fgui.git diff --git a/src/VTKViewer/VTKViewer_ViewModel.cxx b/src/VTKViewer/VTKViewer_ViewModel.cxx index b762a6a5e..14f244025 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.cxx +++ b/src/VTKViewer/VTKViewer_ViewModel.cxx @@ -1,22 +1,58 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// 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 "VTKViewer_ViewModel.h" #include "VTKViewer_ViewWindow.h" #include "VTKViewer_ViewManager.h" #include "VTKViewer_RenderWindowInteractor.h" +#include "QtxBackgroundTool.h" #include "SUIT_ViewWindow.h" #include "SUIT_Desktop.h" #include "SUIT_Session.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include + +// VSR: Uncomment below line to allow texture background support in VTK viewer +#define VTK_ENABLE_TEXTURED_BACKGROUND + +bool _InitializeVtkWarningsCall() +{ + char* isOn = getenv( "VTK_WARNINGS_IS_ON" ); + if ( !isOn || strcmp( isOn, "1" ) ) + vtkObject::GlobalWarningDisplayOff(); + + delete isOn; + return vtkObject::GetGlobalWarningDisplay(); +} +static bool _InitializeVtkWarnings = _InitializeVtkWarningsCall(); /*!Constructor.Sets background color to black.*/ VTKViewer_Viewer::VTKViewer_Viewer() : SUIT_ViewModel(), -myBgColor( Qt::black ) + myDefaultBackground( Qtx::BackgroundData( Qt::black ) ) { } @@ -25,24 +61,62 @@ VTKViewer_Viewer::~VTKViewer_Viewer() { } -/*!Gets background color.*/ +/*! Get data for supported background modes: gradient types, identifiers and supported image formats */ +QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList ) +{ + gradList << tr( "GT_HORIZONTALGRADIENT" ) + << tr( "GT_VERTICALGRADIENT" ) + << tr( "GT_FIRSTDIAGONALGRADIENT" ) + << tr( "GT_SECONDDIAGONALGRADIENT" ) + << tr( "GT_FIRSTCORNERGRADIENT" ) + << tr( "GT_SECONDCORNERGRADIENT" ) + << tr( "GT_THIRDCORNERGRADIENT" ) + << tr( "GT_FOURTHCORNERGRADIENT" ); + idList << HorizontalGradient + << VerticalGradient + << FirstDiagonalGradient + << SecondDiagonalGradient + << FirstCornerGradient + << SecondCornerGradient + << ThirdCornerGradient + << FourthCornerGradient; +#ifdef VTK_ENABLE_TEXTURED_BACKGROUND + txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture; +#endif + return tr("BG_IMAGE_FILES"); +} + +/*!Gets background color [obsolete]*/ QColor VTKViewer_Viewer::backgroundColor() const { - return myBgColor; + return background().color(); } -/*!Sets background color.*/ +/*!Sets background color [obsolete]*/ void VTKViewer_Viewer::setBackgroundColor( const QColor& c ) { - if ( c.isValid() ) - myBgColor = c; + Qtx::BackgroundData bg = background(); + bg.setColor( c ); + setBackground( bg ); +} + +/*!Gets default background data.*/ +Qtx::BackgroundData VTKViewer_Viewer::background() const +{ + return myDefaultBackground; +} + +/*!Sets default background data.*/ +void VTKViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground ) +{ + myDefaultBackground = theBackground.isValid() ? theBackground : Qtx::BackgroundData( Qt::black ); } /*!Create new instance of VTKViewer_ViewWindow, sets background color and return pointer to it.*/ SUIT_ViewWindow* VTKViewer_Viewer::createView( SUIT_Desktop* theDesktop ) { VTKViewer_ViewWindow* vw = new VTKViewer_ViewWindow( theDesktop, this ); - vw->setBackgroundColor( myBgColor ); + vw->setBackground( myDefaultBackground ); return vw; } @@ -61,16 +135,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_BACKGROUND" ), this, SLOT( onChangeBackground() ) ); - 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.*/ @@ -82,14 +156,14 @@ void VTKViewer_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) if ( !rwi ) return; - switch(event->button()) { - case LeftButton: + switch(event->buttons()) { + 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: @@ -116,14 +190,14 @@ void VTKViewer_Viewer::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) if ( !rwi ) return; - switch(event->button()) { - case LeftButton: + switch(event->buttons()) { + 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: @@ -154,15 +228,32 @@ void VTKViewer_Viewer::onDumpView() } /*!On change back ground color event.*/ -void VTKViewer_Viewer::onChangeBgColor() +void VTKViewer_Viewer::onChangeBackground() { VTKViewer_ViewWindow* aView = (VTKViewer_ViewWindow*)(myViewManager->getActiveView()); if ( !aView ) return; - QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView); - if ( aColor.isValid() ) - aView->setBackgroundColor(aColor); + // get supported gradient types + QStringList gradList; + QIntList idList, txtList; + QString formats = backgroundData( gradList, idList, txtList ); + + // invoke dialog box + Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background + aView, // parent for dialog box + txtList, // allowed texture modes + true, // enable solid color mode + true, // enable gradient mode + false, // disable custom gradient mode + !txtList.isEmpty(), // enable texture mode + gradList, // gradient names + idList, // gradient identifiers + formats ); // image formats + + // set chosen background data to the viewer + if ( bgData.isValid() ) + aView->setBackground( bgData ); } /*!On show tool bar event.*/