X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Polyline3D.cxx;h=c8549930cf3ea682cb7b7e9ca7d898210d78911a;hb=3b6027a83768bb776f6577b84c31c860fdb83505;hp=5cf9287fbf69bb7950fd0e566138823b62527d12;hpb=ff852fa6906c698aea0e95554f1c33e2560b61ef;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Polyline3D.cxx b/src/HYDROData/HYDROData_Polyline3D.cxx index 5cf9287f..c8549930 100644 --- a/src/HYDROData/HYDROData_Polyline3D.cxx +++ b/src/HYDROData/HYDROData_Polyline3D.cxx @@ -1,10 +1,12 @@ #include "HYDROData_Polyline3D.h" -#include "HYDROData_Bathymetry.h" +#include "HYDROData_IAltitudeObject.h" #include "HYDROData_Document.h" #include "HYDROData_PolylineXY.h" +#include "HYDROData_Profile.h" #include "HYDROData_ProfileUZ.h" +#include "HYDROData_Tool.h" #include #include @@ -16,8 +18,6 @@ #include #include -#define PYTHON_POLYLINE_ID "KIND_POLYLINE" - IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline3D,HYDROData_Object) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline3D,HYDROData_Object) @@ -33,21 +33,36 @@ HYDROData_Polyline3D::~HYDROData_Polyline3D() QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const { - QStringList aResList; + QStringList aResList = dumpObjectCreation( theTreatedObjects ); + QString aPolylineName = GetObjPyName(); - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( aDocument.IsNull() ) - return aResList; + Handle(HYDROData_PolylineXY) aRefPolyline = GetPolylineXY(); + setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolylineXY" ); - QString aDocName = aDocument->GetDocPyName(); - QString aPolylineName = GetName(); + Handle(HYDROData_ProfileUZ) aRefProfileUZ = GetProfileUZ(); + if ( !aRefProfileUZ.IsNull() ) + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aRefProfileUZ->GetFatherObject() ); + if ( !aProfile.IsNull() ) + { + QString aProfileName = aProfile->GetObjPyName(); + if ( !aProfileName.isEmpty() ) + { + aResList << QString( "%1.SetProfileUZ( %2.GetProfileUZ() );" ) + .arg( aPolylineName ).arg( aProfileName ); + } + } + } + else + { + Handle(HYDROData_IAltitudeObject) aRefBathymetry = GetAltitudeObject(); + setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" ); + } - aResList << QString( "%1 = %2.CreateObject( %3 );" ) - .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINE_ID ); - aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName ); aResList << QString( "" ); - - // TODO + aResList << QString( "%1.Update();" ).arg( aPolylineName ); + aResList << QString( "" ); return aResList; } @@ -64,6 +79,10 @@ HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const if ( !aProfileUZ.IsNull() ) aResSeq.Append( aProfileUZ ); + Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false ); + if ( !aChildProfileUZ.IsNull() ) + aResSeq.Append( aChildProfileUZ ); + return aResSeq; } @@ -77,34 +96,6 @@ TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const return getShape3D(); } -HYDROData_IPolyline::PointsList generateProfileUZPoints( - const Handle(HYDROData_PolylineXY)& thePolyline, - const Handle(HYDROData_Bathymetry)& theBathymetry ) -{ - HYDROData_IPolyline::PointsList aPointsList; - if ( thePolyline.IsNull() || theBathymetry.IsNull() ) - return aPointsList; - - bool anIsSectionClosed = thePolyline->IsClosedSection( 0 ); - HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 ); - HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 ); - if ( aPolylinePoints.IsEmpty() ) - return aPointsList; - - for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i ) - { - const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i ); - - double aPointDistance = thePolyline->GetDistance( 0, i - 1 ); - double aPointDepth = theBathymetry->GetAltitudeForPoint( aSectPoint ); - - HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth ); - aPointsList.Append( anAltitudePoint ); - } - - return aPointsList; -} - void HYDROData_Polyline3D::Update() { HYDROData_Object::Update(); @@ -119,20 +110,16 @@ void HYDROData_Polyline3D::Update() if ( aPolylinePoints.IsEmpty() ) return; - HYDROData_IPolyline::PointsList aProfilePoints; - Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ(); - Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry(); - if ( !aProfileUZ.IsNull() ) - { - aProfilePoints = aProfileUZ->GetPoints(); - } - else if ( !aBathymetry.IsNull() ) - { - aProfilePoints = generateProfileUZPoints( aPolylineXY, aBathymetry ); - } + Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject(); + if ( !anAltitude.IsNull() ) + aProfileUZ = GetChildProfileUZ(); + if ( aProfileUZ.IsNull() ) + return; + + HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints(); if ( aProfilePoints.IsEmpty() ) return; @@ -191,7 +178,8 @@ QColor HYDROData_Polyline3D::getDefaultBorderColor() const return DefaultBorderColor(); } -bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline ) +bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline, + const bool theIsUpdateProfile ) { if ( thePolyline.IsNull() ) return false; @@ -202,6 +190,10 @@ bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& th SetReferenceObject( thePolyline, DataTag_PolylineXY ); + // Update the child profile object + if ( theIsUpdateProfile ) + updateChildProfilePoints(); + // Indicate model of the need to update the polyline presentation SetToUpdate( true ); @@ -238,7 +230,7 @@ bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theP SetReferenceObject( theProfile, DataTag_ProfileUZ ); // Remove the bathymetry, because one altitude object can be presented at time - RemoveBathymetry(); + RemoveAltitudeObject(); // Indicate model of the need to update the polyline presentation SetToUpdate( true ); @@ -264,15 +256,128 @@ void HYDROData_Polyline3D::RemoveProfileUZ() SetToUpdate( true ); } - -bool HYDROData_Polyline3D::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ) +bool HYDROData_Polyline3D::SetAltitudeObject( + const Handle(HYDROData_IAltitudeObject)& theAltitude ) { - if ( !HYDROData_Object::SetBathymetry( theBathymetry ) ) + Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject(); + + if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) ) return false; + if ( IsEqual( aPrevAltitude, theAltitude ) ) + return true; + // Remove the u,z profile, because one altitude object can be presented at time RemoveProfileUZ(); + // Create the child profile object + updateChildProfilePoints(); + return true; } + +void HYDROData_Polyline3D::RemoveAltitudeObject() +{ + HYDROData_Object::RemoveAltitudeObject(); + + // Remove the child profile object + removeChildProfileUZ(); +} + +Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const +{ + Handle(HYDROData_ProfileUZ) aProfileUZ = + Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) ); + if ( !theIsCreate || !aProfileUZ.IsNull() ) + return aProfileUZ; + + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if ( aDocument.IsNull() ) + return aProfileUZ; + + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) ); + + QString aProfilePref = GetName() + "_Profile"; + QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref ); + + aProfile->SetName( aProfileName ); + + aProfileUZ = aProfile->GetProfileUZ(); + + HYDROData_Polyline3D* me = const_cast( this ); // Temporary to be revised + me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ ); + + return aProfileUZ; +} + +HYDROData_IPolyline::PointsList generateProfileUZPoints( + const Handle(HYDROData_PolylineXY)& thePolyline, + const Handle(HYDROData_IAltitudeObject)& theAltitude ) +{ + HYDROData_IPolyline::PointsList aPointsList; + if ( thePolyline.IsNull() || theAltitude.IsNull() ) + return aPointsList; + + bool anIsSectionClosed = thePolyline->IsClosedSection( 0 ); + HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 ); + HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 ); + if ( aPolylinePoints.IsEmpty() ) + return aPointsList; + + for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i ) + { + const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i ); + + double aPointDistance = thePolyline->GetDistance( 0, i - 1 ); + double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint ); + if( aPointDepth == theAltitude->GetInvalidAltitude() ) + aPointDepth = 0.0; + + HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth ); + aPointsList.Append( anAltitudePoint ); + } + + return aPointsList; +} + +void HYDROData_Polyline3D::updateChildProfilePoints() +{ + Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject(); + if ( anAltitude.IsNull() ) + return; + + Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ(); + if ( aChildProfileUZ.IsNull() ) + return; + + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() ); + if ( aProfile.IsNull() ) + return; + + HYDROData_IPolyline::PointsList aProfilePoints = + generateProfileUZPoints( GetPolylineXY(), anAltitude ); + aProfile->SetParametricPoints( aProfilePoints ); + + aProfile->Update(); +} + +void HYDROData_Polyline3D::removeChildProfileUZ() +{ + Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false ); + if ( aChildProfileUZ.IsNull() ) + return; + + ClearReferenceObjects( DataTag_ChildProfileUZ ); + + /* Uncomment if removing is requested + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() ); + if ( !aProfile.IsNull() ) + aProfile->Remove(); + */ +} + +