From e87a86a68d394635790206ff39c90b5ab8b775bc Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 21 May 2013 14:57:30 +0000 Subject: [PATCH] 0021941: [CEA 699] Use for Auto Color method on mesh group the same algorithm that this one in GEOM which define colors. --- src/SMESHGUI/SMESHGUI.cxx | 46 +++++++++++++++++++++++++++++- src/SMESHGUI/SMESHGUI.h | 1 + src/SMESHGUI/SMESHGUI_GroupDlg.cxx | 17 ++++++++--- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 59420f87b..0bbbf9bda 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -174,6 +174,10 @@ //Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx #define WITHGENERICOBJ +// Below macro, when uncommented, switches on simplified (more performant) algorithm +// of auto-color picking up +#define SIMPLE_AUTOCOLOR + //namespace{ // Declarations //============================================================= @@ -969,11 +973,21 @@ aMainObject->SetAutoColor( true ); // mesh groups are re-colored here + QList aReservedColors; + SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups(); for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) { SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i]; - SALOMEDS::Color aColor = aGroupObject->GetColor(); + //SALOMEDS::Color aColor = aGroupObject->GetColor(); + +#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors + SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor(); +#else // old algorithm for auto-colors + SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors ); + aReservedColors.append( aColor ); +#endif // SIMPLE_AUTOCOLOR + _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject); if (aGroupSObject) { QColor c; @@ -6539,3 +6553,33 @@ bool SMESHGUI::renameObject( const QString& entry, const QString& name) { } return false; } + + +SALOMEDS::Color SMESHGUI::getPredefinedUniqueColor() +{ + static QList colors; + + if ( colors.isEmpty() ) { + + for (int s = 0; s < 2 ; s++) + { + for (int v = 100; v >= 40; v = v - 20) + { + for (int h = 0; h < 359 ; h = h + 60) + { + colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100)); + } + } + } + } + static int currentColor = 0; + + SALOMEDS::Color color; + color.R = (double)colors[currentColor].red() / 255.0; + color.G = (double)colors[currentColor].green() / 255.0; + color.B = (double)colors[currentColor].blue() / 255.0; + + currentColor = (currentColor+1) % colors.count(); + + return color; +} diff --git a/src/SMESHGUI/SMESHGUI.h b/src/SMESHGUI/SMESHGUI.h index e4bf81c2c..1b990f099 100644 --- a/src/SMESHGUI/SMESHGUI.h +++ b/src/SMESHGUI/SMESHGUI.h @@ -142,6 +142,7 @@ public : virtual void update( const int ); static SALOMEDS::Color getUniqueColor( const QList& ); + static SALOMEDS::Color getPredefinedUniqueColor(); virtual void storeVisualParameters (int savePoint); virtual void restoreVisualParameters(int savePoint); diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index 932a32299..f0e6f7f63 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -1142,6 +1142,8 @@ bool SMESHGUI_GroupDlg::onApply() myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil(); myFilter = SMESH::Filter::_nil(); + + setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled. } else { @@ -2454,15 +2456,20 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor() bool isAutoColor = myMesh->GetAutoColor(); - QColor aQColor; + QColor aQColor = myColorBtn->color(); if( !isAutoColor ) { - int r = 0, g = 0, b = 0; - SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) ); - aQColor.setRgb( r, g, b ); + if ( !aQColor.isValid() ) { + int r = 0, g = 0, b = 0; + SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) ); + aQColor.setRgb( r, g, b ); + } } else { +#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors + SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor(); +#else // old algorithm for auto-colors SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups(); QList aReservedColors; @@ -2474,6 +2481,8 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor() } SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors ); +#endif // SIMPLE_AUTOCOLOR + aQColor.setRgb( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) ); -- 2.30.2