]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/HEXABLOCKGUI_DocumentSelectionModel.cxx
Salome HOME
Source IHM nettoye
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentSelectionModel.cxx
1 // Copyright (C) 2009-2013  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 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
47 #include "HEXABLOCKGUI_OccGraphicView.hxx"
48 #include "HEXABLOCKGUI_SalomeTools.hxx"
49 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
50 #include "HEXABLOCKGUI_DocumentModel.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 #include <AIS_ListIteratorOfListOfInteractive.hxx>
65
66 #include <QMultiMap>
67
68 #include <OCCViewer_ViewModel.h>
69 #include <SVTK_ViewModel.h>
70 #include <SalomeApp_Study.h>
71 #include <SalomeApp_Application.h>
72 #include <LightApp_SelectionMgr.h>
73 #include <SALOME_ListIteratorOfListIO.hxx>
74 #include <TopExp.hxx>
75 #include <TopExp_Explorer.hxx>
76 #include <TopoDS_Iterator.hxx>
77 #include <TopTools_MapOfShape.hxx>
78 #include <TopTools_IndexedMapOfShape.hxx>
79 #include <TColStd_IndexedMapOfInteger.hxx>
80
81
82 //#define _DEVDEBUG_
83 using namespace std;
84 using namespace HEXABLOCK::GUI;
85
86
87 // //===========================================================================
88 //                              SelectionModel
89 // //===========================================================================
90
91 SelectionModel::SelectionModel( QAbstractItemModel * model ):
92 QItemSelectionModel( model )
93 {
94
95 }
96
97 SelectionModel::~SelectionModel()
98 {
99   disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( salomeSelectionChanged() ) );
100 }
101
102
103 QModelIndex SelectionModel::indexBy( int role, const QString& value )
104 {
105   QModelIndex eltIndex; // element (vertex, edge, quad) of model
106   const QAbstractItemModel* theModel = model();
107   if ( !theModel ) return eltIndex;
108   QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
109                                           role,
110                                           value,
111                                           1,
112                                           Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
113   if ( theIndexes.count()>0 )
114     eltIndex = theIndexes[0] ;
115   return eltIndex;
116 }
117
118
119 QModelIndex SelectionModel::indexBy( int role, const QVariant& var )
120 {
121   QModelIndex eltIndex; // element (vertex, edge, quad) of model
122   const QAbstractItemModel* theModel = model();
123   if ( !theModel ) return eltIndex;
124   QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
125                                           role,
126                                           var,
127                                           1,
128                                           Qt::MatchRecursive /*| Qt::MatchContains*/ );//Qt::MatchFixedString );
129   if ( theIndexes.count()>0 )
130     eltIndex = theIndexes[0] ;
131   return eltIndex;
132 }
133
134 QModelIndex SelectionModel::indexOf( const QString& anEntry, int role )
135 {
136   QModelIndex eltIndex; // element (vertex, edge, quad) of model
137   const QAbstractItemModel* theModel = model();
138   if ( !theModel ) return eltIndex;
139
140   QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
141                                           role,
142                                           anEntry,
143                                           1,
144                                           Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
145   if ( theIndexes.count()>0 )
146     eltIndex = theIndexes[0] ;
147   return eltIndex;
148 }
149
150
151 QModelIndexList SelectionModel::indexListOf( const QString& anEntry, int role )
152 {
153   QModelIndexList theIndexes; // element (vertex, edge, quad) of model
154   const QAbstractItemModel* theModel = model();
155   if ( !theModel ) return theIndexes;
156   theIndexes = theModel->match( theModel->index(0, 0),
157                                 role,
158                                 anEntry,
159                                 -1,
160                                 Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
161   return theIndexes;
162 }
163
164 void SelectionModel::salomeSelectionChanged()
165 {
166     // clear highlights and selections in the trees
167     PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
168     PatternBuilderSelectionModel* pbsm = HEXABLOCKGUI::currentDocGView->getPatternBuilderSelectionModel();
169     PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
170     pdsm->clearSelection();
171     pbsm->clearSelection();
172     pgsm->clearSelection();
173     pdsm->unhighlightTreeItems();
174     pgsm->unhighlightTreeItems();
175
176     try {
177         SALOME_ListIO selectedObjects;
178         Handle(SALOME_InteractiveObject) anIObject;
179
180         switch (HEXABLOCKGUI::getActiveViewType())
181         {
182         case HEXABLOCKGUI::VTK:
183         {
184             HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
185             if ( selectedObjects.IsEmpty() )
186                 return;
187             anIObject = selectedObjects.First();
188             vtkSelectionChanged( anIObject );
189             break;
190         }
191         case HEXABLOCKGUI::OCC:
192             HEXABLOCKGUI::currentOccGView->getSelected(selectedObjects);
193             if ( selectedObjects.IsEmpty() )
194                 return;
195             anIObject = selectedObjects.First();
196             geomSelectionChanged( anIObject );
197             break;
198         }
199     } catch ( ... ) {
200         MESSAGE("*  Unknown selection exception!");
201     }
202 }
203
204
205 QModelIndexList SelectionModel::getSelectionFromModel(const Handle(SALOME_InteractiveObject)& anIObject)
206 {
207    QModelIndexList selectedIndexes;
208
209    //verify if the IOBject is valid and from VTK selection
210    bool fromVTK  = ( strcmp("HEXABLOCK", anIObject->getComponentDataType()) == 0 );
211    if ( !fromVTK || !anIObject->hasEntry() || HEXABLOCKGUI::currentDocGView->getViewWindow() == NULL)
212       return selectedIndexes;
213
214    QString anIOEntry = anIObject->getEntry();
215    int anhexaElemsId;
216    QString aText = "";
217
218    //extract vtk selection from the model -----------
219    if ( GetNameOfSelectedElements( HEXABLOCKGUI::currentDocGView->getViewWindow(), anIObject, aText ) <= 0 )
220       return selectedIndexes;
221
222    Document_Actor* docActor = dynamic_cast<Document_Actor*>( findActorByEntry( HEXABLOCKGUI::currentDocGView->getViewWindow(),
223                                                                                        anIOEntry.toLatin1() ) );
224    if ( !docActor ) return selectedIndexes;
225    QStringList idList = aText.split(" ");
226    foreach( const QString& id, idList )
227    {
228       if (!id.isEmpty())
229          {
230             //find selection in the model
231             anhexaElemsId = docActor->hexaElemsId[ id.toInt() ];
232             anIOEntry = QString::number( anhexaElemsId );
233
234             selectedIndexes << indexOf( anIOEntry, HEXA_ENTRY_ROLE );
235          }
236    }
237    return selectedIndexes;
238 }
239
240 // //===========================================================================
241 //                              PatternDataSelectionModel
242 // //===========================================================================
243
244 PatternDataSelectionModel::PatternDataSelectionModel( QAbstractItemModel * model ):
245 SelectionModel( model )
246 {
247   connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
248            this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ), Qt::UniqueConnection );
249   connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
250            this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ), Qt::UniqueConnection );
251
252 }
253
254 PatternDataSelectionModel::~PatternDataSelectionModel()
255 {
256   disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
257           this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
258   disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
259           this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
260 }
261
262
263 void PatternDataSelectionModel::onCurrentChanged( const QModelIndex & current, const QModelIndex & previous )
264 {
265   //Setting the selection mode of the selected item from the treeview
266   HEXABLOCKGUI::currentDocGView->setSelectionMode( current );
267   HEXABLOCKGUI::currentOccGView->setSelectionMode( current );
268 }
269
270 void PatternDataSelectionModel::highlightTreeItems(QModelIndexList& indexes,
271                                                    Qt::GlobalColor bgColor,
272                                                    Qt::GlobalColor fgColor, bool only)
273 {
274     if (indexes.count() == 0)
275         return;
276
277     if (only)
278         unhighlightTreeItems();
279
280     // * highlight item
281     QAbstractItemModel* theModel = (QAbstractItemModel*) model();
282     QMap<int, QVariant> roles;
283     roles[Qt::BackgroundRole] = bgColor;
284     roles[Qt::ForegroundRole] = fgColor;
285     foreach( const QModelIndex& anItemIndex, indexes )
286     {
287         if (anItemIndex.isValid())
288         {
289             theModel->setItemData(anItemIndex, roles);
290             currentHighlightedItems << anItemIndex;
291         }
292     }
293
294     // * scroll to the first highlighted item in the tree
295     HEXABLOCKGUI* module = HEXABLOCKGUI::getInstance();
296     if (module != NULL && indexes[0].isValid())
297         module->getPatternDataTreeView()->scrollTo(indexes[0]);
298 }
299
300 void PatternDataSelectionModel::unhighlightTreeItems(bool clearSelected)
301 {
302     if (clearSelected)
303         clearSelection();
304     if (currentHighlightedItems.count() == 0)
305         return;
306
307     QAbstractItemModel* theModel = (QAbstractItemModel*) model();
308     QMap<int, QVariant> roles;
309     roles[Qt::BackgroundRole] = Qt::white;
310     roles[Qt::ForegroundRole] = Qt::darkGreen;
311     foreach( const QModelIndex& anItemIndex, currentHighlightedItems)
312     {
313         if (anItemIndex.isValid())
314             theModel->setItemData(anItemIndex, roles);
315     }
316     currentHighlightedItems.clear();
317 }
318
319 QModelIndexList PatternDataSelectionModel::getGeomAssociations(const QModelIndex& dataIndex)
320 {
321     QModelIndexList geomIndexList;
322     DocumentModel               *docModel = NULL;
323     const QSortFilterProxyModel *pModel   = dynamic_cast<const QSortFilterProxyModel *>( model() );
324     PatternGeomSelectionModel* pGSModel = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
325
326     if ( pModel != NULL)
327         docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() );
328
329     if (docModel == NULL || pGSModel == NULL)
330         return geomIndexList;
331
332     HEXA_NS::Vertex* vertex = docModel->getHexaPtr<HEXA_NS::Vertex*>(dataIndex);
333     HEXA_NS::Edge*   edge   = docModel->getHexaPtr<HEXA_NS::Edge*>(dataIndex);
334     HEXA_NS::Quad*   quad   = docModel->getHexaPtr<HEXA_NS::Quad*>(dataIndex);
335     QModelIndex index = pModel->mapToSource(dataIndex);
336
337     if (vertex != NULL)
338         geomIndexList << docModel->getVertexAssociation( index );
339     else if (edge != NULL)
340         geomIndexList = docModel->getEdgeAssociations( index );
341     else if ( quad != NULL)
342         geomIndexList = docModel->getQuadAssociations( index );
343
344     return geomIndexList;
345 }
346
347 void PatternDataSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
348 {
349     QModelIndexList indexes = selected.indexes();
350     if (indexes.count() == 0)
351         return;
352
353     // ** unhighlight current highlighted items in the trees
354     PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
355     if (pgsm == NULL)
356         return;
357     unhighlightTreeItems(false);
358
359     QModelIndexList associatedGeomIndexes = getGeomAssociations(indexes[0]); //Mono Selection
360     if (associatedGeomIndexes.count() == 0)
361         pgsm->unhighlightTreeItems();
362
363     // ** highlight association in geometry tree
364     pgsm->highlightTreeItems(associatedGeomIndexes);
365
366     // ** highlight association in the vtk view
367     HEXABLOCKGUI::currentDocGView->highlight(indexes);
368
369     // ** highlight association in the occ view
370     HEXABLOCKGUI::currentOccGView->highlight(indexes);
371
372 }
373
374 void PatternDataSelectionModel::geomSelectionChanged( const Handle(SALOME_InteractiveObject)& anIObject )
375 {
376 //   if (HEXABLOCKGUI::assocInProgress) return;
377
378    PatternGeomSelectionModel*  pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
379    if (pgsm == NULL) return;
380
381    QModelIndex geomModelIndex = pgsm->getModelIndex(anIObject);
382    if (!geomModelIndex.isValid())
383        return;
384    pgsm->select( geomModelIndex, QItemSelectionModel::SelectCurrent );
385 }
386
387
388 void PatternDataSelectionModel::vtkSelectionChanged( const Handle(SALOME_InteractiveObject)& anIObject )
389 {
390     QModelIndexList selectedIndexes =  getSelectionFromModel(anIObject);
391     if (selectedIndexes.count() == 0)
392     {
393         clearSelection();
394         return;
395     }
396     QModelIndex anIOIndex = selectedIndexes[0]; //Monoselection
397
398     //Temporary Debug for hexa selection ------------------------------
399     if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
400     {
401         DocumentModel               *docModel = NULL;
402         const QSortFilterProxyModel *pModel   = dynamic_cast<const QSortFilterProxyModel *>( model() );
403
404         if ( pModel != NULL){
405             docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() );
406             if ( docModel != NULL && anIOIndex.isValid())
407             {
408                 //get the selected quad
409                 HEXA_NS::Quad* quad = docModel->getHexaPtr<HEXA_NS::Quad*>(anIOIndex);
410
411                 if (quad != NULL)
412                 {
413                     //get the hexa the quad belongs to
414                     HEXA_NS::Hexa* hexa = docModel->getQuadHexa(quad);
415                     if (hexa != NULL) //convert the hexa to a QModelIndex so we can select it in the model
416                         anIOIndex = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(hexa));
417                     else
418                     {
419                         SUIT_MessageBox::critical( 0,
420                                 tr("HexaBlock"),
421                                 tr("The Hexahedron this quad belongs to has been deleted!"));
422                         return;
423                     }
424                 }
425             }
426         }
427     }//end if HEXA_TREE-----------------------------------------------
428
429     //select the element in the model
430     select( anIOIndex, QItemSelectionModel::SelectCurrent );
431 }
432
433 // //===========================================================================
434 //                              PatternGeomSelectionModel
435 // //===========================================================================
436
437 PatternGeomSelectionModel::PatternGeomSelectionModel( QAbstractItemModel * model ):
438 SelectionModel( model )
439 {
440   connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
441            this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
442   connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
443            this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ), Qt::UniqueConnection );
444 }
445
446 PatternGeomSelectionModel::~PatternGeomSelectionModel()
447 {
448   disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
449           this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
450   disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
451           this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
452 }
453
454 void PatternGeomSelectionModel::onCurrentChanged( const QModelIndex & current, const QModelIndex & previous )
455 {
456   //Setting the selection mode of the selected item from the treeview}
457   HEXABLOCKGUI::currentDocGView->setSelectionMode( current );
458   HEXABLOCKGUI::currentOccGView->setSelectionMode( current );
459 }
460
461 void PatternGeomSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
462 {
463     DocumentModel* docModel = NULL;
464     const QSortFilterProxyModel *pModel = dynamic_cast<const QSortFilterProxyModel *>( model() );
465     if ( pModel != NULL)
466         docModel = dynamic_cast<DocumentModel*>(pModel->sourceModel());
467
468     QModelIndexList indexes = selected.indexes();
469     if (indexes.count() == 0 || docModel == NULL)
470         return;
471
472     // ** unhighlight current highlighted items in the trees
473     PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
474     if (pdsm == NULL)
475         return;
476     unhighlightTreeItems(false);
477
478     //find the corresponding element in the model
479     HEXA_NS::SubShape* eltSubShape = dynamic_cast<HEXA_NS::SubShape*>(docModel->getHexaPtr(indexes[0]));
480     if (eltSubShape == NULL) return;
481
482     HEXA_NS::NewShape* subShapeParent = eltSubShape->getParentShape();
483     if (subShapeParent == NULL) return;
484
485     QString parentShapeName = subShapeParent->getName();
486     QString subId = QString::number(eltSubShape->getIdent());
487     QString aGeomObjModelEntry = parentShapeName + "," + subId + ";";
488
489     QModelIndexList assocsIndexes = pdsm->indexListOf(aGeomObjModelEntry, HEXA_ASSOC_ENTRY_ROLE);
490     if (assocsIndexes.count() == 0)
491         pdsm->unhighlightTreeItems();
492
493     // ** highlight associations in the data tree
494     pdsm->highlightTreeItems(assocsIndexes);
495
496     // ** highlight associations in the vtk view
497     HEXABLOCKGUI::currentDocGView->highlight(assocsIndexes);
498
499     // ** highlight the selected element in the occ view
500     QMultiMap<QString, int>  entrySubIDs;
501     entrySubIDs.insert(parentShapeName, eltSubShape->getIdent());
502     HEXABLOCKGUI::currentOccGView->highlight(entrySubIDs);
503 }
504
505 QModelIndex PatternGeomSelectionModel::getModelIndex(const Handle(SALOME_InteractiveObject)& anIObject)
506 {
507     QModelIndex result;
508     DocumentModel               *docModel = NULL;
509     const QSortFilterProxyModel *pModel   = dynamic_cast<const QSortFilterProxyModel *>( model() );
510     if ( pModel != NULL)
511         docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel());
512
513     if ( docModel == NULL || HEXABLOCKGUI::selectionMgr() == NULL ||
514             HEXABLOCKGUI::currentOccGView->getViewWindow() == NULL)
515         return result;
516
517     //extract associated elements in the model
518     TColStd_IndexedMapOfInteger anIndexes;
519     HEXABLOCKGUI::selectionMgr()->GetIndexes(anIObject, anIndexes);
520     if (anIndexes.Extent() == 0) return result;
521     QString aGeomObjStudyEntry = anIObject->getEntry();
522     QString aGeomObjModelEntry = docModel->getGeomObjName(aGeomObjStudyEntry) + "," + QString::number(anIndexes(1));
523
524     HEXA_NS::SubShape*    ssh =  docModel->getGeomPtr(aGeomObjModelEntry);
525     HEXA_NS::VertexShape* vSh =  dynamic_cast<HEXA_NS::VertexShape*>(ssh);
526     HEXA_NS::EdgeShape*   eSh =  dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
527     HEXA_NS::FaceShape*   fSh =  dynamic_cast<HEXA_NS::FaceShape*>(ssh);
528
529     if (vSh != NULL)
530         result = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(vSh));
531     else if (eSh != NULL)
532         result = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(eSh));
533     else if (fSh != NULL)
534         result = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(fSh));
535
536     return result;
537 }
538
539 void PatternGeomSelectionModel::highlightTreeItems(QModelIndexList& indexes,
540                                                    Qt::GlobalColor bgColor,
541                                                    Qt::GlobalColor fgColor, bool only)
542 {
543     if (indexes.count() == 0)
544         return;
545
546     if (only)
547         unhighlightTreeItems();
548
549     // * highlight items
550     QAbstractItemModel* theModel = (QAbstractItemModel*) model();
551     QMap<int, QVariant> roles;
552     roles[Qt::BackgroundRole] = bgColor;
553     roles[Qt::ForegroundRole] = fgColor;
554     foreach( const QModelIndex& anItemIndex, indexes )
555     {
556         if (anItemIndex.isValid())
557         {
558             theModel->setItemData(anItemIndex, roles);
559             currentHighlightedItems << anItemIndex;
560         }
561     }
562
563     // * scroll to the first highlighted item in the tree
564     HEXABLOCKGUI* module = HEXABLOCKGUI::getInstance();
565     if (module != NULL && indexes[0].isValid())
566         module->getPatternGeomTreeView()->scrollTo(indexes[0]);
567 }
568
569 void PatternGeomSelectionModel::unhighlightTreeItems(bool clearSelected)
570 {
571     if (clearSelected)
572         clearSelection();
573     if (currentHighlightedItems.count() == 0)
574         return;
575     QAbstractItemModel* theModel = (QAbstractItemModel*) model();
576     QMap<int, QVariant> roles;
577     roles[Qt::BackgroundRole] = Qt::white;
578     roles[Qt::ForegroundRole] = Qt::darkGreen;
579     foreach( const QModelIndex& anItemIndex, currentHighlightedItems)
580     {
581         if (anItemIndex.isValid())
582             theModel->setItemData(anItemIndex, roles);
583     }
584     currentHighlightedItems.clear();
585 }
586
587 // //===========================================================================
588 //                              GroupsSelectionModel
589 // //===========================================================================
590 GroupsSelectionModel::GroupsSelectionModel( QAbstractItemModel * model ):
591 SelectionModel( model )
592 {
593   connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
594            this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ), Qt::UniqueConnection );
595   connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
596            this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ), Qt::UniqueConnection );
597 }
598
599 GroupsSelectionModel::~GroupsSelectionModel()
600 {
601   disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
602           this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
603   disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
604           this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
605 }
606
607
608 void GroupsSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
609 {
610   try {
611     QModelIndexList indexes = selected.indexes();
612     for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index ){
613       HEXABLOCKGUI::currentDocGView->highlightGroups( *i_index );
614     }
615   } catch ( ... ) {
616     MESSAGE("Unknown exception was cought !!!");
617   }
618 }
619
620 // //===========================================================================
621 //                              MeshSelectionModel
622 // //===========================================================================
623 MeshSelectionModel::MeshSelectionModel( QAbstractItemModel * model ):
624 SelectionModel( model )
625 {
626   connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
627            this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ), Qt::UniqueConnection );
628   connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
629            this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ), Qt::UniqueConnection );
630 }
631
632
633 MeshSelectionModel::~MeshSelectionModel()
634 {
635   disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
636           this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
637   disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
638           this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
639 }
640
641
642 void MeshSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
643 {
644   try {
645
646     QModelIndexList indexes = selected.indexes();
647     for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index ){
648       HEXABLOCKGUI::currentDocGView->highlightPropagation( *i_index );
649     }
650   } catch ( ... ) {
651     MESSAGE("Unknown exception was cought !!!");
652   }
653 }
654