Salome HOME
Merge remote-tracking branch 'remotes/origin/BR_2017' into HEAD
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.cxx
index 91718cb223d29f341008d5dbf1e439b07c2f80ba..4b8e639a92708cc482e6eb376fe1e6ee6e29f3ae 100644 (file)
@@ -92,6 +92,9 @@
 #include <TCollection_AsciiString.hxx>
 #endif
 
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 #include <assert.h>
 
 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
@@ -420,7 +423,10 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH
   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
   TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
   if ( aProfileWire.IsNull() )
-    return false;
+    {
+      DEBTRACE("aProfileWire.IsNull");
+      return false;
+    }
 
   //BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
   BRepAlgo_NormalProjection nproj(thePlane);
@@ -428,10 +434,16 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH
   nproj.SetDefaultParams();
   nproj.Build();
   if(!nproj.IsDone())
-    return false;
+    {
+      DEBTRACE("!nproj.IsDone");
+      return false;
+    }
   TopoDS_Shape aPrjProfile = nproj.Projection();
   if(aPrjProfile.IsNull())
-    return false;
+    {
+      DEBTRACE("aPrjProfile.IsNull");
+      return false;
+    }
   TopoDS_Vertex aV1, aV2;
   if(aPrjProfile.ShapeType() == TopAbs_EDGE)
     TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
@@ -449,14 +461,20 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH
     }
   }
   if(aV1.IsNull() || aV2.IsNull())
-    return false;
+    {
+      DEBTRACE("aV1.IsNull() || aV2.IsNull()");
+      return false;
+    }
   gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
   gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
   aPnt1.SetZ(0.0);
   aPnt2.SetZ(0.0);
   BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2); 
   if(!aMk.IsDone())
-    return false;
+    {
+      DEBTRACE("!aMk.IsDone()");
+      return false;
+    }
   const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
   Standard_Integer aNum(0);
   
@@ -512,6 +530,7 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH
   }
   if(hasInt)
     return true;
+  DEBTRACE("!hasInt " << aPnt1.X() << " " << aPnt1.Y() << " " << aPnt2.X() << " " << aPnt2.Y() << " --- " << aSqDist);
   return false;
 }
 
@@ -530,7 +549,7 @@ bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
   Standard_Real aPar(.0);
   if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
     return false; // Object is already in reference list or it has no intersection
-  
+  //DEBTRACE("AddProfile - insertParameter " << aPar);
   int aProfileIndex = insertParameter( aPar );
   insertProfileInToOrder( theProfile, aProfileIndex );
 
@@ -545,6 +564,7 @@ bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
                                     const bool&                        theIsToOrder )
 {
+  DEBTRACE(" --- SetProfiles " <<theIsToOrder );
   if ( theIsToOrder )
   {
     for ( int i = 1; i <= theProfiles.Length(); ++i )
@@ -764,6 +784,7 @@ void HYDROData_Stream::setParametersArray( const QVector<double>& theArray )
   int n = theArray.size();
   Handle(TDataStd_RealArray) aParamsArray = 
     TDataStd_RealArray::Set( aLabel, 1, n );
+  aParamsArray->SetID(TDataStd_RealArray::GetID());
   for ( int i = 0; i < n; ++i )
   {
     const Standard_Real& aParam = theArray[i];
@@ -809,8 +830,7 @@ int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
   {
     aResIndex = 0;
 
-    QVector<double> aNewArr( anArr->Upper() );
-
+    QVector<double> aNewArr( anArr->Upper() +1 );
     bool isInserted = false;
     for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
     {
@@ -823,13 +843,14 @@ int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
         }
         else
         {
-          aNewArr[j-1] = theParam;
+          if (j<=n+1)
+            aNewArr[j-1] = theParam;
           isInserted = true;
           ++j;
         }
       }
-
-      aNewArr[j-1] = aStoredParam;
+      if (j<=n+1)
+        aNewArr[j-1] = aStoredParam;
     }
 
     if ( !isInserted )