1 // Copyright (C) 2009-2013 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.
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
28 #include "utilities.h"
33 #include <LightApp_Application.h>
35 #include <SUIT_ViewManager.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SVTK_ViewManager.h>
38 #include <SVTK_ViewModel.h>
39 #include <SVTK_ViewWindow.h>
41 #include <SALOME_Actor.h>
42 #include <VTKViewer_Algorithm.h>
43 #include <SalomeApp_Study.h>
46 #include <vtkRenderer.h>
47 #include <vtkActorCollection.h>
48 #include <vtkUnstructuredGrid.h>
49 #include <vtkRenderWindowInteractor.h>
50 #include <vtkSmartPointer.h>
51 #include <SVTK_View.h>
52 // test tutorial (sphere)
53 #include <vtkPolyDataMapper.h>
54 #include <vtkSphereSource.h>
56 // test point (cf. SMESHGUI)
57 #include <vtkIdList.h>
58 #include <vtkCellArray.h>
59 #include <vtkUnsignedCharArray.h>
60 #include <vtkUnstructuredGrid.h>
61 #include <vtkDataSetMapper.h>
62 #include <vtkProperty.h>
63 #include <vtkLineSource.h>
67 #include <vtkHexahedron.h>
69 #include "vtkLookupTable.h"
70 #include "vtkPoints.h"
71 #include "vtkCellArray.h"
72 #include "vtkFloatArray.h"
73 #include "vtkPolyData.h"
74 #include "vtkPolyDataMapper.h"
76 #include "vtkPointData.h"
77 #include "vtkProperty.h"
80 // #include "vtkStructuredGridReader.h"
81 #include "vtkUnstructuredGridReader.h"
83 #include <VTKViewer_CellLocationsArray.h>
90 #define M_PI 3.1415927
93 #include "HEXABLOCKGUI_Trace.hxx"
94 #include "HEXABLOCKGUI_DocumentModel.hxx"
95 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
96 #include "HEXABLOCKGUI.hxx"
101 using namespace HEXABLOCK::GUI;
102 using namespace HEXA_NS;
103 // !!! ceci est ni pipe ni un actor mais un mélange des deux
104 Document_Actor::Document_Actor( Document* doc, const QString& entry ):
108 DEBTRACE("Document_Actor::Document_Actor " << entry.toLatin1() );
109 const char* docName = ((doc != NULL) ? doc->getName() : "");
110 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK", docName );//,theName); CS_TODO
112 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
113 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
114 aMapper->SetInput(aGrid);
117 SetVisibility( true );//VisibilityOff();
118 SetPickable( true ); //PickableOff();//
119 SetMapper( aMapper );
122 vtkProperty* aProp = vtkProperty::New();
124 // aProp->SetRepresentationToSurface();
125 aProp->SetRepresentationToWireframe();
126 // aProp->SetRepresentationToPoints();
127 aProp->EdgeVisibilityOn ();
128 aProp->SetPointSize(5);
129 SetProperty( aProp );
131 // SetPointRepresentation(true);
134 Document_Actor::~Document_Actor()
140 vtkUnstructuredGrid* Document_Actor::getUnstructuredGrid()
142 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
144 _doc->reorderFaces(); //CS_TEST
146 map <int,vtkIdType> vtkNodeId;
147 map <vtkIdType, int> hexaNodeId;
150 vtkPoints* aPoints = vtkPoints::New();
151 int nbVertex = _doc->countVertex();
152 aPoints->SetNumberOfPoints( nbVertex );
156 for ( int i=0; i <nbVertex; ++i ){
157 v = _doc->getVertex(i);
158 aPoints->SetPoint( i, v->getX(), v->getY(), v->getZ() );
159 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
160 vtkNodeId [ vertexId ] = i;
161 hexaNodeId[ i ] = vertexId ;
162 // vtkNodeId [ vertexId ] = i+1;
163 // hexaNodeId[ i+1 ] = vertexId ;
166 theGrid->SetPoints( aPoints );
168 // theGrid->SetCells( 0, 0, 0, 0, 0 );
171 // Calculate cells size
172 int nb0DElement = _doc->countVertex();
173 int nbEdge = _doc->countEdge();
174 int nbFace = _doc->countQuad();
175 int nbVolume = _doc->countHexa();
177 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
178 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
181 vtkCellArray* aConnectivity = vtkCellArray::New();
182 aConnectivity->Allocate( aCellsSize, 0 );
184 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
185 aCellTypesArray->SetNumberOfComponents( 1 );
186 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
188 vtkIdList *anIdList = vtkIdList::New();
189 vtkIdType iVtkElem = 0;
190 // vtkIdType iVtkElem = 1; //CS_TEST
194 for ( int i=0; i<nb0DElement; ++i ){
195 anIdList->SetNumberOfIds( 1 );
196 v = _doc->getVertex(i);
197 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
198 vtkElemsId[iHexaElem] = iVtkElem;
199 hexaElemsId[iVtkElem] = iHexaElem;
200 anIdList->SetId(0, vtkNodeId[iHexaElem]);
201 aConnectivity->InsertNextCell( anIdList );
202 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
208 Vertex* vertexElem = NULL;
209 for ( int i=0; i<nbEdge; ++i ){
210 anIdList->SetNumberOfIds( 2 );
211 e = _doc->getEdge(i);
212 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
213 vtkElemsId[iHexaElem] = iVtkElem;
214 hexaElemsId[iVtkElem] = iHexaElem;
216 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
217 vertexElem = e->getVertex( j );
218 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
220 aConnectivity->InsertNextCell( anIdList );
221 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
227 for ( int i=0; i<nbFace; ++i ){
228 anIdList->SetNumberOfIds( 4 );
229 q = _doc->getQuad(i);
230 iHexaElem = reinterpret_cast<intptr_t>(q); //q->getId();
231 vtkElemsId[iHexaElem] = iVtkElem;
232 hexaElemsId[iVtkElem] = iHexaElem;
234 for( vtkIdType j = 0; j< 4; ++j ){
235 vertexElem = q->getVertex( j );
236 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
238 aConnectivity->InsertNextCell( anIdList );
239 aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
245 std::map<int, int> connectivity;
254 for ( int i=0; i<nbVolume; ++i ){
255 anIdList->SetNumberOfIds( 8 );
256 h = _doc->getHexa(i);
257 iHexaElem = reinterpret_cast<intptr_t>(h); //q->getId();
258 vtkElemsId[iHexaElem] = iVtkElem;
259 hexaElemsId[iVtkElem] = iHexaElem;
261 for( vtkIdType j = 0; j< 8; ++j ){
262 vertexElem = h->getVertex( j );// );
263 anIdList->SetId( connectivity[j], vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ]);//vertexElem->getId() ]);
265 aConnectivity->InsertNextCell( anIdList );
266 aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
272 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
276 // Insert cells in grid
277 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
278 aCellLocationsArray->SetNumberOfComponents( 1 );
279 aCellLocationsArray->SetNumberOfTuples( aNbCells );
280 // std::cout << "aNbCells =>" << aNbCells << std::endl;
282 aConnectivity->InitTraversal();
283 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
284 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
286 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
288 aCellLocationsArray->Delete();
289 aCellTypesArray->Delete();
290 aConnectivity->Delete();
292 //std::cout << "theGrid->GetNumberOfCells()" << theGrid->GetNumberOfCells() << std::endl;
297 // =============================================================== Abu : debut
298 // ===================================================== Constructeur
299 Associate_Actor::Associate_Actor( Document* doc, const QString& entry)
300 : SALOME_Actor(), _doc( doc )
302 DEBTRACE("Associate_Actor::Associate_Actor " << entry.toLatin1() );
303 const char* docName = ((doc != NULL) ? doc->getName() : "");
304 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK", docName );//,theName); CS_TODO
306 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
308 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
309 aMapper->SetInput(aGrid);
312 SetVisibility( true );//VisibilityOff();
313 SetPickable( true ); //PickableOff();//
314 SetMapper( aMapper );
317 vtkProperty* aProp = vtkProperty::New();
318 aProp->SetColor(0,255,0);
319 // aProp->SetRepresentationToSurface();
320 aProp->SetRepresentationToWireframe();
321 // aProp->SetRepresentationToPoints();
322 aProp->EdgeVisibilityOn ();
323 aProp->SetPointSize(5);
324 SetProperty( aProp );
326 // SetPointRepresentation(true);
328 // ===================================================== getUnstructuredGrid
330 vtkUnstructuredGrid* Associate_Actor::getUnstructuredGrid()
332 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
334 _doc->reorderFaces(); //CS_TEST
336 std::map<int,vtkIdType> vtkNodeId;
337 std::map<vtkIdType, int> hexaNodeId;
340 vtkPoints* aPoints = vtkPoints::New();
341 int nbVertex = _doc->countVertex();
342 aPoints->SetNumberOfPoints( nbVertex );
346 for ( int i=0; i <nbVertex; ++i ){
347 v = _doc->getVertex(i);
348 aPoints->SetPoint( i, v->getX()+6, v->getY()+6, v->getZ() );
349 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
350 vtkNodeId [ vertexId ] = i;
351 hexaNodeId[ i ] = vertexId ;
352 // vtkNodeId [ vertexId ] = i+1;
353 // hexaNodeId[ i+1 ] = vertexId ;
356 theGrid->SetPoints( aPoints );
358 // theGrid->SetCells( 0, 0, 0, 0, 0 );
360 // Calculate cells size
361 int nb0DElement = _doc->countVertex();
362 int nbEdge = _doc->countEdge();
363 int nbFace = _doc->countQuad();
364 int nbVolume = _doc->countHexa();
366 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
367 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
370 vtkCellArray* aConnectivity = vtkCellArray::New();
371 aConnectivity->Allocate( aCellsSize, 0 );
373 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
374 aCellTypesArray->SetNumberOfComponents( 1 );
375 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
377 vtkIdList *anIdList = vtkIdList::New();
378 vtkIdType iVtkElem = 0;
379 // vtkIdType iVtkElem = 1; //CS_TEST
383 for ( int i=0; i<nb0DElement; ++i ){
384 anIdList->SetNumberOfIds( 1 );
385 v = _doc->getVertex(i);
386 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
387 vtkElemsId[iHexaElem] = iVtkElem;
388 hexaElemsId[iVtkElem] = iHexaElem;
389 anIdList->SetId(0, vtkNodeId[iHexaElem]);
390 aConnectivity->InsertNextCell( anIdList );
391 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
397 Vertex* vertexElem = NULL;
398 for ( int i=0; i<nbEdge; ++i ){
399 anIdList->SetNumberOfIds( 2 );
400 e = _doc->getEdge(i);
401 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
402 vtkElemsId[iHexaElem] = iVtkElem;
403 hexaElemsId[iVtkElem] = iHexaElem;
405 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
406 vertexElem = e->getVertex( j );
407 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
409 aConnectivity->InsertNextCell( anIdList );
410 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
416 for ( int i=0; i<nbFace; ++i ){
417 anIdList->SetNumberOfIds( 4 );
418 q = _doc->getQuad(i);
419 iHexaElem = reinterpret_cast<intptr_t>(q); //q->getId();
420 vtkElemsId[iHexaElem] = iVtkElem;
421 hexaElemsId[iVtkElem] = iHexaElem;
423 for( vtkIdType j = 0; j< 4; ++j ){
424 vertexElem = q->getVertex( j );
425 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
427 aConnectivity->InsertNextCell( anIdList );
428 aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
434 std::map<int, int> connectivity;
443 for ( int i=0; i<nbVolume; ++i ){
444 anIdList->SetNumberOfIds( 8 );
445 h = _doc->getHexa(i);
446 iHexaElem = reinterpret_cast<intptr_t>(h); //q->getId();
447 vtkElemsId[iHexaElem] = iVtkElem;
448 hexaElemsId[iVtkElem] = iHexaElem;
450 for( vtkIdType j = 0; j< 8; ++j ){
451 vertexElem = h->getVertex( j );// );
452 anIdList->SetId( connectivity[j], vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ]);//vertexElem->getId() ]);
454 aConnectivity->InsertNextCell( anIdList );
455 aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
461 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
465 // Insert cells in grid
466 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
467 aCellLocationsArray->SetNumberOfComponents( 1 );
468 aCellLocationsArray->SetNumberOfTuples( aNbCells );
469 // std::cout << "aNbCells =>" << aNbCells << std::endl;
471 aConnectivity->InitTraversal();
472 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
473 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
475 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
477 aCellLocationsArray->Delete();
478 aCellTypesArray->Delete();
479 aConnectivity->Delete();
486 // -----------------------------------------------------------------------
487 // VtkDocumentGraphicView implementation
488 // -----------------------------------------------------------------------
489 VtkDocumentGraphicView::VtkDocumentGraphicView( DocumentModel* documentModel,
490 SVTK_ViewWindow* view, QWidget* parent ):
491 QAbstractItemView(parent),
493 documentActor( NULL ),
494 associateActor (NULL), // Abu
495 _currentChanged( false ),
501 setModel(documentModel);
502 patternDataModel = new PatternDataModel(parent);
503 patternBuilderModel = new PatternBuilderModel(parent);
504 patternGeomModel = new PatternGeomModel(parent);
505 groupsModel = new GroupsModel(parent);
506 meshModel = new MeshModel(parent);
508 patternDataModel->setSourceModel(documentModel);
509 patternBuilderModel->setSourceModel(documentModel);
510 patternGeomModel->setSourceModel(documentModel);
511 groupsModel->setSourceModel(documentModel);
512 meshModel->setSourceModel(documentModel);
515 patternDataSelectionModel = new PatternDataSelectionModel(patternDataModel);
516 patternBuilderSelectionModel = new PatternBuilderSelectionModel(patternBuilderModel, patternDataSelectionModel);
517 patternGeomSelectionModel = new PatternGeomSelectionModel(patternGeomModel);
518 groupsSelectionModel = new GroupsSelectionModel(groupsModel);
519 meshSelectionModel = new MeshSelectionModel(meshModel );
521 setSelectionModel(patternDataSelectionModel);
524 //Loads the graphic view document
525 void VtkDocumentGraphicView::loadDocument()
527 DocumentModel* docModel = getDocumentModel();
528 if (docModel == NULL) return;
533 //Loads the document from the file in this graphic view
534 void VtkDocumentGraphicView::loadDocument(const QString& file)
536 if ( file.isEmpty() ) return;
537 getDocumentModel()->load(file);
540 //Saves the graphic view's document in the file
541 void VtkDocumentGraphicView::saveDocument(const QString& file)
543 if (file.isEmpty()) return;
544 getDocumentModel()->save(file);
548 VtkDocumentGraphicView::~VtkDocumentGraphicView()
552 delete patternDataModel;
553 delete patternBuilderModel;
557 //Delete Selection Model/ Disconnect signals on delete (Qt)
558 // delete patternDataSelectionModel;
559 // delete patternBuilderSelectionModel;
560 // delete groupsSelectionModel;
561 // delete meshSelectionModel;
564 void VtkDocumentGraphicView::setWindowTitle(const QString& title)
566 viewWindow->setWindowTitle( QString("hexablock : ") + title );
569 void VtkDocumentGraphicView::onPatternDatachanged()
574 void VtkDocumentGraphicView::removeActor()
576 if ( documentActor != NULL && viewWindow != NULL){
577 viewWindow->RemoveActor( documentActor );
578 documentActor->Delete();
582 void VtkDocumentGraphicView::update()
584 DocumentModel* theModel = dynamic_cast<DocumentModel*>( model() );
585 if (theModel == NULL || viewWindow == NULL) return;
587 Document* theDocumentImpl = theModel->documentImpl();
588 QString theDocumentEntry = theModel->documentEntry();
590 if ( documentActor ){
591 viewWindow->RemoveActor( documentActor );
592 documentActor->Delete();
594 documentActor = new Document_Actor( theDocumentImpl, theDocumentEntry );
595 viewWindow->AddActor( documentActor );
597 viewWindow->getRenderer()->Render();
598 viewWindow->Repaint();
601 viewWindow->onFitAll();
606 void VtkDocumentGraphicView::setVertexSelection()
608 setSelectionMode(NodeSelection);
611 // // EdgeOfCellSelection,
614 // // VolumeSelection,
615 // // ActorSelection };
618 void VtkDocumentGraphicView::setEdgeSelection()
620 setSelectionMode(EdgeSelection);
623 void VtkDocumentGraphicView::setQuadSelection()
625 setSelectionMode(FaceSelection);
628 void VtkDocumentGraphicView::setHexaSelection()
630 // SetSelectionMode(VolumeSelection);
631 setSelectionMode(FaceSelection); //temporary for hexa selection debug
632 selectionMode = HEXA_TREE;
633 // aProp->FaceVisibilityOff (); //would debug hexa preselection, selection???
636 void VtkDocumentGraphicView::setAllSelection()
638 setSelectionMode(ActorSelection);
642 void VtkDocumentGraphicView::setSelectionMode(Selection_Mode theMode)
644 if (viewWindow == NULL || selectionMode == theMode)
647 HEXABLOCKGUI::selectionMgr()->clearSelected();
648 viewWindow->SetSelectionMode( theMode );
649 selectionMode = theMode;
652 void VtkDocumentGraphicView::setSelectionMode( const QModelIndex& eltIndex )
654 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
655 if ( !treeVariant.isValid() ) return;
656 int eltType = treeVariant.toInt();
658 if ( selectionMode == eltType ) return;
663 case GEOMPOINT_DIR_TREE:
664 case VERTEX_DIR_TREE : setVertexSelection(); break;
667 case GEOMEDGE_DIR_TREE:
668 case EDGE_DIR_TREE : setEdgeSelection(); break;
671 case GEOMFACE_DIR_TREE:
672 case QUAD_DIR_TREE : setQuadSelection(); break;
675 case GEOMSHAPE_DIR_TREE:
676 case HEXA_DIR_TREE : setHexaSelection(); break;
677 case PROPAGATION_TREE :
678 case PROPAGATION_DIR_TREE : setEdgeSelection(); break;
679 default: setAllSelection();
681 // EdgeOfCellSelection,
687 void VtkDocumentGraphicView::getSelected(SALOME_ListIO& selectedObjects)
689 HEXABLOCKGUI::selectionMgr()->selectedObjects( selectedObjects, SVTK_Viewer::Type());
692 void VtkDocumentGraphicView::clearSelection()
694 if (viewWindow != NULL)
696 // viewWindow->unHighlightAll();
697 setSelectionMode(ActorSelection);
701 void VtkDocumentGraphicView::highlight( const QModelIndex& ielt )
704 QModelIndexList indexList;
706 highlight(indexList);
710 void VtkDocumentGraphicView::highlight( const QModelIndexList& elts )
713 if (elts.size() == 0 || viewWindow == NULL || documentActor == NULL)
715 SVTK_Selector* selector = viewWindow->GetSelector();
716 if ( selector == NULL )
718 // Set selection mode in VTK view
719 // viewWindow->SetSelectionMode(VolumeSelection);
721 // --- elements highlight ---
722 TColStd_IndexedMapOfInteger aMap;
726 foreach( const QModelIndex& iElt, elts ){
729 eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
730 vtkElemsId = documentActor->vtkElemsId[ eltEntry.toInt() ];
731 if ( vtkElemsId > 0 )
732 aMap.Add( vtkElemsId );
735 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
736 viewWindow->highlight( documentActor->getIO(), true, true );
740 void VtkDocumentGraphicView::highlightGroups( const QModelIndex& eltIndex )
742 if ( groupsModel == NULL || viewWindow == NULL || documentActor == NULL) return;
743 SVTK_Selector* selector = viewWindow->GetSelector();
744 if ( selector == NULL ) return;
746 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
747 if ( !treeVariant.isValid())
750 int eltType = treeVariant.toInt();
751 if ( eltType != GROUP_TREE )
754 //Get elements to highlight
755 DocumentModel::Group kind;
756 QModelIndexList iElements = groupsModel->getGroupElements( eltIndex, kind );
757 if (iElements.count() == 0) return;
759 // ---------- elements highlight --------------
761 // Set selection mode in VTK view
763 case HexaCell: case HexaNode: viewWindow->SetSelectionMode(VolumeSelection); break;
764 case QuadCell: case QuadNode: viewWindow->SetSelectionMode(FaceSelection); break;
765 case EdgeCell: case EdgeNode: viewWindow->SetSelectionMode(EdgeSelection); break;
766 case VertexNode: viewWindow->SetSelectionMode(NodeSelection); break;
769 TColStd_MapOfInteger aMap;
773 foreach( const QModelIndex& iElt, iElements ){
776 eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
777 vtkElemsId = documentActor->vtkElemsId[ eltEntry.toInt() ];
778 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
782 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
783 viewWindow->highlight( documentActor->getIO(), true, true );
784 documentActor->highlight( false );
789 void VtkDocumentGraphicView::highlightPropagation( const QModelIndex& eltIndex )
791 if ( meshModel == NULL || viewWindow == NULL || documentActor == NULL) return;
792 SVTK_Selector* selector = viewWindow->GetSelector();
793 if ( selector == NULL ) return;
795 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
796 if ( !treeVariant.isValid())
799 int eltType = treeVariant.toInt();
800 if ( eltType != PROPAGATION_TREE )
803 // Get elements to highlight
804 QModelIndexList iEdges = meshModel->getPropagation( eltIndex );
805 if (iEdges.count() == 0) return;
807 // ---------- elements highlight --------------
809 // Set selection mode in VTK view
810 viewWindow->SetSelectionMode(EdgeSelection);
812 TColStd_MapOfInteger aMap;
816 foreach( const QModelIndex& iEdge, iEdges ){
819 edgeEntry = iEdge.data( HEXA_ENTRY_ROLE ).toString();
820 vtkElemsId = documentActor->vtkElemsId[ edgeEntry.toInt() ];
821 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
825 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
826 viewWindow->highlight( documentActor->getIO(), true, true );
827 documentActor->highlight( false );
834 /********************************************************************************
835 * ABSTRACT METHOD ( MUST BE IMPLEMENTED )
836 ********************************************************************************/
839 Returns the item that covers the coordinate given in the view.
842 QModelIndex VtkDocumentGraphicView::indexAt(const QPoint &point) const
844 return QModelIndex();
847 void VtkDocumentGraphicView::scrollTo(const QModelIndex &index, ScrollHint)
853 Returns the position of the item in viewport coordinates.
855 QRect VtkDocumentGraphicView::visualRect(const QModelIndex &index) const
861 int VtkDocumentGraphicView::horizontalOffset() const
863 return horizontalScrollBar()->value();
866 bool VtkDocumentGraphicView::isIndexHidden(const QModelIndex &index) const
871 QModelIndex VtkDocumentGraphicView::moveCursor(QAbstractItemView::CursorAction cursorAction,
872 Qt::KeyboardModifiers /*modifiers*/)
874 QModelIndex current = currentIndex();
879 Find the indices corresponding to the extent of the selection.
881 void VtkDocumentGraphicView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
886 int VtkDocumentGraphicView::verticalOffset() const
888 return verticalScrollBar()->value();
892 Returns a region corresponding to the selection in viewport coordinates.
894 QRegion VtkDocumentGraphicView::visualRegionForSelection(const QItemSelection &selection) const
900 /********************************************************************************
902 ********************************************************************************/
903 void VtkDocumentGraphicView::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint )
907 void VtkDocumentGraphicView::commitData ( QWidget * editor )
911 void VtkDocumentGraphicView::currentChanged( const QModelIndex & current, const QModelIndex & previous )
913 _currentChanged = true;
916 void VtkDocumentGraphicView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )
919 _currentChanged = false;
922 void VtkDocumentGraphicView::editorDestroyed ( QObject * editor )
926 void VtkDocumentGraphicView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end )
930 void VtkDocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
934 void VtkDocumentGraphicView::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
938 void VtkDocumentGraphicView::updateGeometries ()
943 void VtkDocumentGraphicView::setModel ( QAbstractItemModel * model )
945 QAbstractItemView::setModel( model );
947 // PatternDataModel* pdm = dynamic_cast<PatternDataModel*>(model);
949 // connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
951 DocumentModel* dm = dynamic_cast<DocumentModel*>(model);
953 // setWindowTitle( dm->getName() );
954 connect( dm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
955 // connect( dm, SIGNAL( nameChanged(const QString&) ), this, SLOT ( setWindowTitle(const QString&) ) );
959 // void DocumentGraphicView::loadVTK( const QString& path ) //CS_TEST
961 // std::cout << "DocumentGraphicView::loadVTK=>"<<std::endl;
963 // if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
965 // // QByteArray vtkData = file.readAll ();
966 // QString vtkData = file.readAll ();
967 // vtkData.replace(",",".");
970 // SVTK_ViewWindow* myVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
972 // // vtkStructuredGridReader
973 // vtkUnstructuredGridReader* r = vtkUnstructuredGridReader::New();
974 // // r->SetFileName( path.toLocal8Bit().constData() );
975 // r->SetInputString( vtkData.toLocal8Bit().constData() );
976 // r->SetReadFromInputString( true );
979 // vtkUnstructuredGrid* myGrid = r->GetOutput();//vtkUnstructuredGrid::New();
980 // std::cout << "GetNumberOfCells =>"<< myGrid->GetNumberOfCells();
981 // // Create and display actor
983 // vtkDataSetMapper* myMapper = vtkDataSetMapper::New();
984 // myMapper->SetInput(myGrid);
986 // // if ( myPreviewActor ){
987 // // myVTKViewWindow->RemoveActor(myPreviewActor);
988 // // myPreviewActor->Delete();
991 // SALOME_Actor* myPreviewActor = SALOME_Actor::New();
992 // myPreviewActor = SALOME_Actor::New();
993 // Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(QString::number( reinterpret_cast<intptr_t>(_hexaDocument) ),"HEXABLOCK");//,theName);
994 // myPreviewActor->setIO(anIO);
996 // // myPreviewActor->PickableOff();
997 // myPreviewActor->SetVisibility( true );//VisibilityOff();
998 // myPreviewActor->SetPickable( true );
999 // myPreviewActor->SetMapper(myMapper);
1001 // vtkProperty* aProp = vtkProperty::New();
1002 // // aProp->SetRepresentationToWireframe();
1003 // aProp->SetRepresentationToSurface();
1004 // aProp->EdgeVisibilityOn ();
1006 // // aProp->SetColor(10, 10, 250);
1007 // aProp->SetPointSize(5);
1008 // myPreviewActor->SetProperty(aProp);
1011 // /*vtkProperty* myBackProp = vtkProperty::New();
1012 // GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
1013 // myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
1014 // myPreviewActor->SetBackfaceProperty( myBackProp );
1015 // myBackProp->Delete()*/;
1016 // myVTKViewWindow->AddActor(myPreviewActor);
1017 // myVTKViewWindow->getRenderer()->Render();
1018 // myVTKViewWindow->Repaint();
1019 // myVTKViewWindow->onFitAll();
1021 // myVTKViewWindow->SetSelectionMode( ActorSelection );
1022 // // myVTKViewWindow->SetSelectionMode( NodeSelection );
1023 // // myVTKViewWindow->SetSelectionMode( EdgeSelection );
1024 // // myVTKViewWindow->SetSelectionMode( FaceSelection );