Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
issue #353: Graphical selection
  • Loading branch information
wwmayer committed Oct 24, 2016
1 parent cb99643 commit 761d684
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/Gui/CommandView.cpp
Expand Up @@ -2265,6 +2265,9 @@ static void selectionCallback(void * ud, SoEventCallback * cb)
SoNode* root = view->getSceneGraph();
static_cast<Gui::SoFCUnifiedSelection*>(root)->selectionRole.setValue(true);

typedef enum { CENTER, INTERSECT } SelectionMode;
SelectionMode selectionMode = CENTER;

std::vector<SbVec2f> picked = view->getGLPolygon();
SoCamera* cam = view->getSoRenderManager()->getCamera();
SbViewVolume vv = cam->getViewVolume();
Expand All @@ -2277,6 +2280,11 @@ static void selectionCallback(void * ud, SoEventCallback * cb)
polygon.Add(Base::Vector2D(pt1[0], pt2[1]));
polygon.Add(Base::Vector2D(pt2[0], pt2[1]));
polygon.Add(Base::Vector2D(pt2[0], pt1[1]));

// when selecting from right to left then select by intersection
// oterwise if the center is inside the rectangle
if (picked[0][0] > picked[1][0])
selectionMode = INTERSECT;
}
else {
for (std::vector<SbVec2f>::const_iterator it = picked.begin(); it != picked.end(); ++it)
Expand All @@ -2303,10 +2311,19 @@ static void selectionCallback(void * ud, SoEventCallback * cb)
if ((*jt)->isDerivedFrom(App::PropertyGeometry::getClassTypeId())) {
App::PropertyGeometry* prop = static_cast<App::PropertyGeometry*>(*jt);
Base::BoundBox3d bbox = prop->getBoundingBox();
Base::Vector3d pt2d;
pt2d = proj(bbox.GetCenter());
if (polygon.Contains(Base::Vector2D(pt2d.x, pt2d.y))) {
Gui::Selection().addSelection(doc->getName(), (*it)->getNameInDocument());

if (selectionMode == CENTER) {
Base::Vector3d pt2d;
pt2d = proj(bbox.GetCenter());
if (polygon.Contains(Base::Vector2D(pt2d.x, pt2d.y))) {
Gui::Selection().addSelection(doc->getName(), (*it)->getNameInDocument());
}
}
else {
Base::BoundBox2D bbox2 = bbox.ProjectBox(&proj);
if (bbox2.Intersect(polygon)) {
Gui::Selection().addSelection(doc->getName(), (*it)->getNameInDocument());
}
}
break;
}
Expand Down

0 comments on commit 761d684

Please sign in to comment.