# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-import os, sys
+import os, sys, string
from salome_utils import getTmpDir, generateFileName, uniteFiles
from setenv import add_path, get_lib_dir, salome_subdir
# find plugins
plugin_list = []
resource_path_list = []
+ plugins_dir_var = "GEOM_ENGINE_RESOURCES_DIR"
+ if os.environ.has_key(plugins_dir_var):
+ # reverse the user's paths list, because the used 'add_path' prepends a new path,
+ # but we want to append it: [a, b, c] => [c, b, a]
+ plugins_dirs = os.environ[plugins_dir_var].split(os.pathsep)
+ plugins_dirs.reverse()
+ os.environ[plugins_dir_var] = string.join(plugins_dirs, os.pathsep)
+ pass
for env_var in os.environ.keys():
value = os.environ[env_var]
if env_var[-9:] == "_ROOT_DIR" and value:
resource_dir = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower())
if not os.access( resource_dir, os.F_OK ): continue
for resource_file in os.listdir( resource_dir ):
- if not resource_file.endswith( ".xml") or \
- resource_file.lower() != plugin.lower() + ".xml":
- continue
- # use "name" attribute of "geom-plugin" as name of plugin in a right case
- from xml.dom.minidom import parse
- xml_doc = parse( os.path.join( resource_dir, resource_file ))
- plugin_nodes = xml_doc.getElementsByTagName("geom-plugin")
- if not plugin_nodes or not plugin_nodes[0].hasAttribute("name"): continue
- plugin = plugin_nodes[0].getAttribute("name")
- if plugin in plugin_list: continue
+ if resource_file.endswith( ".xml") and \
+ resource_file.lower() == plugin.lower() + ".xml":
+ # use "name" attribute of "geom-plugin" as name of plugin in a right case
+ from xml.dom.minidom import parse
+ try:
+ xml_doc = parse( os.path.join( resource_dir, resource_file ))
+ plugin_nodes = xml_doc.getElementsByTagName("geom-plugin")
+ except:
+ continue
+ if not plugin_nodes or not plugin_nodes[0].hasAttribute("name"): continue
+ plugin = plugin_nodes[0].getAttribute("name")
+ if plugin in plugin_list: continue
- # add paths of plugin
- plugin_list.append(plugin)
- if not os.environ.has_key("SALOME_"+plugin+"Resources"):
- resource_path = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower())
- os.environ["SALOME_"+plugin+"Resources"] = resource_path
- resource_path_list.append( resource_path )
- add_path(os.path.join(plugin_root,get_lib_dir(),python_version, "site-packages",salome_subdir), "PYTHONPATH")
- add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PYTHONPATH")
+ # add paths of plugin
+ plugin_list.append(plugin)
+ if not os.environ.has_key("SALOME_"+plugin+"Resources"):
+ resource_path = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower())
+ os.environ["SALOME_"+plugin+"Resources"] = resource_path
+ resource_path_list.append( resource_path )
+ add_path(os.path.join(plugin_root,get_lib_dir(),python_version, "site-packages",salome_subdir), "PYTHONPATH")
+ add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PYTHONPATH")
+ if sys.platform == "win32":
+ add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PATH")
+ add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
+ else:
+ add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "LD_LIBRARY_PATH")
+ add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
+ add_path(os.path.join(plugin_root,"bin",salome_subdir), "PATH")
+ pass
+ pass
+ pass
+ elif resource_file == "ImportExport" and plugin.upper() != "GEOM":
+ # add 'ImportExport' plugin file path into variable
+ add_path(resource_dir, plugins_dir_var)
+ # add plugin's library path into environment
if sys.platform == "win32":
add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PATH")
- add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
else:
add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "LD_LIBRARY_PATH")
- add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
- add_path(os.path.join(plugin_root,"bin",salome_subdir), "PATH")
pass
pass
- break
+ pass
plugin_list.append("GEOMActions")
os.environ["GEOM_PluginsList"] = ":".join(plugin_list)
os.environ["SalomeAppConfig"] = os.environ["SalomeAppConfig"] + psep + psep.join(resource_path_list)
+
+ if os.environ.has_key(plugins_dir_var):
+ # reverse back the plugin paths:
+ # [f, e, d, c, b, a] => [a, b, c, d, e, f]
+ plugins_dirs = os.environ[plugins_dir_var].split(os.pathsep)
+ plugins_dirs.reverse()
+ os.environ[plugins_dir_var] = string.join(plugins_dirs, os.pathsep)
+ pass
+ pass
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;
+ // 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);
}
- 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());
+ // 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 {
- aPattern = theFormats->Value(j);
- aPattern += " Files ( *.* )";
+ 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);
}
- thePatterns->Append(aPattern);
}
return (!theFormats->IsEmpty());
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;
+ // 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);
}
- 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());
+ // 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 {
- aPattern = theFormats->Value(j);
- aPattern += " Files ( *.* )";
+ 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);
}
- thePatterns->Append(aPattern);
}
return (!theFormats->IsEmpty());
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 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;
- }
- }
- }
-
// 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()));
-#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;
+ 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;
+ }
}
}
}
//=============================================================================
Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
{
- bool isResourceFound = false;
- bool isResourceFoundUser = false;
- TCollection_AsciiString aUserResDir,aResDir;
+ bool isResourceFound = false;
+ TCollection_AsciiString aNull;
- if (myResMgr.IsNull()) {
- // Initialize the Resource Manager
- TCollection_AsciiString aNull;
- aResDir = TCollection_AsciiString(getenv("GEOM_ROOT_DIR"));
+ myResMgrList.clear();
+
+ // Initialize the GEOM Resource Manager
+ TCollection_AsciiString aResDir = TCollection_AsciiString(getenv("GEOM_ROOT_DIR"));
#ifdef WIN32
- aResDir += "\\share\\salome\\resources\\geom";
+ aResDir += "\\share\\salome\\resources\\geom";
#else
- aResDir += "/share/salome/resources/geom";
+ 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
+ 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;
+ }
- if (myResMgrUser.IsNull()) {
- char * dir = getenv("GEOM_ENGINE_RESOURCES_DIR");
- TCollection_AsciiString aNull;
- if ( dir )
- {
- aUserResDir = dir;
+ // Initialize the user's Resource Manager
+ TCollection_AsciiString 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
- {
- aUserResDir = getenv("HOME");
+ }
+ else
+ {
+ aResDir = getenv("HOME");
#ifdef WIN32
- aUserResDir += "\\.salome\\resources";
+ aResDir += "\\.config\\salome";
#else
- aUserResDir += "/.salome/resources";
+ 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;
}
-
- 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"));
+ return isResourceFound;
}
//=============================================================================