cgma
OCCShapeAttributeSet.cpp
Go to the documentation of this file.
00001 // File:        OCCShapeAttributeSet.cxx
00002 // Created:     Thur Jul 10  2008
00003 // Author:      Jane Hu
00004 
00005 #include <Standard_Stream.hxx>
00006 #include <BRepTools.hxx>
00007 #include "OCCShapeAttributeSet.hpp"
00008 #include "CubitSimpleAttrib.hpp"
00009 #include "OCCAttribSet.hpp"
00010 #include "OCCQueryEngine.hpp"
00011 //#include <Poly.hxx>
00012 #include <TopoDS.hxx>
00013 #include <TColStd_Array1OfReal.hxx>
00014 #include <TColStd_HArray1OfInteger.hxx>
00015 #include <TColgp_Array1OfPnt2d.hxx>
00016 #include <BRep_GCurve.hxx>
00017 #include <Handle_BRep_CurveOnClosedSurface.hxx>
00018 #include <Handle_BRep_CurveOnSurface.hxx>
00019 #include <TopAbs_ShapeEnum.hxx>
00020 //#include <BRep_TFace.hxx>
00021 //#include <BRep_TEdge.hxx>
00022 //#include <BRep_TVertex.hxx>
00023 #include <Handle_BRep_GCurve.hxx>
00024 #include <BRep_Tool.hxx>
00025 #include <TDF_ChildIterator.hxx>
00026 #include <TopTools_LocationSet.hxx>
00027 #include <TopTools_IndexedMapOfShape.hxx>
00028 #include <TopoDS_Iterator.hxx>
00029 //#include <BRep_CurveRepresentation.hxx>
00030 #include <Poly_Polygon3D.hxx>
00031 //#include <BRep_Polygon3D.hxx>
00032 //#include <BRep_PolygonOnSurface.hxx>
00033 //#include <BRep_PolygonOnClosedSurface.hxx>
00034 //#include <BRep_PolygonOnTriangulation.hxx>
00035 //#include <BRep_PolygonOnClosedTriangulation.hxx>
00036 #include <BRep_CurveOnSurface.hxx>
00037 #include <BRep_CurveOnClosedSurface.hxx>
00038 //#include <BRep_ListOfCurveRepresentation.hxx>
00039 //#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
00040 #include <BRep_PointOnCurve.hxx>
00041 #include <BRep_PointOnCurveOnSurface.hxx>
00042 #include <BRep_PointOnSurface.hxx>
00043 //#include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
00044 #include <TDF_Label.hxx>
00045 #include <TopTools_DataMapOfShapeInteger.hxx>
00046 
00047 #ifndef OCC_VERSION_MINOR
00048 #include "Standard_Version.hxx"
00049 #endif
00050 #if OCC_VERSION_MINOR < 5
00051   #include <TDataStd_Shape.hxx>
00052   typedef TDataStd_Shape TDataXtd_Shape;
00053   typedef Handle_TDataStd_Shape Handle_TDataXtd_Shape;
00054 #else
00055   #include <TDataXtd_Shape.hxx>
00056 #endif
00057 
00058 #include <Handle_TDataStd_Name.hxx>
00059 #include <TDataStd_Name.hxx>
00060 #include <Handle_TDataStd_ExtStringArray.hxx>
00061 #include <TDataStd_ExtStringArray.hxx>
00062 #include <TCollection_ExtendedString.hxx>
00063 #include <Handle_TDataStd_IntegerArray.hxx>
00064 #include <TDataStd_IntegerArray.hxx>
00065 #include <Handle_TDataStd_RealArray.hxx>
00066 #include <TDataStd_RealArray.hxx>
00067 #include <Handle_BRep_TVertex.hxx>
00068 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
00069 #include <BRep_TVertex.hxx>
00070 #include <BRep_PointRepresentation.hxx>
00071 #include <Handle_BRep_TEdge.hxx>
00072 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
00073 #include <Handle_BRep_TFace.hxx>
00074 #include <BRep_TFace.hxx>
00075 #include <BRep_TEdge.hxx>
00076 #include <BRep_CurveRepresentation.hxx>
00077 
00078 #include <TopoDS_Vertex.hxx>
00079 
00080 //#include <TColgp_HArray1OfPnt.hxx>
00081 //#include <TColgp_HArray1OfPnt2d.hxx>
00082 #include <TColStd_HArray1OfReal.hxx>
00083 #include <Poly_Triangulation.hxx>
00084 #include <Poly_PolygonOnTriangulation.hxx>
00085 
00086 
00087 #ifdef MacOS
00088 #define strcasecmp(p,q) strcmp(p,q)
00089 #elseif WNT
00090 #define strcasecmp strcmp
00091 #elseif AIX
00092 #include <string.h>
00093 #endif
00094 
00095 const char* dVersion  = "CASCADE Topology V1, (c) Matra-Datavision";
00096 const char* dVersion2 = "CASCADE Topology V2, (c) Matra-Datavision";
00097 
00098 //=======================================================================
00099 //function : PrintShapeEnum
00100 //purpose  :
00101 //=======================================================================
00102 
00103 static void PrintShapeEnum(const TopAbs_ShapeEnum T,
00104                            Standard_OStream& S,
00105                            Standard_Boolean C)
00106 {
00107   switch(T) {
00108 
00109   case TopAbs_VERTEX :
00110     if (C) S << "Ve"; else S << "VERTEX   ";
00111     break;
00112 
00113   case TopAbs_EDGE :
00114     if (C) S << "Ed"; else S << "EDGE     ";
00115     break;
00116 
00117   case TopAbs_WIRE :
00118     if (C) S << "Wi"; else S << "WIRE     ";
00119     break;
00120 
00121   case TopAbs_FACE :
00122     if (C) S << "Fa"; else S << "FACE     ";
00123     break;
00124 
00125   case TopAbs_SHELL :
00126     if (C) S << "Sh"; else S << "SHELL    ";
00127     break;
00128 
00129   case TopAbs_SOLID :
00130     if (C) S << "So"; else S << "SOLID    ";
00131     break;
00132 
00133   case TopAbs_COMPSOLID :
00134     if (C) S << "CS"; else S << "COMPSOLID";
00135     break;
00136 
00137   case TopAbs_COMPOUND :
00138     if (C) S << "Co"; else S << "COMPOUND ";
00139     break;
00140 
00141   case TopAbs_SHAPE :
00142     if (C) S << "Sp"; else S << "SHAPE";
00143     break;
00144   }
00145 }
00146 
00147 //=======================================================================
00148 //function : PrintRegularity
00149 //purpose  :
00150 //=======================================================================
00151 
00152 static void PrintRegularity(const GeomAbs_Shape C,
00153                             Standard_OStream& OS)
00154 {
00155   switch (C) {
00156 
00157   case GeomAbs_C0 :
00158     OS << "C0";
00159     break;
00160 
00161   case GeomAbs_G1 :
00162     OS << "G1";
00163     break;
00164 
00165   case GeomAbs_C1 :
00166     OS << "C1";
00167     break;
00168 
00169   case GeomAbs_G2 :
00170     OS << "G2";
00171     break;
00172 
00173   case GeomAbs_C2 :
00174     OS << "C2";
00175     break;
00176 
00177   case GeomAbs_C3 :
00178     OS << "C3";
00179     break;
00180 
00181   case GeomAbs_CN :
00182     OS << "CN";
00183     break;
00184 
00185   }
00186 }
00187 
00188 //=======================================================================
00189 //function : PrintOrientation
00190 //purpose  :
00191 //=======================================================================
00192 
00193 static void PrintOrientation(const TopAbs_Orientation O,
00194                              Standard_OStream& S,
00195                              Standard_Boolean C)
00196 {
00197   switch(O) {
00198 
00199   case TopAbs_FORWARD :
00200     if (C) S << "+"; else S << "FORWARD";
00201     break;
00202 
00203   case TopAbs_REVERSED :
00204     if (C) S << "-"; else S << "REVERSED";
00205     break;
00206 
00207   case TopAbs_INTERNAL :
00208     if (C) S << "i"; else S << "INTERNAL";
00209     break;
00210 
00211   case TopAbs_EXTERNAL :
00212     if (C) S << "e"; else S << "EXTERNAL";
00213     break;
00214   }
00215 }
00216 
00217 //=======================================================================
00218 //function : ReadShapeEnum
00219 //purpose  :
00220 //=======================================================================
00221 
00222 static TopAbs_ShapeEnum ReadShapeEnum(Standard_IStream& IS)
00223 {
00224   std::string buffer;
00225   IS >> buffer;
00226 
00227   switch (buffer[0]) {
00228 
00229   case 'V' :
00230     return TopAbs_VERTEX;
00231 
00232   case 'E' :
00233     return TopAbs_EDGE;
00234 
00235   case 'W' :
00236     return TopAbs_WIRE;
00237 
00238   case 'F' :
00239     return TopAbs_FACE;
00240 
00241   case 'S' :
00242     if (buffer[1] == 'h')
00243       return TopAbs_SHELL;
00244     else
00245       return TopAbs_SOLID;
00246 
00247   case 'C' :
00248     if (buffer[1] == 'S')
00249       return TopAbs_COMPSOLID;
00250     else
00251       return TopAbs_COMPOUND;
00252 
00253   }
00254   return TopAbs_COMPOUND;
00255 }
00256 
00257 //=======================================================================
00258 //function : ReadRegularity
00259 //purpose  :
00260 //=======================================================================
00261 
00262 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
00263 {
00264   std::string buffer;
00265   IS >> buffer;
00266   switch (buffer[0]) {
00267 
00268   case 'C' :
00269     switch (buffer[1]) {
00270 
00271     case '0' :
00272       return GeomAbs_C0;
00273 
00274     case '1' :
00275       return GeomAbs_C1;
00276 
00277     case '2' :
00278       return GeomAbs_C2;
00279 
00280     case '3' :
00281       return GeomAbs_C3;
00282 
00283     case 'N' :
00284       return GeomAbs_CN;
00285     }
00286     break;
00287 
00288   case 'G' :
00289     switch (buffer[1]) {
00290 
00291     case '1' :
00292       return GeomAbs_G1;
00293 
00294     case '2' :
00295       return GeomAbs_G2;
00296 
00297     }
00298     break;
00299   }
00300   return GeomAbs_C0;
00301 }
00302 
00303 //=======================================================================
00304 //function : OCCShapeAttributeSet
00305 //purpose  :
00306 //=======================================================================
00307 
00308 OCCShapeAttributeSet::OCCShapeAttributeSet()
00309   :myFormatNb(1)
00310 {
00311 }
00312 
00313 //=======================================================================
00314 //function : OCCShapeAttributeSet
00315 //purpose  :
00316 //=======================================================================
00317 
00318 OCCShapeAttributeSet::OCCShapeAttributeSet (const BRep_Builder& B)
00319   :myBuilder(B)
00320 {
00321 }
00322 //=======================================================================
00323 //function : Add
00324 //purpose  :
00325 //=======================================================================
00326 
00327 Standard_Integer  OCCShapeAttributeSet::Add(const TopoDS_Shape& S)
00328 {
00329   if (S.IsNull()) return 0;
00330   myLocations.Add(S.Location());
00331   TopoDS_Shape S2 = S;
00332   S2.Location(TopLoc_Location());
00333   Standard_Integer index = myShapes.FindIndex(S2);
00334   if (index == 0) {
00335     AddGeometry(S2);
00336 
00337     for (TopoDS_Iterator its(S2,Standard_False,Standard_False);
00338          its.More(); its.Next())
00339       Add(its.Value());
00340     index = myShapes.Add(S2);
00341   }
00342  
00343   return index;
00344 }
00345 
00346 //=======================================================================
00347 //function : AddGeometry
00348 //purpose  :
00349 //=======================================================================
00350 
00351 void OCCShapeAttributeSet::AddGeometry(const TopoDS_Shape& S)
00352 {
00353   // Add the geometry
00354 
00355   if (S.ShapeType() == TopAbs_VERTEX) {
00356 
00357     Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
00358     BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
00359 
00360     while (itrp.More()) {
00361       const Handle(BRep_PointRepresentation)& PR = itrp.Value();
00362 
00363       if (PR->IsPointOnCurve()) {
00364         myCurves.Add(PR->Curve());
00365       }
00366 
00367       else if (PR->IsPointOnCurveOnSurface()) {
00368         myCurves2d.Add(PR->PCurve());
00369         mySurfaces.Add(PR->Surface());
00370       }
00371 
00372       else if (PR->IsPointOnSurface()) {
00373         mySurfaces.Add(PR->Surface());
00374       }
00375 
00376       myLocations.Add(PR->Location());
00377       itrp.Next();
00378     }
00379 
00380   }
00381   else if (S.ShapeType() == TopAbs_EDGE) {
00382 
00383     // Add the curve geometry
00384     Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
00385     BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
00386 
00387     while (itrc.More()) {
00388       const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
00389       if (CR->IsCurve3D()) {
00390         if (!CR->Curve3D().IsNull()) {
00391           myCurves.Add(CR->Curve3D());
00392           myLocations.Add(CR->Location());
00393         }
00394       }
00395       else if (CR->IsCurveOnSurface()) {
00396         mySurfaces.Add(CR->Surface());
00397         myCurves2d.Add(CR->PCurve());
00398         myLocations.Add(CR->Location());
00399         if (CR->IsCurveOnClosedSurface())
00400           myCurves2d.Add(CR->PCurve2());
00401       }
00402       else if (CR->IsRegularity()) {
00403         mySurfaces.Add(CR->Surface());
00404         myLocations.Add(CR->Location());
00405         mySurfaces.Add(CR->Surface2());
00406         myLocations.Add(CR->Location2());
00407       }
00408       itrc.Next();
00409     }
00410   }
00411 
00412   else if (S.ShapeType() == TopAbs_FACE) {
00413 
00414     // Add the surface geometry
00415     Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
00416     if (!TF->Surface().IsNull())  mySurfaces.Add(TF->Surface());
00417 
00418     myLocations.Add(TF->Location());
00419   }
00420 }
00421 
00422 //=======================================================================
00423 //function : ReadAttribute
00424 //purpose  :
00425 //=======================================================================
00426 
00427 void  OCCShapeAttributeSet::ReadAttribute(TopoDS_Shape& S,
00428                                           Standard_IStream&   IS,
00429                                           TDF_Label& l_attr)
00430 {
00431   std::string buffer, type, stringdata;
00432   std::vector<CubitString> strings;
00433   std::vector<double> doubles;
00434   std::vector<int> ints;
00435   int c_num, length;
00436   char s;
00437   do {
00438     IS >> c_num; //length of name string
00439     IS.get(); //' '
00440     type.clear();
00441     for(int j = 0; j < c_num; j ++)
00442     {
00443       IS.get(s);
00444       type.push_back(s);
00445     }
00446 
00447     strings.clear();
00448     strings.push_back(type.c_str());
00449 
00450     IS >> length; //number of strings
00451     for(int i =0; i < length; i++)
00452     { 
00453       IS >> c_num ; //length of each string
00454       IS.get(); //' '
00455       stringdata.clear();
00456       for(int j = 0; j < c_num; j ++)
00457       {
00458         IS.get(s);
00459         stringdata.push_back(s);
00460       }
00461       strings.push_back(stringdata.c_str());
00462     }
00463 
00464     int tmp_int;
00465     double  tmp_dbl; 
00466     IS >> length; //number of ints
00467     ints.clear();
00468     for (int i = 0; i < length ; i++)
00469     {
00470       IS >> tmp_int;
00471       ints.push_back( tmp_int );
00472     }
00473 
00474     IS >> length; //number of doubles
00475     doubles.clear();
00476     for (int i = 0; i < length ; i++)
00477     {
00478       IS >> tmp_dbl;
00479       doubles.push_back( tmp_dbl );
00480     }
00481 
00482     CubitSimpleAttrib tmp_attrib(&strings, &doubles, &ints);
00483 
00484     OCCAttribSet::append_attribute(tmp_attrib, S);
00485   
00486     IS >> buffer;
00487   }while(buffer[0] != '*');
00488 }
00489 
00490 //=======================================================================
00491 //function : WriteAttribute
00492 //purpose  :
00493 //=======================================================================
00494 
00495 void  OCCShapeAttributeSet::WriteAttribute(const TopoDS_Shape& S,
00496                                            Standard_OStream&   OS,
00497                                            TDF_Label& l_attr)
00498 {
00499   if(l_attr.IsNull())
00500     return;
00501 
00502   Standard_Boolean found = Standard_False;
00503   TDF_Label myLabel;
00504   for (TDF_ChildIterator it1(l_attr,Standard_False); it1.More(); it1.Next())
00505   {
00506     //find the same shape attribute first
00507     myLabel = it1.Value();
00508 
00509     Handle_TDataXtd_Shape attr_shape;
00510 
00511     TopoDS_Shape exsiting_shape;
00512 
00513     if(TDataXtd_Shape::Find(myLabel, attr_shape))
00514       exsiting_shape = attr_shape->Get(myLabel);
00515 
00516     if(!exsiting_shape.IsNull())
00517     {
00518       if(exsiting_shape.IsPartner(S))
00519       {
00520         //It's possible that the myLabel found in this way wasn't the bounded
00521         //lable with the shape. Find the bounded one now.
00522         if(!OCCQueryEngine::instance()->OCCMap->IsBound(exsiting_shape))
00523           continue;
00524   
00525         int k = OCCQueryEngine::instance()->OCCMap->Find(exsiting_shape);
00526         std::map<int, TDF_Label>::iterator it =
00527            OCCQueryEngine::instance()->Shape_Label_Map->find(k);
00528         if(it != OCCQueryEngine::instance()->Shape_Label_Map->end())
00529         {
00530           found = Standard_True;
00531           myLabel = (*it).second;
00532           break;
00533         }
00534       }
00535     }
00536   }
00537   if(!found)
00538   {
00539     OS << "\n*";
00540     return;
00541   }
00542 
00543   if(!myLabel.HasChild())
00544   {
00545     OS << "\n*";
00546     return;
00547   }
00548 
00549   for (TDF_ChildIterator it2(myLabel,Standard_False); it2.More(); it2.Next())
00550   {
00551     TDF_Label child = it2.Value();
00552     //Write out all attributes
00553     Handle_TDataStd_Name attr_name;
00554     TCollection_ExtendedString name_string;
00555     if(child.FindAttribute(TDataStd_Name::GetID(), attr_name))
00556     {
00557       OS << "\n";
00558       OS << "CGM_ATTRIB ";
00559       name_string = attr_name->Get(); 
00560       int length = name_string.Length();
00561       OS << length << ' ';
00562       name_string.Print(OS);
00563       OS << ' ' ;
00564     }
00565     else
00566       continue;
00567 
00568     Handle_TDataStd_ExtStringArray attr_strings;
00569     if(child.FindAttribute(TDataStd_ExtStringArray::GetID(), attr_strings))
00570     {
00571       Standard_Integer i = attr_strings->Lower();
00572       TCollection_ExtendedString string;
00573       int size = attr_strings->Upper();
00574       OS << size -i + 1 << " ";
00575       for(; i <= size; i++)
00576       {
00577          string = attr_strings->Value(i);     
00578          int length = string.Length();
00579          OS << length << ' ';
00580          string.Print(OS);
00581          OS << ' ';
00582       }
00583     }
00584     else
00585       OS << "0 " ;
00586 
00587     Handle_TDataStd_IntegerArray attr_ints;
00588     
00589     if(child.FindAttribute(TDataStd_IntegerArray::GetID(), attr_ints))
00590     {
00591       Standard_Integer i = attr_ints->Lower();
00592       int size = attr_ints->Upper();
00593       OS << size -i + 1 << " ";
00594       for(; i <= size; i++)
00595         OS << attr_ints->Value(i) << ' ';
00596     }
00597     else
00598       OS << "0 " ;    
00599 
00600     Handle_TDataStd_RealArray attr_doubles;
00601     if(child.FindAttribute(TDataStd_RealArray::GetID(), attr_doubles))
00602     {
00603       Standard_Integer i = attr_doubles->Lower();
00604       Standard_Integer size = attr_doubles->Upper();
00605       OS << size -i + 1 << " ";
00606       for(;i <= size; i++)
00607         OS << attr_doubles->Value(i) << ' ';
00608     }
00609     else
00610       OS << "0 " ;
00611   }
00612   OS << "\n*";
00613 }
00614 
00615 //=======================================================================
00616 //function : Write
00617 //purpose  :
00618 //=======================================================================
00619 
00620 void  OCCShapeAttributeSet::Write(Standard_OStream& OS)
00621 {
00622   //on sauvegarde l'ancien LC_NUMERIC
00623   
00624   char *oldnum,*plocal ;
00625   plocal =   setlocale(LC_NUMERIC, NULL) ;
00626   oldnum = new char[strlen(plocal)+1] ;
00627   strcpy(oldnum,plocal);
00628 
00629   // on positionne LC_NUMERIC a "C" (point decimal)
00630   setlocale(LC_NUMERIC, "C") ;
00631 
00632   int  prec = OS.precision(15);
00633 
00634   // write the copyright
00635   if (myFormatNb == 2)
00636     OS << "\n" << dVersion2 << endl;
00637   else
00638     OS << "\n" << dVersion << endl;
00639 
00640   //-----------------------------------------
00641   // write the locations
00642   //-----------------------------------------
00643   myLocations.Write(OS);
00644 
00645   //-----------------------------------------
00646   // write the geometry
00647   //-----------------------------------------
00648 
00649   WriteGeometry(OS);
00650 
00651   //-----------------------------------------
00652   // write the shapes
00653   //-----------------------------------------
00654   Standard_Integer i, nbShapes = myShapes.Extent();
00655 
00656   OS << "\nTShapes " << nbShapes << "\n";
00657 
00658 
00659   // subshapes are written first
00660   for (i = 1; i <= nbShapes; i++) {
00661 
00662     const TopoDS_Shape& S = myShapes(i);
00663 
00664     // Type
00665     PrintShapeEnum(S.ShapeType(),OS,Standard_True);
00666     OS << "\n";
00667 
00668     // Geometry
00669     WriteGeometry(S,OS);
00670 
00671     // Flags
00672     OS << "\n";
00673     OS << (S.Free()       ? 1 : 0);
00674     OS << (S.Modified()   ? 1 : 0);
00675     OS << (S.Checked()    ? 1 : 0);
00676     OS << (S.Orientable() ? 1 : 0);
00677     OS << (S.Closed()     ? 1 : 0);
00678     OS << (S.Infinite()   ? 1 : 0);
00679     OS << (S.Convex()     ? 1 : 0);
00680     OS << "\n";
00681 
00682     // sub-shapes
00683 
00684     Standard_Integer l = 0;
00685     TopoDS_Iterator its(S,Standard_False,Standard_False);
00686     while (its.More()) {
00687       Write(its.Value(),OS);
00688       l++;
00689       if (l == 10) {
00690         OS << "\n";
00691         l = 0;
00692       }
00693       its.Next();
00694     }
00695     Write(TopoDS_Shape(),OS); // Null shape to end the list
00696     OS << "\n";
00697   }
00698 
00699   OS << endl;
00700   OS.precision(prec);
00701 
00702   // on remet le LC_NUMERIC a la precedente valeur
00703   setlocale(LC_NUMERIC, oldnum) ;
00704   delete[] oldnum;
00705 }
00706 
00707 //=======================================================================
00708 //function : Read
00709 //purpose  :
00710 //=======================================================================
00711 
00712 void  OCCShapeAttributeSet::Read(Standard_IStream& IS, bool print_results)
00713 {
00714  // on sauvegarde l'ancien LC_NUMERIC
00715   char *oldnum,*plocal ;
00716   plocal =   setlocale(LC_NUMERIC, NULL) ;
00717   oldnum = new char[strlen(plocal)+1] ;
00718   strcpy(oldnum,plocal);
00719 
00720   Clear();
00721 
00722   // Check the version
00723   char vers[101];
00724   do {
00725     IS.getline(vers,100,'\n');
00726     // BUC60769 PTV 18.10.2000: remove possible '\r' at the end of the line
00727     //Standard_Integer lv = strlen(vers);
00728     //char *pm;
00729     //if(pm = strchr(vers,'\r'))
00730     //  *pm ='\0';
00731 
00732     for (Standard_Integer lv = (strlen(vers)- 1); lv > 1 && (vers[lv] == '\r' || vers[lv] == '\n') ;lv--)
00733       vers[lv] = '\0';
00734 
00735   } while ( ! IS.fail() && strcmp(vers,dVersion) && strcmp(vers,dVersion2) );
00736   if (IS.fail()) {
00737     if (print_results)
00738       cout << "File was not written with this version of the topology"<<endl;
00739     setlocale(LC_NUMERIC, oldnum) ;
00740     delete[] oldnum;
00741     return;
00742   }
00743   if (strcmp(vers,dVersion2) == 0) myFormatNb = 2;
00744   else myFormatNb = 1;
00745 
00746   //-----------------------------------------
00747   // read the locations
00748   //-----------------------------------------
00749 
00750   myLocations.Read(IS);
00751 
00752   //-----------------------------------------
00753   // read the geometry
00754   //-----------------------------------------
00755 
00756   ReadGeometry(IS);
00757 
00758   //-----------------------------------------
00759   // read the shapes
00760   //-----------------------------------------
00761 
00762   std::string buffer;
00763   IS >> buffer;
00764   if (buffer != "TShapes") {
00765     if (print_results)
00766       cout << "Not a TShape table"<<endl;
00767     setlocale(LC_NUMERIC, oldnum) ;
00768     delete[] oldnum;
00769     return;
00770   }
00771 
00772   Standard_Integer i, nbShapes;
00773   IS >> nbShapes;
00774 
00775   for (i = 1; i <= nbShapes; i++) {
00776 
00777     TopoDS_Shape S;
00778 
00779     //Read type and create empty shape.
00780     TopAbs_ShapeEnum T = ReadShapeEnum(IS);
00781     ReadGeometry(T,IS,S);
00782 
00783     // Set the flags
00784     IS >> buffer;
00785 
00786     // sub-shapes
00787     TopoDS_Shape SS;
00788     do {
00789       Read(SS,IS,nbShapes);
00790       if (!SS.IsNull())
00791         myBuilder.Add(S,SS);
00792     } while(!SS.IsNull());
00793 
00794     S.Free      (buffer[0] == '1');
00795     S.Modified  (buffer[1] == '1');
00796 
00797     if (myFormatNb == 2)
00798       S.Checked   (buffer[2] == '1');
00799     else
00800       S.Checked   (Standard_False);     // force check at reading..
00801 
00802     S.Orientable(buffer[3] == '1');
00803     S.Closed    (buffer[4] == '1');
00804     S.Infinite  (buffer[5] == '1');
00805     S.Convex    (buffer[6] == '1');
00806 
00807     // check
00808 
00809     if (myFormatNb == 1)
00810       Check(T,S);
00811 
00812     myShapes.Add(S);
00813   }
00814 
00815   setlocale(LC_NUMERIC, oldnum) ;
00816   delete[] oldnum;
00817 }
00818 
00819 //=======================================================================
00820 //function : WriteGeometry
00821 //purpose  :
00822 //=======================================================================
00823 
00824 void  OCCShapeAttributeSet::WriteGeometry(Standard_OStream& OS) 
00825 {
00826   myCurves2d.Write(OS);
00827   myCurves.Write(OS);
00828   WritePolygon3D(OS);
00829   WritePolygonOnTriangulation(OS);
00830   mySurfaces.Write(OS);
00831   WriteTriangulation(OS);
00832 }
00833 
00834 //=======================================================================
00835 //function : ReadGeometry
00836 //purpose  :
00837 //=======================================================================
00838 
00839 void  OCCShapeAttributeSet::ReadGeometry(Standard_IStream& IS)
00840 {
00841   myCurves2d.Read(IS);
00842   myCurves.Read(IS);
00843   ReadPolygon3D(IS);
00844   ReadPolygonOnTriangulation(IS);
00845   mySurfaces.Read(IS);
00846   ReadTriangulation(IS);
00847 }
00848 
00849 //=======================================================================
00850 //function : WritePolygon3D
00851 //purpose  :
00852 //=======================================================================
00853 
00854 void OCCShapeAttributeSet::WritePolygon3D(Standard_OStream&      OS,
00855                                         const Standard_Boolean Compact)
00856 {
00857   Standard_Integer i, j, nbpol = myPolygons3D.Extent();
00858   if (Compact)
00859     OS << "Polygon3D " << nbpol << endl;
00860   else {
00861     OS << " -------\n";
00862     OS <<"Dump of " << nbpol << " Polygon3Ds\n";
00863     OS << " -------\n";
00864   }
00865 
00866   Handle(Poly_Polygon3D) P;
00867   for (i = 1; i <= nbpol; i++) {
00868     P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
00869     if (Compact) {
00870       OS << P->NbNodes() << " ";
00871       OS << ((P->HasParameters()) ? "1" : "0") << "\n";
00872     }
00873     else {
00874       OS << "  "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
00875       OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
00876     }
00877 
00878 
00879     // write the deflection
00880     if (!Compact) OS << "Deflection : ";
00881     OS << P->Deflection() << "\n";
00882 
00883     // write the nodes
00884     if (!Compact) OS << "\nNodes :\n";
00885 
00886     Standard_Integer i1, nbNodes = P->NbNodes();
00887     const TColgp_Array1OfPnt& Nodes = P->Nodes();
00888     for (j = 1; j <= nbNodes; j++) {
00889       if (!Compact) OS << setw(10) << j << " : ";
00890       if (!Compact) OS << setw(17);
00891       OS << Nodes(j).X() << " ";
00892       if (!Compact) OS << setw(17);
00893       OS << Nodes(j).Y() << " ";
00894       if (!Compact) OS << setw(17);
00895       OS << Nodes(j).Z();
00896       if (!Compact) OS << "\n";
00897       else OS << " ";
00898     }
00899     OS <<"\n";
00900 
00901     if (P->HasParameters()) {
00902       if (!Compact) OS << "\nParameters :\n";
00903       const TColStd_Array1OfReal& Param = P->Parameters();
00904       for ( i1 = 1; i1 <= nbNodes; i1++ ) {
00905         OS << Param(i1) << " ";
00906       }
00907       OS <<"\n";
00908     }
00909   }
00910 }
00911 
00912 //=======================================================================
00913 //function : WritePolygonOnTriangulation
00914 //purpose  :
00915 //=======================================================================
00916 
00917 void OCCShapeAttributeSet::WritePolygonOnTriangulation(
00918                                           Standard_OStream&      OS,
00919                                           const Standard_Boolean Compact)
00920 {
00921   Standard_Integer i, j, nbpOntri = myNodes.Extent();
00922   if (Compact)
00923     OS << "PolygonOnTriangulations " << nbpOntri << endl;
00924   else {
00925     OS << " -------\n";
00926     OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
00927     OS << " -------\n";
00928   }
00929 
00930   Handle(Poly_PolygonOnTriangulation) Poly;
00931   Handle(TColStd_HArray1OfReal) Param;
00932 
00933   for (i=1; i<=nbpOntri; i++) {
00934     Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
00935     const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
00936     if (!Compact) {
00937       OS << "  "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
00938     }
00939     else OS << Nodes.Length()<<" ";
00940     if (!Compact) OS <<"  ";
00941     for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
00942     OS << "\n";
00943 
00944     // writing parameters:
00945     Param = Poly->Parameters();
00946     if (Compact) OS <<"p ";
00947 
00948     // write the deflection
00949     if (!Compact) OS << "  Deflection : ";
00950     OS <<Poly->Deflection() << " ";
00951     if (!Compact) OS << "\n";
00952 
00953     if (!Param.IsNull()) {
00954       if (!Compact) {
00955         OS << "  "<< "Parameters :";
00956       }
00957       else OS << "1 " ;
00958       if (!Compact) OS <<"  ";
00959       for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
00960       OS << "\n";
00961     }
00962     else OS <<"0 \n";
00963   }
00964 
00965 }
00966 
00967 //=======================================================================
00968 //function : WriteTriangulation
00969 //purpose  :
00970 //=======================================================================
00971 
00972 void OCCShapeAttributeSet::WriteTriangulation(Standard_OStream&      OS,
00973                                         const Standard_Boolean Compact)
00974 {
00975   Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
00976   Standard_Integer nbTriangles = 0, n1, n2, n3;
00977   if (Compact)
00978     OS << "Triangulations " << nbtri << endl;
00979   else {
00980     OS << " -------\n";
00981     OS <<"Dump of " << nbtri << " Triangulations\n";
00982     OS << " -------\n";
00983   }
00984 
00985   Handle(Poly_Triangulation) T;
00986   for (i = 1; i <= nbtri; i++) {
00987     T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
00988     if (Compact) {
00989       OS << T->NbNodes() << " " << T->NbTriangles() << " ";
00990       OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
00991     }
00992     else {
00993       OS << "  "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
00994          << T->NbTriangles() <<" Triangles\n";
00995       OS << "      "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
00996     }
00997 
00998     // write the deflection
00999 
01000     if (!Compact) OS << "  Deflection : ";
01001     OS <<T->Deflection() << "\n";
01002 
01003     // write the 3d nodes
01004 
01005     if (!Compact) OS << "\n3D Nodes :\n";
01006 
01007     nbNodes = T->NbNodes();
01008     const TColgp_Array1OfPnt& Nodes = T->Nodes();
01009     for (j = 1; j <= nbNodes; j++) {
01010       if (!Compact) OS << setw(10) << j << " : ";
01011       if (!Compact) OS << setw(17);
01012       OS << Nodes(j).X() << " ";
01013       if (!Compact) OS << setw(17);
01014       OS << Nodes(j).Y() << " ";
01015       if (!Compact) OS << setw(17);
01016       OS << Nodes(j).Z();
01017       if (!Compact) OS << "\n";
01018       else OS << " ";
01019     }
01020 
01021     if (T->HasUVNodes()) {
01022       if (!Compact) OS << "\nUV Nodes :\n";
01023       const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
01024       for (j = 1; j <= nbNodes; j++) {
01025         if (!Compact) OS << setw(10) << j << " : ";
01026         if (!Compact) OS << setw(17);
01027         OS << UVNodes(j).X() << " ";
01028         if (!Compact) OS << setw(17);
01029         OS << UVNodes(j).Y();
01030         if (!Compact) OS << "\n";
01031         else OS << " ";
01032       }
01033     }
01034 
01035     if (!Compact) OS << "\nTriangles :\n";
01036     nbTriangles = T->NbTriangles();
01037     const Poly_Array1OfTriangle& Triangles = T->Triangles();
01038     for (j = 1; j <= nbTriangles; j++) {
01039       if (!Compact) OS << setw(10) << j << " : ";
01040       Triangles(j).Get(n1, n2, n3);
01041       if (!Compact) OS << setw(10);
01042       OS << n1 << " ";
01043       if (!Compact) OS << setw(10);
01044       OS << n2 << " ";
01045       if (!Compact) OS << setw(10);
01046       OS << n3;
01047       if (!Compact) OS << "\n";
01048       else OS << " ";
01049     }
01050     OS << "\n";
01051   }
01052 
01053 }
01054 //=======================================================================
01055 //function : WriteGeometry
01056 //purpose  :
01057 //=======================================================================
01058 
01059 void  OCCShapeAttributeSet::WriteGeometry(const TopoDS_Shape& S,
01060                                         Standard_OStream&   OS)
01061 {
01062   // Write the geometry
01063 
01064   if (S.ShapeType() == TopAbs_VERTEX) {
01065 
01066     // Write the point geometry
01067     TopoDS_Vertex V = TopoDS::Vertex(S);
01068     OS << BRep_Tool::Tolerance(V) << "\n";
01069     gp_Pnt p = BRep_Tool::Pnt(V);
01070     OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
01071 
01072     Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
01073     BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
01074 
01075     while (itrp.More()) {
01076       const Handle(BRep_PointRepresentation)& PR = itrp.Value();
01077 
01078       OS << PR->Parameter();
01079       if (PR->IsPointOnCurve()) {
01080         OS << " 1 " << myCurves.Index(PR->Curve());
01081       }
01082 
01083       else if (PR->IsPointOnCurveOnSurface()) {
01084         OS << " 2 " <<  myCurves2d.Index(PR->PCurve());
01085         OS << " " << mySurfaces.Index(PR->Surface());
01086       }
01087 
01088       else if (PR->IsPointOnSurface()) {
01089         OS << " 3 " << PR->Parameter2() << " ";
01090         OS << mySurfaces.Index(PR->Surface());
01091       }
01092 
01093       OS << " " << myLocations.Index(PR->Location());
01094       OS << "\n";
01095 
01096       itrp.Next();
01097     }
01098 
01099     OS << "0 0\n"; // end representations
01100 
01101   }
01102 
01103   else if (S.ShapeType() == TopAbs_EDGE) {
01104 
01105     // Write the curve geometry
01106 
01107     Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
01108 
01109     OS << " " << TE->Tolerance() << " ";
01110     OS << ((TE->SameParameter()) ? 1 : 0) << " ";
01111     OS << ((TE->SameRange())     ? 1 : 0) << " ";
01112     OS << ((TE->Degenerated())   ? 1 : 0) << "\n";
01113 
01114     Standard_Real first, last;
01115     BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
01116     while (itrc.More()) {
01117       const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
01118       if (CR->IsCurve3D()) {
01119         if (!CR->Curve3D().IsNull()) {
01120           Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
01121           GC->Range(first, last);
01122           OS << "1 ";                               // -1- Curve 3D
01123           OS << " "<<myCurves.Index(CR->Curve3D());
01124           OS << " "<<myLocations.Index(CR->Location());
01125           OS << " "<<first<<" "<<last;
01126           OS << "\n";
01127         }
01128       }
01129       else if (CR->IsCurveOnSurface()) {
01130         Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
01131         GC->Range(first, last);
01132         if (!CR->IsCurveOnClosedSurface())
01133           OS << "2 ";                             // -2- Curve on surf
01134         else
01135           OS << "3 ";                             // -3- Curve on closed surf
01136         OS <<" "<<myCurves2d.Index(CR->PCurve());
01137         if (CR->IsCurveOnClosedSurface()) {
01138           OS <<" " << myCurves2d.Index(CR->PCurve2());
01139           PrintRegularity(CR->Continuity(),OS);
01140         }
01141         OS << " " << mySurfaces.Index(CR->Surface());
01142         OS << " " << myLocations.Index(CR->Location());
01143         OS << " "<<first<<" "<<last;
01144         OS << "\n";
01145 
01146         // Write UV Points // for XML Persistence higher performance
01147         if (myFormatNb == 2)
01148         {
01149           gp_Pnt2d Pf,Pl;
01150           if (CR->IsCurveOnClosedSurface()) {
01151             Handle(BRep_CurveOnClosedSurface) COCS =
01152               Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
01153             COCS->UVPoints2(Pf,Pl);
01154           }
01155           else {
01156             Handle(BRep_CurveOnSurface) COS =
01157               Handle(BRep_CurveOnSurface)::DownCast(CR);
01158             COS->UVPoints(Pf,Pl);
01159           }
01160           OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
01161         }
01162       }
01163       else if (CR->IsRegularity()) {
01164         OS << "4 ";                              // -4- Regularity
01165         PrintRegularity(CR->Continuity(),OS);
01166         OS << " "<<mySurfaces.Index(CR->Surface());
01167         OS << " "<<myLocations.Index(CR->Location());
01168         OS << " "<<mySurfaces.Index(CR->Surface2());
01169         OS << " "<<myLocations.Index(CR->Location2());
01170         OS << "\n";
01171       }
01172       itrc.Next();
01173     }
01174     OS << "0\n"; // end of the list of representations
01175   }
01176    else if (S.ShapeType() == TopAbs_FACE) {
01177 
01178     Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
01179     const TopoDS_Face& F = TopoDS::Face(S);
01180 
01181     if (!(TF->Surface()).IsNull()) {
01182       OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
01183       OS << " ";
01184       // Write the surface geometry
01185       OS << " " <<TF->Tolerance();
01186       OS << " " <<mySurfaces.Index(TF->Surface());
01187       OS << " " <<myLocations.Index(TF->Location());
01188       OS << "\n";
01189     }
01190   }
01191 
01192 }
01193 
01194 
01195 //=======================================================================
01196 //function : Write
01197 //purpose  :
01198 //=======================================================================
01199 
01200 void  OCCShapeAttributeSet::Write(const TopoDS_Shape& S,
01201                                Standard_OStream& OS,
01202                                TDF_Label* l_attr)
01203 {
01204   if (S.IsNull()) OS << "*";
01205   else {
01206     PrintOrientation(S.Orientation(),OS,Standard_True);
01207     OS << myShapes.Extent() - myShapes.FindIndex(S.Located(TopLoc_Location())) + 1;
01208     OS << " " << myLocations.Index(S.Location()) << " ";
01209   }
01210   //Write Attributes
01211   Standard_Integer i, nbShapes = myShapes.Extent();
01212   if(l_attr != NULL)
01213   {
01214     for ( i = 1; i <= nbShapes; i++)
01215     {
01216       const TopoDS_Shape& Sh = myShapes(i);
01217       WriteAttribute(Sh, OS, *l_attr);
01218     }
01219   }
01220 }
01221 
01222 
01223 //=======================================================================
01224 //function : ReadGeometry
01225 //purpose  :
01226 //=======================================================================
01227 
01228 void  OCCShapeAttributeSet::ReadGeometry(const TopAbs_ShapeEnum T,
01229                                          Standard_IStream&      IS,
01230                                          TopoDS_Shape&          S)
01231 {
01232   // Read the geometry
01233 
01234   Standard_Integer val,c,pc,pc2,s,s2,l,l2,t, pt, pt2;
01235   Standard_Real tol,X,Y,Z,first,last,p1,p2;
01236   Standard_Real PfX,PfY,PlX,PlY;
01237   gp_Pnt2d aPf, aPl;
01238   Standard_Boolean closed;
01239 #ifndef DEB
01240   GeomAbs_Shape reg = GeomAbs_C0;
01241 #else
01242   GeomAbs_Shape reg;
01243 #endif
01244   switch (T) {
01245 
01246 
01247     //---------
01248     // vertex
01249     //---------
01250 
01251   case TopAbs_VERTEX :
01252     {
01253       TopoDS_Vertex& V = TopoDS::Vertex(S);
01254 
01255       // Read the point geometry
01256       IS >> tol;
01257       IS >> X >> Y >> Z;
01258       myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
01259       Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
01260 
01261       BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
01262       TopLoc_Location L;
01263 
01264       do {
01265         IS >> p1 >> val;
01266 
01267         Handle(BRep_PointRepresentation) PR;
01268         switch (val) {
01269 
01270         case 1 :
01271           {
01272             IS >> c;
01273 
01274             if (myCurves.Curve(c).IsNull())
01275               break;
01276 
01277             Handle(BRep_PointOnCurve) POC =
01278               new BRep_PointOnCurve(p1,
01279                                     myCurves.Curve(c),
01280                                     L);
01281             PR = POC;
01282           }
01283           break;
01284 
01285         case 2 :
01286           {
01287             IS >> pc >> s;
01288 
01289             if (myCurves2d.Curve2d(pc).IsNull() ||
01290                 mySurfaces.Surface(s).IsNull())
01291               break;
01292 
01293             Handle(BRep_PointOnCurveOnSurface) POC =
01294               new BRep_PointOnCurveOnSurface(p1,
01295                                              myCurves2d.Curve2d(pc),
01296                                              mySurfaces.Surface(s),
01297                                              L);
01298             PR = POC;
01299           }
01300           break;
01301 
01302         case 3 :
01303           {
01304             IS >> p2 >> s;
01305 
01306             if (mySurfaces.Surface(s).IsNull())
01307               break;
01308 
01309             Handle(BRep_PointOnSurface) POC =
01310               new BRep_PointOnSurface(p1,p2,
01311                                       mySurfaces.Surface(s),
01312                                       L);
01313             PR = POC;
01314           }
01315           break;
01316         }
01317 
01318         if (val > 0) {
01319           IS >> l;
01320           if (!PR.IsNull()) {
01321             PR->Location(myLocations.Location(l));
01322             lpr.Append(PR);
01323           }
01324         }
01325       } while (val > 0);
01326     }
01327     break;
01328 
01329 
01330     //---------
01331     // edge
01332     //---------
01333 
01334 
01335     case TopAbs_EDGE :
01336 
01337       // Create an edge
01338       {
01339         TopoDS_Edge& E = TopoDS::Edge(S);
01340 
01341         myBuilder.MakeEdge(E);
01342 
01343         // Read the curve geometry
01344         IS >> tol;
01345         IS >> val;
01346         myBuilder.SameParameter(E,(val == 1));
01347         IS >> val;
01348         myBuilder.SameRange(E,(val == 1));
01349         IS >> val;
01350         myBuilder.Degenerated(E,(val == 1));
01351 
01352         do {
01353           IS >> val;
01354           switch (val) {
01355 
01356           case 1 :                               // -1- Curve 3D
01357             IS >> c >> l;
01358             if (!myCurves.Curve(c).IsNull()) {
01359               myBuilder.UpdateEdge(E,myCurves.Curve(c),
01360                                    myLocations.Location(l),tol);
01361             }
01362             IS >> first >> last;
01363             if (!myCurves.Curve(c).IsNull()) {
01364               Standard_Boolean Only3d = Standard_True;
01365               myBuilder.Range(E,first,last,Only3d);
01366             }
01367             break;
01368 
01369 
01370           case 2 :                               // -2- Curve on surf
01371           case 3 :                               // -3- Curve on closed surf
01372             closed = (val == 3);
01373             IS >> pc;
01374             if (closed) {
01375               IS >> pc2;
01376               reg = ReadRegularity(IS);
01377             }
01378 
01379             // surface, location
01380             IS >> s >> l;
01381 
01382             // range
01383             IS >> first >> last;
01384 
01385             // read UV Points // for XML Persistence higher performance
01386             if (myFormatNb == 2)
01387             {
01388               IS >> PfX >> PfY >> PlX >> PlY;
01389               aPf = gp_Pnt2d(PfX,PfY);
01390               aPl = gp_Pnt2d(PlX,PlY);
01391             }
01392 
01393             if (myCurves2d.Curve2d(pc).IsNull() ||
01394                 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
01395                 mySurfaces.Surface(s).IsNull())
01396               break;
01397 
01398             if (closed) {
01399               if (myFormatNb == 2)
01400                 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
01401                                      myCurves2d.Curve2d(pc2),
01402                                      mySurfaces.Surface(s),
01403                                      myLocations.Location(l),tol,
01404                                      aPf, aPl);
01405               else
01406                 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
01407                                      myCurves2d.Curve2d(pc2),
01408                                      mySurfaces.Surface(s),
01409                                      myLocations.Location(l),tol);
01410 
01411               myBuilder.Continuity(E,
01412                                    mySurfaces.Surface(s),
01413                                    mySurfaces.Surface(s),
01414                                    myLocations.Location(l),
01415                                    myLocations.Location(l),
01416                                    reg);
01417             }
01418             else
01419             {
01420               if (myFormatNb == 2)
01421                 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
01422                                      mySurfaces.Surface(s),
01423                                      myLocations.Location(l),tol,
01424                                      aPf, aPl);
01425               else
01426                 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
01427                                      mySurfaces.Surface(s),
01428                                      myLocations.Location(l),tol);
01429             }
01430             myBuilder.Range(E,
01431                             mySurfaces.Surface(s),
01432                             myLocations.Location(l),
01433                             first,last);
01434             break;
01435 
01436           case 4 :                               // -4- Regularity
01437             reg = ReadRegularity(IS);
01438             IS >> s >> l >> s2 >> l2;
01439             if (mySurfaces.Surface(s).IsNull() ||
01440                 mySurfaces.Surface(s2).IsNull())
01441               break;
01442             myBuilder.Continuity(E,
01443                                  mySurfaces.Surface(s),
01444                                  mySurfaces.Surface(s2),
01445                                  myLocations.Location(l),
01446                                  myLocations.Location(l2),
01447                                  reg);
01448             break;
01449 
01450           case 5 :   // -5- Polygon3D
01451             IS >> c >> l;
01452             myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), myLocations.Location(l));
01453             break;
01454 
01455           case 6 :
01456           case 7 :
01457             closed = (val == 7);
01458             IS >> pt;
01459             if (closed) {
01460               IS >> pt2;
01461             }
01462             IS >> t >> l;
01463             if (closed) {
01464               myBuilder.UpdateEdge
01465                 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
01466                  Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
01467                  Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
01468                  myLocations.Location(l));
01469             }
01470             else {
01471               myBuilder.UpdateEdge
01472                 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
01473                  Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
01474                  myLocations.Location(l));
01475             }
01476             // range
01477 
01478             break;
01479 
01480           }
01481         } while (val > 0);
01482       }
01483     break;
01484 
01485 
01486     //---------
01487     // wire
01488     //---------
01489 
01490   case TopAbs_WIRE :
01491     myBuilder.MakeWire(TopoDS::Wire(S));
01492     break;
01493 
01494 
01495     //---------
01496     // face
01497     //---------
01498   case TopAbs_FACE :
01499     {
01500     // create a face :
01501     TopoDS_Face& F = TopoDS::Face(S);
01502     myBuilder.MakeFace(F);
01503 
01504     IS >> val; // natural restriction
01505     if (val == 0 || val == 1) {
01506       IS >> tol >> s >> l;
01507       if (!mySurfaces.Surface(s).IsNull()) {
01508         myBuilder.UpdateFace(TopoDS::Face(S),
01509                              mySurfaces.Surface(s),
01510                              myLocations.Location(l),tol);
01511         myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
01512       }
01513     }
01514 
01515     // BUC60769
01516     std::string line;
01517     std::getline( IS, line );
01518     std::getline( IS, line );
01519     std::istringstream str( line );
01520 
01521     if (str.get() == '2') {
01522       // cas triangulation
01523       str >> s;
01524       myBuilder.UpdateFace(TopoDS::Face(S),
01525                            Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
01526     }
01527 //    else IS.seekg(pos);
01528     }
01529     break;
01530 
01531 
01532     //---------
01533     // shell
01534     //---------
01535 
01536   case TopAbs_SHELL :
01537     myBuilder.MakeShell(TopoDS::Shell(S));
01538     break;
01539 
01540 
01541     //---------
01542     // solid
01543     //---------
01544 
01545   case TopAbs_SOLID :
01546     myBuilder.MakeSolid(TopoDS::Solid(S));
01547     break;
01548 
01549 
01550     //---------
01551     // compsolid
01552     //---------
01553 
01554   case TopAbs_COMPSOLID :
01555     myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
01556     break;
01557 
01558 
01559     //---------
01560     // compound
01561     //---------
01562 
01563   case TopAbs_COMPOUND :
01564     myBuilder.MakeCompound(TopoDS::Compound(S));
01565     break;
01566 
01567   default:
01568     break;
01569   }
01570 
01571 }
01572 
01573 //=======================================================================
01574 //function : ReadPolygonOnTriangulation
01575 //purpose  :
01576 //=======================================================================
01577 
01578 void OCCShapeAttributeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
01579 {
01580     std::string buffer;
01581     IS >> buffer;
01582     if (buffer.find("PolygonOnTriangulations") == std::string::npos)
01583       return;
01584 
01585     Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
01586     Standard_Integer hasparameters;
01587     Standard_Real par;
01588     Handle(TColStd_HArray1OfReal) Param;
01589     Handle(Poly_PolygonOnTriangulation) Poly;
01590     IS >> nbpol;
01591     for (i=1; i<=nbpol; i++) {
01592       IS >> nbnodes;
01593       TColStd_Array1OfInteger Nodes(1, nbnodes);
01594       for (j = 1; j <= nbnodes; j++) {
01595         IS >> val;
01596         Nodes(j) = val;
01597       }
01598       IS >> buffer;
01599       Standard_Real def;
01600       IS >> def;
01601       IS >> hasparameters;
01602       if (hasparameters) {
01603         TColStd_Array1OfReal Param1(1, nbnodes);
01604         for (j = 1; j <= nbnodes; j++) {
01605           IS >> par;
01606           Param1(j) = par;
01607         }
01608         Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
01609       }
01610       else Poly = new Poly_PolygonOnTriangulation(Nodes);
01611       Poly->Deflection(def);
01612       myNodes.Add(Poly);
01613     }
01614 }
01615 
01616 //=======================================================================
01617 //function : ReadPolygon3D
01618 //purpose  :
01619 //=======================================================================
01620 
01621 void OCCShapeAttributeSet::ReadPolygon3D(Standard_IStream& IS)
01622 {
01623     std::string buffer;
01624     //  Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
01625     Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;  Standard_Real d, x, y, z;
01626 
01627     IS >> buffer;
01628     if (buffer.find("Polygon3D") == std::string::npos)
01629       return;
01630   
01631     Handle(Poly_Polygon3D) P;
01632     IS >> nbpol;
01633     for (i=1; i<=nbpol; i++) {
01634       IS >> nbnodes;
01635       IS >> hasparameters;
01636       TColgp_Array1OfPnt Nodes(1, nbnodes);
01637       IS >> d;
01638       for (j = 1; j <= nbnodes; j++) {
01639         IS >> x >> y >> z;
01640         Nodes(j).SetCoord(x,y,z);
01641       }
01642       if (hasparameters) {
01643         TColStd_Array1OfReal Param(1,nbnodes);
01644         for (p = 1; p <= nbnodes; p++) {
01645           IS >> Param(p);
01646         }
01647         P = new Poly_Polygon3D(Nodes, Param);
01648       }
01649       else P = new Poly_Polygon3D(Nodes);
01650       P->Deflection(d);
01651       myPolygons3D.Add(P);
01652     }
01653 }
01654 
01655 //=======================================================================
01656 //function : ReadTriangulation
01657 //purpose  :
01658 //=======================================================================
01659 
01660 void OCCShapeAttributeSet::ReadTriangulation(Standard_IStream& IS)
01661 {
01662   std::string buffer;
01663   //  Standard_Integer i, j, val, nbtri;
01664   Standard_Integer i, j, nbtri =0;
01665   Standard_Real d, x, y, z;
01666   Standard_Integer nbNodes =0, nbTriangles=0;
01667   Standard_Boolean hasUV= Standard_False;
01668 
01669   Handle(Poly_Triangulation) T;
01670 
01671   IS >> buffer;
01672   if (buffer.find("Triangulations") != std::string::npos) {
01673     IS >> nbtri;
01674     for (i=1; i<=nbtri; i++) {
01675       IS >> nbNodes >> nbTriangles >> hasUV;
01676       IS >> d;
01677 
01678       TColgp_Array1OfPnt Nodes(1, nbNodes);
01679       TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
01680 
01681       for (j = 1; j <= nbNodes; j++) {
01682         IS >> x >> y >> z;
01683         Nodes(j).SetCoord(x,y,z);
01684       }
01685 
01686       if (hasUV) {
01687         for (j = 1; j <= nbNodes; j++) {
01688           IS >> x >> y;
01689           UVNodes(j).SetCoord(x,y);
01690         }
01691       }
01692 
01693 
01694       // read the triangles
01695       Standard_Integer n1,n2,n3;
01696       Poly_Array1OfTriangle Triangles(1, nbTriangles);
01697       for (j = 1; j <= nbTriangles; j++) {
01698         IS >> n1 >> n2 >> n3;
01699         Triangles(j).Set(n1,n2,n3);
01700       }
01701 
01702       if (hasUV) T =  new Poly_Triangulation(Nodes,UVNodes,Triangles);
01703       else T = new Poly_Triangulation(Nodes,Triangles);
01704 
01705       T->Deflection(d);
01706 
01707       myTriangulations.Add(T);
01708     }
01709   }
01710 }
01711 
01712 //=======================================================================
01713 //function : Clear
01714 //purpose  :
01715 //=======================================================================
01716 
01717 void  OCCShapeAttributeSet::Clear()
01718 {
01719   mySurfaces.Clear();
01720   myCurves.Clear();
01721   myCurves2d.Clear();
01722   myPolygons3D.Clear();
01723   myPolygons2D.Clear();
01724   myNodes.Clear();
01725   myTriangulations.Clear();
01726   myShapes.Clear();
01727   my_ShapeNum_Location.clear();
01728   myLocations.Clear();
01729 }
01730 
01731 //=======================================================================
01732 //function : Read
01733 //purpose  :
01734 //=======================================================================
01735 
01736 void  OCCShapeAttributeSet::Read(TopoDS_Shape& S,
01737                                  Standard_IStream& IS,
01738                                  const int nbshapes,
01739                                  TDF_Label* label )
01740 {
01741   std::string buffer, buffer_attr;
01742   IS >> buffer;
01743   std::map<int,int>::iterator it;
01744   if (buffer[0] == '*')
01745     S = TopoDS_Shape();
01746   else {
01747     char type;
01748     int num;
01749     std::istringstream buffstr(buffer);
01750     buffstr >> type >> num;
01751     S = myShapes(nbshapes - num + 1);
01752     switch (type) {
01753 
01754     case '+' :
01755       S.Orientation(TopAbs_FORWARD);
01756       break;
01757 
01758     case '-' :
01759       S.Orientation(TopAbs_REVERSED);
01760       break;
01761 
01762     case 'i' :
01763       S.Orientation(TopAbs_INTERNAL);
01764       break;
01765 
01766     case 'e' :
01767       S.Orientation(TopAbs_EXTERNAL);
01768       break;
01769     }
01770 
01771     Standard_Integer l;
01772     IS >> l;
01773     S.Location(myLocations.Location(l));
01774 
01775     int shape_num = nbshapes - num + 1;
01776     typedef std::pair <int,int> sh_loc_pair; 
01777     it = my_ShapeNum_Location.find(shape_num);
01778     if(it == my_ShapeNum_Location.end())
01779       my_ShapeNum_Location.insert(sh_loc_pair(shape_num, l));
01780   }
01781   if(label != NULL)
01782   {
01783     Standard_Integer i, nbShapes = myShapes.Extent();
01784     for ( i = 1; i <= nbShapes; i++)
01785     {
01786       TopoDS_Shape Sh = myShapes(i);
01787       IS >> buffer_attr;
01788       if(buffer_attr[0] != '*' && buffer_attr[0] != 'C')
01789         break;
01790       if(buffer_attr[0] == '*') //empty attributes for this shape
01791         continue;
01792       it = my_ShapeNum_Location.find(i);
01793       if(it != my_ShapeNum_Location.end())
01794       {
01795         int loc_num = it->second;
01796         if (loc_num > 0)
01797           Sh.Location(myLocations.Location(loc_num));
01798       }
01799       ReadAttribute(Sh, IS,*label);
01800     }
01801   }
01802 }
01803 
01804 //=======================================================================
01805 //function : Check
01806 //purpose  :
01807 //=======================================================================
01808 
01809 void OCCShapeAttributeSet::Check(const TopAbs_ShapeEnum T,
01810                                  TopoDS_Shape&          S)
01811 {
01812   if (T == TopAbs_FACE) {
01813     const TopoDS_Face& F = TopoDS::Face(S);
01814     BRepTools::Update(F);
01815   }
01816 }
01817 
01818 //=======================================================================
01819 //function : NbShapes
01820 //purpose  :
01821 //=======================================================================
01822 
01823 int  OCCShapeAttributeSet::NbShapes() 
01824 {
01825   return myShapes.Extent();
01826 }
01827 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines