1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-02 17:46:22 +03:00

0029403: Data Exchange - subshapes names are not imported from step

Fix processing of subshape names in STEP in reading and writing.
Replace creating subshapes in Document as tree (invalid) with plain subshapes structure.
Update test cases.
This commit is contained in:
ika 2017-12-26 13:46:08 +03:00 committed by apn
parent 62a672fb35
commit 44f2982356
5 changed files with 111 additions and 50 deletions

View File

@ -306,16 +306,6 @@ TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
}
#endif
//=======================================================================
//function : AllocateSubLabel
//purpose :
//=======================================================================
static TDF_Label AllocateSubLabel(TDF_Label& theRoot)
{
return TDF_TagSource::NewChild(theRoot);
}
//=======================================================================
//function : STEPCAFControl_Reader
//purpose :
@ -4354,7 +4344,7 @@ Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSes
//=======================================================================
TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem,
TDF_Label& theLab,
const TDF_Label& theLab,
const Handle(XCAFDoc_ShapeTool)& theShapeTool,
const Handle(Transfer_TransientProcess)& TP) const
{
@ -4373,7 +4363,9 @@ TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_Represent
return aResult;
// Allocate sub-Label
aResult = AllocateSubLabel(theLab);
aResult = theShapeTool->AddSubShape(theLab, aShape);
if (aResult.IsNull())
return aResult;
TCollection_AsciiString aName = hName->String();
TDataStd_Name::Set(aResult, aName);
@ -4382,6 +4374,34 @@ TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_Represent
return aResult;
}
//=======================================================================
//function : collectRepresentationItems
//purpose : recursive collection of representation items for given representation
// with all representations, related to it.
//=======================================================================
void collectRepresentationItems(const Interface_Graph& theGraph,
const Handle(StepShape_ShapeRepresentation)& theRepresentation,
NCollection_Sequence<Handle(StepRepr_RepresentationItem)>& theItems)
{
Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = theRepresentation->Items();
for (Standard_Integer itemIt = aReprItems->Lower(); itemIt <= aReprItems->Upper(); itemIt++)
theItems.Append(aReprItems->Value(itemIt));
Interface_EntityIterator entIt = theGraph.TypedSharings(theRepresentation, STANDARD_TYPE(StepRepr_RepresentationRelationship));
for (entIt.Start(); entIt.More(); entIt.Next())
{
Handle(StepRepr_RepresentationRelationship) aRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(entIt.Value());
if (aRelationship->Rep1() == theRepresentation)
{
Handle(StepShape_ShapeRepresentation)
aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aRelationship->Rep2());
if (!aRepr.IsNull())
collectRepresentationItems(theGraph, aRepr, theItems);
}
}
}
//=======================================================================
//function : ExpandSubShapes
//purpose :
@ -4432,24 +4452,29 @@ void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& Sha
continue;
// Access representation items
Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = aShapeRepr->Items();
NCollection_Sequence<Handle(StepRepr_RepresentationItem)> aReprItems;
collectRepresentationItems(Graph, aShapeRepr, aReprItems);
if ( aReprItems.IsNull() )
if (aReprItems.Length() == 0)
continue;
if ( !ShapeLabelMap.IsBound(aRootShape) )
continue;
TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape);
// Do not add subshapes to assembly,
// they will be processed with corresponding Shape_Product_Definition of necessary part.
if (ShapeTool->IsAssembly(aRootLab))
continue;
StepRepr_SequenceOfRepresentationItem aMSBSeq;
StepRepr_SequenceOfRepresentationItem aSBSMSeq;
// Iterate over the top level representation items collecting the
// topological containers to expand
for ( Standard_Integer i = aReprItems->Lower(); i <= aReprItems->Upper(); ++i )
for (Standard_Integer i = 1; i <= aReprItems.Length(); ++i)
{
Handle(StepRepr_RepresentationItem) aTRepr = aReprItems->Value(i);
Handle(StepRepr_RepresentationItem) aTRepr = aReprItems.Value(i);
if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ManifoldSolidBrep) ) )
aMSBSeq.Append(aTRepr);
else if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ShellBasedSurfaceModel) ) )
@ -4463,16 +4488,11 @@ void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& Sha
// Expand Manifold Solid BReps
for ( Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i )
{
const Handle(StepRepr_RepresentationItem)& aManiRepr = aMSBSeq.Value(i);
// Put additional Label for SOLID
TDF_Label aManiLab;
if ( doInsertSolidLab )
aManiLab = SettleShapeData(aManiRepr, aRootLab, ShapeTool, TP);
else
aManiLab = aRootLab;
if (doInsertSolidLab)
SettleShapeData(aMSBSeq.Value(i), aRootLab, ShapeTool, TP);
ExpandManifoldSolidBrep(aManiLab, aMSBSeq.Value(i), TP, ShapeTool);
ExpandManifoldSolidBrep(aRootLab, aMSBSeq.Value(i), TP, ShapeTool);
}
// Expand Shell-Based Surface Models
@ -4540,7 +4560,7 @@ void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)
const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
{
// Record CAF data
TDF_Label aShellLab = SettleShapeData(Shell, RootLab, ShapeTool, TP);
SettleShapeData(Shell, RootLab, ShapeTool, TP);
// Access faces
Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces();
@ -4549,7 +4569,7 @@ void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)
const Handle(StepShape_Face)& aFace = aFaces->Value(f);
// Record CAF data
TDF_Label aFaceLab = SettleShapeData(aFace, aShellLab, ShapeTool, TP);
SettleShapeData(aFace, RootLab, ShapeTool, TP);
// Access face bounds
Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds();
@ -4558,7 +4578,7 @@ void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)
const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound();
// Record CAF data
TDF_Label aWireLab = SettleShapeData(aWire, aFaceLab, ShapeTool, TP);
SettleShapeData(aWire, RootLab, ShapeTool, TP);
// Access wire edges
// Currently only EDGE LOOPs are considered (!)
@ -4573,15 +4593,15 @@ void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)
Handle(StepShape_Edge) anEdge = anEdges->Value(e)->EdgeElement();
// Record CAF data
TDF_Label anEdgeLab = SettleShapeData(anEdge, aWireLab, ShapeTool, TP);
SettleShapeData(anEdge, RootLab, ShapeTool, TP);
// Access vertices
Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart();
Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd();
// Record CAF data
SettleShapeData(aV1, anEdgeLab, ShapeTool, TP);
SettleShapeData(aV2, anEdgeLab, ShapeTool, TP);
SettleShapeData(aV1, RootLab, ShapeTool, TP);
SettleShapeData(aV2, RootLab, ShapeTool, TP);
}
}
}

View File

@ -222,7 +222,7 @@ protected:
//! Populates the sub-Label of the passed TDF Label with shape
//! data associated with the given STEP Representation Item,
//! including naming and topological information.
Standard_EXPORT TDF_Label SettleShapeData (const Handle(StepRepr_RepresentationItem)& theItem, TDF_Label& theLab, const Handle(XCAFDoc_ShapeTool)& theShapeTool, const Handle(Transfer_TransientProcess)& theTP) const;
Standard_EXPORT TDF_Label SettleShapeData (const Handle(StepRepr_RepresentationItem)& theItem, const TDF_Label& theLab, const Handle(XCAFDoc_ShapeTool)& theShapeTool, const Handle(Transfer_TransientProcess)& theTP) const;
//! Given the maps of already translated shapes, this method
//! expands their correspondent Labels in XDE Document so that

View File

@ -671,9 +671,9 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
const Handle(XSControl_TransferWriter) &TW = this->ChangeWriter().WS()->TransferWriter();
const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
for ( int i = 1; i <= labels.Length(); i++ )
for ( int i = 1; i <= sublabels.Length(); i++ )
{
TDF_Label L = labels.Value(i);
TDF_Label L = sublabels.Value(i);
for ( TDF_ChildIterator it(L, Standard_True); it.More(); it.Next() )
{

47
tests/bugs/step/bug29403 Normal file
View File

@ -0,0 +1,47 @@
puts "=========="
puts "OCC29403"
puts "=========="
puts ""
#########################################################
# Subshapes names are not imported from step
#########################################################
param read.stepcaf.subshapes.name 1
param write.stepcaf.subshapes.name 1
pload DCAF
ReadStep doc [locate_data_file bug29403_ECOR030312.stp]
set info1 [XStat doc]
regexp {level N 0 +: +([-0-9.+eE]+)} $info1 full l0
regexp {level N 1 +: +([-0-9.+eE]+)} $info1 full l1
regexp {Total number of labels for shapes in the document += +([-0-9.+eE]+)} $info1 full nb
regexp {Number of labels with name += +([-0-9.+eE]+)} $info1 full nbname
WriteStep doc $imagedir/doc_subshapes.stp
ReadStep after_doc $imagedir/doc_subshapes.stp
set info2 [XStat after_doc]
regexp {level N 0 +: +([-0-9.+eE]+)} $info2 full l0_1
regexp {level N 1 +: +([-0-9.+eE]+)} $info2 full l1_1
regexp {Total number of labels for shapes in the document += +([-0-9.+eE]+)} $info2 full nb_1
regexp {Number of labels with name += +([-0-9.+eE]+)} $info2 full nbname_1
if { ${l0} != ${l0_1} ||
${l0} != "38" ||
${l1} != ${l1_1} ||
${l1} != "85" ||
${nb} != ${nb_1} ||
${nb} != "123" ||
${nbname} != ${nbname_1} ||
${nbname} != "123"} {
puts "Error : Document is read/written wrong!"
}
Close doc
Close after_doc
file delete -force $imagedir/doc_subshapes.stp
param read.stepcaf.subshapes.name 0
param write.stepcaf.subshapes.name 0

View File

@ -1,14 +1,10 @@
# Original bug : 23384
# Date : 16 Aug 2012
XOpen [locate_data_file bug23384-doc_subshapes.xbf] doc
pload DCAF
XOpen [locate_data_file bug23384-doc_subshapes_plain.xbf] doc
set info1 [XStat doc]
regexp {level N 0 +: +([-0-9.+eE]+)} $info1 full l0
regexp {level N 1 +: +([-0-9.+eE]+)} $info1 full l1
regexp {level N 2 +: +([-0-9.+eE]+)} $info1 full l2
regexp {level N 3 +: +([-0-9.+eE]+)} $info1 full l3
regexp {level N 4 +: +([-0-9.+eE]+)} $info1 full l4
regexp {level N 5 +: +([-0-9.+eE]+)} $info1 full l5
regexp {level N 6 +: +([-0-9.+eE]+)} $info1 full l6
regexp {Total number of labels for shapes in the document += +([-0-9.+eE]+)} $info1 full nb
regexp {Number of labels with name += +([-0-9.+eE]+)} $info1 full nbname
@ -23,22 +19,20 @@ param read.stepcaf.subshapes.name 1
set info2 [XStat after_doc]
regexp {level N 0 +: +([-0-9.+eE]+)} $info2 full l0_1
regexp {level N 1 +: +([-0-9.+eE]+)} $info2 full l1_1
regexp {level N 2 +: +([-0-9.+eE]+)} $info2 full l2_1
regexp {level N 3 +: +([-0-9.+eE]+)} $info2 full l3_1
regexp {level N 4 +: +([-0-9.+eE]+)} $info2 full l4_1
regexp {level N 5 +: +([-0-9.+eE]+)} $info2 full l5_1
regexp {level N 6 +: +([-0-9.+eE]+)} $info2 full l6_1
regexp {Total number of labels for shapes in the document += +([-0-9.+eE]+)} $info2 full nb_1
regexp {Number of labels with name += +([-0-9.+eE]+)} $info2 full nbname_1
if { ${l0} != ${l0_1} ||
${l0} != "4" ||
${l1} != ${l1_1} ||
${l2} != ${l2_1} ||
${l3} != ${l3_1} ||
${l4} != ${l4_1} ||
${l5} != ${l5_1} ||
${l6} != ${l6_1} ||
${l1} != "131" ||
${nb} != ${nb_1} ||
${nbname} != ${nbname_1} } {
${nb} != "135" ||
${nbname} != ${nbname_1} ||
${nbname} != "135"} {
puts "Error : Document is read/written wrong!"
}
Close doc
Close after_doc
file delete -force $imagedir/doc_subshapes.stp