1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_WidgetPoint2D.h"
10 #include "PartSet_Tools.h"
12 #include <XGUI_ModuleConnector.h>
13 #include <XGUI_Displayer.h>
14 #include <XGUI_Workshop.h>
15 #include <XGUI_Selection.h>
16 #include <XGUI_SelectionMgr.h>
18 #include <ModuleBase_IViewer.h>
19 #include <ModuleBase_IWorkshop.h>
20 #include <ModuleBase_IViewWindow.h>
21 #include <ModuleBase_Operation.h>
22 #include <ModuleBase_ISelection.h>
23 #include <ModuleBase_IPropertyPanel.h>
24 #include <ModuleBase_Operation.h>
26 #include <GeomDataAPI_Point2D.h>
28 #include <Events_Loop.h>
30 #include <SketchPlugin_Line.h>
31 #include <SketchPlugin_Sketch.h>
32 #include <SketchPlugin_Point.h>
33 #include <SketchPlugin_Arc.h>
34 #include <SketchPlugin_Circle.h>
35 #include <SketchPlugin_ConstraintLength.h>
36 #include <SketchPlugin_ConstraintDistance.h>
37 #include <SketchPlugin_ConstraintParallel.h>
38 #include <SketchPlugin_ConstraintPerpendicular.h>
39 #include <SketchPlugin_ConstraintRadius.h>
40 #include <SketchPlugin_ConstraintRigid.h>
42 #include <SelectMgr_IndexedMapOfOwner.hxx>
43 #include <StdSelect_BRepOwner.hxx>
45 #include <ModelAPI_Events.h>
47 #include <QMouseEvent>
48 #include <QApplication>
51 /// Returns list of unique objects by sum of objects from List1 and List2
52 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
53 const QList<ModuleBase_ViewerPrs>& theList2)
55 QList<ModuleBase_ViewerPrs> aRes;
56 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
57 if (!aRes.contains(aPrs))
60 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
61 if (!aRes.contains(aPrs))
67 void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
68 QMap<FeaturePtr, QList<AttributePtr> >& theFeature2AttributeMap,
69 const FeaturePtr theSketch)
71 QList<ModuleBase_ViewerPrs> aRes;
73 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
74 aLast = theList.end();
75 for (; anIt != aLast; anIt++)
77 ModuleBase_ViewerPrs aPrs = *anIt;
78 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
79 if (aFeature.get() == NULL)
82 QList<AttributePtr> anAttributes;
83 if (theFeature2AttributeMap.contains(aFeature)) {
84 anAttributes = theFeature2AttributeMap[aFeature];
87 TopoDS_Shape aShape = aPrs.shape();
88 if (!aShape.IsNull()) {
89 if (aShape.ShapeType() == TopAbs_VERTEX) {
90 anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
91 if (anAttr.get() != NULL && !anAttributes.contains(anAttr))
92 anAttributes.push_back(anAttr);
95 theFeature2AttributeMap[aFeature] = anAttributes;
102 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
103 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false)
105 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
106 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
108 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
109 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
111 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
112 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
114 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
115 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
117 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
118 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
121 PartSet_SketcherMgr::~PartSet_SketcherMgr()
123 if (!myPlaneFilter.IsNull())
124 myPlaneFilter.Nullify();
127 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
130 if (!(theEvent->buttons() & Qt::LeftButton))
133 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
134 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
135 // Use only for sketch operations
136 if (aOperation && myCurrentSketch) {
137 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
140 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
141 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
143 // Avoid non-sketch operations
144 if ((!isSketchOpe) && (!isSketcher))
147 bool isEditing = aOperation->isEditOperation();
149 // Ignore creation sketch operation
150 if ((!isSketcher) && (!isEditing))
153 // MoveTo in order to highlight current object
154 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
155 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
157 // Remember highlighted objects for editing
158 ModuleBase_ISelection* aSelect = aWorkshop->selection();
159 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
160 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
161 myFeature2AttributeMap.clear();
163 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
165 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
166 fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
169 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
172 if (myFeature2AttributeMap.empty()) {
173 if (isSketchOpe && (!isSketcher))
174 // commit previous operation
175 if (!aOperation->commit())
182 get2dPoint(theWnd, theEvent, myCurX, myCurY);
184 aWorkshop->viewer()->enableMultiselection(false);
187 } else if (isSketchOpe && isEditing) {
188 // If selected another object commit current result
189 aOperation->commit();
192 get2dPoint(theWnd, theEvent, myCurX, myCurY);
194 aWorkshop->viewer()->enableMultiselection(false);
196 // This is necessary in order to finalize previous operation
197 QApplication::processEvents();
203 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
205 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
206 ModuleBase_Operation* aOp = aWorkshop->currentOperation();
209 if (!sketchOperationIdList().contains(aOp->id()))
212 // Only for sketcher operations
213 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
215 myIsDragging = false;
217 aViewer->enableMultiselection(true);
219 myFeature2AttributeMap.clear();
221 // Reselect edited object
222 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
223 if (theEvent->modifiers() & Qt::ShiftModifier)
224 aViewer->AISContext()->ShiftSelect();
226 aViewer->AISContext()->Select();
230 if (!aViewer->isMultiSelectionEnabled()) {
231 aViewer->enableMultiselection(true);
235 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
238 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
239 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
240 return; // No edit operation activated
242 Handle(V3d_View) aView = theWnd->v3dView();
243 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
245 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
246 double dX = aX - myCurX;
247 double dY = aY - myCurY;
249 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
250 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
251 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
252 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
254 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
255 static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
257 FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
258 aLast = myFeature2AttributeMap.end();
259 for (; anIt != aLast; anIt++) {
260 FeaturePtr aFeature = anIt.key();
263 AttributeList anAttributes = anIt.value();
264 if (!anAttributes.empty()) {
265 anAttr = anAttributes.first();
268 // save the previous selection
269 std::set<AttributePtr> aSelectedAttributes;
270 std::set<ResultPtr> aSelectedResults;
271 getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
273 // save the previous selection: end
275 // Process selection by attribute
276 if (anAttr.get() != NULL) {
277 std::string aAttrId = anAttr->id();
278 DataPtr aData = aFeature->data();
279 if (aData.get() != NULL) {
280 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
281 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
282 if (aPoint.get() != NULL) {
283 bool isImmutable = aPoint->setImmutable(true);
284 aPoint->move(dX, dY);
285 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
286 aPoint->setImmutable(isImmutable);
290 // Process selection by feature
291 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
292 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
293 if (aSketchFeature) {
294 aSketchFeature->move(dX, dY);
295 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
296 // TODO: the selection restore should be after the AIS presentation is rebuilt
299 //Events_Loop::loop()->flush(aMoveEvent);
300 //Events_Loop::loop()->flush(aUpdateEvent);
301 // restore the previous selection
302 //TODO: after the last flush
303 //SelectMgr_IndexedMapOfOwner anOwnersToSelect;
304 //getSelectionOwners(aFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
305 // aSelectedResults, anOwnersToSelect);
306 //TODO: after the last flush
307 //aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
308 // restore the previous selection
309 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent, true);
310 Events_Loop::loop()->flush(aUpdateEvent);
312 Events_Loop::loop()->flush(aMoveEvent);
313 Events_Loop::loop()->flush(aUpdateEvent);
315 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
316 aDisplayer->updateViewer();
322 //if ((myEditingAttr.size() == 1) && myEditingAttr.first()) {
323 // // probably we have prehighlighted point
324 // AttributePtr aAttr = myEditingAttr.first();
325 // std::string aAttrId = aAttr->id();
326 // ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
327 // QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
328 // // Find corresponded widget to provide dragging
329 // foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
330 // if (aWgt->attributeID() == aAttrId) {
331 // PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
333 // aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
339 // ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
340 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
341 // XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
342 // bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
344 // foreach(FeaturePtr aFeature, myEditingFeatures) {
345 // std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
346 // std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
347 // if (aSketchFeature) {
348 // // save the previous selection
350 // std::set<AttributePtr> aSelectedAttributes;
351 // std::set<ResultPtr> aSelectedResults;
352 // getCurrentSelection(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
353 // aSelectedResults);
354 // // save the previous selection: end
356 // aSketchFeature->move(dX, dY);
357 // // TODO: the selection restore should be after the AIS presentation is rebuilt
358 // Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
359 // Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
361 // // restore the previous selection
362 // SelectMgr_IndexedMapOfOwner anOwnersToSelect;
363 // getSelectionOwners(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
364 // aSelectedResults, anOwnersToSelect);
365 // aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
366 // // restore the previous selection
368 // ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent, true);
369 // Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
372 // //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
373 // //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
375 // //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
376 // aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
377 // aDisplayer->updateViewer();
380 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
382 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
383 if (aOperation && aOperation->isEditOperation()) {
384 std::string aId = aOperation->id().toStdString();
385 if ((aId == SketchPlugin_ConstraintLength::ID()) ||
386 (aId == SketchPlugin_ConstraintDistance::ID()) ||
387 (aId == SketchPlugin_ConstraintRadius::ID()))
389 // Activate dimension value editing on double click
390 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
391 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
392 // Find corresponded widget to activate value editing
393 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
394 if (aWgt->attributeID() == "ConstraintValue") {
403 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
404 double& theX, double& theY)
406 Handle(V3d_View) aView = theWnd->v3dView();
407 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
408 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
411 void PartSet_SketcherMgr::launchEditing()
413 // there should be activate the vertex selection mode because the edit can happens by the selected
416 aModes << TopAbs_VERTEX;
417 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
418 aConnector->activateSubShapesSelection(aModes);
420 if (!myFeature2AttributeMap.empty()) {
421 FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
422 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
423 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
425 myModule->editFeature(aSPFeature);
432 QStringList PartSet_SketcherMgr::sketchOperationIdList()
434 static QStringList aIds;
435 if (aIds.size() == 0) {
436 aIds << SketchPlugin_Line::ID().c_str();
437 aIds << SketchPlugin_Point::ID().c_str();
438 aIds << SketchPlugin_Arc::ID().c_str();
439 aIds << SketchPlugin_Circle::ID().c_str();
440 aIds << SketchPlugin_ConstraintLength::ID().c_str();
441 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
442 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
443 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
444 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
445 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
450 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
452 // Display all sketcher sub-Objects
453 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
454 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
455 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
457 // Hide sketcher result
458 std::list<ResultPtr> aResults = myCurrentSketch->results();
459 std::list<ResultPtr>::const_iterator aIt;
460 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
461 aDisplayer->erase((*aIt), false);
463 aDisplayer->erase(myCurrentSketch, false);
465 // Display sketcher objects
466 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
467 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
468 std::list<ResultPtr> aResults = aFeature->results();
469 std::list<ResultPtr>::const_iterator aIt;
470 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
471 aDisplayer->display((*aIt), false);
473 aDisplayer->display(aFeature, false);
476 if (myPlaneFilter.IsNull())
477 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
479 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
480 if (theOperation->isEditOperation()) {
481 // If it is editing of sketch then it means that plane is already defined
482 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
483 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
485 aDisplayer->updateViewer();
488 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
490 DataPtr aData = myCurrentSketch->data();
491 if ((!aData) || (!aData->isValid())) {
492 // The sketch was aborted
493 myCurrentSketch = CompositeFeaturePtr();
494 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
497 // Hide all sketcher sub-Objects
498 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
499 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
500 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
501 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
502 std::list<ResultPtr> aResults = aFeature->results();
503 std::list<ResultPtr>::const_iterator aIt;
504 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
505 aDisplayer->erase((*aIt), false);
507 aDisplayer->erase(aFeature, false);
509 // Display sketcher result
510 std::list<ResultPtr> aResults = myCurrentSketch->results();
511 std::list<ResultPtr>::const_iterator aIt;
512 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
513 aDisplayer->display((*aIt), false);
515 aDisplayer->display(myCurrentSketch);
517 myCurrentSketch = CompositeFeaturePtr();
518 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
519 aDisplayer->updateViewer();
523 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
525 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
528 void PartSet_SketcherMgr::getCurrentSelection(const ObjectPtr& theObject,
529 const FeaturePtr& theSketch,
530 ModuleBase_IWorkshop* theWorkshop,
531 std::set<AttributePtr>& theSelectedAttributes,
532 std::set<ResultPtr>& theSelectedResults)
534 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
535 if (aFeature.get() == NULL)
538 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
539 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
540 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
541 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
543 std::list<ResultPtr> aResults = aFeature->results();
544 std::list<ResultPtr>::const_iterator aIt;
545 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
547 ResultPtr aResult = *aIt;
548 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
549 if (aAISObj.get() == NULL)
551 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
552 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
554 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
555 aContext->SelectedOwner());
556 if (aBRepOwner.IsNull())
558 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
559 aBRepOwner->Selectable());
560 if (aBRepOwner->HasShape()) {
561 const TopoDS_Shape& aShape = aBRepOwner->Shape();
562 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
563 if (aShapeType == TopAbs_VERTEX) {
564 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theObject,
566 if (aPntAttr.get() != NULL)
567 theSelectedAttributes.insert(aPntAttr);
569 else if (aShapeType == TopAbs_EDGE &&
570 theSelectedResults.find(aResult) == theSelectedResults.end()) {
571 theSelectedResults.insert(aResult);
578 void PartSet_SketcherMgr::getSelectionOwners(const ObjectPtr& theObject,
579 const FeaturePtr& theSketch,
580 ModuleBase_IWorkshop* theWorkshop,
581 const std::set<AttributePtr>& theSelectedAttributes,
582 const std::set<ResultPtr>& theSelectedResults,
583 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
585 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
586 if (aFeature.get() == NULL)
589 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
590 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
591 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
592 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
594 std::list<ResultPtr> aResults = aFeature->results();
595 std::list<ResultPtr>::const_iterator aIt;
596 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
598 ResultPtr aResult = *aIt;
599 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
600 if (aAISObj.get() == NULL)
602 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
604 SelectMgr_IndexedMapOfOwner aSelectedOwners;
605 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
606 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
607 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
608 if ( anOwner.IsNull() || !anOwner->HasShape() )
610 const TopoDS_Shape& aShape = anOwner->Shape();
611 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
612 if (aShapeType == TopAbs_VERTEX) {
613 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
614 if (aPntAttr.get() != NULL &&
615 theSelectedAttributes.find(aPntAttr) != theSelectedAttributes.end()) {
616 anOwnersToSelect.Add(anOwner);
619 else if (aShapeType == TopAbs_EDGE) {
620 bool aFound = theSelectedResults.find(aResult) != theSelectedResults.end();
621 int anIndex = anOwnersToSelect.FindIndex(anOwner);
622 if (theSelectedResults.find(aResult) != theSelectedResults.end()/* &&
623 anOwnersToSelect.FindIndex(anOwner) < 0*/)
624 anOwnersToSelect.Add(anOwner);