1 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #include "utilities.h"
26 #include <QtxWorkstack.h>
27 #include <STD_TabDesktop.h>
28 #include <STD_MDIDesktop.h>
29 #include <STD_SDIDesktop.h>
31 #include <SalomeApp_Tools.h>
33 #include "SOCC_ViewModel.h"
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewModel.h>
36 #include <OCCViewer_ViewWindow.h>
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>
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"
55 #include <SVTK_Selector.h>
56 #include <SVTK_ViewModel.h>
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>
68 #include "MyGEOMBase_Helper.hxx"
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>
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>
86 using namespace HEXABLOCK::GUI;
89 // //===========================================================================
91 // //===========================================================================
93 SelectionModel::SelectionModel( QAbstractItemModel * model ):
94 QItemSelectionModel( model ),
95 //_theModelSelectionChanged(false),
96 //_theVtkSelectionChanged(false),
97 //_theGeomSelectionChanged(false),
99 salomeNothingSelected(true)
104 SelectionModel::~SelectionModel()
106 disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( salomeSelectionChanged() ) );
110 QModelIndex SelectionModel::indexBy( int role, const QString& value )
112 QModelIndex eltIndex; // element (vertex, edge, quad) of model
113 const QAbstractItemModel* theModel = model();
114 if ( !theModel ) return eltIndex;
115 QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
119 Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
120 if ( theIndexes.count()>0 )
121 eltIndex = theIndexes[0] ;
126 QModelIndex SelectionModel::indexBy( int role, const QVariant& var )
128 QModelIndex eltIndex; // element (vertex, edge, quad) of model
129 const QAbstractItemModel* theModel = model();
130 if ( !theModel ) return eltIndex;
131 QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
135 Qt::MatchRecursive /*| Qt::MatchContains*/ );//Qt::MatchFixedString );
136 if ( theIndexes.count()>0 )
137 eltIndex = theIndexes[0] ;
141 QModelIndex SelectionModel::indexOf( const QString& anEntry, int role )
143 QModelIndex eltIndex; // element (vertex, edge, quad) of model
144 const QAbstractItemModel* theModel = model();
145 if ( !theModel ) return eltIndex;
147 QModelIndexList theIndexes = theModel->match( theModel->index(0, 0),
151 Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
152 if ( theIndexes.count()>0 )
153 eltIndex = theIndexes[0] ;
158 QModelIndexList SelectionModel::indexListOf( const QString& anEntry, int role )
160 QModelIndexList theIndexes; // element (vertex, edge, quad) of model
161 const QAbstractItemModel* theModel = model();
162 if ( !theModel ) return theIndexes;
163 theIndexes = theModel->match( theModel->index(0, 0),
167 Qt::MatchRecursive | Qt::MatchContains );//Qt::MatchFixedString );
173 void SelectionModel::salomeSelectionChanged()
175 if (HEXABLOCKGUI::assocInProgress &&
176 HEXABLOCKGUI::getActiveViewType() == HEXABLOCKGUI::OCC) return;
180 if ( HEXABLOCKGUI::selectionMgr() == NULL ) return;
181 SALOME_ListIO salomeSelected;
182 // _salomeSelectionMgr->selectedObjects( salomeSelected, SVTK_Viewer::Type() );//salomeSelected.Extent()
183 if (HEXABLOCKGUI::getActiveViewType() == HEXABLOCKGUI::VTK)
185 HEXABLOCKGUI::selectionMgr()->selectedObjects( salomeSelected, SVTK_Viewer::Type());
187 else if (HEXABLOCKGUI::getActiveViewType() == HEXABLOCKGUI::OCC)
189 HEXABLOCKGUI::selectionMgr()->selectedObjects( salomeSelected, "", false);
192 // HEXABLOCKGUI::selectionMgr()->selectedObjects( salomeSelected, NULL, false );
193 if ( salomeSelected.IsEmpty() ){
194 salomeNothingSelected = true;
199 Handle(SALOME_InteractiveObject) anIObject;
200 SALOME_ListIteratorOfListIO it(salomeSelected);
202 //Handle selection according to the source
203 if (HEXABLOCKGUI::getActiveViewType() == HEXABLOCKGUI::VTK)
205 for( ; it.More(); it.Next()){
206 anIObject = it.Value(); //anIObject->getName()
207 vtkSelectionChanged( anIObject ); // or VTK?...
210 else if (HEXABLOCKGUI::getActiveViewType() == HEXABLOCKGUI::OCC)
212 for( ; it.More(); it.Next()){
213 anIObject = it.Value(); //anIObject->getName()
214 geomSelectionChanged( anIObject );// or VTK?...
218 salomeNothingSelected = false;
220 MESSAGE("* Unknown exception was cought !!!");
225 QModelIndexList SelectionModel::getSelectionFromModel(const Handle(SALOME_InteractiveObject)& anIObject)
227 QModelIndexList selectedIndexes;
229 //verify if the IOBject is valid and from VTK selection
230 bool fromVTK = ( strcmp("HEXABLOCK", anIObject->getComponentDataType()) == 0 );
231 if ( !fromVTK || !anIObject->hasEntry() || HEXABLOCKGUI::currentDocGView->getViewWindow() == NULL)
232 return selectedIndexes;
234 QString anIOEntry = anIObject->getEntry();
238 //extract vtk selection from the model -----------
239 if ( GetNameOfSelectedElements( HEXABLOCKGUI::currentDocGView->getViewWindow(), anIObject, aText ) <= 0 )
240 return selectedIndexes;
242 Document_Actor* docActor = dynamic_cast<Document_Actor*>( findActorByEntry( HEXABLOCKGUI::currentDocGView->getViewWindow(),
243 anIOEntry.toLatin1() ) );
244 if ( !docActor ) return selectedIndexes;
245 QStringList idList = aText.split(" ");
246 foreach( const QString& id, idList )
250 //find selection in the model
251 anhexaElemsId = docActor->hexaElemsId[ id.toInt() ];
252 anIOEntry = QString::number( anhexaElemsId );
254 selectedIndexes << indexOf( anIOEntry, HEXA_ENTRY_ROLE );
257 return selectedIndexes;
260 //Returns the element of the model which is associated to the Interactive object
261 QModelIndexList SelectionModel::getSelectionAssociactions(const Handle(SALOME_InteractiveObject)& anIObject)
263 QModelIndexList assocsIndexes;
264 DocumentModel *docModel = NULL;
265 const QSortFilterProxyModel *pModel = dynamic_cast<const QSortFilterProxyModel *>( model() );
267 docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() );
269 if ( docModel == NULL) return assocsIndexes;
271 //verify if the selection is really from OCC View
272 bool fromGEOM = ( strcmp("GEOM", anIObject->getComponentDataType()) == 0 );
273 if ( !fromGEOM || HEXABLOCKGUI::selectionMgr() == NULL ||
274 HEXABLOCKGUI::currentOccGView->getViewWindow() == NULL)
275 return assocsIndexes;
278 GEOM::GEOM_Object_var aGeomObj = GEOMBase::ConvertIOinGEOMObject( anIObject );
280 //extract associated elements in the model
281 if ( GEOMBase::IsShape(aGeomObj) ){
282 // aName = GEOMBase::GetName(aGeomObj);
283 TColStd_IndexedMapOfInteger anIndexes;
284 HEXABLOCKGUI::selectionMgr()->GetIndexes(anIObject, anIndexes);
285 if (anIndexes.Extent() == 0) return assocsIndexes;
286 QString aGeomObjStudyEntry = aGeomObj->GetStudyEntry();
288 for( int i = 1; i <= anIndexes.Extent(); ++i)
290 QString aGeomObjModelEntry = docModel->getGeomObjName(aGeomObjStudyEntry) + "," + QString::number(anIndexes(i)) + ";";
291 assocsIndexes.append(indexListOf(aGeomObjModelEntry, HEXA_ASSOC_ENTRY_ROLE));
292 if (assocsIndexes.count() > 0)
293 return assocsIndexes; //Premature: On purpose for Monoselection
297 return assocsIndexes;
301 // //===========================================================================
302 // PatternDataSelectionModel
303 // //===========================================================================
305 PatternDataSelectionModel::PatternDataSelectionModel( QAbstractItemModel * model ):
306 SelectionModel( model )
308 connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
309 this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ), Qt::UniqueConnection );
310 connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
311 this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ), Qt::UniqueConnection );
315 PatternDataSelectionModel::~PatternDataSelectionModel()
317 disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
318 this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
319 disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
320 this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
324 void PatternDataSelectionModel::onCurrentChanged( const QModelIndex & current, const QModelIndex & previous )
326 //Setting the selection mode of the selected item from the treeview
327 HEXABLOCKGUI::currentDocGView->setSelectionMode( current );
328 HEXABLOCKGUI::currentOccGView->setSelectionMode( current );
331 void PatternDataSelectionModel::highlightEltsWithAssocs(const QModelIndexList& elts)
334 /*if ( !_theVtkSelectionChanged )*/
335 HEXABLOCKGUI::currentDocGView->highlight(elts);
336 /*if ( !_theGeomSelectionChanged )*/
337 HEXABLOCKGUI::currentOccGView->highlight(elts);
339 MESSAGE("Unknown exception was cought !!!");
343 QModelIndexList PatternDataSelectionModel::getGeomAssociations(const QModelIndex& dataIndex)
345 QModelIndexList geomIndexList;
346 HEXA_NS::SubShape* ssh;
347 HEXA_NS::EdgeShape* sh;
348 if (HEXABLOCKGUI::currentDocGView == NULL) return geomIndexList;
350 DocumentModel *docModel = NULL;
351 const QSortFilterProxyModel *pModel = dynamic_cast<const QSortFilterProxyModel *>( model() );
352 PatternGeomModel* pGModel = HEXABLOCKGUI::currentDocGView->getPatternGeomModel();
353 PatternGeomSelectionModel* pGSModel = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
356 docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() );
358 if (docModel == NULL || pGModel == NULL || pGSModel == NULL)
359 return geomIndexList;
361 HEXA_NS::Vertex* vertex = docModel->getHexaPtr<HEXA_NS::Vertex*>(dataIndex);
362 HEXA_NS::Edge* edge = docModel->getHexaPtr<HEXA_NS::Edge*>(dataIndex);
363 HEXA_NS::Quad* quad = docModel->getHexaPtr<HEXA_NS::Quad*>(dataIndex);
364 QModelIndex index = pModel->mapToSource(dataIndex);
367 geomIndexList << docModel->getVertexAssociation( index/*dataIndex*/ );
368 else if (edge != NULL)
370 QList<DocumentModel::GeomObj> assocs = docModel->getEdgeAssociations( index/*dataIndex*/ );
371 foreach( const DocumentModel::GeomObj& anAssoc, assocs )
373 QString id = anAssoc.shapeName+","+anAssoc.subid;
374 ssh = docModel->getGeomPtr(id);
375 sh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
377 geomIndexList << /*pGModel->mapToSource(*/pGSModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(sh))/*)*/;
380 else if ( quad != NULL)
381 geomIndexList = docModel->getQuadAssociations( index/*dataIndex*/ );
384 return geomIndexList;
388 void PatternDataSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
392 // MESSAGE("PatternDataSelectionModel: ignoring this signal");
393 // ignoreSignal = false;
396 //need to highlight the associated geom obj in the geometry tree
397 //first get the association
398 QModelIndexList associatedGeomIndexes;
399 QModelIndexList indexes = selected.indexes();
400 highlightEltsWithAssocs(indexes);
402 // //highlight in geom
403 // if (HEXABLOCKGUI::currentDocGView == NULL || indexes.count() == 0) return;
404 // associatedGeomIndexes = getGeomAssociations(indexes[0]); //Mono Selection
405 // if (associatedGeomIndexes.count() == 0)
407 // MESSAGE("ON SELECTION CHANGED: no association found: returning...");
408 // HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel()->setIgnoreSignal(false);
411 // if (associatedGeomIndexes[0].isValid())
413 //// MESSAGE("Association found: but not selecting... now returning");
415 // //tell geom selection model to ignore this signal
416 // HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel()->setIgnoreSignal(true);
418 // //selection of the associated element in the geometry tree
419 //// HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel()->setCurrentIndex( associatedGeomIndexes[0],
420 //// QItemSelectionModel::Clear );
421 // const QSortFilterProxyModel *pModel = dynamic_cast<const QSortFilterProxyModel *>( HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel()->model() );
422 // if (pModel == NULL)
424 // HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel()->setIgnoreSignal(false);
427 // MESSAGE("SELECTING THE GEOM TREE INDEX NOW: ");
428 // MESSAGE(HEXABLOCKGUI::currentDocGView->getDocumentModel()->getHexaPtr(associatedGeomIndexes[0])->getName());
430 // HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel()->setCurrentIndex( associatedGeomIndexes[0],
431 // QItemSelectionModel::ClearAndSelect );
436 void PatternDataSelectionModel::geomSelectionChanged( const Handle(SALOME_InteractiveObject)& anIObject )
438 if (HEXABLOCKGUI::assocInProgress) return;
440 // QModelIndexList assocsIndexes = getSelectionAssociactions(anIObject);
441 PatternGeomSelectionModel* pgsm = NULL;
442 if (HEXABLOCKGUI::currentDocGView != NULL)
443 pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
444 if (pgsm == NULL) return;
446 QModelIndex geomModelIndex = pgsm->getModelIndex(anIObject);
448 if (!geomModelIndex.isValid()) return;
449 pgsm->setCurrentIndex( geomModelIndex, QItemSelectionModel::Clear ); //CS_TEST
450 pgsm->setCurrentIndex( geomModelIndex, QItemSelectionModel::SelectCurrent );
454 void PatternDataSelectionModel::vtkSelectionChanged( const Handle(SALOME_InteractiveObject)& anIObject )
456 QModelIndexList selectedIndexes = getSelectionFromModel(anIObject);
457 if (selectedIndexes.count() == 0)
462 // _theVtkSelectionChanged = true;
463 QModelIndex anIOIndex = selectedIndexes[0]; //Monoselection
465 //Temporary Debug for hexa selection -----------------------------
466 if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
468 DocumentModel *docModel = NULL;
469 const QSortFilterProxyModel *pModel = dynamic_cast<const QSortFilterProxyModel *>( model() );
471 if ( pModel != NULL){
472 docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() );
473 if ( docModel != NULL && anIOIndex.isValid())
475 //get the selected quad
476 HEXA_NS::Quad* quad = docModel->getHexaPtr<HEXA_NS::Quad*>(anIOIndex);
480 //get the hexa the quad belongs to
481 HEXA_NS::Hexa* hexa = docModel->getQuadHexa(quad);
482 if (hexa != NULL) //convert the hexa to a QModelIndex so we can select it in the model
483 anIOIndex = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(hexa));
486 SUIT_MessageBox::critical( 0,
488 tr("The Hexahedron this quad belongs to has been deleted!"));
494 }//end if HEXA_TREE----------------------------------------------
496 //select the element in the model
497 setCurrentIndex( anIOIndex, QItemSelectionModel::Clear );
498 setCurrentIndex( anIOIndex, QItemSelectionModel::SelectCurrent );
499 // _theVtkSelectionChanged = false;
502 // //===========================================================================
503 // PatternGeomSelectionModel
504 // //===========================================================================
506 PatternGeomSelectionModel::PatternGeomSelectionModel( QAbstractItemModel * model ):
507 SelectionModel( model )
509 connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
510 this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
511 connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
512 this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ), Qt::UniqueConnection );
515 PatternGeomSelectionModel::~PatternGeomSelectionModel()
517 disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
518 this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
519 disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
520 this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
524 void PatternGeomSelectionModel::onCurrentChanged( const QModelIndex & current, const QModelIndex & previous )
526 //Setting the selection mode of the selected item from the treeview}
527 HEXABLOCKGUI::currentDocGView->setSelectionMode( current );
528 HEXABLOCKGUI::currentOccGView->setSelectionMode( current );
532 void PatternGeomSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
534 //don't handle selection signals coming from the data tree
537 // MESSAGE("PatternGeomSelectionModel: IGNORING THE SIGNAL:!");
538 // ignoreSignal = false;
542 DocumentModel *docModel = NULL;
543 const QSortFilterProxyModel *pModel = dynamic_cast<const QSortFilterProxyModel *>( model() );
545 docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel());
547 QModelIndexList indexes = selected.indexes();
548 if (indexes.count() == 0 || docModel == NULL) return;
550 //find the corresponding element in the model
551 HEXA_NS::SubShape* eltSubShape = dynamic_cast<HEXA_NS::SubShape*>(docModel->getHexaPtr(indexes[0]));
552 if (eltSubShape == NULL) return;
554 HEXA_NS::NewShape* subShapeParent = eltSubShape->getParentShape();
555 if (subShapeParent == NULL) return;
557 QString parentShapeName = subShapeParent->getName();
558 QString subId = QString::number(eltSubShape->getIdent());
559 QString aGeomObjModelEntry = parentShapeName + "," + subId + ";";
561 //get the model of the data tree
562 if (HEXABLOCKGUI::currentDocGView == NULL || HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel() == NULL)
565 QModelIndexList assocsIndexes = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel()->indexListOf(aGeomObjModelEntry, HEXA_ASSOC_ENTRY_ROLE);
567 //selection of the associated elements
568 if (assocsIndexes.count() == 1 && assocsIndexes[0].isValid())
570 // HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel()->setIgnoreSignal(true);
571 //Select associated element in the model => highlight in vtk view
572 // HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel()->setCurrentIndex( assocsIndexes[0], QItemSelectionModel::Clear ); //CS_TEST
573 HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel()->setCurrentIndex( assocsIndexes[0], QItemSelectionModel::ClearAndSelect );
574 HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel()->highlightEltsWithAssocs(assocsIndexes);
578 /*more than one element associated to this geom object: just highlight in the views,
579 not in the model (because of mono selection in the model).*/
581 //hight the selected geom obj in the occ view
582 if (HEXABLOCKGUI::currentOccGView != NULL)
584 QMultiMap<QString, int> entrySubIDs;
585 entrySubIDs.insert(parentShapeName, eltSubShape->getIdent());
587 HEXABLOCKGUI::currentOccGView->highlight(entrySubIDs);
589 //...and its associated elements in the vtk view
590 HEXABLOCKGUI::currentDocGView->highlight(assocsIndexes);
594 QModelIndex PatternGeomSelectionModel::getModelIndex(const Handle(SALOME_InteractiveObject)& anIObject)
597 DocumentModel *docModel = NULL;
598 const QSortFilterProxyModel *pModel = dynamic_cast<const QSortFilterProxyModel *>( model() );
600 docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel());
602 if ( docModel == NULL) return result;
604 //verify if the selection is really from OCC View
605 bool fromGEOM = ( strcmp("GEOM", anIObject->getComponentDataType()) == 0 );
606 if ( !fromGEOM || HEXABLOCKGUI::selectionMgr() == NULL ||
607 HEXABLOCKGUI::currentOccGView->getViewWindow() == NULL)
611 GEOM::GEOM_Object_var aGeomObj = GEOMBase::ConvertIOinGEOMObject( anIObject );
613 //extract associated elements in the model
614 if ( GEOMBase::IsShape(aGeomObj) ){
615 // aName = GEOMBase::GetName(aGeomObj);
616 TColStd_IndexedMapOfInteger anIndexes;
617 HEXABLOCKGUI::selectionMgr()->GetIndexes(anIObject, anIndexes);
618 if (anIndexes.Extent() == 0) return result;
619 QString aGeomObjStudyEntry = aGeomObj->GetStudyEntry();
620 QString aGeomObjModelEntry = docModel->getGeomObjName(aGeomObjStudyEntry) + "," + QString::number(anIndexes(1));
622 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(aGeomObjModelEntry);
625 MESSAGE("Tranna get: " << aGeomObjModelEntry.toStdString() << ", " << ssh->getName());
629 MESSAGE("YOUR SHAPE IS NULL");
631 MESSAGE("Tranna get: " << aGeomObjModelEntry.toStdString());
632 HEXA_NS::VertexShape* vSh = dynamic_cast<HEXA_NS::VertexShape*>(ssh);
633 HEXA_NS::EdgeShape* eSh = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
634 HEXA_NS::FaceShape* fSh = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
637 result = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(vSh));
638 else if (eSh != NULL)
640 MESSAGE("=====> An EDGE: "<< eSh->getName());
641 result = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(eSh));
643 else if (fSh != NULL)
644 result = indexBy( HEXA_DATA_ROLE, QVariant::fromValue(fSh));
649 // //===========================================================================
650 // GroupsSelectionModel
651 // //===========================================================================
653 GroupsSelectionModel::GroupsSelectionModel( QAbstractItemModel * model ):
654 SelectionModel( model )
656 connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
657 this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ), Qt::UniqueConnection );
658 connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
659 this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ), Qt::UniqueConnection );
662 GroupsSelectionModel::~GroupsSelectionModel()
664 disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
665 this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
666 disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
667 this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
671 void GroupsSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
674 // if ( _salomeSelectionMgr == NULL ) return;
675 // _salomeSelectionMgr->clearSelected();
676 // erasePreview(true);
677 QModelIndexList indexes = selected.indexes();
678 for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index ){
679 HEXABLOCKGUI::currentDocGView->highlightGroups( *i_index );
682 // CS_BP todo SALOMEGUI_Swig.cxx:370
683 // indexes = deselected.indexes();
684 // for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index )
685 // _unselectSalome( *i_index);
687 MESSAGE("Unknown exception was cought !!!");
693 // //===========================================================================
694 // MeshSelectionModel
695 // //===========================================================================
698 MeshSelectionModel::MeshSelectionModel( QAbstractItemModel * model ):
699 SelectionModel( model )
701 connect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
702 this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ), Qt::UniqueConnection );
703 connect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
704 this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ), Qt::UniqueConnection );
708 MeshSelectionModel::~MeshSelectionModel()
710 disconnect( this, SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
711 this, SLOT( onCurrentChanged( const QModelIndex & , const QModelIndex & ) ) );
712 disconnect( this, SIGNAL( selectionChanged( const QItemSelection & , const QItemSelection & ) ),
713 this, SLOT( onSelectionChanged( const QItemSelection & , const QItemSelection & ) ) );
717 void MeshSelectionModel::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
721 QModelIndexList indexes = selected.indexes();
722 for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index ){
723 HEXABLOCKGUI::currentDocGView->highlightPropagation( *i_index );
726 // CS_BP todo SALOMEGUI_Swig.cxx:370
727 // indexes = deselected.indexes();
728 // for( QModelIndexList::const_iterator i_index = indexes.begin(); i_index != indexes.end(); ++i_index )
729 // _unselectSalome( *i_index);
731 MESSAGE("Unknown exception was cought !!!");
744 // //=================================================================================
745 // // function : activateSelection
746 // // purpose : Activate selection in accordance with myEditCurrentArgument
747 // //=================================================================================
748 // void PatternDataSelectionModel::activateSelection()
750 // erasePreview(false);
752 // // local selection
753 // if (!myObject->_is_nil() && !isAllSubShapes())
755 // GEOM_Displayer* aDisplayer = getDisplayer();
756 // SALOME_View* view = GEOM_Displayer::GetActiveView();
758 // CORBA::String_var aMainEntry = myObject->GetStudyEntry();
759 // Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
760 // if (view->isVisible(io)) {
761 // aDisplayer->Erase(myObject, false, false);
762 // myIsHiddenMain = true;
766 // int prevDisplayMode = aDisplayer->SetDisplayMode(0);
768 // SUIT_ViewWindow* aViewWindow = 0;
769 // SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
771 // aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
772 // if (aViewWindow == 0) return;
774 // SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
775 // if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
776 // aViewManager->getType() != SVTK_Viewer::Type())
779 // SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
780 // SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
781 // if (aView == 0) return;
783 // //TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
785 // TopTools_IndexedMapOfShape aSubShapesMap;
786 // TopExp::MapShapes(myShape, aSubShapesMap);
787 // CORBA::String_var aMainEntry = myObject->GetStudyEntry();
788 // QString anEntryBase = aMainEntry.in();
790 // TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
791 // for (; anExp.More(); anExp.Next())
793 // TopoDS_Shape aSubShape = anExp.Current();
794 // int index = aSubShapesMap.FindIndex(aSubShape);
795 // QString anEntry = anEntryBase + QString("_%1").arg(index);
797 // SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
799 // displayPreview(aPrs, true, false); // append, do not update
802 // aDisplayer->UpdateViewer();
803 // aDisplayer->SetDisplayMode(prevDisplayMode);
806 // globalSelection(GEOM_ALLSHAPES);
812 // SUIT_DataOwnerPtrList aList;
813 // ObjectList::iterator anIter;
814 // for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
816 // QString anEntry = getEntry( *anIter );
817 // LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
818 // aList.append( anOwher );
821 // SUIT_Session* session = SUIT_Session::session();
822 // SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
826 // LightApp_SelectionMgr* aMgr = app->selectionMgr();
829 // _getVTKViewWindow()
830 // aMgr->setSelecte_getVTKViewWindow()d( aList, false );
836 // SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
837 // if (!anActor || !anActor->hasIO())
840 // Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
841 // //mySelectionMgr->clearSelected();
842 // //mySelectionMgr->AddIObject(anIO, false);
843 // SALOME_ListIO aList;
844 // aList.Append(anIO);
845 // mySelectionMgr->setSelectedObjects(aList, false);
847 // // Remove filter corresponding to the current type from viewer
848 // int aType = myTable->GetType();
849 // int aFilterId = SMESH::UnknownFilter;
850 // if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
851 // else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
852 // else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
853 // Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
854 // SMESH::RemoveFilter(aFilterId);
857 // TColStd_MapOfInteger aMap;
858 // QList<int>::const_iterator anIter;
859 // for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
860 // aMap.Add(*anIter);
863 // // Set new selection
864 // activeViewWindow->AddOrRemoveIndex(anIO, aMap, false);
865 // if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
866 // aViewWindow->highlight( anIO, true, true );
868 // // insert previously stored filter in viewer if necessary
869 // if (!aFilter.IsNull())
870 // SMESH::SetFilter(aFilter);
881 // if(SVTK_Selector* aSelector = aView->GetSelector()){
882 // const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
883 // SALOME_ListIteratorOfListIO anIter(aListIO);
884 // for(; anIter.More(); anIter.Next()){
885 // Handle(SALOME_InteractiveObject) anIO = anIter.Value();
886 // _PTR(Study) aStudy = HEXABLOCKGUI::activeStudy()->studyDS();
887 // _PTR(SObject) aSObj = aStudy->FindObjectID( anEntry.toStdString().c_str() );
888 // LightApp_DataObject* o = HEXABLOCKGUI::activeStudy()->findObjectByEntry(anEntry.toStdString().c_str());
895 // void PatternDataSelectionModel::test()
897 // if (myBusy) return;
900 // SALOME_ListIO aList;
901 // mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
903 // if (aList.Extent() == 1) {
904 // Handle(SALOME_InteractiveObject) anIO = aList.First();
905 // myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
908 // if (SMESH::GetNameOfSelectedNodes(activeViewWindow,anIO,aText) == 1) {
909 // if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
910 // if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
912 // myId->setText(aText);
913 // myX->SetValue(aNode->X());
914 // myY->SetValue(aNode->Y());
915 // myZ->SetValue(aNode->Z());
917 // erasePreview(); // avoid overlapping of a selection and a preview
931 // SUIT_DataOwnerPtrList aOList;
932 // LightApp_DataOwner* anOwher = new LightApp_DataOwner( "0:1:1:1:2" );
933 // aOList.append( anOwher );
934 // _salomeSelectionMgr->setSelected( aOList, false );
937 // void PatternDataSelectionModel::highlightGEOM( const QModelIndex & anEltIndex )
939 // std::cout << "PatternDataSelectionModel::highlightGEOM go find ASSOCIATION for"<< anEltIndex.data().toString().toStdString()<<std::endl;
940 // // HEXABLOCKGUI::currentDocGView->getViewWindow()
942 // QList<DocumentModel::GeomObj> assocList;
944 // DocumentModel *docModel = NULL;
945 // const QSortFilterProxyModel *pModel = NULL;
946 // // const QStandardItemModel *smodel
947 // // const QAbstractItemModel *theModel = NULL;
949 // pModel = dynamic_cast<const QSortFilterProxyModel *>( model() );
951 // std::cout << "pModel "<< pModel << std::endl;
953 // std::cout << "if ( pModel ){"<< std::endl;
954 // docModel = dynamic_cast<DocumentModel*>( pModel->sourceModel() );
956 // std::cout << "if ( docModel ){"<< std::endl;
957 // assocList = docModel->getAssociations( pModel->mapToSource(anEltIndex) );
962 // _PTR(Study) aStudy = GetActiveStudyDocument();
963 // _PTR(SObject) aSChild;
964 // CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
965 // GEOM::GEOM_Object_var assoc;
966 // // foreach( const QString& entry, geomEntries ){
976 // QVariant treeVariant = pModel->mapToSource(anEltIndex).data( HEXA_TREE_ROLE );
978 // if ( !treeVariant.isValid() ) return;
979 // eltType = treeVariant.toInt();
981 // // GEOM::GeomObjPtr
982 // // GEOM::GEOM_Object_ptr firstLine; //firstLine.nullify();//
983 // GEOM::GEOM_Object_var firstLine = GEOM::GEOM_Object::_nil(); //GEOM::GeomObjPtr
984 // GEOM::GEOM_Object_var lastLine = GEOM::GEOM_Object::_nil();
985 // double firstParameter = 0.2; //CS_TODO
986 // double lastParameter = 0.4; //CS_TODO
988 // foreach( const DocumentModel::GeomObj& anAssoc, assocList ){
989 // std::cout << "FOUND=> " << anAssoc.entry.toStdString() << std::endl;
990 // aSChild = aStudy->FindObjectID( anAssoc.entry.toStdString() );
991 // aCorbaObj = corbaObj(aSChild);
992 // assoc = GEOM::GEOM_Object::_narrow(aCorbaObj);
994 // if ( !CORBA::is_nil(assoc) ){
995 // std::cout << "geom to highlight =>" << anAssoc.name.toStdString() << std::endl;
996 // // objects.push_back(assoc._retn());
997 // // if ( eltType == EDGE_TREE ){
998 // // if ( CORBA::is_nil(firstLine) ){
999 // // firstLine = GEOM::GEOM_Object::_duplicate( assoc._retn() );
1001 // // lastLine = GEOM::GEOM_Object::_duplicate( assoc._retn() );
1003 // displayPreview( assoc._retn(),
1004 // true, //false, //append,
1005 // false,//true, //false, //activate,
1006 // false,//true,//update,
1008 // 1,//-1,//displayMode,
1009 // Quantity_NOC_RED );
1011 // std::cout << "not a geom =>" << anAssoc.name.toStdString()<< std::endl;
1014 // // std::cout << "CORBA::is_nil(firstLine) =>" << CORBA::is_nil(firstLine) << std::endl;
1015 // // std::cout << "CORBA::is_nil(lastLine) =>" << CORBA::is_nil(lastLine) << std::endl;
1016 // // std::cout << "test" << ( !( CORBA::is_nil(firstLine) and !CORBA::is_nil(lastLine) ) ) << std::endl;
1018 // if ( !( CORBA::is_nil(firstLine) and !CORBA::is_nil(lastLine) ) ){
1019 // GEOM::GEOM_IBasicOperations_var anOper = _geomEngine->GetIBasicOperations( getStudyId() );
1020 // GEOM::GEOM_Object_var firstPoint = anOper->MakePointOnCurve( firstLine, firstParameter );
1021 // GEOM::GEOM_Object_var lastPoint = anOper->MakePointOnCurve( lastLine, lastParameter );
1023 // // std::cout << "firstPoint->_is_nil() =>" << firstPoint->_is_nil() << std::endl;
1024 // std::cout << "lastPoint->_is_nil() =>" << lastPoint->_is_nil() << std::endl;
1025 // if ( !( CORBA::is_nil(firstPoint) ) )// !firstPoint->_is_nil() )
1026 // displayPreview( firstPoint._retn(), true );
1027 // if ( !( CORBA::is_nil(lastPoint) ) )//if ( !lastPoint->_is_nil() )
1028 // displayPreview( lastPoint._retn(), true );