00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_RemoveElementsDlg.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
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
00056 #include <TColStd_MapOfInteger.hxx>
00057
00058
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
00070 #include <SALOMEconfig.h>
00071 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00072
00073 #define SPACING 6
00074 #define MARGIN 11
00075
00076
00077
00078
00079
00080 SMESHGUI_RemoveElementsDlg
00081 ::SMESHGUI_RemoveElementsDlg(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_ELEMENTS_TITLE"));
00092 setSizeGripEnabled(true);
00093
00094 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_ELEMENT")));
00095 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00096
00097 QVBoxLayout* SMESHGUI_RemoveElementsDlgLayout = new QVBoxLayout(this);
00098 SMESHGUI_RemoveElementsDlgLayout->setSpacing(SPACING);
00099 SMESHGUI_RemoveElementsDlgLayout->setMargin(MARGIN);
00100
00101
00102 GroupConstructors = new QGroupBox(tr("SMESH_ELEMENTS"), 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_ELEMENTS"), 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_RemoveElementsDlgLayout->addWidget(GroupConstructors);
00161 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupC1);
00162 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupButtons);
00163
00164 myHelpFileName = "removing_nodes_and_elements_page.html#removing_elements_anchor";
00165
00166 Init();
00167 }
00168
00169
00170
00171
00172
00173 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
00174 {
00175 if ( myFilterDlg ) {
00176 myFilterDlg->setParent( 0 );
00177 delete myFilterDlg;
00178 myFilterDlg = 0;
00179 }
00180 }
00181
00182
00183
00184
00185
00186 void SMESHGUI_RemoveElementsDlg::Init()
00187 {
00188 myConstructorId = 0;
00189 Constructor1->setChecked(true);
00190 myEditCurrentArgument = LineEditC1A1;
00191
00192 myNbOkElements = 0;
00193 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00194 myActor = 0;
00195 myBusy = false;
00196
00197
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
00207 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
00208 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
00209 SLOT(onTextChange(const QString&)));
00210
00211 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00212 aViewWindow->SetSelectionMode(CellSelection);
00213
00214 SelectionIntoArgument();
00215 }
00216
00217
00218
00219
00220
00221 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
00222 {
00223 if (mySMESHGUI->isActiveStudyLocked())
00224 return;
00225
00226 if (myNbOkElements) {
00227 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
00228 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
00229 anArrayOfIdeces->length(aListId.count());
00230 for (int i = 0; i < aListId.count(); i++)
00231 anArrayOfIdeces[i] = aListId[ i ].toInt();
00232
00233 bool aResult = false;
00234 try {
00235 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00236 aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.in());
00237 } catch (const SALOME::SALOME_Exception& S_ex) {
00238 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00239 myEditCurrentArgument->clear();
00240 } catch (...){
00241 myEditCurrentArgument->clear();
00242 }
00243
00244 if (aResult) {
00245 myEditCurrentArgument->clear();
00246 mySelector->ClearIndex();
00247 SMESH::UpdateView();
00248 SMESHGUI::Modified();
00249 }
00250 }
00251 }
00252
00253
00254
00255
00256
00257 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
00258 {
00259 ClickOnApply();
00260 ClickOnCancel();
00261 }
00262
00263
00264
00265
00266
00267 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
00268 {
00269 if (SMESH::GetCurrentVtkView())
00270 SMESH::RemoveFilters();
00271
00272 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00273 aViewWindow->SetSelectionMode(ActorSelection);
00274 disconnect(mySelectionMgr, 0, this, 0);
00275 mySelectionMgr->clearFilters();
00276 mySMESHGUI->ResetState();
00277 reject();
00278 }
00279
00280
00281
00282
00283
00284 void SMESHGUI_RemoveElementsDlg::ClickOnHelp()
00285 {
00286 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00287 if (app)
00288 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00289 else {
00290 QString platform;
00291 #ifdef WIN32
00292 platform = "winapplication";
00293 #else
00294 platform = "application";
00295 #endif
00296 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00297 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00298 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00299 platform)).
00300 arg(myHelpFileName));
00301 }
00302 }
00303
00304
00305
00306
00307
00308 void SMESHGUI_RemoveElementsDlg::onTextChange(const QString& theNewText)
00309 {
00310 if (myBusy) return;
00311 myBusy = true;
00312
00313 myNbOkElements = 0;
00314
00315
00316 if(myActor){
00317 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
00318 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
00319
00320 TColStd_MapOfInteger newIndices;
00321
00322 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00323 for (int i = 0; i < aListId.count(); i++) {
00324 if(const SMDS_MeshElement *anElem = aMesh->FindElement(aListId[i].toInt())) {
00325 newIndices.Add(anElem->GetID());
00326 myNbOkElements++;
00327 }
00328 }
00329
00330 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
00331 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00332 aViewWindow->highlight(anIO,true,true);
00333 }
00334 }
00335
00336 myBusy = false;
00337 updateButtons();
00338 }
00339
00340
00341
00342
00343
00344 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
00345 {
00346 if (myBusy) return;
00347 if (myFilterDlg && myFilterDlg->isVisible()) return;
00348 if (!GroupButtons->isEnabled()) return;
00349
00350
00351
00352 myNbOkElements = 0;
00353 myActor = 0;
00354
00355 myBusy = true;
00356 myEditCurrentArgument->setText("");
00357 myBusy = false;
00358
00359
00360
00361 SALOME_ListIO aList;
00362 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00363
00364 int nbSel = aList.Extent();
00365 if (nbSel == 1) {
00366
00367 Handle(SALOME_InteractiveObject) anIO = aList.First();
00368 myMesh = SMESH::GetMeshByIO(anIO);
00369
00370 if (!myMesh->_is_nil()) {
00371
00372 myActor = SMESH::FindActorByEntry(anIO->getEntry());
00373 if (myActor) {
00374
00375
00376 QString aString = "";
00377 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aString);
00378 if (nbElems > 0) {
00379 myBusy = true;
00380 myEditCurrentArgument->setText(aString);
00381 myBusy = false;
00382
00383
00384
00385 myNbOkElements = nbElems;
00386 }
00387 }
00388 }
00389 }
00390
00391 updateButtons();
00392 }
00393
00394
00395
00396
00397
00398 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
00399 {
00400 QPushButton* send = (QPushButton*)sender();
00401 switch (myConstructorId) {
00402 case 0:
00403 {
00404 if(send == SelectButtonC1A1) {
00405 LineEditC1A1->setFocus();
00406 myEditCurrentArgument = LineEditC1A1;
00407 }
00408 SelectionIntoArgument();
00409 break;
00410 }
00411 }
00412 }
00413
00414
00415
00416
00417
00418 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
00419 {
00420 if (GroupConstructors->isEnabled()) {
00421 GroupConstructors->setEnabled(false);
00422 GroupC1->setEnabled(false);
00423 GroupButtons->setEnabled(false);
00424 mySMESHGUI->ResetState();
00425 mySMESHGUI->SetActiveDialogBox(0);
00426 }
00427 }
00428
00429
00430
00431
00432
00433 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
00434 {
00435
00436 mySMESHGUI->EmitSignalDeactivateDialog();
00437
00438 GroupConstructors->setEnabled(true);
00439 GroupC1->setEnabled(true);
00440 GroupButtons->setEnabled(true);
00441
00442 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00443
00444 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00445 aViewWindow->SetSelectionMode(CellSelection);
00446
00447 SelectionIntoArgument();
00448 }
00449
00450
00451
00452
00453
00454 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent*)
00455 {
00456 if (!GroupConstructors->isEnabled())
00457 ActivateThisDialog();
00458 }
00459
00460
00461
00462
00463
00464 void SMESHGUI_RemoveElementsDlg::closeEvent(QCloseEvent*)
00465 {
00466
00467 ClickOnCancel();
00468 }
00469
00470
00471
00472
00473
00474 void SMESHGUI_RemoveElementsDlg::hideEvent( QHideEvent* )
00475 {
00476 if (!isMinimized())
00477 ClickOnCancel();
00478 }
00479
00480
00481
00482
00483
00484 void SMESHGUI_RemoveElementsDlg::keyPressEvent( QKeyEvent* e )
00485 {
00486 QDialog::keyPressEvent( e );
00487 if ( e->isAccepted() )
00488 return;
00489
00490 if ( e->key() == Qt::Key_F1 ) {
00491 e->accept();
00492 ClickOnHelp();
00493 }
00494 }
00495
00496
00497
00498
00499
00500 void SMESHGUI_RemoveElementsDlg::setFilters()
00501 {
00502 if(myMesh->_is_nil()) {
00503 SUIT_MessageBox::critical(this,
00504 tr("SMESH_ERROR"),
00505 tr("NO_MESH_SELECTED"));
00506 return;
00507 }
00508 if ( !myFilterDlg )
00509 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
00510
00511 myFilterDlg->SetSelection();
00512 myFilterDlg->SetMesh( myMesh );
00513 myFilterDlg->SetSourceWg( LineEditC1A1 );
00514
00515 myFilterDlg->show();
00516 }
00517
00518
00519
00520
00521
00522 void SMESHGUI_RemoveElementsDlg::updateButtons()
00523 {
00524 buttonOk->setEnabled(myNbOkElements > 0);
00525 buttonApply->setEnabled(myNbOkElements > 0);
00526 }