Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics
 

Snapping and DetectedInteractive function

Snapping and DetectedInteractive function
Laszlo Kudela 2012/07/12 15:56
Hello everyone,

I'm a newbie to this forum and more or less to OpenCascade as well.

I'm working on a university project which aims to develop a basic CAD module as a preprocessor for a simulation environment. At this point we are able to draw points and lines and we are in a phase to start implementing some snapping algorithms.

I already know the code of Sketcher (developed by Sergei Maslov) which has some sort of Snapping but I thought I want to do something else.

My problem is: during sketching, and if snapping is activated, I want to snap to a point. So whenever I move the mouse I say:

... onMouseMove(...)
{
...
get_Context()->MoveTo(myXmax,myYmax,myView);
...
}

If I move the mouse over a point, the point is highlighted. Now I want to get the coordinates of this point. So the code is as follows:

void Sketcher_SnapPoint::SelectEvent()
{
     findbestPnt2d = Standard_False;
     if(myContext->HasDetected())
     {
          detectedInteractive = myContext->DetectedInteractive();
          //If signature == 1, the detected object is a point
          if(detectedInteractive->Signature() == 1)
          {
               findbestPnt2d = Standard_True;
               Handle(AIS_Point) detectedAISPoint = Handle(AIS_Point)::DownCast(detectedInteractive);
               bestPnt2d = Handle(Geom_CartesianPoint)::DownCast(detectedAISPoint->Component());
          }
     }
     else
     {
          findbestPnt2d = Standard_False;
          bestPnt2d->SetCoord(curPnt2d.X(),curPnt2d.Y(),0);
     }
}

The problem is as follows:

I call the DetectedInteractive function, which returns me the AIS_Point, over which the mouse is. I convert this point to a Geom_CartesianPoint and then hand it to the algorithm that creates the line. But for some reason the created line (neither the starting nor the endpoint) would not snap to the point which was downcasted from the detected AIS_Point. It seems that if the mouse is over the sensitive area of the point, it is stuck there, and do not want to give the coordinates of the point, but the coordinates of the point where it touched the area... I can even show this: if you modify the code:

               findbestPnt2d = Standard_True;
               Handle(AIS_Point) detectedAISPoint = Handle(AIS_Point)::DownCast(detectedInteractive);
detectedAISPoint->Redisplay();
               bestPnt2d = Handle(Geom_CartesianPoint)::DownCast(detectedAISPoint->Component());

so that the point will be redisplayed whenever the mouse is over the sensitive area, the point starts to jump on the screen and it always jumps to the location where the mouse touched the area.

I know, RTFM, and so on. I did, but I do not really see what I miss.

Thanks for your help!

Best regards,
Laszlo
Laszlo Kudela 2012/07/12 21:30
I have solved the problem.

The modified code is:

void Sketcher_SnapPoint::SelectEvent()
{
     TopoDS_Vertex topVertex;
     findbestPnt2d = Standard_False;
     if(myContext->HasDetected())
     {
          detectedInteractive = myContext->DetectedInteractive();
          //If signature == 1, the detected object is a point
          if(detectedInteractive->Signature() == 1)
          {
               findbestPnt2d = Standard_True;
               Handle(AIS_Point) detectedPoint = Handle(AIS_Point)::DownCast(detectedInteractive);
               topVertex = detectedPoint->Vertex();
               gp_Pnt point=BRep_Tool::Pnt(topVertex);
               bestPnt2d->SetPnt(point);
               }
....


It turns out that first we have to get the TopoDS_Vertex form the AIS_Point and then we have to convert this point to a gp_Pnt with the BRep_Tool.

I'm not really sure why is it so, but good to know this :)     
 
 
Latest news
  • OCCT Applications
  • Open CASCADE Technology 6.8.0 is available for download!
  • New features to enhance the development process

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map