Salome HOME
Still an error on ZLayers related to edit CalculationCase The call to createViewManag...
[modules/hydro.git] / src / HYDROData / HYDROData_ImmersibleZone.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_ImmersibleZone.h"
20
21 #include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_PolylineXY.h"
25 #include "HYDROData_ShapesTool.h"
26
27 #include <HYDROData_Tool.h>
28
29 #include <TopoDS.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <TopTools_ListIteratorOfListOfShape.hxx>
35 #include <TopTools_HSequenceOfShape.hxx>
36
37
38 #include <ShapeAnalysis.hxx>
39 #include <ShapeAnalysis_FreeBounds.hxx>
40
41
42 #include <QColor>
43 #include <QStringList>
44
45 #define DEB_IMZ
46 #include <BRepTools.hxx>
47 //#define _DEVDEBUG_
48 #include "HYDRO_trace.hxx"
49
50 //#define HYDRODATA_IMZONE_DEB 1
51
52 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
53
54
55 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
56 : HYDROData_NaturalObject( Geom_2d )
57 {
58 }
59
60 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
61 {
62 }
63
64 QStringList HYDROData_ImmersibleZone::DumpToPython( const QString& thePyScriptPath,
65                                                     MapOfTreatedObjects& theTreatedObjects ) const
66 {
67   QStringList aResList = dumpObjectCreation( theTreatedObjects );
68   
69   QString aZoneName = GetObjPyName();
70
71   Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
72   setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" );
73
74   Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
75   setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
76
77   if (!this->IsSubmersible())
78     {
79       aResList << QString( "%1.SetIsSubmersible(False)" ).arg( aZoneName );
80     }
81
82   aResList << QString( "" );
83
84   aResList << QString( "%1.Update()" ).arg( aZoneName );
85   aResList << QString( "" );
86
87   return aResList;
88 }
89
90 HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const
91 {
92   HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects();
93
94   Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
95   if ( !aRefPolyline.IsNull() )
96     aResSeq.Append( aRefPolyline );
97
98   return aResSeq;
99 }
100
101 void HYDROData_ImmersibleZone::Update()
102 {
103   HYDROData_NaturalObject::Update();
104   
105   RemoveGroupObjects();
106   TopoDS_Shape aResShape = generateTopShape();
107   SetTopShape( aResShape );
108
109   createGroupObjects();
110 }
111
112 bool HYDROData_ImmersibleZone::IsHas2dPrs() const
113 {
114   return true;
115 }
116
117 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
118 {
119   return generateTopShape( GetPolyline() );
120 }
121
122 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
123 {
124   return HYDROData_Tool::PolyXY2Face(aPolyline);
125 }
126
127 void HYDROData_ImmersibleZone::createGroupObjects()
128 {
129   TopoDS_Shape aZoneShape = GetTopShape();
130   
131   // Temporary solution while the restriction for polylines is not implemented
132   // and shape for zone can be compound and not face only
133   if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
134   {
135     TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
136     if ( aZoneFaceExp.More() )
137       aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
138   }
139
140   if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
141     return;
142
143   TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
144   
145   TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
146
147   // Create outer edges group
148   QString anOutWiresGroupName = GetName() + "_Outer";
149
150   Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
151   anOutWiresGroup->SetName( anOutWiresGroupName );
152
153   TopTools_SequenceOfShape anOuterEdges;
154   HYDROData_ShapesTool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anOuterEdges );
155   anOutWiresGroup->SetShapes( anOuterEdges );
156
157   int anInnerCounter = 1;
158   TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
159   for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
160   {
161     TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
162     if ( aZoneWire.IsEqual( aZoneOuterWire ) )
163       continue; // Skip the outer wire
164
165     TopTools_SequenceOfShape anInnerEdges;
166     HYDROData_ShapesTool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anInnerEdges );
167     if ( anInnerEdges.IsEmpty() )
168       continue;
169
170     QString anInWiresGroupName = GetName() + "_Inner_" + QString::number( anInnerCounter++ );
171
172     Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
173     anInWiresGroup->SetName( anInWiresGroupName );
174
175     anInWiresGroup->SetShapes( anInnerEdges );
176   }  
177 }
178
179 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
180 {
181   return GetTopShape();
182 }
183
184 QColor HYDROData_ImmersibleZone::DefaultFillingColor() const
185 {
186   return QColor( Qt::darkBlue );
187 }
188
189 QColor HYDROData_ImmersibleZone::DefaultBorderColor() const
190 {
191   return QColor( Qt::transparent );
192 }
193
194 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
195 {
196   if( IsEqual( GetPolyline(), thePolyline ) )
197     return;
198
199   SetReferenceObject( thePolyline, DataTag_Polyline );
200   Changed( Geom_2d );
201 }
202
203 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
204 {
205   return Handle(HYDROData_PolylineXY)::DownCast( 
206            GetReferenceObject( DataTag_Polyline ) );
207 }
208
209 void HYDROData_ImmersibleZone::RemovePolyline()
210 {
211   ClearReferenceObjects( DataTag_Polyline );
212   Changed( Geom_2d );
213 }