Salome HOME
Merge branch 'BR_H2018_3' into BR_2018_V8_5
[modules/hydro.git] / src / HYDROData / HYDROData_IPolyline.cxx
index a0a2fe30fc00b599361d85b2fd3eed62881d2535..ddd6908aa381f9cb8f1993dbeaa05c0361fdb444 100644 (file)
@@ -24,6 +24,7 @@
 #include <TDataStd_ExtStringList.hxx>
 #include <TDataStd_IntegerList.hxx>
 #include <TDataStd_RealList.hxx>
+#include <TDataStd_IntegerArray.hxx>
 #include <TopoDS_Shape.hxx>
 #include <QColor>
 
@@ -40,7 +41,11 @@ HYDROData_IPolyline::~HYDROData_IPolyline()
 
 void HYDROData_IPolyline::SetWireColor( const QColor& theColor )
 {
-  SetColor( theColor, DataTag_WireColor );
+  //SetColor( theColor, DataTag_WireColor ); //DEPRECATED;
+  //set theColor for all sections
+  int nbSec = NbSections();
+  for (int i = 0; i < nbSec; i++)
+    SetSectionColor(i, theColor);
 }
 
 QColor HYDROData_IPolyline::GetWireColor() const
@@ -166,3 +171,75 @@ void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
       aSectLabel.ForgetAllAttributes();
   }
 }
+
+bool HYDROData_IPolyline::GetSectionColor( const int theSectionIndex, QColor &theColor) const
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
+  if ( aLabel.IsNull() )
+    return false;
+
+  TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
+  if ( aSectLabel.IsNull() )
+    return false;
+
+  Handle(TDataStd_IntegerArray) aColorArray;
+
+  if ( aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
+  {
+    theColor.setRed(   aColorArray->Value( 1 ) );
+    theColor.setGreen( aColorArray->Value( 2 ) );
+    theColor.setBlue(  aColorArray->Value( 3 ) );
+    theColor.setAlpha( aColorArray->Value( 4 ) );
+  }
+}
+
+void HYDROData_IPolyline::SetSectionColor( const int theSectionIndex,
+                                           const QColor& theColor )
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, true );
+  if ( aLabel.IsNull() )
+    return;
+
+  TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, true );
+  if ( aSectLabel.IsNull() )
+    return;
+
+  Handle(TDataStd_IntegerArray) aColorArray;
+
+  if ( !aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
+    aColorArray = TDataStd_IntegerArray::Set( aSectLabel, 1, 4 );
+
+  aColorArray->SetValue( 1, theColor.red()   );
+  aColorArray->SetValue( 2, theColor.green() );
+  aColorArray->SetValue( 3, theColor.blue()  );
+  aColorArray->SetValue( 4, theColor.alpha() );
+}
+
+void HYDROData_IPolyline::removeSectionColor( const int theSectionIndex ) const
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
+  if ( aLabel.IsNull() )
+    return;
+
+  if ( theSectionIndex < 0 )
+  {
+    aLabel.ForgetAllAttributes();
+  }
+  else
+  {
+    TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
+    if ( !aSectLabel.IsNull() )
+      aSectLabel.ForgetAllAttributes();
+  }
+}
+
+ void HYDROData_IPolyline::setPythonPolylineSectionColor( QStringList&  theScript,
+                                                          const int     theSectIndex,
+                                                          const QColor& theColor ) const
+{
+  QString anObjName = GetObjPyName();
+  theScript << QString( "%1.SetSectionColor( %2, QColor( %3, %4, %5, %6 ) )" )
+              .arg( anObjName ).arg( theSectIndex )
+              .arg( theColor.red()  ).arg( theColor.green() )
+              .arg( theColor.blue() ).arg( theColor.alpha() );
+}