Salome HOME
5627b29316525df60f212eb408594ae94281665e
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentSelectionModel.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 #include <set>
21 #include <map>
22
23
24 #include "utilities.h"
25
26 #include <QtxWorkstack.h>
27 #include <STD_TabDesktop.h>
28 #include <STD_MDIDesktop.h>
29 #include <STD_SDIDesktop.h>
30
31 #include <SalomeApp_Tools.h>
32
33 #include "SOCC_ViewModel.h"
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewModel.h>
36 #include <OCCViewer_ViewWindow.h>
37
38 #include <SUIT_OverrideCursor.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_Selector.h>
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ViewManager.h>
44 #include <SVTK_View.h>
45
46
47 #include "HEXABLOCKGUI_SalomeTools.hxx"
48 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
49 #include "HEXABLOCKGUI_DocumentModel.hxx"
50 #include "HEXABLOCKGUI_DocumentGraphicView.hxx"
51 #include "HEXABLOCKGUI_DocumentItem.hxx"
52 #include "HEXABLOCKGUI.hxx"
53
54
55 #include <SVTK_Selector.h>
56 #include <SVTK_ViewModel.h>
57
58
59 #include <SalomeApp_Study.h>
60 #include <SalomeApp_Application.h>
61 #include <SALOME_Actor.h>
62 #include <SALOME_ListIO.hxx>
63 #include <SALOME_ListIteratorOfListIO.hxx>
64
65 #include <QMultiMap>
66
67 #include "GEOMBase.h"
68 #include "MyGEOMBase_Helper.hxx"
69
70 #include <OCCViewer_ViewModel.h>
71 #include <SVTK_ViewModel.h>
72 #include <SalomeApp_Study.h>
73 #include <SalomeApp_Application.h>
74 #include <LightApp_SelectionMgr.h>
75 #include <SALOME_ListIteratorOfListIO.hxx>
76 #include <TopExp.hxx>
77 #include <TopExp_Explorer.hxx>
78 #include <TopoDS_Iterator.hxx>
79 #include <TopTools_MapOfShape.hxx>
80 #include <TopTools_IndexedMapOfShape.hxx>
81 #include <TColStd_IndexedMapOfInteger.hxx>
82
83
84 //#define _DEVDEBUG_
85 using namespace std;
86 using namespace HEXABLOCK::GUI;
87
88
89
90 PatternDataSelectionModel::PatternDataSelectionModel( QAbstractItemModel * model ):
91 QItemSelectionModel( model ),
92 MyGEOMBase_Helper( SUIT_Session::session()->activeApplication()->desktop() ),
93 _theModelSelectionChanged(false),
94 _theVtkSelectionChanged(false),
95 _theGeomSelectionChanged(false),
96 salomeNothingSelected(true),
97 _selectionFilter(-1),
98 _salomeSelectionMgr(0)
99 {
100   connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
101            this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
102   connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
103            this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
104
105 }
106
107 PatternDataSelectionModel::~PatternDataSelectionModel()
108 {
109   disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
110           this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
111   disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
112           this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
113
114 //   if ( _salomeSelectionMgr )
115 //     disconnect( _salomeSelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( salomeSelectionChanged() ) );
116   disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( salomeSelectionChanged() ) );
117 }
118
119 void PatternDataSelectionModel::setVertexSelection()
120 {
121   MESSAGE("PatternDataSelectionModel::setVertexSelection(){");
122   SetSelectionMode(NodeSelection);
123 // //  NodeSelection,
124 // //  CellSelection,
125 // //  EdgeOfCellSelection,
126 // //  EdgeSelection,
127 // //  FaceSelection,
128 // //  VolumeSelection,
129 // //  ActorSelection };
130   _selectionFilter = VERTEX_TREE;
131   MESSAGE("}");
132 }
133
134 void PatternDataSelectionModel::setEdgeSelection()
135 {
136   MESSAGE("PatternDataSelectionModel::setEdgeSelection(){");
137   SetSelectionMode(EdgeSelection);
138   _selectionFilter = EDGE_TREE;
139   MESSAGE("}");
140 }
141
142 void PatternDataSelectionModel::setQuadSelection()
143 {
144   MESSAGE("PatternDataSelectionModel::setQuadSelection(){");
145   SetSelectionMode(FaceSelection);
146   _selectionFilter = QUAD_TREE;
147   MESSAGE("}");
148 }
149
150 void PatternDataSelectionModel::setHexaSelection()
151 {
152   MESSAGE("PatternDataSelectionModel::setHexaSelection(){");
153 //  SetSelectionMode(VolumeSelection);
154   SetSelectionMode(FaceSelection); //temporary for hexa selection debug
155   _selectionFilter = HEXA_TREE;
156   MESSAGE("}");
157 }
158
159
160 void PatternDataSelectionModel::setAllSelection()
161 {
162   MESSAGE("PatternDataSelectionModel::setAllSelection(){");
163   SetSelectionMode(ActorSelection);
164   _selectionFilter = -1;
165   MESSAGE("}");
166 }
167
168
169 QModelIndex PatternDataSelectionModel::indexBy( int role, const QString& value )
170 {
171   QModelIndex eltIndex; // element (vertex, edge, quad) of model
172   const QAbstractItemModel* theModel = model();
173   if ( !theModel ) return eltIndex;
174   QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
175                                           role,
176                                           value,
177                                           1,
178                                           Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
179   if ( theIndexes.count()>0 )
180     eltIndex = theIndexes[0] ;
181   return eltIndex;
182 }
183
184
185 QModelIndex PatternDataSelectionModel::indexBy( int role, const QVariant& var )
186 {
187   QModelIndex eltIndex; // element (vertex, edge, quad) of model
188   const QAbstractItemModel* theModel = model();
189   if ( !theModel ) return eltIndex;
190   QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
191                                           role,
192                                           var,
193                                           1,
194                                           Qt::MatchRecursive /*| Qt::MatchContains*/ );//Qt::MatchFixedString );
195   if ( theIndexes.count()>0 )
196     eltIndex = theIndexes[0] ;
197   return eltIndex;
198 }
199
200
201 void PatternDataSelectionModel::setSalomeSelectionMgr( LightApp_SelectionMgr* mgr )
202 {
203   _salomeSelectionMgr = mgr;
204   connect( _salomeSelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( salomeSelectionChanged() ) );
205 }
206
207
208 void  PatternDataSelectionModel::SetSelectionMode(Selection_Mode theMode)
209 {
210   MESSAGE("PatternDataSelectionModel::SetSelectionMode(){");
211 //  SVTK_ViewWindow* aVTKViewWindow = _getVTKViewWindow();
212 //   aViewWindow->clearFilters();
213 //   _salomeSelectionMgr->clearFilters();
214   if ( _getVTKViewWindow() != NULL )
215           _getVTKViewWindow()->SetSelectionMode( theMode );
216   MESSAGE("}");
217 }
218
219
220 //     A) De Salome(OCC, VTK) vers Hexablock(TreeView Data) :
221 //         -Vertex:
222 //             in:     selection (vertex associé OCC).
223 //             out:    (vertex VTK) highlighté, (vertex TreeView) sélectionné.
224 // 
225 //             in :    selection (vertex associé VTK).
226 //             out:    (vertex OCC) highlighté, (vertex TreeView) sélectionné.
227 // 
228 //         -Edge:
229 //             in:     selection (edge associé OCC).
230 //             out:    (vertex VTK) highlighté, (vertex TreeView) sélectionné.
231 // 
232 //             in:     selection (edge associé VTK).
233 //             out:    (toute la ligne OCC) highlighté + vertex sur (deb,fin) , (edge TreeView) sélectionné.
234 // 
235 //         -Face: idem vertex
236 void PatternDataSelectionModel::onCurrentChanged( const QModelIndex & current, const QModelIndex & previous )
237 {
238   MESSAGE("PatternDataSelectionModel::onCurrentChanged(){");
239   MESSAGE("*  current  : " << current.data().toString().toStdString());
240   MESSAGE("*  previous : " << previous.data().toString().toStdString());
241
242   //Setting the selection mode of the selected item from the treeview
243   _setVTKSelectionMode( current);
244
245 //   _selectSalome( current, true );
246 //   _selectSalome( previous, false );
247   MESSAGE("}");
248 }
249
250 void PatternDataSelectionModel::highlightEltsWithAssocs(const QModelIndexList& elts)
251 {
252         try {
253 //              if ( HEXABLOCKGUI::selectionMgr() != NULL) HEXABLOCKGUI::selectionMgr()->clearSelected();
254                 highlightVTKElts(elts);
255                 for( QModelIndexList::const_iterator i_index = elts.begin(); i_index != elts.end(); ++i_index ){
256                         //            _selectVTK( *i_index );
257                         _highlightGEOM( *i_index );
258                 }
259         } catch ( ... ) {
260                 MESSAGE("Unknown exception was cought !!!");
261         }
262 }
263
264 void PatternDataSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
265 {
266 //  MESSAGE("PatternDataSelectionModel::onSelectionChanged(){");
267 //  foreach( const QModelIndex& isel, selected.indexes() ){
268 //    MESSAGE("*  selected : " << isel.data().toString().toStdString());
269 //  }
270 //  foreach( const QModelIndex& iunsel, deselected.indexes() ){
271 //    MESSAGE("*  unselected : " << iunsel.data().toString().toStdString());
272 //  }
273
274 //  _theModelSelectionChanged = true;
275 //  try {
276 //    if ( _salomeSelectionMgr == NULL ) return;
277 ////     if ( !_theVtkSelectionChanged and  !_theGeomSelectionChanged ) return;
278 //
279 //    _salomeSelectionMgr->clearSelected();
280 //    //   erasePreview(true);
281 //    QModelIndexList indexes = selected.indexes();
282 //    for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index ){
283 //  //     std::cout << "entry selected" << i_index->data( HEXA_ENTRY_ROLE ).toString().toStdString() << std::endl;
284 //      if ( !_theVtkSelectionChanged )  _selectVTK( *i_index );
285 //      if ( !_theGeomSelectionChanged ) _highlightGEOM( *i_index );
286 //    }
287 //    // CS_BP todo SALOMEGUI_Swig.cxx:370
288 //    //   indexes = deselected.indexes();
289 //    //   for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index )
290 //    //     _unselectSalome( *i_index);
291 //  } catch ( ... ) {
292 //    MESSAGE("Unknown exception was cought !!!");
293 //  }
294 //  _theModelSelectionChanged = false;
295
296 //  MESSAGE("}");
297 }
298
299 void PatternDataSelectionModel::salomeSelectionChanged()
300 {
301   MESSAGE("PatternDataSelectionModel::salomeSelectionChanged(){");
302   try {
303     QModelIndex toSelect;
304
305     if ( _salomeSelectionMgr == NULL ) return;
306     SALOME_ListIO salomeSelected;
307   //   _salomeSelectionMgr->selectedObjects( salomeSelected, SVTK_Viewer::Type() );//salomeSelected.Extent()
308     _salomeSelectionMgr->selectedObjects( salomeSelected, NULL, false );
309     if ( salomeSelected.IsEmpty() ){
310       MESSAGE("*  salomeSelected.IsEmpty()");
311       salomeNothingSelected = true;
312       clearSelection();
313       return;
314     }
315
316     Handle(SALOME_InteractiveObject) anIObject;
317
318     SALOME_ListIteratorOfListIO it(salomeSelected);
319     for( ; it.More(); it.Next()){
320       anIObject = it.Value(); //anIObject->getName()
321       toSelect = _geomSelectionChanged( anIObject );// is it comming from GEOM?
322       if ( !toSelect.isValid() ){
323         toSelect = _vtkSelectionChanged( anIObject ); ;// or VTK?...
324         if ( toSelect.isValid() )
325           MESSAGE("*  OK : selection from VTK");
326       } else {
327         MESSAGE("*  OK : selection from GEOM");
328       }
329     }
330     salomeNothingSelected = false;
331   } catch ( ... ) {
332     MESSAGE("*  Unknown exception was cought !!!");
333   }
334   MESSAGE("}");
335 }
336
337 QModelIndex PatternDataSelectionModel::_geomSelectionChanged( const Handle(SALOME_InteractiveObject)& anIObject )
338 {
339   MESSAGE("PatternDataSelectionModel::_geomSelectionChanged(){");
340   QModelIndexList assocsIndexes;// elements of the model which is associated to the geom object and that is to be selected
341   QModelIndex assocIndex;
342
343   if (HEXABLOCKGUI::assocInProgress) return assocIndex;
344   bool fromGEOM = ( strcmp("GEOM", anIObject->getComponentDataType()) == 0 );
345   if ( !fromGEOM ) return assocIndex;
346   if (!_salomeSelectionMgr) return assocIndex;
347
348   QString aName;
349   GEOM::GEOM_Object_var aGeomObj = GEOMBase::ConvertIOinGEOMObject( anIObject );
350
351   int anIndex = -1;
352   if ( GEOMBase::IsShape(aGeomObj) ){
353     aName = GEOMBase::GetName(aGeomObj);
354     TColStd_IndexedMapOfInteger anIndexes;
355     _salomeSelectionMgr->GetIndexes(anIObject, anIndexes);
356     if ( anIndexes.Extent() == 1 )
357       anIndex = anIndexes(1);
358       QString aGeomObjStudyEntry = aGeomObj->GetStudyEntry();
359       QString aGeomObjModelEntry = aGeomObjStudyEntry + "," + QString::number(anIndex) + ";";
360       assocsIndexes = _indexListOf( aGeomObjModelEntry, HEXA_ASSOC_ENTRY_ROLE );
361       if ( !_theModelSelectionChanged && assocsIndexes.count()>0 && assocsIndexes[0].isValid() ){ // select in model
362           _theGeomSelectionChanged = true;
363           setCurrentIndex( assocsIndexes[0], QItemSelectionModel::Clear );  //CS_TEST
364           setCurrentIndex( assocsIndexes[0], QItemSelectionModel::SelectCurrent );
365           _theGeomSelectionChanged = false;
366       } else {
367         clearSelection();
368       }
369     }
370
371   MESSAGE("}");
372
373   if (assocsIndexes.count() > 0)
374   {
375 //        HEXABLOCKGUI::currentVtkView->setFocus();
376           highlightVTKElts(assocsIndexes);
377           return assocsIndexes[0];
378   }
379   return assocIndex;
380 }
381
382 QModelIndex PatternDataSelectionModel::_vtkSelectionChanged( const Handle(SALOME_InteractiveObject)& anIObject )
383 {
384   MESSAGE("PatternDataSelectionModel::_vtkSelectionChanged(){");
385   QModelIndex anIOIndex;// // the element of the model which is associated to the Interactive object and that is to be selected
386
387   bool fromVTK  = ( strcmp("HEXABLOCK", anIObject->getComponentDataType()) == 0 );
388   if ( !fromVTK ) return anIOIndex;
389
390   SVTK_ViewWindow* currentVTKViewWindow = _getVTKViewWindow();
391   if ( !currentVTKViewWindow )  return anIOIndex;
392   if ( !anIObject->hasEntry() ) return anIOIndex;
393
394   QString anIOEntry = anIObject->getEntry();
395   Document_Actor *anDocActor = NULL;
396   int anhexaElemsId;
397
398   QString aText = "";
399   if ( GetNameOfSelectedElements( currentVTKViewWindow, anIObject, aText ) <= 0 ) return anIOIndex;
400   anDocActor = dynamic_cast<Document_Actor*>( findActorByEntry( currentVTKViewWindow, anIOEntry.toLatin1() ) );
401   if ( !anDocActor ) return anIOIndex;
402   anhexaElemsId = anDocActor->hexaElemsId[ aText.toInt() ];
403   anIOEntry = QString::number( anhexaElemsId );
404   anIOIndex = _indexOf( anIOEntry, HEXA_ENTRY_ROLE );
405
406   if ( !_theModelSelectionChanged && anIOIndex.isValid() ){ // select in model
407     _theVtkSelectionChanged = true;
408
409     //Temporary Debug for hexa selection -----------------------------------------------------------------
410     if (getSelectionFilter() == HEXA_TREE)
411     {
412         DocumentModel               *docModel = NULL;
413         const QSortFilterProxyModel *pModel   = dynamic_cast<const QSortFilterProxyModel *>( model() );
414
415         if ( pModel != NULL){
416                 docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() );
417                 if ( docModel != NULL && anIOIndex.isValid())
418                 {
419                         //get the selected quad
420                         HEXA_NS::Quad* quad = docModel->getHexaPtr<HEXA_NS::Quad*>(anIOIndex);
421                         if (quad != NULL)
422                         {
423                                 //get the hexa the quad belongs to
424                                 HEXA_NS::Hexa* hexa = docModel->getQuadHexa(quad);
425                                 if (hexa != NULL) //convert the hexa to a QModelIndex so we can select it in the model
426                                         anIOIndex = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(hexa));
427                                 else
428                                 {
429                                         SUIT_MessageBox::critical( 0,
430                                                                         tr("HexaBlock"),
431                                                                         tr("The Hexahedron This quad belongs to has been deleted!"));
432                                         return anIOIndex;
433                                 }
434                         }
435                 }
436         }
437     }//end if HEXA_TREE------------------------------------------------------------------------------------
438
439     setCurrentIndex( anIOIndex, QItemSelectionModel::Clear );
440     setCurrentIndex( anIOIndex, QItemSelectionModel::SelectCurrent );
441     _theVtkSelectionChanged = false;
442   } else {
443     clearSelection();
444   }
445
446 //  if (anIOIndex.isValid())
447 //        _selectVTK(anIOIndex);
448
449 //  if (anIOIndex.isValid())
450 //  {
451 //        QModelIndexList l;
452 //        l << anIOIndex;
453 //        highlightVTKElts(l);
454 //        _highlightGEOM(anIOIndex); // JMD test Ã  faire
455 //  }
456   MESSAGE("}");
457   return anIOIndex;
458 }
459
460
461 SVTK_ViewWindow* PatternDataSelectionModel::_getVTKViewWindow()
462 {
463 //  SVTK_ViewWindow* aVtkView = HEXABLOCKGUI::currentVtkView;
464   return HEXABLOCKGUI::currentVtkView;
465 }
466
467
468 OCCViewer_ViewWindow*  PatternDataSelectionModel::_getOCCViewWindow()
469 {
470 //  OCCViewer_ViewWindow* aOccView = HEXABLOCKGUI::currentOccView;
471 //  MESSAGE(" dans OCCViewer" << aOccView);
472   return HEXABLOCKGUI::currentOccView;
473 }
474
475
476 QModelIndex PatternDataSelectionModel::_indexOf( const QString& anEntry, int role )
477 {
478   QModelIndex eltIndex; // element (vertex, edge, quad) of model
479   const QAbstractItemModel* theModel = model();
480   if ( !theModel ) return eltIndex;
481   QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
482                                           role,
483                                           anEntry,
484                                           1,
485                                           Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
486   if ( theIndexes.count()>0 )
487     eltIndex = theIndexes[0] ;
488   return eltIndex;
489 }
490
491
492 QModelIndexList PatternDataSelectionModel::_indexListOf( const QString& anEntry, int role )
493 {
494   QModelIndexList theIndexes; // element (vertex, edge, quad) of model
495   const QAbstractItemModel* theModel = model();
496   if ( !theModel ) return theIndexes;
497   theIndexes = theModel->match( theModel->index(0, 0),
498                                           role,
499                                           anEntry,
500                                           -1,
501                                           Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
502   return theIndexes;
503 }
504
505
506 void PatternDataSelectionModel::_setVTKSelectionMode( const QModelIndex& eltIndex )
507 {
508   MESSAGE("PatternDataSelectionModel::_setVTKSelectionMode( "<< eltIndex.data().toString().toStdString() << " )");
509   QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
510   if ( !treeVariant.isValid() ) return;
511   int eltType = treeVariant.toInt();
512
513 //  if ( (_selectionFilter != -1) and ( _selectionFilter != eltType ) ) return;
514   if ( _selectionFilter == eltType ) return;
515
516   switch ( eltType ){
517     case VERTEX_TREE :
518     case VERTEX_DIR_TREE : setVertexSelection(); MESSAGE("VERTEX"); break;
519     case EDGE_TREE :
520     case EDGE_DIR_TREE :   setEdgeSelection(); MESSAGE("EDGE");     break;
521     case QUAD_TREE :
522     case QUAD_DIR_TREE :   setQuadSelection(); MESSAGE("QUAD");     break;
523     case HEXA_TREE :
524     case HEXA_DIR_TREE :   setHexaSelection();  MESSAGE("HEXA");   break;
525     case PROPAGATION_TREE :
526     case PROPAGATION_DIR_TREE :   setEdgeSelection(); MESSAGE("PROPAGATION");   break;
527 //  CellSelection,
528 //  EdgeOfCellSelection,
529 //  VolumeSelection,
530 //  ActorSelection
531   }
532 }
533
534
535 void PatternDataSelectionModel::highlightVTKElts( const QModelIndexList& elts )
536 {
537         if (!elts.size()) return;
538
539         SVTK_ViewWindow* currentVTKViewWindow = _getVTKViewWindow();
540         if ( currentVTKViewWindow == NULL ) return;
541         SVTK_Selector* selector = currentVTKViewWindow->GetSelector();
542         if ( selector == NULL ) return;
543
544         // document selection
545         Document_Actor* docActor = NULL;
546         Handle(SALOME_InteractiveObject) docIO;
547 //      Handle(SALOME_InteractiveObject) docIO2; //JMD
548
549         // element highlight
550         TColStd_MapOfInteger aMap;
551 //      TColStd_MapOfInteger aMap2;
552         QList<int>::const_iterator anIter;
553         int vtkElemsId;
554
555         // data from model
556         QString docEntry;
557         QVariant docEntryVariant    = elts[0].data( HEXA_DOC_ENTRY_ROLE );
558
559         if ( !docEntryVariant.isValid() ){
560                 //INFOS("data from model not valid");
561                 return;
562         }
563
564         docEntry = docEntryVariant.toString();
565
566         // Select the document in Salome
567         docActor = dynamic_cast<Document_Actor*>( findActorByEntry( currentVTKViewWindow, docEntry.toLatin1() ) );
568         if ( docActor == NULL) return;
569
570
571         //   // Set selection mode in VTK view
572 //      currentVTKViewWindow->SetSelectionMode(VolumeSelection);
573         docIO = docActor->getIO();
574
575
576
577 //      QString autreDocentry  = "toti";
578 //      Associate_Actor* associateActor = dynamic_cast<Associate_Actor*>( findActorByEntry( currentVTKViewWindow, autreDocentry.toLatin1() ) );
579 //      docIO2 = associateActor->getIO();
580
581         // Highlight in vtk view the element from document
582         //bool rr = true;
583
584         QString eltEntry;
585         foreach( const QModelIndex& iElt, elts ){
586                 eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
587                 vtkElemsId = docActor->vtkElemsId[ eltEntry.toInt() ];
588                 if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
589 //              if (rr) {
590 //                if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
591 //              }
592 //              else
593 //              {
594 //                if ( vtkElemsId > 0 ) aMap2.Add( vtkElemsId );
595 //              }
596 //              rr = ! rr;
597         }
598
599         selector->AddOrRemoveIndex( docIO, aMap, false ); //true
600 //      selector->RemoveIObject(docActor);
601         currentVTKViewWindow->highlight( docIO, true, true );
602 //      Document_Actor* docActor = NULL;
603 //              QVariant docEntryVariant    = selected.data( HEXA_DOC_ENTRY_ROLE );
604 //              if ( docEntryVariant.isValid() ){
605 //                      QString docEntry = docEntryVariant.toString();
606 //                      docActor = dynamic_cast<Document_Actor*>( findActorByEntry( HEXABLOCKGUI::currentVtkView, docEntry.toLatin1() ) );
607 //                      if ( docActor != NULL) HEXABLOCKGUI::currentVtkView->getView()->highlight( docActor->getIO(), false,  false );
608 //              }
609 //      currentVTKViewWindow->getView()->SetColor(docIO, QColor("blue"));
610
611
612 //      selector->AddOrRemoveIndex( docIO2, aMap2, false );
613 //      currentVTKViewWindow->highlight( docIO2, true, true );
614 }
615
616 //SUIT_ViewManager* PatternDataSelectionModel::initOccViewManager()
617 //{
618 //  SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
619 //  SUIT_ViewManager* occVm = anApp->getViewManager( OCCViewer_Viewer::Type(), true );
620 //  SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>(svw);
621 //  return viewWindow;
622 //}
623 SUIT_ViewWindow* PatternDataSelectionModel::initOccViewManager()
624 {
625  SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
626  SUIT_ViewManager* occVm = anApp->getViewManager( OCCViewer_Viewer::Type(), true );
627
628  QVector<SUIT_ViewWindow*> viewS = occVm->getViews ();
629
630  int nb = viewS.count();
631
632  MESSAGE("????HexaBaseDialog::initOccView number of : " << nb);
633
634  if (nb == 1)
635  {
636    MESSAGE(" OK     ????HexaBaseDialog::initOccView number of : " << nb);
637    return viewS.first();
638  }
639
640  return NULL;
641 }
642
643 // 1 vertex -> 1 point
644 // 1 edge   -> n lines + points(deb,fin)
645 // 1 quad   -> n faces
646 void PatternDataSelectionModel::_highlightGEOM( const QMultiMap<QString, int>&  entrySubIDs )
647 {
648   MESSAGE("PatternDataSelectionModel::_highlightGEOM( const QMultiMap<QString, int>&  entrySubIDs ){");
649   MESSAGE("debut    entry => "<< entrySubIDs.count());
650
651   OCCViewer_ViewWindow*  occView = _getOCCViewWindow();
652   if ( occView == NULL ) {
653 //      occView =  (OCCViewer_ViewWindow*)initOccViewManager();
654 //      if ( occView == NULL )
655           return;
656   }
657   MESSAGE("step 1    occView=> " << occView);
658
659   MESSAGE("step 1    entry => ");
660   SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>( occView->getViewManager()->getViewModel() );
661   if (!soccViewer) return;
662   MESSAGE("step 2    entry => ");
663   _PTR(Study) aStudy = GetActiveStudyDocument();
664   if (!aStudy) return;
665   MESSAGE("step 3    entry => ");
666
667   CORBA::Object_var     aCorbaObj = CORBA::Object::_nil();
668   GEOM::GEOM_Object_var aGeomObj  = GEOM::GEOM_Object::_nil();
669   erasePreview(true);
670   MESSAGE("Avant    entry => "<< entrySubIDs.count());
671   foreach ( QString entry, entrySubIDs.keys() ){
672     _PTR(SObject) aSChild = aStudy->FindObjectID( entry.toStdString() );
673     MESSAGE("*    entry => "<< entry.toStdString());
674     aCorbaObj = corbaObj( aSChild );
675     aGeomObj = GEOM::GEOM_Object::_narrow( aCorbaObj );
676     if ( !CORBA::is_nil(aGeomObj) ){
677       MESSAGE("*  !CORBA::is_nil(aGeomObj)");
678       QString objIOR = GEOMBase::GetIORFromObject( aGeomObj._retn() );
679       Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR );//, true );
680       if ( !aSh.IsNull() ){
681         MESSAGE("*  !aSh.IsNull() ");
682         TColStd_IndexedMapOfInteger anIndexes;
683         foreach ( int subid, entrySubIDs.values(entry) ){
684           if ( subid != -1 )
685             anIndexes.Add( subid );
686         }
687         if ( anIndexes.Extent() > 0 ){ // if it's a sub-shape
688           MESSAGE("*  a sub-shape");
689           aSh->highlightSubShapes( anIndexes, true );
690           soccViewer->Repaint();
691         } else {  // or a main shape
692 //             std::cout << "aSh->getIO() => " << aSh->getIO() << std::endl;
693 //           getDisplayer()->SetDisplayMode(0);
694 //           soccViewer->setColor( aSh->getIO(), QColor( Qt::red ), true );
695 //           soccViewer->switchRepresentation( aSh->getIO(), 2 );
696           MESSAGE("*  a main shape");
697 //           globalSelection();
698           soccViewer->highlight( aSh->getIO(), true, true );
699         }
700       }
701     }
702   }
703
704   MESSAGE("}");
705 }
706
707
708 void PatternDataSelectionModel::_highlightGEOM( const QModelIndex & anEltIndex )
709 {
710   MESSAGE("PatternDataSelectionModel::_highlightGEOM(" << anEltIndex.data().toString().toStdString() << ")");
711   // getting association(s) from model
712   QList<DocumentModel::GeomObj> assocs;
713   QMultiMap< QString, int >     assocEntrySubIDs;
714   DocumentModel               *docModel = NULL;
715   const QSortFilterProxyModel *pModel   = dynamic_cast<const QSortFilterProxyModel *>( model() );
716
717   if ( !pModel ) return;
718   docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() );
719   if ( !docModel ) return;
720   assocs = docModel->getAssociations( pModel->mapToSource(anEltIndex) );
721   foreach( const DocumentModel::GeomObj& anAssoc, assocs )
722   {
723 //        MESSAGE("              dedans " << anAssoc.entry.toStdString());
724 //        MESSAGE("                   + " << anAssoc.subid.toInt());
725           assocEntrySubIDs.insert( anAssoc.entry, anAssoc.subid.toInt() );
726
727   }
728   _highlightGEOM( assocEntrySubIDs );
729   MESSAGE("}");
730 }
731
732
733 void PatternDataSelectionModel::_selectVTK( const QModelIndex& eltIndex )
734 {
735   MESSAGE("PatternDataSelectionModel::_selectVTK( "<< eltIndex.data().toString().toStdString() << ")");
736   SVTK_ViewWindow* currentVTKViewWindow = _getVTKViewWindow();
737   if ( currentVTKViewWindow == NULL ) return;
738   SVTK_Selector* selector = currentVTKViewWindow->GetSelector();
739   if ( selector == NULL ) return;
740
741   // document selection
742   Document_Actor* docActor = NULL;
743   Handle(SALOME_InteractiveObject) docIO;
744   SALOME_ListIO aList;
745
746   // element highlight
747   TColStd_MapOfInteger aMap;
748   QList<int>::const_iterator anIter;
749   int vtkElemsId;
750
751   // data from model
752   QString eltEntry;
753   QString docEntry;
754   QVariant entryVariant    = eltIndex.data( HEXA_ENTRY_ROLE );
755   QVariant docEntryVariant = eltIndex.data( HEXA_DOC_ENTRY_ROLE );
756
757   if ( !entryVariant.isValid() ){
758     //INFOS("entryVariant not valid");
759     return;
760   }
761   if ( !docEntryVariant.isValid() ){
762     //INFOS("docEntryVariant not valid");
763     return;
764   }
765
766   eltEntry = entryVariant.toString();
767   docEntry = docEntryVariant.toString();
768
769   // Select the document in Salome
770   docActor = dynamic_cast<Document_Actor*>( findActorByEntry( currentVTKViewWindow, docEntry.toLatin1() ) );
771   if ( docActor == NULL ) return;
772
773   // Set selection mode in VTK view
774   //_setVTKSelectionMode( eltIndex, currentVTKViewWindow );
775
776 // if ( _salomeSelectionMgr == NULL ) return;
777 //   _salomeSelectionMgr->selectedObjects( aList );
778 //   std::cout<<"aList.Extent() => " << aList.Extent() << std::endl;
779 //   aList.Append(docIO);
780 //   _salomeSelectionMgr->setSelectedObjects( aList, true );//false );//true ); //CS_BP false?
781   docIO = docActor->getIO();
782
783   // Highlight in vtk view the element from document
784   vtkElemsId = docActor->vtkElemsId[ eltEntry.toInt() ];// get vtk ids from actor
785   if ( vtkElemsId > 0 ) // CS_BP ?: erreur si 1er elt == vertex (0,0,0)
786     aMap.Add( vtkElemsId );
787 //     for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
788 //       aMap.Add(*anIter);
789 //     }
790   selector->AddOrRemoveIndex( docIO, aMap, false );
791   currentVTKViewWindow->highlight( docIO, true, true );
792
793   MESSAGE("}");
794 }
795
796 GroupsSelectionModel::GroupsSelectionModel( QAbstractItemModel * model ):
797 QItemSelectionModel( model )
798 {
799   connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
800            this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
801   connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
802            this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
803 }
804
805 GroupsSelectionModel::~GroupsSelectionModel()
806 {
807   disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
808           this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
809   disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
810           this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
811 }
812
813
814
815
816 QModelIndex GroupsSelectionModel::indexBy( int role, const QVariant& var )
817 {
818   QModelIndex eltIndex; // element (vertex, edge, quad) of model
819   const QAbstractItemModel* theModel = model();
820   if ( !theModel ) return eltIndex;
821   QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
822                                           role,
823                                           var,
824                                           1,
825                                           Qt::MatchRecursive /*| Qt::MatchContains*/ );//Qt::MatchFixedString );
826   if ( theIndexes.count()>0 )
827     eltIndex = theIndexes[0] ;
828   return eltIndex;
829 }
830
831
832 SVTK_ViewWindow* GroupsSelectionModel::_getVTKViewWindow()
833 {
834 //  SVTK_ViewWindow* aVtkView = HEXABLOCKGUI::currentVtkView;
835   return HEXABLOCKGUI::currentVtkView;
836 }
837
838
839 void GroupsSelectionModel::_highlightGroups( const QModelIndex& eltIndex )
840 {
841   const GroupsModel* m = dynamic_cast<const GroupsModel *>( model() );
842
843 // ---- VTK ----
844   if ( m == NULL ) return;
845   SVTK_ViewWindow* currentVTKViewWindow = _getVTKViewWindow();
846   if ( currentVTKViewWindow == NULL ) return;
847   SVTK_Selector* selector = currentVTKViewWindow->GetSelector();
848   if ( selector == NULL ) return;
849
850 // ----  vtkActor
851   // document selection
852   Document_Actor* docActor = NULL;
853   Handle(SALOME_InteractiveObject) docIO;
854   SALOME_ListIO aList;
855
856   // element highlight
857   TColStd_MapOfInteger aMap;
858   QList<int>::const_iterator anIter;
859   int vtkElemsId;
860
861
862
863   // debut ** data from model
864   int     eltType;
865   QString docEntry;
866
867   QVariant treeVariant        = eltIndex.data( HEXA_TREE_ROLE );
868   QVariant docEntryVariant    = eltIndex.data( HEXA_DOC_ENTRY_ROLE );
869
870   if ( !treeVariant.isValid() || !docEntryVariant.isValid() ){
871     //INFOS("data from model not valid");
872     return;
873   }
874
875   eltType  = treeVariant.toInt();
876   docEntry = docEntryVariant.toString();
877
878   if ( eltType != GROUP_TREE ){
879     //INFOS("bad element type : not a group item" << eltType );
880     return;
881   }
882   // fin ** data from model
883
884   // Select the document in Salome
885   docActor = dynamic_cast<Document_Actor*>( findActorByEntry( currentVTKViewWindow, docEntry.toLatin1() ) );
886   if ( docActor == NULL) return;
887   docIO = docActor->getIO();
888
889   // Highlight in vtk view the element from document
890   DocumentModel::Group kind;
891   QModelIndexList iElements = m->getGroupElements( eltIndex, kind );
892
893   // Set selection mode in VTK view
894   switch (kind){
895   case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: currentVTKViewWindow->SetSelectionMode(VolumeSelection); break;
896   case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: currentVTKViewWindow->SetSelectionMode(FaceSelection);   break;
897   case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: currentVTKViewWindow->SetSelectionMode(EdgeSelection);   break;
898   case HEXA_NS::VertexNode: currentVTKViewWindow->SetSelectionMode(NodeSelection); break;
899   }
900
901   QString eltEntry;
902   foreach( const QModelIndex& iElt, iElements ){
903     eltEntry = iElt.data( HEXA_ENTRY_ROLE ).toString();
904     vtkElemsId = docActor->vtkElemsId[ eltEntry.toInt() ];
905     if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
906   }
907
908   selector->AddOrRemoveIndex( docIO, aMap, false );
909   currentVTKViewWindow->highlight( docIO, true, true );
910
911 }
912
913 void GroupsSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
914 {
915   MESSAGE("GroupsSelectionModel::onSelectionChanged");
916   try {
917     //     if ( _salomeSelectionMgr == NULL ) return;
918     //     _salomeSelectionMgr->clearSelected();
919     //   erasePreview(true);
920     QModelIndexList indexes = selected.indexes();
921     for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index ){
922       MESSAGE( "entry selected" << i_index->data( HEXA_ENTRY_ROLE ).toString().toStdString() );
923       _highlightGroups( *i_index );
924     }
925
926     // CS_BP todo SALOMEGUI_Swig.cxx:370
927     //   indexes = deselected.indexes();
928     //   for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index )
929     //     _unselectSalome( *i_index);
930   } catch ( ... ) {
931     MESSAGE("Unknown exception was cought !!!");
932   }
933
934 }
935
936 MeshSelectionModel::MeshSelectionModel( QAbstractItemModel * model ):
937 QItemSelectionModel( model )
938 {
939   connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
940            this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
941   connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
942            this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
943 }
944
945
946 MeshSelectionModel::~MeshSelectionModel()
947 {
948   disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
949           this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
950   disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
951           this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
952 }
953
954
955 QModelIndex MeshSelectionModel::indexBy( int role, const QVariant& var )
956 {
957   QModelIndex eltIndex; // element (vertex, edge, quad) of model
958   const QAbstractItemModel* theModel = model();
959   if ( !theModel ) return eltIndex;
960   QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
961                                           role,
962                                           var,
963                                           1,
964                                           Qt::MatchRecursive /*| Qt::MatchContains*/ );//Qt::MatchFixedString );
965   if ( theIndexes.count()>0 )
966     eltIndex = theIndexes[0] ;
967   return eltIndex;
968 }
969
970
971
972 SVTK_ViewWindow* MeshSelectionModel::_getVTKViewWindow()
973 {
974 //  SVTK_ViewWindow* aVtkView = HEXABLOCKGUI::currentVtkView;
975   return HEXABLOCKGUI::currentVtkView;
976 }
977
978
979 void MeshSelectionModel::_highlightPropagation( const QModelIndex& eltIndex )
980 {
981   const MeshModel* m = dynamic_cast<const MeshModel *>( model() );
982   if ( m == NULL ) return;
983   SVTK_ViewWindow* currentVTKViewWindow = _getVTKViewWindow();
984   if ( currentVTKViewWindow == NULL ) return;
985   SVTK_Selector* selector = currentVTKViewWindow->GetSelector();
986   if ( selector == NULL ) return;
987
988   // document selection
989   Document_Actor* docActor = NULL;
990   Handle(SALOME_InteractiveObject) docIO;
991   SALOME_ListIO aList;
992
993   // element highlight
994   TColStd_MapOfInteger aMap;
995   QList<int>::const_iterator anIter;
996   int vtkElemsId;
997
998   // data from model
999   int     eltType;
1000   QString docEntry;
1001
1002   QVariant treeVariant        = eltIndex.data( HEXA_TREE_ROLE );
1003   QVariant docEntryVariant    = eltIndex.data( HEXA_DOC_ENTRY_ROLE );
1004
1005   if ( !treeVariant.isValid() || !docEntryVariant.isValid() ){
1006     //INFOS("data from model not valid");
1007     return;
1008   }
1009
1010   eltType  = treeVariant.toInt();
1011   docEntry = docEntryVariant.toString();
1012
1013   if ( eltType != PROPAGATION_TREE ){
1014     //INFOS("bad element type : not a propagation item" << eltType );
1015     return;
1016   }
1017
1018   // Select the document in Salome
1019   docActor = dynamic_cast<Document_Actor*>( findActorByEntry( currentVTKViewWindow, docEntry.toLatin1() ) );
1020   if ( docActor == NULL) return;
1021
1022 //   // Set selection mode in VTK view
1023   currentVTKViewWindow->SetSelectionMode(EdgeSelection);
1024   docIO = docActor->getIO();
1025
1026   // Highlight in vtk view the element from document
1027   QModelIndexList iEdges = m->getPropagation( eltIndex );
1028
1029   QString edgeEntry;
1030   foreach( const QModelIndex& iEdge, iEdges ){
1031     edgeEntry = iEdge.data( HEXA_ENTRY_ROLE ).toString();
1032     vtkElemsId = docActor->vtkElemsId[ edgeEntry.toInt() ];
1033     if ( vtkElemsId > 0 ) aMap.Add( vtkElemsId );
1034   }
1035
1036   selector->AddOrRemoveIndex( docIO, aMap, false );
1037   currentVTKViewWindow->highlight( docIO, true, true );
1038 }
1039
1040
1041
1042 void MeshSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
1043 {
1044   MESSAGE("MeshSelectionModel::onSelectionChanged");
1045   try {
1046     //     if ( _salomeSelectionMgr == NULL ) return;
1047     //     _salomeSelectionMgr->clearSelected();
1048     //   erasePreview(true);
1049     QModelIndexList indexes = selected.indexes();
1050     for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index ){
1051       MESSAGE( "entry selected" << i_index->data( HEXA_ENTRY_ROLE ).toString().toStdString() );
1052       _highlightPropagation( *i_index );
1053     }
1054
1055     // CS_BP todo SALOMEGUI_Swig.cxx:370
1056     //   indexes = deselected.indexes();
1057     //   for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index )
1058     //     _unselectSalome( *i_index);
1059   } catch ( ... ) {
1060     MESSAGE("Unknown exception was cought !!!");
1061   }
1062
1063 }
1064
1065
1066 // //=================================================================================
1067 // // function : activateSelection
1068 // // purpose  : Activate selection in accordance with myEditCurrentArgument
1069 // //=================================================================================
1070 // void PatternDataSelectionModel::activateSelection()
1071 // {
1072 //   erasePreview(false);
1073 // 
1074 //   // local selection
1075 //   if (!myObject->_is_nil() && !isAllSubShapes())
1076 //   {
1077 //     GEOM_Displayer* aDisplayer = getDisplayer();
1078 //     SALOME_View* view = GEOM_Displayer::GetActiveView();
1079 //     if (view) {
1080 //       CORBA::String_var aMainEntry = myObject->GetStudyEntry();
1081 //       Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
1082 //       if (view->isVisible(io)) {
1083 //         aDisplayer->Erase(myObject, false, false);
1084 //         myIsHiddenMain = true;
1085 //       }
1086 //     }
1087 // 
1088 //     int prevDisplayMode = aDisplayer->SetDisplayMode(0);
1089 // 
1090 //     SUIT_ViewWindow* aViewWindow = 0;
1091 //     SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
1092 //     if (activeStudy)
1093 //       aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1094 //     if (aViewWindow == 0) return;
1095 // 
1096 //     SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1097 //     if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1098 //         aViewManager->getType() != SVTK_Viewer::Type())
1099 //       return;
1100 // 
1101 //     SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1102 //     SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1103 //     if (aView == 0) return;
1104 // 
1105 //     //TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
1106 // 
1107 //     TopTools_IndexedMapOfShape aSubShapesMap;
1108 //     TopExp::MapShapes(myShape, aSubShapesMap);
1109 //     CORBA::String_var aMainEntry = myObject->GetStudyEntry();
1110 //     QString anEntryBase = aMainEntry.in();
1111 // 
1112 //     TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
1113 //     for (; anExp.More(); anExp.Next())
1114 //     {
1115 //       TopoDS_Shape aSubShape = anExp.Current();
1116 //       int index = aSubShapesMap.FindIndex(aSubShape);
1117 //       QString anEntry = anEntryBase + QString("_%1").arg(index);
1118 // 
1119 //       SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1120 //       if (aPrs) {
1121 //         displayPreview(aPrs, true, false); // append, do not update
1122 //       }
1123 //     }
1124 //     aDisplayer->UpdateViewer();
1125 //     aDisplayer->SetDisplayMode(prevDisplayMode);
1126 //   }
1127 // 
1128 //   globalSelection(GEOM_ALLSHAPES);
1129 // }
1130
1131
1132
1133
1134 // SUIT_DataOwnerPtrList aList;
1135 //   ObjectList::iterator anIter;
1136 //   for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1137 //   {
1138 //     QString anEntry = getEntry( *anIter );
1139 //     LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1140 //     aList.append( anOwher );
1141 //   }
1142 // 
1143 //   SUIT_Session* session = SUIT_Session::session();
1144 //   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1145 //   if ( !app )
1146 //     return false;
1147 // 
1148 //   LightApp_SelectionMgr* aMgr = app->selectionMgr();
1149 //   if ( !aMgr )
1150 //     return false;
1151 // _getVTKViewWindow()
1152 //   aMgr->setSelecte_getVTKViewWindow()d( aList, false );
1153
1154
1155
1156
1157
1158 //   SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
1159 //   if (!anActor || !anActor->hasIO())
1160 //     return;
1161 // 
1162 //   Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1163 //   //mySelectionMgr->clearSelected();
1164 //   //mySelectionMgr->AddIObject(anIO, false);
1165 //   SALOME_ListIO aList;
1166 //   aList.Append(anIO);
1167 //   mySelectionMgr->setSelectedObjects(aList, false);
1168 // 
1169 //   // Remove filter corresponding to the current type from viewer
1170 //   int aType = myTable->GetType();
1171 //   int aFilterId = SMESH::UnknownFilter;
1172 //   if      (aType == SMESH::EDGE  ) aFilterId = SMESH::EdgeFilter;
1173 //   else if (aType == SMESH::FACE  ) aFilterId = SMESH::FaceFilter;
1174 //   else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
1175 //   Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
1176 //   SMESH::RemoveFilter(aFilterId);
1177 // 
1178 //   // get vtk ids
1179 //   TColStd_MapOfInteger aMap;
1180 //   QList<int>::const_iterator anIter;
1181 //   for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
1182 //     aMap.Add(*anIter);
1183 //   }
1184 // 
1185 //   // Set new selection
1186 //   activeViewWindow->AddOrRemoveIndex(anIO, aMap, false);
1187 //   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1188 //     aViewWindow->highlight( anIO, true, true );
1189 // 
1190 //   // insert previously stored filter in viewer if necessary
1191 //   if (!aFilter.IsNull())
1192 //     SMESH::SetFilter(aFilter);
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202 //     //CS_TEST
1203 //  if(SVTK_Selector* aSelector = aView->GetSelector()){
1204 //             const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
1205 //             SALOME_ListIteratorOfListIO anIter(aListIO);
1206 //             for(; anIter.More(); anIter.Next()){
1207 //               Handle(SALOME_InteractiveObject) anIO = anIter.Value();
1208 //     _PTR(Study) aStudy  = HEXABLOCKGUI::activeStudy()->studyDS();
1209 //     _PTR(SObject) aSObj = aStudy->FindObjectID( anEntry.toStdString().c_str() );
1210 //     LightApp_DataObject*      o = HEXABLOCKGUI::activeStudy()->findObjectByEntry(anEntry.toStdString().c_str());
1211 //     //CS_TEST
1212
1213
1214
1215
1216
1217 // void PatternDataSelectionModel::test()
1218 // {
1219 //   if (myBusy) return;
1220 //   myMeshActor = 0;
1221 // 
1222 //   SALOME_ListIO aList;
1223 //   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
1224 // 
1225 //   if (aList.Extent() == 1) {
1226 //     Handle(SALOME_InteractiveObject) anIO = aList.First();
1227 //     myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
1228 //     if(myMeshActor){
1229 //       QString aText;
1230 //       if (SMESH::GetNameOfSelectedNodes(activeViewWindow,anIO,aText) == 1) {
1231 //         if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
1232 //           if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
1233 //             myBusy = true;
1234 //             myId->setText(aText);
1235 //             myX->SetValue(aNode->X());
1236 //             myY->SetValue(aNode->Y());
1237 //             myZ->SetValue(aNode->Z());
1238 //             myBusy = false;
1239 //             erasePreview(); // avoid overlapping of a selection and a preview
1240 //             updateButtons();
1241 //             return;
1242 //           }
1243 //         }
1244 //       }
1245 //     }
1246 //   }
1247 // 
1248 //   reset();
1249 // }
1250
1251
1252 /*
1253
1254 void PatternDataSelectionModel::setGeomEngine( GEOM::GEOM_Gen_var geomEngine )
1255 {gaumont parnasse
1256   _geomEngine = geomEngine;
1257 }
1258
1259 GEOM::GEOM_IOperations_ptr PatternDataSelectionModel::createOperation()
1260 {
1261 //   return myGeomGUI->GetGeomGen()->GetIBasicOperations(getStudyId());
1262   return _geomEngine->GetIBasicOperations(getStudyId());
1263 }
1264
1265 bool PatternDataSelectionModel::execute(ObjectList& objects)
1266 {
1267   bool res = false;
1268
1269   _PTR(Study)   aStudy = GetActiveStudyDocument();
1270   _PTR(SObject) aSChild;
1271   CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
1272   GEOM::GEOM_Object_var assoc;
1273
1274   foreach( const DocumentModel::GeomObj& anAssoc, _assocList ){
1275     std::cout << "FOUND=> " << anAssoc.entry.toStdString() << std::endl;
1276     aSChild = aStudy->FindObjectID( anAssoc.entry.toStdString() );
1277     aCorbaObj = corbaObj(aSChild);
1278     assoc = GEOM::GEOM_Object::_narrow(aCorbaObj);
1279
1280     if ( !CORBA::is_nil(assoc) ){
1281       std::cout << "geom to highlight =>" << anAssoc.name.toStdString() << std::endl;
1282       objects.push_back( assoc._retn() );
1283       res = true;
1284     } else {
1285       std::cout << "not a geom =>" << anAssoc.name.toStdString()<< std::endl;
1286     }
1287   }
1288
1289   return res;
1290 }
1291 */
1292
1293
1294 // SVTK_ViewWindow* PatternDataSelectionModel::GetViewWindow()
1295 // {
1296 //     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
1297 //         (SUIT_Session::session()->activeApplication());
1298 //     if (anApp) {
1299 //       if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
1300 //         return aView;
1301 // 
1302 // //       SUIT_ViewManager* aViewManager =
1303 // //         anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
1304 // //       if (aViewManager) {
1305 // //         if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
1306 // //           if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
1307 // //             aViewWindow->raise();
1308 // //             aViewWindow->setFocus();
1309 // //             return aView;
1310 // //           }
1311 // //         }
1312 // //       }
1313 //     }
1314 //     return NULL;
1315 // }
1316
1317
1318
1319
1320 // void  PatternDataSelectionModel::SetSelectionMode(Selection_Mode theMode)
1321 // {
1322 // 
1323 //   QList<SUIT_Selector*> aSelectors;
1324 //   _salomeSelectionMgr->selectors( SVTK_Viewer::Type(), aSelectors );
1325 //   QListIterator<SUIT_Selector*> it( aSelectors );
1326 //   
1327 //   std::cout << "PatternDataSelectionModel::SetSelectionMode()" << std::endl;
1328 //   while ( it.hasNext() )
1329 //   {
1330 //   //   SUIT_Selector* selector = it.next();
1331 //     SVTK_Selector* selector = dynamic_cast<SVTK_Selector*>( it.next() );
1332 //     if ( selector ){
1333 //       std::cout << "PatternDataSelectionModel::SetSelectionMode()" << theMode << std::endl;
1334 //       selector->SetSelectionMode(theMode);
1335 //     }
1336 //   }
1337 // }
1338
1339 // LightApp_SelectionMgr* PatternDataSelectionModel::selectionMgr()
1340 // {
1341 //   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1342 //   if( anApp )
1343 //     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1344 //   else
1345 //     return 0;
1346 // }
1347
1348 // //CS_TEST
1349 // SUIT_DataOwnerPtrList aOList;
1350 // LightApp_DataOwner* anOwher = new LightApp_DataOwner( "0:1:1:1:2" );
1351 // aOList.append( anOwher );
1352 // _salomeSelectionMgr->setSelected( aOList, false );
1353 // //CS_TEST
1354
1355 // void PatternDataSelectionModel::_highlightGEOM( const QModelIndex & anEltIndex )
1356 // {
1357 //   std::cout << "PatternDataSelectionModel::_highlightGEOM go find ASSOCIATION for"<< anEltIndex.data().toString().toStdString()<<std::endl;
1358 // // HEXABLOCKGUI::currentVtkView
1359 // 
1360 //   QList<DocumentModel::GeomObj> assocList;
1361 // 
1362 //   DocumentModel               *docModel = NULL;
1363 //   const QSortFilterProxyModel *pModel   = NULL;
1364 // //   const QStandardItemModel    *smodel
1365 // //   const QAbstractItemModel    *theModel = NULL;
1366 // 
1367 //   pModel = dynamic_cast<const QSortFilterProxyModel *>( model() );
1368 // 
1369 //   std::cout << "pModel "<< pModel << std::endl;
1370 //   if ( pModel ){
1371 //     std::cout << "if ( pModel ){"<< std::endl;
1372 //     docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() ); 
1373 //     if ( docModel ){
1374 //       std::cout << "if ( docModel ){"<< std::endl;
1375 //       assocList = docModel->getAssociations( pModel->mapToSource(anEltIndex) );
1376 //     }
1377 //   }
1378 // 
1379 // 
1380 //   _PTR(Study)   aStudy = GetActiveStudyDocument();
1381 //   _PTR(SObject) aSChild;
1382 //   CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
1383 //   GEOM::GEOM_Object_var assoc;
1384 // //   foreach( const QString& entry, geomEntries ){
1385 // // struct GeomObj
1386 // //         {
1387 // //           QString name;
1388 // //           QString entry;
1389 // //           QString brep;
1390 // //           double  start;
1391 // //           double  end;
1392 // //         };
1393 // 
1394 //   QVariant treeVariant = pModel->mapToSource(anEltIndex).data( HEXA_TREE_ROLE );
1395 //   int eltType;
1396 //   if ( !treeVariant.isValid() ) return;
1397 //   eltType = treeVariant.toInt();
1398 // 
1399 // //   GEOM::GeomObjPtr
1400 // //   GEOM::GEOM_Object_ptr firstLine;  //firstLine.nullify();//
1401 //   GEOM::GEOM_Object_var firstLine = GEOM::GEOM_Object::_nil();  //GEOM::GeomObjPtr
1402 //   GEOM::GEOM_Object_var lastLine  = GEOM::GEOM_Object::_nil();
1403 //   double firstParameter = 0.2; //CS_TODO
1404 //   double lastParameter  = 0.4; //CS_TODO
1405 // 
1406 //   foreach( const DocumentModel::GeomObj& anAssoc, assocList ){
1407 //     std::cout << "FOUND=> " << anAssoc.entry.toStdString() << std::endl;
1408 //     aSChild = aStudy->FindObjectID( anAssoc.entry.toStdString() );
1409 //     aCorbaObj = corbaObj(aSChild);
1410 //     assoc = GEOM::GEOM_Object::_narrow(aCorbaObj);
1411 // 
1412 //     if ( !CORBA::is_nil(assoc) ){
1413 //       std::cout << "geom to highlight =>" << anAssoc.name.toStdString() << std::endl;
1414 // //       objects.push_back(assoc._retn());
1415 // //       if ( eltType == EDGE_TREE ){
1416 // //           if ( CORBA::is_nil(firstLine) ){
1417 // //             firstLine = GEOM::GEOM_Object::_duplicate( assoc._retn() );
1418 // //           }
1419 // //           lastLine = GEOM::GEOM_Object::_duplicate( assoc._retn() );
1420 // //       }
1421 //       displayPreview( assoc._retn(),
1422 //                       true, //false, //append,
1423 //                       false,//true, //false, //activate,
1424 //                       false,//true,//update,
1425 //                       4,//lineWidth,
1426 //                       1,//-1,//displayMode,
1427 //                       Quantity_NOC_RED );
1428 //     } else {
1429 //       std::cout << "not a geom =>" << anAssoc.name.toStdString()<< std::endl;
1430 //     }
1431 //   }
1432 // //     std::cout << "CORBA::is_nil(firstLine) =>" << CORBA::is_nil(firstLine) << std::endl;
1433 // //     std::cout << "CORBA::is_nil(lastLine) =>"  << CORBA::is_nil(lastLine) << std::endl;
1434 // //     std::cout << "test" << ( !( CORBA::is_nil(firstLine) and !CORBA::is_nil(lastLine) ) ) << std::endl;
1435 //  /*
1436 //   if ( !( CORBA::is_nil(firstLine) and !CORBA::is_nil(lastLine) ) ){
1437 //     GEOM::GEOM_IBasicOperations_var anOper = _geomEngine->GetIBasicOperations( getStudyId() );
1438 //     GEOM::GEOM_Object_var firstPoint = anOper->MakePointOnCurve( firstLine, firstParameter );
1439 //     GEOM::GEOM_Object_var lastPoint  = anOper->MakePointOnCurve( lastLine, lastParameter );
1440 // 
1441 // //     std::cout << "firstPoint->_is_nil() =>" << firstPoint->_is_nil() << std::endl;
1442 //     std::cout << "lastPoint->_is_nil() =>"  << lastPoint->_is_nil() << std::endl;
1443 //     if ( !( CORBA::is_nil(firstPoint) ) )// !firstPoint->_is_nil() )
1444 //         displayPreview( firstPoint._retn(), true );
1445 //     if ( !( CORBA::is_nil(lastPoint) ) )//if ( !lastPoint->_is_nil() )
1446 //         displayPreview( lastPoint._retn(), true );
1447 //   }*/
1448 // }
1449 //