From: vsr Date: Mon, 6 Oct 2014 11:27:00 +0000 (+0400) Subject: Merge branch 'asl/hydro_porting_741' X-Git-Tag: V7_5_0a1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=541d3637fed062228c2ae0b2224ea698a3114cc5;p=modules%2Fgui.git Merge branch 'asl/hydro_porting_741' --- 541d3637fed062228c2ae0b2224ea698a3114cc5 diff --cc src/OCCViewer/OCCViewer_Utilities.cxx index 4d8de5fbb,a90891852..5b9a8797d mode 100755,100644..100755 --- a/src/OCCViewer/OCCViewer_Utilities.cxx +++ b/src/OCCViewer/OCCViewer_Utilities.cxx @@@ -1,69 -1,67 +1,130 @@@ +// Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 +// +// internal includes #include "OCCViewer_Utilities.h" + #include "OCCViewer_ViewFrame.h" + #include "OCCViewer_ViewModel.h" + #include "OCCViewer_ViewPort3d.h" + + #include "SUIT_ViewManager.h" + #include "QtxActionToolMgr.h" -#include ++#include "QtxMultiAction.h" + +// KERNEL includes +#include + - // OCC Includes - #include ++// OCC includes + #include +// QT includes +#include + #include - /*! Concert QImage to OCCT pixmap*/ - Handle(Image_PixMap) - imageToPixmap( const QImage& anImage ) ++Handle(Image_PixMap) OCCViewer_Utilities::imageToPixmap( const QImage& anImage ) +{ + Handle(Image_PixMap) aPixmap = new Image_PixMap(); + if ( !anImage.isNull() ) { + aPixmap->InitTrash( Image_PixMap::ImgBGRA, anImage.width(), anImage.height() ); + aPixmap->SetTopDown( Standard_True ); + + const uchar* aImageBytes = anImage.bits(); + + for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) { +#if OCC_VERSION_LARGE > 0x06070100 + // convert pixels from ARGB to renderer-compatible RGBA + for ( int aByte = 0; aByte < anImage.width(); ++aByte ) { + Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue(aLine, aByte); + + aPixmapBytes.b() = (Standard_Byte) *aImageBytes++; + aPixmapBytes.g() = (Standard_Byte) *aImageBytes++; + aPixmapBytes.r() = (Standard_Byte) *aImageBytes++; + aPixmapBytes.a() = (Standard_Byte) *aImageBytes++; + } +#else + Image_ColorBGRA* aPixmapBytes = aPixmap->EditData().ChangeRow(aLine); + + // convert pixels from ARGB to renderer-compatible RGBA + for ( int aByte = 0; aByte < anImage.width(); ++aByte ) { + aPixmapBytes->b() = (Standard_Byte) *aImageBytes++; + aPixmapBytes->g() = (Standard_Byte) *aImageBytes++; + aPixmapBytes->r() = (Standard_Byte) *aImageBytes++; + aPixmapBytes->a() = (Standard_Byte) *aImageBytes++; + aPixmapBytes++; + } +#endif + } + } + return aPixmap; +} ++ + void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer, + const OCCViewer_ViewWindow::Mode2dType& theMode ) + { + OCCViewer_ViewFrame* aFrame = dynamic_cast + ( theViewer->getViewManager()->getActiveView() ); + OCCViewer_ViewWindow* aView = aFrame ? aFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW ) : 0; + if ( !aView ) + return; + + // set a view mode + aView->set2dMode( theMode ); + bool is2dMode = theMode != OCCViewer_ViewWindow::No2dMode; + + // enable/disable view actions + QList aNo2dActions; + aNo2dActions << OCCViewer_ViewWindow::ChangeRotationPointId + << OCCViewer_ViewWindow::RotationId + << OCCViewer_ViewWindow::FrontId + << OCCViewer_ViewWindow::BackId + //<< OCCViewer_ViewWindow::TopId + << OCCViewer_ViewWindow::BottomId + << OCCViewer_ViewWindow::LeftId + << OCCViewer_ViewWindow::RightId + << OCCViewer_ViewWindow::AntiClockWiseId + << OCCViewer_ViewWindow::ClockWiseId + << OCCViewer_ViewWindow::ResetId; + + QtxActionToolMgr* aToolMgr = aView->toolMgr(); + QAction* anAction; + for ( int i = 0, aNb = aNo2dActions.size(); i < aNb; i++ ) { + anAction = aToolMgr->action( aNo2dActions[i] ); + if ( anAction ) + anAction->setEnabled( !is2dMode ); + } + QAction* aTop = aToolMgr->action( OCCViewer_ViewWindow::TopId ); + QtxMultiAction* aMulti = dynamic_cast( aTop->parent() ); + aMulti->setActiveAction( aTop ); + + // change view position + Handle(V3d_View) aView3d = aView->getViewPort()->getView(); + if ( !aView3d.IsNull() ) { + switch ( theMode ) { + case OCCViewer_ViewWindow::XYPlane: + aView3d->SetProj (V3d_Zpos); + break; + case OCCViewer_ViewWindow::XZPlane: + aView3d->SetProj (V3d_Yneg); + break; + case OCCViewer_ViewWindow::YZPlane: + aView3d->SetProj (V3d_Xpos); + break; + } + } + } diff --cc src/OCCViewer/OCCViewer_Utilities.h index c745da015,8460f3cc1..1cbbacf24 mode 100755,100644..100755 --- a/src/OCCViewer/OCCViewer_Utilities.h +++ b/src/OCCViewer/OCCViewer_Utilities.h @@@ -20,17 -1,27 +20,39 @@@ #ifndef OCCVIEWER_UTILITIES_H #define OCCVIEWER_UTILITIES_H +// internal includes #include "OCCViewer.h" + #include "OCCViewer_ViewWindow.h" +// OCC includes - #include ++#include + +class QImage; + class OCCViewer_Viewer; - OCCVIEWER_EXPORT - extern - Handle(Image_PixMap) - imageToPixmap( const QImage& anImage ); - + #ifdef WIN32 + #pragma warning ( disable:4251 ) #endif + + class OCCVIEWER_EXPORT OCCViewer_Utilities + { + public: + ++ /*! ++ * Convert Qt image to OCCT pixmap ++ * \param theImage Qt source image ++ * \return resulting OCCT pixmap ++ */ ++ static Handle(Image_PixMap) imageToPixmap( const QImage& theImage ); ++ + /*! + * Set 2D mode for the viewer. Hide or show 3D actions. + * \param theViewer an OCC viewer + * \param theMode OCC view window mode + */ + static void setViewer2DMode( OCCViewer_Viewer* theViewer, + const OCCViewer_ViewWindow::Mode2dType& theMode ); + + }; + -#endif ++#endif // OCCVIEWER_UTILITIES_H diff --cc src/OCCViewer/OCCViewer_ViewModel.cxx index e55694dc8,366d3bb0c..64e558564 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@@ -1003,29 -1031,7 +1003,29 @@@ void OCCViewer_Viewer::setSelectionOpti } } - +/*! + Creates clipping plane based on the incoming plane +*/ +Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn) +{ + Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( thePlane ); + aGraphic3dPlane->SetOn( theIsOn ); + aGraphic3dPlane->SetCapping( Standard_True ); + + // load capping texture + QPixmap px( ":images/hatch.png" ); + if( !px.isNull() ) { - const Handle(Image_PixMap) aPixmap = imageToPixmap( px.toImage() ); ++ const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() ); + Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap ); + if( aTexture->IsDone() ) { + aTexture->EnableModulate(); + aTexture->EnableRepeat(); + aTexture->GetParams()->SetScale( Graphic3d_Vec2( 0.01, 0.01 ) ); + aGraphic3dPlane->SetCappingTexture( aTexture ); + } + } + return aGraphic3dPlane; +} /*! Applies clipping planes to clippable objects */