Version: 6.3.1
Public Member Functions | Private Attributes

SMESH.FilterLibrary_i Class Reference

#include <SMESH_Filter_i.hxx>

Inheritance diagram for SMESH.FilterLibrary_i:
Inheritance graph
[legend]

Public Member Functions

 FilterLibrary_i (const char *theFileName)
 FilterLibrary_i ()
 ~FilterLibrary_i ()
Filter_ptr Copy (const char *theFilterName)
CORBA::Boolean Add (const char *theFilterName, Filter_ptr theFilter)
CORBA::Boolean AddEmpty (const char *theFilterName, ElementType theType)
CORBA::Boolean Delete (const char *theFilterName)
CORBA::Boolean Replace (const char *theFilterName, const char *theNewName, Filter_ptr theFilter)
CORBA::Boolean Save ()
CORBA::Boolean SaveAs (const char *aFileName)
CORBA::Boolean IsPresent (const char *aFilterName)
CORBA::Long NbFilters (ElementType)
string_arrayGetNames (ElementType)
string_arrayGetAllNames ()
void SetFileName (const char *theFileName)
char * GetFileName ()

Private Attributes

char * myFileName
LDOM_Document myDoc
FilterManager_var myFilterMgr

Detailed Description

Definition at line 934 of file SMESH_Filter_i.hxx.


Constructor & Destructor Documentation

FilterLibrary_i::FilterLibrary_i ( const char *  theFileName)

Definition at line 3380 of file SMESH_Filter_i.cxx.

References SMESH.FilterLibrary_i.myDoc, SMESH.FilterLibrary_i.myFileName, and SMESH.FilterLibrary_i.myFilterMgr.

{
  myFileName = strdup( theFileName );
  SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
  myFilterMgr = aFilterMgr->_this();

  LDOMParser aParser;

  // Try to use existing library file
  bool anExists = false;
  if ( !aParser.parse( myFileName ) )
  {
    myDoc = aParser.getDocument();
    anExists = true;
  }
  // Create a new XML document if it doesn't exist
  else
    myDoc = LDOM_Document::createDocument( LDOMString() );

  LDOM_Element aRootElement = myDoc.getDocumentElement();
  if ( aRootElement.isNull() )
  {
    // If the existing document is empty --> try to create a new one
    if ( anExists )
      myDoc = LDOM_Document::createDocument( LDOMString() );
  }
}
FilterLibrary_i::FilterLibrary_i ( )

Definition at line 3412 of file SMESH_Filter_i.cxx.

References SMESH.FilterLibrary_i.myDoc, SMESH.FilterLibrary_i.myFileName, and SMESH.FilterLibrary_i.myFilterMgr.

{
  myFileName = 0;
  SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
  myFilterMgr = aFilter->_this();

  myDoc = LDOM_Document::createDocument( LDOMString() );
}
FilterLibrary_i::~FilterLibrary_i ( )

Definition at line 3421 of file SMESH_Filter_i.cxx.

References SMESH.FilterLibrary_i.myFileName.

{
  delete myFileName;
  //TPythonDump()<<this<<".UnRegister()";
}

Member Function Documentation

CORBA::Boolean FilterLibrary_i::Add ( const char *  theFilterName,
Filter_ptr  theFilter 
)

Definition at line 3524 of file SMESH_Filter_i.cxx.

References createFilterItem(), findFilter(), getSection(), and SMESH.FilterLibrary_i.myDoc.

{
  // if filter already in library or entry filter is null do nothing
  LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
  if ( !aFilterNode.isNull() || theFilter->_is_nil() )
    return false;

  // get section corresponding to the filter type
  ElementType anEntType = theFilter->GetElementType();

  LDOM_Node aSection = getSection( anEntType, myDoc, true );
  if ( aSection.isNull() )
    return false;

  // create filter item
  LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
  if ( aFilterItem.isNull() )
    return false;
  else
  {
    aSection.appendChild( aFilterItem );
    if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
      TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
    return true;
  }
}
CORBA::Boolean FilterLibrary_i::AddEmpty ( const char *  theFilterName,
ElementType  theType 
)

Definition at line 3555 of file SMESH_Filter_i.cxx.

References createFilterItem(), findFilter(), getSection(), SMESH.FilterLibrary_i.myDoc, and SMESH.FilterLibrary_i.myFilterMgr.

{
  // if filter already in library or entry filter is null do nothing
  LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
  if ( !aFilterNode.isNull() )
    return false;

  LDOM_Node aSection = getSection( theType, myDoc, true );
  if ( aSection.isNull() )
    return false;

  // create filter item
  Filter_var aFilter = myFilterMgr->CreateFilter();

  LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
  if ( aFilterItem.isNull() )
    return false;
  else
  {
    aSection.appendChild( aFilterItem );
    TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
    return true;
  }
}
Filter_ptr FilterLibrary_i::Copy ( const char *  theFilterName)

Definition at line 3431 of file SMESH_Filter_i.cxx.

References SMESH_demo_hexa2_upd.a, SMESH_freebord.aCriterion, ATTR_BINARY, ATTR_COMPARE, ATTR_ELEMENT_TYPE, ATTR_THRESHOLD, ATTR_THRESHOLD_STR, ATTR_TOLERANCE, ATTR_TYPE, ATTR_UNARY, SMESH.Filter.Criterion.BinaryOp, SMESH.Filter.Criterion.Compare, createCriterion(), findFilter(), SMESH.FilterLibrary_i.myDoc, SMESH.FilterLibrary_i.myFilterMgr, SMESH.Filter.Criterion.Threshold, SMESH.Filter.Criterion.ThresholdStr, toElementType(), toFunctorType(), SMESH.Filter.Criterion.Tolerance, SMESH.Filter.Criterion.Type, SMESH.Filter.Criterion.TypeOfElement, and SMESH.Filter.Criterion.UnaryOp.

{
  Filter_ptr aRes = Filter::_nil();
  LDOM_Node aFilter = findFilter( theFilterName, myDoc );

  if ( aFilter.isNull() )
    return aRes;

  std::list<SMESH::Filter::Criterion> aCriteria;

  for ( LDOM_Node aCritNode = aFilter.getFirstChild();
        !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
  {
    LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;

    const char* aTypeStr      = aCrit->getAttribute( ATTR_TYPE          ).GetString();
    const char* aCompareStr   = aCrit->getAttribute( ATTR_COMPARE       ).GetString();
    const char* aUnaryStr     = aCrit->getAttribute( ATTR_UNARY         ).GetString();
    const char* aBinaryStr    = aCrit->getAttribute( ATTR_BINARY        ).GetString();
    const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE  ).GetString();

    SMESH::Filter::Criterion aCriterion = createCriterion();

    aCriterion.Type          = toFunctorType( aTypeStr );
    aCriterion.Compare       = toFunctorType( aCompareStr );
    aCriterion.UnaryOp       = toFunctorType( aUnaryStr );
    aCriterion.BinaryOp      = toFunctorType( aBinaryStr );

    aCriterion.TypeOfElement = toElementType( anElemTypeStr );

    LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
    int val = 0;
    aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
      ? val : atof( str.GetString() );

    str = aCrit->getAttribute( ATTR_TOLERANCE );
    aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
      ? val : atof( str.GetString() );

    str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
    if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
    {
      char a[ 255 ];
      sprintf( a, "%d", val );
      aCriterion.ThresholdStr = strdup( a );
    }
    else
      aCriterion.ThresholdStr = str.GetString();

    aCriteria.push_back( aCriterion );
  }

  SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
  aCriteriaVar->length( aCriteria.size() );

  CORBA::ULong i = 0;
  std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();

  for( ; anIter != aCriteria.end(); ++anIter )
    aCriteriaVar[ i++ ] = *anIter;

  aRes = myFilterMgr->CreateFilter();
  aRes->SetCriteria( aCriteriaVar.inout() );

  TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";

  return aRes;
}
CORBA::Boolean FilterLibrary_i::Delete ( const char *  theFilterName)

Definition at line 3584 of file SMESH_Filter_i.cxx.

References findFilter(), and SMESH.FilterLibrary_i.myDoc.

{
  LDOM_Node aParentNode;
  LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
  if ( aFilterNode.isNull() || aParentNode.isNull() )
    return false;

  aParentNode.removeChild( aFilterNode );
  TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
  return true;
}
string_array * FilterLibrary_i::GetAllNames ( )

Definition at line 3706 of file SMESH_Filter_i.cxx.

References SMESH.ALL, SMESH.FilterLibrary_i.GetNames(), and SMESH.VOLUME.

{
  string_array_var aResArray = new string_array;
  for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
  {
    SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );

    int aPrevLength = aResArray->length();
    aResArray->length( aPrevLength + aNames->length() );
    for ( int i = 0, n = aNames->length(); i < n; i++ )
      aResArray[ aPrevLength + i ] = aNames[ i ];
  }

  return aResArray._retn();
}
char * FilterLibrary_i::GetFileName ( )

Definition at line 3515 of file SMESH_Filter_i.cxx.

References SMESH.FilterLibrary_i.myFileName.

{
  return CORBA::string_dup( myFileName );
}
string_array * FilterLibrary_i::GetNames ( ElementType  theType)

Definition at line 3677 of file SMESH_Filter_i.cxx.

References getSection(), and SMESH.FilterLibrary_i.myDoc.

Referenced by SMESH.FilterLibrary_i.GetAllNames(), and SMESH.FilterLibrary_i.NbFilters().

{
  string_array_var anArray = new string_array;
  TColStd_SequenceOfHAsciiString aSeq;

  LDOM_Node aSection = getSection( theType, myDoc, false );

  if ( !aSection.isNull() )
  {
    for ( LDOM_Node aFilter = aSection.getFirstChild();
          !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
    {
      LDOM_Element& anElem = ( LDOM_Element& )aFilter;
      aSeq.Append( new TCollection_HAsciiString(
         (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
    }
  }

  anArray->length( aSeq.Length() );
  for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
    anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );

  return anArray._retn();
}
CORBA::Boolean FilterLibrary_i::IsPresent ( const char *  aFilterName)

Definition at line 3658 of file SMESH_Filter_i.cxx.

References findFilter(), and SMESH.FilterLibrary_i.myDoc.

{
  return !findFilter( theFilterName, myDoc ).isNull();
}
CORBA::Long FilterLibrary_i::NbFilters ( ElementType  theType)

Definition at line 3667 of file SMESH_Filter_i.cxx.

References SMESH.FilterLibrary_i.GetNames().

{
  string_array_var aNames = GetNames( theType );
  return aNames->length();
}
CORBA::Boolean FilterLibrary_i::Replace ( const char *  theFilterName,
const char *  theNewName,
Filter_ptr  theFilter 
)

Definition at line 3601 of file SMESH_Filter_i.cxx.

References createFilterItem(), findFilter(), and SMESH.FilterLibrary_i.myDoc.

{
  LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
  if ( aFilterItem.isNull() || theFilter->_is_nil() )
    return false;

  LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
  if ( aNewItem.isNull() )
    return false;
  else
  {
    aFilterItem.ReplaceElement( aNewItem );
    if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
      TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
    return true;
  }
}
CORBA::Boolean FilterLibrary_i::Save ( )

Definition at line 3625 of file SMESH_Filter_i.cxx.

References SMESH.FilterLibrary_i.myDoc, and SMESH.FilterLibrary_i.myFileName.

Referenced by SMESH.FilterLibrary_i.SaveAs().

{
  if ( myFileName == 0 || strlen( myFileName ) == 0 )
    return false;

  FILE* aOutFile = fopen( myFileName, "wt" );
  if ( !aOutFile )
    return false;

  LDOM_XmlWriter aWriter( aOutFile );
  aWriter.SetIndentation( 2 );
  aWriter << myDoc;
  fclose( aOutFile );

  TPythonDump()<<this<<".Save()";
  return true;
}
CORBA::Boolean FilterLibrary_i::SaveAs ( const char *  aFileName)

Definition at line 3647 of file SMESH_Filter_i.cxx.

References SMESH.FilterLibrary_i.myFileName, and SMESH.FilterLibrary_i.Save().

{
  myFileName = strdup ( aFileName );
  TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
  return Save();
}
void FilterLibrary_i::SetFileName ( const char *  theFileName)

Definition at line 3504 of file SMESH_Filter_i.cxx.

References SMESH.FilterLibrary_i.myFileName.

{
  delete myFileName;
  myFileName = strdup( theFileName );
  TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
}

Field Documentation

LDOM_Document SMESH.FilterLibrary_i.myDoc [private]
FilterManager_var SMESH.FilterLibrary_i.myFilterMgr [private]
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