diff --git a/bin/structure.pl b/bin/structure.pl index e755149..a435997 100644 --- a/bin/structure.pl +++ b/bin/structure.pl @@ -2,6 +2,11 @@ use ISO_10303_21::Grammar; use ISO_10303_21::Actions; +sub print-sorted-keys(%look-for) { + say "Looking for " ~ %look-for.keys.sort(-> $a, $b { substr($a, 1) <=> substr($b, 1) }).join(" "); + +} + for @*ARGS -> $file { say "Reading $file"; my $file-data = slurp($file); @@ -13,17 +18,43 @@ next; } - my @look-for; + my %look-for; for $step-data.entities.kv -> $index, $object { if $object ~~ ISO_10303_21::Record { if $object.keyword ~~ /SHAPE_REPRESENTATION$/ { - @look-for.push($index); + %look-for{$index} = 1; } } else { if any($object.list.map({ $_.keyword ~~ /SHAPE_REPRESENTATION$/ })) { - @look-for.push($index); + %look-for{$index} = 1; } } } + + print-sorted-keys(%look-for); + + my $previous-count = 0; + while $previous-count != +%look-for { + $previous-count = +%look-for; + for $step-data.entities.kv -> $index, $object { + if $object ~~ ISO_10303_21::Record { + for $object.entity_instances -> $reference { + if %look-for{$reference} { + %look-for{$index} = 1; + } + } + } else { + for @($object) -> $object { + for $object.entity_instances -> $reference { + if %look-for{$reference} { + %look-for{$index} = 1; + } + } + } + } + } + print-sorted-keys(%look-for); + } + } \ No newline at end of file