1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 #pragma warning( disable:4786 )
26 #include <Standard_Stream.hxx>
28 #include "GEOM_IInsertOperations_i.hh"
30 #include "utilities.h"
32 #include "Utils_ExceptHandlers.hxx"
34 #include "GEOM_Engine.hxx"
35 #include "GEOM_Object.hxx"
37 #include <Basics_OCCTVersion.hxx>
39 #include <TColStd_HSequenceOfAsciiString.hxx>
41 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
42 #include <TColStd_HArray1OfByte.hxx>
44 #include <TDataStd_HArray1OfByte.hxx>
47 //=============================================================================
51 //=============================================================================
52 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
53 GEOM::GEOM_Gen_ptr theEngine,
54 ::GEOMImpl_IInsertOperations* theImpl)
55 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
57 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
60 //=============================================================================
64 //=============================================================================
65 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
67 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
71 //=============================================================================
75 //=============================================================================
76 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
78 GEOM::GEOM_Object_var aGEOMObject;
81 GetOperations()->SetNotDone();
83 //Get the reference shape
84 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
85 if (anOriginal.IsNull()) return aGEOMObject._retn();
88 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
90 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
92 return GetObject(anObject);
95 //=============================================================================
99 //=============================================================================
100 void GEOM_IInsertOperations_i::Export
101 (GEOM::GEOM_Object_ptr theOriginal,
102 const char* theFileName,
103 const char* theFormatName)
105 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
107 //Set a not done flag
108 GetOperations()->SetNotDone();
110 //Get the reference shape
111 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
112 if (anOriginal.IsNull()) return;
114 //Export the shape to the file
115 char* aFileName = strdup(theFileName);
116 char* aFormatName = strdup(theFormatName);
117 GetOperations()->Export(anOriginal, aFileName, aFormatName);
122 //=============================================================================
126 //=============================================================================
127 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::ImportFile
128 (const char* theFileName,
129 const char* theFormatName)
131 GEOM::GEOM_Object_var aGEOMObject;
133 //Set a not done flag
134 GetOperations()->SetNotDone();
136 //Import the shape from the file
137 char* aFileName = strdup(theFileName);
138 char* aFormatName = strdup(theFormatName);
139 Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
141 if( strcmp(aFormatName,"IGES_UNIT")==0 && !anObject.IsNull() ) {
144 return GetObject(anObject);
150 if (!GetOperations()->IsDone() || anObject.IsNull()) {
151 return aGEOMObject._retn();
154 return GetObject(anObject);
157 //=============================================================================
161 //=============================================================================
162 char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName,
163 const char* theFormatName,
164 const char* theParameterName)
166 //Set a not done flag
167 GetOperations()->SetNotDone();
169 char* aFileName = strdup(theFileName);
170 char* aFormatName = strdup(theFormatName);
171 char* aParameterName = strdup(theParameterName);
173 TCollection_AsciiString aUnits = GetOperations()->ReadValue
174 (aFileName, aFormatName, aParameterName);
178 free(aParameterName);
180 return CORBA::string_dup(aUnits.ToCString());
183 //=============================================================================
187 //=============================================================================
188 void GEOM_IInsertOperations_i::ImportTranslators
189 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
191 // allocate the CORBA arrays
192 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
193 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
195 // Get sequences of available formats
196 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
197 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
198 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
199 const int formSize = aFormats->Length();
200 if (formSize == aPatterns->Length()) {
201 aFormatsArray->length(formSize);
202 aPatternsArray->length(formSize);
204 // fill the local CORBA arrays with values from sequences
206 for (; i <= formSize; i++) {
207 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
208 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
213 // initialize out-parameters with local arrays
214 theFormats = aFormatsArray._retn();
215 thePatterns = aPatternsArray._retn();
218 //=============================================================================
222 //=============================================================================
223 void GEOM_IInsertOperations_i::ExportTranslators
224 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
226 // allocate the CORBA arrays
227 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
228 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
230 // Get sequences of available formats
231 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
232 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
233 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
234 const int formSize = aFormats->Length();
235 if (formSize == aPatterns->Length()) {
236 aFormatsArray->length(formSize);
237 aPatternsArray->length(formSize);
239 // fill the local CORBA arrays with values from sequences
241 for (; i <= formSize; i++) {
242 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
243 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
248 // initialize out-parameters with local arrays
249 theFormats = aFormatsArray._retn();
250 thePatterns = aPatternsArray._retn();
253 //=============================================================================
257 //=============================================================================
258 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::RestoreShape (const SALOMEDS::TMPFile& theStream)
260 GEOM::GEOM_Object_var aGEOMObject;
262 //Set a not done flag
263 GetOperations()->SetNotDone();
265 if (theStream.length() < 1)
266 return aGEOMObject._retn();
268 char* buf = (char*)theStream.NP_data();
269 std::istringstream aStream (buf);
271 Handle(GEOM_Object) anObject = GetOperations()->RestoreShape(aStream);
272 if (!GetOperations()->IsDone() || anObject.IsNull())
273 return aGEOMObject._retn();
275 return GetObject(anObject);
278 //=============================================================================
282 //=============================================================================
283 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
285 GetOperations()->SetNotDone();
286 return GetOperations()->LoadTexture( theTextureFile );
289 //=============================================================================
293 //=============================================================================
294 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
295 const SALOMEDS::TMPFile& theTexture)
297 GetOperations()->SetNotDone();
299 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
300 Handle(TColStd_HArray1OfByte) aTexture;
302 Handle(TDataStd_HArray1OfByte) aTexture;
305 if ( theTexture.length() > 0 ) {
306 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
307 aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
309 aTexture = new TDataStd_HArray1OfByte (1, theTexture.length());
312 for ( int i = 0; i < theTexture.length(); i++ )
313 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
315 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
318 //=============================================================================
322 //=============================================================================
323 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
324 CORBA::Long& theWidth,
325 CORBA::Long& theHeight)
328 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
329 Handle(TColStd_HArray1OfByte) aTextureImpl =
331 Handle(TDataStd_HArray1OfByte) aTextureImpl =
333 GetOperations()->GetTexture(theID, aWidth, aHeight);
336 SALOMEDS::TMPFile_var aTexture;
337 if ( !aTextureImpl.IsNull() ) {
338 aTexture = new SALOMEDS::TMPFile;
339 aTexture->length( aTextureImpl->Length() );
340 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
341 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
343 return aTexture._retn();
346 //=============================================================================
350 //=============================================================================
351 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
353 std::list<int> localIDs = GetOperations()->GetAllTextures();
354 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
355 anIDs->length(localIDs.size());
356 std::list<int>::const_iterator anIt;
358 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
360 return anIDs._retn();