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.:
Adam0 is the first added Adam, Adam1 is the second added Adam
- Must end with a newline
QUESTIONS AND FEEDBACK:
venelin98@abv.bg
+11 -8
View File
@@ -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<person_id> parseSpouses(char*& it_data)
+31 -19
View File
@@ -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<U8> 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,11 +620,8 @@ void Tree::commonAncestorRec(person_id id, vector<U8> &visited) const
for (const Relation& rel: curRels)
{
if (rel.type == Child)
{
++visited[rel.id];
commonAncestorRec(rel.id, visited);
}
}
}
static U8 linkToFirstBorn(I16 startY, I16 startX, bool moreSiblings)
@@ -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 (mom == focused_ || (mom != Nobody && dad == Nobody))
if (findCommonAncestor(focused_, mom) != Nobody) //if selecteds mom is part of main tree
selected_ = mom;
else if (dad != Nobody)
selected_ = dad;
draw();
}
}
void Tree::selectRight()
+1
View File
@@ -47,6 +47,7 @@ public:
person_id last();
std::vector<person_id> 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
+2
View File
@@ -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