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_ImmersibleZone.h"
21 #include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_PolylineXY.h"
25 #include "HYDROData_ShapesTool.h"
27 #include <BRepBuilderAPI_MakeFace.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <TopTools_ListIteratorOfListOfShape.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRepAlgo_FaceRestrictor.hxx>
38 #include <BRepCheck_Analyzer.hxx>
40 #include <ShapeAnalysis.hxx>
43 #include <QStringList>
45 //#define HYDRODATA_IMZONE_DEB 1
47 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
48 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
51 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
52 : HYDROData_NaturalObject( Geom_2d )
56 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
60 QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
62 QStringList aResList = dumpObjectCreation( theTreatedObjects );
64 QString aZoneName = GetObjPyName();
66 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
67 setPythonReferenceObject( theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" );
69 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
70 setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
72 aResList << QString( "" );
74 aResList << QString( "%1.Update();" ).arg( aZoneName );
75 aResList << QString( "" );
80 HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const
82 HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects();
84 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
85 if ( !aRefPolyline.IsNull() )
86 aResSeq.Append( aRefPolyline );
91 void HYDROData_ImmersibleZone::Update()
93 HYDROData_NaturalObject::Update();
95 TopoDS_Shape aResShape = generateTopShape();
96 SetTopShape( aResShape );
101 bool HYDROData_ImmersibleZone::IsHas2dPrs() const
106 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
108 return generateTopShape( GetPolyline() );
111 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
113 TopoDS_Face aResultFace = TopoDS_Face();
115 if( !aPolyline.IsNull() )
117 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
118 TopTools_ListOfShape aWiresList;
120 if ( !aPolylineShape.IsNull() &&
121 aPolylineShape.ShapeType() == TopAbs_WIRE ) {
122 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
123 if ( !aPolylineWire.IsNull() ) {
124 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
126 if( aMakeFace.IsDone() ) {
127 aResultFace = aMakeFace.Face();
131 TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
132 for ( ; anExp.More(); anExp.Next() ) {
133 if(!anExp.Current().IsNull()) {
134 const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
135 aWiresList.Append( aWire );
138 if(aWiresList.IsEmpty())
141 BRepAlgo_FaceRestrictor aFR;
142 TopoDS_Face aRefFace;
143 TopoDS_Shape aS = aWiresList.First();
144 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
146 if( aMakeFace.IsDone() ) {
147 aRefFace = aMakeFace.Face();
149 if(aRefFace.IsNull())
152 aFR.Init(aRefFace,Standard_False, Standard_True);
153 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
154 for ( ; anIt.More(); anIt.Next() ) {
155 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
156 if ( aWire.IsNull() )
162 for (; aFR.More(); aFR.Next()) {
163 aResultFace = aFR.Current();
170 if( aResultFace.IsNull() )
173 BRepCheck_Analyzer anAnalyzer( aResultFace );
174 if( anAnalyzer.IsValid() && aResultFace.ShapeType()==TopAbs_FACE )
177 return TopoDS_Face();
180 void HYDROData_ImmersibleZone::createGroupObjects()
182 TopoDS_Shape aZoneShape = GetTopShape();
184 // Temporary solution while the restriction for polylines is not implemented
185 // and shape for zone can be compound and not face only
186 if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
188 TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
189 if ( aZoneFaceExp.More() )
190 aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
193 if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
196 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
198 TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
200 // Create outer edges group
201 QString anOutWiresGroupName = GetName() + "_Outer";
203 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
204 anOutWiresGroup->SetName( anOutWiresGroupName );
206 TopTools_SequenceOfShape anOuterEdges;
207 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anOuterEdges );
208 anOutWiresGroup->SetShapes( anOuterEdges );
210 int anInnerCounter = 1;
211 TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
212 for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
214 TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
215 if ( aZoneWire.IsEqual( aZoneOuterWire ) )
216 continue; // Skip the outer wire
218 TopTools_SequenceOfShape anInnerEdges;
219 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anInnerEdges );
220 if ( anInnerEdges.IsEmpty() )
223 QString anInWiresGroupName = GetName() + "_Inner_" + QString::number( anInnerCounter++ );
225 Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
226 anInWiresGroup->SetName( anInWiresGroupName );
228 anInWiresGroup->SetShapes( anInnerEdges );
232 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
234 return GetTopShape();
237 QColor HYDROData_ImmersibleZone::DefaultFillingColor() const
239 return QColor( Qt::darkBlue );
242 QColor HYDROData_ImmersibleZone::DefaultBorderColor() const
244 return QColor( Qt::transparent );
247 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
249 if( IsEqual( GetPolyline(), thePolyline ) )
252 SetReferenceObject( thePolyline, DataTag_Polyline );
256 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
258 return Handle(HYDROData_PolylineXY)::DownCast(
259 GetReferenceObject( DataTag_Polyline ) );
262 void HYDROData_ImmersibleZone::RemovePolyline()
264 ClearReferenceObjects( DataTag_Polyline );