From: adv Date: Fri, 13 Dec 2013 07:01:19 +0000 (+0000) Subject: Invert altitudes check-box added for bathymetry (Feature #231). X-Git-Tag: BR_hydro_v_0_5~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7677192227ae6d384a9b870fa76e60f5ec700c25;p=modules%2Fhydro.git Invert altitudes check-box added for bathymetry (Feature #231). --- diff --git a/src/HYDROData/HYDROData_Bathymetry.cxx b/src/HYDROData/HYDROData_Bathymetry.cxx index 2cacf6f0..43d484c7 100644 --- a/src/HYDROData/HYDROData_Bathymetry.cxx +++ b/src/HYDROData/HYDROData_Bathymetry.cxx @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -51,6 +52,9 @@ QStringList HYDROData_Bathymetry::DumpToPython( MapOfTreatedObjects& theTreatedO aResList << QString( "%1.SetName( \"%2\" );" ) .arg( aBathymetryName ).arg( aBathymetryName ); + aResList << QString( "%1.SetAltitudesInverted( %2 );" ) + .arg( aBathymetryName ).arg( IsAltitudesInverted() ); + QString aFilePath = GetFilePath(); if ( !aFilePath.isEmpty() ) { @@ -319,9 +323,58 @@ QString HYDROData_Bathymetry::GetFilePath() const { QString aRes; - Handle(TDataStd_AsciiString) anAsciiStr; - if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) - aRes = QString( anAsciiStr->Get().ToCString() ); + TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false ); + if ( !aLabel.IsNull() ) + { + Handle(TDataStd_AsciiString) anAsciiStr; + if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) + aRes = QString( anAsciiStr->Get().ToCString() ); + } + + return aRes; +} + +void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted, + const bool theIsUpdate ) +{ + bool anIsAltitudesInverted = IsAltitudesInverted(); + if ( anIsAltitudesInverted == theIsInverted ) + return; + + TDataStd_Integer::Set( myLab.FindChild( DataTag_AltitudesInverted ), (Standard_Integer)theIsInverted ); + + SetToUpdate( true ); + + if ( !theIsUpdate ) + return; + + // Update altitude points + AltitudePoints anAltitudePoints = GetAltitudePoints(); + if ( anAltitudePoints.isEmpty() ) + return; + + AltitudePoints::iterator aListItBeg = anAltitudePoints.begin(); + AltitudePoints::iterator aListItEnd = anAltitudePoints.end(); + for ( ; aListItBeg != aListItEnd; ++aListItBeg ) + { + AltitudePoint& aPoint = *aListItBeg; + aPoint.SetZ( aPoint.Z() * -1 ); + } + + SetAltitudePoints( anAltitudePoints ); +} + +bool HYDROData_Bathymetry::IsAltitudesInverted() const +{ + bool aRes = false; + + TDF_Label aLabel = myLab.FindChild( DataTag_AltitudesInverted, false ); + if ( !aLabel.IsNull() ) + { + Handle(TDataStd_Integer) anIntVal; + if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) ) + aRes = (bool)anIntVal->Get(); + } return aRes; } @@ -357,7 +410,7 @@ bool HYDROData_Bathymetry::ImportFromFile( const QString& theFileName ) } bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile, - AltitudePoints& thePoints ) + AltitudePoints& thePoints ) const { if ( !theFile.isOpen() ) return false; @@ -372,6 +425,7 @@ bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile, aTimer.Start(); #endif + bool anIsAltitudesInverted = IsAltitudesInverted(); while ( !theFile.atEnd() ) { QString aLine = theFile.readLine().simplified(); @@ -390,14 +444,17 @@ bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile, bool isXOk = false, isYOk = false, isZOk = false; - // We automaticaly convert the z value to a negative number aPoint.SetX( anX.toDouble( &isXOk ) ); aPoint.SetY( anY.toDouble( &isYOk ) ); - aPoint.SetZ( -aZ.toDouble( &isZOk ) ); + aPoint.SetZ( aZ.toDouble( &isZOk ) ); if ( !isXOk || !isYOk || !isZOk ) return false; + // Invert the z value if requested + if ( anIsAltitudesInverted ) + aPoint.SetZ( -aPoint.Z() ); + thePoints << aPoint; } diff --git a/src/HYDROData/HYDROData_Bathymetry.h b/src/HYDROData/HYDROData_Bathymetry.h index 7c4f092d..d4866779 100644 --- a/src/HYDROData/HYDROData_Bathymetry.h +++ b/src/HYDROData/HYDROData_Bathymetry.h @@ -30,8 +30,9 @@ protected: enum DataTag { DataTag_First = HYDROData_IAltitudeObject::DataTag_First + 100, ///< first tag, to reserve - DataTag_AltitudePoints, ///< altitude points, array of reals - DataTag_FilePath ///< bathymetry imported file path + DataTag_AltitudePoints, ///< altitude points, array of reals + DataTag_FilePath, ///< bathymetry imported file path + DataTag_AltitudesInverted, ///< flag to invert z values }; public: @@ -90,6 +91,19 @@ public: */ HYDRODATA_EXPORT QString GetFilePath() const; + /** + * Set flag indicating needs to invert altitude values + * \param theIsInverted new invert value + * \param theIsUpdate flag indicating necessity to update points + */ + HYDRODATA_EXPORT void SetAltitudesInverted( const bool theIsInverted, + const bool theIsUpdate = true ); + + /** + * Returns flag indicating needs to invert altitude values. + */ + HYDRODATA_EXPORT bool IsAltitudesInverted() const; + /** * Imports Bathymetry data from file. The supported file types: * - xyz @@ -105,7 +119,7 @@ private: * Imports Bathymetry data from 'XYZ' file. */ bool importFromXYZFile( QFile& theFile, - AltitudePoints& thePoints ); + AltitudePoints& thePoints ) const; protected: diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx index 561cd419..d1141ee9 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx @@ -34,6 +34,7 @@ #include #include #include +#include HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_InputPanel( theModule, theTitle ) @@ -70,9 +71,13 @@ HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* the aBathymetryNameLayout->addWidget( aBathymetryNameLabel ); aBathymetryNameLayout->addWidget( myObjectName ); + myInvertAltitudes = new QCheckBox( tr( "INVERT_BATHYMETRY_ALTITUDES" ), this ); + // Common addWidget( myFileNameGroup ); addWidget( myObjectNameGroup ); + addWidget( myInvertAltitudes ); + addStretch(); connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); @@ -113,6 +118,16 @@ QString HYDROGUI_ImportBathymetryDlg::getFileName() const return myFileName->text(); } +void HYDROGUI_ImportBathymetryDlg::setInvertAltitudes( const bool theIsInvert ) +{ + myInvertAltitudes->setChecked( theIsInvert ); +} + +bool HYDROGUI_ImportBathymetryDlg::isInvertAltitudes() const +{ + return myInvertAltitudes->isChecked(); +} + void HYDROGUI_ImportBathymetryDlg::onBrowse() { QString aFilter( tr( "BATHYMETRY_FILTER" ) ); diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h index 1a8a10a7..4b450f62 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h @@ -29,6 +29,7 @@ class QGroupBox; class QLineEdit; +class QCheckBox; class HYDROGUI_ImportBathymetryDlg : public HYDROGUI_InputPanel { @@ -46,6 +47,9 @@ public: void setFileName( const QString& theFileName ); QString getFileName() const; + void setInvertAltitudes( const bool theIsInvert ); + bool isInvertAltitudes() const; + signals: void FileSelected( const QString& theFileName ); @@ -56,6 +60,8 @@ private: QGroupBox* myFileNameGroup; QLineEdit* myFileName; + QCheckBox* myInvertAltitudes; + QGroupBox* myObjectNameGroup; QLineEdit* myObjectName; }; diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx index 458e2e80..9dacc370 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx @@ -67,8 +67,11 @@ void HYDROGUI_ImportBathymetryOp::startOperation() { QString aName = myEditedObject->GetName(); QString aFileName = myEditedObject->GetFilePath(); + bool anIsAltitudesInverted = myEditedObject->IsAltitudesInverted(); + aPanel->setObjectName( aName ); aPanel->setFileName( aFileName ); + aPanel->setInvertAltitudes( anIsAltitudesInverted ); } } } @@ -108,6 +111,8 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, } QString aFileName = aPanel->getFileName().simplified(); + bool anIsInvertAltitudes = aPanel->isInvertAltitudes(); + if ( aFileName.isEmpty() ) { theErrorMsg = tr( "INCORRECT_FILE_NAME" ); @@ -145,10 +150,19 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, if ( aBathymetryObj.IsNull() ) return false; - if ( !aBathymetryObj->ImportFromFile( aFileName ) ) + QString anOldFileName = aBathymetryObj->GetFilePath(); + if ( aFileName != anOldFileName ) { - theErrorMsg = tr( "BAD_IMPORTED_BATHYMETRY_FILE" ).arg( aFileName ); - return false; + aBathymetryObj->SetAltitudesInverted( anIsInvertAltitudes, false ); + if ( !aBathymetryObj->ImportFromFile( aFileName ) ) + { + theErrorMsg = tr( "BAD_IMPORTED_BATHYMETRY_FILE" ).arg( aFileName ); + return false; + } + } + else if ( anIsInvertAltitudes != aBathymetryObj->IsAltitudesInverted() ) + { + aBathymetryObj->SetAltitudesInverted( anIsInvertAltitudes ); } aBathymetryObj->SetName( anObjectName ); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 4e9afd67..b53101fe 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -355,6 +355,10 @@ First remove objects which are created on their basis. NAME Name + + INVERT_BATHYMETRY_ALTITUDES + Invert altitude values +