2 // File : GEOM_Client.cxx
4 // Author : Yves FRICAUD/Lucien PIGNOLONI
7 // Copyright : Open CASCADE
10 #include "GEOM_Client.hxx"
11 #include <SALOMEconfig.h>
12 #include "utilities.h"
14 #include CORBA_SERVER_HEADER(GEOM_Gen)
16 #include <BRep_Builder.hxx>
17 #include <BRepTools.hxx>
18 #include <TopoDS_Shape.hxx>
19 #include <TopoDS_Compound.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <TopExp_Explorer.hxx>
23 #include <TColStd_MapOfInteger.hxx>
24 #include <TopoDS_Iterator.hxx>
25 #include <TopTools_MapOfShape.hxx>
26 #include <TopTools_ListIteratorOfListOfShape.hxx>
27 #include <TopTools_ListOfShape.hxx>
31 //=======================================================================
34 //=======================================================================
35 static TopoDS_Shape Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Shape_ptr aShape )
38 /* get sequence of bytes of resulting brep shape from GEOM server */
39 GEOM::GEOM_Shape::TMPFile_var SeqFile = aShape->GetShapeStream();
40 int sizebuf = SeqFile->length();
42 buf = (char*) &SeqFile[0];
43 istrstream streamBrep(buf,sizebuf);
44 BRep_Builder aBuilder;
45 BRepTools::Read(S, streamBrep, aBuilder);
50 //=======================================================================
51 // function : Create()
53 //=======================================================================
54 GEOM_Client::GEOM_Client()
59 //=======================================================================
62 //=======================================================================
63 Standard_Integer GEOM_Client::Find( const TCollection_AsciiString& IOR, TopoDS_Shape& S )
65 for ( Standard_Integer i = 1; i<= myIORs.Length(); i++ ) {
66 if (myIORs.Value(i).IsEqual(IOR)) {
67 S = myShapes.Value(i);
75 //=======================================================================
78 //=======================================================================
79 void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S )
85 //=======================================================================
86 // function : RemoveShapeFromBuffer()
87 // purpose : Remove shape from Client Buffer
88 //=======================================================================
89 void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& shapeIOR )
91 if( myIORs.IsEmpty() )
95 Standard_Integer anIndex = Find( shapeIOR, S ) ;
97 myIORs.Remove(anIndex) ;
98 myShapes.Remove(anIndex) ;
104 //=======================================================================
105 // function : ClearClientBuffer()
106 // purpose : purge buffer
107 //=======================================================================
108 void GEOM_Client::ClearClientBuffer()
110 if( myIORs.IsEmpty() )
117 //=======================================================================
118 // function : BufferLength()
120 //=======================================================================
121 unsigned int GEOM_Client::BufferLength()
123 return myIORs.Length() ;
127 //=======================================================================
128 // function : GetShape()
130 //=======================================================================
132 TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Shape_ptr aShape )
136 TCollection_AsciiString IOR(aShape->Name());
137 Standard_Integer anIndex = Find(IOR, S);
145 /******* in case of a MAIN GEOM::SHAPE ********/
146 if (aShape->IsMainShape()) {
147 S = Load(geom, aShape);
152 /******* in case of SUB GEOM::SHAPE ***********/
153 // Load and Explore the Main Shape
154 TopoDS_Shape MainShape = GetShape (geom, geom->GetIORFromString(aShape->MainName()));
155 GEOM::GEOM_Shape::ListOfSubShapeID_var list = aShape->Index();
157 Standard_Integer j = 1;
159 TopAbs_ShapeEnum ShapeType = TopAbs_ShapeEnum(aShape->ShapeType());
161 /* Case of only one subshape */
162 if (list->length() == 1)
164 if (ShapeType == TopAbs_COMPOUND)
167 TopTools_ListOfShape CL;
168 CL.Append( MainShape );
169 TopTools_ListIteratorOfListOfShape itC;
170 for (itC.Initialize( CL ); itC.More(); itC.Next())
172 for (it.Initialize( itC.Value() ); it.More(); it.Next())
174 if ( it.Value().ShapeType() == TopAbs_COMPOUND)
183 CL.Append( it.Value() );
190 TopTools_MapOfShape M;
191 for (exp.Init(MainShape, ShapeType); exp.More(); exp.Next()) {
192 if ( M.Add(exp.Current()) )
206 /* Case of a compound containing two or more sub shapes (not a main shape compound !) */
208 /* Warning : the compound when representing sub shapes must be explored in a sub type */
209 /* that is NOT ShapeType=aShape->ShapeType()= TopAbs_COMPOUND ! */
210 /* We have to retrieve the exact sub type of shapes contained in the compound first ! */
212 TopAbs_ShapeEnum exactSubType ;
213 S = Load( geom, aShape );
214 it.Initialize( S, true, true ) ;
216 exactSubType = it.Value().ShapeType() ;
218 TColStd_MapOfInteger MapIndex;
219 Standard_Integer nbSS = list->length();
220 TopoDS_Compound Comp;
221 B.MakeCompound(Comp);
223 for (Standard_Integer i=1; i<=nbSS; i++)
224 MapIndex.Add(list[i-1]);
226 for (exp.Init(MainShape, exactSubType), j=1; exp.More() ; exp.Next(), j++) {
227 if ( MapIndex.Contains(j) ) {
228 B.Add( Comp, exp.Current() );