1 // Copyright (C) 2007-2008 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 <TColStd_HSequenceOfAsciiString.hxx>
38 #include <TDataStd_HArray1OfByte.hxx>
40 //=============================================================================
44 //=============================================================================
45 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
46 GEOM::GEOM_Gen_ptr theEngine,
47 ::GEOMImpl_IInsertOperations* theImpl)
48 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
50 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
53 //=============================================================================
57 //=============================================================================
58 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
60 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
64 //=============================================================================
68 //=============================================================================
69 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
71 GEOM::GEOM_Object_var aGEOMObject;
74 GetOperations()->SetNotDone();
76 //Get the reference shape
77 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
78 if (anOriginal.IsNull()) return aGEOMObject._retn();
81 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
83 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
85 return GetObject(anObject);
88 //=============================================================================
92 //=============================================================================
93 void GEOM_IInsertOperations_i::Export
94 (GEOM::GEOM_Object_ptr theOriginal,
95 const char* theFileName,
96 const char* theFormatName)
98 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
100 //Set a not done flag
101 GetOperations()->SetNotDone();
103 //Get the reference shape
104 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
105 if (anOriginal.IsNull()) return;
107 //Export the shape to the file
108 char* aFileName = strdup(theFileName);
109 char* aFormatName = strdup(theFormatName);
110 GetOperations()->Export(anOriginal, aFileName, aFormatName);
115 //=============================================================================
119 //=============================================================================
120 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
121 (const char* theFileName,
122 const char* theFormatName)
124 GEOM::GEOM_Object_var aGEOMObject;
126 //Set a not done flag
127 GetOperations()->SetNotDone();
129 //Import the shape from the file
130 char* aFileName = strdup(theFileName);
131 char* aFormatName = strdup(theFormatName);
132 Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
134 if( strcmp(aFormatName,"IGES_UNIT")==0 && !anObject.IsNull() ) {
137 return GetObject(anObject);
143 if (!GetOperations()->IsDone() || anObject.IsNull()) {
144 return aGEOMObject._retn();
147 return GetObject(anObject);
150 //=============================================================================
154 //=============================================================================
155 void GEOM_IInsertOperations_i::ImportTranslators
156 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
158 // allocate the CORBA arrays
159 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
160 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
162 // Get sequences of available formats
163 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
164 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
165 if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
166 const int formSize = aFormats->Length();
167 if (formSize == aPatterns->Length()) {
168 aFormatsArray->length(formSize);
169 aPatternsArray->length(formSize);
171 // fill the local CORBA arrays with values from sequences
173 for (; i <= formSize; i++) {
174 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
175 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
180 // initialize out-parameters with local arrays
181 theFormats = aFormatsArray._retn();
182 thePatterns = aPatternsArray._retn();
185 //=============================================================================
189 //=============================================================================
190 void GEOM_IInsertOperations_i::ExportTranslators
191 (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
193 // allocate the CORBA arrays
194 GEOM::string_array_var aFormatsArray = new GEOM::string_array();
195 GEOM::string_array_var aPatternsArray = new GEOM::string_array();
197 // Get sequences of available formats
198 Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
199 Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
200 if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
201 const int formSize = aFormats->Length();
202 if (formSize == aPatterns->Length()) {
203 aFormatsArray->length(formSize);
204 aPatternsArray->length(formSize);
206 // fill the local CORBA arrays with values from sequences
208 for (; i <= formSize; i++) {
209 aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
210 aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
215 // initialize out-parameters with local arrays
216 theFormats = aFormatsArray._retn();
217 thePatterns = aPatternsArray._retn();
220 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
222 GetOperations()->SetNotDone();
223 return GetOperations()->LoadTexture( theTextureFile );
226 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
227 const SALOMEDS::TMPFile& theTexture)
229 GetOperations()->SetNotDone();
230 Handle(TDataStd_HArray1OfByte) aTexture;
231 if ( theTexture.length() > 0 ) {
232 aTexture = new TDataStd_HArray1OfByte( 1, theTexture.length() );
233 for ( int i = 0; i < theTexture.length(); i++ )
234 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
236 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
239 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
240 CORBA::Long& theWidth,
241 CORBA::Long& theHeight)
244 Handle(TDataStd_HArray1OfByte) aTextureImpl = GetOperations()->GetTexture( theID, aWidth, aHeight );
247 SALOMEDS::TMPFile_var aTexture;
248 if ( !aTextureImpl.IsNull() ) {
249 aTexture = new SALOMEDS::TMPFile;
250 aTexture->length( aTextureImpl->Length() );
251 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
252 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
254 return aTexture._retn();
257 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
259 std::list<int> localIDs = GetOperations()->GetAllTextures();
260 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
261 anIDs->length(localIDs.size());
262 std::list<int>::const_iterator anIt;
264 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
266 return anIDs._retn();