#include <TColStd_HSequenceOfInteger.hxx>
#include <TCollection_AsciiString.hxx>
+#include <LDOMParser.hxx>
#ifdef _DEBUG_
static int MYDEBUG = 0;
}
return isValidName;
}
+
+ //================================================================================
+ /*!
+ * \brief Return Python module names of available plug-ins.
+ */
+ //================================================================================
+
+ std::vector<std::string> getPluginNames()
+ {
+ std::vector<std::string> pluginNames;
+ std::vector< std::string > xmlPaths = SMESH_Gen::GetPluginXMLPaths();
+ LDOMParser xmlParser;
+ for ( size_t i = 0; i < xmlPaths.size(); ++i )
+ {
+ bool error = xmlParser.parse( xmlPaths[i].c_str() );
+ if ( error )
+ {
+ TCollection_AsciiString data;
+ INFOS( xmlParser.GetError(data) );
+ continue;
+ }
+ // <meshers-group name="Standard Meshers"
+ // resources="StdMeshers"
+ // idl-module="StdMeshers"
+ // server-lib="StdMeshersEngine"
+ // gui-lib="StdMeshersGUI">
+ LDOM_Document xmlDoc = xmlParser.getDocument();
+ LDOM_NodeList nodeList = xmlDoc.getElementsByTagName( "meshers-group" );
+ for ( int i = 0; i < nodeList.getLength(); ++i )
+ {
+ LDOM_Node node = nodeList.item( i );
+ LDOM_Element& elem = (LDOM_Element&) node;
+ LDOMString idlModule = elem.getAttribute( "idl-module" );
+ if ( strlen( idlModule.GetString() ) > 0 )
+ pluginNames.push_back( idlModule.GetString() );
+ }
+ }
+ return pluginNames;
+ }
}
//=============================================================================
TCollection_AsciiString aScript;
if( isMultiFile )
aScript += "def RebuildData(theStudy):";
+
aScript += "\n\t";
if ( isPublished )
aScript += aSMESHGen + " = smeshBuilder.New(theStudy)\n\t";
aScript += helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()\n\t";
aScript += helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()\n\t";
- // import python files corresponding to plugins
- set<string> moduleNameSet;
- map<string, GenericHypothesisCreator_i*>::iterator hyp_creator = myHypCreatorMap.begin();
- for ( ; hyp_creator != myHypCreatorMap.end(); ++hyp_creator ) {
- string moduleName = hyp_creator->second->GetModuleName();
- bool newModule = moduleNameSet.insert( moduleName ).second;
- if ( newModule )
- aScript += helper + "\n\t" + "from salome." + (char*) moduleName.c_str() + " import " + (char*) moduleName.c_str() +"Builder";
- }
-
// Dump trace of restored study
if (theSavedTrace.Length() > 0) {
// For the convertion of IDL API calls -> smeshBuilder.py API, "smesh" standing for SMESH_Gen
aScript += helper + "\n" + aNewLines;
}
+ // import python files corresponding to plugins if they are used in aScript
+ {
+ TCollection_AsciiString importStr;
+ std::vector<std::string> pluginNames = getPluginNames();
+ for ( size_t i = 0; i < pluginNames.size(); ++i )
+ {
+ // Convert access to plugin members:
+ // e.g. StdMeshers.QUAD_REDUCED -> StdMeshersBuilder.QUAD_REDUCED
+ TCollection_AsciiString pluginAccess = (pluginNames[i] + ".").c_str() ;
+ int iFrom = 1, iPos;
+ while (( iPos = aScript.Location( pluginAccess, iFrom, aScript.Length() )))
+ {
+ aScript.Insert( iPos + pluginNames[i].size(), "Builder" );
+ iFrom = iPos + pluginNames[i].size() + 8;
+ }
+ // if any plugin member is used, import the plugin
+ if ( iFrom > 1 )
+ importStr += ( helper + "\n\t" + "from salome." + (char*) pluginNames[i].c_str() +
+ " import " + (char*) pluginNames[i].c_str() +"Builder" );
+ }
+ if ( !importStr.IsEmpty() )
+ aScript.Insert( 1, importStr + "\n\t" );
+ }
+
// Convert IDL API calls into smeshBuilder.py API.
// Some objects are wrapped with python classes and
// Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
do {
aName = aBaseName + (++objectCounter);
} while (theObjectNames.IsBound(aName));
- seqRemoved.Append(aName);
+ if ( !aRemovedObjIDs.count( anEntry ))
+ seqRemoved.Append(aName);
mapRemoved.Bind(anEntry, "1");
theObjectNames.Bind(anEntry, aName);
}
anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()";
}
for (int ir = 1; ir <= seqRemoved.Length(); ir++) {
- if ( aRemovedObjIDs.count( seqRemoved.Value(ir) )) continue;
anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(";
anUpdatedScript += seqRemoved.Value(ir);
// for object wrapped by class of smeshBuilder.py
}
// Set object names
- anUpdatedScript += "\n\t## set object names";
-// anUpdatedScript += "\n\t\tsmeshgui = salome.ImportComponentGUI(\"SMESH\")";
-// anUpdatedScript += "\n\t\tsmeshgui.Init(theStudy._get_StudyId())";
-// anUpdatedScript += "\n";
- TCollection_AsciiString aGUIName;
+ TCollection_AsciiString aGUIName, aSetNameScriptPart;
Resource_DataMapOfAsciiStringAsciiString mapEntries;
for (Standard_Integer i = 1; i <= aLen; i += 2)
{
aName = geom->GetDumpName( anEntry.ToCString() );
if (aName.IsEmpty() && // Not a GEOM object
theNames.IsBound(anEntry) &&
- !aRemovedObjIDs.count(anEntry) && // a command creating anEntry was erased
+ !aRemovedObjIDs.count(anEntry) && // A command creating anEntry was erased
!mapEntries.IsBound(anEntry) && // Not yet processed
!mapRemoved.IsBound(anEntry)) // Was not removed
{
aName = theObjectNames.Find(anEntry);
aGUIName = theNames.Find(anEntry);
mapEntries.Bind(anEntry, aName);
- anUpdatedScript += helper + "\n\t" + aSMESHGen + ".SetName(" + aName;
+ aSetNameScriptPart += helper + "\n\t" + aSMESHGen + ".SetName(" + aName;
if ( anEntry2AccessorMethod.IsBound( anEntry ) )
- anUpdatedScript += helper + "." + anEntry2AccessorMethod( anEntry );
- anUpdatedScript += helper + ", '" + aGUIName + "')";
+ aSetNameScriptPart += helper + "." + anEntry2AccessorMethod( anEntry );
+ aSetNameScriptPart += helper + ", '" + aGUIName + "')";
}
}
-
- // Issue 0021249: removed (a similar block is dumped by SALOMEDSImpl_Study)
- //anUpdatedScript += "\n\tif salome.sg.hasDesktop():";
- //anUpdatedScript += "\n\t\tsalome.sg.updateObjBrowser(0)";
+ if ( !aSetNameScriptPart.IsEmpty() )
+ {
+ anUpdatedScript += "\n\t## set object names";
+ anUpdatedScript += aSetNameScriptPart;
+ }
// -----------------------------------------------------------------
// store visual properties of displayed objects