Enhancement of mechanism of automatic searching of GEOM plugins to catch Import/Export ones too.

This commit is contained in:
akl 2014-03-05 14:42:58 +04:00
parent 63d63ea8af
commit 37e494a62c
4 changed files with 194 additions and 220 deletions

View File

@ -19,7 +19,7 @@
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # 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 salome_utils import getTmpDir, generateFileName, uniteFiles
from setenv import add_path, get_lib_dir, salome_subdir from setenv import add_path, get_lib_dir, salome_subdir
@ -50,6 +50,14 @@ def set_env( args ):
# find plugins # find plugins
plugin_list = [] plugin_list = []
resource_path_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(): for env_var in os.environ.keys():
value = os.environ[env_var] value = os.environ[env_var]
if env_var[-9:] == "_ROOT_DIR" and value: if env_var[-9:] == "_ROOT_DIR" and value:
@ -60,13 +68,15 @@ def set_env( args ):
resource_dir = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower()) resource_dir = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower())
if not os.access( resource_dir, os.F_OK ): continue if not os.access( resource_dir, os.F_OK ): continue
for resource_file in os.listdir( resource_dir ): for resource_file in os.listdir( resource_dir ):
if not resource_file.endswith( ".xml") or \ if resource_file.endswith( ".xml") and \
resource_file.lower() != plugin.lower() + ".xml": resource_file.lower() == plugin.lower() + ".xml":
continue
# use "name" attribute of "geom-plugin" as name of plugin in a right case # use "name" attribute of "geom-plugin" as name of plugin in a right case
from xml.dom.minidom import parse from xml.dom.minidom import parse
try:
xml_doc = parse( os.path.join( resource_dir, resource_file )) xml_doc = parse( os.path.join( resource_dir, resource_file ))
plugin_nodes = xml_doc.getElementsByTagName("geom-plugin") plugin_nodes = xml_doc.getElementsByTagName("geom-plugin")
except:
continue
if not plugin_nodes or not plugin_nodes[0].hasAttribute("name"): continue if not plugin_nodes or not plugin_nodes[0].hasAttribute("name"): continue
plugin = plugin_nodes[0].getAttribute("name") plugin = plugin_nodes[0].getAttribute("name")
if plugin in plugin_list: continue if plugin in plugin_list: continue
@ -89,7 +99,27 @@ def set_env( args ):
add_path(os.path.join(plugin_root,"bin",salome_subdir), "PATH") add_path(os.path.join(plugin_root,"bin",salome_subdir), "PATH")
pass pass
pass pass
break 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")
else:
add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "LD_LIBRARY_PATH")
pass
pass
pass
plugin_list.append("GEOMActions") plugin_list.append("GEOMActions")
os.environ["GEOM_PluginsList"] = ":".join(plugin_list) os.environ["GEOM_PluginsList"] = ":".join(plugin_list)
os.environ["SalomeAppConfig"] = os.environ["SalomeAppConfig"] + psep + psep.join(resource_path_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

View File

@ -1,5 +1,5 @@
Import: BREP|IGES|STEP|STL|ACIS Import: BREP|IGES|STEP|STL
Export: BREP|IGES|IGES_5_3|STEP|STL_Bin|STL_ASCII|ACIS|VTK Export: BREP|IGES|IGES_5_3|STEP|STL_Bin|STL_ASCII|VTK
BREP.Import: BREPImport BREP.Import: BREPImport
BREP.Export: BREPExport BREP.Export: BREPExport
@ -26,9 +26,5 @@ STL_Bin.Pattern: STL Binary Files ( *.stl )
STL_ASCII.Export: STLExport STL_ASCII.Export: STLExport
STL_ASCII.Pattern: STL ASCII Files ( *.stl ) STL_ASCII.Pattern: STL ASCII Files ( *.stl )
ACIS.Import: ACISImport
ACIS.Export: ACISExport
ACIS.Pattern: ACIS Files ( *.sat )
VTK.Export: VTKExport VTK.Export: VTKExport
VTK.Pattern: VTK Files ( *.vtk ) VTK.Pattern: VTK Files ( *.vtk )

187
src/GEOMImpl/GEOMImpl_IInsertOperations.cxx Normal file → Executable file
View File

@ -392,22 +392,16 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
if (!InitResMgr()) return Standard_False; if (!InitResMgr()) return Standard_False;
// Read Import formats list from install directory // Read Import formats from directories
if (myResMgr->Find("Import")) { Handle(Resource_Manager) aResMgr;
TCollection_AsciiString aFormats (myResMgr->Value("Import")); 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); TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
int i = 1; for (int i = 1; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
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(); int aLenFormats = theFormats->Length();
bool isFound = false; bool isFound = false;
for(int aInd=1;aInd<=aLenFormats;aInd++){ for(int aInd=1;aInd<=aLenFormats;aInd++){
@ -422,20 +416,15 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
} }
// Read Patterns for each supported format // Read Patterns for each supported format
int j = 1, len = theFormats->Length(); for (int j = anOldLen+1; j <= theFormats->Length(); j++) {
for (; j <= len; j++) {
TCollection_AsciiString aKey, aPattern; TCollection_AsciiString aKey, aPattern;
aKey = theFormats->Value(j) + ".ImportPattern"; aKey = theFormats->Value(j) + ".ImportPattern";
if (myResMgr->Find(aKey.ToCString())) if (aResMgr->Find(aKey.ToCString()))
aPattern = myResMgr->Value(aKey.ToCString()); aPattern = aResMgr->Value(aKey.ToCString());
else if(myResMgrUser->Find(aKey.ToCString()))
aPattern = myResMgrUser->Value(aKey.ToCString());
else { else {
aKey = theFormats->Value(j) + ".Pattern"; aKey = theFormats->Value(j) + ".Pattern";
if (myResMgr->Find(aKey.ToCString())) if (aResMgr->Find(aKey.ToCString()))
aPattern = myResMgr->Value(aKey.ToCString()); aPattern = aResMgr->Value(aKey.ToCString());
else if(myResMgrUser->Find(aKey.ToCString()))
aPattern = myResMgrUser->Value(aKey.ToCString());
else { else {
aPattern = theFormats->Value(j); aPattern = theFormats->Value(j);
aPattern += " Files ( *.* )"; aPattern += " Files ( *.* )";
@ -443,6 +432,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
} }
thePatterns->Append(aPattern); thePatterns->Append(aPattern);
} }
}
return (!theFormats->IsEmpty()); return (!theFormats->IsEmpty());
} }
@ -468,22 +458,15 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
if (!InitResMgr()) return Standard_False; if (!InitResMgr()) return Standard_False;
// Read Export formats list from install directory // Read Export formats list from directories
if (myResMgr->Find("Export")) { Handle(Resource_Manager) aResMgr;
TCollection_AsciiString aFormats (myResMgr->Value("Export")); 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); TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
int i = 1; for (int i = 1; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
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(); int aLenFormats = theFormats->Length();
bool isFound = false; bool isFound = false;
for(int aInd=1;aInd<=aLenFormats;aInd++){ for(int aInd=1;aInd<=aLenFormats;aInd++){
@ -498,20 +481,15 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
} }
// Read Patterns for each supported format // Read Patterns for each supported format
int j = 1, len = theFormats->Length(); for (int j = anOldLen+1; j <= theFormats->Length(); j++) {
for (; j <= len; j++) {
TCollection_AsciiString aKey, aPattern; TCollection_AsciiString aKey, aPattern;
aKey = theFormats->Value(j) + ".ExportPattern"; aKey = theFormats->Value(j) + ".ExportPattern";
if (myResMgr->Find(aKey.ToCString())) if (aResMgr->Find(aKey.ToCString()))
aPattern = myResMgr->Value(aKey.ToCString()); aPattern = aResMgr->Value(aKey.ToCString());
else if (myResMgrUser->Find(aKey.ToCString()))
aPattern = myResMgrUser->Value(aKey.ToCString());
else { else {
aKey = theFormats->Value(j) + ".Pattern"; aKey = theFormats->Value(j) + ".Pattern";
if (myResMgr->Find(aKey.ToCString())) if (aResMgr->Find(aKey.ToCString()))
aPattern = myResMgr->Value(aKey.ToCString()); aPattern = aResMgr->Value(aKey.ToCString());
else if (myResMgrUser->Find(aKey.ToCString()))
aPattern = myResMgrUser->Value(aKey.ToCString());
else { else {
aPattern = theFormats->Value(j); aPattern = theFormats->Value(j);
aPattern += " Files ( *.* )"; aPattern += " Files ( *.* )";
@ -519,6 +497,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
} }
thePatterns->Append(aPattern); thePatterns->Append(aPattern);
} }
}
return (!theFormats->IsEmpty()); return (!theFormats->IsEmpty());
} }
@ -541,39 +520,19 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
if (isImport) aMode = "Import"; if (isImport) aMode = "Import";
else aMode = "Export"; 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 // Read supported formats for the certain mode from user directory
if (myResMgrUser->Find(aMode.ToCString())) { Handle(Resource_Manager) aResMgr;
TCollection_AsciiString aFormats (myResMgrUser->Value(aMode.ToCString())); 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) { if (aFormats.Search(theFormat) > -1) {
// Read library name for the supported format // Read library name for the supported format
TCollection_AsciiString aKey (theFormat); TCollection_AsciiString aKey (theFormat);
aKey += "."; aKey += ".";
aKey += aMode; aKey += aMode;
if (myResMgrUser->Find(aKey.ToCString())) { if (aResMgr->Find(aKey.ToCString())) {
TCollection_AsciiString aLibName (myResMgrUser->Value(aKey.ToCString())); TCollection_AsciiString aLibName (aResMgr->Value(aKey.ToCString()));
#ifndef WIN32 #ifndef WIN32
if ( aLibName.Length() > 3 && aLibName.SubString(1,3) != "lib" ) if ( aLibName.Length() > 3 && aLibName.SubString(1,3) != "lib" )
aLibName.Prepend("lib"); aLibName.Prepend("lib");
@ -586,6 +545,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
} }
} }
} }
}
return Standard_False; return Standard_False;
} }
@ -598,66 +558,55 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr() Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
{ {
bool isResourceFound = false; bool isResourceFound = false;
bool isResourceFoundUser = false;
TCollection_AsciiString aUserResDir,aResDir;
if (myResMgr.IsNull()) {
// Initialize the Resource Manager
TCollection_AsciiString aNull; 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 #ifdef WIN32
aResDir += "\\share\\salome\\resources\\geom"; aResDir += "\\share\\salome\\resources\\geom";
#else #else
aResDir += "/share/salome/resources/geom"; aResDir += "/share/salome/resources/geom";
#endif #endif
Handle(Resource_Manager) aGeomResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False);
myResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False); if ( aGeomResMgr->Find("Import") || aGeomResMgr->Find("Export") ) {
myResMgrList.push_back( aGeomResMgr );
isResourceFound = true; 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()) { // Initialize the user's Resource Manager
char * dir = getenv("GEOM_ENGINE_RESOURCES_DIR"); TCollection_AsciiString aResDirsStr = getenv("GEOM_ENGINE_RESOURCES_DIR");
TCollection_AsciiString aNull; if ( !aResDirsStr.IsEmpty() )
if ( dir )
{ {
aUserResDir = dir; 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 else
{ {
aUserResDir = getenv("HOME"); aResDir = getenv("HOME");
#ifdef WIN32 #ifdef WIN32
aUserResDir += "\\.salome\\resources"; aResDir += "\\.config\\salome";
#else #else
aUserResDir += "/.salome/resources"; aResDir += "/.config/salome";
#endif #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;
} }
return isResourceFound;
} 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"));
} }
//============================================================================= //=============================================================================

View File

@ -143,8 +143,7 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
const NCollection_List<TopoDS_Shape> &theShapes); const NCollection_List<TopoDS_Shape> &theShapes);
private: private:
Handle(Resource_Manager) myResMgr; std::vector<Handle(Resource_Manager)> myResMgrList;
Handle(Resource_Manager) myResMgrUser;
GEOMImpl_IShapesOperations* myShapesOperations; GEOMImpl_IShapesOperations* myShapesOperations;
GEOMImpl_IGroupOperations* myGroupOperations; GEOMImpl_IGroupOperations* myGroupOperations;
GEOMImpl_IFieldOperations* myFieldOperations; GEOMImpl_IFieldOperations* myFieldOperations;