0021941: [CEA 699] Use for Auto Color method on mesh group the same algorithm that this one in GEOM which define colors.

This commit is contained in:
vsr 2013-05-21 14:57:30 +00:00
parent 57a7fd817d
commit e87a86a68d
3 changed files with 59 additions and 5 deletions

View File

@ -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<SALOMEDS::Color> 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<QColor> 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;
}

View File

@ -142,6 +142,7 @@ public :
virtual void update( const int );
static SALOMEDS::Color getUniqueColor( const QList<SALOMEDS::Color>& );
static SALOMEDS::Color getPredefinedUniqueColor();
virtual void storeVisualParameters (int savePoint);
virtual void restoreVisualParameters(int savePoint);

View File

@ -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<SALOMEDS::Color> 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 ) );