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 = dumpObjectCreation( theTreatedObjects );
46 QString aZoneName = GetObjPyName();
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" );
68 aResList << QString( "" );
69 aResList << QString( "%1.Update();" ).arg( aZoneName );
70 aResList << QString( "" );
75 HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const
77 HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects();
79 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
80 if ( !aRefPolyline.IsNull() )
81 aResSeq.Append( aRefPolyline );
86 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
91 void HYDROData_ImmersibleZone::Update()
93 HYDROData_NaturalObject::Update();
95 TopoDS_Shape aResShape = generateTopShape();
96 SetTopShape( aResShape );
101 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
103 return generateTopShape( GetPolyline() );
106 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
108 TopoDS_Face aResultFace = TopoDS_Face();
110 if( !aPolyline.IsNull() )
112 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
113 TopTools_ListOfShape aWiresList;
115 if ( !aPolylineShape.IsNull() &&
116 aPolylineShape.ShapeType() == TopAbs_WIRE ) {
117 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
118 if ( !aPolylineWire.IsNull() ) {
119 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
121 if( aMakeFace.IsDone() ) {
122 return aMakeFace.Face();
126 TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
127 for ( ; anExp.More(); anExp.Next() ) {
128 if(!anExp.Current().IsNull()) {
129 const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
130 aWiresList.Append( aWire );
133 if(aWiresList.IsEmpty())
136 BRepAlgo_FaceRestrictor aFR;
137 TopoDS_Face aRefFace;
138 TopoDS_Shape aS = aWiresList.First();
139 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
141 if( aMakeFace.IsDone() ) {
142 aRefFace = aMakeFace.Face();
144 if(aRefFace.IsNull())
147 aFR.Init(aRefFace,Standard_False, Standard_True);
148 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
149 for ( ; anIt.More(); anIt.Next() ) {
150 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
151 if ( aWire.IsNull() )
157 for (; aFR.More(); aFR.Next()) {
158 aResultFace = aFR.Current();
165 if( aResultFace.IsNull() )
168 BRepCheck_Analyzer anAnalyzer( aResultFace );
169 if( anAnalyzer.IsValid() && aResultFace.ShapeType()==TopAbs_FACE )
172 return TopoDS_Face();
175 void HYDROData_ImmersibleZone::createGroupObjects()
177 TopoDS_Shape aZoneShape = GetTopShape();
179 // Temporary solution while the restriction for polylines is not implemented
180 // and shape for zone can be compound and not face only
181 if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
183 TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
184 if ( aZoneFaceExp.More() )
185 aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
188 if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
191 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
193 TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
195 // Create outer edges group
196 QString anOutWiresGroupName = GetName() + "_Outer";
198 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
199 anOutWiresGroup->SetName( anOutWiresGroupName );
201 TopTools_SequenceOfShape anOuterEdges;
202 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anOuterEdges );
203 anOutWiresGroup->SetShapes( anOuterEdges );
205 int anInnerCounter = 1;
206 TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
207 for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
209 TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
210 if ( aZoneWire.IsEqual( aZoneOuterWire ) )
211 continue; // Skip the outer wire
213 TopTools_SequenceOfShape anInnerEdges;
214 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anInnerEdges );
215 if ( anInnerEdges.IsEmpty() )
218 QString anInWiresGroupName = GetName() + "_Inner_" + QString::number( anInnerCounter++ );
220 Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
221 anInWiresGroup->SetName( anInWiresGroupName );
223 anInWiresGroup->SetShapes( anInnerEdges );
227 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
229 return getTopShape();
232 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
234 return QColor( Qt::darkBlue );
237 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
239 return QColor( Qt::transparent );
242 QColor HYDROData_ImmersibleZone::getDefaultFillingColor() const
244 return DefaultFillingColor();
247 QColor HYDROData_ImmersibleZone::getDefaultBorderColor() const
249 return DefaultBorderColor();
252 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
254 SetReferenceObject( thePolyline, DataTag_Polyline );
258 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
260 return Handle(HYDROData_PolylineXY)::DownCast(
261 GetReferenceObject( DataTag_Polyline ) );
264 void HYDROData_ImmersibleZone::RemovePolyline()
266 ClearReferenceObjects( DataTag_Polyline );