2D Graphics > Linking Your Prototype to Application Objects > Step 2: Retrieving and Modifying the Prototype Instances
 
Step 2: Retrieving and Modifying the Prototype Instances
All operations done on prototype instances within a panel, be it a container or a manager, (and on IlvGroups, which are the superclass of prototype instances) are done using an IlvGroupHolder. This class allows you to add, remove, and retrieve objects of class IlvGroup from a panel.
After having read the file, retrieve the group holder associated with the manager. From the group holder, retrieve the prototype instance myThermometer, and initialize its temperature attribute to 0.0:
// Insert the following code after the line:
// "the prototype instances are automatically read."
IlvGroupHolder* holder=IlvGroupHolder::Get(manager);
IlvGroup* myThermometer = holder->getGroup("myThermometer");
if (!myThermometer) {
IlvFatalError("This program expects to find an IlvGroup "
"of name 'myThermometer' in the file 'myPanel.ilv'");
return -1;
}
myThermometer->changeValue(IlvValue("temperature", 0.0));
Next, you need to periodically update the temperature value from values provided by the application. For this, create a timer routine by inserting the following lines before the main function in the program (after the include directives):
// Insert the following code before the main() body.
const IlUInt angleincrement = 4;
static void
TimerProc(IlvTimer*, IlvAny arg)
{
static IlUInt angle=0;
IlvGroup* thermometer=(IlvGroup*) arg;
IlDouble temperature=50.0+40.0*sin(degreesToRadians(angle));
// Feed in temperature values.
thermometer->changeValue(IlvValue("temperature", temperature));
angle = (angle + angleincrement) % 360;
}
This function makes the temperature rise and fall according to a sinusoidal function, between the values of 10 and 90. Next, initialize this timer to wake up every 200 ms and update the prototype instance “myThermometer”, which you retrieved from the panel. After the line:
myThermometer->changeValue(IlvValue("temperature", 0.0));
insert the following code:
// start changing the values of the target group
IlvTimer* timer = new IlvTimer(display, 0, 200, TimerProc,
(IlvAny)myThermometer);
timer->run();
This will periodically update the thermometer values. You can now compile and run your program. You will see that the temperature rises and falls regularly, the thermometer becoming red when the temperature is above the threshold previously set in Rogue Wave Views Studio.
You can change the threshold value with a call to:
myThermometer->changeValue(IlvValue("threshold", 50.0));
You can retrieve the threshold value with the following call:
IlvValue tval("threshold", (IlDouble)0.0);
IlDouble threshold = (IlDouble) myThermometer->queryValue(tval);
The complete source code is provided in the file step2/program.cpp, which serves as a starting point for the next step of the tutorial.

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.