Back to index

salome-smesh  6.5.0
SMESHGUI_RemoveNodesDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_RemoveNodesDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_RemoveNodesDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_MeshUtils.h"
00034 #include "SMESHGUI_IdValidator.h"
00035 #include "SMESHGUI_FilterDlg.h"
00036 
00037 #include <SMESH_Actor.h>
00038 #include <SMDS_Mesh.hxx>
00039 
00040 // SALOME GUI includes
00041 #include <SUIT_ResourceMgr.h>
00042 #include <SUIT_Desktop.h>
00043 #include <SUIT_Session.h>
00044 #include <SUIT_MessageBox.h>
00045 
00046 #include <LightApp_Application.h>
00047 #include <LightApp_SelectionMgr.h>
00048 #include <SalomeApp_Tools.h>
00049 
00050 #include <SVTK_Selector.h>
00051 #include <SVTK_ViewModel.h>
00052 #include <SVTK_ViewWindow.h>
00053 #include <SALOME_ListIO.hxx>
00054 
00055 // OCCT includes
00056 #include <TColStd_MapOfInteger.hxx>
00057 
00058 // Qt includes
00059 #include <QGroupBox>
00060 #include <QLabel>
00061 #include <QLineEdit>
00062 #include <QPushButton>
00063 #include <QRadioButton>
00064 #include <QVBoxLayout>
00065 #include <QHBoxLayout>
00066 #include <QKeyEvent>
00067 #include <QButtonGroup>
00068 
00069 // IDL includes
00070 #include <SALOMEconfig.h>
00071 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00072 
00073 #define SPACING 6
00074 #define MARGIN  11
00075 
00076 //=================================================================================
00077 // class    : SMESHGUI_RemoveNodesDlg()
00078 // purpose  :
00079 //=================================================================================
00080 SMESHGUI_RemoveNodesDlg
00081 ::SMESHGUI_RemoveNodesDlg(SMESHGUI* theModule)
00082   : QDialog(SMESH::GetDesktop(theModule)),
00083     mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
00084     mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
00085     mySMESHGUI(theModule),
00086     myBusy(false),
00087     myFilterDlg(0)
00088 {
00089   setModal( false );
00090   setAttribute( Qt::WA_DeleteOnClose, true );
00091   setWindowTitle(tr("SMESH_REMOVE_NODES_TITLE"));
00092   setSizeGripEnabled(true);
00093   
00094   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_NODE")));
00095   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00096 
00097   QVBoxLayout* SMESHGUI_RemoveNodesDlgLayout = new QVBoxLayout(this);
00098   SMESHGUI_RemoveNodesDlgLayout->setSpacing(SPACING);
00099   SMESHGUI_RemoveNodesDlgLayout->setMargin(MARGIN);
00100 
00101   /***************************************************************/
00102   GroupConstructors = new QGroupBox(tr("SMESH_NODES"), this);
00103   QButtonGroup* ButtonGroup = new QButtonGroup(this);
00104   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
00105   GroupConstructorsLayout->setSpacing(SPACING);
00106   GroupConstructorsLayout->setMargin(MARGIN);
00107 
00108   Constructor1 = new QRadioButton(GroupConstructors);
00109   Constructor1->setIcon(image0);
00110   Constructor1->setChecked(true);
00111 
00112   GroupConstructorsLayout->addWidget(Constructor1);
00113   ButtonGroup->addButton(Constructor1, 0);
00114 
00115   /***************************************************************/
00116   GroupC1 = new QGroupBox(tr("SMESH_REMOVE"), this);
00117   QHBoxLayout* GroupC1Layout = new QHBoxLayout(GroupC1);
00118   GroupC1Layout->setSpacing(SPACING);
00119   GroupC1Layout->setMargin(MARGIN);
00120 
00121   TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
00122   SelectButtonC1A1 = new QPushButton(GroupC1);
00123   SelectButtonC1A1->setIcon(image1);
00124   LineEditC1A1 = new QLineEdit(GroupC1);
00125   LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this));
00126   LineEditC1A1->setMaxLength(-1);
00127   QPushButton* filterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupC1 );
00128   connect(filterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
00129 
00130   GroupC1Layout->addWidget(TextLabelC1A1);
00131   GroupC1Layout->addWidget(SelectButtonC1A1);
00132   GroupC1Layout->addWidget(LineEditC1A1);
00133   GroupC1Layout->addWidget(filterBtn );
00134 
00135   /***************************************************************/
00136   GroupButtons = new QGroupBox(this);
00137   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00138   GroupButtonsLayout->setSpacing(SPACING);
00139   GroupButtonsLayout->setMargin(MARGIN);
00140 
00141   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00142   buttonOk->setAutoDefault(true);
00143   buttonOk->setDefault(true);
00144   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00145   buttonApply->setAutoDefault(true);
00146   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00147   buttonCancel->setAutoDefault(true);
00148   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00149   buttonHelp->setAutoDefault(true);
00150 
00151   GroupButtonsLayout->addWidget(buttonOk);
00152   GroupButtonsLayout->addSpacing(10);
00153   GroupButtonsLayout->addWidget(buttonApply);
00154   GroupButtonsLayout->addSpacing(10);
00155   GroupButtonsLayout->addStretch();
00156   GroupButtonsLayout->addWidget(buttonCancel);
00157   GroupButtonsLayout->addWidget(buttonHelp);
00158 
00159   /***************************************************************/
00160   SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupConstructors);
00161   SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupC1);
00162   SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupButtons);
00163 
00164   myHelpFileName = "removing_nodes_and_elements_page.html#removing_nodes_anchor";
00165 
00166   Init(); /* Initialisations */
00167 }
00168 
00169 //=================================================================================
00170 // function : ~SMESHGUI_RemoveNodesDlg()
00171 // purpose  : Destroys the object and frees any allocated resources
00172 //=================================================================================
00173 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
00174 {
00175   if ( myFilterDlg ) {
00176     myFilterDlg->setParent( 0 );
00177     delete myFilterDlg;
00178     myFilterDlg = 0;
00179   }
00180 }
00181 
00182 //=================================================================================
00183 // function : Init()
00184 // purpose  :
00185 //=================================================================================
00186 void SMESHGUI_RemoveNodesDlg::Init()
00187 {
00188   myConstructorId = 0;
00189   Constructor1->setChecked(true);
00190   myEditCurrentArgument = LineEditC1A1;
00191 
00192   myNbOkNodes = 0;
00193   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00194   myActor = 0;
00195   myBusy = false;
00196 
00197   /* signals and slots connections */
00198   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00199   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00200   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00201   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00202 
00203   connect(SelectButtonC1A1, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
00204   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00205   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00206   /* to close dialog if study change */
00207   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
00208   connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
00209           SLOT(onTextChange(const QString&)));
00210   
00211   SMESH::SetPointRepresentation(true);
00212   
00213   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00214     aViewWindow->SetSelectionMode(NodeSelection);
00215 
00216   SelectionIntoArgument();
00217 }
00218 
00219 //=================================================================================
00220 // function : ClickOnApply()
00221 // purpose  :
00222 //=================================================================================
00223 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
00224 {
00225   if (mySMESHGUI->isActiveStudyLocked())
00226     return;
00227 
00228   if (myNbOkNodes) {
00229     QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
00230     SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
00231     anArrayOfIdeces->length(aListId.count());
00232     for (int i = 0; i < aListId.count(); i++)
00233       anArrayOfIdeces[i] = aListId[ i ].toInt();
00234 
00235     bool aResult = false;
00236     try {
00237       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00238       aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.in());
00239     } catch (const SALOME::SALOME_Exception& S_ex) {
00240       SalomeApp_Tools::QtCatchCorbaException(S_ex);
00241       myEditCurrentArgument->clear();
00242     } catch (...){
00243       myEditCurrentArgument->clear();
00244     }
00245 
00246     if (aResult) {
00247       myEditCurrentArgument->clear();
00248       mySelector->ClearIndex();
00249       SMESH::UpdateView();
00250       SMESHGUI::Modified();
00251     }
00252 
00253     SMESH::SetPointRepresentation(true);
00254   }
00255 }
00256 
00257 //=================================================================================
00258 // function : ClickOnOk()
00259 // purpose  :
00260 //=================================================================================
00261 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
00262 {
00263   ClickOnApply();
00264   ClickOnCancel();
00265 }
00266 
00267 //=================================================================================
00268 // function : ClickOnCancel()
00269 // purpose  :
00270 //=================================================================================
00271 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
00272 {
00273   //mySelectionMgr->clearSelected();
00274   if (SMESH::GetCurrentVtkView()) {
00275     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
00276     SMESH::SetPointRepresentation(false);
00277   }
00278   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00279     aViewWindow->SetSelectionMode(ActorSelection);
00280   disconnect(mySelectionMgr, 0, this, 0);
00281   mySelectionMgr->clearFilters();
00282   mySMESHGUI->ResetState();
00283   reject();
00284 }
00285 
00286 //=================================================================================
00287 // function : ClickOnHelp()
00288 // purpose  :
00289 //=================================================================================
00290 void SMESHGUI_RemoveNodesDlg::ClickOnHelp()
00291 {
00292   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00293   if (app) 
00294     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00295   else {
00296     QString platform;
00297 #ifdef WIN32
00298     platform = "winapplication";
00299 #else
00300     platform = "application";
00301 #endif
00302     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00303                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00304                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00305                                                                  platform)).
00306                              arg(myHelpFileName));
00307   }
00308 }
00309 
00310 //=======================================================================
00311 //function : onTextChange
00312 //purpose  :
00313 //=======================================================================
00314 void SMESHGUI_RemoveNodesDlg::onTextChange(const QString& theNewText)
00315 {
00316   if (myBusy) return;
00317   myBusy = true;
00318 
00319   myNbOkNodes = 0;
00320 
00321   // hilight entered nodes
00322   if(myActor){
00323     if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
00324       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
00325            
00326       TColStd_MapOfInteger newIndices;
00327       
00328       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00329       for (int i = 0; i < aListId.count(); i++) {
00330         if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
00331           newIndices.Add(aNode->GetID());
00332           myNbOkNodes++;
00333         }
00334       }
00335 
00336       mySelector->AddOrRemoveIndex(anIO,newIndices,false);
00337       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00338         aViewWindow->highlight(anIO,true,true);
00339     }
00340   }
00341 
00342   myBusy = false;
00343   updateButtons();
00344 }
00345 
00346 //=================================================================================
00347 // function : SelectionIntoArgument()
00348 // purpose  : Called when selection as changed or other case
00349 //=================================================================================
00350 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
00351 {
00352   if (myBusy) return;                                  // busy
00353   if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
00354   if (!GroupButtons->isEnabled()) return;              // inactive
00355     
00356   // clear
00357 
00358   myNbOkNodes = 0;
00359   myActor = 0;
00360 
00361   myBusy = true;
00362   myEditCurrentArgument->setText("");
00363   myBusy = false;
00364 
00365   // get selected mesh
00366   SALOME_ListIO aList;
00367   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00368 
00369   int nbSel = aList.Extent();
00370   if (nbSel == 1) {
00371 
00372     Handle(SALOME_InteractiveObject) anIO = aList.First();
00373     myMesh = SMESH::GetMeshByIO(anIO);
00374 
00375     if (!myMesh->_is_nil()) {
00376 
00377       myActor = SMESH::FindActorByEntry(anIO->getEntry());
00378       if (myActor) {
00379 
00380         // get selected nodes
00381         QString aString = "";
00382         int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
00383         if (nbNodes > 0) {
00384           myBusy = true;
00385           myEditCurrentArgument->setText(aString);
00386           myBusy = false;
00387           
00388           // OK
00389           
00390           myNbOkNodes = nbNodes;
00391         } // if (nbNodes > 0)
00392       } // if (myActor)
00393     } // if (!myMesh->_is_nil())
00394   } // if (nbSel == 1)
00395 
00396   updateButtons();        
00397 }
00398 
00399 //=================================================================================
00400 // function : SetEditCurrentArgument()
00401 // purpose  :
00402 //=================================================================================
00403 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
00404 {
00405   QPushButton* send = (QPushButton*)sender();
00406   switch (myConstructorId) {
00407   case 0: /* default constructor */
00408     {
00409       if(send == SelectButtonC1A1) {
00410         LineEditC1A1->setFocus();
00411         myEditCurrentArgument = LineEditC1A1;
00412       }
00413       SelectionIntoArgument();
00414       break;
00415     }
00416   }
00417 }
00418 
00419 //=================================================================================
00420 // function : DeactivateActiveDialog()
00421 // purpose  :
00422 //=================================================================================
00423 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
00424 {
00425   if (GroupConstructors->isEnabled()) {
00426     GroupConstructors->setEnabled(false);
00427     GroupC1->setEnabled(false);
00428     GroupButtons->setEnabled(false);
00429     mySMESHGUI->ResetState(); // ??
00430     mySMESHGUI->SetActiveDialogBox(0); // ??
00431   }
00432 }
00433 
00434 //=================================================================================
00435 // function : ActivateThisDialog()
00436 // purpose  :
00437 //=================================================================================
00438 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
00439 {
00440   /* Emit a signal to deactivate the active dialog */
00441   mySMESHGUI->EmitSignalDeactivateDialog();
00442 
00443   GroupConstructors->setEnabled(true);
00444   GroupC1->setEnabled(true);
00445   GroupButtons->setEnabled(true);
00446 
00447   mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
00448 
00449   SMESH::SetPointRepresentation(true);
00450   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00451     aViewWindow->SetSelectionMode(NodeSelection);
00452 
00453   SelectionIntoArgument(); // ??
00454 }
00455 
00456 //=================================================================================
00457 // function : enterEvent()
00458 // purpose  :
00459 //=================================================================================
00460 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent*)
00461 {
00462   if (!GroupConstructors->isEnabled())
00463     ActivateThisDialog();
00464 }
00465 
00466 //=================================================================================
00467 // function : closeEvent()
00468 // purpose  :
00469 //=================================================================================
00470 void SMESHGUI_RemoveNodesDlg::closeEvent(QCloseEvent*)
00471 {
00472   /* same than click on cancel button */
00473   ClickOnCancel();
00474 }
00475 
00476 //=======================================================================
00477 //function : hideEvent
00478 //purpose  : caused by ESC key
00479 //=======================================================================
00480 void SMESHGUI_RemoveNodesDlg::hideEvent( QHideEvent* )
00481 {
00482   if (!isMinimized())
00483     ClickOnCancel();
00484 }
00485 
00486 //=================================================================================
00487 // function : keyPressEvent()
00488 // purpose  :
00489 //=================================================================================
00490 void SMESHGUI_RemoveNodesDlg::keyPressEvent( QKeyEvent* e )
00491 {
00492   QDialog::keyPressEvent( e );
00493   if ( e->isAccepted() )
00494     return;
00495 
00496   if ( e->key() == Qt::Key_F1 ) {
00497     e->accept();
00498     ClickOnHelp();
00499   }
00500 }
00501 
00502 //=================================================================================
00503 // function : setFilters()
00504 // purpose  : SLOT. Called when "Filter" button pressed.
00505 //=================================================================================
00506 void SMESHGUI_RemoveNodesDlg::setFilters()
00507 {
00508   if(myMesh->_is_nil()) {
00509     SUIT_MessageBox::critical(this,
00510                               tr("SMESH_ERROR"),
00511                               tr("NO_MESH_SELECTED"));
00512    return;
00513   }
00514   if ( !myFilterDlg )
00515     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::NODE );
00516 
00517   myFilterDlg->SetSelection();
00518   myFilterDlg->SetMesh( myMesh );
00519   myFilterDlg->SetSourceWg( LineEditC1A1 );
00520 
00521   myFilterDlg->show();
00522 }
00523 
00524 //=================================================================================
00525 // function : updateButtons
00526 // purpose  : enable / disable control buttons
00527 //=================================================================================
00528 void SMESHGUI_RemoveNodesDlg::updateButtons()
00529 {
00530   buttonOk->setEnabled(myNbOkNodes > 0);
00531   buttonApply->setEnabled(myNbOkNodes > 0);
00532 }