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_BaseObject.hxx"
38 #include <Basics_OCCTVersion.hxx>
40 #include <TColStd_HSequenceOfAsciiString.hxx>
42 #include <TColStd_HArray1OfByte.hxx>
44 //=============================================================================
48 //=============================================================================
49 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
50 GEOM::GEOM_Gen_ptr theEngine,
51 ::GEOMImpl_IInsertOperations* theImpl)
52 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
54 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
57 //=============================================================================
61 //=============================================================================
62 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
64 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
68 //=============================================================================
72 //=============================================================================
73 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
75 GEOM::GEOM_Object_var aGEOMObject;
78 GetOperations()->SetNotDone();
80 //Get the reference shape
81 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
82 if (anOriginal.IsNull()) return aGEOMObject._retn();
85 Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
87 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
89 return GetObject(anObject);
92 //=============================================================================
96 //=============================================================================
97 void GEOM_IInsertOperations_i::Export
98 (GEOM::GEOM_Object_ptr theOriginal,
99 const char* theFileName,
100 const char* theFormatName)
102 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
104 //Set a not done flag
105 GetOperations()->SetNotDone();
107 //Get the reference shape
108 Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
109 if (anOriginal.IsNull()) return;
111 //Export the shape to the file
112 GetOperations()->Export(anOriginal, theFileName, theFormatName);
115 //=============================================================================
119 //=============================================================================
120 GEOM::ListOfGBO* GEOM_IInsertOperations_i::ImportFile
121 (const char* theFileName,
122 const char* theFormatName)
124 GEOM::ListOfGBO_var aSeq = new GEOM::ListOfGBO;
126 //Set a not done flag
127 GetOperations()->SetNotDone();
129 //Import the shape from the file
130 Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->Import(theFileName, theFormatName);
132 if (!GetOperations()->IsDone() || aHSeq.IsNull()) {
136 // Copy created objects.
137 Standard_Integer aLength = aHSeq->Length();
139 aSeq->length(aLength);
140 for (Standard_Integer i = 1; i <= aLength; i++)
141 aSeq[i-1] = GetBaseObject(Handle(GEOM_BaseObject)::DownCast(aHSeq->Value(i)));
146 //=============================================================================
150 //=============================================================================
151 char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName,
152 const char* theFormatName,
153 const char* theParameterName)
155 //Set a not done flag
156 GetOperations()->SetNotDone();
158 TCollection_AsciiString aUnits = GetOperations()->ReadValue
159 (theFileName, theFormatName, theParameterName);
161 return CORBA::string_dup(aUnits.ToCString());
164 //=============================================================================
168 //=============================================================================
169 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::RestoreShape (const SALOMEDS::TMPFile& theStream)
171 GEOM::GEOM_Object_var aGEOMObject;
173 //Set a not done flag
174 GetOperations()->SetNotDone();
176 if (theStream.length() < 1)
177 return aGEOMObject._retn();
179 char* buf = (char*)theStream.NP_data();
180 std::istringstream aStream (buf);
182 Handle(GEOM_Object) anObject = GetOperations()->RestoreShape(aStream);
183 if (!GetOperations()->IsDone() || anObject.IsNull())
184 return aGEOMObject._retn();
186 return GetObject(anObject);
189 //=============================================================================
193 //=============================================================================
194 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
196 GetOperations()->SetNotDone();
197 return GetOperations()->LoadTexture( theTextureFile );
200 //=============================================================================
204 //=============================================================================
205 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
206 const SALOMEDS::TMPFile& theTexture)
208 GetOperations()->SetNotDone();
210 Handle(TColStd_HArray1OfByte) aTexture;
212 if ( theTexture.length() > 0 ) {
213 aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
215 for ( int i = 0; i < theTexture.length(); i++ )
216 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
218 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
221 //=============================================================================
225 //=============================================================================
226 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
227 CORBA::Long& theWidth,
228 CORBA::Long& theHeight)
231 Handle(TColStd_HArray1OfByte) aTextureImpl =
232 GetOperations()->GetTexture(theID, aWidth, aHeight);
235 SALOMEDS::TMPFile_var aTexture;
236 if ( !aTextureImpl.IsNull() ) {
237 aTexture = new SALOMEDS::TMPFile;
238 aTexture->length( aTextureImpl->Length() );
239 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
240 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
242 return aTexture._retn();
245 //=============================================================================
249 //=============================================================================
250 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
252 std::list<int> localIDs = GetOperations()->GetAllTextures();
253 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
254 anIDs->length(localIDs.size());
255 std::list<int>::const_iterator anIt;
257 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
259 return anIDs._retn();