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_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
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_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();
00167 }
00168
00169
00170
00171
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
00184
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
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 SMESH::SetPointRepresentation(true);
00212
00213 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00214 aViewWindow->SetSelectionMode(NodeSelection);
00215
00216 SelectionIntoArgument();
00217 }
00218
00219
00220
00221
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
00259
00260
00261 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
00262 {
00263 ClickOnApply();
00264 ClickOnCancel();
00265 }
00266
00267
00268
00269
00270
00271 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
00272 {
00273
00274 if (SMESH::GetCurrentVtkView()) {
00275 SMESH::RemoveFilters();
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
00288
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
00312
00313
00314 void SMESHGUI_RemoveNodesDlg::onTextChange(const QString& theNewText)
00315 {
00316 if (myBusy) return;
00317 myBusy = true;
00318
00319 myNbOkNodes = 0;
00320
00321
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
00348
00349
00350 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
00351 {
00352 if (myBusy) return;
00353 if (myFilterDlg && myFilterDlg->isVisible()) return;
00354 if (!GroupButtons->isEnabled()) return;
00355
00356
00357
00358 myNbOkNodes = 0;
00359 myActor = 0;
00360
00361 myBusy = true;
00362 myEditCurrentArgument->setText("");
00363 myBusy = false;
00364
00365
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
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
00389
00390 myNbOkNodes = nbNodes;
00391 }
00392 }
00393 }
00394 }
00395
00396 updateButtons();
00397 }
00398
00399
00400
00401
00402
00403 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
00404 {
00405 QPushButton* send = (QPushButton*)sender();
00406 switch (myConstructorId) {
00407 case 0:
00408 {
00409 if(send == SelectButtonC1A1) {
00410 LineEditC1A1->setFocus();
00411 myEditCurrentArgument = LineEditC1A1;
00412 }
00413 SelectionIntoArgument();
00414 break;
00415 }
00416 }
00417 }
00418
00419
00420
00421
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
00436
00437
00438 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
00439 {
00440
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
00458
00459
00460 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent*)
00461 {
00462 if (!GroupConstructors->isEnabled())
00463 ActivateThisDialog();
00464 }
00465
00466
00467
00468
00469
00470 void SMESHGUI_RemoveNodesDlg::closeEvent(QCloseEvent*)
00471 {
00472
00473 ClickOnCancel();
00474 }
00475
00476
00477
00478
00479
00480 void SMESHGUI_RemoveNodesDlg::hideEvent( QHideEvent* )
00481 {
00482 if (!isMinimized())
00483 ClickOnCancel();
00484 }
00485
00486
00487
00488
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
00504
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
00526
00527
00528 void SMESHGUI_RemoveNodesDlg::updateButtons()
00529 {
00530 buttonOk->setEnabled(myNbOkNodes > 0);
00531 buttonApply->setEnabled(myNbOkNodes > 0);
00532 }