1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_ImmersibleZone.h"
25 #include "HYDROData_IAltitudeObject.h"
26 #include "HYDROData_Document.h"
27 #include "HYDROData_ShapesGroup.h"
28 #include "HYDROData_PolylineXY.h"
29 #include "HYDROData_ShapesTool.h"
31 #include <BRepBuilderAPI_MakeFace.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopoDS_Compound.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <BRep_Builder.hxx>
41 #include <BRepAlgo_FaceRestrictor.hxx>
42 #include <BRepCheck_Analyzer.hxx>
44 #include <ShapeAnalysis.hxx>
47 #include <QStringList>
49 //#define HYDRODATA_IMZONE_DEB 1
51 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
52 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
55 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
56 : HYDROData_NaturalObject()
60 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
64 QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
66 QStringList aResList = dumpObjectCreation( theTreatedObjects );
68 QString aZoneName = GetObjPyName();
70 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
71 setPythonReferenceObject( theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" );
73 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
74 setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
76 aResList << QString( "" );
78 aResList << QString( "%1.Update();" ).arg( aZoneName );
79 aResList << QString( "" );
84 HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const
86 HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects();
88 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
89 if ( !aRefPolyline.IsNull() )
90 aResSeq.Append( aRefPolyline );
95 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
100 void HYDROData_ImmersibleZone::Update()
102 HYDROData_NaturalObject::Update();
104 TopoDS_Shape aResShape = generateTopShape();
105 SetTopShape( aResShape );
107 createGroupObjects();
110 bool HYDROData_ImmersibleZone::IsHas2dPrs() const
115 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
117 return generateTopShape( GetPolyline() );
120 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
122 TopoDS_Face aResultFace = TopoDS_Face();
124 if( !aPolyline.IsNull() )
126 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
127 TopTools_ListOfShape aWiresList;
129 if ( !aPolylineShape.IsNull() &&
130 aPolylineShape.ShapeType() == TopAbs_WIRE ) {
131 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
132 if ( !aPolylineWire.IsNull() ) {
133 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
135 if( aMakeFace.IsDone() ) {
136 aResultFace = aMakeFace.Face();
140 TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
141 for ( ; anExp.More(); anExp.Next() ) {
142 if(!anExp.Current().IsNull()) {
143 const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
144 aWiresList.Append( aWire );
147 if(aWiresList.IsEmpty())
150 BRepAlgo_FaceRestrictor aFR;
151 TopoDS_Face aRefFace;
152 TopoDS_Shape aS = aWiresList.First();
153 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
155 if( aMakeFace.IsDone() ) {
156 aRefFace = aMakeFace.Face();
158 if(aRefFace.IsNull())
161 aFR.Init(aRefFace,Standard_False, Standard_True);
162 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
163 for ( ; anIt.More(); anIt.Next() ) {
164 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
165 if ( aWire.IsNull() )
171 for (; aFR.More(); aFR.Next()) {
172 aResultFace = aFR.Current();
179 if( aResultFace.IsNull() )
182 BRepCheck_Analyzer anAnalyzer( aResultFace );
183 if( anAnalyzer.IsValid() && aResultFace.ShapeType()==TopAbs_FACE )
186 return TopoDS_Face();
189 void HYDROData_ImmersibleZone::createGroupObjects()
191 TopoDS_Shape aZoneShape = GetTopShape();
193 // Temporary solution while the restriction for polylines is not implemented
194 // and shape for zone can be compound and not face only
195 if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
197 TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
198 if ( aZoneFaceExp.More() )
199 aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
202 if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
205 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
207 TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
209 // Create outer edges group
210 QString anOutWiresGroupName = GetName() + "_Outer";
212 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
213 anOutWiresGroup->SetName( anOutWiresGroupName );
215 TopTools_SequenceOfShape anOuterEdges;
216 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anOuterEdges );
217 anOutWiresGroup->SetShapes( anOuterEdges );
219 int anInnerCounter = 1;
220 TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
221 for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
223 TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
224 if ( aZoneWire.IsEqual( aZoneOuterWire ) )
225 continue; // Skip the outer wire
227 TopTools_SequenceOfShape anInnerEdges;
228 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anInnerEdges );
229 if ( anInnerEdges.IsEmpty() )
232 QString anInWiresGroupName = GetName() + "_Inner_" + QString::number( anInnerCounter++ );
234 Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
235 anInWiresGroup->SetName( anInWiresGroupName );
237 anInWiresGroup->SetShapes( anInnerEdges );
241 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
243 return getTopShape();
246 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
248 return QColor( Qt::darkBlue );
251 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
253 return QColor( Qt::transparent );
256 QColor HYDROData_ImmersibleZone::getDefaultFillingColor() const
258 return DefaultFillingColor();
261 QColor HYDROData_ImmersibleZone::getDefaultBorderColor() const
263 return DefaultBorderColor();
266 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
268 SetReferenceObject( thePolyline, DataTag_Polyline );
272 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
274 return Handle(HYDROData_PolylineXY)::DownCast(
275 GetReferenceObject( DataTag_Polyline ) );
278 void HYDROData_ImmersibleZone::RemovePolyline()
280 ClearReferenceObjects( DataTag_Polyline );