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()
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 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
96 void HYDROData_ImmersibleZone::Update()
98 HYDROData_NaturalObject::Update();
100 TopoDS_Shape aResShape = generateTopShape();
101 SetTopShape( aResShape );
103 createGroupObjects();
106 bool HYDROData_ImmersibleZone::IsHas2dPrs() const
111 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
113 return generateTopShape( GetPolyline() );
116 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
118 TopoDS_Face aResultFace = TopoDS_Face();
120 if( !aPolyline.IsNull() )
122 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
123 TopTools_ListOfShape aWiresList;
125 if ( !aPolylineShape.IsNull() &&
126 aPolylineShape.ShapeType() == TopAbs_WIRE ) {
127 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
128 if ( !aPolylineWire.IsNull() ) {
129 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
131 if( aMakeFace.IsDone() ) {
132 aResultFace = aMakeFace.Face();
136 TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
137 for ( ; anExp.More(); anExp.Next() ) {
138 if(!anExp.Current().IsNull()) {
139 const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
140 aWiresList.Append( aWire );
143 if(aWiresList.IsEmpty())
146 BRepAlgo_FaceRestrictor aFR;
147 TopoDS_Face aRefFace;
148 TopoDS_Shape aS = aWiresList.First();
149 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
151 if( aMakeFace.IsDone() ) {
152 aRefFace = aMakeFace.Face();
154 if(aRefFace.IsNull())
157 aFR.Init(aRefFace,Standard_False, Standard_True);
158 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
159 for ( ; anIt.More(); anIt.Next() ) {
160 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
161 if ( aWire.IsNull() )
167 for (; aFR.More(); aFR.Next()) {
168 aResultFace = aFR.Current();
175 if( aResultFace.IsNull() )
178 BRepCheck_Analyzer anAnalyzer( aResultFace );
179 if( anAnalyzer.IsValid() && aResultFace.ShapeType()==TopAbs_FACE )
182 return TopoDS_Face();
185 void HYDROData_ImmersibleZone::createGroupObjects()
187 TopoDS_Shape aZoneShape = GetTopShape();
189 // Temporary solution while the restriction for polylines is not implemented
190 // and shape for zone can be compound and not face only
191 if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
193 TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
194 if ( aZoneFaceExp.More() )
195 aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
198 if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
201 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
203 TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
205 // Create outer edges group
206 QString anOutWiresGroupName = GetName() + "_Outer";
208 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
209 anOutWiresGroup->SetName( anOutWiresGroupName );
211 TopTools_SequenceOfShape anOuterEdges;
212 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anOuterEdges );
213 anOutWiresGroup->SetShapes( anOuterEdges );
215 int anInnerCounter = 1;
216 TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
217 for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
219 TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
220 if ( aZoneWire.IsEqual( aZoneOuterWire ) )
221 continue; // Skip the outer wire
223 TopTools_SequenceOfShape anInnerEdges;
224 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anInnerEdges );
225 if ( anInnerEdges.IsEmpty() )
228 QString anInWiresGroupName = GetName() + "_Inner_" + QString::number( anInnerCounter++ );
230 Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
231 anInWiresGroup->SetName( anInWiresGroupName );
233 anInWiresGroup->SetShapes( anInnerEdges );
237 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
239 return getTopShape();
242 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
244 return QColor( Qt::darkBlue );
247 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
249 return QColor( Qt::transparent );
252 QColor HYDROData_ImmersibleZone::getDefaultFillingColor() const
254 return DefaultFillingColor();
257 QColor HYDROData_ImmersibleZone::getDefaultBorderColor() const
259 return DefaultBorderColor();
262 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
264 SetReferenceObject( thePolyline, DataTag_Polyline );
268 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
270 return Handle(HYDROData_PolylineXY)::DownCast(
271 GetReferenceObject( DataTag_Polyline ) );
274 void HYDROData_ImmersibleZone::RemovePolyline()
276 ClearReferenceObjects( DataTag_Polyline );