diff --git a/src/Mod/Part/Gui/TaskFaceColors.cpp b/src/Mod/Part/Gui/TaskFaceColors.cpp index ba593b5da..4d2a3b192 100644 --- a/src/Mod/Part/Gui/TaskFaceColors.cpp +++ b/src/Mod/Part/Gui/TaskFaceColors.cpp @@ -24,10 +24,18 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include +# include +# include +# include +# include # include +# include # include # include # include +# include +# include #endif #include @@ -40,7 +48,11 @@ #include #include #include +#include #include +#include +#include +#include #include #include @@ -106,6 +118,66 @@ public: { delete ui; } + void addFacesToSelection(const Gui::ViewVolumeProjection& proj, const Base::Polygon2D& polygon, const TopoDS_Shape& shape) + { + try { + TopTools_IndexedMapOfShape M; + + TopExp_Explorer xp_face(shape,TopAbs_FACE); + while (xp_face.More()) { + M.Add(xp_face.Current()); + xp_face.Next(); + } + + App::Document* appdoc = doc->getDocument(); + for (Standard_Integer k = 1; k <= M.Extent(); k++) { + const TopoDS_Shape& face = M(k); + + GProp_GProps props; + BRepGProp::SurfaceProperties(face, props); + gp_Pnt c = props.CentreOfMass(); + Base::Vector3d pt2d; + pt2d = proj(Base::Vector3d(c.X(), c.Y(), c.Z())); + if (polygon.Contains(Base::Vector2D(pt2d.x, pt2d.y))) { + std::stringstream str; + str << "Face" << k; + Gui::Selection().addSelection(appdoc->getName(), obj->getNameInDocument(), str.str().c_str()); + } + } + } + catch (...) { + } + } + static void selectionCallback(void * ud, SoEventCallback * cb) + { + Gui::View3DInventorViewer* view = reinterpret_cast(cb->getUserData()); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), selectionCallback, ud); + + std::vector picked = view->getGLPolygon(); + SoCamera* cam = view->getCamera(); + SbViewVolume vv = cam->getViewVolume(); + Gui::ViewVolumeProjection proj(vv); + Base::Polygon2D polygon; + if (picked.size() == 2) { + SbVec2f pt1 = picked[0]; + SbVec2f pt2 = picked[1]; + polygon.Add(Base::Vector2D(pt1[0], pt1[1])); + polygon.Add(Base::Vector2D(pt1[0], pt2[1])); + polygon.Add(Base::Vector2D(pt2[0], pt2[1])); + polygon.Add(Base::Vector2D(pt2[0], pt1[1])); + } + else { + for (std::vector::const_iterator it = picked.begin(); it != picked.end(); ++it) + polygon.Add(Base::Vector2D((*it)[0],(*it)[1])); + } + + FaceColors* self = reinterpret_cast(ud); + if (self->d->obj && self->d->obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + cb->setHandled(); + const TopoDS_Shape& shape = static_cast(self->d->obj)->Shape.getValue(); + self->d->addFacesToSelection(proj, polygon, shape); + } + } }; /* TRANSLATOR PartGui::TaskFaceColors */ @@ -146,6 +218,18 @@ void FaceColors::slotDeleteObject(const Gui::ViewProvider& obj) Gui::Control().closeDialog(); } +void FaceColors::on_boxSelection_clicked() +{ + Gui::View3DInventor* view = qobject_cast(Gui::getMainWindow()->activeWindow()); + if (view) { + Gui::View3DInventorViewer* viewer = view->getViewer(); + if (!viewer->isSelecting()) { + viewer->startSelection(Gui::View3DInventorViewer::Rubberband); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), Private::selectionCallback, this); + } + } +} + void FaceColors::on_defaultButton_clicked() { std::fill(d->perface.begin(), d->perface.end(), d->vp->ShapeColor.getValue()); diff --git a/src/Mod/Part/Gui/TaskFaceColors.h b/src/Mod/Part/Gui/TaskFaceColors.h index 3ba96c9ce..be4e0e0ea 100644 --- a/src/Mod/Part/Gui/TaskFaceColors.h +++ b/src/Mod/Part/Gui/TaskFaceColors.h @@ -50,6 +50,7 @@ public: private Q_SLOTS: void on_colorButton_changed(); void on_defaultButton_clicked(); + void on_boxSelection_clicked(); protected: void onSelectionChanged(const Gui::SelectionChanges& msg); diff --git a/src/Mod/Part/Gui/TaskFaceColors.ui b/src/Mod/Part/Gui/TaskFaceColors.ui index 06da3c717..4ce48b820 100644 --- a/src/Mod/Part/Gui/TaskFaceColors.ui +++ b/src/Mod/Part/Gui/TaskFaceColors.ui @@ -14,14 +14,14 @@ Set color per face - + Click on the faces in the 3d view to select them. - + Group box @@ -61,6 +61,13 @@ + + + Box selection + + + + Qt::Vertical