]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
draft split/merge
authorasl <asl@opencascade.com>
Tue, 23 Jun 2015 14:38:17 +0000 (17:38 +0300)
committerasl <asl@opencascade.com>
Tue, 23 Jun 2015 14:38:17 +0000 (17:38 +0300)
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h

index 2256a906797912abc6ab66a03cbad5782f6d10c3..61c835f6123d389986b42d23e185f3cc4ea43910 100644 (file)
 //
 
 #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;
 }
index 5157be0ac74b7a00f3b778013337bf26a652376d..d3e49e3526e0a1d4e7d7bcb5c94ce79ac844e90a 100644 (file)
@@ -20,8 +20,9 @@
 #define HYDROData_PolylineOperator_HeaderFile
 
 #include <HYDROData_PolylineXY.h>
-
-class gp_Pnt2d;
+#include <Geom2d_Curve.hxx>
+#include <gp_Pnt2d.hxx>
+#include <vector>
 
 class HYDROData_PolylineOperator
 {
@@ -32,6 +33,16 @@ public:
                                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