vsTASKER 7 Tutorial
×
Menu
Index

Publish

  
 
Because the Federation Object is quite simple, we will just use the Direct Access method. We keep the DataModel one for complex Federations.
 
Let's start with the Object myEntity:
We start by defining locally the data that will hold the values to be sent to the RTI.
 
Here: int x, y; because we know that myEntity Object got two Attributes X and Y of integer type.
 
Now, for each Attribute, let's do the copying:
 
 "X" <- (int) &x;
 "Y" <- (int) &y;
 
As we are on the publisher object, the base code is called before the Attribute one.
So, it is at myEntity Object level that we will do the setting of x and y variable:
 
 x = entity->pos.x;
 y = entity->pos.y;
 
So, now, we want the FedItem to work with every entity the user will create at runtime.
Each FedItem can work with a list of entities from the design scenario.
But if we want the new one to be automatically added into the list, we need to select the Allow RT Entities field:
 
This lead us to the filtering of new runtime entities, because maybe, not all runtime entities have to be using this FedItem.
So, the user can add a filtering code here:
 
 if (!((Entity*)entity)->status ||
     ((Entity*)entity)->status->isType(_Unknown)) entity = NULL;
 
Here, if the new runtime entity has no Status or is of Unknown type, then, it will not be added to the FedItem.
 
 
Now, time to add the Interaction myReact.
This interaction will be published at every mouse click, producing at runtime the event _MouseDown.
For that reason, we will give the Interaction an On Event triggering mode.
 
Let's activate the FedItem with this event:
 
Now, in the myCreate Interaction code, let's extract the world coordinate position of the Mouse:
 
// the event carries runtime data (see runtime.h)
EvtData* data = (EvtData*) gEvent()->data;
 
// we need the mouse.w world coordinates.
x = data->mouse.wx;
y = data->mouse.wy;
 
// now, we draw a circle, color red for 3 sec
WCoord pos(x, y, 0);
R:gui_map.drawCircle(pos, 10, clRed, 3);
 
return PROCEED;
 
 
Time now to set the posX and posY parameters:
 
And that's it for the publishing side: