-//=============================================================================
-/*!
- * ImportTranslators
- */
-//=============================================================================
-Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
- (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
- Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
-{
- if (theFormats.IsNull())
- theFormats = new TColStd_HSequenceOfAsciiString;
- else
- theFormats->Clear();
-
- if (thePatterns.IsNull())
- thePatterns = new TColStd_HSequenceOfAsciiString;
- else
- thePatterns->Clear();
-
- if (!InitResMgr()) return Standard_False;
-
- // Read Import formats from directories
- Handle(Resource_Manager) aResMgr;
- Handle(TColStd_HSequenceOfAsciiString) aFormatsToAdd;
- for(int index = 0; index < myResMgrList.size(); index++) {
- int anOldLen = theFormats->Length();
- aResMgr = myResMgrList.at(index);
- if (aResMgr->Find("Import")) {
- TCollection_AsciiString aFormats (aResMgr->Value("Import"));
- TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
- for (int i = 1; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
- int aLenFormats = theFormats->Length();
- bool isFound = false;
- for(int aInd=1;aInd<=aLenFormats;aInd++){
- if( theFormats->Value(aInd) == aToken ){
- isFound = true;
- break;
- }
- }
- if(!isFound)
- theFormats->Append(aToken);
- }
- }
-
- // Read Patterns for each supported format
- for (int j = anOldLen+1; j <= theFormats->Length(); j++) {
- TCollection_AsciiString aKey, aPattern;
- aKey = theFormats->Value(j) + ".ImportPattern";
- if (aResMgr->Find(aKey.ToCString()))
- aPattern = aResMgr->Value(aKey.ToCString());
- else {
- aKey = theFormats->Value(j) + ".Pattern";
- if (aResMgr->Find(aKey.ToCString()))
- aPattern = aResMgr->Value(aKey.ToCString());
- else {
- aPattern = theFormats->Value(j);
- aPattern += " Files ( *.* )";
- }
- }
- thePatterns->Append(aPattern);
- }
- }
-
- return (!theFormats->IsEmpty());
-}
-
-//=============================================================================
-/*!
- * ExportTranslators
- */
-//=============================================================================
-Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
- (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
- Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
-{
- if (theFormats.IsNull())
- theFormats = new TColStd_HSequenceOfAsciiString;
- else
- theFormats->Clear();
-
- if (thePatterns.IsNull())
- thePatterns = new TColStd_HSequenceOfAsciiString;
- else
- thePatterns->Clear();
-
- if (!InitResMgr()) return Standard_False;
-
- // Read Export formats list from directories
- Handle(Resource_Manager) aResMgr;
- for(int index=0; index < myResMgrList.size(); index++) {
- int anOldLen = theFormats->Length();
- aResMgr = myResMgrList.at(index);
- if (aResMgr->Find("Export")) {
- TCollection_AsciiString aFormats (aResMgr->Value("Export"));
- TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
- for (int i = 1; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
- int aLenFormats = theFormats->Length();
- bool isFound = false;
- for(int aInd=1;aInd<=aLenFormats;aInd++){
- if( theFormats->Value(aInd) == aToken){
- isFound = true;
- break;
- }
- }
- if(!isFound)
- theFormats->Append(aToken);
- }
- }
-
- // Read Patterns for each supported format
- for (int j = anOldLen+1; j <= theFormats->Length(); j++) {
- TCollection_AsciiString aKey, aPattern;
- aKey = theFormats->Value(j) + ".ExportPattern";
- if (aResMgr->Find(aKey.ToCString()))
- aPattern = aResMgr->Value(aKey.ToCString());
- else {
- aKey = theFormats->Value(j) + ".Pattern";
- if (aResMgr->Find(aKey.ToCString()))
- aPattern = aResMgr->Value(aKey.ToCString());
- else {
- aPattern = theFormats->Value(j);
- aPattern += " Files ( *.* )";
- }
- }
- thePatterns->Append(aPattern);
- }
- }
-
- return (!theFormats->IsEmpty());
-}
-
-//=============================================================================
-/*!
- * IsSupported
- */
-//=============================================================================
-Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
- (const Standard_Boolean isImport,
- const TCollection_AsciiString& theFormat,
- Handle(TCollection_HAsciiString)& theLibName)
-{
- if (!InitResMgr()) return Standard_False;
-
- // Import/Export mode
- TCollection_AsciiString aMode;
- //Standard_CString aMode;
- if (isImport) aMode = "Import";
- else aMode = "Export";
-
- // Read supported formats for the certain mode from user directory
- Handle(Resource_Manager) aResMgr;
- for(int index=0; index < myResMgrList.size(); index++) {
- aResMgr = myResMgrList.at(index);
- if (aResMgr->Find(aMode.ToCString())) {
- TCollection_AsciiString aFormats (aResMgr->Value(aMode.ToCString()));
- if (aFormats.Search(theFormat) > -1) {
- // Read library name for the supported format
- TCollection_AsciiString aKey (theFormat);
- aKey += ".";
- aKey += aMode;
- if (aResMgr->Find(aKey.ToCString())) {
- TCollection_AsciiString aLibName (aResMgr->Value(aKey.ToCString()));
- #ifndef WIN32
- if ( aLibName.Length() > 3 && aLibName.SubString(1,3) != "lib" )
- aLibName.Prepend("lib");
- aLibName += ".so";
- #else
- aLibName += ".dll";
- #endif
- theLibName = new TCollection_HAsciiString (aLibName);
- return Standard_True;
- }
- }
- }
- }
-
- return Standard_False;
-}
-
-//=============================================================================
-/*!
- * InitResMgr
- */
-//=============================================================================
-Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
-{
- bool isResourceFound = false;
- TCollection_AsciiString aNull;
-
- myResMgrList.clear();
-
- // Initialize the GEOM Resource Manager
- TCollection_AsciiString aResDir;
- aResDir = getenv("GEOM_ROOT_DIR");
-#ifdef WIN32
- aResDir += "\\share\\salome\\resources\\geom";
-#else
- aResDir += "/share/salome/resources/geom";
-#endif
- Handle(Resource_Manager) aGeomResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False);
- if ( aGeomResMgr->Find("Import") || aGeomResMgr->Find("Export") ) {
- myResMgrList.push_back( aGeomResMgr );
- isResourceFound = true;
- }
-
- // Initialize the user's Resource Manager
- TCollection_AsciiString aResDirsStr;
- aResDirsStr = getenv("GEOM_ENGINE_RESOURCES_DIR");
- if ( !aResDirsStr.IsEmpty() )
- {
- std::string aSep = ":";
-#ifdef WIN32
- aSep = ";";
-#endif
- aResDir = aResDirsStr.Token(aSep.c_str(), 1);
- for (int i = 1; !aResDir.IsEmpty(); aResDir = aResDirsStr.Token(aSep.c_str(), ++i)) {
- Handle(Resource_Manager) anUserResMgr = new Resource_Manager ("ImportExport", aNull, aResDir, Standard_False);
- if (anUserResMgr->Find("Import") || anUserResMgr->Find("Export")) {
- myResMgrList.push_back( anUserResMgr );
- isResourceFound = true;
- }
- }
- }
- else
- {
- aResDir = getenv("HOME");
-#ifdef WIN32
- aResDir += "\\.config\\salome";
-#else
- aResDir += "/.config/salome";
-#endif
- Handle(Resource_Manager) anUserResMgr = new Resource_Manager ("ImportExport", aNull, aResDir, Standard_False);
- if (anUserResMgr->Find("Import") || anUserResMgr->Find("Export")) {
- myResMgrList.push_back( anUserResMgr );
- isResourceFound = true;
- }
- }
- return isResourceFound;
-}
-