1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_Displayer.h"
22 #include "XGUI_Workshop.h"
23 #include "XGUI_ViewerProxy.h"
24 #include "XGUI_SelectionMgr.h"
25 #include "XGUI_Selection.h"
26 #include "XGUI_CustomPrs.h"
29 #include <AppElements_Viewer.h>
32 #include <ModelAPI_Document.h>
33 #include <ModelAPI_Data.h>
34 #include <ModelAPI_Object.h>
35 #include <ModelAPI_Tools.h>
36 #include <ModelAPI_AttributeIntArray.h>
37 #include <ModelAPI_ResultCompSolid.h>
39 #include <ModuleBase_ResultPrs.h>
40 #include <ModuleBase_Tools.h>
41 #include <ModuleBase_IModule.h>
42 #include <ModuleBase_ViewerPrs.h>
43 #include <ModuleBase_Preferences.h>
45 #include <GeomAPI_Shape.h>
46 #include <GeomAPI_IPresentable.h>
47 #include <GeomAPI_ICustomPrs.h>
49 #include <SUIT_ResourceMgr.h>
51 #include <AIS_InteractiveContext.hxx>
52 #include <AIS_ListOfInteractive.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <AIS_DimensionSelectionMode.hxx>
55 #include <AIS_Shape.hxx>
56 #include <AIS_Dimension.hxx>
57 #include <AIS_Trihedron.hxx>
58 #ifdef BEFORE_TRIHEDRON_PATCH
59 #include <AIS_Axis.hxx>
60 #include <AIS_Plane.hxx>
61 #include <AIS_Point.hxx>
63 #include <AIS_Selection.hxx>
64 #include <TColStd_ListIteratorOfListOfInteger.hxx>
65 #include <SelectMgr_ListOfFilter.hxx>
66 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
67 #include <Prs3d_Drawer.hxx>
68 #include <Prs3d_IsoAspect.hxx>
69 #include <SelectMgr_SelectionManager.hxx>
71 #include <StdSelect_ViewerSelector3d.hxx>
73 #include <TColStd_MapOfTransient.hxx>
74 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
77 #include <VInspectorAPI_CallBack.hxx>
80 #include <Events_Loop.h>
81 #include <ModelAPI_Events.h>
85 /// defines the local context mouse selection sensitivity
86 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
88 //#define DEBUG_ACTIVATE_OBJECTS
89 //#define DEBUG_DEACTIVATE
90 //#define DEBUG_ACTIVATE_AIS
91 //#define DEBUG_DEACTIVATE_AIS
93 //#define DEBUG_DISPLAY
94 //#define DEBUG_FEATURE_REDISPLAY
95 //#define DEBUG_SELECTION_FILTERS
97 //#define DEBUG_COMPOSILID_DISPLAY
99 //#define DEBUG_OCCT_SHAPE_SELECTION
101 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
103 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
105 // Get from null point
106 theAIS->DisplayedObjects(theList, true);
109 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
112 QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
113 for (; anIt != aLast; anIt++) {
114 anInfo.append(QString::number(*anIt));
116 return anInfo.join(theSeparator);
119 void deselectPresentation(const Handle(AIS_InteractiveObject) theObject,
120 const Handle(AIS_InteractiveContext)& theContext)
122 NCollection_List<Handle(SelectBasics_EntityOwner)> aResultOwners;
124 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) {
125 Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
126 if (anOwner.IsNull()) // TODO: check why it is possible
128 if (anOwner->Selectable() == theObject && anOwner->IsSelected())
129 aResultOwners.Append(anOwner);
131 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (aResultOwners);
132 Handle(SelectMgr_EntityOwner) anOwner;
133 for (; anOwnersIt.More(); anOwnersIt.Next()) {
134 anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
135 if (!anOwner.IsNull())
136 theContext->AddOrRemoveSelected(anOwner, false);
140 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
141 : myWorkshop(theWorkshop), myNeedUpdate(false),
142 myIsTrihedronActive(true), myViewerBlockedRecursiveCount(0),
143 myIsFirstAISContextUse(true)
145 myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
148 XGUI_Displayer::~XGUI_Displayer()
152 bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
154 return myResult2AISObjectMap.contains(theObject);
157 bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
159 bool aDisplayed = false;
160 if (isVisible(theObject)) {
161 #ifdef DEBUG_COMPOSILID_DISPLAY
162 ResultCompSolidPtr aCompsolidResult =
163 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
164 if (aCompsolidResult.get()) {
165 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
166 ResultPtr aSubResult = aCompsolidResult->subResult(i);
167 if (aSubResult.get())
168 redisplay(aSubResult, false);
175 aDisplayed = redisplay(theObject, theUpdateViewer);
178 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
179 bool isShading = false;
180 if (aPrs.get() != NULL) {
181 anAIS = aPrs->getAISObject(anAIS);
183 // correct deviation coefficient for
184 /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
185 if (!anAISPrs.IsNull()) {
186 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
187 if (!aShapePrs.IsNull()) {
188 TopoDS_Shape aShape = aShapePrs->Shape();
189 if (!aShape.IsNull())
190 //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
195 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
196 if (aResult.get() != NULL) {
197 #ifdef DEBUG_COMPOSILID_DISPLAY
198 ResultCompSolidPtr aCompsolidResult =
199 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
200 if (aCompsolidResult.get()) {
201 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
202 ResultPtr aSubResult = aCompsolidResult->subResult(i);
203 if (aSubResult.get())
204 display(aSubResult, false);
211 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
212 if (aShapePtr.get() != NULL) {
213 anAIS = AISObjectPtr(new GeomAPI_AISObject());
214 Handle(AIS_InteractiveObject) anAISPrs =
215 myWorkshop->module()->createPresentation(aResult);
216 if (anAISPrs.IsNull())
217 anAISPrs = new ModuleBase_ResultPrs(aResult);
219 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
220 if (!aShapePrs.IsNull())
221 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
223 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
224 //anAIS->createShape(aShapePtr);
227 #ifdef DEBUG_COMPOSILID_DISPLAY
233 aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
238 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
240 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
241 if (!aShapePrs.IsNull()) {
242 TopoDS_Shape aShape = aShapePrs->Shape();
245 TopAbs_ShapeEnum aType = aShape.ShapeType();
246 if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
249 // Check that the presentation is not a sketch
250 return theModule->canBeShaded(theAIS);
256 bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
257 bool isShading, bool theUpdateViewer)
259 bool aDisplayed = false;
261 Handle(AIS_InteractiveContext) aContext = AISContext();
262 if (aContext.IsNull())
265 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
266 if (!anAISIO.IsNull()) {
267 appendResultObject(theObject, theAIS);
269 bool isCustomized = customizeObject(theObject);
271 int aDispMode = isShading? Shading : Wireframe;
273 anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
274 anAISIO->SetDisplayMode(aDispMode);
275 aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
277 if (getCallBack()) getCallBack()->Display(anAISIO);
281 emit objectDisplayed(theObject, theAIS);
282 activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
290 bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
292 bool aErased = false;
293 if (!isVisible(theObject))
296 Handle(AIS_InteractiveContext) aContext = AISContext();
297 if (aContext.IsNull())
300 AISObjectPtr anObject = myResult2AISObjectMap[theObject];
302 Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
303 if (!anAIS.IsNull()) {
304 emit beforeObjectErase(theObject, anObject);
305 aContext->Remove(anAIS, false/*update viewer*/);
307 if (getCallBack()) getCallBack()->Remove(anAIS);
312 myResult2AISObjectMap.remove(theObject);
315 std::ostringstream aPtrStr;
316 aPtrStr << theObject.get();
317 qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
318 qDebug(getResult2AISObjectMapInfo().c_str());
327 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
329 bool aRedisplayed = false;
330 if (!isVisible(theObject))
333 AISObjectPtr aAISObj = getAISObject(theObject);
334 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
336 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
338 AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
340 aRedisplayed = erase(theObject, theUpdateViewer);
343 if (aAIS_Obj != aAISObj) {
344 appendResultObject(theObject, aAIS_Obj);
346 aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
349 Handle(AIS_InteractiveContext) aContext = AISContext();
350 if (!aContext.IsNull() && !aAISIO.IsNull()) {
351 // Check that the visualized shape is the same and the redisplay is not necessary
352 // Redisplay of AIS object leads to this object selection compute and the selection
353 // in the browser is lost
354 // this check is not necessary anymore because the selection store/restore is realized
355 // before and after the values modification.
356 // Moreother, this check avoids customize and redisplay presentation if the presentable
357 // parameter is changed.
358 bool isEqualShapes = false;
359 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
360 if (aResult.get() != NULL) {
361 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
362 if (!aShapePrs.IsNull()) {
363 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
364 if (aShapePtr.get()) {
365 const TopoDS_Shape& aOldShape = aShapePrs->Shape();
366 if (!aOldShape.IsNull())
367 isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
371 // Customization of presentation
372 bool isCustomized = customizeObject(theObject);
373 #ifdef DEBUG_FEATURE_REDISPLAY
374 qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
375 arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
376 .arg(isCustomized).toStdString().c_str());
378 if (!isEqualShapes || isCustomized) {
379 /// if shapes are equal and presentation are customized, selection should be restored
380 bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
381 if (aNeedToRestoreSelection)
382 myWorkshop->module()->storeSelection();
384 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
385 deselectPresentation(aAISIO, aContext);
387 aContext->Redisplay(aAISIO, false);
390 if (getCallBack()) getCallBack()->Redisplay(aAISIO);
393 if (aNeedToRestoreSelection)
394 myWorkshop->module()->restoreSelection();
397 #ifdef DEBUG_FEATURE_REDISPLAY
398 qDebug(" Redisplay happens");
407 void XGUI_Displayer::redisplayObjects()
409 // redisplay objects visualized in the viewer
410 static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
411 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
412 QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
413 QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
414 for (; anIt != aLast; anIt++) {
415 aECreator->sendUpdated(*anIt, EVENT_DISP);
417 Events_Loop::loop()->flush(EVENT_DISP);
420 void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
422 #ifdef DEBUG_DEACTIVATE
423 QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
424 qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
425 arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
427 toStdString().c_str());
429 Handle(AIS_InteractiveContext) aContext = AISContext();
430 if (!aContext.IsNull() && isVisible(theObject)) {
431 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
432 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
434 deactivateAIS(anAIS);
435 // the selection from the previous activation modes should be cleared manually (#26172)
436 #ifndef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
437 deselectPresentation(anAIS, aContext);
444 void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList,
445 const bool theUpdateViewer)
447 //Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
448 //if (!aTrihedron.IsNull())
449 // deactivateAIS(aTrihedron);
451 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
452 for (; anIt != aLast; anIt++) {
453 deactivate(*anIt, false);
455 //VSV It seems that there is no necessity to update viewer on deactivation
456 //if (theUpdateViewer)
460 void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes)
462 Handle(AIS_InteractiveContext) aContext = AISContext();
463 if (aContext.IsNull() || !isVisible(theObject))
466 AISObjectPtr aAISObj = getAISObject(theObject);
468 if (aAISObj.get() != NULL) {
469 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
470 TColStd_ListOfInteger aTColModes;
471 aContext->ActivatedModes(anAISIO, aTColModes);
472 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
473 for (; itr.More(); itr.Next() ) {
474 theModes.append(itr.Value());
479 int XGUI_Displayer::getSelectionMode(int theShapeType)
481 return (theShapeType > TopAbs_SHAPE) ? theShapeType :
482 AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
485 bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
487 bool aVisible = false;
488 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
489 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
490 if (aPrs.get() || aResult.get()) {
491 aVisible = theDisplayer->isVisible(theObject);
492 // compsolid is not visualized in the viewer,
493 // but should have presentation when all sub solids are
494 // visible. It is useful for highlight presentation where compsolid shape is selectable
495 if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
496 ResultCompSolidPtr aCompsolidResult =
497 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
498 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
499 bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
500 for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
501 anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
503 aVisible = anAllSubsVisible;
507 // it is possible that feature is presentable and has results, so we should check visibility
508 // of results if presentation is not shown (e.g. Sketch Circle/Arc features)
510 // check if all results of the feature are visible
511 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
512 std::list<ResultPtr> aResults;
513 ModelAPI_Tools::allResults(aFeature, aResults);
514 std::list<ResultPtr>::const_iterator aIt;
515 aVisible = !aResults.empty();
516 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
517 aVisible = aVisible && theDisplayer->isVisible(*aIt);
523 #ifdef DEBUG_ACTIVATE_OBJECTS
524 QString getModeInfo(const int theMode)
526 QString anInfo = "Undefined";
528 case 0: anInfo = "SHAPE(0)"; break;
529 case 1: anInfo = "VERTEX(1)"; break;
530 case 2: anInfo = "EDGE(2)"; break;
531 case 3: anInfo = "WIRE(3)"; break;
532 case 4: anInfo = "FACE(4)"; break;
533 case 5: anInfo = "SHELL(5)"; break;
534 case 6: anInfo = "SOLID(6)"; break;
535 case 7: anInfo = "COMPSOLID(7)"; break;
536 case 8: anInfo = "COMPOUND(8)"; break;
537 case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
538 case 101: anInfo = "Sel_Constraint(101)"; break;
539 case 102: anInfo = "Sel_Dimension_All(102)"; break;
540 case 103: anInfo = "Sel_Dimension_Line(103)"; break;
541 case 104: anInfo = "Sel_Dimension_Text(104)"; break;
547 QString getModesInfo(const QIntList& theModes)
549 QStringList aModesInfo;
550 for (int i = 0, aSize = theModes.size(); i < aSize; i++)
551 aModesInfo.append(getModeInfo(theModes[i]));
552 return QString("[%1] = %2").arg(aModesInfo.size()).arg(aModesInfo.join(", "));
556 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
557 const bool theUpdateViewer)
559 // Convert shape types to selection types
561 foreach(int aType, theModes) {
562 aModes.append(getSelectionMode(aType));
565 #ifdef DEBUG_ACTIVATE_OBJECTS
567 QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
568 for (; anIt != aLast; ++anIt) {
569 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
571 QString anInfoStr = anInfo.join(", ");
573 qDebug(QString("activateObjects: new modes%1, active modes%2, objects[%3] = %4").
574 arg(getModesInfo(aModes)).
575 arg(getModesInfo(myActiveSelectionModes)).
576 arg(theObjList.size()).
578 toStdString().c_str());
580 // In order to avoid doblications of selection modes
582 foreach (int aMode, aModes) {
583 if (!aNewModes.contains(aMode))
584 aNewModes.append(aMode);
586 myActiveSelectionModes = aNewModes;
587 Handle(AIS_InteractiveContext) aContext = AISContext();
588 // Open local context if there is no one
589 if (aContext.IsNull())
592 //aContext->UseDisplayedObjects();
593 //myUseExternalObjects = true;
595 Handle(AIS_InteractiveObject) anAISIO;
596 AIS_ListOfInteractive aPrsList;
597 //if (aObjList.isEmpty())
600 foreach(ObjectPtr aObj, theObjList) {
601 if (myResult2AISObjectMap.contains(aObj))
602 aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
606 // Add trihedron because it has to partisipate in selection
607 Handle(AIS_InteractiveObject) aTrihedron;
608 if (isTrihedronActive()) {
609 aTrihedron = getTrihedron();
610 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron))
611 aPrsList.Append(aTrihedron);
613 if (aPrsList.Extent() == 0)
616 AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
617 bool isActivationChanged = false;
618 for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
619 anAISIO = aLIt.Value();
620 if (activate(anAISIO, myActiveSelectionModes, false))
621 isActivationChanged = true;
625 bool XGUI_Displayer::isActive(ObjectPtr theObject) const
627 Handle(AIS_InteractiveContext) aContext = AISContext();
628 if (aContext.IsNull() || !isVisible(theObject))
631 AISObjectPtr anObj = myResult2AISObjectMap[theObject];
632 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
634 TColStd_ListOfInteger aModes;
635 aContext->ActivatedModes(anAIS, aModes);
637 if (getCallBack()) getCallBack()->ActivatedModes(anAIS, aModes);
640 return aModes.Extent() > 0;
644 void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues,
645 bool theUpdateViewer)
647 Handle(AIS_InteractiveContext) aContext = AISContext();
648 if (aContext.IsNull())
650 aContext->UnhilightSelected(false);
651 aContext->ClearSelected(false);
653 if (getCallBack()) getCallBack()->ClearSelected();
655 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)>>
658 foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) {
659 const GeomShapePtr& aGeomShape = aPrs->shape();
660 if (aGeomShape.get() && !aGeomShape->isNull()) {
661 const TopoDS_Shape& aShape = aGeomShape->impl<TopoDS_Shape>();
662 #ifdef DEBUG_OCCT_SHAPE_SELECTION
663 // problem 1: performance
664 // problem 2: IO is not specified, so the first found owner is selected, as a result
665 // it might belong to another result
666 aContext->AddOrRemoveSelected(aShape, false);
668 if (getCallBack()) getCallBack()->AddOrRemoveSelected(aShape);
671 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations;
672 if (aShapesToBeSelected.IsBound(aShape))
673 aPresentations = aShapesToBeSelected.Find(aShape);
674 ObjectPtr anObject = aPrs->object();
675 getPresentations(anObject, aPresentations);
677 aShapesToBeSelected.Bind(aShape, aPresentations);
680 ObjectPtr anObject = aPrs->object();
681 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
682 if (aResult.get() && isVisible(aResult)) {
683 AISObjectPtr anObj = myResult2AISObjectMap[aResult];
684 Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
685 if (!anAIS.IsNull()) {
686 // The methods are replaced in order to provide multi-selection, e.g. restore selection
687 // by activating multi selector widget. It also gives an advantage that the multi
688 // selection in OB gives multi-selection in the viewer
689 //aContext->SetSelected(anAIS, false);
690 // The selection in the context was cleared, so the method sets the objects are selected
691 aContext->AddOrRemoveSelected(anAIS, false);
693 if (getCallBack()) getCallBack()->AddOrRemoveSelected(anAIS);
699 if (!aShapesToBeSelected.IsEmpty())
700 XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected);
706 void XGUI_Displayer::clearSelected(const bool theUpdateViewer)
708 Handle(AIS_InteractiveContext) aContext = AISContext();
709 if (!aContext.IsNull()) {
710 aContext->UnhilightSelected(false);//UnhilightCurrents(false);
711 aContext->ClearSelected(theUpdateViewer);
713 if (getCallBack()) getCallBack()->ClearSelected();
718 bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
720 bool aErased = false;
721 Handle(AIS_InteractiveContext) aContext = AISContext();
722 if (!aContext.IsNull()) {
723 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
724 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
726 Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
727 if (!anIO.IsNull()) {
728 emit beforeObjectErase(aObj, aAISObj);
729 aContext->Remove(anIO, false/*update viewer*/);
731 if (getCallBack()) getCallBack()->Remove(anIO);
739 myResult2AISObjectMap.clear();
742 qDebug(getResult2AISObjectMapInfo().c_str());
747 void deactivateObject(Handle(AIS_InteractiveContext) theContext,
748 Handle(AIS_InteractiveObject) theObject
750 , Handle(VInspectorAPI_CallBack) theCallBack
754 if (!theObject.IsNull()) {
755 theContext->Deactivate(theObject);
757 if (theCallBack) theCallBack->Deactivate(theObject);
762 void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const
764 Handle(AIS_InteractiveObject) aTrihedron = getTrihedron();
765 Handle(AIS_InteractiveContext) aContext = AISContext();
766 if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) {
767 Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron);
768 deactivateObject(aContext, aTrie
774 /// #1136 hidden axis are selected in sketch
775 #ifdef BEFORE_TRIHEDRON_PATCH
776 deactivateObject(aContext, aTrie->XAxis()
781 deactivateObject(aContext, aTrie->YAxis()
786 deactivateObject(aContext, aTrie->Axis()
791 deactivateObject(aContext, aTrie->Position()
797 deactivateObject(aContext, aTrie->XYPlane()
802 deactivateObject(aContext, aTrie->XZPlane()
807 deactivateObject(aContext, aTrie->YZPlane()
818 Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const
820 return myWorkshop->viewer()->trihedron();
823 /*void XGUI_Displayer::openLocalContext()
825 Handle(AIS_InteractiveContext) aContext = AISContext();
826 // Open local context if there is no one
827 if (!aContext.IsNull() && !aContext->HasOpenedContext()) {
828 // Preserve selected objects
829 //AIS_ListOfInteractive aAisList;
830 //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
831 // aAisList.Append(aContext->Current());
833 // get the filters from the global context and append them to the local context
834 // a list of filters in the global context is not cleared and should be cleared here
835 SelectMgr_ListOfFilter aFilters;
836 aFilters.Assign(aContext->Filters());
837 // it is important to remove the filters in the global context, because there is a code
838 // in the closeLocalContex, which restore the global context filters
839 aContext->RemoveFilters();
841 //aContext->ClearCurrents();
842 aContext->OpenLocalContext();
843 //deactivateTrihedron();
844 //aContext->NotUseDisplayedObjects();
846 //myUseExternalObjects = false;
848 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
849 for (;aIt.More(); aIt.Next()) {
850 aContext->AddFilter(aIt.Value());
853 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
854 //for(; aIt2.More(); aIt2.Next()) {
855 // aContext->SetSelected(aIt2.Value(), false);
860 /*void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
862 Handle(AIS_InteractiveContext) aContext = AISContext();
863 if (!aContext.IsNull() && aContext->HasOpenedContext()) {
864 // Preserve selected objects
865 //AIS_ListOfInteractive aAisList;
866 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
867 // aAisList.Append(aContext->SelectedInteractive());
869 // get the filters from the local context and append them to the global context
870 // a list of filters in the local context is cleared
871 SelectMgr_ListOfFilter aFilters;
872 aFilters.Assign(aContext->Filters());
874 //aContext->ClearSelected();
875 aContext->CloseAllContexts(false);
877 // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object,
878 // this code is obsolete. It is temporaty commented and should be removed after
879 // the test campaign.
880 // Redisplay all object if they were displayed in localContext
881 /*Handle(AIS_InteractiveObject) aAISIO;
882 foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
883 aAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
884 if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) {
885 aContext->Display(aAISIO, false);
886 aContext->SetDisplayMode(aAISIO, Shading, false);
890 // Append the filters from the local selection in the global selection context
891 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
892 for (;aIt.More(); aIt.Next()) {
893 Handle(SelectMgr_Filter) aFilter = aIt.Value();
894 aContext->AddFilter(aFilter);
899 //myUseExternalObjects = false;
902 //AIS_ListIteratorOfListOfInteractive aIt2(aAisList);
903 //for(; aIt2.More(); aIt2.Next()) {
904 // if (aContext->IsDisplayed(aIt2.Value()))
905 // aContext->SetCurrentObject(aIt2.Value(), false);
910 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
913 if (myResult2AISObjectMap.contains(theObject))
914 anIO = myResult2AISObjectMap[theObject];
918 ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
920 Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
921 return getObject(aRefAIS);
924 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
927 foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
928 AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
929 Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
935 if (!anObject.get()) {
936 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
937 if (!theIO.IsNull()) {
938 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
940 anObject = myWorkshop->module()->findPresentedObject(anAISObj);
945 bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
947 bool aWasEnabled = isUpdateEnabled();
949 myViewerBlockedRecursiveCount--;
951 myViewerBlockedRecursiveCount++;
953 if (myNeedUpdate && isUpdateEnabled()) {
955 myNeedUpdate = false;
960 bool XGUI_Displayer::isUpdateEnabled() const
962 return myViewerBlockedRecursiveCount == 0;
965 void XGUI_Displayer::updateViewer() const
967 Handle(AIS_InteractiveContext) aContext = AISContext();
968 if (!aContext.IsNull() && isUpdateEnabled()) {
969 //myWorkshop->viewer()->Zfitall();
970 aContext->UpdateCurrentViewer();
976 void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
977 const int theMode, const bool theUpdateViewer) const
979 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
980 if (!theIO.IsNull() && theIO == getTrihedron()) {
981 if (theMode != AIS_Shape::SelectionType(TopAbs_EDGE) &&
982 theMode != AIS_Shape::SelectionType(TopAbs_VERTEX))
985 if (!aContext.IsNull()) {
986 if (myWorkshop->module()) {
987 int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
988 aContext->Activate(theIO, theMode, false);
990 aContext->Activate(theIO, theMode, false);
992 if (getCallBack()) getCallBack()->Activate(theIO, theMode);
995 // the fix from VPA for more suitable selection of sketcher lines
996 if (theIO->Width() > 1) {
997 double aPrecision = theIO->Width() + 2;
998 if (theMode == getSelectionMode(TopAbs_VERTEX))
999 aPrecision = ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
1000 "point-selection-sensitivity",
1002 else if ((theMode == getSelectionMode(TopAbs_EDGE)) ||
1003 (theMode == getSelectionMode(TopAbs_WIRE)))
1004 aPrecision = theIO->Width() +
1005 ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
1006 "edge-selection-sensitivity", 2);
1007 aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
1010 #ifdef DEBUG_ACTIVATE_AIS
1011 ObjectPtr anObject = getObject(theIO);
1012 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1013 qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode)
1014 .arg(anInfo).toStdString().c_str());
1016 if (theUpdateViewer)
1021 void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
1022 const int theMode) const
1024 Handle(AIS_InteractiveContext) aContext = AISContext();
1025 if (!aContext.IsNull()) {
1026 if (theMode == -1) {
1027 aContext->Deactivate(theIO);
1029 if (getCallBack()) getCallBack()->Deactivate(theIO);
1033 aContext->Deactivate(theIO, theMode);
1035 if (getCallBack()) getCallBack()->Deactivate(theIO, theMode);
1039 #ifdef DEBUG_DEACTIVATE_AIS
1040 ObjectPtr anObject = getObject(theIO);
1041 anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
1042 qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode)
1043 .arg(anInfo).toStdString().c_str());
1048 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
1050 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1051 if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) {
1052 XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
1053 aDisplayer->myIsFirstAISContextUse = false;
1054 //aContext->OpenLocalContext();
1055 if (!isTrihedronActive())
1056 deactivateTrihedron(true);
1057 aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
1058 aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
1063 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
1065 Handle(AIS_InteractiveContext) aContext = AISContext();
1066 if (!aContext.IsNull() && myAndFilter.IsNull()) {
1067 myAndFilter = new SelectMgr_AndFilter();
1068 aContext->AddFilter(myAndFilter);
1073 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
1074 bool theUpdateViewer)
1076 bool aDisplayed = false;
1077 Handle(AIS_InteractiveContext) aContext = AISContext();
1078 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1079 if (!aContext.IsNull() && !anAISIO.IsNull()) {
1080 aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
1082 if (getCallBack()) getCallBack()->Display(anAISIO);
1085 aContext->Deactivate(anAISIO);
1087 if (getCallBack()) getCallBack()->Deactivate(anAISIO);
1089 aContext->Load(anAISIO);
1091 if (getCallBack()) getCallBack()->Load(anAISIO);
1093 if (toActivateInSelectionModes) {
1094 if (myActiveSelectionModes.size() == 0)
1095 activateAIS(anAISIO, 0, theUpdateViewer);
1097 foreach(int aMode, myActiveSelectionModes) {
1098 activateAIS(anAISIO, aMode, theUpdateViewer);
1102 if (theUpdateViewer)
1108 bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
1110 bool aErased = false;
1111 Handle(AIS_InteractiveContext) aContext = AISContext();
1112 if (!aContext.IsNull()) {
1113 Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
1114 if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
1115 aContext->Remove(anAISIO, false/*update viewer*/);
1117 if (getCallBack()) getCallBack()->Remove(anAISIO);
1122 if (aErased && theUpdateViewer)
1128 void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
1130 if (theMode == NoMode)
1133 Handle(AIS_InteractiveContext) aContext = AISContext();
1134 if (aContext.IsNull())
1137 AISObjectPtr aAISObj = getAISObject(theObject);
1141 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1142 aContext->SetDisplayMode(aAISIO, theMode, false);
1143 // Redisplay in order to update new mode because it could be not computed before
1144 if (theUpdateViewer)
1148 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
1150 Handle(AIS_InteractiveContext) aContext = AISContext();
1151 if (aContext.IsNull())
1154 AISObjectPtr aAISObj = getAISObject(theObject);
1158 Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1159 return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
1162 void XGUI_Displayer::deactivateSelectionFilters()
1164 Handle(AIS_InteractiveContext) aContext = AISContext();
1165 if (!myAndFilter.IsNull()) {
1166 bool aFound = false;
1167 if (!aContext.IsNull()) {
1168 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1169 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
1170 for (; anIt.More() && !aFound; anIt.Next()) {
1171 Handle(SelectMgr_Filter) aFilter = anIt.Value();
1172 aFound = aFilter == myAndFilter;
1175 aContext->RemoveFilter(myAndFilter);
1177 myAndFilter.Nullify();
1181 void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1183 Handle(AIS_InteractiveContext) aContext = AISContext();
1184 if (aContext.IsNull() || hasSelectionFilter(theFilter))
1187 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1188 if (!aCompositeFilter.IsNull()) {
1189 aCompositeFilter->Add(theFilter);
1190 #ifdef DEBUG_SELECTION_FILTERS
1191 int aCount = aCompositeFilter->StoredFilters().Extent();
1192 qDebug(QString("addSelectionFilter: filters.count() = %1").arg(aCount).toStdString().c_str());
1197 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1199 Handle(AIS_InteractiveContext) aContext = AISContext();
1200 if (aContext.IsNull())
1203 Handle(SelectMgr_AndFilter) aCompositeFilter = GetFilter();
1204 if (!aCompositeFilter.IsNull() && aCompositeFilter->IsIn(theFilter)) {
1205 aCompositeFilter->Remove(theFilter);
1206 #ifdef DEBUG_SELECTION_FILTERS
1207 int aCount = aCompositeFilter->StoredFilters().Extent();
1208 qDebug(QString("removeSelectionFilter: filters.count() = %1")
1209 .arg(aCount).toStdString().c_str());
1214 bool XGUI_Displayer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
1216 bool aFilterFound = false;
1218 Handle(AIS_InteractiveContext) aContext = AISContext();
1219 if (aContext.IsNull())
1220 return aFilterFound;
1221 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
1222 SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
1223 for (; aIt.More() && !aFilterFound; aIt.Next()) {
1224 if (theFilter.get() == aIt.Value().get())
1225 aFilterFound = true;
1227 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1228 if (!aCompositeFilter.IsNull()) {
1229 const SelectMgr_ListOfFilter& aStoredFilters = aCompositeFilter->StoredFilters();
1230 for (aIt.Initialize(aStoredFilters); aIt.More() && !aFilterFound; aIt.Next()) {
1231 if (theFilter.get() == aIt.Value().get())
1232 aFilterFound = true;
1235 return aFilterFound;
1238 void XGUI_Displayer::removeFilters()
1240 Handle(AIS_InteractiveContext) aContext = AISContext();
1241 if (aContext.IsNull())
1244 Handle(SelectMgr_CompositionFilter) aCompositeFilter = GetFilter();
1245 if (!aCompositeFilter.IsNull())
1246 aCompositeFilter->Clear();
1249 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
1251 QObjectPtrList aDispList = myResult2AISObjectMap.keys();
1252 foreach(ObjectPtr aObj, aDispList) {
1253 if (!theList.contains(aObj))
1256 foreach(ObjectPtr aObj, theList) {
1257 if (!isVisible(aObj))
1258 display(aObj, false);
1263 bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
1265 if (!isVisible(theObject))
1268 AISObjectPtr aAISObj = getAISObject(theObject);
1269 if (aAISObj.get() == NULL)
1272 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1273 return ::canBeShaded(anAIS, myWorkshop->module());
1276 bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
1277 const QIntList& theModes,
1278 const bool theUpdateViewer) const
1280 Handle(AIS_InteractiveContext) aContext = AISContext();
1281 if (aContext.IsNull() || theIO.IsNull())
1284 bool isActivationChanged = false;
1285 // deactivate object in all modes, which are not in the list of activation
1286 // It seems that after the IO deactivation the selected state of the IO's owners
1287 // is modified in OCC(version: 6.8.0) and the selection of the object later is lost.
1288 // By this reason, the number of the IO deactivate is decreased and the object is deactivated
1289 // only if there is a difference in the current modes and the parameters modes.
1290 // If the selection problem happens again, it is possible to write a test scenario and create
1291 // a bug. The bug steps are the following:
1292 // Create two IO, activate them in 5 modes, select the first IO, deactivate 3 modes for both,
1293 // with clicked SHIFT select the second object.
1294 // The result is the selection of the first IO is lost.
1295 TColStd_ListOfInteger aTColModes;
1296 aContext->ActivatedModes(theIO, aTColModes);
1298 if (getCallBack()) getCallBack()->ActivatedModes(theIO, aTColModes);
1300 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
1301 QIntList aModesActivatedForIO;
1302 bool isDeactivated = false;
1303 bool aHasValidMode = false;
1304 for (; itr.More(); itr.Next() ) {
1305 Standard_Integer aMode = itr.Value();
1306 aHasValidMode = aHasValidMode || aMode != -1;
1307 int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
1308 if (!theModes.contains(aMode)) {
1309 deactivateAIS(theIO, aMode);
1310 isDeactivated = true;
1313 aModesActivatedForIO.append(aMode);
1316 if (isDeactivated) {
1317 // the selection from the previous activation modes should be cleared manually (#26172)
1318 //theIO->ClearSelected();
1320 //if (getCallBack()) getCallBack()->ClearSelected(theIO);
1322 #ifndef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
1323 deselectPresentation(theIO, aContext);
1325 // For performance issues
1326 //if (theUpdateViewer)
1328 isActivationChanged = true;
1331 // loading the interactive object allowing the decomposition
1332 if (aTColModes.IsEmpty() || !aHasValidMode) {
1333 aContext->Load(theIO, -1, true);
1334 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1335 if (!aTrihedron.IsNull()) {
1336 // Workaround for Trihedron. It should be loaded using the next Load method to
1337 // add this object to myGlobal map of selection manager
1338 // it is important to activate trihedron in two selection modes: edges and vertices
1339 aContext->SelectionManager()->Load(theIO);
1343 if (getCallBack()) getCallBack()->Load(theIO);
1347 // trihedron AIS check should be after the AIS loading.
1348 // If it is not loaded, it is steel selectable in the viewer.
1349 Handle(AIS_Trihedron) aTrihedron;
1350 if (!isTrihedronActive())
1351 aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
1352 if (aTrihedron.IsNull()) {
1353 // In order to clear active modes list
1354 if (theModes.size() == 0) {
1355 activateAIS(theIO, 0, theUpdateViewer);
1357 foreach(int aMode, theModes) {
1358 if (!aModesActivatedForIO.contains(aMode)) {
1359 activateAIS(theIO, aMode, theUpdateViewer);
1360 isActivationChanged = true;
1365 return isActivationChanged;
1368 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
1370 AISObjectPtr anAISObj = getAISObject(theObject);
1371 // correct the result's color it it has the attribute
1372 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1374 // Customization of presentation
1375 GeomCustomPrsPtr aCustomPrs;
1376 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1377 if (aFeature.get() != NULL) {
1378 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1379 if (aCustPrs.get() != NULL)
1380 aCustomPrs = aCustPrs;
1382 if (aCustomPrs.get() == NULL) {
1383 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
1384 // we ignore presentable not customized objects
1385 if (aPrs.get() == NULL)
1386 aCustomPrs = myCustomPrs;
1388 bool isCustomized = aCustomPrs.get() &&
1389 aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
1390 isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs)
1392 return isCustomized;
1396 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
1397 const QColor& theColor,
1398 bool theUpdateViewer)
1400 if (!isVisible(theObject))
1403 AISObjectPtr anAISObj = getAISObject(theObject);
1405 anAISObj->getColor(aR, aG, aB);
1406 anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
1407 if (theUpdateViewer)
1409 return QColor(aR, aG, aB);
1412 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
1414 myResult2AISObjectMap[theObject] = theAIS;
1416 #ifdef DEBUG_DISPLAY
1417 std::ostringstream aPtrStr;
1418 aPtrStr << theObject.get();
1419 qDebug(QString("display object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
1420 qDebug(getResult2AISObjectMapInfo().c_str());
1425 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
1427 QStringList aContent;
1428 foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
1429 AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
1430 std::ostringstream aPtrStr;
1431 aPtrStr << "aObj = " << aObj.get() << ":";
1432 aPtrStr << "anAIS = " << aAISObj.get() << ":";
1433 aPtrStr << "[" << ModuleBase_Tools::objectInfo(aObj).toStdString().c_str() << "]";
1435 aContent.append(aPtrStr.str().c_str());
1437 return QString("myResult2AISObjectMap: size = %1\n%2\n").arg(myResult2AISObjectMap.size()).
1438 arg(aContent.join("\n")).toStdString().c_str();
1442 void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
1443 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations)
1445 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1446 if (aResult.get()) {
1447 AISObjectPtr aAISObj = getAISObject(aResult);
1448 if (aAISObj.get() == NULL) {
1449 // if result is a result of a composite feature, it is visualized by visualization of
1450 // composite children, so we should get one of this presentations
1451 ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1452 if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) {
1453 aAISObj = getAISObject(aCompSolid->subResult(0));
1456 if (aAISObj.get() != NULL) {
1457 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1458 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1459 thePresentations.Add(anAIS);
1463 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1464 // find presentation of the feature
1465 AISObjectPtr aAISObj = getAISObject(aFeature);
1466 if (aAISObj.get() != NULL) {
1467 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1468 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1469 thePresentations.Add(anAIS);
1471 // find presentations of the feature results
1472 std::list<ResultPtr> aResults;
1473 ModelAPI_Tools::allResults(aFeature, aResults);
1474 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1475 for (; anIt != aLast; ++anIt) {
1476 AISObjectPtr aAISObj = getAISObject(*anIt);
1477 if (aAISObj.get() != NULL) {
1478 Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1479 if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
1480 thePresentations.Add(anAIS);
1486 void XGUI_Displayer::activateTrihedron(bool theIsActive)
1488 myIsTrihedronActive = theIsActive;
1489 if (!myIsTrihedronActive) {
1490 deactivateTrihedron(true);
1494 void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
1496 Handle(AIS_InteractiveContext) aContext = AISContext();
1497 if (aContext.IsNull())
1500 Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
1503 if (!aContext->IsDisplayed(aTrihedron))
1504 aContext->Display(aTrihedron,
1506 -1 /* selection mode */,
1507 Standard_True /* update viewer*/,
1508 Standard_False /* allow decomposition */,
1509 AIS_DS_Displayed /* xdisplay status */);
1511 if (getCallBack()) getCallBack()->Display(aTrihedron);
1514 if (!isTrihedronActive())
1515 deactivateTrihedron(false);
1517 activate(aTrihedron, myActiveSelectionModes, false);
1519 deactivateTrihedron(false);
1521 aContext->Erase(aTrihedron);
1523 if (getCallBack()) getCallBack()->Remove(aTrihedron);
1530 QIntList XGUI_Displayer::activeSelectionModes() const
1533 foreach (int aMode, myActiveSelectionModes) {
1534 // aMode < 9 is a Shape Enum values
1535 aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
1540 void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
1541 const NCollection_DataMap<TopoDS_Shape,
1542 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
1544 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
1545 theContext->MainSelector()->ActiveOwners(anActiveOwners);
1546 NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
1547 Handle(SelectMgr_EntityOwner) anOwner;
1549 /// It is very important to check that the owner is processed only once and has a map of
1550 /// processed owners because SetSelected works as a switch.
1551 /// If count of calls setSelectec is even, the object stays in the previous state
1552 /// (selected, deselected)
1553 /// OCCT: to write about the problem that active owners method returns one owner several times
1554 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
1555 for (; anOwnersIt.More(); anOwnersIt.Next()) {
1556 anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
1557 if (aSelectedIds.contains((long)anOwner.get()))
1559 aSelectedIds.append((long)anOwner.get());
1561 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1562 if (!BROwnr.IsNull() && BROwnr->HasShape()) {
1563 const TopoDS_Shape& aShape = BROwnr->Shape();
1564 if (aShape.IsNull())
1567 NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)> >
1568 ::Iterator aShapeIt(theShapesToBeSelected);
1569 for (; aShapeIt.More(); aShapeIt.Next()) {
1570 if (aShapeIt.Key().IsSame(aShape)) {
1571 const TopoDS_Shape& aParameterShape = aShapeIt.Key();
1572 // isSame should be used here as it does not check orientation of shapes
1573 // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
1574 // different for Edges shapes in model shape and owner even if this is the same shape
1575 if (aParameterShape.IsSame(aShape)) {
1576 Handle(AIS_InteractiveObject) anOwnerPresentation =
1577 Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
1578 NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
1579 theShapesToBeSelected.Find(aParameterShape);
1580 if (aPresentations.Contains(anOwnerPresentation)) {
1581 theContext->AddOrRemoveSelected(anOwner);
1582 anOwner->SetSelected (Standard_True);