1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_Selection.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
30 #include "utilities.h"
31 #include "SALOME_ListIteratorOfListIO.hxx"
32 #include "SALOME_Selection.h"
33 #include "VISU_Actor.h"
34 #include "VISU_PrsObject_i.hh"
35 #include "VISU_Prs3d_i.hh"
36 #include "VISU_PipeLine.hxx"
38 #include "QAD_MessageBox.h"
39 #include "VTKViewer_ViewFrame.h"
41 #include <TColStd_MapOfInteger.hxx>
42 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
49 #include <qhbuttongroup.h>
50 #include <qradiobutton.h>
52 #include <vtkDataSet.h>
54 #include <qvalidator.h>
56 #include "VisuGUI_Selection.h"
59 extern VisuGUI *visuGUI;
62 VisuGUI_SelectionDlg::VisuGUI_SelectionDlg()
63 : QDialog( QAD_Application::getDesktop(), 0, false,
64 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
66 setCaption( "Data on elements" );
67 setSizeGripEnabled( TRUE );
69 QGridLayout* TopLayout = new QGridLayout(this);
70 TopLayout->setSpacing(6);
71 TopLayout->setMargin(11);
72 TopLayout->setRowStretch(0, 0);
73 TopLayout->setRowStretch(1, 0);
74 TopLayout->setRowStretch(2, 1);
75 TopLayout->setRowStretch(3, 0);
77 QHButtonGroup* aTypeBox = new QHButtonGroup("Selection", this);
79 QRadioButton* aPointBtn = new QRadioButton("Point", aTypeBox);
80 QRadioButton* aCellBtn = new QRadioButton("Cell", aTypeBox);
81 QRadioButton* aActorBtn = new QRadioButton("Actor", aTypeBox);
82 aPointBtn->setChecked(true);
84 connect(aTypeBox, SIGNAL(clicked(int)), this, SLOT(onSelectionChange(int)));
86 TopLayout->addWidget(aTypeBox, 0, 0);
88 QWidget* aNamePane = new QWidget(this);
89 QGridLayout* aNameLay = new QGridLayout(aNamePane);
91 QLabel* aMeshLbl = new QLabel("Mesh name: ", aNamePane);
92 myMeshName = new QLabel(aNamePane);
94 QLabel* aFieldLbl = new QLabel("Field name: ", aNamePane);
95 myFieldName = new QLabel(aNamePane);
97 aNameLay->addWidget(aMeshLbl, 0, 0);
98 aNameLay->addWidget(myMeshName, 0, 1);
99 aNameLay->addWidget(aFieldLbl, 1, 0);
100 aNameLay->addWidget(myFieldName, 1, 1);
102 TopLayout->addWidget(aNamePane, 1, 0);
104 myWidgetStack = new QWidgetStack(this);
106 // Create Points pane
107 myPointsPane = new QVBox(myWidgetStack);
108 myPointsPane->layout()->setSpacing(6);
110 QGroupBox* aDataGrp = new QGroupBox(2, Qt::Horizontal, "Data of Point", myPointsPane);
111 aDataGrp->layout()->setSpacing(6);
113 QLabel* aIDLbl = new QLabel("ID:", aDataGrp);
114 myIDValLbl = new QLineEdit("", aDataGrp);
115 QIntValidator* aIntValidator = new QIntValidator(myIDValLbl);
116 aIntValidator->setBottom(0);
117 myIDValLbl->setValidator(aIntValidator);
118 connect(myIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onPointIdEdit(const QString&)));
120 QLabel* aValueLbl = new QLabel("Scalar Value:", aDataGrp);
121 myScalarValLbl = new QLabel("", aDataGrp);
122 QLabel* aVectorLbl = new QLabel("Vector Value:", aDataGrp);
123 myVectorValLbl = new QLabel("", aDataGrp);
124 myVectorValLbl->setMinimumWidth(150);
126 QGroupBox* aCoordGrp = new QGroupBox(2, Qt::Horizontal, "Coordinates", myPointsPane);
127 aCoordGrp->layout()->setSpacing(6);
128 QLabel* aXLbl = new QLabel("X:", aCoordGrp);
129 myXValLbl = new QLabel("", aCoordGrp);
130 QLabel* aYLbl = new QLabel("Y:", aCoordGrp);
131 myYValLbl = new QLabel("", aCoordGrp);
132 QLabel* aZLbl = new QLabel("Z:",aCoordGrp );
133 myZValLbl = new QLabel("", aCoordGrp);
136 myWidgetStack->addWidget(myPointsPane, 0);
139 myCellsPane = new QWidget(myWidgetStack);
140 QGridLayout* aCellLayout = new QGridLayout(myCellsPane);
141 aCellLayout->setSpacing(6);
142 aCellLayout->setRowStretch(0, 0);
143 aCellLayout->setRowStretch(1, 1);
145 QGroupBox* aCellGrp = new QGroupBox(2, Qt::Horizontal, "Data of Cell", myCellsPane);
147 QLabel* aCellIDLbl = new QLabel("ID:", aCellGrp);
148 myCellIDValLbl = new QLineEdit("", aCellGrp);
149 myCellIDValLbl->setValidator(aIntValidator);
150 connect(myCellIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onCellIdEdit(const QString&)));
152 QLabel* aCellValueLbl = new QLabel("Scalar Value:", aCellGrp);
153 myCellScalarValLbl = new QLabel("", aCellGrp);
154 QLabel* aCellVectorLbl = new QLabel("Vector Value:", aCellGrp);
155 myCellVectorValLbl = new QLabel("", aCellGrp);
157 aCellLayout->addWidget(aCellGrp, 0, 0);
159 myListPoints = new QTable(myCellsPane);
160 myListPoints->setReadOnly(true);
161 myListPoints->setNumCols(6);
162 myListPoints->setNumRows(0);
163 myListPoints->setColumnWidth(0, 40);
164 myListPoints->setColumnWidth(1, 40);
165 myListPoints->setColumnWidth(2, 40);
166 myListPoints->setColumnWidth(3, 40);
167 myListPoints->setSelectionMode(QTable::NoSelection);
168 QHeader* aHeader = myListPoints->horizontalHeader();
169 aHeader->setLabel( 0, "ID" );
170 aHeader->setLabel( 1, "X" );
171 aHeader->setLabel( 2, "Y" );
172 aHeader->setLabel( 3, "Z" );
173 aHeader->setLabel( 4, "Scalar" );
174 aHeader->setLabel( 5, "Vector" );
176 aCellLayout->addWidget(myListPoints, 1, 0);
178 myWidgetStack->addWidget(myCellsPane, 1);
181 myActorsPane = new QVBox(myWidgetStack);
182 myActorsPane->layout()->setSpacing(6);
184 QGroupBox* aPosGrp = new QGroupBox(2, Qt::Horizontal, "Position", myActorsPane);
185 aPosGrp->layout()->setSpacing(6);
186 QLabel* aXPosLbl = new QLabel("X:", aPosGrp);
187 myXPosLbl = new QLabel("0", aPosGrp);
188 QLabel* aYPosLbl = new QLabel("Y:", aPosGrp);
189 myYPosLbl = new QLabel("0", aPosGrp);
190 QLabel* aZPosLbl = new QLabel("Z:", aPosGrp);
191 myZPosLbl = new QLabel("0", aPosGrp);
193 QGroupBox* aSizeGrp = new QGroupBox(2, Qt::Horizontal, "Size", myActorsPane);
194 aSizeGrp->layout()->setSpacing(6);
195 QLabel* aXSizeLbl = new QLabel("dX:", aSizeGrp);
196 myDXLbl = new QLabel("0", aSizeGrp);
197 QLabel* aYSizeLbl = new QLabel("dY:", aSizeGrp);
198 myDYLbl = new QLabel("0", aSizeGrp);
199 QLabel* aZSizeLbl = new QLabel("dZ:",aSizeGrp );
200 myDZLbl = new QLabel("0", aSizeGrp);
202 myWidgetStack->addWidget(myActorsPane, 2);
205 TopLayout->addWidget(myWidgetStack, 2, 0);
207 // Create buttons group
208 QHBox* aBtnBox = new QHBox(this);
209 QHBoxLayout* aBtnLayout = (QHBoxLayout*)aBtnBox->layout();
210 aBtnLayout->addStretch();
212 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
213 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
215 TopLayout->addWidget(aBtnBox, 3, 0);
217 mySelection = SALOME_Selection::Selection(visuGUI->GetActiveStudy()->getSelection());
218 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionEvent()));
220 onSelectionChange(0);
224 void VisuGUI_SelectionDlg::onSelectionChange(int theId) {
228 myWidgetStack->raiseWidget(myPointsPane);
229 QAD_Application::getDesktop()->SetSelectionMode(1, true);
232 myWidgetStack->raiseWidget(myCellsPane);
233 QAD_Application::getDesktop()->SetSelectionMode(3, true);
236 myWidgetStack->raiseWidget(myActorsPane);
237 QAD_Application::getDesktop()->SetSelectionMode(4, true);
240 // if (VTKViewer_ViewFrame* vf = visuGUI->GetVtkViewFrame())
245 void VisuGUI_SelectionDlg::closeEvent(QCloseEvent* theEvent) {
246 QAD_Application::getDesktop()->SetSelectionMode(4, true);
247 disconnect(mySelection,0,0,0);
248 QDialog::closeEvent(theEvent);
251 template<class TData> QString getValue(TData* theData, int theId){
252 if (vtkDataArray *aScalar = theData->GetScalars()){
253 float aVal = aScalar->GetTuple1(theId);
254 return QString::number(aVal);
256 return QString("No data");
260 template<class TData> QString getVector(TData* theData, int theId){
261 if (vtkDataArray *aVector = theData->GetVectors()) {
262 float *aVal = aVector->GetTuple3(theId);
263 return QString("%1; %2; %3").arg(aVal[0]).arg(aVal[1]).arg(aVal[2]);
265 return QString("No data");
270 #define ABS(a) (a>=0)?a:-a
272 void VisuGUI_SelectionDlg::onSelectionEvent() {
273 Handle(SALOME_InteractiveObject) anIO;
274 int aType = myWidgetStack->id(myWidgetStack->visibleWidget());
275 if(VISU::Prs3d_i* aPrs3d = visuGUI->GetSelectedPrs3d(&anIO)){
276 SALOMEDS::SObject_var aSObject = visuGUI->GetStudyDocument()->FindObjectID(anIO->getEntry());
277 QString aMeshName = VisuGUI::getValue(aSObject, "myMeshName");
278 QString aFieldName = VisuGUI::getValue(aSObject, "myFieldName");
279 myMeshName->setText((aMeshName == "NULL")? QString("No name") : aMeshName);
280 myFieldName->setText((aFieldName == "NULL")? QString("No name") : aFieldName);
282 VISU_Actor* anVISUActor = visuGUI->GetActor(aPrs3d);
285 anVISUActor->GetBounds(aCoord);
286 myXPosLbl->setText(QString::number( aCoord[0] ));
287 myYPosLbl->setText(QString::number( aCoord[2] ));
288 myZPosLbl->setText(QString::number( aCoord[4] ));
290 myDXLbl->setText(QString::number( ABS(aCoord[1]-aCoord[0]) ));
291 myDYLbl->setText(QString::number( ABS(aCoord[3]-aCoord[2]) ));
292 myDZLbl->setText(QString::number( ABS(aCoord[5]-aCoord[4]) ));
294 TColStd_MapOfInteger aMapIndex;
295 mySelection->GetIndex(anIO, aMapIndex);
296 TColStd_MapIteratorOfMapOfInteger anIter(aMapIndex);
298 VISU_Actor* anActor = visuGUI->GetActor(aPrs3d);
299 vtkDataSet* aDataSet = anActor->GetMapper()->GetInput();
300 // vtkDataSet* aDataSet = aPrs3d->GetPL()->GetMapper()->GetInput();
301 int aID = anIter.Key();
302 vtkPointData* aPntData = aDataSet->GetPointData();
308 aDataSet->GetPoint(aID, aCoord);
309 myXValLbl->setText( QString::number( aCoord[0] ) );
310 myYValLbl->setText( QString::number( aCoord[1] ) );
311 myZValLbl->setText( QString::number( aCoord[2] ) );
312 myIDValLbl->setText( QString::number(aID) );
313 myScalarValLbl->setText(getValue(aPntData, aID));
314 myVectorValLbl->setText(getVector(aPntData, aID));
316 //qApp->processEvents();
321 int aMaxId = aDataSet->GetNumberOfCells();
322 //cout<<"### MaxId="<<aMaxId<<endl;
323 //cout<<"### SelectedId="<<aID<<endl;
324 vtkCellData* aData = aDataSet->GetCellData();
325 vtkCell* aCell = aDataSet->GetCell(aID);
326 if (aCell == NULL) return;
328 int aNbOfPoints = aCell->GetNumberOfPoints();
329 if (aNbOfPoints <=1 ) { // Cell is point
334 myCellIDValLbl->setText( QString::number(aID) );
335 myCellScalarValLbl->setText(getValue(aData, aID));
336 myCellVectorValLbl->setText(getVector(aData, aID));
339 vtkIdList *aPointList = aCell->GetPointIds();
340 QListViewItem* anItem = NULL;
341 myListPoints->setNumRows(aNbOfPoints);
342 for(int i = 0; i < aNbOfPoints; i++){
343 int idCurrent = aPointList->GetId(i);
344 aDataSet->GetPoint(idCurrent,aCoord);
345 myListPoints->verticalHeader()->setLabel(i, QString::number( i ));
346 myListPoints->setText(i, 0, QString::number( idCurrent ));
347 myListPoints->setText(i, 1, QString::number( aCoord[0] ));
348 myListPoints->setText(i, 2, QString::number( aCoord[1] ));
349 myListPoints->setText(i, 3, QString::number( aCoord[2] ));
350 myListPoints->setText(i, 4, getValue(aPntData, idCurrent));
351 myListPoints->setText(i, 5, getVector(aPntData, idCurrent));
364 void VisuGUI_SelectionDlg::clearFields() {
365 int aType = myWidgetStack->id(myWidgetStack->visibleWidget());
368 myXValLbl->setText( "" );
369 myYValLbl->setText( "" );
370 myZValLbl->setText( "" );
371 myIDValLbl->setText( "" );
372 myScalarValLbl->setText("");
373 myVectorValLbl->setText("");
376 myCellIDValLbl->setText( "" );
377 myCellScalarValLbl->setText("");
378 myCellVectorValLbl->setText("");
379 myListPoints->setNumRows(0);
382 myXPosLbl->setText("");
383 myYPosLbl->setText("");
384 myZPosLbl->setText("");
385 myDXLbl->setText("");
386 myDYLbl->setText("");
387 myDZLbl->setText("");
392 #define SELECTBYNUM(METHODNAME, DATASETMETHOD) \
393 void VisuGUI_SelectionDlg::METHODNAME(const QString& theText) { \
394 int anId = theText.toInt(); \
395 Handle(SALOME_InteractiveObject) anIO; \
396 if(VISU::Prs3d_i* aPrs3d = visuGUI->GetSelectedPrs3d(&anIO)){ \
397 TColStd_MapOfInteger aMapIndex; \
398 mySelection->GetIndex(anIO, aMapIndex); \
399 TColStd_MapIteratorOfMapOfInteger anIter(aMapIndex); \
401 vtkDataSet* aDataSet = aPrs3d->GetPL()->GetMapper()->GetInput(); \
402 int aMaxId = aDataSet->DATASETMETHOD(); \
403 if(0 <= anId && anId < aMaxId){ \
404 mySelection->AddIObject(anIO); \
405 mySelection->AddOrRemoveIndex(anIO, anId, false); \
409 myMeshName->setText(tr ("WRN_NO_AVAILABLE_DATA")); \
410 myFieldName->setText(""); \
414 SELECTBYNUM(onPointIdEdit, GetNumberOfPoints);
415 SELECTBYNUM(onCellIdEdit, GetNumberOfCells);