diff --git a/src/tft.cpp b/src/tft.cpp index d0f280e..c3de9a2 100644 --- a/src/tft.cpp +++ b/src/tft.cpp @@ -32,7 +32,9 @@ int main(int argc, char* argv[]) } init_ncurses(); - displayTree(tree); + + if( !tree.isEmpty() ) + displayTree(tree); return 0; } diff --git a/src/tree.cpp b/src/tree.cpp index e752986..f02b3a8 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -1,8 +1,10 @@ -#include"tree.hpp" -#include"utils.hpp" +#include #include #include -#include +#include + +#include"tree.hpp" +#include"utils.hpp" using std::vector; using std::string; @@ -37,28 +39,40 @@ Tree& Tree::operator+=(const Tree& other) people_.reserve(idCounter); for (person_id i = 0; i < other.people_.size(); ++i) /* add the personal data of II to I */ { - if (newId[i] >= initNum) /* isnt already in I */ + if (newId[i] >= initNum) /* isnt present in I */ people_.push_back(other.people_[i]); } relations_.reserve(idCounter); - for (person_id i = 0; i < other.people_.size(); ++i) //merge the relative data + for (person_id idIn2 = 0; idIn2 < other.people_.size(); ++idIn2) // merge the relational data { - if (newId[i] >= initNum) /* isnt already in I */ + if (newId[idIn2] >= initNum) /* isnt present in I */ { - relations_.push_back(other.relations_[i]); + relations_.push_back(other.relations_[idIn2]); for (Relation& rel: relations_.back()) rel.id = newId[rel.id]; } - else //if present in both trees + else // if present in both trees { - person_id idIn1 = newId[i]; - relations_[idIn1].reserve(relations_[idIn1].size() + other.relations_[i].size()); + person_id idIn1 = newId[idIn2]; + std::vector& relsIn1 = relations_[idIn1]; + relsIn1.reserve(relsIn1.size() + other.relations_[idIn2].size()); - for (Relation rel: other.relations_[i]) + for (Relation relIn2: other.relations_[idIn2]) { - if(newId[rel.id] >= initNum) /* not already in I */ - relations_[idIn1].push_back( {newId[rel.id], rel.type} ); + if(newId[relIn2.id] >= initNum) /* relative not present in I */ + relsIn1.push_back( {newId[relIn2.id], relIn2.type} ); + + else + { + bool foundIn1 = false; + for(Relation relIn1: relsIn1) + if(relIn1.id == newId[relIn2.id]) + foundIn1 = true; + + if( !foundIn1 ) // relative is present in I, but relation only in II + relsIn1.push_back( {newId[relIn2.id], relIn2.type} ); + } } } @@ -529,13 +543,13 @@ I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) cons } const size_t numKids = children.size(); U16 person_w = person.draw(drawY, drawX, - id == selected_, spouse!=Nobody, true, numKids!=0, zoom_==1); + id == selected_, spouse!=Nobody, true, numKids!=0, zoom_==1); U16 spouse_w = 0; if (spouse != Nobody) { U16 spouse_box = people_[spouse].draw(drawY, drawX + person_w + spouse_dist_, - spouse == selected_, false, false, false, zoom_==1); + spouse == selected_, false, false, false, zoom_==1); spouse_w = spouse_dist_ + spouse_box; } diff --git a/src/tree.hpp b/src/tree.hpp index 43ae7a7..62d1396 100644 --- a/src/tree.hpp +++ b/src/tree.hpp @@ -96,7 +96,7 @@ private: // 0 is the first person in the tree person_id focused_ = 0; /* the tree was draw based on this person */ - person_id selected_ = 0; + person_id selected_; U8 zoom_ = 0; // todo: figure out what to do with these constants diff --git a/src/ui.cpp b/src/ui.cpp index 6840604..7acd971 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -16,8 +16,6 @@ namespace void displayTree(Tree& t) { - // checck there are people - person_id selected = 0; // the currently selected selected U8 zoom = 0; // how much info to show for each selected diff --git a/todo.txt b/todo.txt index a1c233c..15d10ce 100644 --- a/todo.txt +++ b/todo.txt @@ -11,7 +11,7 @@ types - screenCoord... Visualization: - zooming - snap to selection/scroll with selection -- horizontal navigation between cousins - finish +- horizontal navigation between cousins - color on different consoles - screen resize - empty tree @@ -33,7 +33,8 @@ Compilation Refactoring - comment style /* - check return codes - setlocale, -- focused -> root ? +- focused -> root +- tree::relations_ to std::set test - no Adam