summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkanzure <kanzure@gmail.com>2009-10-22 13:59:43 -0500
committerkanzure <kanzure@gmail.com>2009-10-22 13:59:43 -0500
commit5f74ae324e331f9c1519884a5507a77ae8f1150e (patch)
tree570a874899fe98360d6d87b39ec08f7c94db54a5
parent633a0f7355f600bff2e5b128e8d6fad104580556 (diff)
downloadskdb-5f74ae324e331f9c1519884a5507a77ae8f1150e.tar.gz
skdb-5f74ae324e331f9c1519884a5507a77ae8f1150e.zip
dot repo file utilities and tools
-rw-r--r--core/interface.py2
-rw-r--r--import_tools/del_repo/repo-add-dimensions.pl199
-rw-r--r--import_tools/del_repo/repo-extract-dimensions.pl234
-rw-r--r--import_tools/del_repo/repo-print-artifacts.pl29
-rw-r--r--import_tools/del_repo/repo-remove-attachments.pl27
-rw-r--r--import_tools/del_repo/repo2gxml.pl125
6 files changed, 615 insertions, 1 deletions
diff --git a/core/interface.py b/core/interface.py
index 3670b1f..1a746dd 100644
--- a/core/interface.py
+++ b/core/interface.py
@@ -143,7 +143,7 @@ class Connection:
i1 = self.interface1.part.interfaces.index(self.interface1)
i2 = self.interface2.part.interfaces.index(self.interface2)
- print "connecting %s's %s to %s's %s brick1[%s] to brick2[%s])" %(self.interface1.part.name, self.interface1.name, self.interface2.part.name, self.interface2.name, i1, i2)
+ print "connecting %s's %s to %s's %s (brick1[%s] to brick2[%s])" %(self.interface1.part.name, self.interface1.name, self.interface2.part.name, self.interface2.name, i1, i2)
self.interface1.connected.append(self) #.append(self.interface2)?
self.interface2.connected.append(self)
return
diff --git a/import_tools/del_repo/repo-add-dimensions.pl b/import_tools/del_repo/repo-add-dimensions.pl
new file mode 100644
index 0000000..a5473d2
--- /dev/null
+++ b/import_tools/del_repo/repo-add-dimensions.pl
@@ -0,0 +1,199 @@
+#!/usr/bin/perl
+# Bryan Bishop
+# 2009-06-10
+# kanzure@gmail.com http://heybryan.org/
+#
+# repo2gxml.pl
+# this converts from the dot repo (.repo) XML file format found in repository.designengineeringlab.org to the GraphSynth 1.9 GXML format.
+#
+# because of the faults with the repository data structure or data representation scheme, there is no way for us to recover the functional links, arcs or edges, so for this reason, the output of this program (the gxml) does not include any arcs connecting different components together.
+
+# this has been modified to fit fenn's needs on 2009-06-10.
+
+use XML::Simple;
+use Data::Dumper;
+
+
+print "\$#ARGV is: $#ARGV\n";
+$numArgs = $#ARGV+1;
+if ($numArgs <= 1) {
+ print "\n\nproper usage (you passed $numArgs arguments)\n\n";
+ print "./repo-add-dimensions.pl example.repo example.out.repo fennfile.fennpo\n\n";
+ exit;
+}
+
+foreach $myArg (@ARGV) {
+ print $myArg . "\n";
+}
+
+$xml = new XML::Simple(ForceArray => 1); #KeepRoot => 1); # poor attempt to get things working better. FIXME
+$data = $xml->XMLin($ARGV[0], forcearray => 1); # set ARGV0 to something like: "/home/bryan/lab/summer2009/something.repo"
+# used to be $data->{System} (and in one other place in this file)
+# where's my repository?
+foreach $system ((@{$data->>{System}})) { # take the <System> element from the XML file (it's in a hashref variable)
+ foreach $artifact ((@{$system->{Artifact}})) {
+ $name = $artifact->{ArtifactName};
+ print "$name\n";
+ }
+}
+
+# DEBUG
+# the following will print the entire hashref. good for quick debugging.
+# print "XML => " . Dumper($data);
+
+# get the input information from fennfile.fenpo
+$fennfile = $ARGV[2];
+open(FENNFILE, "<$ARGV[2]");
+@lines = <FENNFILE>;
+close(FENNFILE);
+
+$thehash = {};
+foreach my $line (@lines) {
+ @parts = split(/\;/, $line);
+ $thehash{$parts[0]} = $parts[1];
+}
+
+# <Parameters ParameterDimension="length" ParameterUnits="inches" ParameterValue="16.9" />
+# http://www.perlmonks.org/?node_id=253934
+
+foreach $system ((@{$data->{System}})) { # take the <System> element from the XML file (it's in a hashref variable)
+ foreach $artifact ((@{$system->{Artifact}})) {
+ $name = $artifact->{ArtifactName};
+ #print "currently at name: $name\n";
+ if($thehash{$name}) {
+ #print "it is in the hash.\n";
+ $thevalues = $thehash{$name};
+ print "dimensions: $thevalues\n";
+ # Now please parse the dimensions.
+ @dimensions = split(/ /, $thevalues);
+ foreach my $dimension (@dimensions) {
+ $type = substr($dimension,0,1);
+ print "dimension of type $type\n";
+ $dimvalue = substr($dimension,1);
+ chomp($dimvalue);
+ print "the value of this dimension is $dimvalue\n";
+ $fullexpression = "height";
+ if($type eq "H") { $fullexpression = "height"; }
+ if($type eq "L") { $fullexpression = "length"; }
+ if($type eq "T") { $fullexpression = "thickness"; }
+ if($type eq "W") { $fullexpression = "width"; }
+ if($type eq "D") { $fullexpression = "diameter"; }
+ #push(, [{'ParameterUnits' = "supergrams", 'ParameterDimension' = 'supermass', 'ParameterValue' = '1444'}]);
+push @{ $artifact->{Parameters} }, { ParameterDimension => $fullexpression, ParameterUnits => 'inches', ParameterValue => $dimvalue };
+ print Dumper($artifact);
+ }
+ }
+ }
+}
+
+open(OUTFILE, ">$ARGV[1]");
+print OUTFILE XMLout($data);
+close(OUTFILE);
+
+# the file output is wrong. RepositorySystem needs to be sent out.
+# so you could open up the file and replace <opt> and </opt> with RepositorySystem. but that's lame.
+
+exit();
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# print out a list of what will one day become nodes in the gxml file.
+
+open(FWRI, ">$ARGV[1]");
+
+print FWRI "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<designGraph xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<name>$ARGV[0]</name>\n<globalLables />\n<globalVariables />\n<nodes>\n";
+
+foreach $system ((@{$data->{System}})) { # take the <System> element from the XML file (it's in a hashref variable)
+ foreach $artifact ((@{$system->{Artifact}})) { # now take the <Artifact> element from the XML file
+ $quantity = $artifact->{ArtifactQty};
+ # we're doing this so that we can output multiple nodes if there are indeed that many nodes of that type within the graph or the original product
+ for($i = 0; $i < $quantity; $i++) {
+ $color = $artifact->{Color}->[0]->{ColorName};; #[0];
+ print "THE COLOR IS: $color\n";
+ $colorname = $color;
+ $newcolor = "HotPink";
+ if($colorname eq "black") {$newcolor = "Black"; }
+ if($colorname eq "blue ") { $newcolor = "Blue"; }
+ if($colorname eq "bright blue") { $newcolor = "LightBlue"; }
+ if($colorname eq "bright cyan") { $newcolor = "LightCyan"; }
+ if($colorname eq "bright green") { $newcolor = "LightGreen"; }
+ if($colorname eq "bright magenta") { $newcolor = ""; }
+ if($colorname eq "bright red") { $newcolor = "Pink"; }
+ if($colorname eq "brown") { $newcolor = "Brown"; }
+ if($colorname eq "clear") { $newcolor = "Tan"; }
+ if($colorname eq "cyan") { $newcolor = "Cyan"; }
+ if($colorname eq "gray") { $newcolor = "Gray"; }
+ if($colorname eq "green") { $newcolor = "Green"; }
+ if($colorname eq "light gray") { $newcolor = "LightGray"; }
+ if($colorname eq "magenta") { $newcolor = "Magenta"; }
+ if($colorname eq "red") { $newcolor = "Red"; }
+ if($colorname eq "white") { $newcolor = "White"; }
+ if($colorname eq "yellow") {$newcolor = "Yellow"; }
+ print "The new color is $newcolor.\n";
+
+ print FWRI "<node>\n"; # print to the output file
+ $name = $artifact->{ArtifactName}; # get the artifact name
+ $name =~ s/ /\_/g;
+ print "node name: $name\n"; # tell me what I'm doing
+ print FWRI "<name>$name</name>\n"; # print to the output file
+ print FWRI "<localLabels />\n<localVariables />\n<shapekey>largeCircleNode.$newcolor.30.30</shapekey>\n<screenX>0</screenX>\n<screenY>0</screenY>\n";
+ $xmlout = XMLout($artifact);
+ print "the xml is: $xmlout\n\n";
+ print FWRI $xmlout; # is this cheating?
+ print FWRI "</node>\n";
+ }
+ }
+}
+
+print FWRI "</nodes>\n<arcs />\n</designGraph>";
+
+close(FWRI);
+
+
+print "\n\n\nscript has naturally finished without error.\n\n";
+
+
+
+
+
+## some old code placed here for reference
+# foreach $system ((@{$data->{System}})) {
+# foreach $artifact ((@{$system->{Artifact}})) {
+# foreach $ArtifactFile ((@{$artifact->{ArtifactFile}})) {
+# $ArtifactFileType = $ArtifactFile->{ArtifactFileType};
+# $ArtifactFileExtension = $ArtifactFile->{ArtifactFileExtension};
+# print $ArtifactFile->{text}, ", ", $ArtifactFileExtension, "\n";
+# $name = $ArtifactFile->{text};
+# #open(WRITER,">2008-10-13_newrepo/$file/index.txt");
+# #print WRITER $ArtifactFile->{text}, ", ", $ArtifactFileExtension, "\n";
+# # Let's test this a bit.
+# #foreach $internals ((@{data->{roomba5-FILE}})) {
+# # print $internals->{text};
+# #}
+# #->{text}, "\n";
+# }
+# foreach $ArtifactImage ((@{$artifact->{ArtifactImage}})) {
+# print $ArtifactImage->{text}, "\n";
+# #print WRITER $ArtifactImage->{text}, "\n";
+# }
+# }
+# }
diff --git a/import_tools/del_repo/repo-extract-dimensions.pl b/import_tools/del_repo/repo-extract-dimensions.pl
new file mode 100644
index 0000000..c9b0c98
--- /dev/null
+++ b/import_tools/del_repo/repo-extract-dimensions.pl
@@ -0,0 +1,234 @@
+#!/usr/bin/perl
+# Bryan Bishop
+# 2009-06-11
+# kanzure@gmail.com http://heybryan.org/
+#
+# repo-extract-dimensions.pl
+# usage: ./repo-extract-dimensions.pl input.repo output.fennfile.po
+# extracts dimensioning information from a dot repo file and puts it into a fennfile.po format thingy.
+#
+# written to be used in combination with gxml-add-dimensions.pl
+
+use XML::Simple;
+use Data::Dumper;
+
+
+print "\$#ARGV is: $#ARGV\n";
+$numArgs = $#ARGV+1;
+if ($numArgs <= 1) {
+ print "\n\nproper usage (you passed $numArgs arguments)\n\n";
+ print "./repo-extract-dimensions.pl example.repo output.fennfile.fennpo\n\n";
+ exit;
+}
+
+print "the arguments that were passed to repo-extract-dimensions.pl were as follows:\n";
+foreach $myArg (@ARGV) {
+ print "\t" . $myArg . "\n";
+}
+print "\n"; # pew-pew!
+
+# down to business
+$xml = new XML::Simple(ForceArray => 1);
+$data = $xml->XMLin($ARGV[0], forcearray => 1); # set ARGV0 to something like: "/home/bryan/lab/summer2009/something.repo"
+
+print "checking the artifact names in $ARGV[0]:\n";
+foreach $system ((@{$data->{System}})) { # take the <System> element from the XML file (it's in a hashref variable)
+ foreach $artifact ((@{$system->{Artifact}})) {
+ $name = $artifact->{ArtifactName};
+ print "\t$name\n";
+ }
+}
+print "\n";
+
+# DEBUG
+# the following will print the entire hashref. good for quick debugging.
+# print "XML => " . Dumper($data);
+
+# get the input information from fennfile.fenpo
+$fennfile = $ARGV[2];
+open(FENNFILE, "<$ARGV[2]");
+@lines = <FENNFILE>;
+close(FENNFILE);
+
+$thehash = {};
+foreach my $line (@lines) {
+ @parts = split(/\;/, $line);
+ $thehash{$parts[0]} = $parts[1];
+}
+
+# <Parameters ParameterDimension="length" ParameterUnits="inches" ParameterValue="16.9" />
+# http://www.perlmonks.org/?node_id=253934
+$fennfileoutput = "";
+
+foreach $system ((@{$data->{System}})) { # take the <System> element from the XML file (it's in a hashref variable)
+ foreach $artifact ((@{$system->{Artifact}})) {
+ $name = $artifact->{ArtifactName};
+ $theoutput = "$name;";
+ #$parameters = $artifact->{Parameters}->[0]->{ParameterValue};
+ #print "$parameters";
+ @parameters = @{$artifact->{Parameters}};
+ #print $parameters->[0]->{ParameterValue};
+ #print "total: " . ($#parameters);
+
+ # FIXME TODO
+ # choose only the first material type (David Agu's format doesn't account for multiple materials)
+ # <Material MaterialName="plastic">
+ # add this to the fennfile output thingy.
+ if(!($artifact->{Material}->[0]->{MaterialName} eq "")) {
+ $theoutput .= " M" . $artifact->{Material}->[0]->{MaterialName};
+ }
+
+ for($i = 0; $i < $#parameters; $i++) { # ((@{$artifact->{Parameters}})) {
+ #print "ha"; #$color = $artifact->{Color}->[0]->{ColorName};; #[0];
+ $ParameterValue = @parameters[$i]->{ParameterValue};
+ $ParameterDimension = @parameters[$i]->{ParameterDimension};
+ #print $ParameterDimension;
+ if($ParameterDimension eq "length") {
+ $theoutput .= " L" . $ParameterValue;
+ } elsif (($ParameterDimension eq "outer diameter") || ($ParameterDimension eq "diameter")) {
+ $theoutput .= " D" . $ParameterValue;
+ } elsif (($ParameterDimension eq "mass") || ($ParameterDimension eq "weight")) {
+ $theoutput .= " m" . $ParameterValue;
+ } elsif ($ParameterDimension eq "shaft diameter") {
+ $theoutput .= " D" . $ParameterValue;
+ } elsif ($ParameterDimension eq "width") {
+ $theoutput .= " W" . $ParameterValue;
+ } elsif (($ParameterDimension eq "thickness") || ($ParameterDimension eq "depth")) {
+ $theoutput .= " T" . $ParameterValue;
+ } elsif ($ParameterDimension eq "height") {
+ $theoutput .= " H" . $ParameterValue;
+ } else {
+ $theoutput .= "\n\n** UNKNOWN DIMENSION ** " . $ParameterDimension . "\n";
+ }
+ # other if statements here for the different types of parameters (H=height, L=length, T=thickness, W=width, D=diameter, m=mass)
+ }
+ $theoutput .= "\n";
+ $theoutput =~ s/\; /\;/g;
+ $fennfileoutput .= $theoutput;
+ print $theoutput;
+ }
+}
+
+open(OUT1, ">$ARGV[1]");
+print OUT1 $fennfileoutput;
+close(OUT1);
+
+exit;
+#
+#
+#
+#
+# #print "currently at name: $name\n";
+# if($thehash{$name}) {
+# #print "it is in the hash.\n";
+# $thevalues = $thehash{$name};
+# print "dimensions: $thevalues\n";
+# # Now please parse the dimensions.
+# @dimensions = split(/ /, $thevalues);
+# foreach my $dimension (@dimensions) {
+# $type = substr($dimension,0,1);
+# print "dimension of type $type\n";
+# $dimvalue = substr($dimension,1);
+# chomp($dimvalue);
+# print "the value of this dimension is $dimvalue\n";
+# $fullexpression = "height";
+# if($type eq "H") { $fullexpression = "height"; }
+# if($type eq "L") { $fullexpression = "length"; }
+# if($type eq "T") { $fullexpression = "thickness"; }
+# if($type eq "W") { $fullexpression = "width"; }
+# if($type eq "D") { $fullexpression = "diameter"; }
+# #push(, [{'ParameterUnits' = "supergrams", 'ParameterDimension' = 'supermass', 'ParameterValue' = '1444'}]);
+# push @{ $artifact->{Parameters} }, { ParameterDimension => $fullexpression, ParameterUnits => 'inches', ParameterValue => $dimvalue };
+# print Dumper($artifact);
+# }
+# }
+# }
+# }
+#
+# open(OUTFILE, ">$ARGV[1]");
+# print OUTFILE XMLout($data);
+# close(OUTFILE);
+#
+# exit();
+#
+# # print out a list of what will one day become nodes in the gxml file.
+#
+# open(FWRI, ">$ARGV[1]");
+#
+# print FWRI "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<designGraph xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<name>$ARGV[0]</name>\n<globalLables />\n<globalVariables />\n<nodes>\n";
+#
+# foreach $system ((@{$data->{System}})) { # take the <System> element from the XML file (it's in a hashref variable)
+# foreach $artifact ((@{$system->{Artifact}})) { # now take the <Artifact> element from the XML file
+# $quantity = $artifact->{ArtifactQty};
+# # we're doing this so that we can output multiple nodes if there are indeed that many nodes of that type within the graph or the original product
+# for($i = 0; $i < $quantity; $i++) {
+# $color = $artifact->{Color}->[0]->{ColorName};; #[0];
+# print "THE COLOR IS: $color\n";
+# $colorname = $color;
+# $newcolor = "HotPink";
+# if($colorname eq "black") {$newcolor = "Black"; }
+# if($colorname eq "blue ") { $newcolor = "Blue"; }
+# if($colorname eq "bright blue") { $newcolor = "LightBlue"; }
+# if($colorname eq "bright cyan") { $newcolor = "LightCyan"; }
+# if($colorname eq "bright green") { $newcolor = "LightGreen"; }
+# if($colorname eq "bright magenta") { $newcolor = ""; }
+# if($colorname eq "bright red") { $newcolor = "Pink"; }
+# if($colorname eq "brown") { $newcolor = "Brown"; }
+# if($colorname eq "clear") { $newcolor = "Tan"; }
+# if($colorname eq "cyan") { $newcolor = "Cyan"; }
+# if($colorname eq "gray") { $newcolor = "Gray"; }
+# if($colorname eq "green") { $newcolor = "Green"; }
+# if($colorname eq "light gray") { $newcolor = "LightGray"; }
+# if($colorname eq "magenta") { $newcolor = "Magenta"; }
+# if($colorname eq "red") { $newcolor = "Red"; }
+# if($colorname eq "white") { $newcolor = "White"; }
+# if($colorname eq "yellow") {$newcolor = "Yellow"; }
+# print "The new color is $newcolor.\n";
+#
+# print FWRI "<node>\n"; # print to the output file
+# $name = $artifact->{ArtifactName}; # get the artifact name
+# $name =~ s/ /\_/g;
+# print "node name: $name\n"; # tell me what I'm doing
+# print FWRI "<name>$name</name>\n"; # print to the output file
+# print FWRI "<localLabels />\n<localVariables />\n<shapekey>largeCircleNode.$newcolor.30.30</shapekey>\n<screenX>0</screenX>\n<screenY>0</screenY>\n";
+# $xmlout = XMLout($artifact);
+# print "the xml is: $xmlout\n\n";
+# print FWRI $xmlout; # is this cheating?
+# print FWRI "</node>\n";
+# }
+# }
+# }
+#
+# print FWRI "</nodes>\n<arcs />\n</designGraph>";
+#
+# close(FWRI);
+#
+#
+# print "\n\n\nscript has naturally finished without error.\n\n";
+#
+#
+#
+#
+#
+# ## some old code placed here for reference
+# # foreach $system ((@{$data->{System}})) {
+# # foreach $artifact ((@{$system->{Artifact}})) {
+# # foreach $ArtifactFile ((@{$artifact->{ArtifactFile}})) {
+# # $ArtifactFileType = $ArtifactFile->{ArtifactFileType};
+# # $ArtifactFileExtension = $ArtifactFile->{ArtifactFileExtension};
+# # print $ArtifactFile->{text}, ", ", $ArtifactFileExtension, "\n";
+# # $name = $ArtifactFile->{text};
+# # #open(WRITER,">2008-10-13_newrepo/$file/index.txt");
+# # #print WRITER $ArtifactFile->{text}, ", ", $ArtifactFileExtension, "\n";
+# # # Let's test this a bit.
+# # #foreach $internals ((@{data->{roomba5-FILE}})) {
+# # # print $internals->{text};
+# # #}
+# # #->{text}, "\n";
+# # }
+# # foreach $ArtifactImage ((@{$artifact->{ArtifactImage}})) {
+# # print $ArtifactImage->{text}, "\n";
+# # #print WRITER $ArtifactImage->{text}, "\n";
+# # }
+# # }
+# # }
diff --git a/import_tools/del_repo/repo-print-artifacts.pl b/import_tools/del_repo/repo-print-artifacts.pl
new file mode 100644
index 0000000..fe3f438
--- /dev/null
+++ b/import_tools/del_repo/repo-print-artifacts.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+# Bryan Bishop kanzure@gmail.com http://heybryan.org/
+# 2009-06-10
+# just a utility script to print out a list of artifact names from a .repo file
+use XML::Simple;
+use Data::Dumper;
+
+
+#print "\$#ARGV is: $#ARGV\n";
+$numArgs = $#ARGV+1;
+if ($numArgs <= 0) {
+ print "\n\nproper usage (you passed $numArgs arguments)\n\n";
+ print "./repo-print-artifacts example.repo\n";
+ exit;
+}
+
+#foreach $myArg (@ARGV) {
+# print $myArg . "\n";
+#}
+
+$xml = new XML::Simple(ForceArray => 1);
+$data = $xml->XMLin($ARGV[0], forcearray => 1); # set ARGV0 to something like: "/home/bryan/lab/summer2009/something.repo"
+
+foreach $system ((@{$data->{System}})) { # take the <System> element from the XML file (it's in a hashref variable)
+ foreach $artifact ((@{$system->{Artifact}})) {
+ $name = $artifact->{ArtifactName};
+ print "$name\n";
+ }
+} \ No newline at end of file
diff --git a/import_tools/del_repo/repo-remove-attachments.pl b/import_tools/del_repo/repo-remove-attachments.pl
new file mode 100644
index 0000000..373ab78
--- /dev/null
+++ b/import_tools/del_repo/repo-remove-attachments.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+# make_pretty.pl
+# Bryan Bishop 2008-10-01
+# This script strips some of the stupid XML from the repository files.
+# (it's not my fault ((I swear))
+
+opendir(DIR, "repo");
+while (defined($file = readdir(DIR))) {
+ # do something with "$dirname/$file"
+
+ open(READER, "<repo/$file");
+ open(WRITER, ">new_repo/$file");
+
+ $stopwriting = 0;
+ foreach $line (<READER>) {
+ chomp($line);
+ if(!($line eq "<!DOCTYPE RepositoryXML>") && !($line eq "<RepositorySystem>") && !($line eq "</RepositorySystem>") && ($stopwriting == 0)) { print WRITER $line; print WRITER "\n"; }
+ if($line =~ "</System>") { $stopwriting = 1; }
+ }
+
+ close(WRITER);
+ close(READER);
+
+}
+closedir(DIR);
+
+
diff --git a/import_tools/del_repo/repo2gxml.pl b/import_tools/del_repo/repo2gxml.pl
new file mode 100644
index 0000000..adba019
--- /dev/null
+++ b/import_tools/del_repo/repo2gxml.pl
@@ -0,0 +1,125 @@
+#!/usr/bin/perl
+# Bryan Bishop
+# 2009-06-10
+# kanzure@gmail.com http://heybryan.org/
+#
+# repo2gxml.pl
+# this converts from the dot repo (.repo) XML file format found in repository.designengineeringlab.org to the GraphSynth 1.9 GXML format.
+#
+# because of the faults with the repository data structure or data representation scheme, there is no way for us to recover the functional links, arcs or edges, so for this reason, the output of this program (the gxml) does not include any arcs connecting different components together.
+
+use XML::Simple;
+use Data::Dumper;
+
+sub hextoint {
+ my $value = shift;
+ $value=unpack ('H*', $value);
+ my $new = join( '', substr($value,-2,1), substr($value,-1,1) );
+ $new = join( '', $new, substr($value,-4,1), substr($value,-3,1) );
+ $new = join( '', $new, substr($value,-6,1), substr($value,-5,1) );
+ $new = join( '', $new, substr($value,-8,1), substr($value,-7,1) );
+ $new = join( '', $new, substr($value,-10,1), substr($value,-9,1) );
+ my $val2=hex($new);
+ return $val2;
+ }
+
+print "\$#ARGV is: $#ARGV\n";
+$numArgs = $#ARGV+1;
+if ($numArgs <= 0) {
+ print "\n\nproper usage (you passed $numArgs arguments)\n\n";
+ print "perl repo2gxml.pl example.repo example.gxml\n\n";
+ exit;
+}
+
+foreach $myArg (@ARGV) {
+ print $myArg . "\n";
+}
+
+$xml = new XML::Simple(ForceArray => 1);
+$data = $xml->XMLin($ARGV[0], forcearray => 1); # set ARGV0 to something like: "/home/bryan/lab/summer2009/something.repo"
+
+# DEBUG
+# the following will print the entire hashref. good for quick debugging.
+print "XML => " . Dumper($data);
+
+# print out a list of what will one day become nodes in the gxml file.
+
+open(FWRI, ">$ARGV[1]");
+
+print FWRI "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<designGraph xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<name>$ARGV[0]</name>\n<globalLables />\n<globalVariables />\n<nodes>\n";
+
+foreach $system ((@{$data->{System}})) { # take the <System> element from the XML file (it's in a hashref variable)
+ foreach $artifact ((@{$system->{Artifact}})) { # now take the <Artifact> element from the XML file
+ $quantity = $artifact->{ArtifactQty};
+ # we're doing this so that we can output multiple nodes if there are indeed that many nodes of that type within the graph or the original product
+ for($i = 0; $i < $quantity; $i++) {
+ $color = $artifact->{Color}->[0]->{ColorName};; #[0];
+ print "THE COLOR IS: $color\n";
+ $colorname = $color;
+ $newcolor = "HotPink";
+ if($colorname eq "black") {$newcolor = "Black"; }
+ if($colorname eq "blue ") { $newcolor = "Blue"; }
+ if($colorname eq "bright blue") { $newcolor = "LightBlue"; }
+ if($colorname eq "bright cyan") { $newcolor = "LightCyan"; }
+ if($colorname eq "bright green") { $newcolor = "LightGreen"; }
+ if($colorname eq "bright magenta") { $newcolor = ""; }
+ if($colorname eq "bright red") { $newcolor = "Pink"; }
+ if($colorname eq "brown") { $newcolor = "Brown"; }
+ if($colorname eq "clear") { $newcolor = "Tan"; }
+ if($colorname eq "cyan") { $newcolor = "Cyan"; }
+ if($colorname eq "gray") { $newcolor = "Gray"; }
+ if($colorname eq "green") { $newcolor = "Green"; }
+ if($colorname eq "light gray") { $newcolor = "LightGray"; }
+ if($colorname eq "magenta") { $newcolor = "Magenta"; }
+ if($colorname eq "red") { $newcolor = "Red"; }
+ if($colorname eq "white") { $newcolor = "White"; }
+ if($colorname eq "yellow") {$newcolor = "Yellow"; }
+ print "The new color is $newcolor.\n";
+
+ print FWRI "<node>\n"; # print to the output file
+ $name = $artifact->{ArtifactName}; # get the artifact name
+ $name =~ s/ /\_/g;
+ print "node name: $name\n"; # tell me what I'm doing
+ print FWRI "<name>$name</name>\n"; # print to the output file
+ print FWRI "<localLabels />\n<localVariables />\n<shapekey>largeCircleNode.$newcolor.30.30</shapekey>\n<screenX>0</screenX>\n<screenY>0</screenY>\n";
+ $xmlout = XMLout($artifact);
+ print "the xml is: $xmlout\n\n";
+ print FWRI $xmlout; # is this cheating?
+ print FWRI "</node>\n";
+ }
+ }
+}
+
+print FWRI "</nodes>\n<arcs />\n</designGraph>";
+
+close(FWRI);
+
+
+print "\n\n\nscript has naturally finished without error.\n\n";
+
+
+
+
+
+## some old code placed here for reference
+# foreach $system ((@{$data->{System}})) {
+# foreach $artifact ((@{$system->{Artifact}})) {
+# foreach $ArtifactFile ((@{$artifact->{ArtifactFile}})) {
+# $ArtifactFileType = $ArtifactFile->{ArtifactFileType};
+# $ArtifactFileExtension = $ArtifactFile->{ArtifactFileExtension};
+# print $ArtifactFile->{text}, ", ", $ArtifactFileExtension, "\n";
+# $name = $ArtifactFile->{text};
+# #open(WRITER,">2008-10-13_newrepo/$file/index.txt");
+# #print WRITER $ArtifactFile->{text}, ", ", $ArtifactFileExtension, "\n";
+# # Let's test this a bit.
+# #foreach $internals ((@{data->{roomba5-FILE}})) {
+# # print $internals->{text};
+# #}
+# #->{text}, "\n";
+# }
+# foreach $ArtifactImage ((@{$artifact->{ArtifactImage}})) {
+# print $ArtifactImage->{text}, "\n";
+# #print WRITER $ArtifactImage->{text}, "\n";
+# }
+# }
+# }