Salome HOME
updated copyright message
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
index 16b1ecb657c27aa009e2f2cc8abb0888b1ff3427..6ee3b9348ca6d06762f143a943fd7929d856ed6f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "XGUI_Displayer.h"
 
-#include "XGUI_CustomPrs.h"
 #include "XGUI_FacesPanel.h"
 #include "XGUI_Selection.h"
 #include "XGUI_SelectionActivate.h"
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultGroup.h>
 
 #include <ModuleBase_BRepOwner.h>
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_Preferences.h>
-#include <ModuleBase_ResultPrs.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_IViewer.h>
@@ -59,9 +56,7 @@
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
-#include <AIS_DimensionSelectionMode.hxx>
 #include <AIS_Shape.hxx>
-#include <AIS_Dimension.hxx>
 #include <AIS_Trihedron.hxx>
 #ifdef BEFORE_TRIHEDRON_PATCH
 #include <AIS_Axis.hxx>
 #include <AIS_Selection.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_IsoAspect.hxx>
+#include <PrsDim_Dimension.hxx>
 #include <SelectMgr_ListOfFilter.hxx>
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 #include <SelectMgr_SelectionManager.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
 
 #include <StdSelect_ViewerSelector3d.hxx>
 
 #include <TColStd_MapOfTransient.hxx>
 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
+#include <Standard_Version.hxx>
 
 #ifdef TINSPECTOR
 #include <inspector/VInspectorAPI_CallBack.hxx>
 
 #include <set>
 
+#ifdef _MSC_VER
+#pragma warning(disable: 4702)
+#endif
+
 /// defines the local context mouse selection sensitivity
 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
 
+/// defines the display priority for results brought to front
+constexpr int FRONT_DISPLAY_PRIORITY = 8; /* = Graphic3d_DisplayPriority_Highlight-1 */
+
+/// defines the default (normal) display priority for all results
+constexpr int DEFAULT_DISPLAY_PRIORITY = 5; /* = Graphic3d_DisplayPriority_Normal */
+
 //#define DEBUG_DISPLAY
 //#define DEBUG_FEATURE_REDISPLAY
 //#define DEBUG_SELECTION_FILTERS
 
-//#define DEBUG_COMPOSILID_DISPLAY
-
 //#define DEBUG_OCCT_SHAPE_SELECTION
 
 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
@@ -110,7 +116,11 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
 {
   // Get from null point
-  theAIS->DisplayedObjects(theList, true);
+#if OCC_VERSION_HEX < 0x070400
+       theAIS->DisplayedObjects(theList, true);
+#else
+       theAIS->DisplayedObjects(theList);
+#endif
 }
 
 QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
@@ -125,10 +135,12 @@ QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QS
 
 //**************************************************************
 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
-: myWorkshop(theWorkshop), myNeedUpdate(false),
-  myViewerBlockedRecursiveCount(0), myIsFirstAISContextUse(true)
+: myWorkshop(theWorkshop),
+  myViewerBlockedRecursiveCount(0),
+  myContextId(0),
+  myNeedUpdate(false)
 {
-  myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
+  BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
 }
 
 //**************************************************************
@@ -147,20 +159,6 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
 {
   bool aDisplayed = false;
   if (isVisible(theObject)) {
-#ifdef DEBUG_COMPOSILID_DISPLAY
-    ResultCompSolidPtr aCompsolidResult =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
-    if (aCompsolidResult.get()) {
-      for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-        ResultPtr aSubResult = aCompsolidResult->subResult(i);
-        if (aSubResult.get())
-          redisplay(aSubResult, false);
-      }
-      if (theUpdateViewer)
-        updateViewer();
-    }
-    else
-#endif
     aDisplayed = redisplay(theObject, theUpdateViewer);
   } else {
     AISObjectPtr anAIS;
@@ -173,62 +171,19 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
         aScreen->setViewScale(getViewScale());
       }
       anAIS = aPrs->getAISObject(anAIS);
-      //if (anAIS.get()) {
-        // correct deviation coefficient for
-        /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAISPrs.IsNull()) {
-          Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
-          if (!aShapePrs.IsNull()) {
-            TopoDS_Shape aShape = aShapePrs->Shape();
-            if (!aShape.IsNull())
-              //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
-          }
-        }*/
-      //}
+      if (anAIS.get())
+        myWorkshop->module()->customizePresentation(theObject, anAIS);
     } else {
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-      if (aResult.get() != NULL) {
-#ifdef DEBUG_COMPOSILID_DISPLAY
-        ResultCompSolidPtr aCompsolidResult =
-          std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
-        if (aCompsolidResult.get()) {
-          for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-            ResultPtr aSubResult = aCompsolidResult->subResult(i);
-            if (aSubResult.get())
-              display(aSubResult, false);
-          }
-          if (theUpdateViewer)
-            updateViewer();
-        }
-        else {
-#endif
-        std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-        if (aShapePtr.get() != NULL) {
-          anAIS = AISObjectPtr(new GeomAPI_AISObject());
-          Handle(AIS_InteractiveObject) anAISPrs =
-            myWorkshop->module()->createPresentation(aResult);
-          if (anAISPrs.IsNull())
-            anAISPrs = new ModuleBase_ResultPrs(aResult);
-          else {
-            Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
-            if (!aShapePrs.IsNull())
-              ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
-          }
-          anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
-          //anAIS->createShape(aShapePtr);
-          isShading = true;
-        }
-#ifdef DEBUG_COMPOSILID_DISPLAY
-        } // close else
-#endif
-      }
+      anAIS = myWorkshop->module()->createPresentation(theObject);
+      isShading = true;
     }
-    if (anAIS)
+    if (anAIS.get())
       aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
   }
   return aDisplayed;
 }
 
+
 //**************************************************************
 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
 {
@@ -262,13 +217,18 @@ bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
   if (!anAISIO.IsNull()) {
     appendResultObject(theObject, theAIS);
 
-    bool isCustomized = customizeObject(theObject);
+    //bool isCustomized = customizeObject(theObject);
 
     int aDispMode = isShading? Shading : Wireframe;
-    if (isShading)
-      anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True );
     anAISIO->SetDisplayMode(aDispMode);
-    aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
+    aContext->Display(anAISIO, aDispMode, 0, false, AIS_DS_Displayed);
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (ModelAPI_Tools::isBringToFront(aResult)) {
+      // NOTE: do not use a priority higher than 8 as highlight uses priority 9!
+      //       Any higher level prevents the highlight from being visible as it would
+      //       appear "behind" the Groups.
+      aContext->SetDisplayPriority(anAISIO, FRONT_DISPLAY_PRIORITY);
+    }
     #ifdef TINSPECTOR
     if (getCallBack()) getCallBack()->Display(anAISIO);
     #endif
@@ -277,6 +237,7 @@ bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
     emit objectDisplayed(theObject, theAIS);
     selectionActivate()->activate(anAISIO, theUpdateViewer);
   }
+  myWorkshop->updateGroupsText();
   if (theUpdateViewer)
     updateViewer();
 
@@ -314,7 +275,7 @@ bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
   qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str());
   qDebug(getResult2AISObjectMapInfo().c_str());
 #endif
-
+  myWorkshop->updateGroupsText();
   if (theUpdateViewer)
     updateViewer();
 
@@ -325,11 +286,15 @@ bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
 bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
 {
   bool aRedisplayed = false;
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return aRedisplayed;
+
   if (!isVisible(theObject))
     return aRedisplayed;
 
   AISObjectPtr aAISObj = getAISObject(theObject);
-  Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+  Handle(AIS_InteractiveObject) aAISIO;
 
   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
   if (aPrs) {
@@ -349,64 +314,68 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
     }
     aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
   }
+  else {
+    aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+  }
 
-  Handle(AIS_InteractiveContext) aContext = AISContext();
-  if (!aContext.IsNull() && !aAISIO.IsNull()) {
-    // Check that the visualized shape is the same and the redisplay is not necessary
-    // Redisplay of AIS object leads to this object selection compute and the selection
-    // in the browser is lost
-    // this check is not necessary anymore because the selection store/restore is realized
-    // before and after the values modification.
-    // Moreother, this check avoids customize and redisplay presentation if the presentable
-    // parameter is changed.
-    bool isEqualShapes = false;
+  if (!aAISIO.IsNull()) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (aResult.get() != NULL) {
-      Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
-      if (!aShapePrs.IsNull()) {
-        std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-        if (aShapePtr.get()) {
-          const TopoDS_Shape& aOldShape = aShapePrs->Shape();
-          if (!aOldShape.IsNull())
-            isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
-        }
+    if (aResult.get()) {
+      // Set color
+      std::vector<int> aColor;
+      ModelAPI_Tools::getColor(aResult, aColor);
+      if (aColor.size() > 0) {
+        Quantity_Color
+          aCol(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
+        aAISIO->SetColor(aCol);
+      }
+      // Set deflection
+      double aDeflection = ModelAPI_Tools::getDeflection(aResult);
+      if ((aDeflection >= 0) && (aDeflection != aAISObj->getDeflection()))
+        aAISObj->setDeflection(aDeflection);
+
+      // Set transparency
+      double aTransparency = ModelAPI_Tools::getTransparency(aResult);
+      if ((aTransparency >= 0) && (aTransparency != aAISObj->getTransparency()))
+        aAISObj->setTransparency(aTransparency);
+
+      // Set Iso-Lines
+      Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO);
+      if (!aResPrs.IsNull())
+        aResPrs->updateIsoLines();
+
+      // Only support the "Bring To Front" command for Groups (for now)
+      ResultGroupPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aResult);
+      if (aGroup.get()) {
+        bool isInFront = ModelAPI_Tools::isBringToFront(aResult);
+        aContext->SetDisplayPriority(aAISIO, (isInFront ? FRONT_DISPLAY_PRIORITY : DEFAULT_DISPLAY_PRIORITY));
       }
     }
-    // Customization of presentation
-    bool isCustomized = customizeObject(theObject);
-    #ifdef DEBUG_FEATURE_REDISPLAY
-      qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3").
-        arg(!isEqualShapes || isCustomized).arg(isEqualShapes)
-        .arg(isCustomized).toStdString().c_str());
-    #endif
-    if (!isEqualShapes || isCustomized) {
-      /// if shapes are equal and presentation are customized, selection should be restored
-      bool aNeedToRestoreSelection = isEqualShapes && isCustomized;
-      if (aNeedToRestoreSelection)
-        myWorkshop->module()->storeSelection();
-
-#ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
-      myWorkshop->selector()->deselectPresentation(aAISIO);
-#endif
-      if (aContext->IsDisplayed(aAISIO))
-        aContext->Redisplay(aAISIO, false);
-      else
-        aContext->Display(aAISIO, false);
+    //myWorkshop->module()->storeSelection();
+
+//#ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
+    //myWorkshop->selector()->deselectPresentation(aAISIO);
+//#endif
 
+    if (aContext->IsDisplayed(aAISIO))
+      aContext->Redisplay(aAISIO, false);
+    else {
+      aContext->Display(aAISIO, false);
+    }
       #ifdef TINSPECTOR
       if (getCallBack()) getCallBack()->Redisplay(aAISIO);
       #endif
 
-      if (aNeedToRestoreSelection)
-        myWorkshop->module()->restoreSelection();
+      //if (aNeedToRestoreSelection)
+    //myWorkshop->module()->restoreSelection();
 
-      aRedisplayed = true;
-      #ifdef DEBUG_FEATURE_REDISPLAY
-        qDebug("  Redisplay happens");
-      #endif
-      if (theUpdateViewer)
-        updateViewer();
-    }
+    aRedisplayed = true;
+    #ifdef DEBUG_FEATURE_REDISPLAY
+      qDebug("  Redisplay happens");
+    #endif
+    myWorkshop->updateGroupsText();
+    if (theUpdateViewer)
+      updateViewer();
   }
   return aRedisplayed;
 }
@@ -417,11 +386,16 @@ void XGUI_Displayer::redisplayObjects()
   // redisplay objects visualized in the viewer
   static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-  QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
+  QObjectPtrList aDisplayed = displayedObjects();
   QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
   for (; anIt != aLast; anIt++) {
     aECreator->sendUpdated(*anIt, EVENT_DISP);
   }
+  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+  if (aViewer->isColorScaleVisible()) {
+    aViewer->setupColorScale();
+    aViewer->setColorScaleShown(true);
+  }
   Events_Loop::loop()->flush(EVENT_DISP);
 }
 
@@ -581,6 +555,7 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer)
         aErased = true;
       }
     }
+    myWorkshop->updateGroupsText();
     if (theUpdateViewer)
       updateViewer();
   }
@@ -635,7 +610,8 @@ ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO)
     if (!theIO.IsNull()) {
       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO));
     }
-    anObject = myWorkshop->module()->findPresentedObject(anAISObj);
+    if (myWorkshop->module())
+      anObject = myWorkshop->module()->findPresentedObject(anAISObj);
   }
   return anObject;
 }
@@ -660,12 +636,6 @@ bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
   return aWasEnabled;
 }
 
-//**************************************************************
-bool XGUI_Displayer::isUpdateEnabled() const
-{
-  return myViewerBlockedRecursiveCount == 0;
-}
-
 //**************************************************************
 void XGUI_Displayer::updateViewer() const
 {
@@ -688,28 +658,52 @@ void XGUI_Displayer::updateViewer() const
 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
 {
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) {
-    XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
-    aDisplayer->myIsFirstAISContextUse = false;
+  if (!aContext.IsNull() && (myContextId != aContext.get())) {
+    myContextId = aContext.get();
     if (!myWorkshop->selectionActivate()->isTrihedronActive())
       selectionActivate()->deactivateTrihedron(true);
-    aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
-    aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
 
+    // Commented out according to discussion in bug #2825
     ModuleBase_IViewer::DefaultHighlightDrawer = aContext->HighlightStyle();
-    Handle(Prs3d_Drawer) aSelStyle = aContext->SelectionStyle();
-    double aDeflection =
-      QString(ModelAPI_ResultConstruction::DEFAULT_DEFLECTION().c_str()).toDouble();
-    try {
-      aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
-    } catch (...) {}
-
-    ModuleBase_IViewer::DefaultHighlightDrawer->SetDeviationCoefficient(aDeflection);
-    aSelStyle->SetDeviationCoefficient(aDeflection);
+
+    Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron();
+    if (!aTrihedron.IsNull())
+      ModuleBase_Tools::setPointBallHighlighting(aTrihedron.get());
   }
   return aContext;
 }
 
+//**************************************************************
+void XGUI_Displayer::setSelectionColor(const std::vector<int>& theColor)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    Quantity_Color aQColor(theColor[0] / 255.,
+                           theColor[1] / 255.,
+                           theColor[2] / 255., Quantity_TOC_RGB);
+    aContext->SelectionStyle()->SetColor(aQColor);
+    aContext->SelectionStyle()->PointAspect()->SetColor(aQColor);
+    aContext->SelectionStyle()->LineAspect()->SetColor(aQColor);
+    aContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor(aQColor);
+  }
+}
+
+
+//**************************************************************
+std::vector<int> XGUI_Displayer::selectionColor() const
+{
+  std::vector<int> aColor;
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    Quantity_Color aQColor = aContext->SelectionStyle()->Color();
+    aColor.push_back((int)(aQColor.Red() * 255));
+    aColor.push_back((int)(aQColor.Green() * 255));
+    aColor.push_back((int)(aQColor.Blue() * 255));
+  }
+  return aColor;
+}
+
+
 //**************************************************************
 Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
 {
@@ -729,7 +723,7 @@ bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSele
   Handle(AIS_InteractiveContext) aContext = AISContext();
   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
   if (!aContext.IsNull() && !anAISIO.IsNull()) {
-    aContext->Display(anAISIO, theDisplayMode, 0, false/*update viewer*/, true, AIS_DS_Displayed);
+    aContext->Display(anAISIO, theDisplayMode, 0, false/*update viewer*/, AIS_DS_Displayed);
     #ifdef TINSPECTOR
     if (getCallBack()) getCallBack()->Display(anAISIO);
     #endif
@@ -932,39 +926,6 @@ bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const
   return ::canBeShaded(anAIS, myWorkshop->module());
 }
 
-//**************************************************************
-bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
-{
-  AISObjectPtr anAISObj = getAISObject(theObject);
-  // correct the result's color it it has the attribute
-  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-
-  // Customization of presentation
-  GeomCustomPrsPtr aCustomPrs;
-  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-  if (aFeature.get() != NULL) {
-    GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
-    if (aCustPrs.get() != NULL)
-      aCustomPrs = aCustPrs;
-  }
-  if (aCustomPrs.get() == NULL) {
-    GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
-    // we ignore presentable not customized objects
-    if (aPrs.get() == NULL)
-      aCustomPrs = myCustomPrs;
-  }
-  bool isCustomized = aCustomPrs.get() &&
-                      aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
-  isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs)
-                 || isCustomized;
-
-  // update presentation state if faces panel is active
-  if (anAISObj.get() && myWorkshop->facesPanel())
-    isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized;
-
-  return isCustomized;
-}
-
 //**************************************************************
 QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
                                       const QColor& theColor,
@@ -977,6 +938,7 @@ QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject,
   int aR, aG, aB;
   anAISObj->getColor(aR, aG, aB);
   anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
+  myWorkshop->updateGroupsText();
   if (theUpdateViewer)
     updateViewer();
   return QColor(aR, aG, aB);
@@ -1058,9 +1020,9 @@ void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
     ModelAPI_Tools::allResults(aFeature, aResults);
     std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
     for (; anIt != aLast; ++anIt) {
-      AISObjectPtr aAISObj = getAISObject(*anIt);
-      if (aAISObj.get() != NULL) {
-        Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+      AISObjectPtr aCurAISObj = getAISObject(*anIt);
+      if (aCurAISObj.get() != NULL) {
+        Handle(AIS_InteractiveObject) anAIS = aCurAISObj->impl<Handle(AIS_InteractiveObject)>();
         if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
           thePresentations.Add(anAIS);
       }
@@ -1084,7 +1046,6 @@ void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
                         0 /*wireframe*/,
                         -1 /* selection mode */,
                         Standard_True /* update viewer*/,
-                        Standard_False /* allow decomposition */,
                         AIS_DS_Displayed /* xdisplay status */);
     #ifdef TINSPECTOR
     if (getCallBack()) getCallBack()->Display(aTrihedron);
@@ -1102,8 +1063,6 @@ void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
     if (getCallBack()) getCallBack()->Remove(aTrihedron);
     #endif
   }
-
-  updateViewer();
 }
 
 //**************************************************************
@@ -1126,7 +1085,7 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
   /// OCCT: to write about the problem that active owners method returns one owner several times
   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());
+    anOwner = anOwnersIt.Value();
     if (aSelectedIds.contains((size_t)anOwner.get()))
       continue;
     aSelectedIds.append((size_t)anOwner.get());
@@ -1134,6 +1093,14 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
     Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
     if (!BROwnr.IsNull() && BROwnr->HasShape()) {
       const TopoDS_Shape& aShape = BROwnr->Shape();
+
+      Handle(ModuleBase_ResultPrs) aResPrs =
+          Handle(ModuleBase_ResultPrs)::DownCast(BROwnr->Selectable());
+      TopoDS_Shape aRealShape;
+      if (!aResPrs.IsNull()) {
+        aRealShape = aResPrs->originalShape();
+      }
+
       if (aShape.IsNull())
         continue;
 
@@ -1143,17 +1110,29 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
                                              ::Iterator aShapeIt(theShapesToBeSelected);
       for (; aShapeIt.More(); aShapeIt.Next()) {
         const TopoDS_Shape& aParameterShape = aShapeIt.Key();
-        // isSame should be used here as it does not check orientation of shapes
-        // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
-        // different for Edges shapes in model shape and owner even if this is the same shape
-        if (aParameterShape.IsSame(aShape)) {
+        // In case of compound we cannot rely on simple comparison method.
+        // If the compound is generated by Group feature then this compound is alwais new.
+        // So, we have to compare content of these compounds
+
+          // isSame should be used here as it does not check orientation of shapes
+          // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
+          // different for Edges shapes in model shape and owner even if this is the same shape
+        bool isSame = ModuleBase_Tools::isSameShape(aParameterShape, aShape);
+        if (!isSame) {
+          // In case of using HideFaces panel we can have instead of an original shape
+          // a compaund of faces which represent original shape with hidden faces.
+          // So, we have to compare the parameter with original shape
+          if (!aRealShape.IsNull())
+            isSame = ModuleBase_Tools::isSameShape(aParameterShape, aRealShape);
+        }
+        if (isSame) {
           Handle(AIS_InteractiveObject) anOwnerPresentation =
-                            Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
+            Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
           NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
-                                      theShapesToBeSelected.Find(aParameterShape);
+            theShapesToBeSelected.Find(aParameterShape);
           if (aPresentations.Contains(anOwnerPresentation)) {
             theContext->AddOrRemoveSelected(anOwner, Standard_False);
-            anOwner->SetSelected (Standard_True);
+            anOwner->SetSelected(Standard_True);
             // collect selected presentations to do not select them if compsolid is selected
             if (!aSelectedPresentations.Contains(anOwnerPresentation))
               aSelectedPresentations.Add(anOwnerPresentation);
@@ -1165,7 +1144,7 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
           Handle(AIS_Shape) anOwnerPresentation =
                             Handle(AIS_Shape)::DownCast(anOwner->Selectable());
           const TopoDS_Shape& aPresentationShape = anOwnerPresentation->Shape();
-          if (aParameterShape.IsSame(anOwnerPresentation->Shape()) &&
+          if (aParameterShape.IsSame(aPresentationShape) &&
               !aCompsolidPresentations.Contains(anOwnerPresentation))
             aCompsolidPresentations.Add(anOwnerPresentation);
         }
@@ -1194,11 +1173,7 @@ GeomPlanePtr XGUI_Displayer::getScreenPlane() const
   Handle(AIS_InteractiveContext) aContext = AISContext();
   if (!aContext.IsNull()) {
     Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
-    Handle(V3d_View) aView;
-    for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) {
-      aView = aViewer->ActiveView();
-      break;
-    }
+    Handle(V3d_View) aView = aViewer->ActiveViews().First();
     if (!aView.IsNull()) {
       double aEyeX, aEyeY, aEyeZ;
       aView->Eye(aEyeX, aEyeY, aEyeZ);
@@ -1220,11 +1195,7 @@ double XGUI_Displayer::getViewScale() const
   Handle(AIS_InteractiveContext) aContext = AISContext();
   if (!aContext.IsNull()) {
     Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
-    Handle(V3d_View) aView;
-    for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) {
-      aView = aViewer->ActiveView();
-      break;
-    }
+    Handle(V3d_View) aView = aViewer->ActiveViews().First();
     return aView->Camera()->Scale();
   }
   return 1;