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>
33 #include "utilities.h"
35 #include CORBA_SERVER_HEADER(SALOMEDS)
36 #include CORBA_SERVER_HEADER(GEOM_Gen)
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>
50 #define HST_CLIENT_LEN 256
54 //=======================================================================
57 //=======================================================================
58 TopoDS_Shape GEOM_Client::Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
60 string hst_client = GetHostname();
62 Engines::Container_var ctn_server = geom->GetContainerRef();
63 long pid_server = ctn_server->getPID();
65 if ( (pid_client==pid_server) && (strcmp(hst_client.c_str(), ctn_server->getHostName())==0) ) {
66 TopoDS_Shape* S = (TopoDS_Shape*)(aShape->getShape());
69 /* get sequence of bytes of resulting brep shape from GEOM server */
71 SALOMEDS::TMPFile_var SeqFile = aShape->GetShapeStream();
72 int sizebuf = SeqFile->length();
74 buf = (char*) &SeqFile[0];
75 istrstream streamBrep(buf,sizebuf);
76 BRep_Builder aBuilder;
77 BRepTools::Read(S, streamBrep, aBuilder);
83 //=======================================================================
84 // function : Create()
85 // purpose : Create in client not in a container
86 //=======================================================================
87 GEOM_Client::GEOM_Client()
89 pid_client = (long)getpid();
92 //=======================================================================
93 // function : Create()
95 //=======================================================================
96 GEOM_Client::GEOM_Client(Engines::Container_ptr client)
98 pid_client = client->getPID();
101 //=======================================================================
104 //=======================================================================
105 Standard_Integer GEOM_Client::Find( const TCollection_AsciiString& IOR, TopoDS_Shape& S )
107 for ( Standard_Integer i = 1; i<= myIORs.Length(); i++ ) {
108 if (myIORs.Value(i).IsEqual(IOR)) {
109 S = myShapes.Value(i);
116 //=======================================================================
119 //=======================================================================
120 Standard_Integer GEOM_Client::Find( const TopoDS_Shape& S, TCollection_AsciiString& IOR )
122 for ( Standard_Integer i = 1; i<= myShapes.Length(); i++ ) {
123 if (myShapes.Value(i) == S) {
124 IOR = myIORs.Value(i);
131 //=======================================================================
134 //=======================================================================
135 void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S )
141 //=======================================================================
142 // function : RemoveShapeFromBuffer()
143 // purpose : Remove shape from Client Buffer
144 //=======================================================================
145 void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR)
147 if( myIORs.IsEmpty() )
151 Standard_Integer anIndex = Find( IOR, S ) ;
153 myIORs.Remove(anIndex) ;
154 myShapes.Remove(anIndex) ;
160 //=======================================================================
161 // function : ClearClientBuffer()
162 // purpose : purge buffer
163 //=======================================================================
164 void GEOM_Client::ClearClientBuffer()
166 if( myIORs.IsEmpty() )
173 //=======================================================================
174 // function : BufferLength()
176 //=======================================================================
177 unsigned int GEOM_Client::BufferLength()
179 return myIORs.Length() ;
183 //=======================================================================
184 // function : GetShape()
186 //=======================================================================
188 TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
191 TCollection_AsciiString IOR = geom->GetStringFromIOR(aShape);
192 Standard_Integer anIndex = Find(IOR, S);
194 if (anIndex !=0 ) return S ;
196 /******* in case of a MAIN GEOM::SHAPE ********/
197 if (aShape->IsMainShape()) {
198 S = Load(geom, aShape);
203 /******* in case of SUB GEOM::SHAPE ***********/
204 // Load and Explore the Main Shape
205 TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape());
206 GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
208 TopTools_IndexedMapOfShape anIndices;
209 TopExp::MapShapes(aMainShape, anIndices);
211 /* Case of only one subshape */
212 if (list->length() == 1)
214 S = anIndices.FindKey(list[0]);
218 TopoDS_Compound aCompound;
219 B.MakeCompound(aCompound);
220 for(int i=0; i<list->length(); i++) {
221 TopoDS_Shape aSubShape = anIndices.FindKey(list[i]);
222 B.Add(aCompound, aSubShape);