0023562: nbshapes command works incorrect with the attached shapes
authoremv <emv@opencascade.com>
Fri, 28 Dec 2012 13:55:30 +0000 (17:55 +0400)
committeremv <emv@opencascade.com>
Fri, 28 Dec 2012 13:55:30 +0000 (17:55 +0400)
This option allows to see the number of sub-shapes counting the same sub-shapes with different location as different sub-shapes.
Adding test cases for this fix

src/DBRep/DBRep.cxx
tests/bugs/demo/bug23562_1 [new file with mode: 0755]
tests/bugs/demo/bug23562_2 [new file with mode: 0755]
tests/bugs/demo/bug23562_3 [new file with mode: 0755]
tests/bugs/demo/bug23562_4 [new file with mode: 0755]
tests/bugs/demo/bug23562_5 [new file with mode: 0755]
tests/bugs/demo/bug23562_6 [new file with mode: 0755]
tests/bugs/demo/end [new file with mode: 0755]

index 5283110..1888392 100755 (executable)
@@ -801,25 +801,69 @@ static Standard_Integer numshapes(Draw_Interpretor& di,
   return 0;
 }
 
+//=======================================================================
+// function : DumpExtent
+// purpose  : Dumps the number of sub-shapes in <aStr>.
+//=======================================================================
+static void DumpExtent(const TopoDS_Shape& aS,
+                       TCollection_AsciiString& aStr)
+{
+  const int aNbTypes=8;
+  const char *pNames[aNbTypes+1]={
+    " SHAPE     : ",
+    " COMPOUND  : ",
+    " COMPSOLID : ",
+    " SOLID     : ",
+    " SHELL     : ",
+    " FACE      : ",
+    " WIRE      : ",
+    " EDGE      : ",
+    " VERTEX    : "
+  };
+  Standard_Integer i, aNb, aNbSh;
+  TopAbs_ShapeEnum aType;
+  TopTools_IndexedMapOfShape aM;
+  //
+  aNbSh=0;
+  //
+  for (i=aNbTypes-1; i>=0; --i) {
+    aM.Clear();
+    aType=(TopAbs_ShapeEnum)i;
+    TopExp::MapShapes(aS, aType, aM);
+    aNb=aM.Extent();
+    aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n";
+    aNbSh+=aNb;
+  }
+  aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n";
+}
+
 //=======================================================================
 // nbshapes
 //=======================================================================
 
 static Standard_Integer nbshapes(Draw_Interpretor& di,
-                                Standard_Integer n, const char** a)
+                                 Standard_Integer n, const char** a)
 {
   if (n < 2) return 1;
 
   Standard_Integer i;
+  Standard_Boolean aTotal;
   TopExp_Explorer ex;
+  //
+  aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False;
+  //
   for (i = 1; i < n; i++) {
     TopoDS_Shape S = DBRep::Get(a[i]);
     if (!S.IsNull()) {
-      BRepTools_ShapeSet BS;
-      BS.Add(S);
       di<<"Number of shapes in "<<a[i]<<"\n";
       TCollection_AsciiString Astr; 
-      BS.DumpExtent(Astr);
+      if (aTotal) {
+        DumpExtent(S, Astr);
+      } else {
+        BRepTools_ShapeSet BS;
+        BS.Add(S);
+        BS.DumpExtent(Astr);
+      }
       di<<Astr.ToCString();
     }
   }
@@ -1160,7 +1204,9 @@ void  DBRep::BasicCommands(Draw_Interpretor& theCommands)
   theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g);
   theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g);
   theCommands.Add("normals","normals s (length = 10), disp normals",__FILE__,normals,g);
-  theCommands.Add("nbshapes","nbshapes s; size of shape",__FILE__,nbshapes,g);
+  theCommands.Add("nbshapes",
+                  "\n nbshapes s - shows the number of sub-shapes in <s>;\n nbshapes s -t - shows the number of sub-shapes in <s> counting the same sub-shapes with different location as different sub-shapes.",
+                  __FILE__,nbshapes,g);
   theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g);
   theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g);
 
diff --git a/tests/bugs/demo/bug23562_1 b/tests/bugs/demo/bug23562_1
new file mode 100755 (executable)
index 0000000..fc2824e
--- /dev/null
@@ -0,0 +1,20 @@
+puts "============"
+puts "CR23562"
+puts "============"
+puts ""
+##########################################################################################################
+# nbshapes command works incorrect with the attached shapes
+##########################################################################################################
+
+restore [locate_data_file bug23562_V3.brep] result
+set nb_info [nbshapes result]
+
+set nb_v_good 25
+set nb_e_good 45
+set nb_w_good 15
+set nb_f_good 15
+set nb_sh_good 1
+set nb_sol_good 1
+set nb_compsol_good 0
+set nb_compound_good 1
+set nb_shape_good 103
diff --git a/tests/bugs/demo/bug23562_2 b/tests/bugs/demo/bug23562_2
new file mode 100755 (executable)
index 0000000..5c85014
--- /dev/null
@@ -0,0 +1,20 @@
+puts "============"
+puts "CR23562"
+puts "============"
+puts ""
+##########################################################################################################
+# nbshapes command works incorrect with the attached shapes
+##########################################################################################################
+
+restore [locate_data_file bug23562_V4.brep] result
+set nb_info [nbshapes result]
+
+set nb_v_good 24
+set nb_e_good 43
+set nb_w_good 20
+set nb_f_good 20
+set nb_sh_good 1
+set nb_sol_good 1
+set nb_compsol_good 0
+set nb_compound_good 1
+set nb_shape_good 110
diff --git a/tests/bugs/demo/bug23562_3 b/tests/bugs/demo/bug23562_3
new file mode 100755 (executable)
index 0000000..c8e2653
--- /dev/null
@@ -0,0 +1,20 @@
+puts "============"
+puts "CR23562"
+puts "============"
+puts ""
+##########################################################################################################
+# nbshapes command works incorrect with the attached shapes
+##########################################################################################################
+
+restore [locate_data_file bug23562_V3.brep] result
+set nb_info [nbshapes result -t]
+
+set nb_v_good 31
+set nb_e_good 51
+set nb_w_good 16
+set nb_f_good 16
+set nb_sh_good 1
+set nb_sol_good 1
+set nb_compsol_good 0
+set nb_compound_good 1
+set nb_shape_good 117
diff --git a/tests/bugs/demo/bug23562_4 b/tests/bugs/demo/bug23562_4
new file mode 100755 (executable)
index 0000000..bb9564a
--- /dev/null
@@ -0,0 +1,20 @@
+puts "============"
+puts "CR23562"
+puts "============"
+puts ""
+##########################################################################################################
+# nbshapes command works incorrect with the attached shapes
+##########################################################################################################
+
+restore [locate_data_file bug23562_V4.brep] result
+set nb_info [nbshapes result -t]
+
+set nb_v_good 30
+set nb_e_good 49
+set nb_w_good 21
+set nb_f_good 21
+set nb_sh_good 1
+set nb_sol_good 1
+set nb_compsol_good 0
+set nb_compound_good 1
+set nb_shape_good 124
diff --git a/tests/bugs/demo/bug23562_5 b/tests/bugs/demo/bug23562_5
new file mode 100755 (executable)
index 0000000..6ddf5a7
--- /dev/null
@@ -0,0 +1,22 @@
+puts "============"
+puts "CR23562"
+puts "============"
+puts ""
+##########################################################################################################
+# nbshapes command works incorrect with the attached shapes
+##########################################################################################################
+
+restore [locate_data_file bug23562_V3.brep] a
+explode a f
+compound a_1 a_16 result
+set nb_info [nbshapes result]
+
+set nb_v_good 6
+set nb_e_good 6
+set nb_w_good 1
+set nb_f_good 1
+set nb_sh_good 0
+set nb_sol_good 0
+set nb_compsol_good 0
+set nb_compound_good 1
+set nb_shape_good 15
diff --git a/tests/bugs/demo/bug23562_6 b/tests/bugs/demo/bug23562_6
new file mode 100755 (executable)
index 0000000..b75edd9
--- /dev/null
@@ -0,0 +1,22 @@
+puts "============"
+puts "CR23562"
+puts "============"
+puts ""
+##########################################################################################################
+# nbshapes command works incorrect with the attached shapes
+##########################################################################################################
+
+restore [locate_data_file bug23562_V3.brep] a
+explode a f
+compound a_1 a_16 result
+set nb_info [nbshapes result -t]
+
+set nb_v_good 12
+set nb_e_good 12
+set nb_w_good 2
+set nb_f_good 2
+set nb_sh_good 0
+set nb_sol_good 0
+set nb_compsol_good 0
+set nb_compound_good 1
+set nb_shape_good 29
diff --git a/tests/bugs/demo/end b/tests/bugs/demo/end
new file mode 100755 (executable)
index 0000000..d2a6600
--- /dev/null
@@ -0,0 +1,114 @@
+if { [isdraw result] } {
+   
+   if { [info exists square] } {
+      set prop "square"
+      set mass $square
+      regexp {Mass +: +([-0-9.+eE]+)} [sprops result] full m      
+   }
+   if { [info exists length] } {
+      set prop "length"
+      set mass $length
+      regexp {Mass +: +([-0-9.+eE]+)} [lprops result] full m      
+   }
+   if { [info exists mass] } {
+      #if mass (length or square) is empty in test case then result should be an empty shape.
+      if { [string compare "$mass" "empty"] != 0 } {
+        if { $m == 0 } {
+                   puts "Error : The $command is not valid. The $prop is 0."
+        }
+        if { $mass > 0 } {
+           puts "The expected $prop is $mass"
+        }
+        #check of change of square is < 1%
+        if { ($mass != 0 && [expr 1.*abs($mass - $m)/$mass] > 0.01) || ($mass == 0 && $m != 0) } {
+           puts "Error : The $prop of result shape is $m"
+        }
+      } else {
+       if { $m != 0 } {
+                  puts "Error : The $command is not valid. The $prop is $m"
+       }
+      }
+   }
+    
+   if { [info exists nb_v_good] } {
+      regexp {VERTEX +: +([-0-9.+eE]+)} $nb_info full nb_v
+       if { ${nb_v} != ${nb_v_good} } {
+         puts "Error : Result shape is WRONG because it must contains ${nb_v_good} vertexes instead of ${nb_v}"
+       } else {
+         puts "Result shape contains ${nb_v} vertexes"
+       }
+    }
+
+    if { [info exists nb_e_good] } {
+       regexp {EDGE +: +([-0-9.+eE]+)} $nb_info full nb_e
+       if { ${nb_e} != ${nb_e_good} } {
+           puts "Error : Result shape is WRONG because it must contains ${nb_e_good} edges instead of ${nb_e}"
+        } else {
+           puts "Result shape contains ${nb_e} edges"
+       }
+    }
+
+    if { [info exists nb_w_good] } {
+       regexp {WIRE +: +([-0-9.+eE]+)} $nb_info full nb_w
+       if { ${nb_w} != ${nb_w_good} } {
+           puts "Error : Result shape is WRONG because it must contains ${nb_w_good} wires instead of ${nb_w}"
+        } else {
+           puts "Result shape contains ${nb_w} wires"
+       }
+    }
+
+    if { [info exists nb_f_good] } {
+       regexp {FACE +: +([-0-9.+eE]+)} $nb_info full nb_f
+       if { ${nb_f} != ${nb_f_good} } {
+           puts "Error : Result shape is WRONG because it must contains ${nb_f_good} faces instead of ${nb_f}"
+        } else {
+           puts "Result shape contains ${nb_f} faces"
+       }
+    }
+
+    if { [info exists nb_sh_good] } {
+       regexp {SHELL +: +([-0-9.+eE]+)} $nb_info full nb_sh
+       if { ${nb_sh} != ${nb_sh_good} } {
+           puts "Error : Result shape is WRONG because it must contains ${nb_sh_good} shells instead of ${nb_sh}"
+        } else {
+           puts "Result shape contains ${nb_sh} shells"
+       }
+    }
+
+    if { [info exists nb_sol_good] } {
+       regexp {SOLID +: +([-0-9.+eE]+)} $nb_info full nb_sol
+       if { ${nb_sol} != ${nb_sol_good} } {
+           puts "Error : Result shape is WRONG because it must contains ${nb_sol_good} solids instead of ${nb_sol}"
+        } else {
+           puts "Result shape contains ${nb_sol} solids"
+       }
+    }
+
+    if { [info exists nb_compsol_good] } {
+       regexp {COMPSOLID +: +([-0-9.+eE]+)} $nb_info full nb_compsol
+       if { ${nb_compsol} != ${nb_compsol_good} } {
+           puts "Error : Result shape is WRONG because it must contains ${nb_compsol_good} compsolids instead of ${nb_compsol}"
+        } else {
+           puts "Result shape contains ${nb_compsol} compsolids"
+       }
+    }
+
+    if { [info exists nb_compound_good] } {
+       regexp {COMPOUND +: +([-0-9.+eE]+)} $nb_info full nb_compound
+       if { ${nb_compound} != ${nb_compound_good} } {
+           puts "Error : Result shape is WRONG because it must contains ${nb_compound_good} compounds instead of ${nb_compound}"
+        } else {
+           puts "Result shape contains ${nb_compound} compounds"
+       }
+    }
+
+    if { [info exists nb_shape_good] } {
+       regexp {SHAPE +: +([-0-9.+eE]+)} $nb_info full nb_shape
+       if { ${nb_shape} != ${nb_shape_good} } {
+           puts "Error : Result shape is WRONG because it must contains ${nb_shape_good} shapes instead of ${nb_shape}"
+        } else {
+           puts "Result shape contains ${nb_shape} shapes"
+       }
+    }
+
+}