0026314: Method SetShape working not correctly.
authorink <ink@opencascade.com>
Thu, 18 Jun 2015 10:54:09 +0000 (13:54 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 18 Jun 2015 10:55:00 +0000 (13:55 +0300)
Test-cases for issues #25441 and #26314
small correction

Small corrections of test-cases for issues #25441 and #26314

src/XCAFDoc/XCAFDoc_ShapeTool.cdl
src/XCAFDoc/XCAFDoc_ShapeTool.cxx
src/XDEDRAW/XDEDRAW_Shapes.cxx
tests/bugs/xde/bug22962
tests/bugs/xde/bug25441 [new file with mode: 0644]
tests/bugs/xde/bug26314 [new file with mode: 0644]

index 51631c0..fcd0553 100644 (file)
@@ -217,7 +217,12 @@ is
         --          Initially it holds empty TopoDS_Compound
 
     SetShape (me:mutable; L: Label from TDF; S: Shape from TopoDS);
-       ---Purpose: Sets representation (TopoDS_Shape) for top-level shape
+       ---Purpose: Sets representation (TopoDS_Shape) for top-level shape.
+       --          If S has location(location.IsIdentity() is false),
+       --          command will be skipped. Sub-shapes of S which is 
+       --          subshape of old shape, will be stored ( all atributes will be stored). 
+       --          If a sub-label of L is not a sub-shape of the new shape,
+       --          it will be removed.
 
     AddShape (me:mutable; S: Shape from TopoDS; 
                          makeAssembly: Boolean = Standard_True;
@@ -328,6 +333,9 @@ is
     RemoveComponent (me; comp: Label from TDF);
        ---Purpose: Removes a component from its assembly
 
+    UpdateAssociatedAssembly (me; L: Label from TDF);
+       ---Purpose: Update labels associated with Label <L>
+
     UpdateAssembly (me; L: Label from TDF);
        ---Purpose: Update an assembly at label <L>
 
index 196fca3..070a32c 100644 (file)
@@ -401,26 +401,32 @@ TDF_Label XCAFDoc_ShapeTool::NewShape() const
 //=======================================================================
 
 void XCAFDoc_ShapeTool::SetShape (const TDF_Label& L, const TopoDS_Shape& S)
-{
+{ 
+  if(IsReference(L) || !IsTopLevel(L) || /*IsAssembly(L) ||*/ !S.Location().IsIdentity())
+    return;
+
+  TDF_LabelSequence aSubShapes;
+  GetSubShapes(L, aSubShapes);
+
   TNaming_Builder tnBuild(L);
   tnBuild.Generated(S);
   Handle(XCAFDoc_ShapeMapTool) A = XCAFDoc_ShapeMapTool::Set(L);
-//  if ( ! L.FindAttribute(XCAFDoc_ShapeMapTool::GetID(), A) ) {
-//    A = XCAFDoc_ShapeMapTool::Set(L);
-//    L.AddAttribute(A);
-//  }
   A->SetShape(S);
 
+  for(Standard_Integer i = 1; i<=aSubShapes.Length(); i++)
+  {
+    TDF_Label aSubLabel = aSubShapes(i);
+    if (!IsSubShape(L, GetShape(aSubLabel)))
+    {
+      aSubLabel.ForgetAllAttributes();
+    }
+  }
+
   if(!myShapeLabels.IsBound(S)) {
     myShapeLabels.Bind(S,L);
   }
-  
-  //:abv 31.10.01: update assemblies that refer a shape
-  TDF_LabelSequence Labels;
-  if ( GetUsers ( L, Labels, Standard_True ) ) {
-    for ( Standard_Integer i=Labels.Length(); i >=1; i-- ) 
-      UpdateAssembly ( Labels(i) );
-  }
+
+  UpdateAssociatedAssembly(L);
 }
 
 //=======================================================================
@@ -991,6 +997,26 @@ void XCAFDoc_ShapeTool::RemoveComponent (const TDF_Label& comp) const
   }
 }
 
+//=======================================================================
+//function : UpdateAssociatedAssembly
+//purpose  : 
+//=======================================================================
+
+void XCAFDoc_ShapeTool::UpdateAssociatedAssembly (const TDF_Label& L) const
+{
+  TDF_LabelSequence Labels;
+  if ( GetUsers ( L, Labels ) ) {
+    for ( Standard_Integer i=Labels.Length(); i >=1; i-- ) 
+    {
+      TDF_Label anAssemblyLabel = Labels(i).Father();
+      if(!anAssemblyLabel.IsNull())
+      {
+        UpdateAssembly(anAssemblyLabel);
+      }
+    }
+  }
+}
+
 //=======================================================================
 //function : UpdateAssembly
 //purpose  : 
@@ -1000,19 +1026,38 @@ void XCAFDoc_ShapeTool::UpdateAssembly (const TDF_Label& L) const
 {
   if ( ! IsAssembly(L) ) return;
 
-  TopoDS_Compound newassembly;
   BRep_Builder b;
-  b.MakeCompound(newassembly);
+  TopoDS_Shape aShape = GetShape(L);
+  Standard_Boolean isFree = aShape.Free();
+  if (!isFree)
+    aShape.Free(Standard_True);
+
+  TopTools_SequenceOfShape aSubShapeSeq;
+  TopoDS_Iterator Iterator(aShape);
+  for (; Iterator.More(); Iterator.Next())
+    aSubShapeSeq.Append(Iterator.Value());
+
+  for (Standard_Integer i = 1; i <= aSubShapeSeq.Length(); i++) 
+    b.Remove(aShape, aSubShapeSeq.Value(i));
 
   TDF_ChildIterator chldLabIt(L);
   for (; chldLabIt.More(); chldLabIt.Next() ) {
     TDF_Label subLabel = chldLabIt.Value();
     if ( IsComponent ( subLabel ) ) {
-      b.Add(newassembly, GetShape(subLabel));
+      b.Add(aShape, GetShape(subLabel));
     }
   }
+
+  if (!isFree)
+    aShape.Free(Standard_False);
+
   TNaming_Builder tnBuild(L);
-  tnBuild.Generated(newassembly);
+  tnBuild.Generated(aShape);
+
+  Handle(XCAFDoc_ShapeMapTool) A = XCAFDoc_ShapeMapTool::Set(L);
+  A->SetShape(aShape);
+
+  UpdateAssociatedAssembly(L);
 }
 
 //=======================================================================
index 77299d0..d7d5c1d 100644 (file)
@@ -109,7 +109,8 @@ static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, c
 //  XCAFDoc_ShapeTool myAssembly;
 //  myAssembly.Init(Doc);
   Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
-  myAssembly->SetShape(aLabel, aShape);
+  if( !myAssembly->IsAssembly(aLabel))
+    myAssembly->SetShape(aLabel, aShape);
   return 0;
 }
 
index 4155ca9..53b527d 100755 (executable)
@@ -7,7 +7,7 @@ puts ""
 #######################################################################
 
 set BugNumber OCC22962
-set check_value 94
+set check_value 96
 pload DCAF
 
 ReadStep D1 [locate_data_file OCC22962-dm1-oc-214.stp]
diff --git a/tests/bugs/xde/bug25441 b/tests/bugs/xde/bug25441
new file mode 100644 (file)
index 0000000..344a7fb
--- /dev/null
@@ -0,0 +1,22 @@
+puts "========"
+puts "OCC25441"
+puts "========"
+puts ""
+###########################################################################
+# XCAFDoc_ShapeTool::UpdateAssembly() does not update the back-references
+###########################################################################
+
+pload OCAFKERNEL
+
+box b 0 0 0 1 1 1
+psphere b1 10
+NewDocument d
+compound b c
+compound c c1
+XAddShape d c1 1
+XShow d
+XSetShape d 0:1:1:3 b1
+XShow d
+vfit
+
+set only_screen 1
diff --git a/tests/bugs/xde/bug26314 b/tests/bugs/xde/bug26314
new file mode 100644 (file)
index 0000000..f7ab90b
--- /dev/null
@@ -0,0 +1,23 @@
+puts "========"
+puts "OCC26314"
+puts "========"
+puts ""
+############################################################
+# Method XCAFDoc_ShapeTool::SetShape() works not correctly
+############################################################
+
+pload OCAFKERNEL
+
+box b 0 0 0 1 1 1
+box b1 -10 -10 -10 10 10 10
+box b2 1 1 1 10 10 10
+NewDocument d
+compound b1 c1
+XAddShape d b 1
+XAddShape d c1 1
+XShow d
+XSetShape d 0:1:1:3 b2
+XShow d
+vfit
+
+set only_screen 1