Salome HOME
refs #639: the button to regenerate colors
[modules/hydro.git] / src / HYDROData / HYDROData_Profile.cxx
index 47418cdf8a0200b45a89d32b4df9534a93abd8b1..cef87e2f953fe4c6a4f926879e782b84c3ea5887 100755 (executable)
 #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>
@@ -294,7 +301,7 @@ bool HYDROData_Profile::GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal,
   if ( aParametricPoints.Length() < 2 )
     return false;
 
-  thePoint = GetParametricPoints().First();
+  thePoint = GetParametricPoints().Last();
 
   TDF_Label aLabel = myLab.FindChild( DataTag_LastPoint, false );
   if ( aLabel.IsNull() )
@@ -748,3 +755,40 @@ HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const
   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