Salome HOME
Code improvement: avoid the code duplication for setSelected method in the displayer...
authornds <natalia.donis@opencascade.com>
Thu, 21 May 2015 05:32:15 +0000 (08:32 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 21 May 2015 05:32:15 +0000 (08:32 +0300)
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ISelection.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_ISelection.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/XGUI/XGUI_Displayer.cpp

index 3b2c8a279a9c35e4f126f4239121fbfbc2e3739f..c54208e1205b88f74a51fcd0b62e9efc913eb41f 100644 (file)
@@ -21,12 +21,12 @@ SET(PROJECT_HEADERS
        ModuleBase_IWorkshop.h
        ModuleBase_Definitions.h
        ModuleBase_SelectionValidator.h
-       ModuleBase_ISelection.h
        ModuleBase_ViewerPrs.h
        ModuleBase_WidgetChoice.h
        ModuleBase_WidgetFileSelector.h
        ModuleBase_DoubleSpinBox.h
        ModuleBase_IPropertyPanel.h
+       ModuleBase_ISelection.h
        ModuleBase_IViewer.h
        ModuleBase_WidgetLineEdit.h
        ModuleBase_WidgetMultiSelector.h
@@ -56,6 +56,7 @@ SET(PROJECT_SOURCES
        ModuleBase_FilterValidated.cpp
        ModuleBase_Tools.cpp
        ModuleBase_IModule.cpp
+       ModuleBase_ISelection.cpp
        ModuleBase_IWorkshop.cpp
        ModuleBase_Operation.cpp
        ModuleBase_OperationDescription.cpp
diff --git a/src/ModuleBase/ModuleBase_ISelection.cpp b/src/ModuleBase/ModuleBase_ISelection.cpp
new file mode 100644 (file)
index 0000000..1904476
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include "ModuleBase_ISelection.h"
+
+QList<ModuleBase_ViewerPrs> ModuleBase_ISelection::getViewerPrs(const QObjectPtrList& theObjects)
+{
+  QList<ModuleBase_ViewerPrs> aSelectedPrs;
+  QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
+  for (; anIt != aLast; anIt++) {
+    ObjectPtr anObject = *anIt;
+    if (anObject.get() != NULL) {
+      aSelectedPrs.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
+    }
+  }
+  return aSelectedPrs;
+}
index b2686be48496f03077af7524b2bb656e6d7e461c..86cfd4f527c5ef6ed7b404ef947b30b0f737cb5e 100644 (file)
@@ -70,6 +70,11 @@ class ModuleBase_ISelection
   virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList, 
     std::list<ObjectPtr>& theOwners) const = 0;
 
+  //! Wraps the object list into the viewer prs list
+  //! \param theObjects a list of objects
+  //! \return a list of prs, where only object is not empty
+  static MODULEBASE_EXPORT QList<ModuleBase_ViewerPrs> getViewerPrs(
+                                                       const QObjectPtrList& theObjects);
 };
 
 #endif
index a5ec4c5fe52498c83bc6d50eaaa8624c6e0d7c9a..4dcf23973ff31c7239325deba633f9aa06dfabf9 100644 (file)
@@ -136,13 +136,7 @@ QList<ModuleBase_ViewerPrs> ModuleBase_WidgetValidated::getSelectedEntitiesOrObj
   if (aSelectedPrs.empty()) {
     // the selection in Object Browser
     QObjectPtrList anObjects = theSelection->selectedObjects();
-    QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
-    for (; anIt != aLast; anIt++) {
-      ObjectPtr anObject = *anIt;
-      if (anObject.get() != NULL) {
-        aSelectedPrs.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
-      }
-    }
+    aSelectedPrs = ModuleBase_ISelection::getViewerPrs(anObjects);
   }
   return aSelectedPrs;
 }
index ce6aadefccc27003aa65cee1f139a9ecfc48b1ce..5254c1ea6d40e10be803a613fa7ae93ba2217c14 100644 (file)
@@ -416,44 +416,6 @@ bool XGUI_Displayer::isActive(ObjectPtr theObject) const
   return aModes.Extent() > 0;
 }
 
-void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer)
-{
-  Handle(AIS_InteractiveContext) aContext = AISContext();
-  if (aContext.IsNull())
-    return;
-  if (aContext->HasOpenedContext()) {
-    aContext->UnhilightSelected();
-    aContext->ClearSelected();
-    foreach(ObjectPtr aResult, theResults) {
-      if (isVisible(aResult)) {
-        AISObjectPtr anObj = myResult2AISObjectMap[aResult];
-        Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAIS.IsNull()) {
-          // The methods are replaced in order to provide multi-selection, e.g. restore selection
-          // by activating multi selector widget. It also gives an advantage that the multi
-          // selection in OB gives multi-selection in the viewer
-          //aContext->SetSelected(anAIS, false);
-          // The selection in the context was cleared, so the method sets the objects are selected
-          aContext->AddOrRemoveSelected(anAIS, false);
-        }
-      }
-    }
-  } else {
-    aContext->UnhilightCurrents();
-    aContext->ClearCurrents();
-    foreach(ObjectPtr aResult, theResults) {
-      if (isVisible(aResult)) {
-        AISObjectPtr anObj = myResult2AISObjectMap[aResult];
-        Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAIS.IsNull())
-          aContext->SetCurrentObject(anAIS, false);
-      }
-    }
-  }
-  if (isUpdateViewer)
-    updateViewer();
-}
-
 void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrs>& theValues, bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();