1 // Copyright (C) 2009-2012 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;
104 Document_Actor::Document_Actor( Document* doc, const QString& entry ):
108 DEBTRACE("Document_Actor::Document_Actor " << entry.toLatin1() );
109 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK" );//,theName); CS_TODO
111 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
112 // std::cout << "Document_Actor aGrid->GetNumberOfCells() =>"<< aGrid->GetNumberOfCells();
113 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
114 aMapper->SetInputData(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);
135 Document_Actor::~Document_Actor()
141 vtkUnstructuredGrid* Document_Actor::getUnstructuredGrid()
143 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
145 _doc->reorderFaces(); //CS_TEST
147 map <int,vtkIdType> vtkNodeId;
148 map <vtkIdType, int> hexaNodeId;
151 vtkPoints* aPoints = vtkPoints::New();
152 int nbVertex = _doc->countVertex();
153 aPoints->SetNumberOfPoints( nbVertex );
157 for ( int i=0; i <nbVertex; ++i ){
158 v = _doc->getVertex(i);
159 aPoints->SetPoint( i, v->getX(), v->getY(), v->getZ() );
160 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
161 vtkNodeId [ vertexId ] = i;
162 hexaNodeId[ i ] = vertexId ;
163 // vtkNodeId [ vertexId ] = i+1;
164 // hexaNodeId[ i+1 ] = vertexId ;
167 theGrid->SetPoints( aPoints );
169 // theGrid->SetCells( 0, 0, 0, 0, 0 );
172 // Calculate cells size
173 int nb0DElement = _doc->countVertex();
174 int nbEdge = _doc->countEdge();
175 int nbFace = _doc->countQuad();
176 int nbVolume = _doc->countHexa();
178 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
179 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
182 vtkCellArray* aConnectivity = vtkCellArray::New();
183 aConnectivity->Allocate( aCellsSize, 0 );
185 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
186 aCellTypesArray->SetNumberOfComponents( 1 );
187 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
189 vtkIdList *anIdList = vtkIdList::New();
190 vtkIdType iVtkElem = 0;
191 // vtkIdType iVtkElem = 1; //CS_TEST
195 for ( int i=0; i<nb0DElement; ++i ){
196 anIdList->SetNumberOfIds( 1 );
197 v = _doc->getVertex(i);
198 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
199 vtkElemsId[iHexaElem] = iVtkElem;
200 hexaElemsId[iVtkElem] = iHexaElem;
201 anIdList->SetId(0, vtkNodeId[iHexaElem]);
202 aConnectivity->InsertNextCell( anIdList );
203 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
209 Vertex* vertexElem = NULL;
210 for ( int i=0; i<nbEdge; ++i ){
211 anIdList->SetNumberOfIds( 2 );
212 e = _doc->getEdge(i);
213 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
214 vtkElemsId[iHexaElem] = iVtkElem;
215 hexaElemsId[iVtkElem] = iHexaElem;
217 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
218 vertexElem = e->getVertex( j );
219 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
221 aConnectivity->InsertNextCell( anIdList );
222 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
228 for ( int i=0; i<nbFace; ++i ){
229 anIdList->SetNumberOfIds( 4 );
230 q = _doc->getQuad(i);
231 iHexaElem = reinterpret_cast<intptr_t>(q); //q->getId();
232 vtkElemsId[iHexaElem] = iVtkElem;
233 hexaElemsId[iVtkElem] = iHexaElem;
235 for( vtkIdType j = 0; j< 4; ++j ){
236 vertexElem = q->getVertex( j );
237 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
239 aConnectivity->InsertNextCell( anIdList );
240 aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
246 std::map<int, int> connectivity;
255 for ( int i=0; i<nbVolume; ++i ){
256 anIdList->SetNumberOfIds( 8 );
257 h = _doc->getHexa(i);
258 iHexaElem = reinterpret_cast<intptr_t>(h); //q->getId();
259 vtkElemsId[iHexaElem] = iVtkElem;
260 hexaElemsId[iVtkElem] = iHexaElem;
262 for( vtkIdType j = 0; j< 8; ++j ){
263 vertexElem = h->getVertex( j );// );
264 anIdList->SetId( connectivity[j], vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ]);//vertexElem->getId() ]);
266 aConnectivity->InsertNextCell( anIdList );
267 aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
273 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
277 // Insert cells in grid
278 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
279 aCellLocationsArray->SetNumberOfComponents( 1 );
280 aCellLocationsArray->SetNumberOfTuples( aNbCells );
281 // std::cout << "aNbCells =>" << aNbCells << std::endl;
283 aConnectivity->InitTraversal();
284 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
285 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
287 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
289 aCellLocationsArray->Delete();
290 aCellTypesArray->Delete();
291 aConnectivity->Delete();
293 //std::cout << "theGrid->GetNumberOfCells()" << theGrid->GetNumberOfCells() << std::endl;
298 // =============================================================== Abu : debut
299 // ===================================================== Constructeur
300 Associate_Actor::Associate_Actor( Document* doc, const QString& entry)
301 : SALOME_Actor(), _doc( doc )
303 DEBTRACE("Associate_Actor::Associate_Actor " << entry.toLatin1() );
304 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK" );//,theName); CS_TODO
306 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
308 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
309 aMapper->SetInputData(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 );
361 // Calculate cells size
362 int nb0DElement = _doc->countVertex();
363 int nbEdge = _doc->countEdge();
364 int nbFace = _doc->countQuad();
365 int nbVolume = _doc->countHexa();
367 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
368 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
371 vtkCellArray* aConnectivity = vtkCellArray::New();
372 aConnectivity->Allocate( aCellsSize, 0 );
374 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
375 aCellTypesArray->SetNumberOfComponents( 1 );
376 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
378 vtkIdList *anIdList = vtkIdList::New();
379 vtkIdType iVtkElem = 0;
380 // vtkIdType iVtkElem = 1; //CS_TEST
384 for ( int i=0; i<nb0DElement; ++i ){
385 anIdList->SetNumberOfIds( 1 );
386 v = _doc->getVertex(i);
387 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
388 vtkElemsId[iHexaElem] = iVtkElem;
389 hexaElemsId[iVtkElem] = iHexaElem;
390 anIdList->SetId(0, vtkNodeId[iHexaElem]);
391 aConnectivity->InsertNextCell( anIdList );
392 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
398 Vertex* vertexElem = NULL;
399 for ( int i=0; i<nbEdge; ++i ){
400 anIdList->SetNumberOfIds( 2 );
401 e = _doc->getEdge(i);
402 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
403 vtkElemsId[iHexaElem] = iVtkElem;
404 hexaElemsId[iVtkElem] = iHexaElem;
406 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
407 vertexElem = e->getVertex( j );
408 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
410 aConnectivity->InsertNextCell( anIdList );
411 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
417 for ( int i=0; i<nbFace; ++i ){
418 anIdList->SetNumberOfIds( 4 );
419 q = _doc->getQuad(i);
420 iHexaElem = reinterpret_cast<intptr_t>(q); //q->getId();
421 vtkElemsId[iHexaElem] = iVtkElem;
422 hexaElemsId[iVtkElem] = iHexaElem;
424 for( vtkIdType j = 0; j< 4; ++j ){
425 vertexElem = q->getVertex( j );
426 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
428 aConnectivity->InsertNextCell( anIdList );
429 aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
435 std::map<int, int> connectivity;
444 for ( int i=0; i<nbVolume; ++i ){
445 anIdList->SetNumberOfIds( 8 );
446 h = _doc->getHexa(i);
447 iHexaElem = reinterpret_cast<intptr_t>(h); //q->getId();
448 vtkElemsId[iHexaElem] = iVtkElem;
449 hexaElemsId[iVtkElem] = iHexaElem;
451 for( vtkIdType j = 0; j< 8; ++j ){
452 vertexElem = h->getVertex( j );// );
453 anIdList->SetId( connectivity[j], vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ]);//vertexElem->getId() ]);
455 aConnectivity->InsertNextCell( anIdList );
456 aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
462 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
466 // Insert cells in grid
467 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
468 aCellLocationsArray->SetNumberOfComponents( 1 );
469 aCellLocationsArray->SetNumberOfTuples( aNbCells );
470 // std::cout << "aNbCells =>" << aNbCells << std::endl;
472 aConnectivity->InitTraversal();
473 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
474 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
476 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
478 aCellLocationsArray->Delete();
479 aCellTypesArray->Delete();
480 aConnectivity->Delete();
487 // -----------------------------------------------------------------------
488 // VtkDocumentGraphicView implementation
489 // -----------------------------------------------------------------------
490 VtkDocumentGraphicView::VtkDocumentGraphicView( DocumentModel* documentModel,
491 SVTK_ViewWindow* view, QWidget* parent ):
492 QAbstractItemView(parent),
494 documentActor( NULL ),
495 associateActor (NULL), // Abu
496 _currentChanged( false ),
502 setModel(documentModel);
503 patternDataModel = new PatternDataModel(parent);
504 patternBuilderModel = new PatternBuilderModel(parent);
505 patternGeomModel = new PatternGeomModel(parent);
506 groupsModel = new GroupsModel(parent);
507 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 );
520 setSelectionModel(patternDataSelectionModel);
523 //Loads the graphic view document
524 void VtkDocumentGraphicView::loadDocument()
526 DocumentModel* docModel = getDocumentModel();
527 if (docModel == NULL) return;
532 //Loads the document from the file in this graphic view
533 void VtkDocumentGraphicView::loadDocument(const QString& file)
535 if ( file.isEmpty() ) return;
536 getDocumentModel()->load(file);
539 //Saves the graphic view's document in the file
540 void VtkDocumentGraphicView::saveDocument(const QString& file)
542 if (file.isEmpty()) return;
543 getDocumentModel()->save(file);
547 VtkDocumentGraphicView::~VtkDocumentGraphicView()
551 delete patternDataModel;
552 delete patternBuilderModel;
556 //Delete Selection Model/ Disconnect signals on delete (Qt)
557 // delete patternDataSelectionModel;
558 // delete patternBuilderSelectionModel;
559 // delete groupsSelectionModel;
560 // delete meshSelectionModel;
563 void VtkDocumentGraphicView::setWindowTitle(const QString& title)
565 viewWindow->setWindowTitle( QString("hexablock : ") + title );
568 void VtkDocumentGraphicView::onPatternDatachanged()
573 void VtkDocumentGraphicView::removeActor()
575 if ( documentActor != NULL && viewWindow != NULL){
576 viewWindow->RemoveActor( documentActor );
577 documentActor->Delete();
581 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 };
616 selectionMode = VERTEX_TREE;
619 void VtkDocumentGraphicView::setEdgeSelection()
621 setSelectionMode(EdgeSelection);
622 selectionMode = EDGE_TREE;
625 void VtkDocumentGraphicView::setQuadSelection()
627 setSelectionMode(FaceSelection);
628 selectionMode = QUAD_TREE;
631 void VtkDocumentGraphicView::setHexaSelection()
633 // SetSelectionMode(VolumeSelection);
634 setSelectionMode(FaceSelection); //temporary for hexa selection debug
635 selectionMode = HEXA_TREE;
636 // aProp->FaceVisibilityOff (); //would debug hexa preselection, selection???
639 void VtkDocumentGraphicView::setAllSelection()
641 setSelectionMode(ActorSelection);
645 void VtkDocumentGraphicView::setSelectionMode(Selection_Mode theMode)
648 if ( viewWindow != NULL )
650 viewWindow->SetSelectionMode( theMode );
651 selectionMode = theMode;
656 void VtkDocumentGraphicView::setSelectionMode( const QModelIndex& eltIndex )
658 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
659 if ( !treeVariant.isValid() ) return;
660 int eltType = treeVariant.toInt();
662 if ( selectionMode == eltType ) return;
667 case GEOMPOINT_DIR_TREE:
668 case VERTEX_DIR_TREE : setVertexSelection(); break;
671 case GEOMEDGE_DIR_TREE:
672 case EDGE_DIR_TREE : setEdgeSelection(); break;
675 case GEOMFACE_DIR_TREE:
676 case QUAD_DIR_TREE : setQuadSelection(); break;
679 case GEOMSHAPE_DIR_TREE:
680 case HEXA_DIR_TREE : setHexaSelection(); break;
681 case PROPAGATION_TREE :
682 case PROPAGATION_DIR_TREE : setEdgeSelection(); break;
683 default: setAllSelection();
685 // EdgeOfCellSelection,
691 void VtkDocumentGraphicView::clearSelection()
693 if (viewWindow != NULL)
695 // viewWindow->unHighlightAll();
696 setSelectionMode(ActorSelection);
700 void VtkDocumentGraphicView::highlight( const QModelIndex& ielt )
703 QModelIndexList indexList;
705 highlight(indexList);
709 void VtkDocumentGraphicView::highlight( const QModelIndexList& elts )
712 if (elts.size() == 0 || viewWindow == NULL || documentActor == NULL) return;
713 SVTK_Selector* selector = viewWindow->GetSelector();
714 if ( selector == NULL ) return;
715 // // Set selection mode in VTK view
716 // viewWindow->SetSelectionMode(VolumeSelection);
718 // --- elements highlight ---
719 TColStd_MapOfInteger aMap;
723 foreach( const QModelIndex& iElt, elts ){
726 eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
727 vtkElemsId = documentActor->vtkElemsId[ eltEntry.toInt() ];
728 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
731 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false ); //true
732 viewWindow->highlight( documentActor->getIO(), true, true );
733 documentActor->highlight( false ); //unhighlight de la bounding box rouge
738 void VtkDocumentGraphicView::highlightGroups( const QModelIndex& eltIndex )
740 if ( groupsModel == NULL || viewWindow == NULL || documentActor == NULL) return;
741 SVTK_Selector* selector = viewWindow->GetSelector();
742 if ( selector == NULL ) return;
744 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
745 if ( !treeVariant.isValid())
746 //INFOS("data from model not valid");
749 int eltType = treeVariant.toInt();
750 if ( eltType != GROUP_TREE )
751 //INFOS("bad element type : not a group item" << eltType );
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())
797 //INFOS("data from model not valid");
800 int eltType = treeVariant.toInt();
801 if ( eltType != PROPAGATION_TREE )
802 //INFOS("bad element type : not a group item" << eltType );
805 // Get elements to highlight
806 QModelIndexList iEdges = meshModel->getPropagation( eltIndex );
807 if (iEdges.count() == 0) return;
809 // ---------- elements highlight --------------
811 // Set selection mode in VTK view
812 viewWindow->SetSelectionMode(EdgeSelection);
814 TColStd_MapOfInteger aMap;
818 foreach( const QModelIndex& iEdge, iEdges ){
821 edgeEntry = iEdge.data( HEXA_ENTRY_ROLE ).toString();
822 vtkElemsId = documentActor->vtkElemsId[ edgeEntry.toInt() ];
823 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
827 selector->AddOrRemoveIndex( documentActor->getIO(), aMap, false );
828 viewWindow->highlight( documentActor->getIO(), true, true );
829 documentActor->highlight( false );
836 /********************************************************************************
837 * ABSTRACT METHOD ( MUST BE IMPLEMENTED )
838 ********************************************************************************/
841 Returns the item that covers the coordinate given in the view.
844 QModelIndex VtkDocumentGraphicView::indexAt(const QPoint &point) const
846 return QModelIndex();
849 void VtkDocumentGraphicView::scrollTo(const QModelIndex &index, ScrollHint)
855 Returns the position of the item in viewport coordinates.
857 QRect VtkDocumentGraphicView::visualRect(const QModelIndex &index) const
863 int VtkDocumentGraphicView::horizontalOffset() const
865 return horizontalScrollBar()->value();
868 bool VtkDocumentGraphicView::isIndexHidden(const QModelIndex &index) const
873 QModelIndex VtkDocumentGraphicView::moveCursor(QAbstractItemView::CursorAction cursorAction,
874 Qt::KeyboardModifiers /*modifiers*/)
876 QModelIndex current = currentIndex();
881 Find the indices corresponding to the extent of the selection.
883 void VtkDocumentGraphicView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
888 int VtkDocumentGraphicView::verticalOffset() const
890 return verticalScrollBar()->value();
894 Returns a region corresponding to the selection in viewport coordinates.
896 QRegion VtkDocumentGraphicView::visualRegionForSelection(const QItemSelection &selection) const
904 /********************************************************************************
906 ********************************************************************************/
907 void VtkDocumentGraphicView::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint )
911 void VtkDocumentGraphicView::commitData ( QWidget * editor )
915 void VtkDocumentGraphicView::currentChanged( const QModelIndex & current, const QModelIndex & previous )
917 // openPersistentEditor( current );
918 _currentChanged = true;
921 void VtkDocumentGraphicView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )
924 _currentChanged = false;
925 // updateObject(topLeft);
928 void VtkDocumentGraphicView::editorDestroyed ( QObject * editor )
932 void VtkDocumentGraphicView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end )
936 void VtkDocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
940 void VtkDocumentGraphicView::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
944 void VtkDocumentGraphicView::updateGeometries ()
948 // bool DocumentGraphicView::canBeDisplayed( const QString& entry, const QString& viewer_type ) const //CS_TODO
950 // bool result = false;
952 // result = (viewer_type==SVTK_Viewer::Type());
953 // // QStringList es = entry.split( "_" );22
954 // // bool result = ( es.count() == 3 && es[ 0 ] == "ATOMSOLVGUI" && viewer_type == SVTK_Viewer::Type() );
955 // // // printf ( " canBeDisplayed : entry = %s, count = %d, res = %d \n", entry.latin1(), es.count(), result );
956 // std::cout << "canBeDisplayed => "<< result << std::endl;
957 // return result; // entry of an atom for sure
960 // SALOME_Prs* HEXABLOCKGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame)
962 // SALOME_Prs* prs = 0;
964 // SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
968 // SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
971 // SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
972 // SALOME_Actor* anActor = myGraphicView->FindActorByEntry( wnd, entry.toLatin1().data() );
975 // // anActor = myGraphicView->CreateActor( study()->studyDS(), entry.toLatin1().data(), true );
976 // anActor = myGraphicView->CreateActor(entry.toLatin1().data());
980 // // Display actor :
981 // SVTK_ViewWindow* vtkWnd = dynamic_cast<SVTK_ViewWindow*> (wnd);
982 // if (vtkWnd != NULL)
984 // vtkWnd->AddActor(anActor);
985 // vtkWnd->Repaint();
986 // prs = LightApp_Displayer::buildPresentation(entry.toLatin1().data(), aViewFrame);
995 // //SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
996 // std::cout << "Remove Actor" << std::endl;
1004 // SALOME_Prs* SMESHGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
1006 // SALOME_Prs* prs = 0;
1008 // SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1010 // if ( aViewFrame )
1012 // SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
1015 // SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
1016 // SMESH_Actor* anActor = SMESH::FindActorByEntry( wnd, entry.toLatin1().data() );
1018 // anActor = SMESH::CreateActor( study()->studyDS(), entry.toLatin1().data(), true );
1021 // SMESH::DisplayActor( wnd, anActor );
1022 // prs = LightApp_Displayer::buildPresentation( entry.toLatin1().data(), aViewFrame );
1025 // UpdatePrs( prs );
1026 // else if( anActor )
1027 // SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
1035 // void DocumentGraphicView::RemoveActor(SUIT_ViewWindow *theWnd, SALOME_Actor* theActor)
1037 // std::cout << "RemoveActor() : 1" << std::endl;
1038 // SVTK_ViewWindow* myViewWindow = dynamic_cast<SVTK_ViewWindow*>(theWnd);
1039 // // SVTK_ViewWindow* myViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
1040 // if (myViewWindow != NULL)
1042 // myViewWindow->RemoveActor(theActor);
1043 // if(theActor->hasIO())
1045 // std::cout << "RemoveActor() : 2" << std::endl;
1046 // Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
1047 // if(anIO->hasEntry())
1049 // std::cout << "RemoveActor() : 3" << std::endl;
1050 // std::string anEntry = anIO->getEntry();
1051 // SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myViewWindow->getViewManager()->study() );
1052 // int aStudyId = aStudy->id();
1053 // // TVisualObjCont::key_type aKey(aStudyId,anEntry);
1054 // // VISUAL_OBJ_CONT.erase(aKey);
1057 // theActor->Delete();
1058 // myViewWindow->Repaint();
1059 // std::cout << "RemoveActor() : 4" << std::endl;
1063 // bool DocumentGraphicView::eventFilter(QObject *obj, QEvent *event)
1065 // std::cout << event->type() << std::endl;
1066 // // if ( event->type() == QEvent::FocusIn ){ //QEvent::KeyPress) {
1069 // // // standard event processing
1070 // // // return QObject::eventFilter(obj, event);
1072 // if ( event->type() == QEvent::Paint ) { //QEvent::FocusIn ){
1073 // std::cout << "PAINTTTTTTTTTT"<< std::endl;
1074 // // loadVTK( "/tmp/load.vtk"); //CS_TEST
1076 // return _suitView->event(event);
1082 //show the actor when show=true and hide it when show=false
1083 //void VtkDocumentGraphicView::showActor(bool show)
1085 // SVTK_ViewWindow* theVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
1086 // if (theVTKViewWindow == NULL || _documentActor == NULL)
1091 // _documentActor->SetVisibility(1);
1092 // theVTKViewWindow->onFitAll();
1096 // _documentActor->SetVisibility(0);
1097 // theVTKViewWindow->onResetView ();
1101 void VtkDocumentGraphicView::setModel ( QAbstractItemModel * model )
1103 QAbstractItemView::setModel( model );
1105 // PatternDataModel* pdm = dynamic_cast<PatternDataModel*>(model);
1107 // connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
1110 DocumentModel* dm = dynamic_cast<DocumentModel*>(model);
1112 // setWindowTitle( dm->getName() );
1113 connect( dm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
1114 // connect( dm, SIGNAL( nameChanged(const QString&) ), this, SLOT ( setWindowTitle(const QString&) ) );
1118 // void DocumentGraphicView::loadVTK( const QString& path ) //CS_TEST
1120 // std::cout << "DocumentGraphicView::loadVTK=>"<<std::endl;
1121 // QFile file(path);
1122 // if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
1124 // // QByteArray vtkData = file.readAll ();
1125 // QString vtkData = file.readAll ();
1126 // vtkData.replace(",",".");
1129 // SVTK_ViewWindow* myVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
1131 // // vtkStructuredGridReader
1132 // vtkUnstructuredGridReader* r = vtkUnstructuredGridReader::New();
1133 // // r->SetFileName( path.toLocal8Bit().constData() );
1134 // r->SetInputString( vtkData.toLocal8Bit().constData() );
1135 // r->SetReadFromInputString( true );
1138 // vtkUnstructuredGrid* myGrid = r->GetOutput();//vtkUnstructuredGrid::New();
1139 // std::cout << "GetNumberOfCells =>"<< myGrid->GetNumberOfCells();
1140 // // Create and display actor
1142 // vtkDataSetMapper* myMapper = vtkDataSetMapper::New();
1143 // myMapper->SetInput(myGrid);
1145 // // if ( myPreviewActor ){
1146 // // myVTKViewWindow->RemoveActor(myPreviewActor);
1147 // // myPreviewActor->Delete();
1150 // SALOME_Actor* myPreviewActor = SALOME_Actor::New();
1151 // myPreviewActor = SALOME_Actor::New();
1152 // Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(QString::number( reinterpret_cast<intptr_t>(_hexaDocument) ),"HEXABLOCK");//,theName);
1153 // myPreviewActor->setIO(anIO);
1155 // // myPreviewActor->PickableOff();
1156 // myPreviewActor->SetVisibility( true );//VisibilityOff();
1157 // myPreviewActor->SetPickable( true );
1158 // myPreviewActor->SetMapper(myMapper);
1160 // vtkProperty* aProp = vtkProperty::New();
1161 // // aProp->SetRepresentationToWireframe();
1162 // aProp->SetRepresentationToSurface();
1163 // aProp->EdgeVisibilityOn ();
1165 // // aProp->SetColor(10, 10, 250);
1166 // aProp->SetPointSize(5);
1167 // myPreviewActor->SetProperty(aProp);
1170 // /*vtkProperty* myBackProp = vtkProperty::New();
1171 // GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
1172 // myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
1173 // myPreviewActor->SetBackfaceProperty( myBackProp );
1174 // myBackProp->Delete()*/;
1175 // myVTKViewWindow->AddActor(myPreviewActor);
1176 // myVTKViewWindow->getRenderer()->Render();
1177 // myVTKViewWindow->Repaint();
1178 // myVTKViewWindow->onFitAll();
1180 // myVTKViewWindow->SetSelectionMode( ActorSelection );
1181 // // myVTKViewWindow->SetSelectionMode( NodeSelection );
1182 // // myVTKViewWindow->SetSelectionMode( EdgeSelection );
1183 // // myVTKViewWindow->SetSelectionMode( FaceSelection );
1186 // void DocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
1189 // // std::cout << "DocumentGraphicView::rowsInserted : " << parent.data().toString().toStdString() << std::endl;
1190 // QModelIndex newRow;
1192 // SVTK_ViewWindow* myViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
1193 // SUIT_ViewManager* vman = myViewWindow->getViewManager();
1194 // SUIT_ViewModel* vmodel = vman->getViewModel();
1196 // for ( int i = start; i<= end; ++i ){
1197 // newRow = parent.child(i,0);
1198 // // std::cout << "newRow.data().toString() =>" << newRow.data().toString().toStdString() << std::endl;
1199 // QString entry = newRow.data(HEXA_ENTRY_ROLE).toString();//.toStdString();
1200 // Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1203 // // addObject(newRow);