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 <BRepBuilderAPI_MakeEdge.hxx>
27 #include <BRepBuilderAPI_MakeWire.hxx>
28 #include <BRepBuilderAPI_MakePolygon.hxx>
30 #include <BRepExtrema_ExtCC.hxx>
32 #include <BRep_Tool.hxx>
37 #include <gp_Pnt2d.hxx>
39 #include <GeomAPI_ProjectPointOnSurf.hxx>
40 #include <Geom_Plane.hxx>
42 #include <TDataStd_AsciiString.hxx>
43 #include <TDataStd_RealArray.hxx>
46 #include <TopoDS_Edge.hxx>
47 #include <TopoDS_Wire.hxx>
48 #include <TopoDS_Iterator.hxx>
50 #include <OSD_File.hxx>
51 #include <OSD_Protection.hxx>
54 #include <QStringList>
57 #include "HYDRO_trace.hxx"
59 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object)
61 HYDROData_Profile::HYDROData_Profile()
62 : HYDROData_Object( Geom_3d )
66 HYDROData_Profile::~HYDROData_Profile()
70 QStringList HYDROData_Profile::DumpToPython( const QString& thePyScriptPath,
71 MapOfTreatedObjects& theTreatedObjects ) const
73 QStringList aResList = dumpObjectCreation( theTreatedObjects );
74 QString aProfileName = GetObjPyName();
76 //TCollection_AsciiString aFilePath = GetFilePath();
77 //if ( !aFilePath.IsEmpty() )
79 // aResList << QString( "%1.ImportFromFile( \"%2\" )" )
80 // .arg( aName ).arg( aFilePath.ToCString() );
83 bool anIsValidProfile = IsValid();
85 QStringList aPntsDefinition;
86 QString aPntsListName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "profile_points" );
88 QString aGap = QString().fill( ' ', aPntsListName.length() + 5 );
89 if ( anIsValidProfile )
91 HYDROData_Profile::ProfilePoints aPointsList = GetProfilePoints( true );
92 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
94 const ProfilePoint& aPoint = aPointsList.Value( k );
95 aPntsDefinition << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" )
96 .arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
97 .arg( ( k < aNbPoints ? "," : "" ) );
102 HYDROData_IPolyline::PointsList aPointsList = GetParametricPoints();
103 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
105 const HYDROData_IPolyline::Point& aPoint = aPointsList.Value( k );
106 aPntsDefinition << QString( aGap + "gp_XY( %1, %2 )%3" )
107 .arg( aPoint.X() ).arg( aPoint.Y() )
108 .arg( ( k < aNbPoints ? "," : "" ) );
112 if ( !aPntsDefinition.isEmpty() )
114 QString& aFirstStr = aPntsDefinition.first();
115 aFirstStr = aFirstStr.trimmed();
116 aFirstStr.prepend( QString( "%1 = [ " ).arg( aPntsListName ) );
118 aPntsDefinition.last().append( " ];" );
120 aResList << aPntsDefinition;
122 aResList << QString( "%1.%3( %2 )" )
123 .arg( aProfileName ).arg( aPntsListName )
124 .arg( anIsValidProfile ? "SetProfilePoints" : "SetParametricPoints" );
126 aResList << QString( "" );
129 // Set a polyline type if it is not default
130 Handle(HYDROData_ProfileUZ) aPrf = GetProfileUZ( false );
131 if ( !aPrf.IsNull() )
133 HYDROData_IPolyline::SectionType aSecType = aPrf->GetSectionType( 0 );
134 if ( aSecType != HYDROData_IPolyline::SECTION_POLYLINE )
136 aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 )" )
137 .arg( aProfileName ).arg( "HYDROData_IPolyline.SECTION_SPLINE" );
138 aResList << QString( "" );
142 aResList << QString( "%1.Update()" ).arg( aProfileName );
143 aResList << QString( "" );
148 TopoDS_Shape HYDROData_Profile::GetTopShape() const
152 gp_XY aFirstPoint, aLastPoint;
153 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
156 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 );
157 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 );
159 BRepBuilderAPI_MakeEdge aMakeEdge( aPnt1, aPnt2 );
160 TopoDS_Edge anEdge = aMakeEdge;
162 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
168 TopoDS_Shape HYDROData_Profile::GetShape3D(bool forceRebuild, bool reverseXCoord) const
171 return CreateProfileWire( true, reverseXCoord );
172 TopoDS_Shape aShape = HYDROData_Object::GetShape3D();
173 if( aShape.IsNull() )
174 aShape = CreateProfileWire( true, reverseXCoord );
178 TopoDS_Shape HYDROData_Profile::CreateProfileWire( bool canUseDefaultPoints, bool reverseXCoord ) const
181 Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
182 if ( !aProfile.IsNull() )
184 ProfilePoints aProfilePoints = GetProfilePoints( false, canUseDefaultPoints );
185 HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
188 for ( int i = 1; i <= aProfilePoints.Size() ; i++ )
190 gp_XYZ& aPoint = aProfilePoints.ChangeValue(i);
191 aPoint.ChangeCoord(1) = -aPoint.X();
194 aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
199 void HYDROData_Profile::Update()
201 HYDROData_Object::Update();
203 TopoDS_Shape aShape = CreateProfileWire( true );
204 SetShape3D( aShape );
207 QColor HYDROData_Profile::DefaultFillingColor() const
209 return QColor( Qt::transparent );
212 QColor HYDROData_Profile::DefaultBorderColor() const
214 return QColor( Qt::black );
217 bool HYDROData_Profile::IsValid() const
219 gp_XY aFirstPoint, aLastPoint;
220 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
223 int aNbPoints = NbPoints();
224 return aNbPoints > 1;
227 void HYDROData_Profile::SetLeftPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
229 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint );
230 if ( aLabel.IsNull() )
233 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
234 gp_XY aLPoint = theGPoint;
235 if( IsConvertFromGlobal )
236 aDoc->Transform( aLPoint, true );
238 Handle(TDataStd_RealArray) anArray;
239 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
241 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
242 anArray->SetID(TDataStd_RealArray::GetID());
245 anArray->SetValue( 0, aLPoint.X() );
246 anArray->SetValue( 1, aLPoint.Y() );
251 bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal,
252 bool CanUseDefault ) const
254 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
255 if ( aParametricPoints.Length() < 2 )
258 thePoint = GetParametricPoints().First();
260 //thePoint.SetX( 0 );
261 thePoint.SetY( 0 ); //default left point of not-georeferenced profile
262 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint, false );
263 if ( aLabel.IsNull() )
265 return CanUseDefault;
268 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
269 Handle(TDataStd_RealArray) anArray;
270 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
272 return CanUseDefault;
275 thePoint.SetX( anArray->Value( 0 ) );
276 thePoint.SetY( anArray->Value( 1 ) );
278 if( IsConvertToGlobal )
279 aDoc->Transform( thePoint, false );
284 void HYDROData_Profile::SetRightPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
286 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint );
288 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
289 gp_XY aLPoint = theGPoint;
290 if( IsConvertFromGlobal )
291 aDoc->Transform( aLPoint, true );
293 Handle(TDataStd_RealArray) anArray;
294 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
296 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
297 anArray->SetID(TDataStd_RealArray::GetID());
300 anArray->SetValue( 0, aLPoint.X() );
301 anArray->SetValue( 1, aLPoint.Y() );
306 bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
307 bool CanUseDefault ) const
309 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
310 if ( aParametricPoints.Length() < 2 )
313 thePoint = GetParametricPoints().Last();
316 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
317 if ( aLabel.IsNull() )
319 return CanUseDefault;
322 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
323 Handle(TDataStd_RealArray) anArray;
324 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
326 return CanUseDefault;
329 thePoint.SetX( anArray->Value( 0 ) );
330 thePoint.SetY( anArray->Value( 1 ) );
332 if( IsConvertToGlobal )
333 aDoc->Transform( thePoint, false );
338 void HYDROData_Profile::Invalidate()
340 TDF_Label aFirstLabel = myLab.FindChild( DataTag_FirstPoint, false );
341 if ( !aFirstLabel.IsNull() )
342 aFirstLabel.ForgetAllAttributes();
344 TDF_Label aLastLabel = myLab.FindChild( DataTag_LastPoint, false );
345 if ( !aLastLabel.IsNull() )
346 aLastLabel.ForgetAllAttributes();
351 Handle(HYDROData_ProfileUZ) HYDROData_Profile::GetProfileUZ( const bool theIsCreate ) const
353 Handle(HYDROData_ProfileUZ) aProfileUZ;
355 TDF_Label aLabel = myLab.FindChild( DataTag_ChildProfileUZ, theIsCreate );
356 if ( aLabel.IsNull() )
359 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( HYDROData_Iterator::Object( aLabel ) );
360 if ( aProfileUZ.IsNull() && theIsCreate )
362 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast(
363 HYDROData_Iterator::CreateObject( aLabel, KIND_PROFILEUZ ) );
369 int HYDROData_Profile::NbPoints() const
371 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
372 return aProfileUZ.IsNull() ? 0 : aProfileUZ->NbPoints();
375 void HYDROData_Profile::RemovePoints()
377 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
378 if ( !aProfileUZ.IsNull() )
380 aProfileUZ->RemoveSections();
385 void HYDROData_Profile::SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints )
389 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
390 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
392 const HYDROData_ProfileUZ::Point& aPoint = thePoints.Value( i );
393 aProfileUZ->AddPoint( 0, aPoint );
399 HYDROData_ProfileUZ::PointsList HYDROData_Profile::GetParametricPoints() const
401 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
402 return aProfileUZ.IsNull() ? HYDROData_ProfileUZ::PointsList() : aProfileUZ->GetPoints();
405 void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints, bool IsConvertFromGlobal )
408 if ( thePoints.Length() < 2 )
411 gp_XY aFirstPoint, aLastPoint;
413 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
414 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
415 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
417 ProfilePoint aPoint = thePoints.Value( i );
418 if( IsConvertFromGlobal )
419 aDoc->Transform( aPoint, true );
421 gp_XY aPointXY( aPoint.X(), aPoint.Y() );
424 aFirstPoint = aPointXY;
426 aLastPoint = aPointXY;
428 double aDistance = gp_Pnt2d( aFirstPoint ).Distance( aPointXY );
430 HYDROData_ProfileUZ::Point aParPoint( aDistance, aPoint.Z() );
431 aProfileUZ->AddPoint( 0, aParPoint );
434 SetLeftPoint( aFirstPoint, false );//already converted to local CS
435 SetRightPoint( aLastPoint, false );
438 HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints
439 ( bool IsConvertToGlobal, bool CanUseDefaultLeftRight ) const
441 gp_XY aFirstPoint, aLastPoint;
442 if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) ||
443 !GetRightPoint( aLastPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) )
444 return HYDROData_Profile::ProfilePoints();
446 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
448 return CalculateProfilePoints(aParametricPoints, aFirstPoint, aLastPoint);
451 HYDROData_Profile::ProfilePoints HYDROData_Profile::CalculateProfilePoints(
452 const HYDROData_ProfileUZ::PointsList& theParametricPoints,
453 const gp_XY& aFirstPoint, const gp_XY& aLastPoint)
455 ProfilePoints aResPoints;
457 if ( theParametricPoints.Length() < 2 )
460 const HYDROData_ProfileUZ::Point& aFirstParPoint = theParametricPoints.First();
461 const HYDROData_ProfileUZ::Point& aLastParPoint = theParametricPoints.Last();
463 double aFullLength = aLastPoint.X() - aFirstPoint.X();
464 double aParFullLength = aLastParPoint.X() - aFirstParPoint.X();
466 // Add first point as is
467 aResPoints.Append( ProfilePoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
469 // Compute all other points
470 for ( int i = 2, n = theParametricPoints.Length(); i < n ; ++i )
472 const HYDROData_ProfileUZ::Point& aParPoint = theParametricPoints.Value( i );
474 double aParPointDist = aParPoint.X() - aFirstParPoint.X();
475 double aRatio = aParPointDist / aParFullLength;
477 double aParX = aFirstPoint.X() * (1-aRatio) + aLastPoint.X() * aRatio;
478 double aParY = aFirstPoint.Y() * (1-aRatio) + aLastPoint.Y() * aRatio;
480 ProfilePoint aCompPoint( aParX, aParY, aParPoint.Y() );
481 aResPoints.Append( aCompPoint );
484 // Add last point as is
485 aResPoints.Append( ProfilePoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
490 void HYDROData_Profile::SetFilePath( const TCollection_AsciiString& theFilePath )
492 Handle(TDataStd_AsciiString) anAttr = TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
493 anAttr->SetID(TDataStd_AsciiString::GetID());
496 TCollection_AsciiString HYDROData_Profile::GetFilePath() const
498 TCollection_AsciiString aRes;
500 Handle(TDataStd_AsciiString) anAsciiStr;
501 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
502 aRes = anAsciiStr->Get();
507 void HYDROData_Profile::SetProfileColor( const QColor& theColor )
509 SetColor( theColor, DataTag_ProfileColor );
512 bool HYDROData_Profile::GetProfileColor(QColor& outColor) const
514 return GetColor( outColor, DataTag_ProfileColor );
517 int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
518 const TCollection_AsciiString& theFileName,
519 NCollection_Sequence<int>& theBadProfilesIds,
522 if ( theDoc.IsNull() || theFileName.IsEmpty() )
525 OSD_File aFile( theFileName );
526 if ( !aFile.IsReadable() )
529 aFile.Open( OSD_ReadOnly, OSD_Protection() );
530 if ( !aFile.IsOpen() )
533 NCollection_Sequence<Handle(HYDROData_Profile)> aCreatedProfiles;
536 Handle(HYDROData_Profile) aNewProfile;
537 for ( ; !aFile.IsAtEnd(); ++aProfileId )
539 if ( aNewProfile.IsNull() )
540 aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
542 bool anIsRead = false;
543 if ( aNewProfile->ImportFromFile( aFile, isToProject, &anIsRead ) )
545 aCreatedProfiles.Append( aNewProfile );
546 aNewProfile.Nullify();
550 theBadProfilesIds.Append( aProfileId );
554 if ( !aNewProfile.IsNull() )
555 aNewProfile->Remove();
560 for ( int i = 1, n = aCreatedProfiles.Length(); i <= n ; ++i )
562 Handle(HYDROData_Profile) aProfile = aCreatedProfiles.Value( i );
564 QString aProfileName = HYDROData_Tool::GenerateObjectName( theDoc, "Profile" );
565 aProfile->SetName( aProfileName );
567 aProfile->SetFilePath( theFileName );
569 aProfile->SetBorderColor( aProfile->DefaultBorderColor() );
572 return aCreatedProfiles.Length();
575 bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
582 // Try to open the file
583 OSD_File aFile( theFileName );
584 if ( !aFile.IsReadable() )
587 aFile.Open( OSD_ReadOnly, OSD_Protection() );
588 if ( !aFile.IsOpen() )
591 bool aRes = ImportFromFile( aFile, isToProject, isNotEmpty );
599 SetFilePath( theFileName );
605 bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
612 if ( !theFile.IsOpen() )
617 bool anIsParametric = false;
618 bool anIsGeoref = false;
620 HYDROData_ProfileUZ::PointsList aPointsUZ;
621 ProfilePoints aPointsXYZ;
623 double aPrevVal = -DBL_MAX;
624 while ( !theFile.IsAtEnd() )
626 Standard_Integer aNbRead = 0;
627 TCollection_AsciiString aLine;
628 theFile.ReadLine( aLine, 1024, aNbRead );
630 aLine.LeftAdjust(); aLine.RightAdjust();
631 if ( aLine.IsEmpty() )
633 if ( !anIsParametric && !anIsGeoref )
634 continue; // Definition is not started yet
636 break; // Next profile started
639 // Set flag of read status to true
643 TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
644 TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
645 TCollection_AsciiString aValZ = aLine.Token( " \t", 3 );
647 if ( aValX.IsEmpty() || !aValX.IsRealValue() ||
648 aValY.IsEmpty() || !aValY.IsRealValue() )
654 if ( !anIsParametric && !anIsGeoref )
656 anIsParametric = aValZ.IsEmpty();
657 anIsGeoref = !aValZ.IsEmpty();
660 double aCoordX = aValX.RealValue();
661 double aCoordY = aValY.RealValue();
663 if ( HYDROData_Tool::IsNan( aCoordX ) || HYDROData_Tool::IsInf( aCoordX ) ||
664 HYDROData_Tool::IsNan( aCoordY ) || HYDROData_Tool::IsInf( aCoordY ) )
667 if ( anIsParametric )
669 if ( aCoordX < aPrevVal )
671 // Move back readed line
672 theFile.Seek( -( aNbRead + 1 ), OSD_FromHere );
676 HYDROData_ProfileUZ::Point aPoint( aCoordX, aCoordY );
677 aPointsUZ.Append( aPoint );
683 if ( aValZ.IsEmpty() || !aValZ.IsRealValue() )
689 double aCoordZ = aValZ.RealValue();
690 if ( HYDROData_Tool::IsNan( aCoordZ ) || HYDROData_Tool::IsInf( aCoordZ ) )
693 ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
694 aPointsXYZ.Append( aPoint );
698 aRes = aRes && ( anIsParametric && !aPointsUZ.IsEmpty() ||
699 anIsGeoref && !aPointsXYZ.IsEmpty() );
702 // Update profile points
703 if ( anIsParametric )
705 SetParametricPoints( aPointsUZ );
707 else if ( anIsGeoref )
710 ProjectProfilePoints( aPointsXYZ );
711 SetProfilePoints( aPointsXYZ, true );
720 void HYDROData_Profile::UpdateLocalCS( double theDx, double theDy )
722 gp_XY aDelta( theDx, theDy );
725 GetLeftPoint( aPnt, false );
727 SetLeftPoint( aPnt, false );
729 GetRightPoint( aPnt, false );
731 SetRightPoint( aPnt, false );
734 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint(bool IsConvertToGlobal) const
736 ProfilePoint aBottom;
738 // Get parametric points
739 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
740 if ( aParametricPoints.Length() < 1 ) {
744 // Calculate midvalue for U parameter
745 Standard_Real anUMidValue = aParametricPoints.First().X();
746 Standard_Real anUMinValue = anUMidValue;
747 Standard_Real anUMaxValue = anUMidValue;
749 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
750 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
751 Standard_Real anU = aParPoint.X();
753 if ( anU < anUMinValue ) {
755 } else if ( anU > anUMaxValue ) {
760 anUMidValue = ( anUMinValue + anUMaxValue ) / 2;
762 // Find index of the parametric point with minimal Z value
763 int aBottomIndex = 1;
764 HYDROData_IPolyline::Point aParBottom = aParametricPoints.First();
766 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
767 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
768 if ( aParPoint.Y() < aParBottom.Y() ) {
770 aParBottom = aParPoint;
771 } else if ( aParPoint.Y() == aParBottom.Y() ) {
772 // Check which point is neares to the U = 0.5
773 if ( fabs( aParPoint.X() - anUMidValue ) < fabs( aParBottom.X() - anUMidValue ) ) {
775 aParBottom = aParPoint;
780 // Find the corresponding profile point
781 ProfilePoints aProfilePoints = GetProfilePoints( IsConvertToGlobal );
782 if ( aBottomIndex >= 1 && aBottomIndex <= aProfilePoints.Length() ) {
783 aBottom = aProfilePoints.Value( aBottomIndex );
789 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetMiddlePoint( bool CanUseDefault ) const
791 ProfilePoint aMiddlePoint;
793 gp_XY aLeftPnt, aRightPnt;
794 if ( GetLeftPoint( aLeftPnt, true, CanUseDefault ) && GetRightPoint( aRightPnt, true, CanUseDefault ) ) {
795 gp_XYZ aPnt1( aLeftPnt.X(), aLeftPnt.Y(), 0. );
796 gp_XYZ aPnt2( aRightPnt.X(), aRightPnt.Y(), 0. );
797 gp_Pnt aMiddlePoint2d( 0.5 * ( aPnt1 + aPnt2 ) );
799 gp_Lin aMidLin( aMiddlePoint2d, gp::DZ() );
800 TopoDS_Edge aMidEdge = BRepLib_MakeEdge( aMidLin );
802 TopoDS_Shape aProf = TopoDS::Wire( GetShape3D() );
805 TopoDS_Iterator anIt( aProf );
806 for ( ; anIt.More(); anIt.Next()) {
807 const TopoDS_Edge& anEdge = TopoDS::Edge( anIt.Value() );
810 Standard_Real aStart, anEnd;
811 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
812 gp_Pnt aMiddlePointOnCurve = aCurve->Value( ( aStart + anEnd ) / 2 );
815 BRepExtrema_ExtCC ExtremaEE( aMidEdge, anEdge);
816 if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) {
817 for ( Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++ ) {
818 if ( ExtremaEE.SquareDistance(i) <= Precision::Confusion() ) {
819 aMiddlePoint = ExtremaEE.PointOnE1(i).XYZ();
830 void HYDROData_Profile::ProjectProfilePoints( ProfilePoints& thePoints )
832 int low = thePoints.Lower(), up = thePoints.Upper();
833 gp_Pnt aFirst = thePoints.Value( low );
834 gp_Pnt aLast = thePoints.Value( up );
835 gp_Vec d( aFirst, aLast );
836 gp_Vec n( d.Y(), -d.X(), 0 );
838 Handle(Geom_Plane) aPlane = new Geom_Plane( aFirst, gp_Dir( n ) );
839 for( int i=low; i<=up; i++ )
841 gp_XYZ p = thePoints.Value( i );
842 gp_Pnt pp = GeomAPI_ProjectPointOnSurf( p, aPlane );
843 thePoints.SetValue( i, pp.XYZ() );