Version: 6.3.1
Public Member Functions | Static Public Member Functions | Data Fields | Private Member Functions | Private Attributes

_pyGen Class Reference

Class corresponding to SMESH_Gen. More...

#include <SMESH_2smeshpy.hxx>

Inheritance diagram for _pyGen:
Inheritance graph
[legend]

Public Member Functions

 _pyGen (Resource_DataMapOfAsciiStringAsciiString &theEntry2AccessorMethod, Resource_DataMapOfAsciiStringAsciiString &theObjectNames)
 _pyGen constructor
 Handle (_pyCommand) AddCommand(const TCollection_AsciiString &theCommand)
void Process (const Handle(_pyCommand)&theCommand)
 Convert the command or remember it for later conversion.
void Flush ()
 Convert the remembered commands.
 Handle (_pyHypothesis) FindHyp(const _pyID &theHypID)
 Handle (_pyHypothesis) FindAlgo(const _pyID &theGeom
const _pyID const Handle (_pyHypothesis)&theHypothesis)
 Handle (_pySubMesh) FindSubMesh(const _pyID &theSubMeshID)
void ExchangeCommands (Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2)
 Change order of commands in the script.
void SetCommandAfter (Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd)
 Set one command after the other.
void SetCommandBefore (Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd)
 Set one command before the other.
 Handle (_pyCommand)&GetLastCommand()
std::list< Handle(_pyCommand) > & GetCommands ()
void SetAccessorMethod (const _pyID &theID, const char *theMethod)
 Set method to access to object wrapped with python class.
bool AddMeshAccessorMethod (Handle(_pyCommand) theCmd) const
 Add access method to mesh that is an argument.
bool AddAlgoAccessorMethod (Handle(_pyCommand) theCmd) const
 Add access method to algo that is an object or an argument.
const char * AccessorMethod () const
 name of SMESH_Gen in smesh.py
_pyID GenerateNewID (const _pyID &theID)
 Generated new ID for object and assign with existing name.
const _pyIDGetID ()
int GetNbCalls () const
void SetCreationCmd (Handle(_pyCommand) cmd)
int GetCommandNb ()

Static Public Member Functions

static _pyID FatherID (const _pyID &childID)
 Return ID of a father.

Data Fields

const _pyIDtheMesh

Private Member Functions

void setNeighbourCommand (Handle(_pyCommand)&theCmd, Handle(_pyCommand)&theOtherCmd, const bool theIsAfter)
 Set one command before or after the other.
 Handle (_pyCommand) myLastCommand

Private Attributes

std::map< _pyID, Handle(_pyMesh) > myMeshes
std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors
std::map< _pyID, Handle(_pyObject) > myObjects
std::list< Handle(_pyHypothesis) > myHypos
std::list< Handle(_pyCommand) > myCommands
int myNbCommands
Resource_DataMapOfAsciiStringAsciiString & myID2AccessorMethod
Resource_DataMapOfAsciiStringAsciiString & myObjectNames

Detailed Description

Class corresponding to SMESH_Gen.

It holds info on existing meshes and hypotheses

Definition at line 181 of file SMESH_2smeshpy.hxx.


Constructor & Destructor Documentation

_pyGen::_pyGen ( Resource_DataMapOfAsciiStringAsciiString &  theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString &  theObjectNames 
)

_pyGen constructor

Definition at line 198 of file SMESH_2smeshpy.cxx.

References myNbCommands.

  : _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )),
    myID2AccessorMethod( theEntry2AccessorMethod ),
    myObjectNames( theObjectNames )
{
  myNbCommands = 0;
  // make that GetID() to return TPythonDump::SMESHGenName()
  GetCreationCmd()->GetString() += "=";
}

Member Function Documentation

const char * _pyGen::AccessorMethod ( ) const [virtual]

name of SMESH_Gen in smesh.py

Reimplemented from _pyObject.

Definition at line 215 of file SMESH_2smeshpy.cxx.

References SMESH_2smeshpy.GenName().

bool _pyGen::AddAlgoAccessorMethod ( Handle(_pyCommand theCmd) const

Add access method to algo that is an object or an argument.

Parameters:
theCmd- command to add access method
Return values:
bool- true if added

Definition at line 524 of file SMESH_2smeshpy.cxx.

References _pyCommand.AddAccessorMethod(), SMESH_demo_hexa2_upd.hyp, and myHypos.

Referenced by _pyHypothesis.Flush().

{
  bool added = false;
  list< Handle(_pyHypothesis) >::const_iterator hyp = myHypos.begin();
  for ( ; hyp != myHypos.end(); ++hyp ) {
    if ( (*hyp)->IsAlgo() && /*(*hyp)->IsWrapped() &&*/
         theCmd->AddAccessorMethod( (*hyp)->GetID(), (*hyp)->AccessorMethod() ))
      added = true;
  }
  return added;
}
bool _pyGen::AddMeshAccessorMethod ( Handle(_pyCommand theCmd) const

Add access method to mesh that is an argument.

Parameters:
theCmd- command to add access method
Return values:
bool- true if added

Definition at line 505 of file SMESH_2smeshpy.cxx.

References _pyCommand.AddAccessorMethod(), and myMeshes.

Referenced by _pyHypothesis.Flush(), _pyMeshEditor.Process(), and Process().

{
  bool added = false;
  map< _pyID, Handle(_pyMesh) >::const_iterator id_mesh = myMeshes.begin();
  for ( ; id_mesh != myMeshes.end(); ++id_mesh ) {
    if ( theCmd->AddAccessorMethod( id_mesh->first, id_mesh->second->AccessorMethod() ))
      added = true;
  }
  return added;
}
void _pyGen::ExchangeCommands ( Handle(_pyCommand theCmd1,
Handle(_pyCommand theCmd2 
)

Change order of commands in the script.

Parameters:
theCmd1- One command
theCmd2- Another command

Definition at line 602 of file SMESH_2smeshpy.cxx.

References _pyCommand.GetOrderNb(), myCommands, and _pyCommand.SetOrderNb().

{
  list< Handle(_pyCommand) >::iterator pos1, pos2;
  pos1 = find( myCommands.begin(), myCommands.end(), theCmd1 );
  pos2 = find( myCommands.begin(), myCommands.end(), theCmd2 );
  myCommands.insert( pos1, theCmd2 );
  myCommands.insert( pos2, theCmd1 );
  myCommands.erase( pos1 );
  myCommands.erase( pos2 );

  int nb1 = theCmd1->GetOrderNb();
  theCmd1->SetOrderNb( theCmd2->GetOrderNb() );
  theCmd2->SetOrderNb( nb1 );
//   cout << "BECOME " << theCmd1->GetOrderNb() << "\t" << theCmd1->GetString() << endl
//        << "BECOME " << theCmd2->GetOrderNb() << "\t" << theCmd2->GetString() << endl << endl;
}
_pyID _pyObject::FatherID ( const _pyID childID) [static, inherited]

Return ID of a father.

Definition at line 2494 of file SMESH_2smeshpy.cxx.

Referenced by _pySegmentLengthAroundVertexHyp.Addition2Creation().

{
  int colPos = childID.SearchFromEnd(':');
  if ( colPos > 0 )
    return childID.SubString( 1, colPos-1 );
  return "";
}
void _pyGen::Flush ( ) [virtual]

Convert the remembered commands.

Implements _pyObject.

Definition at line 469 of file SMESH_2smeshpy.cxx.

References SMESH_2smeshpy.GenName(), SMESH_demo_hexa2_upd.hyp, myCommands, myHypos, myMeshes, myNbCommands, and myObjects.

Referenced by SMESH_2smeshpy.ConvertScript().

{
  // create empty command
  myLastCommand = new _pyCommand();

  map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.begin();
  for ( ; id_mesh != myMeshes.end(); ++id_mesh )
    if ( ! id_mesh->second.IsNull() )
      id_mesh->second->Flush();

  list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
  for ( ; hyp != myHypos.end(); ++hyp )
    if ( !hyp->IsNull() ) {
      (*hyp)->Flush();
      // smeshgen.CreateHypothesis() --> smesh.smesh.CreateHypothesis()
      if ( !(*hyp)->IsWrapped() )
        (*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
    }

  map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.begin();
  for ( ; id_obj != myObjects.end(); ++id_obj )
    if ( ! id_obj->second.IsNull() )
      id_obj->second->Flush();

  myLastCommand->SetOrderNb( ++myNbCommands );
  myCommands.push_back( myLastCommand );
}
_pyID _pyGen::GenerateNewID ( const _pyID theID)

Generated new ID for object and assign with existing name.

Parameters:
theID- ID of existing object

Definition at line 700 of file SMESH_2smeshpy.cxx.

References myObjectNames.

Referenced by _pyMesh.Flush().

{
  int index = 1;
  _pyID aNewID;
  do {
    aNewID = theID + _pyID( ":" ) + _pyID( index++ );
  }
  while ( myObjectNames.IsBound( aNewID ) );
    
  myObjectNames.Bind( aNewID, myObjectNames.IsBound( theID ) 
                      ? (myObjectNames.Find( theID ) + _pyID( "_" ) + _pyID( index-1 ))
                      : _pyID( "A" ) + aNewID );
  return aNewID;
}
int _pyObject.GetCommandNb ( ) [inherited]

Definition at line 167 of file SMESH_2smeshpy.hxx.

{ return myCreationCmd->GetOrderNb(); }
std::list< Handle(_pyCommand) >& _pyGen.GetCommands ( )

Definition at line 198 of file SMESH_2smeshpy.hxx.

References myCommands.

Referenced by SMESH_2smeshpy.ConvertScript(), and _pyLayerDistributionHypo.Flush().

{ return myCommands; }
const _pyID& _pyObject.GetID ( ) [inherited]
int _pyObject.GetNbCalls ( ) const [inherited]

Definition at line 165 of file SMESH_2smeshpy.hxx.

References _pyObject.myNbCalls.

Referenced by _pySubMesh.Flush(), and _pySelfEraser.Flush().

{ return myNbCalls; }
_pyGen.Handle ( _pyHypothesis  ) const
_pyGen.Handle ( _pyHypothesis  ) const
_pyGen.Handle ( _pyCommand  ) [private]

Reimplemented from _pyObject.

const _pyID const _pyGen.Handle ( _pyHypothesis  )
_pyGen.Handle ( _pyCommand  )

Reimplemented from _pyObject.

_pyGen.Handle ( _pyCommand  ) const

Referenced by Process().

_pyGen.Handle ( _pySubMesh  ) const
void _pyGen::Process ( const Handle(_pyCommand)&  theCommand) [virtual]

Convert the command or remember it for later conversion.

Parameters:
theCommand- The python command calling a method of SMESH_Gen

Reimplemented from _pyObject.

Definition at line 349 of file SMESH_2smeshpy.cxx.

References AddMeshAccessorMethod(), _pyCommand.Clear(), SMESH_2smeshpy.GenName(), SMESH_box.geom, _pyCommand.GetArg(), _pyCommand.GetMethod(), _pyCommand.GetNbArgs(), _pyCommand.GetNbResultValues(), _pyCommand.GetResultValue(), Handle(), SMESH_test.ind, PAL_MESH_041_mesh.mesh, myHypos, myMeshes, myObjects, SMESH_reg.names, _pyCommand.RemoveArgs(), _pyCommand.SetArg(), _pyCommand.SetMethod(), _pyCommand.SetObject(), and SMESH_2smeshpy.SmeshpyName().

Referenced by _pyMeshEditor.Process(), and _pyMesh.Process().

{
  // there are methods to convert:
  // CreateMesh( shape )
  // Concatenate( [mesh1, ...], ... )
  // CreateHypothesis( theHypType, theLibName )
  // Compute( mesh, geom )
  // Evaluate( mesh, geom )
  // mesh creation
  TCollection_AsciiString method = theCommand->GetMethod();

  if ( method == "CreateMesh" || method == "CreateEmptyMesh")
  {
    Handle(_pyMesh) mesh = new _pyMesh( theCommand );
    myMeshes.insert( make_pair( mesh->GetID(), mesh ));
    return;
  }
  if ( method == "CreateMeshesFromUNV" || method == "CreateMeshesFromSTL" || method == "CopyMesh" )
  {
    Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
    myMeshes.insert( make_pair( mesh->GetID(), mesh ));
    return;
  }
  if( method == "CreateMeshesFromMED")
  {
    for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
    {
      Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind));
      myMeshes.insert( make_pair( theCommand->GetResultValue(ind), mesh ));     
    }
  }

  // CreateHypothesis()
  if ( method == "CreateHypothesis" )
  {
    // issue 199929, remove standard library name (default parameter)
    const TCollection_AsciiString & aLibName = theCommand->GetArg( 2 );
    if ( aLibName.Search( "StdMeshersEngine" ) != -1 ) {
      // keep first argument
      TCollection_AsciiString arg = theCommand->GetArg( 1 );
      theCommand->RemoveArgs();
      theCommand->SetArg( 1, arg );
    }

    myHypos.push_back( _pyHypothesis::NewHypothesis( theCommand ));
    return;
  }

  // smeshgen.Compute( mesh, geom ) --> mesh.Compute()
  if ( method == "Compute" )
  {
    const _pyID& meshID = theCommand->GetArg( 1 );
    map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
    if ( id_mesh != myMeshes.end() ) {
      theCommand->SetObject( meshID );
      theCommand->RemoveArgs();
      id_mesh->second->Flush();
      return;
    }
  }

  // smeshgen.Evaluate( mesh, geom ) --> mesh.Evaluate(geom)
  if ( method == "Evaluate" )
  {
    const _pyID& meshID = theCommand->GetArg( 1 );
    map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
    if ( id_mesh != myMeshes.end() ) {
      theCommand->SetObject( meshID );
      _pyID geom = theCommand->GetArg( 2 );
      theCommand->RemoveArgs();
      theCommand->SetArg( 1, geom );
      return;
    }
  }

  // objects erasing creation command if no more it's commands invoked:
  // SMESH_Pattern, FilterManager
  if ( method == "GetPattern" || method == "CreateFilterManager" ) {
    Handle(_pyObject) obj = new _pySelfEraser( theCommand );
    if ( !myObjects.insert( make_pair( obj->GetID(), obj )).second )
      theCommand->Clear(); // already created
  }

  // Concatenate( [mesh1, ...], ... )
  if ( method == "Concatenate" || method == "ConcatenateWithGroups")
  {
    if ( method == "ConcatenateWithGroups" ) {
      theCommand->SetMethod( "Concatenate" );
      theCommand->SetArg( theCommand->GetNbArgs() + 1, "True" );
    }
    Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
    myMeshes.insert( make_pair( mesh->GetID(), mesh ));
    AddMeshAccessorMethod( theCommand );
  }

  // Replace name of SMESH_Gen

  // names of SMESH_Gen methods fully equal to methods defined in smesh.py
  static TStringSet smeshpyMethods;
  if ( smeshpyMethods.empty() ) {
    const char * names[] =
      { "SetEmbeddedMode","IsEmbeddedMode","SetCurrentStudy","GetCurrentStudy",
        "GetPattern","GetSubShapesId",
        "" }; // <- mark of array end
    smeshpyMethods.Insert( names );
  }
  if ( smeshpyMethods.Contains( theCommand->GetMethod() ))
    // smeshgen.Method() --> smesh.Method()
    theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
  else
    // smeshgen.Method() --> smesh.smesh.Method()
    theCommand->SetObject( SMESH_2smeshpy::GenName() );
}
void _pyGen::SetAccessorMethod ( const _pyID theID,
const char *  theMethod 
)

Set method to access to object wrapped with python class.

Parameters:
theID- The wrapped object entry
theMethod- The accessor method

Definition at line 688 of file SMESH_2smeshpy.cxx.

References myID2AccessorMethod.

Referenced by _pyMesh._pyMesh(), and _pyAlgorithm.Addition2Creation().

{
  myID2AccessorMethod.Bind( theID, (char*) theMethod );
}
void _pyGen::SetCommandAfter ( Handle(_pyCommand theCmd,
Handle(_pyCommand theAfterCmd 
)

Set one command after the other.

Parameters:
theCmd- Command to move
theAfterCmd- Command ater which to insert the first one

Definition at line 627 of file SMESH_2smeshpy.cxx.

References setNeighbourCommand().

Referenced by _pyCommand.SetDependentCmdsAfter().

{
  setNeighbourCommand( theCmd, theAfterCmd, true );
}
void _pyGen::SetCommandBefore ( Handle(_pyCommand theCmd,
Handle(_pyCommand theBeforeCmd 
)

Set one command before the other.

Parameters:
theCmd- Command to move
theBeforeCmd- Command before which to insert the first one

Definition at line 640 of file SMESH_2smeshpy.cxx.

References setNeighbourCommand().

Referenced by _pyMesh.Flush().

{
  setNeighbourCommand( theCmd, theBeforeCmd, false );
}
void _pyObject.SetCreationCmd ( Handle(_pyCommand cmd) [inherited]

Definition at line 166 of file SMESH_2smeshpy.hxx.

Referenced by _pyHypothesis.Addition2Creation().

{ myCreationCmd = cmd; }
void _pyGen::setNeighbourCommand ( Handle(_pyCommand)&  theCmd,
Handle(_pyCommand)&  theOtherCmd,
const bool  theIsAfter 
) [private]

Set one command before or after the other.

Parameters:
theCmd- Command to move
theOtherCmd- Command ater or before which to insert the first one

Definition at line 653 of file SMESH_2smeshpy.cxx.

References myCommands.

Referenced by SetCommandAfter(), and SetCommandBefore().

{
  list< Handle(_pyCommand) >::iterator pos;
  pos = find( myCommands.begin(), myCommands.end(), theCmd );
  myCommands.erase( pos );
  pos = find( myCommands.begin(), myCommands.end(), theOtherCmd );
  myCommands.insert( (theIsAfter ? ++pos : pos), theCmd );

  int i = 1;
  for ( pos = myCommands.begin(); pos != myCommands.end(); ++pos)
    (*pos)->SetOrderNb( i++ );
}

Field Documentation

std::list< Handle(_pyCommand) > _pyGen.myCommands [private]

Definition at line 216 of file SMESH_2smeshpy.hxx.

Referenced by ExchangeCommands(), Flush(), GetCommands(), and setNeighbourCommand().

std::list< Handle(_pyHypothesis) > _pyGen.myHypos [private]

Definition at line 215 of file SMESH_2smeshpy.hxx.

Referenced by AddAlgoAccessorMethod(), Flush(), and Process().

Resource_DataMapOfAsciiStringAsciiString& _pyGen.myID2AccessorMethod [private]

Definition at line 218 of file SMESH_2smeshpy.hxx.

Referenced by SetAccessorMethod().

std::map< _pyID, Handle(_pyMeshEditor) > _pyGen.myMeshEditors [private]

Definition at line 213 of file SMESH_2smeshpy.hxx.

std::map< _pyID, Handle(_pyMesh) > _pyGen.myMeshes [private]

Definition at line 211 of file SMESH_2smeshpy.hxx.

Referenced by AddMeshAccessorMethod(), Flush(), and Process().

Definition at line 217 of file SMESH_2smeshpy.hxx.

Referenced by _pyGen(), and Flush().

Resource_DataMapOfAsciiStringAsciiString& _pyGen.myObjectNames [private]

Definition at line 219 of file SMESH_2smeshpy.hxx.

Referenced by GenerateNewID().

std::map< _pyID, Handle(_pyObject) > _pyGen.myObjects [private]

Definition at line 214 of file SMESH_2smeshpy.hxx.

Referenced by Flush(), and Process().

Definition at line 191 of file SMESH_2smeshpy.hxx.

Referenced by _pyHypothesis.IsWrappable().

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS