Selection of faces / edges / vertices and LocalContext

Hi,

I displayed one or more AIS_Shape objects and want to select faces of the object.

I used the following code.

m_hCtx->CloseAllContexts();
m_hCtx->OpenLocalContext();
m_hCtx->ActivateStandardMode(TopAbs_FACE);

Selection works fine but highlition (MoveTo function) does not work. It highlights edges (somewhat far away) instead of faces.

Regards,
G.Suresh Babu

Paul Jimenez's picture

It may be caused by the OpenGL implementation your operating system uses, which is usually provided by the graphics card/chip manufacturer.

The problem you describe is similar to the one I'm getting in a PC with an Intel integrated video. Another PC with a SiS integrated video has some problems too, just different ones.

The only workaround I found for that problem was to use a software implementation of OpenGL (Mesa3D), but it makes everything slower. It's either that, or getting used to those glitches.

crazymoon's picture

Hi,

I met the same ploblem as you. I draw a segment using select point, The first point can be snaped by the vertex of another segment well. But when I move mouse set the second point ,the vertexes of other segments do not appear.
I wonder do you solve the problem? If you do, please help me out, thank you in advance

Paul Jimenez's picture

Your problem could be something completely unrelated to the one the original poster had. Could you provide the piece of code you're using that gives you problems? Only post the essential parts.

crazymoon's picture

In the following codes, it has the rubber-band function to draw a line. First I drew two segments: L1 and L2. In order to draw L3, I run OnSnappoint()
to select the vertex of L1 as the first point of L3, it works fine. When turn to select the vertex of L2 as the second point of L3 , both of vertexes of L1 and L2 aren't highted.
But the endpoint (moving with mouse)of L3 is highted. It seems that when I begin to draw L3, only L3 becomes the OpenLocalContext, L1 and L2 are closed.
So, the selection function just takes effects on L3. It confused me several days. If you can help me out, I will appreciated.
Happy newyear.

void CMyoccView::OnSnappoint()
{
mySnapmode=Snappoint;
// mynewAISContext->CloseAllContexts();
mynewAISContext->OpenLocalContext();
mynewAISContext->ActivateStandardMode(TopAbs_VERTEX);
}

void CMyoccView::OnMouseMove(UINT nFlags, CPoint point)
{
if(myCurrentdraw2d==Draw2d_Line&&myCurrentdrawbegin==Draw2d_LBD)
{

Pntbeg=gp_Pnt(X0,Y0,Z0);
BRepBuilderAPI_MakeVertex STA(Pntbeg);
Start_V =STA.Vertex();
Pntmid=gp_Pnt(X1,Y1,Z1);
BRepBuilderAPI_MakeVertex END(Pntmid);
End_V =END.Vertex();

if(myLBUbegin==LBU_P1&&numb==1)
{
mynewAISContext->Erase(afirstlinex1);
}

mynewAISContext->OpenLocalContext();

if(mySnapmode==Snappoint)
{

mynewAISContext->InitSelected();
while (mynewAISContext->MoreSelected())
{
aVertexx=TopoDS::Vertex(mynewAISContext->SelectedShape());
Start_V=aVertexx;
mynewAISContext->NextSelected();
}

}
BRepBuilderAPI_MakeEdge aSegment1(Start_V, End_V);
afirstlinex1=new AIS_Shape(aSegment1.Shape());
mynewAISContext->SetMaterial (afirstlinex1, Graphic3d_NOM_GOLD, Standard_False);
mynewAISContext->SetDisplayMode (afirstlinex1, 1, Standard_False);
mynewAISContext->Display(afirstlinex1);

}
}

Paul Jimenez's picture

Your problem is not a glitch as the first post suggests, but instead a misunderstanding in using Local Contexts.

I haven't tried this, but, my guess is, that when you open a new local context the previous selections are not transfered to the new one. Also, unless you call a special method from AIS_InteractiveContext, all objects you create in Local Context will disappear when you close it. It's up to you to try the different methods, but it looks like KeepTemporary is the right one. Once again, I haven't tried it.

I'm not completely understanding what you want to achieve, but try removing the call to mynewAISContext->OpenLocalContext() in OnMouseMove AND either call KeepTemporary with afirstlinex1 as argument (it is, if that method does what I think it does) AFTER mynewAISContext->Display(afirstlinex1) OR close all contexts BEFORE the same line (the Display one).

In my code I open a Local Context to select sub-shapes, and, when I'm done with selections, I close all contexts, create the final shape and display it.

I hope that helps.

crazymoon's picture

Can you give me your Email address, I send a graph to you . It's convient to

explain the question. Thanks!

Paul Jimenez's picture

Just upload the image to a free image hosting site and put the link to it here with further explanations.

One such a site is: http://imageshack.us/

crazymoon's picture
Paul Jimenez's picture

Did you remove the call to OpenLocalContext as suggested? Also, OnSnappoint shouldn't be called between vertex selections. In other words, open only a single Local Context to select vertices for your purposes. When you have the information for L3, close all contexts then create L3. Do NOT nest calls to OpenLocalContext unnecessarily.

Success with it.

P.S.: I won't be checking the forums till Monday.

crazymoon's picture

Thank you again , I'll try it. See you monday, have a good time.

crazymoon's picture

I think my case is different from yours. In your case, you need select two point first and then draw a line:
selectstartpoint->selectendpoint->finish draw . In my case, one point is selected firstly and then the position of mouse acts as the endpoint of this line. Move the mouse the endpoint changes correspondingly, untill we click down the left button. So, the whole process may be divided into 3 phases: selectstartpoint->Movemouse->draw segment(rubberband)
->selectendpoint->finish draw
After selectstartpoint, select function on other geometries doesn't work.
By the way, I changes the codes on your suggestions, but it is still not work.

Paul Jimenez's picture

I think I get it now.

You need to open a local context to select vertices. That you got already. Then you use the ConvertToGrid method from the view to know where the mouse is after calling MoveTo in the AIS_InteractiveContext when the mouse moves (instead of ConvertToGrid you could use your own method). No need to open a new local context here. You take the first point, create a new one from the current position, create an edge and display it. Also, you must delete the previously drawn edge before displaying the new one. When the user clicks again, take the point, close all contexts, create the line, display it and you're done.

That's guaranteed to work (I do it displaying a face instead of an edge).

crazymoon's picture

thank you for your reply.

crazymoon's picture