+
+void PartSet_SketcherMgr::getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
+ const FeaturePtr& theSketch,
+ ModuleBase_IWorkshop* theWorkshop,
+ FeatureToSelectionMap& theSelection)
+{
+ FeatureToAttributesMap::const_iterator anIt = theFeatureToAttributes.begin(),
+ aLast = theFeatureToAttributes.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = anIt.key();
+ getCurrentSelection(aFeature, theSketch, theWorkshop, theSelection);
+ }
+}
+
+void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
+ const FeaturePtr& theSketch,
+ ModuleBase_IWorkshop* theWorkshop,
+ FeatureToSelectionMap& theSelection)
+{
+ if (theFeature.get() == NULL)
+ return;
+
+ std::set<AttributePtr> aSelectedAttributes;
+ std::set<ResultPtr> aSelectedResults;
+
+ ModuleBase_IViewer* aViewer = theWorkshop->viewer();
+ Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
+ XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+ std::list<ResultPtr> aResults = theFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
+ {
+ ResultPtr aResult = *aIt;
+ AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
+ if (aAISObj.get() == NULL)
+ continue;
+ Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+ for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
+ {
+ Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
+ aContext->SelectedOwner());
+ if (aBRepOwner.IsNull())
+ continue;
+ Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
+ aBRepOwner->Selectable());
+ if (anIO != anAISIO)
+ continue;
+
+ if (aBRepOwner->HasShape()) {
+ const TopoDS_Shape& aShape = aBRepOwner->Shape();
+ TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+ if (aShapeType == TopAbs_VERTEX) {
+ AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
+ aShape, theSketch);
+ if (aPntAttr.get() != NULL)
+ aSelectedAttributes.insert(aPntAttr);
+ }
+ else if (aShapeType == TopAbs_EDGE &&
+ aSelectedResults.find(aResult) == aSelectedResults.end()) {
+ aSelectedResults.insert(aResult);
+ }
+ }
+ }
+ }
+ theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
+}
+
+void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
+ const FeaturePtr& theSketch,
+ ModuleBase_IWorkshop* theWorkshop,
+ const FeatureToSelectionMap& theSelection,
+ SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
+{
+ if (theFeature.get() == NULL)
+ return;
+
+ FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
+ std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
+ std::set<ResultPtr> aSelectedResults = anIt->second.second;
+
+ ModuleBase_IViewer* aViewer = theWorkshop->viewer();
+ Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
+ XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+ std::list<ResultPtr> aResults = theFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
+ {
+ ResultPtr aResult = *aIt;
+ AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
+ if (aAISObj.get() == NULL)
+ continue;
+ Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+
+ SelectMgr_IndexedMapOfOwner aSelectedOwners;
+ aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
+ for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
+ Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
+ if ( anOwner.IsNull() || !anOwner->HasShape() )
+ continue;
+ const TopoDS_Shape& aShape = anOwner->Shape();
+ TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+ if (aShapeType == TopAbs_VERTEX) {
+ AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
+ if (aPntAttr.get() != NULL &&
+ aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
+ anOwnersToSelect.Add(anOwner);
+ }
+ }
+ else if (aShapeType == TopAbs_EDGE) {
+ bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
+ if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
+ anOwnersToSelect.FindIndex(anOwner) <= 0)
+ anOwnersToSelect.Add(anOwner);
+ }
+ }
+ }
+}