From bab9b98219f328a4ea8aa265fef304208495fa03 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 9 Oct 2014 18:54:47 +0400 Subject: [PATCH] Select sub-shapes by shape selector widget --- .../ModuleBase_WidgetShapeSelector.cpp | 45 +++++++++++++++---- .../ModuleBase_WidgetShapeSelector.h | 3 +- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index e70e5dc08..e1eed428d 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -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 aShape; + if (myUseSubShapes) { + NCollection_List aShapeList; + myWorkshop->selection()->selectedShapes(aShapeList); + if (aShapeList.Extent() > 0) { + aShape = boost::shared_ptr(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 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 theShape) const +{ + TopoDS_Shape aShape = theShape->impl(); + foreach (QString aType, myShapeTypes) { + if (aShape.ShapeType() == shapeType(aType)) + return true; + } + return false; +} + //******************************************************************** void ModuleBase_WidgetShapeSelector::updateSelectionName() { diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 760e371a8..bf9cb955f 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -76,9 +76,10 @@ private: void updateSelectionName(); void raisePanel() const; bool isAccepted(const ObjectPtr theObject) const; + bool isAccepted(boost::shared_ptr theShape) const; // Set the given object as a value of the widget - void setObject(ObjectPtr theObj); + void setObject(ObjectPtr theObj, boost::shared_ptr theShape = boost::shared_ptr()); static TopAbs_ShapeEnum shapeType(const QString& theType); -- 2.39.2