diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.cxx b/src/XCAFDoc/XCAFDoc_NotesTool.cxx index ad51f49a07..89f761c1f4 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.cxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.cxx @@ -444,6 +444,72 @@ XCAFDoc_NotesTool::RemoveNote(const TDF_Label& theNoteLabel, return Standard_True; } +Standard_Boolean +XCAFDoc_NotesTool::RemoveSubshapeNote(const TDF_Label& theNoteLabel, + const XCAFDoc_AssemblyItemId& theItemId, + Standard_Integer theSubshapeIndex, + Standard_Boolean theDelIfOrphan) +{ + Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(theNoteLabel); + + if (aNote.IsNull()) + return Standard_False; + + Handle(XCAFDoc_GraphNode) aFather; + if (!theNoteLabel.FindAttribute(XCAFDoc::NoteRefGUID(), aFather)) + return Standard_False; + + TDF_Label anAnnotatedItem = FindAnnotatedItemSubshape(theItemId, theSubshapeIndex); + if (anAnnotatedItem.IsNull()) + return Standard_False; + + Handle(XCAFDoc_GraphNode) aChild; + if (!anAnnotatedItem.FindAttribute(XCAFDoc::NoteRefGUID(), aChild)) + return Standard_False; + + aChild->UnSetFather(aFather); + if (aChild->NbFathers() == 0) + anAnnotatedItem.ForgetAllAttributes(); + + if (theDelIfOrphan && aNote->IsOrphan()) + DeleteNote(theNoteLabel); + + return Standard_True; +} + +Standard_Boolean +XCAFDoc_NotesTool::RemoveAttrNote(const TDF_Label& theNoteLabel, + const XCAFDoc_AssemblyItemId& theItemId, + const Standard_GUID& theGUID, + Standard_Boolean theDelIfOrphan) +{ + Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(theNoteLabel); + + if (aNote.IsNull()) + return Standard_False; + + Handle(XCAFDoc_GraphNode) aFather; + if (!theNoteLabel.FindAttribute(XCAFDoc::NoteRefGUID(), aFather)) + return Standard_False; + + TDF_Label anAnnotatedItem = FindAnnotatedItemAttr(theItemId, theGUID); + if (anAnnotatedItem.IsNull()) + return Standard_False; + + Handle(XCAFDoc_GraphNode) aChild; + if (!anAnnotatedItem.FindAttribute(XCAFDoc::NoteRefGUID(), aChild)) + return Standard_False; + + aChild->UnSetFather(aFather); + if (aChild->NbFathers() == 0) + anAnnotatedItem.ForgetAllAttributes(); + + if (theDelIfOrphan && aNote->IsOrphan()) + DeleteNote(theNoteLabel); + + return Standard_True; +} + Standard_Boolean XCAFDoc_NotesTool::RemoveAllNotes(const XCAFDoc_AssemblyItemId& theItemId, Standard_Boolean theDelIfOrphan) @@ -474,6 +540,68 @@ XCAFDoc_NotesTool::RemoveAllNotes(const XCAFDoc_AssemblyItemId& theItemId, return Standard_True; } +Standard_Boolean +XCAFDoc_NotesTool::RemoveAllSubshapeNotes(const XCAFDoc_AssemblyItemId& theItemId, + Standard_Integer theSubshapeIndex, + Standard_Boolean theDelIfOrphan) +{ + TDF_Label anAnnotatedItem = FindAnnotatedItemSubshape(theItemId, theSubshapeIndex); + if (anAnnotatedItem.IsNull()) + return Standard_False; + + Handle(XCAFDoc_GraphNode) aChild; + if (!anAnnotatedItem.FindAttribute(XCAFDoc::NoteRefGUID(), aChild)) + return Standard_False; + + Standard_Integer nbFathers = aChild->NbFathers(); + for (Standard_Integer iFather = 1; iFather <= nbFathers; ++iFather) + { + Handle(XCAFDoc_GraphNode) aFather = aChild->GetFather(iFather); + Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(aFather->Label()); + if (!aNote.IsNull()) + { + aFather->UnSetChild(aChild); + if (theDelIfOrphan && aNote->IsOrphan()) + DeleteNote(aFather->Label()); + } + } + + anAnnotatedItem.ForgetAllAttributes(); + + return Standard_True; +} + +Standard_Boolean +XCAFDoc_NotesTool::RemoveAllAttrNotes(const XCAFDoc_AssemblyItemId& theItemId, + const Standard_GUID& theGUID, + Standard_Boolean theDelIfOrphan) +{ + TDF_Label anAnnotatedItem = FindAnnotatedItemAttr(theItemId, theGUID); + if (anAnnotatedItem.IsNull()) + return Standard_False; + + Handle(XCAFDoc_GraphNode) aChild; + if (!anAnnotatedItem.FindAttribute(XCAFDoc::NoteRefGUID(), aChild)) + return Standard_False; + + Standard_Integer nbFathers = aChild->NbFathers(); + for (Standard_Integer iFather = 1; iFather <= nbFathers; ++iFather) + { + Handle(XCAFDoc_GraphNode) aFather = aChild->GetFather(iFather); + Handle(XCAFDoc_Note) aNote = XCAFDoc_Note::Get(aFather->Label()); + if (!aNote.IsNull()) + { + aFather->UnSetChild(aChild); + if (theDelIfOrphan && aNote->IsOrphan()) + DeleteNote(aFather->Label()); + } + } + + anAnnotatedItem.ForgetAllAttributes(); + + return Standard_True; +} + Standard_Boolean XCAFDoc_NotesTool::DeleteNote(const TDF_Label& theNoteLabel) { diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.hxx b/src/XCAFDoc/XCAFDoc_NotesTool.hxx index e079fe065d..6a1c3c70c6 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.hxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.hxx @@ -99,8 +99,22 @@ public: Standard_EXPORT Standard_Boolean RemoveNote(const TDF_Label& theNoteLabel, const XCAFDoc_AssemblyItemId& theItemId, Standard_Boolean theDelIfOrphan = Standard_False); + Standard_EXPORT Standard_Boolean RemoveSubshapeNote(const TDF_Label& theNoteLabel, + const XCAFDoc_AssemblyItemId& theItemId, + Standard_Integer theSubshapeIndex, + Standard_Boolean theDelIfOrphan = Standard_False); + Standard_EXPORT Standard_Boolean RemoveAttrNote(const TDF_Label& theNoteLabel, + const XCAFDoc_AssemblyItemId& theItemId, + const Standard_GUID& theGUID, + Standard_Boolean theDelIfOrphan = Standard_False); Standard_EXPORT Standard_Boolean RemoveAllNotes(const XCAFDoc_AssemblyItemId& theItemId, Standard_Boolean theDelIfOrphan = Standard_False); + Standard_EXPORT Standard_Boolean RemoveAllSubshapeNotes(const XCAFDoc_AssemblyItemId& theItemId, + Standard_Integer theSubshapeIndex, + Standard_Boolean theDelIfOrphan = Standard_False); + Standard_EXPORT Standard_Boolean RemoveAllAttrNotes(const XCAFDoc_AssemblyItemId& theItemId, + const Standard_GUID& theGUID, + Standard_Boolean theDelIfOrphan = Standard_False); Standard_EXPORT Standard_Boolean DeleteNote(const TDF_Label& theNoteLabel); Standard_EXPORT Standard_Integer DeleteNotes(TDF_LabelSequence& theNoteLabels);