diff --git a/readme.txt b/readme.txt index b65a056..c40a1b0 100644 --- a/readme.txt +++ b/readme.txt @@ -58,3 +58,6 @@ TFT FORMAT: - Number at the end of a name is used to disambiguate when multiple people have identical names e.g.: Adam0 is the first added Adam, Adam1 is the second added Adam - Must end with a newline + +QUESTIONS AND FEEDBACK: +venelin98@abv.bg diff --git a/src/parser.cpp b/src/parser.cpp index 966e770..7c64b13 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4,6 +4,9 @@ #include "tree.hpp" #include "utils.hpp" +/* macro rather then function to avoid warnings */ +#define UNEXPECTED_END() endwin(); cerr << "Unexpected end of file" << std::endl; exit(1) + using std::cerr; /* using std::string_view; */ using std::string; @@ -51,12 +54,12 @@ namespace /* internal */ exit(1); } - void unexpected_end() - { - endwin(); - cerr << "Unexpected end of file" << std::endl; - exit(1); - } + /* void unexpected_end() */ + /* { */ + /* endwin(); */ + /* cerr << "Unexpected end of file" << std::endl; */ + /* exit(1); */ + /* } */ void proceedToNameEnd(char*& it_data) { @@ -131,7 +134,7 @@ namespace /* internal */ unexpected_char(*it_data); } } - unexpected_end(); + UNEXPECTED_END(); } EventTime processDate(char*& it_data) /* todo validate */ @@ -193,7 +196,7 @@ namespace /* internal */ name.push_back(*it_data); } } - unexpected_end(); + UNEXPECTED_END(); } vector parseSpouses(char*& it_data) diff --git a/src/tree.cpp b/src/tree.cpp index 44b1d37..47bf044 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -129,6 +129,20 @@ person_id Tree::findId(const char* name, Sex s) const return Nobody; } +person_id Tree::findRootAncestor(person_id id) const +{ + for(person_id dad = findParent(id, M); dad != Nobody; dad = findParent(id, M)) + { + id = dad; + } + + for(person_id mom = findParent(id, F); mom != Nobody; mom = findParent(id, F)) + { + id = mom; + } + return id; +} + person_id Tree::findOldestAncestor(person_id id, Sex sex) const { for (const Relation& rel: relations[id]) @@ -141,6 +155,9 @@ person_id Tree::findOldestAncestor(person_id id, Sex sex) const person_id Tree::findCommonAncestor(const unsigned first, const unsigned second) const { + if(first == Nobody || second == Nobody) + return Nobody; + vector visited(people.size()); //if a member is visited twice he's a common ancestor commonAncestorRec(first, visited); @@ -152,8 +169,9 @@ person_id Tree::findCommonAncestor(const unsigned first, const unsigned second) { if (visited[i] == 2 && people[i].birth().year < oldestBday) { - oldestBday = people[i].birth().year; - oldest = i; + /* oldestBday = people[i].birth().year; */ //todo figure it out + /* oldest = i; */ + return i; } } return oldest; @@ -436,8 +454,10 @@ void Tree::display() displayHelp(); draw(); break; + case ' ': case '\n': - focused_ = selected_; + /* focused_ = selected_; */ + focused_ = findRootAncestor(selected_); draw(); break; case KEY_LEFT: @@ -600,10 +620,7 @@ void Tree::commonAncestorRec(person_id id, vector &visited) const for (const Relation& rel: curRels) { if (rel.type == Child) - { - ++visited[rel.id]; commonAncestorRec(rel.id, visited); - } } } @@ -715,7 +732,9 @@ I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) cons for(size_t j = 1; j < numKids; ++j) { - lnHt = linkToChild(drawY+1, prevX+1, childX+1, j < numKids-1) + 1; /* +1 because LTC starts lower then LTFB */ + /* +1 because LTC starts lower then LTFB */ + lnHt = linkToChild(drawY+1, prevX+1, childX+1, j < numKids-1) + 1; + prevX = childX; childX = drawLineWithWives(children[j], drawY + lnHt, childX); } @@ -759,25 +778,18 @@ void Tree::selectDown() void Tree::selectUp() { - person_id dad = Nobody, mom = Nobody; - - for(const Relation& rel: relations[selected_]) + if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree { - if (rel.type == Child) - { - if (people[rel.id].sex == M) - dad = rel.id; - else - mom = rel.id; - } + person_id dad = findParent(selected_, M); + person_id mom = findParent(selected_, F); + + if (findCommonAncestor(focused_, mom) != Nobody) //if selecteds mom is part of main tree + selected_ = mom; + else if (dad != Nobody) + selected_ = dad; + + draw(); } - - if (mom == focused_ || (mom != Nobody && dad == Nobody)) - selected_ = mom; - else if (dad != Nobody) - selected_ = dad; - - draw(); } void Tree::selectRight() diff --git a/src/tree.hpp b/src/tree.hpp index a02943a..e4d2c75 100644 --- a/src/tree.hpp +++ b/src/tree.hpp @@ -47,6 +47,7 @@ public: person_id last(); std::vector findId(const char* name) const; person_id findId(const char* name, Sex) const; + person_id findRootAncestor(person_id) const; person_id findOldestAncestor(person_id, Sex) const;// //oldest common ancestor ID, a person is considerd an ancestor of himself diff --git a/todo.txt b/todo.txt index 08aa276..dd4e6f5 100644 --- a/todo.txt +++ b/todo.txt @@ -14,6 +14,7 @@ findRelation - extend Draw distinct regions of a tree Draw spouses' relatives if main has none? + Zooming Visualization: @@ -22,6 +23,7 @@ Visualization: - color on different consoles - screen resize - empty tree +- half children and main tree Compilation - static and dynamic ncurses