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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : GEOM_Client.cxx
25 // Author : Yves FRICAUD/Lucien PIGNOLONI
31 #include <Standard_Stream.hxx>
33 #include <Standard_Stream.hxx>
37 #include "GEOM_Client.hxx"
38 #include <SALOMEconfig.h>
40 #include "utilities.h"
42 #include <BRep_Builder.hxx>
43 #include <BRepTools.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopoDS_Compound.hxx>
46 #include <TCollection_AsciiString.hxx>
47 #include <TopExp_Explorer.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
58 #include CORBA_SERVER_HEADER(SALOMEDS)
59 #include CORBA_SERVER_HEADER(GEOM_Gen)
61 #define HST_CLIENT_LEN 256
65 //=======================================================================
68 //=======================================================================
69 TopoDS_Shape GEOM_Client::Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
71 string hst_client = GetHostname();
73 Engines::Container_var ctn_server = geom->GetContainerRef();
74 long pid_server = ctn_server->getPID();
76 if ( (pid_client==pid_server) && (strcmp(hst_client.c_str(), ctn_server->getHostName())==0) ) {
77 TopoDS_Shape* S = (TopoDS_Shape*)(aShape->getShape());
80 /* get sequence of bytes of resulting brep shape from GEOM server */
82 SALOMEDS::TMPFile_var SeqFile = aShape->GetShapeStream();
83 int sizebuf = SeqFile->length();
85 buf = (char*) &SeqFile[0];
86 istrstream streamBrep(buf,sizebuf);
87 BRep_Builder aBuilder;
88 BRepTools::Read(S, streamBrep, aBuilder);
94 //=======================================================================
95 // function : Create()
96 // purpose : Create in client not in a container
97 //=======================================================================
98 GEOM_Client::GEOM_Client()
108 //=======================================================================
109 // function : Create()
111 //=======================================================================
112 GEOM_Client::GEOM_Client(Engines::Container_ptr client)
114 pid_client = client->getPID();
117 //=======================================================================
120 //=======================================================================
121 Standard_Integer GEOM_Client::Find( const TCollection_AsciiString& IOR, TopoDS_Shape& S )
123 for ( Standard_Integer i = 1; i<= myIORs.Length(); i++ ) {
124 if (myIORs.Value(i).IsEqual(IOR)) {
125 S = myShapes.Value(i);
132 //=======================================================================
135 //=======================================================================
136 Standard_Integer GEOM_Client::Find( const TopoDS_Shape& S, TCollection_AsciiString& IOR )
138 for ( Standard_Integer i = 1; i<= myShapes.Length(); i++ ) {
139 if (myShapes.Value(i) == S) {
140 IOR = myIORs.Value(i);
147 //=======================================================================
150 //=======================================================================
151 void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S )
157 //=======================================================================
158 // function : RemoveShapeFromBuffer()
159 // purpose : Remove shape from Client Buffer
160 //=======================================================================
161 void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR)
163 if( myIORs.IsEmpty() )
167 Standard_Integer anIndex = Find( IOR, S ) ;
169 myIORs.Remove(anIndex) ;
170 myShapes.Remove(anIndex) ;
176 //=======================================================================
177 // function : ClearClientBuffer()
178 // purpose : purge buffer
179 //=======================================================================
180 void GEOM_Client::ClearClientBuffer()
182 if( myIORs.IsEmpty() )
189 //=======================================================================
190 // function : BufferLength()
192 //=======================================================================
193 unsigned int GEOM_Client::BufferLength()
195 return myIORs.Length() ;
199 //=======================================================================
200 // function : GetShape()
202 //=======================================================================
203 TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
206 TCollection_AsciiString IOR = geom->GetStringFromIOR(aShape);
207 Standard_Integer anIndex = Find(IOR, S);
209 if (anIndex != 0) return S;
211 /******* in case of a MAIN GEOM::SHAPE ********/
212 if (aShape->IsMainShape()) {
213 S = Load(geom, aShape);
218 /******* in case of SUB GEOM::SHAPE ***********/
219 // Load and Explore the Main Shape
220 TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape());
221 GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
223 TopTools_IndexedMapOfShape anIndices;
224 TopExp::MapShapes(aMainShape, anIndices);
226 /* Case of only one subshape */
227 if (list->length() == 1 && list[0] > 0) {
228 S = anIndices.FindKey(list[0]);
232 TopoDS_Compound aCompound;
233 B.MakeCompound(aCompound);
234 for (int i = 0; i < list->length(); i++) {
235 if (0 < list[i] && list[i] <= anIndices.Extent()) {
236 TopoDS_Shape aSubShape = anIndices.FindKey(list[i]);
237 B.Add(aCompound, aSubShape);