From: adv Date: Mon, 25 Nov 2013 11:36:37 +0000 (+0000) Subject: The data model has been rolled back to previous version. X-Git-Tag: issue_132_11_28~32 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=deed826b2d6c39ba2ed410108cdf54d64cded321;p=modules%2Fhydro.git The data model has been rolled back to previous version. --- diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index d0356ae5..63ee232d 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -83,13 +83,12 @@ include_directories( ${CAS_INCLUDE_DIRS} ${QT_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROCurveCreator # ${GUI_ROOT_DIR}/include/salome ${GUI_INCLUDE_DIRS} ) add_library(HYDROData SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) -target_link_libraries(HYDROData HYDROCurveCreator ${CAS_OCAF} ${CAS_OCAFVIS} ${CAS_TKG3d} ${CAS_TKGeomBase} ${CAS_TKGeomAlgo} ${CAS_TKBrep} ${CAS_TKIGES} ${CAS_TKSTEP} ${CAS_TKTopAlgo} ${CAS_TKBO} ${QT_LIBRARIES} ${GUI_ImageComposer}) +target_link_libraries(HYDROData ${GEOM_GEOMUtils} ${CAS_OCAF} ${CAS_OCAFVIS} ${CAS_TKG3d} ${CAS_TKGeomBase} ${CAS_TKGeomAlgo} ${CAS_TKBrep} ${CAS_TKIGES} ${CAS_TKSTEP} ${CAS_TKTopAlgo} ${CAS_TKBO} ${QT_LIBRARIES} ${GUI_ImageComposer}) INSTALL(TARGETS HYDROData EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) set(PROJECT_LIBRARIES HYDROData) diff --git a/src/HYDROData/HYDROData_IPolyline.cxx b/src/HYDROData/HYDROData_IPolyline.cxx index 00f7a04a..20fe2099 100755 --- a/src/HYDROData/HYDROData_IPolyline.cxx +++ b/src/HYDROData/HYDROData_IPolyline.cxx @@ -1,20 +1,15 @@ #include "HYDROData_IPolyline.h" -#include "HYDROData_Document.h" +#include -#include -#include -#include -#include #include IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity) HYDROData_IPolyline::HYDROData_IPolyline() -: HYDROData_Entity(), - myIsOperation( false ) +: HYDROData_Entity() { } @@ -22,198 +17,9 @@ HYDROData_IPolyline::~HYDROData_IPolyline() { } -int HYDROData_IPolyline::getNbUndo() const +int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const { - return getNbOperations(); -} - -bool HYDROData_IPolyline::undo() -{ - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( aDocument.IsNull() ) - return false; - - if ( getNbUndo() < 1 ) - return false; - - aDocument->Undo(); - - int aNbUndoedOperations = getNbUndoedOperations(); - setNbUndoedOperations( aNbUndoedOperations + 1 ); - - return true; -} - -int HYDROData_IPolyline::getNbRedo() const -{ - return getNbUndoedOperations(); -} - -bool HYDROData_IPolyline::redo() -{ - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( aDocument.IsNull() ) - return false; - - if ( getNbRedo() < 1 ) - return false; - - aDocument->Redo(); - - int aNbUndoedOperations = getNbUndoedOperations(); - setNbUndoedOperations( aNbUndoedOperations - 1 ); - - return true; -} - -CurveCreator::Dimension HYDROData_IPolyline::getDimension() const -{ - return CurveCreator::Dim2d; -} - -CurveCreator::Coordinates HYDROData_IPolyline::getPoint( const int theISection, - const int theIPnt ) const -{ - CurveCreator::Coordinates aResPoint; - if ( theISection < 0 || theIPnt < 0 ) - return aResPoint; - - CurveCreator::Coordinates aSectPoints = getPoints( theISection ); - if ( theIPnt >= aSectPoints.size() ) - return aResPoint; - - CurveCreator::Coordinates::reverse_iterator anIt = aSectPoints.rbegin(); - - aResPoint.push_back( *anIt++ ); - aResPoint.push_back( *anIt ); - - return aResPoint; -} - - -int HYDROData_IPolyline::getNbPoints( const int theSectionIndex ) const -{ - return getPoints( theSectionIndex ).size(); -} - -void HYDROData_IPolyline::startOperation() -{ - if ( myIsOperation ) - return; - - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( aDocument.IsNull() ) - return; - - aDocument->StartOperation(); - - myIsOperation = true; -} - -void HYDROData_IPolyline::commitOperation() -{ - if ( !myIsOperation ) - return; - - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( aDocument.IsNull() ) - return; - - int aNbOperations = getNbOperations(); - setNbOperations( aNbOperations + 1 ); - - aDocument->CommitOperation(); - - myIsOperation = false; -} - -void HYDROData_IPolyline::abortOperation() -{ - if ( !myIsOperation ) - return; - - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( aDocument.IsNull() ) - return; - - aDocument->AbortOperation(); - - myIsOperation = false; -} - -void HYDROData_IPolyline::setNbOperations( const int theNb ) -{ - TDF_Label anOpLabel = myLab.FindChild( DataTag_Operations ).FindChild( OperationsTag_Commited ); - TDataStd_Integer::Set( anOpLabel, theNb ); -} - -int HYDROData_IPolyline::getNbOperations() const -{ - TDF_Label aLabel = myLab.FindChild( DataTag_Operations, false ); - if ( aLabel.IsNull() ) - return 0; - - TDF_Label anOpLabel = aLabel.FindChild( OperationsTag_Commited, false ); - if ( anOpLabel.IsNull() ) - return 0; - - Handle(TDataStd_Integer) anOpCount; - if ( !anOpLabel.FindAttribute( TDataStd_Integer::GetID(), anOpCount ) ) - return 0; - - return anOpCount->Get(); -} - -void HYDROData_IPolyline::setNbUndoedOperations( const int theNb ) -{ - TDF_Label anUndoedLabel = myLab.FindChild( DataTag_Operations ).FindChild( OperationsTag_Undoed ); - TDataStd_Integer::Set( anUndoedLabel, theNb ); -} - -int HYDROData_IPolyline::getNbUndoedOperations() const -{ - TDF_Label aLabel = myLab.FindChild( DataTag_Operations, false ); - if ( aLabel.IsNull() ) - return 0; - - TDF_Label anUndoedLabel = aLabel.FindChild( OperationsTag_Undoed, false ); - if ( anUndoedLabel.IsNull() ) - return 0; - - Handle(TDataStd_Integer) anUndoedCount; - if ( !anUndoedLabel.FindAttribute( TDataStd_Integer::GetID(), anUndoedCount ) ) - return 0; - - return anUndoedCount->Get(); -} - -void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList, - Handle(TDataStd_IntegerList)& theTypesList, - Handle(TDataStd_BooleanList)& theClosuresList, - const bool theIsCreate ) const -{ - TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, theIsCreate ); - if ( aSectsLabel.IsNull() ) - return; - - Handle(TDataStd_ExtStringList) aNamesList; - if ( !aSectsLabel.FindAttribute( TDataStd_ExtStringList::GetID(), aNamesList ) && theIsCreate ) - aNamesList = TDataStd_ExtStringList::Set( aSectsLabel ); - - Handle(TDataStd_IntegerList) aTypesList; - if ( !aSectsLabel.FindAttribute( TDataStd_IntegerList::GetID(), aTypesList ) && theIsCreate ) - aTypesList = TDataStd_IntegerList::Set( aSectsLabel ); - - Handle(TDataStd_BooleanList) aClosuresList; - if ( !aSectsLabel.FindAttribute( TDataStd_BooleanList::GetID(), aClosuresList ) && theIsCreate ) - aClosuresList = TDataStd_BooleanList::Set( aSectsLabel ); -} - -void HYDROData_IPolyline::removeSectionsLists() -{ - TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false ); - if ( !aSectsLabel.IsNull() ) - aSectsLabel.ForgetAllAttributes(); + return GetPoints( theSectionIndex ).Length(); } void HYDROData_IPolyline::getPointsLists( const int theSectionIndex, @@ -247,20 +53,13 @@ void HYDROData_IPolyline::getPointsLists( const int theSectionI } } -void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) +void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const { TDF_Label aLabel = myLab.FindChild( DataTag_Points, false ); if ( aLabel.IsNull() ) return; - if ( theSectionIndex == -1 ) - { - aLabel.ForgetAllAttributes(); - } - else - { - TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false ); - if ( !aSectLabel.IsNull() ) - aSectLabel.ForgetAllAttributes(); - } + TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false ); + if ( !aSectLabel.IsNull() ) + aSectLabel.ForgetAllAttributes(); } diff --git a/src/HYDROData/HYDROData_IPolyline.h b/src/HYDROData/HYDROData_IPolyline.h index ebb57a31..9155f693 100644 --- a/src/HYDROData/HYDROData_IPolyline.h +++ b/src/HYDROData/HYDROData_IPolyline.h @@ -4,22 +4,22 @@ #include "HYDROData_Entity.h" -#include -#include DEFINE_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity) +class gp_XY; class TopoDS_Wire; class Handle(TDataStd_RealList); -class Handle(TDataStd_ExtStringList); -class Handle(TDataStd_IntegerList); -class Handle(TDataStd_BooleanList); /**\class HYDROData_IPolyline * \brief Base class that stores/retreives information about the 2D points. */ -class HYDROData_IPolyline : public HYDROData_Entity, public CurveCreator_ICurve +class HYDROData_IPolyline : public HYDROData_Entity { +public: + + typedef gp_XY Point; + typedef NCollection_Sequence PointsList; protected: /** @@ -28,18 +28,7 @@ protected: enum DataTag { DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve - DataTag_Sections, DataTag_Points, - DataTag_Operations - }; - - /** - * Enumeration of tags corresponding to the operations child lable - */ - enum OperationsTag - { - OperationsTag_Commited, - OperationsTag_Undoed }; public: @@ -48,82 +37,89 @@ public: /** * Returns the 3D presentation of all points. */ - HYDRODATA_EXPORT virtual ListAISObjects constructWire() const = 0; + HYDRODATA_EXPORT virtual TopoDS_Wire GetWire() const = 0; -public: + /** + * Returns number of sections. + */ + HYDRODATA_EXPORT virtual int NbSections() const = 0; - // Implementation of ICurvePolyline interface - - /***********************************************/ - /*** Undo/Redo methods ***/ - /***********************************************/ + /** + * Adds new one section. + * \param theIsClosed flag indicates type of polyline + */ + HYDRODATA_EXPORT virtual void AddSection( const bool theIsClosed ) = 0; - //! Get number of available undo operations - HYDRODATA_EXPORT virtual int getNbUndo() const; + /** + * Returns true if section with given index is closed. + * \param theSectionIndex index of section + */ + HYDRODATA_EXPORT virtual bool IsClosedSection( const int theSectionIndex ) const = 0; - //! Undo previous operation - HYDRODATA_EXPORT virtual bool undo(); + /** + * Removes section with given index. + * \param theSectionIndex index of section + */ + HYDRODATA_EXPORT virtual void RemoveSection( const int theSectionIndex ) = 0; - //! Get number of available redo operations - HYDRODATA_EXPORT virtual int getNbRedo() const; + /** + * Removes all sections. + */ + HYDRODATA_EXPORT virtual void RemoveSections() = 0; - //! Redo last previously "undone" operation - HYDRODATA_EXPORT virtual bool redo(); + /** + * Return number of profile points. + * \return number of points + */ + HYDRODATA_EXPORT int NbPoints( const int theSectionIndex = -1 ) const; - /***********************************************/ - /*** Point methods ***/ - /***********************************************/ + /** + * Adds new point for section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePoint point to add + * \param theBeforeIndex if not equal -1 then insert point before this index + */ + HYDRODATA_EXPORT virtual void AddPoint( const int theSectionIndex, + const Point& thePoint, + const int theBeforeIndex = -1 ) = 0; - //! Get the dimension. - HYDRODATA_EXPORT virtual CurveCreator::Dimension getDimension() const; + /** + * Replaces point for section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePointIndex index of point to replace + * \param thePoint new point + */ + HYDRODATA_EXPORT virtual void SetPoint( const int theSectionIndex, + const int thePointIndex, + const Point& thePoint ) = 0; + /** + * Removes point from section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePointIndex index of point + */ + HYDRODATA_EXPORT virtual void RemovePoint( const int theSectionIndex, + const int thePointIndex ) = 0; - //! Get coordinates of specified point - HYDRODATA_EXPORT virtual CurveCreator::Coordinates getPoint( const int theISection, - const int theIPnt ) const; /** - * Get number of points in specified section or (the total number of points - * in Curve if theISection is equal to -1). + * Returns list of points. + * \param theSectionIndex if not equal -1 then list of points returned + * only for section with this index + * \return list of points */ - HYDRODATA_EXPORT virtual int getNbPoints( const int theISection = -1 ) const; - + HYDRODATA_EXPORT virtual PointsList GetPoints( const int theSectionIndex = -1 ) const = 0; protected: - void startOperation(); - - void commitOperation(); - - void abortOperation(); - - - void setNbOperations( const int theNb ); - - int getNbOperations() const; - - - void setNbUndoedOperations( const int theNb ); - - int getNbUndoedOperations() const; - - - void getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList, - Handle(TDataStd_IntegerList)& theTypesList, - Handle(TDataStd_BooleanList)& theClosuresList, - const bool theIsCreate = true ) const; - - void removeSectionsLists(); - - void getPointsLists( const int theSectionIndex, Handle(TDataStd_RealList)& theListX, Handle(TDataStd_RealList)& theListY, const bool theIsCreate = true ) const; - void removePointsLists( const int theSectionIndex = -1 ); + void removePointsLists( const int theSectionIndex ) const; protected: @@ -131,16 +127,12 @@ protected: * Creates new object in the internal data structure. Use higher level objects * to create objects with real content. */ - HYDRODATA_EXPORT HYDROData_IPolyline(); + HYDROData_IPolyline(); /** * Destructs properties of the object and object itself, removes it from the document. */ - HYDRODATA_EXPORT ~HYDROData_IPolyline(); - -protected: - - bool myIsOperation; + ~HYDROData_IPolyline(); }; #endif diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index b97af6d5..f651ac2a 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -3,19 +3,10 @@ #include "HYDROData_Tool.h" -#include +#include -#include - -#include -#include -#include #include -#include -#include -#include -#include #include #include @@ -33,636 +24,152 @@ HYDROData_PolylineXY::~HYDROData_PolylineXY() { } -CurveCreator_ICurve::ListAISObjects HYDROData_PolylineXY::constructWire() const +TopoDS_Wire HYDROData_PolylineXY::GetWire() const { // TODO - ListAISObjects aProfileObjects; - return aProfileObjects; -} - -bool HYDROData_PolylineXY::clear() -{ - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - removeSectionsLists(); - removePointsLists(); - - if ( !anIsOperation ) - commitOperation(); - - return true; -} - -bool HYDROData_PolylineXY::join( const int theISectionTo, - const int theISectionFrom ) -{ - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - if ( aNamesList.IsNull() || aNamesList->Extent() <= 1 ) - return false; - - bool anIsOperation = myIsOperation; - - if ( theISectionTo == -1 || theISectionFrom == -1 ) - { - // Join all sections to one - if ( !anIsOperation ) - startOperation(); - - TCollection_ExtendedString aSectName = aNamesList->First(); - CurveCreator::SectionType aSectType = (CurveCreator::SectionType)aTypesList->First(); - bool anIsClosed = aClosuresList->First(); - - aNamesList->Clear(); - aTypesList->Clear(); - aClosuresList->Clear(); - - aNamesList->Append( aSectName ); - aTypesList->Append( aSectType ); - aClosuresList->Append( anIsClosed ); - - CurveCreator::Coordinates anAllPoints = getPoints(); - removePointsLists(); - - addPoints( anAllPoints, 0 ); - } - else - { - // Join selected range of sections to one - if ( theISectionFrom >= theISectionTo ) - return false; - - if ( !anIsOperation ) - startOperation(); - - TDataStd_ListOfExtendedString anOldNamesList; - anOldNamesList = aNamesList->List(); - - TColStd_ListOfInteger anOldTypesList; - anOldTypesList = aTypesList->List(); - - TDataStd_ListOfByte anOldClosuresList; - anOldClosuresList = aClosuresList->List(); - - // Refill the existing lists - aNamesList->Clear(); - aTypesList->Clear(); - aClosuresList->Clear(); - - Handle(TDataStd_RealList) aJoinListX, aJoinListY; - - TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList ); - TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList ); - TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList ); - - int aNbSect = 0; - for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More(); - aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++aNbSect ) - { - if ( aNbSect < theISectionFrom || aNbSect > theISectionTo ) - { - aNamesList->Append( aNamesIter.Value() ); - aTypesList->Append( aTypesIter.Value() ); - aClosuresList->Append( (bool)aClosuresIter.Value() ); - } - else - { - if ( aNbSect == theISectionFrom ) - { - aNamesList->Append( aNamesIter.Value() ); - aTypesList->Append( aTypesIter.Value() ); - aClosuresList->Append( (bool)aClosuresIter.Value() ); - - getPointsLists( aNbSect, aJoinListX, aJoinListY ); - } - else - { - Handle(TDataStd_RealList) aListX, aListY; - getPointsLists( aNbSect, aListX, aListY ); - - TColStd_ListIteratorOfListOfReal anIterX( aListX->List() ); - TColStd_ListIteratorOfListOfReal anIterY( aListY->List() ); - for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() ) - { - aJoinListX->Append( anIterX.Value() ); - aJoinListY->Append( anIterY.Value() ); - } - - removePointsLists( aNbSect ); - } - } - - // Move the list which are after theISectionTo to correct place - for ( int i = theISectionTo + 1, j = theISectionFrom + 1; i < aNbSect; ++i, j++ ) - { - CurveCreator::Coordinates aPoints = getPoints( i ); - removePointsLists( i ); - addPoints( aPoints, j ); - } - } - } - - if ( !anIsOperation ) - commitOperation(); - - return true; -} - -int HYDROData_PolylineXY::getNbSections() const -{ - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - - return aNamesList.IsNull() ? 0 : aNamesList->Extent(); -} - -TCollection_ExtendedString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList ) -{ - NCollection_Map aNamesMap; - - TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() ); - for ( ; aNamesIter.More(); aNamesIter.Next() ) - aNamesMap.Add( aNamesIter.Value() ); - - TCollection_ExtendedString aResName; - - int aPrefIdx = 1; - do - { - aResName = "Section_" + aPrefIdx; - ++aPrefIdx; - } - while ( aNamesMap.Contains( aResName ) ); - - return aResName; -} - -int HYDROData_PolylineXY::addSection( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ) -{ - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList ); - - TCollection_ExtendedString aSectName = theName.c_str(); - if ( aSectName.Length() <= 0 ) - aSectName = getUniqueSectionName( aNamesList ); - - aNamesList->Append( aSectName ); - aTypesList->Append( theType ); - aClosuresList->Append( theIsClosed ); - - int aSectId = aNamesList->Extent() - 1; - - // Just to create empty data - Handle(TDataStd_RealList) aListX, aListY; - getPointsLists( aSectId, aListX, aListY ); - - if ( !anIsOperation ) - commitOperation(); - - return aSectId; -} - -bool HYDROData_PolylineXY::removeSection( const int theISection ) -{ - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - if ( aNamesList.IsNull() || aNamesList->IsEmpty() ) - return false; - - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - if ( aNamesList->Extent() == 1 ) - { - removeSectionsLists(); - removePointsLists(); - } - else - { - TDataStd_ListOfExtendedString anOldNamesList; - anOldNamesList = aNamesList->List(); - - TColStd_ListOfInteger anOldTypesList; - anOldTypesList = aTypesList->List(); - - TDataStd_ListOfByte anOldClosuresList; - anOldClosuresList = aClosuresList->List(); - - // Refill the existing lists - aNamesList->Clear(); - aTypesList->Clear(); - aClosuresList->Clear(); - - TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList ); - TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList ); - TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList ); - for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More(); - aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i ) - { - if ( i == theISection ) - continue; // skip index to remove - - aNamesList->Append( aNamesIter.Value() ); - aTypesList->Append( aTypesIter.Value() ); - aClosuresList->Append( (bool)aClosuresIter.Value() ); - } - - // Remove points that belong to removed section - removePointsLists( theISection ); - } - - if ( !anIsOperation ) - commitOperation(); - - return true; -} - -bool HYDROData_PolylineXY::isClosed( const int theISection ) const -{ - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() ) - return false; - - TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() ); - for ( int i = 0; aClosuresIter.More() && i != theISection; aClosuresIter.Next(), ++i ); - - return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false; -} - -bool HYDROData_PolylineXY::setClosed( const int theISection, - const bool theIsClosed ) -{ - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() ) - return false; - - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - TDataStd_ListOfByte anOldClosuresList; - anOldClosuresList = aClosuresList->List(); - - // Refill the existing list - aClosuresList->Clear(); - - TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList ); - for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i ) - aClosuresList->Append( i == theISection ? theIsClosed : (bool)aClosuresIter.Value() ); - - if ( !anIsOperation ) - commitOperation(); - - return true; + return TopoDS_Wire(); } -std::string HYDROData_PolylineXY::getSectionName( const int theISection ) const +int HYDROData_PolylineXY::NbSections() const { - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() ) - return ""; - - TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() ); - for ( int i = 0; aNamesIter.More() && i != theISection; aNamesIter.Next(), ++i ); - - TCollection_AsciiString aResName; - if ( aNamesIter.More() ) - aResName = aNamesIter.Value(); - - return aResName.ToCString(); + return 1; } -bool HYDROData_PolylineXY::setSectionName( const int theISection, - const std::string& theName ) +void HYDROData_PolylineXY::AddSection( const bool /*theIsClosed*/ ) { - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() ) - return false; - - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - TDataStd_ListOfExtendedString anOldNamesList; - anOldNamesList = aNamesList->List(); - - // Refill the existing list - aNamesList->Clear(); - - TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() ); - for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i ) - aNamesList->Append( i == theISection ? theName.c_str() : aNamesIter.Value() ); - - if ( !anIsOperation ) - commitOperation(); - - return true; } -CurveCreator::SectionType HYDROData_PolylineXY::getSectionType( const int theISection ) const +bool HYDROData_PolylineXY::IsClosedSection( const int /*theSectionIndex*/ ) const { - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() ) - return CurveCreator::Polyline; - - TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() ); - for ( int i = 0; aTypesIter.More() && i != theISection; aTypesIter.Next(), ++i ); - - return aTypesIter.More() ? (CurveCreator::SectionType)aTypesIter.Value() : CurveCreator::Polyline; + return false; } -bool HYDROData_PolylineXY::setSectionType( const int theISection, - const CurveCreator::SectionType theType ) +void HYDROData_PolylineXY::RemoveSection( const int /*theSectionIndex*/ ) { - Handle(TDataStd_ExtStringList) aNamesList; - Handle(TDataStd_IntegerList) aTypesList; - Handle(TDataStd_BooleanList) aClosuresList; - getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); - if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() ) - return false; - - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - TColStd_ListOfInteger anOldTypesList; - anOldTypesList = aTypesList->List(); - - // Refill the existing list - aTypesList->Clear(); - - TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList ); - for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i ) - aTypesList->Append( i == theISection ? theType : aTypesIter.Value() ); - - if ( !anIsOperation ) - commitOperation(); - - return true; + RemoveSections(); } -void addPointsToLists( const CurveCreator::Coordinates& theCoords, - Handle(TDataStd_RealList)& theListX, - Handle(TDataStd_RealList)& theListY, - const bool theIsAppend ) +void HYDROData_PolylineXY::RemoveSections() { - CurveCreator::Coordinates::const_iterator aBegIter = theCoords.begin(); - CurveCreator::Coordinates::const_iterator anEndIter = theCoords.end(); - while ( aBegIter != anEndIter ) - { - const CurveCreator::TypeCoord& aCoordX = *aBegIter++; - if ( aBegIter == anEndIter ) - break; - - const CurveCreator::TypeCoord& aCoordY = *aBegIter++; - - if ( theIsAppend ) - { - theListX->Append( aCoordX ); - theListY->Append( aCoordY ); - } - else - { - theListX->Prepend( aCoordX ); - theListY->Prepend( aCoordY ); - } - } + removePointsLists( 0 ); } -bool HYDROData_PolylineXY::addPoints( const CurveCreator::Coordinates& theCoords, - const int theISection, - const int theIPnt ) +void HYDROData_PolylineXY::AddPoint( const int /*theSectionIndex*/, + const Point& thePoint, + const int thePointIndex ) { - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); + double aNewCoordU = thePoint.X(); + double aNewCoordZ = thePoint.Y(); - Handle(TDataStd_RealList) aListX, aListY; - getPointsLists( theISection, aListX, aListY ); + Handle(TDataStd_RealList) aListU, aListZ; + getPointsLists( 0, aListU, aListZ ); - if ( theIPnt < 0 || theIPnt >= aListX->Extent() ) + if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() ) { - addPointsToLists( theCoords, aListX, aListY, true ); + aListU->Append( aNewCoordU ); + aListZ->Append( aNewCoordZ ); + return; } - else + else if ( aNewCoordU < aListU->First() ) { - TColStd_ListOfReal anOldListX; - anOldListX = aListX->List(); - - TColStd_ListOfReal anOldListY; - anOldListY = aListY->List(); - - // Refill the existing lists - aListX->Clear(); - aListY->Clear(); - - TColStd_ListIteratorOfListOfReal anIterX( anOldListX ); - TColStd_ListIteratorOfListOfReal anIterY( anOldListY ); - for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i ) - { - double aCoordX = anIterX.Value(); - double aCoordY = anIterY.Value(); - - if ( i == theIPnt ) - { - // Insert our new points - addPointsToLists( theCoords, aListX, aListY, true ); - } - - aListX->Append( aCoordX ); - aListY->Append( aCoordY ); - } + aListU->Prepend( aNewCoordU ); + aListZ->Prepend( aNewCoordZ ); + return; } - if ( !anIsOperation ) - commitOperation(); + TColStd_ListOfReal anOldListU; + anOldListU = aListU->List(); - return true; -} - -bool HYDROData_PolylineXY::setPoint( const int theISection, - const int theIPnt, - const CurveCreator::Coordinates& theCoords ) -{ - if ( theCoords.size() < 2 ) - return false; + TColStd_ListOfReal anOldListZ; + anOldListZ = aListZ->List(); - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); + // Crsat new lists + removePointsLists( 0 ); + getPointsLists( 0, aListU, aListZ ); - Handle(TDataStd_RealList) aListX, aListY; - getPointsLists( theISection, aListX, aListY ); - - if ( theIPnt < 0 ) - { - addPointsToLists( theCoords, aListX, aListY, false ); - } - else if ( theIPnt >= aListX->Extent() ) - { - addPointsToLists( theCoords, aListX, aListY, true ); - } - else + bool anIsInserted = false; + TColStd_ListIteratorOfListOfReal anIterU( anOldListU ); + TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ ); + for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() ) { - CurveCreator::Coordinates::const_iterator aBegIter = theCoords.begin(); - const CurveCreator::TypeCoord& aNewCoordX = *aBegIter++; - const CurveCreator::TypeCoord& aNewCoordY = *aBegIter++; - - TColStd_ListOfReal anOldListX; - anOldListX = aListX->List(); - - TColStd_ListOfReal anOldListY; - anOldListY = aListY->List(); + double aCoordU = anIterU.Value(); + double aCoordZ = anIterZ.Value(); - // Refill the existing lists - aListX->Clear(); - aListY->Clear(); - - TColStd_ListIteratorOfListOfReal anIterX( anOldListX ); - TColStd_ListIteratorOfListOfReal anIterY( anOldListY ); - for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i ) + if ( !anIsInserted ) { - double aCoordX = anIterX.Value(); - double aCoordY = anIterY.Value(); - - if ( i == theIPnt ) + if ( ValuesEquals( aNewCoordU, aCoordU ) ) { - // Insert our new points instead of old one - aCoordX = aNewCoordX; - aCoordY = aNewCoordY; + // Just update Z value + aCoordZ = aNewCoordZ; + anIsInserted = true; + } + else if ( aNewCoordU < aCoordU ) + { + // Insert new point + aListU->Append( aNewCoordU ); + aListZ->Append( aNewCoordZ ); + anIsInserted = true; } - - aListX->Append( aCoordX ); - aListY->Append( aCoordY ); } - } - - if ( !anIsOperation ) - commitOperation(); - return true; + aListU->Append( aCoordU ); + aListZ->Append( aCoordZ ); + } } -//! Set coordinates of specified points from different sections -bool HYDROData_PolylineXY::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords) +void HYDROData_PolylineXY::SetPoint( const int theSectionIndex, + const int /*thePointIndex*/, + const Point& thePoint ) { - return false; + AddPoint( theSectionIndex, thePoint ); } -bool HYDROData_PolylineXY::removePoint( const int theISection, - const int theIPnt ) +void HYDROData_PolylineXY::RemovePoint( const int /*theSectionIndex*/, + const int thePointIndex ) { - Handle(TDataStd_RealList) aListX, aListY; - getPointsLists( theISection, aListX, aListY, false ); - if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() ) - return false; - - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); + Handle(TDataStd_RealList) aListU, aListZ; + getPointsLists( 0, aListU, aListZ, false ); + if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() ) + return; - if ( aListX->Extent() == 1 ) - { - removePointsLists( theISection ); - } - else - { - TColStd_ListOfReal anOldListX; - anOldListX = aListX->List(); + TColStd_ListOfReal anOldListU; + anOldListU = aListU->List(); - TColStd_ListOfReal anOldListY; - anOldListY = aListY->List(); + TColStd_ListOfReal anOldListZ; + anOldListZ = aListZ->List(); - // Refill the existing lists - aListX->Clear(); - aListY->Clear(); + // Creat new lists + removePointsLists( 0 ); + getPointsLists( 0, aListU, aListZ ); - TColStd_ListIteratorOfListOfReal anIterX( anOldListX ); - TColStd_ListIteratorOfListOfReal anIterY( anOldListY ); - for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i ) - { - if ( i == theIPnt ) - continue; // skip index to remove + bool anIsInserted = false; + TColStd_ListIteratorOfListOfReal anIterU( anOldListU ); + TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ ); + for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i ) + { + if ( i == thePointIndex ) + continue; // skip index to remove - aListX->Append( anIterX.Value() ); - aListY->Append( anIterY.Value() ); - } + aListU->Append( anIterU.Value() ); + aListZ->Append( anIterZ.Value() ); } - - if ( !anIsOperation ) - commitOperation(); - - return true; } -//! Remove several points from different sections with given ids -bool HYDROData_PolylineXY::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) +HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int /*theSectionIndex*/ ) const { - return false; -} + PointsList aResList; -CurveCreator::Coordinates HYDROData_PolylineXY::getPoints( const int theISection ) const -{ - CurveCreator::Coordinates aResList; + Handle(TDataStd_RealList) aListU, aListZ; + getPointsLists( 0, aListU, aListZ, false ); + if ( aListU.IsNull() || aListZ.IsNull() ) + return aResList; - if ( theISection < 0 ) - { - int aNbSections = getNbSections(); - for ( int i = 0; i < aNbSections; ++i ) - { - CurveCreator::Coordinates aSectCoords = getPoints( i ); - aResList.insert( aResList.end(), aSectCoords.begin(), aSectCoords.end()); - } - } - else + TColStd_ListIteratorOfListOfReal anIterU( aListU->List() ); + TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() ); + for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() ) { - Handle(TDataStd_RealList) aListX, aListY; - getPointsLists( theISection, aListX, aListY, false ); - if ( !aListX.IsNull() && !aListY.IsNull() ) - { - TColStd_ListIteratorOfListOfReal anIterX( aListX->List() ); - TColStd_ListIteratorOfListOfReal anIterY( aListY->List() ); - for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() ) - { - const double& aCoordX = anIterX.Value(); - const double& aCoordY = anIterY.Value(); - - aResList.push_back( aCoordX ); - aResList.push_back( aCoordY ); - } - } + Point aPoint( anIterU.Value(), anIterZ.Value() ); + aResList.Append( aPoint ); } return aResList; diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index 943f4d8f..ae8c848f 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -33,98 +33,77 @@ public: public: - // Implementation of IPolyline interface - /** * Returns the 3D presentation of all points. */ - HYDRODATA_EXPORT virtual ListAISObjects constructWire() const; - -public: - - // Implementation of ICurve interface - - - /***********************************************/ - /*** Section methods ***/ - /***********************************************/ + HYDRODATA_EXPORT virtual TopoDS_Wire GetWire() const; - //! Clear the polyline (remove all sections) - HYDRODATA_EXPORT virtual bool clear(); - - //! Join range of sections to one section (join all sections if -1 is passed in one of arguments) - HYDRODATA_EXPORT virtual bool join( const int theISectionTo = -1, - const int theISectionFrom = -1 ); - - //! Get number of sections - HYDRODATA_EXPORT virtual int getNbSections() const; - - //! Add a new section. - HYDRODATA_EXPORT virtual int addSection( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ); - - //! Removes the given section. - HYDRODATA_EXPORT virtual bool removeSection( const int theISection ); - - //! Get "closed" flag of the specified section - HYDRODATA_EXPORT virtual bool isClosed( const int theISection ) const; /** - * Set "closed" flag of the specified section (all sections if - * \a theISection is -1). + * Returns number of sections. */ - HYDRODATA_EXPORT virtual bool setClosed( const int theISection, - const bool theIsClosed ); - - //! Returns specifyed section name - HYDRODATA_EXPORT virtual std::string getSectionName( const int theISection ) const; + HYDRODATA_EXPORT virtual int NbSections() const; - /** Set name of the specified section */ - HYDRODATA_EXPORT virtual bool setSectionName( const int theISection, - const std::string& theName ); + /** + * Adds new one section. + * \param theIsClosed flag indicates type of polyline + */ + HYDRODATA_EXPORT virtual void AddSection( const bool theIsClosed ); - //! Get type of the specified section - HYDRODATA_EXPORT virtual CurveCreator::SectionType getSectionType( const int theISection ) const; + /** + * Returns true if section with given index is closed. + * \param theSectionIndex index of section + */ + HYDRODATA_EXPORT virtual bool IsClosedSection( const int theSectionIndex ) const; /** - * Set type of the specified section (or all sections - * if \a theISection is -1). + * Removes section with given index. + * \param theSectionIndex index of section */ - HYDRODATA_EXPORT virtual bool setSectionType( const int theISection, - const CurveCreator::SectionType theType ); + HYDRODATA_EXPORT virtual void RemoveSection( const int theSectionIndex ); + /** + * Removes all sections. + */ + HYDRODATA_EXPORT virtual void RemoveSections(); - /***********************************************/ - /*** Point methods ***/ - /***********************************************/ /** - * Insert one or several points to the specified section starting from the given theIPnt index - * (or add these at the end of section points if \a theIPnt is -1). + * Adds new point for section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePoint point to add + * \param theBeforeIndex if not equal -1 then insert point in this pos */ - HYDRODATA_EXPORT virtual bool addPoints( const CurveCreator::Coordinates& theCoords, - const int theISection, - const int theIPnt = -1 ); + HYDRODATA_EXPORT virtual void AddPoint( const int theSectionIndex, + const Point& thePoint, + const int thePointIndex = -1 ); - //! Set coordinates of specified point - HYDRODATA_EXPORT virtual bool setPoint( const int theISection, - const int theIPnt, - const CurveCreator::Coordinates& theCoords ); - - //! Set coordinates of specified points from different sections - HYDRODATA_EXPORT virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords); + /** + * Replaces point for section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePointIndex index of point to replace + * \param thePoint new point + */ + HYDRODATA_EXPORT virtual void SetPoint( const int theSectionIndex, + const int thePointIndex, + const Point& thePoint ); - //! Remove point with given id - HYDRODATA_EXPORT virtual bool removePoint( const int theISection, const int theIPnt = -1 ); + /** + * Removes point from section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePointIndex index of point + */ + HYDRODATA_EXPORT virtual void RemovePoint( const int theSectionIndex, + const int thePointIndex ); - //! Remove several points from different sections with given ids - HYDRODATA_EXPORT virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs); /** - * Get points of a section (the total points in Curve if theISection is equal to -1).. + * Returns list of points. + * \param theSectionIndex if not equal -1 then list of points returned + * only for section with this index + * \return list of points */ - HYDRODATA_EXPORT virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const; + HYDRODATA_EXPORT virtual PointsList GetPoints( const int theSectionIndex = -1 ) const; protected: diff --git a/src/HYDROData/HYDROData_Profile.cxx b/src/HYDROData/HYDROData_Profile.cxx index 4374e043..9832cadb 100755 --- a/src/HYDROData/HYDROData_Profile.cxx +++ b/src/HYDROData/HYDROData_Profile.cxx @@ -196,40 +196,32 @@ Handle(HYDROData_ProfileUZ) HYDROData_Profile::GetProfileUZ( const bool theIsCre int HYDROData_Profile::NbPoints() const { Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false ); - return aProfileUZ.IsNull() ? 0 : aProfileUZ->getNbPoints(); + return aProfileUZ.IsNull() ? 0 : aProfileUZ->NbPoints(); } void HYDROData_Profile::RemovePoints() { Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false ); if ( !aProfileUZ.IsNull() ) - aProfileUZ->clear(); + aProfileUZ->RemoveSections(); } -void HYDROData_Profile::SetParametricPoints( const CurveCreator::Coordinates& theCoords ) +void HYDROData_Profile::SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints ) { RemovePoints(); Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ(); - - CurveCreator::Coordinates::const_iterator aBegIter = theCoords.begin(); - CurveCreator::Coordinates::const_iterator anEndIter = theCoords.end(); - while ( aBegIter != anEndIter ) + for ( int i = 1, n = thePoints.Length(); i <= n ; ++i ) { - const CurveCreator::TypeCoord& aCoordX = *aBegIter++; - if ( aBegIter == anEndIter ) - break; - - const CurveCreator::TypeCoord& aCoordY = *aBegIter++; - - aProfileUZ->addPoint( aCoordX, aCoordY, 0 ); + const HYDROData_ProfileUZ::Point& aPoint = thePoints.Value( i ); + aProfileUZ->AddPoint( 0, aPoint ); } } -CurveCreator::Coordinates HYDROData_Profile::GetParametricPoints() const +HYDROData_ProfileUZ::PointsList HYDROData_Profile::GetParametricPoints() const { Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false ); - return aProfileUZ.IsNull() ? CurveCreator::Coordinates() : aProfileUZ->getPoints(); + return aProfileUZ.IsNull() ? HYDROData_ProfileUZ::PointsList() : aProfileUZ->GetPoints(); } void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints ) @@ -253,7 +245,8 @@ void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints ) double aDistance = gp_Pnt2d( aFirstPoint ).Distance( aPointXY ); - aProfileUZ->addPoint( 0, aDistance, aPoint.Z() ); + HYDROData_ProfileUZ::Point aParPoint( aDistance, aPoint.Z() ); + aProfileUZ->AddPoint( 0, aParPoint ); } SetFirstPoint( aFirstPoint ); @@ -268,15 +261,12 @@ HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints() const if ( !GetFirstPoint( aFirstPoint ) || !GetLastPoint( aLastPoint ) ) return aResPoints; - CurveCreator::Coordinates aParametricPoints = GetParametricPoints(); - if ( aParametricPoints.size() < 4 ) + HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints(); + if ( aParametricPoints.Length() < 2 ) return aResPoints; - CurveCreator::Coordinates::const_iterator aBegIter = aParametricPoints.begin(); - CurveCreator::Coordinates::const_iterator anEndIter = aParametricPoints.end()--; - - gp_Pnt2d aFirstParPoint( *aBegIter++, *aBegIter++ ); - gp_Pnt2d aLastParPoint( *anEndIter--, *anEndIter ); + const HYDROData_ProfileUZ::Point& aFirstParPoint = aParametricPoints.First(); + const HYDROData_ProfileUZ::Point& aLastParPoint = aParametricPoints.Last(); double aGeoDistance = gp_Pnt2d( aFirstPoint ).Distance( aLastPoint ); double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) ); @@ -285,13 +275,11 @@ HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints() const aResPoints.Append( ProfilePoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) ); // Compute all other points - while ( aBegIter != anEndIter ) + for ( int i = 2, n = aParametricPoints.Length(); i < n ; ++i ) { - const CurveCreator::TypeCoord& aCoordU = *aBegIter++; - if ( aBegIter == anEndIter ) - break; + const HYDROData_ProfileUZ::Point& aParPoint = aParametricPoints.Value( i ); - double aParPointDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aCoordU, 0 ) ); + double aParPointDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aParPoint.X(), 0 ) ); double aParLen = ( aParPointDist / aParCommonDist ) * aGeoDistance; @@ -300,10 +288,7 @@ HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints() const double aParX = ( aFirstPoint.X() + aRatio * aLastPoint.X() ) / ( 1 + aRatio ); double aParY = ( aFirstPoint.Y() + aRatio * aLastPoint.Y() ) / ( 1 + aRatio ); - - const CurveCreator::TypeCoord& aCoordZ = *aBegIter++; - - ProfilePoint aCompPoint( aParX, aParY, aCoordZ ); + ProfilePoint aCompPoint( aParX, aParY, aParPoint.Y() ); aResPoints.Append( aCompPoint ); } @@ -414,8 +399,8 @@ bool HYDROData_Profile::ImportFromFile( OSD_File& theFile ) bool anIsParametric = false; bool anIsGeoref = false; - CurveCreator::Coordinates aPointsUZ; - ProfilePoints aPointsXYZ; + HYDROData_ProfileUZ::PointsList aPointsUZ; + ProfilePoints aPointsXYZ; double aPrevVal = -DBL_MAX; while ( !theFile.IsAtEnd() ) @@ -457,8 +442,8 @@ bool HYDROData_Profile::ImportFromFile( OSD_File& theFile ) break; } - aPointsUZ.push_back( aCoordX ); - aPointsUZ.push_back( aCoordY ); + HYDROData_ProfileUZ::Point aPoint( aCoordX, aCoordY ); + aPointsUZ.Append( aPoint ); aPrevVal = aCoordX; } @@ -477,7 +462,7 @@ bool HYDROData_Profile::ImportFromFile( OSD_File& theFile ) } } - aRes = aRes && ( anIsParametric && !aPointsUZ.empty() || + aRes = aRes && ( anIsParametric && !aPointsUZ.IsEmpty() || anIsGeoref && !aPointsXYZ.IsEmpty() ); if ( aRes ) { diff --git a/src/HYDROData/HYDROData_Profile.h b/src/HYDROData/HYDROData_Profile.h index 13c6f619..775ced7a 100644 --- a/src/HYDROData/HYDROData_Profile.h +++ b/src/HYDROData/HYDROData_Profile.h @@ -8,7 +8,6 @@ DEFINE_STANDARD_HANDLE(HYDROData_Profile, HYDROData_Object) -class gp_XY; class gp_XYZ; class OSD_File; class Handle(HYDROData_Document); @@ -129,13 +128,13 @@ public: * Replace current profile parametric points by new one. * \param thePoints the list with new points in parametric form */ - HYDRODATA_EXPORT void SetParametricPoints( const CurveCreator::Coordinates& theCoords ); + HYDRODATA_EXPORT void SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints ); /** * Returns profile points in parametric form. * \return points list */ - HYDRODATA_EXPORT CurveCreator::Coordinates GetParametricPoints() const; + HYDRODATA_EXPORT HYDROData_ProfileUZ::PointsList GetParametricPoints() const; /** @@ -198,7 +197,7 @@ private: * Imports Profile data from parametric file. */ bool importParametricFile( OSD_File& theFile, - CurveCreator::Coordinates& thePoints ); + HYDROData_ProfileUZ::PointsList& thePoints ); /** * Imports Profile data from Georeferenced file. diff --git a/src/HYDROData/HYDROData_ProfileUZ.cxx b/src/HYDROData/HYDROData_ProfileUZ.cxx index 014288dc..36ce31c6 100755 --- a/src/HYDROData/HYDROData_ProfileUZ.cxx +++ b/src/HYDROData/HYDROData_ProfileUZ.cxx @@ -24,116 +24,42 @@ HYDROData_ProfileUZ::~HYDROData_ProfileUZ() { } -CurveCreator_ICurve::ListAISObjects HYDROData_ProfileUZ::constructWire() const +TopoDS_Wire HYDROData_ProfileUZ::GetWire() const { // TODO - ListAISObjects aProfileObjects; - return aProfileObjects; + return TopoDS_Wire(); } -bool HYDROData_ProfileUZ::clear() -{ - removePointsLists(); - return true; -} - -bool HYDROData_ProfileUZ::join( const int theISectionTo, - const int theISectionFrom ) -{ - return false; -} - -int HYDROData_ProfileUZ::getNbSections() const +int HYDROData_ProfileUZ::NbSections() const { return 1; } -int HYDROData_ProfileUZ::addSection( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ) -{ - return 0; -} - -bool HYDROData_ProfileUZ::removeSection( const int theISection ) +void HYDROData_ProfileUZ::AddSection( const bool /*theIsClosed*/ ) { - return clear(); } -bool HYDROData_ProfileUZ::isClosed( const int theISection ) const +bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const { return false; } -bool HYDROData_ProfileUZ::setClosed( const int theISection, - const bool theIsClosed ) +void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ ) { - return false; + RemoveSections(); } -std::string HYDROData_ProfileUZ::getSectionName( const int theISection ) const +void HYDROData_ProfileUZ::RemoveSections() { - return "Section_1"; + removePointsLists( 0 ); } -bool HYDROData_ProfileUZ::setSectionName( const int theISection, - const std::string& theName ) +void HYDROData_ProfileUZ::AddPoint( const int /*theSectionIndex*/, + const Point& thePoint, + const int thePointIndex ) { - return false; -} - -CurveCreator::SectionType HYDROData_ProfileUZ::getSectionType( const int theISection ) const -{ - return CurveCreator::Polyline; -} - -bool HYDROData_ProfileUZ::setSectionType( const int theISection, - const CurveCreator::SectionType theType ) -{ - return false; -} - -bool HYDROData_ProfileUZ::addPoints( const CurveCreator::Coordinates& theCoords, - const int theISection, - const int theIPnt ) -{ - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - bool aRes = true; - - int anAfterPnt = theIPnt; - - CurveCreator::Coordinates::const_iterator aBegIter = theCoords.begin(); - CurveCreator::Coordinates::const_iterator anEndIter = theCoords.end(); - while ( aBegIter != anEndIter ) - { - const CurveCreator::TypeCoord& aCoordX = *aBegIter++; - if ( aBegIter == anEndIter ) - break; - - const CurveCreator::TypeCoord& aCoordY = *aBegIter++; - - aRes = addPoint( aCoordX, aCoordY, theISection, anAfterPnt ) && aRes; - - if ( anAfterPnt != -1 ) - ++anAfterPnt; - } - - if ( !anIsOperation ) - commitOperation(); - - return aRes; -} - -bool HYDROData_ProfileUZ::addPoint( const CurveCreator::TypeCoord& theCoordX, - const CurveCreator::TypeCoord& theCoordY, - const int theISection, - const int theIPnt ) -{ - CurveCreator::TypeCoord aNewCoordU = theCoordX; - CurveCreator::TypeCoord aNewCoordZ = theCoordY; + double aNewCoordU = thePoint.X(); + double aNewCoordZ = thePoint.Y(); Handle(TDataStd_RealList) aListU, aListZ; getPointsLists( 0, aListU, aListZ ); @@ -142,69 +68,69 @@ bool HYDROData_ProfileUZ::addPoint( const CurveCreator::TypeCoord& theCoordX, { aListU->Append( aNewCoordU ); aListZ->Append( aNewCoordZ ); + return; } else if ( aNewCoordU < aListU->First() ) { aListU->Prepend( aNewCoordU ); aListZ->Prepend( aNewCoordZ ); + return; } - else - { - TColStd_ListOfReal anOldListU; - anOldListU = aListU->List(); - TColStd_ListOfReal anOldListZ; - anOldListZ = aListZ->List(); + TColStd_ListOfReal anOldListU; + anOldListU = aListU->List(); - // Refill the existing lists - aListU->Clear(); - aListZ->Clear(); + TColStd_ListOfReal anOldListZ; + anOldListZ = aListZ->List(); - bool anIsInserted = false; - TColStd_ListIteratorOfListOfReal anIterU( anOldListU ); - TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ ); - for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() ) - { - double aCoordU = anIterU.Value(); - double aCoordZ = anIterZ.Value(); + // Crsat new lists + removePointsLists( 0 ); + getPointsLists( 0, aListU, aListZ ); + + bool anIsInserted = false; + TColStd_ListIteratorOfListOfReal anIterU( anOldListU ); + TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ ); + for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() ) + { + double aCoordU = anIterU.Value(); + double aCoordZ = anIterZ.Value(); - if ( !anIsInserted ) + if ( !anIsInserted ) + { + if ( ValuesEquals( aNewCoordU, aCoordU ) ) { - if ( ValuesEquals( aNewCoordU, aCoordU ) ) - { - // Just update Z value - aCoordZ = aNewCoordZ; - anIsInserted = true; - } - else if ( aNewCoordU < aCoordU ) - { - // Insert new point - aListU->Append( aNewCoordU ); - aListZ->Append( aNewCoordZ ); - anIsInserted = true; - } + // Just update Z value + aCoordZ = aNewCoordZ; + anIsInserted = true; + } + else if ( aNewCoordU < aCoordU ) + { + // Insert new point + aListU->Append( aNewCoordU ); + aListZ->Append( aNewCoordZ ); + anIsInserted = true; } - - aListU->Append( aCoordU ); - aListZ->Append( aCoordZ ); } + + aListU->Append( aCoordU ); + aListZ->Append( aCoordZ ); } +} - return true; +void HYDROData_ProfileUZ::SetPoint( const int theSectionIndex, + const int /*thePointIndex*/, + const Point& thePoint ) +{ + AddPoint( theSectionIndex, thePoint ); } -bool HYDROData_ProfileUZ::removePoint( const int /*theISection*/, - const int theIPnt ) +void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/, + const int thePointIndex ) { Handle(TDataStd_RealList) aListU, aListZ; getPointsLists( 0, aListU, aListZ, false ); - if ( aListU.IsNull() || aListZ.IsNull() || - theIPnt < 0 || theIPnt >= aListU->Extent() ) - return false; - - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); + if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() ) + return; TColStd_ListOfReal anOldListU; anOldListU = aListU->List(); @@ -212,62 +138,26 @@ bool HYDROData_ProfileUZ::removePoint( const int /*theISection*/, TColStd_ListOfReal anOldListZ; anOldListZ = aListZ->List(); - // Refill the existing lists - aListU->Clear(); - aListZ->Clear(); + // Creat new lists + removePointsLists( 0 ); + getPointsLists( 0, aListU, aListZ ); + bool anIsInserted = false; TColStd_ListIteratorOfListOfReal anIterU( anOldListU ); TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ ); for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i ) { - if ( i == theIPnt ) + if ( i == thePointIndex ) continue; // skip index to remove aListU->Append( anIterU.Value() ); aListZ->Append( anIterZ.Value() ); } - - if ( !anIsOperation ) - commitOperation(); - - return true; -} - -//! Remove several points from different sections with given ids -bool HYDROData_ProfileUZ::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) -{ - return false; -} - -bool HYDROData_ProfileUZ::setPoint( const int /*theISection*/, - const int theIPoint, - const CurveCreator::Coordinates& theNewCoords ) -{ - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - // At first we remove point - removePoint( 0, theIPoint ); - - // And then we insert it to correct place - bool aRes = addPoints( theNewCoords, 0 ); - - if ( !anIsOperation ) - commitOperation(); - - return aRes; } -//! Set coordinates of specified points from different sections -bool HYDROData_ProfileUZ::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords) +HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const { - return false; -} - -CurveCreator::Coordinates HYDROData_ProfileUZ::getPoints( const int /*theISection*/ ) const -{ - CurveCreator::Coordinates aResList; + PointsList aResList; Handle(TDataStd_RealList) aListU, aListZ; getPointsLists( 0, aListU, aListZ, false ); @@ -278,11 +168,8 @@ CurveCreator::Coordinates HYDROData_ProfileUZ::getPoints( const int /*theISectio TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() ); for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() ) { - const double& aCoordU = anIterU.Value(); - const double& aCoordZ = anIterZ.Value(); - - aResList.push_back( aCoordU ); - aResList.push_back( aCoordZ ); + Point aPoint( anIterU.Value(), anIterZ.Value() ); + aResList.Append( aPoint ); } return aResList; diff --git a/src/HYDROData/HYDROData_ProfileUZ.h b/src/HYDROData/HYDROData_ProfileUZ.h index 608b6953..22441a56 100644 --- a/src/HYDROData/HYDROData_ProfileUZ.h +++ b/src/HYDROData/HYDROData_ProfileUZ.h @@ -30,117 +30,82 @@ public: */ HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_PROFILEUZ;} - public: - // Implementation of IPolyline interface - /** * Returns the 3D presentation of all points. */ - HYDRODATA_EXPORT virtual ListAISObjects constructWire() const; - -public: - - // Implementation of ICurve interface - - - /***********************************************/ - /*** Section methods ***/ - /***********************************************/ + HYDRODATA_EXPORT virtual TopoDS_Wire GetWire() const; - //! Clear the polyline (remove all sections) - HYDRODATA_EXPORT virtual bool clear(); - - //! Join range of sections to one section (join all sections if -1 is passed in one of arguments) - HYDRODATA_EXPORT virtual bool join( const int theISectionTo = -1, - const int theISectionFrom = -1 ); - - //! Get number of sections - HYDRODATA_EXPORT virtual int getNbSections() const; - - //! Add a new section. - HYDRODATA_EXPORT virtual int addSection( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ); - - //! Removes the given sections. - HYDRODATA_EXPORT virtual bool removeSection( const int theISection ); - - //! Get "closed" flag of the specified section - HYDRODATA_EXPORT virtual bool isClosed( const int theISection ) const; /** - * Set "closed" flag of the specified section (all sections if - * \a theISection is -1). + * Returns number of sections. */ - HYDRODATA_EXPORT virtual bool setClosed( const int theISection, - const bool theIsClosed ); - - //! Returns specifyed section name - HYDRODATA_EXPORT virtual std::string getSectionName( const int theISection ) const; - - /** Set name of the specified section */ - HYDRODATA_EXPORT virtual bool setSectionName( const int theISection, - const std::string& theName ); - - //! Get type of the specified section - HYDRODATA_EXPORT virtual CurveCreator::SectionType getSectionType( const int theISection ) const; + HYDRODATA_EXPORT virtual int NbSections() const; /** - * Set type of the specified section (or all sections - * if \a theISection is -1). + * Adds new one section. + * \param theIsClosed flag indicates type of polyline */ - HYDRODATA_EXPORT virtual bool setSectionType( const int theISection, - const CurveCreator::SectionType theType ); - + HYDRODATA_EXPORT virtual void AddSection( const bool theIsClosed ); - /***********************************************/ - /*** Point methods ***/ - /***********************************************/ + /** + * Returns true if section with given index is closed. + * \param theSectionIndex index of section + */ + HYDRODATA_EXPORT virtual bool IsClosedSection( const int theSectionIndex ) const; /** - * Insert one or several points to the specified section starting from the given theIPnt index - * (or add these at the end of section points if \a theIPnt is -1). + * Removes section with given index. + * \param theSectionIndex index of section */ - HYDRODATA_EXPORT virtual bool addPoints( const CurveCreator::Coordinates& theCoords, - const int theISection, - const int theIPnt = -1 ); + HYDRODATA_EXPORT virtual void RemoveSection( const int theSectionIndex ); - //! Set coordinates of specified point - HYDRODATA_EXPORT virtual bool setPoint( const int theISection, - const int theIPnt, - const CurveCreator::Coordinates& theCoords ); + /** + * Removes all sections. + */ + HYDRODATA_EXPORT virtual void RemoveSections(); - //! Set coordinates of specified points from different sections - HYDRODATA_EXPORT virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords); - //! Remove point with given id - HYDRODATA_EXPORT virtual bool removePoint( const int theISection, const int theIPnt = -1 ); + /** + * Adds new point for section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePoint point to add + * \param theBeforeIndex if not equal -1 then insert point in this pos + */ + HYDRODATA_EXPORT virtual void AddPoint( const int theSectionIndex, + const Point& thePoint, + const int thePointIndex = -1 ); - //! Remove several points from different sections with given ids - HYDRODATA_EXPORT virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs); + /** + * Replaces point for section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePointIndex index of point to replace + * \param thePoint new point + */ + HYDRODATA_EXPORT virtual void SetPoint( const int theSectionIndex, + const int thePointIndex, + const Point& thePoint ); /** - * Get points of a section (the total points in Curve if theISection is equal to -1).. + * Removes point from section with index "theSectionIndex". + * \param theSectionIndex index of section + * \param thePointIndex index of point */ - HYDRODATA_EXPORT virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const; + HYDRODATA_EXPORT virtual void RemovePoint( const int theSectionIndex, + const int thePointIndex ); -protected: /** - * Insert point to the specified section after the given theIPnt index. - * (or add these at the end of section points if \a theIPnt is -1). + * Returns list of points. + * \param theSectionIndex if not equal -1 then list of points returned + * only for section with this index + * \return list of points */ - HYDRODATA_EXPORT virtual bool addPoint( - const CurveCreator::TypeCoord& theCoordX, - const CurveCreator::TypeCoord& theCoordY, - const int theISection, - const int theIPnt = -1 ); + HYDRODATA_EXPORT virtual PointsList GetPoints( const int theSectionIndex = -1 ) const; protected: - friend class HYDROData_Profile; friend class HYDROData_Iterator; /**