fix navigation issues and warnings

This commit is contained in:
vrd
2023-03-04 19:21:46 +02:00
parent cc7e4c07e6
commit cc7a689dc1
5 changed files with 53 additions and 32 deletions
+3
View File
@@ -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.: - 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 Adam0 is the first added Adam, Adam1 is the second added Adam
- Must end with a newline - Must end with a newline
QUESTIONS AND FEEDBACK:
venelin98@abv.bg
+11 -8
View File
@@ -4,6 +4,9 @@
#include "tree.hpp" #include "tree.hpp"
#include "utils.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::cerr;
/* using std::string_view; */ /* using std::string_view; */
using std::string; using std::string;
@@ -51,12 +54,12 @@ namespace /* internal */
exit(1); exit(1);
} }
void unexpected_end() /* void unexpected_end() */
{ /* { */
endwin(); /* endwin(); */
cerr << "Unexpected end of file" << std::endl; /* cerr << "Unexpected end of file" << std::endl; */
exit(1); /* exit(1); */
} /* } */
void proceedToNameEnd(char*& it_data) void proceedToNameEnd(char*& it_data)
{ {
@@ -131,7 +134,7 @@ namespace /* internal */
unexpected_char(*it_data); unexpected_char(*it_data);
} }
} }
unexpected_end(); UNEXPECTED_END();
} }
EventTime processDate(char*& it_data) /* todo validate */ EventTime processDate(char*& it_data) /* todo validate */
@@ -193,7 +196,7 @@ namespace /* internal */
name.push_back(*it_data); name.push_back(*it_data);
} }
} }
unexpected_end(); UNEXPECTED_END();
} }
vector<person_id> parseSpouses(char*& it_data) vector<person_id> parseSpouses(char*& it_data)
+36 -24
View File
@@ -129,6 +129,20 @@ person_id Tree::findId(const char* name, Sex s) const
return Nobody; 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 person_id Tree::findOldestAncestor(person_id id, Sex sex) const
{ {
for (const Relation& rel: relations[id]) 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 person_id Tree::findCommonAncestor(const unsigned first, const unsigned second) const
{ {
if(first == Nobody || second == Nobody)
return Nobody;
vector<U8> visited(people.size()); //if a member is visited twice he's a common ancestor vector<U8> visited(people.size()); //if a member is visited twice he's a common ancestor
commonAncestorRec(first, visited); 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) if (visited[i] == 2 && people[i].birth().year < oldestBday)
{ {
oldestBday = people[i].birth().year; /* oldestBday = people[i].birth().year; */ //todo figure it out
oldest = i; /* oldest = i; */
return i;
} }
} }
return oldest; return oldest;
@@ -436,8 +454,10 @@ void Tree::display()
displayHelp(); displayHelp();
draw(); draw();
break; break;
case ' ':
case '\n': case '\n':
focused_ = selected_; /* focused_ = selected_; */
focused_ = findRootAncestor(selected_);
draw(); draw();
break; break;
case KEY_LEFT: case KEY_LEFT:
@@ -600,10 +620,7 @@ void Tree::commonAncestorRec(person_id id, vector<U8> &visited) const
for (const Relation& rel: curRels) for (const Relation& rel: curRels)
{ {
if (rel.type == Child) if (rel.type == Child)
{
++visited[rel.id];
commonAncestorRec(rel.id, visited); 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) 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; prevX = childX;
childX = drawLineWithWives(children[j], drawY + lnHt, childX); childX = drawLineWithWives(children[j], drawY + lnHt, childX);
} }
@@ -759,25 +778,18 @@ void Tree::selectDown()
void Tree::selectUp() void Tree::selectUp()
{ {
person_id dad = Nobody, mom = Nobody; if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree
for(const Relation& rel: relations[selected_])
{ {
if (rel.type == Child) person_id dad = findParent(selected_, M);
{ person_id mom = findParent(selected_, F);
if (people[rel.id].sex == M)
dad = rel.id; if (findCommonAncestor(focused_, mom) != Nobody) //if selecteds mom is part of main tree
else selected_ = mom;
mom = rel.id; 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() void Tree::selectRight()
+1
View File
@@ -47,6 +47,7 @@ public:
person_id last(); person_id last();
std::vector<person_id> findId(const char* name) const; std::vector<person_id> findId(const char* name) const;
person_id findId(const char* name, Sex) const; person_id findId(const char* name, Sex) const;
person_id findRootAncestor(person_id) const;
person_id findOldestAncestor(person_id, Sex) const;// person_id findOldestAncestor(person_id, Sex) const;//
//oldest common ancestor ID, a person is considerd an ancestor of himself //oldest common ancestor ID, a person is considerd an ancestor of himself
+2
View File
@@ -14,6 +14,7 @@ findRelation - extend
Draw distinct regions of a tree Draw distinct regions of a tree
Draw spouses' relatives if main has none? Draw spouses' relatives if main has none?
Zooming Zooming
Visualization: Visualization:
@@ -22,6 +23,7 @@ Visualization:
- color on different consoles - color on different consoles
- screen resize - screen resize
- empty tree - empty tree
- half children and main tree
Compilation Compilation
- static and dynamic ncurses - static and dynamic ncurses