Skip to main content

notifyAssemblyPartSelected() passes Group

6 replies [Last post]
fz
Offline
Joined: 2003-06-13

Hello,

I am using the menu_assembly and visual rc_handler, the newPart and oldPart passed by Director#notifyAssemblyPartSelected() are Group contains the parts. Also, getCurrentPart() of the assembly passed by returns Group.

I'd be glad if you could tell me how to find the selected Part.

Regards,
Takeshi

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
billf
Offline
Joined: 2004-02-13

You mean from code, like in the Director?

Assembly.getCurrentPart().

BTW, there's a slight inconsistency between the getter and setter for this:

/**
* Get the currently active part within this assembly.
*
* @see #setCurrentFeature(com.hdcookbook.grin.Feature)
**/
public Feature getCurrentPart() {

*

* This really should have been called setCurrentPart() for symmetry
* with getCurrentPart(). Sorry about that!
*
* @see #getCurrentPart()
**/
public void setCurrentFeature(Feature feature) {

fz
Offline
Joined: 2003-06-13

Hello Bill,

I told about notifyAssemblyPartSelected()(of my Director) callback caused by pressing an arrow key on a visual rc_handler with menu_assembly.

In the callback, I tried to see the newly selected part by examining "newPart" parameter, but it was a Group instance containing the part. As an alternative, I invoked getCurrentPart() of "assembly" parameter passed by the callback, the returned object was also a Group instance.

I expected "newPart" was a sub_feature specified in parts clause of menu_assembly.

Regards,
Takeshi

billf
Offline
Joined: 2004-02-13

Hi Takeshi-san,

The menu_assembly construct generates anonymous groups for each of its parts. At runtime, menu_assembly uses the same class as assembly; the GRIN compiler emits an assembly where each part is a group that contains the union of the features that come form the common part and the parts from that branch.

If you want to check which feature is the current part of the assembly, you need to compare the value of getCurrentPart() to what you see from Assembly.findPart(String), or from Assembly.getParts().

Cheers,

Bill

fz
Offline
Joined: 2003-06-13

Hello Bill,

Thank you for your advice.

At first, I tried to call newPart.getName() to see the newly selected part, but the returned value was null.

Now I can get the part index by comparing newPart instance to each element of Assembly#getParts().

BTW, when notifyAssemblyPartSelected() is called back, Assembly#getCurrentPart() returns the same instance as oldPart, is this expected result?

Regards,
Takeshi

billf
Offline
Joined: 2004-02-13

Hi Takeshi-san,

Yes, you're right on all counts.

newPart.getName() is giving you the feature name of the feature itself, and not the name of that part within the assembly. The feature names of non-exported features are set to null to save space in the default binary format.

When you get notifyAssemblyPartSelected(), I'd say the value of Assembly.getCurrentPart() is undefined, but I'm not surprised it's the old part. Oh -- that should be documented, shouldn't it? I'm doing a putback now, including this comment:

*

* Note that during the callback, the current part of the assembly is
* undefined, and might not reflect the new value.

fz
Offline
Joined: 2003-06-13

Hello Bill,

In Assembly, setCurrentFeature(Feature) calls Director#notifynotifyAssemblyPartSelected() with "feature" and "currentFeature", then "currentFeature" is updated to "feature", right?

So, it seems that getCurrentPart() can return correct value at the time if "currentFeature" is volatile.

Also, it'd be nice to update "currentFeature" just before the callback, though "currentFeature" is needed to backup for the callback, what do you think?

Regards,
Takeshi