From: Paul RASCLE Date: Mon, 6 Oct 2014 22:28:15 +0000 (+0000) Subject: correct merge BR_hydro_v1_0_3 on BR_quadtree X-Git-Tag: HYDRO_v1_0_3_quadtree~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1c640c1b3be696caa0348d7904794e899e8e4e69;p=modules%2Fhydro.git correct merge BR_hydro_v1_0_3 on BR_quadtree --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 132e4a90..a66ea384 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,7 +172,6 @@ MARK_AS_ADVANCED( # Sources # ======== -ADD_SUBDIRECTORY (src/HYDROCurveCreator) ADD_SUBDIRECTORY (src/HYDROData) ADD_SUBDIRECTORY (src/HYDROGUI) ADD_SUBDIRECTORY (src/HYDROPy) @@ -202,7 +201,7 @@ ENDIF(SALOME_BUILD_TESTS) IF(SALOME_BUILD_GUI) LIST(APPEND _${PROJECT_NAME}_exposed_targets - HYDROGUI HYDROCurveCreator + HYDROGUI ) ENDIF(SALOME_BUILD_GUI) diff --git a/src/HYDROCurveCreator/CMakeLists.txt b/src/HYDROCurveCreator/CMakeLists.txt deleted file mode 100644 index 2ff0e098..00000000 --- a/src/HYDROCurveCreator/CMakeLists.txt +++ /dev/null @@ -1,126 +0,0 @@ -# Copyright (C) 2012-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 -# - -IF(SALOME_BUILD_GUI) - INCLUDE(${QT_USE_FILE}) -ENDIF(SALOME_BUILD_GUI) - -# --- options --- - -# additional include directories -INCLUDE_DIRECTORIES( - ${QT_INCLUDE_DIRS} - ${PTHREAD_INCLUDE_DIR} - ${CAS_INCLUDE_DIRS} - ${KERNEL_INCLUDE_DIRS} - ${GUI_INCLUDE_DIRS} - ${GEOM_INCLUDE_DIRS} -) - -# additional preprocessor / compiler flags -ADD_DEFINITIONS( - -DCURVECREATOR_EXPORTS - ${CAS_DEFINITIONS} - ${QT_DEFINITIONS} -) - -# libraries to link to -SET(_link_LIBRARIES - ${GEOM_GEOMUtils} -) -IF(SALOME_BUILD_GUI) - LIST(APPEND _link_LIBRARIES - ${GUI_qtx} - ${GUI_suit} - ${GUI_OCCViewer} - ) -ENDIF(SALOME_BUILD_GUI) - -# --- headers --- - -IF(SALOME_BUILD_GUI) - # header files / to be processed by moc - SET(_moc_HEADERS - CurveCreator_NewSectionDlg.h - CurveCreator_TableView.h - CurveCreator_TreeView.h -# CurveCreator_UndoOptsDlg.h - CurveCreator_Widget.h - OCCViewer_Utilities.h - ) -ENDIF(SALOME_BUILD_GUI) - -# header files / no processing -SET(_other_HEADERS - CurveCreator.hxx - CurveCreator_Displayer.h - CurveCreator_Curve.hxx - CurveCreator_Diff.hxx - CurveCreator_ICurve.hxx - CurveCreator_Macro.hxx - CurveCreator_Operation.hxx - CurveCreator_Section.hxx - CurveCreator_Utils.h - CurveCreator_UtilsICurve.hxx - CurveCreator_PosPoint.hxx - CurveCreator_Profile.hxx -) - -# header files / to install -SET(HYDROCurveCreator_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) - -# --- sources --- - -IF(SALOME_BUILD_GUI) - # sources / moc wrappings - QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) -ENDIF(SALOME_BUILD_GUI) - -# sources / static -SET(_other_SOURCES - CurveCreator_Displayer.cxx - CurveCreator_Curve.cxx - CurveCreator_Diff.cxx - CurveCreator_Operation.cxx - CurveCreator_Utils.cxx - CurveCreator_UtilsICurve.cxx - CurveCreator_Profile.cxx -) -IF(SALOME_BUILD_GUI) - LIST(APPEND _other_SOURCES - CurveCreator_NewSectionDlg.cxx - CurveCreator_TableView.cxx - CurveCreator_TreeView.cxx -# CurveCreator_UndoOptsDlg.cxx - CurveCreator_Widget.cxx - OCCViewer_Utilities.cxx - ) -ENDIF(SALOME_BUILD_GUI) - -# sources / to compile -SET(HYDROCurveCreator_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) - -# --- rules --- - -ADD_LIBRARY(HYDROCurveCreator ${HYDROCurveCreator_SOURCES} ${HYDROCurveCreator_HEADERS}) -TARGET_LINK_LIBRARIES(HYDROCurveCreator ${_link_LIBRARIES} ${CAS_TKGeomAlgo}) -INSTALL(TARGETS HYDROCurveCreator EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) - -INSTALL(FILES ${HYDROCurveCreator_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) - diff --git a/src/HYDROCurveCreator/CurveCreator.hxx b/src/HYDROCurveCreator/CurveCreator.hxx deleted file mode 100644 index 9cd7ec72..00000000 --- a/src/HYDROCurveCreator/CurveCreator.hxx +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator.hxx -// Author: Sergey KHROMOV - -#ifndef _CurveCreator_HeaderFile -#define _CurveCreator_HeaderFile - -#include -#include -#include - -struct CurveCreator_Section; -struct CurveCreator_PosPoint; - -namespace CurveCreator -{ - //! Points coordinates - typedef float TypeCoord; - - /** List of coordinates in format depends on section dimension: - * 2D: [x1, y1, x2, y2, x3, y3, ..] - * 3D: [x1, y1, z1, x2, y2, z2, x3, y3, z3, ..] - */ - typedef std::deque Coordinates; - - //! List of sections - typedef std::deque Sections; - - // List of positioned points (points with coordinates) - typedef std::list PosPointsList; - //! Map of sections with positioned points - typedef std::map SectionsMap; -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.cxx b/src/HYDROCurveCreator/CurveCreator_Curve.cxx deleted file mode 100644 index 396c4038..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Curve.cxx +++ /dev/null @@ -1,1037 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_Curve.cxx -// Author: Sergey KHROMOV - -#include "CurveCreator_Curve.hxx" - -#include "CurveCreator.hxx" -#include "CurveCreator_PosPoint.hxx" -#include "CurveCreator_Section.hxx" -#include "CurveCreator_Displayer.h" -#include "CurveCreator_Utils.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -//======================================================================= -// function: Constructor -// purpose: -//======================================================================= -CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimension ) -: myIsLocked (false), - myDimension (theDimension), - myDisplayer (NULL), - myAISShape (NULL), - myNbUndos (0), - myNbRedos (0), - myUndoDepth (-1), - myOpLevel(0), - mySkipSorting(false) -{ -} - -//======================================================================= -// function: Destructor -// purpose: -//======================================================================= -CurveCreator_Curve::~CurveCreator_Curve() -{ - // Delete all allocated data. - clear(); -} - -//======================================================================= -// function: getDimension -// purpose: -//======================================================================= -CurveCreator::Dimension CurveCreator_Curve::getDimension() const -{ - return myDimension; -} - -//======================================================================= -// function: getUniqSectionName -// purpose: return unique section name -//======================================================================= -std::string CurveCreator_Curve::getUniqSectionName() const -{ - CurveCreator_Section* aSection; - for( int i = 0 ; i < 1000000 ; i++ ){ - char aBuffer[255]; - sprintf( aBuffer, "Section_%d", i+1 ); - std::string aName(aBuffer); - int j; - for( j = 0 ; j < mySections.size() ; j++ ){ - aSection = getSection( j ); - if ( aSection && aSection->myName == aName ) - break; - } - if( j == mySections.size() ) - return aName; - } - return ""; -} - -//======================================================================= -// function: setDisplayer -// purpose: set curve changes Displayer -//======================================================================= -void CurveCreator_Curve::setDisplayer( CurveCreator_Displayer* theDisplayer ) -{ - myDisplayer = theDisplayer; -} - -//======================================================================= -// function: getDisplayer -// purpose: get curve changes Displayer -//======================================================================= -CurveCreator_Displayer* CurveCreator_Curve::getDisplayer() -{ - return myDisplayer; -} - -//======================================================================= -// function: removeDisplayer -// purpose: remove the attached Displayer -//======================================================================= -void CurveCreator_Curve::removeDisplayer() -{ - myDisplayer = NULL; -} - -//======================================================================= -// function: addDiff -// purpose: -//======================================================================= -bool CurveCreator_Curve::addEmptyDiff() -{ - bool isEnabled = false; - - if (myUndoDepth != 0) { - // Forget all Redos after the current one. - if (myNbRedos > 0) { - myNbRedos = 0; - myListDiffs.erase(myCurrenPos, myListDiffs.end()); - } - - if (myUndoDepth == -1 || myNbUndos < myUndoDepth) { - // Increase the number of undos. - myNbUndos++; - } else { - // If there are too many differences, remove the first one. - myListDiffs.pop_front(); - } - - // Add new difference. - myListDiffs.push_back(CurveCreator_Diff()); - myCurrenPos = myListDiffs.end(); - isEnabled = true; - } - - return isEnabled; -} - -void CurveCreator_Curve::startOperation() -{ - myOpLevel++; -} - -void CurveCreator_Curve::finishOperation() -{ - myOpLevel--; -} - -//======================================================================= -// function: toICoord -// purpose: -//======================================================================= -int CurveCreator_Curve::toICoord(const int theIPnt) const -{ - return theIPnt * myDimension; -} - -//======================================================================= -// function: setUndoDepth -// purpose: -//======================================================================= -void CurveCreator_Curve::setUndoDepth(const int theDepth) -{ - if (theDepth == 0) { - // Reset all undo/redo data. - myNbUndos = 0; - myNbRedos = 0; - myListDiffs.clear(); - myCurrenPos = myListDiffs.end(); - myUndoDepth = 0; - } else if (theDepth == -1) { - // There is nothing to do as the depth become unlimited. - myUndoDepth = -1; - } else if (theDepth > 0) { - // The new "real" depth is set. - if (theDepth < myNbRedos) { - // The new depth is less then number of redos. Remove the latest redos. - int aShift = (myNbRedos - theDepth); - ListDiff::iterator aFromPos = myListDiffs.end(); - - while (aShift--) { - aFromPos--; - } - - myListDiffs.erase(aFromPos, myListDiffs.end()); - myNbRedos = theDepth; - } - - if (theDepth < myNbUndos + myNbRedos) { - // The new depth is less then the total number of differences. - // Remove the first undos. - int aShift = (myNbUndos + myNbRedos - theDepth); - ListDiff::iterator aToPos = myListDiffs.begin(); - - while (aShift--) { - aToPos++; - } - - myListDiffs.erase(myListDiffs.begin(), aToPos); - myNbUndos = theDepth - myNbRedos; - } - - myUndoDepth = theDepth; - } -} - -//======================================================================= -// function: getUndoDepth -// purpose: -//======================================================================= -int CurveCreator_Curve::getUndoDepth() const -{ - return myUndoDepth; -} - -void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const -{ - CurveCreator::Coordinates aCoords = getPoint( theISection, theIPoint ); - theX = aCoords[0]; - theY = aCoords[1]; - theZ = 0.; - if( getDimension() == CurveCreator::Dim3d ){ - theZ = aCoords[2]; - } -} - -void CurveCreator_Curve::redisplayCurve() -{ - if( myDisplayer ) { - myDisplayer->eraseAll( false ); - myAISShape = NULL; - - myDisplayer->display( getAISObject( true ), true ); - } -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::moveSectionInternal(const int theISection, - const int theNewIndex) -{ - bool res = false; - int aMovedSectionId = theISection >= 0 ? theISection : mySections.size()-1; - - if (aMovedSectionId != theNewIndex) { - CurveCreator_Section* aSection = getSection( aMovedSectionId ); - - // Remove section - CurveCreator::Sections::iterator anIter = mySections.begin() + aMovedSectionId; - - mySections.erase(anIter); - - // Insert section. - anIter = mySections.begin() + theNewIndex; - mySections.insert(anIter, aSection); - res = true; - } - return res; -} - -//======================================================================= -// function: moveSection -// purpose: -//======================================================================= -bool CurveCreator_Curve::moveSection(const int theISection, - const int theNewIndex) -{ - bool res = false; - // Set the difference. - startOperation(); - if (addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::MoveSection, - theISection, theNewIndex); - } - - // Update the curve. - res = moveSectionInternal(theISection, theNewIndex); - finishOperation(); - return res; -} - -/************ Implementation of INTERFACE methods ************/ - -/***********************************************/ -/*** Undo/Redo methods ***/ -/***********************************************/ - -//! Get number of available undo operations -int CurveCreator_Curve::getNbUndo() const -{ - return myNbUndos; -} - -//! Undo previous operation -bool CurveCreator_Curve::undo() -{ - bool res = false; - if (myNbUndos > 0) { - myNbUndos--; - myNbRedos++; - myCurrenPos--; - myCurrenPos->applyUndo(this); - res = true; - } - return res; -} - -//! Get number of available redo operations -int CurveCreator_Curve::getNbRedo() const -{ - return myNbRedos; -} - -//! Redo last previously "undone" operation -bool CurveCreator_Curve::redo() -{ - bool res = false; - if (myNbRedos > 0) { - myCurrenPos->applyRedo(this); - myCurrenPos++; - myNbRedos--; - myNbUndos++; - res = true; - } - return res; -} - -/***********************************************/ -/*** Section methods ***/ -/***********************************************/ -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::clearInternal() -{ - // erase curve from the viewer - if( myDisplayer ) { - myDisplayer->eraseAll( true ); - myAISShape = NULL; - } - // Delete all allocated data. - int i = 0; - const int aNbSections = getNbSections(); - - CurveCreator_Section* aSection; - for (; i < aNbSections; i++) { - aSection = getSection( i ); - if ( aSection ) - delete aSection; - } - - mySections.clear(); - - return true; -} - -//======================================================================= -// function: clear -// purpose: -//======================================================================= -bool CurveCreator_Curve::clear() -{ - bool res = false; - startOperation(); - // Set the difference. - if (addEmptyDiff()) { - myListDiffs.back().init(this); - } - res = clearInternal(); - finishOperation(); - return res; -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::joinInternal( const std::list& theSections ) -{ - bool res = false; - if ( theSections.empty() ) - return res; - - int anISectionMain = theSections.front(); - CurveCreator_Section* aSectionMain = getSection( anISectionMain ); - - std::list aSectionsToJoin = theSections; - aSectionsToJoin.erase( aSectionsToJoin.begin() ); // skip the main section - // it is important to sort and reverse the section ids in order to correctly remove them - aSectionsToJoin.sort(); - aSectionsToJoin.reverse(); - - std::list::const_iterator anIt = aSectionsToJoin.begin(), aLast = aSectionsToJoin.end(); - CurveCreator_Section* aSection; - for (; anIt != aLast; anIt++) { - aSection = getSection( *anIt ); - aSectionMain->myPoints.insert(aSectionMain->myPoints.end(), aSection->myPoints.begin(), - aSection->myPoints.end()); - res = removeSectionInternal(*anIt); - if ( !res ) - break; - } - - redisplayCurve(); - return res; -} - -bool CurveCreator_Curve::join( const std::list& theSections ) -{ - bool res = false; - - if ( !theSections.empty() ) - { - startOperation(); - if (addEmptyDiff()) - myListDiffs.back().init(this, CurveCreator_Operation::Join, theSections); - - res = joinInternal( theSections ); - - finishOperation(); - } - return res; -} - -//! Get number of sections -int CurveCreator_Curve::getNbSections() const -{ - return mySections.size(); -} - -//! For internal use only! Undo/Redo are not used here. -int CurveCreator_Curve::addSectionInternal - (const std::string& theName, const CurveCreator::SectionType theType, - const bool theIsClosed, const CurveCreator::Coordinates &thePoints) -{ - CurveCreator_Section *aSection = new CurveCreator_Section; - - std::string aName = theName; - if( aName.empty() ){ - aName = getUniqSectionName(); - } - aSection->myName = aName; - aSection->myType = theType; - aSection->myIsClosed = theIsClosed; - aSection->myPoints = thePoints; - mySections.push_back(aSection); - redisplayCurve(); - return mySections.size()-1; -} - -//======================================================================= -// function: addSection -// purpose: adds an empty section -//======================================================================= -int CurveCreator_Curve::addSection - (const std::string& theName, const CurveCreator::SectionType theType, - const bool theIsClosed) -{ - int resISection = -1; - // Set the difference. - startOperation(); - CurveCreator::Coordinates aCoords; //empty list - if (addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::AddSection, - theName, aCoords, theType, theIsClosed); - } - - resISection = addSectionInternal(theName, theType, theIsClosed, aCoords); - - finishOperation(); - return resISection; -} -//======================================================================= -// function: addSection -// purpose: adds a section with the given points -//======================================================================= -int CurveCreator_Curve::addSection - (const std::string& theName, const CurveCreator::SectionType theType, - const bool theIsClosed, const CurveCreator::Coordinates &thePoints) -{ - int resISection = -1; - // Set the difference. - startOperation(); - if (addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::AddSection, - theName, thePoints, theType, theIsClosed); - } - - resISection = addSectionInternal(theName, theType, theIsClosed, thePoints); - - finishOperation(); - return resISection; -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::removeSectionInternal( const int theISection ) -{ - if (theISection == -1) { - delete mySections.back(); - mySections.pop_back(); - } else { - CurveCreator::Sections::iterator anIterRm = mySections.begin() + theISection; - - delete *anIterRm; - mySections.erase(anIterRm); - } - redisplayCurve(); - return true; -} - -//! Removes the given sections. -bool CurveCreator_Curve::removeSection( const int theISection ) -{ - bool res = false; - // Set the difference. - startOperation(); - if (addEmptyDiff()) - myListDiffs.back().init(this, CurveCreator_Operation::RemoveSection, theISection); - - res = removeSectionInternal( theISection ); - - finishOperation(); - return res; -} - -/** - * Get number of points in specified section or (the total number of points - * in Curve if theISection is equal to -1). - */ -int CurveCreator_Curve::getNbPoints( const int theISection ) const -{ - int aNbCoords = 0; - - CurveCreator_Section* aSection; - if (theISection == -1) { - int i = 0; - const int aNbSections = getNbSections(); - - for (; i < aNbSections; i++) { - aSection = getSection( i ); - if ( aSection ) - aNbCoords += aSection->myPoints.size(); - } - } else { - aSection = getSection( theISection ); - if ( aSection ) - aNbCoords = aSection->myPoints.size(); - } - - return aNbCoords/myDimension; -} - -void CurveCreator_Curve::setSkipSorting( const bool theIsToSkip ) -{ - mySkipSorting = theIsToSkip; -} - -bool CurveCreator_Curve::canPointsBeSorted() -{ - return false; -} - -/** - * Saves points coordinates difference. - * \param theOldCoords the old points coordinates - */ -void CurveCreator_Curve::saveCoordDiff( const SectionToPointCoordsList &theOldCoords ) -{ - // Set the difference. - startOperation(); - if (addEmptyDiff()) { - myListDiffs.back().init(this, theOldCoords); - } - finishOperation(); -} - -//! Get "closed" flag of the specified section -bool CurveCreator_Curve::isClosed( const int theISection ) const -{ - CurveCreator_Section* aSection = getSection( theISection ); - return aSection ? aSection->myIsClosed : false; -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setClosedInternal( const int theISection, - const bool theIsClosed ) -{ - CurveCreator_Section* aSection = 0; - if (theISection == -1) { - int aSize = mySections.size(); - int i; - - for (i = 0; i < aSize; i++) { - aSection = getSection( i ); - if( aSection ) { - aSection->myIsClosed = theIsClosed; - redisplayCurve(); - } - } - } else { - aSection = getSection( theISection ); - if ( aSection ) { - aSection->myIsClosed = theIsClosed; - redisplayCurve(); - } - } - return true; -} - -/** - * Set "closed" flag of the specified section (all sections if - * \a theISection is -1). - */ -bool CurveCreator_Curve::setClosed( const int theISection, - const bool theIsClosed ) -{ - bool res = false; - // Set the difference. - startOperation(); - if (addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::SetClosed, - theIsClosed, theISection); - } - res = setClosedInternal( theISection, theIsClosed ); - finishOperation(); - return res; -} - -//! Returns specified section name -std::string CurveCreator_Curve::getSectionName( const int theISection ) const -{ - CurveCreator_Section* aSection = getSection( theISection ); - return aSection ? aSection->myName : ""; -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setSectionNameInternal( const int theISection, - const std::string& theName ) -{ - bool res = false; - CurveCreator_Section* aSection = getSection( theISection ); - if( aSection ) { - aSection->myName = theName; - res = true; - } - return res; -} - -/** Set name of the specified section */ -bool CurveCreator_Curve::setSectionName( const int theISection, - const std::string& theName ) -{ - bool res = false; - // Set the difference. - startOperation(); - if (addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::RenameSection, - theName, theISection); - } - res = setSectionNameInternal( theISection, theName ); - finishOperation(); - return res; -} - -//! Get type of the specified section -CurveCreator::SectionType CurveCreator_Curve::getSectionType - ( const int theISection ) const -{ - CurveCreator_Section* aSection = getSection( theISection ); - return aSection ? aSection->myType : CurveCreator::Polyline; -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setSectionTypeInternal( const int theISection, - const CurveCreator::SectionType theType ) -{ - CurveCreator_Section* aSection; - if (theISection == -1) { - int i = 0; - const int aNbSections = getNbSections(); - - for (; i < aNbSections; i++) { - aSection = getSection( i ); - if ( aSection ) - aSection->myType = theType; - } - redisplayCurve(); - } else { - aSection = getSection( theISection ); - if ( aSection && aSection->myType != theType ){ - aSection->myType = theType; - redisplayCurve(); - } - } - return true; -} - -/** - * Set type of the specified section (or all sections - * if \a theISection is -1). - */ -bool CurveCreator_Curve::setSectionType( const int theISection, - const CurveCreator::SectionType theType ) -{ - bool res = false; - startOperation(); - // Set the difference. - if (addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::SetType, - theType, theISection); - } - - res = setSectionTypeInternal( theISection, theType ); - - finishOperation(); - return res; -} - - -/***********************************************/ -/*** Point methods ***/ -/***********************************************/ - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ) -{ - bool res = false; - CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); - CurveCreator_Section *aSection = 0; - for ( ; anIt != theSectionsMap.end(); anIt++ ) { - int anISection = anIt->first; - aSection = getSection( anISection ); - if( aSection ) { - CurveCreator::PosPointsList aSectionPoints = anIt->second; - CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); - for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){ - int anIPnt = (*aPntIt)->myID; - CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords; - CurveCreator::Coordinates::iterator anIterPosition; - if(anIPnt == -1) - anIterPosition = aSection->myPoints.end(); - else - anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt); - CurveCreator::Coordinates::const_iterator aFirstPosition = - aCoords.begin(); - aSection->myPoints.insert(anIterPosition, - aCoords.begin(), aCoords.end()); - } - res = true; - } - } - if(res) - redisplayCurve(); - return res; -} - -/** - * Add one point to the specified section starting from the given theIPnt index - * (or at the end of points if \a theIPnt is -1). - */ -bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords, - const int theISection, - const int theIPnt ) -{ - bool res = false; - CurveCreator::Coordinates aCoords = theCoords; - // Set the difference. - startOperation(); - if (addEmptyDiff()) { - CurveCreator_ICurve::SectionToPointCoordsList aList; - aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords)); - myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints, - aList); - } - CurveCreator::SectionsMap aSectionsMap; - CurveCreator::PosPointsList aPoints; - CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords ); - aPoints.push_back( aPosPoint ); - aSectionsMap[theISection] = aPoints; - - res = addPointsInternal( aSectionsMap ); - - finishOperation(); - return res; -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ) -{ - bool res = false; - // Update the curve. - CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); - CurveCreator_Section *aSection = 0; - for ( ; anIt != theSectionsMap.end(); anIt++ ) { - int anISection = anIt->first; - aSection = getSection( anISection ); - if( aSection ) { - CurveCreator::PosPointsList aSectionPoints = anIt->second; - CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); - for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){ - int anIPnt = (*aPntIt)->myID; - CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords; - for ( int i = 0; i < myDimension; i++) - aSection->myPoints.at(toICoord(anIPnt) + i) = aCoords[i]; - } - res = true; - } - } - if(res) - redisplayCurve(); - - return res; -} - -//! Set coordinates of specified point -bool CurveCreator_Curve::setPoint( const int theISection, - const int theIPnt, - const CurveCreator::Coordinates& theNewCoords ) -{ - bool res = false; - // Set the difference. - startOperation(); - if (addEmptyDiff()) { - CurveCreator_ICurve::SectionToPointCoordsList aList; - aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords)); - myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates, - aList); - } - CurveCreator::SectionsMap aSectionsMap; - CurveCreator::PosPointsList aPoints; - CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords ); - aPoints.push_back( aPosPoint ); - aSectionsMap[theISection] = aPoints; - - int aSize1 = getNbPoints( theISection ); - res = setPointInternal( aSectionsMap ); - int aSize2 = getNbPoints( theISection ); - - finishOperation(); - - return res; -} - -//! Set coordinates of specified points from different sections -bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords, - const bool theIsToSaveDiff ) -{ - bool res = false; - // Set the difference. - startOperation(); - if (theIsToSaveDiff && addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates, - theSectionToPntCoords); - } - CurveCreator::SectionsMap aSectionsMap; - CurveCreator::PosPointsList aPosPoints; - CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = - theSectionToPntCoords.begin(), aLast = theSectionToPntCoords.end(); - int aSectionId, aPointId; - for ( ; anIt != aLast; anIt++ ) { - aPosPoints.clear(); - aSectionId = anIt->first.first; - aPointId = anIt->first.second; - CurveCreator::Coordinates aNewCoords = anIt->second; - CurveCreator_PosPoint* aPosPoint = - new CurveCreator_PosPoint( aPointId, aNewCoords ); - if( aSectionsMap.find(aSectionId) != aSectionsMap.end() ) - aPosPoints = aSectionsMap[aSectionId]; - aPosPoints.push_back( aPosPoint ); - aSectionsMap[aSectionId] = aPosPoints; - - } - res = setPointInternal( aSectionsMap ); - finishOperation(); - - return res; -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints ) -{ - bool aRes = false; - std::map > aConvPoints; - convert( thePoints, aConvPoints ); - std::map >::const_iterator anIt = aConvPoints.begin(), - aLast = aConvPoints.end(); - for ( ; anIt != aLast; anIt++ ) { - int aSectionId = anIt->first; - aRes = removeSectionPoints(aSectionId, anIt->second); - } - if( aRes) - redisplayCurve(); - - return aRes; -} - -//! Remove point with given id -bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt ) -{ - bool res = false; - // Set the difference. - startOperation(); - SectionToPointList aListOfSectionsToPoints; - aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt)); - if (addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints, - aListOfSectionsToPoints); - } - res = removePointsInternal( aListOfSectionsToPoints ); - finishOperation(); - return res; -} - -//! Remove several points from different sections with given ids -bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) -{ - bool res = false; - // Set the difference. - startOperation(); - if (addEmptyDiff()) { - myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints, - theSectionToPntIDs); - } - res = removePointsInternal( theSectionToPntIDs ); - finishOperation(); - return res; -} - - //======================================================================= -// function: getCoordinates -// purpose: -//======================================================================= -CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection, - const int theIPnt) const -{ - CurveCreator_Section* aSection = getSection( theISection ); - CurveCreator::Coordinates::const_iterator - anIter = aSection->myPoints.begin() + toICoord(theIPnt); - CurveCreator::Coordinates aResult(anIter, anIter + myDimension); - - return aResult; -} - -//======================================================================= -// function: getPoints -// purpose: -//======================================================================= -CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const -{ - CurveCreator_Section* aSection = getSection( theISection ); - return aSection ? aSection->myPoints : CurveCreator::Coordinates(); -} - -void CurveCreator_Curve::constructAISObject() -{ - TopoDS_Shape aShape; - CurveCreator_Utils::constructShape( this, aShape ); - - myAISShape = new AIS_Shape( aShape ); -} - -CurveCreator_Section* CurveCreator_Curve::getSection( const int theSectionId ) const -{ - CurveCreator_Section *aSection = 0; - if ( theSectionId >= 0 && theSectionId < mySections.size() ) - aSection = mySections.at( theSectionId ); - - return aSection; -} - -Handle(AIS_InteractiveObject) CurveCreator_Curve::getAISObject( const bool theNeedToBuild ) const -{ - if ( !myAISShape && theNeedToBuild ) { - CurveCreator_Curve* aCurve = (CurveCreator_Curve*)this; - aCurve->constructAISObject(); - } - return myAISShape; -} - -bool CurveCreator_Curve::removeSectionPoints( const int theSectionId, - const std::list& thePointIds ) -{ - bool aRes = false; - - CurveCreator_Section* aSection = getSection( theSectionId ); - if ( !aSection ) - return aRes; - - std::list aSectionPoints = thePointIds; - aSectionPoints.sort(); - std::list::const_reverse_iterator aPntIt = aSectionPoints.rbegin(); - for ( ; aPntIt != aSectionPoints.rend(); aPntIt++ ) { - int aPntIndx = *aPntIt; - CurveCreator::Coordinates::iterator aFirstPosition; - if ( aPntIndx == -1 ) - aFirstPosition = aSection->myPoints.end() - getDimension(); - else - aFirstPosition = aSection->myPoints.begin() + toICoord( aPntIndx ); - aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() ); - aRes = true; - } - return aRes; -} - -void CurveCreator_Curve::convert( const SectionToPointList& thePoints, - std::map< int, std::list >& theConvPoints ) -{ - theConvPoints.clear(); - - SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end(); - std::list aPoints; - int aSectionId, aPointId; - for ( ; anIt != aLast; anIt++ ) { - aSectionId = anIt->first; - aPointId = anIt->second; - aPoints.clear(); - if ( theConvPoints.find( aSectionId ) != theConvPoints.end() ) - aPoints = theConvPoints[aSectionId]; - aPoints.push_back( aPointId ); - theConvPoints[aSectionId] = aPoints; - } -} diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.hxx b/src/HYDROCurveCreator/CurveCreator_Curve.hxx deleted file mode 100644 index adcfc87a..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Curve.hxx +++ /dev/null @@ -1,328 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_Curve.hxx -// Author: Sergey KHROMOV - -#ifndef _CurveCreator_Curve_HeaderFile -#define _CurveCreator_Curve_HeaderFile - -#include "CurveCreator_ICurve.hxx" - -#include "CurveCreator_Macro.hxx" -#include "CurveCreator.hxx" -#include "CurveCreator_Diff.hxx" - -#include -#include - -struct CurveCreator_Section; -class CurveCreator_Displayer; -class AIS_Shape; -class Handle_AIS_InteractiveObject; - -/** - * The CurveCreator_Curve object is represented as one or more sets of - * connected points; thus CurveCreator_Curve object can contain several - * not connected curves (polylines or b-splines), each such curve has two - * only ends "start and end points" in other words non-manifold curves - * are not supported. - */ -class CURVECREATOR_EXPORT CurveCreator_Curve : public CurveCreator_ICurve -{ -protected: - typedef std::list ListDiff; - -public: - //! Constructor of the curve. - /** The dimension is explicitly specified in the constructor - * and cannot be changed later. - */ - CurveCreator_Curve(const CurveCreator::Dimension theDimension); - - //! Destructor. - virtual ~CurveCreator_Curve(); - - //! Get the dimension. - virtual CurveCreator::Dimension getDimension() const; - - //! Return unique section name - virtual std::string getUniqSectionName() const; - - //! Set curve creator Displayer object - virtual void setDisplayer( CurveCreator_Displayer* theDisplayer ); - - //! Return curve creator Displayer object - CurveCreator_Displayer* getDisplayer(); - - //! Remove curve creator Displayer object - virtual void removeDisplayer(); - - /** Set depth of undo operations (unlimited if \a theDepth is -1 - * or disabled if \a theDepth is 0) - */ - virtual void setUndoDepth(const int theDepth = -1); - - //! Get depth of undo operations. - virtual int getUndoDepth() const; - - virtual void startOperation(); - virtual void finishOperation(); - - /** - * This method converts the point index to the index in - * an array of coordinates. - */ - virtual int toICoord(const int theIPnt) const; - - //! For internal use only! Undo/Redo are not used here. - virtual bool moveSectionInternal(const int theISection, - const int theNewIndex); - //! Move section to new position in list - virtual bool moveSection(const int theISection, - const int theNewIndex); - -protected: - /** This method updates all undo/redo information required to be updated - * after curve modification operation. It returns false if undo/redo - * is disabled and true otherwise. - */ - virtual bool addEmptyDiff(); - -public: // TODO: remove public - void getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const; -protected: // TODO: remove public - void redisplayCurve(); - -public: - /************ Implementation of INTERFACE methods ************/ - - /***********************************************/ - /*** Undo/Redo methods ***/ - /***********************************************/ - - //! Get number of available undo operations - virtual int getNbUndo() const; - - //! Undo previous operation - virtual bool undo(); - - //! Get number of available redo operations - virtual int getNbRedo() const; - - //! Redo last previously "undone" operation - virtual bool redo(); - - - /***********************************************/ - /*** Section methods ***/ - /***********************************************/ - - //! For internal use only! Undo/Redo are not used here. - virtual bool clearInternal(); - //! Clear the polyline (remove all sections) - virtual bool clear(); - - //! For internal use only! Undo/Redo are not used here. - virtual bool joinInternal( const std::list& theSections ); - - //! Join list of sections to one section (join all if the list is empty) - // The first section in the list is a leader, another sections are joined to it - virtual bool join( const std::list& theSections ); - - //! Get number of sections - virtual int getNbSections() const; - - //! For internal use only! Undo/Redo are not used here. - virtual int addSectionInternal( const std::string &theName, - const CurveCreator::SectionType theType, - const bool theIsClosed, - const CurveCreator::Coordinates &thePoints); - //! Add a new section. - virtual int addSection( const std::string &theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ); - //! Add a new section. - virtual int addSection( const std::string &theName, - const CurveCreator::SectionType theType, - const bool theIsClosed, - const CurveCreator::Coordinates &thePoints); - - //! For internal use only! Undo/Redo are not used here. - virtual bool removeSectionInternal( const int theISection ); - //! Removes the given sections. - virtual bool removeSection( const int theISection ); - - //! Get "closed" flag of the specified section - virtual bool isClosed( const int theISection ) const; - - //! For internal use only! Undo/Redo are not used here. - virtual bool setClosedInternal( const int theISection, - const bool theIsClosed ); - /** - * Set "closed" flag of the specified section (all sections if - * \a theISection is -1). - */ - virtual bool setClosed( const int theISection, - const bool theIsClosed ); - - //! Returns specifyed section name - virtual std::string getSectionName( const int theISection ) const; - - //! For internal use only! Undo/Redo are not used here. - virtual bool setSectionNameInternal( const int theISection, - const std::string& theName ); - /** Set name of the specified section */ - virtual bool setSectionName( const int theISection, - const std::string& theName ); - - //! Get type of the specified section - virtual CurveCreator::SectionType getSectionType( const int theISection ) const; - - //! For internal use only! Undo/Redo are not used here. - virtual bool setSectionTypeInternal( const int theISection, - const CurveCreator::SectionType theType ); - /** - * Set type of the specified section (or all sections - * if \a theISection is -1). - */ - virtual bool setSectionType( const int theISection, - const CurveCreator::SectionType theType ); - - - /***********************************************/ - /*** Point methods ***/ - /***********************************************/ - - //! For internal use only! Undo/Redo are not used here. - virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ); - /** - * Add one point to the specified section starting from the given theIPnt index - * (or at the end of points if \a theIPnt is -1). - */ - virtual bool addPoints( const CurveCreator::Coordinates &theCoords, - const int theISection, - const int theIPnt = -1 ); - - //! For internal use only! Undo/Redo are not used here. - virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ); - //! Set coordinates of specified point - virtual bool setPoint( const int theISection, - const int theIPnt, - const CurveCreator::Coordinates& theNewCoords ); - - //! Set coordinates of specified points from different sections - virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords, - const bool theIsToSaveDiff = true ); - - //! For internal use only! Undo/Redo are not used here. - virtual bool removePointsInternal( const SectionToPointList &thePoints ); - /** Remove point with given id */ - virtual bool removePoint( const int theISection, const int theIPnt = -1 ); - - //! Remove several points from different sections with given ids - virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs); - - //! Get coordinates of specified point - virtual CurveCreator::Coordinates getPoint( const int theISection, - const int theIPnt ) const; - - /** - * Get points of a section (the total points in Curve if theISection is equal to -1).. - */ - virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const; - - - /** - * Get number of points in specified section or (the total number of points - * in Curve if theISection is equal to -1). - */ - virtual int getNbPoints( const int theISection ) const; - - /** - * Set skip sorting flag. If the flag is true - points sorting will be skipped. - */ - virtual void setSkipSorting( const bool theIsToSkip ); - - /** - * Indicates whether the points can be sorted. - */ - virtual bool canPointsBeSorted(); - - /** - * Saves points coordinates difference. - * \param theOldCoords the old points coordinates - */ - virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords ); - - /***********************************************/ - /*** Presentation methods ***/ - /***********************************************/ - /** - * Get the curve AIS object - */ - virtual Handle_AIS_InteractiveObject getAISObject( const bool theNeedToBuild = false ) const; - -protected: - /** - * Removes the points from the section. It sortes the points and remove them - * in the decreasing order - * \param theSectionId a section index - * \param thePointIds a list of section points - */ - bool removeSectionPoints( const int theSectionId, - const std::list& thePointIds ); - /** - * Converts the list of pairs of section to point into map of a section to list of points - * \param thePoints an source list - * \param theConvPoints a converted map - */ - void convert( const SectionToPointList &thePoints, - std::map > &theConvPoints ); - -protected: - virtual void constructAISObject(); - /** - * Returns the section by the section index or NULL if the index is out of the section - * list range - * \param theSectionId the section index - */ - CurveCreator_Section* getSection( const int theSectionId ) const; - -protected: - bool mySkipSorting; - -public: - bool myIsLocked; - CurveCreator::Sections mySections; //!< curve data - CurveCreator::Dimension myDimension; //!< curve dimension - CurveCreator_Displayer* myDisplayer; //!< curve displayer - -private: - - int myNbUndos; - int myNbRedos; - ListDiff::iterator myCurrenPos; - ListDiff myListDiffs; - int myUndoDepth; - int myOpLevel; - AIS_Shape* myAISShape; //!< AIS shape -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.cxx b/src/HYDROCurveCreator/CurveCreator_Diff.cxx deleted file mode 100644 index d1a7dc32..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Diff.cxx +++ /dev/null @@ -1,619 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_Diff.cxx -// Author: Sergey KHROMOV - -#include "CurveCreator_Diff.hxx" -#include "CurveCreator_Curve.hxx" - -#include - -//======================================================================= -// function: Constructor -// purpose: -//======================================================================= -CurveCreator_Diff::CurveCreator_Diff() -: myNbUndos (0), - myPUndo (NULL), - myPRedo (NULL) -{ -} - -//======================================================================= -// function: Destructor -// purpose: -//======================================================================= -CurveCreator_Diff::~CurveCreator_Diff() -{ - clear(); -} - -//======================================================================= -// function: init -// purpose: -//======================================================================= -bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve) -{ - CurveCreator_Operation::Type aType = CurveCreator_Operation::Clear; - bool isOK = false; - - if (theCurve != NULL) { - clear(); - - // Set redo. - myPRedo = new CurveCreator_Operation; - - if (myPRedo->init(aType)) { - isOK = true; - - const int aNbSections = theCurve->getNbSections(); - - // 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]); - } - } - } - - 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; - default: - break; - } - } - - if (!isOK) { - clear(); - } - } - - return isOK; -} - -//======================================================================= -// function: init -// purpose: -//======================================================================= -bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const std::list& theParams) -{ - bool isOK = false; - - if (theCurve != NULL || theParams.empty()) { - clear(); - - // Set redo. - myPRedo = new CurveCreator_Operation; - - if (myPRedo->init(theType, theParams)) { - // Construct undo for different commands. - switch (theType) { - case CurveCreator_Operation::Join: - { - int aSectionMain = theParams.front(); - const int aNbPointsMain = theCurve->getNbPoints(aSectionMain); - - std::list aSectionsToJoin = theParams; - aSectionsToJoin.erase( aSectionsToJoin.begin() ); - // it is important to sort the section indices in order to correct perform undo - // for the move sections to the previous positions - aSectionsToJoin.sort(); - // 1rst undo for remove points from the main and n-1 undoes to contain joined sections - int aSectionsToJoinNb = aSectionsToJoin.size(); - int aNbUndos = 2*aSectionsToJoinNb + 1; - setNbUndos( aNbUndos ); - - // Add joined sections to undo - std::list::const_iterator anIt = aSectionsToJoin.begin(), - aLast = aSectionsToJoin.end(); - anIt = aSectionsToJoin.begin(); - int aLastSectionId = -1; - for (int i = 0; anIt != aLast && i < aSectionsToJoinNb; anIt++, i++) { - int anISection = *anIt; - isOK = addSectionToUndo( theCurve, anISection, myPUndo[i*2] ); - if (isOK) { - isOK = myPUndo[i*2+1].init(CurveCreator_Operation::MoveSection, - aLastSectionId, anISection); - if (!isOK) - break; - } - } - // Construct undo for RemovePoints command. - if (isOK) { - int aNbPointsInJoined = 0; - anIt = aSectionsToJoin.begin(); - for ( ; anIt != aLast; anIt++ ) - aNbPointsInJoined += theCurve->getNbPoints( *anIt ); - - int aJoinedSize = aNbPointsMain + aNbPointsInJoined; - CurveCreator_ICurve::SectionToPointList aSectionToPointList; - for (int anIPoint = aNbPointsMain; anIPoint < aJoinedSize; anIPoint++) - aSectionToPointList.push_back(std::make_pair(aSectionMain, anIPoint)); - - isOK = myPUndo[aNbUndos-1].init(CurveCreator_Operation::RemovePoints, aSectionToPointList); - } - } - 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 std::string& theName, - const CurveCreator::Coordinates &theCoords, - const int theIntParam1, - const int theIntParam2) -{ - bool isOK = false; - - if (theCurve != NULL) { - clear(); - - // Set redo. - myPRedo = new CurveCreator_Operation; - - if (myPRedo->init(theType, theName, theCoords, theIntParam1, theIntParam2)) { - // Construct undo for different commands. - switch (theType) { - case CurveCreator_Operation::AddSection: - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::RemoveSection, -1); - break; - } - } - } - if( !isOK ) - clear(); - return isOK; -} - -bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const std::string &theName, - const int theIntParam1 ) -{ - bool isOK = false; - myPRedo = new CurveCreator_Operation; - - if (myPRedo->init(theType, theName, theIntParam1 )) { - // Construct undo for different commands. - switch (theType) { - case CurveCreator_Operation::RenameSection: - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::RenameSection, - theCurve->getSectionName(theIntParam1), theIntParam1); - break; - } - } - if( !isOK ){ - clear(); - } - return isOK; -} - -bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const CurveCreator_ICurve::SectionToPointList &theParamList1) -{ - bool isOK = false; - - if (theCurve != NULL) { - clear(); - - // Set redo. - myPRedo = new CurveCreator_Operation; - - if (myPRedo->init(theType, theParamList1)) { - // Construct undo for different commands. - switch (theType) { - case CurveCreator_Operation::RemovePoints: - { - // Construct undo for RemovePoints command. - CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointCoords; - CurveCreator::Coordinates aPointsToAdd; - const CurveCreator::Dimension aDim = theCurve->getDimension(); - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end(); - std::list aPoints; - int aSectionId, aPointId; - for ( ; anIt != aLast; anIt++ ) { - aPointsToAdd.clear(); - aSectionId = anIt->first; - aPointId = anIt->second; - const CurveCreator::Coordinates &aPoints = - theCurve->getPoints(aSectionId); - CurveCreator::Coordinates::const_iterator anIterBegin = - aPoints.begin() + (aDim*aPointId); - CurveCreator::Coordinates::const_iterator anIterEnd = - anIterBegin + aDim; - aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd); - aSectionToPointCoords.push_back(std::make_pair(*anIt, aPointsToAdd)); - } - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints, - aSectionToPointCoords); - } - break; - default: - break; - } - } - - if (!isOK) { - clear(); - } - } - - return isOK; -} - -bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1) -{ - bool isOK = false; - - if (theCurve != NULL) { - clear(); - - // Set redo. - myPRedo = new CurveCreator_Operation; - - if (myPRedo->init(theType, theParamList1)) { - // Construct undo for different commands. - switch (theType) { - case CurveCreator_Operation::InsertPoints: - { - // Construct undo for RemovePoints command. - CurveCreator_ICurve::SectionToPointList aSectionToPointList; - CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end(); - for ( ; anIt != aLast; anIt++ ) { - aSectionToPointList.push_back(anIt->first); - } - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, - aSectionToPointList); - } - break; - case CurveCreator_Operation::SetCoordinates: - { - // Construct undo for SetCoordinates command. - CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointOldCoords; - CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end(); - for ( ; anIt != aLast; anIt++ ) { - CurveCreator::Coordinates anOldCoords = theCurve->getPoint(anIt->first.first, anIt->first.second); - aSectionToPointOldCoords.push_back(std::make_pair(anIt->first, anOldCoords)); - } - - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates, - aSectionToPointOldCoords); - } - break; - default: - break; - } - } - - if (!isOK) { - clear(); - } - } - - return isOK; -} - -bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, - const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList) -{ - bool isOK = false; - - if (theCurve != NULL && theOldParamList.size() > 0) { - clear(); - - // Set redo. - myPRedo = new CurveCreator_Operation; - - // Construct redo for SetCoordinates command. - CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointActualCoords; - CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = - theOldParamList.begin(), aLast = theOldParamList.end(); - for ( ; anIt != aLast; anIt++ ) { - CurveCreator::Coordinates anActualCoords = theCurve->getPoint(anIt->first.first, anIt->first.second); - aSectionToPointActualCoords.push_back(std::make_pair(anIt->first, anActualCoords)); - } - - if (myPRedo->init(CurveCreator_Operation::SetCoordinates, aSectionToPointActualCoords)) { - // Undo for SetCoordinates command. - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates, - theOldParamList); - } - - 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 std::string aName = theCurve->getSectionName(theIndex); - const CurveCreator::Coordinates &aPnts = theCurve->getPoints(theIndex); - const CurveCreator::SectionType aType = theCurve->getSectionType(theIndex); - const bool isClosed = theCurve->isClosed(theIndex); - - bool isOK = theOperation.init(CurveCreator_Operation::AddSection, - aName, aPnts, aType, isClosed); - - return isOK; -} - -//======================================================================= -// function: setTypeOrClosedToUndo -// purpose: -//======================================================================= -bool CurveCreator_Diff::setTypeOrClosedToUndo - (const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const int theIntParam1, - const int theIntParam2) -{ - bool isOK = true; - - // Compute number of modified sections. - const bool isSetType = (theType == CurveCreator_Operation::SetType); - int aNbModif = 0; - std::list aListOfInd; - int aValue; - int i; - - if (theIntParam2 == -1) { - // The operation is applied to all sections. We need to collect - // really modified sections for undo. - const int aNbSections = theCurve->getNbSections(); - - if (aNbSections > 0) { - // Get sections to be modified. - for (i = 0; i < aNbSections; i++) { - if (isSetType) { - aValue = theCurve->getSectionType(i); - } else { - aValue = theCurve->isClosed(i); - } - - if (theIntParam1 != aValue) { - aNbModif++; - aListOfInd.push_back(i); - } - } - - if (aNbSections == aNbModif) { - // All sections are modified. We can use one single command - // with -1 section index. - aNbModif = 1; - aListOfInd.clear(); - aListOfInd.push_back(-1); - } - } - } else { - // There is only particular section modified. - // Check if there is a real modification required. - if (isSetType) { - aValue = theCurve->getSectionType(theIntParam2); - } else { - aValue = theCurve->isClosed(theIntParam2); - } - - if (theIntParam1 != aValue) { - aNbModif = 1; - aListOfInd.push_back(theIntParam2); - } - } - - if (aNbModif > 0) { - // Store the undos - std::list::iterator anIter = aListOfInd.begin(); - - if (isSetType) { - aValue = theCurve->getSectionType(*anIter); - } else { - aValue = theCurve->isClosed(*anIter); - } - - setNbUndos(aNbModif); - - for (i = 0; anIter != aListOfInd.end() && isOK; i++, anIter++) { - isOK = myPUndo[i].init(theType, aValue, *anIter); - } - } - - return isOK; -} diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.hxx b/src/HYDROCurveCreator/CurveCreator_Diff.hxx deleted file mode 100644 index f55f5306..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Diff.hxx +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_Diff.hxx -// Author: Sergey KHROMOV - -#ifndef _CurveCreator_Diff_HeaderFile -#define _CurveCreator_Diff_HeaderFile - -#include "CurveCreator_Operation.hxx" - -class CurveCreator_Curve; - - -/** - * This is the support class for store/retrieve differences of undo/redo - * operations. To fill the difference it is necessary to create it with - * an appropriate type and to call the method initialize with required - * parameters. - */ -class CurveCreator_Diff -{ - -private: - -public: - - /** - * Constructor. - */ - CurveCreator_Diff(); - - /** - * Destructor. - */ - ~CurveCreator_Diff(); - - /** - * This method initializes the difference with an operation without - * parameters. It is applicable to the following operations: - *
    - *
  • Clear
  • - *
- */ - bool init(const CurveCreator_Curve *theCurve); - - /** - * 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
  • - *
- */ - 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 two integer - * parameters. It is applicable to the following operations: - *
    - *
  • Join (with a list of int arguments)
  • - *
- */ - bool init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const std::list& theParams); - - /** - * This method initializes the difference with an operation with one - * Name, one CurveCreator::Coordinates parameter and two integer parameters. - * It is applicable to the following operations: - *
    - *
  • AddSection
  • - *
- */ - bool init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const std::string& theName, - const CurveCreator::Coordinates &theCoords, - const int theIntParam1, - const int theIntParam2); - - /** - * This method initializes the difference with an operation with one - * string and one integer parameters. - * It is applicable to the following operations: - *
    - *
  • RenameSection
  • - *
- */ - bool init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const std::string &theName, - const int theIntParam1 ); - - /** - * This method initializes the difference with an operation with - * list of pairs of integer parameters. - * It is applicable to the following operations: - *
    - *
  • RemovePoints
  • - *
- */ - bool init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const CurveCreator_ICurve::SectionToPointList &theParamList); - - /** - * This method initializes the difference with an operation with - * list of pairs of integer parameters with point coordinates. - * It is applicable to the following operations: - *
    - *
  • RemovePoints
  • - *
- */ - bool init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const CurveCreator_ICurve::SectionToPointCoordsList &theParamList); - - /** - * This method initializes the difference with an operation with - * list of pairs of integer parameters with point coordinates. - * \param theCurve the modified curve - * \param theOldParamList the old parameters (to be saved for undo) - */ - bool init(const CurveCreator_Curve *theCurve, - const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList); - - /** - * This method applies undo operation to theCurve. - */ - void applyUndo(CurveCreator_Curve *theCurve); - - /** - * This method applies redo operation to theCurve. - */ - void applyRedo(CurveCreator_Curve *theCurve); - -private: - - /** - * This method clears initialized data pointers. - */ - void clear(); - - /** - * This method sets the number of undos and allocates the required - * space for myPUndo. - */ - void setNbUndos(const int theNbUndos); - - /** - * This method returns the section index. It returns theIndex if it is - * a real index and the last section's index if theIndex is equal to -1. - */ - int getSectionIndex(const CurveCreator_Curve *theCurve, - const int theIndex) const; - - /** - * Convert theIndex'th section of theCurve into AddSection command - * and store it in theOperation. Returns true in case of success and - * false otherwise. - */ - bool addSectionToUndo(const CurveCreator_Curve *theCurve, - const int theIndex, - CurveCreator_Operation &theOperation) const; - - /** - * Construct undos for SetType and SetClosed operations. Note: the - * algorithm is optimized taking into account that there are only 2 types - * and 2 values of isClosed flag. If the number of types is increased, - * this algorithm should be re-implemented. - */ - bool setTypeOrClosedToUndo(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const int theIntParam1, - const int theIntParam2); - -private: - - int myNbUndos; - CurveCreator_Operation *myPUndo; - CurveCreator_Operation *myPRedo; - -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Displayer.cxx b/src/HYDROCurveCreator/CurveCreator_Displayer.cxx deleted file mode 100644 index 6bc8df52..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Displayer.cxx +++ /dev/null @@ -1,64 +0,0 @@ -#include "CurveCreator_Displayer.h" - -CurveCreator_Displayer::CurveCreator_Displayer( Handle_AIS_InteractiveContext theContext, - const int theZLayer ) : - myContext( theContext ), myZLayer( theZLayer ) -{ - myObjects.clear(); -} - -CurveCreator_Displayer::~CurveCreator_Displayer(void) -{ - eraseAll( true ); - for( int i = 0 ; i < myObjects.size() ; i++ ){ - myObjects[i].Nullify(); - } - myObjects.clear(); -} - -void CurveCreator_Displayer::display( const Handle(AIS_InteractiveObject)& theObject, bool isUpdate ) -{ - if ( theObject.IsNull() ) - return; - - myObjects.push_back( theObject ); - myContext->Display( theObject, Standard_False ); - - if ( myZLayer >= 0 ) - myContext->SetZLayer( theObject, myZLayer ); - - if( isUpdate ) - myContext->UpdateCurrentViewer(); -} - -void CurveCreator_Displayer::eraseAll( bool isUpdate ) -{ - if(myObjects.empty()) - return; - for( int i = 0 ; i < myObjects.size() ; i++ ){ - myContext->Erase(myObjects[i], Standard_False); - } - myObjects.clear(); - if( isUpdate ) - myContext->UpdateCurrentViewer(); -} - -Quantity_Color CurveCreator_Displayer::getActiveColor( bool isHL ) -{ - if( isHL ){ - return Quantity_Color( 1., 0., 0., Quantity_TOC_RGB ); - } - return Quantity_Color( 0., 1., 0., Quantity_TOC_RGB ); -} - -/*void CurveCreator_Displayer::highlight( const AISObjectsList& theObjects, bool isHL ) -{ - return; - //TODO: - Quantity_Color aColor = getActiveColor( isHL ); - for( int i = 0 ; i < theObjects.size() ; i++ ){ - theObjects[i]->SetColor(aColor); - myContext->Display(theObjects[i], Standard_False); - } - myContext->UpdateCurrentViewer(); -}*/ diff --git a/src/HYDROCurveCreator/CurveCreator_Displayer.h b/src/HYDROCurveCreator/CurveCreator_Displayer.h deleted file mode 100644 index f65e9d2e..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Displayer.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CURVECREATOR_DISPLAYER_H -#define CURVECREATOR_DISPLAYER_H - -#include "CurveCreator_Macro.hxx" - -#include -#include - -#include - -class CURVECREATOR_EXPORT CurveCreator_Displayer -{ -typedef std::vector AISObjectsList; - -public: - CurveCreator_Displayer( Handle_AIS_InteractiveContext theContext, - const int theZLayer = -1 ); - ~CurveCreator_Displayer(void); - - void display( const Handle_AIS_InteractiveObject& theObject, bool isUpdate ); - void eraseAll( bool isUpdate ); - //void highlight( const AISObjectsList& theObjects, bool isHL ); - -protected: - Quantity_Color getActiveColor( bool isHL ); - -private: - Handle_AIS_InteractiveContext myContext; - AISObjectsList myObjects; - int myZLayer; -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_ICurve.hxx b/src/HYDROCurveCreator/CurveCreator_ICurve.hxx deleted file mode 100644 index 9effa478..00000000 --- a/src/HYDROCurveCreator/CurveCreator_ICurve.hxx +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_ICurve.hxx -// Author: Alexander KOVALEV and Alexander SOLOVYOV - -#ifndef _CurveCreator_ICurve_HeaderFile -#define _CurveCreator_ICurve_HeaderFile - -#include "CurveCreator_Macro.hxx" -#include -#include -#include -#include - -class Handle_AIS_InteractiveObject; - -namespace CurveCreator -{ - //! Type of the section - enum SectionType - { - Polyline, - Spline, - }; - - //! Dimension of the curve - enum Dimension - { - Dim2d = 2, - Dim3d = 3 - }; - -}; - -/** - * The CurveCreator_ICurve object is represented as one or more sets of - * connected points; thus CurveCreator_ICurve object can contain several - * not connected curves (polylines or b-splines), each such curve has two - * only ends "start and end points" in other words non-manifold curves - * are not supported. - */ -class CURVECREATOR_EXPORT CurveCreator_ICurve -{ -public: - typedef std::pair SectionToPoint; - typedef std::deque SectionToPointList; - - typedef std::deque< std::pair< SectionToPoint,std::deque< float > > > SectionToPointCoordsList; - -public: - /***********************************************/ - /*** Undo/Redo methods ***/ - /***********************************************/ - - //! Get number of available undo operations - virtual int getNbUndo() const = 0; - - //! Undo previous operation - virtual bool undo() = 0; - - //! Get number of available redo operations - virtual int getNbRedo() const = 0; - - //! Redo last previously "undone" operation - virtual bool redo() = 0; - - - /***********************************************/ - /*** Section methods ***/ - /***********************************************/ - - //! Clear the polyline (remove all sections) - virtual bool clear() = 0; - - //! Join list of sections to one section (join all if the list is empty) - // The first section in the list is a leader, another sections are joined to it - virtual bool join( const std::list& theSections ) = 0; - - //! Get number of sections - virtual int getNbSections() const = 0; - - //! Add a new section. - virtual int addSection( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ) = 0; - - //! Removes the given sections. - virtual bool removeSection( const int theISection ) = 0; - - //! Get "closed" flag of the specified section - virtual bool isClosed( const int theISection ) const = 0; - - /** - * Set "closed" flag of the specified section (all sections if - * \a theISection is -1). - */ - virtual bool setClosed( const int theISection, - const bool theIsClosed ) = 0; - - //! Returns specifyed section name - virtual std::string getSectionName( const int theISection ) const = 0; - - /** Set name of the specified section */ - virtual bool setSectionName( const int theISection, - const std::string& theName ) = 0; - - //! Get type of the specified section - virtual CurveCreator::SectionType getSectionType( const int theISection ) const = 0; - - /** - * Set type of the specified section (or all sections - * if \a theISection is -1). - */ - virtual bool setSectionType( const int theISection, - const CurveCreator::SectionType theType ) = 0; - - - /***********************************************/ - /*** Point methods ***/ - /***********************************************/ - - //! Get the dimension. - virtual CurveCreator::Dimension getDimension() const = 0; - - /** - * Insert one or several points to the specified section starting from the given theIPnt index - * (or add these at the end of section points if \a theIPnt is -1). - */ - virtual bool addPoints( const std::deque& theCoords, - const int theISection, - const int theIPnt = -1 ) = 0; - - //! Set coordinates of specified point - virtual bool setPoint( const int theISection, - const int theIPnt, - const std::deque& theNewCoords ) = 0; - - //! Set coordinates of specified points from different sections - virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords, - const bool theIsToSaveDiff = true ) = 0; - - //! Remove point with given id - virtual bool removePoint( const int theISection, const int theIPnt = -1 ) = 0; - //! Remove several points from different sections - virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) = 0; - - //! Get coordinates of specified point - virtual std::deque getPoint( const int theISection, - const int theIPnt ) const = 0; - - /** - * Get points of a section (the total points in Curve if theISection is equal to -1).. - */ - virtual std::deque getPoints( const int theISection = -1 ) const = 0; - - /** - * Get number of points in specified section or (the total number of points - * in Curve if theISection is equal to -1). - */ - virtual int getNbPoints( const int theISection ) const = 0; - - /** - * Set skip sorting flag. If the flag is true - points sorting will be skipped. - */ - virtual void setSkipSorting( const bool ) = 0; - - /** - * Indicates whether the points can be sorted. - */ - virtual bool canPointsBeSorted() = 0; - - /** - * Saves points coordinates difference. - * \param theOldCoords the old points coordinates - */ - virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords ) = 0; - - /***********************************************/ - /*** Presentation methods ***/ - /***********************************************/ - - virtual Handle_AIS_InteractiveObject getAISObject( const bool theNeedToBuild = false ) const = 0; - -protected: - virtual void constructAISObject() = 0; - -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Listener.hxx b/src/HYDROCurveCreator/CurveCreator_Listener.hxx deleted file mode 100755 index 318abac2..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Listener.hxx +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef CURVE_CREATOR_LISTENER_HXX -#define CURVE_CREATOR_LISTENER_HXX - -class CurveCreator_Listener -{ -public: - CurveCreator_Listener(void){}; - virtual ~CurveCreator_Listener(void){}; - - virtual void pointChanged( int theSection, int thePoint ){} - virtual void pointRemoved( int theSection, int theFirstPoint){} - virtual void pointInserted( int theSection, int theIndx ){} - - virtual void sectionClosed( int theSection, bool isClosed ){} - virtual void sectionAdded( int theSection ){} - virtual void sectionRemoved( int theSection ){} - virtual void sectionTypeChanged( int theSection ){} - - virtual void curveChanged(){} -}; - -#endif \ No newline at end of file diff --git a/src/HYDROCurveCreator/CurveCreator_Macro.hxx b/src/HYDROCurveCreator/CurveCreator_Macro.hxx deleted file mode 100644 index ec814eb4..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Macro.hxx +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_Macro.hxx -// Author: Sergey KHROMOV - -#ifndef _CurveCreator_Macro_HeaderFile -#define _CurveCreator_Macro_HeaderFile - -#ifdef WNT - #if defined CURVECREATOR_EXPORTS || defined CurveCreator_EXPORTS - #if defined WIN32 - #define CURVECREATOR_EXPORT __declspec( dllexport ) - #else - #define CURVECREATOR_EXPORT - #endif - #else - #if defined WIN32 - #define CURVECREATOR_EXPORT __declspec( dllimport ) - #else - #define CURVECREATOR_EXPORT - #endif - #endif -#else - #define CURVECREATOR_EXPORT -#endif - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.cxx b/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.cxx deleted file mode 100644 index 526dfb71..00000000 --- a/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.cxx +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "CurveCreator_NewSectionDlg.h" -//#include "CurveCreator_Curve.hxx" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent, bool enableClosed ) : - QWidget(parent), myIsEnableClosed( enableClosed ) -{ - QVBoxLayout* aMainLayout = new QVBoxLayout( this ); - aMainLayout->setMargin( 0 ); - - QFrame* aFrame = new QFrame( this ); - aMainLayout->addWidget( aFrame ); - - QVBoxLayout* aLayout = new QVBoxLayout( aFrame ); - aLayout->setMargin( 0 ); - - QFrame* aCoordFrame = new QFrame( aFrame ); - QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame ); - - QLabel* aLbl = new QLabel(tr("NAME"), this); - myName = new QLineEdit(this); - aCoordLayout->addWidget(aLbl, 0, 0); - aCoordLayout->addWidget(myName, 0 , 1); - - aLbl = new QLabel(tr("LINE_TYPE")); - myLineType = new QComboBox(this); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); - QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); - -// QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE")); -// QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE")); - myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE")); - myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE")); - myLineType->setCurrentIndex(0); - aCoordLayout->addWidget(aLbl, 1, 0); - aCoordLayout->addWidget(myLineType, 1 , 1); - - aLbl = new QLabel(tr("LINE_CLOSED")); - myIsClosed = new QCheckBox(this); - aCoordLayout->addWidget(aLbl, 2, 0); - aCoordLayout->addWidget(myIsClosed, 2, 1); - if ( !myIsEnableClosed ) { - aLbl->hide(); - myIsClosed->hide(); - } - - myBtnFrame = new QFrame( aFrame ); - QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame ); - - myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame ); - myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame ); - - connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) ); - connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelSection() ) ); - - aBtnsLayout->addWidget( myAddBtn ); - aBtnsLayout->addStretch( 1 ); - aBtnsLayout->addWidget( myCancelBtn ); - - aLayout->addWidget( aCoordFrame, 0 ); - aLayout->addWidget( myBtnFrame, 1 ); -} - -void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::SectionType theType ) -{ - myName->setText(theName); - myIsClosed->setChecked(isClosed); - if( theType == CurveCreator::Polyline ) - myLineType->setCurrentIndex(0); - else - myLineType->setCurrentIndex(1); -} - -void CurveCreator_NewSectionDlg::clear() -{ - myName->setText(""); - myIsClosed->setChecked(true); - myLineType->setCurrentIndex(0); -} - -void CurveCreator_NewSectionDlg::setEditMode( bool isEdit ) -{ - myIsEdit = isEdit; - if( myIsEdit ){ - myAddBtn->setText(tr("OK")); - myAddBtn->disconnect( SIGNAL( clicked() ) ); - connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifySection() ) ); - } - else{ - myAddBtn->setText(tr("ADD_BTN")); - myAddBtn->disconnect( SIGNAL( clicked() ) ); - connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) ); - } - updateTitle(); -} - -QString CurveCreator_NewSectionDlg::getName() const -{ - return myName->text(); -} - -bool CurveCreator_NewSectionDlg::isClosed() const -{ - return myIsClosed->isChecked(); -} - -CurveCreator::SectionType CurveCreator_NewSectionDlg::getSectionType() const -{ - if( myLineType->currentIndex() == 0 ) - return CurveCreator::Polyline; - else - return CurveCreator::Spline; -} - -void CurveCreator_NewSectionDlg::updateTitle() -{ - QString aTitle; - if( !myIsEdit ) - aTitle = tr("ADD_NEW_SECTION"); - else - aTitle = QString(tr("SET_SECTION_PARAMETERS")); - setWindowTitle(aTitle); -} - -void CurveCreator_NewSectionDlg::setSectionName( const QString& theName ) -{ - myName->setText(theName); -} diff --git a/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.h b/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.h deleted file mode 100644 index d37ed117..00000000 --- a/src/HYDROCurveCreator/CurveCreator_NewSectionDlg.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef CURVECREATOR_NEWSECTION_H -#define CURVECREATOR_NEWSECTION_H - -#include "CurveCreator.hxx" -#include "CurveCreator_ICurve.hxx" - -#include - -//class CurveCreator_Curve; - -class QLineEdit; -class QComboBox; -class QCheckBox; -class QPushButton; -class QAbstractButton; -class QDialogButtonBox; -class QFrame; - -class CurveCreator_NewSectionDlg : public QWidget -{ - Q_OBJECT -public: - explicit CurveCreator_NewSectionDlg(QWidget *parent = 0, bool enableClosed = true ); - - QString getName() const; - bool isClosed() const; - CurveCreator::SectionType getSectionType() const; - - void setSectionParameters( const QString& theName, bool isClosed, CurveCreator::SectionType theType ); - void setSectionName(const QString& theName ); - void clear(); - void setEditMode( bool isEdit ); - bool isEnableClosed() const { return myIsEnableClosed; } - -signals: - void addSection(); - void modifySection(); - void cancelSection(); -public slots: -protected slots: -protected: - void updateTitle(); -private: - QFrame* myBtnFrame; - QLineEdit* myName; - QComboBox* myLineType; - QCheckBox* myIsClosed; - bool myIsEdit; - bool myIsEnableClosed; - QPushButton* myAddBtn; - QPushButton* myCancelBtn; -}; - -#endif // CURVECREATOR_NEWSECTION_H diff --git a/src/HYDROCurveCreator/CurveCreator_Operation.cxx b/src/HYDROCurveCreator/CurveCreator_Operation.cxx deleted file mode 100644 index 173e1c88..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Operation.cxx +++ /dev/null @@ -1,477 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_Operation.cxx -// Author: Sergey KHROMOV - -#include "CurveCreator_Operation.hxx" -#include "CurveCreator_Curve.hxx" -#include "CurveCreator.hxx" - -#include -#include -#include - -//======================================================================= -// function: Constructor -// purpose: -//======================================================================= -CurveCreator_Operation::CurveCreator_Operation() -: myType (CurveCreator_Operation::Unknown), - myPData (NULL) -{ -} - -//======================================================================= -// function: Destructor -// purpose: -//======================================================================= -CurveCreator_Operation::~CurveCreator_Operation() -{ - clear(); -} - -bool compId(CurveCreator_PosPoint* p1, CurveCreator_PosPoint* p2) -{ - return p1->myID < p2->myID; -} - -//======================================================================= -// function: Constructor -// purpose: -//======================================================================= -bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType) -{ - bool isOK = false; - - if (theType == CurveCreator_Operation::Clear) { - 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 Type theType, const std::list theParamList) -{ - bool isOK = false; - - if (theType == CurveCreator_Operation::Join) - { - const int aNbPoints = theParamList.size(); - - const size_t aSize = - sizeof(aNbPoints) + - aNbPoints * (sizeof(int)); - - int *pIntData = (int *)allocate(aSize); - - *pIntData++ = aNbPoints; - std::list::const_iterator anIt = theParamList.begin(), aLast = theParamList.end(); - for ( ; anIt != aLast; anIt++ ) - *pIntData++ = *anIt; - - 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 std::string& theName, - const CurveCreator::Coordinates &theCoords, - const int theIntParam1, - const int theIntParam2) -{ - bool isOK = false; - if (theType == CurveCreator_Operation::AddSection ) { - const int aNbCoords = theCoords.size(); - const size_t aSize = - 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord) + theName.length() + 1; - int *pIntData = (int *)allocate(aSize); - - *pIntData++ = theIntParam1; - *pIntData++ = theIntParam2; - char* aStrPtr = (char*)pIntData; - if( !theName.empty() ){ - strcpy( aStrPtr, theName.c_str() ); - aStrPtr += theName.length(); - } - else{ - *aStrPtr = 0; - } - aStrPtr++; - pIntData = (int*)aStrPtr; - *pIntData++ = aNbCoords; - - CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; - int i = 0; - - for (; i < aNbCoords; i++) { - *pRealData++ = theCoords[i]; - } - - myType = theType; - isOK = true; - } - - return isOK; -} - -bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, - const std::string &theName, - const int theIntParam1 ) -{ - if (theType == CurveCreator_Operation::RenameSection ) { - size_t aSize = sizeof(theIntParam1) + theName.length() + 1; - int *pIntData = (int *)allocate(aSize); - *pIntData = theIntParam1; - pIntData++; - if( !theName.empty() ){ - strcpy( (char*)pIntData, theName.c_str() ); - } - else{ - *((char*)pIntData) = 0; - } - myType = theType; - return true; - } - return false; -} - -bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, - const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1) -{ - bool isOK = false; - - if (theType == CurveCreator_Operation::InsertPoints || - theType == CurveCreator_Operation::SetCoordinates ) { - - const int aNbPoints = theParamList1.size(); - - CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = - theParamList1.begin(); - const int aNbCoords = anIt->second.size(); - - const size_t aSize = - sizeof(aNbPoints) + sizeof(aNbCoords) + - aNbPoints * (3*sizeof(int) + aNbCoords*sizeof(CurveCreator::TypeCoord)); - int *pIntData = (int *)allocate(aSize); - - *pIntData++ = aNbPoints; - *pIntData++ = aNbCoords; - int aSectionId, aPointId; - for ( ; anIt != theParamList1.end(); anIt++ ) { - aSectionId = anIt->first.first; - aPointId = anIt->first.second; - - *pIntData++ = aSectionId; - *pIntData++ = aPointId; - *pIntData++ = aNbCoords; - - const CurveCreator::Coordinates &aCoords = anIt->second; - CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; - for (int i = 0; i < aNbCoords; i++) { - *pRealData++ = aCoords[i]; - } - pIntData = (int *)pRealData; - } - - myType = theType; - isOK = true; - } - - return isOK; -} - -bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, - const CurveCreator_ICurve::SectionToPointList &theParamList1) -{ - bool isOK = false; - - if (theType == CurveCreator_Operation::RemovePoints) { - const int aNbPoints = theParamList1.size(); - - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = - theParamList1.begin(); - - const size_t aSize = - sizeof(aNbPoints) + - aNbPoints * (2*sizeof(int)); - int *pIntData = (int *)allocate(aSize); - - *pIntData++ = aNbPoints; - int aSectionId, aPointId; - for ( ; anIt != theParamList1.end(); anIt++ ) { - aSectionId = anIt->first; - aPointId = anIt->second; - - *pIntData++ = aSectionId; - *pIntData++ = aPointId; - } - - 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: - case CurveCreator_Operation::InsertPoints: - case CurveCreator_Operation::SetCoordinates: - { - int aSectionId, aPointId; - CurveCreator::SectionsMap aSectionsMap; - CurveCreator::PosPointsList aPoints; - CurveCreator::Coordinates aCoords; - - int nbPoints = pInt[0]; - int nbCoords = pInt[1]; - int nbParams = 3+nbCoords; - for (int i = 0; i < nbPoints*nbParams; i=i+nbParams) { - aCoords.clear(); - aPoints.clear(); - getCoords(&pInt[4+i], aCoords); - aSectionId = pInt[2+i]; - aPointId = pInt[3+i]; - if ( aSectionsMap.find( aSectionId ) != aSectionsMap.end() ) - aPoints = aSectionsMap[aSectionId]; - CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( aPointId, aCoords ); - aPoints.push_back( aPosPoint ); - aPoints.sort(compId); - aSectionsMap[aSectionId] = aPoints; - } - switch (myType) { - case CurveCreator_Operation::AddPoints: - case CurveCreator_Operation::InsertPoints: - theCurve->addPointsInternal( aSectionsMap ); - break; - case CurveCreator_Operation::SetCoordinates: - theCurve->setPointInternal( aSectionsMap ); - break; - } - } - break; - case CurveCreator_Operation::RemovePoints: - { - CurveCreator_ICurve::SectionToPointList aListOfSectionsToPoints; - int nbPoints = pInt[0]; - for (int i = 1; i < nbPoints*2; i=i+2) { - aListOfSectionsToPoints.push_back(std::make_pair(pInt[i], pInt[i+1])); - } - theCurve->removePointsInternal(aListOfSectionsToPoints); - } - break; - case CurveCreator_Operation::SetType: - { - const CurveCreator::SectionType aType = (CurveCreator::SectionType) pInt[0]; - - theCurve->setSectionTypeInternal( pInt[1], aType ); - } - break; - case CurveCreator_Operation::Clear: - theCurve->clearInternal(); - break; - case CurveCreator_Operation::SetClosed: - theCurve->setClosedInternal(pInt[1], (pInt[0] != 0)); - break; - case CurveCreator_Operation::MoveSection: - theCurve->moveSectionInternal(pInt[0], pInt[1]); - break; - case CurveCreator_Operation::Join: - if (myPData != NULL) - { - std::list aListOfSections; - int nbSections = pInt[0]; - for (int i = 1; i < nbSections+1; i++) { - aListOfSections.push_back(pInt[i]); - } - theCurve->joinInternal(aListOfSections); - } - break; - case CurveCreator_Operation::AddSection: - { - const CurveCreator::SectionType aType = (CurveCreator::SectionType) pInt[0]; - - std::string aName = std::string((char*)&pInt[2]); - - CurveCreator::Coordinates aCoords; - - char* aPtr = ((char*)&pInt[2]); - aPtr += (aName.length()) + 1; - getCoords((int*)aPtr, aCoords); - theCurve->addSectionInternal(aName, aType, (pInt[1] != 0), aCoords); - } - break; - case CurveCreator_Operation::RemoveSection: - theCurve->removeSectionInternal(pInt[0]); - break; - case CurveCreator_Operation::RenameSection: - { - std::string aName = std::string((char*)&pInt[1]); - theCurve->setSectionNameInternal(pInt[0], aName); - } - break; - default: - break; - } - } -} - -//======================================================================= -// function: allocate -// purpose: -//======================================================================= -void *CurveCreator_Operation::allocate(const size_t theSize) -{ - if (myPData != NULL) { - clear(); - } - - myPData = malloc(theSize); - - return myPData; -} - -//======================================================================= -// function: clear -// purpose: -//======================================================================= -void CurveCreator_Operation::clear() -{ - myType = CurveCreator_Operation::Unknown; - - if (myPData != NULL) { - free(myPData); - myPData = NULL; - } -} - -//======================================================================= -// function: getCoords -// purpose: -//======================================================================= -void CurveCreator_Operation::getCoords - (int *thePInt, CurveCreator::Coordinates &theCoords) const -{ - const int aNbPnts = *thePInt; - CurveCreator::TypeCoord *pCoord = (CurveCreator::TypeCoord *)&thePInt[1]; - - for (int i = 0; i < aNbPnts; i++) { - theCoords.push_back(pCoord[i]); - } -} diff --git a/src/HYDROCurveCreator/CurveCreator_Operation.hxx b/src/HYDROCurveCreator/CurveCreator_Operation.hxx deleted file mode 100644 index 855d0da2..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Operation.hxx +++ /dev/null @@ -1,216 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_Operation.hxx -// Author: Sergey KHROMOV - -#ifndef _CurveCreator_Operation_HeaderFile -#define _CurveCreator_Operation_HeaderFile - -#include "CurveCreator.hxx" -#include "CurveCreator_ICurve.hxx" -#include "CurveCreator_PosPoint.hxx" - -#include -#include - -class CurveCreator_Curve; - - -/** - * This is the support class that describes a modification operation that - * can be applied to CurveCreator_Curve. - */ -class CurveCreator_Operation -{ - -public: - - /** - * This is a type of CurveCreator_Curve modification operation. - */ - enum Type - { - Unknown = 0, //!< Unknown method. - AddPoints, //!< Method CurveCreator_Curve::addPoints - RemovePoints, //!< Method CurveCreator_Curve::removePoints - InsertPoints, //!< Method CurveCreator_Curve::insertPoints - SetType, //!< Method CurveCreator_Curve::setType - Clear, //!< Method CurveCreator_Curve::clear - SetCoordinates, //!< Method CurveCreator_Curve::setCoordinates - SetClosed, //!< Method CurveCreator_Curve::setClosed - MoveSection, //!< Method CurveCreator_Curve::moveSection - Join, //!< Method CurveCreator_Curve::join - AddSection, //!< Method CurveCreator_Curve::addSection - RemoveSection, //!< Method CurveCreator_Curve::removeSection - RenameSection //!< Method CurveCreator_Curve::renameSection - }; - - /** - * Empty constructor. - */ - CurveCreator_Operation(); - - /** - * Destructor. - */ - ~CurveCreator_Operation(); - - /** - * This method initializes the object with an operation without parameters. - * It is applicable to the following operations: - *
    - *
  • Clear
  • - *
- * @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 two integer - * parameters. It is applicable to the following operations: - *
    - *
  • Join (with a list of int arguments)
  • - *
- * @return true in case of success; false otherwise. - */ - bool init(const Type theType, const std::list theParamList); - - /** - * This method initializes the object with an operation with - * list of pairs of integer parameters. - * It is applicable to the following operations: - *
    - *
  • RemovePoints
  • - *
- * @return true in case of success; false otherwise. - */ - bool init(const Type theType, - const CurveCreator_ICurve::SectionToPointList &theParamList1); - - /** - * 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 - * list of pairs of integer parameters and CurveCreator::Coordinates parameters. - * It is applicable to the following operations: - *
    - *
  • InsertPoints
  • - *
- * @return true in case of success; false otherwise. - */ - bool init(const Type theType, - const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1); - - /** - * This method initializes the object with an operation with one - * string, one CurveCreator::Coordinates parameter and two integer parameters. - * It is applicable to the following operations: - *
    - *
  • AddSection
  • - *
  • InsertPoints
  • - *
  • SetCoordinates
  • - *
- * @return true in case of success; false otherwise. - */ - bool init(const CurveCreator_Operation::Type theType, - const std::string& theName, - const CurveCreator::Coordinates &theCoords, - const int theIntParam1, - const int theIntParam2); - - - /** - * This method initializes the object with an operation with one - * string parameter and one integer. - * It is applicable to the following operations: - *
    - *
  • RenameSection
  • - *
- * @return true in case of success; false otherwise. - */ - bool init(const CurveCreator_Operation::Type theType, - const std::string &theName, - const int theIntParam1 ); - - /** - * This method applies the current operation to theCurve. - */ - void apply(CurveCreator_Curve *theCurve); - -private: - - /** - * This method allocates required memory for the operation data. - * Returns myPData for convenience purpose. - */ - void *allocate(const size_t theSize); - - /** - * This method clears initialized data pointers. - */ - void clear(); - - /** - * This method returns the coordinates read from thePInt. - */ - void getCoords(int *thePInt, CurveCreator::Coordinates &theCoords) const; - -private: - - Type myType; - void *myPData; - -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_PosPoint.hxx b/src/HYDROCurveCreator/CurveCreator_PosPoint.hxx deleted file mode 100644 index 23013742..00000000 --- a/src/HYDROCurveCreator/CurveCreator_PosPoint.hxx +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_PosPoint.hxx -// Author: Alexander KOVALEV - -#ifndef _CurveCreator_PosPoint_HeaderFile -#define _CurveCreator_PosPoint_HeaderFile - -#include "CurveCreator.hxx" - -struct CurveCreator_PosPoint -{ -public: - CurveCreator_PosPoint( int theID, CurveCreator::Coordinates theCoords ) - : myID( theID ), myCoords( theCoords ) - { }; - - ////! Overloaded operator to use sorting. - //bool operator < (CurveCreator_PosPoint const & thePosPoint) const - //{ - // return myID < thePosPoint.myID; - //} - - int myID; // point ID - CurveCreator::Coordinates myCoords; // point coordinates - -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Profile.cxx b/src/HYDROCurveCreator/CurveCreator_Profile.cxx deleted file mode 100644 index bcfc8fb0..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Profile.cxx +++ /dev/null @@ -1,280 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "CurveCreator_Profile.hxx" - -#include "CurveCreator.hxx" -#include "CurveCreator_PosPoint.hxx" -#include "CurveCreator_Section.hxx" -#include "CurveCreator_Displayer.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -CurveCreator_Profile::CurveCreator_Profile() -: CurveCreator_Curve( CurveCreator::Dim2d ) -{ - CurveCreator_Section *aSection = new CurveCreator_Section; - aSection->myName = getUniqSectionName(); - aSection->myType = CurveCreator::Polyline; - aSection->myIsClosed = false; - - mySections.push_back( aSection ); -} - -CurveCreator_Profile::~CurveCreator_Profile() -{ -} - -bool CurveCreator_Profile::moveSectionInternal( const int theISection, - const int theNewIndex ) -{ - return false; -} - -bool CurveCreator_Profile::moveSection( const int theISection, - const int theNewIndex ) -{ - return false; -} - -bool CurveCreator_Profile::clearInternal() -{ - // erase curve from the viewer - if( myDisplayer ) - myDisplayer->eraseAll( true ); - - // Delete all allocated data. - CurveCreator_Section* aSection = getSection( 0 ); - if ( aSection ) - aSection->myPoints.clear(); - - return true; -} - -bool CurveCreator_Profile::joinInternal( const std::list& theSections ) -{ - return false; -} - -bool CurveCreator_Profile::join( const std::list& theSections ) -{ - return false; -} - -int CurveCreator_Profile::addSectionInternal( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed, - const CurveCreator::Coordinates& thePoints ) -{ - return -1; -} - -int CurveCreator_Profile::addSection( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ) -{ - return -1; -} - -int CurveCreator_Profile::addSection( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed, - const CurveCreator::Coordinates& thePoints ) -{ - return -1; -} - -bool CurveCreator_Profile::removeSectionInternal( const int theISection ) -{ - return false; -} - -bool CurveCreator_Profile::removeSection( const int theISection ) -{ - return false; -} - -bool CurveCreator_Profile::setClosedInternal( const int theISection, - const bool theIsClosed ) -{ - return false; -} - -bool CurveCreator_Profile::setClosed( const int theISection, - const bool theIsClosed ) -{ - return false; -} - -bool CurveCreator_Profile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ) -{ - bool res = false; - - CurveCreator_Section* aSection = getSection( 0 ); - if( !aSection ) - return res; - - CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); - for ( ; anIt != theSectionsMap.end(); anIt++ ) - { - int anISection = anIt->first; - if( anISection != 0 ) - continue; - - const CurveCreator::PosPointsList& aSectionPoints = anIt->second; - - CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); - for( ; aPntIt != aSectionPoints.end(); aPntIt++ ) - { - const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords; - CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin(); - for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ ) - { - const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++; - if ( aNewPntIt == aNewCoords.end() ) - break; - - const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt; - - CurveCreator::TypeCoord aC = aCoordU - 1; - if ( !aSection->myPoints.empty() ) - aC = *(aSection->myPoints.end() - 2); - - if ( aSection->myPoints.empty() || aCoordU >= aC ) - { - aSection->myPoints.push_back( aCoordU ); - aSection->myPoints.push_back( aCoordZ ); - } - else if ( aCoordU < aSection->myPoints.front() ) - { - aSection->myPoints.push_front( aCoordZ ); - aSection->myPoints.push_front( aCoordU ); - } - else - { - CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin(); - for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ ) - { - const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++; - if ( aCoordU < aRefCoordU ) - break; - } - - aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 ); - } - } - } - - res = true; - } - - if ( res ) - redisplayCurve(); - - return res; -} - -//! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Profile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ) -{ - bool aRes = false; - - if ( mySkipSorting ) { - return CurveCreator_Curve::setPointInternal( theSectionsMap ); - } - - int anISection = 0; - CurveCreator_Section* aSection = getSection( anISection ); - if( !aSection ) - return aRes; - - CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); - if ( anIt == theSectionsMap.end() ) - return aRes; - - const CurveCreator::PosPointsList& aSectionPoints = anIt->second; - - std::list aConvPoints; - convert( aSectionPoints, aConvPoints ); - removeSectionPoints( anISection, aConvPoints ); - - aRes = addPointsInternal( theSectionsMap ); - if ( aRes ) - redisplayCurve(); - - return aRes; -} - -void CurveCreator_Profile::convert( const CurveCreator::PosPointsList& thePoints, - std::list& theConvPoints ) -{ - theConvPoints.clear(); - - CurveCreator::PosPointsList::const_iterator aPntIt = thePoints.begin(), - aPntLast = thePoints.end(); - for( ; aPntIt != aPntLast; aPntIt++ ) - { - int anIPnt = (*aPntIt)->myID; - theConvPoints.push_back( anIPnt ); - } -} - -bool CurveCreator_Profile::canPointsBeSorted() -{ - return true; -} - -/** - * Add one point to the specified section starting from the given theIPnt index - * (or at the end of points if \a theIPnt is -1). - */ -bool CurveCreator_Profile::addPoints( const CurveCreator::Coordinates& theCoords, - const int theISection, - const int theIPnt ) -{ - int anIPnt = theIPnt; - - if ( anIPnt == - 1 && theCoords.size() > 1 ) { - CurveCreator::Coordinates aCoords; - for ( int i = 0, aNb = getNbPoints( theISection ); i < aNb; i++ ) { - aCoords = getPoint( theISection, i ); - if ( aCoords.size() < 2 ) { - continue; - } - - if ( theCoords[0] < aCoords[0] ) { - anIPnt = i; - break; - } - } - } - - return CurveCreator_Curve::addPoints( theCoords, theISection, anIPnt ); -} \ No newline at end of file diff --git a/src/HYDROCurveCreator/CurveCreator_Profile.hxx b/src/HYDROCurveCreator/CurveCreator_Profile.hxx deleted file mode 100644 index f426fba0..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Profile.hxx +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef _CurveCreator_Profile_HeaderFile -#define _CurveCreator_Profile_HeaderFile - -#include "CurveCreator_Curve.hxx" - -/** - * The CurveCreator_Curve object is represented as one or more sets of - * connected points; thus CurveCreator_Curve object can contain several - * not connected curves (polylines or b-splines), each such curve has two - * only ends start and end points in other words non-manifold curves - * are not supported. - */ -class CURVECREATOR_EXPORT CurveCreator_Profile : public CurveCreator_Curve -{ - -public: - - //! Constructor of the curve. - CurveCreator_Profile(); - - //! Destructor. - virtual ~CurveCreator_Profile(); - -public: - - /***********************************************/ - /*** Section methods ***/ - /***********************************************/ - - //! For internal use only! Undo/Redo are not used here. - virtual bool clearInternal(); - - //! For internal use only! Undo/Redo are not used here. - virtual bool joinInternal( const std::list& theSections ); - - //! For internal use only! Undo/Redo are not used here. - virtual bool moveSectionInternal( const int theISection, - const int theNewIndex); - //! Move section to new position in list - virtual bool moveSection( const int theISection, - const int theNewIndex ); - //! Join list of sections to one section (join all if the list is empty) - // The first section in the list is a leader, another sections are joined to it - virtual bool join( const std::list& theSections ); - - //! For internal use only! Undo/Redo are not used here. - virtual int addSectionInternal( const std::string &theName, - const CurveCreator::SectionType theType, - const bool theIsClosed, - const CurveCreator::Coordinates &thePoints); - //! Add a new section. - virtual int addSection( const std::string &theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ); - //! Add a new section. - virtual int addSection( const std::string &theName, - const CurveCreator::SectionType theType, - const bool theIsClosed, - const CurveCreator::Coordinates &thePoints); - - - //! For internal use only! Undo/Redo are not used here. - virtual bool removeSectionInternal( const int theISection ); - - //! Removes the given sections. - virtual bool removeSection( const int theISection ); - - - //! For internal use only! Undo/Redo are not used here. - virtual bool setClosedInternal( const int theISection, - const bool theIsClosed ); - /** - * Set "closed" flag of the specified section (all sections if - * \a theISection is -1). - */ - virtual bool setClosed( const int theISection, - const bool theIsClosed ); - - /***********************************************/ - /*** Point methods ***/ - /***********************************************/ - - //! For internal use only! Undo/Redo are not used here. - virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ); - /** - * Add one point to the specified section starting from the given theIPnt index - * (or at the end of points if \a theIPnt is -1). - */ - //! For internal use only! Undo/Redo are not used here. - virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ); - - /** - * Add one point to the specified section starting from the given theIPnt index. - * Contrary to CurveCreator_Curve::addPoints(...) if \a theIPnt is -1 the right index - * will be calculated automatically in accordance with X coordinate value of the point. - */ - virtual bool addPoints( const CurveCreator::Coordinates &theCoords, - const int theISection, - const int theIPnt = -1 ); - - /** - * Indicates whether the points can be sorted. - */ - virtual bool canPointsBeSorted(); - -protected: - /** - * Converts the list of custom point position objects into a list of point indices - * \param thePoints an source list - * \param theConvPoints a converted list - */ - void convert( const CurveCreator::PosPointsList& thePoints, - std::list& theConvPoints ); - -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_Section.hxx b/src/HYDROCurveCreator/CurveCreator_Section.hxx deleted file mode 100644 index 68b03aaa..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Section.hxx +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File: CurveCreator_Section.hxx -// Author: Sergey KHROMOV - -#ifndef _CurveCreator_Section_HeaderFile -#define _CurveCreator_Section_HeaderFile - -#include "CurveCreator.hxx" - -#include - -//! Structure to store sections representing the CurveCreator_Curve object -struct CurveCreator_Section -{ - //! Constructor. Initializes object with default values. - CurveCreator_Section() : myName("Section"),myType(CurveCreator::Polyline), myIsClosed(false) - { } - - std::string myName; //!< section name - CurveCreator::Coordinates myPoints; //!< points coordinates - CurveCreator::SectionType myType; //!< type of the section - bool myIsClosed; //!< closed or not - -}; - -#endif diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.cxx b/src/HYDROCurveCreator/CurveCreator_TableView.cxx deleted file mode 100644 index b7567ab5..00000000 --- a/src/HYDROCurveCreator/CurveCreator_TableView.cxx +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "CurveCreator_TableView.h" -#include "CurveCreator_UtilsICurve.hxx" - -#include - -#include -#include - -#include - -const double DBL_MINIMUM = -10000000.; -const double DBL_MAXIMUM = 10000000.; - -const int SECTION_NAME_COLUMN_WIDTH = 75; -const int POINT_INDEX_COLUMN_WIDTH = 40; - -const double LOCAL_SELECTION_TOLERANCE = 0.0001; - -CurveCreator_TableItemDelegate::CurveCreator_TableItemDelegate( QObject* theParent ) -: QItemDelegate( theParent ) -{ -} - -/** - * Creates an editor for the cell - */ -QWidget* CurveCreator_TableItemDelegate::createEditor( QWidget* theParent, - const QStyleOptionViewItem& theOption, - const QModelIndex& theIndex ) const -{ - QWidget* anEditor = 0; - - int aColumnId = theIndex.column(); - if ( aColumnId == 2 || aColumnId == 3 ) { - QDoubleSpinBox* aSpin = new QtxDoubleSpinBox( theParent ); - aSpin->setDecimals( 2 ); - aSpin->setRange( DBL_MINIMUM, DBL_MAXIMUM ); - anEditor = aSpin; - } - else - anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex ); - - return anEditor; -} - -void CurveCreator_TableItemDelegate::setEditorData( QWidget* theEditor, - const QModelIndex& theIndex ) const -{ - int aColumnId = theIndex.column(); - if ( aColumnId == 2 || aColumnId == 3 ) { - QDoubleSpinBox* aDblSpin = dynamic_cast( theEditor ); - if ( aDblSpin ) { - double aValue = theIndex.model()->data( theIndex, Qt::EditRole ).toDouble(); - aDblSpin->setValue( aValue ); - } - } - else - QItemDelegate::setEditorData( theEditor, theIndex ); -} - -void CurveCreator_TableItemDelegate::setModelData( QWidget* theEditor, - QAbstractItemModel* theModel, - const QModelIndex& theIndex ) const -{ - int aColumnId = theIndex.column(); - if ( aColumnId == 2 || aColumnId == 3 ) { - QDoubleSpinBox* aDblSpin = dynamic_cast( theEditor ); - if ( aDblSpin ) { - double aValue = aDblSpin->value(); - theModel->setData( theIndex, aValue, Qt::UserRole); - } - } - else - QItemDelegate::setModelData( theEditor, theModel, theIndex ); -} - -CurveCreator_TableView::CurveCreator_TableView( CurveCreator_ICurve* theCurve, - QWidget* theParent, - const QStringList& theCoordTitles ) -: QTableWidget( theParent ), myCurve( theCurve ) -{ - setItemDelegate( new CurveCreator_TableItemDelegate( this ) ); - setVisible( false ); - setColumnCount( 4 ); - setColumnWidth( 0, SECTION_NAME_COLUMN_WIDTH ); - setColumnWidth( 1, POINT_INDEX_COLUMN_WIDTH ); - QStringList aLabels; - QString aCoord1 = theCoordTitles.size() > 0 ? theCoordTitles[0] : tr( "X" ); // tr( "X_POSITION_LBL" ) - QString aCoord2 = theCoordTitles.size() > 1 ? theCoordTitles[1] : tr( "Y" ); // tr( "Y_POSITION_LBL" ) - //aLabels << tr( "SECTION_LABEL" ) << tr( "IDENTIFIER_LABEL" ) << aCoord1 << aCoord2; - aLabels << tr( "Section" ) << "Index" << aCoord1 << aCoord2; - setHorizontalHeaderLabels( aLabels ); -} - -void CurveCreator_TableView::setCurve( CurveCreator_ICurve* theCurve ) -{ - myCurve = theCurve; -} - -void CurveCreator_TableView::setLocalPointsToTable( - const CurveCreator_ICurve::SectionToPointList& thePoints ) -{ - setRowCount( thePoints.size() ); - - int aRowId = 0; - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(), - aLast = thePoints.end(); - for ( ; anIt != aLast; anIt++ ) { - CurveCreator_ICurve::SectionToPoint aSPoint = *anIt; - int anISection = aSPoint.first; - int anIPoint = aSPoint.second; - - QTableWidgetItem* anItem; - anItem = new QTableWidgetItem( myCurve->getSectionName( anISection ).c_str() ); - anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); - anItem->setData( Qt::UserRole, anISection ); - setItem( aRowId, 0, anItem ); - - anItem = new QTableWidgetItem( QString::number( anIPoint + 1 ) ); - anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); - anItem->setData( Qt::UserRole, anIPoint ); - setItem( aRowId, 1, anItem ); - - gp_Pnt aPoint; - CurveCreator_UtilsICurve::getPoint( myCurve, anISection, anIPoint, aPoint ); - - anItem = item( aRowId, 2 ); - if ( !anItem ) { - anItem = new QTableWidgetItem(); - setItem( aRowId, 2, anItem ); - } - anItem->setData( Qt::UserRole, aPoint.X() ); - anItem->setData( Qt::DisplayRole, QString::number( aPoint.X(), 'f', 2 ) ); - - anItem = item( aRowId, 3 ); - if ( !anItem ) { - anItem = new QTableWidgetItem(); - setItem( aRowId, 3, anItem ); - } - anItem->setData( Qt::UserRole, aPoint.Y() ); - anItem->setData( Qt::DisplayRole, QString::number( aPoint.Y(), 'f', 2 ) ); - - aRowId++; - } -} - -int CurveCreator_TableView::getSectionId( const int theRowId ) const -{ - return item( theRowId, 0 )->data( Qt::UserRole ).toInt(); -} - -/** - * Returns a point index from the table - * \param theRowId a table row - */ -int CurveCreator_TableView::getPointId( const int theRowId ) const -{ - return item( theRowId, 1 )->data( Qt::UserRole ).toInt(); -} diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.h b/src/HYDROCurveCreator/CurveCreator_TableView.h deleted file mode 100644 index 4565ab5d..00000000 --- a/src/HYDROCurveCreator/CurveCreator_TableView.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef CURVECREATOR_TABLEVIEW_H -#define CURVECREATOR_TABLEVIEW_H - -#include "CurveCreator_ICurve.hxx" - -#include -#include - -class CurveCreator_TableItemDelegate : public QItemDelegate -{ -public: - CurveCreator_TableItemDelegate( QObject* theParent ); - ~CurveCreator_TableItemDelegate() {} - - virtual QWidget* createEditor( QWidget* theParent, - const QStyleOptionViewItem& theOption, - const QModelIndex& theIndex ) const; - virtual void setEditorData( QWidget* theEditor, const QModelIndex& theIndex ) const; - virtual void setModelData( QWidget* theEditor, QAbstractItemModel* theModel, - const QModelIndex& theIndex ) const; -}; - -class CurveCreator_TableView : public QTableWidget -{ -public: - CurveCreator_TableView( CurveCreator_ICurve* theCurve, QWidget* theParent = 0, - const QStringList& theCoordTitles = QStringList() ); - ~CurveCreator_TableView() {}; - - void setCurve( CurveCreator_ICurve* theCurve ); - - void setLocalPointsToTable( const CurveCreator_ICurve::SectionToPointList& thePoints ); - - /** - * Returns a section index from the table - * \param theRowId a table row - */ - int getSectionId( const int theRowId ) const; - /** - * Returns a point index from the table - * \param theRowId a table row - */ - int getPointId( const int theRowId ) const; - -private: - CurveCreator_ICurve* myCurve; - -}; - -#endif // CURVECREATOR_TABLEVIEW_H diff --git a/src/HYDROCurveCreator/CurveCreator_TreeView.cxx b/src/HYDROCurveCreator/CurveCreator_TreeView.cxx deleted file mode 100755 index 36d1dfcf..00000000 --- a/src/HYDROCurveCreator/CurveCreator_TreeView.cxx +++ /dev/null @@ -1,451 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "CurveCreator_TreeView.h" -#include "CurveCreator_ICurve.hxx" - -#include -#include - -#include -#include - -#define ID_SECTION -1 - -CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent ) : - QAbstractItemModel(parent), myCurve(theCurve) -{ - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap aSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); - QPixmap aPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); - QPixmap aClosedSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_SPLINE"))); - QPixmap aClosedPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_POLYLINE"))); - QPixmap aPointIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POINT"))); - -/* QPixmap aSplineIcon(tr(":images/ICON_SPLINE")); - QPixmap aPolylineIcon(tr(":images/ICON_POLYLINE")); - QPixmap aClosedPolylineIcon(tr(":images/ICON_CLOSED_POLYLINE")); - QPixmap aClosedSplineIcon(tr(":images/ICON_CLOSED_SPLINE")); - QPixmap aPointIcon(tr(":images/ICON_POINT")); */ - - if( !aSplineIcon.isNull() ) - myCachedIcons[ICON_SPLINE] = aSplineIcon; - - if( !aPolylineIcon.isNull() ) - myCachedIcons[ICON_POLYLINE] = aPolylineIcon; - - if( !aPolylineIcon.isNull() ) - myCachedIcons[ICON_CLOSED_POLYLINE] = aClosedPolylineIcon; - - if( !aPolylineIcon.isNull() ) - myCachedIcons[ICON_CLOSED_SPLINE] = aClosedSplineIcon; - - if( !aPointIcon.isNull() ) - myCachedIcons[ICON_POINT] = aPointIcon; - - setHeaderData(1, Qt::Horizontal, QVariant("Name"), Qt::DisplayRole); - setHeaderData(2, Qt::Horizontal, QVariant("Nb points"), Qt::DisplayRole); -} - -int CurveCreator_TreeViewModel::columnCount(const QModelIndex & parent ) const -{ - if( parent.internalId() == ID_SECTION ) - return 2; - else - return 2; -} - -QVariant CurveCreator_TreeViewModel::data(const QModelIndex & index, int role ) const -{ - int aRow = index.row(); - int aColumn = index.column(); - if( myCurve ){ - if( index.internalId() == ID_SECTION ){ - if( role == Qt::DisplayRole ){ - if( aColumn == 0 ) - return QString::fromStdString(myCurve->getSectionName(aRow)); - else if( aColumn == 1 ) - return QString::number(myCurve->getNbPoints(aRow)); - return QVariant(); - } - else if( role == Qt::DecorationRole ){ - if( aColumn == 0 ){ - CurveCreator::SectionType aSectionType = myCurve->getSectionType(aRow); - if( aSectionType == CurveCreator::Polyline ){ - if( myCurve->isClosed(aRow) ){ - return myCachedIcons[ICON_CLOSED_POLYLINE]; - } - else{ - return myCachedIcons[ICON_POLYLINE]; - } - } - else{ - if( myCurve->isClosed(aRow) ){ - return myCachedIcons[ICON_CLOSED_SPLINE]; - } - else{ - return myCachedIcons[ICON_SPLINE]; - } - } - } - } - } -/* else{ - if( role == Qt::DisplayRole ){ - if( aColumn == 1 ) - return QVariant(); - // return "Point"; - else if( aColumn == 0 ){ - CurveCreator::Coordinates aCoords = myCurve->getCoordinates(index.internalId(),index.row() ); - QString anOut; - if( myCurve->getDimension() == CurveCreator::Dim2d ){ - anOut = QString(tr("X=%1, Y=%2")).arg(aCoords[0]).arg(aCoords[1]); - } - else{ - anOut = QString(tr("X=%1, Y=%2, Z=%3")).arg(aCoords[0]).arg(aCoords[1]).arg(aCoords[2]); - } - return anOut; - } - } - else if( role == Qt::DecorationRole ){ - if( aColumn == 0 ){ - return myCachedIcons[ICON_POINT]; - } - } - }*/ - } - return QVariant(); -} - -QModelIndex CurveCreator_TreeViewModel::index(int row, int column, const QModelIndex & parent ) const -{ - if( parent.isValid() ){ - return createIndex(row, column, parent.row() ); - } - else{ - QModelIndex aParent = createIndex(row, column, ID_SECTION ); - return aParent; - } - return QModelIndex(); -} - -QModelIndex CurveCreator_TreeViewModel::parent(const QModelIndex & theIndex) const -{ - if( !theIndex.isValid() ) - return QModelIndex(); - - if( theIndex.internalId() == ID_SECTION ){ - return QModelIndex(); - } - return createIndex( theIndex.internalId(), 0, ID_SECTION ); -} - -int CurveCreator_TreeViewModel::rowCount(const QModelIndex & parent ) const -{ - int aRowCnt = 0; - if( myCurve != NULL ){ - if( !parent.isValid() ){ - //Section level - aRowCnt = myCurve->getNbSections(); - } - else{ - if( parent.internalId() == ID_SECTION ){ - //Points level - aRowCnt = myCurve->getNbPoints(parent.row()); - } - } - } - return aRowCnt; -} - -QModelIndex CurveCreator_TreeViewModel::sectionIndex( int theSection ) const -{ - return createIndex( theSection, 0, ID_SECTION ); -} - -QModelIndex CurveCreator_TreeViewModel::nbPointsIndex( int theSection ) const -{ - return createIndex( theSection, 1, ID_SECTION ); -} - -QModelIndex CurveCreator_TreeViewModel::pointIndex( int theSection, int thePoint ) const -{ - return createIndex( thePoint, 0, theSection ); -} - -bool CurveCreator_TreeViewModel::isSection( const QModelIndex& theIndx ) const -{ - if( theIndx.internalId() == ID_SECTION ) - return true; - return false; -} - -int CurveCreator_TreeViewModel::getSection( const QModelIndex& theIndx ) const -{ - if( theIndx.internalId() == ID_SECTION ) - return theIndx.row(); - return theIndx.internalId(); -} - -int CurveCreator_TreeViewModel::getPoint( const QModelIndex& theIndx ) const -{ - if( theIndx.internalId() == ID_SECTION ) - return -1; - return theIndx.row(); -} - -void CurveCreator_TreeViewModel::setCurve( CurveCreator_ICurve* theCurve ) -{ - myCurve = theCurve; - reset(); -} - -/*****************************************************************************************/ -CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent) : - QTreeView(parent) -{ - header()->hide(); - header()->setResizeMode(QHeaderView::ResizeToContents); - setUniformRowHeights(true); - setContextMenuPolicy( Qt::CustomContextMenu ); - CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this); - setModel(aModel); - setSelectionBehavior(SelectRows); - setSelectionMode(SingleSelection); - setRootIsDecorated(false); - setItemsExpandable(false); - setAllColumnsShowFocus(true); - connect( selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SIGNAL(selectionChanged()) ); - connect( this, SIGNAL(activated(QModelIndex)), this, SLOT(onActivated(QModelIndex))); -} - -QList CurveCreator_TreeView::getSelectedSections() const -{ - QList aSect; - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( !aModel ) - return aSect; -// QModelIndexList anIndxs = selectionModel()->selectedIndexes(); - QModelIndexList anIndxs = selectionModel()->selectedRows(); - for( int i = 0 ; i < anIndxs.size() ; i++ ){ - if( aModel->isSection(anIndxs[i]) ){ - aSect << aModel->getSection( anIndxs[i] ); - } - } - return aSect; -} - -void CurveCreator_TreeView::pointsAdded( int theSection, int thePoint, int thePointsCnt ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ){ - QModelIndex aSectIndx = aModel->sectionIndex( theSection ); - rowsInserted(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); -// expand( aSectIndx ); - update( aModel->nbPointsIndex( theSection ) ); - } -} - -void CurveCreator_TreeView::pointDataChanged( int theSection, int thePoint ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ){ - QModelIndex aPointIndx = aModel->pointIndex( theSection, thePoint ); - dataChanged( aPointIndx, aPointIndx ); - } -} - -void CurveCreator_TreeView::pointsRemoved( int theSection, int thePoint, int thePointsCnt ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ){ - for( int i = 0 ; i < thePointsCnt ; i++ ){ - QModelIndex aSectIndx = aModel->pointIndex(theSection, thePoint + i); - selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect); - } - QModelIndex aSectIndx = aModel->sectionIndex( theSection ); - rowsRemoved(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); - } -} - -void CurveCreator_TreeView::sectionAdded( int theSection ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ){ - int nbRows = aModel->rowCount(); - int aSection = (theSection == -1 ? (nbRows==0 ? 0 : nbRows-1) : theSection); - rowsInserted(QModelIndex(), aSection, aSection ); - QModelIndex aSectIndx = aModel->sectionIndex(aSection); - selectionModel()->select(aSectIndx, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); - } -} - -void CurveCreator_TreeView::sectionChanged( int theSection, int aSectCnt ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ){ - QModelIndex aFirstSectIndx = aModel->sectionIndex( theSection ); - QModelIndex aLastSectIndx = aModel->sectionIndex( theSection + aSectCnt - 1); - dataChanged( aFirstSectIndx, aLastSectIndx ); - } -} - -void CurveCreator_TreeView::sectionsRemoved( int theSection, int theSectionCnt ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ){ - for( int i = 0 ; i < theSectionCnt ; i++ ){ - QModelIndex aSectIndx = aModel->sectionIndex(theSection + i); - this->selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect); - } - rowsRemoved( QModelIndex(), theSection, theSection+theSectionCnt-1 ); - } -} - -void CurveCreator_TreeView::setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ) -{ - setExpanded( theIndx, isExpanded ); - QItemSelectionModel::SelectionFlags aFlag = QItemSelectionModel::Select; - if( !isSelected ){ - aFlag = QItemSelectionModel::Deselect; - } - selectionModel()->select( theIndx, aFlag ); -} - -void CurveCreator_TreeView::getIndexInfo( const QModelIndex& theIndx, bool& isExpand, bool& isSelected, bool& isCurrent ) -{ - isExpand = isExpanded(theIndx); - isSelected = selectionModel()->isSelected(theIndx); - isCurrent = (theIndx == selectionModel()->currentIndex()); -} - -void CurveCreator_TreeView::swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond ) -{ - bool isFirstSelected; - bool isFirstExpanded; - bool isFirstCurrent; - getIndexInfo( theFirst, isFirstExpanded, isFirstSelected, isFirstCurrent ); - - bool isSecondSelected; - bool isSecondExpanded; - bool isSecondCurrent; - getIndexInfo( theSecond, isSecondExpanded, isSecondSelected, isSecondCurrent ); - - setIndexState( theFirst, isSecondExpanded, isSecondSelected, isSecondCurrent ); - setIndexState( theSecond, isFirstExpanded, isFirstSelected, isFirstCurrent ); - dataChanged(theFirst,theFirst); - dataChanged(theSecond,theSecond); -} - -void CurveCreator_TreeView::sectionsSwapped( int theSection, int theOffset ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ){ - QModelIndex aFirstIndex = aModel->sectionIndex( theSection ); - QModelIndex aSecondIndex = aModel->sectionIndex( theSection + theOffset ); - swapIndexes( aFirstIndex, aSecondIndex ); - } -} - -void CurveCreator_TreeView::setSelectedSections( const QList& theList ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ){ - selectionModel()->clearSelection(); - for( int i = 0 ; i < theList.size() ; i++ ){ - QModelIndex aSectIndx = aModel->sectionIndex(theList[i]); - selectionModel()->select(aSectIndx, QItemSelectionModel::Select | QItemSelectionModel::Rows ); - } - } -} - -bool pointLessThan(const QPair &s1, const QPair &s2) -{ - if( s1.first < s2.first ) - return true; - if( s1.first > s2.first ) - return false; - return s1.second < s2.second; -} - -CurveCreator_TreeView::SelectionType CurveCreator_TreeView::getSelectionType() const -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( !aModel ) - return ST_NOSEL; - bool isPointSel = false; - bool isSectSel = false; - bool isOneSection = true; - int aSectNum = -1; - QModelIndexList aLst = selectionModel()->selectedIndexes(); - for( int i = 0 ; i < aLst.size() ; i++ ){ - if( aModel->isSection( aLst[i] ) ){ - isSectSel = true; - } - else{ - isPointSel = true; - if( aSectNum == -1 ){ - aSectNum = aModel->getSection(aLst[i]); - } - else{ - if( aSectNum != aModel->getSection( aLst[i] ) ){ - isOneSection = false; - } - } - } - } - if( isSectSel && !isPointSel ) - return ST_SECTIONS; - if( isPointSel && !isSectSel ){ - if( isOneSection ){ - return ST_POINTS_ONE_SECTION; - } - return ST_POINTS; - } - if( isPointSel && isSectSel ) - return ST_MIXED; - return ST_NOSEL; -} - -void CurveCreator_TreeView::onActivated( QModelIndex theIndx ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( !aModel ) - return; - int aSect = aModel->getSection(theIndx); - if( aModel->isSection(theIndx) ){ - emit sectionEntered( aSect ); - } -} - -void CurveCreator_TreeView::setCurve( CurveCreator_ICurve* theCurve ) -{ - CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); - if( aModel ) - aModel->setCurve(theCurve); - reset(); -} - -void CurveCreator_TreeView::reset() -{ - QList aSelSections = getSelectedSections(); - QTreeView::reset(); - setSelectedSections(aSelSections); -} diff --git a/src/HYDROCurveCreator/CurveCreator_TreeView.h b/src/HYDROCurveCreator/CurveCreator_TreeView.h deleted file mode 100755 index be00a75d..00000000 --- a/src/HYDROCurveCreator/CurveCreator_TreeView.h +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef CURVECREATOR_TREEVIEW_H -#define CURVECREATOR_TREEVIEW_H - -#include -#include - -class CurveCreator_ICurve; - -class CurveCreator_TreeViewModel : public QAbstractItemModel -{ -public: - CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent ); - virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; - virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; - virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; - virtual QModelIndex parent(const QModelIndex & theIndex) const; -// virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole); - - QModelIndex sectionIndex( int theSection ) const; - QModelIndex nbPointsIndex( int theSection ) const; - QModelIndex pointIndex( int theSection, int thePoint ) const; - - bool isSection( const QModelIndex& theIndx ) const; - int getSection( const QModelIndex& theIndx ) const; - int getPoint( const QModelIndex& theIndx ) const; - - void setCurve( CurveCreator_ICurve* theCurve ); - -private: - enum IconType{ ICON_POLYLINE, ICON_SPLINE, ICON_CLOSED_SPLINE, ICON_CLOSED_POLYLINE, ICON_POINT }; -private: - CurveCreator_ICurve* myCurve; - QMap myCachedIcons; -}; - -class CurveCreator_TreeView : public QTreeView -{ - Q_OBJECT -public: - enum SelectionType{ ST_NOSEL, ST_POINTS, ST_POINTS_ONE_SECTION, ST_SECTIONS, ST_MIXED }; -public: - explicit CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent = 0); - SelectionType getSelectionType() const; - QList getSelectedSections() const; - - void pointsAdded( int theSection, int thePoint, int thePointsCnt=1 ); - void pointDataChanged( int theSection, int thePoint ); - void pointsRemoved(int theSection, int thePoint, int thePointsCnt=1 ); - - void sectionAdded( int theSection ); - void sectionChanged(int theSection , int aSectCnt = 1); - void sectionsRemoved( int theSection, int theSectionCnt=1 ); - void sectionsSwapped( int theSection, int theOffset ); - - void setSelectedSections( const QList& theList ); - - void setCurve( CurveCreator_ICurve* theCurve ); - - void reset(); - -signals: - void selectionChanged(); - void sectionEntered(int); - -protected slots: - void onActivated( QModelIndex theIndx ); -protected: - void setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ); - void swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond ); - void getIndexInfo( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ); - -}; - -#endif // CURVECREATOR_TREEVIEW_H diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.cxx b/src/HYDROCurveCreator/CurveCreator_Utils.cxx deleted file mode 100644 index 7be2d6b3..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Utils.cxx +++ /dev/null @@ -1,537 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "CurveCreator_Utils.h" -#include "CurveCreator.hxx" -#include "CurveCreator_UtilsICurve.hxx" - -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include - -#include "CurveCreator_ICurve.hxx" - -const double LOCAL_SELECTION_TOLERANCE = 0.0001; -const int SCENE_PIXEL_PROJECTION_TOLERANCE = 10; -const int SCENE_PIXEL_POINT_TOLERANCE = 5; - -//======================================================================= -// function : ConvertClickToPoint() -// purpose : Returns the point clicked in 3D view -//======================================================================= -void CurveCreator_Utils::ConvertPointToClick( const gp_Pnt& thePoint, - Handle(V3d_View) theView, - int& x, int& y ) -{ - theView->Convert(thePoint.X(), thePoint.Y(), thePoint.Z(), x, y ); -} - - -//======================================================================= -// function : ConvertClickToPoint() -// purpose : Returns the point clicked in 3D view -//======================================================================= -gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) -{ - // the 3D point, that is a projection of the pixels to the XYZ view plane - //return GEOMUtils::ConvertClickToPoint( x, y, aView ); - - // we need the projection to the XOY plane - // 1. find a point in the plane of the eye and the normal to the plane - Standard_Real X, Y, Z; - Quantity_Parameter Vx, Vy, Vz; - aView->ConvertWithProj( x, y, X, Y, Z, Vx, Vy, Vz ); - - // 2. build a ray from the point by the normal to the XOY plane and intersect it - // The ray equation is the following : p(x,y,z) = p0(x,y,z) + t*V(x,y,z) - // X,Y,Z - defines p0(x,y,z), Vx,Vy,Vz - defines V(x,y,z) - // p(x,y,z) - is a searched point, t - should to be calculated by the condition of XOY plane - // The system of equations is the following: - // p(x) = p0(x)+t*V(x) - // p(y) = p0(y)+t*V(y) - // p(z) = p0(z)+t*V(z) - // p(z) = 0 - - Standard_Real aXp, aYp, aZp; - //It is not possible to use Precision::Confusion(), because it is e-0.8, but V is sometimes e-6 - Standard_Real aPrec = LOCAL_SELECTION_TOLERANCE; - if ( fabs( Vz ) > aPrec ) { - Standard_Real aT = -Z/Vz; - aXp = X + aT*Vx; - aYp = Y + aT*Vy; - aZp = Z + aT*Vz; - } - else { // Vz = 0 - the eyed plane is orthogonal to Z plane - XOZ, or YOZ - aXp = aYp = aZp = 0; - if ( fabs( Vy ) < aPrec ) // Vy = 0 - the YOZ plane - aYp = Y; - else if ( fabs( Vx ) < aPrec ) // Vx = 0 - the XOZ plane - aXp = X; - } - /*std::cout << "ConvertClickToPoint: " << std::endl - << "XYZ1 = (" << X << ", " << Y << ", " << Z << "); " << std::endl - << "Vxyz = (" << Vx << ", " << Vy << ", " << Vz << "); " << std::endl - << "Resp = (" << aXp << ", " << aYp << ", " << aZp << "); " << std::endl;*/ - - gp_Pnt ResultPoint( aXp, aYp, aZp ); - return ResultPoint; -} - -void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve, - TopoDS_Shape& theShape ) -{ - BRep_Builder aBuilder; - TopoDS_Compound aComp; - aBuilder.MakeCompound( aComp ); - for( int iSection = 0 ; iSection < theCurve->getNbSections() ; iSection++ ) - { - int theISection = iSection; - - CurveCreator::SectionType aSectType = theCurve->getSectionType( theISection ); - int aPointSize = theCurve->getNbPoints( theISection ); - if ( aPointSize == 0 ) - continue; - - bool aSectIsClosed = theCurve->isClosed( theISection ); - bool isPolyline = aSectType == CurveCreator::Polyline; - - int iPoint = 0; - gp_Pnt aPrevPoint, aPoint; - // filters the curve points to skip equal points - std::vector aPoints; - CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint ); - aPoints.push_back( aPoint ); - aPrevPoint = aPoint; - iPoint++; - for( ; iPoint < aPointSize; iPoint++ ) { - CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint ); - if ( !isEqualPoints( aPrevPoint, aPoint ) ) - aPoints.push_back( aPoint ); - aPrevPoint = aPoint; - } - int aNbPoints = aPoints.size(); - - if ( aNbPoints == 1 ) { - aPoint = aPoints.front(); - TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); - aBuilder.Add( aComp, aVertex ); - } - else if ( aNbPoints > 1 ) { - Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt(1, aNbPoints); - TColgp_Array1OfVec aTangents(1, aNbPoints); - Handle(TColStd_HArray1OfBoolean) aTangentFlags = new TColStd_HArray1OfBoolean(1, aNbPoints); - gp_Vec aNullVec(0, 0, 0); - - TopoDS_Edge aPointEdge; - TopoDS_Vertex aVertex; - - std::vector::const_iterator aPointIt = aPoints.begin(), aPointLast = aPoints.end(); - aPoint = *aPointIt; - - int aHIndex = 1; - aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); - aBuilder.Add( aComp, aVertex ); - if ( !isPolyline ) { - aHCurvePoints->SetValue( aHIndex, aPoint ); - aTangents.SetValue( aHIndex, aNullVec ); - aTangentFlags->SetValue( aHIndex, Standard_False ); - aHIndex++; - } - - aPrevPoint = aPoint; - aPointIt++; - for( ; aPointIt != aPointLast; aPointIt++ ) { - aPoint = *aPointIt; - aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); - aBuilder.Add( aComp, aVertex ); - if ( isPolyline ) { - TopoDS_Edge aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge(); - aBuilder.Add( aComp, aPointEdge ); - } - else { - aHCurvePoints->SetValue( aHIndex, aPoint ); - aTangents.SetValue( aHIndex, aNullVec ); - aTangentFlags->SetValue( aHIndex, Standard_False ); - aHIndex++; - } - aPrevPoint = aPoint; - } - if( aSectIsClosed && ( aNbPoints > 2 ) ) { - aPoint = aPoints.front(); - aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); - aBuilder.Add( aComp, aVertex ); - if ( isPolyline ) { - aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge(); - aBuilder.Add( aComp, aPointEdge ); - } - } - if( !isPolyline ) { - // compute BSpline - Handle(Geom_BSplineCurve) aBSplineCurve; - GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution()); - // correct the spline degree to be as 3 for non-periodic spline if number of points - // less than 3. It is need to have a knot in each spline point. This knots are used - // to found a neighbour points when a new point is inserted between two existing. - if (!aSectIsClosed ) { - if (aHCurvePoints->Length() == 3) - aGBC.Load(aTangents, aTangentFlags); - } - - aGBC.Perform(); - if ( aGBC.IsDone() ) - aBSplineCurve = aGBC.Curve(); - TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge(); - TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire(); - aBuilder.Add( aComp, aWire ); - } - } - } - theShape = aComp; -} - -class CompareSectionToPoint -{ -public: - CompareSectionToPoint( const int theISection = -1, const int theIPoint = -1 ) - : mySectionId( theISection ), myPointId( theIPoint ) {}; - ~CompareSectionToPoint() {} - - bool operator < ( const CompareSectionToPoint& theOther ) const - { - bool isLess = mySectionId < theOther.mySectionId; - if ( !isLess && mySectionId == theOther.mySectionId ) - isLess = myPointId < theOther.myPointId; - return isLess; - } - -private: - int mySectionId; - int myPointId; -}; - - -void CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext, - const CurveCreator_ICurve* theCurve, - CurveCreator_ICurve::SectionToPointList& thePoints ) -{ - thePoints.clear(); - - std::list aSelectedPoints; - gp_Pnt aPnt; - std::map aPointsMap; - - CurveCreator_ICurve::SectionToPointList aPoints; - for ( theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected() ) { - TopoDS_Vertex aVertex; - TopoDS_Shape aShape = theContext->SelectedShape(); - if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) - aVertex = TopoDS::Vertex( theContext->SelectedShape() ); - - if ( aVertex.IsNull() ) - continue; - aPnt = BRep_Tool::Pnt( aVertex ); - - CurveCreator_UtilsICurve::findSectionsToPoints( theCurve, aPnt.X(), aPnt.Y(), aPoints ); - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(), - aLast = aPoints.end(); - CompareSectionToPoint aPoint; - for ( ; anIt != aLast; anIt++ ) { - aPoint = CompareSectionToPoint( (*anIt).first, (*anIt).second ); - if ( aPointsMap.find( aPoint ) != aPointsMap.end() ) - continue; - aPointsMap[aPoint] = 0; - - thePoints.push_back( *anIt ); - } - } -} - -void CurveCreator_Utils::setSelectedPoints( Handle(AIS_InteractiveContext) theContext, - const CurveCreator_ICurve* theCurve, - const CurveCreator_ICurve::SectionToPointList& thePoints ) -{ - if ( !theCurve ) - return; - - Handle(AIS_InteractiveObject) anAIS = theCurve->getAISObject(); - if ( anAIS.IsNull() ) - return; - Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( anAIS ); - if ( anAISShape.IsNull() ) - return; - - //ASL: we convert list of point indices to list of points coordinates - int aSize = thePoints.size(); - std::vector aPntsToSelect( aSize ); - - CurveCreator_ICurve::SectionToPointList::const_iterator - aPIt = thePoints.begin(), aPLast = thePoints.end(); - CurveCreator_ICurve::SectionToPoint aSToPoint; - for( int i=0; aPIt != aPLast; aPIt++, i++ ) - { - gp_Pnt aPntToSelect; - CurveCreator_UtilsICurve::getPoint( theCurve, aPIt->first, aPIt->second, aPntToSelect ); - aPntsToSelect[i] = aPntToSelect; - } - - theContext->ClearSelected( Standard_False ); - //ASL: we switch off automatic highlight to improve performance of selection - theContext->SetAutomaticHilight( Standard_False ); - - Handle_SelectMgr_Selection aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) ); - for( aSelection->Init(); aSelection->More(); aSelection->Next() ) - { - Handle_SelectBasics_SensitiveEntity aSenEntity = aSelection->Sensitive(); - Handle_Select3D_SensitivePoint aSenPnt = Handle_Select3D_SensitivePoint::DownCast( aSenEntity ); - - gp_Pnt anOwnerPnt = aSenPnt->Point(); - Handle_SelectMgr_EntityOwner anOwner = Handle_SelectMgr_EntityOwner::DownCast( aSenPnt->OwnerId() ); - - - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(), - aLast = thePoints.end(); - bool isFound = false; - for( int i=0; iAddOrRemoveSelected( anOwner, Standard_False ); - break; - } - } - } - - //ASL: we switch on again automatic highlight (otherwise selection will not be shown) - // and call HilightPicked to draw selected owners - theContext->SetAutomaticHilight( Standard_True ); - theContext->LocalContext()->HilightPicked( Standard_True ); -} - -//======================================================================= -// function : setLocalPointContext -// purpose : Open/close the viewer local context -//======================================================================= -void CurveCreator_Utils::setLocalPointContext( const CurveCreator_ICurve* theCurve, - Handle(AIS_InteractiveContext) theContext, - const bool theOpen ) -{ - if ( !theContext ) - return; - - if ( theOpen ) { - // Open local context if there is no one - if ( !theContext->HasOpenedContext() ) { - theContext->ClearCurrents( false ); - theContext->OpenLocalContext( false/*use displayed objects*/, true/*allow shape decomposition*/ ); - } - // load the curve AIS object to the local context with the point selection - Handle(AIS_InteractiveObject) anAIS = theCurve->getAISObject(); - if ( !anAIS.IsNull() ) - { - if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) ) - { - theContext->Load( anAIS, -1/*selection mode*/, true/*allow decomposition*/ ); - theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) ); - } - } - } - else { - if ( theContext->HasOpenedContext() ) - theContext->CloseAllContexts(); - } -} - -bool CurveCreator_Utils::pointOnObject( Handle(V3d_View) theView, - Handle(AIS_InteractiveObject) theObject, - const int theX, const int theY, - gp_Pnt& thePoint, - gp_Pnt& thePoint1, gp_Pnt& thePoint2 ) -{ - bool isFullFound = false; - - if ( theObject.IsNull() || theView.IsNull() ) - return isFullFound; - Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast( theObject ); - if ( aShape.IsNull() ) - return isFullFound; - const TopoDS_Compound& aCompound = TopoDS::Compound( aShape->Shape() ); - if ( aCompound.IsNull() ) - return isFullFound; - - gp_Pnt aCurPoint, aCurPoint1, aCurPoint2; - gp_Pnt aFoundPoint, aFoundPnt1, aFoundPnt2; - Standard_Real aParameter; - bool isFound = false; - int aDelta, aMinDelta = 2*SCENE_PIXEL_PROJECTION_TOLERANCE*SCENE_PIXEL_PROJECTION_TOLERANCE; - TopExp_Explorer anExp( aCompound, TopAbs_EDGE ); - for ( ; anExp.More(); anExp.Next()) - { - const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current()); - if ( anEdge.IsNull() ) - continue; - Standard_Real aFirst, aLast; - Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aFirst, aLast ); - if ( aCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) ) { - Handle(Geom_BSplineCurve) aBSplineCurve = - Handle(Geom_BSplineCurve)::DownCast( aCurve ); - if ( !aBSplineCurve.IsNull() ) { - isFound = hasProjectPointOnCurve( theView, theX, theY, aBSplineCurve, - aParameter, aDelta ); - if ( isFound ) { - aCurPoint = aBSplineCurve->Value( aParameter ); - Standard_Integer anI1, anI2; - aBSplineCurve->LocateU( aParameter, LOCAL_SELECTION_TOLERANCE, anI1, anI2 ); - aCurPoint1 = aBSplineCurve->Value( aBSplineCurve->Knot( anI1 ) ); - aCurPoint2 = aBSplineCurve->Value( aBSplineCurve->Knot( anI2 ) ); - } - } - } - else { // a curve built on a polyline edge - Handle(Geom_Line) aGLine = Handle(Geom_Line)::DownCast( aCurve ); - if ( aGLine.IsNull() ) - continue; - isFound = hasProjectPointOnCurve( theView, theX, theY, aGLine, aParameter, - aDelta ); - if ( isFound ) { - aCurPoint = aGLine->Value( aParameter ); - TopoDS_Vertex V1, V2; - TopExp::Vertices( anEdge, V1, V2, Standard_True ); - if ( V1.IsNull() || V2.IsNull() ) - continue; - aCurPoint1 = BRep_Tool::Pnt(V1); - aCurPoint2 = BRep_Tool::Pnt(V2); - - // check that the projected point is on the bounded curve - gp_Vec aVec1( aCurPoint1, aCurPoint ); - gp_Vec aVec2( aCurPoint2, aCurPoint ); - isFound = fabs( aVec1.Angle( aVec2 ) - M_PI ) < LOCAL_SELECTION_TOLERANCE; - } - } - if ( isFound && aMinDelta >= aDelta ) { - aMinDelta = aDelta; - - isFullFound = true; - aFoundPnt1 = aCurPoint1; - aFoundPnt2 = aCurPoint2; - aFoundPoint = aCurPoint; - } - } - if ( isFullFound ) { - int aX, anY, aX1, anY1, aX2, anY2; - int aDelta; - CurveCreator_Utils::ConvertPointToClick( aFoundPoint, theView, aX, anY ); - CurveCreator_Utils::ConvertPointToClick( aFoundPnt1, theView, aX1, anY1 ); - CurveCreator_Utils::ConvertPointToClick( aFoundPnt2, theView, aX2, anY2 ); - - isFullFound = !isEqualPixels( aX, anY, aX1, anY1, SCENE_PIXEL_POINT_TOLERANCE, aDelta ) && - !isEqualPixels( aX, anY, aX2, anY2, SCENE_PIXEL_POINT_TOLERANCE, aDelta ); - if ( isFullFound ) { - thePoint = aFoundPoint; - thePoint1 = aFoundPnt1; - thePoint2 = aFoundPnt2; - } - } - return isFullFound; -} - -bool CurveCreator_Utils::hasProjectPointOnCurve( Handle(V3d_View) theView, - const int theX, const int theY, - const Handle(Geom_Curve)& theCurve, - Standard_Real& theParameter, - int& theDelta ) -{ - bool isFound = false; - if ( theView.IsNull() ) - return isFound; - - gp_Pnt aPoint = CurveCreator_Utils::ConvertClickToPoint( theX, theY, theView ); - - GeomAPI_ProjectPointOnCurve aProj( aPoint, theCurve ); - Standard_Integer aNbPoint = aProj.NbPoints(); - if (aNbPoint > 0) { - for (Standard_Integer j = 1; j <= aNbPoint && !isFound; j++) { - gp_Pnt aNewPoint = aProj.Point( j ); - theParameter = aProj.Parameter( j ); - - int aX, anY; - CurveCreator_Utils::ConvertPointToClick( aNewPoint, theView, aX, anY ); - - isFound = isEqualPixels( aX, anY, theX, theY, SCENE_PIXEL_PROJECTION_TOLERANCE, theDelta ); - } - } - return isFound; -} - -bool CurveCreator_Utils::isEqualPixels( const int theX, const int theY, const int theOtherX, - const int theOtherY, const double theTolerance, int& theDelta ) -{ - int aXDelta = abs( theX - theOtherX ); - int anYDelta = abs( theY - theOtherY ); - - theDelta = aXDelta*aXDelta + anYDelta*anYDelta; - - return aXDelta < theTolerance && anYDelta < theTolerance; -} - -bool CurveCreator_Utils::isEqualPoints( const gp_Pnt& thePoint, const gp_Pnt& theOtherPoint ) -{ - return theOtherPoint.IsEqual( thePoint, LOCAL_SELECTION_TOLERANCE ); -} diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.h b/src/HYDROCurveCreator/CurveCreator_Utils.h deleted file mode 100644 index 0cf2364d..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Utils.h +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef CURVECREATOR_UTILS_H -#define CURVECREATOR_UTILS_H - -#include "CurveCreator_Macro.hxx" -#include "CurveCreator_ICurve.hxx" - -#include -#include // TODO: remove -#include -#include -#include -#include - -#include -#include // TODO: remove - - -class CurveCreator_Utils -{ -public: - - /*! - * \brief Returns the point clicked in 3D view. - * - * \param x The X coordinate in the view. - * \param y The Y coordinate in the view. - * \param theView View where the given point takes place. - * \retval gp_Pnt Returns the point clicked in 3D view - */ - CURVECREATOR_EXPORT static void ConvertPointToClick( const gp_Pnt& thePoint, - Handle(V3d_View) theView, - int& x, int& y ); - - /*! - * \brief Returns the point clicked in 3D view. - * - * \param x The X coordinate in the view. - * \param y The Y coordinate in the view. - * \param theView View where the given point takes place. - * \retval gp_Pnt Returns the point clicked in 3D view - */ - CURVECREATOR_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y, - Handle(V3d_View) theView ); - - /** - * Generates shape on the curve - * \param theCurve a curve object, that contains data - * \param theShape a generated shape - */ - CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve, - TopoDS_Shape& theShape ); - - /** - * Find selected points in the context - * \param theContext the viewer context - * \param theCurve a curve object, that contains data - */ - CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext, - const CurveCreator_ICurve* theCurve, - CurveCreator_ICurve::SectionToPointList& thePoints ); - - /** - * Set selected points to the context - * \param theContext the viewer context - * \param theCurve a curve object, that contains data - * \param thePoints the curve point indices to be selected in the context - */ - CURVECREATOR_EXPORT static void setSelectedPoints( - Handle(AIS_InteractiveContext) theContext, - const CurveCreator_ICurve* theCurve, - const CurveCreator_ICurve::SectionToPointList& thePoints = - CurveCreator_ICurve::SectionToPointList() ); - - /*! - * \brief Sets the local point context for the 3D viewer. - * \param theCurve a curve object, that contains data - * \param theContext the viewer context - * \param theOpen The flag to open or close the local context. - */ - CURVECREATOR_EXPORT static void setLocalPointContext( - const CurveCreator_ICurve* theCurve, - Handle(AIS_InteractiveContext) theContext, - const bool theOpen ); - - /** - * Checks whether the point belongs to the OCC object - * \param theObject a line or shape with a bspline inside - * \param theX the X coordinate in the view. - * \param theY the Y coordinate in the view. - * \param thePoint the output point to be append to the model curve - * \param thePoint1 the output point to bound the line where a new point should be inserted - * \param thePoint2 the output point to bound the line where a new point should be inserted - */ - CURVECREATOR_EXPORT static bool pointOnObject( Handle(V3d_View) theView, - Handle(AIS_InteractiveObject) theObject, - const int theX, const int theY, - gp_Pnt& thePoint, gp_Pnt& thePoint1, - gp_Pnt& thePoint2 ); - -protected: - /* - * Returns whether the clicked point belong to the curve or has a very near projection - * \param theX the X coordinate of a point clicked in the OCC viewer - * \param theY the Y coordinate of a point clicked in the OCC viewer - * \param theCurve a geometry curve - * \param theOutPoint a found projected point on the curve - */ - CURVECREATOR_EXPORT static bool hasProjectPointOnCurve( - Handle(V3d_View) theView, - const int theX, const int theY, - const Handle(Geom_Curve)& theCurve, - Standard_Real& theParameter, - int& theDelta ); - - /* - * Returns whether the X and Y coordinates is in the pixel tolerance - * \param theX the X coordinate of the first point - * \param theY the Y coordinate of the first point - * \param theOtherX the X coordinate of the second point - * \param theOtherY the Y coordinate of the second point - * \param theTolerance the tolerance to compare - * \param theDelta the sum of the a square of X and a square of Y - * \returns whether the points are provide to the pixel tolerance - */ - CURVECREATOR_EXPORT static bool isEqualPixels( const int theX, const int theY, - const int theOtherX, const int theOtherY, - const double theTolerance, int& theDelta ); - - - /* - * Returns whether the points are the same - * \param thePoint the first point - * \param theOtherPoint the second point - * \returns whether the points are provide to the pixel tolerance - */ - CURVECREATOR_EXPORT static bool isEqualPoints( const gp_Pnt& thePoint, - const gp_Pnt& theOtherPoint ); -}; - -#endif // CURVECREATOR_UTILS_H diff --git a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx deleted file mode 100644 index d11598e2..00000000 --- a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "CurveCreator_UtilsICurve.hxx" - -#include "CurveCreator.hxx" -#include - -const double LOCAL_SELECTION_TOLERANCE = 0.0001; - -int CurveCreator_UtilsICurve::findLocalPointIndex( const CurveCreator_ICurve* theCurve, - int theSectionId, float theX, float theY ) -{ - int aPntIndex = -1; - if ( !theCurve ) - return aPntIndex; - - CurveCreator::Coordinates aCoords; - for ( int i = 0, aNb = theCurve->getNbPoints( theSectionId ); i < aNb && aPntIndex < 0; i++ ) { - aCoords = theCurve->getPoint( theSectionId, i ); - if ( aCoords.size() < 2 ) - continue; - if ( fabs( aCoords[0] - theX ) < LOCAL_SELECTION_TOLERANCE && - fabs( aCoords[1] - theY ) < LOCAL_SELECTION_TOLERANCE ) - aPntIndex = i; - } - - return aPntIndex; -} - -void CurveCreator_UtilsICurve::findSectionsToPoints( const CurveCreator_ICurve* theCurve, - const double theX, const double theY, - CurveCreator_ICurve::SectionToPointList& thePoints ) -{ - thePoints.clear(); - - int aPointId = -1; - for ( int i = 0, aNb = theCurve->getNbSections(); i < aNb; i++ ) { - aPointId = CurveCreator_UtilsICurve::findLocalPointIndex( theCurve, i, theX, theY ); - if ( aPointId < 0 ) - continue; - CurveCreator_ICurve::SectionToPoint aPoint = std::make_pair( i, aPointId ); - if ( !CurveCreator_UtilsICurve::contains( thePoints, aPoint ) ) - thePoints.push_back( aPoint ); - } -} - -void CurveCreator_UtilsICurve::convert( const CurveCreator_ICurve::SectionToPointList& thePoints, - QMap >& theConvPoints ) -{ - theConvPoints.clear(); - - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(), - aLast = thePoints.end(); - QList aPoints; - int aSectionId, aPointId; - for ( ; anIt != aLast; anIt++ ) { - aSectionId = anIt->first; - aPointId = anIt->second; - aPoints.clear(); - if ( theConvPoints.contains( aSectionId ) ) - aPoints = theConvPoints[aSectionId]; - if ( aPoints.contains( aPointId ) ) - continue; - aPoints.append( aPointId ); - theConvPoints[aSectionId] = aPoints; - } -} - -#include "CurveCreator_Curve.hxx" // TODO -void CurveCreator_UtilsICurve::getPoint( const CurveCreator_ICurve* theCurve, const int theISection, - const int theIPoint, gp_Pnt& thePoint ) -{ - double anX, anY, aZ; - // TODO - const CurveCreator_Curve* aCurve = dynamic_cast( theCurve ); - if ( aCurve ) - aCurve->getCoordinates( theISection, theIPoint, anX, anY, aZ ); - thePoint = gp_Pnt( anX, anY, aZ); -} - -std::string CurveCreator_UtilsICurve::getUniqSectionName( CurveCreator_ICurve* theCurve ) -{ - for( int i = 0 ; i < 1000000 ; i++ ){ - char aBuffer[255]; - sprintf( aBuffer, "Section_%d", i+1 ); - std::string aName(aBuffer); - int j; - for( j = 0 ; j < theCurve->getNbSections() ; j++ ){ - if( theCurve->getSectionName(j) == aName ) - break; - } - if( j == theCurve->getNbSections() ) - return aName; - } - return ""; -} - -bool CurveCreator_UtilsICurve::contains( const CurveCreator_ICurve::SectionToPointList& theList, - const CurveCreator_ICurve::SectionToPoint& theValue ) -{ - bool isFound = false; - - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = theList.begin(), - aLast = theList.end(); - for ( ; anIt != aLast && !isFound; anIt++ ) - isFound = anIt->first == theValue.first && anIt->second == theValue.second; - - return isFound; -} diff --git a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx deleted file mode 100644 index 96b4e454..00000000 --- a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef CURVECREATOR_UTILS_ICURVE_H -#define CURVECREATOR_UTILS_ICURVE_H - -#include "CurveCreator_Macro.hxx" - -#include "CurveCreator_ICurve.hxx" - -#include - -#include -#include - -class CurveCreator_UtilsICurve -{ -public: - - /*! - * Returns a point index in the model curve by the point coordinates in the viewer - * \param theX the X coordinate of the point - * \param theY the Y coordinate of the point - */ - CURVECREATOR_EXPORT static int findLocalPointIndex( const CurveCreator_ICurve* theCurve, - int theSectionId, float theX, float theY ); - - CURVECREATOR_EXPORT static void findSectionsToPoints( const CurveCreator_ICurve* theCurve, - const double theX, const double theY, - CurveCreator_ICurve::SectionToPointList& thePoints ); - CURVECREATOR_EXPORT static void convert( const CurveCreator_ICurve::SectionToPointList& thePoints, - QMap >& theConvPoints ); - - CURVECREATOR_EXPORT static void getPoint( const CurveCreator_ICurve* theCurve, const int theISection, - const int theIPoint, gp_Pnt& thePoint ); - - /*! - * Returns a unique section name - * \param theCurve a curve interface - */ - CURVECREATOR_EXPORT static std::string getUniqSectionName( - CurveCreator_ICurve* theCurve ); - - /** - * Returns whethe the container has the value - * \param theList a container of values - * \param theValue a value - */ - CURVECREATOR_EXPORT static bool contains( const CurveCreator_ICurve::SectionToPointList& theList, - const CurveCreator_ICurve::SectionToPoint& theValue ); -}; - -#endif // CURVECREATOR_UTILS_ICURVE_H diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx deleted file mode 100644 index b595c221..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ /dev/null @@ -1,1459 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "CurveCreator_Widget.h" -#include "CurveCreator_TreeView.h" -#include "CurveCreator_ICurve.hxx" -#include "CurveCreator.hxx" -#include "CurveCreator_NewSectionDlg.h" -#include "CurveCreator_Utils.h" -#include "CurveCreator_UtilsICurve.hxx" -#include "CurveCreator_TableView.h" - -#include -#include -#include -#include - -#include -#include -#include -#include "OCCViewer_Utilities.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//#define MEASURE_TIME - -#ifdef MEASURE_TIME - - #define START_MEASURE_TIME \ - QTime aTimer; \ - aTimer.start(); \ - - #define END_MEASURE_TIME( theMsg ) \ - double aTime = aTimer.elapsed() * 0.001; \ - FILE* aFile = fopen( "performance", "a" ); \ - fprintf( aFile, "%s = %.3lf sec\n", theMsg, aTime ); \ - fclose( aFile ); \ - -#else - - #define START_MEASURE_TIME - #define END_MEASURE_TIME( theMsg ) - -#endif - - - - - - -CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, - CurveCreator_ICurve *theCurve, - const int theActionFlags, - const QStringList& theCoordTitles, - Qt::WindowFlags fl, - int theLocalPointRowLimit ) -: QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0), - myDragStarted( false ), myDragInteractionStyle( SUIT_ViewModel::STANDARD ), - myOCCViewer( 0 ), myLocalPointRowLimit( theLocalPointRowLimit ) -{ - bool isToEnableClosed = !( theActionFlags & DisableClosedSection ); - myNewSectionEditor = new CurveCreator_NewSectionDlg( this, isToEnableClosed ); - myNewSectionEditor->hide(); - connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) ); - connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) ); - connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) ); - - QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this); - - mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup); - mySectionView->setSelectionMode( QTreeView::ExtendedSelection ); - connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) ); - connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) ); - connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) ); - - myLocalPointView = new CurveCreator_TableView( myCurve, this, theCoordTitles ); - connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ), - this, SLOT( onCellChanged( int, int ) ) ); - - QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup); -// QToolButton* anUndoBtn = new QToolButton(aTB); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO"))); - QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO"))); - QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION"))); - QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT"))); - QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS"))); - QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS"))); - QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); - QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); - QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE"))); - QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN"))); - QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP"))); - QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN"))); - - QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"), - QKeySequence(Qt::ControlModifier|Qt::Key_Z) ); - connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) ); - aTB->addAction(anAct); - - anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"), - QKeySequence(Qt::ControlModifier|Qt::Key_Y) ); - connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) ); - aTB->addAction(anAct); - - aTB->addSeparator(); - - anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"), - QKeySequence(Qt::ControlModifier|Qt::Key_N) ); - connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) ); - if ( !(theActionFlags & DisableNewSection) ) { - aTB->addAction(anAct); - aTB->addSeparator(); - } - - anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"), - QKeySequence() ); - anAct->setCheckable(true); - connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) ); - connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); - aTB->addAction(anAct); - - anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"), - QKeySequence() ); - anAct->setCheckable(true); - connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) ); - connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); - aTB->addAction(anAct); - - anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"), - QKeySequence() ); - anAct->setCheckable(true); - connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectionMode(bool)) ); - connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); - if ( !(theActionFlags & DisableDetectionMode) ) { - aTB->addAction(anAct); - } - - anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"), - QKeySequence(Qt::ControlModifier|Qt::Key_W) ); - connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) ); - - anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(), - tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) ); - connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) ); - - anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"), - aPolylinePixmap, tr("SET_POLYLINE_TLT"), - QKeySequence(Qt::ControlModifier|Qt::Key_E) ); - connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) ); - - anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap, - tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) ); - connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) ); - - anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"), - QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) ); - connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) ); - aTB->addAction(anAct); - - aTB->addSeparator(); - - anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"), - QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) ); - connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) ); - aTB->addAction(anAct); - - anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"), - QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) ); - connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) ); - - anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"), - QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) ); - connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) ); - - QVBoxLayout* aSectLayout = new QVBoxLayout(); - aSectLayout->setMargin( 5 ); - aSectLayout->setSpacing( 5 ); - aSectLayout->addWidget(aTB); - aSectLayout->addWidget(mySectionView); - aSectLayout->addWidget( myLocalPointView ); - aSectionGroup->setLayout(aSectLayout); - QVBoxLayout* aLay = new QVBoxLayout(); - aLay->setMargin( 0 ); - aLay->setSpacing( 5 ); -// aLay->addLayout(aNameLayout); - aLay->addWidget(aSectionGroup); - setLayout(aLay); - - updateActionsStates(); - updateUndoRedo(); -} - -/** - * Set an OCC viewer - */ -void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer ) -{ - if ( myOCCViewer == theViewer ) - return; - - if ( myOCCViewer ) { - OCCViewer_ViewManager* aViewManager = dynamic_cast - ( myOCCViewer->getViewManager() ); - disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), - this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) ); - disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ), - this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) ); - disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), - this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); - disconnect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), - this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); - // restore normal mode in the viewer - OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::No2dMode ); - // all local contexts should be closed if the viewer is not more used - setLocalPointContext( false, true ); - } - - myOCCViewer = theViewer; - if ( myOCCViewer ) { - OCCViewer_ViewManager* aViewManager = dynamic_cast - ( myOCCViewer->getViewManager() ); - connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), - this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) ); - connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ), - this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) ); - connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), - this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); - connect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), - this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); - OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::XYPlane ); - } -} - -/** - * Returns current OCC viewer - */ -OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer() -{ - return myOCCViewer; -} - -/** - * Returns OCC viewer context - */ -Handle(AIS_InteractiveContext) CurveCreator_Widget::getAISContext() -{ - Handle(AIS_InteractiveContext) aContext; - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( aViewer ) - aContext = aViewer->getAISContext(); - - return aContext; -} - -/** - * Returns OCC viewer view port - */ -OCCViewer_ViewPort3d* CurveCreator_Widget::getViewPort() -{ - OCCViewer_ViewPort3d* aViewPort = 0; - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( aViewer ) - aViewPort = ((OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView())->getViewPort(); - - return aViewPort; -} - -/** - * Set interaction style in the OCC viewer - * \param theStyle a new style - * \return the previous style - */ -int CurveCreator_Widget::changeInteractionStyle( int theStyle ) -{ - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) - return -1; - - int aPrevStyle = aViewer->interactionStyle(); - aViewer->setInteractionStyle( theStyle ); - - return aPrevStyle; -} - -//======================================================================= -// function: reset -// purpose: reset the widget viewer, close local context, clear selection -//======================================================================= -void CurveCreator_Widget::reset() -{ -} - -void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve ) -{ - myCurve = theCurve; - mySectionView->setCurve( myCurve ); - myLocalPointView->setCurve( myCurve ); - updateActionsStates(); - updateUndoRedo(); -} - -void CurveCreator_Widget::onSelectionChanged() -{ - updateActionsStates(); - updateUndoRedo(); - emit selectionChanged(); -} - -void CurveCreator_Widget::updateActionsStates() -{ - QList anEnabledAct; - if( myCurve ){ - anEnabledAct << NEW_SECTION_ID << MODIFICATION_MODE_ID; - if ( removeEnabled() ) - anEnabledAct << REMOVE_ID; - QList aSelSections = mySectionView->getSelectedSections(); - CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); - switch( aSelType ){ - case CurveCreator_TreeView::ST_NOSEL:{ - break; - } - case CurveCreator_TreeView::ST_SECTIONS:{ - /*if( aSelSections[0] > 0 ){ - anEnabledAct << UP_ID; - }*/ - if( aSelSections.size() == 1 ){ - anEnabledAct << ADDITION_MODE_ID << DETECTION_MODE_ID; - } - switch ( getActionMode() ) { - case AdditionMode: { - mySection = -1; - myPointNum = -1; - QList aSelSection = mySectionView->getSelectedSections(); - if( aSelSection.size() > 0 ){ - mySection = aSelSection[0]; - myPointNum = myCurve->getNbPoints(mySection); - } - } - break; - case ModificationMode: { - if ( myNewSectionEditor->isEnableClosed() ) - anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID; - anEnabledAct << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID; - int aSectCnt = myCurve->getNbSections(); - if( aSectCnt > 0 ) - anEnabledAct << CLEAR_ALL_ID; - if( aSectCnt > 1 ) - anEnabledAct << JOIN_ALL_ID; - if( aSelSections.size() > 1 ){ - anEnabledAct << JOIN_ID; - } - } - break; - case DetectionMode: { - } - break; - case NoneMode: - { - int aSectCnt = myCurve->getNbSections(); - if( aSectCnt > 1 ) - anEnabledAct << JOIN_ALL_ID; - if( aSelSections.size() > 1 ) - anEnabledAct << JOIN_ID; - } - break; - default: - break; - } - /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){ - anEnabledAct << DOWN_ID; - }*/ - break; - } - /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{ - if( aSelPoints[0].second > 0 ){ - anEnabledAct << UP_ID; - } - int aLastIndex = aSelPoints.size()-1; - int aSect = aSelPoints[0].first; - if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){ - anEnabledAct << DOWN_ID; - } - if( aSelPoints.size() == 1){ - anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID; - } - break; - }*/ - - } - - /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size(); - if( aSelObjsCnt > 0 ){ - anEnabledAct << REMOVE_ID; - } - if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){ - anEnabledAct << REMOVE_ALL_ID; - }*/ - if( myCurve->getNbSections() > 1 ){ - anEnabledAct << JOIN_ALL_ID; - } - } - QList anIds = myActionMap.keys(); - for( int i = 0 ; i < anIds.size() ; i++ ){ - if( myActionMap.contains(anIds[i]) ){ - if( anEnabledAct.contains(anIds[i]) ){ - myActionMap[anIds[i]]->setEnabled(true); - } - else{ - myActionMap[anIds[i]]->setEnabled(false); - } - } - } -} - -void CurveCreator_Widget::onAdditionMode(bool checked) -{ - if (!checked) - return; - - Handle(AIS_InteractiveContext) aContext = getAISContext(); - if( !myCurve || aContext.IsNull() ) - return; - - mySection= -1; - myPointNum = -1; - QList aSelSection = mySectionView->getSelectedSections(); - if( aSelSection.size() > 0 ){ - mySection = aSelSection[0]; - } -// emit subOperationStarted( myNewPointEditor ); -} - -void CurveCreator_Widget::onModificationMode(bool checked) -{ - myLocalPointView->setVisible( checked ); -} - -void CurveCreator_Widget::onDetectionMode(bool checked) -{ -} - -void CurveCreator_Widget::onModeChanged(bool checked) -{ - ActionMode aMode = NoneMode; - if (checked) { - QAction* anAction = (QAction*)sender(); - switch(myActionMap.key(anAction)) { - case ADDITION_MODE_ID: - aMode = AdditionMode; - if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) - myActionMap[MODIFICATION_MODE_ID]->trigger(); - else if (myActionMap[DETECTION_MODE_ID]->isChecked()) - myActionMap[DETECTION_MODE_ID]->trigger(); - break; - case MODIFICATION_MODE_ID: - aMode = ModificationMode; - if (myActionMap[ADDITION_MODE_ID]->isChecked()) - myActionMap[ADDITION_MODE_ID]->trigger(); - else if (myActionMap[DETECTION_MODE_ID]->isChecked()) - myActionMap[DETECTION_MODE_ID]->trigger(); - break; - case DETECTION_MODE_ID: - aMode = DetectionMode; - if (myActionMap[ADDITION_MODE_ID]->isChecked()) - myActionMap[ADDITION_MODE_ID]->trigger(); - else if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) - myActionMap[MODIFICATION_MODE_ID]->trigger(); - break; - } - } - updateActionsStates(); - updateUndoRedo(); - setLocalPointContext( aMode == ModificationMode, true ); -} - -void CurveCreator_Widget::onNewSection() -{ - if( !myCurve ) - return; - - stopActionMode(); - myNewSectionEditor->clear(); - myNewSectionEditor->setEditMode(false); - QString aSectName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() ); - myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline ); - emit subOperationStarted( myNewSectionEditor, false ); -} - -void CurveCreator_Widget::onAddNewSection() -{ - if( !myCurve ) - return; - myCurve->addSection( myNewSectionEditor->getName().toStdString(), - myNewSectionEditor->getSectionType(), - myNewSectionEditor->isClosed() ); - mySectionView->sectionAdded( -1 ); // add a new section to the end of list - QString aNewName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() ); - myNewSectionEditor->setSectionName(aNewName); - updateActionsStates(); - updateUndoRedo(); - onCancelSection(); -} - -void CurveCreator_Widget::onCancelSection() -{ - emit subOperationFinished( myNewSectionEditor ); -} - -QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage, - const QString& theToolTip, const QKeySequence& theShortcut ) -{ - QAction* anAct = new QAction(theName,this); - if( !theImage.isNull() ){ - anAct->setIcon(theImage); - } - anAct->setShortcut(theShortcut); - anAct->setToolTip(theToolTip); - myActionMap[theId] = anAct; - return anAct; -} - -QAction* CurveCreator_Widget::getAction( ActionId theId ) -{ - if( myActionMap.contains(theId) ) - return myActionMap[theId]; - return NULL; -} - -QAction* CurveCreator_Widget::getAction( ActionMode theMode ) -{ - ActionId anActionId = NONE_ID; - switch ( theMode ) { - case AdditionMode: - anActionId = ADDITION_MODE_ID; - break; - case ModificationMode: - anActionId = MODIFICATION_MODE_ID; - break; - case DetectionMode: - anActionId = DETECTION_MODE_ID; - break; - default: - break; - } - QAction* anAction = 0; - if ( anActionId != NONE_ID && myActionMap.contains( anActionId ) ) - anAction = myActionMap[anActionId]; - return anAction; -} - -void CurveCreator_Widget::onEditSection( int theSection ) -{ - if( !myCurve ) - return; - - stopActionMode(); - mySection = theSection; - QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection)); - bool isClosed = myCurve->isClosed(theSection); - CurveCreator::SectionType aType = myCurve->getSectionType(theSection); - myNewSectionEditor->setEditMode(true); - myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType ); - - emit subOperationStarted( myNewSectionEditor, true ); -} - -void CurveCreator_Widget::onModifySection() -{ - if( !myCurve ) - return; - QString aName = myNewSectionEditor->getName(); - bool isClosed = myNewSectionEditor->isClosed(); - CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType(); - if( myCurve->getSectionName(mySection) != aName.toStdString() ) - myCurve->setSectionName( mySection , aName.toStdString() ); - - if( myCurve->getSectionType(mySection) != aSectType ) - myCurve->setSectionType( mySection, aSectType ); - - if( myCurve->isClosed(mySection) != isClosed ) - myCurve->setClosed( mySection, isClosed ); - mySectionView->sectionChanged(mySection); - updateUndoRedo(); - onCancelSection(); -} - -void CurveCreator_Widget::onJoin() -{ - if( !myCurve ) - return; - QList aSections = mySectionView->getSelectedSections(); - if( aSections.size() == 0 ){ - return; - } - stopActionMode(); - - std::list aSectionsToJoin; - for( int i = 0; i < aSections.size() ; i++ ){ - aSectionsToJoin.push_back( aSections[i] ); - } - //int aMainSect = aSectionsToJoin.front(); - //int aMainSectSize = myCurve->getNbPoints(aMainSect); - if ( myCurve->join( aSectionsToJoin ) ) - { - std::list::const_iterator anIt = aSectionsToJoin.begin(), - aLast = aSectionsToJoin.end(); - // the first section should be skipped. It is not removed, but is modified - anIt++; - for ( ; anIt != aLast; anIt++ ) - mySectionView->sectionsRemoved( *anIt ); - } - - /* The update for the points of the main section - int aNewSectSize = myCurve->getNbPoints(aMainSect); - if( aNewSectSize != aMainSectSize ) - mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );*/ - updateUndoRedo(); -} - -void CurveCreator_Widget::onRemove() -{ - if( !myCurve ) - return; - - switch( getActionMode() ) { - case NoneMode: - removeSection(); - break; - case ModificationMode: - removePoint(); - break; - default: - break; - } -} - -void CurveCreator_Widget::onClearAll() -{ - if( !myCurve ) - return; - stopActionMode(); - myCurve->clear(); - mySectionView->reset(); - updateActionsStates(); - updateUndoRedo(); -} - -void CurveCreator_Widget::onJoinAll() -{ - if( !myCurve ) - return; - stopActionMode(); - - std::list aSectionsToJoin; - for( int i = 0, aNb = myCurve->getNbSections(); i < aNb ; i++ ){ - aSectionsToJoin.push_back( i ); - } - bool aRes = myCurve->join( aSectionsToJoin ); - - mySectionView->reset(); - updateActionsStates(); - updateUndoRedo(); -} - -void CurveCreator_Widget::onUndoSettings() -{ - -} - -void CurveCreator_Widget::onSetSpline() -{ - if( !myCurve ) - return; - stopActionMode(); - QList aSelSections = mySectionView->getSelectedSections(); - for( int i = 0 ; i < aSelSections.size() ; i++ ){ - myCurve->setSectionType(aSelSections[i], CurveCreator::Spline ); - mySectionView->sectionChanged(aSelSections[i]); - } - updateUndoRedo(); -} - -void CurveCreator_Widget::onSetPolyline() -{ - if( !myCurve ) - return; - stopActionMode(); - QList aSelSections = mySectionView->getSelectedSections(); - for( int i = 0 ; i < aSelSections.size() ; i++ ){ - myCurve->setSectionType( aSelSections[i], CurveCreator::Polyline ); - mySectionView->sectionChanged( aSelSections[i] ); - } - updateUndoRedo(); -} - -void CurveCreator_Widget::onCloseSections() -{ - if( !myCurve ) - return; - stopActionMode(); - QList aSelSections = mySectionView->getSelectedSections(); - for( int i = 0 ; i < aSelSections.size() ; i++ ){ - myCurve->setClosed(aSelSections[i], true); - mySectionView->sectionChanged(aSelSections[i]); - } - updateUndoRedo(); -} - -void CurveCreator_Widget::onUncloseSections() -{ - if( !myCurve ) - return; - stopActionMode(); - QList aSelSections = mySectionView->getSelectedSections(); - for( int i = 0 ; i < aSelSections.size() ; i++ ){ - myCurve->setClosed(aSelSections[i], false); - mySectionView->sectionChanged(aSelSections[i]); - } - updateUndoRedo(); -} - -void CurveCreator_Widget::onUndo() -{ - if( !myCurve ) - return; - - CurveCreator_ICurve::SectionToPointList aPoints; - startCurveModification( aPoints, false ); - myCurve->undo(); - finishCurveModification(); - mySectionView->reset(); -} - -void CurveCreator_Widget::onRedo() -{ - if( !myCurve ) - return; - CurveCreator_ICurve::SectionToPointList aPoints; - startCurveModification( aPoints, false ); - myCurve->redo(); - finishCurveModification(); - mySectionView->reset(); -} - -void CurveCreator_Widget::updateUndoRedo() -{ - if( !myCurve ) - return; - QAction* anAct = myActionMap[UNDO_ID]; - if( anAct != 0 ){ - if( myCurve->getNbUndo() != 0 ){ - anAct->setEnabled(true); - } - else{ - anAct->setDisabled(true); - } - } - anAct = myActionMap[REDO_ID]; - if( anAct != 0 ){ - if( myCurve->getNbRedo() != 0 ){ - anAct->setEnabled(true); - } - else{ - anAct->setDisabled(true); - } - } -} - -void CurveCreator_Widget::onContextMenu( QPoint thePoint ) -{ - QList aContextActions; - aContextActions << CLEAR_ALL_ID << JOIN_ID << JOIN_ALL_ID << SEPARATOR_ID << - CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << - SET_SECTIONS_SPLINE_ID; - QPoint aGlPoint = mySectionView->mapToGlobal(thePoint); - bool isVis = false; - QList aResAct; - for( int i = 0 ; i < aContextActions.size() ; i++ ){ - if( aContextActions[i] != SEPARATOR_ID ){ - if( myActionMap.contains(aContextActions[i]) ){ - QAction* anAct = myActionMap[aContextActions[i]]; - if( anAct->isEnabled() ){ - aResAct << aContextActions[i]; - isVis = true; - } - } - } - else{ - aResAct << SEPARATOR_ID; - } - } - if( !isVis ) - return; - - QMenu* aMenu = new QMenu(this); - for( int i = 0 ; i < aResAct.size() ; i++ ){ - if( aResAct[i] == SEPARATOR_ID ){ - aMenu->addSeparator(); - } - else{ - QAction* anAct = myActionMap[aResAct[i]]; - aMenu->insertAction(NULL, anAct); - } - } - aMenu->exec(aGlPoint); -} - -QList CurveCreator_Widget::getSelectedSections() -{ - return mySectionView->getSelectedSections(); -} - -void CurveCreator_Widget::setSelectedSections( const QList& theSections ) -{ - mySectionView->setSelectedSections( theSections ); - updateActionsStates(); - updateUndoRedo(); -} - -/** - * According to the widget state, performs the remove action - */ -void CurveCreator_Widget::removeSelected() -{ - onRemove(); -} - -/** - * Checks whether there are some selection to be removed - */ -bool CurveCreator_Widget::removeEnabled() -{ - bool isEnabled = getActionMode() == ModificationMode; - if ( !isEnabled ) { - QList aSelSections = mySectionView->getSelectedSections(); - CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); - isEnabled = aSelType == CurveCreator_TreeView::ST_SECTIONS && - aSelSections.size() == 1; - } - return isEnabled; -} - -void CurveCreator_Widget::setActionMode( const ActionMode& theMode ) -{ - ActionMode aPrevMode = getActionMode(); - QAction* aPrevAction = getAction( aPrevMode ); - QAction* anAction = getAction( theMode ); - switch ( theMode ) { - case NoneMode: - case AdditionMode: { - if ( aPrevAction ) { - if ( aPrevAction->isChecked() ) { - aPrevAction->setChecked( false ); - } - } - if ( aPrevMode == ModificationMode ) - onModificationMode( false ); - if ( aPrevMode == AdditionMode ) - onAdditionMode( false ); - - if ( theMode == AdditionMode ) - { - anAction->setChecked( true ); - onModeChanged( true ); - } - } - break; - break; - case ModificationMode: - { - //TODO - } - break; - case DetectionMode: - break; - } -} - -CurveCreator_Widget::ActionMode CurveCreator_Widget::getActionMode() const -{ - ActionMode aMode = NoneMode; - - if ( myActionMap[ADDITION_MODE_ID]->isChecked() ) - aMode = AdditionMode; - else if ( myActionMap[MODIFICATION_MODE_ID]->isChecked() ) - aMode = ModificationMode; - else if ( myActionMap[DETECTION_MODE_ID]->isChecked() ) - aMode = DetectionMode; - - return aMode; -} - -//================================================================================= -// function : GeometryGUI::addCoordsByClick() -// purpose : Manage mouse press events in Additon mode -//================================================================================= -void CurveCreator_Widget::addCoordsByClick( QMouseEvent* pe ) -{ - if (pe->button() != Qt::LeftButton) - return; - - if ( pe->modifiers() != Qt::ControlModifier ) { - Handle(AIS_InteractiveContext) ic = getAISContext(); - if ( ic.IsNull() ) - return; - - gp_Pnt aPnt; - - ic->InitSelected(); - if ( pe->modifiers() == Qt::ShiftModifier ) - ic->ShiftSelect(); // Append selection - else - ic->Select(); // New selection - - { - OCCViewer_ViewPort3d* vp = getViewPort(); - aPnt = CurveCreator_Utils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); - } - // set the coordinates into dialog - CurveCreator::Coordinates aCoords; - aCoords.push_back( aPnt.X() ); - aCoords.push_back( aPnt.Y() ); - if ( myCurve->getDimension() == 3 ) { - aCoords.push_back( aPnt.Z() ); - } - addNewPoint(aCoords); - } -} - -/** - * Manage mouse press events - * \param theWindow an owner of the signal - * \param theEvent a mouse event - */ -void CurveCreator_Widget::onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent ) -{ - if ( theEvent->button() != Qt::LeftButton ) - return; - - myPressedX = theEvent->x(); - myPressedY = theEvent->y(); - - switch( getActionMode() ) { - case ModificationMode: { - //store initial cursor position for Drag&Drop - setDragStarted( true, theEvent->pos() ); - break; - } - case AdditionMode: { - addCoordsByClick( theEvent ); - break; - } - default: - break; - } -} - -/** - * Manage mouse release events in Modification mode - * \param theWindow an owner of the signal - * \param theEvent a mouse event - */ -void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent ) -{ - if ( getActionMode() != ModificationMode ) - return; - - if ( myDragStarted ) { - bool isDragged = myDragged; - CurveCreator_ICurve::SectionToPointList aDraggedPoints; - QMap > anInitialDragPointsCoords; - if ( myDragged ) { - aDraggedPoints = myDragPoints; - anInitialDragPointsCoords = myInitialDragPointsCoords; - } - - setDragStarted( false ); - - if ( aDraggedPoints.size() > 0 ) { - // Collect old coordinates of the dragged points - CurveCreator_ICurve::SectionToPointCoordsList anOldPoints; - foreach ( const CurveCreator_ICurve::SectionToPoint aSectionToPoint, anInitialDragPointsCoords.keys() ) { - CurveCreator::Coordinates aCoords = anInitialDragPointsCoords.value( aSectionToPoint ); - anOldPoints.push_back( std::make_pair( aSectionToPoint, aCoords ) ); - } - - if ( myCurve->canPointsBeSorted() ) { - // Add old coordinates of the curve points (except the dragged points) to the list - for( int aSectionId = 0 ; aSectionId < myCurve->getNbSections() ; aSectionId++ ) { - CurveCreator::Coordinates aCoords; - for ( int aPointId = 0, aNb = myCurve->getNbPoints( aSectionId ); aPointId < aNb; aPointId++ ) { - aCoords = myCurve->getPoint( aSectionId, aPointId ); - if ( aCoords.size() < 2 ) { - continue; - } - - CurveCreator_ICurve::SectionToPoint aSectionToPoint = std::make_pair( aSectionId, aPointId ); - - if ( !anInitialDragPointsCoords.contains( aSectionToPoint ) ) { - anOldPoints.push_back( std::make_pair( aSectionToPoint, aCoords ) ); - } - } - } - - // Apply points sorting - CurveCreator_ICurve::SectionToPointList aPoints; - startCurveModification( aPoints, false ); - - myCurve->setSkipSorting( false ); - - CurveCreator_ICurve::SectionToPointCoordsList aCoordList; - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aDraggedPoints.begin(), - aLast = aDraggedPoints.end(); - for ( ; anIt != aLast; anIt++ ) { - int aSectionId = anIt->first; - int aPointId = anIt->second; - std::deque aPos = myCurve->getPoint( aSectionId, aPointId ); - - aCoordList.push_back( - std::make_pair( std::make_pair( aSectionId, aPointId ), aPos ) ); - } - - myCurve->setSeveralPoints( aCoordList, false ); - - finishCurveModification( aDraggedPoints ); - } else { - // if the drag of some points has happened, restore the drag selection - START_MEASURE_TIME; - setSelectedPoints( aDraggedPoints ); - END_MEASURE_TIME( "drop" ); - } - - // Save drag difference - myCurve->saveCoordDiff( anOldPoints ); - } - } - else // check whether the segment is clicked an a new point should be added to the segment - { - int aReleasedX = theEvent->x(); - int aReleasedY = theEvent->y(); - if ( myPressedX == aReleasedX && myPressedY == aReleasedY ) - insertPointToSelectedSegment( aReleasedX, aReleasedY ); - } - - // updates the input panel table to show the selected point coordinates - updateLocalPointView(); - updateUndoRedo(); -} - -/** - * Manage mouse move events in Modification mode - * \param theWindow an owner of the signal - * \param theEvent a mouse event - */ -void CurveCreator_Widget::onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent ) -{ - if ( getActionMode() != ModificationMode || !myDragStarted ) - return; - - QPoint aPos = theEvent->pos(); - if ( (aPos - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() ) - return; - - START_MEASURE_TIME; - - moveSelectedPoints( aPos.x(), aPos.y() ); - myDragStartPosition = aPos; - - END_MEASURE_TIME( "drag" ); -} - -/** - * Set zero viewer by the last view closed in - * \param theManager a viewer manager - */ -void CurveCreator_Widget::onLastViewClosed( SUIT_ViewManager* theManager ) -{ - myOCCViewer = 0; -} - -void CurveCreator_Widget::onMousePress( QMouseEvent* theEvent ) -{ - onMousePress( 0, theEvent ); -} - -void CurveCreator_Widget::onMouseRelease( QMouseEvent* theEvent ) -{ - onMouseRelease( 0, theEvent ); -} - -void CurveCreator_Widget::onMouseMove( QMouseEvent* theEvent ) -{ - onMouseMove( 0, theEvent ); -} - -void CurveCreator_Widget::onCellChanged( int theRow, int theColumn ) -{ - int aCurrSect = myLocalPointView->getSectionId( theRow ); - int aPntIndex = myLocalPointView->getPointId( theRow ); - - if ( aPntIndex < 0 ) - return; - - CurveCreator_ICurve::SectionToPointList aSelPoints; - startCurveModification( aSelPoints ); - - double aX = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble(); - double anY = myLocalPointView->item( theRow, 3 )->data( Qt::UserRole ).toDouble(); - std::deque aChangedPos; - aChangedPos.push_back( aX ); - aChangedPos.push_back( anY ); - myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos ); - - finishCurveModification( aSelPoints ); -} - -/** - * Removes a selected section from the curve. Updates undo/redo status - */ -void CurveCreator_Widget::removeSection() -{ - stopActionMode(); - - QList aSections = mySectionView->getSelectedSections(); - for( int i = 0 ; i < aSections.size() ; i++ ){ - int aSectNum = aSections[i] - (i); - myCurve->removeSection( aSectNum ); - mySectionView->sectionsRemoved( aSectNum ); - } - mySectionView->clearSelection(); - updateUndoRedo(); -} - -/** - * Removes a selected points from the curve. Updates undo/redo status - */ -void CurveCreator_Widget::removePoint() -{ - CurveCreator_ICurve::SectionToPointList aPoints; - getSelectedPoints( aPoints ); - if ( aPoints.size() == 0 ) - return; - - CurveCreator_ICurve::SectionToPointList aSelPoints; - startCurveModification( aSelPoints, false ); - - myCurve->removeSeveralPoints( aPoints ); - finishCurveModification( CurveCreator_ICurve::SectionToPointList() ); -} - -void CurveCreator_Widget::addNewPoint(const CurveCreator::Coordinates& theCoords) -{ - if( !myCurve ) - return; - QList aSections = mySectionView->getSelectedSections(); - if( aSections.size() == 0 ){ - return; - } - int aSection = aSections[0]; - myCurve->addPoints(theCoords, aSection); // add to the end of section - mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) ); - updateActionsStates(); - updateUndoRedo(); -} - -void CurveCreator_Widget::insertPointToSelectedSegment( const int theX, - const int theY ) -{ - Handle(AIS_InteractiveContext) aContext = getAISContext(); - - OCCViewer_ViewPort3d* aViewPort = getViewPort(); - Handle(V3d_View) aView; - if ( aViewPort ) - aView = aViewPort->getView(); - - if ( aContext.IsNull() || aView.IsNull() ) - return; - gp_Pnt aPoint; - gp_Pnt aPoint1, aPoint2; - Handle(AIS_InteractiveObject) anAISObject = myCurve->getAISObject(); - bool isFoundPoint = CurveCreator_Utils::pointOnObject( aView, anAISObject, theX, theY, - aPoint, aPoint1, aPoint2 ); - if ( !isFoundPoint ) - return; - - // insert the point to the model curve - CurveCreator_ICurve::SectionToPointList aSelPoints; - startCurveModification( aSelPoints ); - - CurveCreator::Coordinates aCoords; - aCoords.push_back( aPoint.X() ); - aCoords.push_back( aPoint.Y() ); - - CurveCreator_ICurve::SectionToPointList aPoints1, aPoints2; - findSectionsToPoints( aPoint1.X(), aPoint1.Y(), aPoints1 ); - findSectionsToPoints( aPoint2.X(), aPoint2.Y(), aPoints2 ); - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints1.begin(), - aLast = aPoints1.end(); - int aSectionId = -1; - // find the indices of the neighbour point - // there can be a case when a new point is added into two sections - int aPoint1Id = -1, aPoint2Id = -1; - for ( ; anIt != aLast && aSectionId < 0; anIt++ ) { - int aSectionCur = anIt->first; - CurveCreator_ICurve::SectionToPointList::const_iterator anIt2 = aPoints2.begin(), - aLast2 = aPoints2.end(); - for ( ; anIt2 != aLast2 && aSectionId < 0; anIt2++ ) { - if ( anIt2->first == aSectionCur ) { - aSectionId = aSectionCur; - aPoint1Id = anIt->second; - aPoint2Id = anIt2->second; - } - } - } - - int anInsertPos = -1; - int aLastPoint = myCurve->getNbPoints( aSectionId )-1; - if ( ( aPoint1Id == aLastPoint && aPoint2Id == 0 ) || - ( aPoint2Id == aLastPoint && aPoint1Id == 0 ) ) - anInsertPos = -1; // if the section happens between first and last points - else - anInsertPos = aPoint1Id < aPoint2Id ? aPoint1Id + 1 : aPoint2Id + 1; - - myCurve->addPoints( aCoords, aSectionId, anInsertPos ); - mySectionView->pointsAdded( aSectionId, myCurve->getNbPoints( aSectionId ) ); - - finishCurveModification( aSelPoints ); - - setSelectedPoints(); -} - -void CurveCreator_Widget::moveSelectedPoints( const int theXPosition, - const int theYPosition ) -{ - OCCViewer_ViewPort3d* aViewPort = getViewPort(); - if ( !aViewPort ) - return; - - CurveCreator_ICurve::SectionToPointList aPoints; - startCurveModification( aPoints, false ); - - gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(), - myDragStartPosition.y(), - aViewPort->getView() ); - gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( theXPosition, theYPosition, - aViewPort->getView() ); - double aXDelta = aStartPnt.X() - anEndPnt.X(); - double anYDelta = aStartPnt.Y() - anEndPnt.Y(); - - CurveCreator_ICurve::SectionToPointCoordsList aCoordList; - std::deque aChangedPos; - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myDragPoints.begin(), - aLast = myDragPoints.end(); - for ( ; anIt != aLast; anIt++ ) { - int aSectionId = anIt->first; - int aPointId = anIt->second; - aChangedPos = myCurve->getPoint( aSectionId, aPointId ); - if ( aChangedPos.size() < 2 ) - continue; - - // Remember drag points coordinates - if ( !myDragged ) { - myInitialDragPointsCoords.insert( std::make_pair( aSectionId, aPointId ), aChangedPos ); - } - - aChangedPos[0] = aChangedPos[0] - aXDelta; - aChangedPos[1] = aChangedPos[1] - anYDelta; - - aCoordList.push_back( - std::make_pair(std::make_pair( aSectionId, aPointId ), - aChangedPos )); - } - myCurve->setSeveralPoints( aCoordList, false ); - - myDragged = true; - finishCurveModification( myDragPoints ); -} - -void CurveCreator_Widget::updateLocalPointView() -{ - if ( myDragStarted ) - return; - Handle(AIS_InteractiveContext) aContext = getAISContext(); - if ( aContext.IsNull() ) - return; - - CurveCreator_Utils::getSelectedPoints( aContext, myCurve, myLocalPoints ); - int aNbPoints = myLocalPoints.size(); - - bool isRowLimit = aNbPoints > myLocalPointRowLimit; - myLocalPointView->setVisible( getActionMode() == ModificationMode && !isRowLimit ); - - if ( !isRowLimit ) { - bool isBlocked = myLocalPointView->blockSignals(true); - - myLocalPointView->setLocalPointsToTable( myLocalPoints ); - - myLocalPointView->blockSignals( isBlocked ); - } -} - -/** - * - */ -void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool isUpdateTable ) -{ - CurveCreator_Utils::setLocalPointContext( myCurve, getAISContext(), theOpen ); - if ( !theOpen && isUpdateTable ) - updateLocalPointView(); -} - -/** - * Set drag operation started. Save the position and a list of dragged points - * \param theState the drag operation state: started/finished - * \param thePoint the start drag position - */ -void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint ) -{ - if ( theState ) { - getSelectedPoints( myDragPoints ); - - myDragStarted = myDragPoints.size(); - myDragStartPosition = thePoint; - if ( myDragStarted ) { - // change a viewer interaction style in order to avoid a select rectangle build - myDragInteractionStyle = changeInteractionStyle( SUIT_ViewModel::KEY_FREE ); - myCurve->setSkipSorting( true ); - } - } - else { - if ( myDragStarted ) - changeInteractionStyle( myDragInteractionStyle ); - myDragStarted = false; - myDragPoints.clear(); - myInitialDragPointsCoords.clear(); - } - myDragged = false; -} - -void CurveCreator_Widget::getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints ) -{ - thePoints.clear(); - thePoints = myLocalPoints; -} - -void CurveCreator_Widget::setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& thePoints ) -{ - if ( myDragStarted ) - return; - Handle(AIS_InteractiveContext) aContext = getAISContext(); - if ( aContext.IsNull() || !aContext->HasOpenedContext() ) - return; - - CurveCreator_Utils::setSelectedPoints( aContext, myCurve, thePoints ); - - updateLocalPointView(); -} - -void CurveCreator_Widget::stopActionMode() -{ - setActionMode( NoneMode ); -} - -/** - * Get viewer information before perform the curve modification. - * Take a list of selected cuve points an close local context. - * The context should be closed because the curve presentation is - * redisplayed and if it is not closed, when we close the local context - * later, the presentation shown in the local context is disappeared. - * \param thePoints an output list of curve selected points - * \param theFillPoints a flag whether the selection list should be filled - */ -void CurveCreator_Widget::startCurveModification( - CurveCreator_ICurve::SectionToPointList& thePoints, - const bool theFillPoints ) -{ - if ( theFillPoints ) { - thePoints.clear(); - getSelectedPoints( thePoints ); - } - setLocalPointContext( false ); -} - -/** - * Restore the viewer state after the curve modification is done. - * Open local context and select given points inside it. - * \param thePoints a list of curve selected points - */ -void CurveCreator_Widget::finishCurveModification( - const CurveCreator_ICurve::SectionToPointList& thePoints ) -{ - if ( getActionMode() == ModificationMode ) - setLocalPointContext( true ); - setSelectedPoints( thePoints ); - updateUndoRedo(); -} - -/** - * Returns a point index in the model curve by the point coordinates in the viewer - * \param theX the X coordinate of the point - * \param theY the Y coordinate of the point - */ -int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY ) -{ - return CurveCreator_UtilsICurve::findLocalPointIndex( myCurve, theSectionId, theX, theY ); -} - -void CurveCreator_Widget::findSectionsToPoints( const double theX, const double theY, - CurveCreator_ICurve::SectionToPointList& thePoints ) -{ - return CurveCreator_UtilsICurve::findSectionsToPoints( myCurve, theX, theY, thePoints ); -} - -void CurveCreator_Widget::convert( const CurveCreator_ICurve::SectionToPointList& thePoints, - QMap >& theConvPoints ) -{ - return CurveCreator_UtilsICurve::convert( thePoints, theConvPoints ); -} - -/** - * Returns whethe the container has the value - * \param theList a container of values - * \param theValue a value - */ -bool CurveCreator_Widget::contains( const CurveCreator_ICurve::SectionToPointList& theList, - const CurveCreator_ICurve::SectionToPoint& theValue ) const -{ - return CurveCreator_UtilsICurve::contains( theList, theValue ); -} diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h deleted file mode 100644 index 31b4db03..00000000 --- a/src/HYDROCurveCreator/CurveCreator_Widget.h +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef CURVECREATOR_WIDGET_H -#define CURVECREATOR_WIDGET_H - -#include "CurveCreator_Macro.hxx" -#include "CurveCreator.hxx" -#include "CurveCreator_ICurve.hxx" - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include // TODO - remove - -class OCCViewer_Viewer; -class OCCViewer_ViewPort3d; - -class AIS_ListOfInteractive; - -class QAction; -class QPixmap; -class CurveCreator_TableView; -class CurveCreator_TreeView; -class CurveCreator_NewPointDlg; -class CurveCreator_NewSectionDlg; - -class CURVECREATOR_EXPORT CurveCreator_Widget : public QWidget -{ - Q_OBJECT - -public: - enum ActionFlags { - NoFlags = 0x00000000, - DisableDetectionMode = 0x00000001, - DisableNewSection = 0x00000002, - DisableClosedSection = 0x00000004 - }; - - enum ActionMode { - NoneMode, - AdditionMode, - ModificationMode, - DetectionMode - }; - -public: - explicit CurveCreator_Widget( QWidget* parent, - CurveCreator_ICurve *theCurve, - const int theActionFlags = NoFlags, - const QStringList& theCoordTitles = QStringList(), - Qt::WindowFlags fl=0, - int theLocalPointRowLimit = 20); - - // OCC viewer manipulation - void setOCCViewer( OCCViewer_Viewer* theViewer ); - - Handle(AIS_InteractiveContext) getAISContext(); - OCCViewer_ViewPort3d* getViewPort(); - int changeInteractionStyle( int theStyle ); - - void reset(); - void setCurve( CurveCreator_ICurve* theCurve ); - - QList getSelectedSections(); - void setSelectedSections( const QList& theSections ); - - void removeSelected(); - bool removeEnabled(); - - void setActionMode( const ActionMode& theMode ); - ActionMode getActionMode() const; - -signals: - void selectionChanged(); - void subOperationStarted( QWidget*, bool ); - void subOperationFinished( QWidget* ); - -public slots: - -protected slots: - void onAdditionMode(bool checked); - void onModificationMode(bool checked); - void onDetectionMode(bool checked); - void onModeChanged(bool checked); - void onNewSection(); - void onSelectionChanged(); - void onAddNewSection(); - void onEditSection( int theSection ); - void onModifySection(); - void onCancelSection(); - void onJoin(); - void onRemove(); - void onClearAll(); - void onJoinAll(); - void onSetSpline(); - void onSetPolyline(); - void onCloseSections(); - void onUncloseSections(); - void onUndo(); - void onRedo(); - void onUndoSettings(); - void onContextMenu(QPoint thePoint); - - void onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent ); - void onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent ); - void onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent ); - void onLastViewClosed( SUIT_ViewManager* theManager ); - - void onMousePress( QMouseEvent* theEvent ); - void onMouseRelease( QMouseEvent* theEvent ); - void onMouseMove( QMouseEvent* theEvent ); - - void onCellChanged( int theRow, int theColumn ); - -protected: - void addCoordsByClick( QMouseEvent* ); - -protected: - enum ActionId{ NONE_ID, - UNDO_ID, - REDO_ID, - NEW_SECTION_ID, - ADDITION_MODE_ID, - REMOVE_ID, - REMOVE_ALL_ID, - JOIN_ID, - JOIN_ALL_ID, - CLOSE_SECTIONS_ID, - UNCLOSE_SECTIONS_ID, - SET_SECTIONS_POLYLINE_ID, - SET_SECTIONS_SPLINE_ID, - CLEAR_ALL_ID, - SEPARATOR_ID, - MODIFICATION_MODE_ID, - DETECTION_MODE_ID - }; - -private: - OCCViewer_Viewer* getOCCViewer(); - - QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage, - const QString& theToolTip, const QKeySequence& theShortcut ); - QAction* getAction(ActionId theId); - QAction* getAction(ActionMode theMode); - - void updateActionsStates(); - void updateUndoRedo(); - - void removeSection(); - void removePoint(); - void addNewPoint(const CurveCreator::Coordinates& theCoords); - void insertPointToSelectedSegment( const int theXPosition, - const int theYPosition ); - void moveSelectedPoints( const int theXPosition, const int theYPosition ); - void updateLocalPointView(); - void setLocalPointContext( const bool theOpen, const bool isUpdateTable = false ); - - void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() ); - - void getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints ); - void setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& = - CurveCreator_ICurve::SectionToPointList() ); - - void stopActionMode(); - - void startCurveModification( CurveCreator_ICurve::SectionToPointList& thePoints, - const bool theFillPoints = true ); - void finishCurveModification( const CurveCreator_ICurve::SectionToPointList& thePoints = - CurveCreator_ICurve::SectionToPointList() ); - - // curve algorithm - int findLocalPointIndex( int theSectionId, float theX, float theY ); - void findSectionsToPoints( const double theX, const double theY, - CurveCreator_ICurve::SectionToPointList& thePoints ); - void convert( const CurveCreator_ICurve::SectionToPointList& thePoints, - QMap >& theConvPoints ); - - bool contains( const CurveCreator_ICurve::SectionToPointList& theList, - const CurveCreator_ICurve::SectionToPoint& theValue ) const; - -private: - QMap myActionMap; - CurveCreator_ICurve* myCurve; - CurveCreator_TreeView* mySectionView; - CurveCreator_TableView* myLocalPointView; - CurveCreator_ICurve::SectionToPointList myLocalPoints; - CurveCreator_NewSectionDlg* myNewSectionEditor; - OCCViewer_Viewer* myOCCViewer; - int myLocalPointRowLimit; - int mySection; - int myPointNum; - bool myDragStarted; - QPoint myDragStartPosition; - int myDragInteractionStyle; - CurveCreator_ICurve::SectionToPointList myDragPoints; - QMap myInitialDragPointsCoords; - bool myDragged; - QByteArray myGuiState; - int myPressedX; - int myPressedY; -}; - -#endif // CURVECREATOR_WIDGET_H diff --git a/src/HYDROCurveCreator/OCCViewer_Utilities.cxx b/src/HYDROCurveCreator/OCCViewer_Utilities.cxx deleted file mode 100644 index e89ce451..00000000 --- a/src/HYDROCurveCreator/OCCViewer_Utilities.cxx +++ /dev/null @@ -1,65 +0,0 @@ - -#include "OCCViewer_Utilities.h" - -#include -#include -#include -#include - -#include - -#include - -#include - -void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer, - const OCCViewer_ViewWindow::Mode2dType& theMode ) -{ - OCCViewer_ViewFrame* aFrame = dynamic_cast - ( theViewer->getViewManager()->getActiveView() ); - OCCViewer_ViewWindow* aView = aFrame ? aFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW ) : 0; - if ( !aView ) - return; - - // set a view mode - aView->set2dMode( theMode ); - bool is2dMode = theMode != OCCViewer_ViewWindow::No2dMode; - - // enable/disable view actions - QList aNo2dActions; - aNo2dActions << OCCViewer_ViewWindow::ChangeRotationPointId - << OCCViewer_ViewWindow::RotationId - << OCCViewer_ViewWindow::FrontId - << OCCViewer_ViewWindow::BackId - << OCCViewer_ViewWindow::TopId - << OCCViewer_ViewWindow::BottomId - << OCCViewer_ViewWindow::LeftId - << OCCViewer_ViewWindow::RightId - << OCCViewer_ViewWindow::AntiClockWiseId - << OCCViewer_ViewWindow::ClockWiseId - << OCCViewer_ViewWindow::ResetId; - - QtxActionToolMgr* aToolMgr = aView->toolMgr(); - QAction* anAction; - for ( int i = 0, aNb = aNo2dActions.size(); i < aNb; i++ ) { - anAction = aToolMgr->action( aNo2dActions[i] ); - if ( anAction ) - anAction->setEnabled( !is2dMode ); - } - - // change view position - Handle(V3d_View) aView3d = aView->getViewPort()->getView(); - if ( !aView3d.IsNull() ) { - switch ( theMode ) { - case OCCViewer_ViewWindow::XYPlane: - aView3d->SetProj (V3d_Zpos); - break; - case OCCViewer_ViewWindow::XZPlane: - aView3d->SetProj (V3d_Yneg); - break; - case OCCViewer_ViewWindow::YZPlane: - aView3d->SetProj (V3d_Xpos); - break; - } - } -} diff --git a/src/HYDROCurveCreator/OCCViewer_Utilities.h b/src/HYDROCurveCreator/OCCViewer_Utilities.h deleted file mode 100644 index c89eb45f..00000000 --- a/src/HYDROCurveCreator/OCCViewer_Utilities.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef OCCVIEWER_UTILITIES_H -#define OCCVIEWER_UTILITIES_H - -#include "CurveCreator_Macro.hxx" - -#include - -class OCCViewer_Viewer; - -#ifdef WIN32 -#pragma warning ( disable:4251 ) -#endif - -class CURVECREATOR_EXPORT OCCViewer_Utilities -{ -public: - - /*! - * Set 2D mode for the viewer. Hide or show 3D actions. - * \param theViewer an OCC viewer - * \param theMode OCC view window mode - */ - static void setViewer2DMode( OCCViewer_Viewer* theViewer, - const OCCViewer_ViewWindow::Mode2dType& theMode ); - -}; - -#endif diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 72423bb3..9711309a 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -164,8 +164,10 @@ QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedO { const Point& aSectPoint = aSectPointsList.Value( k ); + QString anXStr = QString::number( aSectPoint.X(), 'f', 2 ); + QString anYStr = QString::number( aSectPoint.Y(), 'f', 2 ); aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) );" ).arg( aPolylineName ) - .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() ); + .arg( i - 1 ).arg( anXStr ).arg( anYStr ); } } } diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 26bb74a6..a3acda81 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -5,6 +5,7 @@ set(PROJECT_HEADERS HYDROGUI.h HYDROGUI_AbstractDisplayer.h HYDROGUI_AISTrihedron.h + HYDROGUI_BathymetryPrs.h HYDROGUI_CalculationDlg.h HYDROGUI_CalculationOp.h HYDROGUI_ChannelDlg.h @@ -12,6 +13,7 @@ set(PROJECT_HEADERS HYDROGUI_ColorWidget.h HYDROGUI_CopyPasteOp.h HYDROGUI_CopyPastePositionOp.h + HYDROGUI_CurveCreatorProfile.h HYDROGUI_DataBrowser.h HYDROGUI_DataModel.h HYDROGUI_DataModelSync.h @@ -58,6 +60,8 @@ set(PROJECT_HEADERS HYDROGUI_Region.h HYDROGUI_RemoveImageRefsOp.h HYDROGUI_Shape.h + HYDROGUI_ShapeBathymetry.h + HYDROGUI_ShapeImage.h HYDROGUI_ShowHideOp.h HYDROGUI_StreamDlg.h HYDROGUI_StreamOp.h @@ -102,6 +106,7 @@ QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) set(PROJECT_SOURCES HYDROGUI_AbstractDisplayer.cxx HYDROGUI_AISTrihedron.cxx + HYDROGUI_BathymetryPrs.cxx HYDROGUI_CalculationDlg.cxx HYDROGUI_CalculationOp.cxx HYDROGUI_ChannelDlg.cxx @@ -109,6 +114,7 @@ set(PROJECT_SOURCES HYDROGUI_ColorWidget.cxx HYDROGUI_CopyPasteOp.cxx HYDROGUI_CopyPastePositionOp.cxx + HYDROGUI_CurveCreatorProfile.cxx HYDROGUI_DataBrowser.cxx HYDROGUI_DataModel.cxx HYDROGUI_DataModelSync.cxx @@ -155,6 +161,8 @@ set(PROJECT_SOURCES HYDROGUI_Region.cxx HYDROGUI_RemoveImageRefsOp.cxx HYDROGUI_Shape.cxx + HYDROGUI_ShapeBathymetry.cxx + HYDROGUI_ShapeImage.cxx HYDROGUI_ShowHideOp.cxx HYDROGUI_StreamDlg.cxx HYDROGUI_StreamOp.cxx @@ -214,16 +222,15 @@ include_directories( ${GEOM_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROData - ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROCurveCreator ${VTK_INCLUDE_DIRS} ) add_library(HYDROGUI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${PROJECT_HEADERS_MOC}) -target_link_libraries(HYDROGUI HYDROData HYDROCurveCreator +target_link_libraries(HYDROGUI HYDROData ${CAS_TKV3d} ${CAS_TKTopAlgo} ${CAS_TKBrep} ${CAS_TKBO} ${GUI_LightApp} ${GUI_CAM} ${GUI_suit} ${GUI_qtx} ${GUI_ObjBrowser} ${GUI_GraphicsView} ${GUI_std} - ${GUI_Event} ${GUI_OCCViewer} ${GEOM_GEOM} ${GEOM_GEOMBase} + ${GUI_Event} ${GUI_OCCViewer} ${GEOM_GEOM} ${GEOM_GEOMBase} ${GEOM_CurveCreator} ${VTK_LIBRARIES} ${SVTK} ${SalomeObject} ${SalomePrs} ) diff --git a/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx b/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx new file mode 100644 index 00000000..057cdcfa --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx @@ -0,0 +1,113 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const int BATH_HIGHLIGHT_MODE = 10; + +HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs() +{ + SetHilightMode( BATH_HIGHLIGHT_MODE ); +} + +HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs() +{ +} + +void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords, + const Handle(Quantity_HArray1OfColor)& theColors ) +{ + myBound.SetVoid(); + if( !theCoords.IsNull() ) + { + int aLower = theCoords->Lower(); + int anUpper = theCoords->Upper(); + + for( int i = aLower; i <= anUpper; i++ ) + { + if( i==aLower ) + myBound.Set( theCoords->Value( i ) ); + else + { + gp_Pnt aPnt = theCoords->Value( i ); + myBound.Update( aPnt.X(), aPnt.Y(), aPnt.Z() ); + } + } + } + AIS_PointCloud::SetPoints( theCoords, theColors ); +} + +void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode ) +{ + if( theMode==BATH_HIGHLIGHT_MODE ) + { + thePresentation->Clear(); + if( myBound.IsVoid() || + myBound.IsOpenXmin() || myBound.IsOpenXmax() || + myBound.IsOpenYmin() || myBound.IsOpenYmax() || + myBound.IsOpenZmin() || myBound.IsOpenZmax() ) + return; + + Standard_Real xmin, xmax, ymin, ymax, zmin, zmax; + myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax ); + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); + Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0 ); + aGroup->SetPrimitivesAspect( aWireAspect->Aspect() ); + + Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 ); + + aLines->AddBound( 5 ); + aLines->AddVertex( xmin, ymin, zmin ); + aLines->AddVertex( xmax, ymin, zmin ); + aLines->AddVertex( xmax, ymax, zmin ); + aLines->AddVertex( xmin, ymax, zmin ); + aLines->AddVertex( xmin, ymin, zmin ); + aLines->AddBound( 5 ); + aLines->AddVertex( xmin, ymin, zmax ); + aLines->AddVertex( xmax, ymin, zmax ); + aLines->AddVertex( xmax, ymax, zmax ); + aLines->AddVertex( xmin, ymax, zmax ); + aLines->AddVertex( xmin, ymin, zmax ); + aLines->AddBound( 2 ); + aLines->AddVertex( xmin, ymin, zmin ); + aLines->AddVertex( xmin, ymin, zmax ); + aLines->AddBound( 2 ); + aLines->AddVertex( xmax, ymin, zmin ); + aLines->AddVertex( xmax, ymin, zmax ); + aLines->AddBound( 2 ); + aLines->AddVertex( xmax, ymax, zmin ); + aLines->AddVertex( xmax, ymax, zmax ); + aLines->AddBound( 2 ); + aLines->AddVertex( xmin, ymax, zmin ); + aLines->AddVertex( xmin, ymax, zmax ); + aGroup->AddPrimitiveArray( aLines ); + } + else + AIS_PointCloud::Compute( thePresentationManager, thePresentation, theMode ); +} + +void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, + const Standard_Integer theMode ) +{ + if( theMode == 0 ) + { + if( myBound.IsVoid() || + myBound.IsOpenXmin() || myBound.IsOpenXmax() || + myBound.IsOpenYmin() || myBound.IsOpenYmax() || + myBound.IsOpenZmin() || myBound.IsOpenZmax() ) + return; + + Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this ); + Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound ); + theSelection->Add( aSensitiveBox ); + } +} diff --git a/src/HYDROGUI/HYDROGUI_BathymetryPrs.h b/src/HYDROGUI/HYDROGUI_BathymetryPrs.h new file mode 100644 index 00000000..5ea3fd24 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_BathymetryPrs.h @@ -0,0 +1,50 @@ +// 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 +// + +#ifndef HYDROGUI_BATHYMETRY_PRS_H +#define HYDROGUI_BATHYMETRY_PRS_H + +#include +#include + +class HYDROGUI_BathymetryPrs : public AIS_PointCloud +{ +public: + HYDROGUI_BathymetryPrs(); + virtual ~HYDROGUI_BathymetryPrs(); + + virtual void SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords, + const Handle(Quantity_HArray1OfColor)& theColors = NULL ); + +protected: + virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode = 0 ); + virtual void ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, + const Standard_Integer theMode ); + +private: + Bnd_Box myBound; +}; + +#endif + diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 954e789f..f3b4351c 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -296,13 +296,13 @@ void HYDROGUI_CalculationOp::onObjectsSelected() aName = anEntity->GetName(); isSelected = aSelectedObjsMap.contains( aName ); aShape->highlight( isSelected, false ); - aShape->update( false ); + aShape->update( false, false ); aLastShape = aShape; } } } if( aLastShape ) - aLastShape->update( true ); + aLastShape->update( true, false ); } void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem ) @@ -407,7 +407,7 @@ void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltit HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() ); if ( aShape ) { - aShape->update(); + aShape->update( true, false ); } } aPanel->refreshZonesBrowser(); diff --git a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx index e820deb6..c91f314a 100644 --- a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx @@ -109,7 +109,7 @@ void HYDROGUI_ChannelOp::startOperation() } // collect information about existing profiles - QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE ); + QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE, true ); aPanel->setObjectName( anObjectName ); diff --git a/src/HYDROGUI/HYDROGUI_CopyPastePositionOp.cxx b/src/HYDROGUI/HYDROGUI_CopyPastePositionOp.cxx index 48ed4378..58f4fe0e 100644 --- a/src/HYDROGUI/HYDROGUI_CopyPastePositionOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CopyPastePositionOp.cxx @@ -58,8 +58,8 @@ void HYDROGUI_CopyPastePositionOp::startOperation() SUIT_ViewWindow* aViewWindow = aViewMgr ? aViewMgr->getActiveView() : 0; double aX, aY, aZ; if ( aDisplayer->GetCursorViewCoordinates( aViewWindow, aX, aY, aZ ) ) { - QString aXStr = HYDROGUI_Tool::GetCoordinateString( aX ); - QString anYStr = HYDROGUI_Tool::GetCoordinateString( aY ); + QString aXStr = HYDROGUI_Tool::GetCoordinateString( aX, false ); + QString anYStr = HYDROGUI_Tool::GetCoordinateString( aY, false ); aResult = tr( "%1,%2" ).arg( aXStr ).arg( anYStr ); } } diff --git a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx new file mode 100644 index 00000000..07c51742 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx @@ -0,0 +1,262 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include + +HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile() +: CurveCreator_Curve( CurveCreator::Dim2d ) +{ + CurveCreator_Section *aSection = new CurveCreator_Section; + aSection->myName = getUniqSectionName(); + aSection->myType = CurveCreator::Polyline; + aSection->myIsClosed = false; + + mySections.push_back( aSection ); +} + +HYDROGUI_CurveCreatorProfile::~HYDROGUI_CurveCreatorProfile() +{ +} + +bool HYDROGUI_CurveCreatorProfile::moveSectionInternal( const int theISection, + const int theNewIndex ) +{ + return false; +} + +bool HYDROGUI_CurveCreatorProfile::moveSection( const int theISection, + const int theNewIndex ) +{ + return false; +} + +bool HYDROGUI_CurveCreatorProfile::clearInternal() +{ + // erase curve from the viewer + if( myDisplayer ) + myDisplayer->eraseAll( true ); + + // Delete all allocated data. + CurveCreator_Section* aSection = getSection( 0 ); + if ( aSection ) + aSection->myPoints.clear(); + + return true; +} + +bool HYDROGUI_CurveCreatorProfile::joinInternal( const std::list& theSections ) +{ + return false; +} + +bool HYDROGUI_CurveCreatorProfile::join( const std::list& theSections ) +{ + return false; +} + +int HYDROGUI_CurveCreatorProfile::addSectionInternal( const std::string& theName, + const CurveCreator::SectionType theType, + const bool theIsClosed, + const CurveCreator::Coordinates& thePoints ) +{ + return -1; +} + +int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName, + const CurveCreator::SectionType theType, + const bool theIsClosed ) +{ + return -1; +} + +int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName, + const CurveCreator::SectionType theType, + const bool theIsClosed, + const CurveCreator::Coordinates& thePoints ) +{ + return -1; +} + +bool HYDROGUI_CurveCreatorProfile::removeSectionInternal( const int theISection ) +{ + return false; +} + +bool HYDROGUI_CurveCreatorProfile::removeSection( const int theISection ) +{ + return false; +} + +bool HYDROGUI_CurveCreatorProfile::setClosedInternal( const int theISection, const bool theIsClosed ) +{ + return false; +} + +bool HYDROGUI_CurveCreatorProfile::setClosed( const int theISection, const bool theIsClosed ) +{ + return false; +} + +bool HYDROGUI_CurveCreatorProfile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ) +{ + bool res = false; + + CurveCreator_Section* aSection = getSection( 0 ); + if( !aSection ) + return res; + + CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); + for ( ; anIt != theSectionsMap.end(); anIt++ ) + { + int anISection = anIt->first; + if( anISection != 0 ) + continue; + + const CurveCreator::PosPointsList& aSectionPoints = anIt->second; + + CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); + for( ; aPntIt != aSectionPoints.end(); aPntIt++ ) + { + const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords; + CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin(); + for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ ) + { + const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++; + if ( aNewPntIt == aNewCoords.end() ) + break; + + const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt; + + CurveCreator::TypeCoord aC = aCoordU - 1; + if ( !aSection->myPoints.empty() ) + aC = *(aSection->myPoints.end() - 2); + + if ( aSection->myPoints.empty() || aCoordU >= aC ) + { + aSection->myPoints.push_back( aCoordU ); + aSection->myPoints.push_back( aCoordZ ); + } + else if ( aCoordU < aSection->myPoints.front() ) + { + aSection->myPoints.push_front( aCoordZ ); + aSection->myPoints.push_front( aCoordU ); + } + else + { + CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin(); + for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ ) + { + const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++; + if ( aCoordU < aRefCoordU ) + break; + } + + aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 ); + } + } + } + + res = true; + } + + if ( res ) + redisplayCurve(); + + return res; +} + +//! For internal use only! Undo/Redo are not used here. +bool HYDROGUI_CurveCreatorProfile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ) +{ + bool aRes = false; + + if ( mySkipSorting ) { + return CurveCreator_Curve::setPointInternal( theSectionsMap ); + } + + int anISection = 0; + CurveCreator_Section* aSection = getSection( anISection ); + if( !aSection ) + return aRes; + + CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); + if ( anIt == theSectionsMap.end() ) + return aRes; + + const CurveCreator::PosPointsList& aSectionPoints = anIt->second; + + std::list aConvPoints; + convert( aSectionPoints, aConvPoints ); + removeSectionPoints( anISection, aConvPoints ); + + aRes = addPointsInternal( theSectionsMap ); + if ( aRes ) + redisplayCurve(); + + return aRes; +} + +void HYDROGUI_CurveCreatorProfile::convert( const CurveCreator::PosPointsList& thePoints, + std::list& theConvPoints ) +{ + theConvPoints.clear(); + + CurveCreator::PosPointsList::const_iterator aPntIt = thePoints.begin(), + aPntLast = thePoints.end(); + for( ; aPntIt != aPntLast; aPntIt++ ) + { + int anIPnt = (*aPntIt)->myID; + theConvPoints.push_back( anIPnt ); + } +} + +bool HYDROGUI_CurveCreatorProfile::canPointsBeSorted() +{ + return true; +} + +/** + * Add one point to the specified section starting from the given theIPnt index + * (or at the end of points if \a theIPnt is -1). + */ +bool HYDROGUI_CurveCreatorProfile::addPoints( const CurveCreator::Coordinates& theCoords, + const int theISection, + const int theIPnt ) +{ + int anIPnt = theIPnt; + + if ( anIPnt == - 1 && theCoords.size() > 1 ) { + CurveCreator::Coordinates aCoords; + for ( int i = 0, aNb = getNbPoints( theISection ); i < aNb; i++ ) { + aCoords = getPoint( theISection, i ); + if ( aCoords.size() < 2 ) { + continue; + } + + if ( theCoords[0] < aCoords[0] ) { + anIPnt = i; + break; + } + } + } + + return CurveCreator_Curve::addPoints( theCoords, theISection, anIPnt ); +} diff --git a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h new file mode 100644 index 00000000..5d4e97d5 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h @@ -0,0 +1,136 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_CurveCreator_Profile_HeaderFile +#define HYDROGUI_CurveCreator_Profile_HeaderFile + +#include "CurveCreator_Curve.hxx" + +/** + * The CurveCreator_Curve object is represented as one or more sets of + * connected points; thus CurveCreator_Curve object can contain several + * not connected curves (polylines or b-splines), each such curve has two + * only ends start and end points in other words non-manifold curves + * are not supported. + */ +class HYDROGUI_CurveCreatorProfile : public CurveCreator_Curve +{ + +public: + + //! Constructor of the curve. + HYDROGUI_CurveCreatorProfile(); + + //! Destructor. + virtual ~HYDROGUI_CurveCreatorProfile(); + +public: + + /***********************************************/ + /*** Section methods ***/ + /***********************************************/ + + //! For internal use only! Undo/Redo are not used here. + virtual bool clearInternal(); + + //! For internal use only! Undo/Redo are not used here. + virtual bool joinInternal( const std::list& theSections ); + + //! For internal use only! Undo/Redo are not used here. + virtual bool moveSectionInternal( const int theISection, + const int theNewIndex); + //! Move section to new position in list + virtual bool moveSection( const int theISection, + const int theNewIndex ); + //! Join list of sections to one section (join all if the list is empty) + // The first section in the list is a leader, another sections are joined to it + virtual bool join( const std::list& theSections ); + + //! For internal use only! Undo/Redo are not used here. + virtual int addSectionInternal( const std::string &theName, + const CurveCreator::SectionType theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints); + //! Add a new section. + virtual int addSection( const std::string &theName, + const CurveCreator::SectionType theType, + const bool theIsClosed ); + //! Add a new section. + virtual int addSection( const std::string &theName, + const CurveCreator::SectionType theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints); + + + //! For internal use only! Undo/Redo are not used here. + virtual bool removeSectionInternal( const int theISection ); + + //! Removes the given sections. + virtual bool removeSection( const int theISection ); + + + //! For internal use only! Undo/Redo are not used here. + virtual bool setClosedInternal( const int theISection, + const bool theIsClosed ); + /** + * Set "closed" flag of the specified section (all sections if + * \a theISection is -1). + */ + virtual bool setClosed( const int theISection, + const bool theIsClosed ); + + /***********************************************/ + /*** Point methods ***/ + /***********************************************/ + + //! For internal use only! Undo/Redo are not used here. + virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ); + /** + * Add one point to the specified section starting from the given theIPnt index + * (or at the end of points if \a theIPnt is -1). + */ + //! For internal use only! Undo/Redo are not used here. + virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ); + + /** + * Add one point to the specified section starting from the given theIPnt index. + * Contrary to CurveCreator_Curve::addPoints(...) if \a theIPnt is -1 the right index + * will be calculated automatically in accordance with X coordinate value of the point. + */ + virtual bool addPoints( const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt = -1 ); + + /** + * Indicates whether the points can be sorted. + */ + virtual bool canPointsBeSorted(); + +protected: + /** + * Converts the list of custom point position objects into a list of point indices + * \param thePoints an source list + * \param theConvPoints a converted list + */ + void convert( const CurveCreator::PosPointsList& thePoints, + std::list& theConvPoints ); + +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_DataObject.h b/src/HYDROGUI/HYDROGUI_DataObject.h index b35d60c0..5d4ffb89 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.h +++ b/src/HYDROGUI/HYDROGUI_DataObject.h @@ -25,13 +25,22 @@ #include -#include +#ifdef WIN32 + #pragma warning( disable: 4250 ) + #pragma warning( disable: 4251 ) +#endif +#include #include #include #include #include +#ifdef WIN32 + #pragma warning( disable: 4250 ) + #pragma warning( disable: 4251 ) +#endif + /** * \class HYDROGUI_DataObject * \brief Module data object, used for object browser tree creation. diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index 030ca3ed..7614db2a 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -30,7 +30,7 @@ #include "HYDROGUI_PrsZoneDriver.h" #include "HYDROGUI_Tool.h" -#include +#include #include #include diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx index 7bb035f0..8f6c6943 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx @@ -24,7 +24,7 @@ #include "HYDROGUI_Tool.h" -#include +#include #include #include @@ -228,10 +228,10 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataList& theData ) // Get georeferencement data for the current profile QString aXg, anYg, aXd, anYd; if ( !aGeoData.isEmpty ) { - aXg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xg ); - anYg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yg ); - aXd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xd ); - anYd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yd ); + aXg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xg, false ); + anYg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yg, false ); + aXd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xd, false ); + anYd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yd, false ); } // Insert row with the data @@ -316,8 +316,8 @@ void HYDROGUI_GeoreferencementDlg::onMousePress( int aColumnX = aColumn < 3 ? 1 : 3; int aColumnY = aColumnX + 1; - QString aXStr = HYDROGUI_Tool::GetCoordinateString( aPnt.X() ); - QString anYStr = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() ); + QString aXStr = HYDROGUI_Tool::GetCoordinateString( aPnt.X(), false ); + QString anYStr = HYDROGUI_Tool::GetCoordinateString( aPnt.Y(), false ); myTable->item( aRow, aColumnX )->setText( aXStr ); myTable->item( aRow, aColumnY )->setText( anYStr ); } diff --git a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx index b6c0fd02..82ec0181 100644 --- a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -256,7 +257,7 @@ void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName TopoDS_Face aFace; if( !aZoneShape.IsNull() ) aFace = TopoDS::Face( aZoneShape ); - myPreviewPrs->setFace( aFace ); + myPreviewPrs->setFace( aFace, true, true, "" ); } QApplication::restoreOverrideCursor(); diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx index 4e828055..b7772dd6 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx @@ -186,6 +186,8 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, aVTKMgr = module()->getApp()->viewManager( SVTK_Viewer::Type() ); } } + + /* // If there is no VTK viewer yet then create a new one if ( !aVTKMgr ) { @@ -195,9 +197,10 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, if ( aVTKMgr ) { module()->setObjectVisible( (size_t)aVTKMgr->getViewModel(), aBathymetryObj, true ); - } + }*/ - theUpdateFlags = UF_Model | UF_VTKViewer | UF_VTK_Init | UF_VTK_Forced; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | + UF_VTKViewer | UF_VTK_Forced; if( !myIsEdit ) { diff --git a/src/HYDROGUI/HYDROGUI_LocalCSDlg.cxx b/src/HYDROGUI/HYDROGUI_LocalCSDlg.cxx index 2b0168b3..18920b94 100644 --- a/src/HYDROGUI/HYDROGUI_LocalCSDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_LocalCSDlg.cxx @@ -36,6 +36,8 @@ HYDROGUI_LocalCSDlg::HYDROGUI_LocalCSDlg( HYDROGUI_Module* theModule, const QStr addWidget( aFrame, 1 ); QGridLayout* aLayout = new QGridLayout( aFrame ); + aLayout->setMargin( 5 ); + aLayout->setSpacing( 5 ); myLX = new QtxDoubleSpinBox( 0, RANGE, STEP, PREC, PREC, aFrame ); myLX->setValue( 0.0 ); diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 4aef231e..51e6c303 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -51,7 +51,7 @@ #include -#include +#include #include #include @@ -937,6 +937,23 @@ void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject, } /////////////////// OCC SHAPES PROCESSING +QList HYDROGUI_Module::getObjectShapes( const int theViewId, + ObjectKind theKind ) const +{ + QList aResult; + + if ( myShapesMap.contains( theViewId ) ) + { + const ListOfShapes& aViewShapes = myShapesMap.value( theViewId ); + foreach ( HYDROGUI_Shape* aShape, aViewShapes ) + { + if( aShape && aShape->getObject()->GetKind()==theKind ) + aResult.append( aShape ); + } + } + return aResult; +} + HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject ) const { @@ -1519,10 +1536,10 @@ void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false ); double WX = aWPnt.X(), WY = aWPnt.Y(); - QString aXStr = HYDROGUI_Tool::GetCoordinateString( X ); - QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y ); - QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX ); - QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY ); + QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true ); + QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true ); + QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true ); + QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true ); QString aMsg = tr( "COORDINATES_INFO" ); aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr ); aDesktop->statusBar()->showMessage( aMsg ); diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index e2dee3ee..963a734e 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -135,6 +135,8 @@ public: */ void setIsToUpdate( const Handle(HYDROData_Entity)& theObject, const bool theState = true ); + QList getObjectShapes( const int theViewId, + ObjectKind theKind ) const; HYDROGUI_Shape* getObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject ) const; void setObjectShape( const int theViewId, diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 310e84de..8ff07424 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -25,15 +25,19 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" -#include "HYDROGUI_Shape.h" +#include +#include #include "HYDROGUI_Operation.h" #include "HYDROGUI_DataObject.h" #include "HYDROGUI_ZLayers.h" +#include #include #include #include +#include + #include #include @@ -42,10 +46,12 @@ #include #include #include +#include HYDROGUI_OCCDisplayer::HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule ) : HYDROGUI_AbstractDisplayer( theModule ) { + myToUpdateColorScale = false; } HYDROGUI_OCCDisplayer::~HYDROGUI_OCCDisplayer() @@ -120,6 +126,7 @@ void HYDROGUI_OCCDisplayer::EraseAll( const int theViewerId ) return; module()->removeViewShapes( (size_t)aViewer ); + UpdateColorScale( aViewer ); } void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs, @@ -138,6 +145,7 @@ void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs, module()->removeObjectShape( (size_t)aViewer, anObj ); } aViewer->update(); + UpdateColorScale( aViewer ); } HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int theViewerId, @@ -151,7 +159,13 @@ HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int if ( !HYDROGUI_Tool::IsObjectHasPresentation( theObject, OCCViewer_Viewer::Type() ) ) return aResShape; - aResShape = new HYDROGUI_Shape( theContext, theObject ); + if( theObject->IsKind( STANDARD_TYPE( HYDROData_Image ) ) ) + aResShape = new HYDROGUI_ShapeImage( theContext, Handle_HYDROData_Image::DownCast( theObject ) ); + else if( theObject->IsKind( STANDARD_TYPE( HYDROData_Bathymetry ) ) ) + aResShape = new HYDROGUI_ShapeBathymetry( this, theContext, Handle_HYDROData_Bathymetry::DownCast( theObject ) ); + else + aResShape = new HYDROGUI_Shape( theContext, theObject ); + module()->setObjectShape( theViewerId, theObject, aResShape ); return aResShape; @@ -275,6 +289,8 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, else if ( !aCtx.IsNull() ) { // TODO: determine if this code is necessary (added as a fix for issue# 359) aCtx->UpdateSelected(); } + + UpdateColorScale( aViewer ); } void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId ) @@ -342,7 +358,7 @@ bool HYDROGUI_OCCDisplayer::Display( const Handle(HYDROData_Entity)& theObject, if ( anObjShape ) { // update if needed if ( anObjShape->getIsToUpdate() || theIsForced ) { - anObjShape->update( false ); + anObjShape->update( false, false ); } // Set visibility @@ -377,6 +393,86 @@ void HYDROGUI_OCCDisplayer::SetZLayer( const OCCViewer_Viewer* theViewer, // Set Z layer if ( anObjShape ) { - aCtx->SetZLayer( anObjShape->getAISShape(), theZLayerId ); + aCtx->SetZLayer( anObjShape->getAISObject(), theZLayerId ); } -} \ No newline at end of file +} + +void HYDROGUI_OCCDisplayer::SetToUpdateColorScale() +{ + myToUpdateColorScale = true; +} + +void HYDROGUI_OCCDisplayer::UpdateColorScale( const OCCViewer_Viewer* theViewer ) +{ + if( !myToUpdateColorScale ) + return; + + OCCViewer_ViewWindow* aWnd = dynamic_cast( theViewer->getViewManager()->getActiveView() ); + Handle(V3d_View) aView = aWnd->getViewPort()->getView(); + + int aViewerId = (size_t)theViewer;//TODO: check if viewer id is correct + QList aShapes = module()->getObjectShapes( aViewerId, KIND_BATHYMETRY ); + + bool isDisplayColorScale = !aShapes.empty(); + Standard_Real anXPos = 0.05; //TODO + Standard_Real anYPos = 0.1; //TODO + Standard_Real aWidth = 0.2; //TODO + Standard_Real aHeight = 0.5; //TODO + Standard_Integer aTextHeight = 14; //TODO + Standard_Integer aNbIntervals = 20; //TODO + TCollection_ExtendedString aColorScaleTitle = "";//TODO + + Standard_Real aColorScaleMin = 0, aColorScaleMax = 1, aMin, aMax; + bool isFirst = true; + foreach( HYDROGUI_Shape* aShape, aShapes ) + { + HYDROGUI_ShapeBathymetry* aBathShape = dynamic_cast( aShape ); + if( !aBathShape || !aBathShape->isVisible() ) + continue; + + aBathShape->GetRange( aMin, aMax ); + + if( isFirst || aMin < aColorScaleMin ) + aColorScaleMin = aMin; + if( isFirst || aMax > aColorScaleMax ) + aColorScaleMax = aMax; + + isFirst = false; + } + + if( isDisplayColorScale ) + { + Handle(Aspect_ColorScale) aColorScale = aView->ColorScale(); + if( !aColorScale.IsNull() ) + { + aColorScale->SetXPosition( anXPos ); + aColorScale->SetYPosition( anYPos ); + aColorScale->SetWidth( aWidth ); + aColorScale->SetHeight( aHeight ); + + aColorScale->SetTextHeight( aTextHeight ); + aColorScale->SetNumberOfIntervals( aNbIntervals ); + + aColorScale->SetTitle( aColorScaleTitle ); + aColorScale->SetRange( aColorScaleMin, aColorScaleMax ); + + foreach( HYDROGUI_Shape* aShape, aShapes ) + { + HYDROGUI_ShapeBathymetry* aBathShape = dynamic_cast( aShape ); + if( !aBathShape || !aBathShape->isVisible() ) + continue; + + aBathShape->UpdateWithColorScale( aColorScale ); + } + } + if( !aView->ColorScaleIsDisplayed() ) + aView->ColorScaleDisplay(); + } + else + { + if( aView->ColorScaleIsDisplayed() ) + aView->ColorScaleErase(); + } + + myToUpdateColorScale = false; +} diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h index ffa2ef9f..62f0cd52 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h @@ -76,6 +76,8 @@ public: void RemoveZLayer( OCCViewer_ViewManager* theMgr, const int theLayer ); + void SetToUpdateColorScale(); + protected: /** * \brief Erase all viewer objects. @@ -110,6 +112,8 @@ protected: */ void purgeObjects( const int theViewerId ); + void UpdateColorScale( const OCCViewer_Viewer* ); + private: /** * \brief Creates new OCC shape. @@ -142,6 +146,9 @@ private: void SetZLayer( const OCCViewer_Viewer* theViewer, const Handle(HYDROData_Entity)& theObject, const int theZLayerId ); + +private: + bool myToUpdateColorScale; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index a97508ef..384fd865 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include diff --git a/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx b/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx index f3bc6b9a..ff53fa17 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include @@ -220,8 +220,8 @@ void HYDROGUI_ProfileDlg::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEve theEvent->x(), theEvent->y(), anOCCViewWindow->getViewPort()->getView() ); // Show the coordinates - QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() ); - QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() ); + QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X(), true ); + QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y(), true ); myCoordLabel->setText( tr("UZ_COORDINATES_INFO").arg( aX ).arg( anY ) ); } } diff --git a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx index 609bdafd..fc5d0f15 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx @@ -19,16 +19,16 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "HYDROGUI_Module.h" -#include "HYDROGUI_ProfileOp.h" -#include "HYDROGUI_ProfileDlg.h" -#include "HYDROGUI_Tool.h" -#include "HYDROGUI_UpdateFlags.h" +#include +#include +#include +#include +#include #include -#include "HYDROData_Document.h" -#include "HYDROData_Profile.h" -#include "CurveCreator_Profile.hxx" -#include "CurveCreator_Displayer.h" +#include +#include +#include +#include #include #include @@ -78,7 +78,7 @@ void HYDROGUI_ProfileOp::startOperation() if( myProfile ) delete myProfile; - myProfile = new CurveCreator_Profile(); + myProfile = new HYDROGUI_CurveCreatorProfile(); HYDROGUI_Operation::startOperation(); diff --git a/src/HYDROGUI/HYDROGUI_ProfileOp.h b/src/HYDROGUI/HYDROGUI_ProfileOp.h index d93311a1..2f14640c 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileOp.h +++ b/src/HYDROGUI/HYDROGUI_ProfileOp.h @@ -27,7 +27,7 @@ #include -class CurveCreator_Profile; +class HYDROGUI_CurveCreatorProfile; class HYDROGUI_ProfileOp : public HYDROGUI_Operation { @@ -57,7 +57,7 @@ private: private: bool myIsEdit; Handle(HYDROData_Profile) myEditedObject; - CurveCreator_Profile* myProfile; + HYDROGUI_CurveCreatorProfile* myProfile; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 550deb93..fcbd28bb 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -20,58 +20,31 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "HYDROGUI_Shape.h" - -#include "HYDROGUI_DataObject.h" -#include "HYDROGUI_Tool.h" - -#include -#include - -#include - -#include -#include -#include - -#include - -#include -#include - +#include +#include #include #include #include -#include #include #include #include #include #include -#include #include #include #include +#include +#include +#include +#include +#include +#include #include -#include #include - +#include #include -#include - -#include - -#include -#include -#include - -#include - -#include -#include - HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext, const Handle(HYDROData_Entity)& theObject, const int theZLayer ) @@ -94,8 +67,41 @@ HYDROGUI_Shape::~HYDROGUI_Shape() if ( !myShape.IsNull() ) myShape.Nullify(); +} + +Handle(AIS_InteractiveContext) HYDROGUI_Shape::getContext() const +{ + return myContext; +} + +Handle(HYDROData_Entity) HYDROGUI_Shape::getObject() const +{ + return myObject; +} - removeTextureFile(); +TopoDS_Shape HYDROGUI_Shape::getTopoShape() const +{ + return myTopoShape; +} + +bool HYDROGUI_Shape::getIsToUpdate() const +{ + return myIsToUpdate; +} + +void HYDROGUI_Shape::setIsToUpdate( bool theState ) +{ + myIsToUpdate = theState; +} + +bool HYDROGUI_Shape::isVisible() const +{ + return myIsVisible; +} + +Handle(AIS_InteractiveObject) HYDROGUI_Shape::getAISObject() const +{ + return myShape; } void HYDROGUI_Shape::display( const bool theIsUpdateViewer ) @@ -114,14 +120,15 @@ void HYDROGUI_Shape::erase( const bool theIsUpdateViewer ) myContext->Erase( myShape, theIsUpdateViewer ); } -void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) +void HYDROGUI_Shape::update( bool isUpdateViewer, + bool isDeactivateSelection ) + { setIsToUpdate( false ); if ( myContext.IsNull() ) return; - bool isDeactivateSelection = false; // Try to retrieve information from object if ( !myObject.IsNull() ) { @@ -136,10 +143,11 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) if ( !aZoneShape.IsNull() ) { if ( aZoneShape.ShapeType() == TopAbs_FACE ) { TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape ); - setFace( aZoneFace, false, false ); + setFace( aZoneFace, false, false, "" ); } else { myTopoShape = aZoneShape; - myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2; + //TODO: myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2; + myDisplayMode = AIS_Shaded; buildShape(); updateShape( false, false ); @@ -209,7 +217,7 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() ); - setFace( aZoneFace, false, false ); + setFace( aZoneFace, false, false, "" ); if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) { // Red color for a zone with bathymetry conflict @@ -239,92 +247,6 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) ); } } - else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) ) - { - Handle(HYDROData_Image) anImageObj = - Handle(HYDROData_Image)::DownCast( myObject ); - - removeTextureFile(); - - QString aTextureFileName = generateTextureFileName( anImageObj ); - - QImage anImage = anImageObj->Image(); - QString aFilePath = anImageObj->GetFilePath(); - QTransform aTrsf = anImageObj->Trsf(); - - int aWidth = anImage.width(); - int aHeight = anImage.height(); - - QString anImageError = ""; - - QTransform anInversion = QTransform::fromScale( -1, -1 ); - anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation ); - - if ( anImage.isNull() ) - anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" ); - else - { - // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813 - int aTrsfWidth = anImage.width(); - int aDelta = aTrsfWidth % 4; - if ( aDelta > 0 ) - { - aTrsfWidth += ( 4 - aDelta ); - } - anImage = anImage.scaledToWidth( aTrsfWidth ); - - // temporary optimization, to reduce the saved image size (and the texture quality) - QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 ); - - bool isSaved = anImageToSave.save( aTextureFileName ); - if ( !isSaved ) - anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName ); - else - QFile::setPermissions( aTextureFileName, (QFile::Permissions)0x4FFFF ); - } - - if ( !anImageError.isEmpty() ) - { - SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ), - QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError ); - } - - QPointF aPoint1( 0, 0 ); // 1: top left - QPointF aPoint2( aWidth, 0 ); // 2: top right - QPointF aPoint3( aWidth, aHeight ); // 3: bottom right - QPointF aPoint4( 0, aHeight ); // 4: bottom left - - aPoint1 = aTrsf.map( aPoint1 ); - aPoint2 = aTrsf.map( aPoint2 ); - aPoint3 = aTrsf.map( aPoint3 ); - aPoint4 = aTrsf.map( aPoint4 ); - - QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4; - QRectF aRect = aPolygon.boundingRect(); - - gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 ); - gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 ); - gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 ); - gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 ); - - Handle_HYDROData_Document aDoc = HYDROData_Document::Document( anImageObj->Label() ); - aDoc->Transform( aPnt1, true ); - aDoc->Transform( aPnt2, true ); - aDoc->Transform( aPnt3, true ); - aDoc->Transform( aPnt4, true ); - - TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge(); - TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge(); - TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge(); - TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge(); - - TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire(); - aWire.Closed( true ); - - setTextureFileName( aTextureFileName, false, false ); - setFace( aWire, false, false ); - isDeactivateSelection = true; - } else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) ) { Handle(HYDROData_Profile) aProfile = @@ -402,7 +324,7 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) if ( myShape.IsNull() || !isVisible() ) return; - displayShape( theIsUpdateViewer ); + displayShape( isUpdateViewer ); if (isDeactivateSelection) myContext->Deactivate(myShape); @@ -490,23 +412,25 @@ void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires, void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire, const bool theToDisplay, - const bool theIsUpdateViewer ) + const bool theIsUpdateViewer, + const QString& theTextureFileName ) { BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True ); aFaceBuilder.Build(); if( aFaceBuilder.IsDone() ) { TopoDS_Face aFace = aFaceBuilder.Face(); - setFace( aFace, theToDisplay, theIsUpdateViewer ); + setFace( aFace, theToDisplay, theIsUpdateViewer, theTextureFileName ); } } void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace, const bool theToDisplay, - const bool theIsUpdateViewer ) + const bool theIsUpdateViewer, + const QString& theTextureFileName ) { myTopoShape = theFace; - myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2; + myDisplayMode = theTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2; //Note: AIS_Shaded+2 is the same as AIS_ExactHLR //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape @@ -561,19 +485,6 @@ QColor HYDROGUI_Shape::getHighlightColor() const return myHighlightColor; } -void HYDROGUI_Shape::setTextureFileName( const QString& theFileName, - const bool theToDisplay, - const bool theIsUpdateViewer ) -{ - myTextureFileName = theFileName; - updateShape( theToDisplay, theIsUpdateViewer ); -} - -QString HYDROGUI_Shape::getTextureFileName() const -{ - return myTextureFileName; -} - void HYDROGUI_Shape::setZLayer( const int theZLayer ) { if ( myZLayer == theZLayer ) @@ -584,29 +495,26 @@ void HYDROGUI_Shape::setZLayer( const int theZLayer ) myContext->SetZLayer( myShape, myZLayer ); } +Handle_AIS_InteractiveObject HYDROGUI_Shape::createShape() const +{ + if( myTopoShape.IsNull() ) + return Handle_AIS_InteractiveObject(); + else + return new AIS_Shape( myTopoShape ); +} + void HYDROGUI_Shape::buildShape() { // Erase previously created shape erase(); - if ( myTopoShape.IsNull() ) { - myShape.Nullify(); + myShape = createShape(); + if( myShape.IsNull() ) return; - } - - QString aTextureFileName = getTextureFileName(); - bool anIsTexture = !aTextureFileName.isEmpty(); - - if ( anIsTexture ) - { - myShape = new AIS_TexturedShape( myTopoShape ); - } - else - { - myShape = new AIS_Shape( myTopoShape ); - } - myShape->SetHLRAngleAndDeviation( 0.001 ); + Handle_AIS_Shape anAISShape = Handle_AIS_Shape::DownCast( myShape ); + if( !anAISShape.IsNull() ) + anAISShape ->SetHLRAngleAndDeviation( 0.001 ); if ( !myObject.IsNull() ) myShape->SetOwner( myObject ); @@ -614,18 +522,6 @@ void HYDROGUI_Shape::buildShape() myShape->SetTransparency( 0 ); myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode ); - if( anIsTexture ) - { - Handle(AIS_TexturedShape) aTexturedShape = - Handle(AIS_TexturedShape)::DownCast( myShape ); - - aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) ); - aTexturedShape->SetTextureMapOn(); - // Just use the texture image as is - aTexturedShape->DisableTextureModulate(); - aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face - } - // Init default params for shape const Handle(AIS_Drawer)& anAttributes = myShape->Attributes(); if ( !anAttributes.IsNull() ) @@ -733,79 +629,40 @@ void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor ) getQuantityColorVal( theColor.green() ), getQuantityColorVal( theColor.blue() ), Quantity_TOC_RGB ); - - if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode - { - myShape->SetColor( aBorderColor ); - } else if ( myDisplayMode == AIS_Shaded ) + if( !myTopoShape.IsNull() ) { - if ( theColor.alpha() == 0 ) + if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode { - anAttributes->SetFaceBoundaryDraw( false ); + myShape->SetColor( aBorderColor ); } - else + else if ( myDisplayMode == AIS_Shaded ) { - anAttributes->SetFaceBoundaryDraw( true ); - - Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect(); - if ( !aBoundaryAspect.IsNull() ) + if ( theColor.alpha() == 0 ) { - aBoundaryAspect->SetColor( aBorderColor ); - anAttributes->SetFaceBoundaryAspect( aBoundaryAspect ); + anAttributes->SetFaceBoundaryDraw( false ); + } + else + { + anAttributes->SetFaceBoundaryDraw( true ); + + Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect(); + if ( !aBoundaryAspect.IsNull() ) + { + aBoundaryAspect->SetColor( aBorderColor ); + anAttributes->SetFaceBoundaryAspect( aBoundaryAspect ); + } + Handle(Prs3d_LineAspect) aWireAspect = anAttributes->WireAspect(); + if ( !aWireAspect.IsNull() ) + { + aWireAspect->SetColor( aBorderColor ); + anAttributes->SetWireAspect( aWireAspect ); + } } } - } - else if ( myDisplayMode == AIS_WireFrame ) - { - myShape->SetColor( aBorderColor ); - } -} - -QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj ) -{ - QString aResult; - if( !theImageObj.IsNull() ) - { - QString aTempDir = HYDROGUI_Tool::GetTempDir( true ); - - int aStudyId = HYDROGUI_Tool::GetActiveStudyId(); - QString aPrefix = QString( "image_%1" ).arg( aStudyId ); - - QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false ); - anEntry.replace( ':', '_' ); - - QString anExtension = "bmp"; - - aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension ); - } - return aResult; -} - -void HYDROGUI_Shape::removeTextureFile() const -{ - QFile aFile( getTextureFileName() ); - if( aFile.exists() ) - aFile.remove(); -} - -QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit ) -{ - double aSizeLimit = (double)theSizeLimit; - double aWidth = (double)theImage.width(); - double aHeight = (double)theImage.height(); - if( aWidth > aSizeLimit || aHeight > aSizeLimit ) - { - if( aWidth > aHeight ) - { - aHeight /= ( aWidth / aSizeLimit ); - aWidth = aSizeLimit; - } - else + else if ( myDisplayMode == AIS_WireFrame ) { - aWidth /= ( aHeight / aSizeLimit ); - aHeight = aSizeLimit; + myShape->SetColor( aBorderColor ); } } - return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation ); } diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 6226f542..69ab1b17 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -23,17 +23,16 @@ #ifndef HYDROGUI_SHAPE_H #define HYDROGUI_SHAPE_H -#include -#include - #include +#include +#include + #include -#include -#include -#include -#include +class TopoDS_Compound; +class TopoDS_Face; +class TopoDS_Wire; class HYDROGUI_Shape { @@ -41,7 +40,7 @@ public: HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext, const Handle(HYDROData_Entity)& theObject, const int theZLayer = -1 ); - ~HYDROGUI_Shape(); + virtual ~HYDROGUI_Shape(); public: virtual void display( const bool theIsUpdateViewer = true ); @@ -50,14 +49,17 @@ public: virtual void highlight( bool theIsHighlight, bool isUpdateViewer ); virtual bool isHighlighted() const; - Handle(HYDROData_Entity) getObject() const { return myObject; } + Handle(AIS_InteractiveContext) getContext() const; + Handle(HYDROData_Entity) getObject() const; + TopoDS_Shape getTopoShape() const; - virtual void update( const bool theIsUpdateViewer = true ); + virtual void update( bool isUpdateViewer, + bool isDeactivateSelection ); - virtual bool getIsToUpdate() const { return myIsToUpdate; } - virtual void setIsToUpdate( bool theState ) { myIsToUpdate = theState; } + virtual bool getIsToUpdate() const; + virtual void setIsToUpdate( bool theState ); - virtual bool isVisible() const { return myIsVisible; } + virtual bool isVisible() const; virtual void setVisible( const bool theState, const bool theIsUpdateViewer = true ); @@ -70,12 +72,14 @@ public: const bool theIsUpdateViewer = true ); virtual void setFace( const TopoDS_Wire& theWire, - const bool theToDisplay = true, - const bool theIsUpdateViewer = true ); + const bool theToDisplay, + const bool theIsUpdateViewer, + const QString& theTextureFileName ); virtual void setFace( const TopoDS_Face& theFace, - const bool theToDisplay = true, - const bool theIsUpdateViewer = true ); + const bool theToDisplay, + const bool theIsUpdateViewer, + const QString& theTextureFileName ); virtual void setShape( const TopoDS_Shape& theShape, const bool theToDisplay = true, @@ -94,12 +98,7 @@ public: virtual void setHighlightColor( const QColor& theColor ); virtual QColor getHighlightColor() const; - virtual void setTextureFileName( const QString& theFileName, - const bool theToDisplay = true, - const bool theIsUpdateViewer = true ); - virtual QString getTextureFileName() const; - - virtual Handle(AIS_Shape) getAISShape() const { return myShape; } + virtual Handle(AIS_InteractiveObject) getAISObject() const; void setZLayer( const int theZLayer ); @@ -107,23 +106,19 @@ protected: virtual void buildShape(); virtual void updateShape( const bool theToDisplay = true, const bool theIsUpdateViewer = true ); - void displayShape( const bool theIsUpdateViewer ); + virtual void displayShape( const bool theIsUpdateViewer ); virtual QColor getActiveColor() const; + virtual Handle_AIS_InteractiveObject createShape() const; private: static double getQuantityColorVal( const int theColorVal ); void colorShapeBorder( const QColor& theColor ); - static QString generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj ); - void removeTextureFile() const; - - static QImage reduceTexture( const QImage& theImage, const int theSizeLimit ); - private: Handle(AIS_InteractiveContext) myContext; Handle(HYDROData_Entity) myObject; - Handle(AIS_Shape) myShape; + Handle(AIS_InteractiveObject) myShape; int myZLayer; @@ -137,8 +132,6 @@ private: QColor myFillingColor; QColor myBorderColor; QColor myHighlightColor; - - QString myTextureFileName; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx new file mode 100644 index 00000000..026f8a04 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx @@ -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 +// + +#include +#include +#include +#include + +#include +#include +#include +#include + +HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer* theDisplayer, + const Handle(AIS_InteractiveContext)& theContext, + const Handle_HYDROData_Bathymetry& theBathymetry, + const int theZLayer ) +: HYDROGUI_Shape( theContext, theBathymetry, theZLayer ), + myDisplayer( theDisplayer ) +{ +} + +HYDROGUI_ShapeBathymetry::~HYDROGUI_ShapeBathymetry() +{ + myDisplayer->SetToUpdateColorScale(); +} + +void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivateSelection ) +{ + setIsToUpdate( false ); + + // Try to retrieve information from object + + Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() ); + + if ( !aBath.IsNull() ) + { + buildShape(); + updateShape( false, false ); + } + + HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection ); +} + + +Handle_AIS_InteractiveObject HYDROGUI_ShapeBathymetry::createShape() const +{ + Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( getObject() ); + if( !aBath.IsNull() ) + { + Handle_AIS_PointCloud aPntCloud = new HYDROGUI_BathymetryPrs(); + aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 2.0)); + + const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints(); + int aLower = aBathPoints.Lower(); + int anUpper = aBathPoints.Upper(); + + HYDROGUI_ShapeBathymetry* aThat = const_cast( this ); + aThat->myCoords = new TColgp_HArray1OfPnt( aLower, anUpper ); + aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper ); + for( int i=aLower; i<=anUpper; i++ ) + aThat->myCoords->SetValue( i, aBathPoints.Value( i ) ); + + return aPntCloud; + } + else + return Handle_AIS_InteractiveObject(); +} + +void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const +{ + theMin = 0; + theMax = 0; + if( myCoords.IsNull() ) + return; + + bool isFirst = true; + for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ ) + { + double aValue = myCoords->Value( i ).Z(); + if( isFirst || aValue < theMin ) + theMin = aValue; + if( isFirst || aValue > theMax ) + theMax = aValue; + isFirst = false; + } +} + +void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale ) +{ + for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ ) + { + double z = myCoords->Value( i ).Z(); + Quantity_Color aColor; + theColorScale->FindColor( z, aColor ); + myColors->SetValue( i, aColor ); + } + Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( getAISObject() ); + aPntCloud->SetPoints( myCoords, myColors ); + getContext()->Redisplay( aPntCloud, Standard_False ); +} + +void HYDROGUI_ShapeBathymetry::setVisible( const bool theState, + const bool theIsUpdateViewer ) +{ + bool isShown = getContext()->IsDisplayed( getAISObject() ); + bool isChanged = ( isShown != theState ); + HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer ); + if( isChanged ) + myDisplayer->SetToUpdateColorScale(); +} + +void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer ) +{ + bool isShown = getContext()->IsDisplayed( getAISObject() ); + bool isChanged = ( !isShown ); + HYDROGUI_Shape::displayShape( theIsUpdateViewer ); + if( isChanged ) + myDisplayer->SetToUpdateColorScale(); +} + +void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer ) +{ + bool isShown = getContext()->IsDisplayed( getAISObject() ); + bool isChanged = ( !isShown ); + HYDROGUI_Shape::display( theIsUpdateViewer ); + if( isChanged ) + myDisplayer->SetToUpdateColorScale(); +} + +void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer ) +{ + bool isShown = getContext()->IsDisplayed( getAISObject() ); + bool isChanged = ( isShown ); + HYDROGUI_Shape::erase( theIsUpdateViewer ); + if( isChanged ) + myDisplayer->SetToUpdateColorScale(); +} diff --git a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h new file mode 100644 index 00000000..c584d592 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h @@ -0,0 +1,64 @@ +// 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 +// + +#ifndef HYDROGUI_SHAPE_BATHYMETRY_H +#define HYDROGUI_SHAPE_BATHYMETRY_H + +#include +#include +#include + +class Handle_HYDROData_Bathymetry; +class Handle_Aspect_ColorScale; +class HYDROGUI_OCCDisplayer; + +class HYDROGUI_ShapeBathymetry : public HYDROGUI_Shape +{ +public: + HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer* theDisplayer, + const Handle(AIS_InteractiveContext)& theContext, + const Handle_HYDROData_Bathymetry& theBathymetry, + const int theZLayer = -1 ); + virtual ~HYDROGUI_ShapeBathymetry(); + + void GetRange( double& theMin, double& theMax ) const; + void UpdateWithColorScale( const Handle_Aspect_ColorScale& ); + + virtual void display( const bool theIsUpdateViewer = true ); + virtual void erase( const bool theIsUpdateViewer = true ); + + virtual void update( bool isUpdateViewer, + bool isDeactivateSelection ); + + virtual void setVisible( const bool theState, + const bool theIsUpdateViewer = true ); +protected: + virtual Handle_AIS_InteractiveObject createShape() const; + virtual void displayShape( const bool theIsUpdateViewer ); + +private: + HYDROGUI_OCCDisplayer* myDisplayer; + Handle_TColgp_HArray1OfPnt myCoords; + Handle_Quantity_HArray1OfColor myColors; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ShapeImage.cxx b/src/HYDROGUI/HYDROGUI_ShapeImage.cxx new file mode 100644 index 00000000..f82a6b90 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ShapeImage.cxx @@ -0,0 +1,225 @@ +// 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 +// + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +HYDROGUI_ShapeImage::HYDROGUI_ShapeImage( const Handle(AIS_InteractiveContext)& theContext, + const Handle_HYDROData_Image& theImage, + const int theZLayer ) +: HYDROGUI_Shape( theContext, theImage, theZLayer ) +{ +} + +HYDROGUI_ShapeImage::~HYDROGUI_ShapeImage() +{ + removeTextureFile(); +} + +void HYDROGUI_ShapeImage::update( bool theIsUpdateViewer, bool isDeactivateSelection ) +{ + setIsToUpdate( false ); + + // Try to retrieve information from object + Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() ); + + if( !anImageObj.IsNull() ) + { + removeTextureFile(); + + QString aTextureFileName = generateTextureFileName( anImageObj ); + + QImage anImage = anImageObj->Image(); + QString aFilePath = anImageObj->GetFilePath(); + QTransform aTrsf = anImageObj->Trsf(); + + int aWidth = anImage.width(); + int aHeight = anImage.height(); + + QString anImageError = ""; + + QTransform anInversion = QTransform::fromScale( -1, -1 ); + anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation ); + + if ( anImage.isNull() ) + anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" ); + else + { + // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813 + int aTrsfWidth = anImage.width(); + int aDelta = aTrsfWidth % 4; + if ( aDelta > 0 ) + { + aTrsfWidth += ( 4 - aDelta ); + } + anImage = anImage.scaledToWidth( aTrsfWidth ); + + // temporary optimization, to reduce the saved image size (and the texture quality) + QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 ); + + bool isSaved = anImageToSave.save( aTextureFileName ); + if ( !isSaved ) + anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName ); + else + QFile::setPermissions( aTextureFileName, (QFile::Permissions)0x4FFFF ); + } + + if ( !anImageError.isEmpty() ) + { + SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ), + QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError ); + } + + QPointF aPoint1( 0, 0 ); // 1: top left + QPointF aPoint2( aWidth, 0 ); // 2: top right + QPointF aPoint3( aWidth, aHeight ); // 3: bottom right + QPointF aPoint4( 0, aHeight ); // 4: bottom left + + aPoint1 = aTrsf.map( aPoint1 ); + aPoint2 = aTrsf.map( aPoint2 ); + aPoint3 = aTrsf.map( aPoint3 ); + aPoint4 = aTrsf.map( aPoint4 ); + + QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4; + QRectF aRect = aPolygon.boundingRect(); + + gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 ); + gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 ); + gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 ); + gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 ); + + Handle_HYDROData_Document aDoc = HYDROData_Document::Document( anImageObj->Label() ); + aDoc->Transform( aPnt1, true ); + aDoc->Transform( aPnt2, true ); + aDoc->Transform( aPnt3, true ); + aDoc->Transform( aPnt4, true ); + + TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge(); + TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge(); + TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge(); + TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge(); + + TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire(); + aWire.Closed( true ); + + setTextureFileName( aTextureFileName, false, false ); + setFace( aWire, false, false, aTextureFileName ); + isDeactivateSelection = true; + } + + HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection ); +} + +void HYDROGUI_ShapeImage::setTextureFileName( const QString& theFileName, + const bool theToDisplay, + const bool theIsUpdateViewer ) +{ + myTextureFileName = theFileName; + updateShape( theToDisplay, theIsUpdateViewer ); +} + +QString HYDROGUI_ShapeImage::getTextureFileName() const +{ + return myTextureFileName; +} + +QString HYDROGUI_ShapeImage::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj ) +{ + QString aResult; + if( !theImageObj.IsNull() ) + { + QString aTempDir = HYDROGUI_Tool::GetTempDir( true ); + + int aStudyId = HYDROGUI_Tool::GetActiveStudyId(); + QString aPrefix = QString( "image_%1" ).arg( aStudyId ); + + QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false ); + anEntry.replace( ':', '_' ); + + QString anExtension = "bmp"; + + aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension ); + } + return aResult; +} + +void HYDROGUI_ShapeImage::removeTextureFile() const +{ + QFile aFile( getTextureFileName() ); + if( aFile.exists() ) + aFile.remove(); +} + +QImage HYDROGUI_ShapeImage::reduceTexture( const QImage& theImage, const int theSizeLimit ) +{ + double aSizeLimit = (double)theSizeLimit; + double aWidth = (double)theImage.width(); + double aHeight = (double)theImage.height(); + if( aWidth > aSizeLimit || aHeight > aSizeLimit ) + { + if( aWidth > aHeight ) + { + aHeight /= ( aWidth / aSizeLimit ); + aWidth = aSizeLimit; + } + else + { + aWidth /= ( aHeight / aSizeLimit ); + aHeight = aSizeLimit; + } + } + return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation ); +} + +Handle_AIS_InteractiveObject HYDROGUI_ShapeImage::createShape() const +{ + QString aTextureFileName = getTextureFileName(); + bool anIsTexture = !aTextureFileName.isEmpty(); + if ( anIsTexture ) + { + Handle_AIS_TexturedShape aTexturedShape = new AIS_TexturedShape( getTopoShape() ); + + aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) ); + aTexturedShape->SetTextureMapOn(); + // Just use the texture image as is + aTexturedShape->DisableTextureModulate(); + aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face + + return aTexturedShape; + } + else + return Handle_AIS_InteractiveObject(); +} + diff --git a/src/HYDROGUI/HYDROGUI_ShapeImage.h b/src/HYDROGUI/HYDROGUI_ShapeImage.h new file mode 100644 index 00000000..ac8a4d16 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ShapeImage.h @@ -0,0 +1,60 @@ +// 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 +// + +#ifndef HYDROGUI_SHAPE_IMAGE_H +#define HYDROGUI_SHAPE_IMAGE_H + +#include + +class Handle_HYDROData_Image; +class QImage; + +class HYDROGUI_ShapeImage : public HYDROGUI_Shape +{ +public: + HYDROGUI_ShapeImage( const Handle(AIS_InteractiveContext)& theContext, + const Handle_HYDROData_Image& theImage, + const int theZLayer = -1 ); + virtual ~HYDROGUI_ShapeImage(); + + virtual void setTextureFileName( const QString& theFileName, + const bool theToDisplay = true, + const bool theIsUpdateViewer = true ); + virtual QString getTextureFileName() const; + + virtual void update( bool isUpdateViewer, + bool isDeactivateSelection ); + +protected: + virtual Handle_AIS_InteractiveObject createShape() const; + +private: + static QString generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj ); + void removeTextureFile() const; + + static QImage reduceTexture( const QImage& theImage, const int theSizeLimit ); + +private: + QString myTextureFileName; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx index d754a33a..4dba86de 100644 --- a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx @@ -147,7 +147,11 @@ void HYDROGUI_ShowHideOp::startOperation() } else if ( anObject->GetKind() == KIND_BATHYMETRY && aVisibility ) { - if ( !(anUpdateFlags & UF_VTKViewer) ) + if ( anUpdateFlags & UF_OCCViewer ) + { + aModule->setObjectVisible( aViewId, anObject, aVisibility ); + } + else if ( !(anUpdateFlags & UF_VTKViewer) ) { // Activate VTK viewer if show a bathymetry aVTKMgr = aModule->getApp()->viewManager( SVTK_Viewer::Type() ); diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 5252cb2f..34f600f5 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -229,7 +230,8 @@ bool HYDROGUI_Tool::IsObjectHasPresentation( const Handle(HYDROData_Entity)& the anObjectKind == KIND_STREAM || anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE || - anObjectKind == KIND_DUMMY_3D + anObjectKind == KIND_DUMMY_3D || + anObjectKind == KIND_BATHYMETRY #ifdef DEB_GROUPS || anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP @@ -692,25 +694,39 @@ QColor HYDROGUI_Tool::GenerateFillingColor( const Handle(HYDROData_Document)& th } QStringList HYDROGUI_Tool::FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc, - const ObjectKind theObjectKind ) + const ObjectKind theObjectKind, + bool isCheckValidProfile ) { QStringList aNames; HYDROData_Iterator anIter( theDoc, theObjectKind ); for ( ; anIter.More(); anIter.Next() ) { Handle(HYDROData_Entity) anObject = anIter.Current(); - if( !anObject.IsNull() ) { - aNames.append( anObject->GetName() ); + + bool isOK = !anObject.IsNull(); + + if( isOK && isCheckValidProfile ) + { + Handle_HYDROData_Profile aProfile = Handle_HYDROData_Profile::DownCast( anObject ); + if( !aProfile.IsNull() && !aProfile->IsValid() ) + isOK = false; } + + if( isOK ) + aNames.append( anObject->GetName() ); } return aNames; } -QString HYDROGUI_Tool::GetCoordinateString( const double theNumber ) +QString HYDROGUI_Tool::GetCoordinateString( const double theNumber, bool isInLocale ) { - //return QString::number( theNumber, 'f', 2 ); - static QLocale aLocale( QLocale::English, QLocale::France ); - return aLocale.toString( theNumber, 'f', 2 ); + if( isInLocale ) + { + static QLocale aLocale( QLocale::English, QLocale::France ); + return aLocale.toString( theNumber, 'f', 2 ); + } + else + return QString::number( theNumber, 'f', 2 ); } diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 7e0efdd8..d504cc4a 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -335,14 +335,15 @@ public: * \return list of names */ static QStringList FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc, - const ObjectKind theObjectKind ); + const ObjectKind theObjectKind, + bool isCheckValidProfile = false ); /** * \brief Converts coordinate value to string. * \param theNumber coordinate as a number * \return coordinate as a string */ - static QString GetCoordinateString( const double theNumber ); + static QString GetCoordinateString( const double theNumber, bool isInLocale ); }; #endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx index 97d0d6c1..15006545 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx index a3d00e2f..00009b47 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx @@ -435,6 +435,10 @@ void HYDROGUI_VTKPrsDisplayer::createScalarBar( const int theViewId ) aScalarBar->SetNumberOfLabels( NB_COLORS * 0.75 ); aScalarBar->SetWidth( aScalarBar->GetWidth() / 1.5 ); aScalarBar->SetTextureGridWidth( aScalarBar->GetTextureGridWidth() * 4. ); + aScalarBar->SetTitle( " " ); + // The call of SetTitle() with dummy string is a workaround necessary + // to avoid the problem with uninitialized variables in VTK scalar bar actor + // which leads to incorrect (very big) size of the VTK scalar bar presentation aTable->Delete(); myScalarBars.insert( theViewId, aScalarBar ); } diff --git a/src/HYDROGUI/HYDROGUI_ZLayers2.cxx b/src/HYDROGUI/HYDROGUI_ZLayers2.cxx index bacb4db1..323aa4a3 100644 --- a/src/HYDROGUI/HYDROGUI_ZLayers2.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLayers2.cxx @@ -39,8 +39,8 @@ void UpdateZLayersOfHilightPresentationsOfDisplayedObjects( const Handle_AIS_Int Handle(AIS_InteractiveObject) aPrsObj = aListIter.Value(); if( !aPrsObj.IsNull() ) { - theContext->MainPrsMgr()->Color( aPrsObj ); int aMode = aPrsObj->HasHilightMode() ? aPrsObj->HilightMode() : 0; + theContext->MainPrsMgr()->Color( aPrsObj, Quantity_NOC_YELLOW, aMode ); SetPrsZLayer( aPrsObj, aMode, theLayer ); theContext->MainPrsMgr()->Unhighlight( aPrsObj, aMode ); } diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 574b4dda..02b897a1 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -101,7 +101,7 @@ CASE_SPLITTED_GROUPS - Splitted groups + Split groups FILE_CAN_NOT_BE_IMPORTED @@ -708,7 +708,7 @@ Would you like to remove all references from the image? DSK_EDIT_SPLITTED_IMAGE - Edit splitted image + Edit split image DSK_COPY_VIEWER_POSITION @@ -956,7 +956,7 @@ Would you like to remove all references from the image? MEN_EDIT_SPLITTED_IMAGE - Edit splitted image + Edit split image MEN_COPY_VIEWER_POSITION @@ -1184,7 +1184,7 @@ Would you like to remove all references from the image? STB_EDIT_SPLITTED_IMAGE - Edit splitted image + Edit split image STB_COPY_VIEWER_POSITION @@ -1548,7 +1548,7 @@ Would you like to remove all references from the image? EDIT_SPLITTED_IMAGE - Edit splitted image + Edit split image FUSE diff --git a/src/HYDROGUI/resources/LightApp.xml b/src/HYDROGUI/resources/LightApp.xml index fcae3718..7f1052e3 100644 --- a/src/HYDROGUI/resources/LightApp.xml +++ b/src/HYDROGUI/resources/LightApp.xml @@ -27,7 +27,7 @@ - +