select siblings and initial tree scrolling
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#!/bin/dash
|
#!/bin/dash
|
||||||
|
|
||||||
|
mkdir -p bin/release
|
||||||
|
|
||||||
language='
|
language='
|
||||||
-std=gnu++20
|
-std=gnu++20
|
||||||
-fno-rtti
|
-fno-rtti
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
|
||||||
|
mkdir -p bin/debug
|
||||||
|
|
||||||
g++ -o bin/debug/famt -std=gnu++20 -g -O0 *.cpp -lncursesw
|
g++ -o bin/debug/famt -std=gnu++20 -g -O0 *.cpp -lncursesw
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ int main()
|
|||||||
/* (test1 + test2).display(); */
|
/* (test1 + test2).display(); */
|
||||||
test1 += test2;
|
test1 += test2;
|
||||||
test1.display();
|
test1.display();
|
||||||
test1.display();
|
/* test1.display(); */
|
||||||
|
|
||||||
|
|
||||||
/* test1.saveTree(); */
|
/* test1.saveTree(); */
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ Help
|
|||||||
|
|
||||||
addPerson add siblings (add relation improve)
|
addPerson add siblings (add relation improve)
|
||||||
|
|
||||||
|
findRelative
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
@@ -21,3 +25,6 @@ Compilation
|
|||||||
?
|
?
|
||||||
- same person can be present twice
|
- same person can be present twice
|
||||||
|
|
||||||
|
Backend
|
||||||
|
- move to SQLlite
|
||||||
|
- backup
|
||||||
|
|||||||
@@ -200,6 +200,17 @@ person_id Tree::findParent(person_id child, bool isParentMale) const
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<person_id> Tree::findChildren(person_id person) const
|
||||||
|
{
|
||||||
|
vector<person_id> children;
|
||||||
|
for(const Relation& rel: relations[person])
|
||||||
|
{
|
||||||
|
if (rel.type == Parent)
|
||||||
|
children.push_back(rel.id);
|
||||||
|
}
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
person_id Tree::findSpouse(person_id person) const
|
person_id Tree::findSpouse(person_id person) const
|
||||||
{
|
{
|
||||||
person_id spouse = Nobody;
|
person_id spouse = Nobody;
|
||||||
@@ -215,16 +226,16 @@ person_id Tree::findSpouse(person_id person) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* person_id Tree::findRelation(person_id first, person_id second) const */
|
RelType Tree::findRelation(person_id first, person_id second) const
|
||||||
/* { */
|
{
|
||||||
/* const auto& curRels = relations[first]; */
|
const auto& curRels = relations[first];
|
||||||
/* for(auto i =0; i<curRels.size(); ++i) */
|
for(const Relation& rel: curRels)
|
||||||
/* { */
|
{
|
||||||
/* if (curRels[i].id == second) */
|
if (rel.id == second)
|
||||||
/* { */
|
return rel.type;
|
||||||
|
}
|
||||||
/* } */
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
void Tree::saveTree() const
|
void Tree::saveTree() const
|
||||||
{
|
{
|
||||||
@@ -412,11 +423,21 @@ void Tree::display()
|
|||||||
focused_ = selected_;
|
focused_ = selected_;
|
||||||
draw();
|
draw();
|
||||||
break;
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
--offsetX_;
|
||||||
|
draw();
|
||||||
|
break;
|
||||||
|
case KEY_RIGHT:
|
||||||
|
++offsetX_;
|
||||||
|
draw();
|
||||||
|
break;
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
selectDown();
|
++offsetY_;
|
||||||
|
draw();
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
selectUp();
|
--offsetY_;
|
||||||
|
draw();
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
selectLeft();
|
selectLeft();
|
||||||
@@ -445,8 +466,8 @@ void Tree::draw() const
|
|||||||
erase(); //Clear the screen
|
erase(); //Clear the screen
|
||||||
wnoutrefresh(stdscr);
|
wnoutrefresh(stdscr);
|
||||||
|
|
||||||
I16 drawY = 0/* (LINES) / 2 */;
|
I16 drawY = offsetY_/* (LINES) / 2 */;
|
||||||
I16 drawX = 0/* (COLS) / 2 */;
|
I16 drawX = offsetX_/* (COLS) / 2 */;
|
||||||
drawLineWithWives(focused_, drawY, drawX);
|
drawLineWithWives(focused_, drawY, drawX);
|
||||||
|
|
||||||
doupdate();
|
doupdate();
|
||||||
@@ -660,14 +681,15 @@ void Tree::selectLeft() /* todo */
|
|||||||
{
|
{
|
||||||
if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree
|
if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree
|
||||||
{
|
{
|
||||||
|
selectLeftSibSpouse(selected_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
person_id spouse = findSpouse(selected_);
|
person_id spouse = findSpouse(selected_);
|
||||||
|
assert(spouse != Nobody);
|
||||||
selected_ = spouse;
|
selected_ = spouse;
|
||||||
draw();
|
|
||||||
}
|
}
|
||||||
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -710,19 +732,87 @@ void Tree::selectUp()
|
|||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tree::selectRight() /* todo */
|
void Tree::selectRight()
|
||||||
{
|
{
|
||||||
if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree
|
if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree
|
||||||
{
|
{
|
||||||
person_id spouse = findSpouse(selected_);
|
if (person_id spouse = findSpouse(selected_); spouse != Nobody)
|
||||||
if (spouse != Nobody)
|
{
|
||||||
selected_ = spouse;
|
selected_ = spouse;
|
||||||
else
|
|
||||||
;
|
|
||||||
draw();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
selectRightSib(selected_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //if spouse of someone in main tree
|
||||||
|
{
|
||||||
|
person_id spouse = findSpouse(selected_);
|
||||||
|
assert(spouse != Nobody);
|
||||||
|
selectRightSib(spouse);
|
||||||
|
}
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tree::selectLeftSibSpouse(person_id person) /* todo: return a value and split */
|
||||||
|
{
|
||||||
|
person_id leftSib = Nobody;
|
||||||
|
if(findRelation(person, focused_) == Child)
|
||||||
|
{
|
||||||
|
auto siblings = findChildren(focused_);
|
||||||
|
for(auto it = siblings.begin()+1; it < siblings.end(); ++it)
|
||||||
|
{
|
||||||
|
if(*it == person)
|
||||||
|
{
|
||||||
|
leftSib = *(it-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(person_id sel_par = findParent(person, true); sel_par != Nobody)
|
||||||
|
{
|
||||||
|
auto siblings = findChildren(sel_par);
|
||||||
|
for(auto it = siblings.begin()+1; it < siblings.end(); ++it)
|
||||||
|
{
|
||||||
|
if(*it == person)
|
||||||
|
{
|
||||||
|
leftSib = *(it-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(leftSib != Nobody)
|
||||||
|
{
|
||||||
|
person_id leftSibSpouse = findSpouse(leftSib);
|
||||||
|
selected_ = leftSibSpouse != Nobody ? leftSibSpouse : leftSib;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tree::selectRightSib(person_id person)
|
||||||
|
{
|
||||||
|
if(findRelation(person, focused_) == Child)
|
||||||
|
{
|
||||||
|
auto siblings = findChildren(focused_);
|
||||||
|
for(auto it = siblings.begin(); it < siblings.end()-1; ++it)
|
||||||
|
{
|
||||||
|
if(*it == person)
|
||||||
|
{
|
||||||
|
selected_ = *(it+1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(person_id sel_par = findParent(person, true); sel_par != Nobody)
|
||||||
|
{
|
||||||
|
auto siblings = findChildren(sel_par);
|
||||||
|
for(auto it = siblings.begin(); it < siblings.end()-1; ++it)
|
||||||
|
{
|
||||||
|
if(*it == person)
|
||||||
|
{
|
||||||
|
selected_ = *(it+1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,18 @@
|
|||||||
#include "person.h"
|
#include "person.h"
|
||||||
|
|
||||||
using person_id = U32;
|
using person_id = U32;
|
||||||
enum RelType: U8;
|
enum RelType : U8
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Parent,
|
||||||
|
Child,
|
||||||
|
Sibling,
|
||||||
|
HalfSibling,
|
||||||
|
Spouse,
|
||||||
|
ExSpouse,
|
||||||
|
|
||||||
|
Other
|
||||||
|
};
|
||||||
|
|
||||||
struct Relation
|
struct Relation
|
||||||
{
|
{
|
||||||
@@ -37,9 +48,10 @@ public:
|
|||||||
person_id findOldestAncestor(person_id id, bool sex = 0) const;//
|
person_id findOldestAncestor(person_id id, bool sex = 0) 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
|
||||||
person_id findCommonAncestor(person_id firstId, person_id secondId) const;
|
person_id findCommonAncestor(person_id firstId, person_id secondId) const;
|
||||||
person_id findRelation(person_id first, person_id second) const;
|
RelType findRelation(person_id first, person_id second) const;
|
||||||
person_id findParent(person_id child, bool isParentMale) const;
|
person_id findParent(person_id child, bool isParentMale) const;
|
||||||
person_id findSpouse(person_id person) const;
|
person_id findSpouse(person_id person) const;
|
||||||
|
std::vector<person_id> findChildren(person_id person) const;
|
||||||
|
|
||||||
void saveTree()const;//
|
void saveTree()const;//
|
||||||
bool loadTree();
|
bool loadTree();
|
||||||
@@ -74,6 +86,8 @@ private:
|
|||||||
void selectUp();
|
void selectUp();
|
||||||
void selectRight();
|
void selectRight();
|
||||||
|
|
||||||
|
void selectLeftSibSpouse(person_id person);
|
||||||
|
void selectRightSib(person_id person);
|
||||||
|
|
||||||
std::string treeName = "Unnamed";
|
std::string treeName = "Unnamed";
|
||||||
unsigned numPeople = 0;
|
unsigned numPeople = 0;
|
||||||
@@ -82,21 +96,10 @@ private:
|
|||||||
|
|
||||||
person_id focused_ = 0; /* the tree was draw based on this person */
|
person_id focused_ = 0; /* the tree was draw based on this person */
|
||||||
person_id selected_ = 0;
|
person_id selected_ = 0;
|
||||||
U16 offset_ = 0; /* offset of the tree */
|
I16 offsetX_ = 0; /* offset of the tree in relation to the screen*/
|
||||||
|
I16 offsetY_ = 0;
|
||||||
U8 dist_between_ = 1; /* distance between people */
|
U8 dist_between_ = 1; /* distance between people */
|
||||||
U8 spouse_dist_ = 0; /* distance between spouses */
|
U8 spouse_dist_ = 0; /* distance between spouses */
|
||||||
//Search, ect.
|
//Search, ect.
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RelType : U8
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
Parent,
|
|
||||||
Child,
|
|
||||||
Sibling,
|
|
||||||
HalfSibling,
|
|
||||||
Spouse,
|
|
||||||
ExSpouse,
|
|
||||||
|
|
||||||
Other
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user