Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentGraphicView.cxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //#define _DEVDEBUG_
21
22 #include <sstream>
23
24 #include <iostream>
25
26 #include <math.h>
27
28 #include "utilities.h"
29
30 #include <QtGui>
31
32
33 #include <LightApp_Application.h>
34
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>
40 #include <SVTK_Prs.h>
41 #include <SALOME_Actor.h>
42 #include <VTKViewer_Algorithm.h>
43 #include <SalomeApp_Study.h>
44
45 // VTK includes
46 #include <vtkRenderer.h>
47 #include <vtkActorCollection.h>
48 #include <vtkUnstructuredGrid.h>
49
50 // test tutorial (sphere)
51 #include <vtkPolyDataMapper.h>
52 #include <vtkSphereSource.h>
53
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>
62
63 #include <vtkLine.h>
64 #include <vtkQuad.h>
65 #include <vtkHexahedron.h>
66
67 #include "vtkLookupTable.h"
68 #include "vtkPoints.h"
69 #include "vtkCellArray.h"
70 #include "vtkFloatArray.h"
71 #include "vtkPolyData.h"
72 #include "vtkPolyDataMapper.h"
73 #include "vtkActor.h"
74 #include "vtkPointData.h"
75 #include "vtkProperty.h"
76
77
78 // #include "vtkStructuredGridReader.h"
79 #include "vtkUnstructuredGridReader.h"
80
81
82 #include <VTKViewer_CellLocationsArray.h>
83
84
85
86
87
88 #ifndef M_PI
89 #define M_PI 3.1415927
90 #endif
91
92 #include "HEXABLOCKGUI_Trace.hxx"
93 #include "HEXABLOCKGUI_DocumentModel.hxx"
94 #include "HEXABLOCKGUI_DocumentGraphicView.hxx"
95
96
97
98 using namespace std;
99 using namespace HEXABLOCK::GUI;
100
101
102 Document_Actor::Document_Actor( HEXA_NS::Document* doc, const QString& entry ):
103   SALOME_Actor(),
104   _doc( doc )
105 {
106   DEBTRACE("Document_Actor::Document_Actor " << entry.toLatin1() );
107   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK" );//,theName); CS_TODO
108   setIO(anIO);
109   vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
110 //   std::cout << "Document_Actor aGrid->GetNumberOfCells() =>"<< aGrid->GetNumberOfCells();
111   vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
112   aMapper->SetInput(aGrid);
113   aGrid->Delete();
114
115   SetVisibility( true );//VisibilityOff();
116   SetPickable( true ); //PickableOff();//
117   SetMapper( aMapper );
118   aMapper->Delete();
119
120   vtkProperty* aProp = vtkProperty::New();
121
122 //   aProp->SetRepresentationToSurface();
123   aProp->SetRepresentationToWireframe();
124 //   aProp->SetRepresentationToPoints();
125   aProp->EdgeVisibilityOn ();
126   aProp->SetPointSize(5);
127   SetProperty( aProp );
128   aProp->Delete();
129 //   SetPointRepresentation(true);
130
131 }
132
133 Document_Actor::~Document_Actor()
134 {
135
136 }
137
138
139 vtkUnstructuredGrid* Document_Actor::getUnstructuredGrid()
140 {
141   vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
142
143   _doc->reorderFaces(); //CS_TEST
144
145   std::map<int,vtkIdType>   vtkNodeId;
146   std::map<vtkIdType, int>  hexaNodeId;
147
148   // Create points
149   vtkPoints* aPoints = vtkPoints::New();
150   int nbVertex = _doc->countVertex();
151   aPoints->SetNumberOfPoints( nbVertex );
152
153   HEXA_NS::Vertex* v = NULL;
154   int vertexId;
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 ;
163   }
164
165   theGrid->SetPoints( aPoints );
166   aPoints->Delete();
167 //   theGrid->SetCells( 0, 0, 0, 0, 0 );
168
169
170   // Calculate cells size
171   int nb0DElement = _doc->countVertex();
172   int nbEdge      = _doc->countEdge();
173   int nbFace      = _doc->countQuad();
174   int nbVolume    = _doc->countHexa();
175
176   vtkIdType aCellsSize =  2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
177   vtkIdType aNbCells   =  nb0DElement + nbEdge + nbFace + nbVolume;
178
179   // Create cells
180   vtkCellArray* aConnectivity = vtkCellArray::New();
181   aConnectivity->Allocate( aCellsSize, 0 );
182
183   vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
184   aCellTypesArray->SetNumberOfComponents( 1 );
185   aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
186
187   vtkIdList *anIdList = vtkIdList::New();
188   vtkIdType iVtkElem = 0;
189 //   vtkIdType iVtkElem = 1; //CS_TEST
190   int       iHexaElem;
191
192   // VERTEX
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 ) );
202     ++iVtkElem;
203   }
204
205   // EDGE
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;
214
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() ]);
218     }
219     aConnectivity->InsertNextCell( anIdList );
220     aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
221     ++iVtkElem;
222   }
223
224   // QUAD
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;
233
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() ]);
237     }
238     aConnectivity->InsertNextCell( anIdList );
239     aCellTypesArray->InsertNextValue( VTK_QUAD );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
240     ++iVtkElem;
241   }
242
243   // HEXA
244   HEXA_NS::Hexa* h = NULL;
245   HEXA_NS::Hexa* hexaElem = NULL;
246   std::map<int, int> connectivity;
247   connectivity[0] = 0;
248   connectivity[1] = 1;
249   connectivity[2] = 3;
250   connectivity[3] = 2;
251   connectivity[4] = 4;
252   connectivity[5] = 5;
253   connectivity[6] = 7;
254   connectivity[7] = 6;
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;
261
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() ]);
265     }
266     aConnectivity->InsertNextCell( anIdList );
267     aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON );
268     ++iVtkElem;
269   }
270
271
272 // 0        1      2     3        4     5      6      7
273 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF, 
274 // 
275 // 0        1     3      2        4    5      7      6
276
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;
282
283   aConnectivity->InitTraversal();
284   for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
285     aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
286   }
287   theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
288
289   aCellLocationsArray->Delete();
290   aCellTypesArray->Delete();
291   aConnectivity->Delete();
292   anIdList->Delete();
293   //std::cout << "theGrid->GetNumberOfCells()" << theGrid->GetNumberOfCells() << std::endl;
294
295   return theGrid;
296 }
297
298 // =============================================================== Abu : debut
299 // ===================================================== Constructeur
300 Associate_Actor::Associate_Actor( HEXA_NS::Document* doc, const QString& entry)
301                : SALOME_Actor(), _doc( doc )
302 {
303   DEBTRACE("Associate_Actor::Associate_Actor " << entry.toLatin1() );
304   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( entry.toLatin1(), "HEXABLOCK" );//,theName); CS_TODO
305   setIO(anIO);
306   vtkUnstructuredGrid* aGrid = getUnstructuredGrid();
307
308   vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
309   aMapper->SetInput(aGrid);
310   aGrid->Delete();
311
312   SetVisibility( true );//VisibilityOff();
313   SetPickable( true ); //PickableOff();//
314   SetMapper( aMapper );
315   aMapper->Delete();
316
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 );
325   aProp->Delete();
326 //   SetPointRepresentation(true);
327 }
328 // ===================================================== getUnstructuredGrid
329 vtkUnstructuredGrid* Associate_Actor::getUnstructuredGrid()
330 {
331   vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();
332
333   _doc->reorderFaces(); //CS_TEST
334
335   std::map<int,vtkIdType>   vtkNodeId;
336   std::map<vtkIdType, int>  hexaNodeId;
337  
338   std::vector <HEXA_NS::Vertex*>  tab_vertex;
339   HEXA_NS::Edges    tab_edge; 
340
341   _doc->getAssoVertices (tab_vertex);
342   _doc->getAssoEdges    (tab_edge);
343
344   int nb0DElement = tab_vertex.size();
345   int nbEdge      = tab_edge.size();
346   int nbFace      = 0;
347   int nbVolume    = 0;
348
349   // Create points
350   vtkPoints* aPoints = vtkPoints::New();
351   int nbVertex = nb0DElement;
352   aPoints->SetNumberOfPoints( nbVertex );
353
354   HEXA_NS::Vertex* v = NULL;
355   int vertexId;
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 ;
364   }
365
366   theGrid->SetPoints( aPoints );
367   aPoints->Delete();
368 //   theGrid->SetCells( 0, 0, 0, 0, 0 );
369
370   // Calculate cells size
371
372   vtkIdType aCellsSize =  2*nb0DElement + 3*nbEdge + ( 4 + 1 )*nbFace + ( 8 + 1 )*nbVolume;
373   vtkIdType aNbCells   =  nb0DElement + nbEdge + nbFace + nbVolume;
374
375   // Create cells
376   vtkCellArray* aConnectivity = vtkCellArray::New();
377   aConnectivity->Allocate( aCellsSize, 0 );
378
379   vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
380   aCellTypesArray->SetNumberOfComponents( 1 );
381   aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
382
383   vtkIdList *anIdList = vtkIdList::New();
384   vtkIdType iVtkElem = 0;
385 //   vtkIdType iVtkElem = 1; //CS_TEST
386   int       iHexaElem;
387
388   // VERTEX
389   for ( int i=0; i<nb0DElement; ++i ){
390     anIdList->SetNumberOfIds( 1 );
391  // v = _doc->getVertex(i);        // Abu 
392     v = tab_vertex [i];
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 ) );
399     ++iVtkElem;
400   }
401
402   // EDGE
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 
408     e = tab_edge [i];
409     iHexaElem = reinterpret_cast<intptr_t>(e); //e->getId();
410     vtkElemsId[iHexaElem] = iVtkElem;
411     hexaElemsId[iVtkElem] = iHexaElem;
412
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() ]);
416     }
417     aConnectivity->InsertNextCell( anIdList );
418     aCellTypesArray->InsertNextValue( VTK_LINE );//getCellType( aType, anElem->IsPoly(), aNbNodes ) );
419     ++iVtkElem;
420   }
421
422
423 // 0        1      2     3        4     5      6      7
424 // V_ACE, V_ACF, V_ADE, V_ADF, V_BCE, V_BCF, V_BDE, V_BDF, 
425 // 
426 // 0        1     3      2        4    5      7      6
427
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;
433
434   aConnectivity->InitTraversal();
435   for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ){
436     aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
437   }
438   theGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
439
440   aCellLocationsArray->Delete();
441   aCellTypesArray->Delete();
442   aConnectivity->Delete();
443   anIdList->Delete();
444   //std::cout << "theGrid->GetNumberOfCells()" << theGrid->GetNumberOfCells() << std::endl;
445
446   return theGrid;
447 }
448 // =============================================================== Abu : Fin
449
450
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 ),
455       _documentActor( 0 ),
456       _associateActor (NULL), // Abu
457       _currentChanged( false )
458 {
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);
465 }
466
467 DocumentGraphicView::~DocumentGraphicView()
468 {  
469 }
470
471 void DocumentGraphicView::setWindowTitle(const QString& title)
472 {
473   _suitView->setWindowTitle( QString("hexablock : ") + title );
474 }
475
476 void DocumentGraphicView::onPatternDatachanged()
477 {
478   MESSAGE("DocumentGraphicView::onPatternDatachanged(){");
479   update();
480   MESSAGE("}");
481 }
482
483
484 void DocumentGraphicView::update()
485 {
486   MESSAGE("DocumentGraphicView::update(){");
487
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;
494     
495   HEXA_NS::Document*  theDocumentImpl  = theModel->documentImpl();
496   QString             theDocumentEntry = theModel->documentEntry();
497
498   if ( _documentActor ){
499     theVTKViewWindow->RemoveActor( _documentActor );
500     _documentActor->Delete();
501   }
502   _documentActor  = new Document_Actor( theDocumentImpl, theDocumentEntry );
503   theVTKViewWindow->AddActor( _documentActor );
504  
505                                  // -------------------- Abu debut 
506   if (HEXA_NS::special_option())
507      {
508      if (_associateActor != NULL)
509         {
510         theVTKViewWindow->RemoveActor( _associateActor );
511         _associateActor->Delete();
512         }
513      _associateActor = new Associate_Actor( theDocumentImpl, theDocumentEntry );
514      theVTKViewWindow->AddActor( _associateActor );
515      }
516                                  // -------------------- Abu fin
517
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 );
525   MESSAGE("}");
526 }
527
528
529 /********************************************************************************
530 *                   ABSTRACT METHOD ( MUST BE IMPLEMENTED )
531 ********************************************************************************/
532
533 /*
534     Returns the item that covers the coordinate given in the view.
535 */
536
537 QModelIndex DocumentGraphicView::indexAt(const QPoint &point) const
538 {
539   MESSAGE("DocumentGraphicView::indexAt(){");
540   MESSAGE("}");
541   return QModelIndex();
542 }
543
544 void DocumentGraphicView::scrollTo(const QModelIndex &index, ScrollHint)
545 {
546   MESSAGE("DocumentGraphicView::scrollTo(){");
547   MESSAGE("*  item   is: " << index.data().toString().toStdString());
548   MESSAGE("}");
549 }
550
551 /*
552     Returns the position of the item in viewport coordinates.
553 */
554 QRect DocumentGraphicView::visualRect(const QModelIndex &index) const
555 {
556     MESSAGE("DocumentGraphicView::visualRect(){");
557     MESSAGE("*  item   is: " << index.data().toString().toStdString());
558     MESSAGE("}");
559     return QRect();
560 }
561
562 // PROTECTED :
563 int DocumentGraphicView::horizontalOffset() const
564 {
565     MESSAGE("DocumentGraphicView::horizontalOffset(){");
566     MESSAGE("}");
567     return horizontalScrollBar()->value();
568 }
569
570 bool DocumentGraphicView::isIndexHidden(const QModelIndex &index) const
571 {
572     MESSAGE("DocumentGraphicView::isIndexHidden(){");
573     MESSAGE("*  item   is: " << index.data().toString().toStdString());
574     MESSAGE("}");
575     return false;
576 }
577
578 QModelIndex DocumentGraphicView::moveCursor(QAbstractItemView::CursorAction cursorAction,
579                                             Qt::KeyboardModifiers /*modifiers*/)
580 {
581     MESSAGE("DocumentGraphicView::moveCursor(){");
582     QModelIndex current = currentIndex();
583     MESSAGE("*  current  is: " << current.data(Qt::DisplayRole).toString().toStdString());
584     MESSAGE("}");
585     return current;
586 }
587
588 /*
589     Find the indices corresponding to the extent of the selection.
590 */
591 void DocumentGraphicView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
592 {
593     MESSAGE("DocumentGraphicView::setSelection(){");
594     MESSAGE("}");
595 }
596
597
598 int DocumentGraphicView::verticalOffset() const
599 {
600     MESSAGE("DocumentGraphicView::verticalOffset(){");
601     MESSAGE("}");
602     return verticalScrollBar()->value();
603 }
604
605 /*
606     Returns a region corresponding to the selection in viewport coordinates.
607 */
608 QRegion DocumentGraphicView::visualRegionForSelection(const QItemSelection &selection) const
609 {
610     MESSAGE("DocumentGraphicView::visualRegionForSelection(){");
611     MESSAGE("}");
612     return QRegion();
613 }
614
615
616
617
618 /********************************************************************************
619 *                   PROTECTED SLOTS 
620 ********************************************************************************/
621 void DocumentGraphicView::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint )
622
623   MESSAGE("DocumentGraphicView::closeEditor(){");
624   MESSAGE("*  hint is: " << hint);
625   MESSAGE("}");
626 }
627
628 void DocumentGraphicView::commitData ( QWidget * editor )
629
630   MESSAGE("DocumentGraphicView::commitData(){");
631   MESSAGE("}");
632 }
633
634 void DocumentGraphicView::currentChanged( const QModelIndex & current, const QModelIndex & previous )
635
636 //   MESSAGE("DocumentGraphicView::currentChanged(){");
637 //   MESSAGE("*  current  is: " << current.data().toString().toStdString());
638 //   MESSAGE("*  previous is: " << previous.data().toString().toStdString());
639 //   MESSAGE("}");
640 //   openPersistentEditor( current );
641   _currentChanged = true;
642 }
643
644 void DocumentGraphicView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )
645
646 //   MESSAGE("DocumentGraphicView::dataChanged(){");
647 //   MESSAGE("*  topLeft     is: " << topLeft.data().toString().toStdString());
648 //   MESSAGE("*  bottomRight is: " << bottomRight.data().toString().toStdString());
649 //   MESSAGE("}");
650   update();
651   _currentChanged = false;
652 //   updateObject(topLeft);
653 }
654
655 void DocumentGraphicView::editorDestroyed ( QObject * editor )
656
657   MESSAGE("DocumentGraphicView::editorDestroyed(){");
658   MESSAGE("}");
659 }
660
661 void DocumentGraphicView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end )
662
663 //   MESSAGE("DocumentGraphicView::rowsAboutToBeRemoved (){");
664 //   MESSAGE("*  parent    is: " << parent.data(Qt::DisplayRole).toString().toStdString());
665 //   MESSAGE("*  start     is: " << start);
666 //   MESSAGE("*  end       is: " << end);
667 //   MESSAGE("}");
668 }
669
670 void DocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
671
672 //   MESSAGE("DocumentGraphicView::rowsInserted(){");
673 //   MESSAGE("*  parent    is: " << parent.data(Qt::DisplayRole).toString().toStdString());
674 //   MESSAGE("*  start     is: " << start);
675 //   MESSAGE("*  end       is: " << end);
676 //   MESSAGE("}");
677 }
678
679 void DocumentGraphicView::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
680
681   MESSAGE("DocumentGraphicView::selectionChanged(){");
682   foreach( const QModelIndex& isel, selected.indexes() ){
683     MESSAGE("*  selected : " << isel.data().toString().toStdString());
684   }
685   foreach( const QModelIndex& iunsel, deselected.indexes() ){
686     MESSAGE("*  unselected : " << iunsel.data().toString().toStdString());
687   }
688   MESSAGE("}");
689 }
690
691 void DocumentGraphicView::updateGeometries ()
692
693   MESSAGE("DocumentGraphicView::updateGeometries (){");
694   MESSAGE("}");
695 }
696
697 SUIT_ViewWindow* DocumentGraphicView::get_SUIT_ViewWindow()
698 {
699   return _suitView;
700 }
701
702 // bool DocumentGraphicView::canBeDisplayed( const QString& entry, const QString& viewer_type ) const //CS_TODO
703 // {
704 //   bool result = false;
705 // 
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
712 // }
713
714 // SALOME_Prs* HEXABLOCKGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame)
715 // {
716 //     SALOME_Prs* prs = 0;
717 // 
718 //     SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
719 // 
720 //     if ( aViewFrame )
721 //     {
722 //         SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
723 //         if (vtk_viewer)
724 //         {
725 //             SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
726 //             SALOME_Actor* anActor = myGraphicView->FindActorByEntry( wnd, entry.toLatin1().data() );
727 //             if (!anActor)
728 //             {
729 // //                anActor = myGraphicView->CreateActor( study()->studyDS(), entry.toLatin1().data(), true );
730 //                 anActor = myGraphicView->CreateActor(entry.toLatin1().data());
731 //             }
732 //             if (anActor)
733 //             {
734 //                 // Display actor :
735 //                 SVTK_ViewWindow* vtkWnd = dynamic_cast<SVTK_ViewWindow*> (wnd);
736 //                 if (vtkWnd != NULL)
737 //                 {
738 //                     vtkWnd->AddActor(anActor);
739 //                     vtkWnd->Repaint();
740 //                     prs = LightApp_Displayer::buildPresentation(entry.toLatin1().data(), aViewFrame);
741 //                 }
742 //             }
743 //             if (prs)
744 //             {
745 //                 UpdatePrs(prs);
746 //             }
747 //             else if (anActor)
748 //             {
749 //                 //SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
750 //                 std::cout << "Remove Actor" << std::endl;
751 //             }
752 //         }
753 //     }
754 // 
755 //     return prs;
756 // }
757
758 // SALOME_Prs* SMESHGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
759 // {
760 //   SALOME_Prs* prs = 0;
761 // 
762 //   SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
763 // 
764 //   if ( aViewFrame )
765 //   {
766 //     SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
767 //     if( vtk_viewer )
768 //     {
769 //       SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
770 //       SMESH_Actor* anActor = SMESH::FindActorByEntry( wnd, entry.toLatin1().data() );
771 //       if( !anActor )
772 //         anActor = SMESH::CreateActor( study()->studyDS(), entry.toLatin1().data(), true );
773 //       if( anActor )
774 //       {
775 //         SMESH::DisplayActor( wnd, anActor );
776 //         prs = LightApp_Displayer::buildPresentation( entry.toLatin1().data(), aViewFrame );
777 //       }
778 //       if( prs )
779 //         UpdatePrs( prs );
780 //       else if( anActor )
781 //         SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
782 //     }
783 //   }
784 // 
785 //   return prs;
786 // }
787
788 // 
789 // void DocumentGraphicView::RemoveActor(SUIT_ViewWindow *theWnd, SALOME_Actor* theActor)
790 // {
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)
795 //     {
796 //         myViewWindow->RemoveActor(theActor);
797 //         if(theActor->hasIO())
798 //         {
799 //             std::cout << "RemoveActor() : 2" << std::endl;            
800 //             Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
801 //             if(anIO->hasEntry())
802 //             {
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);
809 //             }
810 //         }
811 //         theActor->Delete();
812 //         myViewWindow->Repaint();
813 //         std::cout << "RemoveActor() : 4" << std::endl;        
814 //     }
815 // }
816
817 // bool DocumentGraphicView::eventFilter(QObject *obj, QEvent *event)
818 // {
819 //     std::cout << event->type() << std::endl;
820 // //     if ( event->type() == QEvent::FocusIn ){ //QEvent::KeyPress) { 
821 // //         return false;
822 // //     } else {
823 // //          // standard event processing
824 // // //          return QObject::eventFilter(obj, event);
825 // 
826 //     if ( event->type() == QEvent::Paint ) { //QEvent::FocusIn ){ 
827 //       std::cout << "PAINTTTTTTTTTT"<< std::endl;
828 // //       loadVTK( "/tmp/load.vtk"); //CS_TEST
829 //     }
830 //     return _suitView->event(event);
831 // //     }
832 // }
833 // 
834 // 
835 void DocumentGraphicView::setModel ( QAbstractItemModel * model )
836 {
837   MESSAGE("DocumentGraphicView::setModel (){");
838   QAbstractItemView::setModel( model );
839   
840 //   PatternDataModel* pdm = dynamic_cast<PatternDataModel*>(model);
841 //   MESSAGE("pdm"<<pdm);
842 //   if (pdm){    
843 //     connect( pdm, SIGNAL(patternDataChanged() ), this,  SLOT ( onPatternDatachanged() ) );
844 //   }
845     
846   DocumentModel* dm = dynamic_cast<DocumentModel*>(model);
847   MESSAGE("dm"<<dm);
848   if (dm){
849     setWindowTitle( dm->getName() );
850     connect( dm, SIGNAL(patternDataChanged() ), this,  SLOT ( onPatternDatachanged() ) );
851     connect( dm, SIGNAL( nameChanged(const QString&) ), this,  SLOT ( setWindowTitle(const QString&) ) );    
852     
853   }
854   
855   
856 }
857
858 // void DocumentGraphicView::loadVTK( const QString&  path ) //CS_TEST
859 // {
860 //   std::cout << "DocumentGraphicView::loadVTK=>"<<std::endl;
861 //   QFile file(path);
862 //   if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
863 //     return;
864 // //   QByteArray vtkData = file.readAll ();
865 //   QString vtkData = file.readAll ();
866 //   vtkData.replace(",",".");
867 // 
868 // 
869 //   SVTK_ViewWindow* myVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
870 // 
871 //   // vtkStructuredGridReader
872 //   vtkUnstructuredGridReader* r = vtkUnstructuredGridReader::New();
873 // //   r->SetFileName( path.toLocal8Bit().constData() );
874 //   r->SetInputString( vtkData.toLocal8Bit().constData() );
875 //   r->SetReadFromInputString( true );
876 //   r->Update();
877 // 
878 //   vtkUnstructuredGrid* myGrid = r->GetOutput();//vtkUnstructuredGrid::New();
879 //   std::cout << "GetNumberOfCells =>"<< myGrid->GetNumberOfCells();
880 //   // Create and display actor
881 // 
882 //   vtkDataSetMapper* myMapper = vtkDataSetMapper::New();
883 //   myMapper->SetInput(myGrid);
884 // 
885 // //   if ( myPreviewActor ){
886 // //     myVTKViewWindow->RemoveActor(myPreviewActor);
887 // //     myPreviewActor->Delete();
888 // //   }
889 // 
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);
894 // 
895 // //   myPreviewActor->PickableOff();
896 //   myPreviewActor->SetVisibility( true );//VisibilityOff();
897 //   myPreviewActor->SetPickable( true );
898 //   myPreviewActor->SetMapper(myMapper);
899 // 
900 //   vtkProperty* aProp = vtkProperty::New();
901 // //   aProp->SetRepresentationToWireframe();
902 //   aProp->SetRepresentationToSurface();
903 //   aProp->EdgeVisibilityOn ();
904 // 
905 // //   aProp->SetColor(10, 10, 250); 
906 //   aProp->SetPointSize(5);
907 //   myPreviewActor->SetProperty(aProp);
908 //   aProp->Delete();
909 // 
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();
919 // 
920 //   myVTKViewWindow->SetSelectionMode( ActorSelection );
921 // // myVTKViewWindow->SetSelectionMode( NodeSelection );
922 // // myVTKViewWindow->SetSelectionMode( EdgeSelection );
923 // // myVTKViewWindow->SetSelectionMode( FaceSelection );
924 // }
925
926 // void DocumentGraphicView::rowsInserted ( const QModelIndex & parent, int start, int end )
927 // { 
928 // 
929 // //   std::cout << "DocumentGraphicView::rowsInserted  :  " << parent.data().toString().toStdString() << std::endl;
930 //   QModelIndex newRow;
931 // 
932 //   SVTK_ViewWindow* myViewWindow = dynamic_cast<SVTK_ViewWindow*>(_suitView);
933 //   SUIT_ViewManager* vman = myViewWindow->getViewManager();
934 //   SUIT_ViewModel* vmodel = vman->getViewModel();
935 // 
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));
941 //     UpdateViewer();
942 //         
943 // //     addObject(newRow);
944 //   }
945 // }