Salome HOME
porting on Linux
[modules/hydro.git] / src / HYDROData / HYDROData_LandCover.cxx
index a6711927d453ca986bd6ea938e9e38694990fbe6..3680865ca4a39b611265412e37f81b1c11311233 100644 (file)
 
 #include "HYDROData_LandCover.h"
 
+#include "HYDROData_PolylineXY.h"
+
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <TDataStd_AsciiString.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <NCollection_IncAllocator.hxx>
+#include <BOPAlgo_BOP.hxx>
+
+#include <QColor>
+#include <QStringList>
+
 IMPLEMENT_STANDARD_HANDLE( HYDROData_LandCover, HYDROData_Entity )
 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_LandCover, HYDROData_Entity )
 
@@ -25,7 +43,6 @@ HYDROData_LandCover::HYDROData_LandCover()
 {
 }
 
-
 HYDROData_LandCover::~HYDROData_LandCover()
 {
 }
@@ -34,3 +51,218 @@ 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 );
+}
+
+TopoDS_Shape HYDROData_LandCover::GetShape() const
+{
+  TopoDS_Shape aShape;
+
+  TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
+  if ( !aLabel.IsNull() )
+  {
+    Handle(TNaming_NamedShape) aNamedShape;
+    if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) {
+      aShape = aNamedShape->Get();
+    }
+  }
+
+  return aShape;
+}
+
+void HYDROData_LandCover::SetFillingColor( const QColor& theColor )
+{
+  SetColor( theColor, DataTag_FillingColor );
+}
+
+QColor HYDROData_LandCover::GetFillingColor() const
+{
+  return GetColor( DefaultFillingColor(), DataTag_FillingColor );
+}
+
+void HYDROData_LandCover::SetBorderColor( const QColor& theColor )
+{
+  SetColor( theColor, DataTag_BorderColor );
+}
+
+QColor HYDROData_LandCover::GetBorderColor() const
+{
+  return GetColor( DefaultBorderColor(), DataTag_BorderColor );
+}
+
+QColor HYDROData_LandCover::DefaultFillingColor()
+{
+  return QColor( Qt::magenta );
+}
+
+QColor HYDROData_LandCover::DefaultBorderColor()
+{
+  return QColor( Qt::transparent );
+}
+
+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
+  TopoDS_Shape anArgShape;
+  TopTools_ListOfShape aToolShapes;
+  
+  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() ) {
+      continue;
+    }
+
+    TopoDS_Shape aPolyShape = aPolyline->GetShape();
+    if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) {
+      continue;
+    }
+
+    const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape );
+    if ( aPolylineWire.IsNull() ) {
+      continue;
+    }
+
+    TopoDS_Face aResultFace = TopoDS_Face();
+    BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
+    aMakeFace.Build();
+    if( aMakeFace.IsDone() ) {
+      aResultFace = aMakeFace.Face();
+    }
+
+    if( aResultFace.IsNull() ) {
+      continue;
+    }
+
+    if ( anArgShape.IsNull() ) {
+      anArgShape = aResultFace;
+    } else {
+      aToolShapes.Append( aResultFace );
+    }
+  }
+
+  aResShape = anArgShape;
+
+  if ( !anArgShape.IsNull() && aToolShapes.Extent() > 0 ) {
+    Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
+    BOPAlgo_BOP aBOP(aAL);
+    aBOP.AddArgument( anArgShape );
+
+    TopTools_ListIteratorOfListOfShape anIt(aToolShapes);
+    for( ; anIt.More(); anIt.Next() ) {
+      aBOP.AddTool( anIt.Value() );
+    }
+
+    aBOP.SetOperation( BOPAlgo_CUT );
+    aBOP.Perform();
+
+    if ( !aBOP.Shape().IsNull() ) {
+      aResShape = aBOP.Shape();
+    }
+  }
+  
+  return aResShape;
+}
\ No newline at end of file