1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_LandCover.h"
21 #include "HYDROData_PolylineXY.h"
23 #include <BRepBuilderAPI_MakeFace.hxx>
24 #include <TDataStd_AsciiString.hxx>
25 #include <TNaming_Builder.hxx>
26 #include <TNaming_NamedShape.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopoDS_Wire.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TopTools_ListOfShape.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
33 #include <NCollection_IncAllocator.hxx>
34 #include <BOPAlgo_BOP.hxx>
37 #include <QStringList>
39 IMPLEMENT_STANDARD_HANDLE( HYDROData_LandCover, HYDROData_Entity )
40 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_LandCover, HYDROData_Entity )
42 HYDROData_LandCover::HYDROData_LandCover()
46 HYDROData_LandCover::~HYDROData_LandCover()
50 const ObjectKind HYDROData_LandCover::GetKind() const
52 return KIND_LAND_COVER;
55 QStringList HYDROData_LandCover::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
57 QStringList aResList = dumpObjectCreation( theTreatedObjects );
58 QString aName = GetObjPyName();
61 QString aType = GetStricklerType();
62 if ( !aType.isEmpty() ) {
63 aResList << QString( "" );
64 ///< \TODO to be implemented:
65 // aResList << QString( "%1.SetStricklerType( \"%2\" );" ).arg( aName ).arg( aType );
66 aResList << QString( "" );
70 ///< \TODO to be implemented:
72 aResList << QString( "" );
73 aResList << QString( "%1.Update();" ).arg( aName );
74 aResList << QString( "" );
79 HYDROData_SequenceOfObjects HYDROData_LandCover::GetAllReferenceObjects() const
81 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
83 HYDROData_SequenceOfObjects aSeqOfPolylines = GetPolylines();
84 aResSeq.Append( aSeqOfPolylines );
89 bool HYDROData_LandCover::IsHas2dPrs() const
94 void HYDROData_LandCover::SetStricklerType( const QString& theType )
96 TCollection_AsciiString anAsciiStr( theType.toStdString().c_str() );
97 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_StricklerType ), anAsciiStr );
100 QString HYDROData_LandCover::GetStricklerType() const
104 TDF_Label aLabel = myLab.FindChild( DataTag_StricklerType, false );
105 if ( !aLabel.IsNull() ) {
106 Handle(TDataStd_AsciiString) anAsciiStr;
107 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) {
108 aType = QString( anAsciiStr->Get().ToCString() );
115 void HYDROData_LandCover::Update()
117 HYDROData_Entity::Update();
121 TopoDS_Shape aResShape = buildShape();
123 setShape( aResShape );
126 void HYDROData_LandCover::SetPolylines( const HYDROData_SequenceOfObjects& thePolylines )
128 SetReferenceObjects( thePolylines, DataTag_Polylines );
132 HYDROData_SequenceOfObjects HYDROData_LandCover::GetPolylines() const
134 return GetReferenceObjects( DataTag_Polylines );
137 TopoDS_Shape HYDROData_LandCover::GetShape() const
141 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
142 if ( !aLabel.IsNull() )
144 Handle(TNaming_NamedShape) aNamedShape;
145 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) {
146 aShape = aNamedShape->Get();
153 void HYDROData_LandCover::SetFillingColor( const QColor& theColor )
155 SetColor( theColor, DataTag_FillingColor );
158 QColor HYDROData_LandCover::GetFillingColor() const
160 return GetColor( DefaultFillingColor(), DataTag_FillingColor );
163 void HYDROData_LandCover::SetBorderColor( const QColor& theColor )
165 SetColor( theColor, DataTag_BorderColor );
168 QColor HYDROData_LandCover::GetBorderColor() const
170 return GetColor( DefaultBorderColor(), DataTag_BorderColor );
173 QColor HYDROData_LandCover::DefaultFillingColor()
175 return QColor( Qt::magenta );
178 QColor HYDROData_LandCover::DefaultBorderColor()
180 return QColor( Qt::transparent );
183 void HYDROData_LandCover::setShape( const TopoDS_Shape& theShape )
185 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
186 aBuilder.Generated( theShape );
189 void HYDROData_LandCover::removeShape()
191 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
192 if ( !aLabel.IsNull() ) {
193 aLabel.ForgetAllAttributes();
197 TopoDS_Shape HYDROData_LandCover::buildShape() const
199 TopoDS_Shape aResShape;
201 ///< \TODO to be reimplemented
202 TopoDS_Shape anArgShape;
203 TopTools_ListOfShape aToolShapes;
205 HYDROData_SequenceOfObjects aRefPolylines = GetPolylines();
206 for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) {
207 Handle(HYDROData_PolylineXY) aPolyline =
208 Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) );
210 if ( aPolyline.IsNull() ) {
214 if ( !aPolyline->IsClosed() ) {
218 TopoDS_Shape aPolyShape = aPolyline->GetShape();
219 if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) {
223 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape );
224 if ( aPolylineWire.IsNull() ) {
228 TopoDS_Face aResultFace = TopoDS_Face();
229 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
231 if( aMakeFace.IsDone() ) {
232 aResultFace = aMakeFace.Face();
235 if( aResultFace.IsNull() ) {
239 if ( anArgShape.IsNull() ) {
240 anArgShape = aResultFace;
242 aToolShapes.Append( aResultFace );
246 aResShape = anArgShape;
248 if ( !anArgShape.IsNull() && aToolShapes.Extent() > 0 ) {
249 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
250 BOPAlgo_BOP aBOP(aAL);
252 aBOP.AddArgument( anArgShape );
254 TopTools_ListIteratorOfListOfShape anIt(aToolShapes);
255 for( ; anIt.More(); anIt.Next() ) {
256 aBOP.AddTool( anIt.Value() );
259 aBOP.SetOperation( BOPAlgo_CUT );
262 if ( !aBOP.Shape().IsNull() ) {
263 aResShape = aBOP.Shape();