]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1897 Selection of edges in Group feature with SHIFT Key
authornds <nds@opencascade.com>
Tue, 31 Jan 2017 14:31:06 +0000 (17:31 +0300)
committernds <nds@opencascade.com>
Tue, 31 Jan 2017 14:31:06 +0000 (17:31 +0300)
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/Model/Model_AttributeSelectionList.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_SelectionMgr.cpp

index 9d3694bf1c114d8524cc8e8ede5786a5722e767c..6c0c7f27af4498c208f01eda6ac269b77f435288 100644 (file)
@@ -61,6 +61,18 @@ bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
   return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
 }
 
+bool GeomAPI_Shape::isSame(const std::shared_ptr<GeomAPI_Shape> theShape) const
+{
+  if (!theShape.get())
+    return false;
+  if (isNull())
+    return theShape->isNull();
+  if (theShape->isNull())
+    return false;
+
+  return MY_SHAPE->IsSame(theShape->impl<TopoDS_Shape>()) == Standard_True;
+}
+
 bool GeomAPI_Shape::isVertex() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
index ccb1153d33c57809a7bf76c3f337ee64ba3200b1..093779c7b2fc5b5142d9c53b7904f3ec8dc006ca 100644 (file)
@@ -50,6 +50,10 @@ public:
   GEOMAPI_EXPORT
   virtual bool isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const;
 
+  /// Returns whether the shapes are same
+  GEOMAPI_EXPORT
+  virtual bool isSame(const std::shared_ptr<GeomAPI_Shape> theShape) const;
+
   /// Returns whether the shape is a vertex
   GEOMAPI_EXPORT
   virtual bool isVertex() const;
index 29f23b24e72a8bfec5daa1712c9f1b35021ed462..16e5d73dea22784bc3ebfadeb43c651c15cdb1d7 100644 (file)
@@ -217,14 +217,15 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext,
     std::map<ResultPtr, std::list<std::shared_ptr<GeomAPI_Shape> > >::iterator aContext =
       myCash.find(theContext);
     if (aContext != myCash.end()) {
-      // iterate shapes because "isEqual" method must be called for each shape
+      // iterate shapes because "isSame" method must be called for each shape
       std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aShapes = aContext->second.begin();
       for(; aShapes != aContext->second.end(); aShapes++) {
         if (!theSubShape.get()) {
           if (!aShapes->get())
             return true;
         } else {
-          if (theSubShape->isEqual(*aShapes))
+          // we need to call here isSame instead of isEqual to do not check shapes orientation
+          if (theSubShape->isSame(*aShapes))
             return true;
         }
       }
@@ -242,7 +243,8 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext,
             return true;
           }
         } else {
-          if (aValue->isEqual(theSubShape)) // shapes are equal
+          // we need to call here isSame instead of isEqual to do not check shapes orientation
+          if (aValue->isSame(theSubShape)) // shapes are equal
             return true;
         }
       }
index fe5e99ecc75774a09de5d31c28f4b29f7b17edd5..81bf3970fe89dbc9b58d4b1e2d8dcbb8a1a79e06 100755 (executable)
@@ -91,7 +91,8 @@ protected:
 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
                                                                ModuleBase_IWorkshop* theWorkshop,
                                                                const Config_WidgetAPI* theData)
-: ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
+: ModuleBase_WidgetSelector(theParent, theWorkshop, theData),
+  myIsSetSelectionBlocked(false)
 {
   QGridLayout* aMainLay = new QGridLayout(this);
   ModuleBase_Tools::adjustMargins(aMainLay);
@@ -225,6 +226,9 @@ bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
                                                   const bool theToValidate)
 {
+  if (myIsSetSelectionBlocked)
+    return false;
+
   AttributeSelectionListPtr aSelectionListAttr;
   if (attribute()->attributeType() == ModelAPI_AttributeSelectionList::typeId())
     aSelectionListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(attribute());
@@ -271,6 +275,17 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>
     //emit valuesChanged();
   //}
 
+  // Restore selection in the viewer by the attribute selection list
+  // it is possible that diring selection attribute filling, selection in Object Browser
+  // is changed(some items were removed/added) and as result, selection in the viewer
+  // differs from the selection come to this method. By next rows, we restore selection
+  // in the viewer according to content of selection attribute. Case is Edge selection in Group
+  myIsSetSelectionBlocked = true;
+  static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION);
+  ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
+  Events_Loop::loop()->flush(anEvent);
+  myIsSetSelectionBlocked = false;
+
   if (aSelectionListAttr.get())
     aSelectionListAttr->cashValues(false);
 
index 1e61a581e5ef371b3fe9553bbf696162097761db..e7713928ad6fc28d55d18224fd3c9b7bddb4b699 100755 (executable)
@@ -195,6 +195,9 @@ protected:
 
   /// A flag to clear selection by click in empty place in the viewer
   bool myIsNeutralPointClear;
+
+  /// A flag to block set selection perform if the method is in process
+  bool myIsSetSelectionBlocked;
 };
 
 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index fc9b169dfac26d536250e47281de9bd461c9d41c..506ae75d6f78d96005cb7fbed1e719bbf8277e34 100644 (file)
@@ -16,8 +16,7 @@
 #endif
 
 #ifdef VINSPECTOR
-#include <VInspectorAPI_PluginMgr.h>
-#include <VInspectorAPI_Communicator.h>
+#include <VInspectorAPI_Communicator.hxx>
 #ifndef HAVE_SALOME
 #include <AppElements_MainWindow.h>
 #endif
@@ -67,7 +66,7 @@ static bool VInspector_FirstCall = true;
 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
 
 #ifdef VINSPECTOR
-#include <VInspectorAPI_CallBack.h>
+#include <VInspectorAPI_CallBack.hxx>
 #endif
 
 #include <Events_Loop.h>
@@ -1047,14 +1046,19 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
 #ifdef VINSPECTOR
     if (VInspector_FirstCall) {
       XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this;
-      VInspectorAPI_Communicator* aCommunicator = VInspectorAPI_PluginMgr::activateVInspector(
-                                        "VInspector.dll", aContext);
-      aDisplayer->setCommunicator(aCommunicator);
-      #ifndef HAVE_SALOME
-      AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
-      if (aViewer)
-        aViewer->setCallBack(aCommunicator->getCallBack());
-      #endif
+
+      VInspectorAPI_Communicator* aCommunicator =
+                     VInspectorAPI_Communicator::loadPluginLibrary("TKVInspector.dll");
+      if (aCommunicator) {
+        aCommunicator->setContext(aContext);
+
+        aDisplayer->setCommunicator(aCommunicator);
+        #ifndef HAVE_SALOME
+        AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+        if (aViewer)
+          aViewer->setCallBack(aCommunicator->getCallBack());
+        #endif
+      }
       VInspector_FirstCall = false;
     }
 #endif
@@ -1578,14 +1582,27 @@ 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();
-      if (!aShape.IsNull() && theShapesToBeSelected.IsBound(aShape)) {
-        Handle(AIS_InteractiveObject) anOwnerPresentation =
-                                    Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
-        NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
-                                    theShapesToBeSelected.Find(aShape);
-        if (aPresentations.Contains(anOwnerPresentation)) {
-          theContext->AddOrRemoveSelected(anOwner);
-          anOwner->SetSelected (Standard_True);
+      if (aShape.IsNull())
+        continue;
+
+      NCollection_DataMap<TopoDS_Shape,
+        NCollection_Map<Handle(AIS_InteractiveObject)> >::Iterator aShapeIt(theShapesToBeSelected);
+      for (; aShapeIt.More(); aShapeIt.Next()) {
+        if (aShapeIt.Key().IsSame(aShape)) {
+          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 and owner even if this is one shape
+          if (aParameterShape.IsSame(aShape)) {
+            Handle(AIS_InteractiveObject) anOwnerPresentation =
+                                        Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
+            NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
+                                        theShapesToBeSelected.Find(aParameterShape);
+            if (aPresentations.Contains(anOwnerPresentation)) {
+              theContext->AddOrRemoveSelected(anOwner);
+              anOwner->SetSelected (Standard_True);
+            }
+          }
         }
       }
     }
index bccb7ddcf003b398acaac8434538aa8f171c4782..5af4ea4c3f4739988c0d331433bb58b6507f1b20 100644 (file)
@@ -242,24 +242,6 @@ QList<ModuleBase_ViewerPrsPtr> XGUI_Selection::getHighlighted() const
       fillPresentation(aPrs, anOwner);
       aPresentations.push_back(aPrs);
     }
-    else { // TODO: check why the entity owner is null here, case is selection point on a line
-      Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
-      ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
-      aPrs->setInteractive(anIO);
-
-      ObjectPtr aResult = aDisplayer->getObject(anIO);
-      // we should not check the appearance of this feature because there can be some selected
-      // shapes for one feature
-      aPrs->setObject(aResult);
-      TopoDS_Shape aShape = aContext->DetectedShape();
-      if (!aShape.IsNull()) {
-        std::shared_ptr<GeomAPI_Shape> aGeomShape =
-          std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-        aGeomShape->setImpl(new TopoDS_Shape(aShape));
-        aPrs->setShape(aGeomShape);
-      }
-      aPresentations.push_back(aPrs);
-    }
   }
   return aPresentations;
 }
index a442f465ca673b0a5fea6e0322e8cb092ad09cee..df975ca9578ec657acc5aff23c8213248225ff67 100755 (executable)
@@ -27,7 +27,7 @@
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 
 #ifdef VINSPECTOR
-#include <VInspectorAPI_CallBack.h>
+#include <VInspectorAPI_CallBack.hxx>
 #endif
 
 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)