]> git.llucax.com Git - z.facultad/75.52/treemulator.git/blob - viewer/view_btree.cpp
6a1fd165563557bd98717013c28f3d4c53bec63d
[z.facultad/75.52/treemulator.git] / viewer / view_btree.cpp
1
2 #include "view_btree.h"
3 #include "view_btree_data.h"
4 #include <sigc++/slot.h>
5
6 double ViewBTree::byte_to_pixels = 0;
7 double ViewBTree::node_width = 0;
8 double ViewBTree::node_height = 0;
9
10 ViewBTree::ViewBTree (Canvas::Group *parent, std::string filename, uint block_size, int tree_type, int type):Canvas::Group (*parent, 0, 0),
11         BTree (filename, block_size, tree_type, type)
12 {
13         /* Cada bytes lo hago de 5 units de ancho */
14         node_width = 4 * block_size;
15         node_height = 50;
16         byte_to_pixels  = node_width/block_size;
17
18         last_selected = NULL;
19 }
20
21 void ViewBTree::AddNode (uint num, uint padre)
22 {
23         uchar *node = ReadBlock (num);
24
25         BTreeNodeHeader node_h;
26         ReadNodoHeader (node, &node_h);
27
28         std::list<BTreeData *> keys = ReadKeys (node, node_h);
29
30         ViewNode *vnode = new ViewNode (this, num, padre, node_h, keys);
31         vnode->property_y () = 10;
32         vnode->property_x () = 10;
33
34         vnode->signal_selected().connect ( sigc::mem_fun (*this, &ViewBTree::on_item_selected) );
35         vnode->signal_activated().connect ( sigc::mem_fun (*this, &ViewBTree::on_item_activated) );
36
37         last_selected = vnode;
38 }
39
40 void ViewBTree::on_item_activated (BTreeData *data, uint num, ViewNode *vnode)
41 {
42         last_selected = NULL;
43
44         uint next = data->GetChild ();
45         delete vnode;
46
47         std::cout << next << std::endl;
48         AddNode (next, num);
49 }
50
51 void ViewBTree::on_item_selected (BTreeData *data, uint num, ViewNode *vnode)
52 {
53         BTreeNodeHeader node_h;
54         uchar *node;
55         
56         node = ReadBlock (num);
57         ReadNodoHeader (node, &node_h);
58         delete [] node;
59
60         if (last_selected)
61                 if (vnode != last_selected)
62                         last_selected->SetSelected (false);
63         last_selected = vnode;
64
65         m_signal_selected (data, node_h);
66 }
67
68 ViewBTree::type_signal_selected ViewBTree::signal_selected ()
69 {
70         return m_signal_selected;
71 }
72
73 void ViewBTree::Clear ()
74 {
75         if (last_selected)
76                 delete last_selected;
77 }
78
79 void ViewBTree::HighliteKey (Clave &k)
80 {
81         last_selected->HighliteKey (k);
82 }
83