select all faces in shape builder if this option is activated

This commit is contained in:
wmayer
2017-08-10 19:10:07 +02:00
parent 6c4bdf24df
commit 8203a35a0f
2 changed files with 38 additions and 1 deletions

View File

@@ -24,11 +24,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <QButtonGroup>
# include <QMessageBox>
# include <QTextStream>
# include <sstream>
#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<Part::Feature*>(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();

View File

@@ -26,10 +26,12 @@
#include <Gui/TaskView/TaskView.h>
#include <Gui/TaskView/TaskDialog.h>
#include <Gui/Selection.h>
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();