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
29 #include <Standard_Stream.hxx>
33 #include "GEOM_Client.hxx"
34 #include <SALOMEconfig.h>
36 #include "utilities.h"
38 #include <BRep_Builder.hxx>
39 #include <BRepTools.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Compound.hxx>
42 #include <TCollection_AsciiString.hxx>
43 #include <TopExp_Explorer.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
54 #include CORBA_SERVER_HEADER(SALOMEDS)
55 #include CORBA_SERVER_HEADER(GEOM_Gen)
57 #define HST_CLIENT_LEN 256
61 //=======================================================================
64 //=======================================================================
65 TopoDS_Shape GEOM_Client::Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
67 string hst_client = GetHostname();
69 Engines::Container_var ctn_server = geom->GetContainerRef();
70 long pid_server = ctn_server->getPID();
72 if ( (pid_client==pid_server) && (strcmp(hst_client.c_str(), ctn_server->getHostName())==0) ) {
73 TopoDS_Shape* S = (TopoDS_Shape*)(aShape->getShape());
76 /* get sequence of bytes of resulting brep shape from GEOM server */
78 SALOMEDS::TMPFile_var SeqFile = aShape->GetShapeStream();
79 int sizebuf = SeqFile->length();
81 buf = (char*) &SeqFile[0];
82 istrstream streamBrep(buf,sizebuf);
83 BRep_Builder aBuilder;
84 BRepTools::Read(S, streamBrep, aBuilder);
90 //=======================================================================
91 // function : Create()
92 // purpose : Create in client not in a container
93 //=======================================================================
94 GEOM_Client::GEOM_Client()
104 //=======================================================================
105 // function : Create()
107 //=======================================================================
108 GEOM_Client::GEOM_Client(Engines::Container_ptr client)
110 pid_client = client->getPID();
113 //=======================================================================
116 //=======================================================================
117 Standard_Integer GEOM_Client::Find( const TCollection_AsciiString& IOR, TopoDS_Shape& S )
119 for ( Standard_Integer i = 1; i<= myIORs.Length(); i++ ) {
120 if (myIORs.Value(i).IsEqual(IOR)) {
121 S = myShapes.Value(i);
128 //=======================================================================
131 //=======================================================================
132 Standard_Integer GEOM_Client::Find( const TopoDS_Shape& S, TCollection_AsciiString& IOR )
134 for ( Standard_Integer i = 1; i<= myShapes.Length(); i++ ) {
135 if (myShapes.Value(i) == S) {
136 IOR = myIORs.Value(i);
143 //=======================================================================
146 //=======================================================================
147 void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S )
153 //=======================================================================
154 // function : RemoveShapeFromBuffer()
155 // purpose : Remove shape from Client Buffer
156 //=======================================================================
157 void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR)
159 if( myIORs.IsEmpty() )
163 Standard_Integer anIndex = Find( IOR, S ) ;
165 myIORs.Remove(anIndex) ;
166 myShapes.Remove(anIndex) ;
172 //=======================================================================
173 // function : ClearClientBuffer()
174 // purpose : purge buffer
175 //=======================================================================
176 void GEOM_Client::ClearClientBuffer()
178 if( myIORs.IsEmpty() )
185 //=======================================================================
186 // function : BufferLength()
188 //=======================================================================
189 unsigned int GEOM_Client::BufferLength()
191 return myIORs.Length() ;
195 //=======================================================================
196 // function : GetShape()
198 //=======================================================================
200 TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
203 TCollection_AsciiString IOR = geom->GetStringFromIOR(aShape);
204 Standard_Integer anIndex = Find(IOR, S);
206 if (anIndex !=0 ) return S ;
208 /******* in case of a MAIN GEOM::SHAPE ********/
209 if (aShape->IsMainShape()) {
210 S = Load(geom, aShape);
215 /******* in case of SUB GEOM::SHAPE ***********/
216 // Load and Explore the Main Shape
217 TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape());
218 GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
220 TopTools_IndexedMapOfShape anIndices;
221 TopExp::MapShapes(aMainShape, anIndices);
223 /* Case of only one subshape */
224 if (list->length() == 1)
226 S = anIndices.FindKey(list[0]);
230 TopoDS_Compound aCompound;
231 B.MakeCompound(aCompound);
232 for(int i=0; i<list->length(); i++) {
233 TopoDS_Shape aSubShape = anIndices.FindKey(list[i]);
234 B.Add(aCompound, aSubShape);