1 // Copyright (C) 2007-2020 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 <TColStd_HSequenceOfAsciiString.hxx>
40 #include <TColStd_HArray1OfByte.hxx>
42 //=============================================================================
46 //=============================================================================
47 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
48 GEOM::GEOM_Gen_ptr theEngine,
49 ::GEOMImpl_IInsertOperations* theImpl)
50 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
52 MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
55 //=============================================================================
59 //=============================================================================
60 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
62 MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
66 //=============================================================================
70 //=============================================================================
71 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
73 GEOM::GEOM_Object_var aGEOMObject;
76 GetOperations()->SetNotDone();
78 //Get the reference shape
79 Handle(::GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
80 if (anOriginal.IsNull()) return aGEOMObject._retn();
83 Handle(::GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
85 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
87 return GetObject(anObject);
90 //=============================================================================
94 //=============================================================================
95 void GEOM_IInsertOperations_i::Export
96 (GEOM::GEOM_Object_ptr theOriginal,
97 const char* theFileName,
98 const char* theFormatName)
100 GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
102 //Set a not done flag
103 GetOperations()->SetNotDone();
105 //Get the reference shape
106 Handle(::GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
107 if (anOriginal.IsNull()) return;
109 //Export the shape to the file
110 GetOperations()->Export(anOriginal, theFileName, theFormatName);
113 //=============================================================================
117 //=============================================================================
118 GEOM::ListOfGBO* GEOM_IInsertOperations_i::ImportFile
119 (const char* theFileName,
120 const char* theFormatName)
122 GEOM::ListOfGBO_var aSeq = new GEOM::ListOfGBO;
124 //Set a not done flag
125 GetOperations()->SetNotDone();
127 //Import the shape from the file
128 Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->Import(theFileName, theFormatName);
130 if (!GetOperations()->IsDone() || aHSeq.IsNull()) {
134 // Copy created objects.
135 Standard_Integer aLength = aHSeq->Length();
137 aSeq->length(aLength);
138 for (Standard_Integer i = 1; i <= aLength; i++)
139 aSeq[i-1] = GetBaseObject(Handle(::GEOM_BaseObject)::DownCast(aHSeq->Value(i)));
144 //=============================================================================
148 //=============================================================================
149 char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName,
150 const char* theFormatName,
151 const char* theParameterName)
153 //Set a not done flag
154 GetOperations()->SetNotDone();
156 TCollection_AsciiString aUnits = GetOperations()->ReadValue
157 (theFileName, theFormatName, theParameterName);
159 return CORBA::string_dup(aUnits.ToCString());
162 //=============================================================================
166 //=============================================================================
167 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::RestoreShape (const SALOMEDS::TMPFile& theStream)
169 GEOM::GEOM_Object_var aGEOMObject;
171 //Set a not done flag
172 GetOperations()->SetNotDone();
174 if (theStream.length() < 1)
175 return aGEOMObject._retn();
177 char* buf = (char*)theStream.NP_data();
178 std::istringstream aStream (buf);
180 Handle(::GEOM_Object) anObject = GetOperations()->RestoreShape(aStream);
181 if (!GetOperations()->IsDone() || anObject.IsNull())
182 return aGEOMObject._retn();
184 return GetObject(anObject);
187 //=============================================================================
191 //=============================================================================
192 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
194 GetOperations()->SetNotDone();
195 return GetOperations()->LoadTexture( theTextureFile );
198 //=============================================================================
202 //=============================================================================
203 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
204 const SALOMEDS::TMPFile& theTexture)
206 GetOperations()->SetNotDone();
208 Handle(TColStd_HArray1OfByte) aTexture;
210 if ( theTexture.length() > 0 ) {
211 aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
213 for ( CORBA::ULong i = 0; i < theTexture.length(); i++ )
214 aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
216 return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
219 //=============================================================================
223 //=============================================================================
224 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
225 CORBA::Long& theWidth,
226 CORBA::Long& theHeight)
229 Handle(TColStd_HArray1OfByte) aTextureImpl =
230 GetOperations()->GetTexture(theID, aWidth, aHeight);
233 SALOMEDS::TMPFile_var aTexture;
234 if ( !aTextureImpl.IsNull() ) {
235 aTexture = new SALOMEDS::TMPFile;
236 aTexture->length( aTextureImpl->Length() );
237 for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
238 aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
240 return aTexture._retn();
243 //=============================================================================
247 //=============================================================================
248 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
250 std::list<int> localIDs = GetOperations()->GetAllTextures();
251 GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
252 anIDs->length(localIDs.size());
253 std::list<int>::const_iterator anIt;
255 for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
257 return anIDs._retn();
260 //=============================================================================
264 //=============================================================================
265 CORBA::Boolean GEOM_IInsertOperations_i::TransferData
266 (GEOM::GEOM_Object_ptr theObjectFrom,
267 GEOM::GEOM_Object_ptr theObjectTo,
268 GEOM::find_shape_method theFindMethod,
269 GEOM::GEOM_IInsertOperations::ListOfTransferDatum_out theResult)
271 //Set a not done flag
272 GetOperations()->SetNotDone();
274 if (CORBA::is_nil(theObjectFrom) || CORBA::is_nil(theObjectTo))
279 //Get the reference shape
280 Handle(::GEOM_Object) aShapeFrom = GetObjectImpl(theObjectFrom);
281 Handle(::GEOM_Object) aShapeTo = GetObjectImpl(theObjectTo);
283 if (aShapeFrom.IsNull() || aShapeTo.IsNull())
289 std::list<GEOMImpl_IInsertOperations::TransferDatum> aData;
290 int aFindMethod = -1;
292 switch (theFindMethod) {
293 case GEOM::FSM_GetInPlace:
294 aFindMethod = TD_GET_IN_PLACE;
296 case GEOM::FSM_GetInPlaceByHistory:
297 aFindMethod = TD_GET_IN_PLACE_BY_HISTORY;
299 case GEOM::FSM_GetInPlace_Old:
300 aFindMethod = TD_GET_IN_PLACE_OLD;
307 if (aFindMethod > 0) {
308 isOk = GetOperations()->TransferData
309 (aShapeFrom, aShapeTo, aFindMethod, aData);
314 const int aNbDatum = aData.size();
315 GEOM::GEOM_IInsertOperations::ListOfTransferDatum_var aResult =
316 new GEOM::GEOM_IInsertOperations::ListOfTransferDatum;
318 aResult->length(aNbDatum);
320 // fill the local CORBA array with values from lists
321 std::list<GEOMImpl_IInsertOperations::TransferDatum>::const_iterator
322 anIt = aData.begin();
325 for (; anIt != aData.end(); i++, anIt++) {
326 GEOM::GEOM_IInsertOperations::TransferDatum_var aDatum =
327 new GEOM::GEOM_IInsertOperations::TransferDatum;
329 aDatum->myName = CORBA::string_dup(anIt->myName.ToCString());
330 aDatum->myNumber = anIt->myNumber;
331 aDatum->myMaxNumber = anIt->myMaxNumber;
335 theResult = aResult._retn();