]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_ImmersibleZone.cxx
Salome HOME
Coloring of objects (Bug #219).
[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_PolylineXY.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 #include <BRepAlgo_FaceRestrictor.hxx>
18 #include <BRepCheck_Analyzer.hxx>
19 #include <QColor>
20 #include <QStringList>
21
22 #define PYTHON_IMMERSIBLE_ZONE_ID "KIND_IMMERSIBLE_ZONE"
23 //#define HYDRODATA_IMZONE_DEB 1
24
25 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
26 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
27
28
29 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
30 : HYDROData_NaturalObject()
31 {
32 }
33
34 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
35 {
36 }
37
38 QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
39 {
40   QStringList aResList;
41
42   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
43   if ( aDocument.IsNull() )
44     return aResList;
45
46   QString aDocName = aDocument->GetDocPyName();
47   QString aZoneName = GetName();
48
49   aResList << QString( "%1 = %2.CreateObject( %3 );" )
50               .arg( aZoneName ).arg( aDocName ).arg( PYTHON_IMMERSIBLE_ZONE_ID );
51   aResList << QString( "%1.SetName( \"%2\" );" )
52               .arg( aZoneName ).arg( aZoneName );
53   aResList << QString( "" );
54
55   QColor aFillingColor = GetFillingColor();
56   aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
57               .arg( aFillingColor.red()  ).arg( aFillingColor.green() )
58               .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
59   aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName );
60   aResList << QString( "" );
61
62   QColor aBorderColor = GetBorderColor();
63   aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
64               .arg( aBorderColor.red()  ).arg( aBorderColor.green() )
65               .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
66   aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName );
67   aResList << QString( "" );
68
69   Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
70   setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetBathymetry" );
71
72   Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
73   setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
74
75   return aResList;
76 }
77
78 HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const
79 {
80   HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects();
81
82   Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
83   if ( !aRefPolyline.IsNull() )
84     aResSeq.Append( aRefPolyline );
85
86   return aResSeq;
87 }
88
89 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
90 {
91   return getTopShape();
92 }
93
94 void HYDROData_ImmersibleZone::Update()
95 {
96   HYDROData_NaturalObject::Update();
97   
98   TopoDS_Shape aResShape = generateTopShape();
99   SetTopShape( aResShape );
100 }
101
102 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
103 {
104   TopoDS_Shape aResShape = TopoDS_Face();
105
106   Handle(HYDROData_PolylineXY) aPolyline = GetPolyline();
107   if( !aPolyline.IsNull() )
108   {
109     TopoDS_Shape aPolylineShape = aPolyline->GetShape();
110     TopTools_ListOfShape aWiresList;
111
112     if ( !aPolylineShape.IsNull() && 
113          aPolylineShape.ShapeType() == TopAbs_WIRE ) {
114       const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
115       if ( !aPolylineWire.IsNull() ) {
116         BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
117         aMakeFace.Build();
118         if( aMakeFace.IsDone() ) {
119           return aMakeFace.Face();
120         }
121       }
122     } else {
123             TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
124                 for ( ; anExp.More(); anExp.Next() ) {
125                   if(!anExp.Current().IsNull()) {
126             const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
127                     aWiresList.Append( aWire );
128                   }
129                 }
130                 if(aWiresList.IsEmpty())
131            return aResShape;
132             BRepAlgo_FaceRestrictor aFR;
133             TopoDS_Face aRefFace;         
134                 TopoDS_Shape aS = aWiresList.First();
135                 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
136         aMakeFace.Build();
137         if( aMakeFace.IsDone() ) {
138           aRefFace = aMakeFace.Face();
139                 }
140                 if(aRefFace.IsNull())
141                   return aResShape;
142             aFR.Init(aRefFace,Standard_False, Standard_True);
143                 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
144         for ( ; anIt.More(); anIt.Next() ) {
145           TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
146                   if ( aWire.IsNull() ) 
147                           continue;
148           aFR.Add(aWire);
149                 }
150         aFR.Perform();
151                 if (aFR.IsDone()) {
152                   TopoDS_Compound aResult;
153                   BRep_Builder aBB;
154                   aBB.MakeCompound(aResult);
155                   for (; aFR.More(); aFR.Next()) {
156                         const TopoDS_Face& aFF = aFR.Current();
157                         aBB.Add(aResult,aFF);    
158                   }
159                   BRepCheck_Analyzer aChecker(aResult);
160                   if(aChecker.IsValid())
161                     aResShape = aResult;
162 #ifdef HYDRODATA_IMZONE_DEB
163                   else {
164                         aResShape = aResult;             
165                   }
166 #endif
167                 }
168         }
169   }
170   return aResShape;
171 }
172
173 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
174 {
175   return getTopShape();
176 }
177
178 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
179 {
180   return QColor( Qt::darkBlue );
181 }
182
183 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
184 {
185   return QColor( Qt::transparent );
186 }
187
188 QColor HYDROData_ImmersibleZone::getDefaultFillingColor() const
189 {
190   return DefaultFillingColor();
191 }
192
193 QColor HYDROData_ImmersibleZone::getDefaultBorderColor() const
194 {
195   return DefaultBorderColor();
196 }
197
198 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
199 {
200   SetReferenceObject( thePolyline, DataTag_Polyline );
201   SetToUpdate( true );
202 }
203
204 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
205 {
206   return Handle(HYDROData_PolylineXY)::DownCast( 
207            GetReferenceObject( DataTag_Polyline ) );
208 }
209
210 void HYDROData_ImmersibleZone::RemovePolyline()
211 {
212   ClearReferenceObjects( DataTag_Polyline );
213   SetToUpdate( true );
214 }
215
216