#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
+#include <BRepExtrema_ExtCC.hxx>
+
+#include <BRep_Tool.hxx>
+
+#include <gp_Lin.hxx>
#include <gp_XY.hxx>
#include <gp_XYZ.hxx>
#include <gp_Pnt2d.hxx>
#include <TDataStd_AsciiString.hxx>
#include <TDataStd_RealArray.hxx>
+#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
+#include <TopoDS_Iterator.hxx>
#include <OSD_File.hxx>
#include <OSD_Protection.hxx>
TopoDS_Shape HYDROData_Profile::GetShape3D() const
{
- return getShape3D();
+ TopoDS_Shape aShape = getShape3D();
+ if( aShape.IsNull() )
+ aShape = CreateProfileWire( true );
+ return aShape;
}
-void HYDROData_Profile::Update()
+TopoDS_Shape HYDROData_Profile::CreateProfileWire( bool canUseDefaultPoints ) const
{
- HYDROData_Object::Update();
-
TopoDS_Wire aWire;
Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
if ( !aProfile.IsNull() )
{
- ProfilePoints aProfilePoints = GetProfilePoints( false );
+ ProfilePoints aProfilePoints = GetProfilePoints( false, canUseDefaultPoints );
HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
}
- SetShape3D( aWire );
+ return aWire;
+}
+
+void HYDROData_Profile::Update()
+{
+ HYDROData_Object::Update();
+
+ TopoDS_Shape aShape = CreateProfileWire( false );
+ SetShape3D( aShape );
}
QColor HYDROData_Profile::DefaultFillingColor()
SetToUpdate( true );
}
-bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal ) const
+bool HYDROData_Profile::GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal,
+ bool CanUseDefault ) const
{
+ HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
+ if ( aParametricPoints.Length() < 2 )
+ return false;
+
+ thePoint = GetParametricPoints().First();
+
+ thePoint.SetX( 0 );
+ thePoint.SetY( 0 ); //default left point of not-georeferenced profile
TDF_Label aLabel = myLab.FindChild( DataTag_FirstPoint, false );
if ( aLabel.IsNull() )
- return false;
+ {
+ return CanUseDefault;
+ }
Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
Handle(TDataStd_RealArray) anArray;
if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
- return false;
+ {
+ return CanUseDefault;
+ }
thePoint.SetX( anArray->Value( 0 ) );
thePoint.SetY( anArray->Value( 1 ) );
SetToUpdate( true );
}
-bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal ) const
+bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
+ bool CanUseDefault ) const
{
+ HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
+ if ( aParametricPoints.Length() < 2 )
+ return false;
+
+ thePoint = GetParametricPoints().Last();
+
TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
if ( aLabel.IsNull() )
- return false;
+ {
+ return CanUseDefault;
+ }
Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
Handle(TDataStd_RealArray) anArray;
if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
- return false;
+ {
+ return CanUseDefault;
+ }
thePoint.SetX( anArray->Value( 0 ) );
thePoint.SetY( anArray->Value( 1 ) );
SetRightPoint( aLastPoint, false );
}
-HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints( bool IsConvertToGlobal ) const
+HYDROData_Profile::ProfilePoints HYDROData_Profile::GetProfilePoints
+ ( bool IsConvertToGlobal, bool CanUseDefaultLeftRight ) const
{
ProfilePoints aResPoints;
gp_XY aFirstPoint, aLastPoint;
- if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal ) ||
- !GetRightPoint( aLastPoint, IsConvertToGlobal ) )
+ if ( !GetLeftPoint( aFirstPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) ||
+ !GetRightPoint( aLastPoint, IsConvertToGlobal, CanUseDefaultLeftRight ) )
return aResPoints;
HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints();
return aBottom;
}
+ HYDROData_Profile::ProfilePoint HYDROData_Profile::GetMiddlePoint() const
+ {
+ ProfilePoint aMiddlePoint;
+
+ gp_XY aLeftPnt, aRightPnt;
+ if ( GetLeftPoint( aLeftPnt, false ) && GetRightPoint( aRightPnt, false ) ) {
+ gp_XYZ aPnt1( aLeftPnt.X(), aLeftPnt.Y(), 0. );
+ gp_XYZ aPnt2( aRightPnt.X(), aRightPnt.Y(), 0. );
+ gp_Pnt aMiddlePoint2d( 0.5 * ( aPnt1 + aPnt2 ) );
+
+ gp_Lin aMidLin( aMiddlePoint2d, gp::DZ() );
+ TopoDS_Edge aMidEdge = BRepLib_MakeEdge( aMidLin );
+
+ TopoDS_Iterator anIt( TopoDS::Wire( GetShape3D() ) );
+ for ( ; anIt.More(); anIt.Next()) {
+ const TopoDS_Edge& anEdge = TopoDS::Edge( anIt.Value() );
+
+ /*
+ Standard_Real aStart, anEnd;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
+ gp_Pnt aMiddlePointOnCurve = aCurve->Value( ( aStart + anEnd ) / 2 );
+ */
+
+ BRepExtrema_ExtCC ExtremaEE( aMidEdge, anEdge);
+ if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) {
+ for ( Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++ ) {
+ if ( ExtremaEE.SquareDistance(i) <= Precision::Confusion() ) {
+ aMiddlePoint = ExtremaEE.PointOnE1(i).XYZ();
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return aMiddlePoint;
+ }
\ No newline at end of file