Salome HOME
Automatic assigning of default name for the group at the dialog box initialization
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
index eac52ffe464ff8ed896b17b59e3c057914559f1c..41270689a12924e118b3c720ce20376b02a5e8bd 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  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
 enum grpSelectionMode {
   grpNoSelection       = -1,
   grpNodeSelection     = 0,
-  grpEdgeSelection     = 1,
-  grpFaceSelection     = 2,
-  grpVolumeSelection   = 3,
-  grpSubMeshSelection  = 4,
-  grpGroupSelection    = 5,
-  grpMeshSelection     = 6,
-  grpGeomSelection     = 7,
-  grpAllSelection      = 8,
+  grpBallSelection     = 1,
+  grpEdgeSelection     = 2,
+  grpFaceSelection     = 3,
+  grpVolumeSelection   = 4,
+  grpSubMeshSelection  = 5,
+  grpGroupSelection    = 6,
+  grpMeshSelection     = 7,
+  grpGeomSelection     = 8,
+  grpAllSelection      = 9,
 };
 
 //=================================================================================
@@ -213,6 +214,7 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
 
   QStringList types;
   types.append( tr( "MESH_NODE" ) );
+  types.append( tr( "SMESH_BALL_ELEM" ) );
   types.append( tr( "SMESH_EDGE" ) );
   types.append( tr( "SMESH_FACE" ) );
   types.append( tr( "SMESH_VOLUME" ) );
@@ -257,22 +259,22 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
   QWidget* wg3 = new QWidget( myWGStack );
 
   /***************************************************************/
-  QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
+  QGroupBox* aContentBox         = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
   QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
   aContentBoxLayout->setMargin( MARGIN );
   aContentBoxLayout->setSpacing( SPACING );
 
-  mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
+  mySelectAll       = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
   myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
 
   myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
-  myElements = new QListWidget( aContentBox );
+  myElements    = new QListWidget( aContentBox );
   myElements->setSelectionMode( QListWidget::ExtendedSelection );
 
   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
-  myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
+  myAddBtn    = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
   myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
-  mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
+  mySortBtn   = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
 
   aContentBoxLayout->addWidget( mySelectAll,       0, 0 );
   aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
@@ -416,7 +418,7 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
   connect(myName,          SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
   connect(myElements,      SIGNAL(itemSelectionChanged()),      this, SLOT(onListSelectionChanged()));
 
-  connect(myFilterBtn,        SIGNAL(clicked()),     this, SLOT(setFilters()));
+  connect(myFilterBtn,     SIGNAL(clicked()),     this, SLOT(setFilters()));
   connect(aFilter2,        SIGNAL(clicked()),     this, SLOT(setFilters()));
   connect(mySelectAll,     SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
   connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
@@ -519,6 +521,22 @@ QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
   return aName;
 }
 
+void  SMESHGUI_GroupDlg::setDefaultName() const
+{
+  QString aResName;
+  _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+  int i=1;
+  QString aPrefix ="Group_";
+  _PTR(SObject) anObj;
+  do
+  {
+    aResName = aPrefix + QString::number( i++ );
+    anObj = aStudy->FindObject( aResName.toLatin1().data() );
+  }
+  while ( anObj );
+  myName->setText(aResName); 
+}
+
 //=================================================================================
 // function : Init()
 // purpose  :
@@ -541,6 +559,8 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
   SetAppropriateActor();
 
   setDefaultGroupColor();
+  setDefaultName();
+
 
   SALOME_ListIO aList;
   mySelectionMgr->selectedObjects( aList );
@@ -562,7 +582,7 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
 // purpose  :
 //=================================================================================
 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
-                              const bool theIsConvert)
+                              const bool                 theIsConvert)
 {
   restoreShowEntityMode();
   myMesh = theGroup->GetMesh();
@@ -581,17 +601,18 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
 
   int aType = 0;
   switch(theGroup->GetType()) {
-  case SMESH::NODE: aType= 0; break;
-  case SMESH::EDGE: aType = 1; break;
-  case SMESH::FACE: aType = 2; break;
-  case SMESH::VOLUME: aType = 3; break;
+  case SMESH::NODE:   aType = 0; break;
+  case SMESH::BALL:   aType = 1; break;
+  case SMESH::EDGE:   aType = 2; break;
+  case SMESH::FACE:   aType = 3; break;
+  case SMESH::VOLUME: aType = 4; break;
   }
   myTypeGroup->button(aType)->setChecked(true);
 
-  myGroup = SMESH::SMESH_Group::_narrow( theGroup );
-  myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
+  myGroup         = SMESH::SMESH_Group::_narrow( theGroup );
+  myGroupOnGeom   = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
   myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
-  myFilter = SMESH::Filter::_nil();
+  myFilter        = SMESH::Filter::_nil();
 
   if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
     return;
@@ -728,12 +749,12 @@ void SMESHGUI_GroupDlg::onTypeChanged (int id)
   if (myTypeId != id) {
     myElements->clear();
     myTypeId = id;
+    if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
+      setSelectionMode(id);
+    else
+      setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
 
-    int curSelMode = mySelectionMode;
-    mySelectionMode = grpNoSelection;
-    setSelectionMode( curSelMode );
     onObjectSelectionChanged();
-
     setShowEntityMode();
   }
 }
@@ -745,13 +766,13 @@ void SMESHGUI_GroupDlg::onTypeChanged (int id)
 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
 {
   if (myGrpTypeId != id) {
+    myGrpTypeId = id;
     myWGStack->setCurrentIndex( id );
     myName->blockSignals(true);
     myName->setText(myOldName);
     myName->blockSignals(false);
-    onSelectGeomGroup(id == 1);
+    onSelectGeomGroup(id != 0);
   }
-  myGrpTypeId = id;
   updateButtons();
 }
 
@@ -774,33 +795,36 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
   if (myMesh->_is_nil())
     return;
   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
-  bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked();
+  bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
   if (mySelectionMode != theMode) {
     // [PAL10408] mySelectionMgr->clearSelected();
     mySelectionMgr->clearFilters();
-    if (myActorsList.count() > 0) {
-      QListIterator<SMESH_Actor*> it( myActorsList );
-      while ( it.hasNext() )
+    SMESH::RemoveFilters();
+
+    if (myActorsList.count() > 0)
+      for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
         it.next()->SetPointRepresentation(false);
-    }
-    else {
+    else
       SMESH::SetPointRepresentation(false);
-    }
+
     switch (theMode) {
     case grpNodeSelection:
-      if (myActorsList.count() > 0) {
-        QListIterator<SMESH_Actor*> it( myActorsList );
-        while ( it.hasNext() )
-          it.next()->SetPointRepresentation(true);
-      }
-      else {
-        SMESH::SetPointRepresentation(true);
+      if ( myGrpTypeId == 0 ) // standalone
+      {
+        if (myActorsList.count() > 0)
+          for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
+            it.next()->SetPointRepresentation(true);
+        else
+          SMESH::SetPointRepresentation(true);
       }
       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
       break;
     case grpEdgeSelection:
       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
       break;
+    case grpBallSelection:
+      if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
+      break;
     case grpFaceSelection:
       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
       break;
@@ -811,11 +835,11 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
 
       SMESH_TypeFilter* f = 0;
       switch (myTypeId) {
-      case 0: f = new SMESH_TypeFilter(SUBMESH); break;
-      case 1: f = new SMESH_TypeFilter(SUBMESH_EDGE); break;
-      case 2: f = new SMESH_TypeFilter(SUBMESH_FACE); break;
-      case 3: f = new SMESH_TypeFilter(SUBMESH_SOLID); break;
-      default:f = new SMESH_TypeFilter(SUBMESH);
+      case grpNodeSelection:   f = new SMESH_TypeFilter(SUBMESH); break;
+      case grpEdgeSelection:   f = new SMESH_TypeFilter(SUBMESH_EDGE); break;
+      case grpFaceSelection:   f = new SMESH_TypeFilter(SUBMESH_FACE); break;
+      case grpVolumeSelection: f = new SMESH_TypeFilter(SUBMESH_SOLID); break;
+      default:                 f = new SMESH_TypeFilter(SUBMESH);
       }
       QList<SUIT_SelectionFilter*> filtList;
       filtList.append( f );
@@ -831,11 +855,12 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
 
       SMESH_TypeFilter* f = 0;
       switch (myTypeId) {
-      case 0: f = new SMESH_TypeFilter(GROUP_NODE); break;
-      case 1: f = new SMESH_TypeFilter(GROUP_EDGE); break;
-      case 2: f = new SMESH_TypeFilter(GROUP_FACE); break;
-      case 3: f = new SMESH_TypeFilter(GROUP_VOLUME); break;
-      default:f = new SMESH_TypeFilter(GROUP);
+      case grpNodeSelection:   f = new SMESH_TypeFilter(GROUP_NODE); break;
+      case grpBallSelection:   f = new SMESH_TypeFilter(GROUP_BALL); break;
+      case grpEdgeSelection:   f = new SMESH_TypeFilter(GROUP_EDGE); break;
+      case grpFaceSelection:   f = new SMESH_TypeFilter(GROUP_FACE); break;
+      case grpVolumeSelection: f = new SMESH_TypeFilter(GROUP_VOLUME); break;
+      default:                 f = new SMESH_TypeFilter(GROUP);
       }
       QList<SUIT_SelectionFilter*> filtList;
       filtList.append( f );
@@ -876,10 +901,11 @@ bool SMESHGUI_GroupDlg::onApply()
 
   SMESH::ElementType aType = SMESH::ALL;
   switch (myTypeId) {
-  case 0: aType = SMESH::NODE; break;
-  case 1: aType = SMESH::EDGE; break;
-  case 2: aType = SMESH::FACE; break;
-  case 3: aType = SMESH::VOLUME; break;
+  case grpNodeSelection:   aType = SMESH::NODE; break;
+  case grpBallSelection:   aType = SMESH::BALL; break;
+  case grpEdgeSelection:   aType = SMESH::EDGE; break;
+  case grpFaceSelection:   aType = SMESH::FACE; break;
+  case grpVolumeSelection: aType = SMESH::VOLUME; break;
   }
 
   bool anIsOk = false;
@@ -1104,7 +1130,7 @@ bool SMESHGUI_GroupDlg::onApply()
       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
 
       /* init for the next operation */
-      myName->setText( "" );
+      setDefaultName();
       myElements->clear();
       myGroup         = SMESH::SMESH_Group::_nil();
       myGroupOnGeom   = SMESH::SMESH_GroupOnGeom::_nil();
@@ -1113,16 +1139,26 @@ bool SMESHGUI_GroupDlg::onApply()
     }
     else
     {
-      myGroup->SetName(myName->text().toLatin1().data());
+      resultGroup->SetName(myName->text().toLatin1().data());
 
       if ( aMeshGroupSO )
         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
           anActor->setName(myName->text().toLatin1().data());
+         QColor c;
+         int delta;
           switch ( myTypeId ) {
-          case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
-          case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
-          case 2:
-          case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
+          case grpNodeSelection:   anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
+          case grpBallSelection:   anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
+          case grpEdgeSelection:   anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
+          case grpVolumeSelection: 
+              SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
+              anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;          
+             break;
+          case grpFaceSelection:   
+          default:
+              SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
+              anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;          
+             break;
           }
         }
     }
@@ -1338,21 +1374,17 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
         else
           aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
         _PTR(SObject) aGroupMainShapeSO =
-          //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
           aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
 
         _PTR(SObject) anObj, aRef;
         bool isRefOrSubShape = false;
         if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
-          //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
           if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
             isRefOrSubShape = true;
           } else {
             _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
             _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
-            //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
             while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
-              //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
               if (aRef->GetID() == aFather->GetID())
                 isRefOrSubShape = true;
               else
@@ -1583,7 +1615,7 @@ void SMESHGUI_GroupDlg::onSelectGroup(bool on)
 
 //=================================================================================
 // function : (onSelectGeomGroup)
-// purpose  : Called when selection in 3D view or ObjectBrowser is changed
+// purpose  : Called when group type changed. on == "on group" or "on filter"
 //=================================================================================
 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
 {
@@ -1594,8 +1626,13 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
     else if (mySelectGroup->isChecked()) {
       mySelectGroup->setChecked(false);
     }
-    myCurrentLineEdit = myGeomGroupLine;
-    updateGeomPopup();
+    if ( myGrpTypeId == 1 ) { // on group
+      myCurrentLineEdit = myGeomGroupLine;
+      updateGeomPopup();
+    }
+    else { // on filter
+      myCurrentLineEdit = 0;
+    }
     setSelectionMode(grpAllSelection);
   }
   else {
@@ -1604,11 +1641,10 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
     myGeomGroupLine->setText( "" );
     myCurrentLineEdit = 0;
     if (myTypeId != -1)
-      setSelectionMode(myTypeId);
+      setSelectionMode( myTypeId );
   }
 }
 
-
 //=================================================================================
 // function : setCurrentSelection()
 // purpose  :
@@ -1655,11 +1691,12 @@ void SMESHGUI_GroupDlg::setFilters()
   SMESH::ElementType aType = SMESH::ALL;
   switch ( myTypeId )
   {
-    case 0 : aType = SMESH::NODE; break;
-    case 1 : aType = SMESH::EDGE; break;
-    case 2 : aType = SMESH::FACE; break;
-    case 3 : aType = SMESH::VOLUME; break;
-    default: return;
+    case grpNodeSelection:   aType = SMESH::NODE; break;
+    case grpBallSelection:   aType = SMESH::BALL; break;
+    case grpEdgeSelection:   aType = SMESH::EDGE; break;
+    case grpFaceSelection:   aType = SMESH::FACE; break;
+    case grpVolumeSelection: aType = SMESH::VOLUME; break;
+    default:                 return;
   }
 
   if ( myFilterDlg == 0 )
@@ -1738,19 +1775,23 @@ void SMESHGUI_GroupDlg::onAdd()
 
   SMESH::ElementType aType = SMESH::ALL;
   switch(myTypeId) {
-  case 0:
+  case grpNodeSelection:
     aType = SMESH::NODE;
     mySelector->SetSelectionMode(NodeSelection);
     break;
-  case 1:
+  case grpBallSelection:
+    aType = SMESH::BALL;
+    mySelector->SetSelectionMode(BallSelection);
+    break;
+  case grpEdgeSelection:
     aType = SMESH::EDGE;
     mySelector->SetSelectionMode(EdgeSelection);
     break;
-  case 2:
+  case grpFaceSelection:
     aType = SMESH::FACE;
     mySelector->SetSelectionMode(FaceSelection);
     break;
-  case 3:
+  case grpVolumeSelection:
     aType = SMESH::VOLUME;
     mySelector->SetSelectionMode(VolumeSelection);
     break;
@@ -1901,10 +1942,10 @@ void SMESHGUI_GroupDlg::onAdd()
 
     SMESH::ElementType aGroupType = SMESH::ALL;
     switch(aGroupOp->GetType(myGeomObjects[0])) {
-    case 7: aGroupType = SMESH::NODE; break;
-    case 6: aGroupType = SMESH::EDGE; break;
-    case 4: aGroupType = SMESH::FACE; break;
-    case 2: aGroupType = SMESH::VOLUME; break;
+    case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
+    case TopAbs_EDGE:   aGroupType = SMESH::EDGE; break;
+    case TopAbs_FACE:   aGroupType = SMESH::FACE; break;
+    case TopAbs_SOLID:  aGroupType = SMESH::VOLUME; break;
     default: myIsBusy = false; return;
     }
 
@@ -1981,10 +2022,11 @@ void SMESHGUI_GroupDlg::onRemove()
 
     SMESH::ElementType aType = SMESH::ALL;
     switch(myTypeId) {
-    case 0: aType = SMESH::NODE; break;
-    case 1: aType = SMESH::EDGE; break;
-    case 2: aType = SMESH::FACE; break;
-    case 3: aType = SMESH::VOLUME; break;
+    case grpNodeSelection:   aType = SMESH::NODE; break;
+    case grpBallSelection:   aType = SMESH::BALL; break;
+    case grpEdgeSelection:   aType = SMESH::EDGE; break;
+    case grpFaceSelection:   aType = SMESH::FACE; break;
+    case grpVolumeSelection: aType = SMESH::VOLUME; break;
     }
 
     if (myCurrentLineEdit == mySubMeshLine) {
@@ -2418,7 +2460,7 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor()
   if( !isAutoColor )
   {
     int r = 0, g = 0, b = 0;
-    SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
+    SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
     aQColor.setRgb( r, g, b );
   }
   else
@@ -2541,10 +2583,11 @@ void SMESHGUI_GroupDlg::setShowEntityMode()
       if (!myStoredShownEntity)
         myStoredShownEntity = actor->GetEntityMode();
       switch ( myTypeId ) {
-      case 0: restoreShowEntityMode(); break;
-      case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
-      case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
-      case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
+      case grpNodeSelection:   restoreShowEntityMode(); break;
+      case grpBallSelection:   actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
+      case grpEdgeSelection:   actor->SetEntityMode( SMESH_Actor::eEdges ); break;
+      case grpFaceSelection:   actor->SetEntityMode( SMESH_Actor::eFaces ); break;
+      case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
       }
     }
   }