From: skv Date: Mon, 5 Aug 2013 09:52:04 +0000 (+0000) Subject: CurveCreator implementation X-Git-Tag: BR_hydro_v_0_1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=999aec24a6d0285fc01c268d054185f9077303d6;p=modules%2Fgeom.git CurveCreator implementation --- diff --git a/adm_local/unix/config_files/Makefile.am b/adm_local/unix/config_files/Makefile.am index 2d5efa587..0ee0c3488 100644 --- a/adm_local/unix/config_files/Makefile.am +++ b/adm_local/unix/config_files/Makefile.am @@ -22,4 +22,5 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am dist_admlocalm4_DATA = \ check_GEOM.m4 \ check_GUI.m4 \ -check_OpenCV.m4 +check_OpenCV.m4 \ +check_CurveCreator.m4 diff --git a/adm_local/unix/config_files/check_CurveCreator.m4 b/adm_local/unix/config_files/check_CurveCreator.m4 new file mode 100755 index 000000000..3ca9ce5ed --- /dev/null +++ b/adm_local/unix/config_files/check_CurveCreator.m4 @@ -0,0 +1,27 @@ +dnl Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +dnl +dnl See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +dnl + +dnl File : check_CurveCreator.m4 +dnl Author : Sergey KHROMOV +dnl +AC_DEFUN([USE_CURVECREATOR],[ + +CPPFLAGS="-DUSE_CURVE_CREATOR $CPPFLAGS" + +])dnl diff --git a/configure.ac b/configure.ac index bb1e8d656..48b27885c 100644 --- a/configure.ac +++ b/configure.ac @@ -439,6 +439,10 @@ else AC_SUBST(SETX) SETX="set -x" fi +if test "${SalomeGUI_need}" != "no"; then + USE_CURVECREATOR +fi + echo echo --------------------------------------------- echo generating Makefiles and configure files @@ -516,6 +520,7 @@ AC_OUTPUT([ \ src/GEOM_SWIG_WITHIHM/Makefile \ src/GEOM_PY/Makefile \ src/GEOM_PY/structelem/Makefile \ + src/CurveCreator/Makefile \ src/GenerationGUI/Makefile \ src/GroupGUI/Makefile \ src/IGESExport/Makefile \ diff --git a/src/CurveCreator/CurveCreator.hxx b/src/CurveCreator/CurveCreator.hxx new file mode 100644 index 000000000..3fca76886 --- /dev/null +++ b/src/CurveCreator/CurveCreator.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Tue Jun 25 16:34:39 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_HeaderFile +#define _CurveCreator_HeaderFile + + +#include + + +namespace CurveCreator +{ + + //! Dimension of the curve + enum Dimension + { + Dim2d = 2, + Dim3d = 3 + }; + + //! Type of the section + enum Type + { + Polyline, + BSpline + }; + + //! Points coordinates + typedef float TypeCoord; + + typedef std::deque Coordinates; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Curve.cxx b/src/CurveCreator/CurveCreator_Curve.cxx new file mode 100644 index 000000000..64ec55c58 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Curve.cxx @@ -0,0 +1,378 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Thu Jun 20 9:54:07 2013 +// Author: Sergey KHROMOV +// + + +#include +#include + + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_Curve::CurveCreator_Curve + (const CurveCreator::Dimension theDimension) +: myIsLocked (false), + myDimension (theDimension) +{ +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_Curve::~CurveCreator_Curve() +{ + // Delete all allocated data. + clear(); +} + +//======================================================================= +// function: isLocked +// purpose: +//======================================================================= +bool CurveCreator_Curve::isLocked() const +{ + return myIsLocked; +} + +//======================================================================= +// function: getDimension +// purpose: +//======================================================================= +CurveCreator::Dimension CurveCreator_Curve::getDimension() const +{ + return myDimension; +} + +//======================================================================= +// function: getNbPoints +// purpose: +//======================================================================= +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; +} + +//======================================================================= +// function: getNbSections +// purpose: +//======================================================================= +int CurveCreator_Curve::getNbSections() const +{ + return mySections.size(); +} + +//======================================================================= +// function: getCoordinates +// purpose: +//======================================================================= +CurveCreator::Coordinates CurveCreator_Curve::getCoordinates + (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: getType +// purpose: +//======================================================================= +CurveCreator::Type CurveCreator_Curve::getType(const int theISection) const +{ + return mySections.at(theISection)->myType; +} + +//======================================================================= +// function: getPoints +// purpose: +//======================================================================= +const CurveCreator::Coordinates &CurveCreator_Curve::getPoints + (const int theISection) const +{ + return mySections.at(theISection)->myPoints; +} + +//======================================================================= +// function: isClosed +// purpose: +//======================================================================= +bool CurveCreator_Curve::isClosed(const int theISection) const +{ + return mySections.at(theISection)->myIsClosed; +} + +//======================================================================= +// function: setType +// purpose: +//======================================================================= +void CurveCreator_Curve::setType + (const CurveCreator::Type theType, const int theISection) +{ + if (theISection == -1) { + int i = 0; + const int aNbSections = getNbSections(); + + for (; i < aNbSections; i++) { + mySections[i]->myType = theType; + } + } else { + mySections.at(theISection)->myType = theType; + } +} + +//======================================================================= +// function: addPoints +// purpose: +//======================================================================= +void CurveCreator_Curve::addPoints + (const CurveCreator::Coordinates &thePoints, const int theISection) +{ + CurveCreator_Section *aSection = + (theISection == -1 ? mySections.back() : mySections.at(theISection)); + + aSection->myPoints.insert(aSection->myPoints.end(), + thePoints.begin(), thePoints.end()); +} + +//======================================================================= +// function: addSection +// purpose: +//======================================================================= +void CurveCreator_Curve::addSection + (const CurveCreator::Type theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints) +{ + CurveCreator_Section *aSection = new CurveCreator_Section; + + aSection->myType = theType; + aSection->myIsClosed = theIsClosed; + aSection->myPoints = thePoints; + mySections.push_back(aSection); +} + +//======================================================================= +// function: removeSection +// purpose: +//======================================================================= +void CurveCreator_Curve::removeSection(const int theISection) +{ + if (theISection == -1) { + delete mySections.back(); + mySections.pop_back(); + } else { + Sections::iterator anIterRm = mySections.begin() + theISection; + + delete *anIterRm; + mySections.erase(anIterRm); + } +} + +//======================================================================= +// function: insertPoints +// purpose: +//======================================================================= +void CurveCreator_Curve::insertPoints + (const CurveCreator::Coordinates &thePoints, + const int theISection, + const int theIPnt) +{ + if (theIPnt == -1) { + // Add points to the end of section points. + addPoints(thePoints, theISection); + } else { + CurveCreator_Section *aSection = + (theISection == -1 ? mySections.back() : mySections.at(theISection)); + + aSection->myPoints.insert(aSection->myPoints.begin() + toICoord(theIPnt), + thePoints.begin(), thePoints.end()); + } +} + +//======================================================================= +// function: removePoints +// purpose: +//======================================================================= +void CurveCreator_Curve::removePoints(const int theISection, + const int theIPnt, + const int theNbPoints) +{ + CurveCreator_Section *aSection = mySections.at(theISection); + CurveCreator::Coordinates::iterator anIterBegin = + aSection->myPoints.begin() + toICoord(theIPnt); + CurveCreator::Coordinates::iterator anIterEnd = + (theNbPoints == -1 ? + aSection->myPoints.end() : anIterBegin + toICoord(theNbPoints)); + + aSection->myPoints.erase(anIterBegin, anIterEnd); +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_Curve::clear() +{ + // Delete all allocated data. + int i = 0; + const int aNbSections = getNbSections(); + + for (; i < aNbSections; i++) { + delete mySections[i]; + } + + mySections.clear(); +} + +//======================================================================= +// function: setCoordinates +// purpose: +//======================================================================= +void CurveCreator_Curve::setCoordinates + (const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt) +{ + if (theCoords.size() == myDimension) { + CurveCreator_Section *aSection = mySections.at(theISection); + int i; + + for (i = 0; i < myDimension; i++) { + aSection->myPoints.at(toICoord(theIPnt) + i) = theCoords[i]; + } + } +} + +//======================================================================= +// function: setClosed +// purpose: +//======================================================================= +void CurveCreator_Curve::setClosed(const bool theIsClosed, + const int theISection) +{ + if (theISection == -1) { + int aSize = mySections.size(); + int i; + + for (i = 0; i < aSize; i++) { + mySections[i]->myIsClosed = theIsClosed; + } + } else { + mySections.at(theISection)->myIsClosed = theIsClosed; + } +} + +//======================================================================= +// function: moveSection +// purpose: +//======================================================================= +void CurveCreator_Curve::moveSection(const int theISection, + const int theNewIndex) +{ + if (theISection != theNewIndex) { + CurveCreator_Section *aSection = mySections.at(theISection); + + // Remove section + Sections::iterator anIter = mySections.begin() + theISection; + + mySections.erase(anIter); + + // Insert section. + anIter = mySections.begin() + theNewIndex; + mySections.insert(anIter, aSection); + } +} + +//======================================================================= +// function: join +// purpose: +//======================================================================= +void CurveCreator_Curve::join(const int theISectionTo, + const int theISectionFrom) +{ + if (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); + } +} + +//======================================================================= +// function: join +// purpose: +//======================================================================= +void CurveCreator_Curve::join() +{ + const int aSize = mySections.size(); + + if (aSize > 1) { + CurveCreator_Section *aSection1 = mySections[0]; + int i; + + for (i = 1; i < aSize; i++) { + CurveCreator_Section *aSection2 = mySections[i]; + + aSection1->myPoints.insert(aSection1->myPoints.end(), + aSection2->myPoints.begin(), aSection2->myPoints.end()); + delete aSection2; + } + + // Just erace section pointers as they were deleted before. + mySections.erase(mySections.begin() + 1, mySections.end()); + } +} + +//======================================================================= +// function: toICoord +// purpose: +//======================================================================= +int CurveCreator_Curve::toICoord(const int theIPnt) const +{ + return theIPnt*myDimension; +} diff --git a/src/CurveCreator/CurveCreator_Curve.hxx b/src/CurveCreator/CurveCreator_Curve.hxx new file mode 100644 index 000000000..0eb80e7f5 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Curve.hxx @@ -0,0 +1,167 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Thu Jun 20 9:54:14 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_Curve_HeaderFile +#define _CurveCreator_Curve_HeaderFile + + +#include +#include +#include + +class CurveCreator_Section; + + +/** + * 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 +{ + + //! List of curves + typedef std::deque Sections; + +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. + ~CurveCreator_Curve(); + + //! Returns true if this curve is locked by a curve editor. + bool isLocked() const; + + //! Get the dimension. + CurveCreator::Dimension getDimension() const; + + //! Get number of sections. + int getNbSections() const; + + /** Get number of points in specified section or (the total number of points + * in Curve if theISection is equal to -1). + */ + int getNbPoints(const int theISection = -1) const; + + //! Get coordinates of specified point + CurveCreator::Coordinates getCoordinates + (const int theISection, const int theIPnt) const; + + //! Get points of a section. + const CurveCreator::Coordinates &getPoints(const int theISection) const; + + //! Get type of the specified section + CurveCreator::Type getType(const int theISection) const; + + //! Get “closed” flag of the specified section + bool isClosed(const int theISection) const; + +protected: + + /** Set type of the specified section (or all sections + * if \a theISection is -1). + */ + void setType(const CurveCreator::Type theType, const int theISection = -1); + + /** Add points to the specified section (or last section + * if \a theISection is -1). + */ + void addPoints + (const CurveCreator::Coordinates &thePoints, const int theISection = -1); + + //! Add a new section. + void addSection (const CurveCreator::Type theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints); + + //! Removes the section. If theISection equals -1, removes the last section. + void removeSection(const int theISection = -1); + + /** Insert points in the given position (add to the end of list + * if \a theIPnt parameter is -1) of the specified section + * (or last section if \a theISection parameter is -1). + */ + void insertPoints(const CurveCreator::Coordinates &thePoints, + const int theISection = -1, + const int theIPnt = -1); + + /** Remove \a nbPoints points from given \a theISection, + * starting from given \a theIPnt (of all points up to the end of + * section if \a theNbPoints is -1). + */ + void removePoints(const int theISection, + const int theIPnt, + const int theNbPoints = -1); + + //! Remove all sections. + void clear(); + + //! Set coordinates of specified point + void setCoordinates(const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt); + + /** Set “closed” flag of the specified section (all sections if + * \a theISection is -1). + */ + void setClosed(const bool theIsClosed, const int theISection = -1); + + /** Move specified \a theISection to the specified position + * in the sections list. + */ + void moveSection(const int theISection, const int theNewIndex); + + //! Join two sections to one section + void join(const int theISectionTo, const int theISectionFrom); + + //! Join all sections to the single curve + void join(); + + /** + * This method converts the point index to the index in + * an array of coordinates. + */ + int toICoord(const int theIPnt) const; + +protected: + + bool myIsLocked; + Sections mySections; //!< curve data + CurveCreator::Dimension myDimension; //!< curve dimension + + friend class CurveCreator_CurveEditor; + friend class CurveCreator_Operation; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_CurveEditor.cxx b/src/CurveCreator/CurveCreator_CurveEditor.cxx new file mode 100644 index 000000000..a9d7ee378 --- /dev/null +++ b/src/CurveCreator/CurveCreator_CurveEditor.cxx @@ -0,0 +1,450 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_CurveEditor.cxx +// Created: Mon Jun 24 14:33:50 2013 +// Author: Sergey KHROMOV +// + +#include + + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_CurveEditor::CurveCreator_CurveEditor + (CurveCreator_Curve* thePCurve) + : myNbUndos (0), + myNbRedos (0), + myPCurve (thePCurve), + myUndoDepth (-1) +{ + if (myPCurve != NULL) { + if (myPCurve->isLocked()) { + // This curve is locked by another editor. Invalid case. + myPCurve = NULL; + } else { + // Lock the curve. + myPCurve->myIsLocked = true; + myCurrenPos = myListDiffs.end(); + } + } +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_CurveEditor::~CurveCreator_CurveEditor() +{ + if (myPCurve != NULL) { + // Unlock the curve. + myPCurve->myIsLocked = false; + } +} + +//======================================================================= +// function: getCurve +// purpose: +//======================================================================= +CurveCreator_Curve *CurveCreator_CurveEditor::getCurve() const +{ + return myPCurve; +} + +//======================================================================= +// function: isAttached +// purpose: +//======================================================================= +bool CurveCreator_CurveEditor::isAttached() const +{ + return (myPCurve != NULL); +} + +//======================================================================= +// function: undo +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::undo() +{ + if (myNbUndos > 0) { + myNbUndos--; + myNbRedos++; + myCurrenPos--; + myCurrenPos->applyUndo(myPCurve); + } +} + +//======================================================================= +// function: redo +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::redo() +{ + if (myNbRedos > 0) { + myCurrenPos->applyRedo(myPCurve); + myCurrenPos++; + myNbRedos--; + myNbUndos++; + } +} + +//======================================================================= +// function: getNbUndo +// purpose: +//======================================================================= +int CurveCreator_CurveEditor::getNbUndo() const +{ + return myNbUndos; +} + +//======================================================================= +// function: getNbRedo +// purpose: +//======================================================================= +int CurveCreator_CurveEditor::getNbRedo() const +{ + return myNbRedos; +} + +//======================================================================= +// function: setUndoDepth +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::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_CurveEditor::getUndoDepth() const +{ + return myUndoDepth; +} + +//======================================================================= +// function: setType +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::setType(const CurveCreator::Type theType, + const int theISection) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetType, + theType, theISection); + } + + // Update the curve. + myPCurve->setType(theType, theISection); + } +} + +//======================================================================= +// function: addPoints +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::addPoints + (const CurveCreator::Coordinates &thePoints, + const int theISection) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::AddPoints, + thePoints, theISection); + } + + // Update the curve. + myPCurve->addPoints(thePoints, theISection); + } +} + +//======================================================================= +// function: addSection +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::addSection + (const CurveCreator::Type theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::AddSection, + thePoints, theType, theIsClosed); + } + + // Update the curve. + myPCurve->addSection(theType, theIsClosed, thePoints); + } +} + +//======================================================================= +// function: removeSection +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::removeSection(const int theISection) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::RemoveSection, + theISection); + } + + // Update the curve. + myPCurve->removeSection(theISection); + } +} + +//======================================================================= +// function: insertPoints +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::insertPoints + (const CurveCreator::Coordinates &thePoints, + const int theISection, + const int theIPnt) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::InsertPoints, + thePoints, theISection, theIPnt); + } + + // Update the curve. + myPCurve->insertPoints(thePoints, theISection, theIPnt); + } +} + +//======================================================================= +// function: removePoints +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::removePoints + (const int theISection, + const int theIPnt, + const int theNbPoints) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::RemovePoints, + theISection, theIPnt, theNbPoints); + } + + // Update the curve. + myPCurve->removePoints(theISection, theIPnt, theNbPoints); + } +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::clear() +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::Clear); + } + + // Update the curve. + myPCurve->clear(); + } +} + +//======================================================================= +// function: setCoordinates +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::setCoordinates + (const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetCoordinates, + theCoords, theISection, theIPnt); + } + + // Update the curve. + myPCurve->setCoordinates(theCoords, theISection, theIPnt); + } +} + +//======================================================================= +// function: setClosed +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::setClosed(const bool theIsClosed, + const int theISection) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetClosed, + theIsClosed, theISection); + } + + // Update the curve. + myPCurve->setClosed(theIsClosed, theISection); + } +} + +//======================================================================= +// function: moveSection +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::moveSection(const int theISection, + const int theNewIndex) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::MoveSection, + theISection, theNewIndex); + } + + // Update the curve. + myPCurve->moveSection(theISection, theNewIndex); + } +} + +//======================================================================= +// function: join +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::join(const int theISectionTo, + const int theISectionFrom) +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::Join, + theISectionTo, theISectionFrom); + } + + // Update the curve. + myPCurve->join(theISectionTo, theISectionFrom); + } +} + +//======================================================================= +// function: join +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::join() +{ + if (myPCurve != NULL) { + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::Join); + } + + // Update the curve. + myPCurve->join(); + } +} + +//======================================================================= +// function: addDiff +// purpose: +//======================================================================= +bool CurveCreator_CurveEditor::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; +} diff --git a/src/CurveCreator/CurveCreator_CurveEditor.hxx b/src/CurveCreator/CurveCreator_CurveEditor.hxx new file mode 100644 index 000000000..bb9bbf7f6 --- /dev/null +++ b/src/CurveCreator/CurveCreator_CurveEditor.hxx @@ -0,0 +1,157 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_CurveEditor.hxx +// Created: Mon Jun 24 14:33:40 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_CurveEditor_HeaderFile +#define _CurveCreator_CurveEditor_HeaderFile + +#include +#include +#include + +/** + * The CurveCreator_CurveEditor is designed to manage of + * editing operations of CurveCreator_Curve class. + */ +class CURVECREATOR_EXPORT CurveCreator_CurveEditor +{ + +private: + + typedef std::list ListDiff; + +public: + + //! Constuctor, initialized by the curve object + CurveCreator_CurveEditor(CurveCreator_Curve* thePCurve); + + //! Destructor, detaches from the Curve + ~CurveCreator_CurveEditor(); + + //! Returns the curve. + CurveCreator_Curve *getCurve() const; + + //! This method returns true if this editor is attached to a valid curve. + bool isAttached() const; + + //! Undo previous operation + void undo(); + + //! Redo last previously “undoed” operation + void redo(); + + //! Get number of available undo operations + int getNbUndo() const; + + //! Get number of available redo operations + int getNbRedo() const; + + //! Set depth of undo operations (unlimited if \a theDepth is -1 + // or disabled if \a theDepth is 0) + void setUndoDepth(const int theDepth = -1); + + //! Get depth of undo operations. + int getUndoDepth() const; + + /** Set type of the specified section (or all sections + * if \a theISection is -1). + */ + void setType(const CurveCreator::Type theType, const int theISection = -1); + + /** Add points to the specified section (or last section + * if \a theISection is -1). + */ + void addPoints(const CurveCreator::Coordinates &thePoints, + const int theISection = -1); + + //! Add a new section. + void addSection(const CurveCreator::Type theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints); + + //! Removes the section. If theISection equals -1, removes the last section. + void removeSection(const int theISection = -1); + + /** Insert points in the given position (add to the end of list + * if \a theIPnt parameter is -1) of the specified section + * (or last section if \a theISection parameter is -1). + */ + void insertPoints(const CurveCreator::Coordinates &thePoints, + const int theISection = -1, + const int theIPnt = -1); + + /** Remove \a nbPoints points from given \a theISection, + * starting from given \a theIPnt (of all points up to the end of + * section if \a theNbPoints is -1). + */ + void removePoints(const int theISection, + const int theIPnt, + const int theNbPoints = -1); + + //! Remove all sections. + void clear(); + + //! Set coordinates of specified point + void setCoordinates(const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt); + + /** Set “closed” flag of the specified section (all sections if + * \a theISection is -1). + */ + void setClosed(const bool theIsClosed, const int theISection = -1); + + /** Move specified \a theISection to the specified position + * in the sections list. + */ + void moveSection(const int theISection, const int theNewIndex); + + //! Join two sections to one section + void join(const int theISectionTo, const int theISectionFrom); + + //! Join all sections to the single curve + void join(); + +private: + + /** 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. + */ + bool addEmptyDiff(); + +private: + + int myNbUndos; + int myNbRedos; + ListDiff::iterator myCurrenPos; + ListDiff myListDiffs; + CurveCreator_Curve* myPCurve; + int myUndoDepth; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Diff.cxx b/src/CurveCreator/CurveCreator_Diff.cxx new file mode 100644 index 000000000..c5ec02586 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Diff.cxx @@ -0,0 +1,540 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Wed Jun 26 10:58:46 2013 +// Author: Sergey KHROMOV +// + + +#include +#include +#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 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::AddSection: + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RemoveSection, -1); + break; + 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->getCoordinates(theIntParam1, theIntParam2); + + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates, + anOldCoords, theIntParam1, theIntParam2); + } + break; + default: + 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::Type aType = theCurve->getType(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->getType(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->getType(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->getType(*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/CurveCreator/CurveCreator_Diff.hxx b/src/CurveCreator/CurveCreator_Diff.hxx new file mode 100644 index 000000000..5255a43c0 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Diff.hxx @@ -0,0 +1,197 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Wed Jun 26 10:58:46 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_Diff_HeaderFile +#define _CurveCreator_Diff_HeaderFile + + +#include + +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: + *
    + *
  • AddSection
  • + *
  • 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 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/CurveCreator/CurveCreator_EditPntDlg.cxx b/src/CurveCreator/CurveCreator_EditPntDlg.cxx new file mode 100644 index 000000000..ba7f9fb93 --- /dev/null +++ b/src/CurveCreator/CurveCreator_EditPntDlg.cxx @@ -0,0 +1,218 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_EditPntDlg.cxx +// Created: Tue Jul 16 10:58:31 2013 +// Author: Sergey KHROMOV +// + + +#include +#include +#include +#include +#include +#include +#include +#include + + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_EditPntDlg::CurveCreator_EditPntDlg + (QWidget* parent, + const CurveCreator::Dimension theDimension) + : QDialog (parent), + myDimension (theDimension), + myXSpn (NULL), + myYSpn (NULL), + myZSpn (NULL), + myOkBtn (NULL), + myCancelBtn (NULL) +{ + setWindowTitle(tr("CC_EDIT_POINT_TITLE")); + + // Set Add/modify point group + QGroupBox *aModifPntGrp = + new QGroupBox(tr("CC_EDIT_POINT_MODIFY")); + QGridLayout *aModifPntLO = new QGridLayout(aModifPntGrp); + QLabel *aXLbl = + new QLabel(tr("CC_EDIT_POINT_X"), aModifPntGrp); + QLabel *aYLbl = + new QLabel(tr("CC_EDIT_POINT_Y"), aModifPntGrp); + + aXLbl->setAlignment(Qt::AlignRight); + aYLbl->setAlignment(Qt::AlignRight); + myXSpn = new QDoubleSpinBox(aModifPntGrp); + myYSpn = new QDoubleSpinBox(aModifPntGrp); + aModifPntLO->setMargin(9); + aModifPntLO->setSpacing(6); + aModifPntLO->addWidget(aXLbl, 0, 0); + aModifPntLO->addWidget(aYLbl, 1, 0); + aModifPntLO->addWidget(myXSpn, 0, 1); + aModifPntLO->addWidget(myYSpn, 1, 1); + + if (myDimension == CurveCreator::Dim3d) { + QLabel *aZLbl = new QLabel(tr("CC_EDIT_POINT_Z"), aModifPntGrp); + + aZLbl->setAlignment(Qt::AlignRight); + myZSpn = new QDoubleSpinBox(aModifPntGrp); + aModifPntLO->addWidget(aZLbl, 2, 0); + aModifPntLO->addWidget(myZSpn, 2, 1); + } + + // Set OK/Cancel buttons group + QGroupBox *anOkCancelGrp = new QGroupBox; + QGridLayout *anOkCancelLO = new QGridLayout(anOkCancelGrp); + + myOkBtn = new QPushButton(tr("GEOM_BUT_OK"), anOkCancelGrp); + myCancelBtn = new QPushButton(tr("GEOM_BUT_CANCEL"), anOkCancelGrp); + anOkCancelLO->setMargin(9); + anOkCancelLO->setSpacing(6); + anOkCancelLO->addWidget(myOkBtn, 0, 0); + anOkCancelLO->addWidget(myCancelBtn, 0, 1); + + // Set main group + QGroupBox *aMainGrp = new QGroupBox; + QVBoxLayout *aMainLO = new QVBoxLayout(aMainGrp); + + aMainLO->addWidget(aModifPntGrp); + aMainLO->addWidget(anOkCancelGrp); + + setLayout(aMainLO); + + init(); +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_EditPntDlg::~CurveCreator_EditPntDlg() +{ +} + +//======================================================================= +// function: setPoint +// purpose: +//======================================================================= +void CurveCreator_EditPntDlg::setPoint + (const CurveCreator::Coordinates &thePoint) +{ + myPoint = thePoint; + + if (myPoint.size() == myDimension) { + myXSpn->setValue(myPoint[0]); + myYSpn->setValue(myPoint[1]); + + if (myDimension == CurveCreator::Dim3d) { + myZSpn->setValue(myPoint[2]); + } + } +} + +//======================================================================= +// function: getPoint +// purpose: +//======================================================================= +const CurveCreator::Coordinates &CurveCreator_EditPntDlg::getPoint() const +{ + return myPoint; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +void CurveCreator_EditPntDlg::init() +{ + // Init spin boxes. + initSpinBox(myXSpn); + initSpinBox(myYSpn); + + if (myDimension == CurveCreator::Dim3d) { + initSpinBox(myZSpn); + } + + // Init buttons. + myOkBtn->setDefault(true); + + connect(myOkBtn, SIGNAL(clicked()), this, SLOT(accept())); + connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject())); + + setTabOrder(); +} + +//======================================================================= +// function: initSpinBox +// purpose: +//======================================================================= +void CurveCreator_EditPntDlg::initSpinBox(QDoubleSpinBox *theSpinBox) +{ + const double aCoordMin = -1.e+15; + const double aCoordMax = 1.e+15; + const double aStep = 10; + const int aPrecision = 6; + + theSpinBox->setDecimals( qAbs( aPrecision ) ); + theSpinBox->setRange(aCoordMin, aCoordMax); + theSpinBox->setSingleStep(aStep); + theSpinBox->setValue(0.); +} + +//======================================================================= +// function: setTabOrder +// purpose: +//======================================================================= +void CurveCreator_EditPntDlg::setTabOrder() +{ + QWidget::setTabOrder(myXSpn, myYSpn); + + if (myDimension == CurveCreator::Dim3d) { + QWidget::setTabOrder(myYSpn, myZSpn); + QWidget::setTabOrder(myZSpn, myOkBtn); + } else { + QWidget::setTabOrder(myYSpn, myOkBtn); + } + + QWidget::setTabOrder(myOkBtn, myCancelBtn); +} + +//======================================================================= +// function: accept +// purpose: +//======================================================================= +void CurveCreator_EditPntDlg::accept() +{ + // Copy point + myPoint.clear(); + myPoint.push_back(myXSpn->value()); + myPoint.push_back(myYSpn->value()); + + if (myDimension == CurveCreator::Dim3d) { + myPoint.push_back(myZSpn->value()); + } + + QDialog::accept(); +} diff --git a/src/CurveCreator/CurveCreator_EditPntDlg.h b/src/CurveCreator/CurveCreator_EditPntDlg.h new file mode 100644 index 000000000..4dbd397d6 --- /dev/null +++ b/src/CurveCreator/CurveCreator_EditPntDlg.h @@ -0,0 +1,79 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_EditPntDlg.h +// Created: Tue Jul 16 10:58:22 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_EditPntDlg_HeaderFile +#define _CurveCreator_EditPntDlg_HeaderFile + + +#include +#include + +class QListWidget; +class QDoubleSpinBox; +class QPushButton; + + +class CurveCreator_EditPntDlg : public QDialog +{ + Q_OBJECT + +public: + + CurveCreator_EditPntDlg(QWidget* parent, + const CurveCreator::Dimension theDimension); + + ~CurveCreator_EditPntDlg(); + + void setPoint(const CurveCreator::Coordinates &thePoint); + + const CurveCreator::Coordinates &getPoint() const; + +private: + + void init(); + + void initSpinBox(QDoubleSpinBox *theSpinBox); + + void setTabOrder(); + +private slots: + + void accept(); + +protected: + + CurveCreator::Dimension myDimension; + CurveCreator::Coordinates myPoint; + QDoubleSpinBox *myXSpn; + QDoubleSpinBox *myYSpn; + QDoubleSpinBox *myZSpn; + QPushButton *myOkBtn; + QPushButton *myCancelBtn; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_EditPntsDlg.cxx b/src/CurveCreator/CurveCreator_EditPntsDlg.cxx new file mode 100644 index 000000000..124eb8c05 --- /dev/null +++ b/src/CurveCreator/CurveCreator_EditPntsDlg.cxx @@ -0,0 +1,540 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_EditPntsDlg.cxx +// Created: Fri Jul 05 16:29:53 2013 +// Author: Sergey KHROMOV +// + + +#include +#include +#include +#include +#include +#include +#include +#include + + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_EditPntsDlg::CurveCreator_EditPntsDlg + (QWidget* parent, const CurveCreator::Dimension theDimension) + : QDialog (parent), + myDimension (theDimension), + myPntsList (NULL), + myXSpn (NULL), + myYSpn (NULL), + myZSpn (NULL), + myAddBtn (NULL), + myModifBtn (NULL), + myRmBtn (NULL), + myClearBtn (NULL), + myPntUpBtn (NULL), + myPntDownBtn (NULL), + myOkBtn (NULL), + myCancelBtn (NULL) +{ + setWindowTitle(tr("CC_EDIT_POINTS_TITLE")); + + // Set Add/modify point group + QGroupBox *aModifPntGrp = + new QGroupBox(tr("CC_EDIT_POINTS_ADD_MODIFY")); + QGridLayout *aModifPntLO = new QGridLayout(aModifPntGrp); + QLabel *aXLbl = + new QLabel(tr("CC_EDIT_POINTS_X"), aModifPntGrp); + QLabel *aYLbl = + new QLabel(tr("CC_EDIT_POINTS_Y"), aModifPntGrp); + + aXLbl->setAlignment(Qt::AlignRight); + aYLbl->setAlignment(Qt::AlignRight); + myXSpn = new QDoubleSpinBox(aModifPntGrp); + myYSpn = new QDoubleSpinBox(aModifPntGrp); + myAddBtn = new QPushButton(tr("CC_EDIT_POINTS_ADD"), aModifPntGrp); + myModifBtn = new QPushButton(tr("CC_EDIT_POINTS_MODIFY"), aModifPntGrp); + myRmBtn = new QPushButton(tr("CC_EDIT_POINTS_REMOVE"), aModifPntGrp); + aModifPntLO->setMargin(9); + aModifPntLO->setSpacing(6); + aModifPntLO->addWidget(aXLbl, 0, 0); + aModifPntLO->addWidget(aYLbl, 1, 0); + aModifPntLO->addWidget(myXSpn, 0, 1); + aModifPntLO->addWidget(myYSpn, 1, 1); + aModifPntLO->addWidget(myAddBtn, 0, 2); + aModifPntLO->addWidget(myModifBtn, 1, 2); + aModifPntLO->addWidget(myRmBtn, 2, 2); + + if (myDimension == CurveCreator::Dim3d) { + QLabel *aZLbl = new QLabel(tr("CC_EDIT_POINTS_Z"), aModifPntGrp); + + aZLbl->setAlignment(Qt::AlignRight); + myZSpn = new QDoubleSpinBox(aModifPntGrp); + aModifPntLO->addWidget(aZLbl, 2, 0); + aModifPntLO->addWidget(myZSpn, 2, 1); + } + + // Set Buttons group + QGroupBox *aPntsGrp = new QGroupBox(); + QGridLayout *aPntsLO = new QGridLayout(aPntsGrp); + + myClearBtn = new QPushButton(tr("CC_EDIT_POINTS_CLEAR"), aModifPntGrp); + myPntUpBtn = new QPushButton(tr("CC_EDIT_POINTS_UP"), aPntsGrp); + myPntDownBtn = new QPushButton(tr("CC_EDIT_POINTS_DOWN"), aPntsGrp); + myPntsList = new QListWidget(aPntsGrp); + aPntsLO->setMargin(9); + aPntsLO->setSpacing(6); + aPntsLO->addWidget(myClearBtn, 0, 0); + aPntsLO->addWidget(myPntUpBtn, 2, 4); + aPntsLO->addWidget(myPntDownBtn, 3, 4); + aPntsLO->addWidget(myPntsList, 1, 0, 4, 4); + + // Set OK/Cancel buttons group + QGroupBox *anOkCancelGrp = new QGroupBox(); + QGridLayout *anOkCancelLO = new QGridLayout(anOkCancelGrp); + + myOkBtn = new QPushButton(tr("GEOM_BUT_OK"), anOkCancelGrp); + myCancelBtn = new QPushButton(tr("GEOM_BUT_CANCEL"), anOkCancelGrp); + anOkCancelLO->setMargin(9); + anOkCancelLO->setSpacing(6); + anOkCancelLO->addWidget(myOkBtn, 0, 3); + anOkCancelLO->addWidget(myCancelBtn, 0, 4); + + // Set main group + QGroupBox *aMainGrp = new QGroupBox; + QVBoxLayout *aMainLO = new QVBoxLayout(aMainGrp); + + aMainLO->addWidget(aModifPntGrp); + aMainLO->addWidget(aPntsGrp); + aMainLO->addWidget(anOkCancelGrp); + + setLayout(aMainLO); + + init(); +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_EditPntsDlg::~CurveCreator_EditPntsDlg() +{ +} + +//======================================================================= +// function: setPoints +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::setPoints + (const CurveCreator::Coordinates &thePoints) +{ + myPoints = thePoints; + updateEditList(); +} + +//======================================================================= +// function: getPoints +// purpose: +//======================================================================= +const CurveCreator::Coordinates &CurveCreator_EditPntsDlg::getPoints() const +{ + return myPoints; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::init() +{ + // Init spin boxes. + initSpinBox(myXSpn); + initSpinBox(myYSpn); + + if (myDimension == CurveCreator::Dim3d) { + initSpinBox(myZSpn); + } + + // Init buttons. + myModifBtn->setEnabled(false); + myRmBtn->setEnabled(false); + myClearBtn->setEnabled(false); + myPntUpBtn->setEnabled(false); + myPntDownBtn->setEnabled(false); + myOkBtn->setDefault(true); + + connect(myAddBtn, SIGNAL(clicked()), this, SLOT(appendPoint())); + connect(myModifBtn, SIGNAL(clicked()), this, SLOT(modifyPoint())); + connect(myRmBtn, SIGNAL(clicked()), this, SLOT(removePoint())); + connect(myClearBtn, SIGNAL(clicked()), this, SLOT(clear())); + connect(myPntUpBtn, SIGNAL(clicked()), this, SLOT(upPoint())); + connect(myPntDownBtn, SIGNAL(clicked()), this, SLOT(downPoint())); + connect(myOkBtn, SIGNAL(clicked()), this, SLOT(accept())); + connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject())); + + // Init list widget. + myPntsList->clear(); + myPntsList->setSelectionMode(QAbstractItemView::ExtendedSelection); + myPntsList->setDragEnabled(true); + myPntsList->setDragDropMode(QAbstractItemView::InternalMove); + myPntsList->viewport()->setAcceptDrops(true); + + connect(myPntsList, SIGNAL(itemSelectionChanged()), + this, SLOT(changeSelection())); + connect(this, SIGNAL(numberOfItemsChanged(int)), + this, SLOT(onNumberOfItemsChanged(int))); + + // Set tab order. + setTabOrder(); +} + +//======================================================================= +// function: initSpinBox +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::initSpinBox(QDoubleSpinBox *theSpinBox) +{ + const double aCoordMin = -1.e+15; + const double aCoordMax = 1.e+15; + const double aStep = 10; + const int aPrecision = 6; + + theSpinBox->setDecimals( qAbs( aPrecision ) ); + theSpinBox->setRange(aCoordMin, aCoordMax); + theSpinBox->setSingleStep(aStep); + theSpinBox->setValue(0.0); +} + +//======================================================================= +// function: updateEditList +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::updateEditList() +{ + myPntsList->clear(); + + const int aNbCoords = myPoints.size(); + + if (aNbCoords % myDimension == 0) { + int i = 0; + + while (i < aNbCoords) { + const CurveCreator::TypeCoord aX = myPoints[i++]; + const CurveCreator::TypeCoord aY = myPoints[i++]; + + if (myDimension == CurveCreator::Dim3d) { + const CurveCreator::TypeCoord aZ = myPoints[i++]; + + new CurveCreator_PointItem(aX, aY, aZ, myPntsList); + } else { + new CurveCreator_PointItem(aX, aY, myPntsList); + } + } + } + + emit numberOfItemsChanged(myPntsList->count()); +} + +//======================================================================= +// function: movePoints +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::movePoints(const int theShift) +{ + // Sort list items in ascending or descending order depending on + // the sign of theShift. + QList aListItems = myPntsList->selectedItems(); + + if (!aListItems.empty() && theShift != 0) { + QMap aMapItems; + + foreach(QListWidgetItem *anItem, aListItems) { + int aRow = myPntsList->row(anItem); + + if (theShift > 0) { + aRow = -aRow; + } + + aMapItems.insert(aRow, anItem); + } + + // Compute new rows + QList aListRows = aMapItems.keys(); + QList aListNewRows; + int i; + const int aSize = aListRows.size(); + + + if (theShift < 0) { + // Check each row to be positive. + int aMinIndex = 0; + + for (i = 0; i < aSize; i++) { + int aRow = aListRows[i] + theShift; + + if (aRow < aMinIndex) { + aRow = aMinIndex++; + } + + aListNewRows.append(aRow); + } + } else { + // Check each row to be not greater then a myPntsList's size. + int aMaxIndex = myPntsList->count() - 1; + + for (i = 0; i < aSize; i++) { + int aRow = -aListRows[i] + theShift; + + if (aRow > aMaxIndex) { + aRow = aMaxIndex--; + } + + aListRows[i] = -aListRows[i]; + aListNewRows.append(aRow); + } + } + + // Move each item to another position. + for (i = 0; i < aSize; i++) { + if (aListRows[i] != aListNewRows[i]) { + QListWidgetItem *anItem = myPntsList->takeItem(aListRows[i]); + + myPntsList->insertItem(aListNewRows[i], anItem); + } + } + + // Select added items. + foreach (int anIndex, aListNewRows) { + myPntsList->item(anIndex)->setSelected(true); + } + } +} + +//======================================================================= +// function: setTabOrder +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::setTabOrder() +{ + QWidget::setTabOrder(myXSpn, myYSpn); + + if (myDimension == CurveCreator::Dim3d) { + QWidget::setTabOrder(myYSpn, myZSpn); + QWidget::setTabOrder(myZSpn, myAddBtn); + } else { + QWidget::setTabOrder(myYSpn, myAddBtn); + } + + QWidget::setTabOrder(myAddBtn, myModifBtn); + QWidget::setTabOrder(myModifBtn, myRmBtn); + QWidget::setTabOrder(myRmBtn, myClearBtn); + QWidget::setTabOrder(myClearBtn, myPntsList); + QWidget::setTabOrder(myPntsList, myPntUpBtn); + QWidget::setTabOrder(myPntUpBtn, myPntDownBtn); + QWidget::setTabOrder(myPntDownBtn, myOkBtn); + QWidget::setTabOrder(myOkBtn, myCancelBtn); +} + +//======================================================================= +// function: appendPoint +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::appendPoint() +{ + if (myDimension == CurveCreator::Dim3d) { + new CurveCreator_PointItem(myXSpn->value(), myYSpn->value(), + myZSpn->value(), myPntsList); + } else { + new CurveCreator_PointItem(myXSpn->value(), myYSpn->value(), myPntsList); + } + + emit numberOfItemsChanged(myPntsList->count()); +} + +//======================================================================= +// function: modifyPoint +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::modifyPoint() +{ + QList aListItems = myPntsList->selectedItems(); + + if (aListItems.size() == 1) { + CurveCreator_PointItem *aPntItem = + (CurveCreator_PointItem *)aListItems.first(); + + if (myDimension == CurveCreator::Dim3d) { + aPntItem->setCoord(myXSpn->value(), myYSpn->value(), myZSpn->value()); + } else { + aPntItem->setCoord(myXSpn->value(), myYSpn->value()); + } + } +} + +//======================================================================= +// function: removePoint +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::removePoint() +{ + QList aListItems = myPntsList->selectedItems(); + int aRow = -1; + + foreach(QListWidgetItem *anItem, aListItems) { + if (aRow < 0) { + aRow = myPntsList->row(anItem); + } + + delete anItem; + } + + if (aRow >= 0) { + emit numberOfItemsChanged(myPntsList->count()); + } + + // Set the new selection. + if (aRow >= myPntsList->count()) { + aRow = myPntsList->count() - 1; + } + + if (aRow >= 0) { + myPntsList->item(aRow)->setSelected(true); + } +} + +//======================================================================= +// function: upPoint +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::upPoint() +{ + movePoints(-1); +} + +//======================================================================= +// function: downPoint +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::downPoint() +{ + movePoints(1); +} + +//======================================================================= +// function: changeSelection +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::changeSelection() +{ + // Update modify button and spin boxes. + QList aListItems = myPntsList->selectedItems(); + const int aNbItems = aListItems.size(); + + if (aNbItems == 1) { + const CurveCreator_PointItem *aPntItem = + (const CurveCreator_PointItem *)aListItems.first(); + + myModifBtn->setEnabled(true); + myXSpn->setValue(aPntItem->getX()); + myYSpn->setValue(aPntItem->getY()); + + if (myDimension == CurveCreator::Dim3d) { + myZSpn->setValue(aPntItem->getZ()); + } + } else if (myModifBtn->isEnabled()) { + myModifBtn->setEnabled(false); + myXSpn->setValue(0.0); + myYSpn->setValue(0.0); + + if (myDimension == CurveCreator::Dim3d) { + myZSpn->setValue(0.0); + } + } + + // Set enabled remove, up and down points. + bool isEnabled = (aNbItems > 0); + + myRmBtn->setEnabled(isEnabled); + isEnabled &= (aNbItems < myPntsList->count()); + myPntUpBtn->setEnabled(isEnabled); + myPntDownBtn->setEnabled(isEnabled); +} + +//======================================================================= +// function: accept +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::accept() +{ + // Copy points + myPoints.clear(); + + const int aNbPoints = myPntsList->count(); + int i; + + for (i = 0; i < aNbPoints; i++) { + const CurveCreator_PointItem *aPntItem = + (const CurveCreator_PointItem *)myPntsList->item(i); + + myPoints.push_back(aPntItem->getX()); + myPoints.push_back(aPntItem->getY()); + + if (myDimension == CurveCreator::Dim3d) { + myPoints.push_back(aPntItem->getZ()); + } + } + + QDialog::accept(); +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::clear() +{ + bool isEmpty = (myPntsList->count() == 0); + + myPntsList->clear(); + + if (!isEmpty) { + emit onNumberOfItemsChanged(0); + } +} + +//======================================================================= +// function: onNumberOfItemsChanged +// purpose: +//======================================================================= +void CurveCreator_EditPntsDlg::onNumberOfItemsChanged(int theNewValue) +{ + myClearBtn->setEnabled(theNewValue > 0); + + // Update Up and down buttons + QList aListItems = myPntsList->selectedItems(); + const int aNbItems = aListItems.size(); + const bool isEnabled = (aNbItems > 0 && aNbItems < theNewValue); + + myPntUpBtn->setEnabled(isEnabled); + myPntDownBtn->setEnabled(isEnabled); +} diff --git a/src/CurveCreator/CurveCreator_EditPntsDlg.h b/src/CurveCreator/CurveCreator_EditPntsDlg.h new file mode 100644 index 000000000..b85d08a8e --- /dev/null +++ b/src/CurveCreator/CurveCreator_EditPntsDlg.h @@ -0,0 +1,110 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_EditPntsDlg.h +// Created: Fri Jul 05 16:29:48 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_EditPntsDlg_HeaderFile +#define _CurveCreator_EditPntsDlg_HeaderFile + + +#include +#include + +class QListWidget; +class QDoubleSpinBox; +class QPushButton; + + +class CurveCreator_EditPntsDlg : public QDialog +{ + Q_OBJECT + +public: + + CurveCreator_EditPntsDlg(QWidget* parent, + const CurveCreator::Dimension theDimension); + + ~CurveCreator_EditPntsDlg(); + + void setPoints(const CurveCreator::Coordinates &thePoints); + + const CurveCreator::Coordinates &getPoints() const; + +private: + + void init(); + + void initSpinBox(QDoubleSpinBox *theSpinBox); + + void updateEditList(); + + void movePoints(const int theShift); + + void setTabOrder(); + +private slots: + + void appendPoint(); + + void modifyPoint(); + + void removePoint(); + + void upPoint(); + + void downPoint(); + + void changeSelection(); + + void accept(); + + void clear(); + + void onNumberOfItemsChanged(int theNewValue); + +signals: + + void numberOfItemsChanged(int theNewValue); + +protected: + + CurveCreator::Dimension myDimension; + CurveCreator::Coordinates myPoints; + QListWidget *myPntsList; + QDoubleSpinBox *myXSpn; + QDoubleSpinBox *myYSpn; + QDoubleSpinBox *myZSpn; + QPushButton *myAddBtn; + QPushButton *myModifBtn; + QPushButton *myRmBtn; + QPushButton *myClearBtn; + QPushButton *myPntUpBtn; + QPushButton *myPntDownBtn; + QPushButton *myOkBtn; + QPushButton *myCancelBtn; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_EditPntsWidget.cxx b/src/CurveCreator/CurveCreator_EditPntsWidget.cxx new file mode 100644 index 000000000..3cbf0e1e3 --- /dev/null +++ b/src/CurveCreator/CurveCreator_EditPntsWidget.cxx @@ -0,0 +1,236 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_EditPntsWidget.cxx +// Created: Fri Jul 05 16:30:11 2013 +// Author: Sergey KHROMOV +// + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_EditPntsWidget::CurveCreator_EditPntsWidget + (QWidget* parent, + const bool IsSection, + const CurveCreator::Dimension theDimension) + : QWidget (parent), + myDimension (theDimension), + myPntsEdit (NULL), + myPntsBtn (NULL), + myPntsEditDlg (NULL), + myPntsList (NULL) +{ + QGroupBox *aMainGrp = new QGroupBox; + QHBoxLayout *aMainLO = new QHBoxLayout(aMainGrp); + + myPntsEdit = new QLineEdit(aMainGrp); + myPntsBtn = new QPushButton + (IsSection? tr("CC_SECTION_POINTS_EDIT") : tr("CC_POINTS_EDIT"), aMainGrp); + aMainLO->addWidget(myPntsEdit); + aMainLO->addWidget(myPntsBtn); + + setLayout(aMainLO); + + init(); +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_EditPntsWidget::~CurveCreator_EditPntsWidget() +{ +} + +//======================================================================= +// function: setPoints +// purpose: +//======================================================================= +void CurveCreator_EditPntsWidget::setPoints + (const CurveCreator::Coordinates &thePoints) +{ + myPoints = thePoints; + updateEditLine(); +} + +//======================================================================= +// function: getPoints +// purpose: +//======================================================================= +const CurveCreator::Coordinates &CurveCreator_EditPntsWidget::getPoints() const +{ + return myPoints; +} + +//======================================================================= +// function : setPointsList +// purpose : +//======================================================================= +void CurveCreator_EditPntsWidget::setPointsList(QListWidget *thePntsList) +{ + myPntsList = thePntsList; +} + +//======================================================================= +// function : clear +// purpose : +//======================================================================= +void CurveCreator_EditPntsWidget::clear() +{ + myPoints.clear(); + myPntsEdit->setText(""); +} + +//======================================================================= +// function : getPointsEdit +// purpose : +//======================================================================= +QLineEdit *CurveCreator_EditPntsWidget::getPointsEdit() const +{ + return myPntsEdit; +} + +//======================================================================= +// function : getPointsButton +// purpose : +//======================================================================= +QPushButton *CurveCreator_EditPntsWidget::getPointsButton() const +{ + return myPntsBtn; +} + +//======================================================================= +// function : init +// purpose : +//======================================================================= +void CurveCreator_EditPntsWidget::init() +{ + connect(myPntsBtn, SIGNAL(clicked()), this, SLOT(editPoints())); + + myPntsEdit->setReadOnly(true); + updateEditLine(); + + // Set tab order. + QWidget::setTabOrder(myPntsEdit, myPntsBtn); +} + +//======================================================================= +// function : editPoints +// purpose : +//======================================================================= +void CurveCreator_EditPntsWidget::editPoints() +{ + if (myPntsEditDlg == NULL) { + // Create the dialog. + myPntsEditDlg = new CurveCreator_EditPntsDlg(this, myDimension); + } + + // Set points to dialog. + setPointsToDialog(); + + const int aResult = myPntsEditDlg->exec(); + + if (aResult == QDialog::Accepted) { + // Update the list of points and myPntsEdit. + const CurveCreator::Coordinates &aNewPoints = myPntsEditDlg->getPoints(); + + myPoints.clear(); + myPoints.insert(myPoints.end(), aNewPoints.begin(), aNewPoints.end()); + updateEditLine(); + } +} + +//======================================================================= +// function : updateEditLine +// purpose : +//======================================================================= +void CurveCreator_EditPntsWidget::updateEditLine() +{ + const int aNbPnts = myPoints.size(); + + if ( aNbPnts == 0 ) { + myPntsEdit->setText(""); + } else if ( aNbPnts == myDimension ) { + // One point. + QString aText; + + if (myDimension == CurveCreator::Dim3d) { + aText = CurveCreator_PointItem::getText + (myPoints[0], myPoints[1], myPoints[2]); + } else { + aText = CurveCreator_PointItem::getText(myPoints[0], myPoints[1]); + } + + myPntsEdit->setText(aText); + } else if ( aNbPnts > 0 ) { + myPntsEdit->setText(tr("CC_POINTS_NUMBER").arg(aNbPnts/myDimension)); + } +} + +//======================================================================= +// function : setPointsToDialog +// purpose : +//======================================================================= +void CurveCreator_EditPntsWidget::setPointsToDialog() +{ + bool isPntsFromWidget = false; + + if (myPntsList != NULL) { + QList aListItems = myPntsList->selectedItems(); + + if (aListItems.size() > 0) { + CurveCreator::Coordinates aPoints; + + foreach (QListWidgetItem *anItem, aListItems) { + const CurveCreator_PointItem *aPntItem = + (const CurveCreator_PointItem *)anItem; + + aPoints.push_back(aPntItem->getX()); + aPoints.push_back(aPntItem->getY()); + + if (myDimension == CurveCreator::Dim3d) { + aPoints.push_back(aPntItem->getZ()); + } + } + + myPntsEditDlg->setPoints(aPoints); + isPntsFromWidget = true; + } + } + + if (!isPntsFromWidget) { + myPntsEditDlg->setPoints(myPoints); + } +} diff --git a/src/CurveCreator/CurveCreator_EditPntsWidget.h b/src/CurveCreator/CurveCreator_EditPntsWidget.h new file mode 100644 index 000000000..a48ba8005 --- /dev/null +++ b/src/CurveCreator/CurveCreator_EditPntsWidget.h @@ -0,0 +1,89 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_EditPntsWidget.h +// Created: Fri Jul 05 16:30:17 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_EditPntsWidget_HeaderFile +#define _CurveCreator_EditPntsWidget_HeaderFile + + +#include +#include + +class QLineEdit; +class QPushButton; +class QListWidget; +class CurveCreator_EditPntsDlg; + + +class CurveCreator_EditPntsWidget : public QWidget +{ + Q_OBJECT + +public: + + CurveCreator_EditPntsWidget(QWidget* parent, + const bool IsSection, + const CurveCreator::Dimension theDimension); + + ~CurveCreator_EditPntsWidget(); + + void setPoints(const CurveCreator::Coordinates &thePoints); + + const CurveCreator::Coordinates &getPoints() const; + + void setPointsList(QListWidget *thePntsList); + + void clear(); + + QLineEdit *getPointsEdit() const; + + QPushButton *getPointsButton() const; + +private slots: + + void editPoints(); + +private: + + void init(); + + void updateEditLine(); + + void setPointsToDialog(); + +protected: + + CurveCreator::Coordinates myPoints; + CurveCreator::Dimension myDimension; + QPushButton *myPntsBtn; + QLineEdit *myPntsEdit; + CurveCreator_EditPntsDlg *myPntsEditDlg; + QListWidget *myPntsList; + +}; + +#endif + diff --git a/src/CurveCreator/CurveCreator_Macro.hxx b/src/CurveCreator/CurveCreator_Macro.hxx new file mode 100644 index 000000000..0fdaa1a7c --- /dev/null +++ b/src/CurveCreator/CurveCreator_Macro.hxx @@ -0,0 +1,49 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Fri Jun 28 13:21:59 2013 +// 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/CurveCreator/CurveCreator_Operation.cxx b/src/CurveCreator/CurveCreator_Operation.cxx new file mode 100644 index 000000000..88e0d9dde --- /dev/null +++ b/src/CurveCreator/CurveCreator_Operation.cxx @@ -0,0 +1,330 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Wed Jun 26 13:06:56 2013 +// Author: Sergey KHROMOV +// + + +#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: 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: + theCurve->removePoints(pInt[0], pInt[1], pInt[2]); + break; + case CurveCreator_Operation::InsertPoints: + { + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[2], aCoords); + theCurve->insertPoints(aCoords, pInt[0], pInt[1]); + } + break; + case CurveCreator_Operation::SetType: + { + const CurveCreator::Type aType = (CurveCreator::Type) pInt[0]; + + theCurve->setType(aType, pInt[1]); + } + break; + case CurveCreator_Operation::Clear: + theCurve->clear(); + break; + case CurveCreator_Operation::SetCoordinates: + { + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[2], aCoords); + theCurve->setCoordinates(aCoords, pInt[0], pInt[1]); + } + 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::Type aType = (CurveCreator::Type) pInt[0]; + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[2], aCoords); + theCurve->addSection(aType, (pInt[1] != 0), aCoords); + } + break; + case CurveCreator_Operation::RemoveSection: + theCurve->removeSection(pInt[0]); + 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/CurveCreator/CurveCreator_Operation.hxx b/src/CurveCreator/CurveCreator_Operation.hxx new file mode 100644 index 000000000..93b5c8848 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Operation.hxx @@ -0,0 +1,177 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Wed Jun 26 13:06:51 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_Operation_HeaderFile +#define _CurveCreator_Operation_HeaderFile + + +#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 + }; + + /** + * 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 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/CurveCreator/CurveCreator_PointItem.cxx b/src/CurveCreator/CurveCreator_PointItem.cxx new file mode 100644 index 000000000..85f628bbb --- /dev/null +++ b/src/CurveCreator/CurveCreator_PointItem.cxx @@ -0,0 +1,153 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_PointItem.cxx +// Created: Wed Jul 10 12:17:47 2013 +// Author: Sergey KHROMOV +// + + +#include +#include + + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_PointItem::CurveCreator_PointItem + (const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY, + QListWidget *theParent) + : QListWidgetItem(theParent, ITEM_TYPE_XY) +{ + setCoord(theX, theY); +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_PointItem::CurveCreator_PointItem + (const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY, + const CurveCreator::TypeCoord theZ, + QListWidget *theParent) + : QListWidgetItem(theParent, ITEM_TYPE_XYZ) +{ + setCoord(theX, theY, theZ); +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_PointItem::~CurveCreator_PointItem() +{ +} + +//======================================================================= +// function: getText +// purpose: +//======================================================================= +QString CurveCreator_PointItem::getText(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY) +{ + return QObject::tr("CC_PNT_ITEM_X_Y").arg(theX).arg(theY); +} + +//======================================================================= +// function: getText +// purpose: +//======================================================================= +QString CurveCreator_PointItem::getText(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY, + const CurveCreator::TypeCoord theZ) +{ + return QObject::tr("CC_PNT_ITEM_X_Y_Z").arg(theX).arg(theY).arg(theZ); +} + +//======================================================================= +// function: setCoord +// purpose: +//======================================================================= +void CurveCreator_PointItem::setCoord(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY) +{ + if (!is3d()) { + setData(ROLE_X, theX); + setData(ROLE_Y, theY); + setText(getText(theX, theY)); + } +} + +//======================================================================= +// function: setCoord +// purpose: +//======================================================================= +void CurveCreator_PointItem::setCoord(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY, + const CurveCreator::TypeCoord theZ) +{ + if (is3d()) { + setData(ROLE_X, theX); + setData(ROLE_Y, theY); + setData(ROLE_Z, theZ); + setText(getText(theX, theY, theZ)); + } +} + +//======================================================================= +// function: getX +// purpose: +//======================================================================= +CurveCreator::TypeCoord CurveCreator_PointItem::getX() const +{ + return data(ROLE_X).value(); +} + +//======================================================================= +// function: getY +// purpose: +//======================================================================= +CurveCreator::TypeCoord CurveCreator_PointItem::getY() const +{ + return data(ROLE_Y).value(); +} + +//======================================================================= +// function: getZ +// purpose: +//======================================================================= +CurveCreator::TypeCoord CurveCreator_PointItem::getZ() const +{ + return (is3d() ? data(ROLE_Z).value() : 0.); +} + +//======================================================================= +// function: is3d +// purpose: +//======================================================================= +bool CurveCreator_PointItem::is3d() const +{ + return (type() == ITEM_TYPE_XYZ); +} diff --git a/src/CurveCreator/CurveCreator_PointItem.h b/src/CurveCreator/CurveCreator_PointItem.h new file mode 100644 index 000000000..2932e2a1b --- /dev/null +++ b/src/CurveCreator/CurveCreator_PointItem.h @@ -0,0 +1,125 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_PointItem.h +// Created: Wed Jul 10 12:17:40 2013 +// Author: Sergey KHROMOV +// + + +#ifndef _CurveCreator_PointItem_HeaderFile +#define _CurveCreator_PointItem_HeaderFile + + +#include +#include + + +#define ITEM_TYPE_XY QListWidgetItem::UserType + 1 +#define ITEM_TYPE_XYZ QListWidgetItem::UserType + 2 +#define ROLE_X Qt::UserRole + 1 +#define ROLE_Y Qt::UserRole + 2 +#define ROLE_Z Qt::UserRole + 3 + +/** + * This class represents a list widget item to facilitate storage + * of 2d or 3d points in a list widget. The type of a stored point + * (2d or 3d) is determined by a constructor chosen to create an object. + */ +class CurveCreator_PointItem : public QListWidgetItem +{ + +public: + + /** + * Constructor. Initializes the object with 2d point. + */ + CurveCreator_PointItem(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY, + QListWidget * theParent = 0); + + /** + * Constructor. Initializes the object with 3d point. + */ + CurveCreator_PointItem(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY, + const CurveCreator::TypeCoord theZ, + QListWidget * theParent = 0); + + /** + * Destructor + */ + ~CurveCreator_PointItem(); + + /** + * This static method is used to construct the text to be displayed by this + * item for 2d point. + */ + static QString getText(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY); + + /** + * This static method is used to construct the text to be displayed by this + * item for 3d point. + */ + static QString getText(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY, + const CurveCreator::TypeCoord theZ); + + /** + * This method sets the coordinates for 2d point. If the object has type + * 3d point this method does nothing. + */ + void setCoord(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY); + + /** + * This method sets the coordinates for 3d point. If the object has type + * 2d point this method does nothing. + */ + void setCoord(const CurveCreator::TypeCoord theX, + const CurveCreator::TypeCoord theY, + const CurveCreator::TypeCoord theZ); + + /** + * Query the X coordinate of the point. + */ + CurveCreator::TypeCoord getX() const; + + /** + * Query the Y coordinate of the point. + */ + CurveCreator::TypeCoord getY() const; + + /** + * Query the Z coordinate of the point. Return 0 for the type 2d point. + */ + CurveCreator::TypeCoord getZ() const; + + /** + * Returns true if the type of the stored point is 3d; false otherwise. + */ + bool is3d() const; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Section.hxx b/src/CurveCreator/CurveCreator_Section.hxx new file mode 100644 index 000000000..cf8b958f8 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Section.hxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// Created: Tue Jun 25 16:04:25 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_Section_HeaderFile +#define _CurveCreator_Section_HeaderFile + + +#include + + +//! Structure to store sections representing the CurveCreator_Curve object +struct CurveCreator_Section +{ + //! Constructor. Initializes object with default values. + CurveCreator_Section() : myType(CurveCreator::Polyline), myIsClosed(false) + { } + + CurveCreator::Coordinates myPoints; //!< points coordinates + CurveCreator::Type myType; //!< type of the section + bool myIsClosed; //!< closed or not + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_UndoOptsDlg.cxx b/src/CurveCreator/CurveCreator_UndoOptsDlg.cxx new file mode 100644 index 000000000..ad0c3c11a --- /dev/null +++ b/src/CurveCreator/CurveCreator_UndoOptsDlg.cxx @@ -0,0 +1,242 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_UndoOptsDlg.cxx +// Created: Wed Jul 17 12:50:46 2013 +// Author: Sergey KHROMOV +// + + +#include +#include +#include +#include +#include +#include +#include +#include + +#define UNDO_DEPTH_UNLIMITED 0 +#define UNDO_DEPTH_DISABLED 1 +#define UNDO_DEPTH_FIX_SIZE 2 + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_UndoOptsDlg::CurveCreator_UndoOptsDlg(QWidget* parent) + : QDialog (parent), + myUndoDepth (UNDO_DEPTH_UNLIMITED), + myOptsBtnGrp (NULL), + myBufferSizeEdit (NULL), + myOkBtn (NULL), + myCancelBtn (NULL) +{ + setWindowTitle(tr("CC_UNDO_OPTIONS_TITLE")); + + // Set Undo/Redo options group + QGroupBox *anUndoOptsGrp = + new QGroupBox(tr("CC_UNDO_OPTIONS_MODIFY")); + QGridLayout *anUndoOptsLO = new QGridLayout(anUndoOptsGrp); + QRadioButton *aDisabledRdBtn = + new QRadioButton(tr("CC_UNDO_OPTIONS_DISABLED"), anUndoOptsGrp); + QRadioButton *aFixSizeRdBtn = + new QRadioButton(tr("CC_UNDO_OPTIONS_FIXED_SIZE"), anUndoOptsGrp); + QRadioButton *anUnlimRdBtn = + new QRadioButton(tr("CC_UNDO_OPTIONS_UNLIMITED"), anUndoOptsGrp); + + myOptsBtnGrp = new QButtonGroup(anUndoOptsGrp); + myBufferSizeEdit = new QLineEdit(anUndoOptsGrp); + anUndoOptsLO->setMargin(9); + anUndoOptsLO->setSpacing(6); + anUndoOptsLO->addWidget(aDisabledRdBtn, 0, 0); + anUndoOptsLO->addWidget(aFixSizeRdBtn, 1, 0); + anUndoOptsLO->addWidget(anUnlimRdBtn, 2, 0); + anUndoOptsLO->addWidget(myBufferSizeEdit, 1, 1); + myOptsBtnGrp->addButton(anUnlimRdBtn, UNDO_DEPTH_UNLIMITED); + myOptsBtnGrp->addButton(aDisabledRdBtn, UNDO_DEPTH_DISABLED); + myOptsBtnGrp->addButton(aFixSizeRdBtn, UNDO_DEPTH_FIX_SIZE); + + // Set OK/Cancel buttons group + QGroupBox *anOkCancelGrp = new QGroupBox; + QGridLayout *anOkCancelLO = new QGridLayout(anOkCancelGrp); + + myOkBtn = new QPushButton(tr("GEOM_BUT_OK"), anOkCancelGrp); + myCancelBtn = new QPushButton(tr("GEOM_BUT_CANCEL"), anOkCancelGrp); + anOkCancelLO->setMargin(9); + anOkCancelLO->setSpacing(6); + anOkCancelLO->addWidget(myOkBtn, 0, 0); + anOkCancelLO->addWidget(myCancelBtn, 0, 1); + + // Set main group + QGroupBox *aMainGrp = new QGroupBox; + QVBoxLayout *aMainLO = new QVBoxLayout(aMainGrp); + + aMainLO->addWidget(anUndoOptsGrp); + aMainLO->addWidget(anOkCancelGrp); + + setLayout(aMainLO); + + init(); +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_UndoOptsDlg::~CurveCreator_UndoOptsDlg() +{ +} + +//======================================================================= +// function: setUndoDepth +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::setUndoDepth(const int theDepth) +{ + myUndoDepth = theDepth; + + const int aDepthId = myUndoDepth + 1; + int anId = UNDO_DEPTH_FIX_SIZE; + + if (aDepthId == UNDO_DEPTH_UNLIMITED || + aDepthId == UNDO_DEPTH_DISABLED) { + anId = aDepthId; + } else if (myUndoDepth > 0) { + myBufferSizeEdit->setText(QString::number(myUndoDepth)); + } + + myOptsBtnGrp->button(anId)->setChecked(true); + optionChanged(anId); +} + +//======================================================================= +// function: getUndoDepth +// purpose: +//======================================================================= +int CurveCreator_UndoOptsDlg::getUndoDepth() const +{ + return myUndoDepth; +} + +//======================================================================= +// function: isEnabled +// purpose: +//======================================================================= +bool CurveCreator_UndoOptsDlg::isEnabled() const +{ + return (myUndoDepth + 1 != UNDO_DEPTH_DISABLED); +} + +//======================================================================= +// function: isUnlimited +// purpose: +//======================================================================= +bool CurveCreator_UndoOptsDlg::isUnlimited() const +{ + return (myUndoDepth + 1 == UNDO_DEPTH_UNLIMITED); +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::init() +{ + // Initialize sections group. + myOptsBtnGrp->setExclusive(true); + myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED)->setChecked(true); + connect(myOptsBtnGrp, SIGNAL(buttonClicked(int)), + this, SLOT(optionChanged(int))); + + // Initialize line edit. + QIntValidator *aValidator = new QIntValidator(myBufferSizeEdit); + + aValidator->setBottom(1); + myBufferSizeEdit->setValidator(aValidator); + optionChanged(UNDO_DEPTH_UNLIMITED); + + // Init buttons. + myOkBtn->setDefault(true); + + connect(myOkBtn, SIGNAL(clicked()), this, SLOT(accept())); + connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject())); + + setTabOrder(); +} + +//======================================================================= +// function: setTabOrder +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::setTabOrder() +{ + QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_DISABLED), + myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE)); + QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE), + myBufferSizeEdit); + QWidget::setTabOrder(myBufferSizeEdit, + myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED)); + QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED), myOkBtn); + QWidget::setTabOrder(myOkBtn, myCancelBtn); +} + +//======================================================================= +// function: optionChanged +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::optionChanged(int theId) +{ + switch (theId) { + case UNDO_DEPTH_FIX_SIZE: + myBufferSizeEdit->setEnabled(true); + break; + case UNDO_DEPTH_UNLIMITED: + case UNDO_DEPTH_DISABLED: + default: + myBufferSizeEdit->setEnabled(false); + break; + } +} + +//======================================================================= +// function: accept +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::accept() +{ + const int anId = myOptsBtnGrp->checkedId(); + + switch (anId) { + case UNDO_DEPTH_FIX_SIZE: + myUndoDepth = myBufferSizeEdit->text().toInt(); + break; + case UNDO_DEPTH_UNLIMITED: + case UNDO_DEPTH_DISABLED: + myUndoDepth = anId - 1; + break; + default: + break; + } + + QDialog::accept(); +} diff --git a/src/CurveCreator/CurveCreator_UndoOptsDlg.h b/src/CurveCreator/CurveCreator_UndoOptsDlg.h new file mode 100644 index 000000000..a8df525ed --- /dev/null +++ b/src/CurveCreator/CurveCreator_UndoOptsDlg.h @@ -0,0 +1,79 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_UndoOptsDlg.h +// Created: Wed Jul 17 12:50:42 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_UndoOptsDlg_HeaderFile +#define _CurveCreator_UndoOptsDlg_HeaderFile + + +#include + +class QButtonGroup; +class QLineEdit; +class QPushButton; + + +class CurveCreator_UndoOptsDlg : public QDialog +{ + Q_OBJECT + +public: + + CurveCreator_UndoOptsDlg(QWidget* parent); + + ~CurveCreator_UndoOptsDlg(); + + void setUndoDepth(const int theDepth); + + int getUndoDepth() const; + + bool isEnabled() const; + + bool isUnlimited() const; + +private: + + void init(); + + void setTabOrder(); + +private slots: + + void optionChanged(int theId); + + void accept(); + +protected: + + int myUndoDepth; + QButtonGroup *myOptsBtnGrp; + QLineEdit *myBufferSizeEdit; + QPushButton *myOkBtn; + QPushButton *myCancelBtn; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx new file mode 100644 index 000000000..0c0ceac9b --- /dev/null +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -0,0 +1,1176 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_Widget.cxx +// Created: Mon Jul 01 12:49:31 2013 +// Author: Sergey KHROMOV +// + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SECTION_ADD 0 +#define SECTION_MODIFY 1 +#define POLYLINE_INDEX 0 +#define BSPLINE_INDEX 1 +#define UNDO_REDO_DISABLED 0 +#define UNDO_REDO_UNLIMITED -1 + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, + CurveCreator_Curve *theCurve, + Qt::WindowFlags fl) + : QWidget (parent, fl), + myEditor (theCurve), + myDimension (theCurve == NULL ? + CurveCreator::Dim2d : theCurve->getDimension()), + myEnabledUndoLbl (NULL), + myBufSizeUndoLbl (NULL), + myUndoBtn (NULL), + myRedoBtn (NULL), + myUndoOptsBtn (NULL), + myUndoOptsDlg (NULL), + myAddSecGrp (NULL), + mySecBtnGrp (NULL), + mySecTypeCmbBox (NULL), + mySecCloseChkBox (NULL), + mySecAddModifBtn (NULL), + mySecRmBtn (NULL), + mySecJoinBtn (NULL), + mySecJoinAllBtn (NULL), + mySecClearBtn (NULL), + mySecUpBtn (NULL), + mySecDownBtn (NULL), + mySecList (NULL), + myEditSecPnts (NULL), + myPntsGrp (NULL), + myPntsList (NULL), + myPntEditDlg (NULL), + myEditPnts (NULL), + myAddPntsBtn (NULL), + myInsertPntsBtn (NULL), + myRmPntsBtn (NULL) +{ + setWindowTitle(tr("CC_TITLE")); + + // Set undo/redo options group + QGroupBox *anUndoOptsGrp = new QGroupBox(tr("CC_UNDO_REDO_OPTIONS")); + QGridLayout *anUndoOptsLO = new QGridLayout(anUndoOptsGrp); + + myEnabledUndoLbl = new QLabel(tr("CC_UNDO_REDO_ENABLED"), anUndoOptsGrp); + myBufSizeUndoLbl = new QLabel(tr("CC_UNDO_REDO_BUFFER_SIZE"), anUndoOptsGrp); + myUndoOptsBtn = new QPushButton(tr("CC_UNDO_REDO_MODIFY"), anUndoOptsGrp); + anUndoOptsLO->setMargin(9); + anUndoOptsLO->setSpacing(6); + anUndoOptsLO->addWidget(myEnabledUndoLbl, 0, 0); + anUndoOptsLO->addWidget(myBufSizeUndoLbl, 1, 0); + anUndoOptsLO->addWidget(myUndoOptsBtn, 0, 1, 2, 1); + + // Set undo/redo group + QGroupBox *anUndoRedoGrp = new QGroupBox(tr("CC_UNDO_REDO_TITLE")); + QHBoxLayout *anUndoRedoLO = new QHBoxLayout(anUndoRedoGrp); + + myUndoBtn = new QPushButton(tr("CC_UNDO"), anUndoRedoGrp); + myRedoBtn = new QPushButton(tr("CC_REDO"), anUndoRedoGrp); + anUndoRedoLO->setMargin(9); + anUndoRedoLO->setSpacing(6); + anUndoRedoLO->addWidget(myUndoBtn, 0, Qt::AlignRight); + anUndoRedoLO->addWidget(myRedoBtn, 0, Qt::AlignLeft); + anUndoRedoLO->addWidget(anUndoOptsGrp, 0, Qt::AlignRight); + + // Set section add/modification group. + myAddSecGrp = new QGroupBox(tr("CC_SECTION_ADD_TITLE")); + + QGridLayout *anAddSecLO = new QGridLayout(myAddSecGrp); + QLabel *aSectTypeLbl = + new QLabel(tr("CC_SECTION_TYPE"), myAddSecGrp); + QLabel *aSecPntsLbl = + new QLabel(tr("CC_SECTION_POINTS_ADD_LBL"), myAddSecGrp); + + mySecCloseChkBox = new QCheckBox(tr("CC_SECTION_CLOSED"), myAddSecGrp); + mySecTypeCmbBox = new QComboBox(myAddSecGrp); + mySecAddModifBtn = new QPushButton(tr("CC_SECTION_NEW"), myAddSecGrp); + myEditSecPnts = new CurveCreator_EditPntsWidget + (myAddSecGrp, true, myDimension); + anAddSecLO->setMargin(9); + anAddSecLO->setSpacing(6); + anAddSecLO->addWidget(mySecCloseChkBox, 0, 0); + anAddSecLO->addWidget(aSectTypeLbl, 1, 0); + anAddSecLO->addWidget(mySecTypeCmbBox, 1, 1); + anAddSecLO->addWidget(aSecPntsLbl, 2, 0); + anAddSecLO->addWidget(myEditSecPnts, 2, 1); + anAddSecLO->addWidget(mySecAddModifBtn, 1, 3); + + // Set section group + QGroupBox *aSecGrp = new QGroupBox(tr("CC_SECTION_TITLE")); + QGridLayout *aSecLO = new QGridLayout(aSecGrp); + QRadioButton *anAddSecRdBtn = + new QRadioButton(tr("CC_SECTION_ADD_TITLE"), aSecGrp); + QRadioButton *aModifSecRdBtn = + new QRadioButton(tr("CC_SECTION_MODIFY_TITLE"), aSecGrp); + + mySecRmBtn = new QPushButton(tr("CC_SECTION_REMOVE"), aSecGrp); + mySecJoinBtn = new QPushButton(tr("CC_SECTION_JOIN"), aSecGrp); + mySecJoinAllBtn = new QPushButton(tr("CC_SECTION_JOIN_ALL"), aSecGrp); + mySecClearBtn = new QPushButton(tr("CC_SECTION_CLEAR"), aSecGrp); + mySecUpBtn = new QPushButton(tr("CC_SECTION_UP"), aSecGrp); + mySecDownBtn = new QPushButton(tr("CC_SECTION_DOWN"), aSecGrp); + mySecBtnGrp = new QButtonGroup(aSecGrp); + mySecList = new QListWidget(aSecGrp); + aSecLO->setMargin(9); + aSecLO->setSpacing(6); + aSecLO->addWidget(anAddSecRdBtn, 0, 0); + aSecLO->addWidget(aModifSecRdBtn, 0, 1); + aSecLO->addWidget(myAddSecGrp, 1, 0, 1, 5); + aSecLO->addWidget(mySecRmBtn, 2, 0); + aSecLO->addWidget(mySecJoinBtn, 2, 1); + aSecLO->addWidget(mySecJoinAllBtn, 2, 2); + aSecLO->addWidget(mySecClearBtn, 2, 3); + aSecLO->addWidget(mySecUpBtn, 4, 4); + aSecLO->addWidget(mySecDownBtn, 5, 4); + aSecLO->addWidget(mySecList, 3, 0, 4, 4); + mySecBtnGrp->addButton(anAddSecRdBtn, SECTION_ADD); + mySecBtnGrp->addButton(aModifSecRdBtn, SECTION_MODIFY); + + // Set point add/modification group. + QGroupBox *anAddPntsGrp = new QGroupBox(tr("CC_POINTS_ADD_TITLE")); + + QGridLayout *anAddPntsLO = new QGridLayout(anAddPntsGrp); + QLabel *aPntsLbl = + new QLabel(tr("CC_POINTS_ADD_LBL"), anAddPntsGrp); + + myEditPnts = new CurveCreator_EditPntsWidget + (anAddPntsGrp, false, myDimension); + myAddPntsBtn = new QPushButton(tr("CC_POINTS_ADD"), anAddPntsGrp); + myInsertPntsBtn = new QPushButton(tr("CC_POINTS_INSERT"), anAddPntsGrp); + anAddPntsLO->setMargin(9); + anAddPntsLO->setSpacing(6); + anAddPntsLO->addWidget(aPntsLbl, 0, 0); + anAddPntsLO->addWidget(myEditPnts, 0, 1); + anAddPntsLO->addWidget(myAddPntsBtn, 0, 4); + anAddPntsLO->addWidget(myInsertPntsBtn, 1, 4); + + // Set Points group + myPntsGrp = new QGroupBox(tr("CC_POINTS_TITLE")); + + QGridLayout *aPntsLO = new QGridLayout(myPntsGrp); + + myPntsList = new QListWidget(myPntsGrp); + myRmPntsBtn = new QPushButton(tr("CC_POINTS_REMOVE"), myPntsGrp); + aPntsLO->setMargin(9); + aPntsLO->setSpacing(6); + aPntsLO->addWidget(anAddPntsGrp, 0, 0, 1, 4); + aPntsLO->addWidget(myRmPntsBtn, 1, 0); + aPntsLO->addWidget(myPntsList, 2, 0, 4, 4); + + // Set main group + QGroupBox *aMainGrp = new QGroupBox(tr("CC_TITLE")); + QGridLayout *aMainLO = new QGridLayout(aMainGrp); + + aMainLO->setMargin(9); + aMainLO->setSpacing(6); + aMainLO->addWidget(anUndoRedoGrp, 0, 0, 1, 2); + aMainLO->addWidget(aSecGrp, 1, 0); + aMainLO->addWidget(myPntsGrp, 1, 1); + + setLayout(aMainLO); + + init(); +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +void CurveCreator_Widget::init() +{ + // Initialize Undo/Redo group. + QString anUnlim = tr("CC_UNDO_REDO_UNLIMITED"); + + myEnabledUndoLbl->setText(tr("CC_UNDO_REDO_ENABLED")); + myBufSizeUndoLbl->setText(tr("CC_UNDO_REDO_BUFFER_SIZE").arg(anUnlim)); + connect(myUndoOptsBtn, SIGNAL(clicked()), this, SLOT(undoOptionsChanged())); + connect(myUndoBtn, SIGNAL(clicked()), this, SLOT(undo())); + connect(myRedoBtn, SIGNAL(clicked()), this, SLOT(redo())); + updateUndoRedoButtons(); + + // Initialize sections group. + mySecBtnGrp->setExclusive(true); + mySecBtnGrp->button(SECTION_ADD)->setChecked(true); + connect(mySecBtnGrp, SIGNAL(buttonClicked(int)), + this, SLOT(addModifChanged(int))); + + // Init section buttons. + mySecAddModifBtn->setEnabled(true); + mySecRmBtn->setEnabled(false); + mySecJoinBtn->setEnabled(false); + mySecJoinAllBtn->setEnabled(false); + mySecClearBtn->setEnabled(false); + mySecUpBtn->setEnabled(false); + mySecDownBtn->setEnabled(false); + + connect(mySecAddModifBtn, SIGNAL(clicked()),this, SLOT(sectionAddOrModify())); + connect(mySecRmBtn, SIGNAL(clicked()),this, SLOT(sectionRemove())); + connect(mySecJoinBtn, SIGNAL(clicked()),this, SLOT(sectionJoin())); + connect(mySecJoinAllBtn, SIGNAL(clicked()),this, SLOT(sectionJoinAll())); + connect(mySecClearBtn, SIGNAL(clicked()),this, SLOT(sectionClear())); + connect(mySecUpBtn, SIGNAL(clicked()),this, SLOT(sectionUp())); + connect(mySecDownBtn, SIGNAL(clicked()),this, SLOT(sectionDown())); + + // Init section input fields. + mySecCloseChkBox->setChecked(false); + mySecTypeCmbBox->addItem(tr("CC_SECTION_TYPE_POLYLINE")); + mySecTypeCmbBox->addItem(tr("CC_SECTION_TYPE_BSPLINE")); + mySecTypeCmbBox->setCurrentIndex(POLYLINE_INDEX); + myEditSecPnts->clear(); + + // Init sections list widget. + mySecList->setSelectionMode(QAbstractItemView::ExtendedSelection); + + connect(this, SIGNAL(numberOfItemsChanged(QListWidget *)), + this, SLOT(onNumberOfItemsChanged(QListWidget *))); + initSections(); + connect(mySecList, SIGNAL(itemSelectionChanged()), + this, SLOT(changeSecSelection())); + + // Init points list widget. + myPntsGrp->setEnabled(false); + myPntsList->clear(); + myPntsList->setSelectionMode(QAbstractItemView::ExtendedSelection); + + connect(myPntsList, SIGNAL(itemSelectionChanged()), + this, SLOT(changePntsSelection())); + connect(myPntsList, SIGNAL(itemDoubleClicked(QListWidgetItem *)), + this, SLOT(editPnt(QListWidgetItem *))); + + // Init points buttons. + connect(myAddPntsBtn, SIGNAL(clicked()),this, SLOT(pntsAdd())); + connect(myInsertPntsBtn, SIGNAL(clicked()),this, SLOT(pntsInsert())); + connect(myRmPntsBtn, SIGNAL(clicked()),this, SLOT(pntsRemove())); + + // Init edit points widgets. + myEditSecPnts->setPointsList(myPntsList); + myEditPnts->setPointsList(myPntsList); + + // Set tab order + setTabOrder(); +} + +//======================================================================= +// function: initSections +// purpose: +//======================================================================= +void CurveCreator_Widget::initSections() +{ + CurveCreator_Curve *aCurve = myEditor.getCurve(); + + const int aNbSections = aCurve->getNbSections(); + int i; + + mySecList->clear(); + + for (i = 0; i < aNbSections; i++) { + addSectionItem(aCurve->getType(i), aCurve->isClosed(i)); + } + + emit numberOfItemsChanged(mySecList); +} + +//======================================================================= +// function: addSectionItem +// purpose: +//======================================================================= +void CurveCreator_Widget::addSectionItem(const CurveCreator::Type theType, + const bool isClosed) +{ + const int aRow = mySecList->count(); + + new QListWidgetItem(mySecList); + updateSectionItem(aRow, theType, isClosed); + emit numberOfItemsChanged(mySecList); +} + +//======================================================================= +// function: updateSectionItem +// purpose: +//======================================================================= +void CurveCreator_Widget::updateSectionItem(const int theRow, + const CurveCreator::Type theType, + const bool isClosed) +{ + QListWidgetItem *anItem = mySecList->item(theRow); + QString aStrType; + + if (theType == CurveCreator::Polyline) { + aStrType = tr("CC_SECTION_ITEM_POLYLINE"); + } else { + aStrType = tr("CC_SECTION_ITEM_BSPLINE"); + } + + const QString aTrCode = + (isClosed ? "CC_SECTION_ITEM_CLOSED" : "CC_SECTION_ITEM"); + + anItem->setText(tr(aTrCode.toLatin1().constData()).arg(aStrType)); +} + +//======================================================================= +// function: sectionMove +// purpose: +//======================================================================= +void CurveCreator_Widget::sectionMove(const int theShift) +{ + // Sort list items in ascending or descending order depending on + // the sign of theShift. + QList aListItems = mySecList->selectedItems(); + + if (!aListItems.empty() && theShift != 0) { + QMap aMapItems; + + foreach(QListWidgetItem *anItem, aListItems) { + int aRow = mySecList->row(anItem); + + if (theShift > 0) { + aRow = -aRow; + } + + aMapItems.insert(aRow, anItem); + } + + // Compute new rows + QList aListRows = aMapItems.keys(); + QList aListNewRows; + int i; + const int aSize = aListRows.size(); + + + if (theShift < 0) { + // Check each row to be positive. + int aMinIndex = 0; + + for (i = 0; i < aSize; i++) { + int aRow = aListRows[i] + theShift; + + if (aRow < aMinIndex) { + aRow = aMinIndex++; + } + + aListNewRows.append(aRow); + } + } else { + // Check each row to be not greater then a mySecList's size. + int aMaxIndex = mySecList->count() - 1; + + for (i = 0; i < aSize; i++) { + int aRow = -aListRows[i] + theShift; + + if (aRow > aMaxIndex) { + aRow = aMaxIndex--; + } + + aListRows[i] = -aListRows[i]; + aListNewRows.append(aRow); + } + } + + // Move each item to another position. + for (i = 0; i < aSize; i++) { + if (aListRows[i] != aListNewRows[i]) { + QListWidgetItem *anItem = mySecList->takeItem(aListRows[i]); + + // Move section. + mySecList->insertItem(aListNewRows[i], anItem); + myEditor.moveSection(aListRows[i], aListNewRows[i]); + } + } + + // Select added items. + foreach (int anIndex, aListNewRows) { + mySecList->item(anIndex)->setSelected(true); + } + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } +} + +//======================================================================= +// function: initPoints +// purpose: +//======================================================================= +void CurveCreator_Widget::initPoints(const int theSectionIndex) +{ + // Clear the points list + const int aNbPnts = myPntsList->count(); + + myPntsList->clear(); + + if (theSectionIndex < 0) { + if (aNbPnts > 0) { + emit numberOfItemsChanged(myPntsList); + } + } else { + // Fill the points list with the points of the section. + const CurveCreator::Coordinates &aPoints = + myEditor.getCurve()->getPoints(theSectionIndex); + const int aNbCoords = aPoints.size(); + + if (aNbCoords % myDimension == 0) { + int i = 0; + + while (i < aNbCoords) { + const CurveCreator::TypeCoord aX = aPoints[i++]; + const CurveCreator::TypeCoord aY = aPoints[i++]; + + if (myDimension == CurveCreator::Dim3d) { + const CurveCreator::TypeCoord aZ = aPoints[i++]; + + new CurveCreator_PointItem(aX, aY, aZ, myPntsList); + } else { + new CurveCreator_PointItem(aX, aY, myPntsList); + } + } + } + + if (aNbPnts != aNbCoords/myDimension) { + emit numberOfItemsChanged(myPntsList); + } + } +} + +//======================================================================= +// function: getCurrentSectionIndex +// purpose: +//======================================================================= +int CurveCreator_Widget::getCurrentSectionIndex() +{ + int anIndex = -1; + QList aListSec = mySecList->selectedItems(); + + if (aListSec.size() == 1) { + anIndex = mySecList->row(aListSec.first()); + } + + return anIndex; +} + +//======================================================================= +// function: updateUndoRedo +// purpose: +//======================================================================= +void CurveCreator_Widget::updateUndoRedo() +{ + // Update undo/redo buttons. + updateUndoRedoButtons(); + + // Update sections. + CurveCreator_Curve *aCurve = myEditor.getCurve(); + const bool isKeepSelection = (mySecList->count() == aCurve->getNbSections()); + QList aSelectedRows; + QList aListItems = mySecList->selectedItems(); + + if (isKeepSelection) { + foreach (QListWidgetItem *anItem, aListItems) { + aSelectedRows.append(mySecList->row(anItem)); + } + } + + initSections(); + + // Set selection. + if (isKeepSelection) { + foreach (int aRow, aSelectedRows) { + mySecList->item(aRow)->setSelected(true); + } + } + + changeSecSelection(); +} + +//======================================================================= +// function: updateUndoRedoButtons +// purpose: +//======================================================================= +void CurveCreator_Widget::updateUndoRedoButtons() +{ + // Update undo/redo buttons. + const int anUndoDepth = myEditor.getUndoDepth(); + + if (anUndoDepth == UNDO_REDO_DISABLED) { + myUndoBtn->setEnabled(false); + myRedoBtn->setEnabled(false); + } else { + myUndoBtn->setEnabled(myEditor.getNbUndo() > 0); + myRedoBtn->setEnabled(myEditor.getNbRedo() > 0); + } +} + + +//======================================================================= +// function: setTabOrder +// purpose: +//======================================================================= +void CurveCreator_Widget::setTabOrder() +{ + QWidget::setTabOrder(myUndoBtn, myRedoBtn); + QWidget::setTabOrder(myRedoBtn, myUndoOptsBtn); + QWidget::setTabOrder(myUndoOptsBtn, mySecBtnGrp->button(SECTION_ADD)); + QWidget::setTabOrder(mySecBtnGrp->button(SECTION_ADD), + mySecBtnGrp->button(SECTION_MODIFY)); + QWidget::setTabOrder(mySecBtnGrp->button(SECTION_MODIFY), mySecCloseChkBox); + QWidget::setTabOrder(mySecCloseChkBox, mySecTypeCmbBox); + QWidget::setTabOrder(mySecTypeCmbBox, myEditSecPnts->getPointsEdit()); + QWidget::setTabOrder(myEditSecPnts->getPointsEdit(), + myEditSecPnts->getPointsButton()); + QWidget::setTabOrder(myEditSecPnts->getPointsButton(), mySecAddModifBtn); + QWidget::setTabOrder(mySecAddModifBtn, mySecRmBtn); + QWidget::setTabOrder(mySecRmBtn, mySecJoinBtn); + QWidget::setTabOrder(mySecJoinBtn, mySecJoinAllBtn); + QWidget::setTabOrder(mySecJoinAllBtn, mySecClearBtn); + QWidget::setTabOrder(mySecClearBtn, mySecList); + QWidget::setTabOrder(mySecList, mySecUpBtn); + QWidget::setTabOrder(mySecUpBtn, mySecDownBtn); + QWidget::setTabOrder(mySecDownBtn, myEditPnts->getPointsEdit()); + QWidget::setTabOrder(myEditPnts->getPointsEdit(), + myEditPnts->getPointsButton()); + QWidget::setTabOrder(myEditPnts->getPointsButton(), myAddPntsBtn); + QWidget::setTabOrder(myAddPntsBtn, myInsertPntsBtn); + QWidget::setTabOrder(myInsertPntsBtn, myRmPntsBtn); + QWidget::setTabOrder(myRmPntsBtn, myPntsList); +} + +//======================================================================= +// function: undoOptionsChanged +// purpose: +//======================================================================= +void CurveCreator_Widget::undoOptionsChanged() +{ + if (myUndoOptsDlg == NULL) { + // Create the dialog. + myUndoOptsDlg = new CurveCreator_UndoOptsDlg(this); + } + + // set undo depth. + myUndoOptsDlg->setUndoDepth(myEditor.getUndoDepth()); + + const int aResult = myUndoOptsDlg->exec(); + + if (aResult == QDialog::Accepted) { + // Get undo depth. + const int anUndoDepth = myUndoOptsDlg->getUndoDepth(); + const bool isEnabled = myUndoOptsDlg->isEnabled(); + + myEditor.setUndoDepth(anUndoDepth); + + // Update options labels. + myBufSizeUndoLbl->setVisible(isEnabled); + + if (isEnabled) { + QString aSize; + + if (myUndoOptsDlg->isUnlimited()) { + aSize = tr("CC_UNDO_REDO_UNLIMITED"); + } else { + aSize = QString::number(anUndoDepth); + } + + myEnabledUndoLbl->setText(tr("CC_UNDO_REDO_ENABLED")); + myBufSizeUndoLbl->setText(tr("CC_UNDO_REDO_BUFFER_SIZE").arg(aSize)); + } else { + myEnabledUndoLbl->setText(tr("CC_UNDO_REDO_DISABLED")); + } + } + + // Update Undo Redo buttons. + updateUndoRedoButtons(); +} + +//======================================================================= +// function: sectionAddOrModify +// purpose: +//======================================================================= +void CurveCreator_Widget::sectionAddOrModify() +{ + const bool isClosed = mySecCloseChkBox->isChecked(); + CurveCreator::Type aType; + + if (mySecTypeCmbBox->currentIndex() == POLYLINE_INDEX) { + aType = CurveCreator::Polyline; + } else { + aType = CurveCreator::BSpline; + } + + if (mySecBtnGrp->checkedId() == SECTION_MODIFY) { + // Modify section mode. + QList aListItems = mySecList->selectedItems(); + + if (aListItems.size() == 1) { + const int aRow = mySecList->row(aListItems.first()); + bool isModified = false; + CurveCreator_Curve *aCurve = myEditor.getCurve(); + + + if (aCurve->getType(aRow) != aType) { + // Set type. + isModified = true; + myEditor.setType(aType, aRow); + } + + if (aCurve->isClosed(aRow) != isClosed) { + // Set closed flag. + isModified = true; + myEditor.setClosed(isClosed, aRow); + } + + if (isModified) { + updateSectionItem(aRow, aType, isClosed); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } + } + } else { + // Add section mode. Add section. + myEditor.addSection(aType, isClosed, myEditSecPnts->getPoints()); + addSectionItem(aType, isClosed); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } +} + +//======================================================================= +// function: secButtonClicked +// purpose: +//======================================================================= +void CurveCreator_Widget::addModifChanged(int theId) +{ + if (theId == SECTION_ADD) { + // Add section + myAddSecGrp->setTitle(tr("CC_SECTION_ADD_TITLE")); + mySecAddModifBtn->setText(tr("CC_SECTION_NEW")); + myEditSecPnts->setEnabled(true); + mySecAddModifBtn->setEnabled(true); + } else { + // Modify section + myAddSecGrp->setTitle(tr("CC_SECTION_MODIFICATION_TITLE")); + mySecAddModifBtn->setText(tr("CC_SECTION_MODIFY")); + myEditSecPnts->setEnabled(false); + changeSecSelection(); + } +} + +//======================================================================= +// function: changeSecSelection +// purpose: +//======================================================================= +void CurveCreator_Widget::changeSecSelection() +{ + // Update modify button and section data. + QList aListItems = mySecList->selectedItems(); + const int aNbItems = aListItems.size(); + + if (mySecBtnGrp->checkedId() == SECTION_MODIFY) { + // Modify section mode. + if (aNbItems == 1) { + // Initialize type and closed flags. + CurveCreator_Curve *aCurve = myEditor.getCurve(); + const int anIndex = mySecList->row(aListItems.first()); + + mySecAddModifBtn->setEnabled(true); + mySecCloseChkBox->setChecked(aCurve->isClosed(anIndex)); + + if (aCurve->getType(anIndex) == CurveCreator::Polyline) { + mySecTypeCmbBox->setCurrentIndex(POLYLINE_INDEX); + } else { + mySecTypeCmbBox->setCurrentIndex(BSPLINE_INDEX); + } + } else if (mySecAddModifBtn->isEnabled()) { + mySecAddModifBtn->setEnabled(false); + } + } else { + // Add section mode. + mySecAddModifBtn->setEnabled(true); + } + + // Set enabled remove, up and down points. + bool isEnabled = (aNbItems > 0); + const int aCount = mySecList->count(); + + mySecRmBtn->setEnabled(isEnabled); + isEnabled &= (aNbItems < aCount); + mySecUpBtn->setEnabled(isEnabled); + mySecDownBtn->setEnabled(isEnabled); + mySecJoinBtn->setEnabled(aNbItems == 2); + + // Init points. + myPntsGrp->setEnabled(aNbItems == 1); + + if (aNbItems == 1) { + const int aSecIndex = mySecList->row(aListItems.first()); + + initPoints(aSecIndex); + } else { + initPoints(-1); + } +} + +//======================================================================= +// function: sectionRemove +// purpose: +//======================================================================= +void CurveCreator_Widget::sectionRemove() +{ + QList aListItems = mySecList->selectedItems(); + + if (!aListItems.empty()) { + QList aListRows; + + // Get items rows. + foreach(QListWidgetItem *anItem, aListItems) { + aListRows.append(mySecList->row(anItem)); + } + + // Delete items. + foreach(QListWidgetItem *anItem, aListItems) { + delete anItem; + } + + qSort(aListRows); + + // Delete points from curve. + const int aNbPnts = aListRows.size(); + int i; + + for (i = aNbPnts - 1; i >= 0; i--) { + myEditor.removeSection(aListRows[i]); + } + + // Set the new selection. + int aRow = aListRows[0]; + + if (aListRows[0] >= mySecList->count()) { + aRow = mySecList->count() - 1; + } + + if (aRow >= 0) { + mySecList->item(aRow)->setSelected(true); + } + + emit numberOfItemsChanged(mySecList); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } +} + +//======================================================================= +// function: sectionJoin +// purpose: +//======================================================================= +void CurveCreator_Widget::sectionJoin() +{ + QList aListItems = mySecList->selectedItems(); + + if (aListItems.size() == 2) { + int aRowTo = mySecList->row(aListItems.first()); + int aRowFrom = mySecList->row(aListItems.last()); + + if (aRowTo > aRowFrom) { + // Swap rows. + int aTmp = aRowTo; + + aRowTo = aRowFrom; + aRowFrom = aTmp; + } + + // Join two sections. + myEditor.join(aRowTo, aRowFrom); + delete mySecList->takeItem(aRowFrom); + emit numberOfItemsChanged(mySecList); + // Select the joined item. + mySecList->item(aRowTo)->setSelected(true); + changeSecSelection(); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } +} + +//======================================================================= +// function: sectionJoinAll +// purpose: +//======================================================================= +void CurveCreator_Widget::sectionJoinAll() +{ + const int aNbItems = mySecList->count(); + + if (aNbItems > 1) { + // Join two sections. + myEditor.join(); + + // Update mySecList. + for (int i = 1; i < aNbItems; i++) { + delete mySecList->takeItem(1); + } + + emit numberOfItemsChanged(mySecList); + // Select the joined item. + mySecList->item(0)->setSelected(true); + changeSecSelection(); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } +} + +//======================================================================= +// function: sectionClear +// purpose: +//======================================================================= +void CurveCreator_Widget::sectionClear() +{ + bool isEmpty = (mySecList->count() == 0); + + if (!isEmpty) { + mySecList->clear(); + myEditor.clear(); + emit numberOfItemsChanged(mySecList); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } +} + +//======================================================================= +// function: sectionUp +// purpose: +//======================================================================= +void CurveCreator_Widget::sectionUp() +{ + sectionMove(-1); +} + +//======================================================================= +// function: sectionDown +// purpose: +//======================================================================= +void CurveCreator_Widget::sectionDown() +{ + sectionMove(1); +} + +//======================================================================= +// function: onNumberOfItemsChanged +// purpose: +//======================================================================= +void CurveCreator_Widget::onNumberOfItemsChanged(QListWidget *theListWidget) +{ + if (theListWidget == mySecList) { + // List of sections is modified. + mySecJoinAllBtn->setEnabled(mySecList->count() > 1); + mySecClearBtn->setEnabled(mySecList->count() > 0); + } else { + // List of points is modified. + QList aListItems = myPntsList->selectedItems(); + const int aNbItems = aListItems.size(); + + myRmPntsBtn->setEnabled(aNbItems > 0); + } +} + +//======================================================================= +// function: changePntsSelection +// purpose: +//======================================================================= +void CurveCreator_Widget::changePntsSelection() +{ + // Update modify buttons and section data. + QList aListItems = myPntsList->selectedItems(); + const int aNbItems = aListItems.size(); + const int aCount = myPntsList->count(); + + myRmPntsBtn->setEnabled(aNbItems > 0); + myInsertPntsBtn->setEnabled(aCount == 0 || aNbItems == 1); +} + +//======================================================================= +// function: editPnt +// purpose: +//======================================================================= +void CurveCreator_Widget::editPnt(QListWidgetItem *theItem) +{ + if (theItem != NULL) { + if (myPntEditDlg == NULL) { + // Create the dialog. + myPntEditDlg = new CurveCreator_EditPntDlg(this, myDimension); + } + + // Get coordinates. + CurveCreator_PointItem *aPntItem = (CurveCreator_PointItem *)theItem; + CurveCreator::Coordinates aPoint; + + aPoint.push_back(aPntItem->getX()); + aPoint.push_back(aPntItem->getY()); + + if (myDimension == CurveCreator::Dim3d) { + aPoint.push_back(aPntItem->getZ()); + } + + myPntEditDlg->setPoint(aPoint); + + const int aResult = myPntEditDlg->exec(); + + if (aResult == QDialog::Accepted) { + // Get the section index. + const int aSectionIndex = getCurrentSectionIndex(); + + if (aSectionIndex >= 0) { + // Update the point. + const CurveCreator::Coordinates &aNewPoint = myPntEditDlg->getPoint(); + + if (myDimension == CurveCreator::Dim3d) { + aPntItem->setCoord(aNewPoint[0], aNewPoint[1], aNewPoint[2]); + } else { + aPntItem->setCoord(aNewPoint[0], aNewPoint[1]); + } + + // Update curve + const int aPntIndex = myPntsList->row(theItem); + + myEditor.setCoordinates(aNewPoint, aSectionIndex, aPntIndex); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } + } + } +} + +//======================================================================= +// function: pntsAdd +// purpose: +//======================================================================= +void CurveCreator_Widget::pntsAdd() +{ + const CurveCreator::Coordinates &aNewPoints = myEditPnts->getPoints(); + const int aNbCoords = aNewPoints.size(); + + if (aNbCoords > 0 && aNbCoords % myDimension == 0) { + // Get the section index. + const int aSectionIndex = getCurrentSectionIndex(); + + if (aSectionIndex >= 0) { + // Update list. + int i = 0; + + while (i < aNbCoords) { + const CurveCreator::TypeCoord aX = aNewPoints[i++]; + const CurveCreator::TypeCoord aY = aNewPoints[i++]; + + if (myDimension == CurveCreator::Dim3d) { + const CurveCreator::TypeCoord aZ = aNewPoints[i++]; + + new CurveCreator_PointItem(aX, aY, aZ, myPntsList); + } else { + new CurveCreator_PointItem(aX, aY, myPntsList); + } + } + + // Update curve + myEditor.addPoints(aNewPoints, aSectionIndex); + emit numberOfItemsChanged(myPntsList); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } + } +} + +//======================================================================= +// function: pntsInsert +// purpose: +//======================================================================= +void CurveCreator_Widget::pntsInsert() +{ + const CurveCreator::Coordinates &aNewPoints = myEditPnts->getPoints(); + const int aNbCoords = aNewPoints.size(); + + if (aNbCoords > 0 && aNbCoords % myDimension == 0) { + // Get the section index. + const int aSectionIndex = getCurrentSectionIndex(); + + if (aSectionIndex >= 0) { + // Get the selected point index. + int aPntIndex = -1; + QList aListPnts = myPntsList->selectedItems(); + + if (aListPnts.size() == 1) { + aPntIndex = myPntsList->row(aListPnts.first()); + } + + // Update list. + int i = 0; + int aRow = aPntIndex; + + while (i < aNbCoords) { + const CurveCreator::TypeCoord aX = aNewPoints[i++]; + const CurveCreator::TypeCoord aY = aNewPoints[i++]; + CurveCreator_PointItem *aNewItem = NULL; + + if (myDimension == CurveCreator::Dim3d) { + const CurveCreator::TypeCoord aZ = aNewPoints[i++]; + + aNewItem = new CurveCreator_PointItem(aX, aY, aZ); + } else { + aNewItem = new CurveCreator_PointItem(aX, aY); + } + + + if (aPntIndex < 0) { + // Append point. + myPntsList->addItem(aNewItem); + } else { + // Insert point. + myPntsList->insertItem(aRow++, aNewItem); + } + } + + // Update curve + myEditor.insertPoints(aNewPoints, aSectionIndex, aPntIndex); + emit numberOfItemsChanged(myPntsList); + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } + } +} + +//======================================================================= +// function: pntsRemove +// purpose: +//======================================================================= +void CurveCreator_Widget::pntsRemove() +{ + QList aListItems = myPntsList->selectedItems(); + const int aSectionIndex = getCurrentSectionIndex(); + + if (aSectionIndex >= 0 && aListItems.size() > 0) { + QList aListRows; + + // Get items rows. + foreach(QListWidgetItem *anItem, aListItems) { + aListRows.append(myPntsList->row(anItem)); + } + + // Delete items. + foreach(QListWidgetItem *anItem, aListItems) { + delete anItem; + } + + qSort(aListRows); + + // Delete points from curve. + const int aNbPnts = aListRows.size(); + int aNbPntsRm = 1; + int aCurRow = aListRows.last(); + int i; + + for (i = aNbPnts - 2; i >= 0; i--) { + if (aListRows[i] == aCurRow - 1) { + // This is the previous index. + aCurRow--; + aNbPntsRm++; + } else { + // This is not the previous index. Remove the current chain of points. + myEditor.removePoints(aSectionIndex, aCurRow, aNbPntsRm); + aCurRow = aListRows[i]; + aNbPntsRm = 1; + } + } + + // Remove last points. + myEditor.removePoints(aSectionIndex, aCurRow, aNbPntsRm); + + emit numberOfItemsChanged(myPntsList); + + // Set the new selection. + int aRow = aListRows.first(); + + if (aRow >= myPntsList->count()) { + aRow = myPntsList->count() - 1; + } + + if (aRow >= 0) { + myPntsList->item(aRow)->setSelected(true); + } + + // Update undo/redo buttons. + updateUndoRedoButtons(); + } +} + +//======================================================================= +// function: undo +// purpose: +//======================================================================= +void CurveCreator_Widget::undo() +{ + if (myEditor.getNbUndo() > 0) { + // Perform undo + myEditor.undo(); + + // Reinitialize required widgets. + updateUndoRedo(); + } +} + +//======================================================================= +// function: redo +// purpose: +//======================================================================= +void CurveCreator_Widget::redo() +{ + if (myEditor.getNbRedo() > 0) { + // Perform undo + myEditor.redo(); + + // Reinitialize required widgets. + updateUndoRedo(); + } +} diff --git a/src/CurveCreator/CurveCreator_Widget.h b/src/CurveCreator/CurveCreator_Widget.h new file mode 100644 index 000000000..6323987b6 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Widget.h @@ -0,0 +1,160 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_Widget.h +// Created: Mon Jul 01 12:49:21 2013 +// Author: Sergey KHROMOV +// + +#ifndef _CurveCreator_Widget_HeaderFile +#define _CurveCreator_Widget_HeaderFile + + +#include +#include + +class CurveCreator_Curve; +class QGroupBox; +class QButtonGroup; +class QComboBox; +class QCheckBox; +class QPushButton; +class QLabel; +class QListWidget; +class QListWidgetItem; +class CurveCreator_EditPntsWidget; +class CurveCreator_EditPntDlg; +class CurveCreator_UndoOptsDlg; + + +class CurveCreator_Widget : public QWidget +{ + Q_OBJECT + +public: + + CurveCreator_Widget(QWidget* parent, + CurveCreator_Curve *theCurve, + Qt::WindowFlags fl = 0); + +private: + + void init(); + + void initSections(); + + void addSectionItem(const CurveCreator::Type theType, const bool isClosed); + + void updateSectionItem(const int theRow, const CurveCreator::Type theType, + const bool isClosed); + + void sectionMove(const int theShift); + + void initPoints(const int theSectionIndex); + + int getCurrentSectionIndex(); + + void updateUndoRedo(); + + void updateUndoRedoButtons(); + + void setTabOrder(); + +private slots: + + void undoOptionsChanged(); + + void sectionAddOrModify(); + + void addModifChanged(int theId); + + void changeSecSelection(); + + void sectionRemove(); + + void sectionJoin(); + + void sectionJoinAll(); + + void sectionClear(); + + void sectionUp(); + + void sectionDown(); + + void onNumberOfItemsChanged(QListWidget *theListWidget); + + void changePntsSelection(); + + void editPnt(QListWidgetItem *theItem); + + void pntsAdd(); + + void pntsInsert(); + + void pntsRemove(); + + void undo(); + + void redo(); + +signals: + + void numberOfItemsChanged(QListWidget *theListWidget); + +protected: + + CurveCreator_CurveEditor myEditor; + CurveCreator::Dimension myDimension; + // Undo/redo widgets + QLabel *myEnabledUndoLbl; + QLabel *myBufSizeUndoLbl; + QPushButton *myUndoBtn; + QPushButton *myRedoBtn; + QPushButton *myUndoOptsBtn; + CurveCreator_UndoOptsDlg *myUndoOptsDlg; + // Sections widgets + QGroupBox *myAddSecGrp; + QButtonGroup *mySecBtnGrp; + QComboBox *mySecTypeCmbBox; + QCheckBox *mySecCloseChkBox; + QPushButton *mySecAddModifBtn; + QPushButton *mySecRmBtn; + QPushButton *mySecJoinBtn; + QPushButton *mySecJoinAllBtn; + QPushButton *mySecClearBtn; + QPushButton *mySecUpBtn; + QPushButton *mySecDownBtn; + QListWidget *mySecList; + CurveCreator_EditPntsWidget *myEditSecPnts; + // Points widgets + QGroupBox *myPntsGrp; + QListWidget *myPntsList; + CurveCreator_EditPntDlg *myPntEditDlg; + CurveCreator_EditPntsWidget *myEditPnts; + QPushButton *myAddPntsBtn; + QPushButton *myInsertPntsBtn; + QPushButton *myRmPntsBtn; + +}; + +#endif diff --git a/src/CurveCreator/Makefile.am b/src/CurveCreator/Makefile.am new file mode 100644 index 000000000..51528e05b --- /dev/null +++ b/src/CurveCreator/Makefile.am @@ -0,0 +1,97 @@ +# Copyright (C) 2007-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 : Makefile.am +# Author : Sergey KHROMOV +# Modified by : +# Module : GEOM +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# Libraries targets +lib_LTLIBRARIES = libCurveCreator.la + +# Sources files +dist_libCurveCreator_la_SOURCES = \ + CurveCreator_Macro.hxx \ + CurveCreator.hxx \ + CurveCreator_Operation.hxx \ + CurveCreator_Diff.hxx \ + CurveCreator_Section.hxx \ + CurveCreator_Curve.hxx \ + CurveCreator_CurveEditor.hxx \ + CurveCreator_Operation.cxx \ + CurveCreator_Diff.cxx \ + CurveCreator_Curve.cxx \ + CurveCreator_CurveEditor.cxx + +# Header files +salomeinclude_HEADERS = \ + CurveCreator_Macro.hxx \ + CurveCreator.hxx \ + CurveCreator_Operation.hxx \ + CurveCreator_Diff.hxx \ + CurveCreator_Section.hxx \ + CurveCreator_Curve.hxx \ + CurveCreator_CurveEditor.hxx + +# Compilation options for GUI mode +if GEOM_ENABLE_GUI + dist_libCurveCreator_la_SOURCES += \ + CurveCreator_PointItem.h \ + CurveCreator_UndoOptsDlg.h \ + CurveCreator_EditPntDlg.h \ + CurveCreator_EditPntsDlg.h \ + CurveCreator_EditPntsWidget.h \ + CurveCreator_Widget.h \ + CurveCreator_PointItem.cxx \ + CurveCreator_UndoOptsDlg.cxx \ + CurveCreator_EditPntDlg.cxx \ + CurveCreator_EditPntsDlg.cxx \ + CurveCreator_EditPntsWidget.cxx \ + CurveCreator_Widget.cxx + + salomeinclude_HEADERS += \ + CurveCreator_PointItem.h \ + CurveCreator_UndoOptsDlg.h \ + CurveCreator_EditPntDlg.h \ + CurveCreator_EditPntsDlg.h \ + CurveCreator_EditPntsWidget.h \ + CurveCreator_Widget.h + + MOC_FILES = \ + CurveCreator_UndoOptsDlg_moc.cxx \ + CurveCreator_EditPntDlg_moc.cxx \ + CurveCreator_EditPntsDlg_moc.cxx \ + CurveCreator_EditPntsWidget_moc.cxx \ + CurveCreator_Widget_moc.cxx + + nodist_libCurveCreator_la_SOURCES = $(MOC_FILES) +endif + +# additional information to compile and link file + +libCurveCreator_la_CPPFLAGS = \ + $(QT_INCLUDES) \ + $(CAS_CPPFLAGS) \ + $(KERNEL_CXXFLAGS) + +libCurveCreator_la_LDFLAGS = \ + $(KERNEL_LDFLAGS) \ + $(CAS_KERNEL) diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index a853aa998..07b8d9356 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -4931,6 +4931,14 @@ Ignoring units will cause model scaling (as dimensions are supposed to be specif GEOM_SELECT_IMAGE Select image... + + CC_PNT_ITEM_X_Y + X=%1, Y=%2 + + + CC_PNT_ITEM_X_Y_Z + X=%1, Y=%2, Z=%3 + BasicGUI_CurveDlg @@ -5891,4 +5899,267 @@ Do you want to create new material? P&ublish And Close + + CurveCreator_Widget + + CC_TITLE + Curve Creator + + + CC_UNDO_REDO_TITLE + Undo/Redo operations + + + CC_UNDO + Undo + + + CC_REDO + Redo + + + CC_UNDO_REDO_ENABLED + Status: Enabled + + + CC_UNDO_REDO_DISABLED + Status: Disabled + + + CC_UNDO_REDO_BUFFER_SIZE + Undo buffer size: %1 + + + CC_UNDO_REDO_UNLIMITED + Unlimited + + + CC_UNDO_REDO_OPTIONS + Undo/Redo options + + + CC_UNDO_REDO_MODIFY + Modify + + + CC_SECTION_ADD_TITLE + Add section + + + CC_SECTION_MODIFICATION_TITLE + Section modification + + + CC_SECTION_TYPE + Type + + + CC_SECTION_CLOSED + Closed + + + CC_SECTION_NEW + New + + + CC_SECTION_MODIFY + Modify + + + CC_SECTION_POINTS_ADD_LBL + Add points + + + CC_SECTION_TITLE + Sections + + + CC_SECTION_MODIFY_TITLE + Modify section + + + CC_SECTION_REMOVE + Remove + + + CC_SECTION_JOIN + Join + + + CC_SECTION_JOIN_ALL + Join all + + + CC_SECTION_CLEAR + Clear + + + CC_SECTION_UP + Up + + + CC_SECTION_DOWN + Down + + + CC_POINTS_ADD_TITLE + Add points + + + CC_POINTS_MODIFICATION_TITLE + Points modification + + + CC_POINTS_ADD_LBL + Add points + + + CC_POINTS_ADD + Add + + + CC_POINTS_INSERT + Insert + + + CC_POINTS_TITLE + Points + + + CC_POINTS_REMOVE + Remove + + + CC_SECTION_ITEM + %1 + + + CC_SECTION_ITEM_CLOSED + %1, closed + + + CC_SECTION_ITEM_POLYLINE + Polyline + + + CC_SECTION_ITEM_BSPLINE + B-spline + + + CC_SECTION_TYPE_POLYLINE + Polyline + + + CC_SECTION_TYPE_BSPLINE + B-spline + + + + CurveCreator_EditPntsWidget + + CC_SECTION_POINTS_EDIT + Edit section points + + + CC_POINTS_EDIT + Edit points + + + CC_POINTS_NUMBER + %1 points + + + + CurveCreator_EditPntsDlg + + CC_EDIT_POINTS_TITLE + Edit points + + + CC_EDIT_POINTS_ADD_MODIFY + Add or modify points + + + CC_EDIT_POINTS_X + X : + + + CC_EDIT_POINTS_Y + Y : + + + CC_EDIT_POINTS_Z + Z : + + + CC_EDIT_POINTS_ADD + Add + + + CC_EDIT_POINTS_MODIFY + Modify + + + CC_EDIT_POINTS_REMOVE + Remove + + + CC_EDIT_POINTS_CLEAR + Clear + + + CC_EDIT_POINTS_UP + Up + + + CC_EDIT_POINTS_DOWN + Down + + + + CurveCreator_EditPntDlg + + CC_EDIT_POINT_TITLE + Edit point + + + CC_EDIT_POINT_MODIFY + Modify point + + + CC_EDIT_POINT_X + X : + + + CC_EDIT_POINT_Y + Y : + + + CC_EDIT_POINT_Z + Z : + + + + CurveCreator_UndoOptsDlg + + CC_UNDO_OPTIONS_TITLE + Undo/Redo options + + + CC_UNDO_OPTIONS_MODIFY + Modify + + + CC_UNDO_OPTIONS_DISABLED + Undo/Redo operations disabled + + + CC_UNDO_OPTIONS_FIXED_SIZE + Fixed Undo/Redo buffer size + + + CC_UNDO_OPTIONS_UNLIMITED + Unlimited Undo/Redo buffer size + + diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index de3a7b815..e41951780 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -527,6 +527,9 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam ) case GEOMOp::OpSharedShapes: // MENU OPERATION - GET SHARED SHAPES case GEOMOp::OpExtrudedBoss: // MENU OPERATION - EXTRUDED BOSS case GEOMOp::OpExtrudedCut: // MENU OPERATION - EXTRUDED CUT +#ifdef USE_CURVE_CREATOR + case GEOMOp::OpCurveCreator: // MENU OPERATION - CURVE CREATOR +#endif libName = "OperationGUI"; break; case GEOMOp::OpSewing: // MENU REPAIR - SEWING @@ -801,6 +804,9 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpSharedShapes, "GET_SHARED_SHAPES" ); createGeomAction( GEOMOp::OpExtrudedCut, "EXTRUDED_CUT" ); createGeomAction( GEOMOp::OpExtrudedBoss, "EXTRUDED_BOSS" ); +#ifdef USE_CURVE_CREATOR + createGeomAction( GEOMOp::OpCurveCreator, "CURVE_CREATOR" ); +#endif createGeomAction( GEOMOp::OpFillet1d, "FILLET_1D" ); createGeomAction( GEOMOp::OpFillet2d, "FILLET_2D" ); @@ -1035,6 +1041,10 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpChamfer, operId, -1 ); createMenu( GEOMOp::OpExtrudedBoss, operId, -1 ); createMenu( GEOMOp::OpExtrudedCut, operId, -1 ); +#ifdef USE_CURVE_CREATOR + createMenu( separator(), operId, -1 ); + createMenu( GEOMOp::OpCurveCreator, operId, -1 ); +#endif //createMenu( GEOMOp::OpClipping, operId, -1 ); int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 ); @@ -1195,6 +1205,9 @@ void GeometryGUI::initialize( CAM_Application* app ) createTool( GEOMOp::OpChamfer, featTbId ); createTool( GEOMOp::OpExtrudedBoss, featTbId ); createTool( GEOMOp::OpExtrudedCut, featTbId ); +#ifdef USE_CURVE_CREATOR + createTool( GEOMOp::OpCurveCreator, featTbId ); +#endif int buildTbId = createTool( tr( "TOOL_BUILD" ) ); createTool( GEOMOp::OpEdge, buildTbId ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index d170eec02..96da33991 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -145,6 +145,9 @@ namespace GEOMOp { OpSharedShapes = 3708, // MENU OPERATION - GET SHARED SHAPES OpExtrudedBoss = 3709, // MENU OPERATION - ETRUDED BOSS OpExtrudedCut = 3710, // MENU OPERATION - ETRUDED CUT +#ifdef USE_CURVE_CREATOR + OpCurveCreator = 3711, // MENU OPERATION - CURVE CREATOR +#endif // RepairGUI -------------------//-------------------------------- OpSewing = 4000, // MENU REPAIR - SEWING OpSuppressFaces = 4001, // MENU REPAIR - SUPPRESS FACES diff --git a/src/Makefile.am b/src/Makefile.am index 1c2ba31d1..12d24cbc1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,7 +24,7 @@ SUBDIRS = ARCHIMEDE NMTDS NMTTools BlockFix GEOMAlgo SKETCHER OCC2VTK GEOM \ BREPExport BREPImport IGESExport IGESImport STEPExport STEPImport \ STLExport VTKExport ShHealOper GEOMUtils GEOMImpl GEOM_I \ - GEOMClient GEOM_I_Superv GEOM_SWIG GEOM_PY + GEOMClient GEOM_I_Superv GEOM_SWIG GEOM_PY CurveCreator if WITH_OPENCV SUBDIRS += ShapeRecognition @@ -45,4 +45,4 @@ DIST_SUBDIRS = ARCHIMEDE NMTDS NMTTools BlockFix GEOMAlgo SKETCHER \ GEOMToolsGUI DisplayGUI BasicGUI PrimitiveGUI GenerationGUI \ EntityGUI BuildGUI BooleanGUI TransformationGUI OperationGUI \ RepairGUI MeasureGUI GroupGUI BlocksGUI AdvancedGUI \ - GEOM_SWIG_WITHIHM GEOM_PY ShapeRecognition + GEOM_SWIG_WITHIHM GEOM_PY ShapeRecognition CurveCreator diff --git a/src/OperationGUI/Makefile.am b/src/OperationGUI/Makefile.am index e41891a0b..95fae267c 100644 --- a/src/OperationGUI/Makefile.am +++ b/src/OperationGUI/Makefile.am @@ -86,11 +86,13 @@ libOperationGUI_la_CPPFLAGS = \ -I$(srcdir)/../GEOMAlgo \ -I$(srcdir)/../GEOM \ -I$(top_builddir)/src/DlgRef \ - -I$(top_builddir)/idl + -I$(top_builddir)/idl \ + -I$(srcdir)/../CurveCreator libOperationGUI_la_LDFLAGS = \ ../GEOMBase/libGEOMBase.la \ + ../CurveCreator/libCurveCreator.la \ $(CAS_LDPATH) -lTKFillet \ $(OPENCV_LIBS) ############################### diff --git a/src/OperationGUI/OperationGUI.cxx b/src/OperationGUI/OperationGUI.cxx index edf5edc80..9a3d971c3 100644 --- a/src/OperationGUI/OperationGUI.cxx +++ b/src/OperationGUI/OperationGUI.cxx @@ -45,6 +45,12 @@ #include "OperationGUI_GetSharedShapesDlg.h" #include "OperationGUI_ExtrudedFeatureDlg.h" // Methods EXTRUDED BOSS / CUT +#ifdef USE_CURVE_CREATOR +#include +#include +#include +#endif + //======================================================================= // function : OperationGUI() // purpose : Constructor @@ -86,6 +92,33 @@ bool OperationGUI::OnGUIEvent (int theCommandID, SUIT_Desktop* parent) case GEOMOp::OpExtrudedCut: (new OperationGUI_ExtrudedFeatureDlg (CUT, getGeometryGUI(), parent))->show(); break; case GEOMOp::OpFillet1d: (new OperationGUI_Fillet1d2dDlg (getGeometryGUI(), parent, true))->show(); break; case GEOMOp::OpFillet2d: (new OperationGUI_Fillet1d2dDlg (getGeometryGUI(), parent, false))->show(); break; +#ifdef USE_CURVE_CREATOR + // The following code is used for testing purpose only. + // To be removed when tested functionality is completed. + case GEOMOp::OpCurveCreator: + { + static CurveCreator_Curve *aStaticCurve = NULL; + + if (aStaticCurve == NULL) { + aStaticCurve = new CurveCreator_Curve(CurveCreator::Dim3d); + } + + QDialog *aDialog = new QDialog(parent); + QVBoxLayout *aMainLO = new QVBoxLayout; + QPushButton *aQuitButton = new QPushButton(tr("CC_CLOSE")); + CurveCreator_Widget *aWidget = + new CurveCreator_Widget (aDialog, aStaticCurve); + + connect(aQuitButton, SIGNAL(clicked()), aDialog, SLOT(close())); + aMainLO->addWidget(aWidget); + aMainLO->addWidget(aQuitButton); + + aDialog->setLayout(aMainLO); + aDialog->setAttribute(Qt::WA_DeleteOnClose); + aDialog->show(); + } + break; +#endif default: app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); }