Select objects partially enclosed into a rectangle or polygon

Hello,

I need a way to select objects not fully enclosed inside a rectangle/polygon; I see that Select() methot of interactive context only handles object FULLY enclosed; I tried with NIS_View::Select(), but it doesn't select anything, I guess it works only for NIS_Interactives....

Did somebody have a solution ?

Thanx in advance

Max

Massimo Del Fedele's picture

No solution ???
I think that one is a *big* need for a cad application...

Max

Massimo Del Fedele's picture

Well, as many people asked for this, here a "dirty" solution.....

// sort box points
int x1 = min(p1.x, p2.x);
int x2 = max(p1.x, p2.x);
int y1 = min(p1.y, p2.y);
int y2 = max(p1.y, p2.y);
double dx = x2 - x1;
double dy = y2 - y1;

// divide box in overlapping circles
// we assume a number of circles near 100
double l = sqrt(dx * dy / 100);
int nx = fceil(dx / l);
int ny = fceil(dy / l);
double r = max(dx / nx, dy / ny) / sqrt(2);
double xStep = dx / nx;
double yStep = dy / ny;

// sets sensitivity to circle radius
Context->SetSensitivity(fceil(r));

// get the main selector
Handle(StdSelect_ViewerSelector3d) sel3d = Context->MainSelector();

// select entities on nx x ny circles
AIS_MapOfInteractive map;
double x0 = (dx - (nx - 1) * xStep) / 2 + x1;
double y0 = (dy - (ny - 1) * yStep) / 2 + y1;
double y = y0;
for(int iy = 0; iy < ny; iy++)
{
double x = x0;
for(int ix = 0 ; ix < nx; ix++)
{
// pick all objects under mouse
sel3d->Pick((int)x, (int)y, view->viewHandle);

// scan all picked entities and append them to result
int nPicked = sel3d->NbPicked();
Handle(SelectMgr_EntityOwner) e;
for(int i = 1; i <= nPicked; i++)
{
e = sel3d->Picked(i);
if(e.IsNull())
continue;
Handle(AIS_InteractiveObject) obj = Handle(AIS_InteractiveObject)::DownCast(e->Selectable());
if(!map.Contains(obj))
map.Add(obj);
}

x += xStep;
}
y += yStep;
}

The selection rectangle is discretized in some 100+ small circles that overlaps slightly and cover all rectangle.
Sensitivity is set to circle's radius, and 100+ selections picking on circles centers is done, gathering all entities.
The method is not "exact" but for all purpose is more than enough... If you want more precision, just increase the number "100" which is the number of circles.

Anyways, in my opinion, having to take such an approach for a modeling toolkit is completely nonsense... some simple additions to Match() and other functions would allow to add for testing on partial box enclosures; this is a must for every real CAD application.

Max