]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Select sub-shapes by shape selector widget
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 9 Oct 2014 14:54:47 +0000 (18:54 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 9 Oct 2014 14:54:47 +0000 (18:54 +0400)
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h

index e70e5dc08b011513a8ce6d8b549ea9cce6909de7..e1eed428d90ab242b4c62eb42dddc762759f52fa 100644 (file)
@@ -172,26 +172,44 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
     if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
       return;
 
-    // Check that the selection corresponds to selection type
-    if (!isAccepted(aObject))
-      return;
+    // Get sub-shapes from local selection
+    boost::shared_ptr<GeomAPI_Shape> aShape;
+    if (myUseSubShapes) {
+      NCollection_List<TopoDS_Shape> aShapeList;
+      myWorkshop->selection()->selectedShapes(aShapeList);
+      if (aShapeList.Extent() > 0) {
+        aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+        aShape->setImpl(new TopoDS_Shape(aShapeList.First()));
+      }
+    }
 
-    setObject(aObject);
+    // Check that the selection corresponds to selection type
+    if (myUseSubShapes) {
+      if (!isAccepted(aShape))
+        return;
+    } else {
+      if (!isAccepted(aObject))
+        return;
+    }
+    setObject(aObject, aShape);
     emit focusOutWidget(this);
   }
 }
 
 //********************************************************************
-void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj)
+void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape)
 {
   if (mySelectedObject == theObj)
     return;
   mySelectedObject = theObj;
+  myShape = theShape;
   if (mySelectedObject) {
     raisePanel();
-    static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
-    ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
-    Events_Loop::loop()->flush(anEvent);
+    if (!myUseSubShapes) {
+      static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
+      ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
+      Events_Loop::loop()->flush(anEvent);
+    }
   } 
   updateSelectionName();
   activateSelection(false);
@@ -241,6 +259,17 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
   return false;
 }
 
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const
+{
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  foreach (QString aType, myShapeTypes) {
+    if (aShape.ShapeType() == shapeType(aType))
+      return true;
+  }
+  return false;
+}
+
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::updateSelectionName()
 {
index 760e371a82ce489cccab6889e26694252e5f87c7..bf9cb955f6d144316d485a2ec6beb9d492195bec 100644 (file)
@@ -76,9 +76,10 @@ private:
   void updateSelectionName();
   void raisePanel() const;
   bool isAccepted(const ObjectPtr theObject) const;
+  bool isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const;
 
   // Set the given object as a value of the widget
-  void setObject(ObjectPtr theObj);
+  void setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
 
   static TopAbs_ShapeEnum shapeType(const QString& theType);