Update of /cvsroot/avl/avl/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24641
Modified Files:
Makefile avl.cpp bst.cpp test.cpp
Log Message:
added new gui things!
Index: bst.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/bst.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** bst.cpp 8 Sep 2004 10:14:46 -0000 1.17
--- bst.cpp 16 Sep 2004 17:51:16 -0000 1.18
***************
*** 466,477 ****
GtkWidget* Bst::print_best_look()
{
! GtkWidget *scrolled_window;
! GtkWidget *tree_view;
! GtkCellRenderer *cell;
! GtkTreeViewColumn *column;
! Bst* root;
! gchar* msg;
//creo una contenitore che sia scrollabile
--- 466,477 ----
GtkWidget* Bst::print_best_look()
{
! GtkWidget *scrolled_window=NULL;
! GtkWidget *tree_view=NULL;
! GtkCellRenderer *cell=NULL;
! GtkTreeViewColumn *column=NULL;
! Bst* root=NULL;
! gchar* msg=NULL;
//creo una contenitore che sia scrollabile
***************
*** 496,500 ****
//prendo la root e stampo tutto l'albero, appendo il primo valore e poi ricorsivamente tutti gli altri
root=this->root();
!
msg = g_strdup_printf ("%d", root->getValue());
gtk_tree_store_append (GTK_TREE_STORE (store), &iter2,&iter1);
--- 496,500 ----
//prendo la root e stampo tutto l'albero, appendo il primo valore e poi ricorsivamente tutti gli altri
root=this->root();
! if (root) {
msg = g_strdup_printf ("%d", root->getValue());
gtk_tree_store_append (GTK_TREE_STORE (store), &iter2,&iter1);
***************
*** 503,507 ****
root->print_gtk_ric();
!
//finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero.
cell = gtk_cell_renderer_text_new ();
--- 503,507 ----
root->print_gtk_ric();
! }
//finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero.
cell = gtk_cell_renderer_text_new ();
Index: Makefile
===================================================================
RCS file: /cvsroot/avl/avl/src/Makefile,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Makefile 8 Sep 2004 17:59:54 -0000 1.9
--- Makefile 16 Sep 2004 17:51:16 -0000 1.10
***************
*** 2,6 ****
ifdef gtk_gui
! CC=g++ -O2 -Wall -W `pkg-config gtk+-2.0 --cflags` -DGUI
else
CC=g++ -O2 -Wall -W
--- 2,6 ----
ifdef gtk_gui
! CC=g++ -O2 -Wall -W `pkg-config gtk+-2.0 --cflags` -DGUI -g
else
CC=g++ -O2 -Wall -W
Index: test.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/test.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** test.cpp 8 Sep 2004 17:59:54 -0000 1.14
--- test.cpp 16 Sep 2004 17:51:16 -0000 1.15
***************
*** 28,32 ****
Test::~Test() {
!
}
--- 28,32 ----
Test::~Test() {
! if(result_log) free(result_log);
}
Index: avl.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/avl.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** avl.cpp 8 Sep 2004 17:59:54 -0000 1.17
--- avl.cpp 16 Sep 2004 17:51:16 -0000 1.18
***************
*** 38,46 ****
#ifdef GUI
!
GtkWidget *node_list=NULL;
GtkWidget *vpaned1=NULL;
GtkWidget *spinbutton1=NULL;
GtkWidget *spinbutton2=NULL;
// le prossime tre funzioni sono associate al radio button per la scelta del test
--- 38,49 ----
#ifdef GUI
! GtkWidget* node_list_start();
! bool insert=true;
GtkWidget *node_list=NULL;
GtkWidget *vpaned1=NULL;
GtkWidget *spinbutton1=NULL;
GtkWidget *spinbutton2=NULL;
+ GtkWidget *spinbutton3=NULL;
+ GtkWidget *nodelist=NULL;
// le prossime tre funzioni sono associate al radio button per la scelta del test
***************
*** 57,60 ****
--- 60,171 ----
}
+ void shutdown_window() {
+
+ gtk_widget_destroy(node_list);
+ node_list=nodelist;
+
+ gtk_paned_add1 (GTK_PANED (vpaned1), node_list);
+ gtk_widget_show (node_list);
+ gtk_widget_show (vpaned1);
+
+ }
+
+ void popup_window(int kind,char* operation="",int value=9999999){
+
+ GtkWidget *popup_window=NULL;
+ GtkWidget *pane=NULL;
+ GtkWidget *temp_node_list;
+
+ char fullname[200];
+
+ if (kind==0) {
+ sprintf(fullname,"AVL Tree Visualization after the %s of value %d",operation,value);
+ nodelist=aux_avl->print_best_look();
+ temp_node_list=aux_avl->print_best_look();
+ }
+ else if (kind==1) {
+ sprintf(fullname,"BST Tree Visualization after the %s of value %d",operation,value);
+ nodelist=aux_bst->print_best_look();
+ temp_node_list=aux_avl->print_best_look();
+ }
+ else return;
+
+ //crea la popup window
+ popup_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (popup_window), fullname);
+ g_signal_connect_swapped (G_OBJECT (popup_window), "destroy", G_CALLBACK (shutdown_window), G_OBJECT (popup_window));
+ gtk_container_set_border_width (GTK_CONTAINER (popup_window), 15);
+
+ //crea i due pannelli verticali
+ pane = gtk_vpaned_new ();
+ gtk_container_add (GTK_CONTAINER (popup_window), pane);
+ gtk_widget_show (pane);
+
+ gtk_paned_add1 (GTK_PANED (pane), temp_node_list);
+ gtk_widget_show (temp_node_list);
+ gtk_widget_show (popup_window);
+
+ }
+
+ void test_single_operation() {
+
+ GtkWidget* dialog;
+ switch(choice) {
+ case 2:
+ dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "You must choice AVL or BST tree test");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ break;
+
+ case 1:
+ if (aux_bst==NULL) {
+ dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "You must initialise a BST tree before!");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+ else {
+ if (insert) {
+ aux_bst->insert(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton3)));
+ popup_window(1,"insertion", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton3)));
+ }
+ else {
+ aux_bst->erase(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton3)));
+ popup_window(1,"deletion", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton3)));
+ }
+ }
+
+ break;
+
+ case 0:
+ if (aux_avl==NULL) {
+ dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "You must initialise an AVL tree before!");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+ else {
+ if (insert) {
+ aux_avl=aux_avl->insert(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton3)));
+ popup_window(0,"insertion", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton3)));
+ }
+ else {
+ aux_avl=aux_avl->erase(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton3)));
+ popup_window(0,"deletion", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton3)));
+ }
+
+ }
+ break;
+ default:;
+ }
+ }
+
+ void ins_select() {
+ insert=true;
+ }
+
+ void del_select() {
+ insert=false;
+ }
+
+
// linkato col bottone start. Fa partire il test scelto e poi aggiorna a video
// la visualizzazione dell'albero o il report comparativo.
***************
*** 94,98 ****
gtk_widget_show (box1);
- //view= gtk_label_new ("Tree display disabled\nComparation test choosen");
view=gtk_label_new(prova->getResultLog());
gtk_container_add (GTK_CONTAINER (box1), view);
--- 205,208 ----
***************
*** 184,188 ****
#else
!
GtkWidget *window=NULL;
GtkWidget *vpaned2=NULL;
--- 294,298 ----
#else
!
GtkWidget *window=NULL;
GtkWidget *vpaned2=NULL;
***************
*** 193,196 ****
--- 303,307 ----
GtkWidget *box4=NULL;
GtkWidget *box5=NULL;
+ GtkWidget *box6=NULL;
GSList *group=NULL;
GtkAdjustment *adj=NULL;
***************
*** 241,244 ****
--- 352,360 ----
gtk_widget_show (box5);
+ box6 = gtk_hbox_new (FALSE, 10);
+ gtk_container_set_border_width (GTK_CONTAINER (box6), 10);
+ gtk_box_pack_start (GTK_BOX (box1), box6, TRUE, TRUE, 0);
+ gtk_widget_show (box6);
+
//il contenitore per la scelta dei test
label = gtk_label_new ("What do you want to test?");
***************
*** 256,260 ****
button = gtk_radio_button_new_with_label (group, "BST");
g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (bst_select),G_OBJECT (button));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
--- 372,375 ----
***************
*** 292,305 ****
gtk_box_pack_start (GTK_BOX (box4), spinbutton2, FALSE, TRUE, 0);
gtk_widget_show (spinbutton2);
//start e quit button
! button = gtk_button_new_with_label ("start");
g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (start), G_OBJECT (window));
! gtk_box_pack_start (GTK_BOX (box5), button, FALSE, TRUE, 55);
gtk_widget_show (button);
! button = gtk_button_new_with_label ("close");
g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (gtk_main_quit), G_OBJECT (window));
! gtk_box_pack_start (GTK_BOX (box5), button, FALSE, TRUE, 65);
gtk_widget_show (button);
--- 407,450 ----
gtk_box_pack_start (GTK_BOX (box4), spinbutton2, FALSE, TRUE, 0);
gtk_widget_show (spinbutton2);
+
+ label = gtk_label_new ("Select operation and insert a value");
+ gtk_label_set_justify(GTK_LABEL (label),GTK_JUSTIFY_LEFT);
+ gtk_box_pack_start (GTK_BOX (box5), label, TRUE, TRUE, 0);
+ gtk_widget_show (label);
+
+ button = gtk_radio_button_new_with_label (NULL, "Insert");
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (ins_select),G_OBJECT (button));
+ gtk_box_pack_start (GTK_BOX (box5), button, TRUE, TRUE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ gtk_widget_show (button);
+ group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
+ button = gtk_radio_button_new_with_label (group, "Deletion");
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (del_select),G_OBJECT (button));
+ gtk_box_pack_start (GTK_BOX (box5), button, TRUE, TRUE, 0);
+ gtk_widget_show (button);
+
+ adj = (GtkAdjustment *) gtk_adjustment_new (500, 0, 10000000, 10, 0, 0);
+ spinbutton3 = gtk_spin_button_new (adj, 0, 0);
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinbutton3), FALSE);
+ gtk_spin_button_set_numeric(GTK_SPIN_BUTTON (spinbutton3), TRUE);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON (spinbutton3), 1000);
+ gtk_box_pack_start (GTK_BOX (box5), spinbutton3, FALSE, TRUE, 0);
+ gtk_widget_show (spinbutton3);
+
+ button = gtk_button_new_with_label ("Apply Modification");
+ g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (test_single_operation), NULL);
+ gtk_box_pack_start (GTK_BOX (box5), button, FALSE, TRUE, 55);
+ gtk_widget_show (button);
+
//start e quit button
! button = gtk_button_new_with_label ("Initialise");
g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (start), G_OBJECT (window));
! gtk_box_pack_start (GTK_BOX (box6), button, FALSE, TRUE, 55);
gtk_widget_show (button);
! button = gtk_button_new_with_label ("Close");
g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (gtk_main_quit), G_OBJECT (window));
! gtk_box_pack_start (GTK_BOX (box6), button, FALSE, TRUE, 65);
gtk_widget_show (button);
|