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_HANDLE(HYDROData_Profile, HYDROData_Object)
57 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object)
59 HYDROData_Profile::HYDROData_Profile()
60 : HYDROData_Object( Geom_3d )
64 HYDROData_Profile::~HYDROData_Profile()
68 QStringList HYDROData_Profile::DumpToPython( const QString& thePyScriptPath,
69 MapOfTreatedObjects& theTreatedObjects ) const
71 QStringList aResList = dumpObjectCreation( theTreatedObjects );
72 QString aProfileName = GetObjPyName();
74 //TCollection_AsciiString aFilePath = GetFilePath();
75 //if ( !aFilePath.IsEmpty() )
77 // aResList << QString( "%1.ImportFromFile( \"%2\" )" )
78 // .arg( aName ).arg( aFilePath.ToCString() );
81 bool anIsValidProfile = IsValid();
83 QStringList aPntsDefinition;
84 QString aPntsListName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "profile_points" );
86 QString aGap = QString().fill( ' ', aPntsListName.length() + 5 );
87 if ( anIsValidProfile )
89 HYDROData_Profile::ProfilePoints aPointsList = GetProfilePoints( true );
90 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
92 const ProfilePoint& aPoint = aPointsList.Value( k );
93 aPntsDefinition << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" )
94 .arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
95 .arg( ( k < aNbPoints ? "," : "" ) );
100 HYDROData_IPolyline::PointsList aPointsList = GetParametricPoints();
101 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
103 const HYDROData_IPolyline::Point& aPoint = aPointsList.Value( k );
104 aPntsDefinition << QString( aGap + "gp_XY( %1, %2 )%3" )
105 .arg( aPoint.X() ).arg( aPoint.Y() )
106 .arg( ( k < aNbPoints ? "," : "" ) );
110 if ( !aPntsDefinition.isEmpty() )
112 QString& aFirstStr = aPntsDefinition.first();
113 aFirstStr = aFirstStr.trimmed();
114 aFirstStr.prepend( QString( "%1 = [ " ).arg( aPntsListName ) );
116 aPntsDefinition.last().append( " ];" );
118 aResList << aPntsDefinition;
120 aResList << QString( "%1.%3( %2 )" )
121 .arg( aProfileName ).arg( aPntsListName )
122 .arg( anIsValidProfile ? "SetProfilePoints" : "SetParametricPoints" );
124 aResList << QString( "" );
127 // Set a polyline type if it is not default
128 Handle(HYDROData_ProfileUZ) aPrf = GetProfileUZ( false );
129 if ( !aPrf.IsNull() )
131 HYDROData_IPolyline::SectionType aSecType = aPrf->GetSectionType( 0 );
132 if ( aSecType != HYDROData_IPolyline::SECTION_POLYLINE )
134 aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 )" )
135 .arg( aProfileName ).arg( "HYDROData_IPolyline.SECTION_SPLINE" );
136 aResList << QString( "" );
140 aResList << QString( "%1.Update()" ).arg( aProfileName );
141 aResList << QString( "" );
146 TopoDS_Shape HYDROData_Profile::GetTopShape() const
150 gp_XY aFirstPoint, aLastPoint;
151 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
154 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 );
155 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 );
157 BRepBuilderAPI_MakeEdge aMakeEdge( aPnt1, aPnt2 );
158 TopoDS_Edge anEdge = aMakeEdge;
160 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
166 TopoDS_Shape HYDROData_Profile::GetShape3D() const
168 TopoDS_Shape aShape = HYDROData_Object::GetShape3D();
169 if( aShape.IsNull() )
170 aShape = CreateProfileWire( true );
174 TopoDS_Shape HYDROData_Profile::CreateProfileWire( bool canUseDefaultPoints ) const
177 Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
178 if ( !aProfile.IsNull() )
180 ProfilePoints aProfilePoints = GetProfilePoints( false, canUseDefaultPoints );
181 HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
183 aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
188 void HYDROData_Profile::Update()
190 HYDROData_Object::Update();
192 TopoDS_Shape aShape = CreateProfileWire( true );
193 SetShape3D( aShape );
196 QColor HYDROData_Profile::DefaultFillingColor() const
198 return QColor( Qt::transparent );
201 QColor HYDROData_Profile::DefaultBorderColor() const
203 return QColor( Qt::black );
206 bool HYDROData_Profile::IsValid() const
208 gp_XY aFirstPoint, aLastPoint;
209 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
212 int aNbPoints = NbPoints();
213 return aNbPoints > 1;
216 void HYDROData_Profile::SetLeftPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
218 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint );
219 if ( aLabel.IsNull() )
222 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
223 gp_XY aLPoint = theGPoint;
224 if( IsConvertFromGlobal )
225 aDoc->Transform( aLPoint, true );
227 Handle(TDataStd_RealArray) anArray;
228 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
229 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
231 anArray->SetValue( 0, aLPoint.X() );
232 anArray->SetValue( 1, aLPoint.Y() );
237 bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal,
238 bool CanUseDefault ) const
240 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
241 if ( aParametricPoints.Length() < 2 )
244 thePoint = GetParametricPoints().First();
246 //thePoint.SetX( 0 );
247 thePoint.SetY( 0 ); //default left point of not-georeferenced profile
248 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint, false );
249 if ( aLabel.IsNull() )
251 return CanUseDefault;
254 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
255 Handle(TDataStd_RealArray) anArray;
256 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
258 return CanUseDefault;
261 thePoint.SetX( anArray->Value( 0 ) );
262 thePoint.SetY( anArray->Value( 1 ) );
264 if( IsConvertToGlobal )
265 aDoc->Transform( thePoint, false );
270 void HYDROData_Profile::SetRightPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
272 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint );
274 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
275 gp_XY aLPoint = theGPoint;
276 if( IsConvertFromGlobal )
277 aDoc->Transform( aLPoint, true );
279 Handle(TDataStd_RealArray) anArray;
280 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
281 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
283 anArray->SetValue( 0, aLPoint.X() );
284 anArray->SetValue( 1, aLPoint.Y() );
289 bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
290 bool CanUseDefault ) const
292 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
293 if ( aParametricPoints.Length() < 2 )
296 thePoint = GetParametricPoints().Last();
299 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
300 if ( aLabel.IsNull() )
302 return CanUseDefault;
305 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
306 Handle(TDataStd_RealArray) anArray;
307 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
309 return CanUseDefault;
312 thePoint.SetX( anArray->Value( 0 ) );
313 thePoint.SetY( anArray->Value( 1 ) );
315 if( IsConvertToGlobal )
316 aDoc->Transform( thePoint, false );
321 void HYDROData_Profile::Invalidate()
323 TDF_Label aFirstLabel = myLab.FindChild( DataTag_FirstPoint, false );
324 if ( !aFirstLabel.IsNull() )
325 aFirstLabel.ForgetAllAttributes();
327 TDF_Label aLastLabel = myLab.FindChild( DataTag_LastPoint, false );
328 if ( !aLastLabel.IsNull() )
329 aLastLabel.ForgetAllAttributes();
334 Handle(HYDROData_ProfileUZ) HYDROData_Profile::GetProfileUZ( const bool theIsCreate ) const
336 Handle(HYDROData_ProfileUZ) aProfileUZ;
338 TDF_Label aLabel = myLab.FindChild( DataTag_ChildProfileUZ, theIsCreate );
339 if ( aLabel.IsNull() )
342 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( HYDROData_Iterator::Object( aLabel ) );
343 if ( aProfileUZ.IsNull() && theIsCreate )
345 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast(
346 HYDROData_Iterator::CreateObject( aLabel, KIND_PROFILEUZ ) );
352 int HYDROData_Profile::NbPoints() const
354 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
355 return aProfileUZ.IsNull() ? 0 : aProfileUZ->NbPoints();
358 void HYDROData_Profile::RemovePoints()
360 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
361 if ( !aProfileUZ.IsNull() )
363 aProfileUZ->RemoveSections();
368 void HYDROData_Profile::SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints )
372 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
373 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
375 const HYDROData_ProfileUZ::Point& aPoint = thePoints.Value( i );
376 aProfileUZ->AddPoint( 0, aPoint );
382 HYDROData_ProfileUZ::PointsList HYDROData_Profile::GetParametricPoints() const
384 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
385 return aProfileUZ.IsNull() ? HYDROData_ProfileUZ::PointsList() : aProfileUZ->GetPoints();
388 void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints, bool IsConvertFromGlobal )
391 if ( thePoints.Length() < 2 )
394 gp_XY aFirstPoint, aLastPoint;
396 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
397 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
398 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
400 ProfilePoint aPoint = thePoints.Value( i );
401 if( IsConvertFromGlobal )
402 aDoc->Transform( aPoint, true );
404 gp_XY aPointXY( aPoint.X(), aPoint.Y() );
407 aFirstPoint = aPointXY;
409 aLastPoint = aPointXY;
411 double aDistance = gp_Pnt2d( aFirstPoint ).Distance( aPointXY );
413 HYDROData_ProfileUZ::Point aParPoint( aDistance, aPoint.Z() );
414 aProfileUZ->AddPoint( 0, aParPoint );
417 SetLeftPoint( aFirstPoint, false );//already converted to local CS
418 SetRightPoint( aLastPoint, false );
421 HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints
422 ( bool IsConvertToGlobal, bool CanUseDefaultLeftRight ) const
424 ProfilePoints aResPoints;
426 gp_XY aFirstPoint, aLastPoint;
427 if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) ||
428 !GetRightPoint( aLastPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) )
431 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
432 if ( aParametricPoints.Length() < 2 )
435 const HYDROData_ProfileUZ::Point& aFirstParPoint = aParametricPoints.First();
436 const HYDROData_ProfileUZ::Point& aLastParPoint = aParametricPoints.Last();
438 double aFullLength = aLastPoint.X() - aFirstPoint.X();
439 double aParFullLength = aLastParPoint.X() - aFirstParPoint.X();
441 // Add first point as is
442 aResPoints.Append( ProfilePoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
444 // Compute all other points
445 for ( int i = 2, n = aParametricPoints.Length(); i < n ; ++i )
447 const HYDROData_ProfileUZ::Point& aParPoint = aParametricPoints.Value( i );
449 double aParPointDist = aParPoint.X() - aFirstParPoint.X();
450 double aRatio = aParPointDist / aParFullLength;
452 double aParX = aFirstPoint.X() * (1-aRatio) + aLastPoint.X() * aRatio;
453 double aParY = aFirstPoint.Y() * (1-aRatio) + aLastPoint.Y() * aRatio;
455 ProfilePoint aCompPoint( aParX, aParY, aParPoint.Y() );
456 aResPoints.Append( aCompPoint );
459 // Add last point as is
460 aResPoints.Append( ProfilePoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
465 void HYDROData_Profile::SetFilePath( const TCollection_AsciiString& theFilePath )
467 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
470 TCollection_AsciiString HYDROData_Profile::GetFilePath() const
472 TCollection_AsciiString aRes;
474 Handle(TDataStd_AsciiString) anAsciiStr;
475 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
476 aRes = anAsciiStr->Get();
481 int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
482 const TCollection_AsciiString& theFileName,
483 NCollection_Sequence<int>& theBadProfilesIds,
486 if ( theDoc.IsNull() || theFileName.IsEmpty() )
489 OSD_File aFile( theFileName );
490 if ( !aFile.IsReadable() )
493 aFile.Open( OSD_ReadOnly, OSD_Protection() );
494 if ( !aFile.IsOpen() )
497 NCollection_Sequence<Handle(HYDROData_Profile)> aCreatedProfiles;
500 Handle(HYDROData_Profile) aNewProfile;
501 for ( ; !aFile.IsAtEnd(); ++aProfileId )
503 if ( aNewProfile.IsNull() )
504 aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
506 bool anIsRead = false;
507 if ( aNewProfile->ImportFromFile( aFile, isToProject, &anIsRead ) )
509 aCreatedProfiles.Append( aNewProfile );
510 aNewProfile.Nullify();
514 theBadProfilesIds.Append( aProfileId );
518 if ( !aNewProfile.IsNull() )
519 aNewProfile->Remove();
524 for ( int i = 1, n = aCreatedProfiles.Length(); i <= n ; ++i )
526 Handle(HYDROData_Profile) aProfile = aCreatedProfiles.Value( i );
528 QString aProfileName = HYDROData_Tool::GenerateObjectName( theDoc, "Profile" );
529 aProfile->SetName( aProfileName );
531 aProfile->SetFilePath( theFileName );
533 aProfile->SetBorderColor( aProfile->DefaultBorderColor() );
536 return aCreatedProfiles.Length();
539 bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
546 // Try to open the file
547 OSD_File aFile( theFileName );
548 if ( !aFile.IsReadable() )
551 aFile.Open( OSD_ReadOnly, OSD_Protection() );
552 if ( !aFile.IsOpen() )
555 bool aRes = ImportFromFile( aFile, isToProject, isNotEmpty );
563 SetFilePath( theFileName );
569 bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
576 if ( !theFile.IsOpen() )
581 bool anIsParametric = false;
582 bool anIsGeoref = false;
584 HYDROData_ProfileUZ::PointsList aPointsUZ;
585 ProfilePoints aPointsXYZ;
587 double aPrevVal = -DBL_MAX;
588 while ( !theFile.IsAtEnd() )
590 Standard_Integer aNbRead = 0;
591 TCollection_AsciiString aLine;
592 theFile.ReadLine( aLine, 1024, aNbRead );
594 aLine.LeftAdjust(); aLine.RightAdjust();
595 if ( aLine.IsEmpty() )
597 if ( !anIsParametric && !anIsGeoref )
598 continue; // Definition is not started yet
600 break; // Next profile started
603 // Set flag of read status to true
607 TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
608 TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
609 TCollection_AsciiString aValZ = aLine.Token( " \t", 3 );
611 if ( aValX.IsEmpty() || !aValX.IsRealValue() ||
612 aValY.IsEmpty() || !aValY.IsRealValue() )
618 if ( !anIsParametric && !anIsGeoref )
620 anIsParametric = aValZ.IsEmpty();
621 anIsGeoref = !aValZ.IsEmpty();
624 double aCoordX = aValX.RealValue();
625 double aCoordY = aValY.RealValue();
627 if ( HYDROData_Tool::IsNan( aCoordX ) || HYDROData_Tool::IsInf( aCoordX ) ||
628 HYDROData_Tool::IsNan( aCoordY ) || HYDROData_Tool::IsInf( aCoordY ) )
631 if ( anIsParametric )
633 if ( aCoordX < aPrevVal )
635 // Move back readed line
636 theFile.Seek( -( aNbRead + 1 ), OSD_FromHere );
640 HYDROData_ProfileUZ::Point aPoint( aCoordX, aCoordY );
641 aPointsUZ.Append( aPoint );
647 if ( aValZ.IsEmpty() || !aValZ.IsRealValue() )
653 double aCoordZ = aValZ.RealValue();
654 if ( HYDROData_Tool::IsNan( aCoordZ ) || HYDROData_Tool::IsInf( aCoordZ ) )
657 ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
658 aPointsXYZ.Append( aPoint );
662 aRes = aRes && ( anIsParametric && !aPointsUZ.IsEmpty() ||
663 anIsGeoref && !aPointsXYZ.IsEmpty() );
666 // Update profile points
667 if ( anIsParametric )
669 SetParametricPoints( aPointsUZ );
671 else if ( anIsGeoref )
674 ProjectProfilePoints( aPointsXYZ );
675 SetProfilePoints( aPointsXYZ, true );
684 void HYDROData_Profile::UpdateLocalCS( double theDx, double theDy )
686 gp_XY aDelta( theDx, theDy );
689 GetLeftPoint( aPnt, false );
691 SetLeftPoint( aPnt, false );
693 GetRightPoint( aPnt, false );
695 SetRightPoint( aPnt, false );
698 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint(bool IsConvertToGlobal) const
700 ProfilePoint aBottom;
702 // Get parametric points
703 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
704 if ( aParametricPoints.Length() < 1 ) {
708 // Calculate midvalue for U parameter
709 Standard_Real anUMidValue = aParametricPoints.First().X();
710 Standard_Real anUMinValue = anUMidValue;
711 Standard_Real anUMaxValue = anUMidValue;
713 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
714 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
715 Standard_Real anU = aParPoint.X();
717 if ( anU < anUMinValue ) {
719 } else if ( anU > anUMaxValue ) {
724 anUMidValue = ( anUMinValue + anUMaxValue ) / 2;
726 // Find index of the parametric point with minimal Z value
727 int aBottomIndex = 1;
728 HYDROData_IPolyline::Point aParBottom = aParametricPoints.First();
730 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
731 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
732 if ( aParPoint.Y() < aParBottom.Y() ) {
734 aParBottom = aParPoint;
735 } else if ( aParPoint.Y() == aParBottom.Y() ) {
736 // Check which point is neares to the U = 0.5
737 if ( fabs( aParPoint.X() - anUMidValue ) < fabs( aParBottom.X() - anUMidValue ) ) {
739 aParBottom = aParPoint;
744 // Find the corresponding profile point
745 ProfilePoints aProfilePoints = GetProfilePoints( IsConvertToGlobal );
746 if ( aBottomIndex >= 1 && aBottomIndex <= aProfilePoints.Length() ) {
747 aBottom = aProfilePoints.Value( aBottomIndex );
753 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetMiddlePoint( bool CanUseDefault ) const
755 ProfilePoint aMiddlePoint;
757 gp_XY aLeftPnt, aRightPnt;
758 if ( GetLeftPoint( aLeftPnt, true, CanUseDefault ) && GetRightPoint( aRightPnt, true, CanUseDefault ) ) {
759 gp_XYZ aPnt1( aLeftPnt.X(), aLeftPnt.Y(), 0. );
760 gp_XYZ aPnt2( aRightPnt.X(), aRightPnt.Y(), 0. );
761 gp_Pnt aMiddlePoint2d( 0.5 * ( aPnt1 + aPnt2 ) );
763 gp_Lin aMidLin( aMiddlePoint2d, gp::DZ() );
764 TopoDS_Edge aMidEdge = BRepLib_MakeEdge( aMidLin );
766 TopoDS_Iterator anIt( TopoDS::Wire( GetShape3D() ) );
767 for ( ; anIt.More(); anIt.Next()) {
768 const TopoDS_Edge& anEdge = TopoDS::Edge( anIt.Value() );
771 Standard_Real aStart, anEnd;
772 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
773 gp_Pnt aMiddlePointOnCurve = aCurve->Value( ( aStart + anEnd ) / 2 );
776 BRepExtrema_ExtCC ExtremaEE( aMidEdge, anEdge);
777 if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) {
778 for ( Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++ ) {
779 if ( ExtremaEE.SquareDistance(i) <= Precision::Confusion() ) {
780 aMiddlePoint = ExtremaEE.PointOnE1(i).XYZ();
791 void HYDROData_Profile::ProjectProfilePoints( ProfilePoints& thePoints )
793 int low = thePoints.Lower(), up = thePoints.Upper();
794 gp_Pnt aFirst = thePoints.Value( low );
795 gp_Pnt aLast = thePoints.Value( up );
796 gp_Vec d( aFirst, aLast );
797 gp_Vec n( d.Y(), -d.X(), 0 );
799 Handle(Geom_Plane) aPlane = new Geom_Plane( aFirst, gp_Dir( n ) );
800 for( int i=low; i<=up; i++ )
802 gp_XYZ p = thePoints.Value( i );
803 gp_Pnt pp = GeomAPI_ProjectPointOnSurf( p, aPlane );
804 thePoints.SetValue( i, pp.XYZ() );