diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp
index e8c580ca4..3fc244142 100644
--- a/src/Gui/CommandView.cpp
+++ b/src/Gui/CommandView.cpp
@@ -58,6 +58,7 @@
#include "SceneInspector.h"
#include "DemoMode.h"
#include "TextureMapping.h"
+#include "Utilities.h"
#include
#include
@@ -1900,6 +1901,79 @@ void StdViewBoxZoom::activated(int iMsg)
}
}
+//===========================================================================
+// Std_BoxSelection
+//===========================================================================
+DEF_3DV_CMD(StdBoxSelection);
+
+StdBoxSelection::StdBoxSelection()
+ : Command("Std_BoxSelection")
+{
+ sGroup = QT_TR_NOOP("Standard-View");
+ sMenuText = QT_TR_NOOP("Box selection");
+ sToolTipText = QT_TR_NOOP("Box selection");
+ sWhatsThis = "Std_ViewBoxZoom";
+ sStatusTip = QT_TR_NOOP("Box selection");
+ eType = AlterSelection;
+}
+
+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]));
+ }
+
+ App::Document* doc = App::GetApplication().getActiveDocument();
+ if (doc) {
+ cb->setHandled();
+ std::vector geom = doc->getObjectsOfType();
+ for (std::vector::iterator it = geom.begin(); it != geom.end(); ++it) {
+ std::vector props;
+ (*it)->getPropertyList(props);
+ for (std::vector::iterator jt = props.begin(); jt != props.end(); ++jt) {
+ if ((*jt)->isDerivedFrom(App::PropertyGeometry::getClassTypeId())) {
+ App::PropertyGeometry* prop = static_cast(*jt);
+ Base::BoundBox3d bbox = prop->getBoundingBox();
+ Base::Vector3d pt2d;
+ pt2d = proj(bbox.CalcCenter());
+ if (polygon.Contains(Base::Vector2D(pt2d.x, pt2d.y))) {
+ Gui::Selection().addSelection(doc->getName(), (*it)->getNameInDocument());
+ }
+ break;
+ }
+ }
+ }
+ }
+}
+
+void StdBoxSelection::activated(int iMsg)
+{
+ View3DInventor* view = qobject_cast(getMainWindow()->activeWindow());
+ if ( view ) {
+ View3DInventorViewer* viewer = view->getViewer();
+ if (!viewer->isSelecting()) {
+ viewer->startSelection(View3DInventorViewer::Rectangle);
+ viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), selectionCallback);
+ }
+ }
+}
+
//===========================================================================
// Std_TreeSelection
//===========================================================================
@@ -2113,6 +2187,7 @@ void CreateViewStdCommands(void)
rcCmdMgr.addCommand(new StdViewZoomIn());
rcCmdMgr.addCommand(new StdViewZoomOut());
rcCmdMgr.addCommand(new StdViewBoxZoom());
+ rcCmdMgr.addCommand(new StdBoxSelection());
rcCmdMgr.addCommand(new StdCmdTreeSelection());
rcCmdMgr.addCommand(new StdCmdMeasureDistance());
rcCmdMgr.addCommand(new StdCmdSceneInspector());
diff --git a/src/Gui/MouseSelection.cpp b/src/Gui/MouseSelection.cpp
index 065b885cc..97262f601 100644
--- a/src/Gui/MouseSelection.cpp
+++ b/src/Gui/MouseSelection.cpp
@@ -495,6 +495,7 @@ int RectangleSelection::mouseButtonEvent( const SoMouseButtonEvent * const e, co
{
releaseMouseModel();
m_bWorking = false;
+ _clPoly.push_back(e->getPosition());
ret = Finish;
} break;
default:
diff --git a/src/Gui/MouseSelection.h b/src/Gui/MouseSelection.h
index eeb41f2d1..fd8716e72 100644
--- a/src/Gui/MouseSelection.h
+++ b/src/Gui/MouseSelection.h
@@ -88,8 +88,6 @@ protected:
int m_iXnew, m_iYnew;
SbBool m_bInner;
SbBool mustRedraw;
-
-private:
std::vector _clPoly;
};
diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp
index dc32d7dc7..26ca5d698 100644
--- a/src/Gui/Workbench.cpp
+++ b/src/Gui/Workbench.cpp
@@ -441,7 +441,7 @@ MenuItem* StdWorkbench::setupMenuBar() const
edit->setCommand("&Edit");
*edit << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Cut" << "Std_Copy"
<< "Std_Paste" << "Std_DuplicateSelection" << "Separator"
- << "Std_Refresh" << "Std_SelectAll" << "Std_Delete"
+ << "Std_Refresh" << "Std_BoxSelection" << "Std_SelectAll" << "Std_Delete"
<< "Std_Placement" << "Std_Alignment"
<< "Std_Edit" << "Separator" << "Std_DlgPreferences";
diff --git a/src/Mod/Complete/Gui/Workbench.cpp b/src/Mod/Complete/Gui/Workbench.cpp
index d2a5e5aaf..d60424b2d 100644
--- a/src/Mod/Complete/Gui/Workbench.cpp
+++ b/src/Mod/Complete/Gui/Workbench.cpp
@@ -132,7 +132,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
edit->setCommand("&Edit");
*edit << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Cut" << "Std_Copy"
<< "Std_Paste" << "Std_DuplicateSelection" << "Separator"
- << "Std_Refresh" << "Std_SelectAll" << "Std_Delete"
+ << "Std_Refresh" << "Std_BoxSelection" << "Std_SelectAll" << "Std_Delete"
<< "Std_Placement" << "Std_Alignment"
<< "Separator" << "Std_DlgPreferences";