#include <TDataStd_RealArray.hxx>
#include <TDataStd_AsciiString.hxx>
+#include <TDataStd_Integer.hxx>
#include <QFile>
#include <QFileInfo>
aResList << QString( "%1.SetName( \"%2\" );" )
.arg( aBathymetryName ).arg( aBathymetryName );
+ aResList << QString( "%1.SetAltitudesInverted( %2 );" )
+ .arg( aBathymetryName ).arg( IsAltitudesInverted() );
+
QString aFilePath = GetFilePath();
if ( !aFilePath.isEmpty() )
{
{
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;
}
}
bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile,
- AltitudePoints& thePoints )
+ AltitudePoints& thePoints ) const
{
if ( !theFile.isOpen() )
return false;
aTimer.Start();
#endif
+ bool anIsAltitudesInverted = IsAltitudesInverted();
while ( !theFile.atEnd() )
{
QString aLine = theFile.readLine().simplified();
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;
}
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:
*/
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
* Imports Bathymetry data from 'XYZ' file.
*/
bool importFromXYZFile( QFile& theFile,
- AltitudePoints& thePoints );
+ AltitudePoints& thePoints ) const;
protected:
#include <QLineEdit>
#include <QPicture>
#include <QToolButton>
+#include <QCheckBox>
HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_InputPanel( theModule, theTitle )
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() ) );
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" ) );
class QGroupBox;
class QLineEdit;
+class QCheckBox;
class HYDROGUI_ImportBathymetryDlg : public HYDROGUI_InputPanel
{
void setFileName( const QString& theFileName );
QString getFileName() const;
+ void setInvertAltitudes( const bool theIsInvert );
+ bool isInvertAltitudes() const;
+
signals:
void FileSelected( const QString& theFileName );
QGroupBox* myFileNameGroup;
QLineEdit* myFileName;
+ QCheckBox* myInvertAltitudes;
+
QGroupBox* myObjectNameGroup;
QLineEdit* myObjectName;
};
{
QString aName = myEditedObject->GetName();
QString aFileName = myEditedObject->GetFilePath();
+ bool anIsAltitudesInverted = myEditedObject->IsAltitudesInverted();
+
aPanel->setObjectName( aName );
aPanel->setFileName( aFileName );
+ aPanel->setInvertAltitudes( anIsAltitudesInverted );
}
}
}
}
QString aFileName = aPanel->getFileName().simplified();
+ bool anIsInvertAltitudes = aPanel->isInvertAltitudes();
+
if ( aFileName.isEmpty() )
{
theErrorMsg = tr( "INCORRECT_FILE_NAME" );
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 );
<source>NAME</source>
<translation>Name</translation>
</message>
+ <message>
+ <source>INVERT_BATHYMETRY_ALTITUDES</source>
+ <translation>Invert altitude values</translation>
+ </message>
</context>
<context>