[cgma-dev] r2288 - in cgm/trunk/geom: . OCC

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Wed Nov 26 12:02:34 CST 2008


Author: kraftche
Date: 2008-11-26 12:02:34 -0600 (Wed, 26 Nov 2008)
New Revision: 2288

Modified:
   cgm/trunk/geom/GeometryQueryEngine.hpp
   cgm/trunk/geom/OCC/OCCQueryEngine.cpp
   cgm/trunk/geom/OCC/OCCQueryEngine.hpp
   cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp
   cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp
Log:
o 'print_results' argument to GeometryQueryEngine::import_solid_model is for
  disabling error output when doing things like trying every engine until
  one succeeds in importing a file.  Add comment to GeometryQueryEngine.hpp
  specifying this.

o Remove OCC code that printed rather verbose debugging output if the
  'print_results' argument is true (so I can see why tests are failing
  w/out having to redirect output to a file.)

o Disable a couple of OCC error messages on file import if 'print_results'
  is false.

o Fix buffer overflow vulnerability in OCC file import code.

o Change OCC file import to use std::ifstream instead of constructing
  a std::istream from a std::filebuf (functionally the same, but 
  more concise.)



Modified: cgm/trunk/geom/GeometryQueryEngine.hpp
===================================================================
--- cgm/trunk/geom/GeometryQueryEngine.hpp	2008-11-26 16:57:18 UTC (rev 2287)
+++ cgm/trunk/geom/GeometryQueryEngine.hpp	2008-11-26 18:02:34 UTC (rev 2288)
@@ -114,6 +114,10 @@
      //-    "ACIS_SAB"    --  ACIS BINARY (SAB) file format
      //-    "IGES"        --  IGES file
      //-    "STEP"        --  STEP file
+     //O imported_entities
+     //O- List of top-level entities read from file
+     //I print_results
+     //I- If false, fail silently (don't write error messages to stdout or stderr)
      //I heal_step - auto-healing of step bodies on import.  This is recommended
      //              because they always need it.
      //I import_bodies (etc...)

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-11-26 16:57:18 UTC (rev 2287)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-11-26 18:02:34 UTC (rev 2288)
@@ -128,7 +128,6 @@
 typedef std::map<int, TopologyBridge*>::value_type valType;
 int OCCQueryEngine::iTotalTBCreated = 0;
 int OCCQueryEngine::total_coedges = 0;
-CubitBoolean OCCQueryEngine::PRINT_RESULT = CUBIT_FALSE;
 //================================================================================
 // Description:
 // Author     :
@@ -1080,15 +1079,18 @@
                                    
 CubitBoolean OCCQueryEngine::Read(TopoDS_Shape& Sh,
                                   const Standard_CString File,
-                                  TDF_Label label)
+                                  TDF_Label label,
+                                  CubitBoolean print_results)
 {
-  filebuf fic;
-  istream in(&fic);
-  //  if (!fic.open(File,input)) return Standard_False;
-  if (!fic.open(File, ios::in)) return Standard_False;
+  ifstream in( File );
+  if (!in) {
+    if (print_results) 
+      PRINT_INFO("%s: Cannot open file", File );
+    return CUBIT_FAILURE;
+  }
 
   OCCShapeAttributeSet SS;
-  SS.Read(in, label);
+  SS.Read(in, label, print_results);
   int nbshapes = SS.NbShapes();
   if(!nbshapes) return CUBIT_FALSE;
   SS.Read(Sh,in,nbshapes);
@@ -1131,14 +1133,10 @@
 {
   TopoDS_Shape *aShape = new TopoDS_Shape;
   BRep_Builder aBuilder;
-  Standard_Boolean result = Read(*aShape, (char*) file_name, mainLabel);
+  Standard_Boolean result = Read(*aShape, (char*) file_name, mainLabel, print_results);
   if (result==0) return CUBIT_FAILURE;
   
-  CubitBoolean prev_global_val = PRINT_RESULT;
-  PRINT_RESULT = print_results;
-  
   imported_entities = populate_topology_bridge(*aShape);
-  PRINT_RESULT = prev_global_val;
   return CUBIT_SUCCESS;
 }
 
@@ -1197,8 +1195,6 @@
   OCCBody *body;
   if (!OCCMap->IsBound(aShape))
     {
-      if(PRINT_RESULT)
-	PRINT_INFO("Adding Bodies.\n");
       TopoDS_CompSolid *posolid =  new TopoDS_CompSolid;
       *posolid = aShape;
       (iTotalTBCreated)++;
@@ -1236,8 +1232,6 @@
   OCCBody *body;
   if (!OCCMap->IsBound(aShape))
   {
-    if(PRINT_RESULT)
-      PRINT_INFO("Adding solids.\n");
     TopoDS_Solid *posolid =  new TopoDS_Solid;
     *posolid = aShape;
     iTotalTBCreated++;
@@ -1282,8 +1276,6 @@
   DLIList<OCCCoFace*> cofaces_old, cofaces_new;
   if (!OCCMap->IsBound(aShape))
   {
-    if(PRINT_RESULT)
-      PRINT_INFO("Adding shells.\n");
     TopoDS_Shell *poshell = new TopoDS_Shell;
     *poshell = aShape;
     iTotalTBCreated++;
@@ -1372,8 +1364,7 @@
       delete surface;
       return (Surface*) NULL;
     } 
-    if(PRINT_RESULT)
-      PRINT_INFO("Adding faces.\n");
+
     iTotalTBCreated++;
     OCCMap->Bind(*poface, iTotalTBCreated);
     OccToCGM->insert(valType(iTotalTBCreated,
@@ -1417,8 +1408,6 @@
   OCCLoop *loop ;
   if (!OCCMap->IsBound(aShape))
     {
-      if(PRINT_RESULT)
-	PRINT_INFO("Adding loops.\n");
       TopoDS_Wire *powire = new TopoDS_Wire;
       *powire = aShape;
       iTotalTBCreated++;
@@ -1528,8 +1517,6 @@
   Curve *curve;
   if (!OCCMap->IsBound(aShape)) 
     {
-      if(PRINT_RESULT)
-	PRINT_INFO("Adding edges.\n");
       TopoDS_Edge *poedge = new TopoDS_Edge;
       *poedge = aShape;
       iTotalTBCreated++;
@@ -1563,8 +1550,6 @@
   OCCPoint *point;
   if (iTotalTBCreated == 0 || !OCCMap->IsBound(aShape)) 
     {
-      if(PRINT_RESULT)
-	PRINT_INFO("Adding vertices.\n");
       TopoDS_Vertex *povertex = new TopoDS_Vertex;
       *povertex = aShape;
       iTotalTBCreated++;

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.hpp	2008-11-26 16:57:18 UTC (rev 2287)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.hpp	2008-11-26 18:02:34 UTC (rev 2288)
@@ -392,10 +392,9 @@
 
   CubitBoolean Read(TopoDS_Shape& Sh,
                     const Standard_CString File,
-                    TDF_Label label);
+                    TDF_Label label,
+                    bool print_results);
 
-  static CubitBoolean PRINT_RESULT;
-
   static OCCQueryEngine* instance_;
     //- static pointer to unique instance of this class
 

Modified: cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp	2008-11-26 16:57:18 UTC (rev 2287)
+++ cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp	2008-11-26 18:02:34 UTC (rev 2288)
@@ -678,7 +678,8 @@
 //=======================================================================
 
 void  OCCShapeAttributeSet::Read(Standard_IStream& IS,
-                                 TDF_Label& l_attr) 
+                                 TDF_Label& l_attr,
+                                 bool print_results) 
 {
  // on sauvegarde l'ancien LC_NUMERIC
   char *oldnum,*plocal ;
@@ -703,7 +704,8 @@
 
   } while ( ! IS.fail() && strcmp(vers,dVersion) && strcmp(vers,dVersion2) );
   if (IS.fail()) {
-    cout << "File was not written with this version of the topology"<<endl;
+    if (print_results)
+      cout << "File was not written with this version of the topology"<<endl;
     setlocale(LC_NUMERIC, oldnum) ;
     delete[] oldnum;
     return;
@@ -727,10 +729,11 @@
   // read the shapes
   //-----------------------------------------
 
-  char buffer[255];
+  std::string buffer;
   IS >> buffer;
-  if (strcmp(buffer,"TShapes")) {
-    cout << "Not a TShape table"<<endl;
+  if (buffer != "TShapes") {
+    if (print_results)
+      cout << "Not a TShape table"<<endl;
     setlocale(LC_NUMERIC, oldnum) ;
     delete[] oldnum;
     return;

Modified: cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp	2008-11-26 16:57:18 UTC (rev 2287)
+++ cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp	2008-11-26 18:02:34 UTC (rev 2288)
@@ -87,7 +87,7 @@
 void Write(Standard_OStream& OS,
            TDF_Label l_attr)const;
 
-void Read(Standard_IStream& IS, TDF_Label& l_attr);
+void Read(Standard_IStream& IS, TDF_Label& l_attr, bool print);
 
 void Read(TopoDS_Shape& S,Standard_IStream& IS, const int nbshapes)const;
 




More information about the cgma-dev mailing list