5 #include <libgnomecanvasmm.h>
8 #include "view_btree.h"
9 #include "view_properties.h"
10 #include "new_tree_dialog.h"
11 #include "key_dialog.h"
12 #include "view_debug.h"
14 using namespace Gnome::Canvas;
16 Glib::ustring ui_info =
18 " <menubar name='MenuBar'>"
19 " <menu action='MenuFile'>"
20 " <menuitem action='Nuevo'/>"
22 " <menuitem action='Salir'/>"
24 " <menu action='MenuKey'>"
25 " <menuitem action='Agregar Clave'/>"
26 " <menuitem action='Borrar Clave'/>"
27 " <menuitem action='Buscar Clave'/>"
29 " <menu action='MenuZoom'>"
30 " <menuitem action='Alejar'/>"
31 " <menuitem action='Acercar'/>"
33 " <menuitem action='100 %'/>"
39 void agregar_clave ();
46 Glib::RefPtr<ViewBTree> tree;
47 Gnome::Canvas::Canvas *real_canvas;
48 ViewProperties *real_frame;
50 int main(int argc, char *argv[])
52 Gtk::Main kit(argc, argv);
54 Gnome::Canvas::init ();
60 Gtk::ScrolledWindow area;
61 Gnome::Canvas::Canvas canvas;
64 real_canvas = &canvas;
67 canvas.set_scroll_region (0, 0, 100, 100);
70 hbox.pack_start (area);
71 hbox.pack_end (frame, true, true, 10);
73 Glib::RefPtr<Gtk::ActionGroup> actiongroup = Gtk::ActionGroup::create();
75 actiongroup->add( Gtk::Action::create("MenuFile", "_Arbol") );
76 actiongroup->add( Gtk::Action::create("Nuevo", Gtk::Stock::NEW), &nuevo_arbol);
77 actiongroup->add( Gtk::Action::create("Salir", Gtk::Stock::QUIT), Gtk::AccelKey ("<control>q"), &Gtk::Main::quit);
78 actiongroup->add( Gtk::Action::create("MenuKey", "_Clave") );
79 actiongroup->add( Gtk::Action::create("Agregar Clave", Gtk::Stock::ADD), Gtk::AccelKey ("<control>a"), &agregar_clave);
80 actiongroup->add( Gtk::Action::create("Borrar Clave", Gtk::Stock::REMOVE), Gtk::AccelKey ("<control>d"), &borrar_clave);
81 actiongroup->add( Gtk::Action::create("Buscar Clave", Gtk::Stock::FIND), Gtk::AccelKey ("<control>f"), &buscar_clave);
82 actiongroup->add( Gtk::Action::create("MenuZoom", "_Zoom"));
83 actiongroup->add( Gtk::Action::create("Alejar", Gtk::Stock::ZOOM_OUT), Gtk::AccelKey ("<control>z"), &zoom_out );
84 actiongroup->add( Gtk::Action::create("Acercar", Gtk::Stock::ZOOM_IN), Gtk::AccelKey ("<control>x"), &zoom_in);
85 actiongroup->add( Gtk::Action::create("100 %", Gtk::Stock::ZOOM_100), Gtk::AccelKey ("<control>1"), &zoom_normal);
87 Glib::RefPtr<Gtk::UIManager> m_refUIManager = Gtk::UIManager::create();
88 m_refUIManager->insert_action_group (actiongroup);
90 m_refUIManager->add_ui_from_string(ui_info);
91 Gtk::Widget* menubar = m_refUIManager->get_widget("/MenuBar");
94 vbox.pack_start (*menubar, false, true, 0);
95 vbox.pack_end (hbox, true, true, 5);
97 window.add_accel_group (m_refUIManager->get_accel_group ());
99 window.set_size_request (640, 480);
102 /* Conecto el Canvas con el Frame */
103 Gtk::Main::run(window);
110 real_canvas->set_scroll_region (0, 0, 5000, 5000);
113 if (d.run () == Gtk::RESPONSE_OK) {
114 uint altas = d.getAdds ();
115 uint bajas = d.getDels ();
117 double paltas = bajas / (double)altas;
119 int type = d.getKeyType ();
120 tree = Glib::RefPtr<ViewBTree>(new ViewBTree (real_canvas->root(), "test.idx", d.getBlockSize (), type));
121 tree->signal_selected ().connect ( sigc::mem_fun (*real_frame, &ViewProperties::ShowItem) );
122 if (type == BTree::KEY_FIXED) {
124 std::list<int>::iterator it;
126 Random::Ints (lst, altas);
130 while (it != lst.end ()) {
133 double l = Random::Double (0.0f, 1.0f);
134 std::cout << l << " >= " << paltas << std::endl;
139 /* Tengo que borrar una clave entre 0 e "i" de la lista
140 * porque son las que ya agregue. */
141 int aborrar = (int)Random::Double (0, i);
142 std::list<int>::iterator otro = lst.begin ();
144 while (j < aborrar) {
152 std::cout << "Clave Borrada " << sss << std::endl;
158 std::list<std::string> lst;
159 std::list<std::string>::iterator it;
161 Random::Strings (lst, altas);
164 while (it != lst.end ()) {
165 ClaveVariable c(*it);
172 double x1, x2, y1, y2;
173 tree->get_bounds (x1, y1, x2, y2);
174 real_canvas->scroll_to (0, 0);
178 void agregar_clave ()
182 Gtk::MessageDialog d("No hay un arbol creado, por favor primero cree un arbol!",
183 false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
187 KeyDialog d("Agregar");
188 if (d.run () == Gtk::RESPONSE_OK)
190 Glib::ustring str_key = d.key();
191 if (tree->type() == BTree::KEY_FIXED)
193 ClaveFija c(atoi(str_key.c_str()));
198 ClaveVariable c(str_key);
201 delete tree->last_selected;
203 real_canvas->scroll_to (0, 0);
211 Gtk::MessageDialog d("No hay un arbol creado, por favor primero cree un arbol!",
212 false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
216 KeyDialog d("Borrar");
217 if (d.run () == Gtk::RESPONSE_OK)
219 Glib::ustring str_key = d.key();
220 if (tree->type() == BTree::KEY_FIXED)
222 ClaveFija c(atoi(str_key.c_str()));
227 ClaveVariable c(str_key);
230 delete tree->last_selected;
232 real_canvas->scroll_to (0, 0);
240 Gtk::MessageDialog d("No hay un arbol creado, por favor primero cree un arbol!",
241 false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
245 KeyDialog d("Buscar");
246 while (true) // Repite hasta que se encuentre algo o se cancele
248 if (d.run () == Gtk::RESPONSE_OK)
250 BTreeFindResult* result = 0;
252 Glib::ustring str_key = d.key();
253 if (tree->type() == BTree::KEY_FIXED)
255 c = new ClaveFija (atoi(str_key.c_str()));
256 result = tree->FindKey(*c);
260 c = new ClaveVariable (str_key);
261 result = tree->FindKey(*c);
266 tree->AddNode(result->node);
267 tree->HighliteKey (*c);
270 real_canvas->scroll_to (0, 0);
271 return; // Encontramos, salimos
274 Gtk::MessageDialog msg("Clave no encontrada!", false,
275 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
277 // Seguimos intentando
279 else return; // Cancelaron, salimos
285 double r = real_canvas->get_pixels_per_unit ();
289 real_canvas->set_pixels_per_unit (r);
294 double r = real_canvas->get_pixels_per_unit ();
298 real_canvas->set_pixels_per_unit (r);
303 real_canvas->set_pixels_per_unit (1.0f);