Salome HOME
Import/Export new corrections
[modules/hydro.git] / src / HYDROData / HYDROData_PolylineOperator.cxx
index 61c835f6123d389986b42d23e185f3cc4ea43910..e8a7eec82937ebdb4ef51b491f27025a618bfbc6 100644 (file)
 //
 
 #include <HYDROData_PolylineOperator.h>
+#include <HYDROData_Document.h>
 #include <BRepBuilderAPI_MakeEdge2d.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
 
 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
 {
@@ -34,7 +37,9 @@ template<class T> void append( std::vector<T>& theList, const std::vector<T>& th
 }
 
 
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+                                        const TCollection_AsciiString& theNamePrefix,
+                                        const Handle( HYDROData_PolylineXY )& thePolyline,
                                         const gp_Pnt2d& thePoint ) const
 {
   std::vector<gp_Pnt2d> aPointsList( 1 );
@@ -44,13 +49,15 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& th
   for( int i=0, n=aCurves.size(); i<n; i++ )
   {
     std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
-    bool isLocalOK = CreatePolylines( aCurvesList );
+    bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
     isOK = isOK && isLocalOK;
   }
   return isOK;
 }
 
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+                                        const TCollection_AsciiString& theNamePrefix,
+                                        const Handle( HYDROData_PolylineXY )& thePolyline,
                                         const Handle( HYDROData_PolylineXY )& theTool ) const
 {
   std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
@@ -61,13 +68,15 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& th
     {
       std::vector<gp_Pnt2d> aPointsList = Intersection( aCurves[i], aToolCurves[j] );
       std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
-      bool isLocalOK = CreatePolylines( aCurvesList );
+      bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
       isOK = isOK && isLocalOK;
     }
   return isOK;
 }
 
-bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePolylines )
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+                                        const TCollection_AsciiString& theNamePrefix,
+                                        const HYDROData_SequenceOfObjects& thePolylines )
 {
   int f = thePolylines.Lower(), l = thePolylines.Upper();
   bool isOK = true;
@@ -90,13 +99,15 @@ bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePo
       append( aCompletePointsList, aPointsList );
     }
     std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( anAllCurves[i], aCompletePointsList );
-    bool isLocalOK = CreatePolylines( aCurvesList );
+    bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
     isOK = isOK && isLocalOK;
   }
   return isOK;
 }
 
-bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines )
+bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theDoc,
+                                        const TCollection_AsciiString& theName,
+                                        const HYDROData_SequenceOfObjects& thePolylines )
 {
   //TODO
   return true;
@@ -125,13 +136,27 @@ std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::Split( const Han
   return aResult;
 }
 
-bool HYDROData_PolylineOperator::CreatePolylines( const std::vector<Handle( Geom2d_Curve )>& theCurves )
+bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
+                                                  const TCollection_AsciiString& theNamePrefix,
+                                                  const std::vector<Handle( Geom2d_Curve )>& theCurves )
 {
+  if( theDoc.IsNull() )
+    return false;
+
   int n = theCurves.size();
   for( int i=0; i<n; i++ )
   {
     TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge2d( theCurves[i] ).Edge();
-    //TODO
+    BRepBuilderAPI_MakeWire aMakeWire;
+    aMakeWire.Add( anEdge );
+
+    Handle( HYDROData_PolylineXY ) aPolyline = 
+      Handle( HYDROData_PolylineXY )::DownCast( theDoc->CreateObject( KIND_POLYLINEXY ) );
+    if( aPolyline.IsNull() )
+      return false;
+
+    aPolyline->SetShape( aMakeWire.Wire() );
+    //TODO: set name
   }
   return true;
 }