1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 GetOperations()->Export(anOriginal, theFileName, theFormatName);
119 //=============================================================================
123 //=============================================================================
124 GEOM::ListOfGO* GEOM_IInsertOperations_i::ImportFile
125 (const char* theFileName,
126 const char* theFormatName)
128 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
130 //Set a not done flag
131 GetOperations()->SetNotDone();
133 //Import the shape from the file
134 Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->Import(theFileName, theFormatName);
136 if (!GetOperations()->IsDone() || aHSeq.IsNull()) {
140 // Copy created objects.
141 Standard_Integer aLength = aHSeq->Length();
143 aSeq->length(aLength);
144 for (Standard_Integer i = 1; i <= aLength; i++)
145 aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
150 //=============================================================================
154 //=============================================================================
155 char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName,
156 const char* theFormatName,
157 const char* theParameterName)
159 //Set a not done flag
160 GetOperations()->SetNotDone();
162 TCollection_AsciiString aUnits = GetOperations()->ReadValue
163 (theFileName, theFormatName, theParameterName);
165 return CORBA::string_dup(aUnits.ToCString());
168 //=============================================================================
172 //=============================================================================
173 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::RestoreShape (const SALOMEDS::TMPFile& theStream)
175 GEOM::GEOM_Object_var aGEOMObject;
177 //Set a not done flag
178 GetOperations()->SetNotDone();
180 if (theStream.length() < 1)
181 return aGEOMObject._retn();
183 char* buf = (char*)theStream.NP_data();
184 std::istringstream aStream (buf);
186 Handle(GEOM_Object) anObject = GetOperations()->RestoreShape(aStream);
187 if (!GetOperations()->IsDone() || anObject.IsNull())
188 return aGEOMObject._retn();
190 return GetObject(anObject);
193 //=============================================================================
197 //=============================================================================
198 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
200 GetOperations()->SetNotDone();
201 return GetOperations()->LoadTexture( theTextureFile );
204 //=============================================================================
208 //=============================================================================
209 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
210 const SALOMEDS::TMPFile& theTexture)
212 GetOperations()->SetNotDone();
214 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
215 Handle(TColStd_HArray1OfByte) aTexture;
217 Handle(TDataStd_HArray1OfByte) aTexture;
220 if ( theTexture.length() > 0 ) {
221 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
222 aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
224 aTexture = new TDataStd_HArray1OfByte (1, theTexture.length());
227 for ( int i = 0; i < theTexture.length(); i++ )
228 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
230 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
233 //=============================================================================
237 //=============================================================================
238 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
239 CORBA::Long& theWidth,
240 CORBA::Long& theHeight)
243 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
244 Handle(TColStd_HArray1OfByte) aTextureImpl =
246 Handle(TDataStd_HArray1OfByte) aTextureImpl =
248 GetOperations()->GetTexture(theID, aWidth, aHeight);
251 SALOMEDS::TMPFile_var aTexture;
252 if ( !aTextureImpl.IsNull() ) {
253 aTexture = new SALOMEDS::TMPFile;
254 aTexture->length( aTextureImpl->Length() );
255 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
256 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
258 return aTexture._retn();
261 //=============================================================================
265 //=============================================================================
266 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
268 std::list<int> localIDs = GetOperations()->GetAllTextures();
269 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
270 anIDs->length(localIDs.size());
271 std::list<int>::const_iterator anIt;
273 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
275 return anIDs._retn();