-//=============================================================================
-/*!
- * 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 list from install directory
- if (myResMgr->Find("Import")) {
- TCollection_AsciiString aFormats (myResMgr->Value("Import"));
- TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
- int i = 1;
- for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
- theFormats->Append(aToken);
- }
- }
-
- // Read Import formats from user directory
- if (myResMgrUser->Find("Import")) {
- TCollection_AsciiString aFormats (myResMgrUser->Value("Import"));
- TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
- int i = 1;
- for (; !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
- int j = 1, len = theFormats->Length();
- for (; j <= len; j++) {
- TCollection_AsciiString aKey, aPattern;
- aKey = theFormats->Value(j) + ".ImportPattern";
- if (myResMgr->Find(aKey.ToCString()))
- aPattern = myResMgr->Value(aKey.ToCString());
- else if(myResMgrUser->Find(aKey.ToCString()))
- aPattern = myResMgrUser->Value(aKey.ToCString());
- else {
- aKey = theFormats->Value(j) + ".Pattern";
- if (myResMgr->Find(aKey.ToCString()))
- aPattern = myResMgr->Value(aKey.ToCString());
- else if(myResMgrUser->Find(aKey.ToCString()))
- aPattern = myResMgrUser->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 install directory
- if (myResMgr->Find("Export")) {
- TCollection_AsciiString aFormats (myResMgr->Value("Export"));
- TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
- int i = 1;
- for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
- theFormats->Append(aToken);
- }
- }
-
- // Read Export formats list from user directory
- if (myResMgrUser->Find("Export")) {
- TCollection_AsciiString aFormats (myResMgrUser->Value("Export"));
- TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
- int i = 1;
- for (; !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
- int j = 1, len = theFormats->Length();
- for (; j <= len; j++) {
- TCollection_AsciiString aKey, aPattern;
- aKey = theFormats->Value(j) + ".ExportPattern";
- if (myResMgr->Find(aKey.ToCString()))
- aPattern = myResMgr->Value(aKey.ToCString());
- else if (myResMgrUser->Find(aKey.ToCString()))
- aPattern = myResMgrUser->Value(aKey.ToCString());
- else {
- aKey = theFormats->Value(j) + ".Pattern";
- if (myResMgr->Find(aKey.ToCString()))
- aPattern = myResMgr->Value(aKey.ToCString());
- else if (myResMgrUser->Find(aKey.ToCString()))
- aPattern = myResMgrUser->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 install directory
- if (myResMgr->Find(aMode.ToCString())) {
- TCollection_AsciiString aFormats (myResMgr->Value(aMode.ToCString()));
- if (aFormats.Search(theFormat) > -1) {
- // Read library name for the supported format
- TCollection_AsciiString aKey (theFormat);
- aKey += ".";
- aKey += aMode;
- if (myResMgr->Find(aKey.ToCString())) {
- TCollection_AsciiString aLibName (myResMgr->Value(aKey.ToCString()));
-#ifndef WNT
- aLibName += ".so";
-#else
- aLibName += ".dll";
-#endif
- theLibName = new TCollection_HAsciiString (aLibName);
- return Standard_True;
- }
- }
- }
-
- // Read supported formats for the certain mode from user directory
- if (myResMgrUser->Find(aMode.ToCString())) {
- TCollection_AsciiString aFormats (myResMgrUser->Value(aMode.ToCString()));
- if (aFormats.Search(theFormat) > -1) {
- // Read library name for the supported format
- TCollection_AsciiString aKey (theFormat);
- aKey += ".";
- aKey += aMode;
- if (myResMgrUser->Find(aKey.ToCString())) {
- TCollection_AsciiString aLibName (myResMgrUser->Value(aKey.ToCString()));
- theLibName = new TCollection_HAsciiString (aLibName);
- return Standard_True;
- }
- }
- }
-
- return Standard_False;
-}
-
-//=============================================================================
-/*!
- * InitResMgr
- */
-//=============================================================================
-Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
-{
- bool isResourceFound = false;
- bool isResourceFoundUser = false;
- TCollection_AsciiString aUserResDir,aResDir;
-
- if (myResMgr.IsNull()) {
- // Initialize the Resource Manager
- TCollection_AsciiString aNull;
- aResDir = TCollection_AsciiString(getenv("GEOM_ROOT_DIR"));
-#ifdef WNT
- aResDir += "\\share\\salome\\resources\\geom";
-#else
- aResDir += "/share/salome/resources/geom";
-#endif
-
- myResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False);
-
- isResourceFound = true;
- if (!myResMgr->Find("Import") && !myResMgr->Find("Export")) {
- // instead of complains in Resource_Manager
- isResourceFound = false;
- INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
- }
- } else
- isResourceFound = true;
-
- if (myResMgrUser.IsNull()) {
- char * dir = getenv("GEOM_ENGINE_RESOURCES_DIR");
- TCollection_AsciiString aNull;
- if ( dir )
- {
- aUserResDir = dir;
- }
- else
- {
- aUserResDir = getenv("HOME");
-#ifdef WNT
- aUserResDir += "\\.salome\\resources";
-#else
- aUserResDir += "/.salome/resources";
-#endif
- }
-
- myResMgrUser = new Resource_Manager ("ImportExport", aNull, aUserResDir, Standard_False);
-
- isResourceFoundUser = true;
-
- if (!myResMgrUser->Find("Import") && !myResMgrUser->Find("Export")) {
- // instead of complains in Resource_Manager
- isResourceFoundUser = false;
- }
-
- } else
- isResourceFoundUser = true;
-
- if(!isResourceFound && !isResourceFoundUser){
- INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
- INFOS("No valid file \"ImportExport\" found in " << aUserResDir.ToCString() );
- }
-
- return ( myResMgr->Find("Import") || myResMgr->Find("Export") ||
- myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
-}
-