2 #include "HYDROData_ImmersibleZone.h"
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_ShapesGroup.h"
7 #include "HYDROData_PolylineXY.h"
8 #include "HYDROData_Tool.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 PYTHON_IMMERSIBLE_ZONE_ID "KIND_IMMERSIBLE_ZONE"
29 //#define HYDRODATA_IMZONE_DEB 1
31 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
32 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
35 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
36 : HYDROData_NaturalObject()
40 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
44 QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
48 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
49 if ( aDocument.IsNull() )
52 QString aDocName = aDocument->GetDocPyName();
53 QString aZoneName = GetName();
55 aResList << QString( "%1 = %2.CreateObject( %3 );" )
56 .arg( aZoneName ).arg( aDocName ).arg( PYTHON_IMMERSIBLE_ZONE_ID );
57 aResList << QString( "%1.SetName( \"%2\" );" )
58 .arg( aZoneName ).arg( aZoneName );
59 aResList << QString( "" );
61 QColor aFillingColor = GetFillingColor();
62 aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
63 .arg( aFillingColor.red() ).arg( aFillingColor.green() )
64 .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
65 aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName );
66 aResList << QString( "" );
68 QColor aBorderColor = GetBorderColor();
69 aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
70 .arg( aBorderColor.red() ).arg( aBorderColor.green() )
71 .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
72 aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName );
73 aResList << QString( "" );
75 Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
76 setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetBathymetry" );
78 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
79 setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
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 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
112 return generateTopShape( GetPolyline() );
115 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
117 TopoDS_Face aResultFace = TopoDS_Face();
119 if( !aPolyline.IsNull() )
121 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
122 TopTools_ListOfShape aWiresList;
124 if ( !aPolylineShape.IsNull() &&
125 aPolylineShape.ShapeType() == TopAbs_WIRE ) {
126 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
127 if ( !aPolylineWire.IsNull() ) {
128 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
130 if( aMakeFace.IsDone() ) {
131 return aMakeFace.Face();
135 TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
136 for ( ; anExp.More(); anExp.Next() ) {
137 if(!anExp.Current().IsNull()) {
138 const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
139 aWiresList.Append( aWire );
142 if(aWiresList.IsEmpty())
145 BRepAlgo_FaceRestrictor aFR;
146 TopoDS_Face aRefFace;
147 TopoDS_Shape aS = aWiresList.First();
148 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
150 if( aMakeFace.IsDone() ) {
151 aRefFace = aMakeFace.Face();
153 if(aRefFace.IsNull())
156 aFR.Init(aRefFace,Standard_False, Standard_True);
157 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
158 for ( ; anIt.More(); anIt.Next() ) {
159 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
160 if ( aWire.IsNull() )
166 for (; aFR.More(); aFR.Next()) {
167 aResultFace = aFR.Current();
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 TopTools_SequenceOfShape anInnerEdges;
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 anEdges;
210 HYDROData_Tool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anEdges );
211 anInnerEdges.Append( anEdges );
214 // Create outer edges group
215 QString anOutWiresGroupName = GetName() + "_Outer_Wire";
217 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
218 anOutWiresGroup->SetName( anOutWiresGroupName );
220 TopTools_SequenceOfShape anEdges;
221 HYDROData_Tool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anEdges );
222 anOutWiresGroup->SetShapes( anEdges );
224 // Create group for inner edges only if edges is not empty
225 if ( !anInnerEdges.IsEmpty() )
227 QString anInWiresGroupName = GetName() + "_Inner_Wires";
229 Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
230 anInWiresGroup->SetName( anInWiresGroupName );
232 anInWiresGroup->SetShapes( anInnerEdges );
236 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
238 return getTopShape();
241 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
243 return QColor( Qt::darkBlue );
246 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
248 return QColor( Qt::transparent );
251 QColor HYDROData_ImmersibleZone::getDefaultFillingColor() const
253 return DefaultFillingColor();
256 QColor HYDROData_ImmersibleZone::getDefaultBorderColor() const
258 return DefaultBorderColor();
261 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
263 SetReferenceObject( thePolyline, DataTag_Polyline );
267 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
269 return Handle(HYDROData_PolylineXY)::DownCast(
270 GetReferenceObject( DataTag_Polyline ) );
273 void HYDROData_ImmersibleZone::RemovePolyline()
275 ClearReferenceObjects( DataTag_Polyline );