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 TopoDS_Shape aResShape = TopoDS_Face();
114 Handle(HYDROData_PolylineXY) aPolyline = GetPolyline();
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 return 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())
140 BRepAlgo_FaceRestrictor aFR;
141 TopoDS_Face aRefFace;
142 TopoDS_Shape aS = aWiresList.First();
143 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
145 if( aMakeFace.IsDone() ) {
146 aRefFace = aMakeFace.Face();
148 if(aRefFace.IsNull())
150 aFR.Init(aRefFace,Standard_False, Standard_True);
151 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
152 for ( ; anIt.More(); anIt.Next() ) {
153 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
154 if ( aWire.IsNull() )
160 TopoDS_Compound aResult;
162 aBB.MakeCompound(aResult);
163 for (; aFR.More(); aFR.Next()) {
164 const TopoDS_Face& aFF = aFR.Current();
165 aBB.Add(aResult,aFF);
167 BRepCheck_Analyzer aChecker(aResult);
168 if(aChecker.IsValid())
170 #ifdef HYDRODATA_IMZONE_DEB
181 void HYDROData_ImmersibleZone::createGroupObjects()
183 TopoDS_Shape aZoneShape = GetTopShape();
185 // Temporary solution while the restriction for polylines is not implemented
186 // and shape for zone can be compound and not face only
187 if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
189 TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
190 if ( aZoneFaceExp.More() )
191 aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
194 if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
197 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
199 TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
201 TopTools_SequenceOfShape anInnerEdges;
203 TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
204 for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
206 TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
207 if ( aZoneWire.IsEqual( aZoneOuterWire ) )
208 continue; // Skip the outer wire
210 TopTools_SequenceOfShape anEdges;
211 HYDROData_Tool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anEdges );
212 anInnerEdges.Append( anEdges );
215 // Create outer edges group
216 QString anOutWiresGroupName = GetName() + "_Outer_Wire";
218 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
219 anOutWiresGroup->SetName( anOutWiresGroupName );
221 TopTools_SequenceOfShape anEdges;
222 HYDROData_Tool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anEdges );
223 anOutWiresGroup->SetShapes( anEdges );
225 // Create group for inner edges only if edges is not empty
226 if ( !anInnerEdges.IsEmpty() )
228 QString anInWiresGroupName = GetName() + "_Inner_Wires";
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 );