Salome HOME
Porting on OCCT 7.0 and Qt 5. Make compilable version.
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.cxx
index 42a62b5771f92a31f0ccbe1475d0e29404041127..518753aa63fd7f0919a95371faa15fdd6025ee30 100644 (file)
@@ -37,7 +37,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_HArray1OfShape.hxx>
 
-#include <SortTools_QuickSortOfReal.hxx>
-
 #include <QColor>
 #include <QStringList>
+#include <QVector>
 
 //#define DEB_STREAM 1
 #ifdef DEB_STREAM
 
 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
 
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
 
 
 HYDROData_Stream::HYDROData_Stream()
-: HYDROData_NaturalObject()
+: HYDROData_NaturalObject( Geom_3d )
 {
 }
 
@@ -103,29 +100,30 @@ HYDROData_Stream::~HYDROData_Stream()
 {
 }
 
-QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+QStringList HYDROData_Stream::DumpToPython( const QString&       thePyScriptPath,
+                                            MapOfTreatedObjects& theTreatedObjects ) const
 {
   QStringList aResList = dumpObjectCreation( theTreatedObjects );
   QString aName = GetObjPyName();
 
   Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
-  setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
+  setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
 
   HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
   for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
   {
     const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
-    setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
+    setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" );
   }
 
   // Set bottom polyline if exists
   const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
   if ( !aBottomPolyline.IsNull() ) {
-    setPythonReferenceObject( theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
+    setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
   }
 
   aResList << QString( "" );
-  aResList << QString( "%1.Update();" ).arg( aName );
+  aResList << QString( "%1.Update()" ).arg( aName );
   aResList << QString( "" );
 
   return aResList;
@@ -145,16 +143,6 @@ HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
   return aResSeq;
 }
 
-TopoDS_Shape HYDROData_Stream::GetTopShape() const
-{
-  return getTopShape();
-}
-
-TopoDS_Shape HYDROData_Stream::GetShape3D() const
-{
-  return getShape3D();
-}
-
 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve( 
   const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
 {
@@ -279,12 +267,12 @@ void HYDROData_Stream::UpdatePrs()
   anOutGroup->AddShape( aResultPrs.myOutlet );
 }
 
-QColor HYDROData_Stream::DefaultFillingColor()
+QColor HYDROData_Stream::DefaultFillingColor() const
 {
   return QColor( Qt::green );
 }
 
-QColor HYDROData_Stream::DefaultBorderColor()
+QColor HYDROData_Stream::DefaultBorderColor() const
 {
   return QColor( Qt::transparent );
 }
@@ -303,59 +291,28 @@ bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHyd
   return true;
 }
 
-TopoDS_Shape getShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
-                                const int                          theGroupId )
-{
-  TopoDS_Shape aResShape;
-  if ( theGroups.Length() != 4 )
-    return aResShape;
-
-  Handle(HYDROData_ShapesGroup) aGroup =
-    Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
-  if ( aGroup.IsNull() )
-    return aResShape;
-
-  TopTools_SequenceOfShape aGroupShapes;
-  aGroup->GetShapes( aGroupShapes );
-
-  if ( !aGroupShapes.IsEmpty() )
-    aResShape = aGroupShapes.First();
-
-  return aResShape;
-}
-
 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
 {
   HYDROData_SequenceOfObjects aGroups = GetGroups();
-  return getShapeFromGroup( aGroups, 1 );
+  return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
 }
 
 TopoDS_Shape HYDROData_Stream::GetRightShape() const
 {
   HYDROData_SequenceOfObjects aGroups = GetGroups();
-  return getShapeFromGroup( aGroups, 2 );
+  return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
 }
 
 TopoDS_Shape HYDROData_Stream::GetInletShape() const
 {
   HYDROData_SequenceOfObjects aGroups = GetGroups();
-  return getShapeFromGroup( aGroups, 3 );
+  return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
 }
 
 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
 {
   HYDROData_SequenceOfObjects aGroups = GetGroups();
-  return getShapeFromGroup( aGroups, 4 );
-}
-
-QColor HYDROData_Stream::getDefaultFillingColor() const
-{
-  return DefaultFillingColor();
-}
-
-QColor HYDROData_Stream::getDefaultBorderColor() const
-{
-  return DefaultBorderColor();
+  return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
 }
 
 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
@@ -373,7 +330,7 @@ bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& the
   updateProfilesOrder();
 
   // Indicate model of the need to update the stream presentation
-  SetToUpdate( true );
+  Changed( Geom_3d );
 
   return true;
 }
@@ -396,7 +353,7 @@ void HYDROData_Stream::RemoveHydraulicAxis()
   RemoveProfiles();
 
   // Indicate model of the need to update the stream presentation
-  SetToUpdate( true );
+  Changed( Geom_3d );
 }
 
 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
@@ -530,7 +487,7 @@ bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
   insertProfileInToOrder( theProfile, aProfileIndex );
   
   // Indicate model of the need to update the stream presentation
-  SetToUpdate( true );
+  Changed( Geom_3d );
 
   return true;
 }
@@ -575,7 +532,7 @@ bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfil
     SetReferenceObjects( theProfiles, DataTag_Profile );
 
     if ( anIsToUpdate )
-      SetToUpdate( true );
+      Changed( Geom_3d );
   }
 
   return true;
@@ -618,22 +575,20 @@ bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfil
   removeParameter( aProfileIndex );
 
   // Indicate model of the need to update the stream presentation
-  SetToUpdate( true );
+  Changed( Geom_3d );
 
   return true;
 }
 
 void HYDROData_Stream::RemoveProfiles()
 {
-  bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
-
   ClearReferenceObjects( DataTag_Profile );
 
   // Remove the parameters array
   removeParametersArray();
 
   // Indicate model of the need to update the stream presentation
-  SetToUpdate( anIsToUpdate );
+  Changed( Geom_3d );
 }
 
 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
@@ -721,20 +676,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 );
     }
@@ -758,9 +714,9 @@ ObjectKind HYDROData_Stream::getAltitudeObjectType() const
   return KIND_STREAM_ALTITUDE;
 }
 
-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;
@@ -768,13 +724,13 @@ 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 );
+  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 );
   }
 }
 
@@ -816,7 +772,7 @@ int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
   {
     aResIndex = 0;
 
-    TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
+    QVector<double> aNewArr( anArr->Upper() );
 
     bool isInserted = false;
     for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
@@ -830,19 +786,19 @@ int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
         }
         else
         {
-          aNewArr( j ) = theParam;
+          aNewArr[j-1] = theParam;
           isInserted = true;
           ++j;
         }
       }
 
-      aNewArr( j ) = aStoredParam;
+      aNewArr[j-1] = aStoredParam;
     }
 
     if ( !isInserted )
     {
       aResIndex = -1;
-      aNewArr( aNewArr.Upper() ) = theParam;
+      aNewArr[aNewArr.size()-1] = theParam;
     }
     
     setParametersArray( aNewArr );
@@ -850,8 +806,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 );
   }
 
@@ -874,7 +830,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 )
   {
@@ -882,7 +838,7 @@ void HYDROData_Stream::removeParameter( const int& theIndex )
     if ( k == theIndex )
       continue;
 
-    aNewArr.SetValue( j, aStoredParam );
+    aNewArr[j-1] = aStoredParam;
     ++j;
   }
 
@@ -1028,7 +984,8 @@ bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpol
   return isOK;
 }
 
-void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination ) const
+void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
+                               bool isGenerateNewName ) const
 {
   // Get the document
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
@@ -1037,7 +994,7 @@ void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination )
   }
 
   // Call base method
-  HYDROData_Entity::CopyTo( theDestination );
+  HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
 
   Handle(HYDROData_Stream) aStreamCopy = 
     Handle(HYDROData_Stream)::DownCast( theDestination );
@@ -1207,4 +1164,4 @@ bool HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt)
 #endif
 
   return true;
-}
\ No newline at end of file
+}