]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Selection.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_Selection.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VisuGUI_Selection.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_Selection.h"
30
31 #include "VisuGUI.h"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_ViewTools.h"
34
35 #include "VISU_Actor.h"
36 #include "VISU_PrsObject_i.hh"
37 #include "VISU_Prs3d_i.hh"
38 #include "VISU_PipeLine.hxx"
39
40 #include "SalomeApp_Study.h"
41 #include "SalomeApp_Application.h"
42 #include "LightApp_Application.h"
43 #include "LightApp_SelectionMgr.h"
44 #include "LightApp_VTKSelector.h"
45
46 #include "SUIT_MessageBox.h"
47 #include "SUIT_ViewWindow.h"
48 #include "SUIT_Session.h"
49 #include "SUIT_ResourceMgr.h"
50
51 #include "SALOME_ListIO.hxx"
52 #include "SALOME_ListIteratorOfListIO.hxx"
53
54 #include "SVTK_ViewWindow.h"
55 #include "SVTK_Selector.h"
56
57 #include "utilities.h"
58
59 // OCCT Includes
60 #include <TColStd_IndexedMapOfInteger.hxx>
61 #include <TColStd_MapOfInteger.hxx>
62
63 // QT Includes
64 #include <qstring.h>
65 #include <qlabel.h>
66 #include <qspinbox.h>
67 #include <qlistbox.h>
68 #include <qlayout.h>
69 #include <qhbuttongroup.h>
70 #include <qradiobutton.h>
71 #include <qvalidator.h>
72 #include <qpushbutton.h>
73 #include <qwidgetstack.h>
74 #include <qvbox.h>
75 #include <qgroupbox.h>
76 #include <qlineedit.h>
77 #include <qvalidator.h>
78 #include <qtable.h>
79
80 // VTK Includes
81 #include <vtkDataSetMapper.h>
82 #include <vtkDataSet.h>
83 #include <vtkPointData.h>
84 #include <vtkCellData.h>
85 #include <vtkCell.h>
86
87 // STL Includes
88 #include <map>
89
90 using namespace std;
91
92 VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (const SalomeApp_Module* theModule):
93   QDialog(VISU::GetDesktop(theModule),
94           0,
95           false,
96           WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
97   mySelectionMgr(NULL),
98   myModule(theModule)
99 {
100   setCaption( "Data on elements" );
101   setSizeGripEnabled(TRUE);
102
103   QGridLayout* TopLayout = new QGridLayout (this);
104   TopLayout->setSpacing(6);
105   TopLayout->setMargin(11);
106   TopLayout->setRowStretch(0, 0);
107   TopLayout->setRowStretch(1, 0);
108   TopLayout->setRowStretch(2, 1);
109   TopLayout->setRowStretch(3, 0);
110
111   QHButtonGroup* aTypeBox = new QHButtonGroup ("Selection", this);
112
113   QRadioButton* aPointBtn =
114   new QRadioButton ("Point", aTypeBox);
115   new QRadioButton ("Cell" , aTypeBox);
116   new QRadioButton ("Actor", aTypeBox);
117   aPointBtn->setChecked(true);
118
119   connect(aTypeBox, SIGNAL(clicked(int)), this, SLOT(onSelectionChange(int)));
120
121   TopLayout->addWidget(aTypeBox, 0, 0);
122
123   QWidget* aNamePane = new QWidget (this);
124   QGridLayout* aNameLay = new QGridLayout (aNamePane);
125
126   QLabel* aMeshLbl = new QLabel ("Mesh name: ", aNamePane);
127   myMeshName = new QLabel (aNamePane);
128
129   QLabel* aFieldLbl = new QLabel ("Field name: ", aNamePane);
130   myFieldName = new QLabel (aNamePane);
131
132   aNameLay->addWidget(aMeshLbl, 0, 0);
133   aNameLay->addWidget(myMeshName, 0, 1);
134   aNameLay->addWidget(aFieldLbl, 1, 0);
135   aNameLay->addWidget(myFieldName, 1, 1);
136
137   TopLayout->addWidget(aNamePane, 1, 0);
138
139   myWidgetStack = new QWidgetStack (this);
140
141   // Create Points pane
142   myPointsPane = new QVBox (myWidgetStack);
143   myPointsPane->layout()->setSpacing(6);
144
145   QGroupBox* aDataGrp = new QGroupBox (2, Qt::Horizontal, "Data of Point", myPointsPane);
146   aDataGrp->layout()->setSpacing(6);
147
148   new QLabel ("ID:", aDataGrp);
149   myIDValLbl = new QLineEdit ("", aDataGrp);
150   QIntValidator* aIntValidator = new QIntValidator (myIDValLbl);
151   aIntValidator->setBottom(0);
152   myIDValLbl->setValidator(aIntValidator);
153   connect(myIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onPointIdEdit(const QString&)));
154
155   new QLabel ("Scalar Value:", aDataGrp);
156   myScalarValLbl = new QLabel ("", aDataGrp);
157   new QLabel ("Vector Value:", aDataGrp);
158   myVectorValLbl = new QLabel ("", aDataGrp);
159   myVectorValLbl->setMinimumWidth(150);
160
161   QGroupBox* aCoordGrp = new QGroupBox (4, Qt::Horizontal, "Coordinates", myPointsPane);
162   aCoordGrp->layout()->setSpacing(6);
163   new QLabel ("X:", aCoordGrp);
164   myXValLbl = new QLabel ("", aCoordGrp);
165   //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
166   new QLabel ("I:", aCoordGrp);
167   myIValLbl = new QLabel ("-", aCoordGrp);
168   //ENK: 23.11.2006
169   new QLabel ("Y:", aCoordGrp);
170   myYValLbl = new QLabel ("", aCoordGrp);
171   //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
172   new QLabel ("J:", aCoordGrp);
173   myJValLbl = new QLabel ("-", aCoordGrp);
174   //ENK: 23.11.2006
175   new QLabel ("Z:",aCoordGrp );
176   myZValLbl = new QLabel ("", aCoordGrp);
177   //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
178   new QLabel ("K:", aCoordGrp);
179   myKValLbl = new QLabel ("-", aCoordGrp);
180   //ENK: 23.11.2006
181
182
183   myWidgetStack->addWidget(myPointsPane, 0);
184
185   // Create Cells pane
186   myCellsPane = new QWidget (myWidgetStack);
187   QGridLayout* aCellLayout = new QGridLayout (myCellsPane);
188   aCellLayout->setSpacing(6);
189   aCellLayout->setRowStretch(0, 0);
190   aCellLayout->setRowStretch(1, 1);
191
192   QGroupBox* aCellGrp = new QGroupBox(2, Qt::Horizontal, "Data of Cell", myCellsPane);
193
194   new QLabel ("ID:", aCellGrp);
195   myCellIDValLbl = new QLineEdit ("", aCellGrp);
196   myCellIDValLbl->setValidator(aIntValidator);
197   connect(myCellIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onCellIdEdit(const QString&)));
198
199   new QLabel ("Scalar Value:", aCellGrp);
200   myCellScalarValLbl = new QLabel ("", aCellGrp);
201   new QLabel ("Vector Value:", aCellGrp);
202   myCellVectorValLbl = new QLabel ("", aCellGrp);
203
204   aCellLayout->addWidget(aCellGrp, 0, 0);
205
206   myListPoints = new QTable (myCellsPane);
207   myListPoints->setReadOnly(true);
208   myListPoints->setNumCols(9);
209   myListPoints->setNumRows(0);
210   myListPoints->setColumnWidth(0, 40);
211   myListPoints->setColumnWidth(1, 40);
212   myListPoints->setColumnWidth(2, 40);
213   myListPoints->setColumnWidth(3, 40);
214   myListPoints->setColumnWidth(4, 40);//ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
215   myListPoints->setColumnWidth(5, 40);//ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
216   myListPoints->setColumnWidth(6, 40);//ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
217   myListPoints->setSelectionMode(QTable::NoSelection);
218   QHeader* aHeader = myListPoints->horizontalHeader();
219   aHeader->setLabel( 0, "ID" );
220   aHeader->setLabel( 1, "X" );
221   aHeader->setLabel( 2, "Y" );
222   aHeader->setLabel( 3, "Z" );
223   aHeader->setLabel( 4, "I" );//ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
224   aHeader->setLabel( 5, "J" );//ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
225   aHeader->setLabel( 6, "K" );//ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
226   aHeader->setLabel( 7, "Scalar" );
227   aHeader->setLabel( 8, "Vector" );
228
229   aCellLayout->addWidget(myListPoints, 1, 0);
230
231   myWidgetStack->addWidget(myCellsPane, 1);
232
233   // Actor Pane
234   myActorsPane = new QVBox (myWidgetStack);
235   myActorsPane->layout()->setSpacing(6);
236
237   QGroupBox* aPosGrp = new QGroupBox (2, Qt::Horizontal, "Position", myActorsPane);
238   aPosGrp->layout()->setSpacing(6);
239   new QLabel ("X:", aPosGrp);
240   myXPosLbl = new QLabel ("0", aPosGrp);
241   new QLabel ("Y:", aPosGrp);
242   myYPosLbl = new QLabel ("0", aPosGrp);
243   new QLabel ("Z:", aPosGrp);
244   myZPosLbl = new QLabel ("0", aPosGrp);
245
246   QGroupBox* aSizeGrp = new QGroupBox (2, Qt::Horizontal, "Size", myActorsPane);
247   aSizeGrp->layout()->setSpacing(6);
248   new QLabel ("dX:", aSizeGrp);
249   myDXLbl = new QLabel ("0", aSizeGrp);
250   new QLabel ("dY:", aSizeGrp);
251   myDYLbl = new QLabel ("0", aSizeGrp);
252   new QLabel ("dZ:",aSizeGrp );
253   myDZLbl = new QLabel ("0", aSizeGrp);
254
255   myWidgetStack->addWidget(myActorsPane, 2);
256
257
258   TopLayout->addWidget(myWidgetStack, 2, 0);
259
260   // Create buttons group
261   QHBox* aBtnBox = new QHBox (this);
262   QHBoxLayout* aBtnLayout = (QHBoxLayout*)aBtnBox->layout();
263   aBtnLayout->addStretch();
264
265   QPushButton* aCloseBtn = new QPushButton (tr("BUT_CLOSE"), aBtnBox);
266   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
267
268   QPushButton* aHelpBtn = new QPushButton (tr("BUT_HELP"), aBtnBox);
269   connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
270
271   TopLayout->addWidget(aBtnBox, 3, 0);
272
273   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
274     (SUIT_Session::session()->activeApplication());
275   mySelectionMgr = anApp->selectionMgr();
276   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionEvent()));
277
278   //connect(visuGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
279
280   myFl = false;
281
282   // Activate Points pane
283   myWidgetStack->raiseWidget(myPointsPane);
284   if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule))
285     aViewWindow->SetSelectionMode(NodeSelection);
286   onSelectionEvent();
287 }
288
289 VisuGUI_SelectionDlg::~VisuGUI_SelectionDlg()
290 {
291   SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule);
292   if ( !aViewWindow )
293     return;
294
295   switch ( aViewWindow->SelectionMode() ) {
296   case NodeSelection:
297   case CellSelection:
298     aViewWindow->SetSelectionMode(ActorSelection);
299     break;
300   }
301 }
302
303 void VisuGUI_SelectionDlg::onSelectionChange (int theId)
304 {
305   SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule);
306   if (!aViewWindow) return;
307
308   switch (theId) {
309   case 0: // Points
310     myWidgetStack->raiseWidget(myPointsPane);
311     aViewWindow->SetSelectionMode(NodeSelection);
312     onPointIdEdit(myIDValLbl->text());
313     break;
314   case 1: // Cells
315     myWidgetStack->raiseWidget(myCellsPane);
316     aViewWindow->SetSelectionMode(CellSelection);
317     onCellIdEdit(myCellIDValLbl->text());
318     break;
319   case 2: // Actor
320     myWidgetStack->raiseWidget(myActorsPane);
321     aViewWindow->SetSelectionMode(ActorSelection);
322     onSelectionEvent();
323   }
324 }
325
326
327 void VisuGUI_SelectionDlg::closeEvent (QCloseEvent* theEvent)
328 {
329   QDialog::closeEvent(theEvent);
330 }
331
332 template<class TData> QString getValue(TData* theData, int theId){
333   if (vtkDataArray *aScalar = theData->GetScalars()){
334     vtkFloatingPointType aVal = aScalar->GetTuple1(theId);
335     return QString::number(aVal);
336   } else {
337     return QString("No data");
338   }
339 }
340
341 template<class TData> QString getVector(TData* theData, int theId){
342   if (vtkDataArray *aVector = theData->GetVectors()) {
343     vtkFloatingPointType *aVal = aVector->GetTuple3(theId);
344     return QString("%1; %2; %3").arg(aVal[0]).arg(aVal[1]).arg(aVal[2]);
345   } else {
346     return QString("No data");
347   }
348 }
349
350 #define ABS(a) (a>=0)?a:-a
351
352 void VisuGUI_SelectionDlg::onSelectionEvent() {
353   SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule);
354   if (!aViewWindow)
355     return;
356
357   switch (aViewWindow->SelectionMode()) {
358   case NodeSelection:
359   case CellSelection:
360   case ActorSelection:
361     break;
362   default:
363     close( TRUE );
364     return;
365   }
366
367   if (myFl)
368     return;
369   myFl = true;
370
371   int aType = myWidgetStack->id(myWidgetStack->visibleWidget());
372
373   SVTK_Selector* aSelector = aViewWindow->GetSelector();
374
375   _PTR(SObject) aSObject;
376   VISU::Prs3d_i* aPrs3d = NULL;
377   Handle(SALOME_InteractiveObject) anIO;
378
379   VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(myModule);
380   if(aSelectionInfo.size() == 1){
381     // Get selected SObject
382     VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
383     VISU::TObjectInfo anObjectInfo = aSelectionItem.myObjectInfo;
384     aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
385     if(aPrs3d){
386       anIO = aSelectionItem.myIO;
387       aSObject = anObjectInfo.mySObject;
388     }
389   }
390   
391
392   if (aPrs3d) {
393     QString aMeshName("NULL"), aFieldName("NULL");
394     if (aSObject) {
395       VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(aSObject);
396       if (!aMap.empty()) {
397         aMeshName  = VISU::Storable::FindValue(aMap, "myMeshName");
398         aFieldName = VISU::Storable::FindValue(aMap, "myFieldName");
399       }
400     }
401
402     myMeshName ->setText((aMeshName  == "NULL") ? QString("No name") : aMeshName);
403     myFieldName->setText((aFieldName == "NULL") ? QString("No name") : aFieldName);
404
405     VISU_Actor* anVISUActor =
406       VISU::FindActor(VISU::GetAppStudy(myModule), aViewWindow, aSObject->GetID().c_str());
407     if (anVISUActor) {
408       vtkFloatingPointType aCoord[6];
409       anVISUActor->GetBounds(aCoord);
410       myXPosLbl->setText(QString::number( aCoord[0] ));
411       myYPosLbl->setText(QString::number( aCoord[2] ));
412       myZPosLbl->setText(QString::number( aCoord[4] ));
413
414       myDXLbl->setText(QString::number( ABS(aCoord[1]-aCoord[0]) ));
415       myDYLbl->setText(QString::number( ABS(aCoord[3]-aCoord[2]) ));
416       myDZLbl->setText(QString::number( ABS(aCoord[5]-aCoord[4]) ));
417
418       TColStd_IndexedMapOfInteger aMapIndex;
419       typedef std::vector<vtkFloatingPointType> TCoordArray;
420       typedef map<int, TCoordArray> TPointCoordsMap;
421       TPointCoordsMap aPointCoordsMap;
422
423       aSelector->GetIndex(anIO, aMapIndex);
424
425       vtkDataSet* aDataSet = anVISUActor->GetMapper()->GetInput();
426       vtkPointData* aPntData = aDataSet->GetPointData();
427
428       for (int ind = 1; ind <= aMapIndex.Extent(); ind++) {
429         int anID = aMapIndex(ind);
430
431         switch (aType) {
432         case 0:
433           {
434             vtkFloatingPointType* aCoord = anVISUActor->GetNodeCoord(anID);
435             int aVTKID = anVISUActor->GetNodeVTKID(anID);
436             myXValLbl->setText( QString::number( aCoord[0] ) );
437             myYValLbl->setText( QString::number( aCoord[1] ) );
438             myZValLbl->setText( QString::number( aCoord[2] ) );
439             myIDValLbl->setText( QString::number(anID) );
440             myScalarValLbl->setText(getValue(aPntData, aVTKID));
441             myVectorValLbl->setText(getVector(aPntData, aVTKID));
442             //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
443             const VISU::PIDMapper& aMapper = aPrs3d->GetPipeLine()->GetIDMapper();
444             VISU::TIdTypeVector aVec = aMapper->GetIndexesOfNode(anID);
445             switch(aVec.size()){
446               case 3:
447                 myKValLbl->setText(QString::number(aVec[2]));
448               case 2:
449                 myJValLbl->setText(QString::number(aVec[1]));
450               case 1:
451                 myIValLbl->setText(QString::number(aVec[0]));
452                 break;
453             default:
454               myIValLbl->setText("-");
455               myJValLbl->setText("-");
456               myKValLbl->setText("-");
457             }
458             //ENK: 23.11.2006
459           }
460           break;
461         case 1:
462           {
463             vtkCellData* aCellData = aDataSet->GetCellData();
464             vtkCell* aCell = anVISUActor->GetElemCell(anID);
465             int aVTKID = anVISUActor->GetElemVTKID(anID);
466             if (aCell != NULL) {
467               int aNbOfPoints = aCell->GetNumberOfPoints();
468               if ( aNbOfPoints > 0 ) {
469                 myCellIDValLbl->setText( QString::number(anID) );
470                 myCellScalarValLbl->setText(getValue(aCellData, aVTKID));
471                 myCellVectorValLbl->setText(getVector(aCellData, aVTKID));
472
473                 vtkIdList *aPointList = aCell->GetPointIds();
474                 for (int i = 0; i < aNbOfPoints; i++) {
475                   int aNodeVTKId = aPointList->GetId(i);
476                   vtkFloatingPointType* aCoord = aDataSet->GetPoint(aNodeVTKId);
477                   vtkIdType aNodeObjId = anVISUActor->GetNodeObjId(aNodeVTKId);
478                   TCoordArray aCoordArray(aCoord, aCoord + 3);
479                   aPointCoordsMap[aNodeObjId] = aCoordArray;
480                 }
481               }
482             }
483           }
484           break;
485         }
486       }
487
488       myListPoints->setNumRows(aPointCoordsMap.size());
489       TPointCoordsMap::const_iterator anIter = aPointCoordsMap.begin();
490
491       const VISU::PIDMapper& aMapper = aPrs3d->GetPipeLine()->GetIDMapper();
492       for (int i = 0; anIter != aPointCoordsMap.end() && i < myListPoints->numRows(); anIter++, i++) {
493         myListPoints->verticalHeader()->setLabel(i, QString::number( i ));
494         vtkIdType aNodeObjId = anIter->first;
495         //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
496         VISU::TIdTypeVector aVec = aMapper->GetIndexesOfNode(aNodeObjId);
497         QString aI,aJ,aK;
498         aI = "-";
499         aJ = "-";
500         aK = "-";
501         switch(aVec.size()){
502         case 3:
503           aK = QString::number(aVec[2]);
504         case 2:
505           aJ = QString::number(aVec[1]);
506         case 1:
507           aI = QString::number(aVec[0]);
508           break;
509         }
510         //ENK: 23.11.2006
511
512         myListPoints->setText(i, 0, QString::number( aNodeObjId ));
513         const TCoordArray& aCoordArray = anIter->second;
514         myListPoints->setText(i, 1, QString::number( aCoordArray[0] ));
515         myListPoints->setText(i, 2, QString::number( aCoordArray[1] ));
516         myListPoints->setText(i, 3, QString::number( aCoordArray[2] ));
517         myListPoints->setText(i, 4, aI);//ENK: 23.11.2006 - PAL13176
518         myListPoints->setText(i, 5, aJ);//ENK: 23.11.2006 - PAL13176
519         myListPoints->setText(i, 6, aK);//ENK: 23.11.2006 - PAL13176
520
521         vtkIdType aNodeVTKId = anVISUActor->GetNodeVTKID(aNodeObjId);
522         myListPoints->setText(i, 7, getValue(aPntData, aNodeVTKId));
523         myListPoints->setText(i, 8, getVector(aPntData, aNodeVTKId));
524       }
525       for(int aColumnId = 0; aColumnId < 9; aColumnId++)
526         myListPoints->adjustColumn(aColumnId);
527     }
528   } else {
529     clearFields();
530   }
531   myFl = false;
532 }
533 #undef ABS
534
535
536 void VisuGUI_SelectionDlg::clearFields() {
537   int aType = myWidgetStack->id(myWidgetStack->visibleWidget());
538   switch (aType) {
539   case 0:
540     myXValLbl->setText( "" );
541     myYValLbl->setText( "" );
542     myZValLbl->setText( "" );
543     myIValLbl->setText( "-" );//ENK: 23.11.2006 - PAL13176
544     myJValLbl->setText( "-" );//ENK: 23.11.2006 - PAL13176
545     myKValLbl->setText( "-" );//ENK: 23.11.2006 - PAL13176
546     myScalarValLbl->setText("");
547     myVectorValLbl->setText("");
548     break;
549   case 1:
550     myCellScalarValLbl->setText("");
551     myCellVectorValLbl->setText("");
552     myListPoints->setNumRows(0);
553     break;
554   case 2:
555     myXPosLbl->setText("");
556     myYPosLbl->setText("");
557     myZPosLbl->setText("");
558     myDXLbl->setText("");
559     myDYLbl->setText("");
560     myDZLbl->setText("");
561   }
562 }
563
564 typedef  vtkIdType (VISU_PipeLine::* TGetVTKIdMethod)(vtkIdType theID);
565
566 bool onIdEdit (const QString& theText,
567                TGetVTKIdMethod theMethod,
568                bool theIsCell,
569                const SalomeApp_Module* theModule,
570                QLabel* theMeshName,
571                QString theValue,
572                QLabel* theFieldName)
573 {
574   SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule);
575   if (!aViewWindow) 
576     return false;
577   SVTK_Selector* aSelector = aViewWindow->GetSelector();
578
579   _PTR(SObject) aSObject;
580   VISU::Prs3d_i* aPrs3d = NULL;
581   Handle(SALOME_InteractiveObject) anIO;
582
583   VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
584   if(aSelectionInfo.size() == 1){
585     // Get selected SObject
586     VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
587     VISU::TObjectInfo anObjectInfo = aSelectionItem.myObjectInfo;
588     aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
589     if(aPrs3d){
590       anIO = aSelectionItem.myIO;
591       aSObject = anObjectInfo.mySObject;
592     }
593   }
594   if (aPrs3d) {
595     int anObjId = theText.toInt();
596     VISU_PipeLine* aPipeLine = aPrs3d->GetPipeLine();
597     int aVTKId = (aPipeLine->*theMethod)(anObjId);
598     if(aVTKId < 0)
599       return false;
600
601     TColStd_MapOfInteger newIndices;
602     newIndices.Add(anObjId);
603     aSelector->AddOrRemoveIndex(anIO, newIndices, false);
604     aViewWindow->highlight(anIO, true, true);
605
606     return true;
607
608   } else {
609     theMeshName->setText(theValue);
610     theFieldName->setText("");
611   }
612   return false;
613 }
614
615 void VisuGUI_SelectionDlg::onPointIdEdit (const QString& theText)
616 {
617   if (myFl) return;
618   TGetVTKIdMethod aMethod = &VISU_PipeLine::GetNodeVTKID;
619   bool anIsSelected = onIdEdit(theText,
620                                aMethod,
621                                false,
622                                myModule,
623                                myMeshName,
624                                tr("WRN_NO_AVAILABLE_DATA"),
625                                myFieldName);
626   if (anIsSelected)
627     // as selection manager doesn't send signal currentSelectionChanged()
628     onSelectionEvent();
629   else
630     clearFields();
631 }
632
633 void VisuGUI_SelectionDlg::onCellIdEdit (const QString& theText)
634 {
635   if (myFl) return;
636   TGetVTKIdMethod aMethod = &VISU_PipeLine::GetElemVTKID;
637   bool anIsSelected = onIdEdit(theText,
638                                aMethod,
639                                true,
640                                myModule,
641                                myMeshName,
642                                tr("WRN_NO_AVAILABLE_DATA"),
643                                myFieldName);
644   if (anIsSelected)
645     // as selection manager doesn't send signal currentSelectionChanged()
646     onSelectionEvent();
647   else
648     clearFields();
649 }
650
651 void VisuGUI_SelectionDlg::onHelp()
652 {
653   QString aHelpFileName = "selection_info_page.html";
654   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
655   if (app)
656     app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
657   else {
658     QString platform;
659 #ifdef WIN32
660     platform = "winapplication";
661 #else
662     platform = "application";
663 #endif
664     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
665                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
666                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
667                            QObject::tr("BUT_OK"));
668   }
669 }
670
671 void VisuGUI_SelectionDlg::keyPressEvent( QKeyEvent* e )
672 {
673   QDialog::keyPressEvent( e );
674   if ( e->isAccepted() )
675     return;
676
677   if ( e->key() == Key_F1 )
678     {
679       e->accept();
680       onHelp();
681     }
682 }