Salome HOME
INT PAL 0052683: Parameter "Color group" in the "Create Group" dialog box is empty
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
index 7d2f4b1ae1a78faf735dc14d2439731262aa0e8b..4b33a586b5462396fb917097c7853be4b042fdcf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -61,7 +61,6 @@
 #include <LightApp_SelectionMgr.h>
 
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
 
 #include <SVTK_ViewWindow.h>
 
@@ -447,16 +446,17 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
   mySMESHGUI->SetActiveDialogBox(this);
   mySMESHGUI->SetState(800);
 
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
   mySelectionMode = grpNoSelection;
-  myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
+
+  myMeshFilter    = new SMESH_TypeFilter(SMESH::MESH);
   mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
                                             SMESH_LogicalFilter::LO_OR,
                                             /*takeOwnership=*/true);
-  myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
-                                          SMESH_LogicalFilter::LO_OR,
-                                          /*takeOwnership=*/true);
-  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
-  myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
+  myGroupFilter   = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
+                                            SMESH_LogicalFilter::LO_OR,
+                                            /*takeOwnership=*/true);
+  myGeomFilter    = new GEOM_SelectionFilter( aStudy, true );
 
   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(reject()));
@@ -519,7 +519,7 @@ QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
   bool isUnique = false;
   while (!isUnique) {
     aName = theOperation + "_" + QString::number(++aNumber);
-    isUnique = (aSet.count(aName.toUtf8().data()) == 0);
+    isUnique = (aSet.count(std::string(SMESH::toUtf8(aName))) == 0);
   }
 
   return aName;
@@ -535,7 +535,7 @@ void  SMESHGUI_GroupDlg::setDefaultName() const
   do
   {
     aResName = aPrefix + QString::number( i++ );
-    anObj = aStudy->FindObject( aResName.toUtf8().data() );
+    anObj = aStudy->FindObject( SMESH::toUtf8(aResName) );
   }
   while ( anObj );
   myName->setText(aResName); 
@@ -594,14 +594,14 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
 
   myNameChanged = true;
   myName->blockSignals(true);
-  myName->setText(QString::fromUtf8(theGroup->GetName()));
+  myName->setText(SMESH::fromUtf8(theGroup->GetName()));
   myName->blockSignals(false);
   myName->home(false);
 
   SALOMEDS::Color aColor = theGroup->GetColor();
   setGroupColor( aColor );
 
-  myMeshGroupLine->setText(QString::fromUtf8(theGroup->GetName()));
+  myMeshGroupLine->setText(SMESH::fromUtf8(theGroup->GetName()));
 
   int aType = 0;
   switch(theGroup->GetType()) {
@@ -686,7 +686,7 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
   {
     myNameChanged = true;
     myName->blockSignals(true);
-    myName->setText(QString::fromUtf8(theGroup->GetName()));
+    myName->setText(SMESH::fromUtf8(theGroup->GetName()));
     myName->blockSignals(false);
   }
 
@@ -730,6 +730,17 @@ void SMESHGUI_GroupDlg::updateButtons()
     }
   }
 
+  bool meshHasGeom = ( myMesh->_is_nil() || myMesh->HasShapeToMesh() );
+  if ( myGrpTypeId != 1 )
+  {
+    myGrpTypeGroup->button(1)->setEnabled( meshHasGeom );
+  }
+  else
+  {
+    myGeomGroupBtn->setEnabled( meshHasGeom );
+    myGeomGroupLine->setEnabled( meshHasGeom );
+  }
+
   myOKBtn->setEnabled(enable);
   myApplyBtn->setEnabled(enable);
 }
@@ -1041,7 +1052,7 @@ bool SMESHGUI_GroupDlg::onApply()
 
       if (myGeomObjects->length() == 1) {
         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
-                                                    myName->text().toUtf8().data(),
+                                                    SMESH::toUtf8(myName->text()),
                                                     myGeomObjects[0]);
       }
       else {
@@ -1083,11 +1094,11 @@ bool SMESHGUI_GroupDlg::onApply()
           aNewGeomGroupName += myName->text();
           SALOMEDS::SObject_var aNewGroupSO =
             geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
-                                aNewGeomGroupName.toUtf8().data(), aMeshShape);
+                                SMESH::toUtf8(aNewGeomGroupName), aMeshShape);
         }
 
         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
-                                                    myName->text().toUtf8().data(),
+                                                    SMESH::toUtf8(myName->text()),
                                                     aGroupVar);
       }
       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
@@ -1110,7 +1121,7 @@ bool SMESHGUI_GroupDlg::onApply()
         return false;
 
       myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
-                                                      myName->text().toUtf8().data(),
+                                                      SMESH::toUtf8(myName->text()),
                                                       myFilter);
 
       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
@@ -1135,6 +1146,8 @@ bool SMESHGUI_GroupDlg::onApply()
     if( aMeshGroupSO )
       anEntryList.append( aMeshGroupSO->GetID().c_str() );
 
+    resultGroup->SetName(SMESH::toUtf8(myName->text().trimmed()));
+
     if ( isCreation )
     {
       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
@@ -1151,13 +1164,12 @@ bool SMESHGUI_GroupDlg::onApply()
     }
     else
     {
-      resultGroup->SetName(myName->text().toUtf8().data());
-
       if ( aMeshGroupSO )
       {
-        if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
+        if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
+        {
+          Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
           if ( isConversion ) { // need to reset TVisualObj and actor
-            Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
             SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
             SMESH::Update( anIO,true);
             myActorsList.clear();
@@ -1165,7 +1177,7 @@ bool SMESHGUI_GroupDlg::onApply()
             if ( !anActor ) return false;
             myActorsList.append( anActor );
           }
-          anActor->setName(myName->text().toUtf8().data());
+          anActor->setName(SMESH::toUtf8(myName->text()));
           QColor c;
           int delta;
           switch ( myTypeId ) {
@@ -1183,12 +1195,17 @@ bool SMESHGUI_GroupDlg::onApply()
             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;          
             break;
           }
+          // update a visible group accoding to a changed contents
+          if ( !isConversion && anActor->GetVisibility() )
+          {
+            SMESH::Update( anIO, true );
+            SMESH::RepaintCurrentView();
+          }
         }
       }
     }
     SMESHGUI::Modified();
     mySMESHGUI->updateObjBrowser(true);
-    SMESH::UpdateView(); // asv: fix of BUG PAL5515
     mySelectionMgr->clearSelected();
 
     if( LightApp_Application* anApp =
@@ -1312,6 +1329,9 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
         // any visible actor of group or submesh of myMesh
         SetAppropriateActor();
 
+        setDefaultGroupColor();
+        setDefaultName();
+
         aString = aList.First()->getName();
         myMeshGroupLine->setText(aString);
         myMeshGroupLine->home( false );
@@ -1645,7 +1665,7 @@ void SMESHGUI_GroupDlg::onSelectGroup(bool on)
 
 //=================================================================================
 // function : (onSelectGeomGroup)
-// purpose  : Called when group type changed. on == "on group" or "on filter"
+// purpose  : Called when group type changed. on == "on geometry" or "on filter"
 //=================================================================================
 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
 {
@@ -1656,7 +1676,7 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
     else if (mySelectGroup->isChecked()) {
       mySelectGroup->setChecked(false);
     }
-    if ( myGrpTypeId == 1 ) { // on group
+    if ( myGrpTypeId == 1 ) { // on geometry
       myCurrentLineEdit = myGeomGroupLine;
       updateGeomPopup();
     }
@@ -1744,7 +1764,11 @@ void SMESHGUI_GroupDlg::setFilters()
     myFilterDlg->Init( aType );
   }
 
+  bool isStandalone = ( sender() == myFilterBtn );
+  myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
+                           /*diffSources=*/isStandalone );
   myFilterDlg->SetMesh( myMesh );
+  myFilterDlg->SetGroup( myGroupOnFilter );
   myFilterDlg->SetSelection();
   myFilterDlg->SetSourceWg( myElements, false );