diff --git a/src/Mod/Part/Gui/TaskShapeBuilder.cpp b/src/Mod/Part/Gui/TaskShapeBuilder.cpp index b825bf37f4..d0917bbd5c 100644 --- a/src/Mod/Part/Gui/TaskShapeBuilder.cpp +++ b/src/Mod/Part/Gui/TaskShapeBuilder.cpp @@ -24,11 +24,13 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include # include # include # include # include +# include #endif #include "ViewProviderExt.h" @@ -134,6 +136,36 @@ ShapeBuilderWidget::~ShapeBuilderWidget() delete d; } +void ShapeBuilderWidget::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if (d->ui.checkFaces->isChecked()) { + if (msg.Type == Gui::SelectionChanges::AddSelection) { + std::string subName(msg.pSubName); + if (!subName.empty()) { + // From the shape get all faces and add them to the selection + bool blocked = blockConnection(true); + App::Document* doc = App::GetApplication().getDocument(msg.pDocName); + App::DocumentObject* obj = doc->getObject(msg.pObjectName); + if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + TopoDS_Shape myShape = static_cast(obj)->Shape.getValue(); + TopTools_IndexedMapOfShape all_faces; + TopExp::MapShapes(myShape, TopAbs_FACE, all_faces); + for (int i=1; i<= all_faces.Extent(); i++) { + TopoDS_Shape face = all_faces(i); + if (!face.IsNull()) { + std::stringstream str; + str << "Face" << i; + Gui::Selection().addSelection(msg.pDocName, msg.pObjectName, str.str().c_str()); + } + } + } + + blockConnection(blocked); + } + } + } +} + void ShapeBuilderWidget::on_createButton_clicked() { int mode = d->bg.checkedId(); diff --git a/src/Mod/Part/Gui/TaskShapeBuilder.h b/src/Mod/Part/Gui/TaskShapeBuilder.h index c2682f278d..6af6410e9a 100644 --- a/src/Mod/Part/Gui/TaskShapeBuilder.h +++ b/src/Mod/Part/Gui/TaskShapeBuilder.h @@ -26,10 +26,12 @@ #include #include +#include namespace PartGui { -class ShapeBuilderWidget : public QWidget +class ShapeBuilderWidget : public QWidget, + public Gui::SelectionObserver { Q_OBJECT @@ -44,6 +46,9 @@ private Q_SLOTS: void on_createButton_clicked(); void switchMode(int); +private: + virtual void onSelectionChanged(const Gui::SelectionChanges& msg); + private: void createEdgeFromVertex(); void createFaceFromVertex();