0052388: TC7.4.0:Texture is not correct by default

This commit is contained in:
vsr 2014-04-17 16:25:34 +04:00
parent df08a82ac5
commit e1689b8668
5 changed files with 89 additions and 43 deletions

View File

@ -87,11 +87,27 @@ SET(_moc_HEADERS
GeometryGUI.h 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 ---
# sources / moc wrappings # sources / moc wrappings
QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS})
# sources / rcc wrappings
QT4_ADD_RESOURCES(_rcc_SOURCES ${_rcc_RESOURCES})
SET(GEOMGUI_SOURCES SET(GEOMGUI_SOURCES
GeometryGUI.cxx GeometryGUI.cxx
GEOMGUI.cxx GEOMGUI.cxx
@ -103,18 +119,9 @@ SET(GEOMGUI_SOURCES
GEOMGUI_CreationInfoWdg.cxx GEOMGUI_CreationInfoWdg.cxx
GEOMGUI_DimensionProperty.cxx GEOMGUI_DimensionProperty.cxx
${_moc_SOURCES} ${_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 --- # --- rules ---
ADD_LIBRARY(GEOM ${GEOMGUI_SOURCES}) 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(TARGETS GEOM EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
INSTALL(FILES ${GEOMGUI_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) 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}")

5
src/GEOMGUI/GEOMGUI.qrc Normal file
View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/default_texture.png</file>
</qresource>
</RCC>

View File

@ -158,6 +158,50 @@ namespace
return aMap; 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<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++;
}
}
}
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 // Function : cacheTextureFor
// Purpose : Load and cache image for the specified presentation. // Purpose : Load and cache image for the specified presentation.
@ -187,24 +231,7 @@ namespace
if ( anImage.isNull() ) if ( anImage.isNull() )
return NULL; return NULL;
aPixmap = new Image_PixMap(); aPixmap = imageToPixmap( anImage );
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<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++;
}
}
aPixmapCacheMap.insert( thePath, aPixmap ); 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::Texture ), QString( GetTexture().c_str() ) );
study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 ); study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
// Update porpeties map // Update propeties map
propMap = getObjectProperties( study, entry, myViewFrame ); 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(); aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
} }
if ( !aImagePath.isEmpty() ) {
#if OCC_VERSION_LARGE > 0x06070000 #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 // apply image to shape
if ( !aPixmap.IsNull() ) { if ( !aPixmap.IsNull() ) {
AISShape->SetTexturePixMap( aPixmap ); AISShape->SetTexturePixMap( aPixmap );
AISShape->SetTextureMapOn(); AISShape->SetTextureMapOn();
AISShape->DisableTextureModulate(); AISShape->DisableTextureModulate();
} }
else else {
AISShape->SetTextureMapOff(); AISShape->SetTextureMapOff();
}
#else #else
if ( !aImagePath.isEmpty() ) {
AISShape->SetTextureFileName( TCollection_AsciiString( aImagePath.toUtf8().constData() ) ); AISShape->SetTextureFileName( TCollection_AsciiString( aImagePath.toUtf8().constData() ) );
AISShape->SetTextureMapOn(); AISShape->SetTextureMapOn();
AISShape->DisableTextureModulate(); AISShape->DisableTextureModulate();
#endif
} }
else #endif
AISShape->SetTextureMapOff();
// set line width // set line width
AISShape->SetWidth( HasWidth() ? AISShape->SetWidth( HasWidth() ?

View File

@ -224,6 +224,8 @@ GeometryGUI::GeometryGUI() :
myCreationInfoWdg = 0; myCreationInfoWdg = 0;
connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ) ); 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_WIREFRAME") );
aModesList.append( tr("MEN_SHADING") ); aModesList.append( tr("MEN_SHADING") );
aModesList.append( tr("MEN_SHADING_WITH_EDGES") ); aModesList.append( tr("MEN_SHADING_WITH_EDGES") );
aModesList.append( tr("MEN_TEXTURE") );
QList<QVariant> anIndexesList; QList<QVariant> anIndexesList;
anIndexesList.append(0); anIndexesList.append(0);
anIndexesList.append(1); anIndexesList.append(1);
anIndexesList.append(2); anIndexesList.append(2);
anIndexesList.append(3);
setPreferenceProperty( dispmode, "strings", aModesList ); setPreferenceProperty( dispmode, "strings", aModesList );
setPreferenceProperty( dispmode, "indexes", anIndexesList ); setPreferenceProperty( dispmode, "indexes", anIndexesList );

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB