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