]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IInsertOperations_i.cc
Salome HOME
Remove obsolete conditionals
[modules/geom.git] / src / GEOM_I / GEOM_IInsertOperations_i.cc
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifdef WIN32
24 #pragma warning( disable:4786 )
25 #endif
26
27 #include <Standard_Stream.hxx>
28
29 #include "GEOM_IInsertOperations_i.hh"
30
31 #include "utilities.h"
32 #include "OpUtil.hxx"
33 #include "Utils_ExceptHandlers.hxx"
34
35 #include "GEOM_Engine.hxx"
36 #include "GEOM_BaseObject.hxx"
37
38 #include <Basics_OCCTVersion.hxx>
39
40 #include <TColStd_HSequenceOfAsciiString.hxx>
41
42 #include <TColStd_HArray1OfByte.hxx>
43
44 //=============================================================================
45 /*!
46  *  constructor
47  */
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)
53 {
54   MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
55 }
56
57 //=============================================================================
58 /*!
59  *  destructor
60  */
61 //=============================================================================
62 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
63 {
64   MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
65 }
66
67
68 //=============================================================================
69 /*!
70  *  MakeCopy
71  */
72 //=============================================================================
73 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
74 {
75   GEOM::GEOM_Object_var aGEOMObject;
76
77   //Set a not done flag
78   GetOperations()->SetNotDone();
79
80   //Get the reference shape
81   Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
82   if (anOriginal.IsNull()) return aGEOMObject._retn();
83
84   //Create the copy
85   Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
86
87   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
88
89   return GetObject(anObject);
90 }
91
92 //=============================================================================
93 /*!
94  *  Export
95  */
96 //=============================================================================
97 void GEOM_IInsertOperations_i::Export
98                    (GEOM::GEOM_Object_ptr theOriginal,
99                     const char*           theFileName,
100                     const char*           theFormatName)
101 {
102   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
103
104   //Set a not done flag
105   GetOperations()->SetNotDone();
106
107   //Get the reference shape
108   Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
109   if (anOriginal.IsNull()) return;
110
111   //Export the shape to the file
112   GetOperations()->Export(anOriginal, theFileName, theFormatName);
113 }
114
115 //=============================================================================
116 /*!
117  *  ImportFile
118  */
119 //=============================================================================
120 GEOM::ListOfGBO* GEOM_IInsertOperations_i::ImportFile
121                    (const char* theFileName,
122                     const char* theFormatName)
123 {
124   GEOM::ListOfGBO_var aSeq = new GEOM::ListOfGBO;
125
126   //Set a not done flag
127   GetOperations()->SetNotDone();
128
129   //Import the shape from the file
130   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->Import(theFileName, theFormatName);
131
132   if (!GetOperations()->IsDone() || aHSeq.IsNull()) {
133     return aSeq._retn();
134   }
135
136   // Copy created objects.
137   Standard_Integer aLength = aHSeq->Length();
138
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)));
142
143   return aSeq._retn();
144 }
145
146 //=============================================================================
147 /*!
148  *  ReadValue
149  */
150 //=============================================================================
151 char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName,
152                                           const char* theFormatName,
153                                           const char* theParameterName)
154 {
155   //Set a not done flag
156   GetOperations()->SetNotDone();
157
158   TCollection_AsciiString aUnits = GetOperations()->ReadValue
159     (theFileName, theFormatName, theParameterName);
160
161   return CORBA::string_dup(aUnits.ToCString());
162 }
163
164 //=============================================================================
165 /*!
166  *  RestoreShape
167  */
168 //=============================================================================
169 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::RestoreShape (const SALOMEDS::TMPFile& theStream)
170 {
171   GEOM::GEOM_Object_var aGEOMObject;
172
173   //Set a not done flag
174   GetOperations()->SetNotDone();
175
176   if (theStream.length() < 1)
177     return aGEOMObject._retn();
178
179   char* buf = (char*)theStream.NP_data();
180   std::istringstream aStream (buf);
181
182   Handle(GEOM_Object) anObject = GetOperations()->RestoreShape(aStream);
183   if (!GetOperations()->IsDone() || anObject.IsNull())
184     return aGEOMObject._retn();
185
186   return GetObject(anObject);
187 }
188
189 //=============================================================================
190 /*!
191  *  LoadTexture
192  */
193 //=============================================================================
194 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
195 {
196   GetOperations()->SetNotDone();
197   return GetOperations()->LoadTexture( theTextureFile );
198 }
199
200 //=============================================================================
201 /*!
202  *  AddTexture
203  */
204 //=============================================================================
205 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
206                                                  const SALOMEDS::TMPFile& theTexture)
207 {
208   GetOperations()->SetNotDone();
209
210   Handle(TColStd_HArray1OfByte) aTexture;
211
212   if ( theTexture.length() > 0 ) {
213     aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
214
215     for ( int i = 0; i < theTexture.length(); i++ )
216       aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
217   }
218   return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
219 }
220
221 //=============================================================================
222 /*!
223  *  GetTexture
224  */
225 //=============================================================================
226 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
227                                                         CORBA::Long& theWidth,
228                                                         CORBA::Long& theHeight)
229 {
230   int aWidth, aHeight;
231   Handle(TColStd_HArray1OfByte) aTextureImpl =
232     GetOperations()->GetTexture(theID, aWidth, aHeight);
233   theWidth  = aWidth;
234   theHeight = 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 );
241   }
242   return aTexture._retn();
243 }
244
245 //=============================================================================
246 /*!
247  *  GetAllTextures
248  */
249 //=============================================================================
250 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
251 {
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;
256   int i = 0;
257   for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
258     anIDs[i] = *anIt;
259   return anIDs._retn();
260 }
261
262