1 // Copyright (C) 2007-2016 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"
37 #include "GEOMImpl_Types.hxx"
39 #include <Basics_OCCTVersion.hxx>
41 #include <TColStd_HSequenceOfAsciiString.hxx>
43 #include <TColStd_HArray1OfByte.hxx>
45 //=============================================================================
49 //=============================================================================
50 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
51 GEOM::GEOM_Gen_ptr theEngine,
52 ::GEOMImpl_IInsertOperations* theImpl)
53 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
55 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
58 //=============================================================================
62 //=============================================================================
63 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
65 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
69 //=============================================================================
73 //=============================================================================
74 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
76 GEOM::GEOM_Object_var aGEOMObject;
79 GetOperations()->SetNotDone();
81 //Get the reference shape
82 HANDLE_NAMESPACE(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
83 if (anOriginal.IsNull()) return aGEOMObject._retn();
86 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
88 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
90 return GetObject(anObject);
93 //=============================================================================
97 //=============================================================================
98 void GEOM_IInsertOperations_i::Export
99 (GEOM::GEOM_Object_ptr theOriginal,
100 const char* theFileName,
101 const char* theFormatName)
103 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
105 //Set a not done flag
106 GetOperations()->SetNotDone();
108 //Get the reference shape
109 HANDLE_NAMESPACE(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
110 if (anOriginal.IsNull()) return;
112 //Export the shape to the file
113 GetOperations()->Export(anOriginal, theFileName, theFormatName);
116 //=============================================================================
120 //=============================================================================
121 GEOM::ListOfGBO* GEOM_IInsertOperations_i::ImportFile
122 (const char* theFileName,
123 const char* theFormatName)
125 GEOM::ListOfGBO_var aSeq = new GEOM::ListOfGBO;
127 //Set a not done flag
128 GetOperations()->SetNotDone();
130 //Import the shape from the file
131 Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->Import(theFileName, theFormatName);
133 if (!GetOperations()->IsDone() || aHSeq.IsNull()) {
137 // Copy created objects.
138 Standard_Integer aLength = aHSeq->Length();
140 aSeq->length(aLength);
141 for (Standard_Integer i = 1; i <= aLength; i++)
142 aSeq[i-1] = GetBaseObject(HANDLE_NAMESPACE(GEOM_BaseObject)::DownCast(aHSeq->Value(i)));
147 //=============================================================================
151 //=============================================================================
152 char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName,
153 const char* theFormatName,
154 const char* theParameterName)
156 //Set a not done flag
157 GetOperations()->SetNotDone();
159 TCollection_AsciiString aUnits = GetOperations()->ReadValue
160 (theFileName, theFormatName, theParameterName);
162 return CORBA::string_dup(aUnits.ToCString());
165 //=============================================================================
169 //=============================================================================
170 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::RestoreShape (const SALOMEDS::TMPFile& theStream)
172 GEOM::GEOM_Object_var aGEOMObject;
174 //Set a not done flag
175 GetOperations()->SetNotDone();
177 if (theStream.length() < 1)
178 return aGEOMObject._retn();
180 char* buf = (char*)theStream.NP_data();
181 std::istringstream aStream (buf);
183 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->RestoreShape(aStream);
184 if (!GetOperations()->IsDone() || anObject.IsNull())
185 return aGEOMObject._retn();
187 return GetObject(anObject);
190 //=============================================================================
194 //=============================================================================
195 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
197 GetOperations()->SetNotDone();
198 return GetOperations()->LoadTexture( theTextureFile );
201 //=============================================================================
205 //=============================================================================
206 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
207 const SALOMEDS::TMPFile& theTexture)
209 GetOperations()->SetNotDone();
211 Handle(TColStd_HArray1OfByte) aTexture;
213 if ( theTexture.length() > 0 ) {
214 aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
216 for ( int i = 0; i < theTexture.length(); i++ )
217 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
219 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
222 //=============================================================================
226 //=============================================================================
227 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
228 CORBA::Long& theWidth,
229 CORBA::Long& theHeight)
232 Handle(TColStd_HArray1OfByte) aTextureImpl =
233 GetOperations()->GetTexture(theID, aWidth, aHeight);
236 SALOMEDS::TMPFile_var aTexture;
237 if ( !aTextureImpl.IsNull() ) {
238 aTexture = new SALOMEDS::TMPFile;
239 aTexture->length( aTextureImpl->Length() );
240 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
241 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
243 return aTexture._retn();
246 //=============================================================================
250 //=============================================================================
251 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
253 std::list<int> localIDs = GetOperations()->GetAllTextures();
254 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
255 anIDs->length(localIDs.size());
256 std::list<int>::const_iterator anIt;
258 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
260 return anIDs._retn();
263 //=============================================================================
267 //=============================================================================
268 CORBA::Boolean GEOM_IInsertOperations_i::TransferData
269 (GEOM::GEOM_Object_ptr theObjectFrom,
270 GEOM::GEOM_Object_ptr theObjectTo,
271 GEOM::find_shape_method theFindMethod,
272 GEOM::GEOM_IInsertOperations::ListOfTransferDatum_out theResult)
274 //Set a not done flag
275 GetOperations()->SetNotDone();
277 if (CORBA::is_nil(theObjectFrom) || CORBA::is_nil(theObjectTo))
282 //Get the reference shape
283 HANDLE_NAMESPACE(GEOM_Object) aShapeFrom = GetObjectImpl(theObjectFrom);
284 HANDLE_NAMESPACE(GEOM_Object) aShapeTo = GetObjectImpl(theObjectTo);
286 if (aShapeFrom.IsNull() || aShapeTo.IsNull())
292 std::list<GEOMImpl_IInsertOperations::TransferDatum> aData;
293 int aFindMethod = -1;
295 switch (theFindMethod) {
296 case GEOM::FSM_GetInPlace:
297 aFindMethod = TD_GET_IN_PLACE;
299 case GEOM::FSM_GetInPlaceByHistory:
300 aFindMethod = TD_GET_IN_PLACE_BY_HISTORY;
302 case GEOM::FSM_GetInPlace_Old:
303 aFindMethod = TD_GET_IN_PLACE_OLD;
310 if (aFindMethod > 0) {
311 isOk = GetOperations()->TransferData
312 (aShapeFrom, aShapeTo, aFindMethod, aData);
317 const int aNbDatum = aData.size();
318 GEOM::GEOM_IInsertOperations::ListOfTransferDatum_var aResult =
319 new GEOM::GEOM_IInsertOperations::ListOfTransferDatum;
321 aResult->length(aNbDatum);
323 // fill the local CORBA array with values from lists
324 std::list<GEOMImpl_IInsertOperations::TransferDatum>::const_iterator
325 anIt = aData.begin();
328 for (; anIt != aData.end(); i++, anIt++) {
329 GEOM::GEOM_IInsertOperations::TransferDatum_var aDatum =
330 new GEOM::GEOM_IInsertOperations::TransferDatum;
332 aDatum->myName = CORBA::string_dup(anIt->myName.ToCString());
333 aDatum->myNumber = anIt->myNumber;
334 aDatum->myMaxNumber = anIt->myMaxNumber;
338 theResult = aResult._retn();