Salome HOME
Merge remote-tracking branch 'remotes/origin/BR_2017' into HEAD
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.cxx
index 2f85c4241554574f239b6bb9c4d3a5bcbb7fde83..4b8e639a92708cc482e6eb376fe1e6ee6e29f3ae 100644 (file)
@@ -39,7 +39,6 @@
 #include <TColStd_Array1OfReal.hxx>
 #include <TColStd_ListOfReal.hxx>
 #include <TColStd_ListIteratorOfListOfReal.hxx>
-#include <TCollection_CompareOfReal.hxx>
 #include <TColgp_Array1OfPnt.hxx>
 #include <TColgp_HArray1OfPnt.hxx>
 
 #include <TopTools_SequenceOfShape.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 
-#include <SortTools_QuickSortOfReal.hxx>
-
 #include <QColor>
 #include <QStringList>
+#include <QVector>
 
 //#define DEB_STREAM 1
 #ifdef DEB_STREAM
 #include <TCollection_AsciiString.hxx>
 #endif
 
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 #include <assert.h>
 
 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
 
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
 
 
@@ -187,7 +187,7 @@ void HYDROData_Stream::Update()
     }
   }
 
-  Handle_HYDROData_DTM dtm = DTM();
+  Handle(HYDROData_DTM) dtm = DTM();
   dtm->Update();
   UpdatePrs( dtm );
 
@@ -199,7 +199,7 @@ bool HYDROData_Stream::IsHas2dPrs() const
   return true;
 }
 
-bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM,
+bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_DTM)& theDTM,
                                             PrsDefinition&              thePrs )
 {
   if ( theDTM.IsNull() )
@@ -245,7 +245,7 @@ bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM,
   return true;
 }
 
-void HYDROData_Stream::UpdatePrs( const Handle_HYDROData_DTM& theDTM )
+void HYDROData_Stream::UpdatePrs( const Handle(HYDROData_DTM)& theDTM )
 {
   HYDROData_NaturalObject::Update();
   
@@ -330,7 +330,7 @@ TopoDS_Shape HYDROData_Stream::GetOutletShape() const
   return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
 }
 
-Handle_HYDROData_DTM HYDROData_Stream::DTM() const
+Handle(HYDROData_DTM) HYDROData_Stream::DTM() const
 {
   const_cast<HYDROData_Stream*>( this )->checkAndSetAltitudeObject();
   return Handle(HYDROData_DTM)::DownCast( GetAltitudeObject() );
@@ -423,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);
@@ -431,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);
@@ -452,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);
   
@@ -515,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;
 }
 
@@ -533,9 +549,11 @@ 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 );
+
+  DTM()->SetProfiles( GetProfiles() );
   
   // Indicate model of the need to update the stream presentation
   Changed( Geom_3d );
@@ -546,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 )
@@ -714,20 +733,21 @@ void HYDROData_Stream::updateProfilesOrder()
   if ( aList.IsEmpty() )
     return;
 
-  TColStd_Array1OfReal anArr( 1, aList.Extent() );
+  QVector<double> anArr( aList.Extent() );
 
   TColStd_ListIteratorOfListOfReal it( aList );
   for ( int j = 1; it.More(); it.Next(), j++ )
-    anArr( j ) = it.Value();
+    anArr[j-1] = it.Value();
 
   // sorting
   if ( aList.Extent() > 1 )
   {
-    TCollection_CompareOfReal Compar;
-    SortTools_QuickSortOfReal::Sort( anArr, Compar );
+    //TCollection_CompareOfReal Compar;
+    //SortTools_QuickSortOfReal::Sort( anArr, Compar );
+    std::sort( anArr.begin(), anArr.end() );
 
-    for (int j = 1; j <= anArr.Length(); j++) {
-      const Standard_Real aKey =  anArr(j);
+    for (int j = 1; j <= anArr.size(); j++) {
+      const Standard_Real aKey =  anArr[j-1];
       const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
       insertProfileInToOrder( aProfile );
     }
@@ -751,9 +771,9 @@ ObjectKind HYDROData_Stream::getAltitudeObjectType() const
   return KIND_DTM;
 }
 
-void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
+void HYDROData_Stream::setParametersArray( const QVector<double>& theArray )
 {
-  if ( theArray.Length() == 0 )
+  if ( theArray.size() == 0 )
   {
     removeParametersArray();
     return;
@@ -761,13 +781,14 @@ void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray
 
   TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
   
+  int n = theArray.size();
   Handle(TDataStd_RealArray) aParamsArray = 
-    TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
-
-  for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
+    TDataStd_RealArray::Set( aLabel, 1, n );
+  aParamsArray->SetID(TDataStd_RealArray::GetID());
+  for ( int i = 0; i < n; ++i )
   {
-    const Standard_Real& aParam = theArray( i );
-    aParamsArray->SetValue( i, aParam );
+    const Standard_Real& aParam = theArray[i];
+    aParamsArray->SetValue( i+1, aParam );
   }
 }
 
@@ -809,8 +830,7 @@ int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
   {
     aResIndex = 0;
 
-    TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
-
+    QVector<double> aNewArr( anArr->Upper() +1 );
     bool isInserted = false;
     for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
     {
@@ -823,19 +843,20 @@ int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
         }
         else
         {
-          aNewArr( j ) = theParam;
+          if (j<=n+1)
+            aNewArr[j-1] = theParam;
           isInserted = true;
           ++j;
         }
       }
-
-      aNewArr( j ) = aStoredParam;
+      if (j<=n+1)
+        aNewArr[j-1] = aStoredParam;
     }
 
     if ( !isInserted )
     {
       aResIndex = -1;
-      aNewArr( aNewArr.Upper() ) = theParam;
+      aNewArr[aNewArr.size()-1] = theParam;
     }
     
     setParametersArray( aNewArr );
@@ -843,8 +864,8 @@ int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
   }
   else
   {
-    TColStd_Array1OfReal aNewArr( 1, 1 );
-    aNewArr.SetValue( 1, theParam );
+    QVector<double> aNewArr( 1 );
+    aNewArr[0] = theParam;
     setParametersArray( aNewArr );
   }
 
@@ -867,7 +888,7 @@ void HYDROData_Stream::removeParameter( const int& theIndex )
     return;
   }
 
-  TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
+  QVector<double> aNewArr( aParamsArray->Upper() - 2 );
 
   for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
   {
@@ -875,7 +896,7 @@ void HYDROData_Stream::removeParameter( const int& theIndex )
     if ( k == theIndex )
       continue;
 
-    aNewArr.SetValue( j, aStoredParam );
+    aNewArr[j-1] = aStoredParam;
     ++j;
   }
 
@@ -1129,4 +1150,4 @@ void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt)
   thePrs.myOutlet = LS(3);  
   thePrs.myRightBank = LS(4);
 
-}
\ No newline at end of file
+}