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