Update of /cvsroot/avl/avl/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12343/src
Modified Files:
Makefile avl.cpp bst.cpp bst.h
Log Message:
GTK GUI added
Index: bst.h
===================================================================
RCS file: /cvsroot/avl/avl/src/bst.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** bst.h 25 Jun 2004 16:05:57 -0000 1.3
--- bst.h 4 Aug 2004 15:31:36 -0000 1.4
***************
*** 1,5 ****
/***************************************************************************
! * Copyright (C) 2004 by Gianlorenzo D'Angelo *
! * jah@notebook0 *
* *
* This program is free software; you can redistribute it and/or modify *
--- 1,5 ----
/***************************************************************************
! * Copyright (C) 2004 by Patrizio Bassi && Gianlorenzo D'Angelo *
! * *
* *
* This program is free software; you can redistribute it and/or modify *
***************
*** 21,28 ****
#define BST_H
#include "stdio.h"
/**
! @author Gianlorenzo D'Angelo
*/
class Bst {
--- 21,33 ----
#define BST_H
+ #ifdef GUI
+ #include <gtk/gtk.h>
+ #include <glib.h>
+ #endif
+
#include "stdio.h"
/**
! @authors Patrizio Bassi && Gianlorenzo D'Angelo
*/
class Bst {
***************
*** 36,39 ****
--- 41,49 ----
void erase();
void print_ric( int, int );
+ #ifdef GUI
+ void ric();
+ #else
+ void c_print(char*);
+ #endif
public:
***************
*** 71,75 ****
--- 81,89 ----
void print();
+ #ifndef GUI
void print1();
+ #else
+ GtkWidget* print1();
+ #endif
};
Index: bst.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/bst.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** bst.cpp 18 Jul 2004 16:57:10 -0000 1.8
--- bst.cpp 4 Aug 2004 15:31:36 -0000 1.9
***************
*** 1,5 ****
/***************************************************************************
! * Copyright (C) 2004 by Gianlorenzo D'Angelo *
! * jah@notebook0 *
* *
* This program is free software; you can redistribute it and/or modify *
--- 1,5 ----
/***************************************************************************
! * Copyright (C) 2004 by Patrizio Bassi && Gianlorenzo D'Angelo *
! * *
* *
* This program is free software; you can redistribute it and/or modify *
***************
*** 18,23 ****
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "bst.h"
- //#include <string.h>
Bst::Bst()
--- 18,23 ----
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#include "bst.h"
Bst::Bst()
***************
*** 356,360 ****
}
! int c_print(char *string){
// for colors and style.
--- 356,364 ----
}
! // le prossime due funzioni non utilizzano le librerie grafiche GTK
! // ma la semplice stampa a colori con delle printf
! #ifndef GUI
! // funzione di utilità per stampare a colori
! void Bst::c_print(char *string){
// for colors and style.
***************
*** 395,399 ****
printf("[%i;%i;40m",NORMAL,GRAY);
}
!
void Bst::print1()
{
--- 399,403 ----
printf("[%i;%i;40m",NORMAL,GRAY);
}
! // usa c_print per stampare a colori. Funzione ricorsiva
void Bst::print1()
{
***************
*** 428,429 ****
--- 432,523 ----
}
+ #else
+ /* GTK GUI. Utilizza una visualizzazione ad albero
+ permettendo di espandere e ridurre i vari rami
+ */
+
+ GtkTreeIter iter1,iter2; //non si possono utilizzare i puntatori, per problemi di inizializzazione del NULL (il primo) puntatore
+ GtkTreeStore *store;
+
+ void Bst::ric()
+ {
+
+ GtkTreeIter aux;
+ gchar *msg=NULL;
+
+ aux=iter2; //ricorda a che punto stiamo, appende tutti i rami destri e riprende
+ if( getRight() )
+ {
+ msg=NULL;
+ msg = g_strdup_printf ("(son of: %d) Right Value: %d", getValue(),getRight()->getValue());
+ gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,&iter2);
+ gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, msg, -1);
+ if (msg) g_free (msg);
+
+ iter2=iter1;
+ getRight()->ric();
+ }
+ iter2=aux; //riprende dopo aver appeso i rami destri, e termina con i rami sinistri
+ if( getLeft() )
+ {
+ msg=NULL;
+ msg = g_strdup_printf ("(son of: %d) Left Value: %d", getValue(),getLeft()->getValue());
+ gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,&iter2);
+ gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, msg, -1);
+ if (msg) g_free (msg);
+
+ iter2=iter1;
+ getLeft()->ric();
+
+ }
+
+ }
+
+
+ GtkWidget* Bst::print1()
+ {
+ GtkWidget *scrolled_window;
+ GtkWidget *tree_view;
+
+ GtkCellRenderer *cell;
+ GtkTreeViewColumn *column;
+
+ Bst* root;
+ gchar* msg;
+
+ //creo una contenitore che sia scrollabile
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ //creo il contenitore dell'albero
+ store=gtk_tree_store_new(1,G_TYPE_STRING);
+
+ //creo l'albero e lo lego al contenitore
+ tree_view = gtk_tree_view_new ();
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), tree_view);
+
+ //link dell'albero e il suo contenitore
+ gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (store));
+ gtk_widget_show (tree_view);
+
+ //needed workaround - aggiungo un primo elemento root
+ gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,NULL);
+ gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, "Here Begins AVL Tree Diplay", -1);
+
+ //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);
+ gtk_tree_store_set (GTK_TREE_STORE (store), &iter2, 0, msg, -1);
+ g_free(msg);
+
+ root->ric();
+
+ //finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero.
+ cell = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("AVL Tree",cell,"text", 0, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (column));
+
+ return scrolled_window; //ritorno l'oggetto, nel main viene visualizzato e appeso alla finestra principale.
+ }
+ #endif
Index: Makefile
===================================================================
RCS file: /cvsroot/avl/avl/src/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Makefile 17 Jul 2004 12:34:55 -0000 1.4
--- Makefile 4 Aug 2004 15:31:36 -0000 1.5
***************
*** 1,5 ****
# AVL Project
! CC=g++ -O2
LIBS=avlt.o bst.o test.o avl.o
BINARY=avl
--- 1,14 ----
# AVL Project
! ifdef gtk_gui
! CC=g++ -O2 -Wall -W `pkg-config gtk+-2.0 --cflags` -DGUI
! else
! CC=g++ -O2 -Wall -W
! endif
LIBS=avlt.o bst.o test.o avl.o
+ ifdef gtk_gui
+ GTKLIBS=`pkg-config gtk+-2.0 --libs`
+ else
+ GTKLIBS=
+ endif
BINARY=avl
***************
*** 19,23 ****
$(BINARY): $(LIBS)
! $(CC) -o $(BINARY) $(LIBS)
clean:
--- 28,32 ----
$(BINARY): $(LIBS)
! $(CC) -o $(BINARY) $(LIBS) $(GTKLIBS)
clean:
***************
*** 32,33 ****
--- 41,48 ----
$(CC) -fPIC -c avlt.cpp -o avlt.o
$(CC) -shared -Wl,-soname,libavl.a -o libavl.a $(LIBS) -lc
+
+ install:
+ echo "not yet ready"
+
+ gui:
+ make gtk_gui=true
\ No newline at end of file
Index: avl.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/avl.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** avl.cpp 17 Jul 2004 19:48:27 -0000 1.7
--- avl.cpp 4 Aug 2004 15:31:36 -0000 1.8
***************
*** 23,27 ****
#endif
- //#include "avlt.h"
#include "test.h"
#include <iostream>
--- 23,26 ----
***************
*** 30,33 ****
--- 29,79 ----
using namespace std;
+ //era un test con la libreria dotneato, ma non mi compila con l'ultima versione
+ #if 0
+ void print_test(){
+
+
+ Agraph_t *g;
+ Agnode_t *n, *m;
+ Agedge_t *e;
+ Agsym_t *a;
+
+ /*ma serve? no: initialize devi implementarla tu per ripulire la commandline (se vuoi...)*/
+ /* argc = initialize( argc, argv ); */
+
+ /*Prende i parametri -T sul tipo file e -o sull'output file: vedi man dot*/
+ dotneato_initialize( argc, argv );
+
+ /* Crea un semplice digrafo*/
+ g = agopen( "g", AGDIGRAPH );
+ n = agnode( g, "n" );
+ m = agnode( g, "m" );
+ e = agedge( g, n, m);
+
+ /* Setto l'attributo di rendering: "colore blu"*/
+ a = agnodeattr( g, "color", "blue" );
+ agxset( n, a->index, "red" );
+
+ /* Calcola un layout per il grafo: qui neato*/
+ neato_layout( g );
+ /* twopi_layout( g );*/
+ /* dot_layout( g );*/
+
+ /* Scrive il grafo, secondo le opzioni -T ed -o della linea di comando.*/
+ dotneato_write( g );
+
+ /* Ripulisce le strutture dati usate per creare il layout*/
+ neato_cleanup( g );
+ /* twopi_cleanup( g );*/
+ /* dot_cleanup( g );*/
+
+ /* Libera le risorse associate al grafo*/
+ agclose( g );
+
+
+
+ }
+ #endif
+
int main(int argc, char *argv[])
{
***************
*** 123,126 ****
--- 169,177 ----
// printf("%d",b->getValue());
#endif
+
+
+
+
+
/*
// 0= test avl
***************
*** 148,152 ****
printf("Comparation on the way, wait\n");
prova_bst = new Test(2,upper_bound,base_tree);
! }*/
//Test *prova;
//prova = new Test(1,5,1);
--- 199,206 ----
printf("Comparation on the way, wait\n");
prova_bst = new Test(2,upper_bound,base_tree);
! }
! */
!
!
//Test *prova;
//prova = new Test(1,5,1);
***************
*** 156,160 ****
Bst a(1 );
-
a.insert(3);
a.insert(5);
--- 210,213 ----
***************
*** 175,179 ****
a.insert(-600);
a.insert(-700);
a.print1();
! return EXIT_SUCCESS;
}
--- 228,264 ----
a.insert(-600);
a.insert(-700);
+ #ifndef GUI
a.print1();
! #else
! GtkWidget *window;
! GtkWidget *vpaned;
! GtkWidget *node_list;
!
! gtk_init (&argc, &argv);
!
! char* fullname="AVL Tree Visualization";
!
! window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
!
! gtk_window_set_title (GTK_WINDOW (window), fullname);
!
! g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
!
! gtk_container_set_border_width (GTK_CONTAINER (window), 15);
! gtk_widget_set_size_request (GTK_WIDGET (window), 500, 450);
!
! vpaned = gtk_vpaned_new ();
! gtk_container_add (GTK_CONTAINER (window), vpaned);
! gtk_widget_show (vpaned);
!
! node_list = a.print1();
!
! gtk_paned_add1 (GTK_PANED (vpaned), node_list);
! gtk_widget_show (node_list);
!
! gtk_widget_show (window);
!
! gtk_main ();
! #endif
! return EXIT_SUCCESS;
}
|