]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Selection.cxx
Salome HOME
NRI : merge from 1.2c
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VisuGUI_Selection.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND 
26 //  Module : VISU
27 //  $Header$
28
29 using namespace std;
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
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
38
39 #include <qstring.h>
40 #include <qlabel.h>
41 #include <qspinbox.h>
42 #include <qlistbox.h>
43
44 #include <vtkDataSet.h>
45 #include <vtkCell.h>
46
47 #include "VisuGUI_CellsResultsDlg.h"
48 #include "VisuGUI_PointsResultsDlg.h"
49 #include "VisuGUI_Selection.h"
50
51 template<class TData, class TDialog> void SetMessage(TData* theData, int theId, TDialog* theDialog){
52   // Scalar result
53   QString Msg_1;
54   if (vtkDataArray *Scalar = theData->GetScalars()){
55     float aVal = Scalar->GetTuple1(theId);
56     Msg_1.sprintf("%6.3g",aVal);
57   }else
58     Msg_1.sprintf("NO DATA");
59   theDialog->ScalValue->setText( Msg_1.latin1() );
60   
61   // Vector result
62   QString Msg_2;
63   if (vtkDataArray *Vector = theData->GetVectors()){
64     float *aVal = Vector->GetTuple3(theId);
65     Msg_2.sprintf("%6.3g; %6.3g; %6.3g",aVal[0],aVal[1],aVal[2]);
66   }else
67     Msg_2.sprintf("NO DATA");
68   theDialog->VectTxt->setText( Msg_2.latin1() );
69 }
70
71 // ============================================================================================ //
72 //                                      PICKING CELL                                            //
73 // ============================================================================================ //
74
75 void VisuGUI_Selection::PickingCell(QAD_Study *theActiveStudy, vtkDataSet *theDataSet, int theId){
76   if(theId >= 0){
77     VisuGUI_CellsResultsDlg *aResultsDlg = new VisuGUI_CellsResultsDlg(QAD_Application::getDesktop(), 0, TRUE, 0); 
78     vtkCellData *aData = theDataSet->GetCellData();
79     vtkCell *aCell = theDataSet->GetCell(theId);
80
81     float aPntCoord[12][3];
82     int aNbOfPoints = aCell->GetNumberOfPoints();
83     vtkIdList *aPointList = aCell->GetPointIds();
84     QListViewItem* anItem = NULL;
85     for(int i = 0; i < aNbOfPoints; i++){
86       float aCoord[3];
87       int idCurrent = aPointList->GetId(i);
88       theDataSet->GetPoint(idCurrent,aCoord);
89       for (int j=0; j<3; j++)
90         aPntCoord[i][j]=aCoord[j];
91       anItem = new QListViewItem(aResultsDlg->ListPoints, 
92                                  anItem, 
93                                  QString::number( idCurrent ),
94                                  QString::number( aPntCoord[i][0] ),
95                                  QString::number( aPntCoord[i][1] ),
96                                  QString::number( aPntCoord[i][2] ));
97     }
98
99     SetMessage(aData,theId,aResultsDlg);
100
101     aResultsDlg->IdCell->setText( QString::number( theId ) );
102     aResultsDlg->NbPoint->setText( QString::number( aNbOfPoints ) );
103     aResultsDlg->exec(); 
104     delete aResultsDlg;
105   }
106 }
107
108
109 // ============================================================================================ //
110 //                                      PICKING POINT                                           //
111 // ============================================================================================ //
112
113 void VisuGUI_Selection::PickingPoint(QAD_Study *theActiveStudy, vtkDataSet *theDataSet, int theId){
114   if(theId >= 0){
115     VisuGUI_PointsResultsDlg *aResultsDlg = new VisuGUI_PointsResultsDlg(QAD_Application::getDesktop(), 0, TRUE, 0); 
116     vtkPointData *aData = theDataSet->GetPointData();
117
118     float Coord[3];
119     theDataSet->GetPoint(theId,Coord);
120     aResultsDlg->CoordX->setText( QString::number( Coord[0] ) );
121     aResultsDlg->CoordY->setText( QString::number( Coord[1] ) );
122     aResultsDlg->CoordZ->setText( QString::number( Coord[2] ) );
123     aResultsDlg->IdPoint->setText( QString::number(theId) );
124     
125     SetMessage(aData,theId,aResultsDlg);
126
127     aResultsDlg->exec(); 
128     delete aResultsDlg;
129   }
130 }
131
132 void VisuGUI_Selection::Highlight(QAD_Study *theActiveStudy, const Handle(SALOME_InteractiveObject)& theIO, int theId){
133   MESSAGE("HighlightCell");
134   SALOME_Selection *aSel = SALOME_Selection::Selection(theActiveStudy->getSelection());
135   aSel->AddIObject(theIO);
136   aSel->AddOrRemoveIndex(theIO, theId, false);
137 }