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
33 #include "GEOM_Client.hxx"
34 #include <SALOMEconfig.h>
36 #include "utilities.h"
38 #include CORBA_SERVER_HEADER(SALOMEDS)
39 #include CORBA_SERVER_HEADER(GEOM_Gen)
41 #include <BRep_Builder.hxx>
42 #include <BRepTools.hxx>
43 #include <TopoDS_Shape.hxx>
44 #include <TopoDS_Compound.hxx>
45 #include <TCollection_AsciiString.hxx>
46 #include <TopExp_Explorer.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
53 #define HST_CLIENT_LEN 256
57 //=======================================================================
60 //=======================================================================
61 TopoDS_Shape GEOM_Client::Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
63 string hst_client = GetHostname();
65 Engines::Container_var ctn_server = geom->GetContainerRef();
66 long pid_server = ctn_server->getPID();
68 if ( (pid_client==pid_server) && (strcmp(hst_client.c_str(), ctn_server->getHostName())==0) ) {
69 TopoDS_Shape* S = (TopoDS_Shape*)(aShape->getShape());
72 /* get sequence of bytes of resulting brep shape from GEOM server */
74 SALOMEDS::TMPFile_var SeqFile = aShape->GetShapeStream();
75 int sizebuf = SeqFile->length();
77 buf = (char*) &SeqFile[0];
78 istrstream streamBrep(buf,sizebuf);
79 BRep_Builder aBuilder;
80 BRepTools::Read(S, streamBrep, aBuilder);
86 //=======================================================================
87 // function : Create()
88 // purpose : Create in client not in a container
89 //=======================================================================
90 GEOM_Client::GEOM_Client()
92 pid_client = (long)getpid();
95 //=======================================================================
96 // function : Create()
98 //=======================================================================
99 GEOM_Client::GEOM_Client(Engines::Container_ptr client)
101 pid_client = client->getPID();
104 //=======================================================================
107 //=======================================================================
108 Standard_Integer GEOM_Client::Find( const TCollection_AsciiString& IOR, TopoDS_Shape& S )
110 for ( Standard_Integer i = 1; i<= myIORs.Length(); i++ ) {
111 if (myIORs.Value(i).IsEqual(IOR)) {
112 S = myShapes.Value(i);
119 //=======================================================================
122 //=======================================================================
123 Standard_Integer GEOM_Client::Find( const TopoDS_Shape& S, TCollection_AsciiString& IOR )
125 for ( Standard_Integer i = 1; i<= myShapes.Length(); i++ ) {
126 if (myShapes.Value(i) == S) {
127 IOR = myIORs.Value(i);
134 //=======================================================================
137 //=======================================================================
138 void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S )
144 //=======================================================================
145 // function : RemoveShapeFromBuffer()
146 // purpose : Remove shape from Client Buffer
147 //=======================================================================
148 void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR)
150 if( myIORs.IsEmpty() )
154 Standard_Integer anIndex = Find( IOR, S ) ;
156 myIORs.Remove(anIndex) ;
157 myShapes.Remove(anIndex) ;
163 //=======================================================================
164 // function : ClearClientBuffer()
165 // purpose : purge buffer
166 //=======================================================================
167 void GEOM_Client::ClearClientBuffer()
169 if( myIORs.IsEmpty() )
176 //=======================================================================
177 // function : BufferLength()
179 //=======================================================================
180 unsigned int GEOM_Client::BufferLength()
182 return myIORs.Length() ;
186 //=======================================================================
187 // function : GetShape()
189 //=======================================================================
191 TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
194 TCollection_AsciiString IOR = geom->GetStringFromIOR(aShape);
195 Standard_Integer anIndex = Find(IOR, S);
197 if (anIndex !=0 ) return S ;
199 /******* in case of a MAIN GEOM::SHAPE ********/
200 if (aShape->IsMainShape()) {
201 S = Load(geom, aShape);
206 /******* in case of SUB GEOM::SHAPE ***********/
207 // Load and Explore the Main Shape
208 TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape());
209 GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
211 TopTools_IndexedMapOfShape anIndices;
212 TopExp::MapShapes(aMainShape, anIndices);
214 /* Case of only one subshape */
215 if (list->length() == 1)
217 S = anIndices.FindKey(list[0]);
221 TopoDS_Compound aCompound;
222 B.MakeCompound(aCompound);
223 for(int i=0; i<list->length(); i++) {
224 TopoDS_Shape aSubShape = anIndices.FindKey(list[i]);
225 B.Add(aCompound, aSubShape);