PythonDump for SMESH Controls / Filter

This commit is contained in:
apo 2005-03-30 06:58:37 +00:00
parent d448969fe8
commit e5c454adf0
4 changed files with 281 additions and 217 deletions

View File

@ -9,176 +9,10 @@
#include "SMESH_Filter_i.hxx"
#include <TColStd_HSequenceOfInteger.hxx>
#include <TCollection_AsciiString.hxx>
namespace SMESH
{
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString, const char* theArg){
theString += Standard_CString(theArg);
return theString;
}
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString, int theArg){
theString += TCollection_AsciiString(theArg);
return theString;
}
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString, float theArg){
theString += TCollection_AsciiString(theArg);
return theString;
}
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
const SMESH::long_array& theArg)
{
theString<<"[ ";
CORBA::Long i = 1, iEnd = theArg.length();
for(; i <= iEnd; i++) {
theString<<int(theArg[i-1]);
if(i < iEnd)
theString<< ", ";
}
theString<<" ]";
return theString;
}
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
CORBA::Object_ptr theArg)
{
CORBA::String_var aString("None");
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
if(!aSObject->_is_nil()){
aString = aSObject->GetID();
}else if(!CORBA::is_nil(theArg)){
aString = SMESH_Gen_i::GetORB()->object_to_string(theArg);
}
theString<<aString.in();
return theString;
}
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
SMESH::FilterLibrary_i* theArg)
{
theString += TCollection_AsciiString("aFilterLibrary_");
theString += TCollection_AsciiString(int(theArg));
return theString;
}
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
SMESH::FilterManager_i* theArg)
{
theString += TCollection_AsciiString("aFilterManager_");
theString += TCollection_AsciiString(int(theArg));
return theString;
}
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
SMESH::Filter_i* theArg)
{
theString += TCollection_AsciiString("aFilter_");
theString += TCollection_AsciiString(int(theArg));
return theString;
}
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
SMESH::Functor_i* theArg)
{
FunctorType aFunctorType = theArg->GetFunctorType();
switch(aFunctorType){
case FT_AspectRatio:
theString += TCollection_AsciiString("anAspectRatio");
break;
case FT_AspectRatio3D:
theString += TCollection_AsciiString("anAspectRatio3D");
break;
case FT_Warping:
theString += TCollection_AsciiString("aWarping");
break;
case FT_MinimumAngle:
theString += TCollection_AsciiString("aMinimumAngle");
break;
case FT_Taper:
theString += TCollection_AsciiString("aTaper");
break;
case FT_Skew:
theString += TCollection_AsciiString("aSkew");
break;
case FT_Area:
theString += TCollection_AsciiString("aArea");
break;
case FT_FreeBorders:
theString += TCollection_AsciiString("aFreeBorders");
break;
case FT_FreeEdges:
theString += TCollection_AsciiString("aFreeEdges");
break;
case FT_MultiConnection:
theString += TCollection_AsciiString("aMultiConnection");
break;
case FT_MultiConnection2D:
theString += TCollection_AsciiString("aMultiConnection2D");
break;
case FT_Length:
theString += TCollection_AsciiString("aLength");
break;
case FT_Length2D:
theString += TCollection_AsciiString("aLength");
break;
case FT_BelongToGeom:
theString += TCollection_AsciiString("aBelongToGeom");
break;
case FT_BelongToPlane:
theString += TCollection_AsciiString("aBelongToPlane");
break;
case FT_BelongToCylinder:
theString += TCollection_AsciiString("aBelongToCylinder");
break;
case FT_LyingOnGeom:
theString += TCollection_AsciiString("aLyingOnGeom");
break;
case FT_RangeOfIds:
theString += TCollection_AsciiString("aRangeOfIds");
break;
case FT_BadOrientedVolume:
theString += TCollection_AsciiString("aBadOrientedVolume");
break;
case FT_LessThan:
theString += TCollection_AsciiString("aLessThan");
break;
case FT_MoreThan:
theString += TCollection_AsciiString("aMoreThan");
break;
case FT_EqualTo:
theString += TCollection_AsciiString("anEqualTo");
break;
case FT_LogicalNOT:
theString += TCollection_AsciiString("aLogicalNOT");
break;
case FT_LogicalAND:
theString += TCollection_AsciiString("aLogicalAND");
break;
case FT_LogicalOR:
theString += TCollection_AsciiString("aLogicalOR");
break;
case FT_Undefined:
theString += TCollection_AsciiString("anUndefined");
break;
}
theString += Standard_CString("_");
theString += TCollection_AsciiString(int(theArg));
return theString;
}
size_t TPythonDump::myCounter = 0;
@ -194,10 +28,184 @@ namespace SMESH
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
if(!aStudy->_is_nil()){
aSMESHGen->AddToPythonScript(aStudy->StudyId(),myString);
std::string aString = myStream.str();
TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection);
}
}
}
TPythonDump&
TPythonDump::
operator<<(const SMESH::ElementType& theArg)
{
myStream<<"SMESH.";
switch(theArg){
case ALL:
myStream<<"ALL";
break;
case NODE:
myStream<<"NODE";
break;
case EDGE:
myStream<<"EDGE";
break;
case FACE:
myStream<<"FACE";
break;
case VOLUME:
myStream<<"VOLUME";
break;
}
return *this;
}
TPythonDump&
TPythonDump::
operator<<(const SMESH::long_array& theArg)
{
myStream<<"[ ";
CORBA::Long i = 1, iEnd = theArg.length();
for(; i <= iEnd; i++) {
myStream<<theArg[i-1];
if(i < iEnd)
myStream<< ", ";
}
myStream<<" ]";
return *this;
}
TPythonDump&
TPythonDump::
operator<<(CORBA::Object_ptr theArg)
{
CORBA::String_var aString("None");
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
if(!aSObject->_is_nil()){
aString = aSObject->GetID();
}else if(!CORBA::is_nil(theArg)){
aString = SMESH_Gen_i::GetORB()->object_to_string(theArg);
}
myStream<<aString.in();
return *this;
}
TPythonDump&
TPythonDump::
operator<<(SMESH::FilterLibrary_i* theArg)
{
myStream<<"aFilterLibrary"<<theArg;
return *this;
}
TPythonDump&
TPythonDump::
operator<<(SMESH::FilterManager_i* theArg)
{
myStream<<"aFilterManager"<<theArg;
return *this;
}
TPythonDump&
TPythonDump::
operator<<(SMESH::Filter_i* theArg)
{
myStream<<"aFilter"<<theArg;
return *this;
}
TPythonDump&
TPythonDump::
operator<<(SMESH::Functor_i* theArg)
{
FunctorType aFunctorType = theArg->GetFunctorType();
switch(aFunctorType){
case FT_AspectRatio:
myStream<<"anAspectRatio";
break;
case FT_AspectRatio3D:
myStream<<"anAspectRatio3D";
break;
case FT_Warping:
myStream<<"aWarping";
break;
case FT_MinimumAngle:
myStream<<"aMinimumAngle";
break;
case FT_Taper:
myStream<<"aTaper";
break;
case FT_Skew:
myStream<<"aSkew";
break;
case FT_Area:
myStream<<"aArea";
break;
case FT_FreeBorders:
myStream<<"aFreeBorders";
break;
case FT_FreeEdges:
myStream<<"aFreeEdges";
break;
case FT_MultiConnection:
myStream<<"aMultiConnection";
break;
case FT_MultiConnection2D:
myStream<<"aMultiConnection2D";
break;
case FT_Length:
myStream<<"aLength";
break;
case FT_Length2D:
myStream<<"aLength";
break;
case FT_BelongToGeom:
myStream<<"aBelongToGeom";
break;
case FT_BelongToPlane:
myStream<<"aBelongToPlane";
break;
case FT_BelongToCylinder:
myStream<<"aBelongToCylinder";
break;
case FT_LyingOnGeom:
myStream<<"aLyingOnGeom";
break;
case FT_RangeOfIds:
myStream<<"aRangeOfIds";
break;
case FT_BadOrientedVolume:
myStream<<"aBadOrientedVolume";
break;
case FT_LessThan:
myStream<<"aLessThan";
break;
case FT_MoreThan:
myStream<<"aMoreThan";
break;
case FT_EqualTo:
myStream<<"anEqualTo";
break;
case FT_LogicalNOT:
myStream<<"aLogicalNOT";
break;
case FT_LogicalAND:
myStream<<"aLogicalAND";
break;
case FT_LogicalOR:
myStream<<"aLogicalOR";
break;
case FT_Undefined:
myStream<<"anUndefined";
break;
}
myStream<<theArg;
return *this;
}
}
//=======================================================================

View File

@ -70,8 +70,7 @@ namespace SMESH
Predicate_i*
GetPredicate( Predicate_ptr thePredicate )
{
PortableServer::ServantBase_var aServant = SMESH_Gen_i::GetServant( thePredicate );
return dynamic_cast<Predicate_i*>(aServant.in());
return DownCast<Predicate_i*>(thePredicate);
}
}
@ -322,8 +321,7 @@ inline
const SMDS_Mesh*
MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
{
SMESH_Mesh_i* anImplPtr =
dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( theMesh ).in() );
SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
}
@ -437,6 +435,7 @@ CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
{
myNumericalFunctorPtr->SetPrecision( thePrecision );
TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
}
CORBA::Long NumericalFunctor_i::GetPrecision()
@ -731,6 +730,7 @@ void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
myBelongToGeomPtr->SetGeom( aLocShape );
TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
}
void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
@ -740,6 +740,7 @@ void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
void BelongToGeom_i::SetElementType(ElementType theType){
myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
TPythonDump()<<this<<".SetElementType("<<theType<<")";
}
FunctorType BelongToGeom_i::GetFunctorType()
@ -752,6 +753,7 @@ void BelongToGeom_i::SetShapeName( const char* theName )
delete myShapeName;
myShapeName = strdup( theName );
myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
}
char* BelongToGeom_i::GetShapeName()
@ -795,6 +797,7 @@ void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType t
}
myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
TPythonDump()<<this<<".SetSurface("<<theGeom<<",'"<<theType<<"')";
}
void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
@ -802,6 +805,7 @@ void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
delete myShapeName;
myShapeName = strdup( theName );
myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
}
char* BelongToSurface_i::GetShapeName()
@ -812,6 +816,7 @@ char* BelongToSurface_i::GetShapeName()
void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
{
myElementsOnSurfacePtr->SetTolerance( theToler );
TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
}
CORBA::Double BelongToSurface_i::GetTolerance()
@ -832,6 +837,7 @@ BelongToPlane_i::BelongToPlane_i()
void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
{
BelongToSurface_i::SetSurface( theGeom, theType );
TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
}
FunctorType BelongToPlane_i::GetFunctorType()
@ -852,6 +858,7 @@ BelongToCylinder_i::BelongToCylinder_i()
void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
{
BelongToSurface_i::SetSurface( theGeom, theType );
TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
}
FunctorType BelongToCylinder_i::GetFunctorType()
@ -883,6 +890,7 @@ void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
myLyingOnGeomPtr->SetGeom( aLocShape );
TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
}
void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
@ -892,6 +900,7 @@ void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
void LyingOnGeom_i::SetElementType(ElementType theType){
myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
TPythonDump()<<this<<".SetElementType("<<theType<<")";
}
FunctorType LyingOnGeom_i::GetFunctorType()
@ -904,6 +913,7 @@ void LyingOnGeom_i::SetShapeName( const char* theName )
delete myShapeName;
myShapeName = strdup( theName );
myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
}
char* LyingOnGeom_i::GetShapeName()
@ -986,10 +996,12 @@ void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
CORBA::Long iEnd = theIds.length();
for ( CORBA::Long i = 0; i < iEnd; i++ )
myRangeOfIdsPtr->AddToRange( theIds[ i ] );
TPythonDump()<<this<<".SetRange("<<theIds<<")";
}
CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
{
TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
return myRangeOfIdsPtr->SetRangeStr(
TCollection_AsciiString( (Standard_CString)theRange ) );
}
@ -1004,6 +1016,7 @@ char* RangeOfIds_i::GetRangeStr()
void RangeOfIds_i::SetElementType( ElementType theType )
{
myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
TPythonDump()<<this<<".SetElementType("<<theType<<")";
}
FunctorType RangeOfIds_i::GetFunctorType()
@ -1028,7 +1041,7 @@ Comparator_i::~Comparator_i()
void Comparator_i::SetMargin( CORBA::Double theValue )
{
myComparatorPtr->SetMargin( theValue );
TPythonDump()<<this<<".SetMargin("<<float(theValue)<<")";
TPythonDump()<<this<<".SetMargin("<<theValue<<")";
}
CORBA::Double Comparator_i::GetMargin()
@ -1041,7 +1054,7 @@ void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
if ( myNumericalFunctor )
myNumericalFunctor->Destroy();
myNumericalFunctor = dynamic_cast<NumericalFunctor_i*>( SMESH_Gen_i::GetServant( theFunct ).in() );
myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
if ( myNumericalFunctor )
{
@ -1107,7 +1120,7 @@ EqualTo_i::EqualTo_i()
void EqualTo_i::SetTolerance( CORBA::Double theToler )
{
myEqualToPtr->SetTolerance( theToler );
TPythonDump()<<this<<".SetTolerance("<<float(theToler)<<")";
TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
}
CORBA::Double EqualTo_i::GetTolerance()
@ -1821,6 +1834,10 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
long aPrecision = theCriteria[ i ].Precision;
TPythonDump()<<this<<".SetCriteria(SMESH.Filter.Criteria("<<
aCriterion<<","<<aCompare<<","<<aThreshold<<","<<aUnary<<","<<aBinary<<","<<
aTolerance<<",'"<<aThresholdStr<<"',"<<aTypeOfElem<<","<<aPrecision<<")";
SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
@ -2451,7 +2468,9 @@ Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
aRes = myFilterMgr->CreateFilter();
aRes->SetCriteria( aCriteriaVar.inout() );
TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
return aRes;
}
@ -2463,6 +2482,7 @@ void FilterLibrary_i::SetFileName( const char* theFileName )
{
delete myFileName;
myFileName = strdup( theFileName );
TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
}
//=======================================================================
@ -2499,6 +2519,8 @@ CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFi
else
{
aSection.appendChild( aFilterItem );
if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
return true;
}
}
@ -2527,6 +2549,7 @@ CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType
else
{
aSection.appendChild( aFilterItem );
TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
return true;
}
}
@ -2543,6 +2566,7 @@ CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
return false;
aParentNode.removeChild( aFilterNode );
TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
return true;
}
@ -2565,6 +2589,8 @@ CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
else
{
aFilterItem.ReplaceElement( aNewItem );
if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
return true;
}
}
@ -2587,6 +2613,7 @@ CORBA::Boolean FilterLibrary_i::Save()
aWriter << myDoc;
fclose( aOutFile );
TPythonDump()<<this<<".Save()";
return true;
}
@ -2597,6 +2624,7 @@ CORBA::Boolean FilterLibrary_i::Save()
CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
{
myFileName = strdup ( aFileName );
TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
return Save();
}

View File

@ -428,4 +428,16 @@ private:
std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
};
namespace SMESH
{
template<class T>
T
DownCast(CORBA::Object_ptr theArg)
{
return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
}
}
#endif

View File

@ -23,63 +23,79 @@
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SMESH_Mesh)
#include <TCollection_AsciiString.hxx>
#include <sstream>
namespace SMESH
{
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
const char* theArg);
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
int theArg);
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
float theArg);
class FilterLibrary_i;
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
SMESH::FilterLibrary_i* theArg);
class FilterManager_i;
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
SMESH::FilterManager_i* theArg);
class Filter_i;
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
SMESH::Filter_i* theArg);
class Functor_i;
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
SMESH::Functor_i* theArg);
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
CORBA::Object_ptr theArg);
TCollection_AsciiString&
operator<<(TCollection_AsciiString& theString,
const SMESH::long_array& theArg);
class TPythonDump
{
TCollection_AsciiString myString;
std::ostringstream myStream;
static size_t myCounter;
public:
TPythonDump();
virtual ~TPythonDump();
template<class T>
TCollection_AsciiString&
operator<<(T theArg){
return myString<<theArg;
TPythonDump&
operator<<(long int theArg){
myStream<<theArg;
return *this;
}
TPythonDump&
operator<<(int theArg){
myStream<<theArg;
return *this;
}
TPythonDump&
operator<<(double theArg){
myStream<<theArg;
return *this;
}
TPythonDump&
operator<<(float theArg){
myStream<<theArg;
return *this;
}
TPythonDump&
operator<<(const void* theArg){
myStream<<theArg;
return *this;
}
TPythonDump&
operator<<(const char* theArg){
myStream<<theArg;
return *this;
}
TPythonDump&
operator<<(const SMESH::ElementType& theArg);
TPythonDump&
operator<<(const SMESH::long_array& theArg);
TPythonDump&
operator<<(CORBA::Object_ptr theArg);
TPythonDump&
operator<<(SMESH::FilterLibrary_i* theArg);
TPythonDump&
operator<<(SMESH::FilterManager_i* theArg);
TPythonDump&
operator<<(SMESH::Filter_i* theArg);
TPythonDump&
operator<<(SMESH::Functor_i* theArg);
};
}