#!/usr/bin/perl # Bryan Bishop # 2009-06-11 # kanzure@gmail.com http://heybryan.org/ # # gxml-add-dimensions.pl # usage: ./gxml-add-dimensions.pl input.gxml fennfile.po output.gxml # note: to generate the fennfile.po, you could either write it yourself or extract it via running repo-extract-dimensions.pl # # FIXME: does not do handling information since we're assuming that the incomping .gxml files already has this information # FIXME: only works with GraphSynth 2.0 GXML files. #### DEPRECATED NOTES # gxml-add-dimensions.pl # # usage: ./gxml-add-dimensions.pl input.gxml input.repo output.gxml # meaning: output.gxml is the same as input.gxml except using the dimensions from input.repo in a way that fits David Agu's ontology used in his grammar rules for product disassembly # the scheme here is to extract dimensioning information from the dot repo files # then add this dimensioning information to the nodes in the GXML file. # actually, this should be split into two separate scripts. # (1) repo-extract-dimensions.pl # (2) gxml-add-dimensions.pl ##################################################### use XML::Simple; use Data::Dumper; use List::Util qw[min max]; use Switch; print "\$#ARGV is: $#ARGV\n"; $numArgs = $#ARGV+1; if ($numArgs <= 1) { print "\n\nproper usage (you passed $numArgs arguments)\n\n"; print "./gxml-add-dimensions.pl input.gxml fennfile.po output.gxml\n\nnote that this version uses a fennfile.po for input\n\nonly compatible with GraphSynth 2.0 GXML files at the moment\n\n"; exit; } # just making sure the arguments are being correctly passed print "making sure all the arguments are present: \n"; foreach $myArg (@ARGV) { print "\t" . $myArg . "\n"; } print "\n\n\n"; # getting down to business $xml = new XML::Simple(ForceArray => 1); $inputGXML = $xml->XMLin($ARGV[0], forcearray => 1); # first, let's create a hashref of different nodes and their dimensions. # get the contents of the fennfile.po file. open(POF, "<$ARGV[1]"); @flines = ; close(POF); # split up the lines from the fennfile at the semicolon (";"). to the left is the part name. to the right are the parameters or dimensions. $thehash = {}; foreach my $line (@flines) { @parts = split(/\;/, $line); # replace spaces with underscores $parts[0] =~ s/ /_/g; $thehash{$parts[0]} = $parts[1]; print "artifact name: @parts[0]\n"; } # # # # # # # constraint_pin_2 # # # 0 ; material # 0 ; component weight (lbf) # 0 ; size (mm) - the length of the longest side of the smallest rectangular prism that can enclose the part # 0 ; thickness - the length of the shortest side of the smallest rectangular prism which encloses the part # 1 ; handling (given) # 1 ; handling (given) # 0 ; handling (given) # 0 ; handling (given) # 0 ; head type. # 0 ; thread length. # # 868.21059349074665 # 460.13146139119357 # 0 # # # # #foreach $page ((@{$inputGXML->{"GraphSynth:designGraph"}})) { #print "yay"; foreach $designgraph ((@{$inputGXML->{"GraphSynth:designGraph"}})) { #print "yay"; foreach $nodes ((@{$designgraph->{nodes}})) { foreach $node ((@{$nodes->{node}})) { #push @{ $artifact->{Parameters} }, { ParameterDimension => $fullexpression, ParameterUnits => 'inches', ParameterValue => $dimvalue }; #@{(@{$node->{localVariables}})}->{double}[0] = 5; #(@{$node->{localVariables}})->{double}[0] = 5; @doubles = []; foreach $localVariables ((@{$node->{localVariables}})) { @doubles = @{$localVariables->{double}}; print "this many doubles: $#doubles\n"; #@doubles[0] = 5; #foreach $double (@doubles) { # print "\t $double\n"; # $double = 394191; #} } # 0, 1, 2, 3, and 4 come from the fennfile.po $theline = $thehash{$node->{name}[0]}; if($theline eq "") { # ok, maybe remove the numbers at the end of it. # remove numbers from the end of a string $blah = $node->{name}[0]; $blah =~ s/\d//g; # remove all of the numbers from the string. # let's try again? print "trying again with thehash($blah) .. \n"; $theline = $thehash{$blah}; } print "the line is thehash($node->{name}[0]) ..... $theline\n"; @betterstuff = split(/ /, $theline); $thesuperhash = {M=>0,m=>0,W=>0,L=>0,T=>0,D=>0}; foreach my $thingy (@betterstuff) { chomp($thingy); $thesuperhash{substr($thingy,0,1)} = (substr($thingy,1)); } if(@doubles[0] eq "0") { @doubles[0] = $thesuperhash{M}; # well, actually. The material has to be one from David Agu's list. switch(@doubles[0]) { case "plastic" { @doubles[0] = "1" } case "aluminum" { @doubles[0] = "2" } case "copper" { @doubles[0] = "3" } case "steel" { @doubles[0] = "4" } case "iron" { @doubles[0] = "5" } else { if(!(@doubles[0] eq "0")) { @doubles[0] = "7"; } } # other non-metal (and not "no material") } } if(@doubles[1] eq "0") { @doubles[1] = $thesuperhash{m}; } if(@doubles[2] eq "0") { @doubles[2] = $thesuperhash{W}; if($thesuperhash{W} eq undef) { @doubles[2] = $thesuperhash{L}; } # also, H } if(@doubles[3] eq "0") { @doubles[3] = $thesuperhash{T}; # or D if($thesuperhash{T} eq undef) { @doubles[3] = $thesuperhash{D}; } } @doubles[2] = max(@doubles[2], $thesuperhash{W}, $thesuperhash{L}, $thesuperhash{H}); @doubles[3] = max(@doubles[3], $thesuperhash{T}, $thesuperhash{D}); if(@doubles[1] eq undef) { @doubles[1] = 0; print "Error! Component did not have a mass. ($node->{name}[0])\n" } # some components actually don't have a mass, so this is legit. (@{$node->{localVariables}->[0]->{double}})->[0] = @doubles[0]; # material (DA:M) (@{$node->{localVariables}->[0]->{double}})->[1] = @doubles[1]; # component weight (lbf) (DA:m) (@{$node->{localVariables}->[0]->{double}})->[2] = @doubles[2]; # size (mm) (DA: W) (@{$node->{localVariables}->[0]->{double}})->[3] = @doubles[3]; # thickness (mm) (DA: T) (@{$node->{localVariables}->[0]->{double}})->[4] = @doubles[4]; # handling (given) (@{$node->{localVariables}->[0]->{double}})->[5] = @doubles[5]; # handling (given) (@{$node->{localVariables}->[0]->{double}})->[6] = @doubles[6]; # handling (given) (@{$node->{localVariables}->[0]->{double}})->[7] = @doubles[7]; # handling (given) (@{$node->{localVariables}->[0]->{double}})->[8] = @doubles[8]; # head type (given) (@{$node->{localVariables}->[0]->{double}})->[9] = @doubles[9]; # thread length (given) } } } #} print "\n\n"; print Dumper($inputGXML->{"GraphSynth:designGraph"}); open(OUTFILE, ">$ARGV[2]"); print OUTFILE XMLout($inputGXML); close(OUTFILE);