2 #include "HYDROData_ImmersibleZone.h"
4 #include "HYDROData_IAltitudeObject.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_ShapesGroup.h"
7 #include "HYDROData_PolylineXY.h"
8 #include "HYDROData_ShapesTool.h"
10 #include <BRepBuilderAPI_MakeFace.hxx>
13 #include <TopoDS_Face.hxx>
14 #include <TopoDS_Wire.hxx>
15 #include <TopoDS_Compound.hxx>
16 #include <TopExp_Explorer.hxx>
17 #include <TopTools_ListIteratorOfListOfShape.hxx>
19 #include <BRep_Builder.hxx>
20 #include <BRepAlgo_FaceRestrictor.hxx>
21 #include <BRepCheck_Analyzer.hxx>
23 #include <ShapeAnalysis.hxx>
26 #include <QStringList>
28 //#define HYDRODATA_IMZONE_DEB 1
30 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
31 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
34 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
35 : HYDROData_NaturalObject()
39 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
43 QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
45 QStringList aResList = HYDROData_Entity::DumpToPython( theTreatedObjects );
46 QString aZoneName = GetName();
48 QColor aFillingColor = GetFillingColor();
49 aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
50 .arg( aFillingColor.red() ).arg( aFillingColor.green() )
51 .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
52 aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName );
53 aResList << QString( "" );
55 QColor aBorderColor = GetBorderColor();
56 aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
57 .arg( aBorderColor.red() ).arg( aBorderColor.green() )
58 .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
59 aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName );
60 aResList << QString( "" );
62 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
63 setPythonReferenceObject( theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" );
65 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
66 setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
71 HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const
73 HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects();
75 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
76 if ( !aRefPolyline.IsNull() )
77 aResSeq.Append( aRefPolyline );
82 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
87 void HYDROData_ImmersibleZone::Update()
89 HYDROData_NaturalObject::Update();
91 TopoDS_Shape aResShape = generateTopShape();
92 SetTopShape( aResShape );
97 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
99 return generateTopShape( GetPolyline() );
102 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
104 TopoDS_Face aResultFace = TopoDS_Face();
106 if( !aPolyline.IsNull() )
108 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
109 TopTools_ListOfShape aWiresList;
111 if ( !aPolylineShape.IsNull() &&
112 aPolylineShape.ShapeType() == TopAbs_WIRE ) {
113 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
114 if ( !aPolylineWire.IsNull() ) {
115 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
117 if( aMakeFace.IsDone() ) {
118 return aMakeFace.Face();
122 TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
123 for ( ; anExp.More(); anExp.Next() ) {
124 if(!anExp.Current().IsNull()) {
125 const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
126 aWiresList.Append( aWire );
129 if(aWiresList.IsEmpty())
132 BRepAlgo_FaceRestrictor aFR;
133 TopoDS_Face aRefFace;
134 TopoDS_Shape aS = aWiresList.First();
135 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
137 if( aMakeFace.IsDone() ) {
138 aRefFace = aMakeFace.Face();
140 if(aRefFace.IsNull())
143 aFR.Init(aRefFace,Standard_False, Standard_True);
144 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
145 for ( ; anIt.More(); anIt.Next() ) {
146 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
147 if ( aWire.IsNull() )
153 for (; aFR.More(); aFR.Next()) {
154 aResultFace = aFR.Current();
161 if( aResultFace.IsNull() )
164 BRepCheck_Analyzer anAnalyzer( aResultFace );
165 if( anAnalyzer.IsValid() && aResultFace.ShapeType()==TopAbs_FACE )
168 return TopoDS_Face();
171 void HYDROData_ImmersibleZone::createGroupObjects()
173 TopoDS_Shape aZoneShape = GetTopShape();
175 // Temporary solution while the restriction for polylines is not implemented
176 // and shape for zone can be compound and not face only
177 if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
179 TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
180 if ( aZoneFaceExp.More() )
181 aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
184 if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
187 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
189 TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
191 // Create outer edges group
192 QString anOutWiresGroupName = GetName() + "_Outer";
194 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
195 anOutWiresGroup->SetName( anOutWiresGroupName );
197 TopTools_SequenceOfShape anOuterEdges;
198 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anOuterEdges );
199 anOutWiresGroup->SetShapes( anOuterEdges );
201 int anInnerCounter = 1;
202 TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
203 for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
205 TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
206 if ( aZoneWire.IsEqual( aZoneOuterWire ) )
207 continue; // Skip the outer wire
209 TopTools_SequenceOfShape anInnerEdges;
210 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anInnerEdges );
211 if ( anInnerEdges.IsEmpty() )
214 QString anInWiresGroupName = GetName() + "_Inner_" + QString::number( anInnerCounter++ );
216 Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
217 anInWiresGroup->SetName( anInWiresGroupName );
219 anInWiresGroup->SetShapes( anInnerEdges );
223 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
225 return getTopShape();
228 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
230 return QColor( Qt::darkBlue );
233 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
235 return QColor( Qt::transparent );
238 QColor HYDROData_ImmersibleZone::getDefaultFillingColor() const
240 return DefaultFillingColor();
243 QColor HYDROData_ImmersibleZone::getDefaultBorderColor() const
245 return DefaultBorderColor();
248 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
250 SetReferenceObject( thePolyline, DataTag_Polyline );
254 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
256 return Handle(HYDROData_PolylineXY)::DownCast(
257 GetReferenceObject( DataTag_Polyline ) );
260 void HYDROData_ImmersibleZone::RemovePolyline()
262 ClearReferenceObjects( DataTag_Polyline );