From e6d09f89dd71eb9a0af117680f51d99e028e8f9b Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 8 Dec 2015 10:48:57 +0300 Subject: [PATCH] refs #751: equidistance parameter is available in C++, OCAF, Python, GUI --- src/HYDROData/HYDROData_Channel.cxx | 22 ++++++++++++++++++---- src/HYDROData/HYDROData_Channel.h | 6 +++++- src/HYDROData/HYDROData_Entity.cxx | 20 ++++++++++++++++++++ src/HYDROData/HYDROData_Entity.h | 3 +++ src/HYDROData/HYDROData_LandCoverMap.cxx | 15 ++------------- src/HYDROGUI/HYDROGUI_ChannelDlg.cxx | 18 ++++++++++++++++++ src/HYDROGUI/HYDROGUI_ChannelDlg.h | 6 ++++++ src/HYDROGUI/HYDROGUI_ChannelOp.cxx | 8 +++++++- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 4 ++++ src/HYDROPy/HYDROData_Channel.sip | 4 +++- 10 files changed, 86 insertions(+), 20 deletions(-) diff --git a/src/HYDROData/HYDROData_Channel.cxx b/src/HYDROData/HYDROData_Channel.cxx index 3d18e28d..03013b3e 100644 --- a/src/HYDROData/HYDROData_Channel.cxx +++ b/src/HYDROData/HYDROData_Channel.cxx @@ -92,6 +92,8 @@ QStringList HYDROData_Channel::DumpToPython( const QString& thePyScriptPath, Handle(HYDROData_Profile) aRefProfile = GetProfile(); setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefProfile, "SetProfile" ); + aResList << QString( "%1.SetEquiDistance( %2 );" ).arg( aName ).arg( GetEquiDistance() ); + aResList << QString( "" ); aResList << QString( "%1.Update();" ).arg( aName ); aResList << QString( "" ); @@ -116,7 +118,8 @@ HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const bool HYDROData_Channel::CreatePresentations( const Handle(HYDROData_Polyline3D)& theGuideLine, const Handle(HYDROData_Profile)& theProfile, - PrsDefinition& thePrs ) + PrsDefinition& thePrs, + double theEquiDistance ) { // Check input parameters if ( theGuideLine.IsNull() || theProfile.IsNull() ) { @@ -146,8 +149,7 @@ bool HYDROData_Channel::CreatePresentations( const Handle(HYDROData_Polyline3D)& int aNbPoints = aPolylinePoints.Length(); */ - double aEqDistance = 1; // TODO: to pass via properties and OCAF - HYDROData_Polyline3D::Polyline3DPoints aPolylinePoints3D = theGuideLine->GetPoints( aEqDistance ); + HYDROData_Polyline3D::Polyline3DPoints aPolylinePoints3D = theGuideLine->GetPoints( theEquiDistance ); int aNbPoints = aPolylinePoints3D.Length(); if ( aNbPoints < 2 ) return false; @@ -295,7 +297,8 @@ void HYDROData_Channel::Update() Handle(HYDROData_Profile) aProfile = GetProfile(); PrsDefinition aResultPrs; - if ( !CreatePresentations( aGuideLine, aProfile, aResultPrs ) ) + double anEquiDistance = GetEquiDistance(); + if ( !CreatePresentations( aGuideLine, aProfile, aResultPrs, anEquiDistance ) ) return; SetShape3D( aResultPrs.myPrs3D ); @@ -452,3 +455,14 @@ TopoDS_Shape HYDROData_Channel::GetRightShape() const HYDROData_SequenceOfObjects aGroups = GetGroups(); return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2); } + +void HYDROData_Channel::SetEquiDistance( double theEquiDistance ) +{ + double anEquiDistance = theEquiDistance > 0 ? theEquiDistance : 1E-3; + SetDouble( DataTag_EquiDistance, theEquiDistance ); +} + +double HYDROData_Channel::GetEquiDistance() const +{ + return GetDouble( DataTag_EquiDistance, 1.0 ); +} diff --git a/src/HYDROData/HYDROData_Channel.h b/src/HYDROData/HYDROData_Channel.h index 372e57a7..3e069097 100644 --- a/src/HYDROData/HYDROData_Channel.h +++ b/src/HYDROData/HYDROData_Channel.h @@ -58,6 +58,7 @@ protected: DataTag_First = HYDROData_ArtificialObject::DataTag_First + 100, ///< first tag, to reserve DataTag_GuideLine, DataTag_Profile, + DataTag_EquiDistance, }; public: @@ -71,7 +72,8 @@ public: */ HYDRODATA_EXPORT static bool CreatePresentations( const Handle(HYDROData_Polyline3D)& theGuideLine, const Handle(HYDROData_Profile)& theProfile, - PrsDefinition& thePrs ); + PrsDefinition& thePrs, + double theEquiDistance ); public: @@ -157,6 +159,8 @@ public: */ HYDRODATA_EXPORT virtual void RemoveProfile(); + HYDRODATA_EXPORT void SetEquiDistance( double ); + HYDRODATA_EXPORT double GetEquiDistance() const; protected: /** diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index d10c3b09..8681cf1e 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -746,3 +747,22 @@ TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const } return TopoDS_Shape(); } + +void HYDROData_Entity::SetDouble( int theTag, double theValue ) +{ + Handle(TDataStd_Real) anAttr; + TDF_Label aLabel = myLab.FindChild( theTag ); + if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) ) + aLabel.AddAttribute( anAttr = new TDataStd_Real() ); + anAttr->Set( theValue ); +} + +double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const +{ + Handle(TDataStd_Real) anAttr; + TDF_Label aLabel = myLab.FindChild( theTag ); + if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) ) + return theDefValue; + + return anAttr->Get(); +} diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index 44c34dfd..1e41b044 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -434,6 +434,9 @@ protected: void SetShape( int theTag, const TopoDS_Shape& theShape ); TopoDS_Shape GetShape( int theTag ) const; + void SetDouble( int theTag, double theValue ); + double GetDouble( int theTag, double theDefValue = 0.0 ) const; + int GetGeomChangeFlag() const; protected: diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 3cc968d5..e5dacdf5 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -1083,22 +1082,12 @@ TopoDS_Shape HYDROData_LandCoverMap::RemoveInternal(const TopoDS_Shape& InSh) void HYDROData_LandCoverMap::SetTransparency( double theTransparency ) { - Handle(TDataStd_Real) anAttr; - TDF_Label aLabel = myLab.FindChild( DataTag_Transparency ); - if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) ) - aLabel.AddAttribute( anAttr = new TDataStd_Real() ); - anAttr->Set( theTransparency ); + SetDouble( DataTag_Transparency, theTransparency ); } double HYDROData_LandCoverMap::GetTransparency() const { - Handle(TDataStd_Real) anAttr; - TDF_Label aLabel = myLab.FindChild( DataTag_Transparency ); - if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) ) - return 0.5; - - return anAttr->Get(); - + return GetDouble( DataTag_Transparency, 0.5 ); } bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName, diff --git a/src/HYDROGUI/HYDROGUI_ChannelDlg.cxx b/src/HYDROGUI/HYDROGUI_ChannelDlg.cxx index cc08804e..0b55e800 100644 --- a/src/HYDROGUI/HYDROGUI_ChannelDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ChannelDlg.cxx @@ -25,6 +25,7 @@ #include #include #include +#include HYDROGUI_ChannelDlg::HYDROGUI_ChannelDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_InputPanel( theModule, theTitle ) @@ -51,6 +52,11 @@ HYDROGUI_ChannelDlg::HYDROGUI_ChannelDlg( HYDROGUI_Module* theModule, const QStr myProfiles = new QComboBox( aParamGroup ); myProfiles->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myEquiDistance = new QtxDoubleSpinBox( aParamGroup ); + myEquiDistance->setRange( 0.01, 100 ); + myEquiDistance->setValue( 1.0 ); + myEquiDistance->setSingleStep( 1.0 ); + QGridLayout* aParamsLayout = new QGridLayout( aParamGroup ); aParamsLayout->setMargin( 5 ); aParamsLayout->setSpacing( 5 ); @@ -58,6 +64,8 @@ HYDROGUI_ChannelDlg::HYDROGUI_ChannelDlg( HYDROGUI_Module* theModule, const QStr aParamsLayout->addWidget( myGuideLines, 0, 1 ); aParamsLayout->addWidget( new QLabel( tr( "CHANNEL_PROFILE" ), aParamGroup ), 1, 0 ); aParamsLayout->addWidget( myProfiles, 1, 1 ); + aParamsLayout->addWidget( new QLabel( tr( "EQUI_DISTANCE" ), aParamGroup ), 2, 0 ); + aParamsLayout->addWidget( myEquiDistance, 2, 1 ); // Common addWidget( myObjectNameGroup ); @@ -161,3 +169,13 @@ void HYDROGUI_ChannelDlg::onChannelDefChanged() emit CreatePreview(); } + +double HYDROGUI_ChannelDlg::getEquiDistance() const +{ + return myEquiDistance->value(); +} + +void HYDROGUI_ChannelDlg::setEquiDistance( double theValue ) +{ + myEquiDistance->setValue( theValue ); +} diff --git a/src/HYDROGUI/HYDROGUI_ChannelDlg.h b/src/HYDROGUI/HYDROGUI_ChannelDlg.h index 9822928a..e01a9f5e 100644 --- a/src/HYDROGUI/HYDROGUI_ChannelDlg.h +++ b/src/HYDROGUI/HYDROGUI_ChannelDlg.h @@ -25,6 +25,7 @@ class QComboBox; class QGroupBox; class QLineEdit; +class QtxDoubleSpinBox; class HYDROGUI_ChannelDlg : public HYDROGUI_InputPanel { @@ -47,6 +48,9 @@ public: void setProfileName( const QString& theProfile ); QString getProfileName() const; + double getEquiDistance() const; + void setEquiDistance( double ); + signals: void CreatePreview(); @@ -60,6 +64,8 @@ protected: QComboBox* myGuideLines; QComboBox* myProfiles; + + QtxDoubleSpinBox* myEquiDistance; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx index 99bf0cb7..8c3e73e4 100644 --- a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx @@ -118,6 +118,11 @@ void HYDROGUI_ChannelOp::startOperation() aPanel->setGuideLineName( aSelectedGuideLine ); aPanel->setProfileName( aSelectedProfile ); + if( !myEditedObject.IsNull() ) + aPanel->setEquiDistance( myEditedObject->GetEquiDistance() ); + else + aPanel->setEquiDistance( 1.0 ); + aPanel->blockSignals( false ); onCreatePreview(); @@ -210,6 +215,7 @@ bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags, myEditedObject->RemoveProfile(); myEditedObject->SetProfile( aProfile ); + myEditedObject->SetEquiDistance( aPanel->getEquiDistance() ); } if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) ) @@ -292,7 +298,7 @@ void HYDROGUI_ChannelOp::onCreatePreview() HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); HYDROData_Channel::PrsDefinition aPrsDef; - if ( !HYDROData_Channel::CreatePresentations( aGuideLine, aProfile, aPrsDef ) ) + if ( !HYDROData_Channel::CreatePresentations( aGuideLine, aProfile, aPrsDef, aPanel->getEquiDistance() ) ) { erasePreview(); return; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 76fc9857..c7ca128b 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2758,6 +2758,10 @@ Polyline should consist from one not closed curve. CHANNEL_PROFILE Profile + + EQUI_DISTANCE + Equidistance + diff --git a/src/HYDROPy/HYDROData_Channel.sip b/src/HYDROPy/HYDROData_Channel.sip index 9c52de3d..1ff170ac 100644 --- a/src/HYDROPy/HYDROData_Channel.sip +++ b/src/HYDROPy/HYDROData_Channel.sip @@ -136,7 +136,9 @@ public: */ void RemoveProfile(); - + void SetEquiDistance( double ); + double GetEquiDistance() const; + protected: /** -- 2.39.2