Author Topic: Updating Parameter Flags  (Read 3818 times)

0 Members and 1 Guest are viewing this topic.

CKlosters

  • World Machine Veteran
  • ***
  • Posts: 20
    • View Profile
Updating Parameter Flags
« on: November 15, 2011, 03:31:52 AM »
Hi!

I'm trying to change parameter flags based on a user action.
For example: if the user toggles "Visualize" on or off, I want a parameter to be read only or editable based on the state of Visualize (true or false).

I can set flags, but can't find methods to remove them (in the Parameter object). Is there a simple way to accomplish this?
Currenlty in the activate function i do?:

Code: [Select]

bool blend_edges = BlendEdges;

// Try to blank out
if (!blend_edges)
params.GetParam(BlendStart)->setFlag(PARM_FLAG_READONLY);
else
????


CKlosters

  • World Machine Veteran
  • ***
  • Posts: 20
    • View Profile
Re: Updating Parameter Flags
« Reply #1 on: November 15, 2011, 04:33:37 AM »
mm, this seems to work when closing the parameter dialog and opening it again.
How can I refresh (or force a rebuild) of the parameter dialog?

Remnant

  • Author
  • World Machine Guru
  • *****
  • Posts: 2311
    • View Profile
    • http://www.world-machine.com/
Re: Updating Parameter Flags
« Reply #2 on: November 16, 2011, 03:31:57 PM »
Hi there,

what you want is a Parameter Dependency, where certain parameters enabled state can depend upon the value of another. There's alot more I'd like to do with making complex sets of parameters accessible, but here's how to do it currently:



1) Add dependencies in your device constructor after creating your parameters
2) (OPTIONAL) Create callback function if you have complex dependency needs, or want to do more than just enable or disable the target parameter.
3) (OPTIONAL) If running your own UI dialog box, you must call ProcessDependencies() on your device's parameter set to recheck dependencies after a changed value. HOWEVER, the default generic dialog interface does this step for you so if you are using the built in system you are good to go.


More detail on step 1:

(defined in Parameter.h):

Call:

Code: [Select]
bool AddDependence(const char *target, const char *trigger, DEPENDS_TYPE type, VAL dependsval, DEPENDS_FUNC func = NULL);

Where the parameters are:

target: parameter name of the parameter that should be MODIFIED based on dependency
trigger: parameter name of the parameter that, when changed, TRIGGERS the dependency
type: VALUE_CHANGE if the dependency function should be called for any change of the trigger
         VALUE_EQUAL if the target should be turned on when the trigger value = dependsval, and off otherwise
dependsval: value of trigger parameter that triggers dependency
func: the callback assigned to this dependency (optional!)


So, wrapping it up:


A simple "turn this on when this one is turned on" dependency would be expressed like:

Code: [Select]
// example from the Lightmap Generator deice code!
// enable the sun color parameter only when Produce RGB is true
params.AddDependence("Sun Color", "Produce RGB Lightmap", VALUE_EQUAL, VAL(true));

Or, here's a more complex dependence, making sure a filename always has the correct extension when you change the format:

Code: [Select]
void dependsChangeExtension(Device *dev, DependsPair &dep) {
// do string stuff
};

// call the function provided whenever the file format changes
params.AddDependence("File Name", "File Format", VALUE_CHANGE, 0, dependsChangeExtension);

« Last Edit: November 16, 2011, 03:34:31 PM by Remnant »
-- Stephen Schmitt
- Creator of World Machine

CKlosters

  • World Machine Veteran
  • ***
  • Posts: 20
    • View Profile
Re: Updating Parameter Flags
« Reply #3 on: November 17, 2011, 04:07:20 PM »
That's exactly what I needed to know!
In the long run, having access to more comlex parameter sets would be beneficial as well.

Thanks  :D
« Last Edit: November 17, 2011, 04:09:28 PM by CKlosters »

CKlosters

  • World Machine Veteran
  • ***
  • Posts: 20
    • View Profile
Re: Updating Parameter Flags
« Reply #4 on: November 18, 2011, 05:33:20 AM »
I implemented the AddDepence Method in the constructor after adding the parameters.
It seems to work, but only for the depending parameter slider and value.

The actual parameter name doesn't change color (grey to black, black to grey)

Is this expected behaviour?

Code: [Select]
// Add parameter dependencies
params.AddDependence("Edge Blend", "Blend Edges", VALUE_EQUAL, VAL(true));
params.AddDependence("Edge Power", "Blend Edges", VALUE_EQUAL, VAL(true));
params.AddDependence("Min Height","Map Incoming Values",VALUE_EQUAL,VAL(true));
params.AddDependence("Max Height","Map Incoming Values",VALUE_EQUAL,VAL(true));

Remnant

  • Author
  • World Machine Guru
  • *****
  • Posts: 2311
    • View Profile
    • http://www.world-machine.com/
Re: Updating Parameter Flags
« Reply #5 on: November 18, 2011, 11:40:25 AM »
good catch, this is 'normal' but errant behavior -- it should be disabling everything including the label. This will be fixed in the next beta!
-- Stephen Schmitt
- Creator of World Machine

CKlosters

  • World Machine Veteran
  • ***
  • Posts: 20
    • View Profile
Re: Updating Parameter Flags
« Reply #6 on: November 21, 2011, 07:26:54 AM »
Thanks!