Overview
Comment:Writes anonymous components (except junctions) to cmp.txt and then assigns names to them.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: a828e952873a1c6eca1dcec6d02f5208a75880099fc24ab66a2b464868ec75f3
User & Date: geraint@users.sourceforge.net on 2004-08-01 22:07:14
Other Links: branch diff | manifest | tags
Context
2004-08-02
06:55:01
Handles repetitions (cmp.txt, ibg.m and abg.m) check-in: 8882cbd39e user: geraint@users.sourceforge.net tags: origin/master, trunk
2004-08-01
22:07:14
Writes anonymous components (except junctions) to cmp.txt and then assigns names to them. check-in: a828e95287 user: geraint@users.sourceforge.net tags: origin/master, trunk
20:13:30
ibg2abg transformation does not require lbl.txt (directly) check-in: b58a6177cf user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/dia2abg.pl from [38d24fda44] to [631b1db315].

110
111
112
113
114
115
116

117
118
119
120
121
122
123
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124







+







	    'dia_input_file=s' => \$dia_input_file,
	    'dia_output_file=s' => \$dia_output_file,
	    'label_file=s' => \$label_file,
	    'component_list_file=s' => \$component_list_file,
	    'debug' => \$debug,
	    'create_component_list' => \$create_component_list,
	    'create_abg' => \$create_abg,
	    'create_ibg' => \$create_ibg,
	    'abg_file=s' => \$abg_file,
	    '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 '';
134
135
136
137
138
139
140

141
142
143


144
145
146
147
148
149
150
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154







+



+
+







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);

get_bond_data($objects);

create_component_list() if ($create_component_list);
name_anonymous_components();

if ($create_abg) {
    open (OUT,">$abg_file") ||
	die "Cannot open $abg_file for writing.\n";

    # Don't update the label file unless we are creating component list and abg simultaneously...
    if ($create_component_list) {
	print STDERR "WARNING: Label file may be stale.\n" 
176
177
178
179
180
181
182
183

184
185
186
187
188
189


190



191

192
193
194
195
196
197
198
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







-
+





-
+
+

+
+
+
-
+







}

exit 0;


#----------------------------SUBROUTINES-------------------------------------
sub create_component_list {
    my ($name,@line,$i);
    my ($type, $name);

    print_debug("CREATING unique_raw_list...\n");
    open (RAW,">$component_list_file") ||
	die "Cannot open $component_list_file for writing.\n";

    foreach (values(%component_id_tag)) {
    foreach my $val (values(%component_id_tag)) {	
	$_ = $val;
	id_cleaner();
	$val = $_;
	($type, $name) = split (/:/) ;
	$type = $type ? $type : $val;
	print RAW $_ . "\n" if (/:/);
	print RAW $val . "\n" if (($type ne "1") and ($type ne "0"));
    }
    close(RAW);
}


sub get_label_data {
    my ($name,@line,$i);
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
422

423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
415
416
417
418
419
420
421

422
423
424
425
426
427
428
429

430















431
432
433
434
435
436
437







-
+







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	    $i++;
	}
    }
    print OUT "\n";
}

sub output_ibg {
    my (%components,$key,$component,$type,$name,
    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,
	$start_label,$end_label,
	$head_label,$tail_label,
	$effort_causality,$flow_causality,
	$effort_causality,$flow_causality);
	$anon_id);

    # copy component_id_tag and assign names to anonymous components
    %components = %component_id_tag;

    $anon_id = 0;
    while (($id, $component) = each(%components)) {
	$component =~ s/\#//g;
	($type, $name) = split (/:/, $component);
	if (! $name) {
	    $component = "${component}:mtt${component}_${anon_id}";
	}
	$anon_id++;
	$components{$id} = $component;
    }

    output_ibg_header();

    %reverse_mtt_bond_id_index = reverse (%mtt_bond_id_index);

#    while (($mtt_bond_id, $dia_bond_id) = each(%reverse_mtt_bond_id_index)) {
    @bonds = (sort keys (%reverse_mtt_bond_id_index));
476
477
478
479
480
481
482
483
484


485
486
487
488
489
490
491
469
470
471
472
473
474
475


476
477
478
479
480
481
482
483
484







-
-
+
+







	    $head_label = $end_label;
	    $tail_label = $start_label;
	} else {
	    $head_label = $start_label;
	    $tail_label = $end_label;
	}

	$head_component = $components{$head};
	$tail_component = $components{$tail};
	$head_component = $component_id_tag{$head};
	$tail_component = $component_id_tag{$tail};

	$effort_causality = $bond_id_effort_causality{$dia_bond_id};
	$flow_causality   = $bond_id_flow_causality  {$dia_bond_id};

	for ($effort_causality) {
	    if (/-1/) { $effort_causality = "tail";}
	    if (/0/) { $effort_causality = "none";}
555
556
557
558
559
560
561
















562
563
564
565
566
567
568
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







      $strattr = get_first_subnode_by_nodename_attribute(0,$comp,"dia:attribute","name","string");
      $str_elem = get_first_element_subnode($strattr);
      $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 name_anonymous_components {
    my ($id, $component, $type, $name, $anon_id);
    $anon_id = 0;
    while (($id, $component) = each(%component_id_tag)) {
	$_ = $component;
	id_cleaner();
	$component = $_;
	($type, $name) = split (/:/, $component);
	if (! $name) {
	    $component = "${component}:mtt${component}_${anon_id}";
	    $anon_id++;
	}
	$component_id_tag{$id} = $component;
    }    
}

# Dia stores its attributes in a strange way, not using typical xml attributes.
sub get_dia_attribute_value {
    my ($type, $attribute_node )= @_;
    my ($subnode);
    $subnode = get_first_subnode_by_nodename_attribute(0,$attribute_node,$type);


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]