]> OCCT Git - occt.git/commitdiff
0028748: XCAFDoc_GraphNode does not restore child on Undo
authordbv <dbv@opencascade.com>
Wed, 17 May 2017 15:43:59 +0000 (18:43 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 25 May 2017 08:41:58 +0000 (11:41 +0300)
Fixed calling Backup method. Now it called where data really changed.

src/XCAFDoc/XCAFDoc_GraphNode.cxx
src/XDEDRAW/XDEDRAW_Layers.cxx
tests/bugs/xde/bug28748 [new file with mode: 0644]

index 9385cbb0a304090c1b0a0ade3fd56d90d236d0d4..9aa7af0e55d9876593a57155bf019eb417744251 100644 (file)
@@ -140,7 +140,6 @@ Standard_Integer XCAFDoc_GraphNode::SetChild(const Handle(XCAFDoc_GraphNode)& Ch
 
 void XCAFDoc_GraphNode::UnSetFather(const Handle(XCAFDoc_GraphNode)& F) 
 {
-  Backup();
   Standard_Integer Findex = FatherIndex(F);
   if (Findex != 0)
   F->UnSetChildlink(this);
@@ -167,6 +166,7 @@ void XCAFDoc_GraphNode::UnSetFather(const Standard_Integer Findex)
 
 void XCAFDoc_GraphNode::UnSetFatherlink(const Handle(XCAFDoc_GraphNode)& F) 
 {
+  Backup();
   myFathers.Remove( FatherIndex(F) );
 }
 
@@ -177,7 +177,6 @@ void XCAFDoc_GraphNode::UnSetFatherlink(const Handle(XCAFDoc_GraphNode)& F)
 
 void XCAFDoc_GraphNode::UnSetChild(const Handle(XCAFDoc_GraphNode)& Ch) 
 {
-  Backup();
   Standard_Integer Chindex = ChildIndex(Ch);
   if (Chindex != 0) 
   Ch->UnSetFatherlink(this);
@@ -204,6 +203,7 @@ void XCAFDoc_GraphNode::UnSetChild(const Handle(XCAFDoc_GraphNode)& Ch)
 
 void XCAFDoc_GraphNode::UnSetChildlink(const Handle(XCAFDoc_GraphNode)& Ch) 
 {
+  Backup();
   myChildren.Remove( ChildIndex(Ch) );
 }
 
index 858c0720441ade9020051f5bee3d763fbf4399bc..14afe28804c8251af0446159c7fa39203d7135a9 100644 (file)
@@ -24,7 +24,9 @@
 #include <TDF_Tool.hxx>
 #include <TDocStd_Document.hxx>
 #include <TopoDS_Shape.hxx>
+#include <XCAFDoc.hxx>
 #include <XCAFDoc_DocumentTool.hxx>
+#include <XCAFDoc_GraphNode.hxx>
 #include <XCAFDoc_LayerTool.hxx>
 #include <XCAFDoc_ShapeTool.hxx>
 #include <XDEDRAW_Layers.hxx>
@@ -394,6 +396,67 @@ static Standard_Integer isVisible (Draw_Interpretor& di, Standard_Integer argc,
   return 0;
 }
 
+static Standard_Integer getLayerRefs(Draw_Interpretor& theDI,
+                                     Standard_Integer theArgc,
+                                     const char** theArgv)
+{
+  if (theArgc != 3)
+  {
+    theDI << "Use: " << theArgv[0] << "DocName Label\n";
+    return 1;
+  }
+
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument(theArgv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    theDI << "Error: \"" << theArgv[1] << "\" is not a document.\n";
+    return 1;
+  }
+
+  TDF_Label aLabel;
+  TDF_Tool::Label(aDoc->GetData(), theArgv[2], aLabel);
+  if (aLabel.IsNull())
+  {
+    theDI << "Error: Document \"" << theArgv[1] << "\" does not have a label \"" << theArgv[2] << "\".\n";
+    return 1;
+  }
+
+  Handle(XCAFDoc_GraphNode) aGraphNode;
+  aLabel.FindAttribute(XCAFDoc::LayerRefGUID(), aGraphNode);
+  if (aGraphNode.IsNull())
+  {
+    theDI << "Error: Label \"" << theArgv[2] << "\" does not have a layer ref.\n";
+    return 1;
+  }
+
+  if (aGraphNode->NbChildren() > 0)
+  {
+    theDI << "Label \"" << theArgv[2] << "\" childs:\n";
+    for (int anIndex = 1; anIndex <= aGraphNode->NbChildren(); ++anIndex)
+    {
+      Handle(XCAFDoc_GraphNode) aChild = aGraphNode->GetChild(anIndex);
+      TCollection_AsciiString anEntry;
+      TDF_Tool::Entry(aChild->Label(), anEntry);
+      theDI << anEntry << "\n";
+    }
+  }
+
+  if (aGraphNode->NbFathers() > 0)
+  {
+    theDI << "Label \"" << theArgv[2] << "\" fathers:\n";
+    for (int anIndex = 1; anIndex <= aGraphNode->NbFathers(); ++anIndex)
+    {
+      Handle(XCAFDoc_GraphNode) aFather = aGraphNode->GetFather(anIndex);
+      TCollection_AsciiString anEntry;
+      TDF_Tool::Entry(aFather->Label(), anEntry);
+      theDI << anEntry << "\n";
+    }
+  }
+
+  return 0;
+}
+
 //=======================================================================
 //function : InitCommands
 //purpose  : 
@@ -455,4 +518,7 @@ void XDEDRAW_Layers::InitCommands(Draw_Interpretor& di)
 
   di.Add ("XIsVisible","DocName {layerLable|StringLayer} \t: Return 1 if layer is visible, 0 if not",
                   __FILE__, isVisible, g);
+
+  di.Add("XGetLayerRefs", "DocName Label \t: Prints layers labels which are referenced in passed label or prints labels which reference passed layer label.",
+         __FILE__, getLayerRefs, g);
 }
diff --git a/tests/bugs/xde/bug28748 b/tests/bugs/xde/bug28748
new file mode 100644 (file)
index 0000000..2aa5d9c
--- /dev/null
@@ -0,0 +1,23 @@
+puts "=========="
+puts "OCC28748"
+puts "=========="
+puts ""
+###########################################################
+# XCAFDoc_GraphNode does not restore child on Undo
+###########################################################
+
+pload DCAF
+
+ReadStep d [locate_data_file bug21802_as1-oc-214.stp]
+UndoLimit d 1
+OpenCommand d
+XUnSetLayer d 0:1:1:3 256
+CommitCommand d
+Undo d
+set info [XGetLayerRefs d 0:1:3:1]
+if { [regexp "0:1:1:3" $info] != 1 } {
+    puts "Error: child not restored on Undo"
+} else {
+    puts "OK: child restored on Undo"
+}