Salome HOME
Issue #2806: Provide correct selection with Shift button when Multi selector widget...
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
index 364153dcaf508a16d9e640cae364ef056d284429..202afd6b2c7d6253e1a0075e0ec7f1825162bd37 100644 (file)
@@ -342,6 +342,7 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
       return aRedisplayed;
     }
     if (aAIS_Obj != aAISObj) {
+      erase(theObject, theUpdateViewer);
       appendResultObject(theObject, aAIS_Obj);
     }
     aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
@@ -385,7 +386,10 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
       myWorkshop->selector()->deselectPresentation(aAISIO);
 #endif
-      aContext->Redisplay(aAISIO, false);
+      if (aContext->IsDisplayed(aAISIO))
+        aContext->Redisplay(aAISIO, false);
+      else
+        aContext->Display(aAISIO, false);
 
       #ifdef TINSPECTOR
       if (getCallBack()) getCallBack()->Redisplay(aAISIO);
@@ -450,8 +454,9 @@ bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& th
     if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultBody::group()) {
       ResultBodyPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
-        bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
-        for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
+        int aNumberOfSubs = aCompsolidResult->numberOfSubs();
+        bool anAllSubsVisible = aNumberOfSubs > 0;
+        for(int i = 0; i < aNumberOfSubs && anAllSubsVisible; i++) {
           anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
         }
         aVisible = anAllSubsVisible;
@@ -556,8 +561,13 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
   bool aErased = false;
   Handle(AIS_InteractiveContext) aContext = AISContext();
   if (!aContext.IsNull()) {
-    foreach (ObjectPtr aObj, myResult2AISObjectMap.objects()) {
+#ifdef OPTIMIZE_PRS
+    foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) {
       AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj);
+#else
+    foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) {
+      AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
+#endif
       // erase an object
       Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
       if (!anIO.IsNull()) {
@@ -584,7 +594,14 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
 //**************************************************************
 AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
 {
+#ifdef OPTIMIZE_PRS
   return myResult2AISObjectMap.value(theObject);
+#else
+  AISObjectPtr anIO;
+  if (myResult2AISObjectMap.contains(theObject))
+    anIO = myResult2AISObjectMap[theObject];
+  return anIO;
+#endif
 }
 
 //**************************************************************
@@ -597,7 +614,20 @@ ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
 //**************************************************************
 ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
 {
+#ifdef OPTIMIZE_PRS
   ObjectPtr anObject = myResult2AISObjectMap.value(theIO);
+#else
+  ObjectPtr anObject;
+  ResultToAISMap::const_iterator aMapIter = myResult2AISObjectMap.cbegin();
+  for (; aMapIter != myResult2AISObjectMap.cend(); aMapIter++) {
+    const AISObjectPtr& aAIS = aMapIter.value();
+    Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
+    if (anAIS == theIO)
+      anObject = aMapIter.key();
+    if (anObject.get())
+      break;
+  }
+#endif
   if (!anObject.get()) {
     std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
     if (!theIO.IsNull()) {
@@ -860,7 +890,11 @@ void XGUI_Displayer::removeFilters()
 //**************************************************************
 void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
 {
+#ifdef OPTIMIZE_PRS
   QObjectPtrList aDispList = myResult2AISObjectMap.objects();
+#else
+  QObjectPtrList aDispList = myResult2AISObjectMap.keys();
+#endif
   foreach(ObjectPtr aObj, aDispList) {
     if (!theList.contains(aObj))
       erase(aObj, false);
@@ -939,7 +973,11 @@ QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
 //**************************************************************
 void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
 {
+#ifdef OPTIMIZE_PRS
   myResult2AISObjectMap.add(theObject, theAIS);
+#else
+  myResult2AISObjectMap[theObject] = theAIS;
+#endif
 
 #ifdef DEBUG_DISPLAY
   std::ostringstream aPtrStr;
@@ -954,8 +992,13 @@ void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS
 std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
 {
   QStringList aContent;
-  foreach (ObjectPtr aObj, myResult2AISObjectMap.objects()) {
+#ifdef OPTIMIZE_PRS
+  foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) {
     AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj);
+#else
+  foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) {
+    AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
+#endif
     std::ostringstream aPtrStr;
     aPtrStr << "aObj = " << aObj.get() << ":";
     aPtrStr << "anAIS = " << aAISObj.get() << ":";
@@ -1069,12 +1112,12 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
   /// If count of calls setSelectec is even, the object stays in the previous state
   /// (selected, deselected)
   /// OCCT: to write about the problem that active owners method returns one owner several times
-  QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
+  QList<size_t> aSelectedIds; // Remember of selected address in order to avoid duplicates
   for (; anOwnersIt.More(); anOwnersIt.Next()) {
     anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
-    if (aSelectedIds.contains((long)anOwner.get()))
+    if (aSelectedIds.contains((size_t)anOwner.get()))
       continue;
-    aSelectedIds.append((long)anOwner.get());
+    aSelectedIds.append((size_t)anOwner.get());
 
     Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
     if (!BROwnr.IsNull() && BROwnr->HasShape()) {