[cgma-dev] r2790 - cgm/trunk/geom/OCC

jiangtao_ma at yahoo.com jiangtao_ma at yahoo.com
Wed Apr 1 13:38:49 CDT 2009


Author: janehu
Date: 2009-04-01 13:38:48 -0500 (Wed, 01 Apr 2009)
New Revision: 2790

Modified:
   cgm/trunk/geom/OCC/OCCQueryEngine.cpp
   cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp
   cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp
Log:
changed the brep file read/write format to append all attributes at the end of the brep file instead of embedded this info in each subshape. New format is portable to other software like salome.

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2009-03-31 20:39:12 UTC (rev 2789)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2009-04-01 18:38:48 UTC (rev 2790)
@@ -1117,10 +1117,10 @@
   SS.Add(Sh);
 
   os << "DBRep_DrawableShape\n";  // for easy Draw read
-  SS.Write(os, label);
+  SS.Write(os);
   isGood = os.good();
   if(isGood )
-    SS.Write(Sh,os);
+    SS.Write(Sh,os,&label);
   os.flush();
   isGood = os.good();
   os.close();
@@ -1143,10 +1143,10 @@
   }
 
   OCCShapeAttributeSet SS;
-  SS.Read(in, label, print_results);
+  SS.Read(in, print_results);
   int nbshapes = SS.NbShapes();
   if(!nbshapes) return CUBIT_FALSE;
-  SS.Read(Sh,in,nbshapes);
+  SS.Read(Sh,in,nbshapes, &label);
   return CUBIT_TRUE;
 }
 

Modified: cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp	2009-03-31 20:39:12 UTC (rev 2789)
+++ cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp	2009-04-01 18:38:48 UTC (rev 2790)
@@ -414,7 +414,7 @@
 
 void  OCCShapeAttributeSet::ReadAttribute(TopoDS_Shape& S,
                                           Standard_IStream&   IS,
-                                          TDF_Label& l_attr)
+                                          TDF_Label& l_attr)const
 {
   std::string buffer, type, stringdata;
   DLIList<CubitString*> strings;
@@ -429,22 +429,27 @@
     strings.clean_out();
     strings.append(string_prt);
 
-    IS >> buffer;
-    //consider there's only one string in the stringdata field
-    i = buffer.find_first_of("*");
-    if(i > 0)
-    {
-      stringdata = buffer.substr( 0, i );
-      CubitString* string_prt2 = new CubitString(stringdata.c_str());
-      strings.append(string_prt2);
-    }
+    char s = ' ';
+    do {
+      IS >> buffer;
+      i = buffer.find_first_of("*");
+      if(i > 0)
+      {
+        stringdata = buffer.substr( 0, i );
+        CubitString* string_prt2 = new CubitString(stringdata.c_str());
+        strings.append(string_prt2);
+      }
 
-    IS.get(); //' '
+      //check if next data is still string
+      IS.get(); //' '
+      IS.get(s); //either '*' or 'number' or a char
+      IS.unget();
+    } while(s!= '*' && !(s > '0' && s < '9'));
+    
     int tmp_int;
     double  tmp_dbl; 
     doubles.clean_out();
     ints.clean_out();
-    char s;
     IS.get(s); //either '*' or 'number'
     while (s != '\n')
     {
@@ -517,10 +522,16 @@
     }
   }
   if(!found)
+  {
+    OS << "\n*";
     return;
+  }
 
   if(!myLabel.HasChild())
+  {
+    OS << "\n*";
     return;
+  }
 
   for (TDF_ChildIterator it2(myLabel,Standard_False); it2.More(); it2.Next())
   {
@@ -582,8 +593,7 @@
 //purpose  :
 //=======================================================================
 
-void  OCCShapeAttributeSet::Write(Standard_OStream& OS,
-                                  TDF_Label l_attr)const
+void  OCCShapeAttributeSet::Write(Standard_OStream& OS)const
 {
   //on sauvegarde l'ancien LC_NUMERIC
   
@@ -634,9 +644,6 @@
     // Geometry
     WriteGeometry(S,OS);
 
-    // Attributes
-    WriteAttribute(S, OS, l_attr);
-
     // Flags
     OS << "\n";
     OS << (S.Free()       ? 1 : 0);
@@ -679,7 +686,6 @@
 //=======================================================================
 
 void  OCCShapeAttributeSet::Read(Standard_IStream& IS,
-                                 TDF_Label& l_attr,
                                  bool print_results) 
 {
  // on sauvegarde l'ancien LC_NUMERIC
@@ -751,15 +757,9 @@
     TopAbs_ShapeEnum T = ReadShapeEnum(IS);
     ReadGeometry(T,IS,S);
 
-    // Read Attributes and Set the flags
+    // Set the flags
     IS >> buffer;
 
-    while (buffer[0] == 'C')
-    {
-      ReadAttribute(S, IS,l_attr);
-      IS >> buffer;
-    }
-
     // sub-shapes
     TopoDS_Shape SS;
     do {
@@ -1175,7 +1175,8 @@
 //=======================================================================
 
 void  OCCShapeAttributeSet::Write(const TopoDS_Shape& S,
-                               Standard_OStream& OS)const
+                               Standard_OStream& OS,
+                               TDF_Label* l_attr)const
 {
   if (S.IsNull()) OS << "*";
   else {
@@ -1183,6 +1184,16 @@
     OS << myShapes.Extent() - myShapes.FindIndex(S.Located(TopLoc_Location())) + 1;
     OS << " " << myLocations.Index(S.Location()) << " ";
   }
+  //Write Attributes
+  Standard_Integer i, nbShapes = myShapes.Extent();
+  if(l_attr != NULL)
+  {
+    for ( i = 1; i <= nbShapes; i++)
+    {
+      const TopoDS_Shape& Sh = myShapes(i);
+      WriteAttribute(Sh, OS, *l_attr);
+    }
+  }
 }
 
 
@@ -1700,7 +1711,8 @@
 
 void  OCCShapeAttributeSet::Read(TopoDS_Shape& S,
                                  Standard_IStream& IS,
-                                 const int nbshapes)const
+                                 const int nbshapes,
+                                 TDF_Label* label )const
 {
   std::string buffer;
   IS >> buffer;
@@ -1735,6 +1747,18 @@
     IS >> l;
     S.Location(myLocations.Location(l));
   }
+  if(label != NULL)
+  {
+    Standard_Integer i, nbShapes = myShapes.Extent();
+    for ( i = 1; i <= nbShapes; i++)
+    {
+      TopoDS_Shape Sh = myShapes(i);
+      IS >> buffer;
+      if(buffer[0] == '*') //empty attributes for this shape
+        continue;
+      ReadAttribute(Sh, IS,*label);
+    }
+  }
 }
 
 //=======================================================================

Modified: cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp	2009-03-31 20:39:12 UTC (rev 2789)
+++ cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp	2009-04-01 18:38:48 UTC (rev 2790)
@@ -80,18 +80,18 @@
 
 void  ReadAttribute(TopoDS_Shape& S,
                     Standard_IStream&   IS,
-                    TDF_Label& l_attr);
+                    TDF_Label& l_attr)const;
 
 //! Stores <S> and its sub-shape. Returns the index of <S>. <br>
 //!          The method AddGeometry is called on each sub-shape. <br>
 Standard_Integer Add(const TopoDS_Shape& S) ;
 
-void Write(Standard_OStream& OS,
-           TDF_Label l_attr)const;
+void Write(Standard_OStream& OS)const;
 
-void Read(Standard_IStream& IS, TDF_Label& l_attr, bool print);
+void Read(Standard_IStream& IS, bool print);
 
-void Read(TopoDS_Shape& S,Standard_IStream& IS, const int nbshapes)const;
+void Read(TopoDS_Shape& S,Standard_IStream& IS, const int nbshapes,
+          TDF_Label* l_attr = NULL) const;
 
 //! Writes the geometry of  me  on the stream <OS> in a <br>
 //!          format that can be read back by Read. <br>
@@ -111,7 +111,8 @@
 //!          orientation, the index of the TShape and the index <br>
 //!          of the Location. <br>
 void Write(const TopoDS_Shape& S,
-           Standard_OStream& OS) const;
+           Standard_OStream& OS,
+           TDF_Label* l_attr = NULL) const;
 
 //! Writes the 3d polygons <br>
 //!          on the stream <OS> in a format that can <br>



More information about the cgma-dev mailing list