1 // Copyright (C) 2009-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <vtkRenderer.h>
24 #include <vtkUnstructuredGrid.h>
25 #include <vtkDataSetMapper.h>
26 #include "vtkCellArray.h"
27 #include "vtkPolyData.h"
29 #include <VTKViewer_CellLocationsArray.h>
30 #include <SVTK_ViewModel.h>
32 #include "HEXABLOCKGUI_Trace.hxx"
33 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
34 #include "HEXABLOCKGUI.hxx"
39 #define M_PI 3.1415927
43 using namespace HEXABLOCK::GUI;
44 using namespace HEXA_NS;
46 Document_Actor::Document_Actor( Document* doc, const QString& entry ):
50 DEBTRACE("Document_Actor::Document_Actor " << entry.toLatin1() );
51 const char* docName = ((doc != NULL) ? doc->getName() : "");
52 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK", docName );//,theName); CS_TODO
54 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
55 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
56 aMapper->SetInputData(aGrid); // saclay
57 // aMapper->SetInput(aGrid);
60 SetVisibility( true );//VisibilityOff();
61 SetPickable( true ); //PickableOff();//
65 vtkProperty* aProp = vtkProperty::New();
67 // aProp->SetRepresentationToSurface();
68 aProp->SetRepresentationToWireframe();
69 // aProp->SetRepresentationToPoints();
70 aProp->EdgeVisibilityOn ();
71 aProp->SetPointSize(5);
74 // SetPointRepresentation(true);
77 Document_Actor::~Document_Actor()
83 vtkUnstructuredGrid* Document_Actor::getUnstructuredGrid()
85 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
87 _doc->reorderFaces(); //CS_TEST
89 map <int,vtkIdType> vtkNodeId;
90 map <vtkIdType, int> hexaNodeId;
93 vtkPoints* aPoints = vtkPoints::New();
94 int nbVertex = _doc->countVertex();
95 aPoints->SetNumberOfPoints( nbVertex );
99 for ( int i=0; i <nbVertex; ++i ){
100 v = _doc->getVertex(i);
101 aPoints->SetPoint( i, v->getX(), v->getY(), v->getZ() );
102 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
103 vtkNodeId [ vertexId ] = i;
104 hexaNodeId[ i ] = vertexId ;
105 // vtkNodeId [ vertexId ] = i+1;
106 // hexaNodeId[ i+1 ] = vertexId ;
109 theGrid->SetPoints( aPoints );
111 // theGrid->SetCells( 0, 0, 0, 0, 0 );
114 // Calculate cells size
115 int nb0DElement = _doc->countVertex();
116 int nbEdge = _doc->countEdge();
117 int nbFace = _doc->countQuad();
118 int nbVolume = _doc->countHexa();
120 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
121 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
124 vtkCellArray* aConnectivity = vtkCellArray::New();
125 aConnectivity->Allocate( aCellsSize, 0 );
127 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
128 aCellTypesArray->SetNumberOfComponents( 1 );
129 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
131 vtkIdList *anIdList = vtkIdList::New();
132 vtkIdType iVtkElem = 0;
133 // vtkIdType iVtkElem = 1; //CS_TEST
137 for ( int i=0; i<nb0DElement; ++i ){
138 anIdList->SetNumberOfIds( 1 );
139 v = _doc->getVertex(i);
140 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
141 vtkElemsId[iHexaElem] = iVtkElem;
142 hexaElemsId[iVtkElem] = iHexaElem;
143 anIdList->SetId(0, vtkNodeId[iHexaElem]);
144 aConnectivity->InsertNextCell( anIdList );
145 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
151 Vertex* vertexElem = NULL;
152 for ( int i=0; i<nbEdge; ++i ){
153 anIdList->SetNumberOfIds( 2 );
154 e = _doc->getEdge(i);
155 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
156 vtkElemsId[iHexaElem] = iVtkElem;
157 hexaElemsId[iVtkElem] = iHexaElem;
159 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
160 vertexElem = e->getVertex( j );
161 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
163 aConnectivity->InsertNextCell( anIdList );
164 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
170 for ( int i=0; i<nbFace; ++i ){
171 anIdList->SetNumberOfIds( 4 );
172 q = _doc->getQuad(i);
173 iHexaElem = reinterpret_cast<intptr_t>(q); //q->getId();
174 vtkElemsId[iHexaElem] = iVtkElem;
175 hexaElemsId[iVtkElem] = iHexaElem;
177 for( vtkIdType j = 0; j< 4; ++j ){
178 vertexElem = q->getVertex( j );
179 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
181 aConnectivity->InsertNextCell( anIdList );
182 aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
188 std::map<int, int> connectivity;
197 for ( int i=0; i<nbVolume; ++i ){
198 anIdList->SetNumberOfIds( 8 );
199 h = _doc->getHexa(i);
200 iHexaElem = reinterpret_cast<intptr_t>(h); //q->getId();
201 vtkElemsId[iHexaElem] = iVtkElem;
202 hexaElemsId[iVtkElem] = iHexaElem;
204 for( vtkIdType j = 0; j< 8; ++j ){
205 vertexElem = h->getVertex( j );// );
206 anIdList->SetId( connectivity[j], vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ]);//vertexElem->getId() ]);
208 aConnectivity->InsertNextCell( anIdList );
209 aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
215 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
219 // Insert cells in grid
220 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
221 aCellLocationsArray->SetNumberOfComponents( 1 );
222 aCellLocationsArray->SetNumberOfTuples( aNbCells );
223 // std::cout << "aNbCells =>" << aNbCells << std::endl;
225 aConnectivity->InitTraversal();
226 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
227 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
229 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
231 aCellLocationsArray->Delete();
232 aCellTypesArray->Delete();
233 aConnectivity->Delete();
235 //std::cout << "theGrid->GetNumberOfCells()" << theGrid->GetNumberOfCells() << std::endl;
240 // =============================================================== Abu : debut
241 // ===================================================== Constructeur
242 Associate_Actor::Associate_Actor( Document* doc, const QString& entry)
243 : SALOME_Actor(), _doc( doc )
245 DEBTRACE("Associate_Actor::Associate_Actor " << entry.toLatin1() );
246 const char* docName = ((doc != NULL) ? doc->getName() : "");
247 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK", docName );//,theName); CS_TODO
249 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
251 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
252 aMapper->SetInputData(aGrid); // saclay
253 // aMapper->SetInput (aGrid);
256 SetVisibility( true );//VisibilityOff();
257 SetPickable( true ); //PickableOff();//
258 SetMapper( aMapper );
261 vtkProperty* aProp = vtkProperty::New();
262 aProp->SetColor(0,255,0);
263 // aProp->SetRepresentationToSurface();
264 aProp->SetRepresentationToWireframe();
265 // aProp->SetRepresentationToPoints();
266 aProp->EdgeVisibilityOn ();
267 aProp->SetPointSize(5);
268 SetProperty( aProp );
270 // SetPointRepresentation(true);
272 // ===================================================== getUnstructuredGrid
274 vtkUnstructuredGrid* Associate_Actor::getUnstructuredGrid()
276 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
278 _doc->reorderFaces(); //CS_TEST
280 std::map<int,vtkIdType> vtkNodeId;
281 std::map<vtkIdType, int> hexaNodeId;
284 vtkPoints* aPoints = vtkPoints::New();
285 int nbVertex = _doc->countVertex();
286 aPoints->SetNumberOfPoints( nbVertex );
290 for ( int i=0; i <nbVertex; ++i ){
291 v = _doc->getVertex(i);
292 aPoints->SetPoint( i, v->getX()+6, v->getY()+6, v->getZ() );
293 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
294 vtkNodeId [ vertexId ] = i;
295 hexaNodeId[ i ] = vertexId ;
296 // vtkNodeId [ vertexId ] = i+1;
297 // hexaNodeId[ i+1 ] = vertexId ;
300 theGrid->SetPoints( aPoints );
302 // theGrid->SetCells( 0, 0, 0, 0, 0 );
304 // Calculate cells size
305 int nb0DElement = _doc->countVertex();
306 int nbEdge = _doc->countEdge();
307 int nbFace = _doc->countQuad();
308 int nbVolume = _doc->countHexa();
310 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
311 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
314 vtkCellArray* aConnectivity = vtkCellArray::New();
315 aConnectivity->Allocate( aCellsSize, 0 );
317 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
318 aCellTypesArray->SetNumberOfComponents( 1 );
319 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
321 vtkIdList *anIdList = vtkIdList::New();
322 vtkIdType iVtkElem = 0;
323 // vtkIdType iVtkElem = 1; //CS_TEST
327 for ( int i=0; i<nb0DElement; ++i ){
328 anIdList->SetNumberOfIds( 1 );
329 v = _doc->getVertex(i);
330 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
331 vtkElemsId[iHexaElem] = iVtkElem;
332 hexaElemsId[iVtkElem] = iHexaElem;
333 anIdList->SetId(0, vtkNodeId[iHexaElem]);
334 aConnectivity->InsertNextCell( anIdList );
335 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
341 Vertex* vertexElem = NULL;
342 for ( int i=0; i<nbEdge; ++i ){
343 anIdList->SetNumberOfIds( 2 );
344 e = _doc->getEdge(i);
345 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
346 vtkElemsId[iHexaElem] = iVtkElem;
347 hexaElemsId[iVtkElem] = iHexaElem;
349 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
350 vertexElem = e->getVertex( j );
351 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
353 aConnectivity->InsertNextCell( anIdList );
354 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
360 for ( int i=0; i<nbFace; ++i ){
361 anIdList->SetNumberOfIds( 4 );
362 q = _doc->getQuad(i);
363 iHexaElem = reinterpret_cast<intptr_t>(q); //q->getId();
364 vtkElemsId[iHexaElem] = iVtkElem;
365 hexaElemsId[iVtkElem] = iHexaElem;
367 for( vtkIdType j = 0; j< 4; ++j ){
368 vertexElem = q->getVertex( j );
369 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
371 aConnectivity->InsertNextCell( anIdList );
372 aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
378 std::map<int, int> connectivity;
387 for ( int i=0; i<nbVolume; ++i ){
388 anIdList->SetNumberOfIds( 8 );
389 h = _doc->getHexa(i);
390 iHexaElem = reinterpret_cast<intptr_t>(h); //q->getId();
391 vtkElemsId[iHexaElem] = iVtkElem;
392 hexaElemsId[iVtkElem] = iHexaElem;
394 for( vtkIdType j = 0; j< 8; ++j ){
395 vertexElem = h->getVertex( j );// );
396 anIdList->SetId( connectivity[j], vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ]);//vertexElem->getId() ]);
398 aConnectivity->InsertNextCell( anIdList );
399 aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
405 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
409 // Insert cells in grid
410 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
411 aCellLocationsArray->SetNumberOfComponents( 1 );
412 aCellLocationsArray->SetNumberOfTuples( aNbCells );
413 // std::cout << "aNbCells =>" << aNbCells << std::endl;
415 aConnectivity->InitTraversal();
416 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
417 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
419 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
421 aCellLocationsArray->Delete();
422 aCellTypesArray->Delete();
423 aConnectivity->Delete();
430 // -----------------------------------------------------------------------
431 // VtkDocumentGraphicView implementation
432 // -----------------------------------------------------------------------
433 VtkDocumentGraphicView::VtkDocumentGraphicView( DocumentModel* documentModel,
434 SVTK_ViewWindow* view, QWidget* parent ):
435 QAbstractItemView(parent),
437 documentActor( NULL ),
438 associateActor (NULL), // Abu
439 _currentChanged( false ),
445 setModel(documentModel);
446 patternDataModel = new PatternDataModel(parent);
447 patternGeomModel = new PatternGeomModel(parent);
448 groupsModel = new GroupsModel(parent);
449 meshModel = new MeshModel(parent);
451 patternDataModel->setSourceModel(documentModel);
452 patternGeomModel->setSourceModel(documentModel);
453 groupsModel->setSourceModel(documentModel);
454 meshModel->setSourceModel(documentModel);
457 patternDataSelectionModel = new PatternDataSelectionModel(patternDataModel);
458 patternGeomSelectionModel = new PatternGeomSelectionModel(patternGeomModel);
459 groupsSelectionModel = new GroupsSelectionModel(groupsModel);
460 meshSelectionModel = new MeshSelectionModel(meshModel );
462 setSelectionModel(patternDataSelectionModel);
465 //Loads the graphic view document
466 void VtkDocumentGraphicView::loadDocument()
468 DocumentModel* docModel = getDocumentModel();
469 if (docModel == NULL) return;
474 //Loads the document from the file in this graphic view
475 void VtkDocumentGraphicView::loadDocument(const QString& file)
477 if ( file.isEmpty() ) return;
478 getDocumentModel()->load(file);
481 //Saves the graphic view's document in the file
482 void VtkDocumentGraphicView::saveDocument(const QString& file)
484 if (file.isEmpty()) return;
485 getDocumentModel()->save(file);
489 VtkDocumentGraphicView::~VtkDocumentGraphicView()
493 delete patternDataModel;
497 //Delete Selection Model/ Disconnect signals on delete (Qt)
498 // delete patternDataSelectionModel;
499 // delete groupsSelectionModel;
500 // delete meshSelectionModel;
503 void VtkDocumentGraphicView::setWindowTitle(const QString& title)
505 viewWindow->setWindowTitle( QString("hexablock : ") + title );
508 void VtkDocumentGraphicView::onPatternDatachanged()
513 void VtkDocumentGraphicView::removeActor()
515 if ( documentActor != NULL && viewWindow != NULL){
516 viewWindow->RemoveActor( documentActor );
517 documentActor->Delete();
521 void VtkDocumentGraphicView::update()
523 DocumentModel* theModel = dynamic_cast<DocumentModel*>( model() );
524 if (theModel == NULL || viewWindow == NULL) return;
526 Document* theDocumentImpl = theModel->documentImpl();
527 QString theDocumentEntry = theModel->documentEntry();
529 if ( documentActor ){
530 viewWindow->RemoveActor( documentActor );
531 documentActor->Delete();
533 documentActor = new Document_Actor( theDocumentImpl, theDocumentEntry );
534 viewWindow->AddActor( documentActor );
536 viewWindow->getRenderer()->Render();
537 viewWindow->Repaint();
540 viewWindow->onFitAll();
545 void VtkDocumentGraphicView::setVertexSelection()
547 setSelectionMode(NodeSelection);
550 void VtkDocumentGraphicView::setEdgeSelection()
552 setSelectionMode(EdgeSelection);
555 void VtkDocumentGraphicView::setQuadSelection()
557 setSelectionMode(FaceSelection);
560 void VtkDocumentGraphicView::setHexaSelection()
562 // SetSelectionMode(VolumeSelection);
563 setSelectionMode(FaceSelection); //temporary for hexa selection debug
564 selectionMode = HEXA_TREE;
565 // aProp->FaceVisibilityOff (); //would debug hexa preselection, selection???
568 void VtkDocumentGraphicView::setAllSelection()
570 setSelectionMode(ActorSelection);
574 void VtkDocumentGraphicView::setSelectionMode(Selection_Mode theMode)
576 if (viewWindow == NULL || selectionMode == theMode)
579 HEXABLOCKGUI::selectionMgr()->clearSelected();
580 viewWindow->SetSelectionMode( theMode );
581 selectionMode = theMode;
584 void VtkDocumentGraphicView::setSelectionMode( const QModelIndex& eltIndex )
586 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
587 if ( !treeVariant.isValid() ) return;
588 int eltType = treeVariant.toInt();
590 if ( selectionMode == eltType ) return;
595 case GEOMPOINT_DIR_TREE:
596 case VERTEX_DIR_TREE : setVertexSelection(); break;
599 case GEOMEDGE_DIR_TREE:
600 case EDGE_DIR_TREE : setEdgeSelection(); break;
603 case GEOMFACE_DIR_TREE:
604 case QUAD_DIR_TREE : setQuadSelection(); break;
607 case GEOMSHAPE_DIR_TREE:
608 case HEXA_DIR_TREE : setHexaSelection(); break;
609 case PROPAGATION_TREE :
610 case PROPAGATION_DIR_TREE : setEdgeSelection(); break;
611 default: setAllSelection();
615 void VtkDocumentGraphicView::getSelected(SALOME_ListIO& selectedObjects)
617 HEXABLOCKGUI::selectionMgr()->selectedObjects( selectedObjects, SVTK_Viewer::Type());
620 void VtkDocumentGraphicView::clearSelection()
622 if (viewWindow != NULL)
624 // viewWindow->unHighlightAll();
625 setSelectionMode(ActorSelection);
629 void VtkDocumentGraphicView::highlight( const QModelIndex& ielt )
632 QModelIndexList indexList;
634 highlight(indexList);
638 void VtkDocumentGraphicView::highlight( const QModelIndexList& elts )
641 if (elts.size() == 0 || viewWindow == NULL || documentActor == NULL)
643 SVTK_Selector* selector = viewWindow->GetSelector();
644 if ( selector == NULL )
646 // Set selection mode in VTK view
647 // viewWindow->SetSelectionMode(VolumeSelection);
649 // --- elements highlight ---
650 TColStd_IndexedMapOfInteger aMap;
654 foreach( const QModelIndex& iElt, elts ){
657 eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
658 vtkElemsId = documentActor->vtkElemsId[ eltEntry.toInt() ];
659 if ( vtkElemsId > 0 )
660 aMap.Add( vtkElemsId );
663 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
664 viewWindow->highlight( documentActor->getIO(), true, true );
668 void VtkDocumentGraphicView::highlightGroups( const QModelIndex& eltIndex )
670 if ( groupsModel == NULL || viewWindow == NULL || documentActor == NULL) return;
671 SVTK_Selector* selector = viewWindow->GetSelector();
672 if ( selector == NULL ) return;
674 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
675 if ( !treeVariant.isValid())
678 int eltType = treeVariant.toInt();
679 if ( eltType != GROUP_TREE )
682 //Get elements to highlight
683 DocumentModel::Group kind;
684 QModelIndexList iElements = groupsModel->getGroupElements( eltIndex, kind );
685 if (iElements.count() == 0) return;
687 // ---------- elements highlight --------------
689 // Set selection mode in VTK view
691 case HexaCell: case HexaNode: viewWindow->SetSelectionMode(VolumeSelection); break;
692 case QuadCell: case QuadNode: viewWindow->SetSelectionMode(FaceSelection); break;
693 case EdgeCell: case EdgeNode: viewWindow->SetSelectionMode(EdgeSelection); break;
694 case VertexNode: viewWindow->SetSelectionMode(NodeSelection); break;
697 TColStd_MapOfInteger aMap;
701 foreach( const QModelIndex& iElt, iElements ){
704 eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
705 vtkElemsId = documentActor->vtkElemsId[ eltEntry.toInt() ];
706 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
710 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
711 viewWindow->highlight( documentActor->getIO(), true, true );
712 documentActor->highlight( false );
717 void VtkDocumentGraphicView::highlightPropagation( const QModelIndex& eltIndex )
719 if ( meshModel == NULL || viewWindow == NULL || documentActor == NULL) return;
720 SVTK_Selector* selector = viewWindow->GetSelector();
721 if ( selector == NULL ) return;
723 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
724 if ( !treeVariant.isValid())
727 int eltType = treeVariant.toInt();
728 if ( eltType != PROPAGATION_TREE )
731 // Get elements to highlight
732 QModelIndexList iEdges = meshModel->getPropagation( eltIndex );
733 if (iEdges.count() == 0) return;
735 // ---------- elements highlight --------------
737 // Set selection mode in VTK view
738 viewWindow->SetSelectionMode(EdgeSelection);
740 TColStd_MapOfInteger aMap;
744 foreach( const QModelIndex& iEdge, iEdges ){
747 edgeEntry = iEdge.data( HEXA_ENTRY_ROLE ).toString();
748 vtkElemsId = documentActor->vtkElemsId[ edgeEntry.toInt() ];
749 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
753 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
754 viewWindow->highlight( documentActor->getIO(), true, true );
755 documentActor->highlight( false );
762 /********************************************************************************
763 * ABSTRACT METHOD ( MUST BE IMPLEMENTED )
764 ********************************************************************************/
766 Returns the item that covers the coordinate given in the view.
768 QModelIndex VtkDocumentGraphicView::indexAt(const QPoint &point) const
770 return QModelIndex();
773 void VtkDocumentGraphicView::scrollTo(const QModelIndex &index, ScrollHint)
778 Returns the position of the item in viewport coordinates.
780 QRect VtkDocumentGraphicView::visualRect(const QModelIndex &index) const
786 int VtkDocumentGraphicView::horizontalOffset() const
788 return horizontalScrollBar()->value();
791 bool VtkDocumentGraphicView::isIndexHidden(const QModelIndex &index) const
796 QModelIndex VtkDocumentGraphicView::moveCursor(QAbstractItemView::CursorAction cursorAction,
797 Qt::KeyboardModifiers /*modifiers*/)
799 QModelIndex current = currentIndex();
804 Find the indices corresponding to the extent of the selection.
806 void VtkDocumentGraphicView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
811 int VtkDocumentGraphicView::verticalOffset() const
813 return verticalScrollBar()->value();
817 Returns a region corresponding to the selection in viewport coordinates.
819 QRegion VtkDocumentGraphicView::visualRegionForSelection(const QItemSelection &selection) const
825 /********************************************************************************
827 ********************************************************************************/
828 void VtkDocumentGraphicView::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint )
832 void VtkDocumentGraphicView::commitData ( QWidget * editor )
836 void VtkDocumentGraphicView::currentChanged( const QModelIndex & current, const QModelIndex & previous )
838 _currentChanged = true;
841 void VtkDocumentGraphicView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )
844 _currentChanged = false;
847 void VtkDocumentGraphicView::editorDestroyed ( QObject * editor )
851 void VtkDocumentGraphicView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end )
855 void VtkDocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
859 void VtkDocumentGraphicView::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
863 void VtkDocumentGraphicView::updateGeometries ()
868 void VtkDocumentGraphicView::setModel ( QAbstractItemModel * model )
870 QAbstractItemView::setModel( model );
872 // PatternDataModel* pdm = dynamic_cast<PatternDataModel*>(model);
874 // connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
876 DocumentModel* dm = dynamic_cast<DocumentModel*>(model);
878 // setWindowTitle( dm->getName() );
879 connect( dm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
880 // connect( dm, SIGNAL( nameChanged(const QString&) ), this, SLOT ( setWindowTitle(const QString&) ) );