From b4a23678596cdf0fd5993ec6650422a86d2012be Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Fri, 23 Sep 2005 04:11:52 +0000 Subject: [PATCH] Inicio visor de arbol. --- viewer/Makefile | 13 +++++++++++ viewer/main.cpp | 29 +++++++++++++++++++++++ viewer/view_btree.cpp | 47 ++++++++++++++++++++++++++++++++++++++ viewer/view_btree.h | 22 ++++++++++++++++++ viewer/view_btree_data.cpp | 34 +++++++++++++++++++++++++++ viewer/view_btree_data.h | 31 +++++++++++++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 viewer/Makefile create mode 100644 viewer/main.cpp create mode 100644 viewer/view_btree.cpp create mode 100644 viewer/view_btree.h create mode 100644 viewer/view_btree_data.cpp create mode 100644 viewer/view_btree_data.h diff --git a/viewer/Makefile b/viewer/Makefile new file mode 100644 index 0000000..b085b15 --- /dev/null +++ b/viewer/Makefile @@ -0,0 +1,13 @@ +TARGET=viewer +CXXFLAGS=-Wall -g `pkg-config gtkmm-2.4 libgnomecanvasmm-2.6 --cflags` -I../src +OBJECTS=main.o view_btree.o view_btree_data.o + +all: $(TARGET) + +$(TARGET): $(OBJECTS) + g++ -o $(TARGET) $(OBJECTS) ../src/libbtree.a `pkg-config gtkmm-2.4 libgnomecanvasmm-2.6 --libs` + +clean: + rm -rf *.o $(TARGET) + + diff --git a/viewer/main.cpp b/viewer/main.cpp new file mode 100644 index 0000000..6f3f2db --- /dev/null +++ b/viewer/main.cpp @@ -0,0 +1,29 @@ + +#include + +#include +#include + +#include "view_btree.h" + +using namespace Gnome::Canvas; + +int main(int argc, char *argv[]) +{ + Gtk::Main kit(argc, argv); + + Gnome::Canvas::init (); + + Gtk::Window window; + Gnome::Canvas::Canvas canvas; + + ViewBTree canvas_grp (canvas.root (), "test.idx"); + + window.add (canvas); + window.set_size_request (800, 100); + window.show_all (); + + Gtk::Main::run(window); + + return 0; +} diff --git a/viewer/view_btree.cpp b/viewer/view_btree.cpp new file mode 100644 index 0000000..582b776 --- /dev/null +++ b/viewer/view_btree.cpp @@ -0,0 +1,47 @@ + +#include "view_btree.h" +#include "view_btree_data.h" + +ViewBTree::ViewBTree (Canvas::Group *parent, std::string filename):Canvas::Group (*parent, 0, 0), + BTree (filename, 64) +{ + /* TODO : hace que el arbol se abra de un archivo ya creado o que se + * cree afuera + */ + for (int i=0; i<=64; i++) { + ClaveFija c(i); + + AddKey (c); + } + + /* Muestro la raiz */ + uchar *node = ReadBlock (0); + BTreeNodeHeader node_h; + ReadNodoHeader (node, &node_h); + std::list keys = ReadKeys (node, node_h); + + Canvas::Rect *rect = new Canvas::Rect (*this, 0, 0, NODE_WIDTH, NODE_HEIGHT); + rect->property_fill_color() = "gray"; + + int byte_to_pixels = NODE_WIDTH/64; // TODO : 64 == BlockSize + + /* Ahora pongo el lugar que opcupa el header */ + double header_w = byte_to_pixels * sizeof (BTreeNodeHeader); + double x = 0; + + Canvas::Rect *view_header = new Canvas::Rect (*this, x, 0, x+header_w, NODE_HEIGHT); + x += header_w; + + std::list::iterator it = keys.begin (); + while (it != keys.end ()) { + BTreeData *data = (*it); + double w = byte_to_pixels * data->Size (); + + ViewBTreeData::Create (data, this, x, 0, w+x, NODE_HEIGHT); + + x += w; + it++; + } + +} + diff --git a/viewer/view_btree.h b/viewer/view_btree.h new file mode 100644 index 0000000..918a377 --- /dev/null +++ b/viewer/view_btree.h @@ -0,0 +1,22 @@ + +#ifndef _VIEW_BTREE_H_ +#define _VIEW_BTREE_H_ + +#include +#include + +#include "btree.h" + +#define NODE_WIDTH 500 +#define NODE_HEIGHT 50 + +using namespace Gnome; + +class ViewBTree : public Canvas::Group, public BTree { + public: + ViewBTree (Canvas::Group *parent, std::string filename); + +}; + +#endif + diff --git a/viewer/view_btree_data.cpp b/viewer/view_btree_data.cpp new file mode 100644 index 0000000..403da55 --- /dev/null +++ b/viewer/view_btree_data.cpp @@ -0,0 +1,34 @@ + +#include "view_btree_data.h" + +ViewBTreeData::ViewBTreeData (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2): + Canvas::Rect (*parent, x1, y1, x2, y2) +{ + this->data = data; + property_fill_color () = "red"; + property_outline_color () = "black"; +} + + +ViewBTreeData* +ViewBTreeData::Create (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2) +{ + if (dynamic_cast(data)) + return new ViewBTreeChildData (data, parent, x1, y1, x2, y2); + + return new ViewBTreeData (data, parent, x1, y1, x2, y2); +} + +ViewBTreeChildData::ViewBTreeChildData (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2): + ViewBTreeData (data, parent, x1, y1, x2, y2) +{ + property_fill_color () = "yellow"; + property_outline_color () = "black"; + + double w = x2 - x1; + double h = y2 - y1; + + std::string s = *data; + Canvas::Text *text = new Canvas::Text (*parent, x1 + w/2, y1 + h/2, s); +} + diff --git a/viewer/view_btree_data.h b/viewer/view_btree_data.h new file mode 100644 index 0000000..4fb9510 --- /dev/null +++ b/viewer/view_btree_data.h @@ -0,0 +1,31 @@ + +#ifndef _VIEW_BTREE_DATA_H_ +#define _VIEW_BTREE_DATA_H_ + +#include +#include + +#include "btree.h" +#include "btree_data.h" + +using namespace Gnome; + +class ViewBTreeData :public Canvas::Rect { + public: + ViewBTreeData (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2); + + static ViewBTreeData *Create (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2); + + protected: + BTreeData *data; +}; + +class ViewBTreeChildData :public ViewBTreeData { + public: + ViewBTreeChildData (BTreeData *data, Canvas::Group *parent, double x1, double y1, double x2, double y2); + + protected: + BTreeData *data; +}; +#endif + -- 2.43.0