Salome HOME
Remove obsolete staff; redesign Handle-based and CDL-generated classes
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_DuplicateNodesDlg.cxx
index 1ee5ab8c9af6dc321ffc7a2398c707d2932ed009..57428add241d7cb5f2e65714425fc341cc34bb3f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -29,6 +29,7 @@
 
 #include "SMESHGUI.h"
 #include "SMESHGUI_Utils.h"
+#include "SMESHGUI_MeshUtils.h"
 #include "SMESHGUI_VTKUtils.h"
 
 #include <SMESH_TypeFilter.hxx>
@@ -47,7 +48,6 @@
 
 #include <SVTK_ViewWindow.h>
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
 
 // Qt includes
 #include <QApplication>
@@ -63,6 +63,7 @@
 #include <QKeyEvent>
 
 #include <utilities.h>
+#include <SALOMEDSClient_SObject.hxx>
 
 // IDL includes
 #include <SALOMEconfig.h>
@@ -107,6 +108,8 @@ SMESHGUI_DuplicateNodesDlg::SMESHGUI_DuplicateNodesDlg( SMESHGUI* theModule )
   SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
   QPixmap iconWithoutElem (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_NODES")));
   QPixmap iconWithElem (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_NODES_WITH_ELEM")));
+  QPixmap iconElemOnly (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_ELEM_ONLY")));
+  QPixmap iconGrpBoundary (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_GROUP_BOUNDARY")));
   QPixmap iconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
 
   // Main layout
@@ -125,11 +128,19 @@ SMESHGUI_DuplicateNodesDlg::SMESHGUI_DuplicateNodesDlg( SMESHGUI* theModule )
   aRadioButton1->setIcon(iconWithoutElem);
   QRadioButton* aRadioButton2 = new QRadioButton(aConstructorsBox);
   aRadioButton2->setIcon(iconWithElem);
+  QRadioButton* aRadioButton3 = new QRadioButton(aConstructorsBox);
+  aRadioButton3->setIcon(iconElemOnly);
+  QRadioButton* aRadioButton4 = new QRadioButton(aConstructorsBox);
+  aRadioButton4->setIcon(iconGrpBoundary);
   
   aConstructorsBoxLayout->addWidget(aRadioButton1);
   aConstructorsBoxLayout->addWidget(aRadioButton2);
+  aConstructorsBoxLayout->addWidget(aRadioButton3);
+  aConstructorsBoxLayout->addWidget(aRadioButton4);
   myGroupConstructors->addButton(aRadioButton1, 0);
   myGroupConstructors->addButton(aRadioButton2, 1);
+  myGroupConstructors->addButton(aRadioButton3, 2);
+  myGroupConstructors->addButton(aRadioButton4, 3);
 
   // Arguments
   myGroupArguments = new QGroupBox(this);
@@ -155,8 +166,8 @@ SMESHGUI_DuplicateNodesDlg::SMESHGUI_DuplicateNodesDlg( SMESHGUI* theModule )
   myLineEdit3 = new QLineEdit(myGroupArguments);
   myLineEdit3->setReadOnly(true);
 
-  myCheckBoxNewElemGroup = new QCheckBox(tr("CONSTRUCT_NEW_GROUP_ELEMENTS"), myGroupArguments);
-  myCheckBoxNewNodeGroup = new QCheckBox(tr("CONSTRUCT_NEW_GROUP_NODES"), myGroupArguments);
+  myCheckBox1 = new QCheckBox(tr("CONSTRUCT_NEW_GROUP_ELEMENTS"), myGroupArguments);
+  myCheckBox2 = new QCheckBox(tr("CONSTRUCT_NEW_GROUP_NODES"), myGroupArguments);
 
   aGroupArgumentsLayout->addWidget(myTextLabel1,    0, 0);
   aGroupArgumentsLayout->addWidget(mySelectButton1, 0, 1);
@@ -167,8 +178,8 @@ SMESHGUI_DuplicateNodesDlg::SMESHGUI_DuplicateNodesDlg( SMESHGUI* theModule )
   aGroupArgumentsLayout->addWidget(myTextLabel3,    2, 0);
   aGroupArgumentsLayout->addWidget(mySelectButton3, 2, 1);
   aGroupArgumentsLayout->addWidget(myLineEdit3,     2, 2);
-  aGroupArgumentsLayout->addWidget(myCheckBoxNewElemGroup, 3, 0);
-  aGroupArgumentsLayout->addWidget(myCheckBoxNewNodeGroup, 4, 0);
+  aGroupArgumentsLayout->addWidget(myCheckBox1, 3, 0);
+  aGroupArgumentsLayout->addWidget(myCheckBox2, 4, 0);
   aGroupArgumentsLayout->setRowStretch(5, 1);
   
   // Buttons
@@ -200,6 +211,9 @@ SMESHGUI_DuplicateNodesDlg::SMESHGUI_DuplicateNodesDlg( SMESHGUI* theModule )
   aMainLayout->addWidget(myGroupArguments);
   aMainLayout->addWidget(aGroupButtons);
   
+  myCheckBox1->setChecked(true);
+  myCheckBox2->setChecked(true);
+
   // Initialize the dialog
   Init();
 
@@ -213,15 +227,17 @@ SMESHGUI_DuplicateNodesDlg::SMESHGUI_DuplicateNodesDlg( SMESHGUI* theModule )
   connect(mySelectButton2, SIGNAL (clicked()), this, SLOT(onEditCurrentArgument()));
   connect(mySelectButton3, SIGNAL (clicked()), this, SLOT(onEditCurrentArgument()));
 
+  connect(myCheckBox2,    SIGNAL(stateChanged(int)), SLOT(updateButtons()));
+
   connect(myButtonOk,     SIGNAL(clicked()), this, SLOT(onOk()));
-  connect(myButtonClose,  SIGNAL(clicked()), this, SLOT(onClose()));
+  connect(myButtonClose,  SIGNAL(clicked()), this, SLOT(reject()));
   connect(myButtonApply,  SIGNAL(clicked()), this, SLOT(onApply()));
   connect(myButtonHelp,   SIGNAL(clicked()), this, SLOT(onHelp()));
   
   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionChanged()));
 
   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
-  connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(onClose()));
+  connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
 }
 
 /*!
@@ -237,8 +253,6 @@ SMESHGUI_DuplicateNodesDlg::~SMESHGUI_DuplicateNodesDlg()
 void SMESHGUI_DuplicateNodesDlg::Init()
 {
   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
-  myCheckBoxNewElemGroup->setChecked(true);
-  myCheckBoxNewNodeGroup->setChecked(true);
 
   // Set initial parameters
   myBusy = false;
@@ -290,10 +304,14 @@ void SMESHGUI_DuplicateNodesDlg::onConstructorsClicked (int constructorId)
       myTextLabel1->setText(tr("GROUP_NODES_TO_DUPLICATE"));
       myTextLabel2->setText(tr("GROUP_NODES_TO_REPLACE"));
 
-      myCheckBoxNewElemGroup->hide();
-      myCheckBoxNewNodeGroup->show();
+      myCheckBox1->hide();
+      myCheckBox2->show();
+      myCheckBox2->setText( tr("CONSTRUCT_NEW_GROUP_NODES"));
       
       // Hide the third field
+      myTextLabel2->show();
+      mySelectButton2->show();
+      myLineEdit2->show();
       myTextLabel3->hide();
       mySelectButton3->hide();
       myLineEdit3->hide();
@@ -308,18 +326,66 @@ void SMESHGUI_DuplicateNodesDlg::onConstructorsClicked (int constructorId)
       myTextLabel2->setText(tr("GROUP_NODES_NOT_DUPLICATE"));
       myTextLabel3->setText(tr("GROUP_ELEMS_TO_REPLACE"));
       
-      myCheckBoxNewElemGroup->show();
-      myCheckBoxNewNodeGroup->show();
+      myCheckBox1->show();
+      myCheckBox2->show();
+      myCheckBox1->setText( tr("CONSTRUCT_NEW_GROUP_ELEMENTS"));
+      myCheckBox2->setText( tr("CONSTRUCT_NEW_GROUP_NODES"));
 
       // Show the third field
+      myTextLabel2->show();
+      mySelectButton2->show();
+      myLineEdit2->show();
       myTextLabel3->show();
       mySelectButton3->show();
       myLineEdit3->show();
 
+      break;
+    }
+  case 2:
+    {
+      // Set text to the group of arguments and to all the labels
+      myGroupArguments->setTitle(tr("DUPLICATION_ONLY_ELEMS"));
+      myTextLabel1->setText(tr("GROUP_ELEMS_TO_DUPLICATE"));
+      
+      myCheckBox1->show();
+      myCheckBox1->setText( tr("CONSTRUCT_NEW_GROUP_ELEMENTS"));
+      myCheckBox2->hide();
+
+      // Hide the second and the third field
+      myTextLabel2->hide();
+      mySelectButton2->hide();
+      myLineEdit2->hide();
+      myTextLabel3->hide();
+      mySelectButton3->hide();
+      myLineEdit3->hide();
+
+      break;
+    }
+  case 3:
+    {
+      // Set text to the group of arguments and to all the labels
+      myGroupArguments->setTitle(tr("DUPLICATION_GROUP_BOUNDARY"));
+      myTextLabel1->setText(tr("GROUP_VOLUME_GROUPS"));
+      
+      myCheckBox1->show();
+      myCheckBox2->show();
+      myCheckBox1->setText( tr("CREATE_JOINT_ELEMENTS"));
+      myCheckBox2->setText( tr("ON_ALL_BOUNDARIES"));
+
+      // Hide the second and the third field
+      myTextLabel2->hide();
+      mySelectButton2->hide();
+      myLineEdit2->hide();
+      myTextLabel3->hide();
+      mySelectButton3->hide();
+      myLineEdit3->hide();
+
       break;
     }
   }
-  
+  myGroupArguments->hide();
+  myGroupArguments->show();
+  this->resize(this->sizeHint().width(), this->minimumSizeHint().height());
   // Process selection
   onSelectionChanged();
 }
@@ -334,19 +400,22 @@ bool SMESHGUI_DuplicateNodesDlg::onApply()
 
   BusyLocker lock( myBusy );
  
-  bool toCreateElemGroup = myCheckBoxNewElemGroup->isChecked();
-  bool toCreateNodeGroup = myCheckBoxNewNodeGroup->isChecked();
-  int operationMode = myGroupConstructors->checkedId();
+  bool toCreateElemGroup = myCheckBox1->isChecked();
+  bool toCreateNodeGroup = myCheckBox2->isChecked();
+  int operationMode      = myGroupConstructors->checkedId();
   
   // Apply changes
   bool result = false;
   SUIT_OverrideCursor aWaitCursor;
+  QStringList anEntryList;
 
   try {
     SMESH::SMESH_Mesh_var aMesh = myGroups1[0]->GetMesh();
     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
 
-    if ( operationMode == 0 ) {
+    switch ( operationMode ) {
+    case 0:
+    {
       SMESH::ListOfGroups_var g1 = new SMESH::ListOfGroups();
       g1->length( myGroups1.count() );
       for ( int i = 0; i < myGroups1.count(); i++ )
@@ -364,8 +433,10 @@ bool SMESHGUI_DuplicateNodesDlg::onApply()
       else {
         result = aMeshEditor->DoubleNodeGroups( g1.in(), g2.in() );
       }
+      break;
     }
-    else {
+    case 1:
+    {
       SMESH::ListOfGroups_var g1 = new SMESH::ListOfGroups();
       g1->length( myGroups1.count() );
       for ( int i = 0; i < myGroups1.count(); i++ )
@@ -388,15 +459,54 @@ bool SMESHGUI_DuplicateNodesDlg::onApply()
       else {
         result = aMeshEditor->DoubleNodeElemGroups( g1.in(), g2.in(), g3.in() );
       }
+      break;
+    }
+    case 2:
+    {
+      result = true;
+      QString groupName;
+      if ( toCreateElemGroup )
+        groupName = SMESH::UniqueName("DoubleElements");
+      for ( int i = 0; i < myGroups1.count(); i++ )
+      {
+        SMESH::SMESH_Group_var group =
+          aMeshEditor->DoubleElements( myGroups1[i], groupName.toLatin1().data() );
+        if ( group->_is_nil() )
+        {
+          if ( toCreateElemGroup )
+            result = false;
+        }
+        else
+        {
+          if ( _PTR(SObject) so = SMESH::FindSObject( group ))
+            anEntryList.append( so->GetID().c_str() );
+        }
+      }
+      break;
+    }
+    case 3:
+    {
+      bool createJointElems = myCheckBox1->isChecked();
+      bool onAllBoundaries  = myCheckBox2->isChecked();
+
+      SMESH::ListOfGroups_var g1 = new SMESH::ListOfGroups();
+      g1->length( myGroups1.count() );
+      for ( int i = 0; i < myGroups1.count(); i++ )
+        g1[i] = myGroups1[i];
+
+      result = aMeshEditor->DoubleNodesOnGroupBoundaries( g1.in(), createJointElems, onAllBoundaries );
+
+      break;
     }
+    } // switch( operationMode )
   }
   catch (const SALOME::SALOME_Exception& S_ex) {
     SalomeApp_Tools::QtCatchCorbaException(S_ex);
   }
   catch ( const std::exception& exc ) {
     INFOS( "Follow exception was cought:\n\t" << exc.what() );
-  } 
-  catch (...){
+  }
+  catch (...) {
     INFOS( "Unknown exception was cought !!!" );
   }
 
@@ -413,9 +523,14 @@ bool SMESHGUI_DuplicateNodesDlg::onApply()
   SMESHGUI::Modified();
   mySMESHGUI->updateObjBrowser(true);
 
+  if ( !anEntryList.isEmpty())
+    if( LightApp_Application* anApp =
+        dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ))
+      anApp->browseObjects( anEntryList, true, false );
+
   // Reinitialize the dialog
   Init();
-  
+
   return true;
 }
 
@@ -425,19 +540,19 @@ bool SMESHGUI_DuplicateNodesDlg::onApply()
 void SMESHGUI_DuplicateNodesDlg::onOk()
 {
   if (onApply())
-    onClose();
+    reject();
 }
 
 /*!
   \brief SLOT called to close the dialog.
 */
-void SMESHGUI_DuplicateNodesDlg::onClose()
+void SMESHGUI_DuplicateNodesDlg::reject()
 {
   disconnect(mySelectionMgr, 0, this, 0);
   disconnect(mySMESHGUI, 0, this, 0);
   mySMESHGUI->ResetState();
   mySelectionMgr->clearFilters();
-  reject();
+  QDialog::reject();
 }
 
 /*!
@@ -471,15 +586,24 @@ void SMESHGUI_DuplicateNodesDlg::onSelectionChanged()
     // check group of proper type is selected
     if ( ok ) {
       SMESH::ElementType aGroupType = aGroup->GetType();
-      if ( operationMode == 0 ) {
+      switch ( operationMode ) {
+      case 0:
         ok = ( myCurrentLineEdit == myLineEdit1 && aGroupType == SMESH::NODE ) ||
              ( myCurrentLineEdit == myLineEdit2 && aGroupType != SMESH::NODE );
-      }
-      else {
+        break;
+      case 1:
         ok = ( myCurrentLineEdit == myLineEdit1 && ( aGroupType == SMESH::EDGE ||
                                                      aGroupType == SMESH::FACE ) ) ||
              ( myCurrentLineEdit == myLineEdit2 && aGroupType == SMESH::NODE )     ||
              ( myCurrentLineEdit == myLineEdit3 && aGroupType != SMESH::NODE );
+        break;
+      case 2:
+        ok = ( aGroupType != SMESH::NODE );
+        break;
+      case 3:
+        ok = ( aGroupType == SMESH::VOLUME || 
+              aGroupType == SMESH::FACE );
+        break;
       }
     }
     if ( ok ) aGroups << aGroup;
@@ -502,8 +626,15 @@ void SMESHGUI_DuplicateNodesDlg::onSelectionChanged()
     else if ( myCurrentLineEdit == myLineEdit3 ) myGroups3.clear();
     myCurrentLineEdit->clear();
   }
-
   // Enable/disable "Apply and Close" and "Apply" buttons
+  updateButtons();
+}
+
+/*!
+ * \brief Enable/disable "Apply and Close" and "Apply" buttons
+ */
+void SMESHGUI_DuplicateNodesDlg::updateButtons()
+{
   bool isDataValid = isValid();
   myButtonOk->setEnabled( isDataValid );
   myButtonApply->setEnabled( isDataValid );
@@ -533,16 +664,19 @@ void SMESHGUI_DuplicateNodesDlg::onEditCurrentArgument()
 
 /*!
   \brief Check if the input data is valid.
-  \return \c true id the data is valid
+  \return \c true if the data is valid
 */
 bool SMESHGUI_DuplicateNodesDlg::isValid()
 {
-  return myGroupConstructors->checkedId() == 1 ?
-    ( !myGroups1.isEmpty() && !myGroups3.isEmpty()  ) :
-    ( !myGroups1.isEmpty() );
+  switch( myGroupConstructors->checkedId() )
+  {
+  case 1:  return ( !myGroups1.isEmpty() && !myGroups3.isEmpty()  );
+  case 3:  return ( myGroups1.count() > ( myCheckBox2->isChecked() ? 0 : 1 ));
+  default: return !myGroups1.isEmpty();
+  }
+  return false;
 }
 
-
 /*!
   \brief SLOT called when dialog shoud be deativated.
 */
@@ -575,15 +709,6 @@ void SMESHGUI_DuplicateNodesDlg::enterEvent (QEvent*)
   }
 }
 
-/*!
-  \brief Receive close events.
-  Reimplemented from QWidget class.
-*/
-void SMESHGUI_DuplicateNodesDlg::closeEvent (QCloseEvent*)
-{
-  onClose();
-}
-
 /*!
   \brief Receive key press events.
   Reimplemented from QWidget class.