From 1949fa0f3ec6dac7a1af935b60527903f314f2b7 Mon Sep 17 00:00:00 2001 From: ouv Date: Tue, 6 Nov 2007 08:54:05 +0000 Subject: [PATCH] Bug NPAL12872 - EDF189 GEOM, SMESH : Visualization of groups with many colors --- idl/SMESH_Group.idl | 9 +- idl/SMESH_Mesh.idl | 14 +++ src/DriverMED/DriverMED_Family.cxx | 51 ++++++-- src/DriverMED/DriverMED_Family.h | 3 +- src/SMESH/SMESH_Group.hxx | 8 +- src/SMESH/SMESH_Mesh.cxx | 18 +++ src/SMESH/SMESH_Mesh.hxx | 6 + src/SMESHDS/SMESHDS_GroupBase.cxx | 5 +- src/SMESHDS/SMESHDS_GroupBase.hxx | 14 ++- src/SMESHGUI/SMESHGUI.cxx | 162 ++++++++++++++++++++++++- src/SMESHGUI/SMESHGUI.h | 2 + src/SMESHGUI/SMESHGUI_GroupDlg.cxx | 180 +++++++++++++++++++++------- src/SMESHGUI/SMESHGUI_GroupDlg.h | 15 ++- src/SMESHGUI/SMESHGUI_Selection.cxx | 22 ++++ src/SMESHGUI/SMESHGUI_Selection.h | 1 + src/SMESHGUI/SMESHGUI_VTKUtils.cxx | 17 +++ src/SMESHGUI/SMESH_msg_en.po | 20 +++- src/SMESH_I/SMESH_2smeshpy.cxx | 2 +- src/SMESH_I/SMESH_DumpPython.cxx | 47 ++++++++ src/SMESH_I/SMESH_Gen_i.cxx | 62 ++++++++++ src/SMESH_I/SMESH_Group_i.cxx | 17 ++- src/SMESH_I/SMESH_Group_i.hxx | 4 +- src/SMESH_I/SMESH_Mesh_i.cxx | 23 ++++ src/SMESH_I/SMESH_Mesh_i.hxx | 9 ++ src/SMESH_SWIG/smeshDC.py | 6 + 25 files changed, 628 insertions(+), 89 deletions(-) diff --git a/idl/SMESH_Group.idl b/idl/SMESH_Group.idl index 2ef815f1b..4704e05a0 100644 --- a/idl/SMESH_Group.idl +++ b/idl/SMESH_Group.idl @@ -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(); }; /*! diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index 0e9d8ceb8..4e7b2c561 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -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 */ diff --git a/src/DriverMED/DriverMED_Family.cxx b/src/DriverMED/DriverMED_Family.cxx index 45438ee6d..46ae65491 100644 --- a/src/DriverMED/DriverMED_Family.cxx +++ b/src/DriverMED/DriverMED_Family.cxx @@ -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 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; } - + } } //============================================================================= diff --git a/src/DriverMED/DriverMED_Family.h b/src/DriverMED/DriverMED_Family.h index 64ad65a56..1925a3471 100644 --- a/src/DriverMED/DriverMED_Family.h +++ b/src/DriverMED/DriverMED_Family.h @@ -51,6 +51,7 @@ typedef std::list DriverMED_FamilyPtrList; typedef std::map SMESHDS_SubMeshPtrMap; typedef std::list SMESHDS_GroupBasePtrList; typedef std::set ElementsSet; +typedef std::map 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 on some parts (families) on the basis of the elements type. static diff --git a/src/SMESH/SMESH_Group.hxx b/src/SMESH/SMESH_Group.hxx index 1b13bc578..64df569de 100644 --- a/src/SMESH/SMESH_Group.hxx +++ b/src/SMESH/SMESH_Group.hxx @@ -34,6 +34,9 @@ #include #include +#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 diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 236d400fe..b6c55a0cf 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -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. diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index fc5acef94..d7b86da5d 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -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 _mapSubMesh; map _mapGroup; SMESH_Gen * _gen; + + bool _isAutoColor; TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors; diff --git a/src/SMESHDS/SMESHDS_GroupBase.cxx b/src/SMESHDS/SMESHDS_GroupBase.cxx index e374b723b..da7b0da13 100644 --- a/src/SMESHDS/SMESHDS_GroupBase.cxx +++ b/src/SMESHDS/SMESHDS_GroupBase.cxx @@ -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; } //============================================================================= diff --git a/src/SMESHDS/SMESHDS_GroupBase.hxx b/src/SMESHDS/SMESHDS_GroupBase.hxx index 2bba90532..48fd79120 100644 --- a/src/SMESHDS/SMESHDS_GroupBase.hxx +++ b/src/SMESHDS/SMESHDS_GroupBase.hxx @@ -33,6 +33,10 @@ #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 diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 7ed16cefb..0db20e7da 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -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( 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(anIObject); + if( aMainObject->_is_nil() ) + return; + + aMainObject->SetAutoColor( true ); + + QValueList 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(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( 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(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& 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::const_iterator it = theReservedColors.constBegin(); + QValueList::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; +} diff --git a/src/SMESHGUI/SMESHGUI.h b/src/SMESHGUI/SMESHGUI.h index 7dbab6471..edcf8ab8e 100644 --- a/src/SMESHGUI/SMESHGUI.h +++ b/src/SMESHGUI/SMESHGUI.h @@ -109,6 +109,8 @@ public : virtual void update( const int ); + static SALOMEDS::Color getUniqueColor( const QValueList& ); + public slots: virtual bool deactivateModule( SUIT_Study* ); virtual bool activateModule( SUIT_Study* ); diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index 8968d907c..57220e661 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -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 #include #include +#include #include @@ -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 aAddList; QValueList::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 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 ); +} diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.h b/src/SMESHGUI/SMESHGUI_GroupDlg.h index be6f5ebdd..9fa0d1882 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.h +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.h @@ -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; diff --git a/src/SMESHGUI/SMESHGUI_Selection.cxx b/src/SMESHGUI/SMESHGUI_Selection.cxx index 36fdceb67..8ffec5ae3 100644 --- a/src/SMESHGUI/SMESHGUI_Selection.cxx +++ b/src/SMESHGUI/SMESHGUI_Selection.cxx @@ -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 : diff --git a/src/SMESHGUI/SMESHGUI_Selection.h b/src/SMESHGUI/SMESHGUI_Selection.h index 6dd5bc271..440c8d4bd 100644 --- a/src/SMESHGUI/SMESHGUI_Selection.h +++ b/src/SMESHGUI/SMESHGUI_Selection.h @@ -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; diff --git a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx index 3685b46d6..4ab9313db 100644 --- a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx @@ -24,6 +24,7 @@ #include "SMESHGUI.h" #include "SMESH_Actor.h" +#include "SMESH_ActorUtils.h" #include "SMESH_ObjectDef.h" #include @@ -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; diff --git a/src/SMESHGUI/SMESH_msg_en.po b/src/SMESHGUI/SMESH_msg_en.po index 4f4d8a6cf..d2fb9a764 100644 --- a/src/SMESHGUI/SMESH_msg_en.po +++ b/src/SMESHGUI/SMESH_msg_en.po @@ -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" diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index 4d362f69c..15f097a57 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -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 ); } diff --git a/src/SMESH_I/SMESH_DumpPython.cxx b/src/SMESH_I/SMESH_DumpPython.cxx index e1079ebc7..2d5d08883 100644 --- a/src/SMESH_I/SMESH_DumpPython.cxx +++ b/src/SMESH_I/SMESH_DumpPython.cxx @@ -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"; diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index d79dfa565..63f4fe46d 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -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 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( aGroupBaseDS ); if ( aGrp ) diff --git a/src/SMESH_I/SMESH_Group_i.cxx b/src/SMESH_I/SMESH_Group_i.cxx index 7a75b310b..72fb27045 100644 --- a/src/SMESH_I/SMESH_Group_i.cxx +++ b/src/SMESH_I/SMESH_Group_i.cxx @@ -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 ; } - - - diff --git a/src/SMESH_I/SMESH_Group_i.hxx b/src/SMESH_I/SMESH_Group_i.hxx index e6b181377..ea94e9703 100644 --- a/src/SMESH_I/SMESH_Group_i.hxx +++ b/src/SMESH_I/SMESH_Group_i.hxx @@ -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; diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 274e05f39..8180e43a8 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -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 diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 8ad479376..47e0fb3c5 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -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. */ diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index f980b9e93..ff7de3603 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -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() -- 2.39.2