Back to index

salome-smesh  6.5.0
Functions | Variables
SMESH_2smeshpy.cxx File Reference
#include "SMESH_2smeshpy.hxx"
#include "utilities.h"
#include "SMESH_PythonDump.hxx"
#include "SMESH_NoteBook.hxx"
#include "SMESH_Filter_i.hxx"
#include <Resource_DataMapOfAsciiStringAsciiString.hxx>
#include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
#include "SMESH_Gen_i.hxx"
#include <LDOMParser.hxx>
#include <unistd.h>

Go to the source code of this file.

Functions

 IMPLEMENT_STANDARD_HANDLE (_pyObject, Standard_Transient)
 IMPLEMENT_STANDARD_HANDLE (_pyCommand, Standard_Transient)
 IMPLEMENT_STANDARD_HANDLE (_pyHypothesisReader, Standard_Transient)
 IMPLEMENT_STANDARD_HANDLE (_pyGen, _pyObject)
 IMPLEMENT_STANDARD_HANDLE (_pyMesh, _pyObject)
 IMPLEMENT_STANDARD_HANDLE (_pySubMesh, _pyObject)
 IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor, _pyObject)
 IMPLEMENT_STANDARD_HANDLE (_pyHypothesis, _pyObject)
 IMPLEMENT_STANDARD_HANDLE (_pySelfEraser, _pyObject)
 IMPLEMENT_STANDARD_HANDLE (_pyGroup, _pyObject)
 IMPLEMENT_STANDARD_HANDLE (_pyFilter, _pyObject)
 IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm, _pyHypothesis)
 IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis)
 IMPLEMENT_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis)
 IMPLEMENT_STANDARD_RTTIEXT (_pyObject, Standard_Transient)
 IMPLEMENT_STANDARD_RTTIEXT (_pyCommand, Standard_Transient)
 IMPLEMENT_STANDARD_RTTIEXT (_pyHypothesisReader, Standard_Transient)
 IMPLEMENT_STANDARD_RTTIEXT (_pyGen, _pyObject)
 IMPLEMENT_STANDARD_RTTIEXT (_pyMesh, _pyObject)
 IMPLEMENT_STANDARD_RTTIEXT (_pySubMesh, _pyObject)
 IMPLEMENT_STANDARD_RTTIEXT (_pyMeshEditor, _pyObject)
 IMPLEMENT_STANDARD_RTTIEXT (_pyHypothesis, _pyObject)
 IMPLEMENT_STANDARD_RTTIEXT (_pySelfEraser, _pyObject)
 IMPLEMENT_STANDARD_RTTIEXT (_pyGroup, _pyObject)
 IMPLEMENT_STANDARD_RTTIEXT (_pyFilter, _pyObject)
 IMPLEMENT_STANDARD_RTTIEXT (_pyAlgorithm, _pyHypothesis)
 IMPLEMENT_STANDARD_RTTIEXT (_pyComplexParamHypo, _pyHypothesis)
 IMPLEMENT_STANDARD_RTTIEXT (_pyNumberOfSegmentsHyp, _pyHypothesis)
 IMPLEMENT_STANDARD_RTTIEXT (_pyLayerDistributionHypo, _pyHypothesis)
 IMPLEMENT_STANDARD_RTTIEXT (_pySegmentLengthAroundVertexHyp, _pyHypothesis)
static Handle (_pyGen) theGen
 Container of commands into which the initial script is split.
 Handle (_pyCommand) _pyGen
 Convert a command using a specific converter.
 Handle (_pyHypothesis) _pyGen
 Find hypothesis by ID (entry)
 Handle (_pySubMesh) _pyGen
 Find subMesh by ID (entry)
 Handle (_pyObject) _pyGen
 Finds a _pyObject by ID.
 Handle (_pyHypothesisReader) _pyGen
 Return reader of hypotheses of plugins.
static bool isWord (const char c, const bool dotIsWord)
 Check if char is a word part.

Variables

static TCollection_AsciiString theEmptyString

Function Documentation

static Handle ( _pyGen  ) [static]

Container of commands into which the initial script is split.

It also contains data coresponding to SMESH_Gen contents

Convert a command using a specific converter.

Set command be last in list of commands.

Parameters:
theCommand- the command to convert
theCmd- Command to be last

Definition at line 444 of file SMESH_2smeshpy.cxx.

{
  // store theCommand in the sequence
  myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands ));

  Handle(_pyCommand) aCommand = myCommands.back();
#ifdef DUMP_CONVERSION
  MESSAGE ( "## COM " << myNbCommands << ": "<< aCommand->GetString() );
#endif

  const _pyID& objID = aCommand->GetObject();

  if ( objID.IsEmpty() )
    return aCommand;

  // Find an object to process theCommand

  // SMESH_Gen method?
  if ( objID == this->GetID() || objID == SMESH_2smeshpy::GenName())
  {
    this->Process( aCommand );
    return aCommand;
  }

  // SMESH_Mesh method?
  map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
  if ( id_mesh != myMeshes.end() )
  {
    //id_mesh->second->AddProcessedCmd( aCommand );

    // check for mesh editor object
    if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
      _pyID editorID = aCommand->GetResultValue();
      Handle(_pyMeshEditor) editor = new _pyMeshEditor( aCommand );
      myMeshEditors.insert( make_pair( editorID, editor ));
      return aCommand;
    }
    // check for SubMesh objects
    else if ( aCommand->GetMethod() == "GetSubMesh" ) { // SubMesh creation
      _pyID subMeshID = aCommand->GetResultValue();
      Handle(_pySubMesh) subMesh = new _pySubMesh( aCommand );
      myObjects.insert( make_pair( subMeshID, subMesh ));
    }

    id_mesh->second->Process( aCommand );
    id_mesh->second->AddProcessedCmd( aCommand );
    return aCommand;
  }

  // SMESH_MeshEditor method?
  map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
  if ( id_editor != myMeshEditors.end() )
  {
    const TCollection_AsciiString& method = aCommand->GetMethod();

    // some commands of SMESH_MeshEditor create meshes and groups
    _pyID meshID, groups;
    if ( method.Search("MakeMesh") != -1 )
      meshID = aCommand->GetResultValue();
    else if ( method == "MakeBoundaryMesh")
      meshID = aCommand->GetResultValue(1);
    else if ( method == "MakeBoundaryElements")
      meshID = aCommand->GetResultValue(2);

    if ( method.Search("MakeGroups") != -1  ||
         method == "ExtrusionAlongPathX"    ||
         method == "ExtrusionAlongPathObjX" ||
         method == "DoubleNodeGroupNew"     ||
         method == "DoubleNodeGroupsNew"    ||
         method == "DoubleNodeElemGroupNew" ||
         method == "DoubleNodeElemGroupsNew"||
         method == "DoubleNodeElemGroup2New"||
         method == "DoubleNodeElemGroups2New"
         )
      groups = aCommand->GetResultValue();
    else if ( method == "MakeBoundaryMesh" )
      groups = aCommand->GetResultValue(2);
    else if ( method == "MakeBoundaryElements")
      groups = aCommand->GetResultValue(3);

    id_editor->second->Process( aCommand );
    id_editor->second->AddProcessedCmd( aCommand );

    if ( !meshID.IsEmpty() &&
         !myMeshes.count( meshID ) &&
         aCommand->IsStudyEntry( meshID ))
    {
      TCollection_AsciiString processedCommand = aCommand->GetString();
      Handle(_pyMesh) mesh = new _pyMesh( aCommand, meshID );
      myMeshes.insert( make_pair( meshID, mesh ));
      aCommand->Clear();
      aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
    }
    if ( !groups.IsEmpty() )
    {
      if ( !aCommand->IsStudyEntry( meshID ))
        meshID = id_editor->second->GetMesh();
      Handle(_pyMesh) mesh = myMeshes[ meshID ];

      list< _pyID > idList = aCommand->GetStudyEntries( groups );
      list< _pyID >::iterator grID = idList.begin();
      for ( ; grID != idList.end(); ++grID )
        if ( !myObjects.count( *grID ))
        {
          Handle(_pyGroup) group = new _pyGroup( aCommand, *grID );
          AddObject( group );
          if ( !mesh.IsNull() ) mesh->AddGroup( group );
        }
    }
    return aCommand;
  } // SMESH_MeshEditor methods

  // SMESH_Hypothesis method?
  list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
  for ( ; hyp != myHypos.end(); ++hyp )
    if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) {
      (*hyp)->Process( aCommand );
      (*hyp)->AddProcessedCmd( aCommand );
      return aCommand;
    }

  // aFilterManager.CreateFilter() ?
  if ( aCommand->GetMethod() == "CreateFilter" )
  {
    // Set a more human readable name to a filter
    // aFilter0x7fbf6c71cfb0 -> aFilter_nb
    _pyID newID, filterID = aCommand->GetResultValue();
    int pos = filterID.Search( "0x" );
    if ( pos > 1 )
      newID = (filterID.SubString(1,pos-1) + "_") + _pyID( ++myNbFilters );

    Handle(_pyObject) filter( new _pyFilter( aCommand, newID ));
    AddObject( filter );
  }

  // other object method?
  map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.find( objID );
  if ( id_obj != myObjects.end() ) {
    id_obj->second->Process( aCommand );
    id_obj->second->AddProcessedCmd( aCommand );
    return aCommand;
  }

  // Add access to a wrapped mesh
  AddMeshAccessorMethod( aCommand );

  // Add access to a wrapped algorithm
  //  AddAlgoAccessorMethod( aCommand ); // ??? what if algo won't be wrapped at all ???

  // PAL12227. PythonDump was not updated at proper time; result is
  //     aCriteria.append(SMESH.Filter.Criterion(17,26,0,'L1',26,25,1e-07,SMESH.EDGE,-1))
  // TypeError: __init__() takes exactly 11 arguments (10 given)
  const char wrongCommand[] = "SMESH.Filter.Criterion(";
  if ( int beg = theCommand.Location( wrongCommand, 1, theCommand.Length() ))
  {
    _pyCommand tmpCmd( theCommand.SubString( beg, theCommand.Length() ), -1);
    // there must be 10 arguments, 5-th arg ThresholdID is missing,
    const int wrongNbArgs = 9, missingArg = 5;
    if ( tmpCmd.GetNbArgs() == wrongNbArgs )
    {
      for ( int i = wrongNbArgs; i > missingArg; --i )
        tmpCmd.SetArg( i + 1, tmpCmd.GetArg( i ));
      tmpCmd.SetArg(  missingArg, "''");
      aCommand->GetString().Trunc( beg - 1 );
      aCommand->GetString() += tmpCmd.GetString();
    }
    // IMP issue 0021014
    // set GetCriterion(elementType,CritType,Compare,Treshold,UnaryOp,BinaryOp,Tolerance)
    //                  1           2        3       4        5       6        7
    // instead of "SMESH.Filter.Criterion(
    // Type,Compare,Threshold,ThresholdStr,ThresholdID,UnaryOp,BinaryOp,Tolerance,TypeOfElement,Precision)
    // 1    2       3         4            5           6       7        8         9             10
    // in order to avoid the problem of type mismatch of long and FunctorType
    const TCollection_AsciiString
      SMESH("SMESH."), dfltFunctor = "SMESH.FT_Undefined", dftlTol = "1e-07", dftlPreci = "-1";
    TCollection_AsciiString
      Type          = aCommand->GetArg(1),  // long
      Compare       = aCommand->GetArg(2),  // long
      Threshold     = aCommand->GetArg(3),  // double
      ThresholdStr  = aCommand->GetArg(4),  // string
      ThresholdID   = aCommand->GetArg(5),  // string
      UnaryOp       = aCommand->GetArg(6),  // long
      BinaryOp      = aCommand->GetArg(7),  // long
      Tolerance     = aCommand->GetArg(8),  // double
      TypeOfElement = aCommand->GetArg(9),  // ElementType
      Precision     = aCommand->GetArg(10); // long
    fixFunctorType( Type, Compare, UnaryOp, BinaryOp );
    Type     = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( Type.IntegerValue() ));
    Compare  = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( Compare.IntegerValue() ));
    UnaryOp  = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( UnaryOp.IntegerValue() ));
    BinaryOp = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( BinaryOp.IntegerValue() ));

    aCommand->RemoveArgs();
    aCommand->SetObject( SMESH_2smeshpy::GenName() );
    aCommand->SetMethod( "GetCriterion" );

    aCommand->SetArg( 1, TypeOfElement );
    aCommand->SetArg( 2, Type );
    aCommand->SetArg( 3, Compare );

    if ( Type == "SMESH.FT_ElemGeomType" && Threshold.IsIntegerValue() )
    {
      // set SMESH.GeometryType instead of a numerical Threshold
      const char* types[SMESH::Geom_POLYHEDRA+1] = {
        "Geom_POINT", "Geom_EDGE", "Geom_TRIANGLE", "Geom_QUADRANGLE", "Geom_POLYGON",
        "Geom_TETRA", "Geom_PYRAMID", "Geom_HEXA", "Geom_PENTA", "Geom_HEXAGONAL_PRISM",
        "Geom_POLYHEDRA"
      };
      int iGeom = Threshold.IntegerValue();
      if ( -1 < iGeom && iGeom < SMESH::Geom_POLYHEDRA+1 )
        Threshold = SMESH + types[ iGeom ];
    }
    if ( ThresholdID.Length() != 2 && ThresholdStr.Length() != 2) // not '' or ""
      aCommand->SetArg( 4, ThresholdID.SubString( 2, ThresholdID.Length()-1 )); // shape entry
    else if ( ThresholdStr.Length() != 2 )
      aCommand->SetArg( 4, ThresholdStr );
    else if ( ThresholdID.Length() != 2 )
      aCommand->SetArg( 4, ThresholdID );
    else
      aCommand->SetArg( 4, Threshold );
    // find the last not default arg
    int lastDefault = 8;
    if ( Tolerance == dftlTol ) {
      lastDefault = 7;
      if ( BinaryOp == dfltFunctor ) {
        lastDefault = 6;
        if ( UnaryOp == dfltFunctor )
          lastDefault = 5;
      }
    }
    if ( 5 < lastDefault ) aCommand->SetArg( 5, UnaryOp );
    if ( 6 < lastDefault ) aCommand->SetArg( 6, BinaryOp );
    if ( 7 < lastDefault ) aCommand->SetArg( 7, Tolerance );
    if ( Precision != dftlPreci )
    {
      TCollection_AsciiString crit = aCommand->GetResultValue();
      aCommand->GetString() += "; ";
      aCommand->GetString() += crit + ".Precision = " + Precision;
    }
  }
  return aCommand;
}

Here is the call graph for this function:

Find hypothesis by ID (entry)

Returns a new hypothesis initialized according to the read information.

Creates algorithm or hypothesis.

Find algorithm the created algorithm.

Parameters:
theHypID- The hypothesis ID
Return values:
Handle(_pyHypothesis)- The found hypothesis
Parameters:
theGeom- The shape ID the algorithm was created on
theMesh- The mesh ID that created the algorithm
dim- The algo dimension
Return values:
Handle(_pyHypothesis)- The found algo
Parameters:
theCreationCmd- The engine command creating a hypothesis
Return values:
Handle(_pyHypothesis)- Result _pyHypothesis

Definition at line 988 of file SMESH_2smeshpy.cxx.

{
  list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
  for ( ; hyp != myHypos.end(); ++hyp )
    if ( !hyp->IsNull() && theHypID == (*hyp)->GetID() )
      return *hyp;
  return Handle(_pyHypothesis)();
}

Here is the call graph for this function:

Find subMesh by ID (entry)

Parameters:
theSubMeshID- The subMesh ID
Return values:
Handle(_pySubMesh)- The found subMesh

Definition at line 1029 of file SMESH_2smeshpy.cxx.

{
  map< _pyID, Handle(_pyObject) >::iterator id_subMesh = myObjects.find(theSubMeshID);
  if ( id_subMesh != myObjects.end() )
    return Handle(_pySubMesh)::DownCast( id_subMesh->second );
  return Handle(_pySubMesh)();
}

Here is the call graph for this function:

Finds a _pyObject by ID.

Definition at line 1206 of file SMESH_2smeshpy.cxx.

{
  {
    map< _pyID, Handle(_pyObject) >::const_iterator id_obj = myObjects.find( theObjID );
    if ( id_obj != myObjects.end() )
      return id_obj->second;
  }
  {
    map< _pyID, Handle(_pyMesh) >::const_iterator id_obj = myMeshes.find( theObjID );
    if ( id_obj != myMeshes.end() )
      return id_obj->second;
  }
  // {
  //   map< _pyID, Handle(_pyMeshEditor) >::const_iterator id_obj = myMeshEditors.find( theObjID );
  //   if ( id_obj != myMeshEditors.end() )
  //     return id_obj->second;
  // }
  return Handle(_pyObject)();
}

Here is the call graph for this function:

Return reader of hypotheses of plugins.

Definition at line 1273 of file SMESH_2smeshpy.cxx.

{
  if (myHypReader.IsNull() )
    ((_pyGen*) this)->myHypReader = new _pyHypothesisReader;

  return myHypReader;
}
IMPLEMENT_STANDARD_HANDLE ( _pyObject  ,
Standard_Transient   
)
IMPLEMENT_STANDARD_HANDLE ( _pyCommand  ,
Standard_Transient   
)
IMPLEMENT_STANDARD_HANDLE ( _pyHypothesisReader  ,
Standard_Transient   
)
IMPLEMENT_STANDARD_RTTIEXT ( _pyObject  ,
Standard_Transient   
)
IMPLEMENT_STANDARD_RTTIEXT ( _pyCommand  ,
Standard_Transient   
)
IMPLEMENT_STANDARD_RTTIEXT ( _pyHypothesisReader  ,
Standard_Transient   
)
static bool isWord ( const char  c,
const bool  dotIsWord 
) [inline, static]

Check if char is a word part.

Parameters:
c- The character to check
Return values:
bool- The check result

Definition at line 3245 of file SMESH_2smeshpy.cxx.

{
  return
    !isspace(c) && c != ',' && c != '=' && c != ')' && c != '(' && ( dotIsWord || c != '.');
}

Here is the caller graph for this function:


Variable Documentation

TCollection_AsciiString theEmptyString [static]

Definition at line 94 of file SMESH_2smeshpy.cxx.