]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
0021791: [CEA 623] Clipping : no difference between a closed shell and a solid.
authormpa <mpa@opencascade.com>
Thu, 11 Sep 2014 08:57:05 +0000 (12:57 +0400)
committermpa <mpa@opencascade.com>
Thu, 11 Sep 2014 08:57:05 +0000 (12:57 +0400)
- added texture(hatch) for capping

src/OCCViewer/CMakeLists.txt
src/OCCViewer/OCCViewer.qrc [new file with mode: 0644]
src/OCCViewer/OCCViewer_Utilities.cxx [new file with mode: 0755]
src/OCCViewer/OCCViewer_Utilities.h [new file with mode: 0755]
src/OCCViewer/OCCViewer_ViewModel.cxx
src/OCCViewer/images/hatch.png [new file with mode: 0644]

index e9627c89329a577c2af0dfdbbff650c5413f8183..c1476ed9344a350a97a94b7269c072720e59e276 100755 (executable)
@@ -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 (file)
index 0000000..cc4c167
--- /dev/null
@@ -0,0 +1,5 @@
+ <!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+     <file>images/hatch.png</file>
+ </qresource>
+ </RCC>
diff --git a/src/OCCViewer/OCCViewer_Utilities.cxx b/src/OCCViewer/OCCViewer_Utilities.cxx
new file mode 100755 (executable)
index 0000000..4d8de5f
--- /dev/null
@@ -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 <Basics_OCCTVersion.hxx>
+
+// OCC Includes
+#include <Image_PixMap.hxx>
+
+// QT includes
+#include <QImage>
+
+/*! 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<Image_ColorBGRA>(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<Image_ColorBGRA>().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 (executable)
index 0000000..c745da0
--- /dev/null
@@ -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 <Image_PixMap_Handle.hxx>
+
+class QImage;
+
+OCCVIEWER_EXPORT
+extern
+Handle(Image_PixMap)
+imageToPixmap( const QImage& anImage );
+
+#endif
index 7300cebec3245d5d38278e8949824f8fd9bf127b..5aff3c60d3670f3b23dda84fc6ed71c5e09f0b49 100755 (executable)
@@ -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 <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <Graphic3d_TextureParams.hxx>
+
 #include <Geom_Axis2Placement.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_DatumAspect.hxx>
@@ -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 (file)
index 0000000..97232a7
Binary files /dev/null and b/src/OCCViewer/images/hatch.png differ