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