From e5c454adf00cdf7b9459742fa43609a503756f20 Mon Sep 17 00:00:00 2001 From: apo Date: Wed, 30 Mar 2005 06:58:37 +0000 Subject: [PATCH] PythonDump for SMESH Controls / Filter --- src/SMESH_I/SMESH_DumpPython.cxx | 344 ++++++++++++++++--------------- src/SMESH_I/SMESH_Filter_i.cxx | 44 +++- src/SMESH_I/SMESH_Gen_i.hxx | 12 ++ src/SMESH_I/SMESH_PythonDump.hxx | 98 +++++---- 4 files changed, 281 insertions(+), 217 deletions(-) diff --git a/src/SMESH_I/SMESH_DumpPython.cxx b/src/SMESH_I/SMESH_DumpPython.cxx index 5a5d3c25a..d6700df0c 100644 --- a/src/SMESH_I/SMESH_DumpPython.cxx +++ b/src/SMESH_I/SMESH_DumpPython.cxx @@ -9,176 +9,10 @@ #include "SMESH_Filter_i.hxx" #include +#include 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<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<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<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<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<(aServant.in()); + return DownCast(thePredicate); } } @@ -322,8 +321,7 @@ inline const SMDS_Mesh* MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh ) { - SMESH_Mesh_i* anImplPtr = - dynamic_cast( SMESH_Gen_i::GetServant( theMesh ).in() ); + SMESH_Mesh_i* anImplPtr = DownCast(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()<GetShapeReader()->GetShape( aGEOMGen, theGeom ); myBelongToGeomPtr->SetGeom( aLocShape ); + TPythonDump()<SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetGeom( getShapeByName( myShapeName ) ); + TPythonDump()<SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType ); + TPythonDump()<SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType ); + TPythonDump()<SetTolerance( theToler ); + TPythonDump()<GetShapeReader()->GetShape( aGEOMGen, theGeom ); myLyingOnGeomPtr->SetGeom( aLocShape ); + TPythonDump()<SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetGeom( getShapeByName( myShapeName ) ); + TPythonDump()<AddToRange( theIds[ i ] ); + TPythonDump()<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()<SetMargin( theValue ); - TPythonDump()<Destroy(); - myNumericalFunctor = dynamic_cast( SMESH_Gen_i::GetServant( theFunct ).in() ); + myNumericalFunctor = DownCast(theFunct); if ( myNumericalFunctor ) { @@ -1107,7 +1120,7 @@ EqualTo_i::EqualTo_i() void EqualTo_i::SetTolerance( CORBA::Double theToler ) { myEqualToPtr->SetTolerance( theToler ); - TPythonDump()<CreateFilter(); aRes->SetCriteria( aCriteriaVar.inout() ); - + + TPythonDump()<(theFilter)) + TPythonDump()<(theFilter)) + TPythonDump()< myPythonScripts; }; + +namespace SMESH +{ + template + T + DownCast(CORBA::Object_ptr theArg) + { + return dynamic_cast(SMESH_Gen_i::GetServant(theArg).in()); + } +} + + #endif diff --git a/src/SMESH_I/SMESH_PythonDump.hxx b/src/SMESH_I/SMESH_PythonDump.hxx index 4894c7159..34545cf65 100644 --- a/src/SMESH_I/SMESH_PythonDump.hxx +++ b/src/SMESH_I/SMESH_PythonDump.hxx @@ -23,63 +23,79 @@ #include #include CORBA_SERVER_HEADER(SMESH_Mesh) -#include +#include 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 - TCollection_AsciiString& - operator<<(T theArg){ - return myString<