From aeadd52c3b71b69f7ed83b7ec49797c4905a420c Mon Sep 17 00:00:00 2001 From: adv Date: Wed, 11 Sep 2013 07:10:22 +0000 Subject: [PATCH] Dump Polyline data to python script (Feature #13). --- src/HYDROData/HYDROData_Polyline.cxx | 85 ++++++++++++++++++++++++++-- src/HYDROData/HYDROData_Polyline.h | 16 +++++- src/HYDROPy/HYDROData_Polyline.sip | 8 ++- 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/src/HYDROData/HYDROData_Polyline.cxx b/src/HYDROData/HYDROData_Polyline.cxx index 4360cc15..7db4062a 100755 --- a/src/HYDROData/HYDROData_Polyline.cxx +++ b/src/HYDROData/HYDROData_Polyline.cxx @@ -12,10 +12,13 @@ #include #include +#include // tage of the child of my label that contains information about the operator static const Standard_GUID GUID_MUST_BE_UPDATED("6647e1f7-1971-4c5a-86c7-11ff0291452d"); +#define PYTHON_POLYLINE_ID "2" + IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline, HYDROData_Object) @@ -27,6 +30,80 @@ HYDROData_Polyline::~HYDROData_Polyline() { } +/** + * Dump object to Python script representation. + */ +QStringList HYDROData_Polyline::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList aResList; + + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this ); + if ( aDocument.IsNull() ) + return aResList; + + QString aDocName = aDocument->GetDocPyName(); + QString aPolylineName = GetName(); + + aResList << QString( "%1 = %2.CreateObject( %3 );" ) + .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINE_ID ); + aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName ); + + // Set polilyne dimension + + aResList << QString( "" ); + + int aDim = getDimension(); + aResList << QString( "%1.setDimension( %2 );" ) + .arg( aPolylineName ).arg( aDim ); + + // Set polilyne data + + PolylineData aPolylineData = getPolylineData(); + if ( !aPolylineData.isEmpty() ) + { + QString aPolylineDataName = "polyline_data"; + + aResList << QString( "" ); + aResList << QString( "%1 = [];" ).arg( aPolylineDataName ); + + PolylineData::const_iterator aDataIt = aPolylineData.constBegin(); + for ( ; aDataIt != aPolylineData.constEnd(); ++aDataIt ) + { + const PolylineSection& aSection = *aDataIt; + + QString aPolylineSectName = "polyline_section"; + + aResList << QString( "" ); + aResList << QString( "%1 = PolylineSection();" ).arg( aPolylineSectName ); + + QString aCoordsStr; + foreach( const double& aCoordVal, aSection.myCoords ) + aCoordsStr += QString::number( aCoordVal ) + ", "; + aCoordsStr.remove( aCoordsStr.length() - 2, 2 ); + + aResList << QString( "" ); + + aResList << QString( "%1.mySectionName = \"%2\";" ) + .arg( aPolylineSectName ) + .arg( TCollection_AsciiString( aSection.mySectionName ).ToCString() ); + aResList << QString( "%1.myType = %2;" ) + .arg( aPolylineSectName ).arg( aSection.myType ); + aResList << QString( "%1.myIsClosed = %2;" ) + .arg( aPolylineSectName ).arg( aSection.myIsClosed ); + aResList << QString( "%1.myCoords = [ %2 ];" ) + .arg( aPolylineSectName ).arg( aCoordsStr ); + + aResList << QString( "%1.append( %2 );" ) + .arg( aPolylineDataName ).arg( aPolylineSectName ); + } + + aResList << QString( "%1.setPolylineData( %2 );" ) + .arg( aPolylineName ).arg( aPolylineDataName ); + } + + return aResList; +} + /** * Return polyline dimension * \return polyline dimension. 2 or 3 is valid. 0 is invalid. @@ -57,7 +134,7 @@ void HYDROData_Polyline::setDimension( int theDimension ) * Replace current polyline data by new sections list * \param theSections the sections list */ -void HYDROData_Polyline::setPolylineData( const QList& theSections ) +void HYDROData_Polyline::setPolylineData( const PolylineData& theSections ) { //Keep dimension int aDim = getDimension(); @@ -117,10 +194,10 @@ void HYDROData_Polyline::setPolylineData( const QList& theSecti * Return polyline data * \return polyline section list */ -QList HYDROData_Polyline::getPolylineData() +HYDROData_Polyline::PolylineData HYDROData_Polyline::getPolylineData() const { int aSectCnt; - QList aRes; + PolylineData aRes; //Get sections size array handle TDF_Label aLab = myLab.FindChild( DataTag_SectionsSize ); Handle(TDataStd_IntegerArray) aSizeArray; @@ -204,7 +281,7 @@ QPainterPath HYDROData_Polyline::painterPath() int aDim = getDimension(); if( ( aDim != 2 ) && ( aDim != 3) ) return aPath; - QList aSects = getPolylineData(); + PolylineData aSects = getPolylineData(); for( int i = 0 ; i < aSects.size() ; i++ ){ int aPntCnt = aSects[i].myCoords.size()/aDim; if( aPntCnt ){ diff --git a/src/HYDROData/HYDROData_Polyline.h b/src/HYDROData/HYDROData_Polyline.h index 73a06a53..8dc6dced 100755 --- a/src/HYDROData/HYDROData_Polyline.h +++ b/src/HYDROData/HYDROData_Polyline.h @@ -11,7 +11,8 @@ DEFINE_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object) -struct PolylineSection{ +struct PolylineSection +{ public: enum SectionType{ SECTION_POLYLINE=0, SECTION_SPLINE=1 }; @@ -30,6 +31,10 @@ public: */ class HYDROData_Polyline : public HYDROData_Object { +public: + + typedef QList PolylineData; + protected: /** * Enumeration of tags corresponding to the persistent object parameters. @@ -51,17 +56,22 @@ public: */ HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_POLYLINE;} + /** + * Dump object to Python script representation. + */ + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + /** * Replace current polyline data by new sections list * \param theSections the sections list */ - HYDRODATA_EXPORT void setPolylineData( const QList& theSections ); + HYDRODATA_EXPORT void setPolylineData( const PolylineData& theSections ); /** * Return polyline data * \return polyline section list */ - HYDRODATA_EXPORT QList getPolylineData(); + HYDRODATA_EXPORT PolylineData getPolylineData() const; /** * Return polyline dimension diff --git a/src/HYDROPy/HYDROData_Polyline.sip b/src/HYDROPy/HYDROData_Polyline.sip index f3b5c582..d0a8b1ce 100644 --- a/src/HYDROPy/HYDROData_Polyline.sip +++ b/src/HYDROPy/HYDROData_Polyline.sip @@ -69,6 +69,10 @@ class HYDROData_Polyline : HYDROData_Object sipClass = NULL; %End +public: + + typedef QList PolylineData; + public: const ObjectKind GetKind() const; @@ -79,13 +83,13 @@ public: * Replace current polyline data by new sections list * \param theSections the sections list */ - void setPolylineData( const QList& theSections ); + void setPolylineData( const PolylineData& theSections ); /** * Return polyline data * \return polyline section list */ - QList getPolylineData(); + PolylineData getPolylineData(); /** * Return polyline dimension -- 2.39.2