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 // Clear dragging mode
147 myIsDragging = false;
149 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
150 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
151 if (!aViewer->canDragByMouse())
154 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
155 if (aOperation && aOperation->isEditOperation()) {
156 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
157 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
158 // If the current widget is a selector, do do nothing, it processes the mouse press
159 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
164 // Use only for sketch operations
165 if (aOperation && myCurrentSketch) {
166 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
169 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
170 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
172 // Avoid non-sketch operations
173 if ((!isSketchOpe) && (!isSketcher))
176 bool isEditing = aOperation->isEditOperation();
178 // Ignore creation sketch operation
179 if ((!isSketcher) && (!isEditing))
182 // MoveTo in order to highlight current object
183 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
185 // Remember highlighted objects for editing
186 ModuleBase_ISelection* aSelect = aWorkshop->selection();
187 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
188 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
189 myFeature2AttributeMap.clear();
191 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
193 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
194 fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
197 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
200 if (myFeature2AttributeMap.empty()) {
201 if (isSketchOpe && (!isSketcher))
202 // commit previous operation
203 if (!aOperation->commit())
210 get2dPoint(theWnd, theEvent, myCurrentPoint);
214 } else if (isSketchOpe && isEditing) {
215 // If selected another object commit current result
216 aOperation->commit();
219 get2dPoint(theWnd, theEvent, myCurrentPoint);
222 // This is necessary in order to finalize previous operation
223 QApplication::processEvents();
229 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
231 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
232 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
233 if (!aViewer->canDragByMouse())
235 ModuleBase_Operation* aOp = aWorkshop->currentOperation();
237 if (sketchOperationIdList().contains(aOp->id())) {
238 get2dPoint(theWnd, theEvent, myClickedPoint);
240 // Only for sketcher operations
244 myFeature2AttributeMap.clear();
246 // Reselect edited object
247 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
248 if (theEvent->modifiers() & Qt::ShiftModifier)
249 aViewer->AISContext()->ShiftSelect();
251 aViewer->AISContext()->Select();
257 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
258 myIsDragging = false;
261 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
263 myClickedPoint.clear();
266 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
267 // 1. it is necessary to save current selection in order to restore it after the features moving
268 FeatureToSelectionMap aCurrentSelection;
269 getCurrentSelection(myFeature2AttributeMap, myCurrentSketch, aWorkshop, aCurrentSelection);
271 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
272 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
273 // deselected). This flag should be restored in the slot, processed the mouse release signal.
274 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
275 aViewer->enableSelection(false);
277 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
280 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
281 return; // No edit operation activated
283 Handle(V3d_View) aView = theWnd->v3dView();
284 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
286 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
287 double dX = aX - myCurrentPoint.myCurX;
288 double dY = aY - myCurrentPoint.myCurY;
290 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
291 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
292 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
293 // viewer happens by deselect/select the modified objects. The flag should be restored after
294 // the selection processing. The update viewer should be also called.
295 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
297 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
298 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
300 FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
301 aLast = myFeature2AttributeMap.end();
302 // 4. the features and attributes modification(move)
303 for (; anIt != aLast; anIt++) {
304 FeaturePtr aFeature = anIt.key();
306 AttributeList anAttributes = anIt.value();
307 // Process selection by attribute: the priority to the attribute
308 if (!anAttributes.empty()) {
309 AttributeList::const_iterator anAttIt = anAttributes.begin(), anAttLast = anAttributes.end();
310 for (; anAttIt != anAttLast; anAttIt++) {
311 AttributePtr anAttr = *anAttIt;
312 if (anAttr.get() == NULL)
314 std::string aAttrId = anAttr->id();
315 DataPtr aData = aFeature->data();
316 if (aData.get() != NULL) {
317 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
318 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
319 if (aPoint.get() != NULL) {
320 bool isImmutable = aPoint->setImmutable(true);
321 aPoint->move(dX, dY);
322 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
323 aPoint->setImmutable(isImmutable);
328 // Process selection by feature
329 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
330 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
331 if (aSketchFeature) {
332 aSketchFeature->move(dX, dY);
333 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
337 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
338 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
340 // 5. it is necessary to save current selection in order to restore it after the features moving
341 FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
342 aSLast = aCurrentSelection.end();
343 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
344 for (; aSIt != aSLast; aSIt++) {
345 anOwnersToSelect.Clear();
346 getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
348 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
351 // 6. restore the update viewer flag and call this update
352 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
353 aDisplayer->updateViewer();
355 myCurrentPoint.setValue(aX, aY);
359 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
361 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
362 if (aOperation && aOperation->isEditOperation()) {
363 std::string aId = aOperation->id().toStdString();
364 if (isDistanceOperation(aOperation))
366 // Activate dimension value editing on double click
367 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
368 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
369 // Find corresponded widget to activate value editing
370 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
371 if (aWgt->attributeID() == "ConstraintValue") {
380 void PartSet_SketcherMgr::onApplicationStarted()
382 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
383 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
384 XGUI_Workshop* aWorkshop = aConnector->workshop();
385 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
386 if (aPropertyPanel) {
387 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
388 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
392 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
394 if (!myClickedPoint.myIsInitialized)
397 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
398 // the distance constraint feature should not use the clickedd point
399 // this is workaround in order to don't throw down the flyout point value,
400 // set by execute() method of these type of features
401 if (isDistanceOperation(aOperation))
404 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
406 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
410 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) const
412 std::string aId = theOperation ? theOperation->id().toStdString() : "";
414 return (aId == SketchPlugin_ConstraintLength::ID()) ||
415 (aId == SketchPlugin_ConstraintDistance::ID()) ||
416 (aId == SketchPlugin_ConstraintRadius::ID());
419 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
422 Handle(V3d_View) aView = theWnd->v3dView();
423 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
425 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
426 thePoint.setValue(aX, anY);
429 void PartSet_SketcherMgr::launchEditing()
431 // there should be activate the vertex selection mode because the edit can happens by the selected
434 aModes << TopAbs_VERTEX << TopAbs_EDGE;
435 // TODO: #391 - to be uncommented
436 /*aModes.append(AIS_DSM_Text);
437 aModes.append(AIS_DSM_Line);
438 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
439 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));*/
441 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
442 aConnector->activateSubShapesSelection(aModes);
444 if (!myFeature2AttributeMap.empty()) {
445 FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
446 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
447 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
449 myModule->editFeature(aSPFeature);
456 QStringList PartSet_SketcherMgr::sketchOperationIdList()
458 static QStringList aIds;
459 if (aIds.size() == 0) {
460 aIds << SketchPlugin_Line::ID().c_str();
461 aIds << SketchPlugin_Point::ID().c_str();
462 aIds << SketchPlugin_Arc::ID().c_str();
463 aIds << SketchPlugin_Circle::ID().c_str();
464 aIds << SketchPlugin_ConstraintLength::ID().c_str();
465 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
466 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
467 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
468 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
469 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
474 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
476 // Display all sketcher sub-Objects
477 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
478 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
479 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
481 // Hide sketcher result
482 std::list<ResultPtr> aResults = myCurrentSketch->results();
483 std::list<ResultPtr>::const_iterator aIt;
484 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
485 aDisplayer->erase((*aIt), false);
487 aDisplayer->erase(myCurrentSketch, false);
489 // Display sketcher objects
490 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
491 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
492 std::list<ResultPtr> aResults = aFeature->results();
493 std::list<ResultPtr>::const_iterator aIt;
494 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
495 aDisplayer->display((*aIt), false);
497 aDisplayer->display(aFeature, false);
500 if (myPlaneFilter.IsNull())
501 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
503 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
504 if (theOperation->isEditOperation()) {
505 // If it is editing of sketch then it means that plane is already defined
506 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
507 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
509 aDisplayer->updateViewer();
512 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
514 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
515 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
517 DataPtr aData = myCurrentSketch->data();
518 if ((!aData) || (!aData->isValid())) {
519 // The sketch was aborted
520 myCurrentSketch = CompositeFeaturePtr();
521 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
523 // Erase all sketcher objects
524 QStringList aSketchIds = sketchOperationIdList();
525 QObjectPtrList aObjects = aDisplayer->displayedObjects();
526 foreach (ObjectPtr aObj, aObjects) {
527 DataPtr aObjData = aObj->data();
528 if ((!aObjData) || (!aObjData->isValid()))
529 aDisplayer->erase(aObj);
533 // Hide all sketcher sub-Objects
534 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
535 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
536 std::list<ResultPtr> aResults = aFeature->results();
537 std::list<ResultPtr>::const_iterator aIt;
538 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
539 aDisplayer->erase((*aIt), false);
541 aDisplayer->erase(aFeature, false);
543 // Display sketcher result
544 std::list<ResultPtr> aResults = myCurrentSketch->results();
545 std::list<ResultPtr>::const_iterator aIt;
546 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
547 aDisplayer->display((*aIt), false);
549 aDisplayer->display(myCurrentSketch);
551 myCurrentSketch = CompositeFeaturePtr();
552 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
553 aDisplayer->updateViewer();
557 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
559 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
562 void PartSet_SketcherMgr::getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
563 const FeaturePtr& theSketch,
564 ModuleBase_IWorkshop* theWorkshop,
565 FeatureToSelectionMap& theSelection)
567 FeatureToAttributesMap::const_iterator anIt = theFeatureToAttributes.begin(),
568 aLast = theFeatureToAttributes.end();
569 for (; anIt != aLast; anIt++) {
570 FeaturePtr aFeature = anIt.key();
571 getCurrentSelection(aFeature, theSketch, theWorkshop, theSelection);
575 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
576 const FeaturePtr& theSketch,
577 ModuleBase_IWorkshop* theWorkshop,
578 FeatureToSelectionMap& theSelection)
580 if (theFeature.get() == NULL)
583 std::set<AttributePtr> aSelectedAttributes;
584 std::set<ResultPtr> aSelectedResults;
586 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
587 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
588 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
589 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
591 std::list<ResultPtr> aResults = theFeature->results();
592 std::list<ResultPtr>::const_iterator aIt;
593 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
595 ResultPtr aResult = *aIt;
596 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
597 if (aAISObj.get() == NULL)
599 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
600 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
602 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
603 aContext->SelectedOwner());
604 if (aBRepOwner.IsNull())
606 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
607 aBRepOwner->Selectable());
611 if (aBRepOwner->HasShape()) {
612 const TopoDS_Shape& aShape = aBRepOwner->Shape();
613 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
614 if (aShapeType == TopAbs_VERTEX) {
615 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
617 if (aPntAttr.get() != NULL)
618 aSelectedAttributes.insert(aPntAttr);
620 else if (aShapeType == TopAbs_EDGE &&
621 aSelectedResults.find(aResult) == aSelectedResults.end()) {
622 aSelectedResults.insert(aResult);
627 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
630 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
631 const FeaturePtr& theSketch,
632 ModuleBase_IWorkshop* theWorkshop,
633 const FeatureToSelectionMap& theSelection,
634 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
636 if (theFeature.get() == NULL)
639 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
640 std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
641 std::set<ResultPtr> aSelectedResults = anIt->second.second;
643 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
644 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
645 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
646 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
648 std::list<ResultPtr> aResults = theFeature->results();
649 std::list<ResultPtr>::const_iterator aIt;
650 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
652 ResultPtr aResult = *aIt;
653 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
654 if (aAISObj.get() == NULL)
656 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
658 SelectMgr_IndexedMapOfOwner aSelectedOwners;
659 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
660 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
661 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
662 if ( anOwner.IsNull() || !anOwner->HasShape() )
664 const TopoDS_Shape& aShape = anOwner->Shape();
665 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
666 if (aShapeType == TopAbs_VERTEX) {
667 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
668 if (aPntAttr.get() != NULL &&
669 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
670 anOwnersToSelect.Add(anOwner);
673 else if (aShapeType == TopAbs_EDGE) {
674 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
675 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
676 anOwnersToSelect.FindIndex(anOwner) <= 0)
677 anOwnersToSelect.Add(anOwner);