Salome HOME
Merge branch 'BR_H2018_3' into BR_2018_V8_5
[modules/hydro.git] / src / HYDROData / HYDROData_IPolyline.cxx
old mode 100755 (executable)
new mode 100644 (file)
index df150b0..ddd6908
 #include <TDataStd_ExtStringList.hxx>
 #include <TDataStd_IntegerList.hxx>
 #include <TDataStd_RealList.hxx>
-
+#include <TDataStd_IntegerArray.hxx>
 #include <TopoDS_Shape.hxx>
-
-#include <TNaming_Builder.hxx>
-#include <TNaming_NamedShape.hxx>
-
 #include <QColor>
 
-IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
 
 HYDROData_IPolyline::HYDROData_IPolyline()
-: HYDROData_Entity()
+: HYDROData_Entity( Geom_2d )
 {
 }
 
@@ -46,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
@@ -64,29 +63,19 @@ int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
   return GetPoints( theSectionIndex ).Length();
 }
 
-TopoDS_Shape HYDROData_IPolyline::getPolylineShape() const
+TopoDS_Shape HYDROData_IPolyline::GetShape() const
 {
-  TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
-  if ( !aShapeLabel.IsNull() )
-  {
-    Handle(TNaming_NamedShape) aNamedShape;
-    if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
-      return aNamedShape->Get();
-  }
-  return TopoDS_Shape();
+  return HYDROData_Entity::GetShape( DataTag_PolylineShape );
 }
 
-void HYDROData_IPolyline::setPolylineShape( const TopoDS_Shape& theShape )
+void HYDROData_IPolyline::SetShape( const TopoDS_Shape& theShape )
 {
-  TNaming_Builder aBuilder( myLab.FindChild( DataTag_PolylineShape ) );
-  aBuilder.Generated( theShape );
+  HYDROData_Entity::SetShape( DataTag_PolylineShape, theShape );
 }
 
-void HYDROData_IPolyline::removePolylineShape()
+void HYDROData_IPolyline::RemovePolylineShape()
 {
-  TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
-  if ( !aShapeLabel.IsNull() )
-    aShapeLabel.ForgetAllAttributes();
+  SetShape( TopoDS_Shape() );
 }
 
 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
@@ -103,13 +92,22 @@ void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theN
     return;
 
   if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
+  {
     theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
+    theNamesList->SetID(TDataStd_ExtStringList::GetID());
+  }
 
   if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
+  {
     theTypesList = TDataStd_IntegerList::Set( aSectLabel );
+    theTypesList->SetID(TDataStd_IntegerList::GetID());
+  }
 
   if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
+  {
     theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
+    theClosuresList->SetID(TDataStd_BooleanList::GetID());
+  }
 }
 
 void HYDROData_IPolyline::removeSectionsLists()
@@ -139,14 +137,20 @@ void HYDROData_IPolyline::getPointsLists( const int                  theSectionI
   if ( !aLabelX.IsNull() )
   {
     if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
+    {
       theListX = TDataStd_RealList::Set( aLabelX );
+      theListX->SetID(TDataStd_RealList::GetID());
+    }
   }
 
   TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
   if ( !aLabelY.IsNull() )
   {
     if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
+    {
       theListY = TDataStd_RealList::Set( aLabelY );
+      theListY->SetID(TDataStd_RealList::GetID());
+    }
   }
 }
 
@@ -167,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() );
+}