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
#
import os, sys
import os, sys, string
from salome_utils import getTmpDir, generateFileName, uniteFiles
from setenv import add_path, get_lib_dir, salome_subdir
@ -50,6 +50,14 @@ def set_env( args ):
# 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:
@ -60,13 +68,15 @@ def set_env( args ):
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
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
@ -89,7 +99,27 @@ def set_env( args ):
add_path(os.path.join(plugin_root,"bin",salome_subdir), "PATH")
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")
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

View File

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

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

@ -392,26 +392,20 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
if (!InitResMgr()) return Standard_False;
// Read Import formats list from install directory
if (myResMgr->Find("Import")) {
TCollection_AsciiString aFormats (myResMgr->Value("Import"));
// 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);
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)) {
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){
if( theFormats->Value(aInd) == aToken ){
isFound = true;
break;
}
@ -422,20 +416,15 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
}
// Read Patterns for each supported format
int j = 1, len = theFormats->Length();
for (; j <= len; j++) {
for (int j = anOldLen+1; j <= theFormats->Length(); 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());
if (aResMgr->Find(aKey.ToCString()))
aPattern = aResMgr->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());
if (aResMgr->Find(aKey.ToCString()))
aPattern = aResMgr->Value(aKey.ToCString());
else {
aPattern = theFormats->Value(j);
aPattern += " Files ( *.* )";
@ -443,6 +432,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
}
thePatterns->Append(aPattern);
}
}
return (!theFormats->IsEmpty());
}
@ -468,22 +458,15 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
if (!InitResMgr()) return Standard_False;
// Read Export formats list from install directory
if (myResMgr->Find("Export")) {
TCollection_AsciiString aFormats (myResMgr->Value("Export"));
// 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);
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)) {
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++){
@ -498,20 +481,15 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
}
// Read Patterns for each supported format
int j = 1, len = theFormats->Length();
for (; j <= len; j++) {
for (int j = anOldLen+1; j <= theFormats->Length(); 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());
if (aResMgr->Find(aKey.ToCString()))
aPattern = aResMgr->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());
if (aResMgr->Find(aKey.ToCString()))
aPattern = aResMgr->Value(aKey.ToCString());
else {
aPattern = theFormats->Value(j);
aPattern += " Files ( *.* )";
@ -519,6 +497,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
}
thePatterns->Append(aPattern);
}
}
return (!theFormats->IsEmpty());
}
@ -541,51 +520,32 @@ 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()));
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()));
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 (myResMgrUser->Find(aKey.ToCString())) {
TCollection_AsciiString aLibName (myResMgrUser->Value(aKey.ToCString()));
#ifndef WIN32
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
#else
aLibName += ".dll";
#endif
#endif
theLibName = new TCollection_HAsciiString (aLibName);
return Standard_True;
}
}
}
}
return Standard_False;
}
@ -598,66 +558,55 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
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"));
myResMgrList.clear();
// Initialize the GEOM Resource Manager
TCollection_AsciiString aResDir = TCollection_AsciiString(getenv("GEOM_ROOT_DIR"));
#ifdef WIN32
aResDir += "\\share\\salome\\resources\\geom";
#else
aResDir += "/share/salome/resources/geom";
#endif
myResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False);
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 (!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 )
// Initialize the user's Resource Manager
TCollection_AsciiString aResDirsStr = getenv("GEOM_ENGINE_RESOURCES_DIR");
if ( !aResDirsStr.IsEmpty() )
{
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
{
aUserResDir = getenv("HOME");
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;
}
//=============================================================================

View File

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