1 // Copyright (C) 2009-2023 CEA, EDF
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 <vtkUnsignedCharArray.h>
26 #include <vtkDataSetMapper.h>
27 #include "vtkCellArray.h"
28 #include "vtkPolyData.h"
30 //#include <VTKViewer_CellLocationsArray.h>
31 #include <SVTK_ViewModel.h>
33 #include "HEXABLOCKGUI_Trace.hxx"
34 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
35 #include "HEXABLOCKGUI.hxx"
40 #define M_PI 3.1415927
44 using namespace HEXABLOCK::GUI;
45 using namespace HEXA_NS;
47 Document_Actor::Document_Actor( Document* doc, const QString& entry ):
51 DEBTRACE("Document_Actor::Document_Actor " << entry.toLatin1() );
52 const char* docName = ((doc != NULL) ? doc->getName() : "");
53 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK", docName );//,theName); CS_TODO
55 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
56 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
57 aMapper->SetInputData(aGrid); // saclay
58 // aMapper->SetInput(aGrid);
61 SetVisibility( true );//VisibilityOff();
62 SetPickable( true ); //PickableOff();//
66 vtkProperty* aProp = vtkProperty::New();
68 // aProp->SetRepresentationToSurface();
69 aProp->SetRepresentationToWireframe();
70 // aProp->SetRepresentationToPoints();
71 aProp->EdgeVisibilityOn ();
72 aProp->SetPointSize(5);
75 // SetPointRepresentation(true);
78 Document_Actor::~Document_Actor()
84 vtkUnstructuredGrid* Document_Actor::getUnstructuredGrid()
86 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
88 _doc->reorderFaces(); //CS_TEST
90 map <int,vtkIdType> vtkNodeId;
91 map <vtkIdType, int> hexaNodeId;
94 vtkPoints* aPoints = vtkPoints::New();
95 int nbVertex = _doc->countVertex();
96 aPoints->SetNumberOfPoints( nbVertex );
100 for ( int i=0; i <nbVertex; ++i ){
101 v = _doc->getVertex(i);
102 aPoints->SetPoint( i, v->getX(), v->getY(), v->getZ() );
103 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
104 vtkNodeId [ vertexId ] = i;
105 hexaNodeId[ i ] = vertexId ;
106 // vtkNodeId [ vertexId ] = i+1;
107 // hexaNodeId[ i+1 ] = vertexId ;
110 theGrid->SetPoints( aPoints );
112 // theGrid->SetCells( 0, 0, 0, 0, 0 );
115 // Calculate cells size
116 int nb0DElement = _doc->countVertex();
117 int nbEdge = _doc->countEdge();
118 int nbFace = _doc->countQuad();
119 int nbVolume = _doc->countHexa();
121 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
122 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
125 vtkCellArray* aConnectivity = vtkCellArray::New();
126 aConnectivity->Allocate( aCellsSize, 0 );
128 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
129 aCellTypesArray->SetNumberOfComponents( 1 );
130 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
132 vtkIdList *anIdList = vtkIdList::New();
133 vtkIdType iVtkElem = 0;
134 // vtkIdType iVtkElem = 1; //CS_TEST
138 for ( int i=0; i<nb0DElement; ++i ){
139 anIdList->SetNumberOfIds( 1 );
140 v = _doc->getVertex(i);
141 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
142 vtkElemsId[iHexaElem] = iVtkElem;
143 hexaElemsId[iVtkElem] = iHexaElem;
144 anIdList->SetId(0, vtkNodeId[iHexaElem]);
145 aConnectivity->InsertNextCell( anIdList );
146 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
152 Vertex* vertexElem = NULL;
153 for ( int i=0; i<nbEdge; ++i ){
154 anIdList->SetNumberOfIds( 2 );
155 e = _doc->getEdge(i);
156 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
157 vtkElemsId[iHexaElem] = iVtkElem;
158 hexaElemsId[iVtkElem] = iHexaElem;
160 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
161 vertexElem = e->getVertex( j );
162 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
164 aConnectivity->InsertNextCell( anIdList );
165 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
171 for ( int i=0; i<nbFace; ++i ){
172 anIdList->SetNumberOfIds( 4 );
173 q = _doc->getQuad(i);
174 iHexaElem = reinterpret_cast<intptr_t>(q); //q->getId();
175 vtkElemsId[iHexaElem] = iVtkElem;
176 hexaElemsId[iVtkElem] = iHexaElem;
178 for( vtkIdType j = 0; j< 4; ++j ){
179 vertexElem = q->getVertex( j );
180 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
182 aConnectivity->InsertNextCell( anIdList );
183 aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
189 std::map<int, int> connectivity;
198 for ( int i=0; i<nbVolume; ++i ){
199 anIdList->SetNumberOfIds( 8 );
200 h = _doc->getHexa(i);
201 iHexaElem = reinterpret_cast<intptr_t>(h); //q->getId();
202 vtkElemsId[iHexaElem] = iVtkElem;
203 hexaElemsId[iVtkElem] = iHexaElem;
205 for( vtkIdType j = 0; j< 8; ++j ){
206 vertexElem = h->getVertex( j );// );
207 anIdList->SetId( connectivity[j], vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ]);//vertexElem->getId() ]);
209 aConnectivity->InsertNextCell( anIdList );
210 aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
216 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
220 // Insert cells in grid
221 vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
222 aCellLocationsArray->SetNumberOfComponents( 1 );
223 aCellLocationsArray->SetNumberOfTuples( aNbCells );
224 // std::cout << "aNbCells =>" << aNbCells << std::endl;
226 aConnectivity->InitTraversal();
227 vtkIdType const *pts(nullptr);
228 for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
229 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
231 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
233 aCellLocationsArray->Delete();
234 aCellTypesArray->Delete();
235 aConnectivity->Delete();
237 //std::cout << "theGrid->GetNumberOfCells()" << theGrid->GetNumberOfCells() << std::endl;
242 // =============================================================== Abu : debut
243 // ===================================================== Constructeur
244 Associate_Actor::Associate_Actor( Document* doc, const QString& entry)
245 : SALOME_Actor(), _doc( doc )
247 DEBTRACE("Associate_Actor::Associate_Actor " << entry.toLatin1() );
248 const char* docName = ((doc != NULL) ? doc->getName() : "");
249 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK", docName );//,theName); CS_TODO
251 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
253 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
254 aMapper->SetInputData(aGrid); // saclay
255 // aMapper->SetInput (aGrid);
258 SetVisibility( true );//VisibilityOff();
259 SetPickable( true ); //PickableOff();//
260 SetMapper( aMapper );
263 vtkProperty* aProp = vtkProperty::New();
264 aProp->SetColor(0,255,0);
265 // aProp->SetRepresentationToSurface();
266 aProp->SetRepresentationToWireframe();
267 // aProp->SetRepresentationToPoints();
268 aProp->EdgeVisibilityOn ();
269 aProp->SetPointSize(5);
270 SetProperty( aProp );
272 // SetPointRepresentation(true);
274 // ===================================================== getUnstructuredGrid
276 vtkUnstructuredGrid* Associate_Actor::getUnstructuredGrid()
278 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
280 _doc->reorderFaces(); //CS_TEST
282 std::map<int,vtkIdType> vtkNodeId;
283 std::map<vtkIdType, int> hexaNodeId;
286 vtkPoints* aPoints = vtkPoints::New();
287 int nbVertex = _doc->countVertex();
288 aPoints->SetNumberOfPoints( nbVertex );
292 for ( int i=0; i <nbVertex; ++i ){
293 v = _doc->getVertex(i);
294 aPoints->SetPoint( i, v->getX()+6, v->getY()+6, v->getZ() );
295 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
296 vtkNodeId [ vertexId ] = i;
297 hexaNodeId[ i ] = vertexId ;
298 // vtkNodeId [ vertexId ] = i+1;
299 // hexaNodeId[ i+1 ] = vertexId ;
302 theGrid->SetPoints( aPoints );
304 // theGrid->SetCells( 0, 0, 0, 0, 0 );
306 // Calculate cells size
307 int nb0DElement = _doc->countVertex();
308 int nbEdge = _doc->countEdge();
309 int nbFace = _doc->countQuad();
310 int nbVolume = _doc->countHexa();
312 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
313 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
316 vtkCellArray* aConnectivity = vtkCellArray::New();
317 aConnectivity->Allocate( aCellsSize, 0 );
319 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
320 aCellTypesArray->SetNumberOfComponents( 1 );
321 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
323 vtkIdList *anIdList = vtkIdList::New();
324 vtkIdType iVtkElem = 0;
325 // vtkIdType iVtkElem = 1; //CS_TEST
329 for ( int i=0; i<nb0DElement; ++i ){
330 anIdList->SetNumberOfIds( 1 );
331 v = _doc->getVertex(i);
332 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
333 vtkElemsId[iHexaElem] = iVtkElem;
334 hexaElemsId[iVtkElem] = iHexaElem;
335 anIdList->SetId(0, vtkNodeId[iHexaElem]);
336 aConnectivity->InsertNextCell( anIdList );
337 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
343 Vertex* vertexElem = NULL;
344 for ( int i=0; i<nbEdge; ++i ){
345 anIdList->SetNumberOfIds( 2 );
346 e = _doc->getEdge(i);
347 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
348 vtkElemsId[iHexaElem] = iVtkElem;
349 hexaElemsId[iVtkElem] = iHexaElem;
351 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
352 vertexElem = e->getVertex( j );
353 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
355 aConnectivity->InsertNextCell( anIdList );
356 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
362 for ( int i=0; i<nbFace; ++i ){
363 anIdList->SetNumberOfIds( 4 );
364 q = _doc->getQuad(i);
365 iHexaElem = reinterpret_cast<intptr_t>(q); //q->getId();
366 vtkElemsId[iHexaElem] = iVtkElem;
367 hexaElemsId[iVtkElem] = iHexaElem;
369 for( vtkIdType j = 0; j< 4; ++j ){
370 vertexElem = q->getVertex( j );
371 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
373 aConnectivity->InsertNextCell( anIdList );
374 aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
380 std::map<int, int> connectivity;
389 for ( int i=0; i<nbVolume; ++i ){
390 anIdList->SetNumberOfIds( 8 );
391 h = _doc->getHexa(i);
392 iHexaElem = reinterpret_cast<intptr_t>(h); //q->getId();
393 vtkElemsId[iHexaElem] = iVtkElem;
394 hexaElemsId[iVtkElem] = iHexaElem;
396 for( vtkIdType j = 0; j< 8; ++j ){
397 vertexElem = h->getVertex( j );// );
398 anIdList->SetId( connectivity[j], vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ]);//vertexElem->getId() ]);
400 aConnectivity->InsertNextCell( anIdList );
401 aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
407 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
411 // Insert cells in grid
412 vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
413 aCellLocationsArray->SetNumberOfComponents( 1 );
414 aCellLocationsArray->SetNumberOfTuples( aNbCells );
415 // std::cout << "aNbCells =>" << aNbCells << std::endl;
417 aConnectivity->InitTraversal();
418 vtkIdType const *pts(nullptr);
419 for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
420 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
422 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
424 aCellLocationsArray->Delete();
425 aCellTypesArray->Delete();
426 aConnectivity->Delete();
433 // -----------------------------------------------------------------------
434 // VtkDocumentGraphicView implementation
435 // -----------------------------------------------------------------------
436 VtkDocumentGraphicView::VtkDocumentGraphicView( DocumentModel* documentModel,
437 SVTK_ViewWindow* view, QWidget* parent ):
438 QAbstractItemView(parent),
440 documentActor( NULL ),
441 associateActor (NULL), // Abu
442 _currentChanged( false ),
448 setModel(documentModel);
449 patternDataModel = new PatternDataModel(parent);
450 patternGeomModel = new PatternGeomModel(parent);
451 groupsModel = new GroupsModel(parent);
452 meshModel = new MeshModel(parent);
454 patternDataModel->setSourceModel(documentModel);
455 patternGeomModel->setSourceModel(documentModel);
456 groupsModel->setSourceModel(documentModel);
457 meshModel->setSourceModel(documentModel);
460 patternDataSelectionModel = new PatternDataSelectionModel(patternDataModel);
461 patternGeomSelectionModel = new PatternGeomSelectionModel(patternGeomModel);
462 groupsSelectionModel = new GroupsSelectionModel(groupsModel);
463 meshSelectionModel = new MeshSelectionModel(meshModel );
465 setSelectionModel(patternDataSelectionModel);
468 //Loads the graphic view document
469 void VtkDocumentGraphicView::loadDocument()
471 DocumentModel* docModel = getDocumentModel();
472 if (docModel == NULL) return;
477 //Loads the document from the file in this graphic view
478 void VtkDocumentGraphicView::loadDocument(const QString& file)
480 if ( file.isEmpty() ) return;
481 getDocumentModel()->load(file);
484 //Saves the graphic view's document in the file
485 void VtkDocumentGraphicView::saveDocument(const QString& file)
487 if (file.isEmpty()) return;
488 getDocumentModel()->save(file);
492 VtkDocumentGraphicView::~VtkDocumentGraphicView()
496 delete patternDataModel;
500 //Delete Selection Model/ Disconnect signals on delete (Qt)
501 // delete patternDataSelectionModel;
502 // delete groupsSelectionModel;
503 // delete meshSelectionModel;
506 void VtkDocumentGraphicView::setWindowTitle(const QString& title)
508 viewWindow->setWindowTitle( QString("hexablock : ") + title );
511 void VtkDocumentGraphicView::onPatternDatachanged()
516 void VtkDocumentGraphicView::removeActor()
518 if ( documentActor != NULL && viewWindow != NULL){
519 viewWindow->RemoveActor( documentActor );
520 documentActor->Delete();
524 void VtkDocumentGraphicView::update()
526 DocumentModel* theModel = dynamic_cast<DocumentModel*>( model() );
527 if (theModel == NULL || viewWindow == NULL) return;
529 Document* theDocumentImpl = theModel->documentImpl();
530 QString theDocumentEntry = theModel->documentEntry();
532 if ( documentActor ){
533 viewWindow->RemoveActor( documentActor );
534 documentActor->Delete();
536 documentActor = new Document_Actor( theDocumentImpl, theDocumentEntry );
537 viewWindow->AddActor( documentActor );
539 viewWindow->getRenderer()->Render();
540 viewWindow->Repaint();
543 viewWindow->onFitAll();
548 void VtkDocumentGraphicView::setVertexSelection()
550 setSelectionMode(NodeSelection);
553 void VtkDocumentGraphicView::setEdgeSelection()
555 setSelectionMode(EdgeSelection);
558 void VtkDocumentGraphicView::setQuadSelection()
560 setSelectionMode(FaceSelection);
563 void VtkDocumentGraphicView::setHexaSelection()
565 // SetSelectionMode(VolumeSelection);
566 setSelectionMode(FaceSelection); //temporary for hexa selection debug
567 selectionMode = HEXA_TREE;
568 // aProp->FaceVisibilityOff (); //would debug hexa preselection, selection???
571 void VtkDocumentGraphicView::setAllSelection()
573 setSelectionMode(ActorSelection);
577 void VtkDocumentGraphicView::setSelectionMode(Selection_Mode theMode)
579 if (viewWindow == NULL || selectionMode == theMode)
582 HEXABLOCKGUI::selectionMgr()->clearSelected();
583 viewWindow->SetSelectionMode( theMode );
584 selectionMode = theMode;
587 void VtkDocumentGraphicView::setSelectionMode( const QModelIndex& eltIndex )
589 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
590 if ( !treeVariant.isValid() ) return;
591 int eltType = treeVariant.toInt();
593 if ( selectionMode == eltType ) return;
598 case GEOMPOINT_DIR_TREE:
599 case VERTEX_DIR_TREE : setVertexSelection(); break;
602 case GEOMEDGE_DIR_TREE:
603 case EDGE_DIR_TREE : setEdgeSelection(); break;
606 case GEOMFACE_DIR_TREE:
607 case QUAD_DIR_TREE : setQuadSelection(); break;
610 case GEOMSHAPE_DIR_TREE:
611 case HEXA_DIR_TREE : setHexaSelection(); break;
612 case PROPAGATION_TREE :
613 case PROPAGATION_DIR_TREE : setEdgeSelection(); break;
614 default: setAllSelection();
618 void VtkDocumentGraphicView::getSelected(SALOME_ListIO& selectedObjects)
620 HEXABLOCKGUI::selectionMgr()->selectedObjects( selectedObjects, SVTK_Viewer::Type());
623 void VtkDocumentGraphicView::clearSelection()
625 if (viewWindow != NULL)
627 // viewWindow->unHighlightAll();
628 setSelectionMode(ActorSelection);
632 void VtkDocumentGraphicView::highlight( const QModelIndex& ielt )
635 QModelIndexList indexList;
637 highlight(indexList);
641 void VtkDocumentGraphicView::highlight( const QModelIndexList& elts )
644 if (elts.size() == 0 || viewWindow == NULL || documentActor == NULL)
646 SVTK_Selector* selector = viewWindow->GetSelector();
647 if ( selector == NULL )
649 // Set selection mode in VTK view
650 // viewWindow->SetSelectionMode(VolumeSelection);
652 // --- elements highlight ---
653 SVTK_TIndexedMapOfVtkId aMap;
654 vtkIdType vtkElemsId;
657 foreach( const QModelIndex& iElt, elts ){
660 eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
661 vtkElemsId = documentActor->vtkElemsId[ eltEntry.toInt() ];
662 if ( vtkElemsId > 0 )
663 aMap.Add( vtkElemsId );
666 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
667 viewWindow->highlight( documentActor->getIO(), true, true );
671 void VtkDocumentGraphicView::highlightGroups( const QModelIndex& eltIndex )
673 if ( groupsModel == NULL || viewWindow == NULL || documentActor == NULL) return;
674 SVTK_Selector* selector = viewWindow->GetSelector();
675 if ( selector == NULL ) return;
677 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
678 if ( !treeVariant.isValid())
681 int eltType = treeVariant.toInt();
682 if ( eltType != GROUP_TREE )
685 //Get elements to highlight
686 DocumentModel::Group kind;
687 QModelIndexList iElements = groupsModel->getGroupElements( eltIndex, kind );
688 if (iElements.count() == 0) return;
690 // ---------- elements highlight --------------
692 // Set selection mode in VTK view
694 case HexaCell: case HexaNode: viewWindow->SetSelectionMode(VolumeSelection); break;
695 case QuadCell: case QuadNode: viewWindow->SetSelectionMode(FaceSelection); break;
696 case EdgeCell: case EdgeNode: viewWindow->SetSelectionMode(EdgeSelection); break;
697 case VertexNode: viewWindow->SetSelectionMode(NodeSelection); break;
700 SVTK_TVtkIDsMap aMap;
701 vtkIdType vtkElemsId;
704 foreach( const QModelIndex& iElt, iElements ){
707 eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
708 vtkElemsId = documentActor->vtkElemsId[ eltEntry.toInt() ];
709 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
713 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
714 viewWindow->highlight( documentActor->getIO(), true, true );
715 documentActor->highlight( false );
720 void VtkDocumentGraphicView::highlightPropagation( const QModelIndex& eltIndex )
722 if ( meshModel == NULL || viewWindow == NULL || documentActor == NULL) return;
723 SVTK_Selector* selector = viewWindow->GetSelector();
724 if ( selector == NULL ) return;
726 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
727 if ( !treeVariant.isValid())
730 int eltType = treeVariant.toInt();
731 if ( eltType != PROPAGATION_TREE )
734 // Get elements to highlight
735 QModelIndexList iEdges = meshModel->getPropagation( eltIndex );
736 if (iEdges.count() == 0) return;
738 // ---------- elements highlight --------------
740 // Set selection mode in VTK view
741 viewWindow->SetSelectionMode(EdgeSelection);
743 SVTK_TVtkIDsMap aMap;
744 vtkIdType vtkElemsId;
747 foreach( const QModelIndex& iEdge, iEdges ){
750 edgeEntry = iEdge.data( HEXA_ENTRY_ROLE ).toString();
751 vtkElemsId = documentActor->vtkElemsId[ edgeEntry.toInt() ];
752 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
756 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
757 viewWindow->highlight( documentActor->getIO(), true, true );
758 documentActor->highlight( false );
765 /********************************************************************************
766 * ABSTRACT METHOD ( MUST BE IMPLEMENTED )
767 ********************************************************************************/
769 Returns the item that covers the coordinate given in the view.
771 QModelIndex VtkDocumentGraphicView::indexAt(const QPoint &point) const
773 return QModelIndex();
776 void VtkDocumentGraphicView::scrollTo(const QModelIndex &index, ScrollHint)
781 Returns the position of the item in viewport coordinates.
783 QRect VtkDocumentGraphicView::visualRect(const QModelIndex &index) const
789 int VtkDocumentGraphicView::horizontalOffset() const
791 return horizontalScrollBar()->value();
794 bool VtkDocumentGraphicView::isIndexHidden(const QModelIndex &index) const
799 QModelIndex VtkDocumentGraphicView::moveCursor(QAbstractItemView::CursorAction cursorAction,
800 Qt::KeyboardModifiers /*modifiers*/)
802 QModelIndex current = currentIndex();
807 Find the indices corresponding to the extent of the selection.
809 void VtkDocumentGraphicView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
814 int VtkDocumentGraphicView::verticalOffset() const
816 return verticalScrollBar()->value();
820 Returns a region corresponding to the selection in viewport coordinates.
822 QRegion VtkDocumentGraphicView::visualRegionForSelection(const QItemSelection &selection) const
828 /********************************************************************************
830 ********************************************************************************/
831 void VtkDocumentGraphicView::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint )
835 void VtkDocumentGraphicView::commitData ( QWidget * editor )
839 void VtkDocumentGraphicView::currentChanged( const QModelIndex & current, const QModelIndex & previous )
841 _currentChanged = true;
844 void VtkDocumentGraphicView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )
847 _currentChanged = false;
850 void VtkDocumentGraphicView::editorDestroyed ( QObject * editor )
854 void VtkDocumentGraphicView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end )
858 void VtkDocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
862 void VtkDocumentGraphicView::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
866 void VtkDocumentGraphicView::updateGeometries ()
871 void VtkDocumentGraphicView::setModel ( QAbstractItemModel * model )
873 QAbstractItemView::setModel( model );
875 // PatternDataModel* pdm = dynamic_cast<PatternDataModel*>(model);
877 // connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
879 DocumentModel* dm = dynamic_cast<DocumentModel*>(model);
881 // setWindowTitle( dm->getName() );
882 connect( dm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
883 // connect( dm, SIGNAL( nameChanged(const QString&) ), this, SLOT ( setWindowTitle(const QString&) ) );