2 // File : VisuGUI_Selection.cxx
3 // Created : Wed Aug 01 10:23:06 2001
4 // Author : Laurent CORNABE & Hubert ROLLAND
7 // Copyright : PRINCIPIA
10 #include "utilities.h"
11 #include <TColStd_MapOfInteger.hxx>
12 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
13 #include "SALOME_ListIteratorOfListIO.hxx"
15 #include "SALOME_Selection.h"
16 #include "VISU_Actor.h"
19 #include <qfiledialog.h>
20 #include <qapplication.h>
21 #include <qcolordialog.h>
26 #include <vtkDataSetMapper.h>
27 #include <vtkDataSetReader.h>
28 #include <vtkPointPicker.h>
29 #include <vtkLookupTable.h>
30 #include <vtkPolyDataSource.h>
31 #include <vtkDataSet.h>
33 #include <vtkMaskPoints.h>
34 #include <vtkUnstructuredGrid.h>
36 #include "VisuGUI_CellsResultsDlg.h"
37 #include "VisuGUI_PointsResultsDlg.h"
38 #include "VisuGUI_Selection.h"
52 int VisuGUI_Selection::PickViewer(QAD_Study *ActiveStudy, int mode)
54 SALOME_Selection *Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
55 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
56 for(;It.More();It.Next())
58 Handle(SALOME_InteractiveObject)IObject = It.Value();
59 if (Sel->SelectionMode() == mode ) // Selection MODE
61 if (Sel->HasIndex(IObject))
63 TColStd_MapOfInteger MapIndex ;
64 Sel->GetIndex(IObject, MapIndex) ;
65 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
66 for (;ite.More(); ite.Next())
68 MESSAGE("Cell ID =" << ite.Key())
77 void VisuGUI_Selection::PickingResults(QAD_Study *ActiveStudy, int mode, VISU_Actor *Actor)
80 if ( (mode == SelectionCell) || (mode == SelectionEdge) ) // Cell mode
82 PickingCell(ActiveStudy, Actor);
85 else if (mode == SelectionPoint) // Point Mode
87 PickingPoint(ActiveStudy, Actor);
91 // ============================================================================================ //
93 // ============================================================================================ //
95 void VisuGUI_Selection::PickingCell(QAD_Study *ActiveStudy, VISU_Actor *Actor)
101 vtkIdList *PointList;
102 vtkCellData *CellData;
103 vtkPointData *PointData;
104 vtkPoints *Points = vtkPoints::New();
105 float Point_Coord[12][3];
106 float CoordCurrent[3];
109 mode = SelectionCell;
111 vtkActor* anActor = vtkActor::SafeDownCast( Actor );
112 id=PickViewer(ActiveStudy,mode);
113 if (id >= 0) // Cell exist
115 VisuGUI_CellsResultsDlg *ResultsDlg = new VisuGUI_CellsResultsDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
117 vtkDataSetMapper *Mapper = (vtkDataSetMapper*) (anActor->GetMapper());
118 Mapper->SetInput(anActor->GetMapper()->GetInput());
119 Data=Mapper->GetInput();
120 Cell=Data->GetCell(id);
121 CellData=Data->GetCellData();
122 int NbOfPoints=Cell->GetNumberOfPoints();
123 PointList=Cell->GetPointIds();
124 QListViewItem* item = 0;
125 for(int i=0; i<NbOfPoints; i++)
127 idCurrent = PointList->GetId(i);
128 Data->GetPoint(idCurrent,CoordCurrent);
129 for (int j=0; j<3; j++)
130 Point_Coord[i][j]=CoordCurrent[j];
131 item = new QListViewItem(ResultsDlg->ListPoints,
133 QString::number( idCurrent ),
134 QString::number( Point_Coord[i][0] ),
135 QString::number( Point_Coord[i][1] ),
136 QString::number( Point_Coord[i][2] ));
140 Scalar=CellData->GetScalars();
144 ScalarValue=Scalar->GetScalar(id);
145 sprintf(Msg_1,"( %s ) %4f",Actor->FieldName,ScalarValue);
150 sprintf(Msg_1,"No scalar on Cell");
154 Vector=CellData->GetVectors();
158 Vector->GetVector(id,VectorValue);
159 sprintf(Msg_2,"( %s ) %.4f %.4f %.4f",Actor->FieldName,VectorValue[0],VectorValue[1],VectorValue[2]);
164 sprintf(Msg_2,"No Vector on Cell");
167 ResultsDlg->IdCell->setText( QString::number( id ) );
168 ResultsDlg->NbPoint->setText( QString::number( NbOfPoints ) );
169 ResultsDlg->ScalValue->setText( Msg_1 );
170 ResultsDlg->VectTxt->setText( Msg_2 );
177 // ============================================================================================ //
179 // ============================================================================================ //
181 void VisuGUI_Selection::PickingPoint(QAD_Study *ActiveStudy, VISU_Actor *Actor)
186 vtkPointData *PointData;
188 mode = SelectionPoint;
190 id=PickViewer(ActiveStudy,mode);
193 VisuGUI_PointsResultsDlg *ResultsDlg = new VisuGUI_PointsResultsDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
194 vtkDataSetMapper *Mapper = (vtkDataSetMapper*) (Actor->GetMapper());
195 Data=Mapper->GetInput();
196 PointData=Data->GetPointData();
198 Data->GetPoint(id,Coord);
199 ResultsDlg->CoordX->setText( QString::number( Coord[0] ) );
200 ResultsDlg->CoordY->setText( QString::number( Coord[1] ) );
201 ResultsDlg->CoordZ->setText( QString::number( Coord[2] ) );
202 // ActiveStudy->setMessage(Msg);
204 Scalar=PointData->GetScalars();
208 ScalarValue=Scalar->GetScalar(id);
209 sprintf(Msg_1,"( %s ) %4f",Actor->FieldName,ScalarValue);
214 sprintf(Msg_1,"No scalar at Point");
216 // ActiveStudy->setMessage(Msg_1);
219 Vector=PointData->GetVectors();
223 Vector->GetVector(id,VectorValue);
224 sprintf(Msg_2,"( %s ) %.4f %.4f %.4f",Actor->FieldName,VectorValue[0],VectorValue[1],VectorValue[2]);
229 sprintf(Msg_2,"No Vector at Point");
231 ResultsDlg->IdPoint->setText( QString::number(id) );
232 ResultsDlg->ScalValue->setText(Msg_1);
233 ResultsDlg->VectTxt->setText(Msg_2);
237 // ActiveStudy->setMessage( Msg_2 ) ;
241 // ============================================================================================ //
243 // ============================================================================================ //
245 void VisuGUI_Selection::HighlightCell(int idCell, VISU_Actor *Actor, vtkRenderer *ren)
247 MESSAGE("HighlightCell")
248 vtkActor *Cell_Actor = vtkActor::New();
250 vtkUnstructuredGrid* Cell_UGrid = vtkUnstructuredGrid::New();
251 if ( Actor->GetMapper()->GetInput()->IsA("vtkUnstructuredGrid") ) {
252 vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( Actor->GetMapper()->GetInput() );
253 // if (UGrid != NULL) // LCO 1707
255 vtkIdList *ptIds = vtkIdList::New(); ptIds->Allocate(12);
256 vtkDataSetMapper* Cell_Mapper = vtkDataSetMapper::New();
258 Cell_UGrid->SetPoints( UGrid->GetPoints() );
259 UGrid->GetCellPoints( idCell, ptIds );
260 Cell_UGrid->InsertNextCell(Actor->GetMapper()->GetInput()->GetCellType( idCell ), ptIds);
262 Cell_Mapper->SetInput(Cell_UGrid);
263 Cell_Actor->SetMapper(Cell_Mapper);
265 ren->AddActor( Cell_Actor );
267 Cell_Actor->GetProperty()->SetColor(1,1,0);
268 Cell_Actor->GetProperty()->SetRepresentationToSurface();
269 Cell_Actor->VisibilityOn();
273 Cell_Actor->Delete();
276 // ============================================================================================ //
277 // HIGHLIGHT POINT //
278 // ============================================================================================ //
280 void VisuGUI_Selection::HighlightPoint(int idPoint, int nbPoints, VISU_Actor *Actor, vtkRenderer *ren)
282 vtkActor *Point_Actor = vtkActor::New();
284 MESSAGE("HighlightPoint")
285 if ( Actor->GetMapper()->GetInput()->IsA("vtkUnstructuredGrid") ) {
286 vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( Actor->GetMapper()->GetInput() );
287 // if (UGrid != NULL) // LCO 1707
289 vtkUnstructuredGrid* Point_UGrid = vtkUnstructuredGrid::New();
292 vtkPoints *Points = vtkPoints::New();
293 vtkMaskPoints* verts = vtkMaskPoints::New();
294 vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
295 Points->SetNumberOfPoints(nbPoints);
297 UGrid->GetPoint( idPoint, pts) ;
298 // Points->SetPoint(idPoint, 0., 0., 0. );
299 Points->SetPoint(idPoint, pts);
300 Point_UGrid->SetPoints(Points);
301 verts->SetInput(Point_UGrid);
302 verts->SetGenerateVertices(1);
303 verts->SetOnRatio(1);
304 vertMapper->SetInput(verts->GetOutput());
305 Point_Actor->SetMapper(vertMapper);
306 ren->AddActor( Point_Actor );
307 Point_Actor->GetProperty()->SetColor(1,1,0);
308 Point_Actor->GetProperty()->SetRepresentationToSurface();
309 Point_Actor->VisibilityOn();
312 Point_Actor->Delete();
315 // ============================================================================================ //
316 // Function to return results individual //
317 // ============================================================================================ //
319 int VisuGUI_Selection::getId()
324 char *VisuGUI_Selection::getMsg(int nb)
332 float *VisuGUI_Selection::getCoord()
337 float VisuGUI_Selection::getScalar()
340 return (ScalarValue);
345 float *VisuGUI_Selection::getVector()
348 return (VectorValue);
353 int VisuGUI_Selection::getMode()