]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #567: further implementation of the data object.
authormzn <mzn@opencascade.com>
Wed, 10 Jun 2015 13:33:49 +0000 (16:33 +0300)
committermzn <mzn@opencascade.com>
Wed, 10 Jun 2015 13:33:49 +0000 (16:33 +0300)
src/HYDROData/HYDROData_LandCover.cxx
src/HYDROData/HYDROData_LandCover.h

index a6711927d453ca986bd6ea938e9e38694990fbe6..180f640481f2297b78088bdf50be42e764296068 100644 (file)
 
 #include "HYDROData_LandCover.h"
 
+#include "HYDROData_PolylineXY.h"
+
+#include <TDataStd_AsciiString.hxx>
+#include <TNaming_Builder.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <QStringList>
+
 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
index 246208e320dc0837d40ca98cafb9bd378259e46d..d740e7b4d765351c61289447aeb1c5d4a8db55a8 100644 (file)
@@ -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