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