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 <AIS_DimensionSelectionMode.hxx>
49 //#include <AIS_Shape.hxx>
51 #include <ModelAPI_Events.h>
53 #include <QMouseEvent>
54 #include <QApplication>
57 /// Returns list of unique objects by sum of objects from List1 and List2
58 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
59 const QList<ModuleBase_ViewerPrs>& theList2)
61 QList<ModuleBase_ViewerPrs> aRes;
62 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
63 if (!aRes.contains(aPrs))
66 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
67 if (!aRes.contains(aPrs))
73 void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
74 QMap<FeaturePtr, QList<AttributePtr> >& theFeature2AttributeMap,
75 const FeaturePtr theSketch)
77 QList<ModuleBase_ViewerPrs> aRes;
79 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
80 aLast = theList.end();
81 for (; anIt != aLast; anIt++)
83 ModuleBase_ViewerPrs aPrs = *anIt;
84 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
85 if (aFeature.get() == NULL)
88 QList<AttributePtr> anAttributes;
89 if (theFeature2AttributeMap.contains(aFeature)) {
90 anAttributes = theFeature2AttributeMap[aFeature];
93 TopoDS_Shape aShape = aPrs.shape();
94 if (!aShape.IsNull()) {
95 if (aShape.ShapeType() == TopAbs_VERTEX) {
96 anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
97 if (anAttr.get() != NULL && !anAttributes.contains(anAttr))
98 anAttributes.push_back(anAttr);
101 theFeature2AttributeMap[aFeature] = anAttributes;
108 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
109 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false)
111 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
112 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
114 myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
116 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
117 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
119 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
120 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
122 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
123 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
125 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
126 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
128 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
129 XGUI_Workshop* aWorkshop = aConnector->workshop();
130 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
133 PartSet_SketcherMgr::~PartSet_SketcherMgr()
135 if (!myPlaneFilter.IsNull())
136 myPlaneFilter.Nullify();
139 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
141 get2dPoint(theWnd, theEvent, myClickedPoint);
143 if (!(theEvent->buttons() & Qt::LeftButton))
146 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
147 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
148 if (aOperation && aOperation->isEditOperation()) {
149 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
150 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
151 // If the current widget is a selector, do do nothing, it processes the mouse press
152 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
157 // Clear dragging mode
158 myIsDragging = false;
160 // Use only for sketch operations
161 if (aOperation && myCurrentSketch) {
162 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
165 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
166 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
168 // Avoid non-sketch operations
169 if ((!isSketchOpe) && (!isSketcher))
172 bool isEditing = aOperation->isEditOperation();
174 // Ignore creation sketch operation
175 if ((!isSketcher) && (!isEditing))
178 // MoveTo in order to highlight current object
179 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
180 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
182 // Remember highlighted objects for editing
183 ModuleBase_ISelection* aSelect = aWorkshop->selection();
184 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
185 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
186 myFeature2AttributeMap.clear();
188 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
190 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
191 fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
194 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
197 if (myFeature2AttributeMap.empty()) {
198 if (isSketchOpe && (!isSketcher))
199 // commit previous operation
200 if (!aOperation->commit())
207 get2dPoint(theWnd, theEvent, myCurrentPoint);
211 } else if (isSketchOpe && isEditing) {
212 // If selected another object commit current result
213 aOperation->commit();
216 get2dPoint(theWnd, theEvent, myCurrentPoint);
219 // This is necessary in order to finalize previous operation
220 QApplication::processEvents();
226 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
228 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
229 ModuleBase_Operation* aOp = aWorkshop->currentOperation();
231 if (sketchOperationIdList().contains(aOp->id())) {
232 get2dPoint(theWnd, theEvent, myClickedPoint);
234 // Only for sketcher operations
235 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
239 myFeature2AttributeMap.clear();
241 // Reselect edited object
242 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
243 if (theEvent->modifiers() & Qt::ShiftModifier)
244 aViewer->AISContext()->ShiftSelect();
246 aViewer->AISContext()->Select();
252 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
253 myIsDragging = false;
256 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
258 myClickedPoint.clear();
261 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
262 // 1. it is necessary to save current selection in order to restore it after the features moving
263 FeatureToSelectionMap aCurrentSelection;
264 getCurrentSelection(myFeature2AttributeMap, myCurrentSketch, aWorkshop, aCurrentSelection);
266 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
267 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
268 // deselected). This flag should be restored in the slot, processed the mouse release signal.
269 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
270 aViewer->enableSelection(false);
272 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
275 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
276 return; // No edit operation activated
278 Handle(V3d_View) aView = theWnd->v3dView();
279 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
281 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
282 double dX = aX - myCurrentPoint.myCurX;
283 double dY = aY - myCurrentPoint.myCurY;
285 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
286 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
287 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
288 // viewer happens by deselect/select the modified objects. The flag should be restored after
289 // the selection processing. The update viewer should be also called.
290 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
292 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
293 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
295 FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
296 aLast = myFeature2AttributeMap.end();
297 // 4. the features and attributes modification(move)
298 for (; anIt != aLast; anIt++) {
299 FeaturePtr aFeature = anIt.key();
301 AttributeList anAttributes = anIt.value();
302 // Process selection by attribute: the priority to the attribute
303 if (!anAttributes.empty()) {
304 AttributeList::const_iterator anAttIt = anAttributes.begin(), anAttLast = anAttributes.end();
305 for (; anAttIt != anAttLast; anAttIt++) {
306 AttributePtr anAttr = *anAttIt;
307 if (anAttr.get() == NULL)
309 std::string aAttrId = anAttr->id();
310 DataPtr aData = aFeature->data();
311 if (aData.get() != NULL) {
312 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
313 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
314 if (aPoint.get() != NULL) {
315 bool isImmutable = aPoint->setImmutable(true);
316 aPoint->move(dX, dY);
317 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
318 aPoint->setImmutable(isImmutable);
323 // Process selection by feature
324 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
325 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
326 if (aSketchFeature) {
327 aSketchFeature->move(dX, dY);
328 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
332 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
333 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
335 // 5. it is necessary to save current selection in order to restore it after the features moving
336 FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
337 aSLast = aCurrentSelection.end();
338 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
339 for (; aSIt != aSLast; aSIt++) {
340 anOwnersToSelect.Clear();
341 getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
343 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
346 // 6. restore the update viewer flag and call this update
347 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
348 aDisplayer->updateViewer();
350 myCurrentPoint.setValue(aX, aY);
354 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
356 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
357 if (aOperation && aOperation->isEditOperation()) {
358 std::string aId = aOperation->id().toStdString();
359 if (isDistanceOperation(aOperation))
361 // Activate dimension value editing on double click
362 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
363 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
364 // Find corresponded widget to activate value editing
365 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
366 if (aWgt->attributeID() == "ConstraintValue") {
375 void PartSet_SketcherMgr::onApplicationStarted()
377 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
378 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
379 XGUI_Workshop* aWorkshop = aConnector->workshop();
380 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
381 if (aPropertyPanel) {
382 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
383 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
387 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
389 if (!myClickedPoint.myIsInitialized)
392 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
393 // the distance constraint feature should not use the clickedd point
394 // this is workaround in order to don't throw down the flyout point value,
395 // set by execute() method of these type of features
396 if (isDistanceOperation(aOperation))
399 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
401 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
405 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) const
407 std::string aId = theOperation ? theOperation->id().toStdString() : "";
409 return (aId == SketchPlugin_ConstraintLength::ID()) ||
410 (aId == SketchPlugin_ConstraintDistance::ID()) ||
411 (aId == SketchPlugin_ConstraintRadius::ID());
414 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
417 Handle(V3d_View) aView = theWnd->v3dView();
418 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
420 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
421 thePoint.setValue(aX, anY);
424 void PartSet_SketcherMgr::launchEditing()
426 // there should be activate the vertex selection mode because the edit can happens by the selected
429 aModes << TopAbs_VERTEX << TopAbs_EDGE;
430 // TODO: #391 - to be uncommented
431 /*aModes.append(AIS_DSM_Text);
432 aModes.append(AIS_DSM_Line);
433 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
434 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));*/
436 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
437 aConnector->activateSubShapesSelection(aModes);
439 if (!myFeature2AttributeMap.empty()) {
440 FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
441 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
442 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
444 myModule->editFeature(aSPFeature);
451 QStringList PartSet_SketcherMgr::sketchOperationIdList()
453 static QStringList aIds;
454 if (aIds.size() == 0) {
455 aIds << SketchPlugin_Line::ID().c_str();
456 aIds << SketchPlugin_Point::ID().c_str();
457 aIds << SketchPlugin_Arc::ID().c_str();
458 aIds << SketchPlugin_Circle::ID().c_str();
459 aIds << SketchPlugin_ConstraintLength::ID().c_str();
460 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
461 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
462 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
463 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
464 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
469 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
471 // Display all sketcher sub-Objects
472 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
473 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
474 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
476 // Hide sketcher result
477 std::list<ResultPtr> aResults = myCurrentSketch->results();
478 std::list<ResultPtr>::const_iterator aIt;
479 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
480 aDisplayer->erase((*aIt), false);
482 aDisplayer->erase(myCurrentSketch, false);
484 // Display sketcher objects
485 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
486 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
487 std::list<ResultPtr> aResults = aFeature->results();
488 std::list<ResultPtr>::const_iterator aIt;
489 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
490 aDisplayer->display((*aIt), false);
492 aDisplayer->display(aFeature, false);
495 if (myPlaneFilter.IsNull())
496 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
498 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
499 if (theOperation->isEditOperation()) {
500 // If it is editing of sketch then it means that plane is already defined
501 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
502 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
504 aDisplayer->updateViewer();
507 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
509 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
510 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
512 DataPtr aData = myCurrentSketch->data();
513 if ((!aData) || (!aData->isValid())) {
514 // The sketch was aborted
515 myCurrentSketch = CompositeFeaturePtr();
516 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
518 // Erase all sketcher objects
519 QStringList aSketchIds = sketchOperationIdList();
520 QObjectPtrList aObjects = aDisplayer->displayedObjects();
521 foreach (ObjectPtr aObj, aObjects) {
522 DataPtr aObjData = aObj->data();
523 if ((!aObjData) || (!aObjData->isValid()))
524 aDisplayer->erase(aObj);
528 // Hide all sketcher sub-Objects
529 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
530 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
531 std::list<ResultPtr> aResults = aFeature->results();
532 std::list<ResultPtr>::const_iterator aIt;
533 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
534 aDisplayer->erase((*aIt), false);
536 aDisplayer->erase(aFeature, false);
538 // Display sketcher result
539 std::list<ResultPtr> aResults = myCurrentSketch->results();
540 std::list<ResultPtr>::const_iterator aIt;
541 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
542 aDisplayer->display((*aIt), false);
544 aDisplayer->display(myCurrentSketch);
546 myCurrentSketch = CompositeFeaturePtr();
547 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
548 aDisplayer->updateViewer();
552 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
554 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
557 void PartSet_SketcherMgr::getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
558 const FeaturePtr& theSketch,
559 ModuleBase_IWorkshop* theWorkshop,
560 FeatureToSelectionMap& theSelection)
562 FeatureToAttributesMap::const_iterator anIt = theFeatureToAttributes.begin(),
563 aLast = theFeatureToAttributes.end();
564 for (; anIt != aLast; anIt++) {
565 FeaturePtr aFeature = anIt.key();
566 getCurrentSelection(aFeature, theSketch, theWorkshop, theSelection);
570 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
571 const FeaturePtr& theSketch,
572 ModuleBase_IWorkshop* theWorkshop,
573 FeatureToSelectionMap& theSelection)
575 if (theFeature.get() == NULL)
578 std::set<AttributePtr> aSelectedAttributes;
579 std::set<ResultPtr> aSelectedResults;
581 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
582 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
583 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
584 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
586 std::list<ResultPtr> aResults = theFeature->results();
587 std::list<ResultPtr>::const_iterator aIt;
588 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
590 ResultPtr aResult = *aIt;
591 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
592 if (aAISObj.get() == NULL)
594 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
595 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
597 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
598 aContext->SelectedOwner());
599 if (aBRepOwner.IsNull())
601 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
602 aBRepOwner->Selectable());
606 if (aBRepOwner->HasShape()) {
607 const TopoDS_Shape& aShape = aBRepOwner->Shape();
608 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
609 if (aShapeType == TopAbs_VERTEX) {
610 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
612 if (aPntAttr.get() != NULL)
613 aSelectedAttributes.insert(aPntAttr);
615 else if (aShapeType == TopAbs_EDGE &&
616 aSelectedResults.find(aResult) == aSelectedResults.end()) {
617 aSelectedResults.insert(aResult);
622 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
625 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
626 const FeaturePtr& theSketch,
627 ModuleBase_IWorkshop* theWorkshop,
628 const FeatureToSelectionMap& theSelection,
629 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
631 if (theFeature.get() == NULL)
634 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
635 std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
636 std::set<ResultPtr> aSelectedResults = anIt->second.second;
638 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
639 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
640 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
641 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
643 std::list<ResultPtr> aResults = theFeature->results();
644 std::list<ResultPtr>::const_iterator aIt;
645 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
647 ResultPtr aResult = *aIt;
648 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
649 if (aAISObj.get() == NULL)
651 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
653 SelectMgr_IndexedMapOfOwner aSelectedOwners;
654 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
655 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
656 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
657 if ( anOwner.IsNull() || !anOwner->HasShape() )
659 const TopoDS_Shape& aShape = anOwner->Shape();
660 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
661 if (aShapeType == TopAbs_VERTEX) {
662 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
663 if (aPntAttr.get() != NULL &&
664 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
665 anOwnersToSelect.Add(anOwner);
668 else if (aShapeType == TopAbs_EDGE) {
669 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
670 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
671 anOwnersToSelect.FindIndex(anOwner) <= 0)
672 anOwnersToSelect.Add(anOwner);