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_HANDLE(HYDROData_Profile, HYDROData_Object)
54 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object)
56 HYDROData_Profile::HYDROData_Profile()
57 : HYDROData_Object( Geom_3d )
61 HYDROData_Profile::~HYDROData_Profile()
65 QStringList HYDROData_Profile::DumpToPython( const QString& thePyScriptPath,
66 MapOfTreatedObjects& theTreatedObjects ) const
68 QStringList aResList = dumpObjectCreation( theTreatedObjects );
69 QString aProfileName = GetObjPyName();
71 //TCollection_AsciiString aFilePath = GetFilePath();
72 //if ( !aFilePath.IsEmpty() )
74 // aResList << QString( "%1.ImportFromFile( \"%2\" )" )
75 // .arg( aName ).arg( aFilePath.ToCString() );
78 bool anIsValidProfile = IsValid();
80 QStringList aPntsDefinition;
81 QString aPntsListName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "profile_points" );
83 QString aGap = QString().fill( ' ', aPntsListName.length() + 5 );
84 if ( anIsValidProfile )
86 HYDROData_Profile::ProfilePoints aPointsList = GetProfilePoints( true );
87 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
89 const ProfilePoint& aPoint = aPointsList.Value( k );
90 aPntsDefinition << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" )
91 .arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
92 .arg( ( k < aNbPoints ? "," : "" ) );
97 HYDROData_IPolyline::PointsList aPointsList = GetParametricPoints();
98 for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
100 const HYDROData_IPolyline::Point& aPoint = aPointsList.Value( k );
101 aPntsDefinition << QString( aGap + "gp_XY( %1, %2 )%3" )
102 .arg( aPoint.X() ).arg( aPoint.Y() )
103 .arg( ( k < aNbPoints ? "," : "" ) );
107 if ( !aPntsDefinition.isEmpty() )
109 QString& aFirstStr = aPntsDefinition.first();
110 aFirstStr = aFirstStr.trimmed();
111 aFirstStr.prepend( QString( "%1 = [ " ).arg( aPntsListName ) );
113 aPntsDefinition.last().append( " ];" );
115 aResList << aPntsDefinition;
117 aResList << QString( "%1.%3( %2 )" )
118 .arg( aProfileName ).arg( aPntsListName )
119 .arg( anIsValidProfile ? "SetProfilePoints" : "SetParametricPoints" );
121 aResList << QString( "" );
124 // Set a polyline type if it is not default
125 Handle(HYDROData_ProfileUZ) aPrf = GetProfileUZ( false );
126 if ( !aPrf.IsNull() )
128 HYDROData_IPolyline::SectionType aSecType = aPrf->GetSectionType( 0 );
129 if ( aSecType != HYDROData_IPolyline::SECTION_POLYLINE )
131 aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 )" )
132 .arg( aProfileName ).arg( "HYDROData_IPolyline.SECTION_SPLINE" );
133 aResList << QString( "" );
137 aResList << QString( "%1.Update()" ).arg( aProfileName );
138 aResList << QString( "" );
143 TopoDS_Shape HYDROData_Profile::GetTopShape() const
147 gp_XY aFirstPoint, aLastPoint;
148 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
151 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 );
152 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 );
154 BRepBuilderAPI_MakeEdge aMakeEdge( aPnt1, aPnt2 );
155 TopoDS_Edge anEdge = aMakeEdge;
157 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
163 TopoDS_Shape HYDROData_Profile::GetShape3D() const
165 TopoDS_Shape aShape = HYDROData_Object::GetShape3D();
166 if( aShape.IsNull() )
167 aShape = CreateProfileWire( true );
171 TopoDS_Shape HYDROData_Profile::CreateProfileWire( bool canUseDefaultPoints ) const
174 Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
175 if ( !aProfile.IsNull() )
177 ProfilePoints aProfilePoints = GetProfilePoints( false, canUseDefaultPoints );
178 HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
180 aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
185 void HYDROData_Profile::Update()
187 HYDROData_Object::Update();
189 TopoDS_Shape aShape = CreateProfileWire( true );
190 SetShape3D( aShape );
193 QColor HYDROData_Profile::DefaultFillingColor() const
195 return QColor( Qt::transparent );
198 QColor HYDROData_Profile::DefaultBorderColor() const
200 return QColor( Qt::black );
203 bool HYDROData_Profile::IsValid() const
205 gp_XY aFirstPoint, aLastPoint;
206 if ( !GetLeftPoint( aFirstPoint, false ) || !GetRightPoint( aLastPoint, false ) )
209 int aNbPoints = NbPoints();
210 return aNbPoints > 1;
213 void HYDROData_Profile::SetLeftPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
215 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint );
216 if ( aLabel.IsNull() )
219 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
220 gp_XY aLPoint = theGPoint;
221 if( IsConvertFromGlobal )
222 aDoc->Transform( aLPoint, true );
224 Handle(TDataStd_RealArray) anArray;
225 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
226 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
228 anArray->SetValue( 0, aLPoint.X() );
229 anArray->SetValue( 1, aLPoint.Y() );
234 bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal,
235 bool CanUseDefault ) const
237 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
238 if ( aParametricPoints.Length() < 2 )
241 thePoint = GetParametricPoints().First();
243 //thePoint.SetX( 0 );
244 thePoint.SetY( 0 ); //default left point of not-georeferenced profile
245 TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint, false );
246 if ( aLabel.IsNull() )
248 return CanUseDefault;
251 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
252 Handle(TDataStd_RealArray) anArray;
253 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
255 return CanUseDefault;
258 thePoint.SetX( anArray->Value( 0 ) );
259 thePoint.SetY( anArray->Value( 1 ) );
261 if( IsConvertToGlobal )
262 aDoc->Transform( thePoint, false );
267 void HYDROData_Profile::SetRightPoint( const gp_XY& theGPoint, bool IsConvertFromGlobal )
269 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint );
271 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
272 gp_XY aLPoint = theGPoint;
273 if( IsConvertFromGlobal )
274 aDoc->Transform( aLPoint, true );
276 Handle(TDataStd_RealArray) anArray;
277 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
278 anArray = TDataStd_RealArray::Set( aLabel, 0, 1 );
280 anArray->SetValue( 0, aLPoint.X() );
281 anArray->SetValue( 1, aLPoint.Y() );
286 bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
287 bool CanUseDefault ) const
289 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
290 if ( aParametricPoints.Length() < 2 )
293 thePoint = GetParametricPoints().Last();
296 TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
297 if ( aLabel.IsNull() )
299 return CanUseDefault;
302 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
303 Handle(TDataStd_RealArray) anArray;
304 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
306 return CanUseDefault;
309 thePoint.SetX( anArray->Value( 0 ) );
310 thePoint.SetY( anArray->Value( 1 ) );
312 if( IsConvertToGlobal )
313 aDoc->Transform( thePoint, false );
318 void HYDROData_Profile::Invalidate()
320 TDF_Label aFirstLabel = myLab.FindChild( DataTag_FirstPoint, false );
321 if ( !aFirstLabel.IsNull() )
322 aFirstLabel.ForgetAllAttributes();
324 TDF_Label aLastLabel = myLab.FindChild( DataTag_LastPoint, false );
325 if ( !aLastLabel.IsNull() )
326 aLastLabel.ForgetAllAttributes();
331 Handle(HYDROData_ProfileUZ) HYDROData_Profile::GetProfileUZ( const bool theIsCreate ) const
333 Handle(HYDROData_ProfileUZ) aProfileUZ;
335 TDF_Label aLabel = myLab.FindChild( DataTag_ChildProfileUZ, theIsCreate );
336 if ( aLabel.IsNull() )
339 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast( HYDROData_Iterator::Object( aLabel ) );
340 if ( aProfileUZ.IsNull() && theIsCreate )
342 aProfileUZ = Handle(HYDROData_ProfileUZ)::DownCast(
343 HYDROData_Iterator::CreateObject( aLabel, KIND_PROFILEUZ ) );
349 int HYDROData_Profile::NbPoints() const
351 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
352 return aProfileUZ.IsNull() ? 0 : aProfileUZ->NbPoints();
355 void HYDROData_Profile::RemovePoints()
357 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
358 if ( !aProfileUZ.IsNull() )
360 aProfileUZ->RemoveSections();
365 void HYDROData_Profile::SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints )
369 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
370 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
372 const HYDROData_ProfileUZ::Point& aPoint = thePoints.Value( i );
373 aProfileUZ->AddPoint( 0, aPoint );
379 HYDROData_ProfileUZ::PointsList HYDROData_Profile::GetParametricPoints() const
381 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ( false );
382 return aProfileUZ.IsNull() ? HYDROData_ProfileUZ::PointsList() : aProfileUZ->GetPoints();
385 void HYDROData_Profile::SetProfilePoints( const ProfilePoints& thePoints, bool IsConvertFromGlobal )
388 if ( thePoints.Length() < 2 )
391 gp_XY aFirstPoint, aLastPoint;
393 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( Label() );
394 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
395 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
397 ProfilePoint aPoint = thePoints.Value( i );
398 if( IsConvertFromGlobal )
399 aDoc->Transform( aPoint, true );
401 gp_XY aPointXY( aPoint.X(), aPoint.Y() );
404 aFirstPoint = aPointXY;
406 aLastPoint = aPointXY;
408 double aDistance = gp_Pnt2d( aFirstPoint ).Distance( aPointXY );
410 HYDROData_ProfileUZ::Point aParPoint( aDistance, aPoint.Z() );
411 aProfileUZ->AddPoint( 0, aParPoint );
414 SetLeftPoint( aFirstPoint, false );//already converted to local CS
415 SetRightPoint( aLastPoint, false );
418 HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints
419 ( bool IsConvertToGlobal, bool CanUseDefaultLeftRight ) const
421 ProfilePoints aResPoints;
423 gp_XY aFirstPoint, aLastPoint;
424 if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) ||
425 !GetRightPoint( aLastPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) )
428 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
429 if ( aParametricPoints.Length() < 2 )
432 const HYDROData_ProfileUZ::Point& aFirstParPoint = aParametricPoints.First();
433 const HYDROData_ProfileUZ::Point& aLastParPoint = aParametricPoints.Last();
435 double aFullLength = aLastPoint.X() - aFirstPoint.X();
436 double aParFullLength = aLastParPoint.X() - aFirstParPoint.X();
438 // Add first point as is
439 aResPoints.Append( ProfilePoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
441 // Compute all other points
442 for ( int i = 2, n = aParametricPoints.Length(); i < n ; ++i )
444 const HYDROData_ProfileUZ::Point& aParPoint = aParametricPoints.Value( i );
446 double aParPointDist = aParPoint.X() - aFirstParPoint.X();
447 double aRatio = aParPointDist / aParFullLength;
449 double aParX = aFirstPoint.X() * (1-aRatio) + aLastPoint.X() * aRatio;
450 double aParY = aFirstPoint.Y() * (1-aRatio) + aLastPoint.Y() * aRatio;
452 ProfilePoint aCompPoint( aParX, aParY, aParPoint.Y() );
453 aResPoints.Append( aCompPoint );
456 // Add last point as is
457 aResPoints.Append( ProfilePoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
462 void HYDROData_Profile::SetFilePath( const TCollection_AsciiString& theFilePath )
464 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
467 TCollection_AsciiString HYDROData_Profile::GetFilePath() const
469 TCollection_AsciiString aRes;
471 Handle(TDataStd_AsciiString) anAsciiStr;
472 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
473 aRes = anAsciiStr->Get();
478 int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
479 const TCollection_AsciiString& theFileName,
480 NCollection_Sequence<int>& theBadProfilesIds )
482 if ( theDoc.IsNull() || theFileName.IsEmpty() )
485 OSD_File aFile( theFileName );
486 if ( !aFile.IsReadable() )
489 aFile.Open( OSD_ReadOnly, OSD_Protection() );
490 if ( !aFile.IsOpen() )
493 NCollection_Sequence<Handle(HYDROData_Profile)> aCreatedProfiles;
496 Handle(HYDROData_Profile) aNewProfile;
497 for ( ; !aFile.IsAtEnd(); ++aProfileId )
499 if ( aNewProfile.IsNull() )
500 aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
502 bool anIsRead = false;
503 if ( aNewProfile->ImportFromFile( aFile, &anIsRead ) )
505 aCreatedProfiles.Append( aNewProfile );
506 aNewProfile.Nullify();
510 theBadProfilesIds.Append( aProfileId );
514 if ( !aNewProfile.IsNull() )
515 aNewProfile->Remove();
520 for ( int i = 1, n = aCreatedProfiles.Length(); i <= n ; ++i )
522 Handle(HYDROData_Profile) aProfile = aCreatedProfiles.Value( i );
524 QString aProfileName = HYDROData_Tool::GenerateObjectName( theDoc, "Profile" );
525 aProfile->SetName( aProfileName );
527 aProfile->SetFilePath( theFileName );
529 aProfile->SetBorderColor( aProfile->DefaultBorderColor() );
532 return aCreatedProfiles.Length();
535 bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
541 // Try to open the file
542 OSD_File aFile( theFileName );
543 if ( !aFile.IsReadable() )
546 aFile.Open( OSD_ReadOnly, OSD_Protection() );
547 if ( !aFile.IsOpen() )
550 bool aRes = ImportFromFile( aFile, theIsRead );
558 SetFilePath( theFileName );
564 bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
570 if ( !theFile.IsOpen() )
575 bool anIsParametric = false;
576 bool anIsGeoref = false;
578 HYDROData_ProfileUZ::PointsList aPointsUZ;
579 ProfilePoints aPointsXYZ;
581 double aPrevVal = -DBL_MAX;
582 while ( !theFile.IsAtEnd() )
584 Standard_Integer aNbRead = 0;
585 TCollection_AsciiString aLine;
586 theFile.ReadLine( aLine, 1024, aNbRead );
588 aLine.LeftAdjust(); aLine.RightAdjust();
589 if ( aLine.IsEmpty() )
591 if ( !anIsParametric && !anIsGeoref )
592 continue; // Definition is not started yet
594 break; // Next profile started
597 // Set flag of read status to true
601 TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
602 TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
603 TCollection_AsciiString aValZ = aLine.Token( " \t", 3 );
605 if ( aValX.IsEmpty() || !aValX.IsRealValue() ||
606 aValY.IsEmpty() || !aValY.IsRealValue() )
612 if ( !anIsParametric && !anIsGeoref )
614 anIsParametric = aValZ.IsEmpty();
615 anIsGeoref = !aValZ.IsEmpty();
618 double aCoordX = aValX.RealValue();
619 double aCoordY = aValY.RealValue();
621 if ( HYDROData_Tool::IsNan( aCoordX ) || HYDROData_Tool::IsInf( aCoordX ) ||
622 HYDROData_Tool::IsNan( aCoordY ) || HYDROData_Tool::IsInf( aCoordY ) )
625 if ( anIsParametric )
627 if ( aCoordX < aPrevVal )
629 // Move back readed line
630 theFile.Seek( -( aNbRead + 1 ), OSD_FromHere );
634 HYDROData_ProfileUZ::Point aPoint( aCoordX, aCoordY );
635 aPointsUZ.Append( aPoint );
641 if ( aValZ.IsEmpty() || !aValZ.IsRealValue() )
647 double aCoordZ = aValZ.RealValue();
648 if ( HYDROData_Tool::IsNan( aCoordZ ) || HYDROData_Tool::IsInf( aCoordZ ) )
651 ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
652 aPointsXYZ.Append( aPoint );
656 aRes = aRes && ( anIsParametric && !aPointsUZ.IsEmpty() ||
657 anIsGeoref && !aPointsXYZ.IsEmpty() );
660 // Update profile points
661 if ( anIsParametric )
663 SetParametricPoints( aPointsUZ );
665 else if ( anIsGeoref )
667 SetProfilePoints( aPointsXYZ, true );
676 void HYDROData_Profile::UpdateLocalCS( double theDx, double theDy )
678 gp_XY aDelta( theDx, theDy );
681 GetLeftPoint( aPnt, false );
683 SetLeftPoint( aPnt, false );
685 GetRightPoint( aPnt, false );
687 SetRightPoint( aPnt, false );
690 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const
692 ProfilePoint aBottom;
694 // Get parametric points
695 HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
696 if ( aParametricPoints.Length() < 1 ) {
700 // Calculate midvalue for U parameter
701 Standard_Real anUMidValue = aParametricPoints.First().X();
702 Standard_Real anUMinValue = anUMidValue;
703 Standard_Real anUMaxValue = anUMidValue;
705 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
706 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
707 Standard_Real anU = aParPoint.X();
709 if ( anU < anUMinValue ) {
711 } else if ( anU > anUMaxValue ) {
716 anUMidValue = ( anUMinValue + anUMaxValue ) / 2;
718 // Find index of the parametric point with minimal Z value
719 int aBottomIndex = 1;
720 HYDROData_IPolyline::Point aParBottom = aParametricPoints.First();
722 for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) {
723 const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i );
724 if ( aParPoint.Y() < aParBottom.Y() ) {
726 aParBottom = aParPoint;
727 } else if ( aParPoint.Y() == aParBottom.Y() ) {
728 // Check which point is neares to the U = 0.5
729 if ( fabs( aParPoint.X() - anUMidValue ) < fabs( aParBottom.X() - anUMidValue ) ) {
731 aParBottom = aParPoint;
736 // Find the corresponding profile point
737 ProfilePoints aProfilePoints = GetProfilePoints( false );
738 if ( aBottomIndex >= 1 && aBottomIndex <= aProfilePoints.Length() ) {
739 aBottom = aProfilePoints.Value( aBottomIndex );
745 HYDROData_Profile::ProfilePoint HYDROData_Profile::GetMiddlePoint( bool CanUseDefault ) const
747 ProfilePoint aMiddlePoint;
749 gp_XY aLeftPnt, aRightPnt;
750 if ( GetLeftPoint( aLeftPnt, true, CanUseDefault ) && GetRightPoint( aRightPnt, true, CanUseDefault ) ) {
751 gp_XYZ aPnt1( aLeftPnt.X(), aLeftPnt.Y(), 0. );
752 gp_XYZ aPnt2( aRightPnt.X(), aRightPnt.Y(), 0. );
753 gp_Pnt aMiddlePoint2d( 0.5 * ( aPnt1 + aPnt2 ) );
755 gp_Lin aMidLin( aMiddlePoint2d, gp::DZ() );
756 TopoDS_Edge aMidEdge = BRepLib_MakeEdge( aMidLin );
758 TopoDS_Iterator anIt( TopoDS::Wire( GetShape3D() ) );
759 for ( ; anIt.More(); anIt.Next()) {
760 const TopoDS_Edge& anEdge = TopoDS::Edge( anIt.Value() );
763 Standard_Real aStart, anEnd;
764 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
765 gp_Pnt aMiddlePointOnCurve = aCurve->Value( ( aStart + anEnd ) / 2 );
768 BRepExtrema_ExtCC ExtremaEE( aMidEdge, anEdge);
769 if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) {
770 for ( Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++ ) {
771 if ( ExtremaEE.SquareDistance(i) <= Precision::Confusion() ) {
772 aMiddlePoint = ExtremaEE.PointOnE1(i).XYZ();