Salome HOME
Update mechanism is corrected (Bug #182).
[modules/hydro.git] / src / HYDROData / HYDROData_Channel.cxx
1
2 #include "HYDROData_Channel.h"
3
4 #include "HYDROData_Document.h"
5 #include "HYDROData_Polyline3D.h"
6 #include "HYDROData_Profile.h"
7
8 #include <TopoDS.hxx>
9 #include <TopoDS_Wire.hxx>
10
11 #include <QStringList>
12
13 #define PYTHON_CHANNEL_ID "KIND_CHANNEL"
14
15 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
16 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
17
18
19 HYDROData_Channel::HYDROData_Channel()
20 : HYDROData_ArtificialObject()
21 {
22 }
23
24 HYDROData_Channel::~HYDROData_Channel()
25 {
26 }
27
28 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
29 {
30   QStringList aResList;
31
32   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
33   if ( aDocument.IsNull() )
34     return aResList;
35
36   QString aDocName = aDocument->GetDocPyName();
37   QString aChannelName = GetName();
38
39   aResList << QString( "%1 = %2.CreateObject( %3 );" )
40               .arg( aChannelName ).arg( aDocName ).arg( PYTHON_CHANNEL_ID );
41   aResList << QString( "%1.SetName( \"%2\" );" )
42               .arg( aChannelName ).arg( aChannelName );
43   aResList << QString( "" );
44
45   // TODO
46
47   return aResList;
48 }
49
50 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
51 {
52   HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
53
54   Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
55   if ( !aGuideLine.IsNull() )
56     aResSeq.Append( aGuideLine );
57
58   Handle(HYDROData_Profile) aProfile = GetProfile();
59   if ( !aProfile.IsNull() )
60     aResSeq.Append( aProfile );
61
62   return aResSeq;
63 }
64
65 TopoDS_Shape HYDROData_Channel::GetTopShape() const
66 {
67   return getTopShape();
68 }
69
70 TopoDS_Shape HYDROData_Channel::GetShape3D() const
71 {
72   return getShape3D();
73 }
74
75 void HYDROData_Channel::Update()
76 {
77   HYDROData_ArtificialObject::Update();
78
79   Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
80   Handle(HYDROData_Profile) aProfile = GetProfile();
81   if ( aGuideLine.IsNull() || aProfile.IsNull() )
82     return;
83
84   // TODO
85 }
86
87 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
88 {
89   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
90
91   if ( theGuideLine.IsNull() )
92   {
93     RemoveGuideLine();
94     return !aPrevGuideLine.IsNull();
95   }
96
97   if ( IsEqual( aPrevGuideLine, theGuideLine ) )
98     return false;
99
100   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
101   if ( aHydraulicWire.IsNull() )
102     return false; // The polyline must be a single wire
103
104   SetReferenceObject( theGuideLine, DataTag_GuideLine );
105
106   // Indicate model of the need to update the chanel presentation
107   SetToUpdate( true );
108
109   return true;
110 }
111
112 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
113 {
114   return Handle(HYDROData_Polyline3D)::DownCast( 
115            GetReferenceObject( DataTag_GuideLine ) );
116 }
117
118 void HYDROData_Channel::RemoveGuideLine()
119 {
120   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
121   if ( aPrevGuideLine.IsNull() )
122     return;
123
124   ClearReferenceObjects( DataTag_GuideLine );
125
126   // Indicate model of the need to update the chanel presentation
127   SetToUpdate( true );
128 }
129
130 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
131 {
132   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
133
134   if ( theProfile.IsNull() )
135   {
136     RemoveProfile();
137     return !aPrevProfile.IsNull();
138   }
139
140   if ( IsEqual( aPrevProfile, theProfile ) )
141     return false;
142
143   SetReferenceObject( theProfile, DataTag_Profile );
144
145   // Indicate model of the need to update the chanel presentation
146   SetToUpdate( true );
147
148   return true;
149 }
150
151 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
152 {
153   return Handle(HYDROData_Profile)::DownCast( 
154            GetReferenceObject( DataTag_Profile ) );
155 }
156
157 void HYDROData_Channel::RemoveProfile()
158 {
159   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
160   if ( aPrevProfile.IsNull() )
161     return;
162
163   ClearReferenceObjects( DataTag_Profile );
164
165   // Indicate model of the need to update the chanel presentation
166   SetToUpdate( true );
167 }