From: mzn Date: Wed, 10 Jun 2015 13:33:49 +0000 (+0300) Subject: refs #567: further implementation of the data object. X-Git-Tag: v1.4.1~6^2^2~2^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b67f5f24fd48cf975a3473cbe2f5a023c8238fc7;p=modules%2Fhydro.git refs #567: further implementation of the data object. --- diff --git a/src/HYDROData/HYDROData_LandCover.cxx b/src/HYDROData/HYDROData_LandCover.cxx index a6711927..180f6404 100644 --- a/src/HYDROData/HYDROData_LandCover.cxx +++ b/src/HYDROData/HYDROData_LandCover.cxx @@ -18,6 +18,14 @@ #include "HYDROData_LandCover.h" +#include "HYDROData_PolylineXY.h" + +#include +#include +#include + +#include + IMPLEMENT_STANDARD_HANDLE( HYDROData_LandCover, HYDROData_Entity ) IMPLEMENT_STANDARD_RTTIEXT( HYDROData_LandCover, HYDROData_Entity ) @@ -25,7 +33,6 @@ HYDROData_LandCover::HYDROData_LandCover() { } - HYDROData_LandCover::~HYDROData_LandCover() { } @@ -34,3 +41,121 @@ const ObjectKind HYDROData_LandCover::GetKind() const { return KIND_LAND_COVER; } + +QStringList HYDROData_LandCover::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList aResList = dumpObjectCreation( theTreatedObjects ); + QString aName = GetObjPyName(); + + // Set Strickler type + QString aType = GetStricklerType(); + if ( !aType.isEmpty() ) { + aResList << QString( "" ); + ///< \TODO to be implemented: + // aResList << QString( "%1.SetStricklerType( \"%2\" );" ).arg( aName ).arg( aType ); + aResList << QString( "" ); + } + + // Set polylines + ///< \TODO to be implemented: + + aResList << QString( "" ); + aResList << QString( "%1.Update();" ).arg( aName ); + aResList << QString( "" ); + + return aResList; +} + +HYDROData_SequenceOfObjects HYDROData_LandCover::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects(); + + HYDROData_SequenceOfObjects aSeqOfPolylines = GetPolylines(); + aResSeq.Append( aSeqOfPolylines ); + + return aResSeq; +} + +bool HYDROData_LandCover::IsHas2dPrs() const +{ + return true; +} + +void HYDROData_LandCover::SetStricklerType( const QString& theType ) +{ + TCollection_AsciiString anAsciiStr( theType.toStdString().c_str() ); + TDataStd_AsciiString::Set( myLab.FindChild( DataTag_StricklerType ), anAsciiStr ); +} + +QString HYDROData_LandCover::GetStricklerType() const +{ + QString aType; + + TDF_Label aLabel = myLab.FindChild( DataTag_StricklerType, false ); + if ( !aLabel.IsNull() ) { + Handle(TDataStd_AsciiString) anAsciiStr; + if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) { + aType = QString( anAsciiStr->Get().ToCString() ); + } + } + + return aType; +} + +void HYDROData_LandCover::Update() +{ + HYDROData_Entity::Update(); + + removeShape(); + + TopoDS_Shape aResShape = buildShape(); + + setShape( aResShape ); +} + +void HYDROData_LandCover::SetPolylines( const HYDROData_SequenceOfObjects& thePolylines ) +{ + SetReferenceObjects( thePolylines, DataTag_Polylines ); + SetToUpdate( true ); +} + +HYDROData_SequenceOfObjects HYDROData_LandCover::GetPolylines() const +{ + return GetReferenceObjects( DataTag_Polylines ); +} + +void HYDROData_LandCover::setShape( const TopoDS_Shape& theShape ) +{ + TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) ); + aBuilder.Generated( theShape ); +} + +void HYDROData_LandCover::removeShape() +{ + TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false ); + if ( !aLabel.IsNull() ) { + aLabel.ForgetAllAttributes(); + } +} + +TopoDS_Shape HYDROData_LandCover::buildShape() const +{ + TopoDS_Shape aResShape; + + ///< \TODO to be reimplemented + HYDROData_SequenceOfObjects aRefPolylines = GetPolylines(); + for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) { + Handle(HYDROData_PolylineXY) aPolyline = + Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) ); + + if ( aPolyline.IsNull() ) { + continue; + } + + if ( aPolyline->IsClosed() ) { + aResShape = aPolyline->GetShape(); + break; + } + } + return aResShape; +} \ No newline at end of file diff --git a/src/HYDROData/HYDROData_LandCover.h b/src/HYDROData/HYDROData_LandCover.h index 246208e3..d740e7b4 100644 --- a/src/HYDROData/HYDROData_LandCover.h +++ b/src/HYDROData/HYDROData_LandCover.h @@ -23,6 +23,8 @@ DEFINE_STANDARD_HANDLE( HYDROData_LandCover, HYDROData_Entity ) +class TopoDS_Shape; + class HYDROData_LandCover : public HYDROData_Entity { protected: @@ -30,7 +32,10 @@ protected: enum DataTag { - DataTag_Table = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve + DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve + DataTag_Shape, ///< the shape presentation of the land cover + DataTag_StricklerType, ///< the type corresponding to types in the Strickler tables + DataTag_Polylines ///< the set of reference polylines }; HYDRODATA_EXPORT HYDROData_LandCover(); @@ -39,7 +44,66 @@ protected: public: DEFINE_STANDARD_RTTI( HYDROData_LandCover ); + /** + */ HYDRODATA_EXPORT virtual const ObjectKind GetKind() const; + + /** + * Dump object to Python script representation. + */ + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + + /** + * Update the shape presentation of the land cover. + * Call this method whenever you made changes for land cover polylines. + */ + HYDRODATA_EXPORT virtual void Update(); + + /** + * Checks that object has 2D presentation. Reimlemented to return true. + */ + HYDRODATA_EXPORT virtual bool IsHas2dPrs() const; + + /** + * Set Strickler type for the land cover. + */ + HYDRODATA_EXPORT virtual void SetStricklerType( const QString& theType ); + + /** + * Returns Strickler type for the land cover. + */ + HYDRODATA_EXPORT virtual QString GetStricklerType() const; + + /** + * Set reference polyline objects for the land cover. + */ + HYDRODATA_EXPORT virtual void SetPolylines( const HYDROData_SequenceOfObjects& thePolylines ); + + /** + * Returns all reference polyline objects of the land cover. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetPolylines() const; + +protected: + /** + * Sets shape presentation of the land cover. + */ + HYDRODATA_EXPORT virtual void setShape( const TopoDS_Shape& theShape ); + + /** + * Removes the shape from data label of the land cover object. + */ + HYDRODATA_EXPORT virtual void removeShape(); + + /** + * Build the shape presentation of the land cover. + */ + HYDRODATA_EXPORT virtual TopoDS_Shape buildShape() const; }; #endif