1 // Copyright (C) 2007-2013 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
24 #pragma warning( disable:4786 )
27 #include <Standard_Stream.hxx>
29 #include "GEOM_IInsertOperations_i.hh"
31 #include "utilities.h"
33 #include "Utils_ExceptHandlers.hxx"
35 #include "GEOM_Engine.hxx"
36 #include "GEOM_Object.hxx"
38 #include <Basics_OCCTVersion.hxx>
40 #include <TColStd_HSequenceOfAsciiString.hxx>
42 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
43 #include <TColStd_HArray1OfByte.hxx>
45 #include <TDataStd_HArray1OfByte.hxx>
48 //=============================================================================
52 //=============================================================================
53 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
54 GEOM::GEOM_Gen_ptr theEngine,
55 ::GEOMImpl_IInsertOperations* theImpl)
56 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
58 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
61 //=============================================================================
65 //=============================================================================
66 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
68 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
72 //=============================================================================
76 //=============================================================================
77 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
79 GEOM::GEOM_Object_var aGEOMObject;
82 GetOperations()->SetNotDone();
84 //Get the reference shape
85 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
86 if (anOriginal.IsNull()) return aGEOMObject._retn();
89 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
91 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
93 return GetObject(anObject);
96 //=============================================================================
100 //=============================================================================
101 void GEOM_IInsertOperations_i::Export
102 (GEOM::GEOM_Object_ptr theOriginal,
103 const char* theFileName,
104 const char* theFormatName)
106 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
108 //Set a not done flag
109 GetOperations()->SetNotDone();
111 //Get the reference shape
112 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
113 if (anOriginal.IsNull()) return;
115 //Export the shape to the file
116 char* aFileName = strdup(theFileName);
117 char* aFormatName = strdup(theFormatName);
118 GetOperations()->Export(anOriginal, aFileName, aFormatName);
123 //=============================================================================
127 //=============================================================================
128 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::ImportFile
129 (const char* theFileName,
130 const char* theFormatName)
132 GEOM::GEOM_Object_var aGEOMObject;
134 //Set a not done flag
135 GetOperations()->SetNotDone();
137 //Import the shape from the file
138 char* aFileName = strdup(theFileName);
139 char* aFormatName = strdup(theFormatName);
140 Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
142 if( strcmp(aFormatName,"IGES_UNIT")==0 && !anObject.IsNull() ) {
145 return GetObject(anObject);
151 if (!GetOperations()->IsDone() || anObject.IsNull()) {
152 return aGEOMObject._retn();
155 return GetObject(anObject);
158 //=============================================================================
162 //=============================================================================
163 char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName,
164 const char* theFormatName,
165 const char* theParameterName)
167 //Set a not done flag
168 GetOperations()->SetNotDone();
170 char* aFileName = strdup(theFileName);
171 char* aFormatName = strdup(theFormatName);
172 char* aParameterName = strdup(theParameterName);
174 TCollection_AsciiString aUnits = GetOperations()->ReadValue
175 (aFileName, aFormatName, aParameterName);
179 free(aParameterName);
181 return CORBA::string_dup(aUnits.ToCString());
184 //=============================================================================
188 //=============================================================================
189 void GEOM_IInsertOperations_i::ImportTranslators
190 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
192 // allocate the CORBA arrays
193 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
194 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
196 // Get sequences of available formats
197 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
198 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
199 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
200 const int formSize = aFormats->Length();
201 if (formSize == aPatterns->Length()) {
202 aFormatsArray->length(formSize);
203 aPatternsArray->length(formSize);
205 // fill the local CORBA arrays with values from sequences
207 for (; i <= formSize; i++) {
208 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
209 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
214 // initialize out-parameters with local arrays
215 theFormats = aFormatsArray._retn();
216 thePatterns = aPatternsArray._retn();
219 //=============================================================================
223 //=============================================================================
224 void GEOM_IInsertOperations_i::ExportTranslators
225 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
227 // allocate the CORBA arrays
228 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
229 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
231 // Get sequences of available formats
232 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
233 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
234 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
235 const int formSize = aFormats->Length();
236 if (formSize == aPatterns->Length()) {
237 aFormatsArray->length(formSize);
238 aPatternsArray->length(formSize);
240 // fill the local CORBA arrays with values from sequences
242 for (; i <= formSize; i++) {
243 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
244 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
249 // initialize out-parameters with local arrays
250 theFormats = aFormatsArray._retn();
251 thePatterns = aPatternsArray._retn();
254 //=============================================================================
258 //=============================================================================
259 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::RestoreShape (const SALOMEDS::TMPFile& theStream)
261 GEOM::GEOM_Object_var aGEOMObject;
263 //Set a not done flag
264 GetOperations()->SetNotDone();
266 if (theStream.length() < 1)
267 return aGEOMObject._retn();
269 char* buf = (char*)theStream.NP_data();
270 std::istringstream aStream (buf);
272 Handle(GEOM_Object) anObject = GetOperations()->RestoreShape(aStream);
273 if (!GetOperations()->IsDone() || anObject.IsNull())
274 return aGEOMObject._retn();
276 return GetObject(anObject);
279 //=============================================================================
283 //=============================================================================
284 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
286 GetOperations()->SetNotDone();
287 return GetOperations()->LoadTexture( theTextureFile );
290 //=============================================================================
294 //=============================================================================
295 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
296 const SALOMEDS::TMPFile& theTexture)
298 GetOperations()->SetNotDone();
300 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
301 Handle(TColStd_HArray1OfByte) aTexture;
303 Handle(TDataStd_HArray1OfByte) aTexture;
306 if ( theTexture.length() > 0 ) {
307 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
308 aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
310 aTexture = new TDataStd_HArray1OfByte (1, theTexture.length());
313 for ( int i = 0; i < theTexture.length(); i++ )
314 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
316 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
319 //=============================================================================
323 //=============================================================================
324 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
325 CORBA::Long& theWidth,
326 CORBA::Long& theHeight)
329 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
330 Handle(TColStd_HArray1OfByte) aTextureImpl =
332 Handle(TDataStd_HArray1OfByte) aTextureImpl =
334 GetOperations()->GetTexture(theID, aWidth, aHeight);
337 SALOMEDS::TMPFile_var aTexture;
338 if ( !aTextureImpl.IsNull() ) {
339 aTexture = new SALOMEDS::TMPFile;
340 aTexture->length( aTextureImpl->Length() );
341 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
342 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
344 return aTexture._retn();
347 //=============================================================================
351 //=============================================================================
352 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
354 std::list<int> localIDs = GetOperations()->GetAllTextures();
355 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
356 anIDs->length(localIDs.size());
357 std::list<int>::const_iterator anIt;
359 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
361 return anIDs._retn();