From: mpa Date: Thu, 11 Sep 2014 08:57:05 +0000 (+0400) Subject: 0021791: [CEA 623] Clipping : no difference between a closed shell and a solid. X-Git-Tag: V7_5_0a1~16^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1e79bc9837ed4bf66383139ae7d5b94f7ebd0259;p=modules%2Fgui.git 0021791: [CEA 623] Clipping : no difference between a closed shell and a solid. - added texture(hatch) for capping --- diff --git a/src/OCCViewer/CMakeLists.txt b/src/OCCViewer/CMakeLists.txt index e9627c893..c1476ed93 100755 --- a/src/OCCViewer/CMakeLists.txt +++ b/src/OCCViewer/CMakeLists.txt @@ -77,6 +77,7 @@ SET(_other_HEADERS OCCViewer_ClipPlane.h OCCViewer_Trihedron.h OCCViewer_VService.h + OCCViewer_Utilities.h ) # header files / no moc processing / internal @@ -90,6 +91,9 @@ SET(OCCViewer_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) # --- resources --- +# resource files / to be processed by rcc +SET(_rcc_RESOURCES OCCViewer.qrc) + # resource files / to be processed by lrelease SET(_ts_RESOURCES resources/OCCViewer_images.ts @@ -140,6 +144,9 @@ SET(_other_RESOURCES # sources / moc wrappings QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) +# sources / rcc wrappings +QT4_ADD_RESOURCES(_rcc_SOURCES ${_rcc_RESOURCES}) + # sources / static SET(_other_SOURCES OCCViewer_AISSelector.cxx @@ -162,10 +169,11 @@ SET(_other_SOURCES OCCViewer_ViewWindow.cxx OCCViewer_ViewportInputFilter.cxx OCCViewer_ClipPlaneInteractor.cxx + OCCViewer_Utilities.cxx ) # sources / to compile -SET(OCCViewer_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) +SET(OCCViewer_SOURCES ${_other_SOURCES} ${_moc_SOURCES} ${_rcc_SOURCES}) # --- rules --- diff --git a/src/OCCViewer/OCCViewer.qrc b/src/OCCViewer/OCCViewer.qrc new file mode 100644 index 000000000..cc4c1671d --- /dev/null +++ b/src/OCCViewer/OCCViewer.qrc @@ -0,0 +1,5 @@ + + + images/hatch.png + + diff --git a/src/OCCViewer/OCCViewer_Utilities.cxx b/src/OCCViewer/OCCViewer_Utilities.cxx new file mode 100755 index 000000000..4d8de5fbb --- /dev/null +++ b/src/OCCViewer/OCCViewer_Utilities.cxx @@ -0,0 +1,69 @@ +// 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" + +// KERNEL includes +#include + +// OCC Includes +#include + +// QT includes +#include + +/*! Concert QImage to OCCT pixmap*/ +Handle(Image_PixMap) +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; +} diff --git a/src/OCCViewer/OCCViewer_Utilities.h b/src/OCCViewer/OCCViewer_Utilities.h new file mode 100755 index 000000000..c745da015 --- /dev/null +++ b/src/OCCViewer/OCCViewer_Utilities.h @@ -0,0 +1,36 @@ +// 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 +// + +#ifndef OCCVIEWER_UTILITIES_H +#define OCCVIEWER_UTILITIES_H + +// internal includes +#include "OCCViewer.h" + +// OCC includes +#include + +class QImage; + +OCCVIEWER_EXPORT +extern +Handle(Image_PixMap) +imageToPixmap( const QImage& anImage ); + +#endif diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 7300cebec..5aff3c60d 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -26,6 +26,7 @@ #include "OCCViewer_VService.h" #include "OCCViewer_ViewPort3d.h" #include "OCCViewer_ClippingDlg.h" +#include "OCCViewer_Utilities.h" #include "SUIT_ViewWindow.h" #include "SUIT_ViewManager.h" @@ -54,6 +55,9 @@ #include #include +#include +#include + #include #include #include @@ -1039,6 +1043,19 @@ Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& theP 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() ); + 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; } /*! diff --git a/src/OCCViewer/images/hatch.png b/src/OCCViewer/images/hatch.png new file mode 100644 index 000000000..97232a79a Binary files /dev/null and b/src/OCCViewer/images/hatch.png differ