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

janehu at mcs.anl.gov janehu at mcs.anl.gov
Thu Jul 31 13:16:19 CDT 2008


Author: janehu
Date: 2008-07-31 13:16:18 -0500 (Thu, 31 Jul 2008)
New Revision: 2033

Added:
   cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp
   cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp
Modified:
   cgm/trunk/geom/OCC/Makefile.am
   cgm/trunk/geom/OCC/OCCAttrib.hpp
   cgm/trunk/geom/OCC/OCCAttribSet.cpp
   cgm/trunk/geom/OCC/OCCAttribSet.hpp
   cgm/trunk/geom/OCC/OCCBody.cpp
   cgm/trunk/geom/OCC/OCCBody.hpp
   cgm/trunk/geom/OCC/OCCCurve.cpp
   cgm/trunk/geom/OCC/OCCCurve.hpp
   cgm/trunk/geom/OCC/OCCLoop.cpp
   cgm/trunk/geom/OCC/OCCLump.cpp
   cgm/trunk/geom/OCC/OCCLump.hpp
   cgm/trunk/geom/OCC/OCCModifyEngine.hpp
   cgm/trunk/geom/OCC/OCCPoint.cpp
   cgm/trunk/geom/OCC/OCCPoint.hpp
   cgm/trunk/geom/OCC/OCCQueryEngine.cpp
   cgm/trunk/geom/OCC/OCCQueryEngine.hpp
   cgm/trunk/geom/OCC/OCCSurface.cpp
Log:
Added read-write attribute functionality.

Modified: cgm/trunk/geom/OCC/Makefile.am
===================================================================
--- cgm/trunk/geom/OCC/Makefile.am	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/Makefile.am	2008-07-31 18:16:18 UTC (rev 2033)
@@ -20,7 +20,7 @@
 
 # The non-template sources
 libcubit_OCC_la_SOURCES = \
-    OCCAttrib.cpp \
+    OCCShapeAttributeSet.cpp \
     OCCAttribSet.cpp \
     OCCBody.cpp \
     OCCCoEdge.cpp \
@@ -39,7 +39,7 @@
 # Headers to be installed.  If any file in this list should
 # not be installed, move it to the _SOURCES list above.
 libcubit_OCC_la_include_HEADERS = \
-    OCCAttrib.hpp \
+    OCCShapeAttributeSet.hpp \
     OCCAttribSet.hpp \
     OCCBody.hpp \
     OCCCoEdge.hpp \

Modified: cgm/trunk/geom/OCC/OCCAttrib.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCAttrib.hpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCAttrib.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -1,5 +1,5 @@
-#ifndef FACET_ATTRIB_HPP
-#define FACET_ATTRIB_HPP
+#ifndef OCC_ATTRIB_HPP
+#define OCC_ATTRIB_HPP
 
 #include "CubitDefines.h"
 #include "CubitString.hpp"

Modified: cgm/trunk/geom/OCC/OCCAttribSet.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCAttribSet.cpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCAttribSet.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -11,7 +11,8 @@
 //-------------------------------------------------------------------------
 
 #include "OCCAttribSet.hpp"
-#include "OCCAttrib.hpp"
+//#include "OCCAttrib.hpp"
+#include "OCCQueryEngine.hpp"
 #include "CubitSimpleAttrib.hpp"
 #include "CubitFileIOWrapper.hpp"
 #include "Handle_TDataStd_Shape.hxx"
@@ -28,293 +29,420 @@
 #include "TopoDS_Shape.hxx"
 #include "TDF_ChildIterator.hxx"
 
-void OCCAttribSet::append_attribute( CubitSimpleAttrib* csa, TopoDS_Shape& shape )
+void OCCAttribSet::FindShape(TopoDS_Shape& shape,
+                             TDF_Label& aLabel,
+                             CubitBoolean& found) 
 {
-  OCCAttrib* new_attrib = new OCCAttrib(csa);
-  new_attrib->listNext = listHead;
-  listHead = new_attrib;
-
-  TDF_Label child;
-  //Add attributes on child of myLabel
-  //1. add shape attribute, first check to make sure there's no shape attribute
-  CubitBoolean found = CUBIT_FALSE;
-  for (TDF_ChildIterator it1(myLabel, CUBIT_FALSE); it1.More(); it1.Next())
+  for (TDF_ChildIterator it1(OCCQueryEngine::instance()->mainLabel, CUBIT_FALSE);
+    it1.More(); it1.Next())
   {
-    //find the same type attribute first
-    child = it1.Value();
+    //find the same shape attribute first
+    aLabel = it1.Value();
 
     Handle_TDataStd_Shape attr_shape;
     TopoDS_Shape old_shape;
-    if(TDataStd_Shape::Find(child, attr_shape))
-      old_shape = attr_shape->Get(child);
-    if(old_shape.IsEqual(shape)) 
+    if(aLabel.FindAttribute(TDataStd_Shape::GetID(), attr_shape))
+      old_shape = attr_shape->Get(aLabel);
+    if(old_shape.IsSame(shape))
     {
       found = CUBIT_TRUE;
       break;
     }
   }
+}
 
+void OCCAttribSet::append_attribute( CubitSimpleAttrib* csa, TopoDS_Shape& shape )
+{
+  //Add attributes on child of myLabel
+  //1. add shape attribute, first check to make sure there's no shape attribute
+  CubitBoolean found = CUBIT_FALSE;
+  TDF_Label aLabel;
+
+  FindShape(shape, aLabel, found);
+
   if(!found)
   { 
-    child = myLabel.NewChild();
-    Handle_TDataStd_Shape attr_shape = TDataStd_Shape::Set(child, shape);
-    child.AddAttribute(attr_shape);
+    aLabel = OCCQueryEngine::instance()->mainLabel.NewChild();
+    Handle_TDataStd_Shape attr_shape = TDataStd_Shape::Set(aLabel, shape);
+    //myLabel.AddAttribute(attr_shape);
+    //test if the attribute has been attached
+    assert(aLabel.IsAttribute(TDataStd_Shape::GetID()));
   }
 
-  //2. add type attribute , belowing attributes are added on child lable of child
-  //First create new child label
-  TDF_Label lab = child.NewChild();
-  
-  //Then add child labels
-  CubitString type = csa->character_type(); 
-  if(type.length() > 0)
+  //2. add type attribute , below attributes are added on child lable of myLabel
+  //First check if the attributes are already exist, if so, create new data.
+  TDF_Label lab;
+  Handle_TDataStd_Name attr_name;
+  TCollection_ExtendedString name_string;
+  CubitString type = csa->character_type();
+  TCollection_ExtendedString cstring( (Standard_CString)type.c_str() );
+  found = CUBIT_FALSE;
+  for (TDF_ChildIterator it(aLabel,CUBIT_FALSE); it.More(); it.Next()) 
   {
-    TCollection_ExtendedString cstring( (Standard_CString)type.c_str() );
-    Handle_TDataStd_Name attr_name = TDataStd_Name::Set(lab, cstring);
-    lab.AddAttribute(attr_name);
+    lab = it.Value();
+    found = find_attribute(lab, csa);
+    if(!found)
+    {
+      //check if the type attribute is the same, disable it
+      TCollection_ExtendedString old_string;
+      if(lab.FindAttribute(TDataStd_Name::GetID(), attr_name))
+      {
+        old_string = attr_name->Get();
+
+        if(old_string == cstring)
+          lab.ForgetAllAttributes();
+      }
+    }
+    if(found)
+      break;
   }
 
+  //if not exist,  create new child label
+  if (!found)
+  {
+    lab = aLabel.NewChild();
+    attr_name = TDataStd_Name::Set(lab, cstring);
+    assert(lab.IsAttribute(TDataStd_Name::GetID()));
+  }
+     
+  else//nothing to do
+    return;
+
   //3. add string attribute
   DLIList<CubitString*>* strings = csa->string_data_list();
-  TDF_Label lab_child = lab.NewChild(); 
   Handle_TDataStd_ExtStringArray attr_string;
-  if(strings && strings->size() > 0)
+  int size = strings->size()-1;
+  if(strings && size > 0)
   {
-    //set the length of String Array be 11, can be extended.
-    attr_string = TDataStd_ExtStringArray::Set(lab_child, 0, 10);
+    //set the length of String Array .
+    attr_string = TDataStd_ExtStringArray::Set(lab, 0, size-1);
   }
-
-  for(int i = 0; strings && i < strings->size(); i++)
+  strings->reset();
+  strings->step(); //type string filters out
+  for(int i = 0; strings && i < size; i++)
   {
     TCollection_ExtendedString 
        cstring((Standard_CString)strings->get_and_step()->c_str() );
     attr_string->SetValue(i, cstring) ;
   }
-  if(strings && strings->size() > 0)
-    lab_child.AddAttribute(attr_string);
+  
+  if (strings && size > 0)
+    assert(lab.IsAttribute(TDataStd_ExtStringArray::GetID()));
 
   //4. add double attribute
   DLIList<double*>* doubles = csa->double_data_list();
   Handle_TDataStd_RealArray attr_double;
-  if(doubles && doubles->size() > 0)
+  size = doubles->size();
+  if(doubles && size > 0)
   {
-    //set the length of double array be 11, can be extended.
-    attr_double = TDataStd_RealArray::Set(lab_child,0, 10);
+    //set the length of double array .
+    attr_double = TDataStd_RealArray::Set(lab,0, size-1);
   } 
-
-  for(int i = 0; doubles && i < doubles->size(); i++)
+  doubles->reset();
+  for(int i = 0; doubles && i < size; i++)
     attr_double->SetValue(i, *(doubles->get_and_step()));
 
-  if(doubles && doubles->size() > 0)
-    lab_child.AddAttribute(attr_double);
+  if(doubles && size > 0)
+    assert(lab.IsAttribute(TDataStd_RealArray::GetID()));
     
   //5. add int attribute
   DLIList<int*>* ints = csa->int_data_list();
   Handle_TDataStd_IntegerArray attr_int;
-  if(ints && ints->size() > 0)
+  size = ints->size();
+  if(ints && size > 0)
   {
     //set the length of int array be 11, can be extended.
-    attr_int = TDataStd_IntegerArray::Set(lab_child, 0, 10);
+    attr_int = TDataStd_IntegerArray::Set(lab, 0, size-1);
   }
-
-  for(int i = 0; ints && i < ints->size(); i++)
+  ints->reset();
+  for(int i = 0; ints && i < size; i++)
     attr_int->SetValue(i, *(ints->get_and_step()));
 
-  if(ints && ints->size() > 0)
-    lab_child.AddAttribute(attr_int);
+  if(ints && size > 0)
+    assert(lab.IsAttribute(TDataStd_IntegerArray::GetID()));
 }
 
-void OCCAttribSet::remove_attribute( CubitSimpleAttrib* csa)
+CubitBoolean OCCAttribSet::find_attribute(TDF_Label child,
+                                          CubitSimpleAttrib* csa)
 {
-  if( !listHead )
-    return;
-    
-  OCCAttrib* attrib = 0;
-  if ( listHead->equals(csa) )
-  {
-    attrib = listHead;
-    listHead = listHead->listNext;
-    delete attrib;
-    return;
-  }
-  
-  for ( OCCAttrib* prev = listHead; prev->listNext; prev = prev->listNext )
-  {
-    if( prev->listNext->equals(csa) )
-    {
-      attrib = prev->listNext;
-      prev->listNext = attrib->listNext;
-      delete attrib;
-      return;
-    }
-  }
-
-  //forget csa attribute from the document
   DLIList<int*>* ints = csa->int_data_list();
   CubitString type = csa->character_type();
   TCollection_ExtendedString cstring( (Standard_CString)type.c_str() );
+  DLIList<double*>* doubles = csa->double_data_list();
+  DLIList<CubitString*>* strings = csa->string_data_list();
 
-  if(type.length() == 0)
-      return;
-
-  DLIList<double*>* doubles = csa->double_data_list();
-  DLIList<CubitString*>* strings = csa->string_data_list();  
-  for (TDF_ChildIterator it1(myLabel, CUBIT_TRUE); it1.More(); it1.Next())
+  //find the same type attribute first
+  Handle_TDataStd_Name attr_name;
+  TCollection_ExtendedString old_string;
+  if(child.FindAttribute(TDataStd_Name::GetID(), attr_name))
   {
-    //find the same type attribute first
-    TDF_Label child = it1.Value();
+    old_string = attr_name->Get();
 
-    Handle_TDataStd_Name attr_name;
-    TCollection_ExtendedString old_string;
-    if(child.FindAttribute(TDataStd_Name::GetID(), attr_name))
-      old_string = attr_name->Get(); 
+    if(old_string != cstring)
+      return CUBIT_FALSE;
+  }
 
-    if(old_string != cstring) 
-      continue; 
-  
-    //continue to compare the rest attributes.
-    CubitBoolean is_same = CUBIT_TRUE;
-    for(TDF_ChildIterator it2(child,CUBIT_FALSE); it2.More(); it2.Next())
+  else
+    return CUBIT_FALSE;
+
+  //continue to compare the rest attributes.
+  CubitBoolean is_same = CUBIT_TRUE;
+  if(ints->size() > 0 )
+  {
+    Handle_TDataStd_IntegerArray attr_ints;
+    if(child.FindAttribute(TDataStd_IntegerArray::GetID(), attr_ints) &&
+       attr_ints->Length() == ints->size())
     {
-      is_same = CUBIT_TRUE;
-      TDF_Label g_child = it2.Value();
-      if(ints->size() > 0 )
-      {
-        Handle_TDataStd_IntegerArray attr_ints;
-        if(g_child.FindAttribute(TDataStd_IntegerArray::GetID(), attr_ints) && 
-           attr_ints->Length() == ints->size())
+      for(int i = 0; i < ints->size(); i++)
+        if(attr_ints->Value(i) != *ints->get_and_step())
         {
-          for(int i = 0; i < ints->size(); i++)
-            if(attr_ints->Value(i) != *ints->get_and_step())   
-            {
-              is_same = CUBIT_FALSE;
-              break;
-            } 
+          is_same = CUBIT_FALSE;
+          break;
         }
-      }
-      if(!is_same)
-        continue;
- 
-      if(doubles->size() > 0 )
-      {
-        Handle_TDataStd_RealArray attr_doubles;
-        if(g_child.FindAttribute(TDataStd_RealArray::GetID(), attr_doubles) &&
-           attr_doubles->Length() == doubles->size())
+    }
+  }
+  if(!is_same)
+    return is_same;
+
+  if(doubles->size() > 0 )
+  {
+    Handle_TDataStd_RealArray attr_doubles;
+    if(child.FindAttribute(TDataStd_RealArray::GetID(), attr_doubles) &&
+       attr_doubles->Length() == doubles->size())
+    {
+      for(int i = 0; i < doubles->size(); i++)
+        if(attr_doubles->Value(i) != *doubles->get_and_step())
         {
-          for(int i = 0; i < doubles->size(); i++)
-            if(attr_doubles->Value(i) != *doubles->get_and_step())
-            {
-              is_same = CUBIT_FALSE;
-              break;
-            }
+          is_same = CUBIT_FALSE;
+          break;
         }
-      }
+    }
+  }
 
-      if(!is_same)
-        continue;
+  if(!is_same)
+    return is_same;
 
-      if(strings->size() > 0 )
+  if(strings->size() > 0 )
+  {
+    Handle_TDataStd_ExtStringArray attr_strings;
+    if(child.FindAttribute(TDataStd_ExtStringArray::GetID(), attr_strings) &&
+       attr_strings->Length() == strings->size()-1)
+    {
+      strings->step();//filter out type string
+      for(int i = 0; i < strings->size()-1; i++)
       {
-        Handle_TDataStd_ExtStringArray attr_strings;
-        if(g_child.FindAttribute(TDataStd_ExtStringArray::GetID(), attr_strings) &&
-           attr_strings->Length() == strings->size())
+        CubitString astring = *strings->get_and_step();
+        TCollection_ExtendedString string( (Standard_CString)astring.c_str() );
+        if(attr_strings->Value(i) != string)
         {
-          for(int i = 0; i < strings->size(); i++)
-          {
-            CubitString astring = *strings->get_and_step();
-            TCollection_ExtendedString string( (Standard_CString)astring.c_str() );
-            if(attr_strings->Value(i) != string)
-            {
-              is_same = CUBIT_FALSE;
-              break;
-            }
-          }
+          is_same = CUBIT_FALSE;
+          break;
         }
       }
-      if(!is_same)
-        continue;
-
-      child.ForgetAllAttributes( );
     }
   }
+  return is_same  ;
 }
 
-void OCCAttribSet::remove_all_attributes()
+void OCCAttribSet::remove_attribute( CubitSimpleAttrib* csa)
 {
-  while( listHead )
+  CubitString type = csa->character_type();
+  if(type.length() == 0)
+      return;
+
+  TDF_Label myLabel;
+  for (TDF_ChildIterator it(OCCQueryEngine::instance()->mainLabel, CUBIT_FALSE); it.More(); it.Next())
   {
-    OCCAttrib* dead = listHead;
-    listHead = dead->listNext;
-    delete dead;
+    //find the same type attribute first
+    myLabel = it.Value();
+
+    //forget csa attribute from the document
+    for (TDF_ChildIterator it1(myLabel, CUBIT_FALSE); it1.More(); it1.Next())
+    {
+      //find the same type attribute first
+      TDF_Label child = it1.Value();
+
+      CubitBoolean found = find_attribute(child, csa);
+
+      if(found)
+        child.ForgetAllAttributes( );
+    }
   }
-  myLabel.ForgetAllAttributes( );
 }
 
-CubitStatus OCCAttribSet::get_attributes( DLIList<CubitSimpleAttrib*>& list ) const
+void OCCAttribSet::remove_attribute( CubitSimpleAttrib* csa, 
+                                     TopoDS_Shape& shape)
 {
-  for( OCCAttrib* attrib = listHead; attrib; attrib = attrib->listNext )
-    list.append( attrib->get_CSA() );
-  return CUBIT_SUCCESS;
+  CubitBoolean found = CUBIT_FALSE;
+  TDF_Label myLabel;
+
+  FindShape(shape, myLabel, found);
+
+  if(!found)
+    return;
+
+  for (TDF_ChildIterator it1(myLabel, CUBIT_FALSE); it1.More(); it1.Next())
+  {
+    //find the same type attribute first
+    TDF_Label child = it1.Value();
+
+    if(!csa)
+      child.ForgetAllAttributes( );
+
+    else
+    {
+      CubitBoolean found = find_attribute(child, csa);
+
+      if(found)
+        child.ForgetAllAttributes( );
+    }
+  }
 }
 
-CubitStatus OCCAttribSet::get_attributes( const CubitString& name,
-                                    DLIList<CubitSimpleAttrib*>& list ) const
+void OCCAttribSet::get_attributes(TDF_Label &lab,
+                                  DLIList<CubitSimpleAttrib*>& list)
 {
-  for( OCCAttrib* attrib = listHead; attrib; attrib = attrib->listNext )
-    if( attrib->name() == name )
-      list.append( attrib->get_CSA() );
-  return CUBIT_SUCCESS;
+  DLIList<CubitString*> strings;
+  CubitString* string;
+  DLIList<double> doubles;
+  DLIList<int> ints;
+
+  Handle_TDataStd_Name attr_name;
+  TCollection_ExtendedString name_string;
+  Handle_TDataStd_ExtStringArray attr_string;
+  Handle_TDataStd_RealArray attr_doubles;
+  Handle_TDataStd_IntegerArray attr_ints;
+
+  if(lab.FindAttribute(TDataStd_Name::GetID(), attr_name))
+  {
+    name_string = attr_name->Get();
+    int length = name_string.Length();
+    char temp_type[length];
+    for (int i = 1 ;  i <= length; i++)
+    {
+      Standard_ExtCharacter c = name_string.Value(i);
+      temp_type[i-1] = ToCharacter(c);
+    }
+    CubitString temp_string(temp_type);
+    temp_string = temp_string.substr(0, length);
+    string = new CubitString(temp_string);
+    strings.append(string);
+  }
+  if(lab.FindAttribute(TDataStd_ExtStringArray::GetID(), attr_string))
+  {
+    int length = attr_string->Length();
+    for (int i = 0 ;  i < length; i++)
+    {
+      name_string = attr_string->Value(i);
+      int length2 = name_string.Length();
+      char temp_string[length2];
+      for(int j = 1; j <= length2; j ++)
+      {
+        Standard_ExtCharacter c = name_string.Value(j);
+        temp_string[j-1] = ToCharacter(c);
+      }
+      CubitString tmp_string(temp_string);
+      tmp_string = tmp_string.substr(0, length2);
+      string = new CubitString(tmp_string);
+      strings.append(string);
+    }
+  }
+  if(lab.FindAttribute(TDataStd_RealArray::GetID(), attr_doubles))
+  {
+    for(int i = 0; i < attr_doubles->Length(); i++)
+    {
+      double d = attr_doubles->Value(i);
+      doubles.append(d);
+    }
+  }
+  if(lab.FindAttribute(TDataStd_IntegerArray::GetID(), attr_ints))
+  {
+    for(int i = 0; i < attr_ints->Length(); i++)
+    {
+      int j = attr_ints->Value(i);
+      ints.append(j);
+    }
+  }
+  CubitSimpleAttrib *tmp_attrib;
+  if(strings.size() > 0 || doubles.size() || ints.size())
+  {
+    tmp_attrib = new CubitSimpleAttrib(&strings, &doubles, &ints);
+    list.append(tmp_attrib);
+  }
+  for(int i = 0; i < strings.size(); i++)
+    delete strings.get_and_step();
 }
 
-CubitStatus OCCAttribSet::save_attributes( FILE* file_ptr ) const
+CubitStatus OCCAttribSet::get_attributes( TopoDS_Shape& shape,
+                                          DLIList<CubitSimpleAttrib*>& list) 
 {
-  OCCAttrib *curr_attrib;
-  CubitStatus status = CUBIT_SUCCESS;
-  
-  //save # attribs
-  unsigned int size = attribute_count();
-  NCubitFile::CIOWrapper wrapper( file_ptr );
-  wrapper.Write( &size, 1 ); 
+  CubitBoolean found = CUBIT_FALSE;
+  TDF_Label myLabel;
 
-  //save each attrib
-  for( curr_attrib = listHead; curr_attrib; curr_attrib = curr_attrib->listNext )
-    if( !curr_attrib->save(file_ptr) )
-      status = CUBIT_FAILURE;
+  FindShape(shape, myLabel, found);
 
-  return status;
+  if(!found)
+    return CUBIT_FAILURE;
+
+  DLIList<CubitString*> strings;
+  CubitString* string;
+  DLIList<double> doubles;
+  DLIList<int> ints;
+  TDF_Label lab;
+  Handle_TDataStd_Name attr_name;
+  TCollection_ExtendedString name_string;
+  Handle_TDataStd_ExtStringArray attr_string;
+  Handle_TDataStd_RealArray attr_doubles;
+  Handle_TDataStd_IntegerArray attr_ints;
+  for (TDF_ChildIterator it(myLabel,CUBIT_FALSE); it.More(); it.Next())
+  {
+    lab = it.Value();
+    get_attributes(lab, list);
+  }     
+  return CUBIT_SUCCESS;
 }
-  
-CubitStatus OCCAttribSet::restore_attributes( FILE* file_ptr, unsigned endian )
+
+CubitStatus OCCAttribSet::get_attributes( const CubitString& name,
+                                          TopoDS_Shape& shape,
+                                    DLIList<CubitSimpleAttrib*>& list ) 
 {
-  OCCAttrib *curr_attrib;
-  
-  //Read # attribs
-  unsigned int size;
-  NCubitFile::CIOWrapper wrapper( endian, file_ptr );
-  wrapper.Read( &size, 1 ); 
+  CubitBoolean found = CUBIT_FALSE;
+  TDF_Label aLabel;
 
-  for (unsigned i = 0; i < size; i++)
+  FindShape(shape, aLabel, found);
+
+  if(!found)
+    return CUBIT_FAILURE;
+
+  Handle_TDataStd_Name attr_name;
+  TCollection_ExtendedString cstring( (Standard_CString)name.c_str() );
+  TDF_Label lab;
+  for (TDF_ChildIterator it(aLabel,CUBIT_FALSE); it.More(); it.Next())
   {
-    curr_attrib = OCCAttrib::restore( file_ptr, endian);  
-    if (!curr_attrib)
+    lab = it.Value();
+
+    //check if the type attribute is the same, disable it
+    TCollection_ExtendedString old_string;
+    if(lab.FindAttribute(TDataStd_Name::GetID(), attr_name))
     {
-        // file corrupt?  don't try to read any more
-      return CUBIT_FAILURE;
+      old_string = attr_name->Get();
+
+      if(old_string == cstring)
+      {
+        get_attributes(lab, list);
+        break;
+      }
     }
-    
-    curr_attrib->listNext = listHead;
-    listHead = curr_attrib;
   }
-
+ 
   return CUBIT_SUCCESS;
 }
 
 
-int OCCAttribSet::attribute_count() const
+int OCCAttribSet::attribute_count() 
 {
   int count = 0;
-  for( OCCAttrib* attrib = listHead; attrib; attrib = attrib->listNext )
-    count++;
+  
   return count;
 }
 

Modified: cgm/trunk/geom/OCC/OCCAttribSet.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCAttribSet.hpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCAttribSet.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -12,14 +12,12 @@
 
 #ifndef FACET_BRIDGE_HPP
 #define FACET_BRIDGE_HPP
+#include "config.h"
 
 #include <DLIList.hpp>
 #include "TDF_Label.hxx"
-#include "TDF_TagSource.hxx"
-#include "OCCQueryEngine.hpp"
 
 class CubitSimpleAttrib;
-class OCCAttrib;
 class CubitString;
 class TopoDS_Shape;
 
@@ -28,32 +26,35 @@
 
   public:
   
-    OCCAttribSet() : listHead(0) 
-    {myLabel = TDF_TagSource::NewChild(OCCQueryEngine::mainLabel);}
+    OCCAttribSet() {}; 
     
-    ~OCCAttribSet() { remove_all_attributes(); }
+    ~OCCAttribSet() { ; }
+    static void FindShape(TopoDS_Shape& shape,
+                          TDF_Label& aLabel,
+                          CubitBoolean& found);
     
-    void append_attribute( CubitSimpleAttrib*, TopoDS_Shape& shape );
+    static CubitBoolean find_attribute(TDF_Label child,
+                                       CubitSimpleAttrib* csa);
+
+    static void append_attribute( CubitSimpleAttrib*, TopoDS_Shape& shape );
     
-    void remove_attribute( CubitSimpleAttrib* );
+    static void remove_attribute( CubitSimpleAttrib* );
     
-    void remove_all_attributes();
+    static void remove_attribute(CubitSimpleAttrib*, TopoDS_Shape& shape );
+ 
+    static void get_attributes(TDF_Label &lab,
+                               DLIList<CubitSimpleAttrib*>& list);
+
+    static CubitStatus get_attributes( TopoDS_Shape& shape,
+                                       DLIList<CubitSimpleAttrib*>& ) ;
     
-    CubitStatus get_attributes( DLIList<CubitSimpleAttrib*>& ) const;
+    static CubitStatus get_attributes( const CubitString& name,
+                                       TopoDS_Shape& shape,
+                                DLIList<CubitSimpleAttrib*>& ) ;
     
-    CubitStatus get_attributes( const CubitString& name,
-                                DLIList<CubitSimpleAttrib*>& ) const;
+    static int attribute_count() ;
     
-    CubitStatus save_attributes( FILE* file ) const;
-    
-    CubitStatus restore_attributes( FILE* file, unsigned int endian );
-    
-    int attribute_count() const;
-    
   private:
-  
-    OCCAttrib* listHead;
-    TDF_Label   myLabel;
 };
 
 #endif

Modified: cgm/trunk/geom/OCC/OCCBody.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCBody.cpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCBody.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -127,27 +127,72 @@
 }
 
 void OCCBody::append_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.append_attribute(csa, *myTopoDSShape); }
+{ 
+  if(IsSheetBody)
+  {
+    TopoDS_Face * face = mySheetSurface->get_TopoDS_Face();
+    OCCAttribSet::append_attribute(csa, *face);
+  }
+  else if(myShell)
+  {
+    TopoDS_Shell* shell = myShell->get_TopoDS_Shell();
+    OCCAttribSet::append_attribute(csa, *shell);
+  }
+  else
+    OCCAttribSet::append_attribute(csa, *myTopoDSShape); 
+}
   
 void OCCBody::remove_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.remove_attribute(csa); }
+{ 
+  if(IsSheetBody)
+  {
+    TopoDS_Face * face = mySheetSurface->get_TopoDS_Face();
+    OCCAttribSet::remove_attribute(csa, *face);
+  }
+  else if(myShell)
+  {
+    TopoDS_Shell* shell = myShell->get_TopoDS_Shell();
+    OCCAttribSet::remove_attribute(csa, *shell);
+  }
+  else
+    OCCAttribSet::remove_attribute(csa, *myTopoDSShape); 
+}
 
+
 void OCCBody::remove_all_simple_attribute_virt()
-  { attribSet.remove_all_attributes(); }
+  { remove_simple_attribute_virt(NULL); }
   
 CubitStatus OCCBody::get_simple_attribute(DLIList<CubitSimpleAttrib*>& csa_list)
-  { return attribSet.get_attributes(csa_list); }
+{ 
+  if(IsSheetBody)
+  {
+    TopoDS_Face * face = mySheetSurface->get_TopoDS_Face();
+    return OCCAttribSet::get_attributes(*face, csa_list);
+  }
+  else if(myShell)
+  {
+    TopoDS_Shell* shell = myShell->get_TopoDS_Shell();
+    return OCCAttribSet::get_attributes(*shell, csa_list);
+  }
+  return OCCAttribSet::get_attributes(*myTopoDSShape,csa_list); 
+}
 
 CubitStatus OCCBody::get_simple_attribute( const CubitString& name,
                                           DLIList<CubitSimpleAttrib*>& csa_list )
-  { return attribSet.get_attributes( name, csa_list ); }
+{ 
+  if(IsSheetBody)
+  {
+    TopoDS_Face * face = mySheetSurface->get_TopoDS_Face();
+    return OCCAttribSet::get_attributes(name, *face, csa_list);
+  }
+  else if(myShell)
+  {
+    TopoDS_Shell* shell = myShell->get_TopoDS_Shell();
+    return OCCAttribSet::get_attributes(name, *shell, csa_list);
+  }
+  return OCCAttribSet::get_attributes( name, *myTopoDSShape, csa_list ); 
+}
 
-CubitStatus OCCBody::save_attribs( FILE *file_ptr )
-  { return attribSet.save_attributes( file_ptr); }
-
-CubitStatus OCCBody::restore_attribs( FILE *file_ptr, unsigned int endian )
-  { return attribSet.restore_attributes( file_ptr, endian ); }
-
 CubitStatus OCCBody::get_transforms( CubitTransformMatrix &tfm )
 {
   return CUBIT_SUCCESS;

Modified: cgm/trunk/geom/OCC/OCCBody.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCBody.hpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCBody.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -159,12 +159,6 @@
   CubitStatus reflect(double,double,double);
     //- reflect about an axis
 
-  CubitStatus save_attribs( FILE* file_ptr );
-    // Write FactAttribs out to file
-
-  CubitStatus restore_attribs( FILE* file_ptr, unsigned int endian );
-    // Read FactAttribs from file
-
   virtual void get_parents_virt( DLIList<TopologyBridge*>& parents );
   virtual void get_children_virt( DLIList<TopologyBridge*>& children );
   

Modified: cgm/trunk/geom/OCC/OCCCurve.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCCurve.cpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCCurve.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -135,7 +135,7 @@
 // Creation Date : 07/14/00
 //-------------------------------------------------------------------------
 void OCCCurve::append_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.append_attribute(csa, *myTopoDSEdge); }
+  { OCCAttribSet::append_attribute(csa, *myTopoDSEdge); }
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to remove a simple 
@@ -149,7 +149,7 @@
 // Creation Date : 07/14/00
 //-------------------------------------------------------------------------
 void OCCCurve::remove_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.remove_attribute(csa); }
+  { OCCAttribSet::remove_attribute(csa, *myTopoDSEdge); }
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to remove all simple 
@@ -164,7 +164,7 @@
 // Creation Date : 07/14/00
 //-------------------------------------------------------------------------
 void OCCCurve::remove_all_simple_attribute_virt()
-  { attribSet.remove_all_attributes(); }
+  { OCCAttribSet::remove_attribute(NULL, *myTopoDSEdge); }
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to get the  
@@ -179,21 +179,12 @@
 //-------------------------------------------------------------------------
 CubitStatus OCCCurve::get_simple_attribute(DLIList<CubitSimpleAttrib*>&
                                                csa_list)
-  { return attribSet.get_attributes(csa_list); }
+  { return OCCAttribSet::get_attributes(*myTopoDSEdge, csa_list); }
   
 CubitStatus OCCCurve::get_simple_attribute( const CubitString& name,
                                       DLIList<CubitSimpleAttrib*>& csa_list)
-  { return attribSet.get_attributes( name, csa_list ); }
+  { return OCCAttribSet::get_attributes( name, *myTopoDSEdge, csa_list ); }
 
-
-CubitStatus OCCCurve::save_attribs( FILE *file_ptr )
-  { return attribSet.save_attributes(file_ptr); }
-
-CubitStatus OCCCurve::restore_attribs( FILE *file_ptr, unsigned int endian )
-  { return attribSet.restore_attributes(file_ptr, endian); }
-
-
-
 //-------------------------------------------------------------------------
 // Purpose       : Get geometry modeling engine: OCCQueryEngine
 //

Modified: cgm/trunk/geom/OCC/OCCCurve.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCCurve.hpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCCurve.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -17,7 +17,7 @@
 
 // ********** BEGIN STANDARD INCLUDES      **********
 // ********** END STANDARD INCLUDES        **********
-
+#include "config.h"
 // ********** BEGIN CUBIT INCLUDES         **********
 #include "CubitDefines.h"
 #include "Curve.hpp"

Modified: cgm/trunk/geom/OCC/OCCLoop.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLoop.cpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCLoop.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -108,9 +108,6 @@
 //-------------------------------------------------------------------------
 void OCCLoop::append_simple_attribute_virt(CubitSimpleAttrib* /*csattrib_ptr*/)
 {
-  //PRINT_ERROR("OCCLoop::append_simple_attribute_virt not defined\n");
-  return;
-
 }
 
 //-------------------------------------------------------------------------
@@ -123,8 +120,6 @@
 //-------------------------------------------------------------------------
 void OCCLoop::remove_simple_attribute_virt(CubitSimpleAttrib* /*csattrib_ptr*/)
 {
-  //PRINT_ERROR("OCCLoop::remove_simple_attribute_virt not defined\n");
-  return;
 }
 
 //-------------------------------------------------------------------------
@@ -138,8 +133,6 @@
 //-------------------------------------------------------------------------
 void OCCLoop::remove_all_simple_attribute_virt()
 {
-  //PRINT_ERROR(" OCCLoop::remove_all_simple_attribute_virt not defined\n");
-  return;
 }
 
 //-------------------------------------------------------------------------
@@ -153,11 +146,9 @@
 CubitStatus OCCLoop::get_simple_attribute(DLIList<CubitSimpleAttrib*>&
                                                  /*cubit_simple_attrib_list*/)
 {
-  //PRINT_ERROR("OCCLoop::get_simple_attribute not defined\n");
-  return CUBIT_FAILURE;
 }
 CubitStatus OCCLoop::get_simple_attribute(const CubitString&,
-                                              DLIList<CubitSimpleAttrib*>&)
+                                          DLIList<CubitSimpleAttrib*>&)
   { return CUBIT_FAILURE; }
 
 void OCCLoop::get_parents_virt( DLIList<TopologyBridge*>& parents )

Modified: cgm/trunk/geom/OCC/OCCLump.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLump.cpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCLump.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -124,7 +124,16 @@
 // Creation Date : 11/21/96
 //-------------------------------------------------------------------------
 void OCCLump::append_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.append_attribute(csa, *myTopoDSSolid); }
+{ 
+  TopoDS_Shape shape;
+  if(mySheetSurface)
+    shape = *(mySheetSurface->get_TopoDS_Face());
+  else if(myShell)
+    shape = *(myShell->get_TopoDS_Shell());
+  else
+    shape =*myTopoDSSolid;
+  OCCAttribSet::append_attribute(csa, shape); 
+}
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to remove a simple 
@@ -138,7 +147,16 @@
 // Creation Date : 03/18/97
 //-------------------------------------------------------------------------
 void OCCLump::remove_simple_attribute_virt(CubitSimpleAttrib *csa )
-  { attribSet.remove_attribute(csa); }
+{ 
+  TopoDS_Shape shape;
+  if(mySheetSurface)
+    shape = *(mySheetSurface->get_TopoDS_Face());
+  else if(myShell)
+    shape = *(myShell->get_TopoDS_Shell());
+  else
+    shape =*myTopoDSSolid;
+  OCCAttribSet::remove_attribute(csa, shape); 
+}
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to remove all simple 
@@ -153,7 +171,16 @@
 // Creation Date : 07/10/98
 //-------------------------------------------------------------------------
 void OCCLump::remove_all_simple_attribute_virt()
-{ attribSet.remove_all_attributes(); }
+{ 
+  TopoDS_Shape shape;
+  if(mySheetSurface)
+    shape = *(mySheetSurface->get_TopoDS_Face());
+  else if(myShell)
+    shape = *(myShell->get_TopoDS_Shell());
+  else
+    shape =*myTopoDSSolid;
+  OCCAttribSet::remove_attribute(NULL, shape); 
+}
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to get the  
@@ -164,21 +191,31 @@
 //
 //-------------------------------------------------------------------------
 CubitStatus OCCLump::get_simple_attribute(DLIList<CubitSimpleAttrib*>& csa_list)
-  { return attribSet.get_attributes( csa_list ); }
+{ 
+  TopoDS_Shape shape;
+  if(mySheetSurface)
+    shape = *(mySheetSurface->get_TopoDS_Face());
+  else if(myShell)
+    shape = *(myShell->get_TopoDS_Shell());
+  else
+    shape =*myTopoDSSolid;
+  return OCCAttribSet::get_attributes(shape, csa_list ); 
+}
 
 CubitStatus OCCLump::get_simple_attribute( const CubitString& name,
                                         DLIList<CubitSimpleAttrib*>& csa_list )
-  { return attribSet.get_attributes( name, csa_list ); }
+{
+  TopoDS_Shape shape;
+  if(mySheetSurface)
+    shape = *(mySheetSurface->get_TopoDS_Face());
+  else if(myShell)
+    shape = *(myShell->get_TopoDS_Shell());
+  else
+    shape =*myTopoDSSolid;
+  return OCCAttribSet::get_attributes( name, shape, csa_list ); 
+}
 
-CubitStatus OCCLump::save_attribs( FILE *file_ptr )
-  { return attribSet.save_attributes( file_ptr ); }
 
-CubitStatus OCCLump::restore_attribs( FILE *file_ptr, unsigned int endian )
-  { return attribSet.restore_attributes( file_ptr, endian ); }
-
-
-
-
 //-------------------------------------------------------------------------
 // Purpose       : Get the bounding box of the object.
 //

Modified: cgm/trunk/geom/OCC/OCCLump.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLump.hpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCLump.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -15,6 +15,7 @@
 
 // ********** BEGIN STANDARD INCLUDES      **********
 // ********** END STANDARD INCLUDES        **********
+#include "config.h"
 
 // ********** BEGIN CUBIT INCLUDES         **********
 #include "CubitDefines.h"

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.hpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -28,6 +28,7 @@
 class TopoDS_Edge;
 class TopoDS_Face;
 class CubitBox;
+class BRepAlgoAPI_BooleanOperation;
 
 class OCCModifyEngine : public GeometryModifyEngine
 {

Modified: cgm/trunk/geom/OCC/OCCPoint.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCPoint.cpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCPoint.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -22,7 +22,6 @@
 #include "OCCCurve.hpp"
 #include "OCCQueryEngine.hpp"
 #include "CastTo.hpp"
-#include "OCCAttribSet.hpp"
 #include "CubitSimpleAttrib.hpp"
 #include "BRep_Tool.hxx"
 #include "TopExp.hxx"
@@ -105,7 +104,7 @@
 // Creation Date : 07/16/00
 //-------------------------------------------------------------------------
 void OCCPoint::append_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.append_attribute(csa, *myTopoDSVertex); }
+  { OCCAttribSet::append_attribute(csa, *myTopoDSVertex); }
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to remove a simple 
@@ -119,7 +118,7 @@
 // Creation Date : 07/16/00
 //-------------------------------------------------------------------------
 void OCCPoint::remove_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.remove_attribute(csa); }
+  { OCCAttribSet::remove_attribute(csa, *myTopoDSVertex); }
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to remove all simple 
@@ -134,7 +133,7 @@
 // Creation Date : 07/16/00
 //-------------------------------------------------------------------------
 void OCCPoint::remove_all_simple_attribute_virt()
-  { attribSet.remove_all_attributes(); }
+  { OCCAttribSet::remove_attribute(NULL, *myTopoDSVertex); }
 
 //-------------------------------------------------------------------------
 // Purpose       : The purpose of this function is to get the  
@@ -149,22 +148,14 @@
 //-------------------------------------------------------------------------
 CubitStatus OCCPoint::get_simple_attribute(DLIList<CubitSimpleAttrib*>&
                                                csa_list)
-  { return attribSet.get_attributes(csa_list);
+  { return OCCAttribSet::get_attributes(*myTopoDSVertex,csa_list);
   }
 
 CubitStatus OCCPoint::get_simple_attribute(const CubitString& name,
                                      DLIList<CubitSimpleAttrib*>& csa_list )
-  { return attribSet.get_attributes( name, csa_list );
+  { return OCCAttribSet::get_attributes( name, *myTopoDSVertex, csa_list );
   }
 
-CubitStatus OCCPoint::save_attribs( FILE *file_ptr )
-  { return attribSet.save_attributes(file_ptr); 
-  }
-
-CubitStatus OCCPoint::restore_attribs( FILE *file_ptr, unsigned int endian )
-  { return attribSet.restore_attributes(file_ptr, endian); 
-  }
-
 //-------------------------------------------------------------------------
 // Purpose       : Returns the coordinates of this Point. 
 //

Modified: cgm/trunk/geom/OCC/OCCPoint.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCPoint.hpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCPoint.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -17,7 +17,7 @@
 
 // ********** BEGIN STANDARD INCLUDES      **********
 // ********** END STANDARD INCLUDES        **********
-
+#include "config.h"
 // ********** BEGIN CUBIT INCLUDES         **********
 #include "Point.hpp"
 #include <stdio.h>

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -14,6 +14,7 @@
 //
 //-------------------------------------------------------------------------
 #include "config.h"
+#include <Standard_Stream.hxx>
 #include "BRep_Tool.hxx"
 #include "gp_Pnt.hxx"
 #include "gp_Ax1.hxx"
@@ -23,6 +24,7 @@
 #include "BRepBuilderAPI.hxx"
 #include "BRepBuilderAPI_Transform.hxx"
 #include "BRepBuilderAPI_MakeSolid.hxx"
+#include "OCCShapeAttributeSet.hpp"
 #include "BRepBuilderAPI_MakeShell.hxx"
 #include "BRepTools_WireExplorer.hxx"
 #include "TColgp_Array1OfPnt.hxx"
@@ -95,6 +97,8 @@
 #include <BndLib_AddSurface.hxx>
 #include <Precision.hxx>
 #include <BRepAdaptor_Surface.hxx>
+#include <TDataStd_Shape.hxx>
+#include <TDF_ChildIterator.hxx>
 #include "Standard_Boolean.hxx"
 
 //#include "TopOpeBRep_ShapeIntersector.hxx"
@@ -153,6 +157,7 @@
   TCollection_ExtendedString xString;
   MyDF = new TDocStd_Document(xString);
   mainLabel = MyDF->Main();
+  EXPORT_ATTRIB = CUBIT_TRUE;
 }
 
 //================================================================================
@@ -1006,13 +1011,63 @@
       B.Add(Co, *vertex);
     }
  
-  if(!BRepTools::Write(Co, const_cast<char*>(file_name)))
+  TDF_Label label;
+  if(EXPORT_ATTRIB)
+    label = mainLabel;
+
+  if(!Write(Co, const_cast<char*>(file_name),label))
+  //if(!BRepTools::Write(Co, const_cast<char*>(file_name)))
     return CUBIT_FAILURE;
  
   return CUBIT_SUCCESS;
 }
 
+CubitBoolean OCCQueryEngine::Write(const TopoDS_Shape& Sh,
+                                   const Standard_CString File,
+                                   TDF_Label label) 
+{
+  ofstream os;
+  os.open(File, ios::out);
+  if (!os.rdbuf()->is_open()) return Standard_False;
+  
+  CubitBoolean isGood = (os.good() && !os.eof());
+  if(!isGood)
+    return isGood;
 
+  OCCShapeAttributeSet SS;
+  SS.Add(Sh);
+
+  os << "DBRep_DrawableShape\n";  // for easy Draw read
+  SS.Write(os, label);
+  isGood = os.good();
+  if(isGood )
+    SS.Write(Sh,os);
+  os.flush();
+  isGood = os.good();
+  os.close();
+  isGood = os.good() && isGood;
+
+  return isGood;
+}
+
+                                   
+CubitBoolean OCCQueryEngine::Read(TopoDS_Shape& Sh,
+                                  const Standard_CString File,
+                                  TDF_Label label)
+{
+  filebuf fic;
+  istream in(&fic);
+  //  if (!fic.open(File,input)) return Standard_False;
+  if (!fic.open(File, ios::in)) return Standard_False;
+
+  OCCShapeAttributeSet SS;
+  SS.Read(in, label);
+  int nbshapes = SS.NbShapes();
+  if(!nbshapes) return CUBIT_FALSE;
+  SS.Read(Sh,in,nbshapes);
+  return CUBIT_TRUE;
+}
+
 CubitStatus
 OCCQueryEngine::import_temp_geom_file(FILE* file_ptr,
                                       const char* file_name,
@@ -1049,7 +1104,7 @@
 {
   TopoDS_Shape *aShape = new TopoDS_Shape;
   BRep_Builder aBuilder;
-  Standard_Boolean result = BRepTools::Read(*aShape, (char*) file_name, aBuilder);
+  Standard_Boolean result = Read(*aShape, (char*) file_name, mainLabel);
   if (result==0) return CUBIT_FAILURE;
   
   CubitBoolean prev_global_val = PRINT_RESULT;
@@ -1241,7 +1296,7 @@
     OCCCoFace * coface = NULL;
     int size = cofaces_old.size();
     CubitSense sense ;
-    if( aShape.Orientation() == CUBIT_REVERSED )
+    if( aShape.Orientation() == TopAbs_REVERSED )
       sense = (topo_face.Orientation() == TopAbs_FORWARD ? CUBIT_REVERSED : CUBIT_FORWARD);
     else
       sense = (topo_face.Orientation() == TopAbs_FORWARD ? CUBIT_FORWARD : CUBIT_REVERSED); 
@@ -2573,6 +2628,19 @@
   if (!OCCMap->IsBound(old_shape) || old_shape.IsEqual(new_shape))
     return -1;
 
+  //update the attribute label tree
+  DLIList<CubitSimpleAttrib*> list;
+  OCCAttribSet::get_attributes(old_shape, list);
+  
+  for(int i = 0; i < list.size(); i ++)
+  {
+    CubitSimpleAttrib* s_attr = list.get_and_step();
+    OCCAttribSet::remove_attribute(s_attr);
+    if(!new_shape.IsNull())
+      OCCAttribSet::append_attribute(s_attr, new_shape);
+  }
+  
+  //update CGM-OCC map
   int k = OCCMap->Find(old_shape);
   assert (k > 0 && k <= iTotalTBCreated);
 

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.hpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -26,13 +26,14 @@
 #endif
 
 // ********** END STANDARD INCLUDES           **********
-
+#include "TDF_Label.hxx"
 // ********** BEGIN CUBIT INCLUDES            **********
 #include "config.h"
 #include "CubitFileIOWrapper.hpp"
 #include "GeometryQueryEngine.hpp"
 #include "Handle_TDocStd_Document.hxx"
 #include <map>
+
 // ********** END CUBIT INCLUDES              **********
 
 // ********** BEGIN FORWARD DECLARATIONS
@@ -77,7 +78,6 @@
 class OCCCurve;
 class OCCPoint;
  
-class TDF_Label;
 class BRepBuilderAPI_Transform;
 class TopTools_DataMapOfShapeInteger;
 class BRepAlgoAPI_BooleanOperation;
@@ -112,6 +112,8 @@
     //- Singleton pattern
     //- Controlled access and creation of the sole instance of this class.
 
+  CubitBoolean EXPORT_ATTRIB;
+
   int update_OCC_map(TopoDS_Shape old_shape, TopoDS_Shape new_shape);
 
   virtual ~OCCQueryEngine();
@@ -362,7 +364,7 @@
   DLIList<OCCLoop*> *WireList; //standalone wire list
   DLIList<OCCCurve*> *CurveList ;
   Handle(TDocStd_Document) MyDF;
-  static TDF_Label mainLabel;
+  TDF_Label mainLabel;
   TopTools_DataMapOfShapeInteger* OCCMap;
   std::map<int, TopologyBridge*>* OccToCGM;
   static int iTotalTBCreated ;
@@ -382,6 +384,14 @@
                               DLIList<OCCCurve*> &facet_curves,
                               DLIList<OCCPoint*> &facet_points );
 
+  CubitBoolean Write(const TopoDS_Shape& Sh,
+                     const Standard_CString File,
+                     TDF_Label label);
+
+  CubitBoolean Read(TopoDS_Shape& Sh,
+                    const Standard_CString File,
+                    TDF_Label label);
+
   static CubitBoolean PRINT_RESULT;
 
   static OCCQueryEngine* instance_;

Added: cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp	                        (rev 0)
+++ cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -0,0 +1,1784 @@
+// File:        OCCShapeAttributeSet.cxx
+// Created:     Thur Jul 10  2008
+// Author:      Jane Hu
+
+#include <Standard_Stream.hxx>
+#include <BRepTools.hxx>
+#include "OCCShapeAttributeSet.hpp"
+#include "CubitSimpleAttrib.hpp"
+#include "OCCAttribSet.hpp"
+//#include <Poly.hxx>
+#include <TopoDS.hxx>
+#include <TColStd_Array1OfReal.hxx>
+#include <TColStd_HArray1OfInteger.hxx>
+#include <TColgp_Array1OfPnt2d.hxx>
+#include <BRep_GCurve.hxx>
+#include <Handle_BRep_CurveOnClosedSurface.hxx>
+#include <Handle_BRep_CurveOnSurface.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+//#include <BRep_TFace.hxx>
+//#include <BRep_TEdge.hxx>
+//#include <BRep_TVertex.hxx>
+#include <Handle_BRep_GCurve.hxx>
+#include <BRep_Tool.hxx>
+#include <TDF_ChildIterator.hxx>
+#include <Handle_TDataStd_Shape.hxx>
+#include <TopTools_LocationSet.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopoDS_Iterator.hxx>
+//#include <BRep_CurveRepresentation.hxx>
+#include <Poly_Polygon3D.hxx>
+//#include <BRep_Polygon3D.hxx>
+//#include <BRep_PolygonOnSurface.hxx>
+//#include <BRep_PolygonOnClosedSurface.hxx>
+//#include <BRep_PolygonOnTriangulation.hxx>
+//#include <BRep_PolygonOnClosedTriangulation.hxx>
+#include <BRep_CurveOnSurface.hxx>
+#include <BRep_CurveOnClosedSurface.hxx>
+//#include <BRep_ListOfCurveRepresentation.hxx>
+//#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
+#include <BRep_PointOnCurve.hxx>
+#include <BRep_PointOnCurveOnSurface.hxx>
+#include <BRep_PointOnSurface.hxx>
+//#include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
+#include <TDF_Label.hxx>
+#include <TDataStd_Shape.hxx>
+#include <Handle_TDataStd_Name.hxx>
+#include <TDataStd_Name.hxx>
+#include <Handle_TDataStd_ExtStringArray.hxx>
+#include <TDataStd_ExtStringArray.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <Handle_TDataStd_IntegerArray.hxx>
+#include <TDataStd_IntegerArray.hxx>
+#include <Handle_TDataStd_RealArray.hxx>
+#include <TDataStd_RealArray.hxx>
+#include <Handle_BRep_TVertex.hxx>
+#include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
+#include <BRep_TVertex.hxx>
+#include <BRep_PointRepresentation.hxx>
+#include <Handle_BRep_TEdge.hxx>
+#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
+#include <Handle_BRep_TFace.hxx>
+#include <BRep_TFace.hxx>
+#include <BRep_TEdge.hxx>
+#include <BRep_CurveRepresentation.hxx>
+
+#include <TopoDS_Vertex.hxx>
+
+//#include <TColgp_HArray1OfPnt.hxx>
+//#include <TColgp_HArray1OfPnt2d.hxx>
+#include <TColStd_HArray1OfReal.hxx>
+#include <Poly_Triangulation.hxx>
+#include <Poly_PolygonOnTriangulation.hxx>
+
+
+#ifdef MacOS
+#define strcasecmp(p,q) strcmp(p,q)
+#elseif WNT
+#define strcasecmp strcmp
+#elseif AIX
+#include <string.h>
+#endif
+
+const char* dVersion  = "CASCADE Topology V1, (c) Matra-Datavision";
+const char* dVersion2 = "CASCADE Topology V2, (c) Matra-Datavision";
+
+//=======================================================================
+//function : PrintShapeEnum
+//purpose  :
+//=======================================================================
+
+static void PrintShapeEnum(const TopAbs_ShapeEnum T,
+                           Standard_OStream& S,
+                           Standard_Boolean C)
+{
+  switch(T) {
+
+  case TopAbs_VERTEX :
+    if (C) S << "Ve"; else S << "VERTEX   ";
+    break;
+
+  case TopAbs_EDGE :
+    if (C) S << "Ed"; else S << "EDGE     ";
+    break;
+
+  case TopAbs_WIRE :
+    if (C) S << "Wi"; else S << "WIRE     ";
+    break;
+
+  case TopAbs_FACE :
+    if (C) S << "Fa"; else S << "FACE     ";
+    break;
+
+  case TopAbs_SHELL :
+    if (C) S << "Sh"; else S << "SHELL    ";
+    break;
+
+  case TopAbs_SOLID :
+    if (C) S << "So"; else S << "SOLID    ";
+    break;
+
+  case TopAbs_COMPSOLID :
+    if (C) S << "CS"; else S << "COMPSOLID";
+    break;
+
+  case TopAbs_COMPOUND :
+    if (C) S << "Co"; else S << "COMPOUND ";
+    break;
+
+  case TopAbs_SHAPE :
+    if (C) S << "Sp"; else S << "SHAPE";
+    break;
+  }
+}
+
+//=======================================================================
+//function : PrintRegularity
+//purpose  :
+//=======================================================================
+
+static void PrintRegularity(const GeomAbs_Shape C,
+                            Standard_OStream& OS)
+{
+  switch (C) {
+
+  case GeomAbs_C0 :
+    OS << "C0";
+    break;
+
+  case GeomAbs_G1 :
+    OS << "G1";
+    break;
+
+  case GeomAbs_C1 :
+    OS << "C1";
+    break;
+
+  case GeomAbs_G2 :
+    OS << "G2";
+    break;
+
+  case GeomAbs_C2 :
+    OS << "C2";
+    break;
+
+  case GeomAbs_C3 :
+    OS << "C3";
+    break;
+
+  case GeomAbs_CN :
+    OS << "CN";
+    break;
+
+  }
+}
+
+//=======================================================================
+//function : PrintOrientation
+//purpose  :
+//=======================================================================
+
+static void PrintOrientation(const TopAbs_Orientation O,
+                             Standard_OStream& S,
+                             Standard_Boolean C)
+{
+  switch(O) {
+
+  case TopAbs_FORWARD :
+    if (C) S << "+"; else S << "FORWARD";
+    break;
+
+  case TopAbs_REVERSED :
+    if (C) S << "-"; else S << "REVERSED";
+    break;
+
+  case TopAbs_INTERNAL :
+    if (C) S << "i"; else S << "INTERNAL";
+    break;
+
+  case TopAbs_EXTERNAL :
+    if (C) S << "e"; else S << "EXTERNAL";
+    break;
+  }
+}
+
+//=======================================================================
+//function : ReadShapeEnum
+//purpose  :
+//=======================================================================
+
+static TopAbs_ShapeEnum ReadShapeEnum(Standard_IStream& IS)
+{
+  char buffer[255];
+  IS >> buffer;
+
+  switch (buffer[0]) {
+
+  case 'V' :
+    return TopAbs_VERTEX;
+
+  case 'E' :
+    return TopAbs_EDGE;
+
+  case 'W' :
+    return TopAbs_WIRE;
+
+  case 'F' :
+    return TopAbs_FACE;
+
+  case 'S' :
+    if (buffer[1] == 'h')
+      return TopAbs_SHELL;
+    else
+      return TopAbs_SOLID;
+
+  case 'C' :
+    if (buffer[1] == 'S')
+      return TopAbs_COMPSOLID;
+    else
+      return TopAbs_COMPOUND;
+
+  }
+  return TopAbs_COMPOUND;
+}
+
+//=======================================================================
+//function : ReadRegularity
+//purpose  :
+//=======================================================================
+
+static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
+{
+  char buffer[255];
+  IS >> buffer;
+  switch (buffer[0]) {
+
+  case 'C' :
+    switch (buffer[1]) {
+
+    case '0' :
+      return GeomAbs_C0;
+
+    case '1' :
+      return GeomAbs_C1;
+
+    case '2' :
+      return GeomAbs_C2;
+
+    case '3' :
+      return GeomAbs_C3;
+
+    case 'N' :
+      return GeomAbs_CN;
+    }
+    break;
+
+  case 'G' :
+    switch (buffer[1]) {
+
+    case '1' :
+      return GeomAbs_G1;
+
+    case '2' :
+      return GeomAbs_G2;
+
+    }
+    break;
+  }
+  return GeomAbs_C0;
+}
+
+//=======================================================================
+//function : OCCShapeAttributeSet
+//purpose  :
+//=======================================================================
+
+OCCShapeAttributeSet::OCCShapeAttributeSet()
+  :myFormatNb(1)
+{
+}
+
+//=======================================================================
+//function : OCCShapeAttributeSet
+//purpose  :
+//=======================================================================
+
+OCCShapeAttributeSet::OCCShapeAttributeSet (const BRep_Builder& B)
+  :myBuilder(B)
+{
+}
+//=======================================================================
+//function : Add
+//purpose  :
+//=======================================================================
+
+Standard_Integer  OCCShapeAttributeSet::Add(const TopoDS_Shape& S)
+{
+  if (S.IsNull()) return 0;
+  myLocations.Add(S.Location());
+  TopoDS_Shape S2 = S;
+  S2.Location(TopLoc_Location());
+  Standard_Integer index = myShapes.FindIndex(S2);
+  if (index == 0) {
+    AddGeometry(S2);
+
+    for (TopoDS_Iterator its(S2,Standard_False,Standard_False);
+         its.More(); its.Next())
+      Add(its.Value());
+    index = myShapes.Add(S2);
+  }
+ 
+  return index;
+}
+
+//=======================================================================
+//function : AddGeometry
+//purpose  :
+//=======================================================================
+
+void OCCShapeAttributeSet::AddGeometry(const TopoDS_Shape& S)
+{
+  // Add the geometry
+
+  if (S.ShapeType() == TopAbs_VERTEX) {
+
+    Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
+    BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
+
+    while (itrp.More()) {
+      const Handle(BRep_PointRepresentation)& PR = itrp.Value();
+
+      if (PR->IsPointOnCurve()) {
+        myCurves.Add(PR->Curve());
+      }
+
+      else if (PR->IsPointOnCurveOnSurface()) {
+        myCurves2d.Add(PR->PCurve());
+        mySurfaces.Add(PR->Surface());
+      }
+
+      else if (PR->IsPointOnSurface()) {
+        mySurfaces.Add(PR->Surface());
+      }
+
+      myLocations.Add(PR->Location());
+      itrp.Next();
+    }
+
+  }
+  else if (S.ShapeType() == TopAbs_EDGE) {
+
+    // Add the curve geometry
+    Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
+    BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
+
+    while (itrc.More()) {
+      const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
+      if (CR->IsCurve3D()) {
+        if (!CR->Curve3D().IsNull()) {
+          myCurves.Add(CR->Curve3D());
+          myLocations.Add(CR->Location());
+        }
+      }
+      else if (CR->IsCurveOnSurface()) {
+        mySurfaces.Add(CR->Surface());
+        myCurves2d.Add(CR->PCurve());
+        myLocations.Add(CR->Location());
+        if (CR->IsCurveOnClosedSurface())
+          myCurves2d.Add(CR->PCurve2());
+      }
+      else if (CR->IsRegularity()) {
+        mySurfaces.Add(CR->Surface());
+        myLocations.Add(CR->Location());
+        mySurfaces.Add(CR->Surface2());
+        myLocations.Add(CR->Location2());
+      }
+      itrc.Next();
+    }
+  }
+
+  else if (S.ShapeType() == TopAbs_FACE) {
+
+    // Add the surface geometry
+    Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
+    if (!TF->Surface().IsNull())  mySurfaces.Add(TF->Surface());
+
+    myLocations.Add(TF->Location());
+  }
+}
+
+//=======================================================================
+//function : ReadAttribute
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::ReadAttribute(TopoDS_Shape& S,
+                                          Standard_IStream&   IS,
+                                          TDF_Label& l_attr)
+{
+  char buffer[255];
+  DLIList<CubitString*> strings;
+  DLIList<double> doubles;
+  DLIList<int> ints;
+  do {
+    IS >> buffer; 
+    int i = 0;
+    while(buffer[i] != '*')
+      i++;
+    strings.clean_out(); 
+    char type[i];
+  
+    i = 0;
+    while(buffer[i] != '*')
+    {
+      type[i] = buffer[i];
+      i++;
+    }
+    CubitString string(type);
+    string = string.substr(0, i );
+    CubitString* string_prt = new CubitString(string);
+    strings.append(string_prt);
+
+    IS >> buffer;
+    //consider there's only one string in the stringdata field
+    i = 0;
+    while(buffer[i] != '*')
+      i++;
+    char* stringdata = NULL;
+    if(i > 0)
+    {
+      stringdata = new char[i];
+      i = 0;
+      while(buffer[i] != '*')
+      {
+        stringdata[i] = buffer[i];
+        i++;
+      }
+      CubitString string2(stringdata);
+      string2 = string2.substr(0, i );
+      CubitString* string_prt2 = new CubitString(string2);
+      strings.append(string_prt2);
+    }
+
+    IS.get(); //' '
+    int  ints_[10];
+    double  doubles_[10]; 
+    doubles.clean_out();
+    ints.clean_out();
+    char s;
+    IS.get(s); //either '*' or 'number'
+    i = 0;
+    while (s != '\n')
+    {
+      while(s != '*') // integer attributes
+      {
+        IS.unget(); 
+        IS >> ints_[i];
+        i++;
+        IS.get(); //' '
+        IS.get(s); //either '*' or 'number'
+      }
+
+      if(i > 0)
+      {
+        for(int j = 0; j < i; j++)
+          ints.append( ints_[j] );
+      }
+      i = 0;
+      IS.get(); //' '
+      IS.get(s); //either '*' or 'number'
+      while(s != '*') // double attributes
+      {
+        IS.unget();
+        IS >> doubles_[i];
+        i++;
+        IS.get(); //' '
+        IS.get(s); //either '*' or 'number' 
+      }
+
+      if(i > 0)
+      {
+        for(int j = 0; j < i; j++)
+          doubles.append(doubles_[j]);
+      }
+      IS.get(s); //'\n' 
+    }
+    
+    CubitSimpleAttrib *tmp_attrib = new CubitSimpleAttrib(&strings, &doubles, &ints);
+
+    for(int i = 0; i < strings.size(); i++)
+      delete strings.get_and_step();
+
+    OCCAttribSet::append_attribute(tmp_attrib, S);
+    delete tmp_attrib;
+
+    IS >> buffer;
+  }while(buffer[0] != '*');
+}
+
+//=======================================================================
+//function : WriteAttribute
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::WriteAttribute(const TopoDS_Shape& S,
+                                           Standard_OStream&   OS,
+                                           TDF_Label& l_attr)const
+{
+  if(l_attr.IsNull())
+    return;
+
+  Standard_Boolean found = Standard_False;
+  TDF_Label myLabel;
+  for (TDF_ChildIterator it1(l_attr,Standard_False); it1.More(); it1.Next())
+  {
+    //find the same shape attribute first
+    myLabel = it1.Value();
+
+    Handle_TDataStd_Shape attr_shape;
+    TopoDS_Shape exsiting_shape;
+    if(TDataStd_Shape::Find(myLabel, attr_shape))
+      exsiting_shape = attr_shape->Get(myLabel);
+
+    if(!exsiting_shape.IsNull())
+    {
+      if(exsiting_shape.IsPartner(S))
+      {
+        found = Standard_True; 
+        break;
+      }
+    }
+  }
+  if(!found)
+    return;
+
+  if(!myLabel.HasChild())
+    return;
+
+  for (TDF_ChildIterator it2(myLabel,Standard_False); it2.More(); it2.Next())
+  {
+    TDF_Label child = it2.Value();
+    //Write out all attributes
+    Handle_TDataStd_Name attr_name;
+    TCollection_ExtendedString name_string;
+    if(child.FindAttribute(TDataStd_Name::GetID(), attr_name))
+    {
+      OS << "\n";
+      OS << "NEW_SIMPLE_ATTRIB ";
+      name_string = attr_name->Get(); 
+      name_string.Print(OS);
+      OS << "* " ;
+    }
+    else
+      continue;
+
+    Handle_TDataStd_ExtStringArray attr_strings;
+    if(child.FindAttribute(TDataStd_ExtStringArray::GetID(), attr_strings))
+    {
+      Standard_Integer i = attr_strings->Lower();
+      TCollection_ExtendedString string;
+      int size = attr_strings->Upper();
+      for(; i <= size; i++)
+      {
+         string = attr_strings->Value(i);     
+         string.Print(OS);
+         if(i < size ) 
+           OS << " ";
+      }
+    }
+    OS << "* " ;
+
+    Handle_TDataStd_IntegerArray attr_ints;
+    
+    if(child.FindAttribute(TDataStd_IntegerArray::GetID(), attr_ints))
+    {
+      for(Standard_Integer i = attr_ints->Lower(); i <= attr_ints->Upper(); i++)
+        OS << attr_ints->Value(i) << " ";
+    }
+    
+    OS << '*' << ' ' ;
+
+    Handle_TDataStd_RealArray attr_doubles;
+    if(child.FindAttribute(TDataStd_RealArray::GetID(), attr_doubles))
+    {
+      Standard_Integer i = attr_doubles->Lower();
+      for(;i <= attr_doubles->Upper(); i++)
+        OS << attr_doubles->Value(i) << " ";
+    }
+    OS << '*' ; 
+  }
+  OS << "\n*";
+}
+
+//=======================================================================
+//function : Write
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::Write(Standard_OStream& OS,
+                                  TDF_Label l_attr)const
+{
+  //on sauvegarde l'ancien LC_NUMERIC
+  
+  char *oldnum,*plocal ;
+  plocal =   setlocale(LC_NUMERIC, NULL) ;
+  oldnum = new char[strlen(plocal)+1] ;
+  strcpy(oldnum,plocal);
+
+  // on positionne LC_NUMERIC a "C" (point decimal)
+  setlocale(LC_NUMERIC, "C") ;
+
+  int  prec = OS.precision(15);
+
+  // write the copyright
+  if (myFormatNb == 2)
+    OS << "\n" << dVersion2 << endl;
+  else
+    OS << "\n" << dVersion << endl;
+
+  //-----------------------------------------
+  // write the locations
+  //-----------------------------------------
+  myLocations.Write(OS);
+
+  //-----------------------------------------
+  // write the geometry
+  //-----------------------------------------
+
+  WriteGeometry(OS);
+
+  //-----------------------------------------
+  // write the shapes
+  //-----------------------------------------
+  Standard_Integer i, nbShapes = myShapes.Extent();
+
+  OS << "\nTShapes " << nbShapes << "\n";
+
+
+  // subshapes are written first
+  for (i = 1; i <= nbShapes; i++) {
+
+    const TopoDS_Shape& S = myShapes(i);
+
+    // Type
+    PrintShapeEnum(S.ShapeType(),OS,Standard_True);
+    OS << "\n";
+
+    // Geometry
+    WriteGeometry(S,OS);
+
+    // Attributes
+    WriteAttribute(S, OS, l_attr);
+
+    // Flags
+    OS << "\n";
+    OS << (S.Free()       ? 1 : 0);
+    OS << (S.Modified()   ? 1 : 0);
+    OS << (S.Checked()    ? 1 : 0);
+    OS << (S.Orientable() ? 1 : 0);
+    OS << (S.Closed()     ? 1 : 0);
+    OS << (S.Infinite()   ? 1 : 0);
+    OS << (S.Convex()     ? 1 : 0);
+    OS << "\n";
+
+    // sub-shapes
+
+    Standard_Integer l = 0;
+    TopoDS_Iterator its(S,Standard_False,Standard_False);
+    while (its.More()) {
+      Write(its.Value(),OS);
+      l++;
+      if (l == 10) {
+        OS << "\n";
+        l = 0;
+      }
+      its.Next();
+    }
+    Write(TopoDS_Shape(),OS); // Null shape to end the list
+    OS << "\n";
+  }
+
+  OS << endl;
+  OS.precision(prec);
+
+  // on remet le LC_NUMERIC a la precedente valeur
+  setlocale(LC_NUMERIC, oldnum) ;
+  delete[] oldnum;
+}
+
+//=======================================================================
+//function : Read
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::Read(Standard_IStream& IS,
+                                 TDF_Label& l_attr) 
+{
+ // on sauvegarde l'ancien LC_NUMERIC
+  char *oldnum,*plocal ;
+  plocal =   setlocale(LC_NUMERIC, NULL) ;
+  oldnum = new char[strlen(plocal)+1] ;
+  strcpy(oldnum,plocal);
+
+  Clear();
+
+  // Check the version
+  char vers[101];
+  do {
+    IS.getline(vers,100,'\n');
+    // BUC60769 PTV 18.10.2000: remove possible '\r' at the end of the line
+    //Standard_Integer lv = strlen(vers);
+    //char *pm;
+    //if(pm = strchr(vers,'\r'))
+    //  *pm ='\0';
+
+    for (Standard_Integer lv = (strlen(vers)- 1); lv > 1 && (vers[lv] == '\r' || vers[lv] == '\n') ;lv--)
+      vers[lv] = '\0';
+
+  } while ( ! IS.fail() && strcmp(vers,dVersion) && strcmp(vers,dVersion2) );
+  if (IS.fail()) {
+    cout << "File was not written with this version of the topology"<<endl;
+    setlocale(LC_NUMERIC, oldnum) ;
+    delete[] oldnum;
+    return;
+  }
+  if (strcmp(vers,dVersion2) == 0) myFormatNb = 2;
+  else myFormatNb = 1;
+
+  //-----------------------------------------
+  // read the locations
+  //-----------------------------------------
+
+  myLocations.Read(IS);
+
+  //-----------------------------------------
+  // read the geometry
+  //-----------------------------------------
+
+  ReadGeometry(IS);
+
+  //-----------------------------------------
+  // read the shapes
+  //-----------------------------------------
+
+  char buffer[255];
+  IS >> buffer;
+  if (strcmp(buffer,"TShapes")) {
+    cout << "Not a TShape table"<<endl;
+    setlocale(LC_NUMERIC, oldnum) ;
+    delete[] oldnum;
+    return;
+  }
+
+  Standard_Integer i, nbShapes;
+  IS >> nbShapes;
+
+  for (i = 1; i <= nbShapes; i++) {
+
+    TopoDS_Shape S;
+
+    //Read type and create empty shape.
+    TopAbs_ShapeEnum T = ReadShapeEnum(IS);
+    ReadGeometry(T,IS,S);
+
+    // Read Attributes and Set the flags
+    IS >> buffer;
+
+    while (buffer[0] == 'N')
+    {
+      ReadAttribute(S, IS,l_attr);
+      IS >> buffer;
+    }
+
+    // sub-shapes
+    TopoDS_Shape SS;
+    do {
+      Read(SS,IS,nbShapes);
+      if (!SS.IsNull())
+        myBuilder.Add(S,SS);
+    } while(!SS.IsNull());
+
+    S.Free      (buffer[0] == '1');
+    S.Modified  (buffer[1] == '1');
+
+    if (myFormatNb == 2)
+      S.Checked   (buffer[2] == '1');
+    else
+      S.Checked   (Standard_False);     // force check at reading..
+
+    S.Orientable(buffer[3] == '1');
+    S.Closed    (buffer[4] == '1');
+    S.Infinite  (buffer[5] == '1');
+    S.Convex    (buffer[6] == '1');
+
+    // check
+
+    if (myFormatNb == 1)
+      Check(T,S);
+
+    myShapes.Add(S);
+  }
+
+  setlocale(LC_NUMERIC, oldnum) ;
+  delete[] oldnum;
+}
+
+//=======================================================================
+//function : WriteGeometry
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::WriteGeometry(Standard_OStream& OS) const
+{
+  myCurves2d.Write(OS);
+  myCurves.Write(OS);
+  WritePolygon3D(OS);
+  WritePolygonOnTriangulation(OS);
+  mySurfaces.Write(OS);
+  WriteTriangulation(OS);
+}
+
+//=======================================================================
+//function : ReadGeometry
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::ReadGeometry(Standard_IStream& IS)
+{
+  myCurves2d.Read(IS);
+  myCurves.Read(IS);
+  ReadPolygon3D(IS);
+  ReadPolygonOnTriangulation(IS);
+  mySurfaces.Read(IS);
+  ReadTriangulation(IS);
+}
+
+//=======================================================================
+//function : WritePolygon3D
+//purpose  :
+//=======================================================================
+
+void OCCShapeAttributeSet::WritePolygon3D(Standard_OStream&      OS,
+                                        const Standard_Boolean Compact)const
+{
+  Standard_Integer i, j, nbpol = myPolygons3D.Extent();
+  if (Compact)
+    OS << "Polygon3D " << nbpol << endl;
+  else {
+    OS << " -------\n";
+    OS <<"Dump of " << nbpol << " Polygon3Ds\n";
+    OS << " -------\n";
+  }
+
+  Handle(Poly_Polygon3D) P;
+  for (i = 1; i <= nbpol; i++) {
+    P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
+    if (Compact) {
+      OS << P->NbNodes() << " ";
+      OS << ((P->HasParameters()) ? "1" : "0") << "\n";
+    }
+    else {
+      OS << "  "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
+      OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
+    }
+
+
+    // write the deflection
+    if (!Compact) OS << "Deflection : ";
+    OS << P->Deflection() << "\n";
+
+    // write the nodes
+    if (!Compact) OS << "\nNodes :\n";
+
+    Standard_Integer i1, nbNodes = P->NbNodes();
+    const TColgp_Array1OfPnt& Nodes = P->Nodes();
+    for (j = 1; j <= nbNodes; j++) {
+      if (!Compact) OS << setw(10) << j << " : ";
+      if (!Compact) OS << setw(17);
+      OS << Nodes(j).X() << " ";
+      if (!Compact) OS << setw(17);
+      OS << Nodes(j).Y() << " ";
+      if (!Compact) OS << setw(17);
+      OS << Nodes(j).Z();
+      if (!Compact) OS << "\n";
+      else OS << " ";
+    }
+    OS <<"\n";
+
+    if (P->HasParameters()) {
+      if (!Compact) OS << "\nParameters :\n";
+      const TColStd_Array1OfReal& Param = P->Parameters();
+      for ( i1 = 1; i1 <= nbNodes; i1++ ) {
+        OS << Param(i1) << " ";
+      }
+      OS <<"\n";
+    }
+  }
+}
+
+//=======================================================================
+//function : WritePolygonOnTriangulation
+//purpose  :
+//=======================================================================
+
+void OCCShapeAttributeSet::WritePolygonOnTriangulation(
+                                          Standard_OStream&      OS,
+                                          const Standard_Boolean Compact)const
+{
+  Standard_Integer i, j, nbpOntri = myNodes.Extent();
+  if (Compact)
+    OS << "PolygonOnTriangulations " << nbpOntri << endl;
+  else {
+    OS << " -------\n";
+    OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
+    OS << " -------\n";
+  }
+
+  Handle(Poly_PolygonOnTriangulation) Poly;
+  Handle(TColStd_HArray1OfReal) Param;
+
+  for (i=1; i<=nbpOntri; i++) {
+    Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
+    const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
+    if (!Compact) {
+      OS << "  "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
+    }
+    else OS << Nodes.Length()<<" ";
+    if (!Compact) OS <<"  ";
+    for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
+    OS << "\n";
+
+    // writing parameters:
+    Param = Poly->Parameters();
+    if (Compact) OS <<"p ";
+
+    // write the deflection
+    if (!Compact) OS << "  Deflection : ";
+    OS <<Poly->Deflection() << " ";
+    if (!Compact) OS << "\n";
+
+    if (!Param.IsNull()) {
+      if (!Compact) {
+        OS << "  "<< "Parameters :";
+      }
+      else OS << "1 " ;
+      if (!Compact) OS <<"  ";
+      for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
+      OS << "\n";
+    }
+    else OS <<"0 \n";
+  }
+
+}
+
+//=======================================================================
+//function : WriteTriangulation
+//purpose  :
+//=======================================================================
+
+void OCCShapeAttributeSet::WriteTriangulation(Standard_OStream&      OS,
+                                        const Standard_Boolean Compact)const
+{
+  Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
+  Standard_Integer nbTriangles = 0, n1, n2, n3;
+  if (Compact)
+    OS << "Triangulations " << nbtri << endl;
+  else {
+    OS << " -------\n";
+    OS <<"Dump of " << nbtri << " Triangulations\n";
+    OS << " -------\n";
+  }
+
+  Handle(Poly_Triangulation) T;
+  for (i = 1; i <= nbtri; i++) {
+    T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
+    if (Compact) {
+      OS << T->NbNodes() << " " << T->NbTriangles() << " ";
+      OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
+    }
+    else {
+      OS << "  "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
+         << T->NbTriangles() <<" Triangles\n";
+      OS << "      "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
+    }
+
+    // write the deflection
+
+    if (!Compact) OS << "  Deflection : ";
+    OS <<T->Deflection() << "\n";
+
+    // write the 3d nodes
+
+    if (!Compact) OS << "\n3D Nodes :\n";
+
+    nbNodes = T->NbNodes();
+    const TColgp_Array1OfPnt& Nodes = T->Nodes();
+    for (j = 1; j <= nbNodes; j++) {
+      if (!Compact) OS << setw(10) << j << " : ";
+      if (!Compact) OS << setw(17);
+      OS << Nodes(j).X() << " ";
+      if (!Compact) OS << setw(17);
+      OS << Nodes(j).Y() << " ";
+      if (!Compact) OS << setw(17);
+      OS << Nodes(j).Z();
+      if (!Compact) OS << "\n";
+      else OS << " ";
+    }
+
+    if (T->HasUVNodes()) {
+      if (!Compact) OS << "\nUV Nodes :\n";
+      const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
+      for (j = 1; j <= nbNodes; j++) {
+        if (!Compact) OS << setw(10) << j << " : ";
+        if (!Compact) OS << setw(17);
+        OS << UVNodes(j).X() << " ";
+        if (!Compact) OS << setw(17);
+        OS << UVNodes(j).Y();
+        if (!Compact) OS << "\n";
+        else OS << " ";
+      }
+    }
+
+    if (!Compact) OS << "\nTriangles :\n";
+    nbTriangles = T->NbTriangles();
+    const Poly_Array1OfTriangle& Triangles = T->Triangles();
+    for (j = 1; j <= nbTriangles; j++) {
+      if (!Compact) OS << setw(10) << j << " : ";
+      Triangles(j).Get(n1, n2, n3);
+      if (!Compact) OS << setw(10);
+      OS << n1 << " ";
+      if (!Compact) OS << setw(10);
+      OS << n2 << " ";
+      if (!Compact) OS << setw(10);
+      OS << n3;
+      if (!Compact) OS << "\n";
+      else OS << " ";
+    }
+    OS << "\n";
+  }
+
+}
+//=======================================================================
+//function : WriteGeometry
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::WriteGeometry(const TopoDS_Shape& S,
+                                        Standard_OStream&   OS)const
+{
+  // Write the geometry
+
+  if (S.ShapeType() == TopAbs_VERTEX) {
+
+    // Write the point geometry
+    TopoDS_Vertex V = TopoDS::Vertex(S);
+    OS << BRep_Tool::Tolerance(V) << "\n";
+    gp_Pnt p = BRep_Tool::Pnt(V);
+    OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
+
+    Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
+    BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
+
+    while (itrp.More()) {
+      const Handle(BRep_PointRepresentation)& PR = itrp.Value();
+
+      OS << PR->Parameter();
+      if (PR->IsPointOnCurve()) {
+        OS << " 1 " << myCurves.Index(PR->Curve());
+      }
+
+      else if (PR->IsPointOnCurveOnSurface()) {
+        OS << " 2 " <<  myCurves2d.Index(PR->PCurve());
+        OS << " " << mySurfaces.Index(PR->Surface());
+      }
+
+      else if (PR->IsPointOnSurface()) {
+        OS << " 3 " << PR->Parameter2() << " ";
+        OS << mySurfaces.Index(PR->Surface());
+      }
+
+      OS << " " << myLocations.Index(PR->Location());
+      OS << "\n";
+
+      itrp.Next();
+    }
+
+    OS << "0 0\n"; // end representations
+
+  }
+
+  else if (S.ShapeType() == TopAbs_EDGE) {
+
+    // Write the curve geometry
+
+    Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
+
+    OS << " " << TE->Tolerance() << " ";
+    OS << ((TE->SameParameter()) ? 1 : 0) << " ";
+    OS << ((TE->SameRange())     ? 1 : 0) << " ";
+    OS << ((TE->Degenerated())   ? 1 : 0) << "\n";
+
+    Standard_Real first, last;
+    BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
+    while (itrc.More()) {
+      const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
+      if (CR->IsCurve3D()) {
+        if (!CR->Curve3D().IsNull()) {
+          Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
+          GC->Range(first, last);
+          OS << "1 ";                               // -1- Curve 3D
+          OS << " "<<myCurves.Index(CR->Curve3D());
+          OS << " "<<myLocations.Index(CR->Location());
+          OS << " "<<first<<" "<<last;
+          OS << "\n";
+        }
+      }
+      else if (CR->IsCurveOnSurface()) {
+        Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
+        GC->Range(first, last);
+        if (!CR->IsCurveOnClosedSurface())
+          OS << "2 ";                             // -2- Curve on surf
+        else
+          OS << "3 ";                             // -3- Curve on closed surf
+        OS <<" "<<myCurves2d.Index(CR->PCurve());
+        if (CR->IsCurveOnClosedSurface()) {
+          OS <<" " << myCurves2d.Index(CR->PCurve2());
+          PrintRegularity(CR->Continuity(),OS);
+        }
+        OS << " " << mySurfaces.Index(CR->Surface());
+        OS << " " << myLocations.Index(CR->Location());
+        OS << " "<<first<<" "<<last;
+        OS << "\n";
+
+        // Write UV Points // for XML Persistence higher performance
+        if (myFormatNb == 2)
+        {
+          gp_Pnt2d Pf,Pl;
+          if (CR->IsCurveOnClosedSurface()) {
+            Handle(BRep_CurveOnClosedSurface) COCS =
+              Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
+            COCS->UVPoints2(Pf,Pl);
+          }
+          else {
+            Handle(BRep_CurveOnSurface) COS =
+              Handle(BRep_CurveOnSurface)::DownCast(CR);
+            COS->UVPoints(Pf,Pl);
+          }
+          OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
+        }
+      }
+      else if (CR->IsRegularity()) {
+        OS << "4 ";                              // -4- Regularity
+        PrintRegularity(CR->Continuity(),OS);
+        OS << " "<<mySurfaces.Index(CR->Surface());
+        OS << " "<<myLocations.Index(CR->Location());
+        OS << " "<<mySurfaces.Index(CR->Surface2());
+        OS << " "<<myLocations.Index(CR->Location2());
+        OS << "\n";
+      }
+      itrc.Next();
+    }
+    OS << "0\n"; // end of the list of representations
+  }
+   else if (S.ShapeType() == TopAbs_FACE) {
+
+    Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
+    const TopoDS_Face& F = TopoDS::Face(S);
+
+    if (!(TF->Surface()).IsNull()) {
+      OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
+      OS << " ";
+      // Write the surface geometry
+      OS << " " <<TF->Tolerance();
+      OS << " " <<mySurfaces.Index(TF->Surface());
+      OS << " " <<myLocations.Index(TF->Location());
+      OS << "\n";
+    }
+  }
+
+}
+
+
+//=======================================================================
+//function : Write
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::Write(const TopoDS_Shape& S,
+                               Standard_OStream& OS)const
+{
+  if (S.IsNull()) OS << "*";
+  else {
+    PrintOrientation(S.Orientation(),OS,Standard_True);
+    OS << myShapes.Extent() - myShapes.FindIndex(S.Located(TopLoc_Location())) + 1;
+    OS << " " << myLocations.Index(S.Location()) << " ";
+  }
+}
+
+
+//=======================================================================
+//function : ReadGeometry
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::ReadGeometry(const TopAbs_ShapeEnum T,
+                                         Standard_IStream&      IS,
+                                         TopoDS_Shape&          S)
+{
+  // Read the geometry
+
+  Standard_Integer val,c,pc,pc2,s,s2,l,l2,t, pt, pt2;
+  Standard_Real tol,X,Y,Z,first,last,p1,p2;
+  Standard_Real PfX,PfY,PlX,PlY;
+  gp_Pnt2d aPf, aPl;
+  Standard_Boolean closed;
+#ifndef DEB
+  GeomAbs_Shape reg = GeomAbs_C0;
+#else
+  GeomAbs_Shape reg;
+#endif
+  switch (T) {
+
+
+    //---------
+    // vertex
+    //---------
+
+  case TopAbs_VERTEX :
+    {
+      TopoDS_Vertex& V = TopoDS::Vertex(S);
+
+      // Read the point geometry
+      IS >> tol;
+      IS >> X >> Y >> Z;
+      myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
+      Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
+
+      BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
+      TopLoc_Location L;
+
+      do {
+        IS >> p1 >> val;
+
+        Handle(BRep_PointRepresentation) PR;
+        switch (val) {
+
+        case 1 :
+          {
+            IS >> c;
+
+            if (myCurves.Curve(c).IsNull())
+              break;
+
+            Handle(BRep_PointOnCurve) POC =
+              new BRep_PointOnCurve(p1,
+                                    myCurves.Curve(c),
+                                    L);
+            PR = POC;
+          }
+          break;
+
+        case 2 :
+          {
+            IS >> pc >> s;
+
+            if (myCurves2d.Curve2d(pc).IsNull() ||
+                mySurfaces.Surface(s).IsNull())
+              break;
+
+            Handle(BRep_PointOnCurveOnSurface) POC =
+              new BRep_PointOnCurveOnSurface(p1,
+                                             myCurves2d.Curve2d(pc),
+                                             mySurfaces.Surface(s),
+                                             L);
+            PR = POC;
+          }
+          break;
+
+        case 3 :
+          {
+            IS >> p2 >> s;
+
+            if (mySurfaces.Surface(s).IsNull())
+              break;
+
+            Handle(BRep_PointOnSurface) POC =
+              new BRep_PointOnSurface(p1,p2,
+                                      mySurfaces.Surface(s),
+                                      L);
+            PR = POC;
+          }
+          break;
+        }
+
+        if (val > 0) {
+          IS >> l;
+          if (!PR.IsNull()) {
+            PR->Location(myLocations.Location(l));
+            lpr.Append(PR);
+          }
+        }
+      } while (val > 0);
+    }
+    break;
+
+
+    //---------
+    // edge
+    //---------
+
+
+    case TopAbs_EDGE :
+
+      // Create an edge
+      {
+        TopoDS_Edge& E = TopoDS::Edge(S);
+
+        myBuilder.MakeEdge(E);
+
+        // Read the curve geometry
+        IS >> tol;
+        IS >> val;
+        myBuilder.SameParameter(E,(val == 1));
+        IS >> val;
+        myBuilder.SameRange(E,(val == 1));
+        IS >> val;
+        myBuilder.Degenerated(E,(val == 1));
+
+        do {
+          IS >> val;
+          switch (val) {
+
+          case 1 :                               // -1- Curve 3D
+            IS >> c >> l;
+            if (!myCurves.Curve(c).IsNull()) {
+              myBuilder.UpdateEdge(E,myCurves.Curve(c),
+                                   myLocations.Location(l),tol);
+            }
+            IS >> first >> last;
+            if (!myCurves.Curve(c).IsNull()) {
+              Standard_Boolean Only3d = Standard_True;
+              myBuilder.Range(E,first,last,Only3d);
+            }
+            break;
+
+
+          case 2 :                               // -2- Curve on surf
+          case 3 :                               // -3- Curve on closed surf
+            closed = (val == 3);
+            IS >> pc;
+            if (closed) {
+              IS >> pc2;
+              reg = ReadRegularity(IS);
+            }
+
+            // surface, location
+            IS >> s >> l;
+
+            // range
+            IS >> first >> last;
+
+            // read UV Points // for XML Persistence higher performance
+            if (myFormatNb == 2)
+            {
+              IS >> PfX >> PfY >> PlX >> PlY;
+              aPf = gp_Pnt2d(PfX,PfY);
+              aPl = gp_Pnt2d(PlX,PlY);
+            }
+
+            if (myCurves2d.Curve2d(pc).IsNull() ||
+                (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
+                mySurfaces.Surface(s).IsNull())
+              break;
+
+            if (closed) {
+              if (myFormatNb == 2)
+                myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
+                                     myCurves2d.Curve2d(pc2),
+                                     mySurfaces.Surface(s),
+                                     myLocations.Location(l),tol,
+                                     aPf, aPl);
+              else
+                myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
+                                     myCurves2d.Curve2d(pc2),
+                                     mySurfaces.Surface(s),
+                                     myLocations.Location(l),tol);
+
+              myBuilder.Continuity(E,
+                                   mySurfaces.Surface(s),
+                                   mySurfaces.Surface(s),
+                                   myLocations.Location(l),
+                                   myLocations.Location(l),
+                                   reg);
+            }
+            else
+            {
+              if (myFormatNb == 2)
+                myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
+                                     mySurfaces.Surface(s),
+                                     myLocations.Location(l),tol,
+                                     aPf, aPl);
+              else
+                myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
+                                     mySurfaces.Surface(s),
+                                     myLocations.Location(l),tol);
+            }
+            myBuilder.Range(E,
+                            mySurfaces.Surface(s),
+                            myLocations.Location(l),
+                            first,last);
+            break;
+
+          case 4 :                               // -4- Regularity
+            reg = ReadRegularity(IS);
+            IS >> s >> l >> s2 >> l2;
+            if (mySurfaces.Surface(s).IsNull() ||
+                mySurfaces.Surface(s2).IsNull())
+              break;
+            myBuilder.Continuity(E,
+                                 mySurfaces.Surface(s),
+                                 mySurfaces.Surface(s2),
+                                 myLocations.Location(l),
+                                 myLocations.Location(l2),
+                                 reg);
+            break;
+
+          case 5 :   // -5- Polygon3D
+            IS >> c >> l;
+            myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), myLocations.Location(l));
+            break;
+
+          case 6 :
+          case 7 :
+            closed = (val == 7);
+            IS >> pt;
+            if (closed) {
+              IS >> pt2;
+            }
+            IS >> t >> l;
+            if (closed) {
+              myBuilder.UpdateEdge
+                (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
+                 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
+                 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
+                 myLocations.Location(l));
+            }
+            else {
+              myBuilder.UpdateEdge
+                (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
+                 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
+                 myLocations.Location(l));
+            }
+            // range
+
+            break;
+
+          }
+        } while (val > 0);
+      }
+    break;
+
+
+    //---------
+    // wire
+    //---------
+
+  case TopAbs_WIRE :
+    myBuilder.MakeWire(TopoDS::Wire(S));
+    break;
+
+
+    //---------
+    // face
+    //---------
+  case TopAbs_FACE :
+    {
+    // create a face :
+    TopoDS_Face& F = TopoDS::Face(S);
+    myBuilder.MakeFace(F);
+
+    IS >> val; // natural restriction
+    if (val == 0 || val == 1) {
+      IS >> tol >> s >> l;
+      if (!mySurfaces.Surface(s).IsNull()) {
+        myBuilder.UpdateFace(TopoDS::Face(S),
+                             mySurfaces.Surface(s),
+                             myLocations.Location(l),tol);
+        myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
+      }
+    }
+
+    // BUC60769
+    char string[260];
+    IS.getline ( string, 256, '\n' );
+    IS.getline ( string, 256, '\n' );
+
+    if (string[0] == '2') {
+      // cas triangulation
+      s = atoi ( &string[2] );
+      myBuilder.UpdateFace(TopoDS::Face(S),
+                           Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
+    }
+//    else IS.seekg(pos);
+    }
+    break;
+
+
+    //---------
+    // shell
+    //---------
+
+  case TopAbs_SHELL :
+    myBuilder.MakeShell(TopoDS::Shell(S));
+    break;
+
+
+    //---------
+    // solid
+    //---------
+
+  case TopAbs_SOLID :
+    myBuilder.MakeSolid(TopoDS::Solid(S));
+    break;
+
+
+    //---------
+    // compsolid
+    //---------
+
+  case TopAbs_COMPSOLID :
+    myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
+    break;
+
+
+    //---------
+    // compound
+    //---------
+
+  case TopAbs_COMPOUND :
+    myBuilder.MakeCompound(TopoDS::Compound(S));
+    break;
+
+  default:
+    break;
+  }
+
+}
+
+//=======================================================================
+//function : ReadPolygonOnTriangulation
+//purpose  :
+//=======================================================================
+
+void OCCShapeAttributeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
+{
+  char buffer[255];
+  IS >> buffer;
+  if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
+    Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
+    Standard_Integer hasparameters;
+    Standard_Real par;
+    Handle(TColStd_HArray1OfReal) Param;
+    Handle(Poly_PolygonOnTriangulation) Poly;
+    IS >> nbpol;
+    for (i=1; i<=nbpol; i++) {
+      IS >> nbnodes;
+      TColStd_Array1OfInteger Nodes(1, nbnodes);
+      for (j = 1; j <= nbnodes; j++) {
+        IS >> val;
+        Nodes(j) = val;
+      }
+      IS >> buffer;
+      Standard_Real def;
+      IS >> def;
+      IS >> hasparameters;
+      if (hasparameters) {
+        TColStd_Array1OfReal Param1(1, nbnodes);
+        for (j = 1; j <= nbnodes; j++) {
+          IS >> par;
+          Param1(j) = par;
+        }
+        Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
+      }
+      else Poly = new Poly_PolygonOnTriangulation(Nodes);
+      Poly->Deflection(def);
+      myNodes.Add(Poly);
+    }
+}
+
+//=======================================================================
+//function : ReadPolygon3D
+//purpose  :
+//=======================================================================
+
+void OCCShapeAttributeSet::ReadPolygon3D(Standard_IStream& IS)
+{
+  char buffer[255];
+  //  Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
+  Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;  Standard_Real d, x, y, z;
+
+  IS >> buffer;
+  if (strstr(buffer,"Polygon3D") == NULL) return;
+    Handle(Poly_Polygon3D) P;
+    IS >> nbpol;
+    for (i=1; i<=nbpol; i++) {
+      IS >> nbnodes;
+      IS >> hasparameters;
+      TColgp_Array1OfPnt Nodes(1, nbnodes);
+      IS >> d;
+      for (j = 1; j <= nbnodes; j++) {
+        IS >> x >> y >> z;
+        Nodes(j).SetCoord(x,y,z);
+      }
+      if (hasparameters) {
+        TColStd_Array1OfReal Param(1,nbnodes);
+        for (p = 1; p <= nbnodes; p++) {
+          IS >> Param(p);
+        }
+        P = new Poly_Polygon3D(Nodes, Param);
+      }
+      else P = new Poly_Polygon3D(Nodes);
+      P->Deflection(d);
+      myPolygons3D.Add(P);
+    }
+}
+
+//=======================================================================
+//function : ReadTriangulation
+//purpose  :
+//=======================================================================
+
+void OCCShapeAttributeSet::ReadTriangulation(Standard_IStream& IS)
+{
+  char buffer[255];
+  //  Standard_Integer i, j, val, nbtri;
+  Standard_Integer i, j, nbtri =0;
+  Standard_Real d, x, y, z;
+  Standard_Integer nbNodes =0, nbTriangles=0;
+  Standard_Boolean hasUV= Standard_False;
+
+  Handle(Poly_Triangulation) T;
+
+  IS >> buffer;
+  if (strstr(buffer,"Triangulations") != NULL) {
+    IS >> nbtri;
+    for (i=1; i<=nbtri; i++) {
+      IS >> nbNodes >> nbTriangles >> hasUV;
+      IS >> d;
+
+      TColgp_Array1OfPnt Nodes(1, nbNodes);
+      TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
+
+      for (j = 1; j <= nbNodes; j++) {
+        IS >> x >> y >> z;
+        Nodes(j).SetCoord(x,y,z);
+      }
+
+      if (hasUV) {
+        for (j = 1; j <= nbNodes; j++) {
+          IS >> x >> y;
+          UVNodes(j).SetCoord(x,y);
+        }
+      }
+
+
+      // read the triangles
+      Standard_Integer n1,n2,n3;
+      Poly_Array1OfTriangle Triangles(1, nbTriangles);
+      for (j = 1; j <= nbTriangles; j++) {
+        IS >> n1 >> n2 >> n3;
+        Triangles(j).Set(n1,n2,n3);
+      }
+
+      if (hasUV) T =  new Poly_Triangulation(Nodes,UVNodes,Triangles);
+      else T = new Poly_Triangulation(Nodes,Triangles);
+
+      T->Deflection(d);
+
+      myTriangulations.Add(T);
+    }
+  }
+}
+
+//=======================================================================
+//function : Clear
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::Clear()
+{
+  mySurfaces.Clear();
+  myCurves.Clear();
+  myCurves2d.Clear();
+  myPolygons3D.Clear();
+  myPolygons2D.Clear();
+  myNodes.Clear();
+  myTriangulations.Clear();
+  myShapes.Clear();
+  myLocations.Clear();
+}
+
+//=======================================================================
+//function : Read
+//purpose  :
+//=======================================================================
+
+void  OCCShapeAttributeSet::Read(TopoDS_Shape& S,
+                                 Standard_IStream& IS,
+                                 const int nbshapes)const
+{
+  char buffer[255];
+  IS >> buffer;
+  if (buffer[0] == '*')
+    S = TopoDS_Shape();
+  else {
+    S = myShapes(nbshapes - atoi(buffer+1) + 1);
+    switch (buffer[0]) {
+
+    case '+' :
+      S.Orientation(TopAbs_FORWARD);
+      break;
+
+    case '-' :
+      S.Orientation(TopAbs_REVERSED);
+      break;
+
+    case 'i' :
+      S.Orientation(TopAbs_INTERNAL);
+      break;
+
+    case 'e' :
+      S.Orientation(TopAbs_EXTERNAL);
+      break;
+    }
+
+    Standard_Integer l;
+    IS >> l;
+    S.Location(myLocations.Location(l));
+  }
+}
+
+//=======================================================================
+//function : Check
+//purpose  :
+//=======================================================================
+
+void OCCShapeAttributeSet::Check(const TopAbs_ShapeEnum T,
+                                 TopoDS_Shape&          S)
+{
+  if (T == TopAbs_FACE) {
+    const TopoDS_Face& F = TopoDS::Face(S);
+    BRepTools::Update(F);
+  }
+}
+
+//=======================================================================
+//function : NbShapes
+//purpose  :
+//=======================================================================
+
+int  OCCShapeAttributeSet::NbShapes() const
+{
+  return myShapes.Extent();
+}
+

Added: cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp	                        (rev 0)
+++ cgm/trunk/geom/OCC/OCCShapeAttributeSet.hpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -0,0 +1,179 @@
+// File:        OCCShapeAttributeSet.hxx
+// Created:     Thur Jul 10  2008
+// Author:      Jane Hu
+
+#ifndef _OCCShapeAttributeSet_HeaderFile
+#define _OCCShapeAttributeSet_HeaderFile
+
+class TopoDS_Shape;
+class TDF_Label;
+
+#ifndef _TopTools_LocationSet_HeaderFile
+#include <TopTools_LocationSet.hxx>
+#endif
+#ifndef _BRep_Builder_HeaderFile
+#include <BRep_Builder.hxx>
+#endif
+#ifndef _TopTools_IndexedMapOfShape_HeaderFile
+#include <TopTools_IndexedMapOfShape.hxx>
+#endif
+#ifndef _GeomTools_SurfaceSet_HeaderFile
+#include <GeomTools_SurfaceSet.hxx>
+#endif
+#ifndef _GeomTools_CurveSet_HeaderFile
+#include <GeomTools_CurveSet.hxx>
+#endif
+#ifndef _GeomTools_Curve2dSet_HeaderFile
+#include <GeomTools_Curve2dSet.hxx>
+#endif
+#ifndef _TColStd_IndexedMapOfTransient_HeaderFile
+#include <TColStd_IndexedMapOfTransient.hxx>
+#endif
+#ifndef _TopAbs_ShapeEnum_HeaderFile
+#include <TopAbs_ShapeEnum.hxx>
+#endif
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+//! Contains a Shape and all  its subshapes, locations <br>
+//!          and geometries, and attributes. <br>
+//! <br>
+//  It's re-write version of BRepTools_ShapeSet
+class OCCShapeAttributeSet {
+
+public:
+
+    void* operator new(size_t,void* anAddress) 
+      {
+        return anAddress;
+      }
+    void* operator new(size_t size) 
+      { 
+        return Standard::Allocate(size); 
+      }
+    void  operator delete(void *anAddress) 
+      { 
+        if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+      }
+ // Methods PUBLIC
+ // 
+
+//! Builds an empty ShapeAttributeSet. <br>
+OCCShapeAttributeSet();
+
+OCCShapeAttributeSet(const BRep_Builder& B);
+
+//! Stores the goemetry of <S>. <br>
+void AddGeometry(const TopoDS_Shape& S) ;
+
+//! Writes the attributs of <S>  on the stream <OS> in a <br>
+//!          format that can be read back by Read. <br>
+void WriteAttribute(const TopoDS_Shape& S,
+                    Standard_OStream& OS,
+                    TDF_Label& l_attr)const;
+
+void  ReadAttribute(TopoDS_Shape& S,
+                    Standard_IStream&   IS,
+                    TDF_Label& l_attr);
+
+//! 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 Read(Standard_IStream& IS, TDF_Label& l_attr);
+
+void Read(TopoDS_Shape& S,Standard_IStream& IS, const int nbshapes)const;
+
+//! Writes the geometry of  me  on the stream <OS> in a <br>
+//!          format that can be read back by Read. <br>
+void WriteGeometry(Standard_OStream& OS) const;
+
+void ReadGeometry(Standard_IStream& IS);
+
+//! Writes the geometry of <S>  on the stream <OS> in a <br>
+//!          format that can be read back by Read. <br>
+void WriteGeometry(const TopoDS_Shape& S,Standard_OStream& OS) const;
+
+void ReadGeometry(const TopAbs_ShapeEnum T,
+                  Standard_IStream&      IS,
+                  TopoDS_Shape&          S);
+
+//! Writes   on  <OS>   the shape   <S>.    Writes the <br>
+//!          orientation, the index of the TShape and the index <br>
+//!          of the Location. <br>
+void Write(const TopoDS_Shape& S,
+           Standard_OStream& OS) const;
+
+//! Writes the 3d polygons <br>
+//!          on the stream <OS> in a format that can <br>
+//!          be read back by Read. <br>
+Standard_EXPORT   void WritePolygon3D(Standard_OStream& OS,const Standard_Boolean Compact = Standard_True) const;
+
+void ReadPolygon3D(Standard_IStream& IS);
+
+//! Writes the polygons on triangulation <br>
+//!          on the stream <OS> in a format that can <br>
+//!          be read back by Read. <br>
+Standard_EXPORT   void WritePolygonOnTriangulation(Standard_OStream& OS,const Standard_Boolean Compact = Standard_True) const;
+
+void ReadPolygonOnTriangulation(Standard_IStream& IS);
+
+//! Writes the triangulation <br>
+//!          on the stream <OS> in a format that can <br>
+//!          be read back by Read. <br>
+Standard_EXPORT   void WriteTriangulation(Standard_OStream& OS,const Standard_Boolean Compact = Standard_True) const;
+
+void ReadTriangulation(Standard_IStream& IS);
+
+void  Clear();
+
+void Check(const TopAbs_ShapeEnum T,TopoDS_Shape& S);
+
+int NbShapes() const;
+
+protected:
+ // Methods PROTECTED
+ // 
+
+
+ // Fields PROTECTED
+ //
+
+
+private: 
+
+ // Methods PRIVATE
+ // 
+
+
+ // Fields PRIVATE
+ //
+BRep_Builder myBuilder;
+TopTools_IndexedMapOfShape myShapes;
+TopTools_LocationSet myLocations;
+Standard_Integer myFormatNb;
+GeomTools_SurfaceSet mySurfaces;
+GeomTools_CurveSet myCurves;
+GeomTools_Curve2dSet myCurves2d;
+TColStd_IndexedMapOfTransient myPolygons2D;
+TColStd_IndexedMapOfTransient myPolygons3D;
+TColStd_IndexedMapOfTransient myTriangulations;
+TColStd_IndexedMapOfTransient myNodes;
+};
+
+
+
+
+
+// other Inline functions and methods (like "C++: function call" methods)
+//
+
+
+#endif

Modified: cgm/trunk/geom/OCC/OCCSurface.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCSurface.cpp	2008-07-29 21:22:57 UTC (rev 2032)
+++ cgm/trunk/geom/OCC/OCCSurface.cpp	2008-07-31 18:16:18 UTC (rev 2033)
@@ -117,7 +117,7 @@
 //
 //-------------------------------------------------------------------------
 void OCCSurface::append_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.append_attribute(csa, *myTopoDSFace); }
+  { OCCAttribSet::append_attribute(csa, *myTopoDSFace); }
 
 
 //-------------------------------------------------------------------------
@@ -129,7 +129,7 @@
 //
 //-------------------------------------------------------------------------
 void OCCSurface::remove_simple_attribute_virt(CubitSimpleAttrib *csa)
-  { attribSet.remove_attribute( csa ); }
+  { OCCAttribSet::remove_attribute( csa , *myTopoDSFace); }
 
 
 //-------------------------------------------------------------------------
@@ -142,7 +142,7 @@
 //
 //-------------------------------------------------------------------------
 void OCCSurface::remove_all_simple_attribute_virt()
-  { attribSet.remove_all_attributes(); }
+  { OCCAttribSet::remove_attribute(NULL, *myTopoDSFace); }
 
 
 //-------------------------------------------------------------------------
@@ -155,21 +155,13 @@
 //-------------------------------------------------------------------------
 CubitStatus OCCSurface::get_simple_attribute(DLIList<CubitSimpleAttrib*>&
                                                  csa_list)
-  { return attribSet.get_attributes(csa_list); }
+  { return OCCAttribSet::get_attributes(*myTopoDSFace,csa_list); }
 
 CubitStatus OCCSurface::get_simple_attribute(const CubitString& name,
                                         DLIList<CubitSimpleAttrib*>& csa_list )
-  { return attribSet.get_attributes( name, csa_list ); }
+  { return OCCAttribSet::get_attributes( name, *myTopoDSFace, csa_list ); }
 
 
-CubitStatus OCCSurface::save_attribs( FILE *file_ptr )
-  { return attribSet.save_attributes(file_ptr); }
-  
-CubitStatus OCCSurface::restore_attribs( FILE *file_ptr, unsigned int endian )
-  { return attribSet.restore_attributes( file_ptr, endian ); }
-
-
-
 //-------------------------------------------------------------------------
 // Purpose       : Get geometry modeling engine: OCCQueryEngine
 //




More information about the cgma-dev mailing list