Debian Codegraph @

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

raw
1 =pod
2
3 =head1 NAME
4
5 Pedigree::PersonNode - a person in a pedigree
6
7 =head1 SYNOPSIS
8
9 use Pedigree::PersonNode;
10
11 $node = new Pedigree::PersonNode(I<%params>);
12
13 $Id = $node->MotherId();
14 $Id = $node->FatherId();
15
16 $isProband = $node->isProband();
17
18 $sex = $node->Sex();
19
20 $DoB = $node->DoB();
21
22 $DoD = $node->DoD();
23
24 $cond = $node->Condition();
25
26 $GenName = $node->GetGenName();
27
28 $node->SetGenName(I<$name>);
29
30 $node->DrawNode(I<$xidst>, I<$ydist>, I<$belowtextfont>, I<$abovetextfont>,
31 I<@fieldsfornode>);
32
33 $node->PrintLegend(I<$land>, I<@fields>);
34
35 =head1 DESCRIPTION
36
37 This package contains data about a person.
38
39 =cut
40
41 ####################################################################
42 # Define the package #
43 ####################################################################
44
45 package Pedigree::PersonNode;
46 use Pedigree;
47 use strict;
48 our @ISA=('Pedigree::Node');
49
50 ####################################################################
51 # new #
52 ####################################################################
53
54 =pod
55
56 =over 4
57
58 =item B<new>(I<%params>);
59
60 Construct a new node from the given parameters.
61
62 =cut
63
64 sub new {
65 my ($class,%params)=@_;
66 my $self=$class->SUPER::new(%params);
67
68 if (!ref($self)) {
69 return 0;
70 }
71
72 #
73 # Only Person Nodes are numbered in pedigrees
74 #
75
76 $self->{'Numbered'}=1;
77
78 #
79 # Now Twins...
80 #
81
82 if (exists $self->{'Twins'}) {
83 my $Id=$self->{'Id'};
84 my $string = $self->{'Twins'};
85 $string =~ s/^\s*//;
86 $string =~ s/\s*$//;
87 my @twinIds=($Id, split (/[\s,;]+/, $string));
88 if ($main::DEBUG) {
89 print STDERR "Found twins: ", join(', ',@twinIds), "\n";
90 }
91 my $found=0;
92 for (my $i=0; $i<scalar @{$self->{'twin_sets'}}; $i++) {
93 if (exists $self->{'twin_sets'}->[$i]->{'KidIds'}->{$Id}) {
94 $found=1;
95 foreach my $kidId (@twinIds) {
96 $self->{'twin_sets'}->[$i]->{'KidIds'}->{$kidId}=1;
97 }
98 if ($main::DEBUG) {
99 print STDERR "Added to twin set number $i\n";
100 }
101 last; # twin_set
102 }
103 }
104 if (!$found) { # Add twin set
105 my $set;
106 $set->{'Type'} = $self->{'Type'};
107 foreach my $kidId (@twinIds) {
108 $set->{'KidIds'}->{$kidId}=1;
109 }
110 push @{$self->{'twin_sets'}}, $set;
111 if ($main::DEBUG) {
112 print STDERR "Started a new twin set number ",
113 scalar(@{$self->{'twin_sets'}})-1, "\n";
114 }
115 }
116 }
117
118 return $self;
119
120 }
121
122
123 ####################################################################
124 # MotherId #
125 ####################################################################
126
127 =pod
128
129 =item B<MotherId>();
130
131 Return Mother Id.
132
133 =cut
134
135 sub MotherId {
136 my $self=shift;
137 return $self->{'Mother'};
138 }
139
140 ####################################################################
141 # FatherId #
142 ####################################################################
143
144 =pod
145
146 =item B<FatherId>();
147
148 Return Father Id.
149
150 =cut
151
152 sub FatherId {
153 my $self=shift;
154 return $self->{'Father'};
155 }
156
157
158 ####################################################################
159 # isProband #
160 ####################################################################
161
162 =pod
163
164 =item B<isProband>();
165
166 Return 1 if the pesron is a Proband and zero otherwise
167
168 =cut
169
170 sub isProband {
171 my $self=shift;
172 if ($self->{Proband} == 1) {
173 return 1;
174 } else {
175 return 0;
176 }
177 }
178
179 ####################################################################
180 # Sex #
181 ####################################################################
182
183 =pod
184
185 =item B<Sex>();
186
187 Get the sex of the node
188
189 =cut
190
191 sub Sex {
192 my $self = shift;
193 return $self->{'Sex'};
194 }
195
196 ####################################################################
197 # DoB #
198 ####################################################################
199
200 =pod
201
202 =item B<DoB>();
203
204 Get the DoB of the node
205
206 =cut
207
208 sub DoB {
209 my $self = shift;
210 return $self->{'DoB'};
211 }
212
213 ####################################################################
214 # DoB #
215 ####################################################################
216
217 =pod
218
219 =item B<DoD>();
220
221 Get the DoB of the node
222
223 =cut
224
225 sub DoD {
226 my $self = shift;
227 return $self->{'DoD'};
228 }
229
230 ####################################################################
231 # Condition #
232 ####################################################################
233
234 =pod
235
236 =item B<Condition>();
237
238 Returns node conditon.
239
240 =cut
241
242 sub Condition {
243 my $self=shift;
244 return $self->{'Condition'};
245 }
246
247
248 ####################################################################
249 # GetGenName #
250 ####################################################################
251
252 =pod
253
254 =item B<GetGenName>();
255
256 Find the generation name for the node
257
258 =cut
259
260 sub GetGenName {
261 my $self = shift;
262 return $self->{'GenName'};
263 }
264
265
266 ####################################################################
267 # SetGenName #
268 ####################################################################
269
270 =pod
271
272 =item B<SetGenName>(I<$name>);
273
274 Set the generation name of the node
275
276 =cut
277
278 sub SetGenName {
279 my ($self, $name) = @_;
280 $self->{'GenName'} = $name;
281 return 0;
282 }
283
284
285 ####################################################################
286 # DrawNode #
287 ####################################################################
288
289 =pod
290
291 =item B<DrawNode>(I<$xdist>, I<$ydist>, I<$belowtextfont>, I<$abovetextfont>,
292 I<@fieldsfornode>);
293
294 Output the command to draw this node. The parameters are
295 distances between the nodes (in cm) and fields for abovetext.
296
297 =cut
298
299 sub DrawNode {
300 my $self=shift;
301 my ($xdist, $ydist, $belowtextfont, $abovetextfont, @fieldsfornode) = @_;
302 my $result = '\rput('.($xdist*$self->GetAbsX()).", ".
303 ($ydist*$self->GetAbsY()).'){\pstPerson[';
304 my @opts=($self->Sex(), $self->Condition(),
305 'belowtext={'."$belowtextfont ".$self->GetGenName().'}');
306 if (length($self->DoD())>0) {
307 push @opts, 'deceased';
308 }
309 if ($self->isProband()) {
310 push @opts, 'proband';
311 }
312 if (scalar @fieldsfornode) {
313 my @abovetext;
314 foreach my $field (@fieldsfornode) {
315 push @abovetext, $self->{$field};
316 }
317 push @opts,'abovetext={'."$abovetextfont ".join('; ',@abovetext).'}';
318 }
319 $result .= join(', ',@opts);
320 $result .= ']{'.$self->Id()."}}\n";
321 return $result;
322 }
323
324 ####################################################################
325 # PrintLegend #
326 ####################################################################
327
328 =pod
329
330 =item B<PrintLegend>(I<$lang>, I<@fields>);
331
332 Print the legend for the given node, including I<@fields> in the given
333 language I<$lang>.
334
335 =cut
336
337 sub PrintLegend {
338 my ($self, $lang, @fields) = @_;
339 my $result = '\item['.$self->GetGenName().'] ';
340 my @desc;
341 foreach my $field (@fields) {
342 if (exists $self->{$field}) {
343 my $res = $lang->PrintField($field, $self->{$field});
344 if (length($res)>0) {
345 push @desc, $res;
346 }
347 }
348 }
349 $result .= join ("; ",@desc);
350 $result .= ".\n";
351 #
352 # We print only the nodes, for which there is an information
353 #
354 if (scalar @desc) {
355 return $result;
356 }
357 return;
358 }
359
360
361
362 ####################################################################
363 # THE END #
364 ####################################################################
365
366
367 =pod
368
369 =back
370
371 =head1 ENVIRONMENT
372
373 The calling program should define B<$main::DEBUG> and set it to 0
374 or 1.
375
376
377 =head1 SEE ALSO
378
379 pedigree(1), Pedigree(3)
380
381 =head1 AUTHOR
382
383 Boris Veytsman, Leila Akhmadeeva, 2006, 2007
384
385
386
387 =cut
388
389 1;