]> OCCT Git - occt-copy.git/commitdiff
XCAF: remove subshape/attr note/all notes
authorsnn <snn@opencascade.com>
Thu, 11 May 2017 08:31:57 +0000 (11:31 +0300)
committerapl <apl@opencascade.com>
Mon, 15 May 2017 10:34:52 +0000 (13:34 +0300)
src/XCAFDoc/XCAFDoc_NotesTool.cxx
src/XCAFDoc/XCAFDoc_NotesTool.hxx

index ad51f49a07fbe9880a44d4eac33a5d1954d4aa74..89f761c1f4e0df3c076e78045346a39c667d5a62 100644 (file)
@@ -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)
 {
index e079fe065d6a603fc5e49db994da4d6dac44d3ad..6a1c3c70c60a89f1f9e440c5d76020ba69149188 100644 (file)
@@ -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);