From: vsr Date: Thu, 17 Apr 2014 12:25:34 +0000 (+0400) Subject: 0052388: TC7.4.0:Texture is not correct by default X-Git-Tag: V7_4_0rc1~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e1689b866889baeb386e33cbebf9cd283942c1dc;p=modules%2Fgeom.git 0052388: TC7.4.0:Texture is not correct by default --- diff --git a/src/GEOMGUI/CMakeLists.txt b/src/GEOMGUI/CMakeLists.txt index b4005537f..c5dc25f8a 100755 --- a/src/GEOMGUI/CMakeLists.txt +++ b/src/GEOMGUI/CMakeLists.txt @@ -87,11 +87,27 @@ SET(_moc_HEADERS GeometryGUI.h ) +# --- resources --- + +# resource files / to be processed by rcc +SET(_rcc_RESOURCES GEOMGUI.qrc) + +# resource files / to be processed by lrelease +SET(_ts_RESOURCES + GEOM_images.ts + GEOM_msg_en.ts + GEOM_msg_fr.ts + GEOM_msg_ja.ts +) + # --- sources --- # sources / moc wrappings QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) +# sources / rcc wrappings +QT4_ADD_RESOURCES(_rcc_SOURCES ${_rcc_RESOURCES}) + SET(GEOMGUI_SOURCES GeometryGUI.cxx GEOMGUI.cxx @@ -103,18 +119,9 @@ SET(GEOMGUI_SOURCES GEOMGUI_CreationInfoWdg.cxx GEOMGUI_DimensionProperty.cxx ${_moc_SOURCES} + ${_rcc_SOURCES} ) -# --- resources --- - -# resource files / to be processed by lrelease -SET(GEOMGUI_RESOURCES - GEOM_images.ts - GEOM_msg_en.ts - GEOM_msg_fr.ts - GEOM_msg_ja.ts -) - # --- rules --- ADD_LIBRARY(GEOM ${GEOMGUI_SOURCES}) @@ -122,4 +129,4 @@ TARGET_LINK_LIBRARIES(GEOM ${_link_LIBRARIES}) INSTALL(TARGETS GEOM EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) INSTALL(FILES ${GEOMGUI_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) -QT4_INSTALL_TS_RESOURCES("${GEOMGUI_RESOURCES}" "${SALOME_GEOM_INSTALL_RES_DATA}") +QT4_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${SALOME_GEOM_INSTALL_RES_DATA}") diff --git a/src/GEOMGUI/GEOMGUI.qrc b/src/GEOMGUI/GEOMGUI.qrc new file mode 100644 index 000000000..43311c3ae --- /dev/null +++ b/src/GEOMGUI/GEOMGUI.qrc @@ -0,0 +1,5 @@ + + + images/default_texture.png + + diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 16131193c..098436963 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -158,6 +158,50 @@ namespace return aMap; } + //=========================================================================== + // Function : imageToPixmap + // Purpose : Concert QImage to OCCT pixmap + //=========================================================================== + static inline 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 ) { + 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++; + } + } + } + return aPixmap; + } + + //=========================================================================== + // Function : getDefaultTexture + // Purpose : Get default texture + //=========================================================================== + static inline Handle(Image_PixMap) getDefaultTexture() + { + static Handle(Image_PixMap) aPixmap; + if ( aPixmap.IsNull() ) { + QPixmap px(":images/default_texture.png"); + if ( !px.isNull() ) + aPixmap = imageToPixmap( px.toImage() ); + } + return aPixmap; + } + //=========================================================================== // Function : cacheTextureFor // Purpose : Load and cache image for the specified presentation. @@ -187,24 +231,7 @@ namespace if ( anImage.isNull() ) return NULL; - aPixmap = new Image_PixMap(); - 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 ) { - 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++; - } - } + aPixmap = imageToPixmap( anImage ); aPixmapCacheMap.insert( thePath, aPixmap ); @@ -866,7 +893,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) ); study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 ); - // Update porpeties map + // Update propeties map propMap = getObjectProperties( study, entry, myViewFrame ); } } @@ -875,26 +902,29 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString(); } - if ( !aImagePath.isEmpty() ) { #if OCC_VERSION_LARGE > 0x06070000 - Handle(Image_PixMap) aPixmap = cacheTextureFor( aImagePath, AISShape ); + Handle(Image_PixMap) aPixmap; + if ( !aImagePath.isEmpty() ) + aPixmap = cacheTextureFor( aImagePath, AISShape ); + else + aPixmap = getDefaultTexture(); - // apply image to shape - if ( !aPixmap.IsNull() ) { - AISShape->SetTexturePixMap( aPixmap ); - AISShape->SetTextureMapOn(); - AISShape->DisableTextureModulate(); - } - else - AISShape->SetTextureMapOff(); + // apply image to shape + if ( !aPixmap.IsNull() ) { + AISShape->SetTexturePixMap( aPixmap ); + AISShape->SetTextureMapOn(); + AISShape->DisableTextureModulate(); + } + else { + AISShape->SetTextureMapOff(); + } #else + if ( !aImagePath.isEmpty() ) { AISShape->SetTextureFileName( TCollection_AsciiString( aImagePath.toUtf8().constData() ) ); AISShape->SetTextureMapOn(); AISShape->DisableTextureModulate(); -#endif } - else - AISShape->SetTextureMapOff(); +#endif // set line width AISShape->SetWidth( HasWidth() ? diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 8327f4869..fab29f562 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -224,6 +224,8 @@ GeometryGUI::GeometryGUI() : myCreationInfoWdg = 0; connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ) ); + + Q_INIT_RESOURCE( GEOMGUI ); } //======================================================================= @@ -2488,11 +2490,13 @@ void GeometryGUI::createPreferences() aModesList.append( tr("MEN_WIREFRAME") ); aModesList.append( tr("MEN_SHADING") ); aModesList.append( tr("MEN_SHADING_WITH_EDGES") ); + aModesList.append( tr("MEN_TEXTURE") ); QList anIndexesList; anIndexesList.append(0); anIndexesList.append(1); anIndexesList.append(2); + anIndexesList.append(3); setPreferenceProperty( dispmode, "strings", aModesList ); setPreferenceProperty( dispmode, "indexes", anIndexesList ); diff --git a/src/GEOMGUI/images/default_texture.png b/src/GEOMGUI/images/default_texture.png new file mode 100755 index 000000000..b1caf0466 Binary files /dev/null and b/src/GEOMGUI/images/default_texture.png differ