1 // GEOM GEOMClient : tool to transfer BREP files from GEOM server to GEOM client
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GEOM_Client.cxx
25 // Author : Yves FRICAUD/Lucien PIGNOLONI
30 #include "GEOM_Client.hxx"
31 #include <SALOMEconfig.h>
32 #include "utilities.h"
34 #include CORBA_SERVER_HEADER(GEOM_Gen)
36 #include <BRep_Builder.hxx>
37 #include <BRepTools.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Compound.hxx>
40 #include <TCollection_AsciiString.hxx>
41 #include <TopExp_Explorer.hxx>
43 #include <TColStd_MapOfInteger.hxx>
44 #include <TopoDS_Iterator.hxx>
45 #include <TopTools_MapOfShape.hxx>
46 #include <TopTools_ListIteratorOfListOfShape.hxx>
47 #include <TopTools_ListOfShape.hxx>
51 //=======================================================================
54 //=======================================================================
55 static TopoDS_Shape Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Shape_ptr aShape )
58 /* get sequence of bytes of resulting brep shape from GEOM server */
59 GEOM::GEOM_Shape::TMPFile_var SeqFile = aShape->GetShapeStream();
60 int sizebuf = SeqFile->length();
62 buf = (char*) &SeqFile[0];
63 istrstream streamBrep(buf,sizebuf);
64 BRep_Builder aBuilder;
65 BRepTools::Read(S, streamBrep, aBuilder);
70 //=======================================================================
71 // function : Create()
73 //=======================================================================
74 GEOM_Client::GEOM_Client()
79 //=======================================================================
82 //=======================================================================
83 Standard_Integer GEOM_Client::Find( const TCollection_AsciiString& IOR, TopoDS_Shape& S )
85 for ( Standard_Integer i = 1; i<= myIORs.Length(); i++ ) {
86 if (myIORs.Value(i).IsEqual(IOR)) {
87 S = myShapes.Value(i);
95 //=======================================================================
98 //=======================================================================
99 void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S )
105 //=======================================================================
106 // function : RemoveShapeFromBuffer()
107 // purpose : Remove shape from Client Buffer
108 //=======================================================================
109 void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& shapeIOR )
111 if( myIORs.IsEmpty() )
115 Standard_Integer anIndex = Find( shapeIOR, S ) ;
117 myIORs.Remove(anIndex) ;
118 myShapes.Remove(anIndex) ;
124 //=======================================================================
125 // function : ClearClientBuffer()
126 // purpose : purge buffer
127 //=======================================================================
128 void GEOM_Client::ClearClientBuffer()
130 if( myIORs.IsEmpty() )
137 //=======================================================================
138 // function : BufferLength()
140 //=======================================================================
141 unsigned int GEOM_Client::BufferLength()
143 return myIORs.Length() ;
147 //=======================================================================
148 // function : GetShape()
150 //=======================================================================
152 TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Shape_ptr aShape )
156 TCollection_AsciiString IOR(aShape->Name());
157 Standard_Integer anIndex = Find(IOR, S);
165 /******* in case of a MAIN GEOM::SHAPE ********/
166 if (aShape->IsMainShape()) {
167 S = Load(geom, aShape);
172 /******* in case of SUB GEOM::SHAPE ***********/
173 // Load and Explore the Main Shape
174 TopoDS_Shape MainShape = GetShape (geom, geom->GetIORFromString(aShape->MainName()));
175 GEOM::GEOM_Shape::ListOfSubShapeID_var list = aShape->Index();
177 Standard_Integer j = 1;
179 TopAbs_ShapeEnum ShapeType = TopAbs_ShapeEnum(aShape->ShapeType());
181 /* Case of only one subshape */
182 if (list->length() == 1)
184 if (ShapeType == TopAbs_COMPOUND)
187 TopTools_ListOfShape CL;
188 CL.Append( MainShape );
189 TopTools_ListIteratorOfListOfShape itC;
190 for (itC.Initialize( CL ); itC.More(); itC.Next())
192 for (it.Initialize( itC.Value() ); it.More(); it.Next())
194 if ( it.Value().ShapeType() == TopAbs_COMPOUND)
203 CL.Append( it.Value() );
210 TopTools_MapOfShape M;
211 for (exp.Init(MainShape, ShapeType); exp.More(); exp.Next()) {
212 if ( M.Add(exp.Current()) )
226 /* Case of a compound containing two or more sub shapes (not a main shape compound !) */
228 /* Warning : the compound when representing sub shapes must be explored in a sub type */
229 /* that is NOT ShapeType=aShape->ShapeType()= TopAbs_COMPOUND ! */
230 /* We have to retrieve the exact sub type of shapes contained in the compound first ! */
232 TopAbs_ShapeEnum exactSubType ;
233 S = Load( geom, aShape );
234 it.Initialize( S, true, true ) ;
236 exactSubType = it.Value().ShapeType() ;
238 TColStd_MapOfInteger MapIndex;
239 Standard_Integer nbSS = list->length();
240 TopoDS_Compound Comp;
241 B.MakeCompound(Comp);
243 for (Standard_Integer i=1; i<=nbSS; i++)
244 MapIndex.Add(list[i-1]);
246 for (exp.Init(MainShape, exactSubType), j=1; exp.More() ; exp.Next(), j++) {
247 if ( MapIndex.Contains(j) ) {
248 B.Add( Comp, exp.Current() );