Back to index

salome-smesh  6.5.0
Public Member Functions | Private Attributes
_pyHypothesisReader Class Reference

Class reading _pyHypothesis'es from resource files of mesher Plugins. More...

#include <SMESH_2smeshpy.hxx>

Collaboration diagram for _pyHypothesisReader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 _pyHypothesisReader ()
 Reads _pyHypothesis'es from resource files of mesher Plugins.
 Handle (_pyHypothesis) GetHypothesis(const _AString &hypType
const Handle (_pyCommand)&creationCmd) const

Private Attributes

std::map< _AString, Handle(_pyHypothesis)> myType2Hyp

Detailed Description

Class reading _pyHypothesis'es from resource files of mesher Plugins.

Definition at line 597 of file SMESH_2smeshpy.hxx.


Constructor & Destructor Documentation

Reads _pyHypothesis'es from resource files of mesher Plugins.

Definition at line 3935 of file SMESH_2smeshpy.cxx.

{
  // Get paths to xml files of plugins
  vector< string > xmlPaths;
  string sep;
  if ( const char* meshersList = getenv("SMESH_MeshersList") )
  {
    string meshers = meshersList, plugin;
    string::size_type from = 0, pos;
    while ( from < meshers.size() )
    {
      // cut off plugin name
      pos = meshers.find( ':', from );
      if ( pos != string::npos )
        plugin = meshers.substr( from, pos-from );
      else
        plugin = meshers.substr( from ), pos = meshers.size();
      from = pos + 1;

      // get PLUGIN_ROOT_DIR path
      string rootDirVar, pluginSubDir = plugin;
      if ( plugin == "StdMeshers" )
        rootDirVar = "SMESH", pluginSubDir = "smesh";
      else
        for ( pos = 0; pos < plugin.size(); ++pos )
          rootDirVar += toupper( plugin[pos] );
      rootDirVar += "_ROOT_DIR";

      const char* rootDir = getenv( rootDirVar.c_str() );
      if ( !rootDir || strlen(rootDir) == 0 )
      {
        rootDirVar = plugin + "_ROOT_DIR"; // HexoticPLUGIN_ROOT_DIR
        rootDir = getenv( rootDirVar.c_str() );
        if ( !rootDir || strlen(rootDir) == 0 ) continue;
      }

      // get a separator from rootDir
      for ( pos = strlen( rootDir )-1; pos >= 0 && sep.empty(); --pos )
        if ( rootDir[pos] == '/' || rootDir[pos] == '\\' )
        {
          sep = rootDir[pos];
          break;
        }
#ifdef WNT
      if (sep.empty() ) sep = "\\";
#else
      if (sep.empty() ) sep = "/";
#endif

      // get a path to resource file
      string xmlPath = rootDir;
      if ( xmlPath[ xmlPath.size()-1 ] != sep[0] )
        xmlPath += sep;
      xmlPath += "share" + sep + "salome" + sep + "resources" + sep;
      for ( pos = 0; pos < pluginSubDir.size(); ++pos )
        xmlPath += tolower( pluginSubDir[pos] );
      xmlPath += sep + plugin + ".xml";
      bool fileOK;
#ifdef WNT
      fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES);
#else
      fileOK = (access(xmlPath.c_str(), F_OK) == 0);
#endif
      if ( fileOK )
        xmlPaths.push_back( xmlPath );
    }
  }

  // Read xml files
  LDOMParser xmlParser;
  for ( size_t i = 0; i < xmlPaths.size(); ++i )
  {
    bool error = xmlParser.parse( xmlPaths[i].c_str() );
    if ( error )
    {
      _AString data;
      INFOS( xmlParser.GetError(data) );
      continue;
    }
    // <algorithm type="Regular_1D"
    //            label-id="Wire discretisation"
    //            ...>
    //   <python-wrap>
    //     <algo>Regular_1D=Segment()</algo>
    //     <hypo>LocalLength=LocalLength(SetLength(1),,SetPrecision(1))</hypo>
    //
    LDOM_Document xmlDoc = xmlParser.getDocument();
    LDOM_NodeList algoNodeList = xmlDoc.getElementsByTagName( "algorithm" );
    for ( int i = 0; i < algoNodeList.getLength(); ++i )
    {
      LDOM_Node algoNode = algoNodeList.item( i );
      LDOM_Element& algoElem = (LDOM_Element&) algoNode;
      LDOM_NodeList pyAlgoNodeList = algoElem.getElementsByTagName( "algo" );
      if ( pyAlgoNodeList.getLength() < 1 ) continue;

      _AString text, algoType, method, arg;
      for ( int iA = 0; iA < pyAlgoNodeList.getLength(); ++iA )
      {
        LDOM_Node pyAlgoNode = pyAlgoNodeList.item( iA );
        LDOM_Node textNode   = pyAlgoNode.getFirstChild();
        text = textNode.getNodeValue();
        Handle(_pyCommand) algoCmd = new _pyCommand( text );
        algoType = algoCmd->GetResultValue();
        method   = algoCmd->GetMethod();
        arg      = algoCmd->GetArg(1);
        if ( !algoType.IsEmpty() && !method.IsEmpty() )
        {
          Handle(_pyAlgorithm) algo = new _pyAlgorithm( algoCmd );
          algo->SetConvMethodAndType( method, algoType );
          if ( !arg.IsEmpty() )
            algo->setCreationArg( 1, arg );

          myType2Hyp[ algoType ] = algo;
          break;
        }
      }
      if ( algoType.IsEmpty() ) continue;

      LDOM_NodeList pyHypoNodeList = algoElem.getElementsByTagName( "hypo" );
      _AString hypType;
      Handle( _pyHypothesis ) hyp;
      for ( int iH = 0; iH < pyHypoNodeList.getLength(); ++iH )
      {
        LDOM_Node pyHypoNode = pyHypoNodeList.item( iH );
        LDOM_Node textNode   = pyHypoNode.getFirstChild();
        text = textNode.getNodeValue();
        Handle(_pyCommand) hypoCmd = new _pyCommand( text );
        hypType = hypoCmd->GetResultValue();
        method  = hypoCmd->GetMethod();
        if ( !hypType.IsEmpty() && !method.IsEmpty() )
        {
          map<_AString, Handle(_pyHypothesis)>::iterator type2hyp = myType2Hyp.find( hypType );
          if ( type2hyp == myType2Hyp.end() )
            hyp = new _pyHypothesis( hypoCmd );
          else
            hyp = type2hyp->second;
          hyp->SetConvMethodAndType( method, algoType );
          for ( int iArg = 1; iArg <= hypoCmd->GetNbArgs(); ++iArg )
          {
            _pyCommand argCmd( hypoCmd->GetArg( iArg ));
            _AString argMethod = argCmd.GetMethod();
            _AString argNbText = argCmd.GetArg( 1 );
            if ( argMethod.IsEmpty() && !argCmd.IsEmpty() )
              hyp->setCreationArg( 1, argCmd.GetString() ); // e.g. Parameters(smesh.SIMPLE)
            else
              hyp->AddArgMethod( argMethod,
                                 argNbText.IsIntegerValue() ? argNbText.IntegerValue() : 1 );
          }
          myType2Hyp[ hypType ] = hyp;
        }
      }
    }
  }
}

Here is the call graph for this function:


Member Function Documentation

Here is the caller graph for this function:


Member Data Documentation

Definition at line 599 of file SMESH_2smeshpy.hxx.


The documentation for this class was generated from the following files: