Salome HOME
INT PAL 0052968: 'Mesh Information' dialog shows incorrect color of group built from...
authormpa <mpa@opencascade.com>
Mon, 30 Nov 2015 10:31:21 +0000 (13:31 +0300)
committermpa <mpa@opencascade.com>
Mon, 30 Nov 2015 10:31:21 +0000 (13:31 +0300)
src/SMESHDS/SMESHDS_GroupBase.cxx
src/SMESHDS/SMESHDS_GroupBase.hxx
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI_GroupOnShapeDlg.cxx
src/SMESHGUI/SMESHGUI_GroupOpDlg.cxx
src/SMESHGUI/SMESHGUI_GroupOpDlg.h
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx

index a9c378fd621ac033dcfdee2f95a71461ecbee1c8..ef2f2de4a5c5e1c76b7900f9c6cc40f9d19093bb 100644 (file)
@@ -32,6 +32,8 @@
 
 using namespace std;
 
+Quantity_Color SMESHDS_GroupBase::myDefaultColor = Quantity_Color( 0.0, 0.0, 0.0, Quantity_TOC_RGB );
+
 //=============================================================================
 /*!
  *  
@@ -44,7 +46,7 @@ SMESHDS_GroupBase::SMESHDS_GroupBase (const int                 theID,
        myID(theID), myMesh(theMesh), myType(theType), myStoreName(""),
        myCurIndex(0), myCurID(-1)
 {
-  myColor = Quantity_Color( 0.0, 0.0, 0.0, Quantity_TOC_RGB );
+  myColor = myDefaultColor;
 }
 
 //=============================================================================
index 959498e82c59138abaa5c122c146ef6c044b69a8..305ecb8c08a2ec6d0713f6f3a3d77001ccdc56b7 100644 (file)
@@ -85,6 +85,9 @@ class SMESHDS_EXPORT SMESHDS_GroupBase
 
   int GetColorGroup() const;
   
+  static void SetDefaultColor (const Quantity_Color& theColor)
+  { myDefaultColor = theColor;}
+
  protected:
   const SMDS_MeshElement* findInMesh (const int theID) const;
   void resetIterator();
@@ -105,6 +108,8 @@ class SMESHDS_EXPORT SMESHDS_GroupBase
   int                  myCurIndex;
   int                  myCurID;
   SMDS_ElemIteratorPtr myIterator;
+
+  static Quantity_Color myDefaultColor;
 };
 
 #endif
index b3d61a7631e3fc9e7d4a9e00185850af186729ee..d72312ddb456b4aac9d5d6f612c90f5775717c73 100644 (file)
@@ -1951,7 +1951,7 @@ SalomeApp_Module( "SMESH" )
     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
     myComponentSMESH->SetDefaultNbSegments( nbSeg );
 
-    const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif" };
+    const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif", "default_grp_color" };
     for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
       if ( aResourceMgr->hasValue( "SMESH", options[i] ))
       {
@@ -5376,7 +5376,7 @@ void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
       myComponentSMESH->SetDefaultNbSegments( nbSeg );
     }
-    else if ( name == "historical_python_dump" || name == "forget_mesh_on_hyp_modif")
+    else if ( name == "historical_python_dump" || name == "forget_mesh_on_hyp_modif" || name == "default_grp_color" )
     {
       QString val = aResourceMgr->stringValue( "SMESH", name );
       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
index deeaad22ff1481a30d5eeb513726c2c7683933f1..258084e05a8228384a6a8b4a1e658b3347844c83 100644 (file)
@@ -30,7 +30,6 @@
 #include "SMESHGUI.h"
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_GEOMGenUtils.h"
-#include <SMESH_ActorUtils.h>
 
 #include <GeometryGUI.h>
 #include <GEOM_SelectionFilter.h>
@@ -351,17 +350,9 @@ bool SMESHGUI_GroupOnShapeOp::onApply()
 
       //printf( "apply() %s %s\n", (*geomID).latin1(), name.latin1() );
       group = mesh->CreateGroupFromGEOM( elemType, name.toLatin1().data(), geom );
-      if( !group->_is_nil() ) {
-        // set default color for created group
-        QColor c = SMESH::GetColor( "SMESH", "default_grp_color" );
-        SALOMEDS::Color aColor;
-        aColor.R = c.redF();
-        aColor.G = c.greenF();
-        aColor.B = c.blueF();
-        group->SetColor(aColor);
+      if( !group->_is_nil() )
         if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( group ) )
           anEntryList.append( aSObject->GetID().c_str() );
-      }
     }
   }
   SMESHGUI::Modified();
index 69077f967f5ef8ec291f55ad8706943d2ef6b401..6f32383c0706c598664c1c558f07d83c18bb057c 100644 (file)
@@ -31,6 +31,7 @@
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_VTKUtils.h"
 #include "SMESH_TypeFilter.hxx"
+#include <SMESH_ActorUtils.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
@@ -232,6 +233,8 @@ void SMESHGUI_GroupOpDlg::Init()
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode(ActorSelection);
   mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
+
+  setDefaultGroupColor();
 }
 
 /*!
@@ -447,6 +450,14 @@ SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
   return aColor;
 }
 
+/*!
+  \brief Set default color for group
+*/
+void SMESHGUI_GroupOpDlg::setDefaultGroupColor()
+{
+  myColorBtn->setColor( SMESH::GetColor( "SMESH", "default_grp_color", QColor( 255, 170, 0 ) ) );
+}
+
 /*!
   \brief SLOT, called when selection is changed. Current implementation does 
    nothing. The method should be redefined in derived classes to update 
@@ -505,6 +516,7 @@ void SMESHGUI_GroupOpDlg::reset()
 {
   myNameEdit->setText("");
   myNameEdit->setFocus();
+  setDefaultGroupColor();
 }
 
 /*!
index 6f6b70175f49c3402cf7cca13d1464c57057719c..f4191a9428a1a91f08a4eccc13d1557a95cda2f0 100644 (file)
@@ -88,6 +88,7 @@ protected:
   SMESH::ListOfGroups*      convert( const QList<SMESH::SMESH_GroupBase_var>& );
 
   SALOMEDS::Color           getColor() const;
+  void                      setDefaultGroupColor();
 
   void                      setIsApplyAndClose( const bool theFlag );
   bool                      isApplyAndClose() const;
index a63597715faaa7946c371ca4a514fd79e9d94266..d069a3df80269164f5227240927734b06dded12e 100644 (file)
@@ -953,6 +953,22 @@ void SMESH_Gen_i::SetOption(const char* name, const char* value)
       msgToGUI = "preferences/SMESH/forget_mesh_on_hyp_modif/";
       msgToGUI += myToForgetMeshDataOnHypModif ? "true" : "false";
     }
+    else if ( strcmp(name, "default_grp_color") == 0 )
+    {
+      vector<int> color;
+      string str = value;
+      if ( str.at(0) == '#' && str.length() == 7 ) // color should be presented as a string (#aaaaaa, for example)
+        str = str.substr(1);
+        for ( int i = 0; i < str.length()/2; i++ )
+          if ( str.at(i*2) >= '0' && str.at(i*2) <= 'f' && str.at(i*2+1) >= '0' && str.at(i*2+1) <= 'f' )
+            color.push_back( strtol( str.substr( i*2, 2 ).c_str(), NULL, 16 ) );
+      if ( color.size() == 3 ) { // color must have three valid component
+        SMESHDS_GroupBase::SetDefaultColor( Quantity_Color( color[0]/255., color[1]/255., color[2]/255., Quantity_TOC_RGB ) );
+        myDefaultGroupColor = value;
+        msgToGUI = "preferences/SMESH/default_grp_color/";
+        msgToGUI += value;
+      }
+    }
 
     // update preferences in case if SetOption() is invoked from python console
     if ( !msgToGUI.empty() )
@@ -983,6 +999,10 @@ char* SMESH_Gen_i::GetOption(const char* name)
     {
       return CORBA::string_dup( myToForgetMeshDataOnHypModif ? "true" : "false" );
     }
+    if ( strcmp(name, "default_grp_color") == 0 )
+    {
+      return CORBA::string_dup( myDefaultGroupColor.c_str() );
+    }
   }
   return CORBA::string_dup( "" );
 }
index 7f642720517fc7d3a7018437cd9877102002de74..e2be6042d64755912c884bd8cbd906028fcf0615 100644 (file)
@@ -679,6 +679,9 @@ private:
   SALOMEDS::Study_var       myCurrentStudy;     // Current study
   CORBA::Boolean            myIsEmbeddedMode;   // Current mode
 
+  // Default color of groups
+  std::string myDefaultGroupColor;
+
   // To load full mesh data from study at hyp modification or not
   bool myToForgetMeshDataOnHypModif;