Back to index

salome-geom  6.5.0
GEOMImpl_IInsertOperations.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_IInsertOperations.hxx>
00026 
00027 #include <GEOMImpl_CopyDriver.hxx>
00028 #include <GEOMImpl_ExportDriver.hxx>
00029 #include <GEOMImpl_ImportDriver.hxx>
00030 #include <GEOMImpl_ICopy.hxx>
00031 #include <GEOMImpl_IImportExport.hxx>
00032 #include <GEOMImpl_Types.hxx>
00033 
00034 #include <GEOM_Function.hxx>
00035 #include <GEOM_PythonDump.hxx>
00036 
00037 #include <Basics_OCCTVersion.hxx>
00038 
00039 #include "utilities.h"
00040 #include <OpUtil.hxx>
00041 #include <Utils_ExceptHandlers.hxx>
00042 
00043 #include <TFunction_DriverTable.hxx>
00044 #include <TFunction_Driver.hxx>
00045 #include <TFunction_Logbook.hxx>
00046 #include <TDF_Tool.hxx>
00047 
00048 #include <TopoDS.hxx>
00049 #include <TopoDS_Vertex.hxx>
00050 #include <BRep_Tool.hxx>
00051 #include <gp_Pnt.hxx>
00052 
00053 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00054 #include <TColStd_HArray1OfByte.hxx>
00055 #else
00056 #include <TDataStd_HArray1OfByte.hxx>
00057 #endif
00058 
00059 #include <Standard_Failure.hxx>
00060 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
00061 
00062 //=============================================================================
00066 //=============================================================================
00067 
00068 GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, int theDocID)
00069 : GEOM_IOperations(theEngine, theDocID)
00070 {
00071   MESSAGE("GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations");
00072 }
00073 
00074 //=============================================================================
00078 //=============================================================================
00079 
00080 GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations()
00081 {
00082   MESSAGE("GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations");
00083 }
00084 
00085 
00086 
00087 //=============================================================================
00091 //=============================================================================
00092 Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) theOriginal)
00093 {
00094   SetErrorCode(KO);
00095 
00096   if (theOriginal.IsNull()) return NULL;
00097 
00098   //Add a new Copy object
00099   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
00100 
00101   //Add a Copy function for creation a copy object
00102   Handle(GEOM_Function) aFunction = aCopy->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITH_REF);
00103 
00104   //Check if the function is set correctly
00105   if(aFunction->GetDriverGUID() != GEOMImpl_CopyDriver::GetID()) return NULL;
00106 
00107   GEOMImpl_ICopy aCI(aFunction);
00108 
00109   Handle(GEOM_Function) aRefFunction = theOriginal->GetLastFunction();
00110   if (aRefFunction.IsNull()) return NULL;
00111 
00112   aCI.SetOriginal(aRefFunction);
00113 
00114   //Compute the Copy value
00115   try {
00116 #if OCC_VERSION_LARGE > 0x06010000
00117     OCC_CATCH_SIGNALS;
00118 #endif
00119     if (!GetSolver()->ComputeFunction(aFunction)) {
00120       SetErrorCode("Copy driver failed");
00121       return NULL;
00122     }
00123   }
00124   catch (Standard_Failure) {
00125     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00126     SetErrorCode(aFail->GetMessageString());
00127     return NULL;
00128   }
00129 
00130   //Make a Python command
00131   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeCopy(" << theOriginal << ")";
00132 
00133   SetErrorCode(OK);
00134   return aCopy;
00135 }
00136 
00137 //=============================================================================
00141 //=============================================================================
00142 void GEOMImpl_IInsertOperations::Export
00143                      (const Handle(GEOM_Object)      theOriginal,
00144                       const TCollection_AsciiString& theFileName,
00145                       const TCollection_AsciiString& theFormatName)
00146 {
00147   SetErrorCode(KO);
00148 
00149   if (theOriginal.IsNull()) return;
00150 
00151   Handle(GEOM_Function) aRefFunction = theOriginal->GetLastFunction();
00152   if (aRefFunction.IsNull()) return;  //There is no function which creates an object to be exported
00153 
00154   //Add a new result object
00155   Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
00156 
00157   //Add an Export function
00158   Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_ExportDriver::GetID(), EXPORT_SHAPE);
00159   if (aFunction.IsNull()) return;
00160 
00161   //Check if the function is set correctly
00162   if (aFunction->GetDriverGUID() != GEOMImpl_ExportDriver::GetID()) return;
00163 
00164   Handle(TCollection_HAsciiString) aHLibName;
00165   if (!IsSupported(Standard_False, theFormatName, aHLibName)) {
00166     return;
00167   }
00168   TCollection_AsciiString aLibName = aHLibName->String();
00169 
00170   //Set parameters
00171   GEOMImpl_IImportExport aCI (aFunction);
00172   aCI.SetOriginal(aRefFunction);
00173   aCI.SetFileName(theFileName);
00174   aCI.SetFormatName(theFormatName);
00175   aCI.SetPluginName(aLibName);
00176 
00177   //Perform the Export
00178   try {
00179 #if OCC_VERSION_LARGE > 0x06010000
00180     OCC_CATCH_SIGNALS;
00181 #endif
00182     if (!GetSolver()->ComputeFunction(aFunction)) {
00183       SetErrorCode("Not enough space on disk, or you haven't permissions to write this directory");
00184       return;
00185     }
00186   }
00187   catch (Standard_Failure) {
00188     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00189     SetErrorCode(aFail->GetMessageString());
00190     return;
00191   }
00192 
00193   //Make a Python command
00194   GEOM::TPythonDump(aFunction) << "geompy.Export(" << theOriginal << ", \""
00195     << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
00196 
00197   SetErrorCode(OK);
00198 }
00199 
00200 //=============================================================================
00204 //=============================================================================
00205 Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
00206                                  (const TCollection_AsciiString& theFileName,
00207                                   const TCollection_AsciiString& theFormatName)
00208 {
00209   SetErrorCode(KO);
00210 
00211   if (theFileName.IsEmpty() || theFormatName.IsEmpty()) return NULL;
00212 
00213   //Add a new result object
00214   Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
00215 
00216   //Add an Import function
00217   Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_ImportDriver::GetID(), IMPORT_SHAPE);
00218   if (aFunction.IsNull()) return result;
00219 
00220   //Check if the function is set correctly
00221   if (aFunction->GetDriverGUID() != GEOMImpl_ImportDriver::GetID()) return result;
00222 
00223   Handle(TCollection_HAsciiString) aHLibName;
00224   if (!IsSupported(Standard_True, theFormatName.SubString(1,4), aHLibName)) {
00225     return result;
00226   }
00227   TCollection_AsciiString aLibName = aHLibName->String();
00228 
00229   //Set parameters
00230   GEOMImpl_IImportExport aCI (aFunction);
00231   aCI.SetFileName(theFileName);
00232   aCI.SetFormatName(theFormatName);
00233   aCI.SetPluginName(aLibName);
00234   //cout<<"IIO: theFormatName = "<<theFormatName.ToCString()<<endl;
00235 
00236   //Perform the Import
00237   try {
00238 #if OCC_VERSION_LARGE > 0x06010000
00239     OCC_CATCH_SIGNALS;
00240 #endif
00241     if (!GetSolver()->ComputeFunction(aFunction)) {
00242       SetErrorCode("Import driver failed");
00243       return NULL;
00244     }
00245   }
00246   catch (Standard_Failure) {
00247     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00248     SetErrorCode(aFail->GetMessageString());
00249     return NULL;
00250   }
00251 
00252   //Make a Python command
00253   if( theFormatName != "IGES_UNIT" ) {
00254     GEOM::TPythonDump(aFunction) << result << " = geompy.ImportFile(\""
00255       << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
00256   }
00257 
00258   SetErrorCode(OK);
00259 
00260   if( theFormatName == "IGES_UNIT" ) {
00261     TopoDS_Shape S = aFunction->GetValue();
00262     TopoDS_Vertex V = TopoDS::Vertex(S);
00263     gp_Pnt P = BRep_Tool::Pnt(V);
00264     double scale = P.X();
00265     TCollection_AsciiString aUnitName = "UNIT_M";
00266     if( fabs(scale-0.01) < 1.e-6 )
00267       aUnitName = "UNIT_CM";
00268     else if( fabs(scale-0.001) < 1.e-6 )
00269       aUnitName = "UNIT_MM";
00270     //cout<<"IIO: aUnitName = "<<aUnitName.ToCString()<<endl;
00271     SetErrorCode(aUnitName);
00272   }
00273 
00274   return result;
00275 }
00276 
00277 //=============================================================================
00281 //=============================================================================
00282 Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
00283                      (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
00284                       Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
00285 {
00286   if (theFormats.IsNull())
00287     theFormats = new TColStd_HSequenceOfAsciiString;
00288   else
00289     theFormats->Clear();
00290 
00291   if (thePatterns.IsNull())
00292     thePatterns = new TColStd_HSequenceOfAsciiString;
00293   else
00294     thePatterns->Clear();
00295 
00296   if (!InitResMgr()) return Standard_False;
00297 
00298   // Read Import formats list from install directory
00299   if (myResMgr->Find("Import")) {
00300     TCollection_AsciiString aFormats (myResMgr->Value("Import"));
00301     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
00302     int i = 1;
00303     for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
00304       theFormats->Append(aToken);
00305     }
00306   }
00307 
00308   // Read Import formats from user directory
00309   if (myResMgrUser->Find("Import")) {
00310     TCollection_AsciiString aFormats (myResMgrUser->Value("Import"));
00311     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
00312     int i = 1;
00313     for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
00314       int aLenFormats = theFormats->Length();
00315       bool isFound = false;
00316       for(int aInd=1;aInd<=aLenFormats;aInd++){
00317         if( theFormats->Value(aInd) == aToken){
00318           isFound = true;
00319           break;
00320         }
00321       }
00322       if(!isFound)
00323         theFormats->Append(aToken);
00324     }
00325   }
00326 
00327   // Read Patterns for each supported format
00328   int j = 1, len = theFormats->Length();
00329   for (; j <= len; j++) {
00330     TCollection_AsciiString aKey, aPattern;
00331     aKey = theFormats->Value(j) + ".ImportPattern";
00332     if (myResMgr->Find(aKey.ToCString()))
00333       aPattern = myResMgr->Value(aKey.ToCString());
00334     else if(myResMgrUser->Find(aKey.ToCString()))
00335       aPattern = myResMgrUser->Value(aKey.ToCString());
00336     else {
00337       aKey = theFormats->Value(j) + ".Pattern";
00338       if (myResMgr->Find(aKey.ToCString()))
00339         aPattern = myResMgr->Value(aKey.ToCString());
00340       else if(myResMgrUser->Find(aKey.ToCString()))
00341         aPattern = myResMgrUser->Value(aKey.ToCString());
00342       else {
00343         aPattern = theFormats->Value(j);
00344         aPattern += " Files ( *.* )";
00345       }
00346     }
00347     thePatterns->Append(aPattern);
00348   }
00349 
00350   return (!theFormats->IsEmpty());
00351 }
00352 
00353 //=============================================================================
00357 //=============================================================================
00358 Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
00359                      (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
00360                       Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
00361 {
00362   if (theFormats.IsNull())
00363     theFormats = new TColStd_HSequenceOfAsciiString;
00364   else
00365     theFormats->Clear();
00366 
00367   if (thePatterns.IsNull())
00368     thePatterns = new TColStd_HSequenceOfAsciiString;
00369   else
00370     thePatterns->Clear();
00371 
00372   if (!InitResMgr()) return Standard_False;
00373 
00374   // Read Export formats list from install directory
00375   if (myResMgr->Find("Export")) {
00376     TCollection_AsciiString aFormats (myResMgr->Value("Export"));
00377     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
00378     int i = 1;
00379     for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
00380       theFormats->Append(aToken);
00381     }
00382   }
00383 
00384   // Read Export formats list from user directory
00385   if (myResMgrUser->Find("Export")) {
00386     TCollection_AsciiString aFormats (myResMgrUser->Value("Export"));
00387     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
00388     int i = 1;
00389     for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
00390       int aLenFormats = theFormats->Length();
00391       bool isFound = false;
00392       for(int aInd=1;aInd<=aLenFormats;aInd++){
00393         if( theFormats->Value(aInd) == aToken){
00394           isFound = true;
00395           break;
00396         }
00397       }
00398       if(!isFound)
00399         theFormats->Append(aToken);
00400     }
00401   }
00402 
00403   // Read Patterns for each supported format
00404   int j = 1, len = theFormats->Length();
00405   for (; j <= len; j++) {
00406     TCollection_AsciiString aKey, aPattern;
00407     aKey = theFormats->Value(j) + ".ExportPattern";
00408     if (myResMgr->Find(aKey.ToCString()))
00409       aPattern = myResMgr->Value(aKey.ToCString());
00410     else if (myResMgrUser->Find(aKey.ToCString()))
00411       aPattern = myResMgrUser->Value(aKey.ToCString());
00412     else {
00413       aKey = theFormats->Value(j) + ".Pattern";
00414       if (myResMgr->Find(aKey.ToCString()))
00415         aPattern = myResMgr->Value(aKey.ToCString());
00416       else if (myResMgrUser->Find(aKey.ToCString()))
00417         aPattern = myResMgrUser->Value(aKey.ToCString());
00418       else {
00419         aPattern = theFormats->Value(j);
00420         aPattern += " Files ( *.* )";
00421       }
00422     }
00423     thePatterns->Append(aPattern);
00424   }
00425 
00426   return (!theFormats->IsEmpty());
00427 }
00428 
00429 //=============================================================================
00433 //=============================================================================
00434 Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
00435                             (const Standard_Boolean isImport,
00436                              const TCollection_AsciiString& theFormat,
00437                              Handle(TCollection_HAsciiString)& theLibName)
00438 {
00439   if (!InitResMgr()) return Standard_False;
00440 
00441   // Import/Export mode
00442   TCollection_AsciiString aMode;
00443   //Standard_CString aMode;
00444   if (isImport) aMode = "Import";
00445   else aMode = "Export";
00446 
00447   // Read supported formats for the certain mode from install directory
00448   if (myResMgr->Find(aMode.ToCString())) {
00449     TCollection_AsciiString aFormats (myResMgr->Value(aMode.ToCString()));
00450     if (aFormats.Search(theFormat) > -1) {
00451       // Read library name for the supported format
00452       TCollection_AsciiString aKey (theFormat);
00453       aKey += ".";
00454       aKey += aMode;
00455       if (myResMgr->Find(aKey.ToCString())) {
00456         TCollection_AsciiString aLibName (myResMgr->Value(aKey.ToCString()));        
00457 #ifndef WNT
00458         aLibName += ".so";     
00459 #else
00460         aLibName += ".dll";
00461 #endif
00462         theLibName = new TCollection_HAsciiString (aLibName);
00463         return Standard_True;
00464       }
00465     }
00466   }
00467   
00468   // Read supported formats for the certain mode from user directory
00469   if (myResMgrUser->Find(aMode.ToCString())) {
00470     TCollection_AsciiString aFormats (myResMgrUser->Value(aMode.ToCString()));
00471     if (aFormats.Search(theFormat) > -1) {
00472       // Read library name for the supported format
00473       TCollection_AsciiString aKey (theFormat);
00474       aKey += ".";
00475       aKey += aMode;
00476       if (myResMgrUser->Find(aKey.ToCString())) {
00477         TCollection_AsciiString aLibName (myResMgrUser->Value(aKey.ToCString()));
00478         theLibName = new TCollection_HAsciiString (aLibName);
00479         return Standard_True;
00480       }
00481     }
00482   }
00483   
00484   return Standard_False;
00485 }
00486 
00487 //=============================================================================
00491 //=============================================================================
00492 Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
00493 {
00494   bool isResourceFound     = false;
00495   bool isResourceFoundUser = false;
00496   TCollection_AsciiString aUserResDir,aResDir;
00497   
00498   if (myResMgr.IsNull()) {
00499     // Initialize the Resource Manager
00500     TCollection_AsciiString aNull;
00501     aResDir = TCollection_AsciiString(getenv("GEOM_ROOT_DIR"));
00502 #ifdef WNT
00503     aResDir += "\\share\\salome\\resources\\geom";
00504 #else
00505     aResDir += "/share/salome/resources/geom";
00506 #endif
00507     
00508     myResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False);
00509 
00510     isResourceFound = true;
00511     if (!myResMgr->Find("Import") && !myResMgr->Find("Export")) {
00512       // instead of complains in Resource_Manager
00513       isResourceFound = false;
00514       INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
00515     }
00516   } else
00517     isResourceFound = true;
00518 
00519   if (myResMgrUser.IsNull()) {
00520     char * dir = getenv("GEOM_ENGINE_RESOURCES_DIR");
00521     TCollection_AsciiString aNull;
00522     if ( dir )
00523     {
00524       aUserResDir = dir;
00525     }
00526     else
00527     {
00528       aUserResDir = getenv("HOME");
00529 #ifdef WNT
00530       aUserResDir += "\\.salome\\resources";
00531 #else
00532       aUserResDir += "/.salome/resources";
00533 #endif
00534     }
00535 
00536     myResMgrUser = new Resource_Manager ("ImportExport", aNull, aUserResDir, Standard_False);
00537 
00538     isResourceFoundUser = true;
00539     
00540     if (!myResMgrUser->Find("Import") && !myResMgrUser->Find("Export")) {
00541       // instead of complains in Resource_Manager
00542       isResourceFoundUser = false;
00543     }
00544       
00545   } else
00546     isResourceFoundUser = true;
00547     
00548   if(!isResourceFound && !isResourceFoundUser){
00549     INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
00550     INFOS("No valid file \"ImportExport\" found in " << aUserResDir.ToCString() );
00551   }
00552 
00553   return ( myResMgr->Find("Import") || myResMgr->Find("Export") ||
00554            myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
00555 }
00556 
00557 int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTextureFile)
00558 {
00559   SetErrorCode(KO);
00560 
00561   if (theTextureFile.IsEmpty()) return 0;
00562 
00563 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00564   Handle(TColStd_HArray1OfByte) aTexture;
00565 #else
00566   Handle(TDataStd_HArray1OfByte) aTexture;
00567 #endif
00568 
00569   FILE* fp = fopen(theTextureFile.ToCString(), "r");
00570   if (!fp) return 0;
00571 
00572   std::list<std::string> lines;
00573   char buffer[4096];
00574   int maxlen = 0;
00575   while (!feof(fp)) {
00576     if ((fgets(buffer, 4096, fp)) == NULL) break;
00577     int aLen = strlen(buffer);
00578     if (buffer[aLen-1] == '\n') buffer[aLen-1] = '\0';
00579     lines.push_back(buffer);
00580     maxlen = std::max(maxlen, (int)strlen(buffer));
00581   }
00582 
00583   fclose(fp);
00584 
00585   int lenbytes = maxlen/8;
00586   if (maxlen%8) lenbytes++;
00587 
00588   if (lenbytes == 0 || lines.empty())
00589     return 0;
00590 
00591   std::list<unsigned char> bytedata;
00592   std::list<std::string>::const_iterator it;
00593   for (it = lines.begin(); it != lines.end(); ++it) {
00594     std::string line = *it;
00595     int lenline = (line.size()/8 + (line.size()%8 ? 1 : 0)) * 8;
00596     for (int i = 0; i < lenline/8; i++) {
00597       unsigned char byte = 0;
00598       for (int j = 0; j < 8; j++)
00599         byte = (byte << 1) + ( i*8+j < line.size() && line[i*8+j] != '0' ? 1 : 0 );
00600       bytedata.push_back(byte);
00601     }
00602     for (int i = lenline/8; i < lenbytes; i++)
00603       bytedata.push_back((unsigned char)0);
00604   }
00605 
00606   if (bytedata.empty() || bytedata.size() != lines.size()*lenbytes)
00607     return 0;
00608 
00609 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00610   aTexture = new TColStd_HArray1OfByte (1, lines.size()*lenbytes);
00611 #else
00612   aTexture = new TDataStd_HArray1OfByte (1, lines.size()*lenbytes);
00613 #endif
00614 
00615   std::list<unsigned char>::iterator bdit;
00616   int i;
00617   for (i = 1, bdit = bytedata.begin(); bdit != bytedata.end(); ++bdit, ++i)
00618     aTexture->SetValue(i, (Standard_Byte)(*bdit));
00619 
00620   int aTextureId = GetEngine()->addTexture(GetDocID(), lenbytes*8, lines.size(), aTexture, theTextureFile);
00621   if (aTextureId > 0) SetErrorCode(OK);
00622   return aTextureId;
00623 }
00624   
00625 int GEOMImpl_IInsertOperations::AddTexture(int theWidth, int theHeight, 
00626 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00627                                            const Handle(TColStd_HArray1OfByte)& theTexture)
00628 #else
00629                                            const Handle(TDataStd_HArray1OfByte)& theTexture)
00630 #endif
00631 {
00632   SetErrorCode(KO);
00633   int aTextureId = GetEngine()->addTexture(GetDocID(), theWidth, theHeight, theTexture);
00634   if (aTextureId > 0) SetErrorCode(OK);
00635   return aTextureId;
00636 }
00637 
00638 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00639 Handle(TColStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTextureId,
00640 #else
00641 Handle(TDataStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTextureId,
00642 #endif
00643                                                                       int& theWidth, int& theHeight)
00644 {
00645   SetErrorCode(KO);
00646   
00647 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00648   Handle(TColStd_HArray1OfByte) aTexture;
00649 #else
00650   Handle(TDataStd_HArray1OfByte) aTexture;
00651 #endif
00652 
00653   theWidth = theHeight = 0;
00654   TCollection_AsciiString aFileName;
00655 
00656   if (theTextureId <= 0)
00657     return aTexture;
00658 
00659   aTexture = GetEngine()->getTexture(GetDocID(), theTextureId, theWidth, theHeight, aFileName);
00660 
00661   if (theWidth > 0 && theHeight > 0 && aTexture->Length() > 0) SetErrorCode(OK);
00662 
00663   return aTexture;
00664 }
00665 
00666 std::list<int> GEOMImpl_IInsertOperations::GetAllTextures()
00667 {
00668   SetErrorCode(KO);
00669   std::list<int> id_list = GetEngine()->getAllTextures(GetDocID());
00670   SetErrorCode(OK);
00671   return id_list;
00672 }