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>
56 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object)
58 HYDROData_Profile::HYDROData_Profile()
59 : HYDROData_Object( Geom_3d )
63 HYDROData_Profile::~HYDROData_Profile()
67 QStringList HYDROData_Profile::DumpToPython( const QString& thePyScriptPath,
68 MapOfTreatedObjects& theTreatedObjects ) const
70 QStringList aResList = dumpObjectCreation( theTreatedObjects );
71 QString aProfileName = GetObjPyName();
73 //TCollection_AsciiString aFilePath = GetFilePath();
74 //if ( !aFilePath.IsEmpty() )
76 // aResList << QString( "%1.ImportFromFile( \"%2\" )" )
77 // .arg( aName ).arg( aFilePath.ToCString() );
80 bool anIsValidProfile = IsValid();
82 QStringList aPntsDefinition;
83 QString aPntsListName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "profile_points" );
85 QString aGap = QString().fill( ' ', aPntsListName.length() + 5 );
86 if ( anIsValidProfile )
88 HYDROData_Profile::ProfilePoints aPointsList = GetProfilePoints( true );
89 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
91 const ProfilePoint& aPoint = aPointsList.Value( k );
92 aPntsDefinition << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" )
93 .arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
94 .arg( ( k < aNbPoints ? "," : "" ) );
99 HYDROData_IPolyline::PointsList aPointsList = GetParametricPoints();
100 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
102 const HYDROData_IPolyline::Point& aPoint = aPointsList.Value( k );
103 aPntsDefinition << QString( aGap + "gp_XY( %1, %2 )%3" )
104 .arg( aPoint.X() ).arg( aPoint.Y() )
105 .arg( ( k < aNbPoints ? "," : "" ) );
109 if ( !aPntsDefinition.isEmpty() )
111 QString& aFirstStr = aPntsDefinition.first();
112 aFirstStr = aFirstStr.trimmed();
113 aFirstStr.prepend( QString( "%1 = [ " ).arg( aPntsListName ) );
115 aPntsDefinition.last().append( " ];" );
117 aResList << aPntsDefinition;
119 aResList << QString( "%1.%3( %2 )" )
120 .arg( aProfileName ).arg( aPntsListName )
121 .arg( anIsValidProfile ? "SetProfilePoints" : "SetParametricPoints" );
123 aResList << QString( "" );
126 // Set a polyline type if it is not default
127 Handle(HYDROData_ProfileUZ) aPrf = GetProfileUZ( false );
128 if ( !aPrf.IsNull() )
130 HYDROData_IPolyline::SectionType aSecType = aPrf->GetSectionType( 0 );
131 if ( aSecType != HYDROData_IPolyline::SECTION_POLYLINE )
133 aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 )" )
134 .arg( aProfileName ).arg( "HYDROData_IPolyline.SECTION_SPLINE" );
135 aResList << QString( "" );
139 aResList << QString( "%1.Update()" ).arg( aProfileName );
140 aResList << QString( "" );
145 TopoDS_Shape HYDROData_Profile::GetTopShape() const
149 gp_XY aFirstPoint, aLastPoint;
150 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
153 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 );
154 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 );
156 BRepBuilderAPI_MakeEdge aMakeEdge( aPnt1, aPnt2 );
157 TopoDS_Edge anEdge = aMakeEdge;
159 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
165 TopoDS_Shape HYDROData_Profile::GetShape3D(bool forceRebuild, bool reverseXCoord) const
168 return CreateProfileWire( true, reverseXCoord );
169 TopoDS_Shape aShape = HYDROData_Object::GetShape3D();
170 if( aShape.IsNull() )
171 aShape = CreateProfileWire( true, reverseXCoord );
175 TopoDS_Shape HYDROData_Profile::CreateProfileWire( bool canUseDefaultPoints, bool reverseXCoord ) const
178 Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
179 if ( !aProfile.IsNull() )
181 ProfilePoints aProfilePoints = GetProfilePoints( false, canUseDefaultPoints );
182 HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
185 for ( int i = 1; i <= aProfilePoints.Size() ; i++ )
187 gp_XYZ& aPoint = aProfilePoints.ChangeValue(i);
188 aPoint.ChangeCoord(1) = -aPoint.X();
191 aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
196 void HYDROData_Profile::Update()
198 HYDROData_Object::Update();
200 TopoDS_Shape aShape = CreateProfileWire( true );
201 SetShape3D( aShape );
204 QColor HYDROData_Profile::DefaultFillingColor() const
206 return QColor( Qt::transparent );
209 QColor HYDROData_Profile::DefaultBorderColor() const
211 return QColor( Qt::black );
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 ) )
238 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
239 anArray->SetID(TDataStd_RealArray::GetID());
242 anArray->SetValue( 0, aLPoint.X() );
243 anArray->SetValue( 1, aLPoint.Y() );
248 bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal,
249 bool CanUseDefault ) const
251 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
252 if ( aParametricPoints.Length() < 2 )
255 thePoint = GetParametricPoints().First();
257 //thePoint.SetX( 0 );
258 thePoint.SetY( 0 ); //default left point of not-georeferenced profile
259 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint, false );
260 if ( aLabel.IsNull() )
262 return CanUseDefault;
265 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
266 Handle(TDataStd_RealArray) anArray;
267 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
269 return CanUseDefault;
272 thePoint.SetX( anArray->Value( 0 ) );
273 thePoint.SetY( anArray->Value( 1 ) );
275 if( IsConvertToGlobal )
276 aDoc->Transform( thePoint, false );
281 void HYDROData_Profile::SetRightPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
283 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint );
285 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
286 gp_XY aLPoint = theGPoint;
287 if( IsConvertFromGlobal )
288 aDoc->Transform( aLPoint, true );
290 Handle(TDataStd_RealArray) anArray;
291 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
293 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
294 anArray->SetID(TDataStd_RealArray::GetID());
297 anArray->SetValue( 0, aLPoint.X() );
298 anArray->SetValue( 1, aLPoint.Y() );
303 bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
304 bool CanUseDefault ) const
306 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
307 if ( aParametricPoints.Length() < 2 )
310 thePoint = GetParametricPoints().Last();
313 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
314 if ( aLabel.IsNull() )
316 return CanUseDefault;
319 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
320 Handle(TDataStd_RealArray) anArray;
321 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
323 return CanUseDefault;
326 thePoint.SetX( anArray->Value( 0 ) );
327 thePoint.SetY( anArray->Value( 1 ) );
329 if( IsConvertToGlobal )
330 aDoc->Transform( thePoint, false );
335 void HYDROData_Profile::Invalidate()
337 TDF_Label aFirstLabel = myLab.FindChild( DataTag_FirstPoint, false );
338 if ( !aFirstLabel.IsNull() )
339 aFirstLabel.ForgetAllAttributes();
341 TDF_Label aLastLabel = myLab.FindChild( DataTag_LastPoint, false );
342 if ( !aLastLabel.IsNull() )
343 aLastLabel.ForgetAllAttributes();
348 Handle(HYDROData_ProfileUZ) HYDROData_Profile::GetProfileUZ( const bool theIsCreate ) const
350 Handle(HYDROData_ProfileUZ) aProfileUZ;
352 TDF_Label aLabel = myLab.FindChild( DataTag_ChildProfileUZ, theIsCreate );
353 if ( aLabel.IsNull() )
356 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( HYDROData_Iterator::Object( aLabel ) );
357 if ( aProfileUZ.IsNull() && theIsCreate )
359 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast(
360 HYDROData_Iterator::CreateObject( aLabel, KIND_PROFILEUZ ) );
366 int HYDROData_Profile::NbPoints() const
368 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
369 return aProfileUZ.IsNull() ? 0 : aProfileUZ->NbPoints();
372 void HYDROData_Profile::RemovePoints()
374 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
375 if ( !aProfileUZ.IsNull() )
377 aProfileUZ->RemoveSections();
382 void HYDROData_Profile::SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints )
386 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
387 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
389 const HYDROData_ProfileUZ::Point& aPoint = thePoints.Value( i );
390 aProfileUZ->AddPoint( 0, aPoint );
396 HYDROData_ProfileUZ::PointsList HYDROData_Profile::GetParametricPoints() const
398 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
399 return aProfileUZ.IsNull() ? HYDROData_ProfileUZ::PointsList() : aProfileUZ->GetPoints();
402 void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints, bool IsConvertFromGlobal )
405 if ( thePoints.Length() < 2 )
408 gp_XY aFirstPoint, aLastPoint;
410 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
411 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
412 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
414 ProfilePoint aPoint = thePoints.Value( i );
415 if( IsConvertFromGlobal )
416 aDoc->Transform( aPoint, true );
418 gp_XY aPointXY( aPoint.X(), aPoint.Y() );
421 aFirstPoint = aPointXY;
423 aLastPoint = aPointXY;
425 double aDistance = gp_Pnt2d( aFirstPoint ).Distance( aPointXY );
427 HYDROData_ProfileUZ::Point aParPoint( aDistance, aPoint.Z() );
428 aProfileUZ->AddPoint( 0, aParPoint );
431 SetLeftPoint( aFirstPoint, false );//already converted to local CS
432 SetRightPoint( aLastPoint, false );
435 HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints
436 ( bool IsConvertToGlobal, bool CanUseDefaultLeftRight ) const
438 gp_XY aFirstPoint, aLastPoint;
439 if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) ||
440 !GetRightPoint( aLastPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) )
441 return HYDROData_Profile::ProfilePoints();
443 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
445 return CalculateProfilePoints(aParametricPoints, aFirstPoint, aLastPoint);
448 HYDROData_Profile::ProfilePoints HYDROData_Profile::CalculateProfilePoints(
449 const HYDROData_ProfileUZ::PointsList& theParametricPoints,
450 const gp_XY& aFirstPoint, const gp_XY& aLastPoint)
452 ProfilePoints aResPoints;
454 if ( theParametricPoints.Length() < 2 )
457 const HYDROData_ProfileUZ::Point& aFirstParPoint = theParametricPoints.First();
458 const HYDROData_ProfileUZ::Point& aLastParPoint = theParametricPoints.Last();
460 double aFullLength = aLastPoint.X() - aFirstPoint.X();
461 double aParFullLength = aLastParPoint.X() - aFirstParPoint.X();
463 // Add first point as is
464 aResPoints.Append( ProfilePoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
466 // Compute all other points
467 for ( int i = 2, n = theParametricPoints.Length(); i < n ; ++i )
469 const HYDROData_ProfileUZ::Point& aParPoint = theParametricPoints.Value( i );
471 double aParPointDist = aParPoint.X() - aFirstParPoint.X();
472 double aRatio = aParPointDist / aParFullLength;
474 double aParX = aFirstPoint.X() * (1-aRatio) + aLastPoint.X() * aRatio;
475 double aParY = aFirstPoint.Y() * (1-aRatio) + aLastPoint.Y() * aRatio;
477 ProfilePoint aCompPoint( aParX, aParY, aParPoint.Y() );
478 aResPoints.Append( aCompPoint );
481 // Add last point as is
482 aResPoints.Append( ProfilePoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
487 void HYDROData_Profile::SetFilePath( const TCollection_AsciiString& theFilePath )
489 Handle(TDataStd_AsciiString) anAttr = TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
490 anAttr->SetID(TDataStd_AsciiString::GetID());
493 TCollection_AsciiString HYDROData_Profile::GetFilePath() const
495 TCollection_AsciiString aRes;
497 Handle(TDataStd_AsciiString) anAsciiStr;
498 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
499 aRes = anAsciiStr->Get();
504 void HYDROData_Profile::SetProfileColor( const QColor& theColor )
506 SetColor( theColor, DataTag_ProfileColor );
509 bool HYDROData_Profile::GetProfileColor(QColor& outColor) const
511 return GetColor( outColor, DataTag_ProfileColor );
514 int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
515 const TCollection_AsciiString& theFileName,
516 NCollection_Sequence<int>& theBadProfilesIds,
519 if ( theDoc.IsNull() || theFileName.IsEmpty() )
522 OSD_File aFile( theFileName );
523 if ( !aFile.IsReadable() )
526 aFile.Open( OSD_ReadOnly, OSD_Protection() );
527 if ( !aFile.IsOpen() )
530 NCollection_Sequence<Handle(HYDROData_Profile)> aCreatedProfiles;
533 Handle(HYDROData_Profile) aNewProfile;
534 for ( ; !aFile.IsAtEnd(); ++aProfileId )
536 if ( aNewProfile.IsNull() )
537 aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
539 bool anIsRead = false;
540 if ( aNewProfile->ImportFromFile( aFile, isToProject, &anIsRead ) )
542 aCreatedProfiles.Append( aNewProfile );
543 aNewProfile.Nullify();
547 theBadProfilesIds.Append( aProfileId );
551 if ( !aNewProfile.IsNull() )
552 aNewProfile->Remove();
557 for ( int i = 1, n = aCreatedProfiles.Length(); i <= n ; ++i )
559 Handle(HYDROData_Profile) aProfile = aCreatedProfiles.Value( i );
561 QString aProfileName = HYDROData_Tool::GenerateObjectName( theDoc, "Profile" );
562 aProfile->SetName( aProfileName );
564 aProfile->SetFilePath( theFileName );
566 aProfile->SetBorderColor( aProfile->DefaultBorderColor() );
569 return aCreatedProfiles.Length();
572 bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
579 // Try to open the file
580 OSD_File aFile( theFileName );
581 if ( !aFile.IsReadable() )
584 aFile.Open( OSD_ReadOnly, OSD_Protection() );
585 if ( !aFile.IsOpen() )
588 bool aRes = ImportFromFile( aFile, isToProject, isNotEmpty );
596 SetFilePath( theFileName );
602 bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
609 if ( !theFile.IsOpen() )
614 bool anIsParametric = false;
615 bool anIsGeoref = false;
617 HYDROData_ProfileUZ::PointsList aPointsUZ;
618 ProfilePoints aPointsXYZ;
620 double aPrevVal = -DBL_MAX;
621 while ( !theFile.IsAtEnd() )
623 Standard_Integer aNbRead = 0;
624 TCollection_AsciiString aLine;
625 theFile.ReadLine( aLine, 1024, aNbRead );
627 aLine.LeftAdjust(); aLine.RightAdjust();
628 if ( aLine.IsEmpty() )
630 if ( !anIsParametric && !anIsGeoref )
631 continue; // Definition is not started yet
633 break; // Next profile started
636 // Set flag of read status to true
640 TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
641 TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
642 TCollection_AsciiString aValZ = aLine.Token( " \t", 3 );
644 if ( aValX.IsEmpty() || !aValX.IsRealValue() ||
645 aValY.IsEmpty() || !aValY.IsRealValue() )
651 if ( !anIsParametric && !anIsGeoref )
653 anIsParametric = aValZ.IsEmpty();
654 anIsGeoref = !aValZ.IsEmpty();
657 double aCoordX = aValX.RealValue();
658 double aCoordY = aValY.RealValue();
660 if ( HYDROData_Tool::IsNan( aCoordX ) || HYDROData_Tool::IsInf( aCoordX ) ||
661 HYDROData_Tool::IsNan( aCoordY ) || HYDROData_Tool::IsInf( aCoordY ) )
664 if ( anIsParametric )
666 if ( aCoordX < aPrevVal )
668 // Move back readed line
669 theFile.Seek( -( aNbRead + 1 ), OSD_FromHere );
673 HYDROData_ProfileUZ::Point aPoint( aCoordX, aCoordY );
674 aPointsUZ.Append( aPoint );
680 if ( aValZ.IsEmpty() || !aValZ.IsRealValue() )
686 double aCoordZ = aValZ.RealValue();
687 if ( HYDROData_Tool::IsNan( aCoordZ ) || HYDROData_Tool::IsInf( aCoordZ ) )
690 ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
691 aPointsXYZ.Append( aPoint );
695 aRes = aRes && ( anIsParametric && !aPointsUZ.IsEmpty() ||
696 anIsGeoref && !aPointsXYZ.IsEmpty() );
699 // Update profile points
700 if ( anIsParametric )
702 SetParametricPoints( aPointsUZ );
704 else if ( anIsGeoref )
707 ProjectProfilePoints( aPointsXYZ );
708 SetProfilePoints( aPointsXYZ, true );
717 void HYDROData_Profile::UpdateLocalCS( double theDx, double theDy )
719 gp_XY aDelta( theDx, theDy );
722 GetLeftPoint( aPnt, false );
724 SetLeftPoint( aPnt, false );
726 GetRightPoint( aPnt, false );
728 SetRightPoint( aPnt, false );
731 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint(bool IsConvertToGlobal) const
733 ProfilePoint aBottom;
735 // Get parametric points
736 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
737 if ( aParametricPoints.Length() < 1 ) {
741 // Calculate midvalue for U parameter
742 Standard_Real anUMidValue = aParametricPoints.First().X();
743 Standard_Real anUMinValue = anUMidValue;
744 Standard_Real anUMaxValue = anUMidValue;
746 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
747 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
748 Standard_Real anU = aParPoint.X();
750 if ( anU < anUMinValue ) {
752 } else if ( anU > anUMaxValue ) {
757 anUMidValue = ( anUMinValue + anUMaxValue ) / 2;
759 // Find index of the parametric point with minimal Z value
760 int aBottomIndex = 1;
761 HYDROData_IPolyline::Point aParBottom = aParametricPoints.First();
763 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
764 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
765 if ( aParPoint.Y() < aParBottom.Y() ) {
767 aParBottom = aParPoint;
768 } else if ( aParPoint.Y() == aParBottom.Y() ) {
769 // Check which point is neares to the U = 0.5
770 if ( fabs( aParPoint.X() - anUMidValue ) < fabs( aParBottom.X() - anUMidValue ) ) {
772 aParBottom = aParPoint;
777 // Find the corresponding profile point
778 ProfilePoints aProfilePoints = GetProfilePoints( IsConvertToGlobal );
779 if ( aBottomIndex >= 1 && aBottomIndex <= aProfilePoints.Length() ) {
780 aBottom = aProfilePoints.Value( aBottomIndex );
786 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetMiddlePoint( bool CanUseDefault ) const
788 ProfilePoint aMiddlePoint;
790 gp_XY aLeftPnt, aRightPnt;
791 if ( GetLeftPoint( aLeftPnt, true, CanUseDefault ) && GetRightPoint( aRightPnt, true, CanUseDefault ) ) {
792 gp_XYZ aPnt1( aLeftPnt.X(), aLeftPnt.Y(), 0. );
793 gp_XYZ aPnt2( aRightPnt.X(), aRightPnt.Y(), 0. );
794 gp_Pnt aMiddlePoint2d( 0.5 * ( aPnt1 + aPnt2 ) );
796 gp_Lin aMidLin( aMiddlePoint2d, gp::DZ() );
797 TopoDS_Edge aMidEdge = BRepLib_MakeEdge( aMidLin );
799 TopoDS_Iterator anIt( TopoDS::Wire( GetShape3D() ) );
800 for ( ; anIt.More(); anIt.Next()) {
801 const TopoDS_Edge& anEdge = TopoDS::Edge( anIt.Value() );
804 Standard_Real aStart, anEnd;
805 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
806 gp_Pnt aMiddlePointOnCurve = aCurve->Value( ( aStart + anEnd ) / 2 );
809 BRepExtrema_ExtCC ExtremaEE( aMidEdge, anEdge);
810 if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) {
811 for ( Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++ ) {
812 if ( ExtremaEE.SquareDistance(i) <= Precision::Confusion() ) {
813 aMiddlePoint = ExtremaEE.PointOnE1(i).XYZ();
824 void HYDROData_Profile::ProjectProfilePoints( ProfilePoints& thePoints )
826 int low = thePoints.Lower(), up = thePoints.Upper();
827 gp_Pnt aFirst = thePoints.Value( low );
828 gp_Pnt aLast = thePoints.Value( up );
829 gp_Vec d( aFirst, aLast );
830 gp_Vec n( d.Y(), -d.X(), 0 );
832 Handle(Geom_Plane) aPlane = new Geom_Plane( aFirst, gp_Dir( n ) );
833 for( int i=low; i<=up; i++ )
835 gp_XYZ p = thePoints.Value( i );
836 gp_Pnt pp = GeomAPI_ProjectPointOnSurf( p, aPlane );
837 thePoints.SetValue( i, pp.XYZ() );