Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_SketcherMgr.cpp
4 // Created:     19 Dec 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_WidgetPoint2D.h"
10 #include "PartSet_Tools.h"
11
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>
17
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>
25
26 #include <GeomDataAPI_Point2D.h>
27
28 #include <Events_Loop.h>
29
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>
41
42 #include <SelectMgr_IndexedMapOfOwner.hxx>
43 #include <StdSelect_BRepOwner.hxx>
44
45 #include <ModelAPI_Events.h>
46
47 #include <QMouseEvent>
48 #include <QApplication>
49
50
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)
54 {
55   QList<ModuleBase_ViewerPrs> aRes;
56   foreach (ModuleBase_ViewerPrs aPrs, theList1) {
57     if (!aRes.contains(aPrs))
58       aRes.append(aPrs);
59   }
60   foreach (ModuleBase_ViewerPrs aPrs, theList2) {
61     if (!aRes.contains(aPrs))
62       aRes.append(aPrs);
63   }
64   return aRes;
65 }*/
66
67 void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
68                            QMap<FeaturePtr, QList<AttributePtr> >& theFeature2AttributeMap,
69                            const FeaturePtr theSketch)
70 {
71   QList<ModuleBase_ViewerPrs> aRes;
72
73   QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
74                                               aLast = theList.end();
75   for (; anIt != aLast; anIt++)
76   {
77     ModuleBase_ViewerPrs aPrs = *anIt;
78     FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
79     if (aFeature.get() == NULL)
80       continue;
81
82     QList<AttributePtr> anAttributes;
83     if (theFeature2AttributeMap.contains(aFeature)) {
84       anAttributes = theFeature2AttributeMap[aFeature];
85     }
86     AttributePtr anAttr;
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);
93       }
94     }
95     theFeature2AttributeMap[aFeature] = anAttributes;
96   }
97 }
98
99
100
101
102 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
103   : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false)
104 {
105   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
106   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
107
108   myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
109
110   connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
111           this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
112
113   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
114           this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
115
116   connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
117           this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
118
119   connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
120           this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
121 }
122
123 PartSet_SketcherMgr::~PartSet_SketcherMgr()
124 {
125   if (!myPlaneFilter.IsNull())
126     myPlaneFilter.Nullify();
127 }
128
129 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
130 {
131   // 
132   if (!(theEvent->buttons() & Qt::LeftButton))
133     return;
134
135   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
136   ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
137   // Use only for sketch operations
138   if (aOperation && myCurrentSketch) {
139     if (!PartSet_Tools::sketchPlane(myCurrentSketch))
140       return;
141
142     bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
143     bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
144
145     // Avoid non-sketch operations
146     if ((!isSketchOpe) && (!isSketcher))
147       return;
148
149     bool isEditing = aOperation->isEditOperation();
150
151     // Ignore creation sketch operation
152     if ((!isSketcher) && (!isEditing))
153       return;
154
155     // MoveTo in order to highlight current object
156     ModuleBase_IViewer* aViewer = aWorkshop->viewer();
157     aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
158
159     // Remember highlighted objects for editing
160     ModuleBase_ISelection* aSelect = aWorkshop->selection();
161     QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
162     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
163     myFeature2AttributeMap.clear();
164
165     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
166     if (aHasShift) {
167       fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
168       fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
169     }
170     else {
171       fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
172     }
173
174     if (myFeature2AttributeMap.empty()) {
175       if (isSketchOpe && (!isSketcher))
176         // commit previous operation
177         if (!aOperation->commit())
178           aOperation->abort();
179       return;
180     }
181
182     if (isSketcher) {
183       myIsDragging = true;
184
185       get2dPoint(theWnd, theEvent, myCurX, myCurY);
186       myDragDone = false;
187       aWorkshop->viewer()->enableMultiselection(false);
188       launchEditing();
189
190     } else if (isSketchOpe && isEditing) {
191       // If selected another object commit current result
192       aOperation->commit();
193
194       myIsDragging = true;
195       get2dPoint(theWnd, theEvent, myCurX, myCurY);
196       myDragDone = false;
197       aWorkshop->viewer()->enableMultiselection(false);
198
199       // This is necessary in order to finalize previous operation
200       QApplication::processEvents();
201       launchEditing();
202     }
203   }
204 }
205
206 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
207 {
208   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
209   ModuleBase_Operation* aOp = aWorkshop->currentOperation();
210   if (!aOp)
211     return;
212   if (!sketchOperationIdList().contains(aOp->id()))
213     return;
214
215   // Only for sketcher operations
216   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
217   if (myIsDragging) {
218     aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
219     myIsDragging = false;
220     if (myDragDone) {
221       aViewer->enableMultiselection(true);
222       //aOp->commit();
223       myFeature2AttributeMap.clear();
224       return;
225     }
226   }
227   if (!aViewer->isMultiSelectionEnabled()) {
228     aViewer->enableMultiselection(true);
229   }
230 }
231
232 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
233 {
234   if (myIsDragging) {
235     // the selection should be switched off in order to do not deselect moved objects by the 
236     // mouse release
237     ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
238     aViewer->enableSelection(false);
239
240     ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
241     if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
242       return; // No edit operation activated
243
244     Handle(V3d_View) aView = theWnd->v3dView();
245     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
246     double aX, aY;
247     PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
248     double dX =  aX - myCurX;
249     double dY =  aY - myCurY;
250
251     ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
252     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
253     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
254     bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
255
256     static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
257     //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
258
259     FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
260                                            aLast = myFeature2AttributeMap.end();
261     FeatureToSelectionMap aCurrentSelection;
262     for (; anIt != aLast; anIt++) {
263       FeaturePtr aFeature = anIt.key();
264       AttributePtr anAttr;
265
266       AttributeList anAttributes = anIt.value();
267       if (!anAttributes.empty()) {
268         anAttr = anAttributes.first();
269       }
270
271       // save the previous selection
272       getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, aCurrentSelection);
273       // save the previous selection: end
274
275       // Process selection by attribute: the priority to the 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);
287           }
288         }
289       } else {
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         }
297       }
298     }
299     Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
300     //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
301
302     // restore the previous selection
303     FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
304                                           aSLast = aCurrentSelection.end();
305     SelectMgr_IndexedMapOfOwner anOwnersToSelect;
306     for (; aSIt != aSLast; aSIt++) {
307       anOwnersToSelect.Clear();
308       getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
309                          anOwnersToSelect);
310       aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
311     }
312     // restore the previous selection: end
313
314     aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
315     aDisplayer->updateViewer();
316     myDragDone = true;
317     myCurX = aX;
318     myCurY = aY;
319   }
320 }
321
322 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
323 {
324   ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
325   if (aOperation && aOperation->isEditOperation()) {
326     std::string aId = aOperation->id().toStdString();
327     if ((aId == SketchPlugin_ConstraintLength::ID()) ||
328       (aId == SketchPlugin_ConstraintDistance::ID()) ||
329       (aId == SketchPlugin_ConstraintRadius::ID())) 
330     {
331       // Activate dimension value editing on double click
332       ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
333       QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
334       // Find corresponded widget to activate value editing
335       foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
336         if (aWgt->attributeID() == "ConstraintValue") {
337           aWgt->focusTo();
338           return;
339         }
340       }
341     }
342   }
343 }
344
345 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
346                                 double& theX, double& theY)
347 {
348   Handle(V3d_View) aView = theWnd->v3dView();
349   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
350   PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
351 }
352
353 void PartSet_SketcherMgr::launchEditing()
354 {
355   // there should be activate the vertex selection mode because the edit can happens by the selected
356   // point
357   QIntList aModes;
358   aModes << TopAbs_VERTEX << TopAbs_EDGE;
359   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
360   aConnector->activateSubShapesSelection(aModes);
361
362   if (!myFeature2AttributeMap.empty()) {
363     FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
364     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
365               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
366     if (aSPFeature) {
367       myModule->editFeature(aSPFeature);
368     }
369   }
370  
371 }
372
373
374 QStringList PartSet_SketcherMgr::sketchOperationIdList()
375 {
376   static QStringList aIds;
377   if (aIds.size() == 0) {
378     aIds << SketchPlugin_Line::ID().c_str();
379     aIds << SketchPlugin_Point::ID().c_str();
380     aIds << SketchPlugin_Arc::ID().c_str();
381     aIds << SketchPlugin_Circle::ID().c_str();
382     aIds << SketchPlugin_ConstraintLength::ID().c_str();
383     aIds << SketchPlugin_ConstraintDistance::ID().c_str();
384     aIds << SketchPlugin_ConstraintRigid::ID().c_str();
385     aIds << SketchPlugin_ConstraintRadius::ID().c_str();
386     aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
387     aIds << SketchPlugin_ConstraintParallel::ID().c_str();
388   }
389   return aIds;
390 }
391
392 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
393 {
394   // Display all sketcher sub-Objects
395   myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
396   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
397   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
398
399   // Hide sketcher result
400   std::list<ResultPtr> aResults = myCurrentSketch->results();
401   std::list<ResultPtr>::const_iterator aIt;
402   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
403     aDisplayer->erase((*aIt), false);
404   }
405   aDisplayer->erase(myCurrentSketch, false);
406
407   // Display sketcher objects
408   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
409     FeaturePtr aFeature = myCurrentSketch->subFeature(i);
410     std::list<ResultPtr> aResults = aFeature->results();
411     std::list<ResultPtr>::const_iterator aIt;
412     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
413       aDisplayer->display((*aIt), false);
414     }
415     aDisplayer->display(aFeature, false);
416   }
417
418   if (myPlaneFilter.IsNull()) 
419     myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
420
421   myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
422   if (theOperation->isEditOperation()) {
423     // If it is editing of sketch then it means that plane is already defined
424     std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
425     myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
426   }
427   aDisplayer->updateViewer();
428 }
429
430 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
431 {
432   DataPtr aData = myCurrentSketch->data();
433   if ((!aData) || (!aData->isValid())) {
434     // The sketch was aborted
435     myCurrentSketch = CompositeFeaturePtr();
436     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
437     return; 
438   }
439   // Hide all sketcher sub-Objects
440   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
441   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
442   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
443     FeaturePtr aFeature = myCurrentSketch->subFeature(i);
444     std::list<ResultPtr> aResults = aFeature->results();
445     std::list<ResultPtr>::const_iterator aIt;
446     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
447       aDisplayer->erase((*aIt), false);
448     }
449     aDisplayer->erase(aFeature, false);
450   }
451   // Display sketcher result
452   std::list<ResultPtr> aResults = myCurrentSketch->results();
453   std::list<ResultPtr>::const_iterator aIt;
454   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
455     aDisplayer->display((*aIt), false);
456   }
457   aDisplayer->display(myCurrentSketch);
458     
459   myCurrentSketch = CompositeFeaturePtr();
460   myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
461   aDisplayer->updateViewer();
462 }
463
464
465 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
466 {
467   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
468 }
469
470 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
471                                               const FeaturePtr& theSketch,
472                                               ModuleBase_IWorkshop* theWorkshop,
473                                               FeatureToSelectionMap& theSelection)
474                                               //std::set<AttributePtr>& theSelectedAttributes,
475                                               //std::set<ResultPtr>& theSelectedResults)
476 {
477   if (theFeature.get() == NULL)
478     return;
479
480   std::set<AttributePtr> aSelectedAttributes;
481   std::set<ResultPtr> aSelectedResults;
482
483   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
484   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
485   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
486   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
487
488   std::list<ResultPtr> aResults = theFeature->results();
489   std::list<ResultPtr>::const_iterator aIt;
490   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
491   {
492     ResultPtr aResult = *aIt;
493     AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
494     if (aAISObj.get() == NULL)
495       continue;
496     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
497     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
498     {
499       Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
500                                                                       aContext->SelectedOwner());
501       if (aBRepOwner.IsNull())
502         continue;
503       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
504                                                                         aBRepOwner->Selectable());
505       if (aBRepOwner->HasShape()) {
506         const TopoDS_Shape& aShape = aBRepOwner->Shape();
507         TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
508         if (aShapeType == TopAbs_VERTEX) {
509           AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
510                                                                         aShape, theSketch);
511           if (aPntAttr.get() != NULL)
512             aSelectedAttributes.insert(aPntAttr);
513         }
514         else if (aShapeType == TopAbs_EDGE &&
515                  aSelectedResults.find(aResult) == aSelectedResults.end()) {
516           aSelectedResults.insert(aResult);
517         }
518       }
519     }
520   }
521   theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
522 }
523
524 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
525                                              const FeaturePtr& theSketch,
526                                              ModuleBase_IWorkshop* theWorkshop,
527                                              //const std::set<AttributePtr>& theSelectedAttributes,
528                                              //const std::set<ResultPtr>& theSelectedResults,
529                                              const FeatureToSelectionMap& theSelection,
530                                              SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
531 {
532   if (theFeature.get() == NULL)
533     return;
534
535   FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
536   std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
537   std::set<ResultPtr> aSelectedResults = anIt->second.second;
538
539   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
540   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
541   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
542   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
543
544   std::list<ResultPtr> aResults = theFeature->results();
545   std::list<ResultPtr>::const_iterator aIt;
546   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
547   {
548     ResultPtr aResult = *aIt;
549     AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
550     if (aAISObj.get() == NULL)
551       continue; 
552     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
553
554     SelectMgr_IndexedMapOfOwner aSelectedOwners;  
555     aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
556     for  ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
557       Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
558       if ( anOwner.IsNull() || !anOwner->HasShape() )
559         continue;
560       const TopoDS_Shape& aShape = anOwner->Shape();
561       TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
562       if (aShapeType == TopAbs_VERTEX) {
563         AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
564         if (aPntAttr.get() != NULL &&
565             aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
566           anOwnersToSelect.Add(anOwner);
567         }
568       }
569       else if (aShapeType == TopAbs_EDGE) {
570         bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
571         if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
572             anOwnersToSelect.FindIndex(anOwner) <= 0)
573           anOwnersToSelect.Add(anOwner);
574       }
575     }
576   }
577 }