LEDA Methods:
We created a library of methods that can be useful while building your own
algorithm implementation. We take a low level leda procedures, and wrapped
them with a more convenience methods for the user.
The advantage for the user is a easier interface with the leda tools.
In this document we explain about all the methods we created,
How to use them, we also have some example methods, that the
User can change to his own need.
User can also go inside our sources if he wants to understand better the use of the
methods.
remarks: user should define global variable of graphwin instance.
GraphWin GW(G, width,height,"title for the window") – this is a pointer
For the main window of the program, where
1. G in the graph refers to the window, should be declared as:
GRAPH<int,int> G;
2. width – the width of the window.
3. heigth – the heigth of the window.
4. title of the window.
Also user should define global variable shift.
Int shift – indicate if we refer to the nodes of the graph which has n
nodes from 0 to n-1 or from 1 to n. if shift it 0, so it is the first
one, otherwise from 1 to n.
In methods where there is a color parameter the possible values are:
black, white, red, green, blue, yellow, violet, orange,cyan, brown, pink,
green2, blue2, grey1, grey2, grey3.
Methods:
=================================================
1. void put_msg_on_screen(char* msg1,char* msg2, bool new_win)
=================================================
description: get a message and puts it on screen. If it gets true with the boolean
variable, it opens a new window with a title it gets(msg2) and puts the
message in the new window. the message lines are separated by /n.
The procedure takes all lines in the message and shows them on screen.
Parameters:
msg1 - the message to display on screen.
msg2 - the title of the window.
new_win - indicate if to show the message on a new window(true),
otherwise shows the message on the current window.
=================================================
2. void put_msg_on_screen(char* msg1,char* msg2, bool new_win ,
int width , int height)
=================================================
description: get a message and puts it on screen. If it gets true with the boolean
variable, it opens a new window with a title it gets(msg2), the size it gets,
and puts the message in the new window.
The message lines are separated by /n.
The procedure takes all lines in the message and shows them on screen.
Parameters:
msg1 - the message to display on screen.
msg2 - the title of the window.
new_win - indicate if to show the message on a new window(true),
otherwise shows the message on the current window.
width – the width of the window to open.
height – the height of the window to open.
=================================================
3.void put_msg_tight_on_screen(char* msg1,char* msg2, bool new_win)
=================================================
description: get a message and puts it on screen. If it gets true with the boolean
variable, it opens a new window with a title it gets(msg2) and puts the
message in the new window. the messgae lines are separated by /n.
the procedure takes all lines in the message and shows them on screen.
The procedure show the message “as tight as possible”.
That means, counts the line of the message and the width of it
(max char in line) and opens a window as much small as it can.
Parameters:
msg1 - the message to display on screen.
msg2 - the title of the window.
new_win - indicate if to show the message on a new window(true),
otherwise shows the message on the current window.
Remark: in the first 3 methods, user can puts the window at position
that he wants. For doing that, user has to change the line:
W.open();
with the line:
W.display(x_position,y_position).
=================================================
4. int count_lines(char* msg)
=================================================
description: returns the number of lines in a message.
the message lines are separated by /n.
Parameters:
msg - the message to return its number of lines.
=================================================
5. int count_width(char* msg)
=================================================
description: returns the width of the message, that means the maximum
chars in a line in the message. the message lines are separated by /n.
Parameters:
msg - the message to return its width.
=================================================
6. int key_Pressed2(int time, int press)
=================================================
description: waits time (in miliseconds) for a key to be pressed.
If key was pressed, it returns 1 and puts in press parameter the
value of the the key that was pressed, else return -1.
Parameters:
time - a time in milliseconds to wait.
press - variable to put the value of the key that was pressed.
=================================================
7. Vertex** make_adj_list(GraphWin& gw)
=================================================
description: make_adj_list - gets a graphwin variable, that includes a
graph inside, and returns an adjacency list that represents the graph.
The adjacency list is a Vertex** variable, that means an array of
pointers, for all nodes where each pointer points to the chain of
neighbors of the current nodes.
Description of class Vertex exists in Class_structure.doc.
Parameters:
gw - the graphwin that include the graph.
=================================================
8. void send_message (int from, int to , string value , int edgeColor )
=================================================
description: colors an edge, when a message with a value is send from
one node to another and put the value of the message on edge (label).
The graph is directed. This it a privte method for algorithm that
Include sending messages. It also can be used for methods that
colors an edge and put a label on it.
Parameters:
from - the source of the message.
to - the target of the message.
value - the value of the message.
edgeColor - the color for the edge to be colored.
=================================================
9. bool is_tree()
=================================================
description: checks if the graph (in the window) is a tree.
The method returns true if the graph is a tree, otherwise false.
=================================================
10. void mouse_right_button(GraphWin& gw)
=================================================
description: waits until the right button of the mouse is pressed.
Parameters:
gw - pointer to the graphwin.
=================================================
11. void mouse_left_button(GraphWin& gw)
=================================================
description: waits until the left button of the mouse is pressed.
Parameters:
gw - pointer to the graphwin.
=================================================
12. void colorNode(int i , color c)
=================================================
description: colors the node with the color c.
Parameters:
i - the number of the node to color.
c - the color to color with.
=================================================
13. void colorEdge( int from , int to ,color c)
=================================================
description: colors an edge with the color c.
Parameters:
from - the number of the source node of the edge.
to - the number of the target node of the edge.
c - the color to color with.
=================================================
14. void set_nodes_indexes(graph& G, color c)
=================================================
description: puts on all the nodes labels which are theirs numbers. The label
color is a parameter to the procedure.
Parameters:
c - the color of the label.
G - pointer to the graph.
=================================================
15. void change_node_label(int num, char* str)
=================================================
description: changes the label of a node.
Parameters:
num - the number of the node.
str - the new label.
=================================================
16. void change_node_label(char* str, int col)
=================================================
description: changes the label of the node with a ’col’ color.
This procedure is useful for algorithm that in it, there is always exists
only one such node.
Parameters:
str - the new label.
col - the color of the node to change its label.
=================================================
17. void set_edge_width(int from, int to, int width)
description: sets the width of an edge.
Parameters:
from - the source of the edge.
to - the destination of the edge.
width - the new width to set
=================================================
18. void change_node_shape(int num, gw_node_shape shape)
=================================================
description: changes the shape of a node.
Parameters:
num - the number of the node.
shape - the new shape of the node.
All the possible shapes are (gw_node_shape enum definition):
circle_node, ellipse_node, square_node, rectangle_node, roundrect_node,
ovalrect_node, rhombus_node, triang0_node, triang1_node, triang2_node,
triang3_node.
=================================================
19. char* translateColor(int c)
=================================================
description: translates a color from its number to its name.
Parameters:
c - the color number.
=================================================
20. char* translateShape(int c)
=================================================
description: translates a shape from its number in the
gw_node_shape enum definition to its name.
Parameters:
str - the shape number.
=================================================
21. int translateShapeToInt(string str)
=================================================
description: translates a shape from name to its number in the
gw_node_shape enum definition.
Parameters:
str - the shape name.
=================================================
22. node get_node(int num)
=================================================
description: gets the number of a node and return pointer to the node.
Parameters:
num - the number (index) of the node.
=================================================
23. edge get_edge(int from , int to)
=================================================
description: gets the numbers of the edge node's source and edge node's
target and returns a pointer to the edge.
Parameters:
from - the number (index) of the source node.
to - the number (index) of the target node.
=================================================
24. int get_node(node n,graph& G)
=================================================
description: gets a node pointer and returns its number(index).
Parameters:
n - the node.
G - the graph pointer.
=================================================
25. int edge_source(edge e,graph& G)
=================================================
description: gets an edge pointer and returns the number of its node source.
Parameters:
e - the edge
G - the graph pointer.
=================================================
26. int edge_target(edge e,graph& G)
=================================================
description: gets an edge pointer and returns the number of its node target.
Parameters:
e - the edge
G - the graph pointer.
=================================================
27. int get_node_color(int num)
=================================================
description: gets a node number and return its color.
The color that the procedure returns is a number from the
predefined colors in leda. To get the name of the color use
the translate procedure that gets a number and returns a string.
Parameters:
num - the node number.
=================================================
28. int get_node_shape(int num)
=================================================
description: gets a node number and return its shape.
The shape that the procedure returns is a number from the
gw_node_shape enum definition. To get the name of the shape
use the translate procedure that gets a number and returns a string.
Parameters:
num - the node number.
=================================================
29. string get_node_label(int num)
=================================================
description: gets a node number and returns its label.
Parameters:
num - the node number.
=================================================
30. int get_edge_color(int from, int to)
=================================================
description: gets an edge from and to nodes numbers and returns
its color. The color that the procedure returns is a number from
the predefined colors in leda. To get the name of the color use
the translate procedure that gets a number and returns a string.
Parameters:
num - the node number.
=================================================
31. int get_edge_width(int from, int to)
=================================================
description: gets an edge from and to nodes numbers and returns its width.
Parameters:
from - the edge source number.
to - the edge target number.
=================================================
32. string get_edge_label(int from, int to)
=================================================
description: gets an edge from and to nodes numbers and returns its label.
Parameters:
from - the edge source number.
to - the edge target number.
*****************************************************************
Example Methods:
Below there are examples of sources of some methods, with explanations
for functions of leda used. User can change these methods for his own need.
/*****************************************
Choose_Algorithm_Attribute
description: this is an example for choosing attributes for visualizing algorithm,
like a color item and int item (value of edge width for example).
Parameters:
gw - pointer to the graphwin.
*****************************************/
void Choose_Algorithm_Attribute (GraphWin& gw) {
int button_id,pressed;
color c1(color1);
color c2(color2);
color c3(color3);
itn int_item1,int_item2;
window W(500,500,"Choose Algorithm Attribute");
button_id=W.button(" O.k. ",1,Exit1,0);
W.set_item_width(25);
/******************************************
the function color_item get 4 parameters:
1. label to describe the item.
2. a color variable – this color variable gets initial value
when we declare it.
example: color c1(color1);
that means, c1 is a variable of color instance, that
its initial value is color1, like red for example,
and that value (red) is chosen in the color item.
(the red button is pressed).
3. the function to invoke when the value get changed.
the function is a function that gets int parameter
which is the value the user is choosing. For example, if user
choose blue, the function that was declared in the code,
is invoked and the int parameter it gets his value is blue
(or the position of blue in the int item).
the function must has a prototype:
void func_name(int i).
4. (const char*)0.
******************************************/
W.color_item("&select color 1",c1,function_color_1,(const char*)0);
W.color_item("&select color 2",c2,function_color_1,(const char*)0);
W.color_item("&select color 3",c3,function_color_1,(const char*)0);
/******************************************
the function int_item get 4 parameters:
1. a label to describe the item.
2. the variable to change. first the item shows the old
variable value, and the variable gets the new value when
the user change it.
3. the minimum value of the int item.
4. the maximum value of the int item.
******************************************/
W.int_item("select int item 1 ",int_item1,min_value1,max_value1);
W.int_item("select int item 2 ",int_item2,min_value2,max_value2);
gw .disable_calls();
W.open();
while(1){
pressed=W.read_mouse();
if (pressed==button_id)
break;
}
W.close();
gw.enable_calls();
GW.update_graph();
} //Choose_Algorithm_Attribute()
/******************************************
set_basic_menu
description: example for setting a main menu (a set of buttons) in the
graphwin, includes sub menus, buttons and changing a menu in the
node and edge menu, a menu that you get when you press on the right
mouse button.
Main menu - the menu of the man window (the window that start up
when the program start up).
Sub menu - a button with opposite triangle on him, that includes
a menu of his own.
Button - a button to press on, that invokes a procedure.
Parameters:
gw - pointer to the graphwin.
*****************************************/
void set_basic_menu(GraphWin& gw){
int how_to_run;
int expmale,help;
graph& G = gw.get_graph();
gw.set_frame_label("The Distributed algorithm");
/******************************************
function add_menu add a sub menu. it gets 3 parameters:
1. label to display on the button.
2. the menu_id of the menu to add to the sub menu. 0 means
the main menu, other means other sub menu.
3. const 0.
the function return menu_id.
******************************************/
how_to_run = gw.add_menu("&Running Mode",0,0);
/******************************************
function add_simple_call add a button to a sub menu.
it gets 4 parameters:
1. function which will be invoked when the user will press on it.
the function must have a prototype:
void func_name(GraphWin& gw)
2. label to display on the button.
3. the menu id (0 means main menu). In this example how_to_run
is the menu id of the sub menu we declared before.
4. const 0.
******************************************/
gw.add_simple_call(Step_By_Step,"&Step by Step",how_to_run,0);
gw.add_simple_call(Continually,"&Continually",how_to_run,0);
/******************************************
function gw_add_simple_call add a button to the main menu.
it gets 4 parameters:
1. pointer to the graphwin.
2. function which will be invoked when the user will press on it.
the function must have a prototype:
void func_name(GraphWin& gw)
3. label to display on the button.
4. const 0.
the function return button id.
******************************************/
gw_add_simple_call(gw,Choose_Algorithm_Attribute,
"&Algorithm Attribute",0);
gw_add_simple_call(gw,original_graph,"&original graph",0);
gw_add_simple_call(gw,the_algorithm,"&START",0);
gw_add_simple_call(gw,Exit,"&Exit",0);
gw_add_simple_call(gw,Restart,"&Restart",0);
gw_add_simple_call(gw,Theory,"&Theory",0);
gw_add_simple_call(gw,About,"&About",0);
expmale = gw.add_menu("&Examples",0,0);
gw.add_simple_call(example1,"&Example 1",exapmale,0);
gw.add_simple_call(example2,"&Example 2",exapmale,0);
gw.add_simple_call(example3,"&Example 3",exapmale,0);
help = gw.add_menu("&HELP",0,0);
gw.add_simple_call(help_Running_Mode,"&Running Mode",help,0);
gw.add_simple_call(help_Algorithm_Attribute,"&Algorithm Attribute",help,0);
/*****************************************/
function add_node_menu add a line to the menu of a node.
(the menu you get when you press on the right button of the mouse).
the function gets 2 parameters:
1. the label to display on the menu.
2. function which will be invoked when the user will press on it.
the function must have a prototype:
void func_name(GraphWin& gw).
******************************************/
gw.add_node_menu("&History",Show_Node_History);
gw.update_graph();
} //set_basic_menu()
/******************************************
Theory
description: this is an example for a window to write theory or help or about
and etc.
Parameters:
gw - pointer to the graphwin.
*****************************************/
void Theory(GraphWin& gw) {
window W(400,450,"Theory");
int button_id,pressed;
button_id=W.button("Exit This Window",1,Exit1,0);
W.open();
gw.disable_calls();
W.text_box("Here you have to write your theory...");
while(1){
pressed= W.read_mouse();
if (pressed==button_id)
break;
}
W.close();
gw.enable_calls();
} //Theory()
/******************************************
Choose_Int_Attribute
description: this is an example for choosing and changing an int
attribute for all graph nodes. this procedure use two global arrays.
1. old_int_attribute_values - keeps the old values.
2. int_attribute_values - keeps the new values.
the procedure create a window menu, with a line to each node,
and in each line there is an int item (in this example from 1 to 100).
After the user finishes to changing the values, the procedure calls to another
procedure that checks which nodes, their attribute has been changed and
invoke a procedure(or some commands) for those nodes.
Parameters:
gw - pointer to the graphwin.
*****************************************/
void Choose_Int_Attribute(GraphWin& gw) {
graph& G = gw.get_graph();
char str[40];
int button_id,pressed,index;
int number_of_nodes = G.number_of_nodes();
for (index = 0 ; index < number_of_nodes ; index++)
old_int_attribute_values[index] = int_attribute_values[index];
window W(50,number_of_nodes*35,"Choose Int Attribute");
button_id=W.button(" O.k. ",1,Exit1,0);
// loop foreach node, add a line to the menu for each node.
for (index = 0 ; index < number_of_nodes ; index++) {
sprintf(str, "node %d",index+shift);
W.int_item(str,int_attribute_values[index],0,100);
}
W.open();
while(1){
pressed=W.read_mouse();
if (pressed==button_id)
break;
}
W.close();
/* here you have to call the procedure that checks which nodes,
their attribute have been changed and invoke a procedure on those nodes.
proc_name( int_attribute_values , old_int_attribute_values ,
number_of_nodes)
The procedure gets two arrays:
1.int_attribute_values - the new values to user has been chosen.
2.old_int_attribute_values - the old values to user has been chosen.
The procedure has to check which values are different, and make
some operations on those nodes.
*/
set_color(color_attribute_values,old_color_attribute_values,number_of_nodes);
} //Choose_Int_Attribute()
/******************************************
set_int
description: this is an example for procedure that checks which nodes,
their attribute have been changed and apply a procedure(or some
commands) for those nodes. In this example the procedure only print in
the window which of the nodes theirs attribute have been changed.
Parameters:
new_values – the new values the user has been chosen.
old_values – the old values the user has been chosen.
num_of_nodes – the number of nodes.
*****************************************/
void set_int(int* new_values, int* old_values, int num_of_nodes) {
int index,len;
char str[2000];
len = 0;
for (index = 0 ; index < num_of_nodes ; index++ ) {
// check if node number 'index' int attribute has been changed.
if (new_values[index] != old_values[index])
//apply some commands for this node
len += sprintf(str+len,"node number %d int attribute was changed
from %d to %d\\n
,index+shift,old_values[index],new_values[index]);
}
if (len != 0)
GW.message((string)str);
} //set_int()
/******************************************
Choose_Color_Attribute
description: this is an example for choosing and changing a color attribute
for all graph nodes.This procedure uses two global arrays.
1. old_color_attribute_values - keeps the old values.
2. color_attribute_values - keeps the new values.
the procedure create a window menu, with a line to each node,
and in each line there is an color item.
After the user finishes changing the values, the procedure calls
to another procedure that checks which nodes, their attribute
has been changed and invoke a procedure(or some commands)
for those nodes.
Parameters:
gw - pointer to the graphwin.
*****************************************/
void Choose_Color_Attribute(GraphWin& gw) {
graph& G = gw.get_graph();
char str[40];
int button_id,pressed,index;
int number_of_nodes = G.number_of_nodes();
for (index = 0 ; index < number_of_nodes ; index++)
old_color_attribute_values[index] = color_attribute_values[index] =
GW.get_color(get_node(index));
window W(50,number_of_nodes*35,"Choose Color Attribute");
button_id=W.button(" O.k. ",1,Exit1,0);
// loop foreach node, add a line to the menu for each node.
for (index = 0 ; index < number_of_nodes ; index++) {
sprintf(str, "node %d",index+shift);
W.color_item(str,color_attribute_values[index],(const char*)0);
}
W.open();
while(1){
pressed=W.read_mouse();
if (pressed==button_id)
break;
}
W.close();
/* here you have to call the procedure that checks which nodes,
their attribute have been changed and invoke a procedure for those nodes.
proc_name( color_attribute_values , old_color_attribute_values ,
number_of_nodes)
The procedure get two arrays:
1.color_attribute_values - the new values to user has been chosen.
2.old_color_attribute_values - the old values to user has been chosen.
The procedure has to check which values are different, and make
some operations on those nodes.
*/
set_color(color_attribute_values,old_color_attribute_values, number_of_nodes);
} //Choose_Color_Attribute()
/******************************************
set_color
description: this is an example for procedure that checks which nodes,
their attribute have been changed and invoke a procedure(or some
commands) for those nodes. In this example the procedure changes the
nodes color for the new color the user has been chosen and print in
the window which of the nodes theirs attribute have been changed.
Parameters:
new_values – the new values the user has been chosen.
old_values – the old values the user has been chosen.
num_of_nodes – the number of nodes.
*****************************************/
void set_color(color* new_values, color* old_values, int num_of_nodes) {
int index,len;
char str[2000];
len = 0;
for (index = 0 ; index < num_of_nodes ; index++ ) {
// check if node number 'index' color attribute has been changed.
if (new_values[index] != old_values[index]) {
//apply some commands for this node
len += sprintf(str+len,"node number %d color was changed from
%s to %s\\n" ,
index+shift,translateColor(old_values[index].get_index())
,translateColor(new_values[index].get_index()));
GW.set_color(get_node(index),new_values[index]);
}
}
if (len != 0)
GW.message((string)str);
} //set_color()
/******************************************
Choose_Shape_Attribute
description: this is an example for choosing and changing a shape attribute for
all graph nodes. This procedure uses two global arrays.
1. old_shape_attribute_values - keeps the old values.
2. shape_attribute_values - keeps the new values.
The procedure creates a window menu, with a line to each node,
and in each line there is a string item.
After the user finishes to changing the values, the procedure invoke
another procedure that checks which nodes, their attribute
have been changed and invoke a procedure(or some commands)
for those nodes.
Parameters:
gw - pointer to the graphwin.
*****************************************/
void Choose_Shape_Attribute(GraphWin& gw) {
graph& G = gw.get_graph();
char str[40];
int button_id,pressed,index;
int number_of_nodes = G.number_of_nodes();
list<string> l;
l.push("circle");
l.push("ellipse");
l.push("square");
l.push("rectangle");
l.push("roundrect");
l.push("ovalrect");
l.push("rhombus");
l.push("triangle");
for (index = 0 ; index < number_of_nodes ; index++)
old_shape_attribute_values[index] = shape_attribute_values[index] =
translateShape1 (GW.get_shape(get_node(index)));
window W(50,number_of_nodes*35,"Choose Shape Attribute");
button_id=W.button(" O.k. ",1,Exit1,0);
// loop foreach node, add a line to the menu for each node.
for (index = 0 ; index < number_of_nodes ; index++) {
sprintf(str, "node %d",index+shift);
/* the function string_item get 4 parameters:
1. a label to describe the item.
2. the variable to change. first the item shows the old
variable value, and the variable gets the new value when
the user change it.
3. a list with all the possible values to choose from.
4. (const char*)0.
*/
W.string_item(str,shape_attribute_values[index],l,(const char*)0);
}
W.open();
while(1){
pressed=W.read_mouse();
if (pressed==button_id)
break;
}
W.close();
/* here you have to call the procedure that checks which nodes,
their attribute have been changed and invoke a procedure for those nodes.
proc_name( shape_attribute_values , old_shape_attribute_values ,
number_of_nodes)
the procedure get two arrays:
1.shape_attribute_values - the new values to user has been chosen.
2.old_shape_attribute_values - the old values to user has been chosen.
the procedure has to check which values are different, and make
some operations on those nodes.
*/
set_shape(shape_attribute_values,old_shape_attribute_values,number_of_nodes);
} //Choose_Shape_Attribute()
/******************************************
set_shape
description: this is an example for procedure that checks which nodes,
their attribute have been changed and apply a procedure(or some
commands) for those nodes. in this example the procedure changes
the nodes shape for the new shape the user has been chosen and print in
the window which of the nodes theirs attribute have been changed.
Parameters:
new_values – the new values the user has been chosen.
old_values – the old values the user has been chosen.
num_of_nodes – the number of nodes.
*****************************************/
void set_shape(string* new_values, string* old_values, int num_of_nodes) {
int index,len;
char str[2000];
len = 0;
for (index = 0 ; index < num_of_nodes ; index++ ) {
// check if node number 'index' shape attribute has been changed.
if (new_values[index] != old_values[index]) {
//apply some commands for this node
len += sprintf(str+len,"node number %d shape was
changed from %s to%s\\n" , index+shift ,
old_values[index].cstring() ,
new_values[index].cstring());
GW.set_shape(get_node(index),
(gw_node_shape)translateShapeToInt(new_values[index]));
}
}
if (len != 0)
GW.message((string)str);
} //set_shape()
/******************************************
description: this is an example for choosing and changing a node
size attribute for all graph nodes.
This procedure uses two global arrays.
1. old_node_size_values - keeps the old values.
2. node_size_values - keeps the new values.
The procedure creates a window menu, with a line to each node,
and in each line there is a size item.
After the user finishes changing the values, the procedure invoke
another procedure that checks which nodes, their attribute
has been changed and apply a procedure(or some commands)
for those nodes.
Parameters:
gw - pointer to the graphwin.
*****************************************/
void Choose_Node_Size(GraphWin& gw) {
graph& G = gw.get_graph();
char str[40];
int button_id,pressed,index;
int number_of_nodes = G.number_of_nodes();
for (index = 0 ; index < number_of_nodes ; index++)
old_node_size_values[index] = node_size_values[index] =
GW.get_width(get_node(index));
window W(50,number_of_nodes*35,"Choose Nodes Size Attribute");
button_id=W.button(" O.k. ",1,Exit1,0);
// loop foreach node, add a line to the menu for each node.
for (index = 0 ; index < number_of_nodes ; index++) {
sprintf(str, "node %d",index+shift);
W.int_item(str,node_size_values[index],0,200);
}
W.open();
while(1){
pressed=W.read_mouse();
if (pressed==button_id)
break;
}
W.close();
/* here you have to call the procedure that checks which nodes,
their node size has been changed and invoke a procedure for those nodes.
proc_name( node_size_values , old_node_size_values , number_of_nodes)
The procedure gets two arrays:
1.node_size_values - the new values to user has been chosen.
2.old_node_size_values - the old values to user has been chosen.
The procedure has to check which values are different, and makes
some operations on those nodes.
*/
set_nodes_size(node_size_values ,old_node_size_values ,number_of_nodes);
} //Choose_Node_Size()
/******************************************
description: this is an example for procedure that checks which nodes,
their attribute have been changed and invoke a procedure(or some
commands) for those nodes. In this example the procedure changes
the nodes size with the chosen values and prints in the window which
of the nodes theirs attribute have been changed.
Parameters:
new_values – the new values the user has been chosen.
old_values – the old values the user has been chosen.
num_of_nodes – the number of nodes.
*****************************************/
void set_nodes_size(int* new_values, int* old_values, int num_of_nodes) {
int index,len;
char str[2000];
len = 0;
for (index = 0 ; index < num_of_nodes ; index++ )
if (new_values[index] != old_values[index]) {
GW.set_height(get_node(index),new_values[index]);
GW.set_width(get_node(index),new_values[index]);
len += sprintf(str+len,"node number %d int attribute was
changed from %d to %d\\n
",index+shift,old_values[index],new_values[index]);
}
if (len != 0)
GW.message((string)str);
} //set_nodes_size()
© Copyright 2026 Paperzz