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