1 // Copyright (C) 2007-2011 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 void GEOM_IInsertOperations_i::ImportTranslators
163 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
165 // allocate the CORBA arrays
166 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
167 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
169 // Get sequences of available formats
170 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
171 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
172 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
173 const int formSize = aFormats->Length();
174 if (formSize == aPatterns->Length()) {
175 aFormatsArray->length(formSize);
176 aPatternsArray->length(formSize);
178 // fill the local CORBA arrays with values from sequences
180 for (; i <= formSize; i++) {
181 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
182 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
187 // initialize out-parameters with local arrays
188 theFormats = aFormatsArray._retn();
189 thePatterns = aPatternsArray._retn();
192 //=============================================================================
196 //=============================================================================
197 void GEOM_IInsertOperations_i::ExportTranslators
198 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
200 // allocate the CORBA arrays
201 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
202 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
204 // Get sequences of available formats
205 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
206 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
207 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
208 const int formSize = aFormats->Length();
209 if (formSize == aPatterns->Length()) {
210 aFormatsArray->length(formSize);
211 aPatternsArray->length(formSize);
213 // fill the local CORBA arrays with values from sequences
215 for (; i <= formSize; i++) {
216 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
217 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
222 // initialize out-parameters with local arrays
223 theFormats = aFormatsArray._retn();
224 thePatterns = aPatternsArray._retn();
227 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
229 GetOperations()->SetNotDone();
230 return GetOperations()->LoadTexture( theTextureFile );
233 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
234 const SALOMEDS::TMPFile& theTexture)
236 GetOperations()->SetNotDone();
238 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
239 Handle(TColStd_HArray1OfByte) aTexture;
241 Handle(TDataStd_HArray1OfByte) aTexture;
244 if ( theTexture.length() > 0 ) {
245 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
246 aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
248 aTexture = new TDataStd_HArray1OfByte (1, theTexture.length());
251 for ( int i = 0; i < theTexture.length(); i++ )
252 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
254 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
257 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
258 CORBA::Long& theWidth,
259 CORBA::Long& theHeight)
262 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
263 Handle(TColStd_HArray1OfByte) aTextureImpl =
265 Handle(TDataStd_HArray1OfByte) aTextureImpl =
267 GetOperations()->GetTexture(theID, aWidth, aHeight);
270 SALOMEDS::TMPFile_var aTexture;
271 if ( !aTextureImpl.IsNull() ) {
272 aTexture = new SALOMEDS::TMPFile;
273 aTexture->length( aTextureImpl->Length() );
274 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
275 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
277 return aTexture._retn();
280 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
282 std::list<int> localIDs = GetOperations()->GetAllTextures();
283 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
284 anIDs->length(localIDs.size());
285 std::list<int>::const_iterator anIt;
287 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
289 return anIDs._retn();