Salome HOME
0021941: [CEA 699] Use for Auto Color method on mesh group the same algorithm that...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 59420f87bee15cf122c3b7c9e7989a465d53d6df..0bbbf9bdad90aee8ea7667cc3344fb25f745b7df 100644 (file)
 //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
   //=============================================================
 
     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;
+}