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 // Clear dragging mode
145 myIsDragging = false;
147 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
148 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
149 // Use only for sketch operations
150 if (aOperation && myCurrentSketch) {
151 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
154 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
155 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
157 // Avoid non-sketch operations
158 if ((!isSketchOpe) && (!isSketcher))
161 bool isEditing = aOperation->isEditOperation();
163 // Ignore creation sketch operation
164 if ((!isSketcher) && (!isEditing))
167 // MoveTo in order to highlight current object
168 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
169 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
171 // Remember highlighted objects for editing
172 ModuleBase_ISelection* aSelect = aWorkshop->selection();
173 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
174 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
175 myFeature2AttributeMap.clear();
177 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
179 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
180 fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
183 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
186 if (myFeature2AttributeMap.empty()) {
187 if (isSketchOpe && (!isSketcher))
188 // commit previous operation
189 if (!aOperation->commit())
196 get2dPoint(theWnd, theEvent, myCurrentPoint);
200 } else if (isSketchOpe && isEditing) {
201 // If selected another object commit current result
202 aOperation->commit();
205 get2dPoint(theWnd, theEvent, myCurrentPoint);
208 // This is necessary in order to finalize previous operation
209 QApplication::processEvents();
215 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
217 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
218 ModuleBase_Operation* aOp = aWorkshop->currentOperation();
220 if (sketchOperationIdList().contains(aOp->id())) {
221 get2dPoint(theWnd, theEvent, myClickedPoint);
223 // Only for sketcher operations
224 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
228 myFeature2AttributeMap.clear();
230 // Reselect edited object
231 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
232 if (theEvent->modifiers() & Qt::ShiftModifier)
233 aViewer->AISContext()->ShiftSelect();
235 aViewer->AISContext()->Select();
241 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
242 myIsDragging = false;
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();
264 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
265 return; // No edit operation activated
267 Handle(V3d_View) aView = theWnd->v3dView();
268 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
270 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
271 double dX = aX - myCurrentPoint.myCurX;
272 double dY = aY - myCurrentPoint.myCurY;
274 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
275 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
276 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
277 // viewer happens by deselect/select the modified objects. The flag should be restored after
278 // the selection processing. The update viewer should be also called.
279 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
281 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
282 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
284 FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
285 aLast = myFeature2AttributeMap.end();
286 // 4. the features and attributes modification(move)
287 for (; anIt != aLast; anIt++) {
288 FeaturePtr aFeature = anIt.key();
290 AttributeList anAttributes = anIt.value();
291 // Process selection by attribute: the priority to the attribute
292 if (!anAttributes.empty()) {
293 AttributeList::const_iterator anAttIt = anAttributes.begin(), anAttLast = anAttributes.end();
294 for (; anAttIt != anAttLast; anAttIt++) {
295 AttributePtr anAttr = *anAttIt;
296 if (anAttr.get() == NULL)
298 std::string aAttrId = anAttr->id();
299 DataPtr aData = aFeature->data();
300 if (aData.get() != NULL) {
301 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
302 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
303 if (aPoint.get() != NULL) {
304 bool isImmutable = aPoint->setImmutable(true);
305 aPoint->move(dX, dY);
306 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
307 aPoint->setImmutable(isImmutable);
312 // Process selection by feature
313 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
314 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
315 if (aSketchFeature) {
316 aSketchFeature->move(dX, dY);
317 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
321 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
322 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
324 // 5. it is necessary to save current selection in order to restore it after the features moving
325 FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
326 aSLast = aCurrentSelection.end();
327 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
328 for (; aSIt != aSLast; aSIt++) {
329 anOwnersToSelect.Clear();
330 getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
332 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
335 // 6. restore the update viewer flag and call this update
336 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
337 aDisplayer->updateViewer();
339 myCurrentPoint.setValue(aX, aY);
343 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
345 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
346 if (aOperation && aOperation->isEditOperation()) {
347 std::string aId = aOperation->id().toStdString();
348 if (isDistanceOperation(aOperation))
350 // Activate dimension value editing on double click
351 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
352 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
353 // Find corresponded widget to activate value editing
354 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
355 if (aWgt->attributeID() == "ConstraintValue") {
364 void PartSet_SketcherMgr::onApplicationStarted()
366 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
367 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
368 XGUI_Workshop* aWorkshop = aConnector->workshop();
369 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
370 if (aPropertyPanel) {
371 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
372 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
376 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
378 if (!myClickedPoint.myIsInitialized)
381 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
382 // the distance constraint feature should not use the clickedd point
383 // this is workaround in order to don't throw down the flyout point value,
384 // set by execute() method of these type of features
385 if (isDistanceOperation(aOperation))
388 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
390 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
394 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) const
396 std::string aId = theOperation ? theOperation->id().toStdString() : "";
398 return (aId == SketchPlugin_ConstraintLength::ID()) ||
399 (aId == SketchPlugin_ConstraintDistance::ID()) ||
400 (aId == SketchPlugin_ConstraintRadius::ID());
403 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
406 Handle(V3d_View) aView = theWnd->v3dView();
407 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
409 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
410 thePoint.setValue(aX, anY);
413 void PartSet_SketcherMgr::launchEditing()
415 // there should be activate the vertex selection mode because the edit can happens by the selected
418 aModes << TopAbs_VERTEX << TopAbs_EDGE;
419 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
420 aConnector->activateSubShapesSelection(aModes);
422 if (!myFeature2AttributeMap.empty()) {
423 FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
424 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
425 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
427 myModule->editFeature(aSPFeature);
434 QStringList PartSet_SketcherMgr::sketchOperationIdList()
436 static QStringList aIds;
437 if (aIds.size() == 0) {
438 aIds << SketchPlugin_Line::ID().c_str();
439 aIds << SketchPlugin_Point::ID().c_str();
440 aIds << SketchPlugin_Arc::ID().c_str();
441 aIds << SketchPlugin_Circle::ID().c_str();
442 aIds << SketchPlugin_ConstraintLength::ID().c_str();
443 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
444 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
445 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
446 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
447 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
452 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
454 // Display all sketcher sub-Objects
455 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
456 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
457 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
459 // Hide sketcher result
460 std::list<ResultPtr> aResults = myCurrentSketch->results();
461 std::list<ResultPtr>::const_iterator aIt;
462 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
463 aDisplayer->erase((*aIt), false);
465 aDisplayer->erase(myCurrentSketch, false);
467 // Display sketcher objects
468 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
469 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
470 std::list<ResultPtr> aResults = aFeature->results();
471 std::list<ResultPtr>::const_iterator aIt;
472 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
473 aDisplayer->display((*aIt), false);
475 aDisplayer->display(aFeature, false);
478 if (myPlaneFilter.IsNull())
479 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
481 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
482 if (theOperation->isEditOperation()) {
483 // If it is editing of sketch then it means that plane is already defined
484 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
485 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
487 aDisplayer->updateViewer();
490 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
492 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
493 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
495 DataPtr aData = myCurrentSketch->data();
496 if ((!aData) || (!aData->isValid())) {
497 // The sketch was aborted
498 myCurrentSketch = CompositeFeaturePtr();
499 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
501 // Erase all sketcher objects
502 QStringList aSketchIds = sketchOperationIdList();
503 QObjectPtrList aObjects = aDisplayer->displayedObjects();
504 foreach (ObjectPtr aObj, aObjects) {
505 DataPtr aObjData = aObj->data();
506 if ((!aObjData) || (!aObjData->isValid()))
507 aDisplayer->erase(aObj);
511 // Hide all sketcher sub-Objects
512 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
513 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
514 std::list<ResultPtr> aResults = aFeature->results();
515 std::list<ResultPtr>::const_iterator aIt;
516 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
517 aDisplayer->erase((*aIt), false);
519 aDisplayer->erase(aFeature, false);
521 // Display sketcher result
522 std::list<ResultPtr> aResults = myCurrentSketch->results();
523 std::list<ResultPtr>::const_iterator aIt;
524 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
525 aDisplayer->display((*aIt), false);
527 aDisplayer->display(myCurrentSketch);
529 myCurrentSketch = CompositeFeaturePtr();
530 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
531 aDisplayer->updateViewer();
535 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
537 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
540 void PartSet_SketcherMgr::getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
541 const FeaturePtr& theSketch,
542 ModuleBase_IWorkshop* theWorkshop,
543 FeatureToSelectionMap& theSelection)
545 FeatureToAttributesMap::const_iterator anIt = theFeatureToAttributes.begin(),
546 aLast = theFeatureToAttributes.end();
547 for (; anIt != aLast; anIt++) {
548 FeaturePtr aFeature = anIt.key();
549 getCurrentSelection(aFeature, theSketch, theWorkshop, theSelection);
553 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
554 const FeaturePtr& theSketch,
555 ModuleBase_IWorkshop* theWorkshop,
556 FeatureToSelectionMap& theSelection)
558 if (theFeature.get() == NULL)
561 std::set<AttributePtr> aSelectedAttributes;
562 std::set<ResultPtr> aSelectedResults;
564 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
565 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
566 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
567 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
569 std::list<ResultPtr> aResults = theFeature->results();
570 std::list<ResultPtr>::const_iterator aIt;
571 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
573 ResultPtr aResult = *aIt;
574 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
575 if (aAISObj.get() == NULL)
577 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
578 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
580 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
581 aContext->SelectedOwner());
582 if (aBRepOwner.IsNull())
584 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
585 aBRepOwner->Selectable());
589 if (aBRepOwner->HasShape()) {
590 const TopoDS_Shape& aShape = aBRepOwner->Shape();
591 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
592 if (aShapeType == TopAbs_VERTEX) {
593 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
595 if (aPntAttr.get() != NULL)
596 aSelectedAttributes.insert(aPntAttr);
598 else if (aShapeType == TopAbs_EDGE &&
599 aSelectedResults.find(aResult) == aSelectedResults.end()) {
600 aSelectedResults.insert(aResult);
605 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
608 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
609 const FeaturePtr& theSketch,
610 ModuleBase_IWorkshop* theWorkshop,
611 const FeatureToSelectionMap& theSelection,
612 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
614 if (theFeature.get() == NULL)
617 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
618 std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
619 std::set<ResultPtr> aSelectedResults = anIt->second.second;
621 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
622 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
623 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
624 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
626 std::list<ResultPtr> aResults = theFeature->results();
627 std::list<ResultPtr>::const_iterator aIt;
628 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
630 ResultPtr aResult = *aIt;
631 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
632 if (aAISObj.get() == NULL)
634 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
636 SelectMgr_IndexedMapOfOwner aSelectedOwners;
637 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
638 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
639 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
640 if ( anOwner.IsNull() || !anOwner->HasShape() )
642 const TopoDS_Shape& aShape = anOwner->Shape();
643 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
644 if (aShapeType == TopAbs_VERTEX) {
645 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
646 if (aPntAttr.get() != NULL &&
647 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
648 anOwnersToSelect.Add(anOwner);
651 else if (aShapeType == TopAbs_EDGE) {
652 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
653 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
654 anOwnersToSelect.FindIndex(anOwner) <= 0)
655 anOwnersToSelect.Add(anOwner);