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
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 void GEOM_IInsertOperations_i::ImportTranslators
164 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
166 // allocate the CORBA arrays
167 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
168 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
170 // Get sequences of available formats
171 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
172 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
173 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
174 const int formSize = aFormats->Length();
175 if (formSize == aPatterns->Length()) {
176 aFormatsArray->length(formSize);
177 aPatternsArray->length(formSize);
179 // fill the local CORBA arrays with values from sequences
181 for (; i <= formSize; i++) {
182 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
183 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
188 // initialize out-parameters with local arrays
189 theFormats = aFormatsArray._retn();
190 thePatterns = aPatternsArray._retn();
193 //=============================================================================
197 //=============================================================================
198 void GEOM_IInsertOperations_i::ExportTranslators
199 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
201 // allocate the CORBA arrays
202 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
203 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
205 // Get sequences of available formats
206 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
207 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
208 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
209 const int formSize = aFormats->Length();
210 if (formSize == aPatterns->Length()) {
211 aFormatsArray->length(formSize);
212 aPatternsArray->length(formSize);
214 // fill the local CORBA arrays with values from sequences
216 for (; i <= formSize; i++) {
217 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
218 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
223 // initialize out-parameters with local arrays
224 theFormats = aFormatsArray._retn();
225 thePatterns = aPatternsArray._retn();
228 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
230 GetOperations()->SetNotDone();
231 return GetOperations()->LoadTexture( theTextureFile );
234 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
235 const SALOMEDS::TMPFile& theTexture)
237 GetOperations()->SetNotDone();
239 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
240 Handle(TColStd_HArray1OfByte) aTexture;
242 Handle(TDataStd_HArray1OfByte) aTexture;
245 if ( theTexture.length() > 0 ) {
246 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
247 aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
249 aTexture = new TDataStd_HArray1OfByte (1, theTexture.length());
252 for ( int i = 0; i < theTexture.length(); i++ )
253 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
255 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
258 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
259 CORBA::Long& theWidth,
260 CORBA::Long& theHeight)
263 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
264 Handle(TColStd_HArray1OfByte) aTextureImpl =
266 Handle(TDataStd_HArray1OfByte) aTextureImpl =
268 GetOperations()->GetTexture(theID, aWidth, aHeight);
271 SALOMEDS::TMPFile_var aTexture;
272 if ( !aTextureImpl.IsNull() ) {
273 aTexture = new SALOMEDS::TMPFile;
274 aTexture->length( aTextureImpl->Length() );
275 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
276 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
278 return aTexture._retn();
281 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
283 std::list<int> localIDs = GetOperations()->GetAllTextures();
284 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
285 anIDs->length(localIDs.size());
286 std::list<int>::const_iterator anIt;
288 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
290 return anIDs._retn();