1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_Profile.h"
21 #include "HYDROData_Document.h"
22 #include "HYDROData_Iterator.h"
23 #include "HYDROData_Tool.h"
24 #include "HYDROData_PolylineXY.h"
26 #include <boost/math/special_functions/fpclassify.hpp>
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRepBuilderAPI_MakeWire.hxx>
30 #include <BRepBuilderAPI_MakePolygon.hxx>
32 #include <BRepExtrema_ExtCC.hxx>
34 #include <BRep_Tool.hxx>
39 #include <gp_Pnt2d.hxx>
41 #include <TDataStd_AsciiString.hxx>
42 #include <TDataStd_RealArray.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Wire.hxx>
47 #include <TopoDS_Iterator.hxx>
49 #include <OSD_File.hxx>
50 #include <OSD_Protection.hxx>
53 #include <QStringList>
55 IMPLEMENT_STANDARD_HANDLE(HYDROData_Profile, HYDROData_Object)
56 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object)
58 HYDROData_Profile::HYDROData_Profile()
63 HYDROData_Profile::~HYDROData_Profile()
67 QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
69 QStringList aResList = dumpObjectCreation( theTreatedObjects );
70 QString aProfileName = GetObjPyName();
72 //TCollection_AsciiString aFilePath = GetFilePath();
73 //if ( !aFilePath.IsEmpty() )
75 // aResList << QString( "%1.ImportFromFile( \"%2\" );" )
76 // .arg( aName ).arg( aFilePath.ToCString() );
79 bool anIsValidProfile = IsValid();
81 QStringList aPntsDefinition;
82 QString aPntsListName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "profile_points" );
84 QString aGap = QString().fill( ' ', aPntsListName.length() + 5 );
85 if ( anIsValidProfile )
87 HYDROData_Profile::ProfilePoints aPointsList = GetProfilePoints( true );
88 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
90 const ProfilePoint& aPoint = aPointsList.Value( k );
91 aPntsDefinition << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" )
92 .arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
93 .arg( ( k < aNbPoints ? "," : "" ) );
98 HYDROData_IPolyline::PointsList aPointsList = GetParametricPoints();
99 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
101 const HYDROData_IPolyline::Point& aPoint = aPointsList.Value( k );
102 aPntsDefinition << QString( aGap + "gp_XY( %1, %2 )%3" )
103 .arg( aPoint.X() ).arg( aPoint.Y() )
104 .arg( ( k < aNbPoints ? "," : "" ) );
108 if ( !aPntsDefinition.isEmpty() )
110 QString& aFirstStr = aPntsDefinition.first();
111 aFirstStr = aFirstStr.trimmed();
112 aFirstStr.prepend( QString( "%1 = [ " ).arg( aPntsListName ) );
114 aPntsDefinition.last().append( " ];" );
116 aResList << aPntsDefinition;
118 aResList << QString( "%1.%3( %2 );" )
119 .arg( aProfileName ).arg( aPntsListName )
120 .arg( anIsValidProfile ? "SetProfilePoints" : "SetParametricPoints" );
122 aResList << QString( "" );
125 // Set a polyline type if it is not default
126 Handle(HYDROData_ProfileUZ) aPrf = GetProfileUZ( false );
127 if ( !aPrf.IsNull() )
129 HYDROData_IPolyline::SectionType aSecType = aPrf->GetSectionType( 0 );
130 if ( aSecType != HYDROData_IPolyline::SECTION_POLYLINE )
132 aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 );" )
133 .arg( aProfileName ).arg( "HYDROData_IPolyline.SECTION_SPLINE" );
134 aResList << QString( "" );
138 aResList << QString( "%1.Update();" ).arg( aProfileName );
139 aResList << QString( "" );
144 TopoDS_Shape HYDROData_Profile::GetTopShape() const
148 gp_XY aFirstPoint, aLastPoint;
149 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
152 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 );
153 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 );
155 BRepBuilderAPI_MakeEdge aMakeEdge( aPnt1, aPnt2 );
156 TopoDS_Edge anEdge = aMakeEdge;
158 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
164 TopoDS_Shape HYDROData_Profile::GetShape3D() const
166 TopoDS_Shape aShape = getShape3D();
167 if( aShape.IsNull() )
168 aShape = CreateProfileWire( true );
172 TopoDS_Shape HYDROData_Profile::CreateProfileWire( bool canUseDefaultPoints ) const
175 Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
176 if ( !aProfile.IsNull() )
178 ProfilePoints aProfilePoints = GetProfilePoints( false, canUseDefaultPoints );
179 HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
181 aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
186 void HYDROData_Profile::Update()
188 HYDROData_Object::Update();
190 TopoDS_Shape aShape = CreateProfileWire( false );
191 SetShape3D( aShape );
194 QColor HYDROData_Profile::DefaultFillingColor()
196 return QColor( Qt::transparent );
199 QColor HYDROData_Profile::DefaultBorderColor()
201 return QColor( Qt::black );
204 QColor HYDROData_Profile::getDefaultFillingColor() const
206 return DefaultFillingColor();
209 QColor HYDROData_Profile::getDefaultBorderColor() const
211 return DefaultBorderColor();
214 bool HYDROData_Profile::IsValid() const
216 gp_XY aFirstPoint, aLastPoint;
217 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
220 int aNbPoints = NbPoints();
221 return aNbPoints > 1;
224 void HYDROData_Profile::SetLeftPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
226 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint );
227 if ( aLabel.IsNull() )
230 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
231 gp_XY aLPoint = theGPoint;
232 if( IsConvertFromGlobal )
233 aDoc->Transform( aLPoint, true );
235 Handle(TDataStd_RealArray) anArray;
236 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
237 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
239 anArray->SetValue( 0, aLPoint.X() );
240 anArray->SetValue( 1, aLPoint.Y() );
245 bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal,
246 bool CanUseDefault ) const
248 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
249 if ( aParametricPoints.Length() < 2 )
252 thePoint = GetParametricPoints().First();
255 thePoint.SetY( 0 ); //default left point of not-georeferenced profile
256 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint, false );
257 if ( aLabel.IsNull() )
259 return CanUseDefault;
262 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
263 Handle(TDataStd_RealArray) anArray;
264 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
266 return CanUseDefault;
269 thePoint.SetX( anArray->Value( 0 ) );
270 thePoint.SetY( anArray->Value( 1 ) );
272 if( IsConvertToGlobal )
273 aDoc->Transform( thePoint, false );
278 void HYDROData_Profile::SetRightPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
280 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint );
282 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
283 gp_XY aLPoint = theGPoint;
284 if( IsConvertFromGlobal )
285 aDoc->Transform( aLPoint, true );
287 Handle(TDataStd_RealArray) anArray;
288 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
289 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
291 anArray->SetValue( 0, aLPoint.X() );
292 anArray->SetValue( 1, aLPoint.Y() );
297 bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
298 bool CanUseDefault ) const
300 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
301 if ( aParametricPoints.Length() < 2 )
304 thePoint = GetParametricPoints().Last();
306 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
307 if ( aLabel.IsNull() )
309 return CanUseDefault;
312 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
313 Handle(TDataStd_RealArray) anArray;
314 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
316 return CanUseDefault;
319 thePoint.SetX( anArray->Value( 0 ) );
320 thePoint.SetY( anArray->Value( 1 ) );
322 if( IsConvertToGlobal )
323 aDoc->Transform( thePoint, false );
328 void HYDROData_Profile::Invalidate()
330 TDF_Label aFirstLabel = myLab.FindChild( DataTag_FirstPoint, false );
331 if ( !aFirstLabel.IsNull() )
332 aFirstLabel.ForgetAllAttributes();
334 TDF_Label aLastLabel = myLab.FindChild( DataTag_LastPoint, false );
335 if ( !aLastLabel.IsNull() )
336 aLastLabel.ForgetAllAttributes();
341 Handle(HYDROData_ProfileUZ) HYDROData_Profile::GetProfileUZ( const bool theIsCreate ) const
343 Handle(HYDROData_ProfileUZ) aProfileUZ;
345 TDF_Label aLabel = myLab.FindChild( DataTag_ChildProfileUZ, theIsCreate );
346 if ( aLabel.IsNull() )
349 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( HYDROData_Iterator::Object( aLabel ) );
350 if ( aProfileUZ.IsNull() && theIsCreate )
352 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast(
353 HYDROData_Iterator::CreateObject( aLabel, KIND_PROFILEUZ ) );
359 int HYDROData_Profile::NbPoints() const
361 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
362 return aProfileUZ.IsNull() ? 0 : aProfileUZ->NbPoints();
365 void HYDROData_Profile::RemovePoints()
367 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
368 if ( !aProfileUZ.IsNull() )
370 aProfileUZ->RemoveSections();
375 void HYDROData_Profile::SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints )
379 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
380 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
382 const HYDROData_ProfileUZ::Point& aPoint = thePoints.Value( i );
383 aProfileUZ->AddPoint( 0, aPoint );
389 HYDROData_ProfileUZ::PointsList HYDROData_Profile::GetParametricPoints() const
391 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
392 return aProfileUZ.IsNull() ? HYDROData_ProfileUZ::PointsList() : aProfileUZ->GetPoints();
395 void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints, bool IsConvertFromGlobal )
398 if ( thePoints.Length() < 2 )
401 gp_XY aFirstPoint, aLastPoint;
403 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
404 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
405 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
407 ProfilePoint aPoint = thePoints.Value( i );
408 if( IsConvertFromGlobal )
409 aDoc->Transform( aPoint, true );
411 gp_XY aPointXY( aPoint.X(), aPoint.Y() );
414 aFirstPoint = aPointXY;
416 aLastPoint = aPointXY;
418 double aDistance = gp_Pnt2d( aFirstPoint ).Distance( aPointXY );
420 HYDROData_ProfileUZ::Point aParPoint( aDistance, aPoint.Z() );
421 aProfileUZ->AddPoint( 0, aParPoint );
424 SetLeftPoint( aFirstPoint, false );//already converted to local CS
425 SetRightPoint( aLastPoint, false );
428 HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints
429 ( bool IsConvertToGlobal, bool CanUseDefaultLeftRight ) const
431 ProfilePoints aResPoints;
433 gp_XY aFirstPoint, aLastPoint;
434 if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) ||
435 !GetRightPoint( aLastPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) )
438 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
439 if ( aParametricPoints.Length() < 2 )
442 const HYDROData_ProfileUZ::Point& aFirstParPoint = aParametricPoints.First();
443 const HYDROData_ProfileUZ::Point& aLastParPoint = aParametricPoints.Last();
445 double aGeoDistance = gp_Pnt2d( aFirstPoint ).Distance( aLastPoint );
446 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
448 // Add first point as is
449 aResPoints.Append( ProfilePoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
451 // Compute all other points
452 for ( int i = 2, n = aParametricPoints.Length(); i < n ; ++i )
454 const HYDROData_ProfileUZ::Point& aParPoint = aParametricPoints.Value( i );
456 double aParPointDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aParPoint.X(), 0 ) );
458 double aParLen = ( aParPointDist / aParCommonDist ) * aGeoDistance;
460 double aRatio = aParLen / ( aGeoDistance - aParLen );
462 double aParX = ( aFirstPoint.X() + aRatio * aLastPoint.X() ) / ( 1 + aRatio );
463 double aParY = ( aFirstPoint.Y() + aRatio * aLastPoint.Y() ) / ( 1 + aRatio );
465 ProfilePoint aCompPoint( aParX, aParY, aParPoint.Y() );
466 aResPoints.Append( aCompPoint );
469 // Add last point as is
470 aResPoints.Append( ProfilePoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
475 void HYDROData_Profile::SetFilePath( const TCollection_AsciiString& theFilePath )
477 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
480 TCollection_AsciiString HYDROData_Profile::GetFilePath() const
482 TCollection_AsciiString aRes;
484 Handle(TDataStd_AsciiString) anAsciiStr;
485 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
486 aRes = anAsciiStr->Get();
491 int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
492 const TCollection_AsciiString& theFileName,
493 NCollection_Sequence<int>& theBadProfilesIds )
495 if ( theDoc.IsNull() || theFileName.IsEmpty() )
498 OSD_File aFile( theFileName );
499 if ( !aFile.IsReadable() )
502 aFile.Open( OSD_ReadOnly, OSD_Protection() );
503 if ( !aFile.IsOpen() )
506 NCollection_Sequence<Handle(HYDROData_Profile)> aCreatedProfiles;
509 Handle(HYDROData_Profile) aNewProfile;
510 for ( ; !aFile.IsAtEnd(); ++aProfileId )
512 if ( aNewProfile.IsNull() )
513 aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
515 bool anIsRead = false;
516 if ( aNewProfile->ImportFromFile( aFile, &anIsRead ) )
518 aCreatedProfiles.Append( aNewProfile );
519 aNewProfile.Nullify();
523 theBadProfilesIds.Append( aProfileId );
527 if ( !aNewProfile.IsNull() )
528 aNewProfile->Remove();
533 for ( int i = 1, n = aCreatedProfiles.Length(); i <= n ; ++i )
535 Handle(HYDROData_Profile) aProfile = aCreatedProfiles.Value( i );
537 QString aProfileName = HYDROData_Tool::GenerateObjectName( theDoc, "Profile" );
538 aProfile->SetName( aProfileName );
540 aProfile->SetFilePath( theFileName );
542 aProfile->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
545 return aCreatedProfiles.Length();
548 bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
554 // Try to open the file
555 OSD_File aFile( theFileName );
556 if ( !aFile.IsReadable() )
559 aFile.Open( OSD_ReadOnly, OSD_Protection() );
560 if ( !aFile.IsOpen() )
563 bool aRes = ImportFromFile( aFile, theIsRead );
571 SetFilePath( theFileName );
577 bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
583 if ( !theFile.IsOpen() )
588 bool anIsParametric = false;
589 bool anIsGeoref = false;
591 HYDROData_ProfileUZ::PointsList aPointsUZ;
592 ProfilePoints aPointsXYZ;
594 double aPrevVal = -DBL_MAX;
595 while ( !theFile.IsAtEnd() )
597 Standard_Integer aNbRead = 0;
598 TCollection_AsciiString aLine;
599 theFile.ReadLine( aLine, 1024, aNbRead );
601 aLine.LeftAdjust(); aLine.RightAdjust();
602 if ( aLine.IsEmpty() )
604 if ( !anIsParametric && !anIsGeoref )
605 continue; // Definition is not started yet
607 break; // Next profile started
610 // Set flag of read status to true
614 TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
615 TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
616 TCollection_AsciiString aValZ = aLine.Token( " \t", 3 );
618 if ( aValX.IsEmpty() || !aValX.IsRealValue() ||
619 aValY.IsEmpty() || !aValY.IsRealValue() )
625 if ( !anIsParametric && !anIsGeoref )
627 anIsParametric = aValZ.IsEmpty();
628 anIsGeoref = !aValZ.IsEmpty();
631 double aCoordX = aValX.RealValue();
632 double aCoordY = aValY.RealValue();
634 if ( boost::math::isnan( aCoordX ) || boost::math::isinf( aCoordX ) ||
635 boost::math::isnan( aCoordY ) || boost::math::isinf( aCoordY ) )
638 if ( anIsParametric )
640 if ( aCoordX < aPrevVal )
642 // Move back readed line
643 theFile.Seek( -( aNbRead + 1 ), OSD_FromHere );
647 HYDROData_ProfileUZ::Point aPoint( aCoordX, aCoordY );
648 aPointsUZ.Append( aPoint );
654 if ( aValZ.IsEmpty() || !aValZ.IsRealValue() )
660 double aCoordZ = aValZ.RealValue();
661 if ( boost::math::isnan( aCoordZ ) || boost::math::isinf( aCoordZ ) )
664 ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
665 aPointsXYZ.Append( aPoint );
669 aRes = aRes && ( anIsParametric && !aPointsUZ.IsEmpty() ||
670 anIsGeoref && !aPointsXYZ.IsEmpty() );
673 // Update profile points
674 if ( anIsParametric )
676 SetParametricPoints( aPointsUZ );
678 else if ( anIsGeoref )
680 SetProfilePoints( aPointsXYZ, true );
689 void HYDROData_Profile::UpdateLocalCS( double theDx, double theDy )
691 gp_XY aDelta( theDx, theDy );
694 GetLeftPoint( aPnt, false );
696 SetLeftPoint( aPnt, false );
698 GetRightPoint( aPnt, false );
700 SetRightPoint( aPnt, false );
703 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const
705 ProfilePoint aBottom;
707 // Get parametric points
708 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
709 if ( aParametricPoints.Length() < 1 ) {
713 // Calculate midvalue for U parameter
714 Standard_Real anUMidValue = aParametricPoints.First().X();
715 Standard_Real anUMinValue = anUMidValue;
716 Standard_Real anUMaxValue = anUMidValue;
718 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
719 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
720 Standard_Real anU = aParPoint.X();
722 if ( anU < anUMinValue ) {
724 } else if ( anU > anUMaxValue ) {
729 anUMidValue = ( anUMinValue + anUMaxValue ) / 2;
731 // Find index of the parametric point with minimal Z value
732 int aBottomIndex = 1;
733 HYDROData_IPolyline::Point aParBottom = aParametricPoints.First();
735 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
736 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
737 if ( aParPoint.Y() < aParBottom.Y() ) {
739 aParBottom = aParPoint;
740 } else if ( aParPoint.Y() == aParBottom.Y() ) {
741 // Check which point is neares to the U = 0.5
742 if ( fabs( aParPoint.X() - anUMidValue ) < fabs( aParBottom.X() - anUMidValue ) ) {
744 aParBottom = aParPoint;
749 // Find the corresponding profile point
750 ProfilePoints aProfilePoints = GetProfilePoints( false );
751 if ( aBottomIndex >= 1 && aBottomIndex <= aProfilePoints.Length() ) {
752 aBottom = aProfilePoints.Value( aBottomIndex );
758 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetMiddlePoint() const
760 ProfilePoint aMiddlePoint;
762 gp_XY aLeftPnt, aRightPnt;
763 if ( GetLeftPoint( aLeftPnt, false ) && GetRightPoint( aRightPnt, false ) ) {
764 gp_XYZ aPnt1( aLeftPnt.X(), aLeftPnt.Y(), 0. );
765 gp_XYZ aPnt2( aRightPnt.X(), aRightPnt.Y(), 0. );
766 gp_Pnt aMiddlePoint2d( 0.5 * ( aPnt1 + aPnt2 ) );
768 gp_Lin aMidLin( aMiddlePoint2d, gp::DZ() );
769 TopoDS_Edge aMidEdge = BRepLib_MakeEdge( aMidLin );
771 TopoDS_Iterator anIt( TopoDS::Wire( GetShape3D() ) );
772 for ( ; anIt.More(); anIt.Next()) {
773 const TopoDS_Edge& anEdge = TopoDS::Edge( anIt.Value() );
776 Standard_Real aStart, anEnd;
777 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
778 gp_Pnt aMiddlePointOnCurve = aCurve->Value( ( aStart + anEnd ) / 2 );
781 BRepExtrema_ExtCC ExtremaEE( aMidEdge, anEdge);
782 if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) {
783 for ( Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++ ) {
784 if ( ExtremaEE.SquareDistance(i) <= Precision::Confusion() ) {
785 aMiddlePoint = ExtremaEE.PointOnE1(i).XYZ();