|
Business Graphic Objects
You will see how PrStudio provides
an easy way to access the prototypes in C++ applications. It provides a
specific set of objects, the Value Source. They are data providers
for the prototypes.
PrStudio setup
First, go back to the panel you created
in the last step and remove the slider prototype. The connection between
the slider and the SuperGauge prototype is automatically destroyed.
Then create the Value Source.
The creation command is not directly available in PrStudio through
toolbars or menus. You need to access the "Commands" panel by pressing
the "Commands" button
The Commands panel should appear:
Select the "AddValueSource"
command, and press "Apply". By the way, you can see that all the ILOG Studio
commands are shown here. Most of them are available through buttons, menus
or inspectors, but it is sometimes useful to see them all in this panel,
classified by categories.
When the command is selected, you
are asked to select a Value Source from among four possible choices:
-
Clock: uses a timer with a variable
period. Very useful for animated prototypes.
-
Random: random generator.
-
File: file reader to provide data.
-
Application: provides data that come
from the application
Here, you will use an Application value
source. Give a name to this value source (for example: "AppliData"). Nothing
looks different in your edited panel, but if you click again on the "Group
Connection" button ,
you will see a green rectangle showing the created Value Source:
This rectangle is used
to create a connection between the application and the prototypes.
Create a link between "AppliData"
and your prototype. This operation pops up the connection panel again:
Enter any name in the
left text field (for example: SuperGaugeValue) to specify the name of the
value that will be used later in the C++ code, and select the Gauge Value
in the right column.
This operation creates a connection
that is represented in the panel by a green arrow. If you click on this
arrow, you will see a tooltip with the details about this connection. Save
your panel as GaugePanel.ilv for example.
C++ code
You can now use all this in a sample
application. Here is the necessary C++ code:
IlvDisplay* display = new IlvDisplay("Protos", 0, argc,
argv);
if (!display || display->isBad())
{
IlvFatalError("Couldn't open display");
delete display;
return -1;
}
IlvProtoManager* protoman = new IlvProtoManager(display);
IlvView* view = new IlvView(display, "Proto sample", "Proto
sample",
IlvRect(0,
0, 400, 180));
protoman->addView(view); |
The first part of the code creates a
display,
a manager and a view. All these points are detailed in the
"2D
images" section of this tutorial. Note the manager creation: an IlvProtoManager
is created instead of the classic IlvManager. It is a specific manager
for prototypes.
| protoman->read("GaugePanel.ilv"); |
You can read a panel file (.ilv) using
the "read" function. It instantiates all the necessary objects in the manager.
| IlvValueSource* source = protoman->getValueSource("AppliData"); |
You can get the value source created
in PrStudio by providing its name ("AppliData").
IlvTimer* timer = new IlvTimer(display, 0, 50, TimerAction,
source);
timer->run(); |
The timer is useful for animating the
gauge (timer creation process is detailed in the "2D
images" section). The "TimerAction" function is called by the timer
every 50 milliseconds:
static void TimerAction(IlvTimer*, IlvAny arg)
{
static IlvUInt currentValue = 0;
static IlvInt increment = 2;
// Get the Value Source
IlvValueSource* valueSource = (IlvValueSource*)arg;
// Value variation
currentValue += increment;
// Min and Max tests
if ((currentValue < 0) || (currentValue > 100))
{
currentValue -= increment;
increment = -increment;
}
// Push the new value
valueSource->pushValue(IlvValue("SuperGaugeData", currentValue));
} |
First, you get the value source pointer
passed as a user argument and new gauge value (with limit tests) is computed.
The "pushValue" function is used to update the prototype. You just have
to specify the value you want to access ("SuperGaugeData" value), and that's
it! Because the Gauge Value is now connected to the value source, the prototype
is automatically updated and redrawn.
See
complete code.
Download source
code.
Note: This example is very
similar to the "connect" sample provided with ILOG Views, in the "samples/protos"
directory.
Conclusion
Once your panel is created with
PrStudio
using application value sources, it is very easy to transfer data from
the application to the prototypes. All the prototypes linked to a specific
value source through a value will automatically be updated and redrawn
if necessary. The prototypes provide a very easy way to customize data
display without affecting your application code.
|