From: adv Date: Wed, 27 Nov 2013 11:07:15 +0000 (+0000) Subject: The curve creator for Profile object first implementation. X-Git-Tag: issue_132_11_28~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ef4d7d3d8ca516f771c37459c70597c67edb06d9;p=modules%2Fhydro.git The curve creator for Profile object first implementation. --- diff --git a/src/HYDROCurveCreator/CMakeLists.txt b/src/HYDROCurveCreator/CMakeLists.txt index 6913762d..ee2a4c9e 100644 --- a/src/HYDROCurveCreator/CMakeLists.txt +++ b/src/HYDROCurveCreator/CMakeLists.txt @@ -78,6 +78,7 @@ SET(_other_HEADERS CurveCreator_Section.hxx CurveCreator_Utils.h CurveCreator_PosPoint.hxx + CurveCreator_Profile.hxx ) # header files / to install @@ -97,6 +98,7 @@ SET(_other_SOURCES CurveCreator_Diff.cxx CurveCreator_Operation.cxx CurveCreator_Utils.cxx + CurveCreator_Profile.cxx ) IF(SALOME_BUILD_GUI) LIST(APPEND _other_SOURCES diff --git a/src/HYDROCurveCreator/CurveCreator_Profile.cxx b/src/HYDROCurveCreator/CurveCreator_Profile.cxx new file mode 100644 index 00000000..bd56d272 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Profile.cxx @@ -0,0 +1,252 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "CurveCreator_Profile.hxx" + +#include "CurveCreator.hxx" +#include "CurveCreator_PosPoint.hxx" +#include "CurveCreator_Section.hxx" +#include "CurveCreator_Displayer.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +CurveCreator_Profile::CurveCreator_Profile() +: CurveCreator_Curve( CurveCreator::Dim2d ) +{ + CurveCreator_Section *aSection = new CurveCreator_Section; + aSection->myName = getUniqSectionName(); + aSection->myType = CurveCreator::Polyline; + aSection->myIsClosed = false; + + mySections.push_back( aSection ); +} + +CurveCreator_Profile::~CurveCreator_Profile() +{ +} + +bool CurveCreator_Profile::moveSectionInternal( const int theISection, + const int theNewIndex ) +{ + return false; +} + +bool CurveCreator_Profile::moveSection( const int theISection, + const int theNewIndex ) +{ + return false; +} + +bool CurveCreator_Profile::clearInternal() +{ + // erase curve from the viewer + if( myDisplayer ) + myDisplayer->erase(); + + // Delete all allocated data. + mySections[ 0 ]->myPoints.clear(); + + return true; +} + +bool CurveCreator_Profile::joinInternal( const int theISectionTo, + const int theISectionFrom ) +{ + return false; +} + +bool CurveCreator_Profile::join( const int theISectionTo, + const int theISectionFrom ) +{ + return false; +} + +int CurveCreator_Profile::addSectionInternal( const std::string& theName, + const CurveCreator::SectionType theType, + const bool theIsClosed, + const CurveCreator::Coordinates& thePoints ) +{ + return -1; +} + +int CurveCreator_Profile::addSection( const std::string& theName, + const CurveCreator::SectionType theType, + const bool theIsClosed ) +{ + return -1; +} + +int CurveCreator_Profile::addSection( const std::string& theName, + const CurveCreator::SectionType theType, + const bool theIsClosed, + const CurveCreator::Coordinates& thePoints ) +{ + return -1; +} + +bool CurveCreator_Profile::removeSectionInternal( const int theISection ) +{ + return false; +} + +bool CurveCreator_Profile::removeSection( const int theISection ) +{ + return false; +} + +bool CurveCreator_Profile::setClosedInternal( const int theISection, + const bool theIsClosed ) +{ + return false; +} + +bool CurveCreator_Profile::setClosed( const int theISection, + const bool theIsClosed ) +{ + return false; +} + +bool CurveCreator_Profile::setSectionTypeInternal( const int theISection, + const CurveCreator::SectionType theType ) +{ + return false; +} + +bool CurveCreator_Profile::setSectionType( const int theISection, + const CurveCreator::SectionType theType ) +{ + return false; +} + +bool CurveCreator_Profile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ) +{ + bool res = false; + + CurveCreator_Section* aSection = mySections.at( 0 ); + if( !aSection ) + return res; + + CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); + for ( ; anIt != theSectionsMap.end(); anIt++ ) + { + int anISection = anIt->first; + if( anISection != 0 ) + continue; + + const CurveCreator::PosPointsList& aSectionPoints = anIt->second; + + CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); + for( ; aPntIt != aSectionPoints.end(); aPntIt++ ) + { + const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords; + CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin(); + for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ ) + { + const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++; + if ( aNewPntIt == aNewCoords.end() ) + break; + + const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt; + + CurveCreator::TypeCoord aC = aCoordU - 1; + if ( !aSection->myPoints.empty() ) + aC = *(aSection->myPoints.end() - 2); + + if ( aSection->myPoints.empty() || aCoordU > aC ) + { + aSection->myPoints.push_back( aCoordU ); + aSection->myPoints.push_back( aCoordZ ); + } + else if ( aCoordU < aSection->myPoints.front() ) + { + aSection->myPoints.push_front( aCoordZ ); + aSection->myPoints.push_front( aCoordU ); + } + else + { + CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin(); + for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ ) + { + const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++; + if ( aCoordU < aRefCoordU ) + break; + } + + aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 ); + } + } + } + + res = true; + } + + if ( res ) + redisplayCurve(); + + return res; +} + +//! For internal use only! Undo/Redo are not used here. +bool CurveCreator_Profile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ) +{ + bool res = false; + + CurveCreator_Section* aSection = mySections.at( 0 ); + if( !aSection ) + return res; + + CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); + for ( ; anIt != theSectionsMap.end(); anIt++ ) + { + int anISection = anIt->first; + if( anISection != 0 ) + continue; + + const CurveCreator::PosPointsList& aSectionPoints = anIt->second; + + CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); + for( ; aPntIt != aSectionPoints.end(); aPntIt++ ) + { + int anIPnt = (*aPntIt)->myID; + aSection->myPoints.erase( aSection->myPoints.begin() + toICoord( anIPnt ), + aSection->myPoints.begin() + toICoord( anIPnt ) + 2 ); + } + } + + res = addPointsInternal( theSectionsMap ); + + if ( res ) + redisplayCurve(); + + return res; +} diff --git a/src/HYDROCurveCreator/CurveCreator_Profile.hxx b/src/HYDROCurveCreator/CurveCreator_Profile.hxx new file mode 100644 index 00000000..288732c6 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Profile.hxx @@ -0,0 +1,129 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _CurveCreator_Profile_HeaderFile +#define _CurveCreator_Profile_HeaderFile + +#include "CurveCreator_Curve.hxx" + +/** + * The CurveCreator_Curve object is represented as one or more sets of + * connected points; thus CurveCreator_Curve object can contain several + * not connected curves (polylines or b-splines), each such curve has two + * only ends start and end points in other words non-manifold curves + * are not supported. + */ +class CURVECREATOR_EXPORT CurveCreator_Profile : public CurveCreator_Curve +{ + +public: + + //! Constructor of the curve. + CurveCreator_Profile(); + + //! Destructor. + virtual ~CurveCreator_Profile(); + +public: + + /***********************************************/ + /*** Section methods ***/ + /***********************************************/ + + //! For internal use only! Undo/Redo are not used here. + virtual bool clearInternal(); + + //! For internal use only! Undo/Redo are not used here. + virtual bool joinInternal( const int theISectionTo = -1, + const int theISectionFrom = -1 ); + + //! For internal use only! Undo/Redo are not used here. + virtual bool moveSectionInternal( const int theISection, + const int theNewIndex); + //! Move section to new position in list + virtual bool moveSection( const int theISection, + const int theNewIndex ); + + //! Join range of sections to one section (join all sections if -1 is passed in one of arguments) + virtual bool join( const int theISectionTo = -1, + const int theISectionFrom = -1 ); + + //! For internal use only! Undo/Redo are not used here. + virtual int addSectionInternal( const std::string &theName, + const CurveCreator::SectionType theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints); + //! Add a new section. + virtual int addSection( const std::string &theName, + const CurveCreator::SectionType theType, + const bool theIsClosed ); + //! Add a new section. + virtual int addSection( const std::string &theName, + const CurveCreator::SectionType theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints); + + + //! For internal use only! Undo/Redo are not used here. + virtual bool removeSectionInternal( const int theISection ); + + //! Removes the given sections. + virtual bool removeSection( const int theISection ); + + + //! For internal use only! Undo/Redo are not used here. + virtual bool setClosedInternal( const int theISection, + const bool theIsClosed ); + /** + * Set "closed" flag of the specified section (all sections if + * \a theISection is -1). + */ + virtual bool setClosed( const int theISection, + const bool theIsClosed ); + + + //! For internal use only! Undo/Redo are not used here. + virtual bool setSectionTypeInternal( const int theISection, + const CurveCreator::SectionType theType ); + /** + * Set type of the specified section (or all sections + * if \a theISection is -1). + */ + virtual bool setSectionType( const int theISection, + const CurveCreator::SectionType theType ); + + + /***********************************************/ + /*** Point methods ***/ + /***********************************************/ + + //! For internal use only! Undo/Redo are not used here. + virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ); + /** + * Add one point to the specified section starting from the given theIPnt index + * (or at the end of points if \a theIPnt is -1). + */ + //! For internal use only! Undo/Redo are not used here. + virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ); + +private: + +}; + +#endif