//
#include <HYDROData_PolylineOperator.h>
+#include <BRepBuilderAPI_MakeEdge2d.hxx>
+#include <TopoDS_Edge.hxx>
+
+template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
+{
+ int aSize = theList.size();
+ int aNewSize = aSize + theList2.size();
+
+ if( aSize==aNewSize )
+ return;
+
+ theList.resize( aNewSize );
+ for( int i=aSize, j=0; i<aNewSize; i++, j++ )
+ theList[i] = theList2[j];
+}
+
bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
const gp_Pnt2d& thePoint ) const
{
- //TODO
- return true;
+ std::vector<gp_Pnt2d> aPointsList( 1 );
+ aPointsList[0] = thePoint;
+ std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
+ bool isOK = true;
+ for( int i=0, n=aCurves.size(); i<n; i++ )
+ {
+ std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
+ bool isLocalOK = CreatePolylines( aCurvesList );
+ isOK = isOK && isLocalOK;
+ }
+ return isOK;
}
bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
- const Handle( HYDROData_PolylineXY )& theTool ) const
+ const Handle( HYDROData_PolylineXY )& theTool ) const
{
- //TODO
- return true;
+ std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
+ std::vector<Handle( Geom2d_Curve )> aToolCurves = GetCurves( theTool );
+ bool isOK = true;
+ for( int i=0, n=aCurves.size(); i<n; i++ )
+ for( int j=0, m=aToolCurves.size(); j<m; j++ )
+ {
+ std::vector<gp_Pnt2d> aPointsList = Intersection( aCurves[i], aToolCurves[j] );
+ std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
+ bool isLocalOK = CreatePolylines( aCurvesList );
+ isOK = isOK && isLocalOK;
+ }
+ return isOK;
}
bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePolylines )
+{
+ int f = thePolylines.Lower(), l = thePolylines.Upper();
+ bool isOK = true;
+ std::vector<Handle( Geom2d_Curve )> anAllCurves;
+ for( int i=f; i<=l; i++ )
+ {
+ Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) );
+ std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( aPolyline );
+ append( anAllCurves, aCurves );
+ }
+
+ for( int i=0, n=anAllCurves.size(); i<n; i++ )
+ {
+ std::vector<gp_Pnt2d> aCompletePointsList;
+ for( int j=0; j<n; j++ )
+ {
+ if( i==j )
+ continue;
+ std::vector<gp_Pnt2d> aPointsList = Intersection( anAllCurves[i], anAllCurves[j] );
+ append( aCompletePointsList, aPointsList );
+ }
+ std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( anAllCurves[i], aCompletePointsList );
+ bool isLocalOK = CreatePolylines( aCurvesList );
+ isOK = isOK && isLocalOK;
+ }
+ return isOK;
+}
+
+bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines )
{
//TODO
return true;
}
-bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines )
+std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline )
{
+ std::vector<Handle( Geom2d_Curve )> aResult;
//TODO
+ return aResult;
+}
+
+std::vector<gp_Pnt2d> HYDROData_PolylineOperator::Intersection( const Handle( Geom2d_Curve )& theCurve,
+ const Handle( Geom2d_Curve )& theTool )
+{
+ std::vector<gp_Pnt2d> aResult;
+ //TODO
+ return aResult;
+}
+
+std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::Split( const Handle( Geom2d_Curve )& theCurve,
+ const std::vector<gp_Pnt2d>& thePoints )
+{
+ std::vector<Handle( Geom2d_Curve )> aResult;
+ //TODO
+ return aResult;
+}
+
+bool HYDROData_PolylineOperator::CreatePolylines( const std::vector<Handle( Geom2d_Curve )>& theCurves )
+{
+ int n = theCurves.size();
+ for( int i=0; i<n; i++ )
+ {
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge2d( theCurves[i] ).Edge();
+ //TODO
+ }
return true;
}
#define HYDROData_PolylineOperator_HeaderFile
#include <HYDROData_PolylineXY.h>
-
-class gp_Pnt2d;
+#include <Geom2d_Curve.hxx>
+#include <gp_Pnt2d.hxx>
+#include <vector>
class HYDROData_PolylineOperator
{
const Handle( HYDROData_PolylineXY )& theTool ) const;
HYDRODATA_EXPORT bool Split( const HYDROData_SequenceOfObjects& thePolylines );
HYDRODATA_EXPORT bool Merge( const HYDROData_SequenceOfObjects& thePolylines );
+
+ static HYDRODATA_EXPORT std::vector<Handle( Geom2d_Curve )> GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline );
+
+ static HYDRODATA_EXPORT std::vector<gp_Pnt2d> Intersection( const Handle( Geom2d_Curve )& theCurve,
+ const Handle( Geom2d_Curve )& theTool );
+
+ static HYDRODATA_EXPORT std::vector<Handle( Geom2d_Curve )> Split( const Handle( Geom2d_Curve )& theCurve,
+ const std::vector<gp_Pnt2d>& thePoints );
+
+ static HYDRODATA_EXPORT bool CreatePolylines( const std::vector<Handle( Geom2d_Curve )>& theCurves );
};
#endif