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