Debian Codegraph @

texmf-dist/scripts/pedigree-perl/Pedigree/MarriageNode.pm

raw
1 =pod
2
3 =head1 NAME
4
5 Pedigree::MarriageNode - a marriage in a pedigree
6
7 =head1 SYNOPSIS
8
9 use Pedigree::MarriageNode;
10
11 $node = new Pedigree::MarriageNode(I<%params>);
12
13 $FSpouse = $node->FSpouse();
14
15 $MSpouse = $node->MSpouse();
16
17 $consang = $self->isConsanguinic();
18
19 $area = $node->SetArea();
20
21 $node->CalcAbsCoord(I<$x>, I<$y>);
22
23 $node->DrawNode(I<$xidst>, I<$ydist>, I<$belowtextfont>, I<$abovetextfont>,
24 I<@fieldsfornode>);
25
26 $node->DrawConnections();
27
28
29 =head1 DESCRIPTION
30
31 This package contains data about a marriage.
32
33
34 =cut
35
36
37
38 ####################################################################
39 # Define the package #
40 ####################################################################
41
42 package Pedigree::MarriageNode;
43 use Pedigree;
44 use strict;
45 our @ISA=('Pedigree::Node');
46
47
48 ####################################################################
49 # new #
50 ####################################################################
51
52 =pod
53
54 =over 4
55
56 =item B<new>(I<%params>);
57
58 Construct a new node from the given parameters.
59
60 =cut
61
62 sub new {
63 my ($class,%params)=@_;
64 my $self=$class->SUPER::new(%params);
65 if (!ref($self)) { # Bad node
66 return 0;
67 }
68
69 bless ($self,$class);
70
71 #
72 # Normally marriage nodes are not consanguinic
73 #
74 if (!exists($self->{'Consanguinic'})) {
75 $self->{'Consanguinic'} = 0;
76 }
77
78 # After we constructed the node, we want to move the kids
79 # from the parent nodes to the marriage node
80
81 my $selfId = $self->{'Id'};
82 if (exists($self->{'FSpouse'}) && exists($self->{'MSpouse'})) {
83 my $fspouse = $self->{'FSpouse'};
84 my $fspouseId = $fspouse->Id();
85 my $mspouse = $self->{'MSpouse'};
86 my $mspouseId = $mspouse->Id();
87
88
89 foreach my $kidId (keys %{$self->{'kids_by_parent_id'}->{$fspouseId}}) {
90 if ($main::DEBUG) {
91 print STDERR "Checking kid $kidId for $selfId\n";
92 }
93 if (exists ($self->{'kids_by_parent_id'}->{$mspouseId}->{$kidId})) {
94 if ($main::DEBUG) {
95 print STDERR
96 "Moving $kidId from $fspouseId and $mspouseId to ".
97 "$selfId\n";
98 }
99 delete $self->{'kids_by_parent_id'}->{$mspouseId}->{$kidId};
100 delete $self->{'kids_by_parent_id'}->{$fspouseId}->{$kidId};
101 $self->{'kids_by_parent_id'}->{$selfId}->{$kidId}=1;
102 }
103 }
104 }
105
106 return $self;
107 }
108
109
110 ####################################################################
111 # FSpouse #
112 ####################################################################
113
114 =pod
115
116 =item B<FSpouse>();
117
118 Get female spouse of a node.
119
120 =cut
121
122 sub FSpouse {
123 my $self = shift;
124 return $self->{'FSpouse'};
125 }
126
127
128 ####################################################################
129 # MSpouse #
130 ####################################################################
131
132 =pod
133
134 =item B<MSpouse>();
135
136 Get female spouse of a node.
137
138 =cut
139
140 sub MSpouse {
141 my $self = shift;
142 return $self->{'MSpouse'};
143 }
144
145 ####################################################################
146 # isConsanguinic #
147 ####################################################################
148
149 =pod
150
151 =item B<isConsanguinic>();
152
153 Check whether the node is consanguinic
154
155 =cut
156
157 sub isConsanguinic {
158 my $self = shift;
159 return $self->{'Consanguinic'};
160 }
161
162
163 ####################################################################
164 # SetArea #
165 ####################################################################
166
167 =pod
168
169 =item B<SetArea>();
170
171 Calculate relative coordinates for all nodes, that are descendants of
172 the given node I<and> the spouses that form the marriage. We create a
173 Pedigree::Area(3) around the given node and recursively apply the
174 function to all descendants. The subroutine
175 returns the reference to the created area.
176
177 =cut
178
179 sub SetArea {
180 my $self = shift;
181 my $area = $self->SUPER::SetArea();
182
183 #
184 # Female is to the right, male is to the left unless we have
185 # Sort Order set for anybody. If it is set, the order
186 # is OPPOSITE to the SortOrder
187 #
188 my ($left,$right) = ($self->MSpouse(), $self->FSpouse());
189 if ($left->SortOrder() <=> $right->SortOrder()) {
190 ($left,$right) =
191 sort {$a->SortOrder() <=> $b->SortOrder()} ($left,$right);
192 }
193 my ($rightRoot,$gen) = @{$right->FindRoot(0,-1)};
194 $rightRoot->SetRelY($gen);
195 my $rightArea=$rightRoot->SetArea();
196 $area->AddRight($rightArea);
197
198 my ($leftRoot,$gen) = @{$left->FindRoot(0,1)};
199 $leftRoot->SetRelY($gen);
200 my $leftArea=$leftRoot->SetArea();
201 $area->AddLeft($leftArea);
202
203 $self->{'Area'}=$area;
204
205 if ($main::DEBUG) {
206 print STDERR "Setting area for marriage node ",$self->Id(),"\n";
207 for (my $y=$area->GetYmin(); $y<=$area->GetYmax(); $y++) {
208 print STDERR "\t$y: ", $area->GetXmin($y), ", ",
209 $area->GetXmax($y), "\n";
210 }
211 }
212
213
214 return $area;
215 }
216
217
218 ####################################################################
219 # CalcAbsCoor #
220 ####################################################################
221
222 =pod
223
224 =item B<CalcAbsCoor>(I<$x>, $<y>);
225
226 Set the absolute coordinates of the given node, if the absolute
227 coordinates of the parent node are (I<$x>, I<$y>), and recursively
228 do this for all descendants of this node, and right and left clumps.
229
230 =cut
231
232 sub CalcAbsCoor {
233 my $self=shift;
234 my ($x,$y) = @_;
235 $self->SUPER::CalcAbsCoor($x, $y);
236 $x += $self->GetRelX();
237 $y += $self->GetRelY();
238
239 my ($FRoot,undef) = @{$self->FSpouse()->FindRoot(0)};
240 $FRoot->CalcAbsCoor($x, $y);
241
242 my ($MRoot,undef) = @{$self->MSpouse()->FindRoot(0)};
243 $MRoot->CalcAbsCoor($x, $y);
244
245 return 0;
246 }
247
248
249 ####################################################################
250 # DrawNode #
251 ####################################################################
252
253 =pod
254
255 =item B<DrawNode>(I<$xdist>, I<$ydist>, I<$belowtextfont>, I<$abovetextfont>,
256 I<@fieldsfornode>);
257
258 Output the command to draw this node. The parameters are
259 distances between the nodes (in cm).
260
261 =cut
262
263 sub DrawNode {
264 my $self=shift;
265 my ($xdist, $ydist, $belowtextfont, $abovetextfont, @fieldsfornode) = @_;
266 my $result = '\rput('.($xdist*$self->GetAbsX()).", ".
267 ($ydist*$self->GetAbsY()).'){\pnode{'.
268 $self->Id()."}}\n";
269 return $result;
270 }
271
272 ####################################################################
273 # DrawConnections #
274 ####################################################################
275
276 =pod
277
278 =item B<DrawConnections>();
279
280 Draw the connections from the given node to its descendants and
281 the spouses
282
283 =cut
284
285 sub DrawConnections {
286 my $self = shift;
287 my $xdist = shift;
288 my $ydist = shift;
289 my $result = $self->SUPER::DrawConnections($xdist, $ydist);
290 my $Id=$self->Id();
291 my $style="";
292 if ($self->isConsanguinic()) {
293 $style='doubleline=true, ';
294 }
295 foreach my $spouse ($self->FSpouse(), $self->MSpouse()) {
296 if (!ref($spouse)) {
297 next;
298 }
299 my $sId=$spouse->Id();
300 # Check whether spouse nodes are adjacent to the marriage node.
301 # We do this check only for non-consanguinic unions
302 if (!($self->isConsanguinic()) &&
303 (abs($self->GetIndexX() - $spouse->GetIndexX()) > 1)) {
304 my ($nodeA,$nodeB) = sort
305 {$a->GetIndexX() <=> $b->GetIndexX()} ($spouse, $self);
306 my $IdA=$nodeA->Id();
307 my $IdB=$nodeB->Id();
308 $result .=
309 "\\ncloop[$style angleA=0, angleB=180, loopsize=".
310 0.4*$ydist . ', arm=' . 0.4*$xdist .
311 ']{'.$IdA.'}{'.$IdB.'}'."\n";
312 } else {
313 $result .= "\\ncline[$style]{".$Id.'}{'.$sId.'}'."\n";
314 }
315 }
316 return $result;
317 }
318
319
320
321
322 ####################################################################
323 # THE END #
324 ####################################################################
325
326 =pod
327
328 =back
329
330 =head1 ENVIRONMENT
331
332 The calling program should define B<$main::DEBUG> and set it to 0
333 or 1.
334
335 =head1 SEE ALSO
336
337 pedigree(1), Pedigree(3)
338
339 =head1 AUTHOR
340
341 Boris Veytsman, Leila Akhmadeeva, 2006, 2007
342
343
344
345 =cut
346
347 1;