0031313: Foundation Classes - Dump improvement for classes
[occt.git] / src / XDEDRAW / XDEDRAW_Props.cxx
index 64c818c..dcb270c 100644 (file)
@@ -79,7 +79,7 @@ static double TetraVol(gp_Pnt RefPoint, gp_Pnt Som1, gp_Pnt Som2, gp_Pnt Som3)
        N=v1^v2;
        Plane123=gp_Pln( Som1, gp_Dir( N ) );
       }
-    catch(Standard_Failure) {return(0.);}
+    catch(Standard_Failure const&) {return(0.);}
   }
   double L1, L2, L3;
   L1 = Som1.Distance(Som2);
@@ -575,7 +575,7 @@ static Standard_Integer CheckProps (Draw_Interpretor& di, Standard_Integer argc,
                 ( wholeDoc ? "" : "\n" ));
        di << string2;
       }
-      catch (Standard_Failure) {
+      catch (Standard_Failure const&) {
        //printf ( "%-16.16s", "exception" );
        char string3[260];
        Sprintf (string3, "%-16.16s", "exception" );
@@ -652,7 +652,7 @@ static Standard_Integer CheckProps (Draw_Interpretor& di, Standard_Integer argc,
          di << string8;
        }
       }
-      catch (Standard_Failure) {
+      catch (Standard_Failure const& anException) {
        //printf ( "%40.40s", "exception" );
        char string9[260];
        Sprintf (string9, "%40.40s", "exception" );
@@ -660,9 +660,10 @@ static Standard_Integer CheckProps (Draw_Interpretor& di, Standard_Integer argc,
 #ifdef OCCT_DEBUG
        //fflush ( stdout );
        di << ": ";
-       di << Standard_Failure::Caught()->GetMessageString();
+       di << anException.GetMessageString();
        di<<" ** Skip\n";
 #endif
+       (void)anException;
       }
     }
     else if ( wholeDoc ) {
@@ -707,9 +708,9 @@ static Standard_Integer ShapeVolume (Draw_Interpretor& di, Standard_Integer argc
     tol = -tol;
   }
   localVolume = CalculVolume(aShape, aPoint, tol, withForce, di);
-  //cout << "Volume : " << setw(15) << localVolume << "\n" << endl;
+  //std::cout << "Volume : " << std::setw(15) << localVolume << "\n" << std::endl;
   Standard_SStream aSStream;
-  aSStream << "Volume : " << setw(15) << localVolume << "\n";
+  aSStream << "Volume : " << std::setw(15) << localVolume << "\n";
   di << aSStream;
   return 0;
 }
@@ -897,6 +898,96 @@ static Standard_Integer SetMaterial (Draw_Interpretor& di, Standard_Integer argc
   return 0;
 }
 
+static Standard_Integer GetValidationProps(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+  if (argc< 2) {
+    di<<"Use: "<<argv[0]<<" Doc {Label|Shape}\n";
+    return 1;
+  }
+  Handle(TDocStd_Document) Doc;   
+  DDocStd::GetDocument(argv[1], Doc);
+  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
+  Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
+  TDF_LabelSequence aLabels;
+  if( argc == 2)
+    STool->GetShapes (aLabels);
+  else
+  {
+    TDF_Label aLabel;
+    TopoDS_Shape aShape = DBRep::Get(argv[2]);
+    if( aShape.IsNull())
+    {
+      TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
+    }
+    else
+    {
+      aLabel = STool->FindShape(aShape);
+    }
+    if( !aLabel.IsNull())
+      aLabels.Append(aLabel);
+  }
+   
+  
+  enum
+  {
+    Vol =0,
+    Area = 1,
+    Centroid = 2
+  };
+  Standard_Integer nbProps[3];
+  Standard_Integer j =0;
+  for( ; j <= Centroid; j++)
+    nbProps[j] = 0;
+  Standard_Integer i = 1;
+  for( ; i <= aLabels.Length() ; i++)
+  {
+    TDF_Label aLabel = aLabels(i);
+    
+    Standard_Real aProp[2];
+    
+    aProp[0] = 0.;
+    aProp[1] = 0.;
+    
+
+    gp_Pnt aP(Precision::Infinite(), Precision::Infinite(), Precision::Infinite());
+    XCAFDoc_Volume::Get(aLabel, aProp[Vol]);
+    XCAFDoc_Area::Get(aLabel, aProp[Area]);
+
+    Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
+    if (aLabel.FindAttribute (XCAFDoc_Centroid::GetID(), aCentroid)) 
+      XCAFDoc_Centroid::Get(aLabel, aP);
+        
+    if(aProp[Vol] > 0 || aProp[Area] > 0 || !Precision::IsInfinite(aP.X()) )
+    {
+      TCollection_AsciiString str;
+      TDF_Tool::Entry ( aLabel, str );
+      di<<"Label : "<<str;
+      
+      for(j = 0 ; j <= Area; j++)
+      {
+        if( aProp[j] > 0)
+        {
+          di<<(j == Vol ? "; Volume - " : "; Area - ")<<aProp[j];
+          nbProps[j]++;
+        }
+      }
+
+      if( !Precision::IsInfinite(aP.X()) )
+      {      
+        di<< "; Centroid -  "<< aP.X()<<" "<<aP.Y()<<" "<<aP.Z();
+        nbProps[Centroid]++;
+      }
+       di<<"\n";
+    }
+  }
+  di<<"========================================================="<<"\n";
+  di<< "Number of the validation properties : ";
+  for( i = Vol; i <= Centroid; i++)
+    di<< ( i == Vol ? "Volume" : (i == Area ? "Area" : "Centroid"))<<" : "<<nbProps[i]<<" ; "; 
+    
+  di<<"\n";
+  return 0;
+}
 
 //=======================================================================
 //function : InitCommands
@@ -905,9 +996,12 @@ static Standard_Integer SetMaterial (Draw_Interpretor& di, Standard_Integer argc
 
 void XDEDRAW_Props::InitCommands(Draw_Interpretor& di) 
 {
-
   static Standard_Boolean initactor = Standard_False;
-  if (initactor) return;  initactor = Standard_True;
+  if (initactor)
+  {
+    return;
+  }
+  initactor = Standard_True;
 
   Standard_CString g = "XDE property's commands";
   
@@ -940,5 +1034,6 @@ void XDEDRAW_Props::InitCommands(Draw_Interpretor& di)
                   __FILE__,ShapeMassProps , g);
   di.Add ("XSetMaterial","Doc {Label|Shape} name density(g/cu sm) \t: Set material to shape given by Label",
                   __FILE__, SetMaterial, g);
-
+  di.Add ("XGetValProps","Doc {Label|Shape}",__FILE__, GetValidationProps, g);
 }