Overview
| Comment: | Removed functions associated with writing _abg.m directly. dia2abg.pl now produces _ibg.m instead. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | origin/master | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
3ee8dd04622f12678972cd8a672b6d5e |
| User & Date: | geraint@users.sourceforge.net on 2004-08-19 19:17:41.000 |
| Other Links: | branch diff | manifest | tags |
Context
|
2004-08-19
| ||
| 19:33:43 | Sorts component list into alphabetical order to improve default lbl.txt generation. check-in: 5ada2f34b7 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
| 19:17:41 |
Removed functions associated with writing _abg.m directly. dia2abg.pl now produces _ibg.m instead. check-in: 3ee8dd0462 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
| 19:14:11 | File removed: abg2ibg_dia2m is now used instead. check-in: 5ad4a3ecdd user: geraint@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/bin/trans/dia2abg.pl
from [9fb297b3c3]
to [f8b9be78d9].
1 2 3 4 5 6 7 8 9 10 11 12 | #!/usr/bin/perl -w #---------------------------------------------------------------------------- # dia2abg.pl # Copyright (C) 2002; David Hoover. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/usr/bin/perl -w #---------------------------------------------------------------------------- # dia2abg.pl # Copyright (C) 2002; David Hoover. # Modified 2004 Geraint Bevan. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, |
| ︙ | ︙ | |||
22 23 24 25 26 27 28 | # For more information about free software, visit http://www.fsf.org/ #---------------------------------------------------------------------------- ############################################################################# # Given a DIA diagram, the script has functions that perform the following # MTT (model transformation tools) functions: # 1. Write a _cmp.txt file containing component types:names | | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # For more information about free software, visit http://www.fsf.org/ #---------------------------------------------------------------------------- ############################################################################# # Given a DIA diagram, the script has functions that perform the following # MTT (model transformation tools) functions: # 1. Write a _cmp.txt file containing component types:names # 2. Write a _ibg.m file containing an acausal bond graph suitable for # processing by MTT. # 3. Modify a diagram by changing causality as desired. ############################################################################# #---------------------------------------------------------------------------- # Dia uses a unique id for each object. # get_component_data and get_bond_data read the xml file and collect # important information about component and bond id's, component |
| ︙ | ︙ | |||
70 71 72 73 74 75 76 | # The %bond_id_flow_causality hash is a boolean that provides the # flow arrow-oriented causality. # # key=bond_id # value=arrow-oriented flow causality. # %mtt_bond_id_index provides a unique positive integer index for each | | | > | | > | | | | | | < | | | < | < | | | | | | < | | | < | < | | | | | < < | < < < < < < < < < < < < < < < < < < < < | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# The %bond_id_flow_causality hash is a boolean that provides the
# flow arrow-oriented causality.
#
# key=bond_id
# value=arrow-oriented flow causality.
# %mtt_bond_id_index provides a unique positive integer index for each
# Dia bond ID. The index is written to the ibg.m file for mtt.
# The %component_id_type, %component_id_name, %component_id_reps hashes
# store the information from _cmp.m for each component
#
# key=component_id
# value=component type, name or number of repetitions
#----------------------------------------------------------------------------
#----------------------------MAIN PROGRAM------------------------------------
use strict;
use Getopt::Long;
use XML::DOM;
my (%component_id_tag, %bond_id_start_id, %bond_id_end_id,
$objects, %mtt_bond_id_index,
%bond_id_arrow_on_start, %bond_id_flow_causality, %bond_id_effort_causality,
%bond_id_start_label,%bond_id_end_label);
my (%component_id_type, %component_id_name, %component_id_reps);
# Parse user options:
my $diagram_name = '';
my $dia_input_file = '';
my $dia_output_file = '';
my $component_list_file = '';
my $debug = 0;
my $create_component_list = 0;
my $create_ibg = 0;
my $ibg_file = '';
my $change_flow_causality = '';
my $change_effort_causality = '';
GetOptions ('diagram_name=s' => \$diagram_name,
'dia_input_file=s' => \$dia_input_file,
'dia_output_file=s' => \$dia_output_file,
'component_list_file=s' => \$component_list_file,
'debug' => \$debug,
'create_component_list' => \$create_component_list,
'create_ibg' => \$create_ibg,
'ibg_file=s' => \$ibg_file,
'change_flow_causality=s' => \$change_flow_causality,
'change_effort_causality=s' => \$change_effort_causality,
);
die usage() if $diagram_name eq '';
# Use defaults if necessary:
$dia_input_file = $diagram_name . "_abg.dia" if ($dia_input_file eq '');
$dia_output_file = $diagram_name . "_cbg.dia" if ($dia_output_file eq '');
$ibg_file = $diagram_name . "_ibg.m" if ($ibg_file eq '');
$component_list_file = $diagram_name . "_cmp.txt" if ($component_list_file eq '');
# Start Parsing XML, and creating files:
my $dom = new XML::DOM::Parser;
my ($doc);
$doc = $dom->parsefile($dia_input_file);
$objects = get_objects_node($doc,"Bond Graph");
get_component_data($objects);
parse_component_data();
get_bond_data($objects);
create_component_list() if ($create_component_list);
if ($create_ibg) {
open (OUT,">$ibg_file") ||
die "Cannot open $ibg_file for writing.\n";
output_ibg();
}
if ($change_flow_causality ne '' || $change_effort_causality ne '') {
open (DIA_OUT,">$dia_output_file") ||
die "Cannot open $dia_output_file for writing.\n";
|
| ︙ | ︙ | |||
201 202 203 204 205 206 207 |
id_cleaner();
$val = $_;
print RAW $val . "\n";
}
close(RAW);
}
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
id_cleaner();
$val = $_;
print RAW $val . "\n";
}
close(RAW);
}
sub get_objects_node {
my ( $doc_node, $layer_name )= @_;
my ($root,$layer_node,$objects);
$root = get_first_element_subnode($doc_node);
die "could not find top-level element dia_diagram.\n"
unless $root->getTagName eq 'dia:diagram';
$layer_node = get_first_subnode_by_nodename_attribute(0,$root,"dia:layer","name",$layer_name);
die "I found no dia:layer named $layer_name. Are you sure the diagram has one?\n" unless
$layer_node->getTagName eq 'dia:layer' &&
$layer_node->getAttributeNode("name")->getValue eq $layer_name;
$objects = $layer_node->getElementsByTagName('dia:object');
return $objects;
}
sub output_ibg_header {
my ($date);
$date = `date`; chomp($date);
print OUT <<"EOF";
## -*-octave-*- put Emacs into Octave mode
|
| ︙ | ︙ | |||
313 314 315 316 317 318 319 |
sub output_ibg_footer {
print OUT <<"EOF";
endfunction
EOF
}
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
sub output_ibg_footer {
print OUT <<"EOF";
endfunction
EOF
}
sub output_ibg {
my ($key,$component,$type,$name,
%reverse_mtt_bond_id_index,$mtt_bond_id,$dia_bond_id,
@bonds,
$bond_id,$start,$end,$id,
$head,$head_component,$head_type,$head_name,
$tail,$tail_component,$tail_type,$tail_name,
|
| ︙ | ︙ | |||
536 537 538 539 540 541 542 |
" ${diagram_name}.bonds.bond${mtt_bond_id_index{$dia_bond_id}}." .
"causality.flow = \"$flow_causality\";\n\n";
}
output_ibg_footer();
}
| < < < < < < < < < < < < < < < < < < | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
" ${diagram_name}.bonds.bond${mtt_bond_id_index{$dia_bond_id}}." .
"causality.flow = \"$flow_causality\";\n\n";
}
output_ibg_footer();
}
sub get_component_data {
my ( $objects_node )= @_;
my($obj,$id,$attr,$comp,$strattr,$str_elem,$string);
print_debug("READING COMPONENTS FROM $dia_input_file...\n");
for my $i (0..$objects_node->getLength-1) {
$obj = $objects_node->item($i);
|
| ︙ | ︙ | |||
577 578 579 580 581 582 583 |
$string = get_first_text_subnode($str_elem);
$component_id_tag{$id} = $string->getData;
}
die "There are no components!\n" unless keys(%component_id_tag) > 0;
}
sub parse_component_data {
| | < < < < | 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
$string = get_first_text_subnode($str_elem);
$component_id_tag{$id} = $string->getData;
}
die "There are no components!\n" unless keys(%component_id_tag) > 0;
}
sub parse_component_data {
my (%anon_index, $id, $component);
while (($id, $component) = each (%component_id_tag)) {
$_ = $component;
id_cleaner();
$component = $_;
my ($type_name, $repetitions) = split (/\*/, $component);
if (! $repetitions) {
$type_name = $component;
$repetitions = 1;
}
my ($type, $name) = split (/:/, $type_name);
if (! $name) {
$type = $type_name;
if (! defined ($anon_index{$type})) {
$anon_index{$type} = 1;
$name = "mtt${type}";
} else {
my $num = ++$anon_index{$type};
$name = "mtt${type}_${num}";
}
}
$component_id_type{$id} = $type;
$component_id_name{$id} = $name;
$component_id_reps{$id} = $repetitions;
}
}
# Dia stores its attributes in a strange way, not using typical xml attributes.
sub get_dia_attribute_value {
my ($type, $attribute_node )= @_;
my ($subnode);
|
| ︙ | ︙ | |||
782 783 784 785 786 787 788 |
$subnode->getNodeType == TEXT_NODE;
}
sub id_cleaner {
s/#?([^#]*)#?/$1/;
}
| < < < < < < < < < < < < < < < < < < < | | | 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
$subnode->getNodeType == TEXT_NODE;
}
sub id_cleaner {
s/#?([^#]*)#?/$1/;
}
sub print_debug {
print STDERR $_[0] if ($debug);
}
sub usage {
return
"\n" .
"Usage: dia2abg.pl --diagram_name <diagram_name> [options]\n" .
"Options:\n" .
"\t--dia_input_file <dia_input_file>\n" .
"\t--component_list_file\n" .
"\t--create_component_list\n" .
"\t--create_ibg\n" .
"\t--debug\n" .
"\t--ibg_file <ibg_file>\n" .
"\t--change_flow_causality <bond causality spec>\n" .
"\t--change_effort_causality <bond causality spec>\n" .
"\n" .
"\t\tBond causality spec:\n" .
"\t\t 'bond:causality;bond:causality;...'\n" .
"\t\tbond:\n" .
"\t\t [mtt_bond_id|all]\n" .
|
| ︙ | ︙ |