Salome HOME
Import of profiles corrected.
[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 TopoDS_Shape HYDROData_Channel::GetTopShape() const
51 {
52   return getTopShape();
53 }
54
55 TopoDS_Shape HYDROData_Channel::GetShape3D() const
56 {
57   return getShape3D();
58 }
59
60 void HYDROData_Channel::Update()
61 {
62   removeTopShape();
63   removeShape3D();
64   SetToUpdate( false );
65
66   Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
67   Handle(HYDROData_Profile) aProfile = GetProfile();
68   if ( aGuideLine.IsNull() || aProfile.IsNull() )
69     return;
70
71   // TODO
72 }
73
74 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
75 {
76   if ( theGuideLine.IsNull()  )
77     return false;
78   
79   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
80   if ( aHydraulicWire.IsNull() )
81     return false; // The polyline must be a single wire
82
83   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
84   if ( IsEqual( aPrevGuideLine, theGuideLine ) )
85     return true;
86
87   SetReferenceObject( theGuideLine, DataTag_GuideLine );
88
89   // Indicate model of the need to update the chanel presentation
90   SetToUpdate( true );
91
92   return true;
93 }
94
95 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
96 {
97   return Handle(HYDROData_Polyline3D)::DownCast( 
98            GetReferenceObject( DataTag_GuideLine ) );
99 }
100
101 void HYDROData_Channel::RemoveGuideLine()
102 {
103   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
104   if ( aPrevGuideLine.IsNull() )
105     return;
106
107   ClearReferenceObjects( DataTag_GuideLine );
108
109   // Indicate model of the need to update the chanel presentation
110   SetToUpdate( true );
111 }
112
113 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
114 {
115   if ( theProfile.IsNull()  )
116     return false;
117   
118   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
119   if ( IsEqual( aPrevProfile, theProfile ) )
120     return true;
121
122   SetReferenceObject( theProfile, DataTag_Profile );
123
124   // Indicate model of the need to update the chanel presentation
125   SetToUpdate( true );
126
127   return true;
128 }
129
130 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
131 {
132   return Handle(HYDROData_Profile)::DownCast( 
133            GetReferenceObject( DataTag_Profile ) );
134 }
135
136 void HYDROData_Channel::RemoveProfile()
137 {
138   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
139   if ( aPrevProfile.IsNull() )
140     return;
141
142   ClearReferenceObjects( DataTag_Profile );
143
144   // Indicate model of the need to update the chanel presentation
145   SetToUpdate( true );
146 }