#include "SALOME_Exception.idl"
#include "SALOME_GenericObj.idl"
+#include "SALOMEDS_Attributes.idl"
#include "SMESH_Mesh.idl"
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();
};
/*!
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
*/
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)
}
// 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())
* 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();
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;
}
-
+ }
}
//=============================================================================
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
{
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
#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;
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);
SMESHDS_GroupBase * myGroupDS;
std::string myName;
int myColorNumber;
+ SALOMEDS::Color myColor;
};
#endif
_idDoc = theDocument->NewMesh(theIsEmbeddedMode);
_myMeshDS = theDocument->GetMesh(_idDoc);
_isShapeToMesh = false;
+ _isAutoColor = false;
_myMeshDS->ShapeToMesh( PseudoShape() );
}
}
}
+//=============================================================================
+/*!
+ * 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.
// 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.
*/
map <int, SMESH_subMesh *> _mapSubMesh;
map <int, SMESH_Group *> _mapGroup;
SMESH_Gen * _gen;
+
+ bool _isAutoColor;
TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;
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;
}
//=============================================================================
#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
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;
int myCurIndex;
int myCurID;
SMDS_ElemIteratorPtr myIterator;
- int myColorGroup;
+ SALOMEDS::Color myColor;
};
#endif
}
}
- 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:{
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;
break;
}
+ // Auto-color
+ case 1136:
+ ::AutoColor();
+ break;
+
+ case 1137:
+ ::DisableAutoColor();
+ break;
+
case 1134: // Clipping
case 1133: // Tranparency
case 1132: // Colors / Size
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" );
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 )"),
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
//-------------------------------------------------
//-------------------------------------------------
// 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
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;
+}
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* );
#include "SMESH_TypeFilter.hxx"
#include "SMESH_Actor.h"
+#include "SMESH_ActorUtils.h"
#include "GEOMBase.h"
#include "GEOM_SelectionFilter.h"
#include <qpixmap.h>
#include <qmemarray.h>
#include <qwidgetstack.h>
+#include <qcolordialog.h>
#include <QtxIntSpinBox.h>
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");
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()));
myActor = SMESH::FindActorByObject(myMesh);
SMESH::SetPickable(myActor);
+ setDefaultGroupColor();
+
SALOME_ListIO aList;
mySelectionMgr->selectedObjects( aList );
if( !aList.IsEmpty() )
myName->setText(theGroup->GetName());
myName->home(false);
- myColorSpinBox->setValue( theGroup->GetColorNumber() );
+ SALOMEDS::Color aColor = theGroup->GetColor();
+ setGroupColor( aColor );
myMeshGroupLine->setText(theGroup->GetName());
updateButtons();
}
-//=================================================================================
-// function : onNbColorsChanged()
-// purpose :
-//=================================================================================
-void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
-{
- updateButtons();
-}
-
//=================================================================================
// function : onTypeChanged()
// purpose : Group elements type radio button management
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
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;
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);
}
}
-//=================================================================================
-// 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()
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 );
+}
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 );
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 */
QPushButton* myGroupBtn;
QLineEdit* myGroupLine;
- QCheckBox* mySelectColorGroup;
- QtxIntSpinBox* myColorSpinBox;
+ QPushButton* myColorBtn;
QCheckBox* mySelectGeomGroup;
QToolButton* myGeomGroupBtn;
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 ) );
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 :
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;
#include "SMESHGUI.h"
#include "SMESH_Actor.h"
+#include "SMESH_ActorUtils.h"
#include "SMESH_ObjectDef.h"
#include <SMDS_Mesh.hxx>
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;
#Check color group
msgid "SMESH_CHECK_COLOR"
-msgstr "Color number"
+msgstr "Color"
#%1 SubMeshes
msgid "SMESH_SUBMESH_SELECTED"
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"
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"
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"
"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 );
}
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";
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;
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() ) ) {
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" ) ) {
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 )
*
*/
//=============================================================================
-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();
}
//=============================================================================
*
*/
//=============================================================================
-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 ;
}
-
-
-
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;
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
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.
*/
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()