]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_ImmersibleZone.cxx
Salome HOME
Bugs #113, 114: use polylines with several section and immersible zones made of such...
[modules/hydro.git] / src / HYDROData / HYDROData_ImmersibleZone.cxx
1
2 #include "HYDROData_ImmersibleZone.h"
3
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_Polyline.h"
7
8 #include <BRepBuilderAPI_MakeFace.hxx>
9
10 #include <TopoDS.hxx>
11 #include <TopoDS_Face.hxx>
12 #include <TopoDS_Wire.hxx>
13 #include <TopoDS_Compound.hxx>
14 #include <TopExp_Explorer.hxx>
15 #include <TopTools_ListIteratorOfListOfShape.hxx>
16 #include <BRep_Builder.hxx>
17
18 #include <QColor>
19 #include <QStringList>
20
21 #define PYTHON_IMMERSIBLE_ZONE_ID "KIND_IMMERSIBLE_ZONE"
22
23 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
24 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
25
26
27 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
28 : HYDROData_NaturalObject()
29 {
30 }
31
32 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
33 {
34 }
35
36 QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
37 {
38   QStringList aResList;
39
40   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
41   if ( aDocument.IsNull() )
42     return aResList;
43
44   QString aDocName = aDocument->GetDocPyName();
45   QString aZoneName = GetName();
46
47   aResList << QString( "%1 = %2.CreateObject( %3 );" )
48               .arg( aZoneName ).arg( aDocName ).arg( PYTHON_IMMERSIBLE_ZONE_ID );
49   aResList << QString( "%1.SetName( \"%2\" );" )
50               .arg( aZoneName ).arg( aZoneName );
51   aResList << QString( "" );
52
53   QColor aFillingColor = GetFillingColor();
54   aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
55               .arg( aFillingColor.red()  ).arg( aFillingColor.green() )
56               .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
57   aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName );
58   aResList << QString( "" );
59
60   QColor aBorderColor = GetBorderColor();
61   aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
62               .arg( aBorderColor.red()  ).arg( aBorderColor.green() )
63               .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
64   aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName );
65   aResList << QString( "" );
66
67   Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
68   setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetBathymetry" );
69
70   Handle(HYDROData_Polyline) aRefPolyline = GetPolyline();
71   setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
72
73   return aResList;
74 }
75
76 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
77 {
78   TopoDS_Shape aResShape = TopoDS_Face();
79
80   Handle(HYDROData_Polyline) aPolyline = GetPolyline();
81   if( !aPolyline.IsNull() )
82   {
83     TopoDS_Shape aPolylineShape = aPolyline->GetTopShape();
84     TopTools_ListOfShape aWiresList;
85
86     TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
87     if ( !anExp.More() ) {
88       TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
89       if ( !aPolylineWire.IsNull() ) {
90         BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
91         aMakeFace.Build();
92         if( aMakeFace.IsDone() ) {
93           return aMakeFace.Face();
94         }
95       }
96     } else {
97       for ( ; anExp.More(); anExp.Next() ) {
98         TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
99         aWiresList.Append( aWire );
100       }
101     }
102     
103     TopoDS_Compound aCompound;
104     BRep_Builder aBuilder;
105     aBuilder.MakeCompound( aCompound );
106
107     TopTools_ListIteratorOfListOfShape anIter( aWiresList );
108     for ( ; anIter.More(); anIter.Next() ) {
109       TopoDS_Wire aWire = TopoDS::Wire( anIter.Value() );
110       if ( aWire.IsNull() ) {
111         continue;
112       }
113
114       BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
115       aMakeFace.Build();
116       if( aMakeFace.IsDone() ) {
117         aBuilder.Add( aCompound, aMakeFace.Face() );
118       }
119     }
120
121     aResShape = aCompound;
122   }
123
124   return aResShape;
125 }
126
127 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
128 {
129   // TODO
130   return getTopShape();
131 }
132
133 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
134 {
135   return QColor( Qt::green );
136 }
137
138 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
139 {
140   return QColor( Qt::transparent );
141 }
142
143 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline )
144 {
145   SetReferenceObject( thePolyline, DataTag_Polyline );
146 }
147
148 Handle(HYDROData_Polyline) HYDROData_ImmersibleZone::GetPolyline() const
149 {
150   return Handle(HYDROData_Polyline)::DownCast( 
151            GetReferenceObject( DataTag_Polyline ) );
152 }
153
154 void HYDROData_ImmersibleZone::RemovePolyline()
155 {
156   ClearReferenceObjects( DataTag_Polyline );
157 }
158
159