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"
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
44 #include <vtkDataSet.h>
47 #include "VisuGUI_CellsResultsDlg.h"
48 #include "VisuGUI_PointsResultsDlg.h"
49 #include "VisuGUI_Selection.h"
51 int PickViewer(QAD_Study *theActiveStudy, int theSelectionMode){
52 SALOME_Selection *aSel = SALOME_Selection::Selection(theActiveStudy->getSelection());
53 SALOME_ListIteratorOfListIO It(aSel->StoredIObjects());
54 for(;It.More(); It.Next()){
55 Handle(SALOME_InteractiveObject) IObject = It.Value();
56 if (aSel->SelectionMode() == theSelectionMode ){
57 if (aSel->HasIndex(IObject)) {
58 TColStd_MapOfInteger MapIndex ;
59 aSel->GetIndex(IObject, MapIndex) ;
60 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
61 for(;ite.More(); ite.Next())
69 template<class TData, class TDialog> void SetMessage(TData* theData, int theId, TDialog* theDialog){
72 if (vtkDataArray *Scalar = theData->GetScalars()){
73 float aVal = Scalar->GetTuple1(theId);
74 Msg_1.sprintf("%6.3g",aVal);
76 Msg_1.sprintf("NO DATA");
77 theDialog->ScalValue->setText( Msg_1.latin1() );
81 if (vtkDataArray *Vector = theData->GetVectors()){
82 float *aVal = Vector->GetTuple3(theId);
83 Msg_2.sprintf("%6.3g; %6.3g; %6.3g",aVal[0],aVal[1],aVal[2]);
85 Msg_2.sprintf("NO DATA");
86 theDialog->VectTxt->setText( Msg_2.latin1() );
89 // ============================================================================================ //
91 // ============================================================================================ //
93 void VisuGUI_Selection::PickingCell(QAD_Study *theActiveStudy, vtkDataSet *theDataSet){
94 int id = PickViewer(theActiveStudy,SelectionCell);
96 VisuGUI_CellsResultsDlg *aResultsDlg = new VisuGUI_CellsResultsDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
97 vtkCellData *aData = theDataSet->GetCellData();
98 vtkCell *aCell = theDataSet->GetCell(id);
100 float aPntCoord[12][3];
101 int aNbOfPoints = aCell->GetNumberOfPoints();
102 vtkIdList *aPointList = aCell->GetPointIds();
103 QListViewItem* anItem = NULL;
104 for(int i = 0; i < aNbOfPoints; i++){
106 int idCurrent = aPointList->GetId(i);
107 theDataSet->GetPoint(idCurrent,aCoord);
108 for (int j=0; j<3; j++)
109 aPntCoord[i][j]=aCoord[j];
110 anItem = new QListViewItem(aResultsDlg->ListPoints,
112 QString::number( idCurrent ),
113 QString::number( aPntCoord[i][0] ),
114 QString::number( aPntCoord[i][1] ),
115 QString::number( aPntCoord[i][2] ));
118 SetMessage(aData,id,aResultsDlg);
120 aResultsDlg->IdCell->setText( QString::number( id ) );
121 aResultsDlg->NbPoint->setText( QString::number( aNbOfPoints ) );
128 // ============================================================================================ //
130 // ============================================================================================ //
132 void VisuGUI_Selection::PickingPoint(QAD_Study *theActiveStudy, vtkDataSet *theDataSet){
133 int id = PickViewer(theActiveStudy,SelectionPoint);
135 VisuGUI_PointsResultsDlg *aResultsDlg = new VisuGUI_PointsResultsDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
136 vtkPointData *aData = theDataSet->GetPointData();
139 theDataSet->GetPoint(id,Coord);
140 aResultsDlg->CoordX->setText( QString::number( Coord[0] ) );
141 aResultsDlg->CoordY->setText( QString::number( Coord[1] ) );
142 aResultsDlg->CoordZ->setText( QString::number( Coord[2] ) );
143 aResultsDlg->IdPoint->setText( QString::number(id) );
145 SetMessage(aData,id,aResultsDlg);
152 void VisuGUI_Selection::Highlight(QAD_Study *theActiveStudy, const Handle(SALOME_InteractiveObject)& theIO, int theId){
153 MESSAGE("HighlightCell");
154 SALOME_Selection *aSel = SALOME_Selection::Selection(theActiveStudy->getSelection());
155 aSel->AddIObject( theIO, false );
156 aSel->AddOrRemoveIndex( theIO, theId, false, true );