Salome HOME
Bug NPAL12872 - EDF189 GEOM, SMESH : Visualization of groups with many colors
authorouv <ouv@opencascade.com>
Tue, 6 Nov 2007 08:54:05 +0000 (08:54 +0000)
committerouv <ouv@opencascade.com>
Tue, 6 Nov 2007 08:54:05 +0000 (08:54 +0000)
25 files changed:
idl/SMESH_Group.idl
idl/SMESH_Mesh.idl
src/DriverMED/DriverMED_Family.cxx
src/DriverMED/DriverMED_Family.h
src/SMESH/SMESH_Group.hxx
src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_Mesh.hxx
src/SMESHDS/SMESHDS_GroupBase.cxx
src/SMESHDS/SMESHDS_GroupBase.hxx
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI.h
src/SMESHGUI/SMESHGUI_GroupDlg.cxx
src/SMESHGUI/SMESHGUI_GroupDlg.h
src/SMESHGUI/SMESHGUI_Selection.cxx
src/SMESHGUI/SMESHGUI_Selection.h
src/SMESHGUI/SMESHGUI_VTKUtils.cxx
src/SMESHGUI/SMESH_msg_en.po
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_DumpPython.cxx
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Group_i.cxx
src/SMESH_I/SMESH_Group_i.hxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx
src/SMESH_SWIG/smeshDC.py

index 2ef815f1bff633c2833db5cc900c66ac2dd01c29..4704e05a07285cab33fc5bf1742ccf150fad5eeb 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "SALOME_Exception.idl"
 #include "SALOME_GenericObj.idl"
+#include "SALOMEDS_Attributes.idl"
 
 #include "SMESH_Mesh.idl"
 
@@ -86,14 +87,14 @@ module SMESH
     SMESH_Mesh GetMesh();
 
     /*!
-     * Sets group color number
+     * Sets group color
      */
-    void SetColorNumber( in long color );
+    void SetColor(in SALOMEDS::Color theColor);
 
     /*!
-     * Returns group color number
+     * Returns group color
      */
-    long GetColorNumber();
+    SALOMEDS::Color GetColor();
   }; 
 
   /*!
index 0e9d8ceb8abc167faaafe6448e35b4de92ba3d20..4e7b2c56123848329dec5700b071edd0a5d41548 100644 (file)
@@ -335,6 +335,20 @@ module SMESH
     void ClearLog()
       raises (SALOME::SALOME_Exception);
 
+    /*!
+     * Toggle auto color mode on the object.
+     * @params
+     * - theAutoColor : flag which toggles auto color mode.
+     */
+    void SetAutoColor(in boolean theAutoColor)
+      raises (SALOME::SALOME_Exception);
+
+    /*!
+     * Get flag of object's auto color mode.
+     */
+    boolean GetAutoColor()
+      raises (SALOME::SALOME_Exception);
+
     /*!
      * Get the internal Id
      */
index 45438ee6d203f461bff50895b53455bf9f8b8b71..46ae6549104403da0ac27c0c0ede12a86dc6ba3e 100644 (file)
@@ -129,6 +129,16 @@ DriverMED_Family
   return myElements.empty(); 
 }
 
+bool CompareColors( const SALOMEDS::Color& theColor, const SALOMEDS::Color& theRefColor )
+{
+  if( fabs( theColor.R - theRefColor.R ) < 0.01 &&
+      fabs( theColor.G - theRefColor.G ) < 0.01 &&
+      fabs( theColor.B - theRefColor.B ) < 0.01 )
+    return true;
+
+  return false;
+}
+
 //=============================================================================
 /*!
  *  Split each group from list <aGroups> on some parts (families)
@@ -201,11 +211,33 @@ DriverMED_Family
   }
 
   // Process groups
-  SMESHDS_GroupBasePtrList::const_iterator aGroupsIter = theGroups.begin();
-  for (; aGroupsIter != theGroups.end(); aGroupsIter++)
+  SMESHDS_GroupBasePtrList::const_iterator aGroupsIter;
+
+  int id = 0;
+  ColorMap aColorMap;
+  for (aGroupsIter = theGroups.begin(); aGroupsIter != theGroups.end(); aGroupsIter++)
+  {
+    SALOMEDS::Color aColor = (*aGroupsIter)->GetColor();
+
+    bool isFound = false;
+    for (ColorMap::iterator aColorIter = aColorMap.begin(); aColorIter != aColorMap.end(); aColorIter++)
+    {
+      SALOMEDS::Color aRefColor = aColorIter->second;
+      if( CompareColors( aColor, aRefColor ) )
+      {
+       isFound = true;
+       break;
+      }
+    }
+
+    if( !isFound )
+      aColorMap[ id++ ] = aColor;
+  }
+
+  for (aGroupsIter = theGroups.begin(); aGroupsIter != theGroups.end(); aGroupsIter++)
   {
     DriverMED_FamilyPtr aFam2 (new DriverMED_Family);
-    aFam2->Init(*aGroupsIter);
+    aFam2->Init(*aGroupsIter, aColorMap);
 
     DriverMED_FamilyPtrList::iterator aFamsIter = aFamilies.begin();
     while (aFamsIter != aFamilies.end())
@@ -364,7 +396,7 @@ DriverMED_Family::GetFamilyInfo(const MED::PWrapper& theWrapper,
  *  Initialize the tool by SMESHDS_GroupBase
  */
 //=============================================================================
-void DriverMED_Family::Init (SMESHDS_GroupBase* theGroup)
+void DriverMED_Family::Init (SMESHDS_GroupBase* theGroup, const ColorMap& theColorMap)
 {
   // Elements
   myElements.clear();
@@ -383,11 +415,16 @@ void DriverMED_Family::Init (SMESHDS_GroupBase* theGroup)
 
   myGroupAttributVal = 0;
   
-  if (theGroup->GetColorGroup()!=0)
+  ColorMap::const_iterator aColorIter = theColorMap.begin();
+  for (; aColorIter != theColorMap.end(); aColorIter++)
+  {
+    SALOMEDS::Color aColor = aColorIter->second;
+    if( CompareColors( theGroup->GetColor(), aColor ) )
     {
-      myGroupAttributVal = theGroup->GetColorGroup();
+      myGroupAttributVal = aColorIter->first;
+      break;
     }
-
+  }
 }
 
 //=============================================================================
index 64ad65a566a15f542c2516c0dbe6aeb1db9b8091..1925a34718c419d7d30649f1775e94213dd9cc21 100644 (file)
@@ -51,6 +51,7 @@ typedef std::list<DriverMED_FamilyPtr> DriverMED_FamilyPtrList;
 typedef std::map<int,SMESHDS_SubMesh*> SMESHDS_SubMeshPtrMap;
 typedef std::list<SMESHDS_GroupBase*> SMESHDS_GroupBasePtrList;
 typedef std::set<const SMDS_MeshElement*> ElementsSet;
+typedef std::map<int,SALOMEDS::Color> ColorMap;
 
 class MESHDRIVERMED_EXPORT DriverMED_Family
 {
@@ -107,7 +108,7 @@ class MESHDRIVERMED_EXPORT DriverMED_Family
 
  private:
   //! Initialize the tool by SMESHDS_GroupBase
-  void Init (SMESHDS_GroupBase* group);
+  void Init (SMESHDS_GroupBase* theGroup, const ColorMap& theColorMap);
 
   //! Split <theSubMesh> on some parts (families) on the basis of the elements type.
   static
index 1b13bc57859985b2efbf44f4820e7f935b151b3d..64df569def5ab015e9d8c001ab5534579c56efc5 100644 (file)
@@ -34,6 +34,9 @@
 #include <string>
 #include <TopoDS_Shape.hxx>
 
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOMEDS)
+#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
 
 class SMESHDS_GroupBase;
 class SMESH_Mesh;
@@ -55,8 +58,8 @@ class SMESH_EXPORT  SMESH_Group
 
   SMESHDS_GroupBase * GetGroupDS () { return myGroupDS; }
 
-  void SetColorNumber (int theColorNumber) { myColorNumber = theColorNumber; }
-  int GetColorNumber() const { return myColorNumber; }
+  void SetColor (const SALOMEDS::Color& theColor) { myColor = theColor; }
+  SALOMEDS::Color GetColor() const { return myColor; }
 
  private:
   SMESH_Group (const SMESH_Group& theOther);
@@ -67,6 +70,7 @@ class SMESH_EXPORT  SMESH_Group
   SMESHDS_GroupBase * myGroupDS;
   std::string         myName;
   int                 myColorNumber;
+  SALOMEDS::Color     myColor;
 };
 
 #endif
index 236d400feab6dc94d2c636d2eb45a8c4a083ee37..b6c55a0cf2f6180a0fd9364017fa5a75c1fa66ed 100644 (file)
@@ -98,6 +98,7 @@ SMESH_Mesh::SMESH_Mesh(int               theLocalId,
   _idDoc         = theDocument->NewMesh(theIsEmbeddedMode);
   _myMeshDS      = theDocument->GetMesh(_idDoc);
   _isShapeToMesh = false;
+  _isAutoColor   = false;
   _myMeshDS->ShapeToMesh( PseudoShape() );
 }
 
@@ -871,6 +872,23 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* h
   }
 }
 
+//=============================================================================
+/*!
+ *  Auto color functionality
+ */
+//=============================================================================
+void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
+{
+  Unexpect aCatch(SalomeException);
+  _isAutoColor = theAutoColor;
+}
+
+bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
+{
+  Unexpect aCatch(SalomeException);
+  return _isAutoColor;
+}
+
 //=============================================================================
 /*! Export* methods.
  *  To store mesh contents on disk in different formats.
index fc5acef94e02e07c511d8bf6af7d3e4bb19021d4..d7b86da5d0daefec1a7495d8a2c75c5b9b7114e5 100644 (file)
@@ -174,6 +174,10 @@ public:
   // return list of ancestors of theSubShape in the order
   // that lower dimention shapes come first.
 
+  void SetAutoColor(bool theAutoColor) throw(SALOME_Exception);
+
+  bool GetAutoColor() throw(SALOME_Exception);
+
   /*! Check group names for duplications.
    *  Consider maximum group name length stored in MED file.
    */
@@ -249,6 +253,8 @@ protected:
   map <int, SMESH_subMesh *> _mapSubMesh;
   map <int, SMESH_Group *>   _mapGroup;
   SMESH_Gen *                _gen;
+
+  bool                       _isAutoColor;
   
   TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;
 
index e374b723bdb5024fb167b22c2618da8877ae3309..da7b0da13f2200da883385a8651e4e73dd9c543b 100644 (file)
@@ -41,8 +41,11 @@ SMESHDS_GroupBase::SMESHDS_GroupBase (const int                 theID,
                                       const SMESHDS_Mesh*       theMesh,
                                       const SMDSAbs_ElementType theType):
        myID(theID), myMesh(theMesh), myType(theType), myStoreName(""),
-       myCurIndex(0), myCurID(-1), myColorGroup(0)
+       myCurIndex(0), myCurID(-1)
 {
+  myColor.R = 0.f;
+  myColor.G = 0.f;
+  myColor.B = 0.f;
 }
 
 //=============================================================================
index 2bba90532d447926f044ce75910fbef630212b26..48fd791205554a7fe0307f1b5173c79a453a5276 100644 (file)
 #include "SMDSAbs_ElementType.hxx"
 #include "SMDS_MeshElement.hxx"
   
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOMEDS)
+#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
+
 class SMESHDS_Mesh;
 
 class SMESHDS_EXPORT SMESHDS_GroupBase
@@ -68,11 +72,11 @@ class SMESHDS_EXPORT SMESHDS_GroupBase
 
   virtual ~SMESHDS_GroupBase() {}
 
-  void SetColorGroup (int theColorGroup)
-  { myColorGroup = theColorGroup;}
+  void SetColor (const SALOMEDS::Color& theColor)
+  { myColor = theColor;}
   
-  int GetColorGroup() const
-  { return myColorGroup;}
+  SALOMEDS::Color GetColor() const
+  { return myColor;}
   
  protected:
   const SMDS_MeshElement* findInMesh (const int theID) const;
@@ -92,7 +96,7 @@ class SMESHDS_EXPORT SMESHDS_GroupBase
   int                  myCurIndex;
   int                  myCurID;
   SMDS_ElemIteratorPtr myIterator;
-  int                  myColorGroup;
+  SALOMEDS::Color      myColor;
 };
 
 #endif
index 7ed16cefb7a9f5dff4c8ddd0fb93e2e8ad01fe45..0db20e7daffce5e127f5e01e139807d91fc58c87 100644 (file)
@@ -500,12 +500,81 @@ using namespace std;
     }
   }
 
-  void SetDisplayMode(int theCommandID){
+  void AutoColor(){
+    SALOME_ListIO selected;
+    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+    if( !app )
+      return;
+
+    LightApp_SelectionMgr* aSel = app->selectionMgr();
+    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+    if( !aSel || !appStudy )
+      return;
+
+    aSel->selectedObjects( selected );
+    if( selected.IsEmpty() )
+      return;
+
+    Handle(SALOME_InteractiveObject) anIObject = selected.First();
+
+    _PTR(Study) aStudy = appStudy->studyDS();
+    _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
+    SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
+    if( aMainObject->_is_nil() )
+      return;
+
+    aMainObject->SetAutoColor( true );
+
+    QValueList<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 aCurrentColor = aGroupObject->GetColor();
+
+      SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
+      aGroupObject->SetColor( aColor );
+      aReservedColors.append( aColor );
+
+      _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
+      if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str()))
+       anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
+    }
+
+    SMESH::RepaintCurrentView();
+  }
+
+  void DisableAutoColor(){
     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
     SALOME_ListIO selected;
     if( aSel )
       aSel->selectedObjects( selected );
 
+    if(selected.Extent()){
+      Handle(SALOME_InteractiveObject) anIObject = selected.First();
+      SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
+      if ( !aMesh->_is_nil() ) {
+       aMesh->SetAutoColor( false );
+      }
+    }
+  }
+
+  void SetDisplayMode(int theCommandID){
+    SALOME_ListIO selected;
+    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+    if( !app )
+      return;
+
+    LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+    if( !aSel || !appStudy )
+      return;
+
+    _PTR(Study) aStudy = appStudy->studyDS();
+
+    aSel->selectedObjects( selected );
+
     if(selected.Extent() >= 1){
       switch(theCommandID){
       case 1134:{
@@ -611,6 +680,16 @@ using namespace std;
                                      vtkFloatingPointType (nodecolor.blue()) / 255.);
                anActor->SetNodeSize(aDlg->GetIntValue(2));
 
+               SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
+               if( !aGroupObject->_is_nil() )
+               {
+                 SALOMEDS::Color aColor;
+                 aColor.R = (float)color.red() / 255.0;
+                 aColor.G = (float)color.green() / 255.0;
+                 aColor.B = (float)color.blue() / 255.0;
+                 aGroupObject->SetColor( aColor );
+               }
+
                delete aDlg;
              }
              break;
@@ -1237,6 +1316,15 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       break;
     }
 
+    // Auto-color
+  case 1136:
+    ::AutoColor();
+  break;
+
+  case 1137:
+    ::DisableAutoColor();
+  break;
+
   case 1134: // Clipping
   case 1133: // Tranparency
   case 1132: // Colors / Size
@@ -2422,6 +2510,8 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( 1133, "TRANSP" );
   createSMESHAction( 1134, "CLIP" );
   createSMESHAction( 1135, "DISP_ENT" );
+  createSMESHAction( 1136, "AUTO_COLOR" );
+  createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
   createSMESHAction( 2000, "CTRL" );
 
   createSMESHAction( 300, "ERASE" );
@@ -2698,6 +2788,10 @@ void SMESHGUI::initialize( CAM_Application* app )
   createPopupItem( 902, View, mesh );       // STD_INFO
   popupMgr()->insert( separator(), -1, 0 );
 
+  createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
+  createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
+  popupMgr()->insert( separator(), -1, 0 );
+
   int anId;
   QString
     isInvisible("not( isVisible )"),
@@ -2718,6 +2812,10 @@ void SMESHGUI::initialize( CAM_Application* app )
   aType = aType.arg( mesh_group );
   QString aMeshInVTK = aClient + "&&" + aType;
 
+  aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
+  QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
+  QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
+
   //-------------------------------------------------
   // Numbering
   //-------------------------------------------------
@@ -2885,10 +2983,6 @@ void SMESHGUI::initialize( CAM_Application* app )
   //-------------------------------------------------
   // Display / Erase
   //-------------------------------------------------
-  aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
-  QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
-  QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
-
   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
@@ -3335,3 +3429,61 @@ LightApp_Displayer* SMESHGUI::displayer()
     myDisplayer = new SMESHGUI_Displayer( getApp() );
   return myDisplayer;
 }
+
+SALOMEDS::Color SMESHGUI::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
+{
+  int aHue = -1;
+  int aTolerance = 64;
+  int anIterations = 0;
+  int aPeriod = 5;
+
+  while( 1 )
+  {
+    anIterations++;
+    if( anIterations % aPeriod == 0 )
+    {
+      aTolerance /= 2;
+      if( aTolerance < 1 )
+       break;
+    }
+    //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
+
+    aHue = (int)( 360.0 * rand() / RAND_MAX );
+    //cout << "Hue = " << aHue << endl;
+
+    //cout << "Auto colors : ";
+    bool ok = true;
+    QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
+    QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
+    for( ; it != itEnd; ++it )
+    {
+      SALOMEDS::Color anAutoColor = *it;
+      QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
+
+      int h, s, v;
+      aQColor.getHsv( &h, &s, &v );
+      //cout << h << " ";
+      if( abs( h - aHue ) < aTolerance )
+      {
+       ok = false;
+       //cout << "break (diff = " << abs( h - aHue ) << ")";
+       break;
+      }
+    }
+    //cout << endl;
+
+    if( ok )
+      break;
+  }
+
+  //cout << "Hue of the returned color = " << aHue << endl;
+  QColor aColor;
+  aColor.setHsv( aHue, 255, 255 );
+
+  SALOMEDS::Color aSColor;
+  aSColor.R = (double)aColor.red() / 255.0;
+  aSColor.G = (double)aColor.green() / 255.0;
+  aSColor.B = (double)aColor.blue() / 255.0;
+
+  return aSColor;
+}
index 7dbab6471692f2b7aa0d41e0c56d6b1390c4d683..edcf8ab8e2bc3e96cb46ec178442c64239cf0638 100644 (file)
@@ -109,6 +109,8 @@ public :
   
   virtual void                update( const int );
 
+  static SALOMEDS::Color      getUniqueColor( const QValueList<SALOMEDS::Color>& );
+
 public slots:
   virtual bool                deactivateModule( SUIT_Study* );
   virtual bool                activateModule( SUIT_Study* );
index 8968d907c014f6b78973747d980b7e6f0b09b180..57220e6613085997a63c0a6f432e6f943f799b5e 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "SMESH_TypeFilter.hxx"
 #include "SMESH_Actor.h"
+#include "SMESH_ActorUtils.h"
 
 #include "GEOMBase.h"
 #include "GEOM_SelectionFilter.h"
@@ -82,6 +83,7 @@
 #include <qpixmap.h>
 #include <qmemarray.h>
 #include <qwidgetstack.h>
+#include <qcolordialog.h>
 
 #include <QtxIntSpinBox.h>
 
@@ -321,16 +323,10 @@ void SMESHGUI_GroupDlg::initDialog(bool create)
   QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
   aColorBox->setTitle(tr("SMESH_SET_COLOR"));
 
-  mySelectColorGroup = new QCheckBox(aColorBox, "color checkbox");
-  mySelectColorGroup->setText(tr("SMESH_CHECK_COLOR"));
-  
-  myColorSpinBox = new QtxIntSpinBox( aColorBox );
-  myColorSpinBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
-  myColorSpinBox->setMinValue( 0 );
-  myColorSpinBox->setMaxValue( 9999 );
-  
-  onSelectColorGroup(false);
-  
+  new QLabel( tr("SMESH_CHECK_COLOR"), aColorBox, "color label" );
+  myColorBtn = new QPushButton(aColorBox, "color button");
+  myColorBtn->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
+
   /***************************************************************/
   
   QFrame* aButtons = new QFrame(this, "button box");
@@ -391,8 +387,7 @@ void SMESHGUI_GroupDlg::initDialog(bool create)
   connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
   connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
   connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
-  connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool)));
-  connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&)));
+  connect(myColorBtn, SIGNAL(clicked()), this, SLOT(onSelectColor()));
   
   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
   connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
@@ -453,6 +448,8 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
   myActor = SMESH::FindActorByObject(myMesh);
   SMESH::SetPickable(myActor);
 
+  setDefaultGroupColor();
+
   SALOME_ListIO aList;
   mySelectionMgr->selectedObjects( aList );
   if( !aList.IsEmpty() )
@@ -479,7 +476,8 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
   myName->setText(theGroup->GetName());
   myName->home(false);
 
-  myColorSpinBox->setValue( theGroup->GetColorNumber() );
+  SALOMEDS::Color aColor = theGroup->GetColor();
+  setGroupColor( aColor );
   
   myMeshGroupLine->setText(theGroup->GetName());
 
@@ -581,15 +579,6 @@ void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
   updateButtons();
 }
 
-//=================================================================================
-// function : onNbColorsChanged()
-// purpose  :
-//=================================================================================
-void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
-{
-  updateButtons();
-}
-
 //=================================================================================
 // function : onTypeChanged()
 // purpose  : Group elements type radio button management
@@ -617,6 +606,19 @@ void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
   myGrpTypeId = id;
 }
 
+//=================================================================================
+// function : onSelectColor()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::onSelectColor()
+{
+  QColor color = getGroupQColor();
+  color = QColorDialog::getColor( color );
+  setGroupQColor( color );
+
+  updateButtons();
+}
+
 //=================================================================================
 // function : setSelectionMode()
 // purpose  : Radio button management
@@ -713,25 +715,28 @@ bool SMESHGUI_GroupDlg::onApply()
       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
       myGroup->Add(anIdList.inout());
 
-      int aColorNumber = myColorSpinBox->value();
-      myGroup->SetColorNumber(aColorNumber);
+      SALOMEDS::Color aColor = getGroupColor();
+      myGroup->SetColor(aColor);
 
       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
 
-      SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
+      //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
 
       /* init for next operation */
       myName->setText("");
-      myColorSpinBox->setValue(0);
       myElements->clear();
       myGroup = SMESH::SMESH_Group::_nil();
 
     } else { // edition
       myGroup->SetName(myName->text());
         
-      int aColorNumber = myColorSpinBox->value();
-      myGroup->SetColorNumber(aColorNumber);
+      SALOMEDS::Color aColor = getGroupColor();
+      myGroup->SetColor(aColor);
+
+      _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
+      if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
+       anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
 
       QValueList<int> aAddList;
       QValueList<int>::iterator anIt;
@@ -836,25 +841,27 @@ bool SMESHGUI_GroupDlg::onApply()
         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
       }
 
-      int aColorNumber = myColorSpinBox->value();
-      myGroupOnGeom->SetColorNumber(aColorNumber);
+      SALOMEDS::Color aColor = getGroupColor();
+      myGroupOnGeom->SetColor(aColor);
 
       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
 
-      SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
-
+      //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
       SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
 
       /* init for next operation */
       myName->setText("");
-      myColorSpinBox->setValue(0);
       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
     }
     else { // edition
       myGroupOnGeom->SetName(myName->text());
 
-      int aColorNumber = myColorSpinBox->value();
-      myGroupOnGeom->SetColorNumber(aColorNumber);
+      SALOMEDS::Color aColor = getGroupColor();
+      myGroupOnGeom->SetColor(aColor);
+
+      _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
+      if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
+       anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
     }
 
     mySMESHGUI->updateObjBrowser(true);
@@ -1222,17 +1229,6 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
   }
 }
 
-//=================================================================================
-// function : (onSelectColorGroup)
-// purpose  : Called when setting a color on group
-//=================================================================================
-void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
-{
-  if (!on)
-    myColorSpinBox->setValue(0);
-  
-  myColorSpinBox->setEnabled(on);
-}
 
 //=================================================================================
 // function : setCurrentSelection()
@@ -1854,3 +1850,95 @@ void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
       setSelectionMode(7);
     }
 }
+
+//=================================================================================
+// function : setGroupColor()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
+{
+  QColor aQColor( (int)( theColor.R * 255.0 ),
+                 (int)( theColor.G * 255.0 ),
+                 (int)( theColor.B * 255.0 ) );
+  setGroupQColor( aQColor );
+}
+
+//=================================================================================
+// function : getGroupColor()
+// purpose  :
+//=================================================================================
+SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
+{
+  QColor aQColor = getGroupQColor();
+
+  SALOMEDS::Color aColor;
+  aColor.R = (float)aQColor.red() / 255.0;
+  aColor.G = (float)aQColor.green() / 255.0;
+  aColor.B = (float)aQColor.blue() / 255.0;
+
+  return aColor;
+}
+
+//=================================================================================
+// function : setGroupQColor()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
+{
+  if( theColor.isValid() )
+  {
+    QPalette pal = myColorBtn->palette();
+    pal.setColor(QColorGroup::Button, theColor);
+    myColorBtn->setPalette(pal);
+  }
+}
+
+//=================================================================================
+// function : getGroupQColor()
+// purpose  :
+//=================================================================================
+QColor SMESHGUI_GroupDlg::getGroupQColor() const
+{
+  QColor aColor = myColorBtn->palette().active().button();
+  return aColor;
+}
+
+//=================================================================================
+// function : setDefaultGroupColor()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::setDefaultGroupColor()
+{
+  if( myMesh->_is_nil() )
+    return;
+
+  bool isAutoColor = myMesh->GetAutoColor();
+
+  QColor aQColor;
+  if( !isAutoColor )
+  {
+    int r = 0, g = 0, b = 0;
+    SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
+    aQColor.setRgb( r, g, b );
+  }
+  else
+  {
+    SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
+
+    QValueList<SALOMEDS::Color> aReservedColors;
+    for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
+    {
+      SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
+      SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
+      aReservedColors.append( aReservedColor );
+    }
+
+    SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
+    aQColor.setRgb( (int)( aColor.R * 255.0 ),
+                   (int)( aColor.G * 255.0 ),
+                   (int)( aColor.B * 255.0 ) );
+
+  }
+
+  setGroupQColor( aQColor );
+}
index be6f5ebdd8845bea1fdf6d208774f46b40f04d85..9fa0d1882099b01dcaf0b43db7a1c2d214ddddf0 100644 (file)
@@ -103,16 +103,16 @@ private slots:
     void onSelectSubMesh(bool on);
     void onSelectGroup(bool on);
     void onSelectGeomGroup(bool on);
-    void onSelectColorGroup(bool on);
     void setCurrentSelection();
 
     void setFilters();
     void onSort();
 
     void onNameChanged(const QString& text);
-    void onNbColorsChanged(const QString& text);
     void onFilterAccepted();
 
+    void onSelectColor();
+
     void onGeomPopup( int );
     void onGeomSelectionButton( bool );
 
@@ -131,6 +131,14 @@ private:
     void updateButtons();
     void updateGeomPopup();
 
+    void                          setGroupColor( const SALOMEDS::Color& );
+    SALOMEDS::Color               getGroupColor() const;
+
+    void                          setGroupQColor( const QColor& );
+    QColor                        getGroupQColor() const;
+
+    void                          setDefaultGroupColor();
+
     SMESHGUI*                     mySMESHGUI;              /* Current SMESHGUI object */
     LightApp_SelectionMgr*        mySelectionMgr;          /* User shape selection */
     SMESH_Actor*                  myActor;                 /* Current mesh actor */
@@ -159,8 +167,7 @@ private:
     QPushButton*                  myGroupBtn;
     QLineEdit*                    myGroupLine;
 
-    QCheckBox*                    mySelectColorGroup;
-    QtxIntSpinBox*                myColorSpinBox;
+    QPushButton*                  myColorBtn;
 
     QCheckBox*                    mySelectGeomGroup;
     QToolButton*                  myGeomGroupBtn;
index 36fdceb67e4210ad3b880c566114e4b88d0db017..8ffec5ae3925b9d2085eec526b52e2e31ecda135 100644 (file)
@@ -100,6 +100,7 @@ QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
        if ( p=="client" )        val = QtxValue( globalParam( p ) );
   else if ( p=="type" )          val = QtxValue( myTypes[ind] );
   else if ( p=="elemTypes" )     val = QtxValue( elemTypes( ind ) );
+  else if ( p=="isAutoColor" )   val = QtxValue( isAutoColor( ind ) );
   else if ( p=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
   else if ( p=="labeledTypes" )  val = QtxValue( labeledTypes( ind ) );
   else if ( p=="shrinkMode" )    val = QtxValue( shrinkMode( ind ) );
@@ -252,6 +253,27 @@ QString SMESHGUI_Selection::controlMode( int ind ) const
   return "eNone";
 }
 
+//=======================================================================
+//function : isAutoColor
+//purpose  : 
+//=======================================================================
+
+bool SMESHGUI_Selection::isAutoColor( int ind ) const
+{
+  if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
+  {
+    _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
+    CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
+
+    if ( ! CORBA::is_nil( obj )) {
+      SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
+      if ( ! mesh->_is_nil() )
+        return mesh->GetAutoColor();
+    }
+  }
+  return false;
+}
+
 //=======================================================================
 //function : numberOfNodes
 //purpose  : 
index 6dd5bc27179a984ee3db38cc63c928d63e9af3a2..440c8d4bd81a8bfd76209935c9a3d4fbb9038b45 100644 (file)
@@ -50,6 +50,7 @@ public:
   virtual void     processOwner( const LightApp_DataOwner* );
 
   // got from object, not from actor
+  virtual bool isAutoColor( int ind ) const;
   virtual int numberOfNodes( int ind ) const;
   virtual QVariant isComputable( int ind ) const;
   virtual QVariant hasReference( int ind ) const;
index 3685b46d6bdc54eb5c352ce2c464a5dfefcf7fc3..4ab9313dbb2f525ef4615f9132ed62c53e97f357 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "SMESHGUI.h"
 #include "SMESH_Actor.h"
+#include "SMESH_ActorUtils.h"
 #include "SMESH_ObjectDef.h"
 #include <SMDS_Mesh.hxx>
 
@@ -484,6 +485,22 @@ namespace SMESH {
          std::string aNameVal = aName->Value();
          anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
        }
+
+       SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
+       if(!CORBA::is_nil(aGroup))
+       {
+         SALOMEDS::Color aColor = aGroup->GetColor();
+         if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ) )
+         {
+           int r = 0, g = 0, b = 0;
+           SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
+           aColor.R = (float)r / 255.0;
+           aColor.G = (float)g / 255.0;
+           aColor.B = (float)b / 255.0;
+           aGroup->SetColor( aColor );
+         }
+         anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
+       }
       }
     }
     return anActor;
index 4f4d8a6cf4b2396dd1d4b282411fb53ebabb8ea9..d2fb9a7649024c10d3aa9c0b805ea848e814234f 100644 (file)
@@ -986,7 +986,7 @@ msgstr "Color group"
 
 #Check color group
 msgid "SMESH_CHECK_COLOR"
-msgstr "Color number"
+msgstr "Color"
 
 #%1 SubMeshes
 msgid "SMESH_SUBMESH_SELECTED"
@@ -2385,6 +2385,12 @@ msgstr "Shrink"
 msgid "MEN_AUTO_UPD"
 msgstr "Automatic update"
 
+msgid "MEN_AUTO_COLOR"
+msgstr "Auto color"
+
+msgid "MEN_DISABLE_AUTO_COLOR"
+msgstr "Disable auto color"
+
 msgid "MEN_COLORS"
 msgstr "Colors / Size"
 
@@ -2747,6 +2753,12 @@ msgstr "Shrink"
 msgid "TOP_AUTO_UPD"
 msgstr "Automatic update"
 
+msgid "TOP_AUTO_COLOR"
+msgstr "Auto color"
+
+msgid "TOP_DISABLE_AUTO_COLOR"
+msgstr "Disable auto color"
+
 msgid "TOP_COLORS"
 msgstr "Colors / Size"
 
@@ -3060,6 +3072,12 @@ msgstr "Shrink"
 msgid "STB_AUTO_UPD"
 msgstr "Automatic update"
 
+msgid "STB_AUTO_COLOR"
+msgstr "Auto color"
+
+msgid "STB_DISABLE_AUTO_COLOR"
+msgstr "Disable auto color"
+
 msgid "STB_COLORS"
 msgstr "Colors / Size"
 
index 4d362f69c81147c255b5bf7ed03f8bca1311a40b..15f097a57b2750b7dbc258692c26f21dce7b67bb 100644 (file)
@@ -751,7 +751,7 @@ bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
         "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
         "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
         "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
-        "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList",
+        "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
         "" }; // <- mark of end
     sameMethods.Insert( names );
   }
index e1079ebc7c43c54594303b4afef3a6e8923d8e9b..2d5d08883168734146f5a55a9443f1eac45c8865 100644 (file)
@@ -749,6 +749,53 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   if (aSeq->Value(aLen) < aScriptLength)
     anUpdatedScript += aScript.SubString(aSeq->Value(aLen) + 1, aScriptLength);
 
+
+  SMESH_Gen_i* aSMESHGenI = SMESH_Gen_i::GetSMESHGen();
+  SALOMEDS::Study_ptr aStudy = aSMESHGenI->GetCurrentStudy();
+  if( !CORBA::is_nil(aStudy) )
+  {
+    SALOMEDS::SObject_var aComp = aStudy->FindComponent(ComponentDataType());
+    if( !CORBA::is_nil(aComp) )
+    {
+      SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aComp);
+      for( Itr->InitEx(true); Itr->More(); Itr->Next() )
+      {
+       SALOMEDS::SObject_var aSObj = Itr->Value();
+       CORBA::String_var aName = aSObj->GetName();
+
+       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH_Gen_i::SObjectToObject( aSObj ) );
+       if( !CORBA::is_nil(aMesh) )
+       {
+         bool isAutoColor = aMesh->GetAutoColor();
+         if( isAutoColor )
+         {
+           anUpdatedScript += "\n\t";
+           anUpdatedScript += (char*)aName.in();
+           anUpdatedScript += ".SetAutoColor(1)";
+         }
+       }
+       SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH_Gen_i::SObjectToObject( aSObj ) );
+       if( !CORBA::is_nil(aGroup) )
+       {
+         SALOMEDS::Color aColor = aGroup->GetColor();
+         if ( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 )
+         {
+           anUpdatedScript += "\n\t";
+           anUpdatedScript += (char*)aName.in();
+           anUpdatedScript += ".SetColor(SALOMEDS.Color(";
+           anUpdatedScript += aColor.R;
+           anUpdatedScript += ",";
+           anUpdatedScript += aColor.G;
+           anUpdatedScript += ",";
+           anUpdatedScript += aColor.B;
+           anUpdatedScript += "))";
+         }
+       }
+      }
+    }
+  }
+
   // Remove removed objects
   if ( seqRemoved.Length() > 0 ) {
     anUpdatedScript += "\n\t## some objects were removed";
index d79dfa565e4ac4c8a9f312f4f07a9ecaf509e230..63f4fe46dab4b70e7f879284153fc8543ed6f572 100644 (file)
@@ -1822,6 +1822,18 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
             aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
             aDataset->CloseOnDisk();
 
+           // ouv : NPAL12872
+            // for each mesh open the HDF group basing on its auto color parameter
+           char meshAutoColorName[ 30 ];
+           sprintf( meshAutoColorName, "AutoColorMesh %d", id );
+           int anAutoColor[1];
+           anAutoColor[0] = myImpl->GetAutoColor();
+           aSize[ 0 ] = 1;
+           aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
+           aDataset->CreateOnDisk();
+           aDataset->WriteOnDisk( anAutoColor );
+           aDataset->CloseOnDisk();
+
             // write reference on a shape if exists
             SALOMEDS::SObject_var myRef;
             bool shapeRefFound = false;
@@ -2147,6 +2159,22 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
                    aDataset->WriteOnDisk( aUserName );
                    aDataset->CloseOnDisk();
 
+                   // ouv : NPAL12872
+                   // For each group, create a dataset named "Group <group_persistent_id> Color"
+                   // and store the group's color into it
+                   char grpColorName[ 30 ];
+                   sprintf( grpColorName, "ColorGroup %d", anId );
+                   SALOMEDS::Color aColor = myGroupImpl->GetColor();
+                   double anRGB[3];
+                   anRGB[ 0 ] = aColor.R;
+                   anRGB[ 1 ] = aColor.G;
+                   anRGB[ 2 ] = aColor.B;
+                   aSize[ 0 ] = 3;
+                   aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
+                   aDataset->CreateOnDisk();
+                   aDataset->WriteOnDisk( anRGB );
+                   aDataset->CloseOnDisk();
+
                    // Store the group contents into MED file
                    if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
                      
@@ -2821,6 +2849,21 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
          int newId = myStudyContext->findId( iorString );
          myStudyContext->mapOldToNew( id, newId );
 
+         // ouv : NPAL12872
+         // try to read and set auto color flag
+         char aMeshAutoColorName[ 30 ];
+         sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
+         if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
+         {
+           aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
+           aDataset->OpenOnDisk();
+           size = aDataset->GetSize();
+           int* anAutoColor = new int[ size ];
+           aDataset->ReadFromDisk( anAutoColor );
+           aDataset->CloseOnDisk();
+           myNewMeshImpl->SetAutoColor( (bool)anAutoColor[0] );
+         }
+
           // try to read and set reference to shape
           GEOM::GEOM_Object_var aShapeObject;
           if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
@@ -3425,6 +3468,25 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
               SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
               aGroupBaseDS->SetStoreName( name_dataset );
 
+             // ouv : NPAL12872
+             // Read color of the group
+              char aGroupColorName[ 30 ];
+              sprintf( aGroupColorName, "ColorGroup %d", subid);
+              if ( aGroup->ExistInternalObject( aGroupColorName ) )
+             {
+               aDataset = new HDFdataset( aGroupColorName, aGroup );
+               aDataset->OpenOnDisk();
+               size = aDataset->GetSize();
+               double* anRGB = new double[ size ];
+               aDataset->ReadFromDisk( anRGB );
+               aDataset->CloseOnDisk();
+               SALOMEDS::Color aColor;
+               aColor.R = anRGB[0];
+               aColor.G = anRGB[1];
+               aColor.B = anRGB[2];
+               aGroupBaseDS->SetColor( aColor );
+             }
+
               // Fill group with contents from MED file
               SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
               if ( aGrp )
index 7a75b310be55a430c394341c1e546a0483eb31c0..72fb270451e5db3d18933948a16b8c908be3c33c 100644 (file)
@@ -424,13 +424,13 @@ GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
  *
  */
 //=============================================================================
-CORBA::Long SMESH_GroupBase_i::GetColorNumber()
+SALOMEDS::Color SMESH_GroupBase_i::GetColor()
 {
   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
   if (aGroupDS)
-    return aGroupDS->GetColorGroup();
-  MESSAGE("get color number of a vague group");
-  return 0;
+    return aGroupDS->GetColor();
+  MESSAGE("get color of a group");
+  return SALOMEDS::Color();
 }
 
 //=============================================================================
@@ -438,14 +438,11 @@ CORBA::Long SMESH_GroupBase_i::GetColorNumber()
  *
  */
 //=============================================================================
-void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
+void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
 {
   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
   if (aGroupDS)
-    return aGroupDS->SetColorGroup(color);
-  MESSAGE("set color number of a vague group");
+    return aGroupDS->SetColor(color);
+  MESSAGE("set color of a group");
   return ;
 }
-
-
-
index e6b1813773257fa1161553ddc4f06afcb2fa9085..ea94e970379ab6f0ff51ba1318d9cba5f6c9062b 100644 (file)
@@ -75,8 +75,8 @@ class SMESH_I_EXPORT SMESH_GroupBase_i:
   SMESH_Group* GetSmeshGroup() const;
   SMESHDS_GroupBase* GetGroupDS() const;
 
-   void SetColorNumber(CORBA::Long color);
-   CORBA::Long GetColorNumber();
+  void SetColor(const SALOMEDS::Color& color);
+  SALOMEDS::Color GetColor();
 
 private:
   SMESH_Mesh_i* myMeshServant;
index 274e05f3997c5f3b8e31d448bb5f8cca4ffeabd7..8180e43a8587ee8c72a06e9f86307cc7bfaf8170 100644 (file)
@@ -1392,6 +1392,29 @@ SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
   return aMesh._retn();
 }
 
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  _impl->SetAutoColor(theAutoColor);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  return _impl->GetAutoColor();
+}
+
+
 //=============================================================================
 /*!
  *  Export in different formats
index 8ad4793767e003ea0a11c811bc63626c36d266d5..47e0fb3c51d764da1eeb9a020038dafdd499be2e 100644 (file)
@@ -160,6 +160,15 @@ public:
   SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName )
     throw (SALOME::SALOME_Exception);
 
+  /*!
+   *  Auto color
+   */
+  void SetAutoColor(CORBA::Boolean theAutoColor)
+    throw (SALOME::SALOME_Exception);
+
+  CORBA::Boolean GetAutoColor()
+    throw (SALOME::SALOME_Exception);
+
   /*! Check group names for duplications.
    *  Consider maximum group name length stored in MED file.
    */
index f980b9e93e9b80325b44bf516efef6b5cb0bb1a1..ff7de36036d3451df63c88c5d983c025a5465bd0 100644 (file)
@@ -1893,6 +1893,12 @@ class Mesh:
     def ClearLog(self):
         self.mesh.ClearLog()
 
+    def SetAutoColor(self, color):
+        self.mesh.SetAutoColor(color)
+
+    def GetAutoColor(self):
+        return self.mesh.GetAutoColor()
+
     ## Get the internal Id
     def GetId(self):
         return self.mesh.GetId()