1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-01 17:36:21 +03:00

0029402: In OCCT7.2.1-dev the names written into a FSD_File are associated with the wrong shapes.

The issue of incorrect Roots indexing is fixed by changing DataMap to IndexedDataMap.
Draw command fsdread was improved to allow restoring of shapes with kept names.
This commit is contained in:
szy 2017-12-27 17:28:54 +03:00 committed by apn
parent 44f2982356
commit 409095ba18
4 changed files with 118 additions and 29 deletions

View File

@ -155,12 +155,17 @@ static Standard_Integer DDocStd_fsdread(Draw_Interpretor& theDI,
theDI << "Usage : fsdread filename shape\n";
theDI << " Arguments:\n";
theDI << " filename : input file name\n";
theDI << " shape : name of an output shape,\n";
theDI << " root shapes will be put into a compound\n";
theDI << " in case of multiple roots in the file\n";
theDI << " shape : name of an output shape, or \n";
theDI << " reserved name = 'restore_with_names';\n";
theDI << " by default root shapes will be put into \n";
theDI << " a compound in case of multiple roots in the file;\n";
theDI << " if name = restore_with_names, the shapes will be put to\n";
theDI << " separate variables according kept names.\n";
return 1;
}
Standard_Boolean rflag(Standard_False);
if (strcmp(theArgs[2],"restore_with_names") == 0)
rflag = Standard_True;
Handle(StdStorage_Data) aData;
Storage_Error anError = StdStorage::Read(TCollection_AsciiString(theArgs[1]), aData);
if (anError != Storage_VSOk)
@ -186,7 +191,20 @@ static Standard_Integer DDocStd_fsdread(Draw_Interpretor& theDI,
if (aHShape) // shapes are expected
{
TopoDS_Shape aShape = aHShape->Import();
aShapes.Append(aShape);
if(rflag) {
if(!aRoot->Name().IsEmpty())
DBRep::Set(aRoot->Name().ToCString(), aShape);
else {
TCollection_AsciiString aNam("name_");
aNam += aRoot->Reference();
DBRep::Set(aNam.ToCString(), aShape);
}
#ifdef DEBUG_FSDREAD
Standard_Integer indx = aRoot->Reference();
theDI << "Ref indx = " <<indx << " Name = " << aRoot->Name().ToCString() << "\n";
#endif
} else
aShapes.Append(aShape);
}
}
}
@ -194,20 +212,21 @@ static Standard_Integer DDocStd_fsdread(Draw_Interpretor& theDI,
theDI << "Info : " << aTypeData->NumberOfTypes() << " type(s)\n";
theDI << " " << aRoots->Length() << " root(s)\n";
theDI << " " << aShapes.Length() << " shape(s) translated\n";
if (aShapes.Length() > 1)
{
BRep_Builder aB;
TopoDS_Compound aC;
aB.MakeCompound(aC);
for (Standard_Integer i = 1; i <= aShapes.Length(); ++i)
aB.Add(aC, aShapes.Value(i));
DBRep::Set(theArgs[2], aC);
if (!rflag) {
if (aShapes.Length() > 1)
{
theDI << " " << aShapes.Length() << " shape(s) translated\n";
BRep_Builder aB;
TopoDS_Compound aC;
aB.MakeCompound(aC);
for (Standard_Integer i = 1; i <= aShapes.Length(); ++i)
aB.Add(aC, aShapes.Value(i));
DBRep::Set(theArgs[2], aC);
}
else
DBRep::Set(theArgs[2], aShapes.First());
}
else
DBRep::Set(theArgs[2], aShapes.First());
return 0;
}
@ -229,7 +248,7 @@ void DDocStd::ShapeSchemaCommands(Draw_Interpretor& theCommands)
__FILE__, DDocStd_fsdwrite, g);
theCommands.Add("fsdread",
"fsdread filename shape",
"fsdread filename shape [name | or key 'restore_with_names']",
__FILE__, DDocStd_fsdread, g);
}

View File

@ -19,8 +19,9 @@
#include <StdStorage_Root.hxx>
#include <TCollection_AsciiString.hxx>
#include <NCollection_DataMap.hxx>
#include <NCollection_IndexedDataMap.hxx>
typedef NCollection_DataMap<TCollection_AsciiString, Handle(StdStorage_Root), TCollection_AsciiString> StdStorage_MapOfRoots;
typedef NCollection_DataMap<TCollection_AsciiString, Handle(StdStorage_Root), TCollection_AsciiString>::Iterator StdStorage_DataMapIteratorOfMapOfRoots;
typedef NCollection_IndexedDataMap<TCollection_AsciiString, Handle(StdStorage_Root), TCollection_AsciiString> StdStorage_MapOfRoots;
typedef NCollection_IndexedDataMap<TCollection_AsciiString, Handle(StdStorage_Root), TCollection_AsciiString>::Iterator StdStorage_DataMapIteratorOfMapOfRoots;
#endif // StdStorage_MapOfRoots_HeaderFile

View File

@ -66,7 +66,7 @@ Standard_Boolean StdStorage_RootData::Read(Storage_BaseDriver& theDriver)
}
Handle(StdStorage_Root) aRoot = new StdStorage_Root(aRootName, aRef, aTypeName);
myObjects.Bind(aRootName, aRoot);
myObjects.Add(aRootName, aRoot);
}
myErrorStatus = theDriver.EndReadRootSection();
@ -132,7 +132,7 @@ Standard_Integer StdStorage_RootData::NumberOfRoots() const
void StdStorage_RootData::AddRoot(const Handle(StdStorage_Root)& aRoot)
{
myObjects.Bind(aRoot->Name(), aRoot);
myObjects.Add(aRoot->Name(), aRoot);
aRoot->myRef = myObjects.Size();
}
@ -151,9 +151,8 @@ Handle(StdStorage_HSequenceOfRoots) StdStorage_RootData::Roots() const
Handle(StdStorage_Root) StdStorage_RootData::Find(const TCollection_AsciiString& aName) const
{
Handle(StdStorage_Root) p;
if (myObjects.IsBound(aName)) {
p = myObjects.Find(aName);
if (myObjects.Contains(aName)) {
p = myObjects.FindFromKey(aName);
}
return p;
@ -161,14 +160,14 @@ Handle(StdStorage_Root) StdStorage_RootData::Find(const TCollection_AsciiString&
Standard_Boolean StdStorage_RootData::IsRoot(const TCollection_AsciiString& aName) const
{
return myObjects.IsBound(aName);
return myObjects.Contains(aName);
}
void StdStorage_RootData::RemoveRoot(const TCollection_AsciiString& aName)
{
if (myObjects.IsBound(aName)) {
myObjects.ChangeFind(aName)->myRef = 0;
myObjects.UnBind(aName);
if (myObjects.Contains(aName)) {
myObjects.ChangeFromKey(aName)->myRef = 0;
myObjects.RemoveKey(aName);
Standard_Integer aRef = 1;
for (StdStorage_MapOfRoots::Iterator anIt(myObjects); anIt.More(); anIt.Next(), ++aRef)
anIt.ChangeValue()->myRef = aRef;

70
tests/persist/fsd/B2 Normal file
View File

@ -0,0 +1,70 @@
# check write / read set of shapes with names to FSD archive and reading its back
# create 7 shapes
box b1 10 20 30
box b2 100 0 0 20 30 40
box b3 200 0 0 30 40 50
box b4 300 0 0 40 50 60
box b5 400 0 0 50 60 70
box b6 500 0 0 60 70 80
box b7 600 0 0 70 80 90
# calculate mass of each shape and keep to 'wb%' variable
regexp {Mass +: +([-0-9.+eE]+)} [vprops b1] full wb1
regexp {Mass +: +([-0-9.+eE]+)} [vprops b2] full wb2
regexp {Mass +: +([-0-9.+eE]+)} [vprops b3] full wb3
regexp {Mass +: +([-0-9.+eE]+)} [vprops b4] full wb4
regexp {Mass +: +([-0-9.+eE]+)} [vprops b5] full wb5
regexp {Mass +: +([-0-9.+eE]+)} [vprops b6] full wb6
regexp {Mass +: +([-0-9.+eE]+)} [vprops b7] full wb7
# remove old file if exist
catch {file delete ${imagedir}/test29402.cmp}
# write set of shapes to the file
fsdwrite b1 b2 b3 b4 b5 b6 b7 ${imagedir}/test29402.cmp cmp
# unset variables
unset b1 b2 b3 b4 b5 b6 b7
# read back the file
fsdread ${imagedir}/test29402.cmp restore_with_names
# calculate mass of each shape and keep to 'rb%' variable
regexp {Mass +: +([-0-9.+eE]+)} [vprops b1] full rb1
regexp {Mass +: +([-0-9.+eE]+)} [vprops b2] full rb2
regexp {Mass +: +([-0-9.+eE]+)} [vprops b3] full rb3
regexp {Mass +: +([-0-9.+eE]+)} [vprops b4] full rb4
regexp {Mass +: +([-0-9.+eE]+)} [vprops b5] full rb5
regexp {Mass +: +([-0-9.+eE]+)} [vprops b6] full rb6
regexp {Mass +: +([-0-9.+eE]+)} [vprops b7] full rb7
# compare mass property of old and new shapes
set NumBad 0
if { $wb1 != $rb1 } {
puts " Faulty : incorrect shape $b1"; incr NumBad
}
if { $wb2 != $rb2 } {
puts " Faulty : incorrect shape $b2"; incr NumBad
}
if { $wb3 != $rb3 } {
puts " Faulty : incorrect shape $b3"; incr NumBad
}
if { $wb4 != $rb4 } {
puts " Faulty : incorrect shape $b4"; incr NumBad
}
if { $wb5 != $rb5 } {
puts " Faulty : incorrect shape $b5"; incr NumBad
}
if { $wb6 != $rb6 } {
puts " Faulty : incorrect shape $b6"; incr NumBad
}
if { $wb7 != $rb7 } {
puts " Faulty : incorrect shape $b7"; incr NumBad
}
if { $NumBad == 0} {
puts " BUG29402 OK : All shapes kept properly"
} else {
puts " Faulty : Found $NumBad bad shapes"
}