cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

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

xd
1-Newbie
1-Newbie

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

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.
1 ACCEPTED SOLUTION

Accepted Solutions
FV
17-Peridot
17-Peridot
(To:xd)

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.

View solution in original post

13 REPLIES 13
MarkStallard
3-Visitor
(To:xd)

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  |+|

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?

hheinz
1-Newbie
(To:xd)

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
1-Newbie
1-Newbie
(To:hheinz)

Hi Hans, it's disappointed to hear that.

I agree with you that the asynchronous way you proposed is not a good idea.

By the way, another application similar is as follows.

the drawing change mark

If it's the first time i change the drawing from version A to B, i add the mark with No. 1,

If it's the third time i change the drawing from version C to D, i change the mark No.1 to  No.3,

According the discussion above,  i must make a choice between add mark and change mark at first, isn't it?

So disappointed.

FV
17-Peridot
17-Peridot
(To:MarkStallard)

Hi all,

XD, Mark is correct. In his example he had used "any_note" note as the selection option, but there is nothing stopping you from using "any_note,sldedge,sldface,dtl_symbol" or whatever other combination of possible selections you are after. To provide an 'instant' color feedback you have to use the fourth argument ProSelFunctions - ProSelectionPreFiter for ProSelect(...).

HIH.

Feliks.

xd
1-Newbie
1-Newbie
(To:FV)

Hi FV, Thanks for the information.

xd
1-Newbie
1-Newbie
(To:FV)

And,

is there any suggestion about how to find out if there is an item at the clicked cursor point?

FV
17-Peridot
17-Peridot
(To:xd)

<LOAD_POINT>\protoolkit\protk_appls\pt_examples\pt_famtab\TestFamTab.c :

ProError TestFamSelectionExtRefFilter(

    ProSelection selection,

    Pro3dPnt point,

    ProMatrix transform,

    char * option,

    int level,

    ProAppData app_data);

xd
1-Newbie
1-Newbie
(To:xd)

Thanks everyone, though not solved.

FV
17-Peridot
17-Peridot
(To:xd)

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
1-Newbie
1-Newbie
(To:FV)

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?

FV
17-Peridot
17-Peridot
(To:xd)

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.

xd
1-Newbie
1-Newbie
(To:FV)

Great!

Much thanks, Feliks.

That's what i need.

Top Tags