fix navigation issues and warnings
This commit is contained in:
+11
-8
@@ -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)
|
||||
|
||||
+36
-24
@@ -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,10 +620,7 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user