AVS (Advanced Visualization System) quick reference
static char file_version[] = "@(#)widgets.c 8.4 AVS 92/10/16";
static char choices3[] = "Information#Warning#More Options";
static char choices5[] =
"Information#Debug#Warning#Error#Fatal#Fewer Options";
Module Name:
AVSset_module_name("widgets", MODULE_DATA);
Output Port Creation
iport = AVScreate_output_port("Output Field",
"field 3D scalar uniform float");
AVSautofree_output(iport);
###?
/* Setup a string parameter that can be updated by the module to
* reflect a change each call
*/
Generalities:
(default, min, max)
String Parameter Updated each call (# of times module is called)
iparam = AVSadd_parameter("CalledCount","string","Not called yet","","");
/* Request a preferred widget class */
AVSconnect_widget(iparam, "text");
/* Specify a width (The network control panel is about 4 units wide) */
AVSadd_parameter_prop(iparam, "width", "integer", 3);
Browser
iparam = AVSadd_parameter("Browser","string","","","");
AVSconnect_widget(iparam,"browser");
Slider - Real
iparam = AVSadd_float_parameter("Range", 10.0, 1.0, 1000.0);
AVSconnect_widget(iparam, "slider");
AVSadd_parameter_prop(iparam, "immediate", "boolean", 0);
Dials - Integer
(default for integer & real)
iparam = AVSadd_parameter("LowerRange", "integer", 0, 0, 5);
AVSadd_parameter_prop(iparam, "title", "string", "Lower");
AVSadd_parameter_prop(iparam, "immediate", "boolean", 1);
Dials - Real
iparam = AVSadd_float_parameter("UpperRange", 7.5, 5.0, 10.0);
AVSadd_parameter_prop(iparam, "title", "string", "Upper");
AVSadd_parameter_prop(iparam, "immediate", "boolean", 1);
Toggle
iparam = AVSadd_parameter("Toggle", "boolean", 0,0,0);
TriState
iparam = AVSadd_parameter("TriState", "tristate", 0,0,0);
OneShot
iparam = AVSadd_parameter("Shoot Once", "oneshot", 0,0,0);
/**********************************************************/
/* Examples of error handling using string and choice widget
* The choices request an AVSmessage of a given severity or
* alteration of the possible choices
*/
iparam = AVSadd_parameter("Message","string","(no message)","","");
AVSconnect_widget(iparam, "text");
/* Choices - initial value, choicelist, seperator
* Using pound sign (#) as separator to allow spaces in choices
* Placement of choice at end of list facilitates automatic
* resizing of control panel as choices grow or shrink
*/
iparam = AVSadd_parameter("MessageChoices","choice","",choices3,"#");
AVSadd_parameter_prop(iparam, "width", "integer", 2);
AVSadd_parameter_prop(iparam, "columns", "integer", 2);
/**********************************************************/
/* Identify the computation routine */
AVSset_compute_proc((AVS_FNCP) widgets_compute);
return(1);
}
/************************************************************/
static widgets_compute(output, called_value, browser_value,
range_value, lower_value, upper_value,
boolean_value, tristate_value, oneshot_value,
message_value, message_choice)
AVSfield_char **output;
char *called_value, *browser_value, *message_value, *message_choice;
int lower_value, boolean_value, tristate_value, oneshot_value;
float *range_value, *upper_value;
{
char cbuf[1024], answer[32];
int dims[3];
static int icalled = 0;
float half,quarter;
int ihalf,iquarter;
/* Since this module just exercises the widgets, many parameters are not
actively used - UNUSED_ARG() is just a macro that allows some systems
that would otherwise complain about these arguments to be placated */
UNUSED_ARG(called_value);
UNUSED_ARG(browser_value);
UNUSED_ARG(lower_value);
UNUSED_ARG(upper_value);
UNUSED_ARG(boolean_value);
UNUSED_ARG(tristate_value);
UNUSED_ARG(oneshot_value);
UNUSED_ARG(message_value);
dims[0] = 1;
dims[1] = 1;
dims[2] = 1;
/* Allocate Space For Volume Data */
*output = (AVSfield_char*)AVSdata_alloc("field 3D scalar byte uniform", dims);
/**********************************************************/
/* CAUTION - AFTER MODIFYING PARAMETER VALUES, THERE IS NO IMMEDIATE
* IMPACT ON THE ARGUMENTS RECEIVED IN THE COMPUTE ROUTINE CALL
* UNTIL THE NEXT CALL. POSSIBLE EXCEPTION IS REALS.
* AFTER PARAMETER MODIFIED, CORRESPONDING STRING VALUE ARGUMENTS
* WILL HAVE BEEN FREED SO MAKE COPIES BEFORE HAND
*/
/* Update string text widget to reflect number of times called */
sprintf(cbuf,"Called %d times",++icalled);
AVSmodify_parameter("CalledCount", AVS_VALUE, cbuf, 0,0);
/**********************************************************/
/* Nothing done with filename in this example */
/**********************************************************/
/* Update ranges
* If range value changed, update the two subranges appropriately
* NOTE: Float parameters must use AVSmodify_float_parameter
* OR pass in float*'s for init,min,max values
*/
if (AVSparameter_changed("Range") != 0) {
half = *range_value / 2.0;
quarter = *range_value / 4.0;
ihalf = (int) half;
iquarter = (int) quarter;
/* Truncate half for bounds on real subrange */
half = (float) ihalf;
AVSmodify_parameter("LowerRange",AVS_VALUE | AVS_MAXVAL,
iquarter,0,ihalf);
AVSmodify_float_parameter("UpperRange",
AVS_VALUE | AVS_MINVAL | AVS_MAXVAL,
half+quarter, half, *range_value);
}
/**********************************************************/
/* Handle requests for error messages
* Information and Debug will go to stdout and the log file
* Warnings and Errors will present a dialog box for user choice
* Fatal errors will kill module off
* More Options and Fewer Options choices modify choices
*/
if (AVSparameter_changed("MessageChoices") != 0) {
if (!strcmp(message_choice,"Information")) {
AVSinformation("Simple Information message (%s %d %f)", "test", 1, 1.234);
strcpy(answer,"(Information)");
}
else if (!strcmp(message_choice,"Debug")) {
AVSdebug("Internal debugging message (%s %d %f)", "test", 1, 1.234);
strcpy(answer,"(Debug)");
}
else if (!strcmp(message_choice,"Warning")) {
AVSwarning("Simple warning with no choices (%s %d %f)", "test", 1, 1.234);
strcpy(answer,"(Simple Warning)");
}
else if (!strcmp(message_choice,"Error")) {
strcpy(answer,
AVSmessage(file_version,AVS_Error,0,
"widgets_compute","Ok!Not Ok!Not So Bad",
"Example of a more serious error with choices (%s %d %f)",
"test", 1, 1.234));
}
else if (!strcmp(message_choice,"Fatal")) {
strcpy(answer,
AVSmessage(file_version,AVS_Warning,0,
"widgets_compute","Cancel!Go ahead",
"Fatal message will cause module to shut down"));
if (!strcmp(answer,"Go ahead")) {
strcpy(answer,
AVSmessage(file_version,AVS_Fatal,0,
"widgets_compute","Acknowledge",
"Example of a fatal error"));
exit(1);
}
}
else if (!strcmp(message_choice,"More Options")) {
AVSmodify_parameter("MessageChoices", AVS_VALUE | AVS_MINVAL,
"",choices5, 0);
strcpy(answer,"(More Choices)");
}
else if (!strcmp(message_choice,"Fewer Options")) {
AVSmodify_parameter("MessageChoices", AVS_VALUE | AVS_MINVAL,
"",choices3, 0);
strcpy(answer,"(Fewer Choices)");
}
AVSmodify_parameter("Message",AVS_VALUE,answer,0,0);
}
/**********************************************************/
/* Make sure the return value is set to 1 to indicate success */
return(1);
}
/************************************************************
* initialization for modules contained in this file.
*/
static int ((*mod_list[])()) = {
widgets_init, /* PLUG IN YOUR MODULE INIT FUNCTION(S) HERE */
};
#define NMODS (sizeof(mod_list) / sizeof(char *))
void AVSinit_modules()
{
AVSinit_from_module_list(mod_list, NMODS);
}