2 #include "HYDROData_IPolyline.h"
4 #include "HYDROData_Document.h"
6 #include <TDataStd_BooleanList.hxx>
7 #include <TDataStd_ExtStringList.hxx>
8 #include <TDataStd_Integer.hxx>
9 #include <TDataStd_IntegerList.hxx>
10 #include <TDataStd_RealList.hxx>
12 IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity)
13 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
15 HYDROData_IPolyline::HYDROData_IPolyline()
17 myIsOperation( false )
21 HYDROData_IPolyline::~HYDROData_IPolyline()
25 int HYDROData_IPolyline::getNbUndo() const
27 return getNbOperations();
30 bool HYDROData_IPolyline::undo()
32 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
33 if ( aDocument.IsNull() )
36 if ( getNbUndo() < 1 )
41 int aNbUndoedOperations = getNbUndoedOperations();
42 setNbUndoedOperations( aNbUndoedOperations + 1 );
47 int HYDROData_IPolyline::getNbRedo() const
49 return getNbUndoedOperations();
52 bool HYDROData_IPolyline::redo()
54 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
55 if ( aDocument.IsNull() )
58 if ( getNbRedo() < 1 )
63 int aNbUndoedOperations = getNbUndoedOperations();
64 setNbUndoedOperations( aNbUndoedOperations - 1 );
69 CurveCreator::Dimension HYDROData_IPolyline::getDimension() const
71 return CurveCreator::Dim2d;
74 CurveCreator::Coordinates HYDROData_IPolyline::getPoint( const int theISection,
75 const int theIPnt ) const
77 CurveCreator::Coordinates aResPoint;
78 if ( theISection < 0 || theIPnt < 0 )
81 CurveCreator::Coordinates aSectPoints = getPoints( theISection );
82 if ( theIPnt >= aSectPoints.size() )
85 CurveCreator::Coordinates::reverse_iterator anIt = aSectPoints.rbegin();
87 aResPoint.push_back( *anIt++ );
88 aResPoint.push_back( *anIt );
94 int HYDROData_IPolyline::getNbPoints( const int theSectionIndex ) const
96 return getPoints( theSectionIndex ).size();
99 void HYDROData_IPolyline::startOperation()
104 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
105 if ( aDocument.IsNull() )
108 aDocument->StartOperation();
110 myIsOperation = true;
113 void HYDROData_IPolyline::commitOperation()
115 if ( !myIsOperation )
118 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
119 if ( aDocument.IsNull() )
122 int aNbOperations = getNbOperations();
123 setNbOperations( aNbOperations + 1 );
125 aDocument->CommitOperation();
127 myIsOperation = false;
130 void HYDROData_IPolyline::abortOperation()
132 if ( !myIsOperation )
135 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
136 if ( aDocument.IsNull() )
139 aDocument->AbortOperation();
141 myIsOperation = false;
144 void HYDROData_IPolyline::setNbOperations( const int theNb )
146 TDF_Label anOpLabel = myLab.FindChild( DataTag_Operations ).FindChild( OperationsTag_Commited );
147 TDataStd_Integer::Set( anOpLabel, theNb );
150 int HYDROData_IPolyline::getNbOperations() const
152 TDF_Label aLabel = myLab.FindChild( DataTag_Operations, false );
153 if ( aLabel.IsNull() )
156 TDF_Label anOpLabel = aLabel.FindChild( OperationsTag_Commited, false );
157 if ( anOpLabel.IsNull() )
160 Handle(TDataStd_Integer) anOpCount;
161 if ( !anOpLabel.FindAttribute( TDataStd_Integer::GetID(), anOpCount ) )
164 return anOpCount->Get();
167 void HYDROData_IPolyline::setNbUndoedOperations( const int theNb )
169 TDF_Label anUndoedLabel = myLab.FindChild( DataTag_Operations ).FindChild( OperationsTag_Undoed );
170 TDataStd_Integer::Set( anUndoedLabel, theNb );
173 int HYDROData_IPolyline::getNbUndoedOperations() const
175 TDF_Label aLabel = myLab.FindChild( DataTag_Operations, false );
176 if ( aLabel.IsNull() )
179 TDF_Label anUndoedLabel = aLabel.FindChild( OperationsTag_Undoed, false );
180 if ( anUndoedLabel.IsNull() )
183 Handle(TDataStd_Integer) anUndoedCount;
184 if ( !anUndoedLabel.FindAttribute( TDataStd_Integer::GetID(), anUndoedCount ) )
187 return anUndoedCount->Get();
190 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
191 Handle(TDataStd_IntegerList)& theTypesList,
192 Handle(TDataStd_BooleanList)& theClosuresList,
193 const bool theIsCreate ) const
195 TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
196 if ( aSectsLabel.IsNull() )
199 Handle(TDataStd_ExtStringList) aNamesList;
200 if ( !aSectsLabel.FindAttribute( TDataStd_ExtStringList::GetID(), aNamesList ) && theIsCreate )
201 aNamesList = TDataStd_ExtStringList::Set( aSectsLabel );
203 Handle(TDataStd_IntegerList) aTypesList;
204 if ( !aSectsLabel.FindAttribute( TDataStd_IntegerList::GetID(), aTypesList ) && theIsCreate )
205 aTypesList = TDataStd_IntegerList::Set( aSectsLabel );
207 Handle(TDataStd_BooleanList) aClosuresList;
208 if ( !aSectsLabel.FindAttribute( TDataStd_BooleanList::GetID(), aClosuresList ) && theIsCreate )
209 aClosuresList = TDataStd_BooleanList::Set( aSectsLabel );
212 void HYDROData_IPolyline::removeSectionsLists()
214 TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
215 if ( !aSectsLabel.IsNull() )
216 aSectsLabel.ForgetAllAttributes();
219 void HYDROData_IPolyline::getPointsLists( const int theSectionIndex,
220 Handle(TDataStd_RealList)& theListX,
221 Handle(TDataStd_RealList)& theListY,
222 const bool theIsCreate ) const
227 TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
228 if ( aLabel.IsNull() )
231 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
232 if ( aSectLabel.IsNull() )
235 TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
236 if ( !aLabelX.IsNull() )
238 if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
239 theListX = TDataStd_RealList::Set( aLabelX );
242 TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
243 if ( !aLabelY.IsNull() )
245 if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
246 theListY = TDataStd_RealList::Set( aLabelY );
250 void HYDROData_IPolyline::removePointsLists( const int theSectionIndex )
252 TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
253 if ( aLabel.IsNull() )
256 if ( theSectionIndex == -1 )
258 aLabel.ForgetAllAttributes();
262 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
263 if ( !aSectLabel.IsNull() )
264 aSectLabel.ForgetAllAttributes();