Skip to content
Open
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
4 changes: 1 addition & 3 deletions src/DataExchange/TKDEGLTF/RWGltf/RWGltf_CafReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -449,20 +449,18 @@ void RWGltf_CafReader::fillDocument()
Message::SendWarning("Warning: Length unit of document not equal to the system length unit");
}

const bool wasAutoNaming = XCAFDoc_ShapeTool::AutoNaming();
XCAFDoc_ShapeTool::SetAutoNaming(false);
const TCollection_AsciiString aRootName; // = generateRootName (theFile);
CafDocumentTools aTools;
aTools.ShapeTool = XCAFDoc_DocumentTool::ShapeTool(myXdeDoc->Main());
aTools.ColorTool = XCAFDoc_DocumentTool::ColorTool(myXdeDoc->Main());
aTools.VisMaterialTool = XCAFDoc_DocumentTool::VisMaterialTool(myXdeDoc->Main());
XCAFDoc_ShapeTool::OwnAutoNamingScope anAutoNamingScope(aTools.ShapeTool, false);
for (NCollection_Sequence<TopoDS_Shape>::Iterator aRootIter(myRootShapes); aRootIter.More();
aRootIter.Next())
{
addShapeIntoDoc(aTools, aRootIter.Value(), TDF_Label(), aRootName);
}
XCAFDoc_DocumentTool::ShapeTool(myXdeDoc->Main())->UpdateAssemblies();
XCAFDoc_ShapeTool::SetAutoNaming(wasAutoNaming);
}

//=================================================================================================
Expand Down
4 changes: 1 addition & 3 deletions src/DataExchange/TKRWMesh/RWMesh/RWMesh_CafReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,18 @@ void RWMesh_CafReader::fillDocument()
Message::SendWarning("Warning: Length unit of document not equal to the system length unit");
}

const bool wasAutoNaming = XCAFDoc_ShapeTool::AutoNaming();
XCAFDoc_ShapeTool::SetAutoNaming(false);
const TCollection_AsciiString aRootName; // = generateRootName (theFile);
CafDocumentTools aTools;
aTools.ShapeTool = XCAFDoc_DocumentTool::ShapeTool(myXdeDoc->Main());
aTools.ColorTool = XCAFDoc_DocumentTool::ColorTool(myXdeDoc->Main());
aTools.VisMaterialTool = XCAFDoc_DocumentTool::VisMaterialTool(myXdeDoc->Main());
XCAFDoc_ShapeTool::OwnAutoNamingScope anAutoNamingScope(aTools.ShapeTool, false);
for (NCollection_Sequence<TopoDS_Shape>::Iterator aRootIter(myRootShapes); aRootIter.More();
aRootIter.Next())
{
addShapeIntoDoc(aTools, aRootIter.Value(), TDF_Label(), aRootName);
}
XCAFDoc_DocumentTool::ShapeTool(myXdeDoc->Main())->UpdateAssemblies();
XCAFDoc_ShapeTool::SetAutoNaming(wasAutoNaming);
}

//=================================================================================================
Expand Down
7 changes: 2 additions & 5 deletions src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ bool XCAFDoc_Editor::Expand(const TDF_Label& theDoc,
{
return false;
}
occ::handle<XCAFDoc_ShapeTool> aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDoc);
bool isAutoNaming = aShapeTool->AutoNaming();
aShapeTool->SetAutoNaming(false);
occ::handle<XCAFDoc_ShapeTool> aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDoc);
XCAFDoc_ShapeTool::OwnAutoNamingScope anAutoNamingScope(aShapeTool, false);

TDF_Label aCompoundPartL = theShape;
if (aShapeTool->IsReference(theShape))
Expand Down Expand Up @@ -139,10 +138,8 @@ bool XCAFDoc_Editor::Expand(const TDF_Label& theDoc,
}
}
}
aShapeTool->SetAutoNaming(isAutoNaming);
return true;
}
aShapeTool->SetAutoNaming(isAutoNaming);
return false;
}

Expand Down
40 changes: 34 additions & 6 deletions src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_ShapeTool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <XCAFDoc_ShapeTool.hxx>

#include <atomic>

#include <BRep_Builder.hxx>
#include <gp_Pnt.hxx>
#include <gp_Trsf.hxx>
Expand Down Expand Up @@ -50,7 +52,7 @@

IMPLEMENT_DERIVED_ATTRIBUTE_WITH_TYPE(XCAFDoc_ShapeTool, TDataStd_GenericEmpty, "xcaf", "ShapeTool")

static bool theAutoNaming = true;
static std::atomic<bool> theAutoNaming{true};

// attribute methods //////////////////////////////////////////////////

Expand Down Expand Up @@ -81,6 +83,7 @@ occ::handle<XCAFDoc_ShapeTool> XCAFDoc_ShapeTool::Set(const TDF_Label& L)
XCAFDoc_ShapeTool::XCAFDoc_ShapeTool()
{
hasSimpleShapes = false;
myOwnAutonaming = -1;
}

//=================================================================================================
Expand Down Expand Up @@ -453,7 +456,7 @@ void XCAFDoc_ShapeTool::MakeReference(const TDF_Label& L,
refNode->Remove(); // abv: fix against bug in TreeNode::Append()
mainNode->Append(refNode);

if (theAutoNaming)
if (OwnAutoNaming())
{
SetLabelNameByLink(L);
}
Expand Down Expand Up @@ -529,7 +532,7 @@ TDF_Label XCAFDoc_ShapeTool::addShape(const TopoDS_Shape& S, const bool makeAsse
// }
A->SetShape(S);

if (theAutoNaming)
if (OwnAutoNaming())
{
SetLabelNameByShape(ShapeLabel);
}
Expand All @@ -540,7 +543,7 @@ TDF_Label XCAFDoc_ShapeTool::addShape(const TopoDS_Shape& S, const bool makeAsse
// mark assembly by assigning UAttribute
occ::handle<TDataStd_UAttribute> Uattr;
Uattr = TDataStd_UAttribute::Set(ShapeLabel, XCAFDoc::AssemblyGUID());
if (theAutoNaming)
if (OwnAutoNaming())
{
TDataStd_Name::Set(ShapeLabel, TCollection_ExtendedString("ASSEMBLY"));
}
Expand Down Expand Up @@ -702,6 +705,31 @@ bool XCAFDoc_ShapeTool::AutoNaming()

//=================================================================================================

// Saves/restores the instance's own override, not a shared flag -- no locking
// needed, and nested scopes on the same instance compose correctly since each
// one restores exactly the state it observed on entry.
XCAFDoc_ShapeTool::OwnAutoNamingScope::OwnAutoNamingScope(
const occ::handle<XCAFDoc_ShapeTool>& theTool,
const bool theTemporaryValue)
: myTool(theTool),
myWasOwnAutoNaming(theTool.IsNull() ? -1 : theTool->myOwnAutonaming)
{
if (!myTool.IsNull())
{
myTool->myOwnAutonaming = theTemporaryValue ? 1 : 0;
}
}

XCAFDoc_ShapeTool::OwnAutoNamingScope::~OwnAutoNamingScope()
{
if (!myTool.IsNull())
{
myTool->myOwnAutonaming = myWasOwnAutoNaming;
}
}

//=================================================================================================

void XCAFDoc_ShapeTool::ComputeShapes(const TDF_Label& L)
{
TDF_ChildIterator it(L);
Expand Down Expand Up @@ -1542,7 +1570,7 @@ bool XCAFDoc_ShapeTool::SetSHUO(const NCollection_Sequence<TDF_Label>& labels,

TDF_TagSource aTag;
TDF_Label UpperSubL = TDF_TagSource::NewChild(labels(1));
if (theAutoNaming)
if (OwnAutoNaming())
{
TCollection_ExtendedString Entry("SHUO");
TDataStd_Name::Set(UpperSubL, TCollection_ExtendedString(Entry));
Expand All @@ -1555,7 +1583,7 @@ bool XCAFDoc_ShapeTool::SetSHUO(const NCollection_Sequence<TDF_Label>& labels,
for (i = 2; i <= labels.Length(); i++)
{
TDF_Label NextSubL = TDF_TagSource::NewChild(labels(i));
if (theAutoNaming)
if (OwnAutoNaming())
{
TCollection_ExtendedString EntrySub("SHUO-");
EntrySub += i;
Expand Down
41 changes: 38 additions & 3 deletions src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_ShapeTool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,39 @@ public:
//! description.
Standard_EXPORT static bool AutoNaming();

//! Returns the auto-naming mode for this instance: its own local override if
//! set, otherwise the process-wide default. See SetOwnAutoNaming().
bool OwnAutoNaming() const
{
return myOwnAutonaming == -1 ? XCAFDoc_ShapeTool::AutoNaming() : myOwnAutonaming == 1;
}

//! Locally overrides auto-naming for this instance only, leaving the
//! process-wide default and other documents untouched. Prefer
//! OwnAutoNamingScope so a local override can't leak past an exception.
void SetOwnAutoNaming(const bool theOwnFlag) { myOwnAutonaming = theOwnFlag ? 1 : 0; }

//! Resets this instance to inherit the process-wide default again.
void UnsetOwnAutoNaming() { myOwnAutonaming = -1; }

//! RAII scope: locally overrides auto-naming on one ShapeTool instance,
//! restoring its previous own-override state on destruction. Needs no
//! locking, and nests correctly on the same instance.
class OwnAutoNamingScope
{
public:
Standard_EXPORT OwnAutoNamingScope(const occ::handle<XCAFDoc_ShapeTool>& theTool,
const bool theTemporaryValue);
Standard_EXPORT ~OwnAutoNamingScope();

OwnAutoNamingScope(const OwnAutoNamingScope&) = delete;
OwnAutoNamingScope& operator=(const OwnAutoNamingScope&) = delete;

private:
occ::handle<XCAFDoc_ShapeTool> myTool;
int myWasOwnAutoNaming;
};

//! recursive
Standard_EXPORT void ComputeShapes(const TDF_Label& L);

Expand Down Expand Up @@ -500,9 +533,9 @@ private:

//! Makes a shape on label L to be a reference to shape refL
//! with location loc
Standard_EXPORT static void MakeReference(const TDF_Label& L,
const TDF_Label& refL,
const TopLoc_Location& loc);
Standard_EXPORT void MakeReference(const TDF_Label& L,
const TDF_Label& refL,
const TopLoc_Location& loc);

//! Auxiliary method for Expand
//! Add declared under expanded theMainShapeL subshapes to new part label thePart
Expand All @@ -517,6 +550,8 @@ private:
NCollection_DataMap<TopoDS_Shape, TDF_Label, TopTools_ShapeMapHasher> mySubShapes;
NCollection_DataMap<TopoDS_Shape, TDF_Label, TopTools_ShapeMapHasher> mySimpleShapes;
bool hasSimpleShapes;
//! -1: inherit the process-wide default; 0/1: local override.
int myOwnAutonaming;
};

#endif // _XCAFDoc_ShapeTool_HeaderFile
Loading