| 21 |
**/ |
**/ |
| 22 |
#include "BakeryGateway/ViewChildToFamilyLink.hh" |
#include "BakeryGateway/ViewChildToFamilyLink.hh" |
| 23 |
#include "OneFamilyLinkHandler.hh" |
#include "OneFamilyLinkHandler.hh" |
| 24 |
|
#include "FamilyMemberHandler.hh" |
| 25 |
#include "OneChildToFamilyLink.hh" |
#include "OneChildToFamilyLink.hh" |
| 26 |
#include "OneChildToFamilyLinkHandler.hh" |
#include "OneChildToFamilyLinkHandler.hh" |
| 27 |
#include "MMIMenuLinkEditor.hh" |
#include "MMIMenuLinkEditor.hh" |
| 30 |
#include "GEDCOMParser/Predicates/IsMale.hh" |
#include "GEDCOMParser/Predicates/IsMale.hh" |
| 31 |
#include "GEDCOMParser/Predicates/HasChild.hh" |
#include "GEDCOMParser/Predicates/HasChild.hh" |
| 32 |
#include "GEDCOMParser/Predicates/NameEqualsTo.hh" |
#include "GEDCOMParser/Predicates/NameEqualsTo.hh" |
| 33 |
|
#include "GEDCOMHelper/IndividualRecordHelper.hh" |
| 34 |
|
|
| 35 |
BakeryGateway::ViewChildToFamilyLink::ViewChildToFamilyLink(MMIChildToFamilyLink * mmi) : |
BakeryGateway::ViewChildToFamilyLink::ViewChildToFamilyLink(MMIChildToFamilyLink * mmi) : |
| 36 |
_mmi_childtofamilylink(mmi) |
_mmi_childtofamilylink(mmi), |
| 37 |
|
_father_predicate(0), |
| 38 |
|
_mother_predicate(0) |
| 39 |
{ |
{ |
| 40 |
_mmi_childtofamilylink->FamilyAdded().connect(slot(this, &ViewChildToFamilyLink::family_added)); |
_mmi_childtofamilylink->FamilyAdded().connect(slot(this, &ViewChildToFamilyLink::family_added)); |
| 41 |
_mmi_childtofamilylink->FamilyDeleted().connect(slot(this, &ViewChildToFamilyLink::family_deleted)); |
_mmi_childtofamilylink->FamilyDeleted().connect(slot(this, &ViewChildToFamilyLink::family_deleted)); |
| 52 |
{ |
{ |
| 53 |
if ((! _during_load) && (_parent_entity != 0)) |
if ((! _during_load) && (_parent_entity != 0)) |
| 54 |
{ |
{ |
| 55 |
get_document()->AddParents(_parent_entity); |
GEDCOMHelper::IndividualRecordHelper individual_record_helper(_parent_entity, get_document()); |
| 56 |
|
individual_record_helper.setChildInFamily(); |
| 57 |
} |
} |
| 58 |
save_to_document(); |
save_to_document(); |
| 59 |
load_from_document(); //FIXME |
load_from_document(); //FIXME |
| 64 |
{ |
{ |
| 65 |
GEDCOMParser::ChildToFamilyLinks_t family_links = _parent_entity->getChildToFamilyLinks(); |
GEDCOMParser::ChildToFamilyLinks_t family_links = _parent_entity->getChildToFamilyLinks(); |
| 66 |
SmartPtr < GEDCOMParser::ChildToFamilyLink > family_link_to_delete = family_links[family_index]; |
SmartPtr < GEDCOMParser::ChildToFamilyLink > family_link_to_delete = family_links[family_index]; |
| 67 |
get_document()->RemoveChildToFamilyLink(_parent_entity, family_link_to_delete.getPtr()); |
GEDCOMHelper::IndividualRecordHelper individual_record_helper(_parent_entity, get_document()); |
| 68 |
|
GEDCOMParser::FamilyRecords_t families = get_document()->getFamilyRecords(); |
| 69 |
|
SmartPtr < GEDCOMParser::FamilyRecord > family = families[family_link_to_delete->getFamcXref()]; |
| 70 |
|
individual_record_helper.RemoveChildFromFamily(family.getPtr()); |
| 71 |
save_to_document(); |
save_to_document(); |
| 72 |
return; |
return; |
| 73 |
} |
} |
| 74 |
|
|
| 75 |
BakeryGateway::ViewChildToFamilyLink::~ViewChildToFamilyLink(void) |
BakeryGateway::ViewChildToFamilyLink::~ViewChildToFamilyLink(void) |
| 76 |
{ |
{ |
| 77 |
|
delete _father_predicate; _father_predicate = 0; |
| 78 |
|
delete _mother_predicate; _mother_predicate = 0; |
| 79 |
return; |
return; |
| 80 |
} |
} |
| 81 |
|
|
| 91 |
GEDCOMParser::FamilyRecords_t families = get_document()->getFamilyRecords(); |
GEDCOMParser::FamilyRecords_t families = get_document()->getFamilyRecords(); |
| 92 |
for (GEDCOMParser::ChildToFamilyLinks_t::const_iterator iter = links.begin(); iter != links.end(); iter++) |
for (GEDCOMParser::ChildToFamilyLinks_t::const_iterator iter = links.begin(); iter != links.end(); iter++) |
| 93 |
{ |
{ |
| 94 |
std::string famc_id = (*iter)->getRawFamcXref(); |
std::string famc_id = (*iter)->getFamcXref(); |
| 95 |
GEDCOMParser::FamilyRecord * familyrecord = 0; |
GEDCOMParser::FamilyRecord * familyrecord = 0; |
| 96 |
OneFamilyLinkHandler * familylink_handler = 0; |
OneFamilyLinkHandler * familylink_handler = 0; |
| 97 |
if (ManageFamilyLinkHandler(famc_id, families, individuals, &familyrecord, &familylink_handler)) |
if (ManageFamilyLinkHandler(famc_id, families, individuals, &familyrecord, &familylink_handler)) |
| 98 |
{ |
{ |
| 99 |
OneFamilyLink * new_family_link = _mmi_childtofamilylink->addFamilyLink(*familylink_handler); |
OneFamilyLink * new_family_link = _mmi_childtofamilylink->addFamilyLink(*familylink_handler); |
|
new_family_link->LinkEdited().connect(SigC::slot(this, &ViewChildToFamilyLink::family_edited)); |
|
| 100 |
ManageFamilyLinkNote(new_family_link, (*iter).getPtr()); |
ManageFamilyLinkNote(new_family_link, (*iter).getPtr()); |
| 101 |
ManageFamilyRecordNote(new_family_link, familyrecord); |
ManageFamilyRecordNote(new_family_link, familyrecord); |
| 102 |
} |
} |
| 119 |
{ |
{ |
| 120 |
|
|
| 121 |
bool res; |
bool res; |
|
std::string * father_id = 0; |
|
|
std::string * mother_id = 0; |
|
| 122 |
GEDCOMParser::FamilyRecords_t::const_iterator family_iter = families.find(family_record_id); |
GEDCOMParser::FamilyRecords_t::const_iterator family_iter = families.find(family_record_id); |
| 123 |
if (family_iter != families.end()) |
if (family_iter != families.end()) |
| 124 |
{ |
{ |
| 125 |
res = true; |
res = true; |
| 126 |
*familyrecord = (*family_iter).second.getPtr(); |
*familyrecord = (*family_iter).second.getPtr(); |
| 127 |
father_id = new std::string((*family_iter).second->getHusb()); |
std::string const &father_id = (*family_iter).second->getHusb(); |
| 128 |
mother_id = new std::string((*family_iter).second->getWife()); |
std::string father = get_name_individual(individuals, father_id); |
| 129 |
std::string father = get_name_individual(individuals, *father_id); |
FamilyMemberHandler::NavigationSlotHandler_t * navigation_slot_father = getNavigationSlotHandler(&father_id); |
| 130 |
std::string mother = get_name_individual(individuals, *mother_id); |
BakeryGateway::IndividualRecordsPredicates_t const * const father_predicates = FatherPredicates(); |
| 131 |
std::string * individu_id = new std::string(_parent_entity->getId()); |
FamilyMemberHandler::PopdownLinkEditionSlotHandler_t * popdownlinkedition_slot_father = getPopdownLinkEditionSlotHandler(*familyrecord, father_predicates); |
| 132 |
OneFamilyLinkHandler::NavigationSlotHandler_t * navigation_slot_father = getNavigationSlotHandler(father_id); |
|
| 133 |
OneFamilyLinkHandler::NavigationSlotHandler_t * navigation_slot_mother = getNavigationSlotHandler(mother_id); |
std::string const &mother_id = (*family_iter).second->getWife(); |
| 134 |
|
std::string mother = get_name_individual(individuals, mother_id); |
| 135 |
GEDCOMParser::LineageLinkageGedcom const * const lineage = get_document(); |
FamilyMemberHandler::NavigationSlotHandler_t * navigation_slot_mother = getNavigationSlotHandler(&mother_id); |
| 136 |
std::string const name = _parent_entity->getPersonalNames()[0]->getGivn(); |
BakeryGateway::IndividualRecordsPredicates_t const * const mother_predicates = MotherPredicates(); |
| 137 |
SmartPtr < GEDCOMParser::Predicates::PredicateIndividualRecords > * father_predicate = new SmartPtr < GEDCOMParser::Predicates::PredicateIndividualRecords > (GEDCOMParser::Predicates::getGenericPredicateIndividualRecords( std::compose2(std::logical_and<bool>(), |
FamilyMemberHandler::PopdownLinkEditionSlotHandler_t * popdownlinkedition_slot_mother = getPopdownLinkEditionSlotHandler(*familyrecord, mother_predicates); |
| 138 |
std::compose1( |
FamilyMemberHandler * father_handler = new FamilyMemberHandler(father, navigation_slot_father, popdownlinkedition_slot_father); |
| 139 |
std::logical_not<bool>(), |
FamilyMemberHandler * mother_handler = new FamilyMemberHandler(mother, navigation_slot_mother, popdownlinkedition_slot_mother); |
| 140 |
std::bind1st(GEDCOMParser::Predicates::HasChild(),lineage)), |
OneFamilyLinkHandler * familylink_handler_tmp = new OneChildToFamilyLinkHandler(*father_handler, *mother_handler); |
|
std::compose2(std::logical_and<bool>(), |
|
|
GEDCOMParser::Predicates::IsMale(), |
|
|
std::bind1st(GEDCOMParser::Predicates::NameEqualsTo(), name) |
|
|
|
|
|
) |
|
|
) |
|
|
); |
|
|
|
|
|
OneFamilyLinkHandler::PopdownLinkEditionSlotHandler_t * popdownlinkedition_slot_father = getPopdownLinkEditionSlotHandler(individu_id, father_predicate); |
|
|
OneFamilyLinkHandler::PopdownLinkEditionSlotHandler_t * popdownlinkedition_slot_mother = getPopdownLinkEditionSlotHandler(individu_id, father_predicate); |
|
|
|
|
|
OneFamilyLinkHandler * familylink_handler_tmp = new OneChildToFamilyLinkHandler(father, mother, navigation_slot_father, navigation_slot_mother, popdownlinkedition_slot_father, popdownlinkedition_slot_mother); |
|
| 141 |
*familylink_handler = familylink_handler_tmp; |
*familylink_handler = familylink_handler_tmp; |
| 142 |
} |
} |
| 143 |
else |
else |
| 147 |
return res; |
return res; |
| 148 |
} |
} |
| 149 |
|
|
| 150 |
|
BakeryGateway::IndividualRecordsPredicates_t const * BakeryGateway::ViewChildToFamilyLink::MotherPredicates(void) |
| 151 |
|
{ |
| 152 |
|
if (_mother_predicate == 0) |
| 153 |
|
{ |
| 154 |
|
GEDCOMParser::LineageLinkageGedcom const * const lineage = get_document(); |
| 155 |
|
_mother_predicate = new BakeryGateway::IndividualRecordsPredicates_t(); |
| 156 |
|
SmartPtr < GEDCOMParser::Predicates::PredicateIndividualRecords > predicate(GEDCOMParser::Predicates::getGenericPredicateIndividualRecords(std::compose2(std::logical_and<bool>(),std::compose1(std::logical_not<bool>(),std::bind1st(GEDCOMParser::Predicates::HasChild(),lineage)),std::compose1(std::logical_not<bool>(),GEDCOMParser::Predicates::IsMale())))); |
| 157 |
|
_mother_predicate->push_back(predicate); |
| 158 |
|
predicate = SmartPtr < GEDCOMParser::Predicates::PredicateIndividualRecords >(GEDCOMParser::Predicates::getGenericPredicateIndividualRecords(std::compose1(std::logical_not < bool > (), GEDCOMParser::Predicates::IsMale()))); |
| 159 |
|
_mother_predicate->push_back(predicate); |
| 160 |
|
} |
| 161 |
|
return _mother_predicate; |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
BakeryGateway::IndividualRecordsPredicates_t const * BakeryGateway::ViewChildToFamilyLink::FatherPredicates(void) |
| 165 |
|
{ |
| 166 |
|
if (_father_predicate == 0) |
| 167 |
|
{ |
| 168 |
|
GEDCOMParser::LineageLinkageGedcom const * const lineage = get_document(); |
| 169 |
|
std::string const name = _parent_entity->getPersonalNames()[0]->getSurn(); |
| 170 |
|
_father_predicate = new BakeryGateway::IndividualRecordsPredicates_t(); |
| 171 |
|
SmartPtr < GEDCOMParser::Predicates::PredicateIndividualRecords > predicate(GEDCOMParser::Predicates::getGenericPredicateIndividualRecords(std::compose2(std::logical_and<bool>(), std::compose1(std::logical_not<bool>(), std::bind1st(GEDCOMParser::Predicates::HasChild(),lineage)), std::compose2(std::logical_and<bool>(), GEDCOMParser::Predicates::IsMale(), std::bind1st(GEDCOMParser::Predicates::NameEqualsTo(), name))))); |
| 172 |
|
_father_predicate->push_back(predicate); |
| 173 |
|
predicate = SmartPtr < GEDCOMParser::Predicates::PredicateIndividualRecords >(GEDCOMParser::Predicates::getGenericPredicateIndividualRecords(std::compose2(std::logical_and<bool>(),GEDCOMParser::Predicates::IsMale(),std::bind1st(GEDCOMParser::Predicates::NameEqualsTo(), name)))); |
| 174 |
|
_father_predicate->push_back(predicate); |
| 175 |
|
predicate = SmartPtr < GEDCOMParser::Predicates::PredicateIndividualRecords >(new GEDCOMParser::Predicates::IsMale()); |
| 176 |
|
_father_predicate->push_back(predicate); |
| 177 |
|
} |
| 178 |
|
return _father_predicate; |
| 179 |
|
} |
| 180 |
|
|
| 181 |
MMIFamilyLink * BakeryGateway::ViewChildToFamilyLink::getMMIFamilyLink(void) const |
MMIFamilyLink * BakeryGateway::ViewChildToFamilyLink::getMMIFamilyLink(void) const |
| 182 |
{ |
{ |
| 183 |
return _mmi_childtofamilylink; |
return _mmi_childtofamilylink; |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
void BakeryGateway::ViewChildToFamilyLink::family_edited(std::string id) |
void BakeryGateway::ViewChildToFamilyLink::family_edited(std::string * id, GEDCOMParser::FamilyRecord * const record) |
| 187 |
{ |
{ |
| 188 |
std::cerr << "Family edited : individu id = " << id << std::endl; |
std::cerr << "FAMILY RECORD EDITED : " << record->getId() << std::endl; |
| 189 |
|
std::cerr << "INDIVIDU SELECTED : " << *id << std::endl; |
| 190 |
|
if (*id != "-1") |
| 191 |
|
{ |
| 192 |
|
GEDCOMParser::LineageLinkageGedcom * lineage = get_document(); |
| 193 |
|
GEDCOMParser::IndividualRecords_t individus = lineage->getIndividualRecords(); |
| 194 |
|
SmartPtr < GEDCOMParser::IndividualRecord > individu = individus[*id]; |
| 195 |
|
if (! individu.Null()) |
| 196 |
|
{ |
| 197 |
|
GEDCOMHelper::IndividualRecordHelper helper(individu.getPtr(), lineage); |
| 198 |
|
helper.setSpouseInFamily(record); |
| 199 |
|
} |
| 200 |
|
save_to_document(); |
| 201 |
|
load_from_document(); |
| 202 |
|
} |
| 203 |
return; |
return; |
| 204 |
} |
} |
| 205 |
|
|