relation change
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <iostream>
|
||||
#include<fstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include"tree.h"
|
||||
#include"person.h"
|
||||
#include"help.h"
|
||||
@@ -169,7 +171,7 @@ unsigned Tree::findOldestAncestor(const unsigned &id, const bool &isMale)const
|
||||
{
|
||||
for (unsigned i = 0; i < people[id].numRel_; ++i)
|
||||
{
|
||||
if (relations[id][i] == Son && people[ relatives[id][i] ].isMale_ == isMale)
|
||||
if (relations[id][i] == Child && people[ relatives[id][i] ].isMale_ == isMale)
|
||||
return findOldestAncestor(relatives[id][i], isMale);
|
||||
}
|
||||
return id;
|
||||
@@ -273,8 +275,8 @@ void Tree::addPerson(const char* name, bool isMale, unsigned father, unsigned mo
|
||||
Array<Relation> newRelation;
|
||||
relations.push(newRelation);
|
||||
++numPeople;
|
||||
addRelation(father, Father, numPeople - 1);
|
||||
addRelation(mother, Mother, numPeople - 1);
|
||||
addRelation(father, Parent, numPeople - 1);
|
||||
addRelation(mother, Parent, numPeople - 1);
|
||||
}
|
||||
|
||||
bool Tree::addRelation(const char* firstName, const Relation type, const char* secondName)
|
||||
@@ -306,61 +308,20 @@ bool Tree::addRelation(const unsigned firstId, const Relation type, const unsign
|
||||
|
||||
if (!opposite)
|
||||
{
|
||||
if (people[secondId].isMale_)
|
||||
switch (type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Father:
|
||||
case Mother:
|
||||
addRelation(secondId, Son, firstId, 1);
|
||||
break;
|
||||
case Son:
|
||||
case Daughter:
|
||||
addRelation(secondId, Father, firstId, 1);
|
||||
break;
|
||||
case Brother:
|
||||
case Sister:
|
||||
addRelation(secondId, Brother, firstId, 1);
|
||||
break;
|
||||
case HalfBrother:
|
||||
case HalfSister:
|
||||
addRelation(secondId, HalfBrother, firstId, 1);
|
||||
break;
|
||||
case Wife:
|
||||
addRelation(secondId, Husband, firstId, 1);
|
||||
break;
|
||||
case ExWife:
|
||||
addRelation(secondId, ExHusband, firstId, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Father:
|
||||
case Mother:
|
||||
addRelation(secondId, Daughter, firstId, 1);
|
||||
break;
|
||||
case Son:
|
||||
case Daughter:
|
||||
addRelation(secondId, Mother, firstId, 1);
|
||||
break;
|
||||
case Brother:
|
||||
case Sister:
|
||||
addRelation(secondId, Sister, firstId, 1);
|
||||
break;
|
||||
case HalfBrother:
|
||||
case HalfSister:
|
||||
addRelation(secondId, HalfSister, firstId, 1);
|
||||
break;
|
||||
case Husband:
|
||||
addRelation(secondId, Wife, firstId, 1);
|
||||
break;
|
||||
case ExHusband:
|
||||
addRelation(secondId, ExWife, firstId, 1);
|
||||
break;
|
||||
}
|
||||
case Parent:
|
||||
addRelation(secondId, Child, firstId, 1);
|
||||
break;
|
||||
case Child:
|
||||
addRelation(secondId, Parent, firstId, 1);
|
||||
break;
|
||||
case Sibling:
|
||||
case HalfSibling:
|
||||
case Spouse:
|
||||
case ExSpouse:
|
||||
addRelation(secondId, type, firstId, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@@ -450,14 +411,25 @@ void Tree::draw() const
|
||||
/* 1, drawX, */
|
||||
/* 1 +fh-1, drawX + fw-1); */
|
||||
|
||||
const U32 numPpl = people.gNum();
|
||||
std::vector<bool> drawn(numPpl, false);
|
||||
|
||||
people[0].draw(0, 0);
|
||||
U16 drawY = 0/* (LINES) / 2 */;
|
||||
U16 drawX = 0/* (COLS) / 2 */;
|
||||
drawLineRec(0, drawY, drawX);
|
||||
/* people[0].draw(drawY, drawY); */
|
||||
/* for(U32 i=0; i<relations[0].gNum(); ++i) */
|
||||
/* { */
|
||||
/* if(relations[0][i] == Relation::Son) */
|
||||
/* { */
|
||||
/* drawX = drawLineRec(i, drawY, drawX) + 2; */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* pnoutrefresh(mother, 0, 0, 1, d */
|
||||
|
||||
doupdate();
|
||||
getch();
|
||||
|
||||
}
|
||||
|
||||
void Tree::print() const
|
||||
@@ -470,53 +442,53 @@ void Tree::print() const
|
||||
|
||||
void Tree::printRel(const unsigned id)const
|
||||
{
|
||||
cout << people[id].name_;
|
||||
if (people[id].numRel_ == 0)
|
||||
cout << " has no known relatives";
|
||||
else
|
||||
{
|
||||
unsigned relId;
|
||||
cout << "'s relatives:\n";
|
||||
for (unsigned i = 0; i < people[id].numRel_; ++i)
|
||||
{
|
||||
relId = relatives[id][i];
|
||||
cout << people[relId].name_ << " - ";
|
||||
/* cout << people[id].name_; */
|
||||
/* if (people[id].numRel_ == 0) */
|
||||
/* cout << " has no known relatives"; */
|
||||
/* else */
|
||||
/* { */
|
||||
/* unsigned relId; */
|
||||
/* cout << "'s relatives:\n"; */
|
||||
/* for (unsigned i = 0; i < people[id].numRel_; ++i) */
|
||||
/* { */
|
||||
/* relId = relatives[id][i]; */
|
||||
/* cout << people[relId].name_ << " - "; */
|
||||
|
||||
switch (relations[id][i])
|
||||
{
|
||||
case Father:
|
||||
case Mother:
|
||||
cout << (people[relId].isMale_ ? "son" : "daughter");
|
||||
break;
|
||||
case Son:
|
||||
case Daughter:
|
||||
cout << (people[relId].isMale_ ? "father" : "mother");
|
||||
break;
|
||||
case Brother:
|
||||
case Sister:
|
||||
cout << (people[relId].isMale_ ? "brother" : "sister");
|
||||
break;
|
||||
case HalfBrother:
|
||||
case HalfSister:
|
||||
cout << (people[relId].isMale_ ? "half brother" : "half sister");
|
||||
break;
|
||||
case Husband:
|
||||
cout << "wife";
|
||||
break;
|
||||
case Wife:
|
||||
cout << "husband";
|
||||
break;
|
||||
case ExHusband:
|
||||
cout << "ex-wife\n";
|
||||
break;
|
||||
case ExWife:
|
||||
cout << "ex-husband\n";
|
||||
break;
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
/* switch (relations[id][i]) */
|
||||
/* { */
|
||||
/* case Father: */
|
||||
/* case Mother: */
|
||||
/* cout << (people[relId].isMale_ ? "son" : "daughter"); */
|
||||
/* break; */
|
||||
/* case Son: */
|
||||
/* case Daughter: */
|
||||
/* cout << (people[relId].isMale_ ? "father" : "mother"); */
|
||||
/* break; */
|
||||
/* case Brother: */
|
||||
/* case Sister: */
|
||||
/* cout << (people[relId].isMale_ ? "brother" : "sister"); */
|
||||
/* break; */
|
||||
/* case HalfBrother: */
|
||||
/* case HalfSister: */
|
||||
/* cout << (people[relId].isMale_ ? "half brother" : "half sister"); */
|
||||
/* break; */
|
||||
/* case Husband: */
|
||||
/* cout << "wife"; */
|
||||
/* break; */
|
||||
/* case Wife: */
|
||||
/* cout << "husband"; */
|
||||
/* break; */
|
||||
/* case ExHusband: */
|
||||
/* cout << "ex-wife\n"; */
|
||||
/* break; */
|
||||
/* case ExWife: */
|
||||
/* cout << "ex-husband\n"; */
|
||||
/* break; */
|
||||
/* } */
|
||||
/* cout << '\n'; */
|
||||
/* } */
|
||||
/* cout << '\n'; */
|
||||
/* } */
|
||||
}
|
||||
|
||||
void Tree::printMember(const unsigned id)const
|
||||
@@ -532,21 +504,80 @@ void Tree::printOldestAncestors(const unsigned id)const
|
||||
|
||||
|
||||
|
||||
unsigned Tree::gNumP()const
|
||||
{
|
||||
return numPeople;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Tree::commonAncestorRec(const unsigned &id, const Array<char> &visited)const
|
||||
{
|
||||
for (unsigned i = 0; i < people[id].numRel_; ++i)
|
||||
{
|
||||
if (relations[id][i] == Son)
|
||||
if (relations[id][i] == Child)
|
||||
{
|
||||
++visited[relatives[id][i]];
|
||||
commonAncestorRec(relatives[id][i], visited);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void linkToFirstBorn(I16 startY, I16 startX)
|
||||
{
|
||||
if(startY >= -2 && startX >= 0)
|
||||
{
|
||||
WINDOW* win = newwin(3, 1, startY, startX); /* TODO: pad */
|
||||
|
||||
waddch(win, ACS_VLINE);
|
||||
mvwaddch(win, 1, 0, ACS_LTEE);
|
||||
mvwaddch(win, 2, 0, ACS_VLINE);
|
||||
|
||||
wnoutrefresh(win);
|
||||
delwin(win);
|
||||
}
|
||||
}
|
||||
|
||||
static void linkToChild(I16 startY, I16 startX, I16 endX)
|
||||
{
|
||||
assert(endX >= startX);
|
||||
|
||||
if(startY >= -1 && endX >= 0)
|
||||
{
|
||||
const I16 len = endX - startX;
|
||||
WINDOW* win = newwin(2, len, startY, startX);
|
||||
|
||||
for(U16 i = 0; i < len-1; ++i)
|
||||
waddch(win, ACS_HLINE);
|
||||
/* whline(win, '_', len-1); */
|
||||
waddch(win, ACS_TTEE);
|
||||
|
||||
mvwaddch(win, 1, len-1, ACS_VLINE);
|
||||
|
||||
wnoutrefresh(win);
|
||||
delwin(win);
|
||||
}
|
||||
}
|
||||
|
||||
I16 Tree::drawLineRec(person_id id, I16 drawY, I16 drawX) const
|
||||
{
|
||||
people[id].draw(drawY, drawX);
|
||||
std::vector<person_id> sons;
|
||||
for(U32 i=0; i<relations[id].gNum(); ++i)
|
||||
{
|
||||
if(relations[id][i] == Relation::Parent)
|
||||
sons.push_back(relatives[id][i]);
|
||||
}
|
||||
|
||||
if(!sons.empty())
|
||||
{
|
||||
auto prevX = drawX;
|
||||
drawY += BOX_HEIGHT;
|
||||
|
||||
linkToFirstBorn(drawY, drawX);
|
||||
drawX = drawLineRec(sons[0], drawY + 3, drawX) + 1;
|
||||
|
||||
for(size_t j = 1; j < sons.size(); ++j)
|
||||
{
|
||||
linkToChild(drawY + 1, prevX+1, drawX+1);
|
||||
prevX = drawX;
|
||||
drawX = drawLineRec(sons[j], drawY + 3, drawX) + 1;
|
||||
}
|
||||
return drawX;
|
||||
}
|
||||
|
||||
return drawX + people[id].boxWidth();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user