X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Polyline3D.cxx;h=0ae2a44f78e3e65e919c0955940336a2db242c4d;hb=5875b067c1dffa0bd68b31c018b0ee4091775344;hp=c55cbe07fdce1370503544d9c5eb211e8e858b61;hpb=46e9c3121cf0a1ffe99a62cbf9640eb2e1f716ba;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Polyline3D.cxx b/src/HYDROData/HYDROData_Polyline3D.cxx index c55cbe07..0ae2a44f 100644 --- a/src/HYDROData/HYDROData_Polyline3D.cxx +++ b/src/HYDROData/HYDROData_Polyline3D.cxx @@ -1,3 +1,20 @@ +// 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" @@ -6,15 +23,33 @@ #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 @@ -44,7 +79,7 @@ QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedO { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aRefProfileUZ->GetFatherObject() ); - if ( !aProfile.IsNull() ) + if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) ) { QString aProfileName = aProfile->GetObjPyName(); if ( !aProfileName.isEmpty() ) @@ -64,7 +99,7 @@ QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedO { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() ); - if ( !aProfile.IsNull() ) + if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) ) { QString aProfileName = aProfile->GetObjPyName(); if ( !aProfileName.isEmpty() ) @@ -175,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() @@ -404,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; +}