From: adv Date: Fri, 15 Nov 2013 05:59:12 +0000 (+0000) Subject: Curve creator has been moved from GEOM to HYDRO. X-Git-Tag: BR_hydro_v_0_3~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=66eed78107ad562c2846807c99978fe5a212cca4;p=modules%2Fhydro.git Curve creator has been moved from GEOM to HYDRO. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f68683cd..0bd2fb02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ find_package(SalomeCPPUNIT) set(HYDRO_salomeres_DATA share/salome/resources/hydro) +add_subdirectory (src/HYDROCurveCreator) add_subdirectory (src/HYDROData) add_subdirectory (src/HYDROGUI) add_subdirectory (src/HYDROPy) diff --git a/src/HYDROCurveCreator/CMakeLists.txt b/src/HYDROCurveCreator/CMakeLists.txt new file mode 100644 index 00000000..d1a5b304 --- /dev/null +++ b/src/HYDROCurveCreator/CMakeLists.txt @@ -0,0 +1,87 @@ + +include(../../CMake/Common.cmake) +include(../../CMake/UseQT4EXT.cmake) + +# --- options --- + +# additional include directories +INCLUDE_DIRECTORIES( + ${QT_INCLUDE_DIRS} + ${PTHREAD_INCLUDE_DIR} + ${CAS_INCLUDE_DIRS} + ${KERNEL_INCLUDE_DIRS} + ${GEOM_ROOT_DIR}/include/salome + ${GUI_ROOT_DIR}/include/salome +) + +# additional preprocessor / compiler flags +ADD_DEFINITIONS( + -DCURVECREATOR_EXPORTS + ${CAS_DEFINITIONS} + ${QT_DEFINITIONS} +) + +# libraries to link to +SET(_link_LIBRARIES + ${GEOM_GEOMUtils} + ${GUI_qtx} + ${GUI_suit} + ${GUI_OCCViewer} +) + +# --- headers --- + +# header files / to be processed by moc +SET(_moc_HEADERS + CurveCreator_NewSectionDlg.h + CurveCreator_TreeView.h +# CurveCreator_UndoOptsDlg.h + CurveCreator_Widget.h +) + +# header files / no processing +SET(_other_HEADERS + CurveCreator.hxx + CurveCreator_Curve.hxx + CurveCreator_Diff.hxx + CurveCreator_ICurve.hxx + CurveCreator_Listener.hxx + CurveCreator_Macro.hxx + CurveCreator_Operation.hxx + CurveCreator_Section.hxx +) + +# header files / to install +SET(CurveCreator_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) + +# --- sources --- + +# sources / moc wrappings +QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) + +# sources / static +SET(_other_SOURCES + CurveCreator_Curve.cxx + CurveCreator_Diff.cxx + CurveCreator_Operation.cxx +) + +LIST(APPEND _other_SOURCES + CurveCreator_NewSectionDlg.cxx + CurveCreator_TreeView.cxx +# CurveCreator_UndoOptsDlg.cxx + CurveCreator_Widget.cxx + ) + +# sources / to compile +SET(CurveCreator_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) + +# --- rules --- + +ADD_LIBRARY(HYDROCurveCreator ${CurveCreator_SOURCES} ${CurveCreator_HEADERS}) +TARGET_LINK_LIBRARIES(HYDROCurveCreator ${_link_LIBRARIES}) + +set(PROJECT_HEADERS ${CurveCreator_SOURCES}) +set(PROJECT_LIBRARIES HYDROCurveCreator) + +include(../../CMake/CommonInstall.cmake) diff --git a/src/HYDROCurveCreator/CurveCreator.hxx b/src/HYDROCurveCreator/CurveCreator.hxx new file mode 100644 index 00000000..031f7a5b --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator.hxx @@ -0,0 +1,46 @@ +// 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 +// + +// File: CurveCreator.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_HeaderFile +#define _CurveCreator_HeaderFile + +#include + +struct CurveCreator_Section; + +namespace CurveCreator +{ + //! Points coordinates + typedef float TypeCoord; + + /** List of coordinates in format depends on section dimension: + * 2D: [x1, y1, x2, y2, x3, y3, ..] + * 3D: [x1, y1, z1, x2, y2, z2, x3, y3, z3, ..] + */ + typedef std::deque Coordinates; + + //! List of sections + typedef std::deque Sections; + +}; + +#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.cxx b/src/HYDROCurveCreator/CurveCreator_Curve.cxx new file mode 100644 index 00000000..83b4c68f --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Curve.cxx @@ -0,0 +1,629 @@ +// 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 +// + +// File: CurveCreator_Curve.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_Curve.hxx" + +#include "CurveCreator.hxx" +#include "CurveCreator_Section.hxx" +#include "CurveCreator_Listener.hxx" + +#include + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimension ) +: myIsLocked (false), + myDimension (theDimension), + myListener(NULL), + myNbUndos (0), + myNbRedos (0), + myUndoDepth (-1), + myOpLevel(0) +{ +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_Curve::~CurveCreator_Curve() +{ + // Delete all allocated data. + clear(); +} + +//======================================================================= +// function: getDimension +// purpose: +//======================================================================= +CurveCreator::Dimension CurveCreator_Curve::getDimension() const +{ + return myDimension; +} + +//======================================================================= +// function: getUniqSectionName +// purpose: return unique section name +//======================================================================= +std::string CurveCreator_Curve::getUniqSectionName() const +{ + for( int i = 0 ; i < 1000000 ; i++ ){ + char aBuffer[255]; + sprintf( aBuffer, "Section_%d", i+1 ); + std::string aName(aBuffer); + int j; + for( j = 0 ; j < mySections.size() ; j++ ){ + if( mySections[j]->myName == aName ) + break; + } + if( j == mySections.size() ) + return aName; + } + return ""; +} + +//======================================================================= +// function: setListener +// purpose: set curve changes listener +//======================================================================= +void CurveCreator_Curve::setListener( CurveCreator_Listener* theListener ) +{ + myListener = theListener; +} + +//======================================================================= +// function: removeListener +// purpose: remove the attached listener +//======================================================================= +void CurveCreator_Curve::removeListener() +{ + myListener = NULL; +} + +//======================================================================= +// function: addDiff +// purpose: +//======================================================================= +bool CurveCreator_Curve::addEmptyDiff() +{ + bool isEnabled = false; + + if (myUndoDepth != 0) { + // Forget all Redos after the current one. + if (myNbRedos > 0) { + myNbRedos = 0; + myListDiffs.erase(myCurrenPos, myListDiffs.end()); + } + + if (myUndoDepth == -1 || myNbUndos < myUndoDepth) { + // Increase the number of undos. + myNbUndos++; + } else { + // If there are too many differences, remove the first one. + myListDiffs.pop_front(); + } + + // Add new difference. + myListDiffs.push_back(CurveCreator_Diff()); + myCurrenPos = myListDiffs.end(); + isEnabled = true; + } + + return isEnabled; +} + +void CurveCreator_Curve::startOperation() +{ + myOpLevel++; +} + +void CurveCreator_Curve::finishOperation() +{ + myOpLevel--; +} + +//======================================================================= +// function: toICoord +// purpose: +//======================================================================= +int CurveCreator_Curve::toICoord(const int theIPnt) const +{ + return theIPnt * myDimension; +} + +//======================================================================= +// function: setUndoDepth +// purpose: +//======================================================================= +void CurveCreator_Curve::setUndoDepth(const int theDepth) +{ + if (theDepth == 0) { + // Reset all undo/redo data. + myNbUndos = 0; + myNbRedos = 0; + myListDiffs.clear(); + myCurrenPos = myListDiffs.end(); + myUndoDepth = 0; + } else if (theDepth == -1) { + // There is nothing to do as the depth become unlimited. + myUndoDepth = -1; + } else if (theDepth > 0) { + // The new "real" depth is set. + if (theDepth < myNbRedos) { + // The new depth is less then number of redos. Remove the latest redos. + int aShift = (myNbRedos - theDepth); + ListDiff::iterator aFromPos = myListDiffs.end(); + + while (aShift--) { + aFromPos--; + } + + myListDiffs.erase(aFromPos, myListDiffs.end()); + myNbRedos = theDepth; + } + + if (theDepth < myNbUndos + myNbRedos) { + // The new depth is less then the total number of differences. + // Remove the first undos. + int aShift = (myNbUndos + myNbRedos - theDepth); + ListDiff::iterator aToPos = myListDiffs.begin(); + + while (aShift--) { + aToPos++; + } + + myListDiffs.erase(myListDiffs.begin(), aToPos); + myNbUndos = theDepth - myNbRedos; + } + + myUndoDepth = theDepth; + } +} + +//======================================================================= +// function: getUndoDepth +// purpose: +//======================================================================= +int CurveCreator_Curve::getUndoDepth() const +{ + return myUndoDepth; +} + +/************ Implementation of INTERFACE methods ************/ + +/***********************************************/ +/*** Undo/Redo methods ***/ +/***********************************************/ + +//! Get number of available undo operations +int CurveCreator_Curve::getNbUndo() const +{ + return myNbUndos; +} + +//! Undo previous operation +bool CurveCreator_Curve::undo() +{ + bool res = false; + if (myNbUndos > 0) { + myNbUndos--; + myNbRedos++; + myCurrenPos--; + myCurrenPos->applyUndo(this); + res = true; + } + return res; +} + +//! Get number of available redo operations +int CurveCreator_Curve::getNbRedo() const +{ + return myNbRedos; +} + +//! Redo last previously "undone" operation +bool CurveCreator_Curve::redo() +{ + bool res = false; + if (myNbRedos > 0) { + myCurrenPos->applyRedo(this); + myCurrenPos++; + myNbRedos--; + myNbUndos++; + res = true; + } + return res; +} + +/***********************************************/ +/*** Section methods ***/ +/***********************************************/ +//======================================================================= +// function: clear +// purpose: +//======================================================================= +bool CurveCreator_Curve::clear() +{ + // Delete all allocated data. + int i = 0; + const int aNbSections = getNbSections(); + + for (; i < aNbSections; i++) { + delete mySections[i]; + } + + mySections.clear(); + if( myListener ) + myListener->curveChanged(); + + return true; +} + +//! Join range of sections to one section (join all sections if -1 is passed in one of arguments) +bool CurveCreator_Curve::join( const int theISectionTo, + const int theISectionFrom ) +{ + if (theISectionTo != theISectionFrom) { + startOperation(); + if (addEmptyDiff()) + myListDiffs.back().init(this, CurveCreator_Operation::Join, theISectionTo, theISectionFrom); + + CurveCreator_Section *aSection1 = mySections.at(theISectionTo); + CurveCreator_Section *aSection2 = mySections.at(theISectionFrom); + + aSection1->myPoints.insert(aSection1->myPoints.end(), + aSection2->myPoints.begin(), + aSection2->myPoints.end()); + + removeSection(theISectionFrom); + if( myListener ) + myListener->curveChanged(); + + finishOperation(); + return true; + } + return false; +} + +//! Get number of sections +int CurveCreator_Curve::getNbSections() const +{ + return mySections.size(); +} + +//======================================================================= +// function: addSection +// purpose: adds an empty section +//======================================================================= +int CurveCreator_Curve::addSection + (const std::string& theName, const CurveCreator::SectionType theType, + const bool theIsClosed) +{ + int resISection = -1; + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + CurveCreator::Coordinates aCoords; //empty list + myListDiffs.back().init(this, CurveCreator_Operation::AddSection, + theName, aCoords, theType, theIsClosed); + } + CurveCreator_Section *aSection = new CurveCreator_Section; + + std::string aName = theName; + if( aName.empty() ){ + aName = getUniqSectionName(); + } + aSection->myName = aName; + aSection->myType = theType; + aSection->myIsClosed = theIsClosed; + mySections.push_back(aSection); + if( myListener ) + myListener->sectionAdded( -1 ); + + finishOperation(); + return mySections.size()-1; +} +//======================================================================= +// function: addSection +// purpose: adds a section with the given points +//======================================================================= +int CurveCreator_Curve::addSection + (const std::string& theName, const CurveCreator::SectionType theType, + const bool theIsClosed, const CurveCreator::Coordinates &thePoints) +{ + int resISection = -1; + //// Set the difference. + //startOperation(); + //if (addEmptyDiff()) { + // myListDiffs.back().init(this, CurveCreator_Operation::AddSection, + // theName, thePoints, theType, theIsClosed); + //} + + // create an empty section + resISection = addSection(theName, theType, theIsClosed); + if( resISection != -1 ) { + // attach the given points to created section + CurveCreator_Section *aSection = mySections.at(resISection); + aSection->myPoints = thePoints; + } + + //finishOperation(); + return resISection; +} + +//! Removes the given sections. +bool CurveCreator_Curve::removeSection( const int theISection ) +{ + // Set the difference. + startOperation(); + if (addEmptyDiff()) + myListDiffs.back().init(this, CurveCreator_Operation::RemoveSection, theISection); + + if (theISection == -1) { + delete mySections.back(); + mySections.pop_back(); + } else { + CurveCreator::Sections::iterator anIterRm = mySections.begin() + theISection; + + delete *anIterRm; + mySections.erase(anIterRm); + } + if( myListener ) + myListener->sectionRemoved(theISection); + + finishOperation(); + return true; +} + +/** + * Get number of points in specified section or (the total number of points + * in Curve if theISection is equal to -1). + */ +int CurveCreator_Curve::getNbPoints( const int theISection ) const +{ + int aNbCoords = 0; + + if (theISection == -1) { + int i = 0; + const int aNbSections = getNbSections(); + + for (; i < aNbSections; i++) { + aNbCoords += mySections[i]->myPoints.size(); + } + } else { + aNbCoords = mySections.at(theISection)->myPoints.size(); + } + + return aNbCoords/myDimension; +} + +//! Get "closed" flag of the specified section +bool CurveCreator_Curve::isClosed( const int theISection ) const +{ + return mySections.at(theISection)->myIsClosed; +} + +/** + * Set "closed" flag of the specified section (all sections if + * \a theISection is -1). + */ +bool CurveCreator_Curve::setClosed( const int theISection, + const bool theIsClosed ) +{ + if (theISection == -1) { + int aSize = mySections.size(); + int i; + + for (i = 0; i < aSize; i++) { + mySections[i]->myIsClosed = theIsClosed; + if( myListener ){ + myListener->sectionClosed( theISection, theIsClosed ); + } + } + } else { + mySections.at(theISection)->myIsClosed = theIsClosed; + if( myListener ){ + myListener->sectionClosed( theISection, theIsClosed ); + } + } + return true; +} + +//! Returns specifyed section name +std::string CurveCreator_Curve::getSectionName( const int theISection ) const +{ + if( ( theISection >= 0 ) && ( theISection < mySections.size() )) + return mySections.at(theISection)->myName; + return ""; +} + +/** Set name of the specified section */ +bool CurveCreator_Curve::setSectionName + ( const int theISection, const std::string& theName ) +{ + if( ( theISection >= 0 ) && ( theISection < mySections.size() )){ + mySections.at(theISection)->myName = theName; + return true; + } + return false; +} + +//! Get type of the specified section +CurveCreator::SectionType CurveCreator_Curve::getSectionType + ( const int theISection ) const +{ + return mySections.at(theISection)->myType; +} + +/** + * Set type of the specified section (or all sections + * if \a theISection is -1). + */ +bool CurveCreator_Curve::setSectionType( const int theISection, + const CurveCreator::SectionType theType ) +{ + if (theISection == -1) { + int i = 0; + const int aNbSections = getNbSections(); + + for (; i < aNbSections; i++) { + mySections[i]->myType = theType; + } + if( myListener ) + myListener->curveChanged(); + } else { + if( mySections.at(theISection)->myType != theType ){ + mySections.at(theISection)->myType = theType; + if( myListener ) + myListener->sectionTypeChanged(theISection); + } + } + return true; +} + + +/***********************************************/ +/*** Point methods ***/ +/***********************************************/ + +/** + * Add one point to the specified section starting from the given theIPnt index + * (or at the end of points if \a theIPnt is -1). + */ +bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords, + const int theISection, + const int theIPnt ) +{ + bool res = false; + CurveCreator::Coordinates aCoords = theCoords; + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(this, CurveCreator_Operation::AddPoints, + theCoords, theISection); + } + CurveCreator_Section *aSection = + (theISection == -1 ? mySections.back() : mySections.at(theISection)); + + if( aSection ) { + int anICoord = ( theIPnt == -1 ? 0 : toICoord(theIPnt) ); + CurveCreator::Coordinates::iterator anIterPosition = aSection->myPoints.end(); + if( theIPnt != -1 ) + anIterPosition = aSection->myPoints.begin() + toICoord(theIPnt); + aSection->myPoints.insert(anIterPosition, + theCoords.begin(), theCoords.end()); + if( myListener ) + myListener->pointInserted( theISection, -1 ); + res = true; + } + finishOperation(); + return res; +} + + //! Set coordinates of specified point +bool CurveCreator_Curve::setPoint( const int theISection, + const int theIPnt, + const CurveCreator::Coordinates& theNewCoords ) +{ + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates, + theNewCoords, theISection, theIPnt); + } + + bool res = false; + + // Update the curve. + if (theNewCoords.size() == myDimension) { + CurveCreator_Section *aSection = mySections.at(theISection); + int i; + for (i = 0; i < myDimension; i++) { + aSection->myPoints.at(toICoord(theIPnt) + i) = theNewCoords[i]; + } + if( myListener ) + myListener->pointChanged( theISection, theIPnt ); + + res = true; + } + + finishOperation(); + + return res; +} + +//! Remove point with given id +bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt ) +{ + bool res = false; + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints, + theISection, theIPnt, 0); + } + CurveCreator_Section *aSection = mySections.at(theISection); + if( aSection ) { + CurveCreator::Coordinates::iterator anIterPosition = + aSection->myPoints.begin() + toICoord(theIPnt); + aSection->myPoints.erase( anIterPosition ); + if( myListener ) + myListener->pointRemoved( theISection, theIPnt ); + res = true; + } + finishOperation(); + return res; +} + +//======================================================================= +// function: getCoordinates +// purpose: +//======================================================================= +CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection, + const int theIPnt) const +{ + CurveCreator_Section *aSection = mySections.at(theISection); + CurveCreator::Coordinates::const_iterator + anIter = aSection->myPoints.begin() + toICoord(theIPnt); + CurveCreator::Coordinates aResult(anIter, anIter + myDimension); + + return aResult; +} + +//======================================================================= +// function: getPoints +// purpose: +//======================================================================= +CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const +{ + return mySections.at(theISection)->myPoints; +} + + +/***********************************************/ +/*** Presentation methods ***/ +/***********************************************/ +/* TopoDS_Wire CurveCreator_Curve::constructWire() const +{ +}*/ diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.hxx b/src/HYDROCurveCreator/CurveCreator_Curve.hxx new file mode 100644 index 00000000..656b312b --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Curve.hxx @@ -0,0 +1,231 @@ +// 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 +// + +// File: CurveCreator_Curve.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Curve_HeaderFile +#define _CurveCreator_Curve_HeaderFile + +#include "CurveCreator_ICurve.hxx" + +#include "CurveCreator_Macro.hxx" +#include "CurveCreator.hxx" +#include "CurveCreator_Diff.hxx" + +#include + +struct CurveCreator_Section; +class CurveCreator_Listener; + +/** + * 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_Curve : public CurveCreator_ICurve +{ +private: + typedef std::list ListDiff; + +public: + //! Constructor of the curve. + /** The dimension is explicitly specified in the constructor + * and cannot be changed later. + */ + CurveCreator_Curve(const CurveCreator::Dimension theDimension); + + //! Destructor. + virtual ~CurveCreator_Curve(); + + //! Get the dimension. + virtual CurveCreator::Dimension getDimension() const; + + //! Return unique section name + virtual std::string getUniqSectionName() const; + + //! Set curve creator listener object + virtual void setListener( CurveCreator_Listener* theWatcher ); + + //! Remove curve creator listener object + virtual void removeListener(); + + /** Set depth of undo operations (unlimited if \a theDepth is -1 + * or disabled if \a theDepth is 0) + */ + virtual void setUndoDepth(const int theDepth = -1); + + //! Get depth of undo operations. + virtual int getUndoDepth() const; + + virtual void startOperation(); + virtual void finishOperation(); + + /** + * This method converts the point index to the index in + * an array of coordinates. + */ + virtual int toICoord(const int theIPnt) const; + +protected: + /** This method updates all undo/redo information required to be updated + * after curve modification operation. It returns false if undo/redo + * is disabled and true otherwise. + */ + virtual bool addEmptyDiff(); + + +public: + /************ Implementation of INTERFACE methods ************/ + + /***********************************************/ + /*** Undo/Redo methods ***/ + /***********************************************/ + + //! Get number of available undo operations + virtual int getNbUndo() const; + + //! Undo previous operation + virtual bool undo(); + + //! Get number of available redo operations + virtual int getNbRedo() const; + + //! Redo last previously "undone" operation + virtual bool redo(); + + + /***********************************************/ + /*** Section methods ***/ + /***********************************************/ + + //! Clear the polyline (remove all sections) + virtual bool clear(); + + //! 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 ); + + //! Get number of sections + virtual int getNbSections() const; + + //! 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); + + //! Removes the given sections. + virtual bool removeSection( const int theISection ); + + //! Get "closed" flag of the specified section + virtual bool isClosed( const int theISection ) const; + + /** + * Set "closed" flag of the specified section (all sections if + * \a theISection is -1). + */ + virtual bool setClosed( const int theISection, + const bool theIsClosed ); + + //! Returns specifyed section name + virtual std::string getSectionName( const int theISection ) const; + + /** Set name of the specified section */ + virtual bool setSectionName( const int theISection, + const std::string& theName ); + + //! Get type of the specified section + virtual CurveCreator::SectionType getSectionType( const int theISection ) const; + + /** + * 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 ***/ + /***********************************************/ + + /** + * Add one point to the specified section starting from the given theIPnt index + * (or at the end of points if \a theIPnt is -1). + */ + virtual bool addPoints( const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt = -1 ); + + //! Set coordinates of specified point + virtual bool setPoint( const int theISection, + const int theIPnt, + const CurveCreator::Coordinates& theNewCoords ); + + /** Remove point with given id */ + virtual bool removePoint( const int theISection, const int theIPnt = -1 ); + + //! Get coordinates of specified point + virtual CurveCreator::Coordinates getPoint( const int theISection, + const int theIPnt ) const; + + /** + * Get points of a section (the total points in Curve if theISection is equal to -1).. + */ + virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const; + + + /** + * Get number of points in specified section or (the total number of points + * in Curve if theISection is equal to -1). + */ + virtual int getNbPoints( const int theISection ) const; + + + /***********************************************/ + /*** Presentation methods ***/ + /***********************************************/ +// virtual TopoDS_Wire constructWire() const; + +public: + + bool myIsLocked; + CurveCreator::Sections mySections; //!< curve data + CurveCreator::Dimension myDimension; //!< curve dimension + CurveCreator_Listener* myListener; //!< listener + +private: + + int myNbUndos; + int myNbRedos; + ListDiff::iterator myCurrenPos; + ListDiff myListDiffs; + int myUndoDepth; + int myOpLevel; +}; + +#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.cxx b/src/HYDROCurveCreator/CurveCreator_Diff.cxx new file mode 100644 index 00000000..97c1e6b4 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Diff.cxx @@ -0,0 +1,588 @@ +// 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 +// + +// File: CurveCreator_Diff.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_Diff.hxx" +#include "CurveCreator_Curve.hxx" + +#include + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_Diff::CurveCreator_Diff() +: myNbUndos (0), + myPUndo (NULL), + myPRedo (NULL) +{ +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_Diff::~CurveCreator_Diff() +{ + clear(); +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType)) { + isOK = true; + + const int aNbSections = theCurve->getNbSections(); + + if (theType == CurveCreator_Operation::Clear) { + // Construct undo for Clear command. + if (aNbSections > 0) { + setNbUndos(aNbSections); + + for (int i = 0; i < aNbSections && isOK; i++) { + // Add AddSection command. + isOK = addSectionToUndo(theCurve, i, myPUndo[i]); + } + } + } else { // theType == CurveCreator_Operation::Join + // Construct undo for Join command. + if (aNbSections > 1) { + // Add the RemovePoints command to remove points of + // the second section fron the first one. + const int aNbPoints = theCurve->getNbPoints(0); + + setNbUndos(aNbSections); + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + 0, aNbPoints, -1); + + for (int i = 1; i < aNbSections && isOK; i++) { + // Add AddSection command. + isOK = addSectionToUndo(theCurve, i, myPUndo[i]); + } + } + } + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theIntParam)) { + // Construct undo for RemoveSection command. + // If the last section is removed, one AddSection command is enough. + // If not last section is removed, two commands are requred: AddSection + // and MoveSection. + const int aLastIndex = theCurve->getNbSections() - 1; + + if (theIntParam == aLastIndex) { + setNbUndos(1); + } else { + setNbUndos(2); + } + + isOK = addSectionToUndo(theCurve, theIntParam, myPUndo[0]); + + if (isOK && theIntParam != aLastIndex) { + isOK = myPUndo[1].init(CurveCreator_Operation::MoveSection, + aLastIndex, theIntParam); + } + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theIntParam1, theIntParam2)) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::SetType: + case CurveCreator_Operation::SetClosed: + isOK = setTypeOrClosedToUndo + (theCurve, theType, theIntParam1, theIntParam2); + break; + case CurveCreator_Operation::MoveSection: + setNbUndos(1); + isOK = myPUndo[0].init(theType, theIntParam2, theIntParam1); + break; + case CurveCreator_Operation::Join: + { + // If the last section is removed, one AddSection command is + // enough. If not last section is removed, two commands are + // requred: AddSection and MoveSection. + const int aLastIndex = theCurve->getNbSections() - 1; + const int aNbPoints = theCurve->getNbPoints(theIntParam1); + + if (theIntParam2 == aLastIndex) { + setNbUndos(2); + } else { + setNbUndos(3); + } + + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + theIntParam1, aNbPoints, -1); + + if (isOK) { + isOK = addSectionToUndo(theCurve, theIntParam2, myPUndo[1]); + + if (isOK && theIntParam2 != aLastIndex) { + isOK = myPUndo[2].init(CurveCreator_Operation::MoveSection, + aLastIndex, theIntParam2); + } + } + } + break; + default: + break; + } + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2, + const int theIntParam3) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theIntParam1, theIntParam2, theIntParam3)) { + // Construct undo for RemovePoints command. + const CurveCreator::Dimension aDim = theCurve->getDimension(); + const CurveCreator::Coordinates &aPoints = + theCurve->getPoints(theIntParam1); + CurveCreator::Coordinates::const_iterator anIterBegin = + aPoints.begin() + (aDim*theIntParam2); + CurveCreator::Coordinates::const_iterator anIterEnd; + + if (theIntParam3 == -1) { + anIterEnd = aPoints.end(); + } else { + anIterEnd = anIterBegin + (aDim*theIntParam3); + } + + CurveCreator::Coordinates aPointsToAdd; + + setNbUndos(1); + aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd); + isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints, + aPointsToAdd, theIntParam1, theIntParam2); + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theCoords, theIntParam)) { + // Construct undo for AddPoints command. + const int aSectionInd = getSectionIndex(theCurve, theIntParam); + const CurveCreator::Dimension aDim = theCurve->getDimension(); + const CurveCreator::Coordinates &aPoints = + theCurve->getPoints(aSectionInd); + const int aNbPoints = (aPoints.size()/aDim); + + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + aSectionInd, aNbPoints, -1); + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const std::string& theName, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theName, theCoords, theIntParam1, theIntParam2)) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::AddSection: + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RemoveSection, -1); + break; + } + } + } + if( !isOK ) + clear(); + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theCoords, theIntParam1, theIntParam2)) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::InsertPoints: + { + const CurveCreator::Dimension aDim = theCurve->getDimension(); + const int aNbPoints = (theCoords.size()/aDim); + const int aSectionInd = getSectionIndex(theCurve, theIntParam1); + int aPointInd; + + if (theIntParam2 == -1) { + aPointInd = theCurve->getNbPoints(aSectionInd); + } else { + aPointInd = theIntParam2; + } + + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + aSectionInd, aPointInd, aNbPoints); + } + break; + case CurveCreator_Operation::SetCoordinates: + { + const CurveCreator::Coordinates anOldCoords = + theCurve->getPoint(theIntParam1, theIntParam2); + + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates, + anOldCoords, theIntParam1, theIntParam2); + } + break; + default: + break; + } + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const std::string &theName, + const int theIntParam1 ) +{ + bool isOK = false; + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theName, theIntParam1 )) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::RenameSection: + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RenameSection, + theCurve->getSectionName(theIntParam1), theIntParam1); + break; + } + } + if( !isOK ){ + clear(); + } + return isOK; +} + +//======================================================================= +// function: applyUndo +// purpose: +//======================================================================= +void CurveCreator_Diff::applyUndo(CurveCreator_Curve *theCurve) +{ + if (myNbUndos > 0 && myPUndo != NULL) { + for (int i = 0; i < myNbUndos; i++) { + myPUndo[i].apply(theCurve); + } + } +} + +//======================================================================= +// function: applyRedo +// purpose: +//======================================================================= +void CurveCreator_Diff::applyRedo(CurveCreator_Curve *theCurve) +{ + if (myPRedo != NULL) { + myPRedo->apply(theCurve); + } +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_Diff::clear() +{ + if (myPUndo != NULL) { + delete [] myPUndo; + myPUndo = NULL; + } + + myNbUndos = 0; + + if (myPRedo != NULL) { + delete myPRedo; + myPRedo = NULL; + } +} + +//======================================================================= +// function: setNbUndos +// purpose: +//======================================================================= +void CurveCreator_Diff::setNbUndos(const int theNbUndos) +{ + myNbUndos = theNbUndos; + myPUndo = new CurveCreator_Operation[myNbUndos]; +} + +//======================================================================= +// function: getSectionIndex +// purpose: +//======================================================================= +int CurveCreator_Diff::getSectionIndex(const CurveCreator_Curve *theCurve, + const int theIndex) const +{ + return (theIndex == -1 ? theCurve->getNbSections() - 1 : theIndex); +} + +//======================================================================= +// function: addSectionToUndo +// purpose: +//======================================================================= +bool CurveCreator_Diff::addSectionToUndo + (const CurveCreator_Curve *theCurve, + const int theIndex, + CurveCreator_Operation &theOperation) const +{ + const CurveCreator::Coordinates &aPnts = theCurve->getPoints(theIndex); + const CurveCreator::SectionType aType = theCurve->getSectionType(theIndex); + const bool isClosed = theCurve->isClosed(theIndex); + + bool isOK = theOperation.init(CurveCreator_Operation::AddSection, + aPnts, aType, isClosed); + + return isOK; +} + +//======================================================================= +// function: setTypeOrClosedToUndo +// purpose: +//======================================================================= +bool CurveCreator_Diff::setTypeOrClosedToUndo + (const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = true; + + // Compute number of modified sections. + const bool isSetType = (theType == CurveCreator_Operation::SetType); + int aNbModif = 0; + std::list aListOfInd; + int aValue; + int i; + + if (theIntParam2 == -1) { + // The operation is applied to all sections. We need to collect + // really modified sections for undo. + const int aNbSections = theCurve->getNbSections(); + + if (aNbSections > 0) { + // Get sections to be modified. + for (i = 0; i < aNbSections; i++) { + if (isSetType) { + aValue = theCurve->getSectionType(i); + } else { + aValue = theCurve->isClosed(i); + } + + if (theIntParam1 != aValue) { + aNbModif++; + aListOfInd.push_back(i); + } + } + + if (aNbSections == aNbModif) { + // All sections are modified. We can use one single command + // with -1 section index. + aNbModif = 1; + aListOfInd.clear(); + aListOfInd.push_back(-1); + } + } + } else { + // There is only particular section modified. + // Check if there is a real modification required. + if (isSetType) { + aValue = theCurve->getSectionType(theIntParam2); + } else { + aValue = theCurve->isClosed(theIntParam2); + } + + if (theIntParam1 != aValue) { + aNbModif = 1; + aListOfInd.push_back(theIntParam2); + } + } + + if (aNbModif > 0) { + // Store the undos + std::list::iterator anIter = aListOfInd.begin(); + + if (isSetType) { + aValue = theCurve->getSectionType(*anIter); + } else { + aValue = theCurve->isClosed(*anIter); + } + + setNbUndos(aNbModif); + + for (i = 0; anIter != aListOfInd.end() && isOK; i++, anIter++) { + isOK = myPUndo[i].init(theType, aValue, *anIter); + } + } + + return isOK; +} diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.hxx b/src/HYDROCurveCreator/CurveCreator_Diff.hxx new file mode 100644 index 00000000..291aaee3 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Diff.hxx @@ -0,0 +1,218 @@ +// 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 +// + +// File: CurveCreator_Diff.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Diff_HeaderFile +#define _CurveCreator_Diff_HeaderFile + +#include "CurveCreator_Operation.hxx" + +class CurveCreator_Curve; + + +/** + * This is the support class for store/retrieve differences of undo/redo + * operations. To fill the difference it is necessary to create it with + * an appropriate type and to call the method initialize with required + * parameters. + */ +class CurveCreator_Diff +{ + +private: + +public: + + /** + * Constructor. + */ + CurveCreator_Diff(); + + /** + * Destructor. + */ + ~CurveCreator_Diff(); + + /** + * This method initializes the difference with an operation without + * parameters. It is applicable to the following operations: + *
    + *
  • Clear
  • + *
  • Join (without arguments)
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType); + + /** + * This method initializes the difference with an operation with one integer + * parameter. It is applicable to the following operations: + *
    + *
  • RemoveSection
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam); + + /** + * This method initializes the difference with an operation with two integer + * parameters. It is applicable to the following operations: + *
    + *
  • SetType
  • + *
  • SetClosed
  • + *
  • MoveSection
  • + *
  • Join (with 2 int arguments)
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2); + + /** + * This method initializes the difference with an operation with three + * integer parameters. It is applicable to the following operations: + *
    + *
  • RemovePoints
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2, + const int theIntParam3); + + /** + * This method initializes the difference with an operation with one + * CurveCreator::Coordinates parameter and one integer parameter. + * It is applicable to the following operations: + *
    + *
  • AddPoints
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam); + + /** + * This method initializes the difference with an operation with one + * CurveCreator::Coordinates parameter and two integer parameters. + * It is applicable to the following operations: + *
    + *
  • InsertPoints
  • + *
  • SetCoordinates
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2); + + /** + * This method initializes the difference with an operation with one + * Name, one CurveCreator::Coordinates parameter and two integer parameters. + * It is applicable to the following operations: + *
    + *
  • AddSection
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const std::string& theName, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2); + + /** + * This method initializes the difference with an operation with one + * string and one integer parameters. + * It is applicable to the following operations: + *
    + *
  • RenameSection
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const std::string &theName, + const int theIntParam1 ); + + /** + * This method applies undo operation to theCurve. + */ + void applyUndo(CurveCreator_Curve *theCurve); + + /** + * This method applies redo operation to theCurve. + */ + void applyRedo(CurveCreator_Curve *theCurve); + +private: + + /** + * This method clears initialized data pointers. + */ + void clear(); + + /** + * This method sets the number of undos and allocates the required + * space for myPUndo. + */ + void setNbUndos(const int theNbUndos); + + /** + * This method returns the section index. It returns theIndex if it is + * a real index and the last section's index if theIndex is equal to -1. + */ + int getSectionIndex(const CurveCreator_Curve *theCurve, + const int theIndex) const; + + /** + * Convert theIndex'th section of theCurve into AddSection command + * and store it in theOperation. Returns true in case of success and + * false otherwise. + */ + bool addSectionToUndo(const CurveCreator_Curve *theCurve, + const int theIndex, + CurveCreator_Operation &theOperation) const; + + /** + * Construct undos for SetType and SetClosed operations. Note: the + * algorithm is optimized taking into account that there are only 2 types + * and 2 values of isClosed flag. If the number of types is increased, + * this algorithm should be re-implemented. + */ + bool setTypeOrClosedToUndo(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2); + +private: + + int myNbUndos; + CurveCreator_Operation *myPUndo; + CurveCreator_Operation *myPRedo; + +}; + +#endif diff --git a/src/HYDROCurveCreator/CurveCreator_ICurve.hxx b/src/HYDROCurveCreator/CurveCreator_ICurve.hxx new file mode 100644 index 00000000..4a9b4c3b --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_ICurve.hxx @@ -0,0 +1,169 @@ +// 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 +// + +// File: CurveCreator_ICurve.hxx +// Author: Alexander KOVALEV and Alexander SOLOVYOV + +#ifndef _CurveCreator_ICurve_HeaderFile +#define _CurveCreator_ICurve_HeaderFile + +#include "CurveCreator_Macro.hxx" +#include + +namespace CurveCreator +{ + //! Type of the section + enum SectionType + { + Polyline, + Spline, + }; + + //! Dimension of the curve + enum Dimension + { + Dim2d = 2, + Dim3d = 3 + }; + +}; + +/** + * The CurveCreator_ICurve object is represented as one or more sets of + * connected points; thus CurveCreator_ICurve 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_ICurve +{ +public: + /***********************************************/ + /*** Undo/Redo methods ***/ + /***********************************************/ + + //! Get number of available undo operations + virtual int getNbUndo() const = 0; + + //! Undo previous operation + virtual bool undo() = 0; + + //! Get number of available redo operations + virtual int getNbRedo() const = 0; + + //! Redo last previously "undone" operation + virtual bool redo() = 0; + + + /***********************************************/ + /*** Section methods ***/ + /***********************************************/ + + //! Clear the polyline (remove all sections) + virtual bool clear() = 0; + + //! 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 ) = 0; + + //! Get number of sections + virtual int getNbSections() const = 0; + + //! Add a new section. + virtual int addSection( const std::string& theName, + const CurveCreator::SectionType theType, + const bool theIsClosed ) = 0; + + //! Removes the given sections. + virtual bool removeSection( const int theISection ) = 0; + + //! Get "closed" flag of the specified section + virtual bool isClosed( const int theISection ) const = 0; + + /** + * Set "closed" flag of the specified section (all sections if + * \a theISection is -1). + */ + virtual bool setClosed( const int theISection, + const bool theIsClosed ) = 0; + + //! Returns specifyed section name + virtual std::string getSectionName( const int theISection ) const = 0; + + /** Set name of the specified section */ + virtual bool setSectionName( const int theISection, + const std::string& theName ) = 0; + + //! Get type of the specified section + virtual CurveCreator::SectionType getSectionType( const int theISection ) const = 0; + + /** + * Set type of the specified section (or all sections + * if \a theISection is -1). + */ + virtual bool setSectionType( const int theISection, + const CurveCreator::SectionType theType ) = 0; + + + /***********************************************/ + /*** Point methods ***/ + /***********************************************/ + + //! Get the dimension. + virtual CurveCreator::Dimension getDimension() const = 0; + + /** + * 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). + */ + virtual bool addPoints( const std::deque& theCoords, + const int theISection, + const int theIPnt = -1 ) = 0; + + //! Set coordinates of specified point + virtual bool setPoint( const int theISection, + const int theIPnt, + const std::deque& theNewCoords ) = 0; + + //! Remove point with given id + virtual bool removePoint( const int theISection, const int theIPnt = -1 ) = 0; + + //! Get coordinates of specified point + virtual std::deque getPoint( const int theISection, + const int theIPnt ) const = 0; + + /** + * Get points of a section (the total points in Curve if theISection is equal to -1).. + */ + virtual std::deque getPoints( const int theISection = -1 ) const = 0; + + /** + * Get number of points in specified section or (the total number of points + * in Curve if theISection is equal to -1). + */ + virtual int getNbPoints( const int theISection ) const = 0; + + + /***********************************************/ + /*** Presentation methods ***/ + /***********************************************/ +// virtual TopoDS_Wire constructWire() const = 0; +}; + +#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Listener.hxx b/src/HYDROCurveCreator/CurveCreator_Listener.hxx new file mode 100755 index 00000000..318abac2 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Listener.hxx @@ -0,0 +1,41 @@ +// 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 CURVE_CREATOR_LISTENER_HXX +#define CURVE_CREATOR_LISTENER_HXX + +class CurveCreator_Listener +{ +public: + CurveCreator_Listener(void){}; + virtual ~CurveCreator_Listener(void){}; + + virtual void pointChanged( int theSection, int thePoint ){} + virtual void pointRemoved( int theSection, int theFirstPoint){} + virtual void pointInserted( int theSection, int theIndx ){} + + virtual void sectionClosed( int theSection, bool isClosed ){} + virtual void sectionAdded( int theSection ){} + virtual void sectionRemoved( int theSection ){} + virtual void sectionTypeChanged( int theSection ){} + + virtual void curveChanged(){} +}; + +#endif \ No newline at end of file diff --git a/src/HYDROCurveCreator/CurveCreator_Macro.hxx b/src/HYDROCurveCreator/CurveCreator_Macro.hxx new file mode 100644 index 00000000..ec814eb4 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Macro.hxx @@ -0,0 +1,44 @@ +// 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 +// + +// File: CurveCreator_Macro.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Macro_HeaderFile +#define _CurveCreator_Macro_HeaderFile + +#ifdef WNT + #if defined CURVECREATOR_EXPORTS || defined CurveCreator_EXPORTS + #if defined WIN32 + #define CURVECREATOR_EXPORT __declspec( dllexport ) + #else + #define CURVECREATOR_EXPORT + #endif + #else + #if defined WIN32 + #define CURVECREATOR_EXPORT __declspec( dllimport ) + #else + #define CURVECREATOR_EXPORT + #endif + #endif +#else + #define CURVECREATOR_EXPORT +#endif + +#endif diff --git a/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.cxx b/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.cxx new file mode 100644 index 00000000..a155efb0 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.cxx @@ -0,0 +1,149 @@ +// 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_NewSectionDlg.h" +//#include "CurveCreator_Curve.hxx" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent ) : + QWidget(parent) +{ + QFrame* aFrame = new QFrame( this ); + QVBoxLayout* aLayout = new QVBoxLayout( aFrame ); + + QFrame* aCoordFrame = new QFrame( aFrame ); + QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame ); + + QLabel* aLbl = new QLabel(tr("NAME"), this); + myName = new QLineEdit(this); + aCoordLayout->addWidget(aLbl, 0, 0); + aCoordLayout->addWidget(myName, 0 , 1); + + aLbl = new QLabel(tr("LINE_TYPE")); + myLineType = new QComboBox(this); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); + QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); + +// QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE")); +// QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE")); + myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE")); + myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE")); + myLineType->setCurrentIndex(0); + aCoordLayout->addWidget(aLbl, 1, 0); + aCoordLayout->addWidget(myLineType, 1 , 1); + + aLbl = new QLabel(tr("LINE_CLOSED")); + myIsClosed = new QCheckBox(this); + aCoordLayout->addWidget(aLbl, 2, 0); + aCoordLayout->addWidget(myIsClosed, 2, 1); + + myBtnFrame = new QFrame( aFrame ); + QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame ); + + myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame ); + myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame ); + + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelSection() ) ); + + aBtnsLayout->addWidget( myAddBtn ); + aBtnsLayout->addStretch( 1 ); + aBtnsLayout->addWidget( myCancelBtn ); + + aLayout->addWidget( aCoordFrame, 0 ); + aLayout->addWidget( myBtnFrame, 1 ); +} + +void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::SectionType theType ) +{ + myName->setText(theName); + myIsClosed->setChecked(isClosed); + if( theType == CurveCreator::Polyline ) + myLineType->setCurrentIndex(0); + else + myLineType->setCurrentIndex(1); +} + +void CurveCreator_NewSectionDlg::clear() +{ + myName->setText(""); + myIsClosed->setChecked(true); + myLineType->setCurrentIndex(0); +} + +void CurveCreator_NewSectionDlg::setEditMode( bool isEdit ) +{ + myIsEdit = isEdit; + if( myIsEdit ){ + myAddBtn->setText(tr("OK")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifySection() ) ); + } + else{ + myAddBtn->setText(tr("ADD_BTN")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) ); + } + updateTitle(); +} + +QString CurveCreator_NewSectionDlg::getName() const +{ + return myName->text(); +} + +bool CurveCreator_NewSectionDlg::isClosed() const +{ + return myIsClosed->isChecked(); +} + +CurveCreator::SectionType CurveCreator_NewSectionDlg::getSectionType() const +{ + if( myLineType->currentIndex() == 0 ) + return CurveCreator::Polyline; + else + return CurveCreator::Spline; +} + +void CurveCreator_NewSectionDlg::updateTitle() +{ + QString aTitle; + if( !myIsEdit ) + aTitle = tr("ADD_NEW_SECTION"); + else + aTitle = QString(tr("SET_SECTION_PARAMETERS")); + setWindowTitle(aTitle); +} + +void CurveCreator_NewSectionDlg::setSectionName( const QString& theName ) +{ + myName->setText(theName); +} diff --git a/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.h b/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.h new file mode 100644 index 00000000..96af4385 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.h @@ -0,0 +1,71 @@ +// 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_NEWSECTION_H +#define CURVECREATOR_NEWSECTION_H + +#include "CurveCreator.hxx" +#include "CurveCreator_ICurve.hxx" + +#include + +//class CurveCreator_Curve; + +class QLineEdit; +class QComboBox; +class QCheckBox; +class QPushButton; +class QAbstractButton; +class QDialogButtonBox; +class QFrame; + +class CurveCreator_NewSectionDlg : public QWidget +{ + Q_OBJECT +public: + explicit CurveCreator_NewSectionDlg(QWidget *parent = 0); + + QString getName() const; + bool isClosed() const; + CurveCreator::SectionType getSectionType() const; + + void setSectionParameters( const QString& theName, bool isClosed, CurveCreator::SectionType theType ); + void setSectionName(const QString& theName ); + void clear(); + void setEditMode( bool isEdit ); + +signals: + void addSection(); + void modifySection(); + void cancelSection(); +public slots: +protected slots: +protected: + void updateTitle(); +private: + QFrame* myBtnFrame; + QLineEdit* myName; + QComboBox* myLineType; + QCheckBox* myIsClosed; + bool myIsEdit; + QPushButton* myAddBtn; + QPushButton* myCancelBtn; +}; + +#endif // CURVECREATOR_NEWSECTION_H diff --git a/src/HYDROCurveCreator/CurveCreator_Operation.cxx b/src/HYDROCurveCreator/CurveCreator_Operation.cxx new file mode 100644 index 00000000..073d8ec7 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Operation.cxx @@ -0,0 +1,403 @@ +// 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 +// + +// File: CurveCreator_Operation.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_Operation.hxx" +#include "CurveCreator_Curve.hxx" + +#include +#include +#include + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_Operation::CurveCreator_Operation() +: myType (CurveCreator_Operation::Unknown), + myPData (NULL) +{ +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_Operation::~CurveCreator_Operation() +{ + clear(); +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::Clear || + theType == CurveCreator_Operation::Join) { + clear(); + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const int theIntParam) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::RemoveSection) { + int *pData = (int *)allocate(sizeof(int)); + + pData[0] = theIntParam; + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::SetType || + theType == CurveCreator_Operation::SetClosed || + theType == CurveCreator_Operation::MoveSection || + theType == CurveCreator_Operation::Join) { + int *pData = (int *)allocate(2*sizeof(int)); + + pData[0] = theIntParam1; + pData[1] = theIntParam2; + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2, + const int theIntParam3) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::RemovePoints) { + int *pData = (int *)allocate(3*sizeof(int)); + + pData[0] = theIntParam1; + pData[1] = theIntParam2; + pData[2] = theIntParam3; + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::AddPoints) { + const int aNbCoords = theCoords.size(); + const size_t aSize = + 2*sizeof(theIntParam) + aNbCoords*sizeof(CurveCreator::TypeCoord); + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = theIntParam; + *pIntData++ = aNbCoords; + + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; + int i = 0; + + for (; i < aNbCoords; i++) { + *pRealData++ = theCoords[i]; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::AddSection || + theType == CurveCreator_Operation::InsertPoints || + theType == CurveCreator_Operation::SetCoordinates) { + const int aNbCoords = theCoords.size(); + const size_t aSize = + 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord); + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = theIntParam1; + *pIntData++ = theIntParam2; + *pIntData++ = aNbCoords; + + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; + int i = 0; + + for (; i < aNbCoords; i++) { + *pRealData++ = theCoords[i]; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const std::string& theName, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + if (theType == CurveCreator_Operation::AddSection ) { + const int aNbCoords = theCoords.size(); + const size_t aSize = + 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord) + theName.length() + 1; + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = theIntParam1; + *pIntData++ = theIntParam2; + char* aStrPtr = (char*)pIntData; + if( !theName.empty() ){ + strcpy( aStrPtr, theName.c_str() ); + aStrPtr += theName.length(); + } + else{ + *aStrPtr = 0; + } + aStrPtr++; + pIntData = (int*)aStrPtr; + *pIntData++ = aNbCoords; + + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)aStrPtr; + int i = 0; + + for (; i < aNbCoords; i++) { + *pRealData++ = theCoords[i]; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const std::string &theName, + const int theIntParam1 ) +{ + if (theType == CurveCreator_Operation::RenameSection ) { + size_t aSize = sizeof(theIntParam1) + theName.length() + 1; + int *pIntData = (int *)allocate(aSize); + *pIntData = theIntParam1; + pIntData++; + if( !theName.empty() ){ + strcpy( (char*)pIntData, theName.c_str() ); + } + else{ + *((char*)pIntData) = 0; + } + myType = theType; + return true; + } + return false; +} + +//======================================================================= +// function: apply +// purpose: +//======================================================================= +void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) +{ + if (theCurve != NULL) { + int *pInt = (int *)myPData; + + switch (myType) { + case CurveCreator_Operation::AddPoints: + { + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[1], aCoords); + theCurve->addPoints(aCoords, pInt[0]); + } + break; + case CurveCreator_Operation::RemovePoints: +//AKL: TODO Undo/Redo support theCurve->removePoints(pInt[0], pInt[1], pInt[2]); + break; + case CurveCreator_Operation::InsertPoints: + { + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[2], aCoords); + theCurve->addPoints(aCoords, pInt[0], pInt[1]); + } + break; + case CurveCreator_Operation::SetType: + { + const CurveCreator::SectionType aType = (CurveCreator::SectionType) pInt[0]; + + theCurve->setSectionType( pInt[1], aType ); + } + break; + case CurveCreator_Operation::Clear: + theCurve->clear(); + break; + case CurveCreator_Operation::SetCoordinates: + { + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[2], aCoords); + theCurve->setPoint(pInt[0], pInt[1], aCoords); + } + break; + case CurveCreator_Operation::SetClosed: + theCurve->setClosed((pInt[0] != 0), pInt[1]); + break; +/* case CurveCreator_Operation::MoveSection: + theCurve->moveSection(pInt[0], pInt[1]); + break;*/ + case CurveCreator_Operation::Join: + if (myPData == NULL) { + theCurve->join(); + } else { + theCurve->join(pInt[0], pInt[1]); + } + break; + case CurveCreator_Operation::AddSection: + { + const CurveCreator::SectionType aType = (CurveCreator::SectionType) pInt[0]; + + std::string aName = std::string((char*)&pInt[2]); + + CurveCreator::Coordinates aCoords; + + char* aPtr = ((char*)&pInt[2]); + aPtr += (aName.length()) + 1; + getCoords((int*)aPtr, aCoords); + theCurve->addSection(aName, aType, (pInt[1] != 0), aCoords); + } + break; + case CurveCreator_Operation::RemoveSection: + theCurve->removeSection(pInt[0]); + break; + case CurveCreator_Operation::RenameSection: + { + std::string aName = std::string((char*)&pInt[1]); + theCurve->setSectionName(pInt[0], aName); + } + break; + default: + break; + } + } +} + +//======================================================================= +// function: allocate +// purpose: +//======================================================================= +void *CurveCreator_Operation::allocate(const size_t theSize) +{ + if (myPData != NULL) { + clear(); + } + + myPData = malloc(theSize); + + return myPData; +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_Operation::clear() +{ + myType = CurveCreator_Operation::Unknown; + + if (myPData != NULL) { + free(myPData); + myPData = NULL; + } +} + +//======================================================================= +// function: getCoords +// purpose: +//======================================================================= +void CurveCreator_Operation::getCoords + (int *thePInt, CurveCreator::Coordinates &theCoords) const +{ + const int aNbPnts = *thePInt; + CurveCreator::TypeCoord *pCoord = (CurveCreator::TypeCoord *)&thePInt[1]; + + for (int i = 0; i < aNbPnts; i++) { + theCoords.push_back(pCoord[i]); + } +} diff --git a/src/HYDROCurveCreator/CurveCreator_Operation.hxx b/src/HYDROCurveCreator/CurveCreator_Operation.hxx new file mode 100644 index 00000000..0c84c468 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Operation.hxx @@ -0,0 +1,205 @@ +// 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 +// + +// File: CurveCreator_Operation.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Operation_HeaderFile +#define _CurveCreator_Operation_HeaderFile + +#include "CurveCreator.hxx" + +#include + +class CurveCreator_Curve; + + +/** + * This is the support class that describes a modification operation that + * can be applied to CurveCreator_Curve. + */ +class CurveCreator_Operation +{ + +public: + + /** + * This is a type of CurveCreator_Curve modification operation. + */ + enum Type + { + Unknown = 0, //!< Unknown method. + AddPoints, //!< Method CurveCreator_Curve::addPoints + RemovePoints, //!< Method CurveCreator_Curve::removePoints + InsertPoints, //!< Method CurveCreator_Curve::insertPoints + SetType, //!< Method CurveCreator_Curve::setType + Clear, //!< Method CurveCreator_Curve::clear + SetCoordinates, //!< Method CurveCreator_Curve::setCoordinates + SetClosed, //!< Method CurveCreator_Curve::setClosed + MoveSection, //!< Method CurveCreator_Curve::moveSection + Join, //!< Method CurveCreator_Curve::join + AddSection, //!< Method CurveCreator_Curve::addSection + RemoveSection, //!< Method CurveCreator_Curve::removeSection + RenameSection //!< Method CurveCreator_Curve::renameSection + }; + + /** + * Empty constructor. + */ + CurveCreator_Operation(); + + /** + * Destructor. + */ + ~CurveCreator_Operation(); + + /** + * This method initializes the object with an operation without parameters. + * It is applicable to the following operations: + *
    + *
  • Clear
  • + *
  • Join (without arguments)
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType); + + /** + * This method initializes the object with an operation with one integer + * parameter. It is applicable to the following operations: + *
    + *
  • RemoveSection
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const int theIntParam); + + /** + * This method initializes the object with an operation with two integer + * parameters. It is applicable to the following operations: + *
    + *
  • SetType
  • + *
  • SetClosed
  • + *
  • MoveSection
  • + *
  • Join (with 2 int arguments)
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const int theIntParam1, + const int theIntParam2); + + /** + * This method initializes the object with an operation with three integer + * parameters. It is applicable to the following operations: + *
    + *
  • RemovePoints
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const int theIntParam1, + const int theIntParam2, const int theIntParam3); + + /** + * This method initializes the object with an operation with one + * CurveCreator::Coordinates parameter and one integer parameter. + * It is applicable to the following operations: + *
    + *
  • AddPoints
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const CurveCreator::Coordinates &theCoords, + const int theIntParam); + + /** + * This method initializes the object with an operation with one + * CurveCreator::Coordinates parameter and two integer parameters. + * It is applicable to the following operations: + *
    + *
  • AddSection
  • + *
  • InsertPoints
  • + *
  • SetCoordinates
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const CurveCreator::Coordinates &theCoords, + const int theIntParam1, const int theIntParam2); + + /** + * This method initializes the object with an operation with one + * string, one CurveCreator::Coordinates parameter and two integer parameters. + * It is applicable to the following operations: + *
    + *
  • AddSection
  • + *
  • InsertPoints
  • + *
  • SetCoordinates
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const CurveCreator_Operation::Type theType, + const std::string& theName, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2); + + + /** + * This method initializes the object with an operation with one + * string parameter and one integer. + * It is applicable to the following operations: + *
    + *
  • RenameSection
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const CurveCreator_Operation::Type theType, + const std::string &theName, + const int theIntParam1 ); + + /** + * This method applies the current operation to theCurve. + */ + void apply(CurveCreator_Curve *theCurve); + +private: + + /** + * This method allocates required memory for the operation data. + * Returns myPData for convenience purpose. + */ + void *allocate(const size_t theSize); + + /** + * This method clears initialized data pointers. + */ + void clear(); + + /** + * This method returns the coordinates read from thePInt. + */ + void getCoords(int *thePInt, CurveCreator::Coordinates &theCoords) const; + +private: + + Type myType; + void *myPData; + +}; + +#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Section.hxx b/src/HYDROCurveCreator/CurveCreator_Section.hxx new file mode 100644 index 00000000..68b03aaa --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Section.hxx @@ -0,0 +1,44 @@ +// 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 +// + +// File: CurveCreator_Section.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Section_HeaderFile +#define _CurveCreator_Section_HeaderFile + +#include "CurveCreator.hxx" + +#include + +//! Structure to store sections representing the CurveCreator_Curve object +struct CurveCreator_Section +{ + //! Constructor. Initializes object with default values. + CurveCreator_Section() : myName("Section"),myType(CurveCreator::Polyline), myIsClosed(false) + { } + + std::string myName; //!< section name + CurveCreator::Coordinates myPoints; //!< points coordinates + CurveCreator::SectionType myType; //!< type of the section + bool myIsClosed; //!< closed or not + +}; + +#endif diff --git a/src/HYDROCurveCreator/CurveCreator_TreeView.cxx b/src/HYDROCurveCreator/CurveCreator_TreeView.cxx new file mode 100755 index 00000000..800546cf --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_TreeView.cxx @@ -0,0 +1,489 @@ +// 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_TreeView.h" +#include "CurveCreator_ICurve.hxx" + +#include +#include + +#include +#include + +#define ID_SECTION -1 + +CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent ) : + QAbstractItemModel(parent), myCurve(theCurve) +{ + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap aSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); + QPixmap aPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); + QPixmap aClosedSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_SPLINE"))); + QPixmap aClosedPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_POLYLINE"))); + QPixmap aPointIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POINT"))); + +/* QPixmap aSplineIcon(tr(":images/ICON_SPLINE")); + QPixmap aPolylineIcon(tr(":images/ICON_POLYLINE")); + QPixmap aClosedPolylineIcon(tr(":images/ICON_CLOSED_POLYLINE")); + QPixmap aClosedSplineIcon(tr(":images/ICON_CLOSED_SPLINE")); + QPixmap aPointIcon(tr(":images/ICON_POINT")); */ + + if( !aSplineIcon.isNull() ) + myCachedIcons[ICON_SPLINE] = aSplineIcon; + + if( !aPolylineIcon.isNull() ) + myCachedIcons[ICON_POLYLINE] = aPolylineIcon; + + if( !aPolylineIcon.isNull() ) + myCachedIcons[ICON_CLOSED_POLYLINE] = aClosedPolylineIcon; + + if( !aPolylineIcon.isNull() ) + myCachedIcons[ICON_CLOSED_SPLINE] = aClosedSplineIcon; + + if( !aPointIcon.isNull() ) + myCachedIcons[ICON_POINT] = aPointIcon; + + setHeaderData(1, Qt::Horizontal, QVariant("Name"), Qt::DisplayRole); + setHeaderData(2, Qt::Horizontal, QVariant("Nb points"), Qt::DisplayRole); +} + +int CurveCreator_TreeViewModel::columnCount(const QModelIndex & parent ) const +{ + if( parent.internalId() == ID_SECTION ) + return 2; + else + return 2; +} + +QVariant CurveCreator_TreeViewModel::data(const QModelIndex & index, int role ) const +{ + int aRow = index.row(); + int aColumn = index.column(); + if( myCurve ){ + if( index.internalId() == ID_SECTION ){ + if( role == Qt::DisplayRole ){ + if( aColumn == 0 ) + return QString::fromStdString(myCurve->getSectionName(aRow)); + else if( aColumn == 1 ) + return QString::number(myCurve->getNbPoints(aRow)); + return QVariant(); + } + else if( role == Qt::DecorationRole ){ + if( aColumn == 0 ){ + CurveCreator::SectionType aSectionType = myCurve->getSectionType(aRow); + if( aSectionType == CurveCreator::Polyline ){ + if( myCurve->isClosed(aRow) ){ + return myCachedIcons[ICON_CLOSED_POLYLINE]; + } + else{ + return myCachedIcons[ICON_POLYLINE]; + } + } + else{ + if( myCurve->isClosed(aRow) ){ + return myCachedIcons[ICON_CLOSED_SPLINE]; + } + else{ + return myCachedIcons[ICON_SPLINE]; + } + } + } + } + } +/* else{ + if( role == Qt::DisplayRole ){ + if( aColumn == 1 ) + return QVariant(); + // return "Point"; + else if( aColumn == 0 ){ + CurveCreator::Coordinates aCoords = myCurve->getCoordinates(index.internalId(),index.row() ); + QString anOut; + if( myCurve->getDimension() == CurveCreator::Dim2d ){ + anOut = QString(tr("X=%1, Y=%2")).arg(aCoords[0]).arg(aCoords[1]); + } + else{ + anOut = QString(tr("X=%1, Y=%2, Z=%3")).arg(aCoords[0]).arg(aCoords[1]).arg(aCoords[2]); + } + return anOut; + } + } + else if( role == Qt::DecorationRole ){ + if( aColumn == 0 ){ + return myCachedIcons[ICON_POINT]; + } + } + }*/ + } + return QVariant(); +} + +QModelIndex CurveCreator_TreeViewModel::index(int row, int column, const QModelIndex & parent ) const +{ + if( parent.isValid() ){ + return createIndex(row, column, parent.row() ); + } + else{ + QModelIndex aParent = createIndex(row, column, ID_SECTION ); + return aParent; + } + return QModelIndex(); +} + +QModelIndex CurveCreator_TreeViewModel::parent(const QModelIndex & theIndex) const +{ + if( !theIndex.isValid() ) + return QModelIndex(); + + if( theIndex.internalId() == ID_SECTION ){ + return QModelIndex(); + } + return createIndex( theIndex.internalId(), 0, ID_SECTION ); +} + +int CurveCreator_TreeViewModel::rowCount(const QModelIndex & parent ) const +{ + int aRowCnt = 0; + if( myCurve != NULL ){ + if( !parent.isValid() ){ + //Section level + aRowCnt = myCurve->getNbSections(); + } + else{ + if( parent.internalId() == ID_SECTION ){ + //Points level + aRowCnt = myCurve->getNbPoints(parent.row()); + } + } + } + return aRowCnt; +} + +QModelIndex CurveCreator_TreeViewModel::sectionIndex( int theSection ) const +{ + return createIndex( theSection, 0, ID_SECTION ); +} + +QModelIndex CurveCreator_TreeViewModel::nbPointsIndex( int theSection ) const +{ + return createIndex( theSection, 1, ID_SECTION ); +} + +QModelIndex CurveCreator_TreeViewModel::pointIndex( int theSection, int thePoint ) const +{ + return createIndex( thePoint, 0, theSection ); +} + +bool CurveCreator_TreeViewModel::isSection( const QModelIndex& theIndx ) const +{ + if( theIndx.internalId() == ID_SECTION ) + return true; + return false; +} + +int CurveCreator_TreeViewModel::getSection( const QModelIndex& theIndx ) const +{ + if( theIndx.internalId() == ID_SECTION ) + return theIndx.row(); + return theIndx.internalId(); +} + +int CurveCreator_TreeViewModel::getPoint( const QModelIndex& theIndx ) const +{ + if( theIndx.internalId() == ID_SECTION ) + return -1; + return theIndx.row(); +} + +void CurveCreator_TreeViewModel::setCurve( CurveCreator_ICurve* theCurve ) +{ + myCurve = theCurve; + reset(); +} + +/*****************************************************************************************/ +CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent) : + QTreeView(parent) +{ + header()->hide(); + header()->setResizeMode(QHeaderView::ResizeToContents); + setUniformRowHeights(true); + setContextMenuPolicy( Qt::CustomContextMenu ); + CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this); + setModel(aModel); + setSelectionBehavior(SelectRows); + setSelectionMode(SingleSelection); + setRootIsDecorated(false); + setItemsExpandable(false); + setAllColumnsShowFocus(true); + connect( selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SIGNAL(selectionChanged()) ); + connect( this, SIGNAL(activated(QModelIndex)), this, SLOT(onActivated(QModelIndex))); +} + +QList CurveCreator_TreeView::getSelectedSections() const +{ + QList aSect; + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( !aModel ) + return aSect; +// QModelIndexList anIndxs = selectionModel()->selectedIndexes(); + QModelIndexList anIndxs = selectionModel()->selectedRows(); + for( int i = 0 ; i < anIndxs.size() ; i++ ){ + if( aModel->isSection(anIndxs[i]) ){ + aSect << aModel->getSection( anIndxs[i] ); + } + } + qSort(aSect.begin(), aSect.end()); + return aSect; +} + +void CurveCreator_TreeView::pointsAdded( int theSection, int thePoint, int thePointsCnt ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aSectIndx = aModel->sectionIndex( theSection ); + rowsInserted(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); +// expand( aSectIndx ); + update( aModel->nbPointsIndex( theSection ) ); + } +} + +void CurveCreator_TreeView::pointDataChanged( int theSection, int thePoint ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aPointIndx = aModel->pointIndex( theSection, thePoint ); + dataChanged( aPointIndx, aPointIndx ); + } +} + +void CurveCreator_TreeView::pointsRemoved( int theSection, int thePoint, int thePointsCnt ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + for( int i = 0 ; i < thePointsCnt ; i++ ){ + QModelIndex aSectIndx = aModel->pointIndex(theSection, thePoint + i); + selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect); + } + QModelIndex aSectIndx = aModel->sectionIndex( theSection ); + rowsRemoved(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); + } +} + +void CurveCreator_TreeView::sectionAdded( int theSection ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + int nbRows = aModel->rowCount(); + int aSection = (theSection == -1 ? (nbRows==0 ? 0 : nbRows-1) : theSection); + rowsInserted(QModelIndex(), aSection, aSection ); + QModelIndex aSectIndx = aModel->sectionIndex(aSection); + selectionModel()->select(aSectIndx, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); + } +} + +void CurveCreator_TreeView::sectionChanged( int theSection, int aSectCnt ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aFirstSectIndx = aModel->sectionIndex( theSection ); + QModelIndex aLastSectIndx = aModel->sectionIndex( theSection + aSectCnt - 1); + dataChanged( aFirstSectIndx, aLastSectIndx ); + } +} + +void CurveCreator_TreeView::sectionsRemoved( int theSection, int theSectionCnt ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + for( int i = 0 ; i < theSectionCnt ; i++ ){ + QModelIndex aSectIndx = aModel->sectionIndex(theSection + i); + this->selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect); + } + rowsRemoved( QModelIndex(), theSection, theSection+theSectionCnt-1 ); + } +} + +void CurveCreator_TreeView::setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ) +{ + setExpanded( theIndx, isExpanded ); + QItemSelectionModel::SelectionFlags aFlag = QItemSelectionModel::Select; + if( !isSelected ){ + aFlag = QItemSelectionModel::Deselect; + } + selectionModel()->select( theIndx, aFlag ); +} + +void CurveCreator_TreeView::getIndexInfo( const QModelIndex& theIndx, bool& isExpand, bool& isSelected, bool& isCurrent ) +{ + isExpand = isExpanded(theIndx); + isSelected = selectionModel()->isSelected(theIndx); + isCurrent = (theIndx == selectionModel()->currentIndex()); +} + +void CurveCreator_TreeView::swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond ) +{ + bool isFirstSelected; + bool isFirstExpanded; + bool isFirstCurrent; + getIndexInfo( theFirst, isFirstExpanded, isFirstSelected, isFirstCurrent ); + + bool isSecondSelected; + bool isSecondExpanded; + bool isSecondCurrent; + getIndexInfo( theSecond, isSecondExpanded, isSecondSelected, isSecondCurrent ); + + setIndexState( theFirst, isSecondExpanded, isSecondSelected, isSecondCurrent ); + setIndexState( theSecond, isFirstExpanded, isFirstSelected, isFirstCurrent ); + dataChanged(theFirst,theFirst); + dataChanged(theSecond,theSecond); +} + +void CurveCreator_TreeView::sectionsSwapped( int theSection, int theOffset ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aFirstIndex = aModel->sectionIndex( theSection ); + QModelIndex aSecondIndex = aModel->sectionIndex( theSection + theOffset ); + swapIndexes( aFirstIndex, aSecondIndex ); + } +} + +void CurveCreator_TreeView::pointsSwapped( int theSection, int thePointNum, int theOffset ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aFirstIndex = aModel->pointIndex( theSection, thePointNum ); + QModelIndex aSecondIndex = aModel->pointIndex( theSection, thePointNum + theOffset ); + swapIndexes( aFirstIndex, aSecondIndex ); + } +} + +void CurveCreator_TreeView::setSelectedSections( const QList& theList ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + selectionModel()->clearSelection(); + for( int i = 0 ; i < theList.size() ; i++ ){ + QModelIndex aSectIndx = aModel->sectionIndex(theList[i]); + selectionModel()->select(aSectIndx, QItemSelectionModel::Select ); + } + } +} + +void CurveCreator_TreeView::setSelectedPoints( const QList< QPair >& thePointsList ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + selectionModel()->clearSelection(); + for( int i = 0 ; i < thePointsList.size() ; i++ ){ + QModelIndex aSectIndx = aModel->pointIndex( thePointsList[i].first, thePointsList[i].second ); + selectionModel()->select(aSectIndx, QItemSelectionModel::Select ); + } + } +} + +bool pointLessThan(const QPair &s1, const QPair &s2) +{ + if( s1.first < s2.first ) + return true; + if( s1.first > s2.first ) + return false; + return s1.second < s2.second; +} + +QList< QPair< int, int > > CurveCreator_TreeView::getSelectedPoints() const +{ + QList< QPair< int, int > > aPoints; + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( !aModel ) + return aPoints; + QModelIndexList anIndxs = selectionModel()->selectedIndexes(); + for( int i = 0 ; i < anIndxs.size() ; i++ ){ + if( !aModel->isSection( anIndxs[i] ) ){ + int aSect = aModel->getSection(anIndxs[i]); + int aPointNum = aModel->getPoint(anIndxs[i]); + QPair< int, int > aPoint = QPair( aSect, aPointNum ); + aPoints.push_back( aPoint ); + } + } + qSort( aPoints.begin(), aPoints.end(), pointLessThan ); + return aPoints; +} + +CurveCreator_TreeView::SelectionType CurveCreator_TreeView::getSelectionType() const +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( !aModel ) + return ST_NOSEL; + bool isPointSel = false; + bool isSectSel = false; + bool isOneSection = true; + int aSectNum = -1; + QModelIndexList aLst = selectionModel()->selectedIndexes(); + for( int i = 0 ; i < aLst.size() ; i++ ){ + if( aModel->isSection( aLst[i] ) ){ + isSectSel = true; + } + else{ + isPointSel = true; + if( aSectNum == -1 ){ + aSectNum = aModel->getSection(aLst[i]); + } + else{ + if( aSectNum != aModel->getSection( aLst[i] ) ){ + isOneSection = false; + } + } + } + } + if( isSectSel && !isPointSel ) + return ST_SECTIONS; + if( isPointSel && !isSectSel ){ + if( isOneSection ){ + return ST_POINTS_ONE_SECTION; + } + return ST_POINTS; + } + if( isPointSel && isSectSel ) + return ST_MIXED; + return ST_NOSEL; +} + +void CurveCreator_TreeView::onActivated( QModelIndex theIndx ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( !aModel ) + return; + int aSect = aModel->getSection(theIndx); + if( aModel->isSection(theIndx) ){ + emit sectionEntered( aSect ); + return; + } + int aPointNum = aModel->getPoint( theIndx ); + emit pointEntered( aSect, aPointNum ); +} + +void CurveCreator_TreeView::setCurve( CurveCreator_ICurve* theCurve ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ) + aModel->setCurve(theCurve); + reset(); +} diff --git a/src/HYDROCurveCreator/CurveCreator_TreeView.h b/src/HYDROCurveCreator/CurveCreator_TreeView.h new file mode 100755 index 00000000..20f8a622 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_TreeView.h @@ -0,0 +1,96 @@ +// 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_TREEVIEW_H +#define CURVECREATOR_TREEVIEW_H + +#include +#include + +class CurveCreator_ICurve; + +class CurveCreator_TreeViewModel : public QAbstractItemModel +{ +public: + CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent ); + virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; + virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; + virtual QModelIndex parent(const QModelIndex & theIndex) const; +// virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole); + + QModelIndex sectionIndex( int theSection ) const; + QModelIndex nbPointsIndex( int theSection ) const; + QModelIndex pointIndex( int theSection, int thePoint ) const; + + bool isSection( const QModelIndex& theIndx ) const; + int getSection( const QModelIndex& theIndx ) const; + int getPoint( const QModelIndex& theIndx ) const; + + void setCurve( CurveCreator_ICurve* theCurve ); + +private: + enum IconType{ ICON_POLYLINE, ICON_SPLINE, ICON_CLOSED_SPLINE, ICON_CLOSED_POLYLINE, ICON_POINT }; +private: + CurveCreator_ICurve* myCurve; + QMap myCachedIcons; +}; + +class CurveCreator_TreeView : public QTreeView +{ + Q_OBJECT +public: + enum SelectionType{ ST_NOSEL, ST_POINTS, ST_POINTS_ONE_SECTION, ST_SECTIONS, ST_MIXED }; +public: + explicit CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent = 0); + SelectionType getSelectionType() const; + QList getSelectedSections() const; + QList< QPair< int, int > > getSelectedPoints() const; + + void pointsAdded( int theSection, int thePoint, int thePointsCnt=1 ); + void pointDataChanged( int theSection, int thePoint ); + void pointsRemoved(int theSection, int thePoint, int thePointsCnt=1 ); + void pointsSwapped( int theSection, int thePointNum, int theOffset ); + + void sectionAdded( int theSection ); + void sectionChanged(int theSection , int aSectCnt = 1); + void sectionsRemoved( int theSection, int theSectionCnt=1 ); + void sectionsSwapped( int theSection, int theOffset ); + + void setSelectedSections( const QList& theList ); + void setSelectedPoints( const QList< QPair >& thePointsList ); + + void setCurve( CurveCreator_ICurve* theCurve ); + +signals: + void selectionChanged(); + void sectionEntered(int); + void pointEntered(int,int); +public slots: +protected slots: + void onActivated( QModelIndex theIndx ); +protected: + void setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ); + void swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond ); + void getIndexInfo( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ); + +}; + +#endif // CURVECREATOR_TREEVIEW_H diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx new file mode 100644 index 00000000..5aea5035 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -0,0 +1,1088 @@ +// 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_Widget.h" +#include "CurveCreator_TreeView.h" +#include "CurveCreator_ICurve.hxx" +//#include "CurveCreator_CurveEditor.hxx" +#include "CurveCreator.hxx" +//#include "CurveCreator_NewPointDlg.h" +#include "CurveCreator_NewSectionDlg.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +//#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOCAL_SELECTION_TOLERANCE 0.0001 + +CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, + CurveCreator_ICurve *theCurve, + Qt::WindowFlags fl) : + QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0) +{ + myNewSectionEditor = new CurveCreator_NewSectionDlg( this ); + myNewSectionEditor->hide(); + connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) ); + connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) ); + connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) ); + + QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this); + + mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup); + connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) ); + connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) ); + connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) ); + + myLocalPointView = new QTableWidget(); + myLocalPointView->setVisible( false ); + myLocalPointView->setColumnCount( 3 ); + QStringList aLabels; + //aLabels << tr( "IDENTIFIER_LABEL" ) << tr( "X_POSITION_LBL" ) << tr( "Y_POSITION_LBL" ); + aLabels << tr( "id" ) << tr( "X" ) << tr( "Y" ); + myLocalPointView->setHorizontalHeaderLabels( aLabels ); + connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ), + this, SLOT( onLocalPointChanged( int, int ) ) ); + + QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup); +// QToolButton* anUndoBtn = new QToolButton(aTB); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO"))); + QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO"))); + QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION"))); + QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT"))); + QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS"))); + QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS"))); + QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); + QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); + QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE"))); + QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN"))); + QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP"))); + QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN"))); + + QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Z) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) ); + aTB->addAction(anAct); + + anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Y) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) ); + aTB->addAction(anAct); + + aTB->addSeparator(); + + anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_N) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) ); + aTB->addAction(anAct); + aTB->addSeparator(); + + anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"), + QKeySequence() ); + anAct->setCheckable(true); + connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) ); + connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); + aTB->addAction(anAct); + + anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"), + QKeySequence() ); + anAct->setCheckable(true); + connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) ); + connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); + aTB->addAction(anAct); + + anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"), + QKeySequence() ); + anAct->setCheckable(true); + connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectionMode(bool)) ); + connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); + aTB->addAction(anAct); + + anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_W) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) ); + + anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(), + tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) ); + + anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"), + aPolylinePixmap, tr("SET_POLYLINE_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_E) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) ); + + anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap, + tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) ); + + anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) ); + aTB->addAction(anAct); + aTB->addSeparator(); + + anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) ); + aTB->addAction(anAct); + aTB->addSeparator(); + + anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"), + QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) ); + + anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"), + QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) ); + + QVBoxLayout* aSectLayout = new QVBoxLayout(); + aSectLayout->setMargin( 5 ); + aSectLayout->setSpacing( 5 ); + aSectLayout->addWidget(aTB); + aSectLayout->addWidget(mySectionView); + aSectLayout->addWidget( myLocalPointView ); + aSectionGroup->setLayout(aSectLayout); + QVBoxLayout* aLay = new QVBoxLayout(); + aLay->setMargin( 0 ); + aLay->setSpacing( 5 ); +// aLay->addLayout(aNameLayout); + aLay->addWidget(aSectionGroup); + setLayout(aLay); + onSelectionChanged(); + + /*OCCViewer_Viewer* anOCCViewer = getOCCViewer(); + if (anOCCViewer) { + OCCViewer_ViewWindow* aWnd = dynamic_cast(anOCCViewer->getViewManager()->getActiveView()); + if ( aWnd ) + aWnd->installEventFilter( this ); + }*/ +} + +//======================================================================= +// function: getUniqSectionName +// purpose: return unique section name +//======================================================================= +OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer() +{ + OCCViewer_Viewer* anOCCViewer = 0; + + OCCViewer_ViewWindow* aViewWindow = 0; + SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); + if ( activeStudy ) + aViewWindow = dynamic_cast(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()); + if ( aViewWindow == 0 ) + return anOCCViewer; + OCCViewer_ViewManager* aViewManager = dynamic_cast(aViewWindow->getViewManager()); + if ( aViewManager == 0 ) + return anOCCViewer; + + anOCCViewer = aViewManager->getOCCViewer(); + return anOCCViewer; +} + +/*! + \brief Customize event handling + \param watched event receiver object + \param e event + \return \c true if the event processing should be stopped +*/ +/*bool CurveCreator_Widget::eventFilter( QObject* theWatched, QEvent* theEvent ) +{ + OCCViewer_Viewer* anOCCViewer = getOCCViewer(); + Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext(); + bool isLocalContext = aContext->HasOpenedContext(); + if ( !isLocalContext ) + return QWidget::eventFilter( theWatched, theEvent ); + + bool isProcessed = true; + + return isProcessed; +}*/ + +//======================================================================= +// function: getUniqSectionName +// purpose: return unique section name +//======================================================================= +std::string CurveCreator_Widget::getUniqSectionName( CurveCreator_ICurve* theCurve ) const +{ + for( int i = 0 ; i < 1000000 ; i++ ){ + char aBuffer[255]; + sprintf( aBuffer, "Section_%d", i+1 ); + std::string aName(aBuffer); + int j; + for( j = 0 ; j < theCurve->getNbSections() ; j++ ){ + if( theCurve->getSectionName(j) == aName ) + break; + } + if( j == theCurve->getNbSections() ) + return aName; + } + return ""; +} + +void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve ) +{ + myCurve = theCurve; + mySectionView->setCurve(myCurve); + onSelectionChanged(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onSelectionChanged() +{ + QList anEnabledAct; + if( myCurve ){ + anEnabledAct << NEW_SECTION_ID; + QList aSelSections = mySectionView->getSelectedSections(); + QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints(); + CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); + switch( aSelType ){ + case CurveCreator_TreeView::ST_NOSEL:{ + break; + } + case CurveCreator_TreeView::ST_SECTIONS:{ + /*if( aSelSections[0] > 0 ){ + anEnabledAct << UP_ID; + }*/ + if( aSelSections.size() == 1 ){ + anEnabledAct << ADDITION_MODE_ID << MODIFICATION_MODE_ID << DETECTION_MODE_ID; + } + if (myActionMap[ADDITION_MODE_ID]->isChecked()) { + mySection = -1; + myPointNum = -1; + QList aSelSection = mySectionView->getSelectedSections(); + if( aSelSection.size() > 0 ){ + mySection = aSelSection[0]; + myPointNum = myCurve->getNbPoints(mySection); + } + } else if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) { + anEnabledAct << REMOVE_ID; + anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID; + int aSectCnt = myCurve->getNbSections(); + if( aSectCnt > 0 ) + anEnabledAct << CLEAR_ALL_ID; + if( aSectCnt > 1 ) + anEnabledAct << JOIN_ALL_ID; + if( aSelSections.size() > 1 ){ + anEnabledAct << JOIN_ID; + } + } else if (myActionMap[DETECTION_MODE_ID]->isChecked()) { + } else { //no active mode + } + /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){ + anEnabledAct << DOWN_ID; + }*/ + break; + } + /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{ + if( aSelPoints[0].second > 0 ){ + anEnabledAct << UP_ID; + } + int aLastIndex = aSelPoints.size()-1; + int aSect = aSelPoints[0].first; + if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){ + anEnabledAct << DOWN_ID; + } + if( aSelPoints.size() == 1){ + anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID; + } + break; + }*/ + + } + + /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size(); + if( aSelObjsCnt > 0 ){ + anEnabledAct << REMOVE_ID; + } + if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){ + anEnabledAct << REMOVE_ALL_ID; + }*/ + if( myCurve->getNbSections() > 1 ){ + anEnabledAct << JOIN_ALL_ID; + } + } + QList anIds = myActionMap.keys(); + for( int i = 0 ; i < anIds.size() ; i++ ){ + if( myActionMap.contains(anIds[i]) ){ + if( anEnabledAct.contains(anIds[i]) ){ + myActionMap[anIds[i]]->setEnabled(true); + } + else{ + myActionMap[anIds[i]]->setEnabled(false); + } + } + } + emit selectionChanged(); +} + +void CurveCreator_Widget::onAdditionMode(bool checked) +{ + if( !myCurve ) + return; + OCCViewer_Viewer* anOCCViewer = getOCCViewer(); + Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext(); + OCCViewer_ViewManager* aViewManager = dynamic_cast + (anOCCViewer->getViewManager()); +// if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) { + if( anOCCViewer ) { + if (checked) { +/* myGuiState = aViewWindow->saveState(); + anOCCViewer->enableMultiselection(false); + anOCCViewer->enableSelection(false);*/ + connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onGetCoordsByClick( SUIT_ViewWindow*, QMouseEvent* ) ) ); + } else { + disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onGetCoordsByClick( SUIT_ViewWindow*, QMouseEvent* ) ) ); +/* anOCCViewer->enableMultiselection(true); + anOCCViewer->enableSelection(true); + aViewWindow->restoreState( myGuiState );*/ + return; + } + } + + mySection= -1; + myPointNum = -1; + QList aSelSection = mySectionView->getSelectedSections(); + if( aSelSection.size() > 0 ){ + mySection = aSelSection[0]; + } + else{ + QList< QPair > aSelPoints = mySectionView->getSelectedPoints(); + if( aSelPoints.size() > 0 ){ + mySection = aSelPoints[0].first; + myPointNum = aSelPoints[0].second + 1; + } + } +// emit subOperationStarted( myNewPointEditor ); +} + +void CurveCreator_Widget::onModificationMode(bool checked) +{ + myLocalPointView->setVisible( checked ); + OCCViewer_Viewer* anOCCViewer = getOCCViewer(); + OCCViewer_ViewManager* aViewManager = dynamic_cast + (anOCCViewer->getViewManager()); +/* + SUIT_ViewWindow* aViewWindow = 0; + SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); + if ( activeStudy ) + aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + if ( aViewWindow == 0 ) + return; + SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();*/ + if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) { + if (checked) { + connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) ); + connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) ); + } + else { + disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) ); + disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) ); + return; + } + } + //NDS OCCViewer_ViewWindow* anOCCWnd = dynamic_cast(aViewWindow); + //anOCCWnd->activateStartPointSelection(); + // activate selection ------> + //OCCViewer_Viewer* anOCCViewer = dynamic_cast(aViewManager->getViewModel()); + + setLocalPointContext( true ); +} + +void CurveCreator_Widget::onDetectionMode(bool checked) +{ +} + +void CurveCreator_Widget::onModeChanged(bool checked) +{ + setLocalPointContext( false ); + if (checked) { + QAction* anAction = (QAction*)sender(); + switch(myActionMap.key(anAction)) { + case ADDITION_MODE_ID: + if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) + myActionMap[MODIFICATION_MODE_ID]->trigger(); + else if (myActionMap[DETECTION_MODE_ID]->isChecked()) + myActionMap[DETECTION_MODE_ID]->trigger(); + break; + case MODIFICATION_MODE_ID: + if (myActionMap[ADDITION_MODE_ID]->isChecked()) + myActionMap[ADDITION_MODE_ID]->trigger(); + else if (myActionMap[DETECTION_MODE_ID]->isChecked()) + myActionMap[DETECTION_MODE_ID]->trigger(); + break; + case DETECTION_MODE_ID: + if (myActionMap[ADDITION_MODE_ID]->isChecked()) + myActionMap[ADDITION_MODE_ID]->trigger(); + else if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) + myActionMap[MODIFICATION_MODE_ID]->trigger(); + break; + } + } + onSelectionChanged(); +} + +void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords) +{ + if( !myCurve ) + return; + myCurve->addPoints(theCoords, mySection, myPointNum ); + mySectionView->pointsAdded( mySection, myPointNum ); + myPointNum++; + onSelectionChanged(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onNewSection() +{ + if( !myCurve ) + return; + myNewSectionEditor->clear(); + myNewSectionEditor->setEditMode(false); + QString aSectName = QString( getUniqSectionName(myCurve).c_str() ); + myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline ); + emit subOperationStarted( myNewSectionEditor ); +} + +void CurveCreator_Widget::onAddNewSection() +{ + if( !myCurve ) + return; + myCurve->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(), + myNewSectionEditor->isClosed() ); + mySectionView->sectionAdded( -1 ); // add a new section to the end of list + QString aNewName = QString(getUniqSectionName(myCurve).c_str()); + myNewSectionEditor->setSectionName(aNewName); + onSelectionChanged(); + updateUndoRedo(); + onCancelSection(); +} + +void CurveCreator_Widget::onCancelSection() +{ + emit subOperationFinished( myNewSectionEditor ); +} + +QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage, + const QString& theToolTip, const QKeySequence& theShortcut ) +{ + QAction* anAct = new QAction(theName,this); + if( !theImage.isNull() ){ + anAct->setIcon(theImage); + } + anAct->setShortcut(theShortcut); + anAct->setToolTip(theToolTip); + myActionMap[theId] = anAct; + return anAct; +} + +QAction* CurveCreator_Widget::getAction(ActionId theId) +{ + if( myActionMap.contains(theId) ) + return myActionMap[theId]; + return NULL; +} + +void CurveCreator_Widget::onEditSection( int theSection ) +{ + if( !myCurve ) + return; + mySection = theSection; + QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection)); + bool isClosed = myCurve->isClosed(theSection); + CurveCreator::SectionType aType = myCurve->getSectionType(theSection); + myNewSectionEditor->setEditMode(true); + myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType ); + + emit subOperationStarted( myNewSectionEditor ); +} + +void CurveCreator_Widget::onModifySection() +{ + if( !myCurve ) + return; + QString aName = myNewSectionEditor->getName(); + bool isClosed = myNewSectionEditor->isClosed(); + CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType(); +// myCurve->startOperation(); + myCurve->setClosed( isClosed, mySection ); + myCurve->setSectionName( mySection , aName.toStdString() ); + myCurve->setSectionType( mySection, aSectType ); +// myCurve->finishOperation(); + mySectionView->sectionChanged(mySection); + updateUndoRedo(); + onCancelSection(); +} + +/*void CurveCreator_Widget::onEditPoint( int theSection, int thePoint ) +{ + if( !myNewPointEditor || !myEdit ) + return; + mySection = theSection; + myPointNum = thePoint; + QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection)); + myNewPointEditor->setEditMode(true); + myNewPointEditor->setSectionName(aSectName); + myNewPointEditor->setDimension( myCurve->getDimension() ); + CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint); + myNewPointEditor->setCoordinates(aCoords); + emit subOperationStarted( myNewPointEditor ); +} + +void CurveCreator_Widget::onModifyPoint() +{ + if( !myEdit ) + return; + CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates(); + myEdit->setCoordinates( aCoords, mySection, myPointNum ); + mySectionView->pointDataChanged( mySection, myPointNum ); + updateUndoRedo(); + onCancelPoint(); +}*/ + +void CurveCreator_Widget::onJoin() +{ + if( !myCurve ) + return; + QList aSections = mySectionView->getSelectedSections(); + if( aSections.size() == 0 ){ + return; + } + int aMainSect = aSections[0]; + int aMainSectSize = myCurve->getNbPoints(aMainSect); +// myCurve->startOperation(); + for( int i = 1 ; i < aSections.size() ; i++ ){ + int aSectNum = aSections[i] - (i-1); + myCurve->join( aMainSect, aSectNum ); + mySectionView->sectionsRemoved( aSectNum ); + } +// myCurve->finishOperation(); + int aNewSectSize = myCurve->getNbPoints(aMainSect); + if( aNewSectSize != aMainSectSize ) + mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize ); + updateUndoRedo(); +} + +void CurveCreator_Widget::onRemove() +{ + if( !myCurve ) + return; + QList< QPair > aSelPoints = mySectionView->getSelectedPoints(); + int aCurrSect=-1; + int aRemoveCnt = 0; +// myCurve->startOperation(); + for( int i = 0 ; i < aSelPoints.size() ; i++ ){ + if( aCurrSect != aSelPoints[i].first ){ + aRemoveCnt = 0; + aCurrSect = aSelPoints[i].first; + } + int aPntIndx = aSelPoints[i].second - aRemoveCnt; + myCurve->removePoint( aCurrSect, aPntIndx ); + mySectionView->pointsRemoved( aCurrSect, aPntIndx ); + aRemoveCnt++; + } + QList aSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSections.size() ; i++ ){ + int aSectNum = aSections[i] - (i); + myCurve->removeSection( aSectNum ); + mySectionView->sectionsRemoved( aSectNum ); + } +// myCurve->finishOperation(); + mySectionView->clearSelection(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onClearAll() +{ + if( !myCurve ) + return; + myCurve->clear(); + mySectionView->reset(); + onSelectionChanged(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onJoinAll() +{ + if( !myCurve ) + return; + myCurve->join(); + mySectionView->reset(); + onSelectionChanged(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onUndoSettings() +{ + +} + +void CurveCreator_Widget::onSetSpline() +{ + if( !myCurve ) + return; + QList aSelSections = mySectionView->getSelectedSections(); +// myCurve->startOperation(); + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + myCurve->setSectionType(aSelSections[i], CurveCreator::Spline ); + mySectionView->sectionChanged(aSelSections[i]); + } +// myCurve->finishOperation(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onSetPolyline() +{ + if( !myCurve ) + return; +// myCurve->startOperation(); + QList aSelSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + myCurve->setSectionType( aSelSections[i], CurveCreator::Polyline ); + mySectionView->sectionChanged( aSelSections[i] ); + } +// myCurve->finishOperation(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onCloseSections() +{ + if( !myCurve ) + return; +// myCurve->startOperation(); + QList aSelSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + myCurve->setClosed(true, aSelSections[i]); + mySectionView->sectionChanged(aSelSections[i]); + } +// myCurve->finishOperation(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onUncloseSections() +{ + if( !myCurve ) + return; +// myCurve->startOperation(); + QList aSelSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + myCurve->setClosed(false, aSelSections[i]); + mySectionView->sectionChanged(aSelSections[i]); + } +// myCurve->finishOperation(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onUndo() +{ + if( !myCurve ) + return; + myCurve->undo(); + mySectionView->reset(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onRedo() +{ + if( !myCurve ) + return; + myCurve->redo(); + mySectionView->reset(); + updateUndoRedo(); +} + +void CurveCreator_Widget::updateUndoRedo() +{ + QAction* anAct = myActionMap[UNDO_ID]; + if( anAct != 0 ){ + if( myCurve->getNbUndo() != 0 ){ + anAct->setEnabled(true); + } + else{ + anAct->setDisabled(true); + } + } + anAct = myActionMap[REDO_ID]; + if( anAct != 0 ){ + if( myCurve->getNbRedo() != 0 ){ + anAct->setEnabled(true); + } + else{ + anAct->setDisabled(true); + } + } +} + +void CurveCreator_Widget::onContextMenu( QPoint thePoint ) +{ + QList aContextActions; + aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID << + CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << + SET_SECTIONS_SPLINE_ID; + QPoint aGlPoint = mySectionView->mapToGlobal(thePoint); + bool isVis = false; + QList aResAct; + for( int i = 0 ; i < aContextActions.size() ; i++ ){ + if( aContextActions[i] != SEPARATOR_ID ){ + if( myActionMap.contains(aContextActions[i]) ){ + QAction* anAct = myActionMap[aContextActions[i]]; + if( anAct->isEnabled() ){ + aResAct << aContextActions[i]; + isVis = true; + } + } + } + else{ + aResAct << SEPARATOR_ID; + } + } + if( !isVis ) + return; + + QMenu* aMenu = new QMenu(this); + for( int i = 0 ; i < aResAct.size() ; i++ ){ + if( aResAct[i] == SEPARATOR_ID ){ + aMenu->addSeparator(); + } + else{ + QAction* anAct = myActionMap[aResAct[i]]; + aMenu->insertAction(NULL, anAct); + } + } + aMenu->exec(aGlPoint); +} + +QList CurveCreator_Widget::getSelectedSections() +{ + return mySectionView->getSelectedSections(); +} + +QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints() +{ + return mySectionView->getSelectedPoints(); +} + +//================================================================================= +// function : GeometryGUI::onGetCoordsByClick() +// purpose : Manage mouse press events in Additon mode +//================================================================================= +void CurveCreator_Widget::onGetCoordsByClick( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe ) +{ + if (pe->button() != Qt::LeftButton) + return; + + if ( theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && + pe->modifiers() != Qt::ControlModifier ) { + OCCViewer_Viewer* anOCCViewer = + ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + + gp_Pnt aPnt; + + ic->InitSelected(); + if ( pe->modifiers() == Qt::ShiftModifier ) + ic->ShiftSelect(); // Append selection + else + ic->Select(); // New selection + + /*TopoDS_Shape aShape; + + ic->InitSelected(); + if ( ic->MoreSelected() ) + aShape = ic->SelectedShape(); + + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); + else*/ + { + OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + } + // set the coordinates into dialog + CurveCreator::Coordinates aCoords; + aCoords.push_back( aPnt.X() ); + aCoords.push_back( aPnt.Y() ); + if ( myCurve->getDimension() == 3 ) { + aCoords.push_back( aPnt.Z() ); + } + onAddNewPoint(aCoords); +// myNewPointEditor->setCoordinates( aCoords ); + } +} + +//================================================================================= +// function : HYDROGUI_PolylineOp::onPointSelect() +// purpose : Manage mouse press events in Modification mode +//================================================================================= +void CurveCreator_Widget::onPointSelect( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe ) +{ + //store initial cursor position for Drag&Drop + if (pe->button() == Qt::LeftButton) + myDragStartPosition = pe->pos(); + + //gp_Pnt aPnt; + OCCViewer_Viewer* anOCCViewer = + ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); + Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext(); + + //ic->InitSelected(); + //if ( pe->modifiers() == Qt::ShiftModifier ) + // ic->ShiftSelect(); // Append selection + //else + // ic->Select(); // New selection + + /*ic->InitSelected(); + if ( ic->MoreSelected() ) { + TopoDS_Shape aShape = ic->SelectedShape(); + Standard_Boolean hasdet = ic->HasDetectedShape(); + Standard_Boolean hassel = ic->HasSelectedShape(); + Standard_Integer nbcur = ic->NbCurrents(); + Standard_Integer nbsel = ic->NbSelected(); + if(!aShape.IsNull()) + if ( aShape.ShapeType() == TopAbs_VERTEX ) + aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); + } + + Qt::KeyboardModifiers modifiers = pe->modifiers(); +// aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog*/ + + updateLocalPointView(); +} + +//================================================================================= +// function : GeometryGUI::onPointDrag() +// purpose : Manage mouse move events in Modification mode +//================================================================================= +void CurveCreator_Widget::onPointDrag( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe ) +{ + if ( !(pe->buttons() & Qt::LeftButton) ) + return; + if ( (pe->pos() - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() ) + return; +/* + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setData(mimeType, data); + drag->setMimeData(mimeData); + + Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); + */ +} + +void CurveCreator_Widget::onLocalPointChanged( int theRow, int theColumn ) +{ + setLocalPointContext( false ); + + QList aSelSections = mySectionView->getSelectedSections(); + + int aPntIndex = -1; + int aCurrSect=-1; + std::deque aChangedPos; + float aPrevX, aPrevY, aX, anY; + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + aCurrSect = aSelSections[i]; + + aPrevX = myLocalPointView->item( theRow, 1 )->data( Qt::UserRole ).toDouble(); + aPrevY = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble(); + + aPntIndex = findLocalPointIndex( aCurrSect, aPrevX, aPrevY ); + if ( aPntIndex < 0 ) + continue; + + aX = myLocalPointView->item( theRow, 1 )->text().toDouble(); + anY = myLocalPointView->item( theRow, 2 )->text().toDouble(); + aChangedPos.clear(); + aChangedPos.push_back( aX ); + aChangedPos.push_back( anY ); + myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos ); + } + updateLocalPointView(); + + setLocalPointContext( true ); +} + +int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY ) +{ + int aPntIndex = -1; + + CurveCreator::Coordinates aCoords; + for ( int i = 0, aNb = myCurve->getNbPoints( theSectionId ); i < aNb && aPntIndex < 0; i++ ) { + aCoords = myCurve->getPoint( theSectionId, i ); + if ( aCoords.size() < 2 ) + continue; + if ( fabs( aCoords[0] - theX ) < LOCAL_SELECTION_TOLERANCE && + fabs( aCoords[1] - theY ) < LOCAL_SELECTION_TOLERANCE ) + aPntIndex = i; + } + + return aPntIndex; +} + +void CurveCreator_Widget::updateLocalPointView() +{ + OCCViewer_Viewer* anOCCViewer = getOCCViewer(); + if ( !anOCCViewer ) + return; + Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext(); + + bool isBlocked = myLocalPointView->blockSignals(true); + gp_Pnt aPnt; + myLocalPointView->setRowCount( 0 ); + for ( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) { + TopoDS_Vertex aVertex; + TopoDS_Shape aShape = aContext->SelectedShape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + aVertex = TopoDS::Vertex( aContext->SelectedShape() ); + else { + Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); + if ( !anOwner.IsNull() ) { + Handle(AIS_InteractiveObject) anAIS = Handle(AIS_InteractiveObject)::DownCast( anOwner->Selectable() ); + if ( !anAIS.IsNull() ) { + Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS); + if ( !aPoint.IsNull() ) + aVertex = TopoDS::Vertex( aPoint->Vertex() ); + } + if ( aVertex.IsNull() ) { + // the following happens if there are no points in the current curve, there is only a shape + /*Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); + if ( aBrepOwner.IsNull() ) + continue; + if ( aBrepOwner->HasShape() ) { + const TopoDS_Shape& aShape = aBrepOwner->Shape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + { + aVertex = TopoDS::Vertex( aShape ); + } + }*/ + } + } + if ( aVertex.IsNull() ) + continue; + aPnt = BRep_Tool::Pnt( aVertex ); + addLocalPointToTable( aPnt.X(), aPnt.Y() ); + } + } + myLocalPointView->blockSignals(isBlocked); +} + +void CurveCreator_Widget::setLocalPointContext( const bool theOpen ) +{ + OCCViewer_Viewer* anOCCViewer = getOCCViewer(); + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + + if ( theOpen ) { + // Open local context if there is no one + bool allObjects = true; + if ( !ic->HasOpenedContext() ) { + ic->ClearCurrents( false ); + ic->OpenLocalContext( allObjects, true, true ); + } + AIS_ListOfInteractive aList; + ic->DisplayedObjects( aList ); + int aLSize = 0; + for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() ) + aLSize++; + + int theMode = TopAbs_VERTEX; + for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() ) + { + Handle(AIS_InteractiveObject) anAIS = it.Value(); + if ( !anAIS.IsNull() ) + { + if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) ) + { + ic->Load( anAIS, -1, false ); + ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) ); + } + else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) ) + { + ic->Load( anAIS, -1, false ); + ic->Activate( anAIS, theMode ); + } + } + continue; + } + } + else { + ic->CloseAllContexts(); + } +} + +void CurveCreator_Widget::addLocalPointToTable( const double theX, const double theY ) +{ + int aRowId = myLocalPointView->rowCount(); + double aCurrentX, aCurrentY; + for ( int i = 0; i < aRowId; i++ ) { + aCurrentX = myLocalPointView->item( i, 1 )->data( Qt::UserRole ).toDouble(); + aCurrentY = myLocalPointView->item( i, 2 )->data( Qt::UserRole ).toDouble(); + if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE && + fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE ) + return; + } + QTableWidgetItem* anItem; + + myLocalPointView->setRowCount( aRowId+1 ); + myLocalPointView->setItem( aRowId, 0, new QTableWidgetItem( QString::number( aRowId + 1 ) ) ); + + anItem = new QTableWidgetItem( QString::number( theX ) ); + anItem->setData( Qt::UserRole, theX ); + myLocalPointView->setItem( aRowId, 1, anItem ); + + anItem = new QTableWidgetItem( QString::number( theY ) ); + anItem->setData( Qt::UserRole, theY ); + myLocalPointView->setItem( aRowId, 2, anItem ); +} \ No newline at end of file diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h new file mode 100644 index 00000000..82e5b732 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_Widget.h @@ -0,0 +1,137 @@ +// 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_WIDGET_H +#define CURVECREATOR_WIDGET_H + +//#include "CurveCreator_ICurve.hxx" +#include "CurveCreator.hxx" +#include "CurveCreator_Macro.hxx" + +#include +#include + +#include + +class OCCViewer_Viewer; + +class QAction; +class QPixmap; +class QTableWidget; +class CurveCreator_ICurve; +class CurveCreator_TreeView; +class CurveCreator_NewPointDlg; +class CurveCreator_NewSectionDlg; + +class CURVECREATOR_EXPORT CurveCreator_Widget : public QWidget +{ + Q_OBJECT +public: + explicit CurveCreator_Widget( QWidget* parent, + CurveCreator_ICurve *theCurve, + Qt::WindowFlags fl=0 ); + + OCCViewer_Viewer* getOCCViewer(); + + //virtual bool eventFilter( QObject* theWatched, QEvent* theEvent ); + + //! Return unique section name + std::string getUniqSectionName(CurveCreator_ICurve* theCurve) const; + + void setCurve( CurveCreator_ICurve* theCurve ); + + QList getSelectedSections(); + QList< QPair< int, int > > getSelectedPoints(); + +signals: + void selectionChanged(); + void subOperationStarted( QWidget* ); + void subOperationFinished( QWidget* ); + +public slots: + +protected slots: + void onAdditionMode(bool checked); + void onModificationMode(bool checked); + void onDetectionMode(bool checked); + void onModeChanged(bool checked); + void onNewSection(); + void onSelectionChanged(); + void onAddNewPoint(const CurveCreator::Coordinates& theCoords); + void onAddNewSection(); + void onEditSection( int theSection ); + void onModifySection(); + void onCancelSection(); + void onJoin(); + void onRemove(); + void onClearAll(); + void onJoinAll(); + void onSetSpline(); + void onSetPolyline(); + void onCloseSections(); + void onUncloseSections(); + void onUndo(); + void onRedo(); + void onUndoSettings(); + void onContextMenu(QPoint thePoint); + void onGetCoordsByClick( SUIT_ViewWindow*, QMouseEvent* ); + void onPointSelect( SUIT_ViewWindow*, QMouseEvent* ); + void onPointDrag( SUIT_ViewWindow*, QMouseEvent* ); + void onLocalPointChanged( int theRow, int theColumn ); +protected: + enum ActionId{ UNDO_ID, + REDO_ID, + NEW_SECTION_ID, + ADDITION_MODE_ID, + REMOVE_ID, + REMOVE_ALL_ID, + JOIN_ID, + JOIN_ALL_ID, + CLOSE_SECTIONS_ID, + UNCLOSE_SECTIONS_ID, + SET_SECTIONS_POLYLINE_ID, + SET_SECTIONS_SPLINE_ID, + CLEAR_ALL_ID, + SEPARATOR_ID, + MODIFICATION_MODE_ID, + DETECTION_MODE_ID + }; +private: + QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage, + const QString& theToolTip, const QKeySequence& theShortcut ); + QAction* getAction(ActionId theId); + void updateUndoRedo(); + int findLocalPointIndex( int theSectionId, float theX, float theY ); + void updateLocalPointView(); + void setLocalPointContext( const bool theOpen ); + void addLocalPointToTable( const double theX, const double theY ); + +private: + QMap myActionMap; + CurveCreator_ICurve* myCurve; + CurveCreator_TreeView* mySectionView; + QTableWidget* myLocalPointView; + CurveCreator_NewSectionDlg* myNewSectionEditor; + int mySection; + int myPointNum; + QPoint myDragStartPosition; + QByteArray myGuiState; +}; + +#endif // CURVECREATOR_WIDGET_H diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 0a832141..390d9070 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -121,16 +121,15 @@ include_directories( ${CAS_INCLUDE_DIRS} ${QT_INCLUDES} ${GUI_ROOT_DIR}/include/salome - ${GEOM_ROOT_DIR}/include/salome ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROData + ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROCurveCreator ) add_library(HYDROGUI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${PROJECT_HEADERS_MOC}) -target_link_libraries(HYDROGUI HYDROData - ${CAS_TKV3d} ${CAS_TKTopAlgo} ${CAS_TKBrep} ${CAS_TKBO} +target_link_libraries(HYDROGUI HYDROData HYDROCurveCreator + ${CAS_TKV3d} ${CAS_TKTopAlgo} ${CAS_TKBrep} ${CAS_TKBO} ${CAS_TKService} ${LightApp} ${CAM} ${suit} ${qtx} ${ObjBrowser} ${GraphicsView} ${std} ${Event} ${OCCViewer} - ${CurveCreator} ) set(PROJECT_LIBRARIES HYDROGUI) diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.cxx b/src/HYDROGUI/HYDROGUI_AISCurve.cxx index 16364e6f..87a2d7d5 100755 --- a/src/HYDROGUI/HYDROGUI_AISCurve.cxx +++ b/src/HYDROGUI/HYDROGUI_AISCurve.cxx @@ -2,6 +2,7 @@ #include +#include #include #include @@ -69,7 +70,7 @@ void HYDROGUI_AISCurveSection::Erase() void HYDROGUI_AISCurveSection::buildSection() { - CurveCreator::Type aSectType = myCurve->getType( mySection ); + CurveCreator::SectionType aSectType = myCurve->getSectionType( mySection ); int aSectSize = myCurve->getNbPoints( mySection ); bool aSectIsClosed = myCurve->isClosed( mySection ); @@ -91,7 +92,7 @@ void HYDROGUI_AISCurveSection::buildSection() } } } - else if( aSectType == CurveCreator::BSpline ) + else if( aSectType == CurveCreator::Spline ) { QList aPoints; for( int i = 0; i < aSectSize; i++ ) @@ -155,7 +156,7 @@ Handle_AIS_Line HYDROGUI_AISCurveSection::getAISLine( int theIndx1, int theIndx2 void HYDROGUI_AISCurveSection::getPoint( int theIndx, double& theX, double& theY, double& theZ ) { CurveCreator::Dimension aDim = myCurve->getDimension(); - CurveCreator::Coordinates aCoords = myCurve->getCoordinates( mySection, theIndx ); + const CurveCreator::Coordinates aCoords = myCurve->getPoint( mySection, theIndx ); theX = aCoords[0]; theY = aCoords[1]; theZ = 0.; @@ -212,6 +213,11 @@ void HYDROGUI_AISCurve::buildCurve() } } +void HYDROGUI_AISCurve::pointChanged( int theSection, int thePoint ) +{ + buildCurve(); +} + void HYDROGUI_AISCurve::pointInserted( int theSection, int theIndx ) { buildCurve(); diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.h b/src/HYDROGUI/HYDROGUI_AISCurve.h index f1fca75a..325aa19f 100755 --- a/src/HYDROGUI/HYDROGUI_AISCurve.h +++ b/src/HYDROGUI/HYDROGUI_AISCurve.h @@ -58,6 +58,7 @@ public: void Display(); void Erase(); + virtual void pointChanged( int theSection, int thePoint ); virtual void pointInserted( int theSection, int theIndx ); void highlightSection( int theSection, bool isHL ); diff --git a/src/HYDROGUI/HYDROGUI_OCCSelector.cxx b/src/HYDROGUI/HYDROGUI_OCCSelector.cxx index 3abc6754..a3582ed2 100644 --- a/src/HYDROGUI/HYDROGUI_OCCSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCSelector.cxx @@ -49,12 +49,16 @@ void HYDROGUI_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const if ( !aViewer ) return; + Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext(); + bool isLocalContext = aContext->HasOpenedContext(); + AIS_ListOfInteractive aSelList; aViewer->getSelectedObjects( aSelList ); for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() ) if ( !anIt.Value().IsNull() ) { - aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) ); + if ( !isLocalContext ) + aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) ); } // add externally selected objects SUIT_DataOwnerPtrList::const_iterator anExtIter; @@ -63,6 +67,20 @@ void HYDROGUI_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const } } +void HYDROGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList ) +{ + OCCViewer_Viewer* aViewer = viewer(); + if ( !aViewer ) + return; + + Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext(); + if ( aContext->HasOpenedContext() ) { + return; + } + + LightApp_OCCSelector::setSelection( aList ); +} + QString HYDROGUI_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const { QString aRes; diff --git a/src/HYDROGUI/HYDROGUI_OCCSelector.h b/src/HYDROGUI/HYDROGUI_OCCSelector.h index b427fd34..ddecc093 100644 --- a/src/HYDROGUI/HYDROGUI_OCCSelector.h +++ b/src/HYDROGUI/HYDROGUI_OCCSelector.h @@ -41,6 +41,7 @@ public: protected: virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); virtual QString entry( const Handle_AIS_InteractiveObject& ) const; diff --git a/src/HYDROGUI/HYDROGUI_PolylineDlg.cxx b/src/HYDROGUI/HYDROGUI_PolylineDlg.cxx index 52087532..e68a8f67 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineDlg.cxx @@ -43,7 +43,6 @@ HYDROGUI_PolylineDlg::HYDROGUI_PolylineDlg( HYDROGUI_Module* theModule, const QS addLayout(aNameLayout); myEditorWidget = new CurveCreator_Widget( this, NULL ); - myEditorWidget->setInstantSketchingEnabled( true ); addWidget( myEditorWidget, 3 ); myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this ); diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index 33986c67..dbf830ba 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -23,15 +23,13 @@ #include "HYDROGUI_PolylineOp.h" #include "HYDROGUI_PolylineDlg.h" #include "HYDROGUI_Tool.h" -#include "CurveCreator.hxx" -#include "CurveCreator_Curve.hxx" -#include "CurveCreator_CurveEditor.hxx" #include "HYDROGUI_AISCurve.h" +#include "HYDROGUI_UpdateFlags.h" #include #include + #include -#include #include #include @@ -83,27 +81,25 @@ void HYDROGUI_PolylineOp::startOperation() myCurve = new CurveCreator_Curve(aDim); QList aPolylineData = myEditedObject->GetPolylineData(); - CurveCreator_CurveEditor* anEdit = new CurveCreator_CurveEditor(myCurve); for( int i = 0 ; i < aPolylineData.size() ; i++ ){ std::string aName = HYDROGUI_Tool::ToQString(aPolylineData[i].mySectionName).toStdString(); bool isClosed = aPolylineData[i].myIsClosed; - CurveCreator::Type aType = CurveCreator::Polyline; + CurveCreator::SectionType aType = CurveCreator::Polyline; if( aPolylineData[i].myType == PolylineSection::SECTION_SPLINE ){ - aType = CurveCreator::BSpline; + aType = CurveCreator::Spline; } CurveCreator::Coordinates aCoords; for( int j = 0 ; j < aPolylineData[i].myCoords.size() ; j++ ){ aCoords.push_back(aPolylineData[i].myCoords[j]); } - anEdit->addSection( aName, aType, isClosed, aCoords ); + myCurve->addSection( aName, aType, isClosed, aCoords ); } - delete anEdit; aPanel->setPolylineName( myEditedObject->GetName() ); } else{ myCurve = new CurveCreator_Curve(CurveCreator::Dim2d); - aPanel->setCurve(myCurve); + //aPanel->setCurve(myCurve); QString aNewName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_POLYLINE_NAME" ) ); aPanel->setPolylineName(aNewName); } @@ -173,7 +169,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str())); aSect.myIsClosed = myCurve->isClosed(i); aSect.myType = PolylineSection::SECTION_POLYLINE; - if( myCurve->getType(i) == CurveCreator::BSpline ){ + if( myCurve->getSectionType(i) == CurveCreator::Spline ){ aSect.myType = PolylineSection::SECTION_SPLINE; } CurveCreator::Coordinates aCoords = myCurve->getPoints(i); @@ -184,7 +180,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, } aPolylineObj->SetPolylineData(aPolylineData); - theUpdateFlags = UF_Model; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true ); return true; }