Skip to main content
1-Visitor
November 19, 2015
Solved

How to get the item under the cursor after a mouse click

  • November 19, 2015
  • 2 replies
  • 4923 views

I am coding a tool with ProToolKit,

it's as follows,

1, the user click the left mouse button the the drawing.

2, If there is a note or a dim at the mouse cursor, then change the color of the note or dim to Red.

3, if there is a geometry (surf or line) at the mouse cursor, then change the geometry color to Green.

4, if there is nothing at the cursor when clicking, do nothing.

I can use ProMousePickGet()  to  read the screen coordinate of the mouse,

But , how to find whether there is a note or a geometry at the cursor?

Is there a API method ?

Please help.


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
Best answer by FV_01

Hi all,

The examples of pre or post filters are in 'TestFamTab.c'.

The short version:

static ProError test_sel_psf( ProSelection selection, ProAppData app_data)
{
ProError err = PRO_TK_NO_ERROR;
ProGeomitem    gi;
err = ProSelectionModelitemGet( selection, (ProModelitem *) &gi);
if( err != PRO_TK_NO_ERROR ){
  return( PRO_TK_NO_ERROR);
}

ProWindowRepaint(PRO_VALUE_UNUSED); // in real life situation - would have to use ProSelectionUnhighlight() for previously highlighted entities
if( gi.type == PRO_CURVE || gi.type == PRO_EDGE || gi.type == PRO_SURFACE){
  ProSelectionHighlight( selection, PRO_COLOR_SHEETMETAL); // green
}
else {
  ProSelectionHighlight( selection, PRO_COLOR_ERROR); // red
}


return( PRO_TK_NO_ERROR);
}

ProError test ()

{

ProError err = PRO_TK_GENERAL_ERROR;

int n_sel = 0;

ProSelection *p_sel = NULL;

ProSelFunctions      sel_functions;

memset( &sel_functions, '\0', sizeof( sel_functions));
  sel_functions.pre_filter = NULL;
  sel_functions.post_filter = test_sel_psf;
  sel_functions.post_selact = NULL;
  sel_functions.app_data = NULL;

 
  err = ProSelect( "any_note,symbol_3d,sldedge,dimension", 1, NULL, &sel_functions, NULL, NULL, &p_sel, &n_sel);
  if( err != PRO_TK_NO_ERROR) {
   return( PRO_TK_GENERAL_ERROR);
  }
  else if( n_sel <= 0 )
   return( PRO_TK_GENERAL_ERROR);

// do something with selection

return( PRO_TK_NO_ERROR);

}

HIH.

Feliks.

2 replies

1-Visitor
November 19, 2015

Hi -

ProMousePickGet will only provide you with coordinate values. If you want to select entities, you'll need to use ProSelect.  ProSelect, and the ProSelection data structure it returns, can be used in many ways. Give yourself some time to learn it.

Here's a summary of some code I wrote a long time ago to select a single drawing note:

ProSelection *selection ;     // Pro/Array of entity selection data

int           selection_cnt ; // Size of selection[]

ProError      error ;         // Pro/Tk error value


error = ProSelect( "any_note", 1, NULL, NULL, NULL, NULL, &selection, &selection_cnt ) ;

You'll need to add code to check the returned error value.

|+|  M a r k  |+|

xd_011-VisitorAuthor
1-Visitor
November 20, 2015

Hi Mark, thanks for your reply.

I knew about the ProSelect function,

Using ProSelect function, we must indicate the parameter "any_note".

Then, it can not return from the ProSelect function with a left button click and nothing is selected,

it return until 1 note item is selected or the select dialog is canceled.


Actually,What i need is only one click and then something is done.

It can not be trapped in the ProSelect function.


In my opinion, i want to use ProMousePick to get a left button click, and then check if there is a note or geometry.

But i do not know how to check it.


And i believe it's useful to find out if there is a item (dim, note or geometry) at the indicated point.

Is there any suggestion?

1-Visitor
November 20, 2015

Well, Mark's answer is the only way to do it in a good and safe way.

...however, you could build an asynchronous application that listens to Mouse events. Every time there is a click, get the current selection buffer, look inside it, see if there is something selected that you want to work with and then do that.

I would not recommend doing it this way, though, as the Creo selection buffers are notoriously fickle. And I'd really, REALLY not recommend doing it with the TK, since it hasn't got error handling and will crash your asynch application (and, if you're unlucky, Creo as well) when there's something wrong with the selection buffer.

EDIT: Just looked it up in the API and this will likely not even work as ProSelbufferSelectionsGet needs an active selection buffer and thus likely needs a running selection tool to even exist.

xd_011-VisitorAuthor
1-Visitor
November 23, 2015

Thanks everyone, though not solved.

FV_01
November 23, 2015

XD,

Prefilter will work for geomitems only - notes out of the question... I did not realize it. Please use postfilter - take a look at the attached video. Unfortunately there is a slight delay between placing a cursor over the entity and color change event - looks like unavoidable...

HIH.

Feliks.

Video Link : 6535

xd_011-VisitorAuthor
1-Visitor
November 25, 2015

hi Feliks, thanks for your reply. But, i can not see the video. will you send the video to xd200800@163.com?

And will you show me the post filter usage?