Skip to content
Browse files

Output a graphviz of the top structure of the file we're looking at.

  • Loading branch information...
1 parent d65de09 commit 0972762824dcf7d1e706c94601c7d3e596ba0880 @colomon committed Oct 30, 2012
Showing with 54 additions and 19 deletions.
  1. +54 −19 bin/structure.pl
View
73 bin/structure.pl
@@ -3,25 +3,32 @@
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(" ");
-
+ $*ERR.say: "Looking for " ~ %look-for.keys.sort(-> $a, $b { substr($a, 1) <=> substr($b, 1) }).join(" ");
+}
+
+sub entity-references($object) {
+ if $object ~~ ISO_10303_21::Record {
+ $object.entity_instances;
+ } else {
+ @($object).map(*.entity_instances);
+ }
}
for @*ARGS -> $file {
- say "Reading $file";
+ $*ERR.say: "Reading $file";
my $file-data = slurp($file);
$file-data .= subst(/"/*" .*? "*/"/, " ", :global);
my $step-data = ISO_10303_21::Actions.new;
my $match = ISO_10303_21::LooseGrammar.parse($file-data, :rule<exchange_file>, :actions($step-data));
unless $match ~~ Match && $match {
- say "Something went wrong with the import.";
+ $*ERR.say: "Something went wrong with the import.";
next;
}
my %look-for;
for $step-data.entities.kv -> $index, $object {
if $object ~~ ISO_10303_21::Record {
- if $object.keyword ~~ /SHAPE_REPRESENTATION$/ {
+ if $object.keyword ~~ /SHAPE_REPRESENTATION$/ || $object.keyword ~~ /NEXT_ASSEMBLY_USAGE_OCCURRENCE/ {
%look-for{$index} = 1;
}
} else {
@@ -38,23 +45,51 @@
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;
- }
- }
+ for entity-references($object) -> $reference {
+ if %look-for{$reference} {
+ %look-for{$index} = 1;
}
}
}
print-sorted-keys(%look-for);
}
-
+
+ say "digraph finite_state_machine \{";
+ say " rankdir=LR";
+
+ my %tags;
+ my %types;
+ for %look-for.keys -> $index {
+ my $object = $step-data.entities{$index};
+ %tags{$index} = 1;
+ %types{$object.keyword} = 1 if $object ~~ ISO_10303_21::Record;
+ for entity-references($object) -> $entity {
+ %tags{$entity} = 1;
+ }
+ }
+
+ for %tags.keys -> $index {
+ my $object = $step-data.entities{$index};
+ if $object ~~ ISO_10303_21::Record {
+ given $object.keyword {
+ when "CONTEXT_DEPENDENT_SHAPE_REPRESENTATION" { say qq{ "$index" [shape=box,color=yellow,style=filled] } }
+ when "ADVANCED_BREP_SHAPE_REPRESENTATION" { say qq{ "$index" [shape=box,color=blue,style=filled] } }
+ when "SHAPE_REPRESENTATION" { say qq{ "$index" [shape=box] } }
+ when "NEXT_ASSEMBLY_USAGE_OCCURRENCE" { say qq{ "$index" [shape=diamond] } }
+ when "AXIS2_PLACEMENT_3D" { say qq{ "$index" [shape=invtriangle] } }
+ }
+ }
+ }
+
+ for %look-for.keys -> $index {
+ my $object = $step-data.entities{$index};
+ for entity-references($object) -> $reference {
+ say qq[ "$index" -> "$reference";];
+ }
+ }
+ say "\}";
+
+ for %types.keys -> $type {
+ $*ERR.say: "Found $type";
+ }
}

0 comments on commit 0972762

Please sign in to comment.
Something went wrong with that request. Please try again.