X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Polyline3D.cxx;h=0ae2a44f78e3e65e919c0955940336a2db242c4d;hb=5875b067c1dffa0bd68b31c018b0ee4091775344;hp=2bdd60a5d09f751a3bc74d85c00fe6853abe6e55;hpb=5c45a299fb45a108740d6175f7e83c5f63f4c004;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Polyline3D.cxx b/src/HYDROData/HYDROData_Polyline3D.cxx index 2bdd60a5..0ae2a44f 100644 --- a/src/HYDROData/HYDROData_Polyline3D.cxx +++ b/src/HYDROData/HYDROData_Polyline3D.cxx @@ -1,25 +1,58 @@ +// Copyright (C) 2014-2015 EDF-R&D +// 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, or (at your option) any later version. +// +// 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 "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_ShapesTool.h" #include "HYDROData_Tool.h" +#include + +#include +#include + +#include + #include #include #include +#include + #include +#include +#include #include +#include + +#include + +#include + #include #include -#define PYTHON_POLYLINE_ID "KIND_POLYLINE" - IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline3D,HYDROData_Object) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline3D,HYDROData_Object) @@ -35,21 +68,55 @@ 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 ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) ) + { + QString aProfileName = aProfile->GetObjPyName(); + if ( !aProfileName.isEmpty() ) + { + aResList << QString( "%1.SetProfileUZ( %2.GetProfileUZ() );" ) + .arg( aPolylineName ).arg( aProfileName ); + } + } + } + else + { + Handle(HYDROData_IAltitudeObject) aRefBathymetry = GetAltitudeObject(); + if ( !aRefBathymetry.IsNull() ) + { + Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ(); + if ( !aChildProfileUZ.IsNull() ) + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() ); + if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) ) + { + QString aProfileName = aProfile->GetObjPyName(); + if ( !aProfileName.isEmpty() ) + { + aResList << QString( "%1.SetChildProfileUZ( %2.GetProfileUZ() );" ) + .arg( aPolylineName ).arg( aProfileName ); + } + } + } + + 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; } @@ -99,8 +166,8 @@ void HYDROData_Polyline3D::Update() Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ(); - Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry(); - if ( !aBathymetry.IsNull() ) + Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject(); + if ( !anAltitude.IsNull() ) aProfileUZ = GetChildProfileUZ(); if ( aProfileUZ.IsNull() ) @@ -143,6 +210,12 @@ void HYDROData_Polyline3D::Update() TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints ); SetTopShape( aResWire ); SetShape3D( aResWire ); + + double Xmin=0, Xmax=0, Ymin=0, Ymax=0, Zmin=-9999, Zmax=-9999; + Bnd_Box B; + BRepBndLib::Add(aResWire, B); + B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); + SetMiddleZ((Zmin+Zmax)/2.); } QColor HYDROData_Polyline3D::DefaultFillingColor() @@ -217,7 +290,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 ); @@ -243,14 +316,15 @@ void HYDROData_Polyline3D::RemoveProfileUZ() SetToUpdate( true ); } -bool HYDROData_Polyline3D::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ) +bool HYDROData_Polyline3D::SetAltitudeObject( + const Handle(HYDROData_IAltitudeObject)& theAltitude ) { - Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry(); + Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject(); - if ( !HYDROData_Object::SetBathymetry( theBathymetry ) ) + if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) ) return false; - if ( IsEqual( aPrevBathymetry, theBathymetry ) ) + if ( IsEqual( aPrevAltitude, theAltitude ) ) return true; // Remove the u,z profile, because one altitude object can be presented at time @@ -263,9 +337,9 @@ bool HYDROData_Polyline3D::SetBathymetry( const Handle(HYDROData_Bathymetry)& th } -void HYDROData_Polyline3D::RemoveBathymetry() +void HYDROData_Polyline3D::RemoveAltitudeObject() { - HYDROData_Object::RemoveBathymetry(); + HYDROData_Object::RemoveAltitudeObject(); // Remove the child profile object removeChildProfileUZ(); @@ -292,18 +366,23 @@ Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool aProfileUZ = aProfile->GetProfileUZ(); - Handle(HYDROData_Polyline3D) me = this; - me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ ); + HYDROData_Polyline3D* me = const_cast( this ); // Temporary to be revised + me->SetChildProfileUZ( aProfileUZ ); return aProfileUZ; } +void HYDROData_Polyline3D::SetChildProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile ) +{ + SetReferenceObject( theProfile, DataTag_ChildProfileUZ ); +} + HYDROData_IPolyline::PointsList generateProfileUZPoints( - const Handle(HYDROData_PolylineXY)& thePolyline, - const Handle(HYDROData_Bathymetry)& theBathymetry ) + const Handle(HYDROData_PolylineXY)& thePolyline, + const Handle(HYDROData_IAltitudeObject)& theAltitude ) { HYDROData_IPolyline::PointsList aPointsList; - if ( thePolyline.IsNull() || theBathymetry.IsNull() ) + if ( thePolyline.IsNull() || theAltitude.IsNull() ) return aPointsList; bool anIsSectionClosed = thePolyline->IsClosedSection( 0 ); @@ -317,8 +396,8 @@ HYDROData_IPolyline::PointsList generateProfileUZPoints( const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i ); double aPointDistance = thePolyline->GetDistance( 0, i - 1 ); - double aPointDepth = theBathymetry->GetAltitudeForPoint( aSectPoint ); - if( aPointDepth==theBathymetry->GetInvalidAltitude() ) + double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint ); + if( aPointDepth == theAltitude->GetInvalidAltitude() ) aPointDepth = 0.0; HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth ); @@ -330,8 +409,8 @@ HYDROData_IPolyline::PointsList generateProfileUZPoints( void HYDROData_Polyline3D::updateChildProfilePoints() { - Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry(); - if ( aBathymetry.IsNull() ) + Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject(); + if ( anAltitude.IsNull() ) return; Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ(); @@ -344,7 +423,7 @@ void HYDROData_Polyline3D::updateChildProfilePoints() return; HYDROData_IPolyline::PointsList aProfilePoints = - generateProfileUZPoints( GetPolylineXY(), GetBathymetry() ); + generateProfileUZPoints( GetPolylineXY(), anAltitude ); aProfile->SetParametricPoints( aProfilePoints ); aProfile->Update(); @@ -366,4 +445,76 @@ void HYDROData_Polyline3D::removeChildProfileUZ() */ } +HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetPoints() const +{ + Polyline3DPoints aPoints; + + Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY(); + TopoDS_Wire aWire = TopoDS::Wire( GetShape3D() ); + if ( aPolylineXY.IsNull() || aWire.IsNull() ) { + return aPoints; + } + + // Explode polyline on edges + TopTools_SequenceOfShape anEdges; + HYDROData_ShapesTool::ExploreShapeToShapes( aWire, TopAbs_EDGE, anEdges ); + + // Get points + if ( !anEdges.IsEmpty() ) { + HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 ); + + if ( aSectionType == HYDROData_IPolyline::SECTION_POLYLINE ) { + // Get points from wire + /* Seems that intermediate vertices are duplicated + TopExp_Explorer anExp( aWire, TopAbs_VERTEX ); + for ( ; anExp.More(); anExp.Next() ) { + TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() ); + if ( !aVertex.IsNull() ) { + gp_Pnt aPnt = BRep_Tool::Pnt( aVertex ); + aPoints.Append( aPnt.XYZ() ); + } + } + */ + TopExp_Explorer anExp( aWire, TopAbs_EDGE ); + bool isFirst = true; + for ( ; anExp.More(); anExp.Next() ) { + TopoDS_Edge anEdge = TopoDS::Edge( anExp.Current() ); + if ( !anEdge.IsNull() ) { + TopoDS_Vertex aV1, aV2; + TopExp::Vertices( anEdge, aV1, aV2 ); + if ( isFirst ) { + gp_Pnt aPnt1 = BRep_Tool::Pnt( aV1 ); + aPoints.Append( aPnt1.XYZ() ); + } + + gp_Pnt aPnt2 = BRep_Tool::Pnt( aV2 ); + aPoints.Append( aPnt2.XYZ() ); + + isFirst = false; + } + } + } else { + // Get points from spline curve + Standard_Real aStart, anEnd; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve( TopoDS::Edge( anEdges.First() ), aStart, anEnd ); + Handle(Geom_BSplineCurve) aGeomSpline = Handle(Geom_BSplineCurve)::DownCast( aCurve ); + + if ( !aGeomSpline.IsNull() ) { + int aNbKnots = aGeomSpline->NbKnots(); + + TColStd_Array1OfReal aSplineKnots( 1, aNbKnots ); + aGeomSpline->Knots( aSplineKnots ); + + for ( int i = 1; i <= aNbKnots; ++i ) { + const Standard_Real& aKnot = aSplineKnots.Value( i ); + gp_Pnt aPnt; + aGeomSpline->D0( aKnot, aPnt ); + aPoints.Append( aPnt.XYZ() ); + } + } + } + } + + return aPoints; +}