Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IInsertOperations.cxx
1 // Copyright (C) 2007-2012  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.
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 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_IInsertOperations.hxx>
26
27 #include <GEOMImpl_CopyDriver.hxx>
28 #include <GEOMImpl_ExportDriver.hxx>
29 #include <GEOMImpl_ImportDriver.hxx>
30 #include <GEOMImpl_ICopy.hxx>
31 #include <GEOMImpl_IImportExport.hxx>
32 #include <GEOMImpl_Types.hxx>
33
34 #include <GEOM_Function.hxx>
35 #include <GEOM_PythonDump.hxx>
36
37 #include <Basics_OCCTVersion.hxx>
38
39 #include "utilities.h"
40 #include <OpUtil.hxx>
41 #include <Utils_ExceptHandlers.hxx>
42
43 #include <TFunction_DriverTable.hxx>
44 #include <TFunction_Driver.hxx>
45 #include <TFunction_Logbook.hxx>
46 #include <TDF_Tool.hxx>
47
48 #include <TopoDS.hxx>
49 #include <TopoDS_Vertex.hxx>
50 #include <BRep_Tool.hxx>
51 #include <gp_Pnt.hxx>
52
53 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
54 #include <TColStd_HArray1OfByte.hxx>
55 #else
56 #include <TDataStd_HArray1OfByte.hxx>
57 #endif
58
59 #include <Standard_Failure.hxx>
60 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
61
62 //=============================================================================
63 /*!
64  *   constructor:
65  */
66 //=============================================================================
67
68 GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, int theDocID)
69 : GEOM_IOperations(theEngine, theDocID)
70 {
71   MESSAGE("GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations");
72 }
73
74 //=============================================================================
75 /*!
76  *  destructor
77  */
78 //=============================================================================
79
80 GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations()
81 {
82   MESSAGE("GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations");
83 }
84
85
86
87 //=============================================================================
88 /*!
89  *  MakeCopy
90  */
91 //=============================================================================
92 Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) theOriginal)
93 {
94   SetErrorCode(KO);
95
96   if (theOriginal.IsNull()) return NULL;
97
98   //Add a new Copy object
99   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
100
101   //Add a Copy function for creation a copy object
102   Handle(GEOM_Function) aFunction = aCopy->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITH_REF);
103
104   //Check if the function is set correctly
105   if(aFunction->GetDriverGUID() != GEOMImpl_CopyDriver::GetID()) return NULL;
106
107   GEOMImpl_ICopy aCI(aFunction);
108
109   Handle(GEOM_Function) aRefFunction = theOriginal->GetLastFunction();
110   if (aRefFunction.IsNull()) return NULL;
111
112   aCI.SetOriginal(aRefFunction);
113
114   //Compute the Copy value
115   try {
116 #if OCC_VERSION_LARGE > 0x06010000
117     OCC_CATCH_SIGNALS;
118 #endif
119     if (!GetSolver()->ComputeFunction(aFunction)) {
120       SetErrorCode("Copy driver failed");
121       return NULL;
122     }
123   }
124   catch (Standard_Failure) {
125     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
126     SetErrorCode(aFail->GetMessageString());
127     return NULL;
128   }
129
130   //Make a Python command
131   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeCopy(" << theOriginal << ")";
132
133   SetErrorCode(OK);
134   return aCopy;
135 }
136
137 //=============================================================================
138 /*!
139  *  Export
140  */
141 //=============================================================================
142 void GEOMImpl_IInsertOperations::Export
143                      (const Handle(GEOM_Object)      theOriginal,
144                       const TCollection_AsciiString& theFileName,
145                       const TCollection_AsciiString& theFormatName)
146 {
147   SetErrorCode(KO);
148
149   if (theOriginal.IsNull()) return;
150
151   Handle(GEOM_Function) aRefFunction = theOriginal->GetLastFunction();
152   if (aRefFunction.IsNull()) return;  //There is no function which creates an object to be exported
153
154   //Add a new result object
155   Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
156
157   //Add an Export function
158   Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_ExportDriver::GetID(), EXPORT_SHAPE);
159   if (aFunction.IsNull()) return;
160
161   //Check if the function is set correctly
162   if (aFunction->GetDriverGUID() != GEOMImpl_ExportDriver::GetID()) return;
163
164   Handle(TCollection_HAsciiString) aHLibName;
165   if (!IsSupported(Standard_False, theFormatName, aHLibName)) {
166     return;
167   }
168   TCollection_AsciiString aLibName = aHLibName->String();
169
170   //Set parameters
171   GEOMImpl_IImportExport aCI (aFunction);
172   aCI.SetOriginal(aRefFunction);
173   aCI.SetFileName(theFileName);
174   aCI.SetFormatName(theFormatName);
175   aCI.SetPluginName(aLibName);
176
177   //Perform the Export
178   try {
179 #if OCC_VERSION_LARGE > 0x06010000
180     OCC_CATCH_SIGNALS;
181 #endif
182     if (!GetSolver()->ComputeFunction(aFunction)) {
183       SetErrorCode("Not enough space on disk, or you haven't permissions to write this directory");
184       return;
185     }
186   }
187   catch (Standard_Failure) {
188     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
189     SetErrorCode(aFail->GetMessageString());
190     return;
191   }
192
193   //Make a Python command
194   GEOM::TPythonDump(aFunction) << "geompy.Export(" << theOriginal << ", \""
195     << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
196
197   SetErrorCode(OK);
198 }
199
200 //=============================================================================
201 /*!
202  *  Import
203  */
204 //=============================================================================
205 Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
206                                  (const TCollection_AsciiString& theFileName,
207                                   const TCollection_AsciiString& theFormatName)
208 {
209   SetErrorCode(KO);
210
211   if (theFileName.IsEmpty() || theFormatName.IsEmpty()) return NULL;
212
213   //Add a new result object
214   Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
215
216   //Add an Import function
217   Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_ImportDriver::GetID(), IMPORT_SHAPE);
218   if (aFunction.IsNull()) return result;
219
220   //Check if the function is set correctly
221   if (aFunction->GetDriverGUID() != GEOMImpl_ImportDriver::GetID()) return result;
222
223   Handle(TCollection_HAsciiString) aHLibName;
224   if (!IsSupported(Standard_True, theFormatName.SubString(1,4), aHLibName)) {
225     return result;
226   }
227   TCollection_AsciiString aLibName = aHLibName->String();
228
229   //Set parameters
230   GEOMImpl_IImportExport aCI (aFunction);
231   aCI.SetFileName(theFileName);
232   aCI.SetFormatName(theFormatName);
233   aCI.SetPluginName(aLibName);
234   //cout<<"IIO: theFormatName = "<<theFormatName.ToCString()<<endl;
235
236   //Perform the Import
237   try {
238 #if OCC_VERSION_LARGE > 0x06010000
239     OCC_CATCH_SIGNALS;
240 #endif
241     if (!GetSolver()->ComputeFunction(aFunction)) {
242       SetErrorCode("Import driver failed");
243       return NULL;
244     }
245   }
246   catch (Standard_Failure) {
247     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
248     SetErrorCode(aFail->GetMessageString());
249     return NULL;
250   }
251
252   //Make a Python command
253   if( theFormatName != "IGES_UNIT" ) {
254     GEOM::TPythonDump(aFunction) << result << " = geompy.ImportFile(\""
255       << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
256   }
257
258   SetErrorCode(OK);
259
260   if( theFormatName == "IGES_UNIT" ) {
261     TopoDS_Shape S = aFunction->GetValue();
262     TopoDS_Vertex V = TopoDS::Vertex(S);
263     gp_Pnt P = BRep_Tool::Pnt(V);
264     double scale = P.X();
265     TCollection_AsciiString aUnitName = "UNIT_M";
266     if( fabs(scale-0.01) < 1.e-6 )
267       aUnitName = "UNIT_CM";
268     else if( fabs(scale-0.001) < 1.e-6 )
269       aUnitName = "UNIT_MM";
270     //cout<<"IIO: aUnitName = "<<aUnitName.ToCString()<<endl;
271     SetErrorCode(aUnitName);
272   }
273
274   return result;
275 }
276
277 //=============================================================================
278 /*!
279  *  ImportTranslators
280  */
281 //=============================================================================
282 Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
283                      (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
284                       Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
285 {
286   if (theFormats.IsNull())
287     theFormats = new TColStd_HSequenceOfAsciiString;
288   else
289     theFormats->Clear();
290
291   if (thePatterns.IsNull())
292     thePatterns = new TColStd_HSequenceOfAsciiString;
293   else
294     thePatterns->Clear();
295
296   if (!InitResMgr()) return Standard_False;
297
298   // Read Import formats list from install directory
299   if (myResMgr->Find("Import")) {
300     TCollection_AsciiString aFormats (myResMgr->Value("Import"));
301     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
302     int i = 1;
303     for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
304       theFormats->Append(aToken);
305     }
306   }
307
308   // Read Import formats from user directory
309   if (myResMgrUser->Find("Import")) {
310     TCollection_AsciiString aFormats (myResMgrUser->Value("Import"));
311     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
312     int i = 1;
313     for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
314       int aLenFormats = theFormats->Length();
315       bool isFound = false;
316       for(int aInd=1;aInd<=aLenFormats;aInd++){
317         if( theFormats->Value(aInd) == aToken){
318           isFound = true;
319           break;
320         }
321       }
322       if(!isFound)
323         theFormats->Append(aToken);
324     }
325   }
326
327   // Read Patterns for each supported format
328   int j = 1, len = theFormats->Length();
329   for (; j <= len; j++) {
330     TCollection_AsciiString aKey, aPattern;
331     aKey = theFormats->Value(j) + ".ImportPattern";
332     if (myResMgr->Find(aKey.ToCString()))
333       aPattern = myResMgr->Value(aKey.ToCString());
334     else if(myResMgrUser->Find(aKey.ToCString()))
335       aPattern = myResMgrUser->Value(aKey.ToCString());
336     else {
337       aKey = theFormats->Value(j) + ".Pattern";
338       if (myResMgr->Find(aKey.ToCString()))
339         aPattern = myResMgr->Value(aKey.ToCString());
340       else if(myResMgrUser->Find(aKey.ToCString()))
341         aPattern = myResMgrUser->Value(aKey.ToCString());
342       else {
343         aPattern = theFormats->Value(j);
344         aPattern += " Files ( *.* )";
345       }
346     }
347     thePatterns->Append(aPattern);
348   }
349
350   return (!theFormats->IsEmpty());
351 }
352
353 //=============================================================================
354 /*!
355  *  ExportTranslators
356  */
357 //=============================================================================
358 Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
359                      (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
360                       Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
361 {
362   if (theFormats.IsNull())
363     theFormats = new TColStd_HSequenceOfAsciiString;
364   else
365     theFormats->Clear();
366
367   if (thePatterns.IsNull())
368     thePatterns = new TColStd_HSequenceOfAsciiString;
369   else
370     thePatterns->Clear();
371
372   if (!InitResMgr()) return Standard_False;
373
374   // Read Export formats list from install directory
375   if (myResMgr->Find("Export")) {
376     TCollection_AsciiString aFormats (myResMgr->Value("Export"));
377     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
378     int i = 1;
379     for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
380       theFormats->Append(aToken);
381     }
382   }
383
384   // Read Export formats list from user directory
385   if (myResMgrUser->Find("Export")) {
386     TCollection_AsciiString aFormats (myResMgrUser->Value("Export"));
387     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
388     int i = 1;
389     for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
390       int aLenFormats = theFormats->Length();
391       bool isFound = false;
392       for(int aInd=1;aInd<=aLenFormats;aInd++){
393         if( theFormats->Value(aInd) == aToken){
394           isFound = true;
395           break;
396         }
397       }
398       if(!isFound)
399         theFormats->Append(aToken);
400     }
401   }
402
403   // Read Patterns for each supported format
404   int j = 1, len = theFormats->Length();
405   for (; j <= len; j++) {
406     TCollection_AsciiString aKey, aPattern;
407     aKey = theFormats->Value(j) + ".ExportPattern";
408     if (myResMgr->Find(aKey.ToCString()))
409       aPattern = myResMgr->Value(aKey.ToCString());
410     else if (myResMgrUser->Find(aKey.ToCString()))
411       aPattern = myResMgrUser->Value(aKey.ToCString());
412     else {
413       aKey = theFormats->Value(j) + ".Pattern";
414       if (myResMgr->Find(aKey.ToCString()))
415         aPattern = myResMgr->Value(aKey.ToCString());
416       else if (myResMgrUser->Find(aKey.ToCString()))
417         aPattern = myResMgrUser->Value(aKey.ToCString());
418       else {
419         aPattern = theFormats->Value(j);
420         aPattern += " Files ( *.* )";
421       }
422     }
423     thePatterns->Append(aPattern);
424   }
425
426   return (!theFormats->IsEmpty());
427 }
428
429 //=============================================================================
430 /*!
431  *  IsSupported
432  */
433 //=============================================================================
434 Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
435                             (const Standard_Boolean isImport,
436                              const TCollection_AsciiString& theFormat,
437                              Handle(TCollection_HAsciiString)& theLibName)
438 {
439   if (!InitResMgr()) return Standard_False;
440
441   // Import/Export mode
442   TCollection_AsciiString aMode;
443   //Standard_CString aMode;
444   if (isImport) aMode = "Import";
445   else aMode = "Export";
446
447   // Read supported formats for the certain mode from install directory
448   if (myResMgr->Find(aMode.ToCString())) {
449     TCollection_AsciiString aFormats (myResMgr->Value(aMode.ToCString()));
450     if (aFormats.Search(theFormat) > -1) {
451       // Read library name for the supported format
452       TCollection_AsciiString aKey (theFormat);
453       aKey += ".";
454       aKey += aMode;
455       if (myResMgr->Find(aKey.ToCString())) {
456         TCollection_AsciiString aLibName (myResMgr->Value(aKey.ToCString()));        
457 #ifndef WNT
458         aLibName += ".so";     
459 #else
460         aLibName += ".dll";
461 #endif
462         theLibName = new TCollection_HAsciiString (aLibName);
463         return Standard_True;
464       }
465     }
466   }
467   
468   // Read supported formats for the certain mode from user directory
469   if (myResMgrUser->Find(aMode.ToCString())) {
470     TCollection_AsciiString aFormats (myResMgrUser->Value(aMode.ToCString()));
471     if (aFormats.Search(theFormat) > -1) {
472       // Read library name for the supported format
473       TCollection_AsciiString aKey (theFormat);
474       aKey += ".";
475       aKey += aMode;
476       if (myResMgrUser->Find(aKey.ToCString())) {
477         TCollection_AsciiString aLibName (myResMgrUser->Value(aKey.ToCString()));
478         theLibName = new TCollection_HAsciiString (aLibName);
479         return Standard_True;
480       }
481     }
482   }
483   
484   return Standard_False;
485 }
486
487 //=============================================================================
488 /*!
489  *  InitResMgr
490  */
491 //=============================================================================
492 Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
493 {
494   bool isResourceFound     = false;
495   bool isResourceFoundUser = false;
496   TCollection_AsciiString aUserResDir,aResDir;
497   
498   if (myResMgr.IsNull()) {
499     // Initialize the Resource Manager
500     TCollection_AsciiString aNull;
501     aResDir = TCollection_AsciiString(getenv("GEOM_ROOT_DIR"));
502 #ifdef WNT
503     aResDir += "\\share\\salome\\resources\\geom";
504 #else
505     aResDir += "/share/salome/resources/geom";
506 #endif
507     
508     myResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False);
509
510     isResourceFound = true;
511     if (!myResMgr->Find("Import") && !myResMgr->Find("Export")) {
512       // instead of complains in Resource_Manager
513       isResourceFound = false;
514       INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
515     }
516   } else
517     isResourceFound = true;
518
519   if (myResMgrUser.IsNull()) {
520     char * dir = getenv("GEOM_ENGINE_RESOURCES_DIR");
521     TCollection_AsciiString aNull;
522     if ( dir )
523     {
524       aUserResDir = dir;
525     }
526     else
527     {
528       aUserResDir = getenv("HOME");
529 #ifdef WNT
530       aUserResDir += "\\.salome\\resources";
531 #else
532       aUserResDir += "/.salome/resources";
533 #endif
534     }
535
536     myResMgrUser = new Resource_Manager ("ImportExport", aNull, aUserResDir, Standard_False);
537
538     isResourceFoundUser = true;
539     
540     if (!myResMgrUser->Find("Import") && !myResMgrUser->Find("Export")) {
541       // instead of complains in Resource_Manager
542       isResourceFoundUser = false;
543     }
544       
545   } else
546     isResourceFoundUser = true;
547     
548   if(!isResourceFound && !isResourceFoundUser){
549     INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
550     INFOS("No valid file \"ImportExport\" found in " << aUserResDir.ToCString() );
551   }
552
553   return ( myResMgr->Find("Import") || myResMgr->Find("Export") ||
554            myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
555 }
556
557 int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTextureFile)
558 {
559   SetErrorCode(KO);
560
561   if (theTextureFile.IsEmpty()) return 0;
562
563 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
564   Handle(TColStd_HArray1OfByte) aTexture;
565 #else
566   Handle(TDataStd_HArray1OfByte) aTexture;
567 #endif
568
569   FILE* fp = fopen(theTextureFile.ToCString(), "r");
570   if (!fp) return 0;
571
572   std::list<std::string> lines;
573   char buffer[4096];
574   int maxlen = 0;
575   while (!feof(fp)) {
576     if ((fgets(buffer, 4096, fp)) == NULL) break;
577     int aLen = strlen(buffer);
578     if (buffer[aLen-1] == '\n') buffer[aLen-1] = '\0';
579     lines.push_back(buffer);
580     maxlen = std::max(maxlen, (int)strlen(buffer));
581   }
582
583   fclose(fp);
584
585   int lenbytes = maxlen/8;
586   if (maxlen%8) lenbytes++;
587
588   if (lenbytes == 0 || lines.empty())
589     return 0;
590
591   std::list<unsigned char> bytedata;
592   std::list<std::string>::const_iterator it;
593   for (it = lines.begin(); it != lines.end(); ++it) {
594     std::string line = *it;
595     int lenline = (line.size()/8 + (line.size()%8 ? 1 : 0)) * 8;
596     for (int i = 0; i < lenline/8; i++) {
597       unsigned char byte = 0;
598       for (int j = 0; j < 8; j++)
599         byte = (byte << 1) + ( i*8+j < line.size() && line[i*8+j] != '0' ? 1 : 0 );
600       bytedata.push_back(byte);
601     }
602     for (int i = lenline/8; i < lenbytes; i++)
603       bytedata.push_back((unsigned char)0);
604   }
605
606   if (bytedata.empty() || bytedata.size() != lines.size()*lenbytes)
607     return 0;
608
609 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
610   aTexture = new TColStd_HArray1OfByte (1, lines.size()*lenbytes);
611 #else
612   aTexture = new TDataStd_HArray1OfByte (1, lines.size()*lenbytes);
613 #endif
614
615   std::list<unsigned char>::iterator bdit;
616   int i;
617   for (i = 1, bdit = bytedata.begin(); bdit != bytedata.end(); ++bdit, ++i)
618     aTexture->SetValue(i, (Standard_Byte)(*bdit));
619
620   int aTextureId = GetEngine()->addTexture(GetDocID(), lenbytes*8, lines.size(), aTexture, theTextureFile);
621   if (aTextureId > 0) SetErrorCode(OK);
622   return aTextureId;
623 }
624   
625 int GEOMImpl_IInsertOperations::AddTexture(int theWidth, int theHeight, 
626 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
627                                            const Handle(TColStd_HArray1OfByte)& theTexture)
628 #else
629                                            const Handle(TDataStd_HArray1OfByte)& theTexture)
630 #endif
631 {
632   SetErrorCode(KO);
633   int aTextureId = GetEngine()->addTexture(GetDocID(), theWidth, theHeight, theTexture);
634   if (aTextureId > 0) SetErrorCode(OK);
635   return aTextureId;
636 }
637
638 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
639 Handle(TColStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTextureId,
640 #else
641 Handle(TDataStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTextureId,
642 #endif
643                                                                       int& theWidth, int& theHeight)
644 {
645   SetErrorCode(KO);
646   
647 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
648   Handle(TColStd_HArray1OfByte) aTexture;
649 #else
650   Handle(TDataStd_HArray1OfByte) aTexture;
651 #endif
652
653   theWidth = theHeight = 0;
654   TCollection_AsciiString aFileName;
655
656   if (theTextureId <= 0)
657     return aTexture;
658
659   aTexture = GetEngine()->getTexture(GetDocID(), theTextureId, theWidth, theHeight, aFileName);
660
661   if (theWidth > 0 && theHeight > 0 && aTexture->Length() > 0) SetErrorCode(OK);
662
663   return aTexture;
664 }
665
666 std::list<int> GEOMImpl_IInsertOperations::GetAllTextures()
667 {
668   SetErrorCode(KO);
669   std::list<int> id_list = GetEngine()->getAllTextures(GetDocID());
670   SetErrorCode(OK);
671   return id_list;
672 }