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 <TDataStd_AsciiString.hxx>
40 #include <TDataStd_RealArray.hxx>
43 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Wire.hxx>
45 #include <TopoDS_Iterator.hxx>
47 #include <OSD_File.hxx>
48 #include <OSD_Protection.hxx>
51 #include <QStringList>
53 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object)
55 HYDROData_Profile::HYDROData_Profile()
56 : HYDROData_Object( Geom_3d )
60 HYDROData_Profile::~HYDROData_Profile()
64 QStringList HYDROData_Profile::DumpToPython( const QString& thePyScriptPath,
65 MapOfTreatedObjects& theTreatedObjects ) const
67 QStringList aResList = dumpObjectCreation( theTreatedObjects );
68 QString aProfileName = GetObjPyName();
70 //TCollection_AsciiString aFilePath = GetFilePath();
71 //if ( !aFilePath.IsEmpty() )
73 // aResList << QString( "%1.ImportFromFile( \"%2\" )" )
74 // .arg( aName ).arg( aFilePath.ToCString() );
77 bool anIsValidProfile = IsValid();
79 QStringList aPntsDefinition;
80 QString aPntsListName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "profile_points" );
82 QString aGap = QString().fill( ' ', aPntsListName.length() + 5 );
83 if ( anIsValidProfile )
85 HYDROData_Profile::ProfilePoints aPointsList = GetProfilePoints( true );
86 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
88 const ProfilePoint& aPoint = aPointsList.Value( k );
89 aPntsDefinition << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" )
90 .arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
91 .arg( ( k < aNbPoints ? "," : "" ) );
96 HYDROData_IPolyline::PointsList aPointsList = GetParametricPoints();
97 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
99 const HYDROData_IPolyline::Point& aPoint = aPointsList.Value( k );
100 aPntsDefinition << QString( aGap + "gp_XY( %1, %2 )%3" )
101 .arg( aPoint.X() ).arg( aPoint.Y() )
102 .arg( ( k < aNbPoints ? "," : "" ) );
106 if ( !aPntsDefinition.isEmpty() )
108 QString& aFirstStr = aPntsDefinition.first();
109 aFirstStr = aFirstStr.trimmed();
110 aFirstStr.prepend( QString( "%1 = [ " ).arg( aPntsListName ) );
112 aPntsDefinition.last().append( " ];" );
114 aResList << aPntsDefinition;
116 aResList << QString( "%1.%3( %2 )" )
117 .arg( aProfileName ).arg( aPntsListName )
118 .arg( anIsValidProfile ? "SetProfilePoints" : "SetParametricPoints" );
120 aResList << QString( "" );
123 // Set a polyline type if it is not default
124 Handle(HYDROData_ProfileUZ) aPrf = GetProfileUZ( false );
125 if ( !aPrf.IsNull() )
127 HYDROData_IPolyline::SectionType aSecType = aPrf->GetSectionType( 0 );
128 if ( aSecType != HYDROData_IPolyline::SECTION_POLYLINE )
130 aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 )" )
131 .arg( aProfileName ).arg( "HYDROData_IPolyline.SECTION_SPLINE" );
132 aResList << QString( "" );
136 aResList << QString( "%1.Update()" ).arg( aProfileName );
137 aResList << QString( "" );
142 TopoDS_Shape HYDROData_Profile::GetTopShape() const
146 gp_XY aFirstPoint, aLastPoint;
147 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
150 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 );
151 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 );
153 BRepBuilderAPI_MakeEdge aMakeEdge( aPnt1, aPnt2 );
154 TopoDS_Edge anEdge = aMakeEdge;
156 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
162 TopoDS_Shape HYDROData_Profile::GetShape3D() const
164 TopoDS_Shape aShape = HYDROData_Object::GetShape3D();
165 if( aShape.IsNull() )
166 aShape = CreateProfileWire( true );
170 TopoDS_Shape HYDROData_Profile::CreateProfileWire( bool canUseDefaultPoints ) const
173 Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
174 if ( !aProfile.IsNull() )
176 ProfilePoints aProfilePoints = GetProfilePoints( false, canUseDefaultPoints );
177 HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
179 aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
184 void HYDROData_Profile::Update()
186 HYDROData_Object::Update();
188 TopoDS_Shape aShape = CreateProfileWire( true );
189 SetShape3D( aShape );
192 QColor HYDROData_Profile::DefaultFillingColor() const
194 return QColor( Qt::transparent );
197 QColor HYDROData_Profile::DefaultBorderColor() const
199 return QColor( Qt::black );
202 bool HYDROData_Profile::IsValid() const
204 gp_XY aFirstPoint, aLastPoint;
205 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
208 int aNbPoints = NbPoints();
209 return aNbPoints > 1;
212 void HYDROData_Profile::SetLeftPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
214 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint );
215 if ( aLabel.IsNull() )
218 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
219 gp_XY aLPoint = theGPoint;
220 if( IsConvertFromGlobal )
221 aDoc->Transform( aLPoint, true );
223 Handle(TDataStd_RealArray) anArray;
224 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
225 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
227 anArray->SetValue( 0, aLPoint.X() );
228 anArray->SetValue( 1, aLPoint.Y() );
233 bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal,
234 bool CanUseDefault ) const
236 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
237 if ( aParametricPoints.Length() < 2 )
240 thePoint = GetParametricPoints().First();
242 //thePoint.SetX( 0 );
243 thePoint.SetY( 0 ); //default left point of not-georeferenced profile
244 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint, false );
245 if ( aLabel.IsNull() )
247 return CanUseDefault;
250 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
251 Handle(TDataStd_RealArray) anArray;
252 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
254 return CanUseDefault;
257 thePoint.SetX( anArray->Value( 0 ) );
258 thePoint.SetY( anArray->Value( 1 ) );
260 if( IsConvertToGlobal )
261 aDoc->Transform( thePoint, false );
266 void HYDROData_Profile::SetRightPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
268 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint );
270 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
271 gp_XY aLPoint = theGPoint;
272 if( IsConvertFromGlobal )
273 aDoc->Transform( aLPoint, true );
275 Handle(TDataStd_RealArray) anArray;
276 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
277 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
279 anArray->SetValue( 0, aLPoint.X() );
280 anArray->SetValue( 1, aLPoint.Y() );
285 bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
286 bool CanUseDefault ) const
288 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
289 if ( aParametricPoints.Length() < 2 )
292 thePoint = GetParametricPoints().Last();
295 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
296 if ( aLabel.IsNull() )
298 return CanUseDefault;
301 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
302 Handle(TDataStd_RealArray) anArray;
303 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
305 return CanUseDefault;
308 thePoint.SetX( anArray->Value( 0 ) );
309 thePoint.SetY( anArray->Value( 1 ) );
311 if( IsConvertToGlobal )
312 aDoc->Transform( thePoint, false );
317 void HYDROData_Profile::Invalidate()
319 TDF_Label aFirstLabel = myLab.FindChild( DataTag_FirstPoint, false );
320 if ( !aFirstLabel.IsNull() )
321 aFirstLabel.ForgetAllAttributes();
323 TDF_Label aLastLabel = myLab.FindChild( DataTag_LastPoint, false );
324 if ( !aLastLabel.IsNull() )
325 aLastLabel.ForgetAllAttributes();
330 Handle(HYDROData_ProfileUZ) HYDROData_Profile::GetProfileUZ( const bool theIsCreate ) const
332 Handle(HYDROData_ProfileUZ) aProfileUZ;
334 TDF_Label aLabel = myLab.FindChild( DataTag_ChildProfileUZ, theIsCreate );
335 if ( aLabel.IsNull() )
338 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( HYDROData_Iterator::Object( aLabel ) );
339 if ( aProfileUZ.IsNull() && theIsCreate )
341 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast(
342 HYDROData_Iterator::CreateObject( aLabel, KIND_PROFILEUZ ) );
348 int HYDROData_Profile::NbPoints() const
350 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
351 return aProfileUZ.IsNull() ? 0 : aProfileUZ->NbPoints();
354 void HYDROData_Profile::RemovePoints()
356 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
357 if ( !aProfileUZ.IsNull() )
359 aProfileUZ->RemoveSections();
364 void HYDROData_Profile::SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints )
368 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
369 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
371 const HYDROData_ProfileUZ::Point& aPoint = thePoints.Value( i );
372 aProfileUZ->AddPoint( 0, aPoint );
378 HYDROData_ProfileUZ::PointsList HYDROData_Profile::GetParametricPoints() const
380 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
381 return aProfileUZ.IsNull() ? HYDROData_ProfileUZ::PointsList() : aProfileUZ->GetPoints();
384 void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints, bool IsConvertFromGlobal )
387 if ( thePoints.Length() < 2 )
390 gp_XY aFirstPoint, aLastPoint;
392 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
393 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
394 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
396 ProfilePoint aPoint = thePoints.Value( i );
397 if( IsConvertFromGlobal )
398 aDoc->Transform( aPoint, true );
400 gp_XY aPointXY( aPoint.X(), aPoint.Y() );
403 aFirstPoint = aPointXY;
405 aLastPoint = aPointXY;
407 double aDistance = gp_Pnt2d( aFirstPoint ).Distance( aPointXY );
409 HYDROData_ProfileUZ::Point aParPoint( aDistance, aPoint.Z() );
410 aProfileUZ->AddPoint( 0, aParPoint );
413 SetLeftPoint( aFirstPoint, false );//already converted to local CS
414 SetRightPoint( aLastPoint, false );
417 HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints
418 ( bool IsConvertToGlobal, bool CanUseDefaultLeftRight ) const
420 ProfilePoints aResPoints;
422 gp_XY aFirstPoint, aLastPoint;
423 if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) ||
424 !GetRightPoint( aLastPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) )
427 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
428 if ( aParametricPoints.Length() < 2 )
431 const HYDROData_ProfileUZ::Point& aFirstParPoint = aParametricPoints.First();
432 const HYDROData_ProfileUZ::Point& aLastParPoint = aParametricPoints.Last();
434 double aFullLength = aLastPoint.X() - aFirstPoint.X();
435 double aParFullLength = aLastParPoint.X() - aFirstParPoint.X();
437 // Add first point as is
438 aResPoints.Append( ProfilePoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
440 // Compute all other points
441 for ( int i = 2, n = aParametricPoints.Length(); i < n ; ++i )
443 const HYDROData_ProfileUZ::Point& aParPoint = aParametricPoints.Value( i );
445 double aParPointDist = aParPoint.X() - aFirstParPoint.X();
446 double aRatio = aParPointDist / aParFullLength;
448 double aParX = aFirstPoint.X() * (1-aRatio) + aLastPoint.X() * aRatio;
449 double aParY = aFirstPoint.Y() * (1-aRatio) + aLastPoint.Y() * aRatio;
451 ProfilePoint aCompPoint( aParX, aParY, aParPoint.Y() );
452 aResPoints.Append( aCompPoint );
455 // Add last point as is
456 aResPoints.Append( ProfilePoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
461 void HYDROData_Profile::SetFilePath( const TCollection_AsciiString& theFilePath )
463 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
466 TCollection_AsciiString HYDROData_Profile::GetFilePath() const
468 TCollection_AsciiString aRes;
470 Handle(TDataStd_AsciiString) anAsciiStr;
471 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
472 aRes = anAsciiStr->Get();
477 int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
478 const TCollection_AsciiString& theFileName,
479 NCollection_Sequence<int>& theBadProfilesIds )
481 if ( theDoc.IsNull() || theFileName.IsEmpty() )
484 OSD_File aFile( theFileName );
485 if ( !aFile.IsReadable() )
488 aFile.Open( OSD_ReadOnly, OSD_Protection() );
489 if ( !aFile.IsOpen() )
492 NCollection_Sequence<Handle(HYDROData_Profile)> aCreatedProfiles;
495 Handle(HYDROData_Profile) aNewProfile;
496 for ( ; !aFile.IsAtEnd(); ++aProfileId )
498 if ( aNewProfile.IsNull() )
499 aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
501 bool anIsRead = false;
502 if ( aNewProfile->ImportFromFile( aFile, &anIsRead ) )
504 aCreatedProfiles.Append( aNewProfile );
505 aNewProfile.Nullify();
509 theBadProfilesIds.Append( aProfileId );
513 if ( !aNewProfile.IsNull() )
514 aNewProfile->Remove();
519 for ( int i = 1, n = aCreatedProfiles.Length(); i <= n ; ++i )
521 Handle(HYDROData_Profile) aProfile = aCreatedProfiles.Value( i );
523 QString aProfileName = HYDROData_Tool::GenerateObjectName( theDoc, "Profile" );
524 aProfile->SetName( aProfileName );
526 aProfile->SetFilePath( theFileName );
528 aProfile->SetBorderColor( aProfile->DefaultBorderColor() );
531 return aCreatedProfiles.Length();
534 bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
540 // Try to open the file
541 OSD_File aFile( theFileName );
542 if ( !aFile.IsReadable() )
545 aFile.Open( OSD_ReadOnly, OSD_Protection() );
546 if ( !aFile.IsOpen() )
549 bool aRes = ImportFromFile( aFile, theIsRead );
557 SetFilePath( theFileName );
563 bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
569 if ( !theFile.IsOpen() )
574 bool anIsParametric = false;
575 bool anIsGeoref = false;
577 HYDROData_ProfileUZ::PointsList aPointsUZ;
578 ProfilePoints aPointsXYZ;
580 double aPrevVal = -DBL_MAX;
581 while ( !theFile.IsAtEnd() )
583 Standard_Integer aNbRead = 0;
584 TCollection_AsciiString aLine;
585 theFile.ReadLine( aLine, 1024, aNbRead );
587 aLine.LeftAdjust(); aLine.RightAdjust();
588 if ( aLine.IsEmpty() )
590 if ( !anIsParametric && !anIsGeoref )
591 continue; // Definition is not started yet
593 break; // Next profile started
596 // Set flag of read status to true
600 TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
601 TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
602 TCollection_AsciiString aValZ = aLine.Token( " \t", 3 );
604 if ( aValX.IsEmpty() || !aValX.IsRealValue() ||
605 aValY.IsEmpty() || !aValY.IsRealValue() )
611 if ( !anIsParametric && !anIsGeoref )
613 anIsParametric = aValZ.IsEmpty();
614 anIsGeoref = !aValZ.IsEmpty();
617 double aCoordX = aValX.RealValue();
618 double aCoordY = aValY.RealValue();
620 if ( HYDROData_Tool::IsNan( aCoordX ) || HYDROData_Tool::IsInf( aCoordX ) ||
621 HYDROData_Tool::IsNan( aCoordY ) || HYDROData_Tool::IsInf( aCoordY ) )
624 if ( anIsParametric )
626 if ( aCoordX < aPrevVal )
628 // Move back readed line
629 theFile.Seek( -( aNbRead + 1 ), OSD_FromHere );
633 HYDROData_ProfileUZ::Point aPoint( aCoordX, aCoordY );
634 aPointsUZ.Append( aPoint );
640 if ( aValZ.IsEmpty() || !aValZ.IsRealValue() )
646 double aCoordZ = aValZ.RealValue();
647 if ( HYDROData_Tool::IsNan( aCoordZ ) || HYDROData_Tool::IsInf( aCoordZ ) )
650 ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
651 aPointsXYZ.Append( aPoint );
655 aRes = aRes && ( anIsParametric && !aPointsUZ.IsEmpty() ||
656 anIsGeoref && !aPointsXYZ.IsEmpty() );
659 // Update profile points
660 if ( anIsParametric )
662 SetParametricPoints( aPointsUZ );
664 else if ( anIsGeoref )
666 SetProfilePoints( aPointsXYZ, true );
675 void HYDROData_Profile::UpdateLocalCS( double theDx, double theDy )
677 gp_XY aDelta( theDx, theDy );
680 GetLeftPoint( aPnt, false );
682 SetLeftPoint( aPnt, false );
684 GetRightPoint( aPnt, false );
686 SetRightPoint( aPnt, false );
689 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const
691 ProfilePoint aBottom;
693 // Get parametric points
694 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
695 if ( aParametricPoints.Length() < 1 ) {
699 // Calculate midvalue for U parameter
700 Standard_Real anUMidValue = aParametricPoints.First().X();
701 Standard_Real anUMinValue = anUMidValue;
702 Standard_Real anUMaxValue = anUMidValue;
704 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
705 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
706 Standard_Real anU = aParPoint.X();
708 if ( anU < anUMinValue ) {
710 } else if ( anU > anUMaxValue ) {
715 anUMidValue = ( anUMinValue + anUMaxValue ) / 2;
717 // Find index of the parametric point with minimal Z value
718 int aBottomIndex = 1;
719 HYDROData_IPolyline::Point aParBottom = aParametricPoints.First();
721 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
722 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
723 if ( aParPoint.Y() < aParBottom.Y() ) {
725 aParBottom = aParPoint;
726 } else if ( aParPoint.Y() == aParBottom.Y() ) {
727 // Check which point is neares to the U = 0.5
728 if ( fabs( aParPoint.X() - anUMidValue ) < fabs( aParBottom.X() - anUMidValue ) ) {
730 aParBottom = aParPoint;
735 // Find the corresponding profile point
736 ProfilePoints aProfilePoints = GetProfilePoints( false );
737 if ( aBottomIndex >= 1 && aBottomIndex <= aProfilePoints.Length() ) {
738 aBottom = aProfilePoints.Value( aBottomIndex );
744 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetMiddlePoint( bool CanUseDefault ) const
746 ProfilePoint aMiddlePoint;
748 gp_XY aLeftPnt, aRightPnt;
749 if ( GetLeftPoint( aLeftPnt, true, CanUseDefault ) && GetRightPoint( aRightPnt, true, CanUseDefault ) ) {
750 gp_XYZ aPnt1( aLeftPnt.X(), aLeftPnt.Y(), 0. );
751 gp_XYZ aPnt2( aRightPnt.X(), aRightPnt.Y(), 0. );
752 gp_Pnt aMiddlePoint2d( 0.5 * ( aPnt1 + aPnt2 ) );
754 gp_Lin aMidLin( aMiddlePoint2d, gp::DZ() );
755 TopoDS_Edge aMidEdge = BRepLib_MakeEdge( aMidLin );
757 TopoDS_Iterator anIt( TopoDS::Wire( GetShape3D() ) );
758 for ( ; anIt.More(); anIt.Next()) {
759 const TopoDS_Edge& anEdge = TopoDS::Edge( anIt.Value() );
762 Standard_Real aStart, anEnd;
763 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
764 gp_Pnt aMiddlePointOnCurve = aCurve->Value( ( aStart + anEnd ) / 2 );
767 BRepExtrema_ExtCC ExtremaEE( aMidEdge, anEdge);
768 if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) {
769 for ( Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++ ) {
770 if ( ExtremaEE.SquareDistance(i) <= Precision::Confusion() ) {
771 aMiddlePoint = ExtremaEE.PointOnE1(i).XYZ();