Author: janehu Date: 2008-07-03 14:04:25 -0500 (Thu, 03 Jul 2008) New Revision: 1980 Modified: cgm/trunk/geom/OCC/OCCAttrib.cpp 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/OCCCurve.cpp cgm/trunk/geom/OCC/OCCLump.cpp cgm/trunk/geom/OCC/OCCPoint.cpp cgm/trunk/geom/OCC/OCCQueryEngine.cpp cgm/trunk/geom/OCC/OCCQueryEngine.hpp cgm/trunk/geom/OCC/OCCSurface.cpp Log: Added simple attribute append and remove method on CGM side. It's stored in a document system with Labels and Attributes. Labels has a tree structure with one root label and multiple children labels of 3 layers deep. First layer storesshape attribute, any 0d-3d geometry could have attribute, if it has, its shape is stored in the first layer; second layer stores type attribute which is CubitSimpleAttrib's charactertype, each shape level label can have multiple children with character type as the attribute; Last level stores attributes of stringarray, doublearray and intarray. When going to opencascade read and write function, it recognize attribute through different TopoDS_Shapes. Modified: cgm/trunk/geom/OCC/OCCAttrib.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCAttrib.cpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCAttrib.cpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -4,7 +4,7 @@ #include "CubitFileIOWrapper.hpp" // Constructor - copy from CubitSimpleAttrib -OCCAttrib::OCCAttrib( CubitSimpleAttrib* csa ) : listNext(0) +OCCAttrib::OCCAttrib( CubitSimpleAttrib* csa) : listNext(0) { int i; Modified: cgm/trunk/geom/OCC/OCCAttrib.hpp =================================================================== --- cgm/trunk/geom/OCC/OCCAttrib.hpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCAttrib.hpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -3,6 +3,7 @@ #include "CubitDefines.h" #include "CubitString.hpp" + class CubitSimpleAttrib; class CubitString; @@ -43,8 +44,8 @@ private: OCCAttrib( int string_count, CubitString* strings, - int double_count, double* doubles, - int integer_count, int* integers ); + int double_count, double* doubles, + int integer_count, int* integers); }; Modified: cgm/trunk/geom/OCC/OCCAttribSet.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCAttribSet.cpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCAttribSet.cpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -14,15 +14,117 @@ #include "OCCAttrib.hpp" #include "CubitSimpleAttrib.hpp" #include "CubitFileIOWrapper.hpp" +#include "Handle_TDataStd_Shape.hxx" +#include "TCollection_ExtendedString.hxx" +#include "Handle_TDataStd_Name.hxx" +#include "Handle_TDataStd_ExtStringArray.hxx" +#include "Handle_TDataStd_RealArray.hxx" +#include "Handle_TDataStd_IntegerArray.hxx" +#include "TDataStd_Name.hxx" +#include "TDataStd_ExtStringArray.hxx" +#include "TDataStd_RealArray.hxx" +#include "TDataStd_IntegerArray.hxx" +#include "TDataStd_Shape.hxx" +#include "TopoDS_Shape.hxx" +#include "TDF_ChildIterator.hxx" -void OCCAttribSet::append_attribute( CubitSimpleAttrib* csa ) +void OCCAttribSet::append_attribute( CubitSimpleAttrib* csa, TopoDS_Shape& shape ) { 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()) + { + //find the same type attribute first + child = 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)) + { + found = CUBIT_TRUE; + break; + } + } + + if(!found) + { + child = myLabel.NewChild(); + Handle_TDataStd_Shape attr_shape = TDataStd_Shape::Set(child, shape); + child.AddAttribute(attr_shape); + } + + //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) + { + TCollection_ExtendedString cstring( (Standard_CString)type.c_str() ); + Handle_TDataStd_Name attr_name = TDataStd_Name::Set(lab, cstring); + lab.AddAttribute(attr_name); + } + + //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) + { + //set the length of String Array be 11, can be extended. + attr_string = TDataStd_ExtStringArray::Set(lab_child, 0, 10); + } + + for(int i = 0; strings && i < strings->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); + + //4. add double attribute + DLIList<double*>* doubles = csa->double_data_list(); + Handle_TDataStd_RealArray attr_double; + if(doubles && doubles->size() > 0) + { + //set the length of double array be 11, can be extended. + attr_double = TDataStd_RealArray::Set(lab_child,0, 10); + } + + for(int i = 0; doubles && i < doubles->size(); i++) + attr_double->SetValue(i, *(doubles->get_and_step())); + + if(doubles && doubles->size() > 0) + lab_child.AddAttribute(attr_double); + + //5. add int attribute + DLIList<int*>* ints = csa->int_data_list(); + Handle_TDataStd_IntegerArray attr_int; + if(ints && ints->size() > 0) + { + //set the length of int array be 11, can be extended. + attr_int = TDataStd_IntegerArray::Set(lab_child, 0, 10); + } + + for(int i = 0; ints && i < ints->size(); i++) + attr_int->SetValue(i, *(ints->get_and_step())); + + if(ints && ints->size() > 0) + lab_child.AddAttribute(attr_int); } -void OCCAttribSet::remove_attribute( CubitSimpleAttrib* csa ) +void OCCAttribSet::remove_attribute( CubitSimpleAttrib* csa) { if( !listHead ) return; @@ -46,6 +148,95 @@ 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() ); + + 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 + TDF_Label child = it1.Value(); + + 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) + continue; + + //continue to compare the rest attributes. + CubitBoolean is_same = CUBIT_TRUE; + for(TDF_ChildIterator it2(child,CUBIT_FALSE); it2.More(); it2.Next()) + { + 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()) + { + 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()) + { + for(int i = 0; i < doubles->size(); i++) + if(attr_doubles->Value(i) != *doubles->get_and_step()) + { + is_same = CUBIT_FALSE; + break; + } + } + } + + if(!is_same) + continue; + + if(strings->size() > 0 ) + { + Handle_TDataStd_ExtStringArray attr_strings; + if(g_child.FindAttribute(TDataStd_ExtStringArray::GetID(), attr_strings) && + attr_strings->Length() == strings->size()) + { + 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; + } + } + } + } + if(!is_same) + continue; + + child.ForgetAllAttributes( ); + } + } } void OCCAttribSet::remove_all_attributes() @@ -56,6 +247,7 @@ listHead = dead->listNext; delete dead; } + myLabel.ForgetAllAttributes( ); } CubitStatus OCCAttribSet::get_attributes( DLIList<CubitSimpleAttrib*>& list ) const Modified: cgm/trunk/geom/OCC/OCCAttribSet.hpp =================================================================== --- cgm/trunk/geom/OCC/OCCAttribSet.hpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCAttribSet.hpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -14,21 +14,26 @@ #define FACET_BRIDGE_HPP #include <DLIList.hpp> +#include "TDF_Label.hxx" +#include "TDF_TagSource.hxx" +#include "OCCQueryEngine.hpp" class CubitSimpleAttrib; class OCCAttrib; class CubitString; +class TopoDS_Shape; class OCCAttribSet { public: - OCCAttribSet() : listHead(0) {} + OCCAttribSet() : listHead(0) + {myLabel = TDF_TagSource::NewChild(OCCQueryEngine::mainLabel);} ~OCCAttribSet() { remove_all_attributes(); } - void append_attribute( CubitSimpleAttrib* ); + void append_attribute( CubitSimpleAttrib*, TopoDS_Shape& shape ); void remove_attribute( CubitSimpleAttrib* ); @@ -48,6 +53,7 @@ private: OCCAttrib* listHead; + TDF_Label myLabel; }; #endif Modified: cgm/trunk/geom/OCC/OCCBody.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCBody.cpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCBody.cpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -127,7 +127,7 @@ } void OCCBody::append_simple_attribute_virt(CubitSimpleAttrib *csa) - { attribSet.append_attribute(csa); } + { attribSet.append_attribute(csa, *myTopoDSShape); } void OCCBody::remove_simple_attribute_virt(CubitSimpleAttrib *csa) { attribSet.remove_attribute(csa); } Modified: cgm/trunk/geom/OCC/OCCCurve.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCCurve.cpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCCurve.cpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -135,7 +135,7 @@ // Creation Date : 07/14/00 //------------------------------------------------------------------------- void OCCCurve::append_simple_attribute_virt(CubitSimpleAttrib *csa) - { attribSet.append_attribute(csa); } + { attribSet.append_attribute(csa, *myTopoDSEdge); } //------------------------------------------------------------------------- // Purpose : The purpose of this function is to remove a simple Modified: cgm/trunk/geom/OCC/OCCLump.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCLump.cpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCLump.cpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -124,7 +124,7 @@ // Creation Date : 11/21/96 //------------------------------------------------------------------------- void OCCLump::append_simple_attribute_virt(CubitSimpleAttrib *csa) - { attribSet.append_attribute(csa); } + { attribSet.append_attribute(csa, *myTopoDSSolid); } //------------------------------------------------------------------------- // Purpose : The purpose of this function is to remove a simple Modified: cgm/trunk/geom/OCC/OCCPoint.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCPoint.cpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCPoint.cpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -105,7 +105,7 @@ // Creation Date : 07/16/00 //------------------------------------------------------------------------- void OCCPoint::append_simple_attribute_virt(CubitSimpleAttrib *csa) - { attribSet.append_attribute(csa); } + { attribSet.append_attribute(csa, *myTopoDSVertex); } //------------------------------------------------------------------------- // Purpose : The purpose of this function is to remove a simple Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCQueryEngine.cpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -102,10 +102,13 @@ //#include "TopOpeBRepTool_ShapeTool.hxx" //#include "BRepPrimAPI_MakePrism.hxx" //#include "TopOpeBRep_Point2d.hxx" +#include "TDF_Label.hxx" #include "TopTools_DataMapOfShapeInteger.hxx" #include "BRepExtrema_DistShapeShape.hxx" #include "BRepAlgoAPI_Section.hxx" #include "BRepBuilderAPI_MakeEdge.hxx" +#include "TDocStd_Document.hxx" +#include "TCollection_ExtendedString.hxx" #include "gp_Lin.hxx" using namespace NCubitFile; @@ -147,6 +150,9 @@ WireList = new DLIList<OCCLoop*>; SurfaceList = new DLIList<OCCSurface*>; CurveList = new DLIList<OCCCurve*>; + TCollection_ExtendedString xString; + MyDF = new TDocStd_Document(xString); + mainLabel = MyDF->Main(); } //================================================================================ @@ -1351,7 +1357,7 @@ OCCCoEdge * coedge = NULL; int size = coedges_old.size(); CubitSense sense ; - if( aShape.Orientation() == CUBIT_REVERSED ) + if( aShape.Orientation() == TopAbs_REVERSED ) sense = (Ex.Orientation() == TopAbs_FORWARD ? CUBIT_REVERSED : CUBIT_FORWARD); else sense = (Ex.Orientation() == TopAbs_FORWARD ? CUBIT_FORWARD : CUBIT_REVERSED); Modified: cgm/trunk/geom/OCC/OCCQueryEngine.hpp =================================================================== --- cgm/trunk/geom/OCC/OCCQueryEngine.hpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCQueryEngine.hpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -31,7 +31,7 @@ #include "config.h" #include "CubitFileIOWrapper.hpp" #include "GeometryQueryEngine.hpp" - +#include "Handle_TDocStd_Document.hxx" #include <map> // ********** END CUBIT INCLUDES ********** @@ -77,6 +77,7 @@ class OCCCurve; class OCCPoint; +class TDF_Label; class BRepBuilderAPI_Transform; class TopTools_DataMapOfShapeInteger; class BRepAlgoAPI_BooleanOperation; @@ -360,6 +361,8 @@ DLIList<OCCSurface*> *SurfaceList ; DLIList<OCCLoop*> *WireList; //standalone wire list DLIList<OCCCurve*> *CurveList ; + Handle(TDocStd_Document) MyDF; + static TDF_Label mainLabel; TopTools_DataMapOfShapeInteger* OCCMap; std::map<int, TopologyBridge*>* OccToCGM; static int iTotalTBCreated ; @@ -387,7 +390,6 @@ static const int OCCQE_MAJOR_VERSION; static const int OCCQE_MINOR_VERSION; static const int OCCQE_SUBMINOR_VERSION; - }; // ********** BEGIN INLINE FUNCTIONS ********** Modified: cgm/trunk/geom/OCC/OCCSurface.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCSurface.cpp 2008-07-03 18:46:43 UTC (rev 1979) +++ cgm/trunk/geom/OCC/OCCSurface.cpp 2008-07-03 19:04:25 UTC (rev 1980) @@ -117,7 +117,7 @@ // //------------------------------------------------------------------------- void OCCSurface::append_simple_attribute_virt(CubitSimpleAttrib *csa) - { attribSet.append_attribute(csa); } + { attribSet.append_attribute(csa, *myTopoDSFace); } //-------------------------------------------------------------------------
participants (1)
-
janehu@mcs.anl.gov