X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_SelectionMgr.cpp;h=df975ca9578ec657acc5aff23c8213248225ff67;hb=1a972d24c2f891d8ae3e3b8cfe324339d28602bc;hp=0bba0d847e44253acc5379e70d42b3c64deef85b;hpb=b79d895f103e77d30d0f1bf2114b3750a746ed94;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp old mode 100644 new mode 100755 index 0bba0d847..df975ca95 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -1,97 +1,176 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + #include "XGUI_SelectionMgr.h" + #include "XGUI_Workshop.h" -#include "XGUI_MainWindow.h" #include "XGUI_ObjectsBrowser.h" -#include "XGUI_Viewer.h" #include "XGUI_SalomeConnector.h" +#include "XGUI_ViewerProxy.h" +#include "XGUI_Displayer.h" +#include "XGUI_Selection.h" + +#ifndef HAVE_SALOME +#include +#endif #include -#include +#include #include #include +#include +#include +#include + +#include +#include +#include +#ifdef VINSPECTOR +#include +#endif -XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) : - QObject(theParent), myWorkshop(theParent) +XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) + : QObject(theParent), + myWorkshop(theParent) { + mySelection = new XGUI_Selection(myWorkshop); } XGUI_SelectionMgr::~XGUI_SelectionMgr() { + delete mySelection; } //************************************************************** void XGUI_SelectionMgr::connectViewers() { - connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), - this, SLOT(onObjectBrowserSelection())); + connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this, + SLOT(onObjectBrowserSelection())); //Connect to other viewers - if (myWorkshop->isSalomeMode()) { - connect(myWorkshop, SIGNAL(salomeViewerSelection()), - this, SLOT(onViewerSelection())); - } else { - connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()), - this, SLOT(onViewerSelection())); - } + connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection())); } //************************************************************** -void XGUI_SelectionMgr::onObjectBrowserSelection() +void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners, + bool isUpdateViewer) { + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (!aContext.IsNull()) { + /// previous selection should be cleared, else there will be decomposition of selections: + /// as AddOrRemoveSelected inverts current selection + aContext->ClearSelected(false); - // TODO: Highliht selected objects in Viewer 3d + for (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++) { + Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i); - emit selectionChanged(); + aContext->AddOrRemoveSelected(anOwner, isUpdateViewer); + #ifdef VINSPECTOR + if (myWorkshop->displayer()->getCallBack()) + myWorkshop->displayer()->getCallBack()->AddOrRemoveSelected(anOwner); + #endif + } + } } //************************************************************** -void XGUI_SelectionMgr::onViewerSelection() +void XGUI_SelectionMgr::onObjectBrowserSelection() { - // TODO: Highliht selected objects in Object Browser + QList aSelectedPrs = + myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser); + + QList aTmpList = aSelectedPrs; + ObjectPtr aObject; + FeaturePtr aFeature; + foreach(ModuleBase_ViewerPrsPtr aPrs, aTmpList) { + aObject = aPrs->object(); + if (aObject.get()) { + aFeature = std::dynamic_pointer_cast(aObject); + if (aFeature.get()) { + const std::list> aResList = aFeature->results(); + ResultPtr aResult; + ResultCompSolidPtr aCompSolid; + std::list::const_iterator aIt; + for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { + aResult = (*aIt); + aSelectedPrs.append(std::shared_ptr( + new ModuleBase_ViewerPrs(aResult, GeomShapePtr(), NULL))); + aCompSolid = std::dynamic_pointer_cast(aResult); + if (aCompSolid.get()) { + for (int i = 0; i < aCompSolid->numberOfSubs(); i++) { + ResultBodyPtr aResult = aCompSolid->subResult(i); + aSelectedPrs.append(std::shared_ptr( + new ModuleBase_ViewerPrs(aResult, aResult->shape(), NULL))); + } + } + } + } + } + } + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->setSelected(aSelectedPrs); emit selectionChanged(); } //************************************************************** -QFeatureList XGUI_SelectionMgr::selectedFeatures() const -{ - return myWorkshop->objectBrowser()->selectedFeatures(); -} +void XGUI_SelectionMgr::onViewerSelection() +{ + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr anActiveDocument = aMgr->activeDocument(); + QObjectPtrList aFeatures; + ResultPtr aResult; + FeaturePtr aFeature; + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (!aContext.IsNull()) { + QList aPresentations = + selection()->getSelected(ModuleBase_ISelection::Viewer); + foreach(ModuleBase_ViewerPrsPtr aPrs, aPresentations) { + if (aPrs->object().get()) { + if (!aFeatures.contains(aPrs->object())) + aFeatures.append(aPrs->object()); + if (aPrs->shape().get()) { + aResult = std::dynamic_pointer_cast(aPrs->object()); + if (aResult.get()) { + aFeature = anActiveDocument->producedByFeature(aResult, aPrs->shape()); + if (aFeature.get() && (!aFeatures.contains(aFeature))) + aFeatures.append(aFeature); + } + } + } + } + } + bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); + myWorkshop->objectBrowser()->setObjectsSelected(aFeatures); + myWorkshop->objectBrowser()->blockSignals(aBlocked); -//************************************************************** -QModelIndexList XGUI_SelectionMgr::selectedIndexes() const -{ - return myWorkshop->objectBrowser()->selectionModel()->selectedIndexes(); + emit selectionChanged(); } //************************************************************** -void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const +void XGUI_SelectionMgr::updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace) { - if (myWorkshop->isSalomeMode()) { - Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeConnector()->AISContext(); - theList.Clear(); - for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) - theList.Append(aContext->SelectedInteractive()); - } else { - XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); - aViewer->getSelectedObjects(theList); + QList aSelectedPrs = + myWorkshop->selector()->selection()->getSelected(thePlace); + if (thePlace == ModuleBase_ISelection::Browser) { + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->setSelected(aSelectedPrs); } -} +} //************************************************************** -void XGUI_SelectionMgr::selectedShapes(NCollection_List& theList) const +void XGUI_SelectionMgr::clearSelection() { - if (myWorkshop->isSalomeMode()) { - theList.Clear(); - Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeConnector()->AISContext(); - for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { - TopoDS_Shape aShape = aContext->SelectedShape(); - if (!aShape.IsNull()) - theList.Append(aShape); - } - } else { - XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); - aViewer->getSelectedShapes(theList); - } -} \ No newline at end of file + QObjectPtrList aFeatures; + bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); + myWorkshop->objectBrowser()->setObjectsSelected(aFeatures); + myWorkshop->objectBrowser()->blockSignals(aBlocked); + + QList aSelectedPrs = + myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser); + + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->setSelected(aSelectedPrs); + + emit selectionChanged(); +}