Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Framework - Invalid document after partial read of XBF #201

Draft
wants to merge 1 commit into
base: IR
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <TDF_Attribute.hxx>
#include <TDF_Data.hxx>
#include <TDF_Label.hxx>
#include <TDF_Tool.hxx>
#include <TDocStd_Document.hxx>
#include <TDocStd_FormatVersion.hxx>
#include <TDocStd_Owner.hxx>
Expand Down Expand Up @@ -322,13 +323,22 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
myPAtt.SetIStream (theIStream); // for reading shapes data from the stream directly
EnableQuickPartReading (myMsgDriver, aQuickPart);

myResolvedLinks.Clear();
myUnresolvedLinks.Clear();

// read sub-tree of the root label
if (!theFilter.IsNull())
theFilter->StartIteration();
const auto aStreamStartPosition = theIStream.tellg();
Standard_Integer nbRead = ReadSubTree (theIStream, aData->Root(), theFilter, aQuickPart, Standard_False, aPS.Next());
if (!myUnresolvedLinks.IsEmpty())
while (!myUnresolvedLinks.IsEmpty())
{
if (!aPS.More())
{
myReaderStatus = PCDM_RS_UserBreak;
return;
}

// In case we have skipped some linked TreeNodes before getting to
// their children.
theFilter->StartIteration();
Expand Down Expand Up @@ -497,10 +507,17 @@ Standard_Integer BinLDrivers_DocumentRetrievalDriver::ReadSubTree
theLabel.AddAttribute(tAtt);
}
}
else
else if (theLabel != tAtt->Label())
{
TCollection_AsciiString aLabelEntry1, aLabelEntry2;
TDF_Tool::Entry (tAtt->Label(), aLabelEntry1);
TDF_Tool::Entry (theLabel, aLabelEntry2);

myMsgDriver->Send(aMethStr +
"warning: attempt to attach attribute " +
aDriver->TypeName() + " to a second label", Message_Warning);
aDriver->TypeName() + " to a second label " + "(" +
aLabelEntry1 + " => " + aLabelEntry2 + ")", Message_Warning);
}

Standard_Boolean ok = aDriver->Paste(myPAtt, tAtt, myRelocTable);
if (!ok) {
Expand All @@ -511,12 +528,16 @@ Standard_Integer BinLDrivers_DocumentRetrievalDriver::ReadSubTree
else if (!isBound)
{
myRelocTable.Bind(anID, tAtt);
Handle(TDataStd_TreeNode) aNode = Handle(TDataStd_TreeNode)::DownCast(tAtt);
if (!theFilter.IsNull() && !aNode.IsNull() && !aNode->Father().IsNull() && aNode->Father()->IsNew())
}

Handle(TDataStd_TreeNode) aNode = Handle(TDataStd_TreeNode)::DownCast(tAtt);
if (!theFilter.IsNull() && !aNode.IsNull() && !aNode->Father().IsNull() && aNode->Father()->IsNew())
{
Standard_Integer anUnresolvedLink;
myPAtt.SetPosition(BP_HEADSIZE);
myPAtt >> anUnresolvedLink;
if (myResolvedLinks.Add (myPAtt.Id()))
{
Standard_Integer anUnresolvedLink;
myPAtt.SetPosition(BP_HEADSIZE);
myPAtt >> anUnresolvedLink;
myUnresolvedLinks.Add(anUnresolvedLink);
}
}
Expand Down Expand Up @@ -650,6 +671,7 @@ void BinLDrivers_DocumentRetrievalDriver::Clear()
myPAtt.Destroy(); // free buffer
myRelocTable.Clear();
myMapUnsupported.Clear();
myResolvedLinks.Clear();
}

//=======================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private:
TColStd_MapOfInteger myMapUnsupported;
BinLDrivers_VectorOfDocumentSection mySections;
NCollection_Map<Standard_Integer> myUnresolvedLinks;

NCollection_Map<Standard_Integer> myResolvedLinks;

};

Expand Down
Loading