-/*QFeatureList XGUI_SelectionMgr::selectedFeatures() const
- {
- return myWorkshop->objectBrowser()->selectedFeatures();
- }
-
- //**************************************************************
- QModelIndexList XGUI_SelectionMgr::selectedIndexes() const
- {
- return myWorkshop->objectBrowser()->selectedIndexes();
- }
-
- //**************************************************************
- void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
- {
- Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
- theList.Clear();
- for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
- theList.Append(aContext->SelectedInteractive());
- }
-
- //**************************************************************
- void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
- {
- theList.Clear();
- Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
- for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
- TopoDS_Shape aShape = aContext->SelectedShape();
- if (!aShape.IsNull())
- theList.Append(aShape);
- }
- }*/
+void XGUI_SelectionMgr::convertToObjectBrowserSelection(
+ const QList<ModuleBase_ViewerPrsPtr>& theValues,
+ QObjectPtrList& theObjects)
+{
+ theObjects.clear();
+
+ ResultPtr aResult;
+ FeaturePtr aFeature;
+ bool aHasOperation = (myWorkshop->operationMgr()->currentOperation() != 0);
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr anActiveDocument = aMgr->activeDocument();
+
+ TopTools_MapOfShape aShapeMap;
+ bool aToOptimize = (theValues.size() > OPTIMIZATION_LEVEL);
+
+ GeomShapePtr aShape;
+ TopoDS_Shape aTShape;
+ foreach(ModuleBase_ViewerPrsPtr aPrs, theValues) {
+ if (aPrs->object().get()) {
+ if (!theObjects.contains(aPrs->object()))
+ theObjects.append(aPrs->object());
+ if (aPrs->shape().get() && (!aHasOperation)) {
+ aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
+ if (aResult.get()) {
+ aShape = aPrs->shape();
+ aTShape = aShape->impl<TopoDS_Shape>();
+ if (aToOptimize) {
+ if (!aShapeMap.Contains(aTShape)) {
+ aFeature = anActiveDocument->producedByFeature(aResult, aShape);
+ if (aFeature.get()) {
+ QList<TopoDS_Shape> aResList = findAllShapes(aResult);
+ foreach(TopoDS_Shape aResShape, aResList) {
+ if (!aShapeMap.Contains(aResShape))
+ aShapeMap.Add(aResShape);
+ }
+ }
+ }
+ }
+ else {
+ aFeature = anActiveDocument->producedByFeature(aResult, aShape);
+ }
+ if (aFeature.get() && (!theObjects.contains(aFeature)))
+ theObjects.append(aFeature);
+ }
+ }
+ }
+ }
+}
+
+std::list<FeaturePtr> XGUI_SelectionMgr::getSelectedFeatures()
+{
+ std::list<FeaturePtr> aFeatures;
+ QObjectPtrList aObjects = selection()->selectedObjects();
+ if (aObjects.isEmpty())
+ return aFeatures;
+
+ bool isPart = false;
+ foreach(ObjectPtr aObj, aObjects) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature.get()) {
+ ResultPtr aRes = aFeature->firstResult();
+ isPart = (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group()));
+ if (!isPart)
+ aFeatures.push_back(aFeature);
+ }
+ }
+ return aFeatures;
+}
+
+QList<TopoDS_Shape> XGUI_SelectionMgr::findAllShapes(const ResultPtr& theResult) const
+{
+ QIntList aModes = myWorkshop->selectionActivate()->activeSelectionModes();
+ GeomShapePtr aResShape = theResult->shape();
+ TopoDS_Shape aShape = aResShape->impl<TopoDS_Shape>();
+ QList<TopoDS_Shape> aResult;
+ foreach(int aShapeType, aModes) {
+ if (aShapeType < TopAbs_SHAPE) {
+ TopExp_Explorer aExp(aShape, (TopAbs_ShapeEnum)aShapeType);
+ for (; aExp.More(); aExp.Next()) {
+ aResult.append(aExp.Current());
+ }
+ }
+ }
+ return aResult;
+}
\ No newline at end of file