This is the function that handles our graph object for display. It is a typical callback as previously explained. Note we begin as usual by doing appropriate casts and grabbing important information from the application_data structure via the use of T.
#include "simulation.h"
void run(Widget w,XtPointer client_data,XtPointer call_data)
{
XmPushButtonCallbackStruct *P = (XmPushButtonCallbackStruct *)call_data;
application_data *T = (application_data *)client_data;
Display *display = T->display;
Drawable drawable = T->drawable;
Pixmap pixmap1 = T->pixmap;
Pixmap pixmap2 = T->pixmap2;
GC gc = T->gc;
Pixel graph_colors[4];
for(int i=0;i<4;++i)
graph_colors[i] = T->pParts[i]->pixel;
Next, we construct the graph object:
if(T->T==NULL){
printf("Building the XGraph object.\n");
T->T = new Graph(T->radius,T->center, //node circle
T->separation,
T->foreground, //fg
T->background, //bg
graph_colors, //graph colors
T->display, //graphics
T->drawable,
T->pixmap,
T->pixmap2,
T->gc);
}
Now we decide how many nodes and edges and construct a random graph of that size, save it to a file and then read it in.
printf("Graph Object Constructed\n");
cout << "Checking Random Graph Generation" << endl;
T->T->GenerateRandomGraph("RandomGraph");
cout << "Checking file read method" << endl;
T->T->ReadInputFile("RandomGraph");
Then we initialize all the pixmaps and draw the graph object.
//initialize pixmaps and compute image
T->T->erase(T->pixmap);
T->T->draw(T->pixmap);
T->T->erase(T->pixmap2);
T->T->draw(T->pixmap2);
image(w,T);
}