X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMImpl%2FGEOMImpl_IInsertOperations.cxx;h=efb8255fa11b2e6e157c705ffe7817e0fd29dd60;hb=90dda39995ebbd4c4de8184fd89f528fafc45474;hp=5fb461ff7d4e13310675a14bab77cac0d4682737;hpb=392885c1a8d50369708bbe5e6b44033ed8b8ba51;p=modules%2Fgeom.git diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx index 5fb461ff7..efb8255fa 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include #include @@ -44,6 +45,12 @@ #include +#include +#include +#include +#include +#include + #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC @@ -129,8 +136,8 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) the //============================================================================= void GEOMImpl_IInsertOperations::Export (const Handle(GEOM_Object) theOriginal, - const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& theFormatName) + const TCollection_AsciiString& theFileName, + const TCollection_AsciiString& theFormatName) { SetErrorCode(KO); @@ -189,7 +196,7 @@ void GEOMImpl_IInsertOperations::Export //============================================================================= Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import (const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& theFormatName) + const TCollection_AsciiString& theFormatName) { SetErrorCode(KO); @@ -206,7 +213,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import if (aFunction->GetDriverGUID() != GEOMImpl_ImportDriver::GetID()) return result; Handle(TCollection_HAsciiString) aHLibName; - if (!IsSupported(Standard_True, theFormatName, aHLibName)) { + if (!IsSupported(Standard_True, theFormatName.SubString(1,4), aHLibName)) { return result; } TCollection_AsciiString aLibName = aHLibName->String(); @@ -216,6 +223,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import aCI.SetFileName(theFileName); aCI.SetFormatName(theFormatName); aCI.SetPluginName(aLibName); + //cout<<"IIO: theFormatName = "<GetValue(); + TopoDS_Vertex V = TopoDS::Vertex(S); + gp_Pnt P = BRep_Tool::Pnt(V); + double scale = P.X(); + TCollection_AsciiString aUnitName = "UNIT_M"; + if( fabs(scale-0.01) < 1.e-6 ) + aUnitName = "UNIT_CM"; + else if( fabs(scale-0.001) < 1.e-6 ) + aUnitName = "UNIT_MM"; + //cout<<"IIO: aUnitName = "<Length(); bool isFound = false; for(int aInd=1;aInd<=aLenFormats;aInd++){ - if( theFormats->Value(aInd) == aToken){ - isFound = true; - break; - } + if( theFormats->Value(aInd) == aToken){ + isFound = true; + break; + } } if(!isFound) - theFormats->Append(aToken); + theFormats->Append(aToken); } } @@ -305,7 +330,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators if (myResMgr->Find(aKey.ToCString())) aPattern = myResMgr->Value(aKey.ToCString()); else if(myResMgrUser->Find(aKey.ToCString())) - aPattern = myResMgrUser->Value(aKey.ToCString()); + aPattern = myResMgrUser->Value(aKey.ToCString()); else { aPattern = theFormats->Value(j); aPattern += " Files ( *.* )"; @@ -324,7 +349,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators //============================================================================= Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators (Handle(TColStd_HSequenceOfAsciiString)& theFormats, - Handle(TColStd_HSequenceOfAsciiString)& thePatterns) + Handle(TColStd_HSequenceOfAsciiString)& thePatterns) { if (theFormats.IsNull()) theFormats = new TColStd_HSequenceOfAsciiString; @@ -357,13 +382,13 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators int aLenFormats = theFormats->Length(); bool isFound = false; for(int aInd=1;aInd<=aLenFormats;aInd++){ - if( theFormats->Value(aInd) == aToken){ - isFound = true; - break; - } + if( theFormats->Value(aInd) == aToken){ + isFound = true; + break; + } } if(!isFound) - theFormats->Append(aToken); + theFormats->Append(aToken); } } @@ -381,7 +406,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators if (myResMgr->Find(aKey.ToCString())) aPattern = myResMgr->Value(aKey.ToCString()); else if (myResMgrUser->Find(aKey.ToCString())) - aPattern = myResMgrUser->Value(aKey.ToCString()); + aPattern = myResMgrUser->Value(aKey.ToCString()); else { aPattern = theFormats->Value(j); aPattern += " Files ( *.* )"; @@ -411,7 +436,6 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported if (isImport) aMode = "Import"; else aMode = "Export"; - // Read supported formats for the certain mode from install directory if (myResMgr->Find(aMode.ToCString())) { TCollection_AsciiString aFormats (myResMgr->Value(aMode.ToCString())); @@ -519,5 +543,100 @@ Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr() } return ( myResMgr->Find("Import") || myResMgr->Find("Export") || - myResMgrUser->Find("Import") || myResMgrUser->Find("Export")); + myResMgrUser->Find("Import") || myResMgrUser->Find("Export")); +} + +int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTextureFile) +{ + SetErrorCode(KO); + + if (theTextureFile.IsEmpty()) return 0; + + Handle(TDataStd_HArray1OfByte) aTexture; + + FILE* fp = fopen(theTextureFile.ToCString(), "r"); + if (!fp) return 0; + + std::list lines; + char buffer[4096]; + int maxlen = 0; + while (!feof(fp)) { + if ((fgets(buffer, 4096, fp)) == NULL) break; + int aLen = strlen(buffer); + if (buffer[aLen-1] == '\n') buffer[aLen-1] = '\0'; + lines.push_back(buffer); + maxlen = std::max(maxlen, (int)strlen(buffer)); + } + + fclose(fp); + + int lenbytes = maxlen/8; + if (maxlen%8) lenbytes++; + + if (lenbytes == 0 || lines.empty()) + return 0; + + std::list bytedata; + std::list::const_iterator it; + for (it = lines.begin(); it != lines.end(); ++it) { + std::string line = *it; + int lenline = (line.size()/8 + (line.size()%8 ? 1 : 0)) * 8; + for (int i = 0; i < lenline/8; i++) { + unsigned char byte = 0; + for (int j = 0; j < 8; j++) + byte = (byte << 1) + ( i*8+j < line.size() && line[i*8+j] != '0' ? 1 : 0 ); + bytedata.push_back(byte); + } + for (int i = lenline/8; i < lenbytes; i++) + bytedata.push_back((unsigned char)0); + } + + if (bytedata.empty() || bytedata.size() != lines.size()*lenbytes) + return 0; + + aTexture = new TDataStd_HArray1OfByte(1, lines.size()*lenbytes); + std::list::iterator bdit; + int i; + for (i = 1, bdit = bytedata.begin(); bdit != bytedata.end(); ++bdit, ++i) + aTexture->SetValue(i, (Standard_Byte)(*bdit)); + + int aTextureId = GetEngine()->addTexture(GetDocID(), lenbytes*8, lines.size(), aTexture, theTextureFile); + if (aTextureId > 0) SetErrorCode(OK); + return aTextureId; +} + +int GEOMImpl_IInsertOperations::AddTexture(int theWidth, int theHeight, + const Handle(TDataStd_HArray1OfByte)& theTexture) +{ + SetErrorCode(KO); + int aTextureId = GetEngine()->addTexture(GetDocID(), theWidth, theHeight, theTexture); + if (aTextureId > 0) SetErrorCode(OK); + return aTextureId; +} + +Handle(TDataStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTextureId, + int& theWidth, int& theHeight) +{ + SetErrorCode(KO); + + Handle(TDataStd_HArray1OfByte) aTexture; + theWidth = theHeight = 0; + TCollection_AsciiString aFileName; + + if (theTextureId <= 0) + return aTexture; + + aTexture = GetEngine()->getTexture(GetDocID(), theTextureId, theWidth, theHeight, aFileName); + + if (theWidth > 0 && theHeight > 0 && aTexture->Length() > 0) SetErrorCode(OK); + + return aTexture; +} + +std::list GEOMImpl_IInsertOperations::GetAllTextures() +{ + SetErrorCode(KO); + std::list id_list = GetEngine()->getAllTextures(GetDocID()); + SetErrorCode(OK); + return id_list; }