1 // Copyright (C) 2007-2010 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 <TColStd_HSequenceOfAsciiString.hxx>
39 #include <TDataStd_HArray1OfByte.hxx>
41 //=============================================================================
45 //=============================================================================
46 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
47 GEOM::GEOM_Gen_ptr theEngine,
48 ::GEOMImpl_IInsertOperations* theImpl)
49 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
51 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
54 //=============================================================================
58 //=============================================================================
59 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
61 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
65 //=============================================================================
69 //=============================================================================
70 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
72 GEOM::GEOM_Object_var aGEOMObject;
75 GetOperations()->SetNotDone();
77 //Get the reference shape
78 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
79 if (anOriginal.IsNull()) return aGEOMObject._retn();
82 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
84 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
86 return GetObject(anObject);
89 //=============================================================================
93 //=============================================================================
94 void GEOM_IInsertOperations_i::Export
95 (GEOM::GEOM_Object_ptr theOriginal,
96 const char* theFileName,
97 const char* theFormatName)
99 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
101 //Set a not done flag
102 GetOperations()->SetNotDone();
104 //Get the reference shape
105 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
106 if (anOriginal.IsNull()) return;
108 //Export the shape to the file
109 char* aFileName = strdup(theFileName);
110 char* aFormatName = strdup(theFormatName);
111 GetOperations()->Export(anOriginal, aFileName, aFormatName);
116 //=============================================================================
120 //=============================================================================
121 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
122 (const char* theFileName,
123 const char* theFormatName)
125 GEOM::GEOM_Object_var aGEOMObject;
127 //Set a not done flag
128 GetOperations()->SetNotDone();
130 //Import the shape from the file
131 char* aFileName = strdup(theFileName);
132 char* aFormatName = strdup(theFormatName);
133 Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
135 if( strcmp(aFormatName,"IGES_UNIT")==0 && !anObject.IsNull() ) {
138 return GetObject(anObject);
144 if (!GetOperations()->IsDone() || anObject.IsNull()) {
145 return aGEOMObject._retn();
148 return GetObject(anObject);
151 //=============================================================================
155 //=============================================================================
156 void GEOM_IInsertOperations_i::ImportTranslators
157 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
159 // allocate the CORBA arrays
160 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
161 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
163 // Get sequences of available formats
164 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
165 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
166 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
167 const int formSize = aFormats->Length();
168 if (formSize == aPatterns->Length()) {
169 aFormatsArray->length(formSize);
170 aPatternsArray->length(formSize);
172 // fill the local CORBA arrays with values from sequences
174 for (; i <= formSize; i++) {
175 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
176 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
181 // initialize out-parameters with local arrays
182 theFormats = aFormatsArray._retn();
183 thePatterns = aPatternsArray._retn();
186 //=============================================================================
190 //=============================================================================
191 void GEOM_IInsertOperations_i::ExportTranslators
192 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
194 // allocate the CORBA arrays
195 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
196 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
198 // Get sequences of available formats
199 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
200 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
201 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
202 const int formSize = aFormats->Length();
203 if (formSize == aPatterns->Length()) {
204 aFormatsArray->length(formSize);
205 aPatternsArray->length(formSize);
207 // fill the local CORBA arrays with values from sequences
209 for (; i <= formSize; i++) {
210 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
211 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
216 // initialize out-parameters with local arrays
217 theFormats = aFormatsArray._retn();
218 thePatterns = aPatternsArray._retn();
221 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
223 GetOperations()->SetNotDone();
224 return GetOperations()->LoadTexture( theTextureFile );
227 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
228 const SALOMEDS::TMPFile& theTexture)
230 GetOperations()->SetNotDone();
231 Handle(TDataStd_HArray1OfByte) aTexture;
232 if ( theTexture.length() > 0 ) {
233 aTexture = new TDataStd_HArray1OfByte( 1, theTexture.length() );
234 for ( int i = 0; i < theTexture.length(); i++ )
235 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
237 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
240 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
241 CORBA::Long& theWidth,
242 CORBA::Long& theHeight)
245 Handle(TDataStd_HArray1OfByte) aTextureImpl = GetOperations()->GetTexture( theID, aWidth, aHeight );
248 SALOMEDS::TMPFile_var aTexture;
249 if ( !aTextureImpl.IsNull() ) {
250 aTexture = new SALOMEDS::TMPFile;
251 aTexture->length( aTextureImpl->Length() );
252 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
253 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
255 return aTexture._retn();
258 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
260 std::list<int> localIDs = GetOperations()->GetAllTextures();
261 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
262 anIDs->length(localIDs.size());
263 std::list<int>::const_iterator anIt;
265 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
267 return anIDs._retn();