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_MoveNodesDlg.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_SpinBox.h"
00032 #include "SMESHGUI_IdValidator.h"
00033 #include "SMESHGUI_Utils.h"
00034 #include "SMESHGUI_VTKUtils.h"
00035 #include "SMESHGUI_MeshUtils.h"
00036
00037 #include <SMESH_Actor.h>
00038 #include <SMDS_Mesh.hxx>
00039
00040
00041 #include <LightApp_SelectionMgr.h>
00042 #include <LightApp_Application.h>
00043 #include <SUIT_ResourceMgr.h>
00044 #include <SUIT_Desktop.h>
00045 #include <SUIT_Session.h>
00046 #include <SUIT_MessageBox.h>
00047
00048 #include <SVTK_ViewModel.h>
00049 #include <SVTK_ViewWindow.h>
00050 #include <SALOME_ListIO.hxx>
00051
00052 #include <VTKViewer_CellLocationsArray.h>
00053
00054
00055 #include <TColStd_MapOfInteger.hxx>
00056
00057
00058 #include <vtkIdList.h>
00059 #include <vtkCellArray.h>
00060 #include <vtkUnsignedCharArray.h>
00061 #include <vtkUnstructuredGrid.h>
00062 #include <vtkDataSetMapper.h>
00063 #include <vtkProperty.h>
00064
00065
00066 #include <QGroupBox>
00067 #include <QLabel>
00068 #include <QLineEdit>
00069 #include <QPushButton>
00070 #include <QRadioButton>
00071 #include <QHBoxLayout>
00072 #include <QVBoxLayout>
00073 #include <QKeyEvent>
00074 #include <QButtonGroup>
00075
00076
00077 #include <SALOMEconfig.h>
00078 #include CORBA_SERVER_HEADER(SMESH_Mesh)
00079 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00080
00081 #define SPACING 6
00082 #define MARGIN 11
00083
00084
00085
00086
00087
00088 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg(SMESHGUI* theModule):
00089 QDialog(SMESH::GetDesktop(theModule)),
00090 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
00091 mySMESHGUI(theModule)
00092 {
00093 myPreviewActor = 0;
00094 myBusy = false;
00095
00096 setModal(false);
00097 setWindowTitle(tr("CAPTION"));
00098
00099 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
00100 aDlgLay->setSpacing(SPACING);
00101 aDlgLay->setMargin(MARGIN);
00102
00103 QWidget* aMainFrame = createMainFrame (this);
00104 QWidget* aBtnFrame = createButtonFrame(this);
00105
00106 aDlgLay->addWidget(aMainFrame);
00107 aDlgLay->addWidget(aBtnFrame);
00108
00109 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00110
00111 myHelpFileName = "moving_nodes_page.html";
00112
00113 Init();
00114 }
00115
00116
00117
00118
00119
00120 QWidget* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
00121 {
00122 QFrame* aFrame = new QFrame(theParent);
00123 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
00124
00125 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
00126 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
00127 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
00128 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
00129
00130 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
00131 aLay->setSpacing(SPACING);
00132 aLay->setMargin(MARGIN);
00133
00134 aLay->addWidget(myOkBtn);
00135 aLay->addSpacing(10);
00136 aLay->addWidget(myApplyBtn);
00137 aLay->addSpacing(10);
00138 aLay->addStretch();
00139 aLay->addWidget(myCloseBtn);
00140 aLay->addWidget(myHelpBtn);
00141
00142 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
00143 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
00144 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
00145 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
00146
00147 return aFrame;
00148 }
00149
00150
00151
00152
00153
00154 QWidget* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
00155 {
00156 QWidget* aFrame = new QWidget(theParent);
00157
00158 QPixmap iconMoveNode (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
00159 QPixmap iconSelect (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00160
00161
00162 QGroupBox* aPixGrp = new QGroupBox(tr("MESH_NODE"), aFrame);
00163 QButtonGroup* aBtnGrp = new QButtonGroup(this);
00164 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
00165 aPixGrpLayout->setSpacing(SPACING);
00166 aPixGrpLayout->setMargin(MARGIN);
00167
00168 QRadioButton* aRBut = new QRadioButton(aPixGrp);
00169 aRBut->setIcon(iconMoveNode);
00170 aRBut->setChecked(true);
00171
00172 aPixGrpLayout->addWidget(aRBut);
00173 aBtnGrp->addButton(aRBut, 0);
00174
00175
00176 QGroupBox* anIdGrp = new QGroupBox(tr("SMESH_MOVE"), aFrame);
00177 QHBoxLayout* anIdGrpLayout = new QHBoxLayout(anIdGrp);
00178 anIdGrpLayout->setSpacing(SPACING);
00179 anIdGrpLayout->setMargin(MARGIN);
00180
00181 QLabel* idLabl = new QLabel(tr("NODE_ID"), anIdGrp);
00182 QPushButton* idBtn = new QPushButton(anIdGrp);
00183 idBtn->setIcon(iconSelect);
00184 myId = new QLineEdit(anIdGrp);
00185 myId->setValidator(new SMESHGUI_IdValidator(this, 1));
00186
00187 anIdGrpLayout->addWidget(idLabl);
00188 anIdGrpLayout->addWidget(idBtn);
00189 anIdGrpLayout->addWidget(myId);
00190
00191
00192 QGroupBox* aCoordGrp = new QGroupBox(tr("SMESH_COORDINATES"), aFrame);
00193 QHBoxLayout* aCoordGrpLayout = new QHBoxLayout(aCoordGrp);
00194 aCoordGrpLayout->setSpacing(SPACING);
00195 aCoordGrpLayout->setMargin(MARGIN);
00196
00197 QLabel* aXLabel = new QLabel(tr("SMESH_X"), aCoordGrp);
00198 myX = new SMESHGUI_SpinBox(aCoordGrp);
00199
00200 QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aCoordGrp);
00201 myY = new SMESHGUI_SpinBox(aCoordGrp);
00202
00203 QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aCoordGrp);
00204 myZ = new SMESHGUI_SpinBox(aCoordGrp);
00205
00206 aCoordGrpLayout->addWidget(aXLabel);
00207 aCoordGrpLayout->addWidget(myX);
00208 aCoordGrpLayout->addWidget(aYLabel);
00209 aCoordGrpLayout->addWidget(myY);
00210 aCoordGrpLayout->addWidget(aZLabel);
00211 aCoordGrpLayout->addWidget(myZ);
00212
00213
00214 myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, "length_precision");
00215 myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, "length_precision");
00216 myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, "length_precision");
00217
00218
00219 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
00220 aLay->setMargin(0);
00221 aLay->setMargin(SPACING);
00222 aLay->addWidget(aPixGrp);
00223 aLay->addWidget(anIdGrp);
00224 aLay->addWidget(aCoordGrp);
00225
00226
00227
00228 connect(myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
00229 connect(myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
00230 connect(myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
00231 connect(myId, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00232
00233 return aFrame;
00234 }
00235
00236
00237
00238
00239
00240 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
00241 {
00242 erasePreview();
00243 }
00244
00245
00246
00247
00248
00249 void SMESHGUI_MoveNodesDlg::Init()
00250 {
00251 myPreviewActor = 0;
00252 myMeshActor = 0;
00253 myBusy = false;
00254
00255 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00256
00257
00258 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
00259 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
00260 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
00261
00262 reset();
00263 setEnabled(true);
00264
00265
00266 SMESH::SetPointRepresentation(true);
00267 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00268 aViewWindow->SetSelectionMode(NodeSelection);
00269
00270 onSelectionDone();
00271 }
00272
00273
00274
00275
00276
00277 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess)
00278 {
00279 if (myId->text().isEmpty()) {
00280 if (theMess)
00281 SUIT_MessageBox::information(this, tr("SMESH_WARNING"),
00282 tr("NODE_ID_IS_NOT_DEFINED"));
00283 return false;
00284 }
00285
00286 QString msg;
00287 bool ok = true;
00288 ok = myX->isValid( msg, theMess ) && ok;
00289 ok = myY->isValid( msg, theMess ) && ok;
00290 ok = myZ->isValid( msg, theMess ) && ok;
00291 if( !ok ) {
00292 if( theMess ) {
00293 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
00294 if ( !msg.isEmpty() )
00295 str += "\n" + msg;
00296 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
00297 }
00298 return false;
00299 }
00300
00301 return true;
00302 }
00303
00304
00305
00306
00307
00308 void SMESHGUI_MoveNodesDlg::reset()
00309 {
00310 myId->clear();
00311 myX->SetValue(0);
00312 myY->SetValue(0);
00313 myZ->SetValue(0);
00314 redisplayPreview();
00315 updateButtons();
00316 }
00317
00318
00319
00320
00321
00322 bool SMESHGUI_MoveNodesDlg::onApply()
00323 {
00324 if (mySMESHGUI->isActiveStudyLocked())
00325 return false;
00326
00327 if (!isValid(true))
00328 return false;
00329
00330 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
00331 if (aMesh->_is_nil()) {
00332 SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
00333 tr("SMESHG_NO_MESH"));
00334 return false;
00335 }
00336
00337 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
00338 if (aMeshEditor->_is_nil())
00339 return false;
00340
00341 int anId = myId->text().toInt();
00342 bool aResult = false;
00343 try {
00344 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
00345
00346 QStringList aParameters;
00347 aParameters << myX->text();
00348 aParameters << myY->text();
00349 aParameters << myZ->text();
00350 aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00351 } catch (...) {
00352 }
00353
00354 if (aResult) {
00355 SALOME_ListIO aList;
00356 aList.Append(myMeshActor->getIO());
00357 mySelectionMgr->setSelectedObjects(aList,false);
00358 SMESH::UpdateView();
00359 SMESHGUI::Modified();
00360 reset();
00361 }
00362
00363 return aResult;
00364 }
00365
00366
00367
00368
00369
00370 void SMESHGUI_MoveNodesDlg::onOk()
00371 {
00372 if (onApply())
00373 onClose();
00374 }
00375
00376
00377
00378
00379
00380 void SMESHGUI_MoveNodesDlg::onClose()
00381 {
00382
00383 SMESH::SetPointRepresentation(false);
00384 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00385 aViewWindow->SetSelectionMode(ActorSelection);
00386 disconnect(mySelectionMgr, 0, this, 0);
00387 disconnect(mySMESHGUI, 0, this, 0);
00388 erasePreview();
00389 mySMESHGUI->ResetState();
00390 reject();
00391 }
00392
00393
00394
00395
00396
00397 void SMESHGUI_MoveNodesDlg::onHelp()
00398 {
00399 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00400 if (app)
00401 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00402 else {
00403 QString platform;
00404 #ifdef WIN32
00405 platform = "winapplication";
00406 #else
00407 platform = "application";
00408 #endif
00409 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00410 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00411 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00412 platform)).
00413 arg(myHelpFileName));
00414 }
00415 }
00416
00417
00418
00419
00420
00421 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
00422 {
00423 if (myBusy) return;
00424
00425 myOkBtn->setEnabled(false);
00426 myApplyBtn->setEnabled(false);
00427 erasePreview();
00428
00429
00430 if(myMeshActor){
00431 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
00432 myBusy = true;
00433 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
00434 SALOME_ListIO aList;
00435 aList.Append(anIO);
00436 mySelectionMgr->setSelectedObjects(aList,false);
00437 myBusy = false;
00438
00439 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
00440 TColStd_MapOfInteger aListInd;
00441 aListInd.Add(anElem->GetID());
00442 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
00443 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00444 aViewWindow->highlight(anIO,true,true);
00445
00446 onSelectionDone();
00447 }
00448 }
00449 }
00450 }
00451
00452
00453
00454
00455
00456 void SMESHGUI_MoveNodesDlg::onSelectionDone()
00457 {
00458 if (myBusy) return;
00459 myMeshActor = 0;
00460
00461 SALOME_ListIO aList;
00462 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00463
00464 if (aList.Extent() == 1) {
00465 Handle(SALOME_InteractiveObject) anIO = aList.First();
00466 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
00467 if(myMeshActor){
00468 QString aText;
00469 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
00470 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
00471 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
00472 myBusy = true;
00473 myId->setText(aText);
00474 myX->SetValue(aNode->X());
00475 myY->SetValue(aNode->Y());
00476 myZ->SetValue(aNode->Z());
00477 myBusy = false;
00478 erasePreview();
00479 updateButtons();
00480 return;
00481 }
00482 }
00483 }
00484 }
00485 }
00486
00487 reset();
00488 }
00489
00490
00491
00492
00493
00494 void SMESHGUI_MoveNodesDlg::onDeactivate()
00495 {
00496 setEnabled(false);
00497 erasePreview();
00498 }
00499
00500
00501
00502
00503
00504 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
00505 {
00506 if (!isEnabled()) {
00507 mySMESHGUI->EmitSignalDeactivateDialog();
00508
00509
00510 SMESH::SetPointRepresentation(true);
00511 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00512 aViewWindow->SetSelectionMode(NodeSelection);
00513
00514 redisplayPreview();
00515
00516 setEnabled(true);
00517 }
00518 }
00519
00520
00521
00522
00523
00524 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
00525 {
00526 onClose();
00527 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00528 aViewWindow->Repaint();
00529 }
00530
00531
00532
00533
00534
00535 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
00536 {
00537 if (!isMinimized())
00538 onClose();
00539 }
00540
00541
00542
00543
00544
00545 void SMESHGUI_MoveNodesDlg::updateButtons()
00546 {
00547 bool isEnabled = isValid(false);
00548 myOkBtn->setEnabled(isEnabled);
00549 myApplyBtn->setEnabled(isEnabled);
00550 }
00551
00552
00553
00554
00555
00556 void SMESHGUI_MoveNodesDlg::erasePreview()
00557 {
00558 if (myPreviewActor == 0)
00559 return;
00560
00561 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
00562 if (aViewWindow)
00563 aViewWindow->RemoveActor(myPreviewActor);
00564 myPreviewActor->Delete();
00565 myPreviewActor = 0;
00566 if (aViewWindow)
00567 aViewWindow->Repaint();
00568 }
00569
00570
00571
00572
00573
00574 void SMESHGUI_MoveNodesDlg::redisplayPreview()
00575 {
00576 if (myBusy)
00577 return;
00578
00579 if (myPreviewActor != 0)
00580 erasePreview();
00581
00582 if (!isValid(false))
00583 return;
00584
00585 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
00586
00587 vtkPoints* aPoints = vtkPoints::New();
00588 aPoints->SetNumberOfPoints(1);
00589 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
00590
00591
00592
00593 vtkIdList *anIdList = vtkIdList::New();
00594 anIdList->SetNumberOfIds(1);
00595
00596 vtkCellArray *aCells = vtkCellArray::New();
00597 aCells->Allocate(2, 0);
00598
00599 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00600 aCellTypesArray->SetNumberOfComponents(1);
00601 aCellTypesArray->Allocate(1);
00602
00603 anIdList->SetId(0, 0);
00604 aCells->InsertNextCell(anIdList);
00605 aCellTypesArray->InsertNextValue(VTK_VERTEX);
00606 anIdList->Delete();
00607
00608 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00609 aCellLocationsArray->SetNumberOfComponents(1);
00610 aCellLocationsArray->SetNumberOfTuples(1);
00611
00612 aCells->InitTraversal();
00613 vtkIdType npts;
00614 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
00615
00616 aGrid->SetPoints(aPoints);
00617 aPoints->Delete();
00618
00619 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
00620 aCellLocationsArray->Delete();
00621 aCellTypesArray->Delete();
00622 aCells->Delete();
00623
00624
00625 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
00626 aMapper->SetInput(aGrid);
00627 aGrid->Delete();
00628
00629 myPreviewActor = SALOME_Actor::New();
00630 myPreviewActor->PickableOff();
00631 myPreviewActor->SetMapper(aMapper);
00632 aMapper->Delete();
00633
00634 vtkProperty* aProp = vtkProperty::New();
00635 aProp->SetRepresentationToWireframe();
00636 aProp->SetColor(250, 0, 250);
00637 aProp->SetPointSize(5);
00638 myPreviewActor->SetProperty(aProp);
00639 aProp->Delete();
00640
00641 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00642 {
00643 aViewWindow->AddActor(myPreviewActor);
00644 aViewWindow->Repaint();
00645 }
00646 }
00647
00648
00649
00650
00651
00652 void SMESHGUI_MoveNodesDlg::keyPressEvent( QKeyEvent* e )
00653 {
00654 QDialog::keyPressEvent( e );
00655 if ( e->isAccepted() )
00656 return;
00657
00658 if ( e->key() == Qt::Key_F1 ) {
00659 e->accept();
00660 onHelp();
00661 }
00662 }