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>
50 // test tutorial (sphere)
51 #include <vtkPolyDataMapper.h>
52 #include <vtkSphereSource.h>
54 // test point (cf. SMESHGUI)
55 #include <vtkIdList.h>
56 #include <vtkCellArray.h>
57 #include <vtkUnsignedCharArray.h>
58 #include <vtkUnstructuredGrid.h>
59 #include <vtkDataSetMapper.h>
60 #include <vtkProperty.h>
61 #include <vtkLineSource.h>
65 #include <vtkHexahedron.h>
67 #include "vtkLookupTable.h"
68 #include "vtkPoints.h"
69 #include "vtkCellArray.h"
70 #include "vtkFloatArray.h"
71 #include "vtkPolyData.h"
72 #include "vtkPolyDataMapper.h"
74 #include "vtkPointData.h"
75 #include "vtkProperty.h"
78 // #include "vtkStructuredGridReader.h"
79 #include "vtkUnstructuredGridReader.h"
82 #include <VTKViewer_CellLocationsArray.h>
89 #define M_PI 3.1415927
92 #include "HEXABLOCKGUI_Trace.hxx"
93 #include "HEXABLOCKGUI_DocumentModel.hxx"
94 #include "HEXABLOCKGUI_DocumentGraphicView.hxx"
99 using namespace HEXABLOCK::GUI;
102 Document_Actor::Document_Actor( HEXA_NS::Document* doc, const QString& entry ):
106 DEBTRACE("Document_Actor::Document_Actor " << entry.toLatin1() );
107 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK" );//,theName); CS_TODO
109 vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
110 // std::cout << "Document_Actor aGrid->GetNumberOfCells() =>"<< aGrid->GetNumberOfCells();
111 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
112 aMapper->SetInput(aGrid);
115 SetVisibility( true );//VisibilityOff();
116 SetPickable( true ); //PickableOff();//
117 SetMapper( aMapper );
120 vtkProperty* aProp = vtkProperty::New();
122 // aProp->SetRepresentationToSurface();
123 aProp->SetRepresentationToWireframe();
124 // aProp->SetRepresentationToPoints();
125 aProp->EdgeVisibilityOn ();
126 aProp->SetPointSize(5);
127 SetProperty( aProp );
129 // SetPointRepresentation(true);
133 Document_Actor::~Document_Actor()
139 vtkUnstructuredGrid* Document_Actor::getUnstructuredGrid()
141 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
143 _doc->reorderFaces(); //CS_TEST
145 std::map<int,vtkIdType> vtkNodeId;
146 std::map<vtkIdType, int> hexaNodeId;
149 vtkPoints* aPoints = vtkPoints::New();
150 int nbVertex = _doc->countVertex();
151 aPoints->SetNumberOfPoints( nbVertex );
153 HEXA_NS::Vertex* v = NULL;
155 for ( int i=0; i <nbVertex; ++i ){
156 v = _doc->getVertex(i);
157 aPoints->SetPoint( i, v->getX(), v->getY(), v->getZ() );
158 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
159 vtkNodeId [ vertexId ] = i;
160 hexaNodeId[ i ] = vertexId ;
161 // vtkNodeId [ vertexId ] = i+1;
162 // hexaNodeId[ i+1 ] = vertexId ;
165 theGrid->SetPoints( aPoints );
167 // theGrid->SetCells( 0, 0, 0, 0, 0 );
170 // Calculate cells size
171 int nb0DElement = _doc->countVertex();
172 int nbEdge = _doc->countEdge();
173 int nbFace = _doc->countQuad();
174 int nbVolume = _doc->countHexa();
176 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
177 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
180 vtkCellArray* aConnectivity = vtkCellArray::New();
181 aConnectivity->Allocate( aCellsSize, 0 );
183 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
184 aCellTypesArray->SetNumberOfComponents( 1 );
185 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
187 vtkIdList *anIdList = vtkIdList::New();
188 vtkIdType iVtkElem = 0;
189 // vtkIdType iVtkElem = 1; //CS_TEST
193 for ( int i=0; i<nb0DElement; ++i ){
194 anIdList->SetNumberOfIds( 1 );
195 v = _doc->getVertex(i);
196 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
197 vtkElemsId[iHexaElem] = iVtkElem;
198 hexaElemsId[iVtkElem] = iHexaElem;
199 anIdList->SetId(0, vtkNodeId[iHexaElem]);
200 aConnectivity->InsertNextCell( anIdList );
201 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
206 HEXA_NS::Edge* e = NULL;
207 HEXA_NS::Vertex* vertexElem = NULL;
208 for ( int i=0; i<nbEdge; ++i ){
209 anIdList->SetNumberOfIds( 2 );
210 e = _doc->getEdge(i);
211 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
212 vtkElemsId[iHexaElem] = iVtkElem;
213 hexaElemsId[iVtkElem] = iHexaElem;
215 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
216 vertexElem = e->getVertex( j );
217 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
219 aConnectivity->InsertNextCell( anIdList );
220 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
225 HEXA_NS::Quad* q = NULL;
226 HEXA_NS::Quad* quadElem = NULL;
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 ) );
244 HEXA_NS::Hexa* h = NULL;
245 HEXA_NS::Hexa* hexaElem = NULL;
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( HEXA_NS::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->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
329 vtkUnstructuredGrid* Associate_Actor::getUnstructuredGrid()
331 vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
333 _doc->reorderFaces(); //CS_TEST
335 std::map<int,vtkIdType> vtkNodeId;
336 std::map<vtkIdType, int> hexaNodeId;
338 std::vector <HEXA_NS::Vertex*> tab_vertex;
339 HEXA_NS::Edges tab_edge;
341 _doc->getAssoVertices (tab_vertex);
342 _doc->getAssoEdges (tab_edge);
344 int nb0DElement = tab_vertex.size();
345 int nbEdge = tab_edge.size();
350 vtkPoints* aPoints = vtkPoints::New();
351 int nbVertex = nb0DElement;
352 aPoints->SetNumberOfPoints( nbVertex );
354 HEXA_NS::Vertex* v = NULL;
356 for ( int i=0; i <nbVertex; ++i ){
357 v = _doc->getVertex(i);
358 aPoints->SetPoint( i, v->getX(), v->getY(), v->getZ() );
359 vertexId = reinterpret_cast<intptr_t>(v); //v->getId();
360 vtkNodeId [ vertexId ] = i;
361 hexaNodeId[ i ] = vertexId ;
362 // vtkNodeId [ vertexId ] = i+1;
363 // hexaNodeId[ i+1 ] = vertexId ;
366 theGrid->SetPoints( aPoints );
368 // theGrid->SetCells( 0, 0, 0, 0, 0 );
370 // Calculate cells size
372 vtkIdType aCellsSize = 2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
373 vtkIdType aNbCells = nb0DElement + nbEdge + nbFace + nbVolume;
376 vtkCellArray* aConnectivity = vtkCellArray::New();
377 aConnectivity->Allocate( aCellsSize, 0 );
379 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
380 aCellTypesArray->SetNumberOfComponents( 1 );
381 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
383 vtkIdList *anIdList = vtkIdList::New();
384 vtkIdType iVtkElem = 0;
385 // vtkIdType iVtkElem = 1; //CS_TEST
389 for ( int i=0; i<nb0DElement; ++i ){
390 anIdList->SetNumberOfIds( 1 );
391 // v = _doc->getVertex(i); // Abu
393 iHexaElem = reinterpret_cast<intptr_t>(v);//v->getId();
394 vtkElemsId[iHexaElem] = iVtkElem;
395 hexaElemsId[iVtkElem] = iHexaElem;
396 anIdList->SetId(0, vtkNodeId[iHexaElem]);
397 aConnectivity->InsertNextCell( anIdList );
398 aCellTypesArray->InsertNextValue( VTK_VERTEX );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
403 HEXA_NS::Edge* e = NULL;
404 HEXA_NS::Vertex* vertexElem = NULL;
405 for ( int i=0; i<nbEdge; ++i ){
406 anIdList->SetNumberOfIds( 2 );
407 // e = _doc->getEdge(i); // Abu
409 iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
410 vtkElemsId[iHexaElem] = iVtkElem;
411 hexaElemsId[iVtkElem] = iHexaElem;
413 for( vtkIdType j = 0; j< 2; ++j ){ //j< e->countVertex(); ++j ){
414 vertexElem = e->getVertex( j );
415 anIdList->SetId( j, vtkNodeId[ reinterpret_cast<intptr_t>(vertexElem) ] );//vertexElem->getId() ]);
417 aConnectivity->InsertNextCell( anIdList );
418 aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
424 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF,
428 // Insert cells in grid
429 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
430 aCellLocationsArray->SetNumberOfComponents( 1 );
431 aCellLocationsArray->SetNumberOfTuples( aNbCells );
432 // std::cout << "aNbCells =>" << aNbCells << std::endl;
434 aConnectivity->InitTraversal();
435 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
436 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
438 theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
440 aCellLocationsArray->Delete();
441 aCellTypesArray->Delete();
442 aConnectivity->Delete();
444 //std::cout << "theGrid->GetNumberOfCells()" << theGrid->GetNumberOfCells() << std::endl;
448 // =============================================================== Abu : Fin
451 // DocumentGraphicView::DocumentGraphicView(SalomeApp_Application* app, SUIT_ViewWindow *suitView, QWidget *parent)
452 DocumentGraphicView::DocumentGraphicView( LightApp_Application* app, SUIT_ViewWindow *suitView, QWidget *parent )
453 : QAbstractItemView(parent),
454 _suitView( suitView ),
456 _associateActor (NULL), // Abu
457 _currentChanged( false )
459 // MESSAGE("DocumentGraphicView::DocumentGraphicView() app"<<app);
460 // MESSAGE("DocumentGraphicView::DocumentGraphicView() suitView"<<suitView);
461 // MESSAGE("DocumentGraphicView::DocumentGraphicView() parent"<<parent);
462 // _suitView->getViewPort();
463 // _suitView->viewport();
464 // _suitView->installEventFilter(this);
467 DocumentGraphicView::~DocumentGraphicView()
471 void DocumentGraphicView::setWindowTitle(const QString& title)
473 _suitView->setWindowTitle( QString("hexablock : ") + title );
476 void DocumentGraphicView::onPatternDatachanged()
478 MESSAGE("DocumentGraphicView::onPatternDatachanged(){");
484 void DocumentGraphicView::update()
486 MESSAGE("DocumentGraphicView::update(){");
488 SVTK_ViewWindow* theVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
489 // PatternDataModel* theModel = dynamic_cast<PatternDataModel *>( model() );
490 DocumentModel* theModel = dynamic_cast<DocumentModel*>( model() );
491 MESSAGE("model()"<<model());
492 MESSAGE("theModel"<<theModel);
493 if (!theModel) return;
495 HEXA_NS::Document* theDocumentImpl = theModel->documentImpl();
496 QString theDocumentEntry = theModel->documentEntry();
498 if ( _documentActor ){
499 theVTKViewWindow->RemoveActor( _documentActor );
500 _documentActor->Delete();
502 _documentActor = new Document_Actor( theDocumentImpl, theDocumentEntry );
503 theVTKViewWindow->AddActor( _documentActor );
505 // -------------------- Abu debut
506 if (HEXA_NS::special_option())
508 if (_associateActor != NULL)
510 theVTKViewWindow->RemoveActor( _associateActor );
511 _associateActor->Delete();
513 _associateActor = new Associate_Actor( theDocumentImpl, theDocumentEntry );
514 theVTKViewWindow->AddActor( _associateActor );
516 // -------------------- Abu fin
518 // display HEXABLOCK document model
519 theVTKViewWindow->getRenderer()->Render();
520 theVTKViewWindow->Repaint();
521 theVTKViewWindow->onFitAll();
522 // myVTKViewWindow->SetSelectionMode( ActorSelection );
523 // theVTKViewWindow->SetSelectionMode( NodeSelection );
524 // myVTKViewWindow->SetSelectionMode( FaceSelection );
529 /********************************************************************************
530 * ABSTRACT METHOD ( MUST BE IMPLEMENTED )
531 ********************************************************************************/
534 Returns the item that covers the coordinate given in the view.
537 QModelIndex DocumentGraphicView::indexAt(const QPoint &point) const
539 MESSAGE("DocumentGraphicView::indexAt(){");
541 return QModelIndex();
544 void DocumentGraphicView::scrollTo(const QModelIndex &index, ScrollHint)
546 MESSAGE("DocumentGraphicView::scrollTo(){");
547 MESSAGE("* item is: " << index.data().toString().toStdString());
552 Returns the position of the item in viewport coordinates.
554 QRect DocumentGraphicView::visualRect(const QModelIndex &index) const
556 MESSAGE("DocumentGraphicView::visualRect(){");
557 MESSAGE("* item is: " << index.data().toString().toStdString());
563 int DocumentGraphicView::horizontalOffset() const
565 MESSAGE("DocumentGraphicView::horizontalOffset(){");
567 return horizontalScrollBar()->value();
570 bool DocumentGraphicView::isIndexHidden(const QModelIndex &index) const
572 MESSAGE("DocumentGraphicView::isIndexHidden(){");
573 MESSAGE("* item is: " << index.data().toString().toStdString());
578 QModelIndex DocumentGraphicView::moveCursor(QAbstractItemView::CursorAction cursorAction,
579 Qt::KeyboardModifiers /*modifiers*/)
581 MESSAGE("DocumentGraphicView::moveCursor(){");
582 QModelIndex current = currentIndex();
583 MESSAGE("* current is: " << current.data(Qt::DisplayRole).toString().toStdString());
589 Find the indices corresponding to the extent of the selection.
591 void DocumentGraphicView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
593 MESSAGE("DocumentGraphicView::setSelection(){");
598 int DocumentGraphicView::verticalOffset() const
600 MESSAGE("DocumentGraphicView::verticalOffset(){");
602 return verticalScrollBar()->value();
606 Returns a region corresponding to the selection in viewport coordinates.
608 QRegion DocumentGraphicView::visualRegionForSelection(const QItemSelection &selection) const
610 MESSAGE("DocumentGraphicView::visualRegionForSelection(){");
618 /********************************************************************************
620 ********************************************************************************/
621 void DocumentGraphicView::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint )
623 MESSAGE("DocumentGraphicView::closeEditor(){");
624 MESSAGE("* hint is: " << hint);
628 void DocumentGraphicView::commitData ( QWidget * editor )
630 MESSAGE("DocumentGraphicView::commitData(){");
634 void DocumentGraphicView::currentChanged( const QModelIndex & current, const QModelIndex & previous )
636 // MESSAGE("DocumentGraphicView::currentChanged(){");
637 // MESSAGE("* current is: " << current.data().toString().toStdString());
638 // MESSAGE("* previous is: " << previous.data().toString().toStdString());
640 // openPersistentEditor( current );
641 _currentChanged = true;
644 void DocumentGraphicView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )
646 // MESSAGE("DocumentGraphicView::dataChanged(){");
647 // MESSAGE("* topLeft is: " << topLeft.data().toString().toStdString());
648 // MESSAGE("* bottomRight is: " << bottomRight.data().toString().toStdString());
651 _currentChanged = false;
652 // updateObject(topLeft);
655 void DocumentGraphicView::editorDestroyed ( QObject * editor )
657 MESSAGE("DocumentGraphicView::editorDestroyed(){");
661 void DocumentGraphicView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end )
663 // MESSAGE("DocumentGraphicView::rowsAboutToBeRemoved (){");
664 // MESSAGE("* parent is: " << parent.data(Qt::DisplayRole).toString().toStdString());
665 // MESSAGE("* start is: " << start);
666 // MESSAGE("* end is: " << end);
670 void DocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
672 // MESSAGE("DocumentGraphicView::rowsInserted(){");
673 // MESSAGE("* parent is: " << parent.data(Qt::DisplayRole).toString().toStdString());
674 // MESSAGE("* start is: " << start);
675 // MESSAGE("* end is: " << end);
679 void DocumentGraphicView::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
681 MESSAGE("DocumentGraphicView::selectionChanged(){");
682 foreach( const QModelIndex& isel, selected.indexes() ){
683 MESSAGE("* selected : " << isel.data().toString().toStdString());
685 foreach( const QModelIndex& iunsel, deselected.indexes() ){
686 MESSAGE("* unselected : " << iunsel.data().toString().toStdString());
691 void DocumentGraphicView::updateGeometries ()
693 MESSAGE("DocumentGraphicView::updateGeometries (){");
697 SUIT_ViewWindow* DocumentGraphicView::get_SUIT_ViewWindow()
702 // bool DocumentGraphicView::canBeDisplayed( const QString& entry, const QString& viewer_type ) const //CS_TODO
704 // bool result = false;
706 // result = (viewer_type==SVTK_Viewer::Type());
707 // // QStringList es = entry.split( "_" );22
708 // // bool result = ( es.count() == 3 && es[ 0 ] == "ATOMSOLVGUI" && viewer_type == SVTK_Viewer::Type() );
709 // // // printf ( " canBeDisplayed : entry = %s, count = %d, res = %d \n", entry.latin1(), es.count(), result );
710 // std::cout << "canBeDisplayed => "<< result << std::endl;
711 // return result; // entry of an atom for sure
714 // SALOME_Prs* HEXABLOCKGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame)
716 // SALOME_Prs* prs = 0;
718 // SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
722 // SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
725 // SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
726 // SALOME_Actor* anActor = myGraphicView->FindActorByEntry( wnd, entry.toLatin1().data() );
729 // // anActor = myGraphicView->CreateActor( study()->studyDS(), entry.toLatin1().data(), true );
730 // anActor = myGraphicView->CreateActor(entry.toLatin1().data());
734 // // Display actor :
735 // SVTK_ViewWindow* vtkWnd = dynamic_cast<SVTK_ViewWindow*> (wnd);
736 // if (vtkWnd != NULL)
738 // vtkWnd->AddActor(anActor);
739 // vtkWnd->Repaint();
740 // prs = LightApp_Displayer::buildPresentation(entry.toLatin1().data(), aViewFrame);
749 // //SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
750 // std::cout << "Remove Actor" << std::endl;
758 // SALOME_Prs* SMESHGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
760 // SALOME_Prs* prs = 0;
762 // SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
766 // SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
769 // SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
770 // SMESH_Actor* anActor = SMESH::FindActorByEntry( wnd, entry.toLatin1().data() );
772 // anActor = SMESH::CreateActor( study()->studyDS(), entry.toLatin1().data(), true );
775 // SMESH::DisplayActor( wnd, anActor );
776 // prs = LightApp_Displayer::buildPresentation( entry.toLatin1().data(), aViewFrame );
780 // else if( anActor )
781 // SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
789 // void DocumentGraphicView::RemoveActor(SUIT_ViewWindow *theWnd, SALOME_Actor* theActor)
791 // std::cout << "RemoveActor() : 1" << std::endl;
792 // SVTK_ViewWindow* myViewWindow = dynamic_cast<SVTK_ViewWindow*>(theWnd);
793 // // SVTK_ViewWindow* myViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
794 // if (myViewWindow != NULL)
796 // myViewWindow->RemoveActor(theActor);
797 // if(theActor->hasIO())
799 // std::cout << "RemoveActor() : 2" << std::endl;
800 // Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
801 // if(anIO->hasEntry())
803 // std::cout << "RemoveActor() : 3" << std::endl;
804 // std::string anEntry = anIO->getEntry();
805 // SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myViewWindow->getViewManager()->study() );
806 // int aStudyId = aStudy->id();
807 // // TVisualObjCont::key_type aKey(aStudyId,anEntry);
808 // // VISUAL_OBJ_CONT.erase(aKey);
811 // theActor->Delete();
812 // myViewWindow->Repaint();
813 // std::cout << "RemoveActor() : 4" << std::endl;
817 // bool DocumentGraphicView::eventFilter(QObject *obj, QEvent *event)
819 // std::cout << event->type() << std::endl;
820 // // if ( event->type() == QEvent::FocusIn ){ //QEvent::KeyPress) {
823 // // // standard event processing
824 // // // return QObject::eventFilter(obj, event);
826 // if ( event->type() == QEvent::Paint ) { //QEvent::FocusIn ){
827 // std::cout << "PAINTTTTTTTTTT"<< std::endl;
828 // // loadVTK( "/tmp/load.vtk"); //CS_TEST
830 // return _suitView->event(event);
835 void DocumentGraphicView::setModel ( QAbstractItemModel * model )
837 MESSAGE("DocumentGraphicView::setModel (){");
838 QAbstractItemView::setModel( model );
840 // PatternDataModel* pdm = dynamic_cast<PatternDataModel*>(model);
841 // MESSAGE("pdm"<<pdm);
843 // connect( pdm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
846 DocumentModel* dm = dynamic_cast<DocumentModel*>(model);
849 setWindowTitle( dm->getName() );
850 connect( dm, SIGNAL(patternDataChanged() ), this, SLOT ( onPatternDatachanged() ) );
851 connect( dm, SIGNAL( nameChanged(const QString&) ), this, SLOT ( setWindowTitle(const QString&) ) );
858 // void DocumentGraphicView::loadVTK( const QString& path ) //CS_TEST
860 // std::cout << "DocumentGraphicView::loadVTK=>"<<std::endl;
862 // if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
864 // // QByteArray vtkData = file.readAll ();
865 // QString vtkData = file.readAll ();
866 // vtkData.replace(",",".");
869 // SVTK_ViewWindow* myVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
871 // // vtkStructuredGridReader
872 // vtkUnstructuredGridReader* r = vtkUnstructuredGridReader::New();
873 // // r->SetFileName( path.toLocal8Bit().constData() );
874 // r->SetInputString( vtkData.toLocal8Bit().constData() );
875 // r->SetReadFromInputString( true );
878 // vtkUnstructuredGrid* myGrid = r->GetOutput();//vtkUnstructuredGrid::New();
879 // std::cout << "GetNumberOfCells =>"<< myGrid->GetNumberOfCells();
880 // // Create and display actor
882 // vtkDataSetMapper* myMapper = vtkDataSetMapper::New();
883 // myMapper->SetInput(myGrid);
885 // // if ( myPreviewActor ){
886 // // myVTKViewWindow->RemoveActor(myPreviewActor);
887 // // myPreviewActor->Delete();
890 // SALOME_Actor* myPreviewActor = SALOME_Actor::New();
891 // myPreviewActor = SALOME_Actor::New();
892 // Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(QString::number( reinterpret_cast<intptr_t>(_hexaDocument) ),"HEXABLOCK");//,theName);
893 // myPreviewActor->setIO(anIO);
895 // // myPreviewActor->PickableOff();
896 // myPreviewActor->SetVisibility( true );//VisibilityOff();
897 // myPreviewActor->SetPickable( true );
898 // myPreviewActor->SetMapper(myMapper);
900 // vtkProperty* aProp = vtkProperty::New();
901 // // aProp->SetRepresentationToWireframe();
902 // aProp->SetRepresentationToSurface();
903 // aProp->EdgeVisibilityOn ();
905 // // aProp->SetColor(10, 10, 250);
906 // aProp->SetPointSize(5);
907 // myPreviewActor->SetProperty(aProp);
910 // /*vtkProperty* myBackProp = vtkProperty::New();
911 // GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
912 // myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
913 // myPreviewActor->SetBackfaceProperty( myBackProp );
914 // myBackProp->Delete()*/;
915 // myVTKViewWindow->AddActor(myPreviewActor);
916 // myVTKViewWindow->getRenderer()->Render();
917 // myVTKViewWindow->Repaint();
918 // myVTKViewWindow->onFitAll();
920 // myVTKViewWindow->SetSelectionMode( ActorSelection );
921 // // myVTKViewWindow->SetSelectionMode( NodeSelection );
922 // // myVTKViewWindow->SetSelectionMode( EdgeSelection );
923 // // myVTKViewWindow->SetSelectionMode( FaceSelection );
926 // void DocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
929 // // std::cout << "DocumentGraphicView::rowsInserted : " << parent.data().toString().toStdString() << std::endl;
930 // QModelIndex newRow;
932 // SVTK_ViewWindow* myViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
933 // SUIT_ViewManager* vman = myViewWindow->getViewManager();
934 // SUIT_ViewModel* vmodel = vman->getViewModel();
936 // for ( int i = start; i<= end; ++i ){
937 // newRow = parent.child(i,0);
938 // // std::cout << "newRow.data().toString() =>" << newRow.data().toString().toStdString() << std::endl;
939 // QString entry = newRow.data(HEXA_ENTRY_ROLE).toString();//.toStdString();
940 // Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
943 // // addObject(newRow);