mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-29 14:00:49 +03:00
0033183: Data Exchange - Lose texture after saving XBF file
Texture reading and writing changed in VisMaterial drivers
This commit is contained in:
@@ -126,23 +126,68 @@ static void readColor (const BinObjMgt_Persistent& theSource,
|
|||||||
static void writeTexture (BinObjMgt_Persistent& theTarget,
|
static void writeTexture (BinObjMgt_Persistent& theTarget,
|
||||||
const Handle(Image_Texture)& theImage)
|
const Handle(Image_Texture)& theImage)
|
||||||
{
|
{
|
||||||
theTarget.PutAsciiString (!theImage.IsNull()
|
if (theImage.IsNull())
|
||||||
&& !theImage->FilePath().IsEmpty()
|
{
|
||||||
&& theImage->FileOffset() == -1
|
theTarget.PutAsciiString("");
|
||||||
? theImage->FilePath()
|
return;
|
||||||
: "");
|
}
|
||||||
|
if (theImage->DataBuffer().IsNull())
|
||||||
|
{
|
||||||
|
theTarget.PutAsciiString(theImage->FilePath());
|
||||||
|
theTarget.PutBoolean(false);
|
||||||
|
if (theImage->FileOffset() == -1 || theImage->FileLength() == -1)
|
||||||
|
{
|
||||||
|
theTarget.PutBoolean(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
theTarget.PutBoolean(false);
|
||||||
|
theTarget.PutInteger(static_cast<int>(theImage->FileOffset()));
|
||||||
|
theTarget.PutInteger(static_cast<int>(theImage->FileLength()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
theTarget.PutAsciiString(theImage->TextureId());
|
||||||
|
theTarget.PutBoolean(true);
|
||||||
|
theTarget.PutInteger(static_cast<int>(theImage->DataBuffer()->Size()));
|
||||||
|
theTarget.PutByteArray((Standard_Byte*)theImage->DataBuffer()->Data(),
|
||||||
|
static_cast<int>(theImage->DataBuffer()->Size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Decode texture path.
|
//! Decode texture path.
|
||||||
static void readTexture (const BinObjMgt_Persistent& theSource,
|
static void readTexture (const BinObjMgt_Persistent& theSource,
|
||||||
Handle(Image_Texture)& theTexture)
|
Handle(Image_Texture)& theTexture)
|
||||||
{
|
{
|
||||||
TCollection_AsciiString aPath;
|
TCollection_AsciiString aStr;
|
||||||
theSource.GetAsciiString (aPath);
|
theSource.GetAsciiString(aStr);
|
||||||
if (!aPath.IsEmpty())
|
if (aStr.IsEmpty())
|
||||||
{
|
{
|
||||||
theTexture = new Image_Texture (aPath);
|
return;
|
||||||
}
|
}
|
||||||
|
Standard_Boolean anUseBuffer;
|
||||||
|
if (!theSource.GetBoolean(anUseBuffer).IsOK())
|
||||||
|
{
|
||||||
|
theTexture = new Image_Texture(aStr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Standard_Integer anOffset = -1, aLength = -1;
|
||||||
|
if (!anUseBuffer)
|
||||||
|
{
|
||||||
|
Standard_Boolean isOnlyFilePath;
|
||||||
|
theSource.GetBoolean(isOnlyFilePath);
|
||||||
|
if (isOnlyFilePath)
|
||||||
|
{
|
||||||
|
theTexture = new Image_Texture(aStr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
theSource.GetInteger(anOffset);
|
||||||
|
theSource.GetInteger(aLength);
|
||||||
|
theTexture = new Image_Texture(aStr, anOffset, aLength);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
theSource.GetInteger(aLength);
|
||||||
|
Handle(NCollection_Buffer) aBuff =
|
||||||
|
new NCollection_Buffer(NCollection_BaseAllocator::CommonBaseAllocator(), aLength);
|
||||||
|
theSource.GetByteArray(aBuff->ChangeData(), aLength);
|
||||||
|
theTexture = new Image_Texture(aBuff, aStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
@@ -13,9 +13,11 @@
|
|||||||
|
|
||||||
#include <XmlMXCAFDoc_VisMaterialDriver.hxx>
|
#include <XmlMXCAFDoc_VisMaterialDriver.hxx>
|
||||||
|
|
||||||
|
#include <Message.hxx>
|
||||||
#include <Message_Messenger.hxx>
|
#include <Message_Messenger.hxx>
|
||||||
#include <XCAFDoc_VisMaterial.hxx>
|
#include <XCAFDoc_VisMaterial.hxx>
|
||||||
#include <XmlObjMgt.hxx>
|
#include <XmlObjMgt.hxx>
|
||||||
|
#include <XmlObjMgt_Document.hxx>
|
||||||
#include <XmlObjMgt_Persistent.hxx>
|
#include <XmlObjMgt_Persistent.hxx>
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_VisMaterialDriver, XmlMDF_ADriver)
|
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_VisMaterialDriver, XmlMDF_ADriver)
|
||||||
@@ -42,6 +44,10 @@ IMPLEMENT_DOMSTRING(EmissiveColor, "emissive_color")
|
|||||||
IMPLEMENT_DOMSTRING(Shininess, "shininess")
|
IMPLEMENT_DOMSTRING(Shininess, "shininess")
|
||||||
IMPLEMENT_DOMSTRING(Transparency, "transparency")
|
IMPLEMENT_DOMSTRING(Transparency, "transparency")
|
||||||
IMPLEMENT_DOMSTRING(DiffuseTexture, "diffuse_texture")
|
IMPLEMENT_DOMSTRING(DiffuseTexture, "diffuse_texture")
|
||||||
|
IMPLEMENT_DOMSTRING(FilePath, "file_path")
|
||||||
|
IMPLEMENT_DOMSTRING(TextureId, "texture_id")
|
||||||
|
IMPLEMENT_DOMSTRING(Offset, "offset")
|
||||||
|
IMPLEMENT_DOMSTRING(Length, "length")
|
||||||
|
|
||||||
//! Encode alpha mode into character.
|
//! Encode alpha mode into character.
|
||||||
static const char* alphaModeToString (Graphic3d_AlphaMode theMode)
|
static const char* alphaModeToString (Graphic3d_AlphaMode theMode)
|
||||||
@@ -202,11 +208,26 @@ static void writeTexture (XmlObjMgt_Persistent& theTarget,
|
|||||||
const XmlObjMgt_DOMString& theName,
|
const XmlObjMgt_DOMString& theName,
|
||||||
const Handle(Image_Texture)& theImage)
|
const Handle(Image_Texture)& theImage)
|
||||||
{
|
{
|
||||||
if (!theImage.IsNull()
|
if (theImage.IsNull())
|
||||||
&& !theImage->FilePath().IsEmpty()
|
|
||||||
&& theImage->FileOffset() == -1)
|
|
||||||
{
|
{
|
||||||
theTarget.Element().setAttribute (theName, theImage->FilePath().ToCString());
|
return;
|
||||||
|
}
|
||||||
|
XmlObjMgt_Document aDoc(theTarget.Element().getOwnerDocument());
|
||||||
|
XmlObjMgt_Element aCurTarget = aDoc.createElement(theName);
|
||||||
|
theTarget.Element().appendChild(aCurTarget);
|
||||||
|
if (theImage->DataBuffer().IsNull())
|
||||||
|
{
|
||||||
|
aCurTarget.setAttribute(::FilePath(), theImage->FilePath().ToCString());
|
||||||
|
if (theImage->FileOffset() == -1 || theImage->FileLength() == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
aCurTarget.setAttribute(::Offset(), static_cast<int>(theImage->FileOffset()));
|
||||||
|
aCurTarget.setAttribute(::Length(), static_cast<int>(theImage->FileLength()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Message::SendWarning(TCollection_AsciiString("Can't write a texture to buffer."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,10 +236,34 @@ static void readTexture (const XmlObjMgt_Element& theElement,
|
|||||||
const XmlObjMgt_DOMString& theName,
|
const XmlObjMgt_DOMString& theName,
|
||||||
Handle(Image_Texture)& theImage)
|
Handle(Image_Texture)& theImage)
|
||||||
{
|
{
|
||||||
TCollection_AsciiString aPath (theElement.getAttribute (theName).GetString());
|
TCollection_AsciiString aStr(theElement.getAttribute(theName).GetString());
|
||||||
if (!aPath.IsEmpty())
|
if (!aStr.IsEmpty())
|
||||||
{
|
{
|
||||||
theImage = new Image_Texture (aPath);
|
theImage = new Image_Texture(aStr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LDOM_Element anElement = theElement.GetChildByTagName(theName);
|
||||||
|
if (anElement.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TCollection_AsciiString aFilePath(anElement.getAttribute(::FilePath()).GetString());
|
||||||
|
TCollection_AsciiString anId(anElement.getAttribute(::TextureId()).GetString());
|
||||||
|
Standard_Integer anOffset = -1, aLength = -1;
|
||||||
|
if (!aFilePath.IsEmpty())
|
||||||
|
{
|
||||||
|
anElement.getAttribute(::Offset()).GetInteger(anOffset);
|
||||||
|
anElement.getAttribute(::Length()).GetInteger(aLength);
|
||||||
|
if (anOffset == -1 || aLength == -1)
|
||||||
|
{
|
||||||
|
theImage = new Image_Texture(aFilePath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
theImage = new Image_Texture(aFilePath, anOffset, aLength);
|
||||||
|
}
|
||||||
|
else if (!anId.IsEmpty())
|
||||||
|
{
|
||||||
|
Message::SendWarning(TCollection_AsciiString("Can't read a texture from buffer."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
pload XDE
|
pload XDE OCAF VISUALISATION
|
||||||
|
|
||||||
set subgroup xde
|
set subgroup xde
|
||||||
|
21
tests/bugs/xde/bug33183_1
Normal file
21
tests/bugs/xde/bug33183_1
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "0033183: Data Exchange - Lose texture after saving XBF file"
|
||||||
|
puts "Checking saving of textures for the previous version"
|
||||||
|
puts "========"
|
||||||
|
|
||||||
|
Close D -silent
|
||||||
|
XOpen [locate_data_file bug33183_ship_boat.xbf] D
|
||||||
|
set data [XGetVisMaterial D 0:1:10:3]
|
||||||
|
|
||||||
|
if {[string first "Common.DiffuseTexture" $data] == -1} {
|
||||||
|
puts "Error: Texture is not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
vinit View1
|
||||||
|
XDisplay -dispMode 1 D
|
||||||
|
vfit
|
||||||
|
if { [vreadpixel 130 300 rgb name] != "ROSYBROWN" } { puts "Error: color not match" }
|
||||||
|
if { [vreadpixel 150 250 rgb name] != "ORANGE2" } { puts "Error: color not match" }
|
||||||
|
if { [vreadpixel 250 250 rgb name] != "GRAY43" } { puts "Error: color not match" }
|
||||||
|
|
||||||
|
Close D
|
21
tests/bugs/xde/bug33183_2
Normal file
21
tests/bugs/xde/bug33183_2
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "0033183: Data Exchange - Lose texture after saving XBF file"
|
||||||
|
puts "Checking saving of textures for the previous version"
|
||||||
|
puts "========"
|
||||||
|
|
||||||
|
Close D -silent
|
||||||
|
XOpen [locate_data_file bug33183_ship_boat.xml] D
|
||||||
|
set data [XGetVisMaterial D 0:1:10:3]
|
||||||
|
|
||||||
|
if {[string first "Common.DiffuseTexture" $data] == -1} {
|
||||||
|
puts "Error: Texture is not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
vinit View1
|
||||||
|
XDisplay -dispMode 1 D
|
||||||
|
vfit
|
||||||
|
if { [vreadpixel 130 300 rgb name] != "ROSYBROWN" } { puts "Error: color not match" }
|
||||||
|
if { [vreadpixel 150 250 rgb name] != "ORANGE2" } { puts "Error: color not match" }
|
||||||
|
if { [vreadpixel 250 250 rgb name] != "GRAY43" } { puts "Error: color not match" }
|
||||||
|
|
||||||
|
Close D
|
Reference in New Issue
Block a user