Salome HOME
Merge remote-tracking branch 'origin/master' into BR_LAND_COVER_MAP
[modules/hydro.git] / src / HYDROData / HYDROData_PolylineOperator.cxx
index 612d24f985e09c6dc764661df0e5ce9cfe4b2ada..7e44abefa551166741ff52efc984e12951d4047a 100644 (file)
@@ -20,7 +20,9 @@
 #include <HYDROData_Document.h>
 #include <HYDROData_TopoCurve.h>
 
+#ifndef LIGHT_MODE
 #include <CurveCreator_Utils.hxx>
+#endif
 
 #include <BRepAdaptor_Curve.hxx>
 #include <BRep_Builder.hxx>
@@ -45,6 +47,7 @@
 #include <TopExp_Explorer.hxx>
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 #include <QString>
+#include <Geom_BSplineCurve.hxx>
 
 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
 {
@@ -64,6 +67,11 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD
                                         const gp_Pnt2d& thePoint,
                                         double theTolerance ) const
 {
+  if (thePolyline.IsNull())
+  {
+    return false;
+  }
+
   std::vector<gp_Pnt2d> aPointsList( 1 );
   aPointsList[0] = thePoint;
   std::vector<TopoDS_Wire> aCurves;
@@ -82,11 +90,17 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD
 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
               const Handle( HYDROData_PolylineXY )& thePolyline,
               const Handle( HYDROData_PolylineXY )& theTool,
-              double theTolerance ) const
+              double theTolerance,
+              bool& theIsIntersected) const
 {
+  if (thePolyline.IsNull() || theTool.IsNull())
+  {
+    return false;
+  }
+
   HYDROData_SequenceOfObjects aSeq;
   aSeq.Append( theTool );
-  return split( theDoc, thePolyline, aSeq, theTolerance, -1 );
+  return split( theDoc, thePolyline, aSeq, theTolerance, -1, theIsIntersected);
 }
 
 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
@@ -97,7 +111,8 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD
   for( int i=f; i<=l; i++ )
   {
     Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) );
-    if( !split( theDoc, aPolyline, thePolylines, theTolerance, i ) )
+    bool isIntersected;
+    if( !split( theDoc, aPolyline, thePolylines, theTolerance, i, isIntersected) )
       return false;
   }
   return true;
@@ -153,8 +168,16 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD
                                         const Handle( HYDROData_PolylineXY )& thePolyline,
                                         const HYDROData_SequenceOfObjects& theTools,
                                         double theTolerance,
-                                        int theIgnoreIndex ) const
+                                        int theIgnoreIndex,
+                                        bool& theIsIntersected) const
 {
+  theIsIntersected = false;
+
+  if (thePolyline.IsNull())
+  {
+    return false;
+  }
+
   std::vector<TopoDS_Wire> aCurves;
   GetWires(thePolyline, aCurves);
   std::vector<TopoDS_Wire> aToolCurves;
@@ -163,11 +186,19 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD
     {
       Handle( HYDROData_PolylineXY ) aToolPolyline = 
         Handle( HYDROData_PolylineXY )::DownCast( theTools.Value( i ) );
-      std::vector<TopoDS_Wire> aTCurves;
-      GetWires(aToolPolyline, aTCurves);
-      append( aToolCurves, aTCurves);
+      if (!aToolPolyline.IsNull())
+      {
+        std::vector<TopoDS_Wire> aTCurves;
+        GetWires(aToolPolyline, aTCurves);
+        append( aToolCurves, aTCurves);
+      }
     }
 
+  if (aToolCurves.empty())
+  {
+    return false;
+  }
+
   const int aPSCount = aCurves.size();
   const int aTSCount = aToolCurves.size();
   std::vector<TopoDS_Shape> aResult;
@@ -186,7 +217,7 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD
     }
 
     std::deque<HYDROData_TopoCurve> aSplittedCurves;
-    aCurve.Cut(aParams, aSplittedCurves);
+    theIsIntersected |= aCurve.Cut(aParams, aSplittedCurves);
     std::deque<HYDROData_TopoCurve>::const_iterator aCIt =
       aSplittedCurves.begin();
     std::deque<HYDROData_TopoCurve>::const_iterator aLastCIt =
@@ -303,7 +334,9 @@ double HYDROData_PolylineOperator::ReduceDeflection(
   }
   Handle(Geom_BSplineCurve) aBSpline2;
   const bool isClosed = theCurve.IsClosed();
+#ifndef LIGHT_MODE
   if (!CurveCreator_Utils::constructBSpline(aPs2, isClosed, aBSpline2))
+#endif
   {
     return -1;
   }