1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_WidgetPoint2d.h"
10 #include "PartSet_Tools.h"
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 #include <ModuleBase_ModelWidget.h>
18 #include <XGUI_ModuleConnector.h>
19 #include <XGUI_PropertyPanel.h>
21 #include <ModuleBase_IViewer.h>
22 #include <ModuleBase_IWorkshop.h>
23 #include <ModuleBase_IViewWindow.h>
24 #include <ModuleBase_Operation.h>
25 #include <ModuleBase_ISelection.h>
26 #include <ModuleBase_IPropertyPanel.h>
27 #include <ModuleBase_Operation.h>
29 #include <GeomDataAPI_Point2D.h>
31 #include <Events_Loop.h>
33 #include <SketchPlugin_Line.h>
34 #include <SketchPlugin_Sketch.h>
35 #include <SketchPlugin_Point.h>
36 #include <SketchPlugin_Arc.h>
37 #include <SketchPlugin_Circle.h>
38 #include <SketchPlugin_ConstraintLength.h>
39 #include <SketchPlugin_ConstraintDistance.h>
40 #include <SketchPlugin_ConstraintParallel.h>
41 #include <SketchPlugin_ConstraintPerpendicular.h>
42 #include <SketchPlugin_ConstraintRadius.h>
43 #include <SketchPlugin_ConstraintRigid.h>
45 #include <SelectMgr_IndexedMapOfOwner.hxx>
46 #include <StdSelect_BRepOwner.hxx>
48 #include <ModelAPI_Events.h>
50 #include <QMouseEvent>
51 #include <QApplication>
54 /// Returns list of unique objects by sum of objects from List1 and List2
55 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
56 const QList<ModuleBase_ViewerPrs>& theList2)
58 QList<ModuleBase_ViewerPrs> aRes;
59 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
60 if (!aRes.contains(aPrs))
63 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
64 if (!aRes.contains(aPrs))
70 void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
71 QMap<FeaturePtr, QList<AttributePtr> >& theFeature2AttributeMap,
72 const FeaturePtr theSketch)
74 QList<ModuleBase_ViewerPrs> aRes;
76 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
77 aLast = theList.end();
78 for (; anIt != aLast; anIt++)
80 ModuleBase_ViewerPrs aPrs = *anIt;
81 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
82 if (aFeature.get() == NULL)
85 QList<AttributePtr> anAttributes;
86 if (theFeature2AttributeMap.contains(aFeature)) {
87 anAttributes = theFeature2AttributeMap[aFeature];
90 TopoDS_Shape aShape = aPrs.shape();
91 if (!aShape.IsNull()) {
92 if (aShape.ShapeType() == TopAbs_VERTEX) {
93 anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
94 if (anAttr.get() != NULL && !anAttributes.contains(anAttr))
95 anAttributes.push_back(anAttr);
98 theFeature2AttributeMap[aFeature] = anAttributes;
105 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
106 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false)
108 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
109 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
111 myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
113 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
114 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
116 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
117 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
119 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
120 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
122 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
123 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
125 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
126 XGUI_Workshop* aWorkshop = aConnector->workshop();
127 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
130 PartSet_SketcherMgr::~PartSet_SketcherMgr()
132 if (!myPlaneFilter.IsNull())
133 myPlaneFilter.Nullify();
136 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
138 get2dPoint(theWnd, theEvent, myClickedPoint);
141 if (!(theEvent->buttons() & Qt::LeftButton))
144 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
145 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
146 // Use only for sketch operations
147 if (aOperation && myCurrentSketch) {
148 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
151 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
152 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
154 // Avoid non-sketch operations
155 if ((!isSketchOpe) && (!isSketcher))
158 bool isEditing = aOperation->isEditOperation();
160 // Ignore creation sketch operation
161 if ((!isSketcher) && (!isEditing))
164 // MoveTo in order to highlight current object
165 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
166 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
168 // Remember highlighted objects for editing
169 ModuleBase_ISelection* aSelect = aWorkshop->selection();
170 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
171 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
172 myFeature2AttributeMap.clear();
174 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
176 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
177 fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
180 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
183 if (myFeature2AttributeMap.empty()) {
184 if (isSketchOpe && (!isSketcher))
185 // commit previous operation
186 if (!aOperation->commit())
194 get2dPoint(theWnd, theEvent, myCurrentPoint);
198 } else if (isSketchOpe && isEditing) {
199 // If selected another object commit current result
200 aOperation->commit();
203 get2dPoint(theWnd, theEvent, myCurrentPoint);
206 // This is necessary in order to finalize previous operation
207 QApplication::processEvents();
213 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
215 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
216 ModuleBase_Operation* aOp = aWorkshop->currentOperation();
219 if (!sketchOperationIdList().contains(aOp->id()))
222 get2dPoint(theWnd, theEvent, myClickedPoint);
224 // Only for sketcher operations
225 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
227 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
228 myIsDragging = false;
231 myFeature2AttributeMap.clear();
233 // Reselect edited object
234 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
235 if (theEvent->modifiers() & Qt::ShiftModifier)
236 aViewer->AISContext()->ShiftSelect();
238 aViewer->AISContext()->Select();
245 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
247 myClickedPoint.clear();
250 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
251 // 1. it is necessary to save current selection in order to restore it after the features moving
252 FeatureToSelectionMap aCurrentSelection;
253 getCurrentSelection(myFeature2AttributeMap, myCurrentSketch, aWorkshop, aCurrentSelection);
255 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
256 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
257 // deselected). This flag should be restored in the slot, processed the mouse release signal.
258 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
259 aViewer->enableSelection(false);
261 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
262 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
263 return; // No edit operation activated
265 Handle(V3d_View) aView = theWnd->v3dView();
266 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
268 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
269 double dX = aX - myCurrentPoint.myCurX;
270 double dY = aY - myCurrentPoint.myCurY;
272 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
273 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
274 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
275 // viewer happens by deselect/select the modified objects. The flag should be restored after
276 // the selection processing. The update viewer should be also called.
277 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
279 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
280 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
282 FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
283 aLast = myFeature2AttributeMap.end();
284 // 4. the features and attributes modification(move)
285 for (; anIt != aLast; anIt++) {
286 FeaturePtr aFeature = anIt.key();
288 AttributeList anAttributes = anIt.value();
289 // Process selection by attribute: the priority to the attribute
290 if (!anAttributes.empty()) {
291 AttributeList::const_iterator anAttIt = anAttributes.begin(), anAttLast = anAttributes.end();
292 for (; anAttIt != anAttLast; anAttIt++) {
293 AttributePtr anAttr = *anAttIt;
294 if (anAttr.get() == NULL)
296 std::string aAttrId = anAttr->id();
297 DataPtr aData = aFeature->data();
298 if (aData.get() != NULL) {
299 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
300 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
301 if (aPoint.get() != NULL) {
302 bool isImmutable = aPoint->setImmutable(true);
303 aPoint->move(dX, dY);
304 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
305 aPoint->setImmutable(isImmutable);
310 // Process selection by feature
311 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
312 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
313 if (aSketchFeature) {
314 aSketchFeature->move(dX, dY);
315 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
319 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
320 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
322 // 5. it is necessary to save current selection in order to restore it after the features moving
323 FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
324 aSLast = aCurrentSelection.end();
325 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
326 for (; aSIt != aSLast; aSIt++) {
327 anOwnersToSelect.Clear();
328 getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
330 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
333 // 6. restore the update viewer flag and call this update
334 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
335 aDisplayer->updateViewer();
337 myCurrentPoint.setValue(aX, aY);
341 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
343 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
344 if (aOperation && aOperation->isEditOperation()) {
345 std::string aId = aOperation->id().toStdString();
346 if (isDistanceOperation(aOperation))
348 // Activate dimension value editing on double click
349 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
350 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
351 // Find corresponded widget to activate value editing
352 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
353 if (aWgt->attributeID() == "ConstraintValue") {
362 void PartSet_SketcherMgr::onApplicationStarted()
364 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
365 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
366 XGUI_Workshop* aWorkshop = aConnector->workshop();
367 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
368 if (aPropertyPanel) {
369 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
370 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
374 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
376 if (!myClickedPoint.myIsInitialized)
379 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
380 // the distance constraint feature should not use the clickedd point
381 // this is workaround in order to don't throw down the flyout point value,
382 // set by execute() method of these type of features
383 if (isDistanceOperation(aOperation))
386 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
388 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
392 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) const
394 std::string aId = theOperation ? theOperation->id().toStdString() : "";
396 return (aId == SketchPlugin_ConstraintLength::ID()) ||
397 (aId == SketchPlugin_ConstraintDistance::ID()) ||
398 (aId == SketchPlugin_ConstraintRadius::ID());
401 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
404 Handle(V3d_View) aView = theWnd->v3dView();
405 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
407 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
408 thePoint.setValue(aX, anY);
411 void PartSet_SketcherMgr::launchEditing()
413 // there should be activate the vertex selection mode because the edit can happens by the selected
416 aModes << TopAbs_VERTEX << TopAbs_EDGE;
417 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
418 aConnector->activateSubShapesSelection(aModes);
420 if (!myFeature2AttributeMap.empty()) {
421 FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
422 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
423 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
425 myModule->editFeature(aSPFeature);
432 QStringList PartSet_SketcherMgr::sketchOperationIdList()
434 static QStringList aIds;
435 if (aIds.size() == 0) {
436 aIds << SketchPlugin_Line::ID().c_str();
437 aIds << SketchPlugin_Point::ID().c_str();
438 aIds << SketchPlugin_Arc::ID().c_str();
439 aIds << SketchPlugin_Circle::ID().c_str();
440 aIds << SketchPlugin_ConstraintLength::ID().c_str();
441 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
442 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
443 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
444 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
445 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
450 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
452 // Display all sketcher sub-Objects
453 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
454 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
455 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
457 // Hide sketcher result
458 std::list<ResultPtr> aResults = myCurrentSketch->results();
459 std::list<ResultPtr>::const_iterator aIt;
460 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
461 aDisplayer->erase((*aIt), false);
463 aDisplayer->erase(myCurrentSketch, false);
465 // Display sketcher objects
466 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
467 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
468 std::list<ResultPtr> aResults = aFeature->results();
469 std::list<ResultPtr>::const_iterator aIt;
470 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
471 aDisplayer->display((*aIt), false);
473 aDisplayer->display(aFeature, false);
476 if (myPlaneFilter.IsNull())
477 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
479 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
480 if (theOperation->isEditOperation()) {
481 // If it is editing of sketch then it means that plane is already defined
482 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
483 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
485 aDisplayer->updateViewer();
488 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
490 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
491 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
493 DataPtr aData = myCurrentSketch->data();
494 if ((!aData) || (!aData->isValid())) {
495 // The sketch was aborted
496 myCurrentSketch = CompositeFeaturePtr();
497 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
499 // Erase all sketcher objects
500 QStringList aSketchIds = sketchOperationIdList();
501 QObjectPtrList aObjects = aDisplayer->displayedObjects();
502 foreach (ObjectPtr aObj, aObjects) {
503 DataPtr aObjData = aObj->data();
504 if ((!aObjData) || (!aObjData->isValid()))
505 aDisplayer->erase(aObj);
509 // Hide all sketcher sub-Objects
510 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
511 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
512 std::list<ResultPtr> aResults = aFeature->results();
513 std::list<ResultPtr>::const_iterator aIt;
514 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
515 aDisplayer->erase((*aIt), false);
517 aDisplayer->erase(aFeature, false);
519 // Display sketcher result
520 std::list<ResultPtr> aResults = myCurrentSketch->results();
521 std::list<ResultPtr>::const_iterator aIt;
522 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
523 aDisplayer->display((*aIt), false);
525 aDisplayer->display(myCurrentSketch);
527 myCurrentSketch = CompositeFeaturePtr();
528 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
529 aDisplayer->updateViewer();
533 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
535 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
538 void PartSet_SketcherMgr::getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
539 const FeaturePtr& theSketch,
540 ModuleBase_IWorkshop* theWorkshop,
541 FeatureToSelectionMap& theSelection)
543 FeatureToAttributesMap::const_iterator anIt = theFeatureToAttributes.begin(),
544 aLast = theFeatureToAttributes.end();
545 for (; anIt != aLast; anIt++) {
546 FeaturePtr aFeature = anIt.key();
547 getCurrentSelection(aFeature, theSketch, theWorkshop, theSelection);
551 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
552 const FeaturePtr& theSketch,
553 ModuleBase_IWorkshop* theWorkshop,
554 FeatureToSelectionMap& theSelection)
556 if (theFeature.get() == NULL)
559 std::set<AttributePtr> aSelectedAttributes;
560 std::set<ResultPtr> aSelectedResults;
562 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
563 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
564 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
565 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
567 std::list<ResultPtr> aResults = theFeature->results();
568 std::list<ResultPtr>::const_iterator aIt;
569 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
571 ResultPtr aResult = *aIt;
572 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
573 if (aAISObj.get() == NULL)
575 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
576 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
578 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
579 aContext->SelectedOwner());
580 if (aBRepOwner.IsNull())
582 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
583 aBRepOwner->Selectable());
587 if (aBRepOwner->HasShape()) {
588 const TopoDS_Shape& aShape = aBRepOwner->Shape();
589 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
590 if (aShapeType == TopAbs_VERTEX) {
591 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
593 if (aPntAttr.get() != NULL)
594 aSelectedAttributes.insert(aPntAttr);
596 else if (aShapeType == TopAbs_EDGE &&
597 aSelectedResults.find(aResult) == aSelectedResults.end()) {
598 aSelectedResults.insert(aResult);
603 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
606 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
607 const FeaturePtr& theSketch,
608 ModuleBase_IWorkshop* theWorkshop,
609 const FeatureToSelectionMap& theSelection,
610 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
612 if (theFeature.get() == NULL)
615 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
616 std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
617 std::set<ResultPtr> aSelectedResults = anIt->second.second;
619 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
620 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
621 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
622 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
624 std::list<ResultPtr> aResults = theFeature->results();
625 std::list<ResultPtr>::const_iterator aIt;
626 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
628 ResultPtr aResult = *aIt;
629 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
630 if (aAISObj.get() == NULL)
632 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
634 SelectMgr_IndexedMapOfOwner aSelectedOwners;
635 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
636 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
637 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
638 if ( anOwner.IsNull() || !anOwner->HasShape() )
640 const TopoDS_Shape& aShape = anOwner->Shape();
641 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
642 if (aShapeType == TopAbs_VERTEX) {
643 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
644 if (aPntAttr.get() != NULL &&
645 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
646 anOwnersToSelect.Add(anOwner);
649 else if (aShapeType == TopAbs_EDGE) {
650 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
651 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
652 anOwnersToSelect.FindIndex(anOwner) <= 0)
653 anOwnersToSelect.Add(anOwner);