Differences From Artifact [2f3ab8ea62]:

To Artifact [58045c3642]:


1
2
3
4
5
6
7



8
9
10
11
12
13
14
function [bonds,components] = rbg2abg(rbonds,rstrokes,rcomponents,rports,infofile)

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$



% %% Revision 1.3  1996/08/09 08:26:35  peter
% %% Cosmetic tidy up.
% %%
% %% Revision 1.2  1996/08/04 18:37:57  peter
% %% Fixed  no causal strokes bug.
% %%
% %% Revision 1.1  1996/08/04 18:30:14  peter







>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function [bonds,components] = rbg2abg(rbonds,rstrokes,rcomponents,rports,infofile)

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$
% %% Revision 1.4  1996/08/24 18:00:33  peter
% %% Fixed bug with finding ports.
% %%
% %% Revision 1.3  1996/08/09 08:26:35  peter
% %% Cosmetic tidy up.
% %%
% %% Revision 1.2  1996/08/04 18:37:57  peter
% %% Fixed  no causal strokes bug.
% %%
% %% Revision 1.1  1996/08/04 18:30:14  peter
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
else
  fnum = fopen(infofile, 'w');
end;

% Xfig scaling factor
scale = 1200.0;

%Rotation matrix
rot = [0 -1; 1 0];

% Find number of strokes
[n_strokes,columns] = size(rstrokes);
if (columns ~= 4)&(n_strokes>0)
  error('Incorrect rstrokes matrix: must have 4 columns');
end;







|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
else
  fnum = fopen(infofile, 'w');
end;

% Xfig scaling factor
scale = 1200.0;

% Rotation matrix
rot = [0 -1; 1 0];

% Find number of strokes
[n_strokes,columns] = size(rstrokes);
if (columns ~= 4)&(n_strokes>0)
  error('Incorrect rstrokes matrix: must have 4 columns');
end;
61
62
63
64
65
66
67
68
69
70
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
    arrow_end;
 
% Locate the bond end nearest to each port
for i = 1:n_ports
  near_bond = adjbond(rports(i,1:2),arrow_end,other_end);
  port_near_bond(i,:) = [near_bond, rports(i,3)];
end;
port_near_bond

% Locate the components at the ends of each bond
for i = 1:n_bonds
  comp_near_bond(i,:) = adjcomp(arrow_end(i,:),other_end(i,:),rcomponents);
end;
comp_near_bond

% Produce a list of bonds on each component - sorted if explicit port numbers
for i = 1:n_components
  [index,n] = getindex(comp_near_bond,i);





  if index(1,1) ~= 0 % Then its a genuine component 
    one = ones(n,1);
    bond_list = index(:,1); % either end of bond at component

    

    % Default sort of bonds (ie no change)
    sort_index = [1:n]'; 
    
    if n_ports>0
      % Are the component ports numbered? (either they all are or none are)
      k=0;
      for j = 1:n
	[port_index,m] = getindex(port_near_bond(:,1:2),bond_list(j));
	if m==1 % exactly one number on this bond
	  if index(j,2)==port_near_bond(port_index,2) % same end

	    k=k+1;

	    port_number(k,1) = port_near_bond(port_index,3);

	  end;
	end;



      end;

      % Must have a lable for each port or non at all
      if k==n
	[junk,sort_index]=sort(port_number);




      elseif k~=0
	info = sprintf(... 
	    'Component at (%1.3f,%1.3f) has inconsistent port numbers', ...
	    rcomponents(i,1)/scale, rcomponents(i,2)/scale);
	mtt_info(info,fnum);
      end;

    end;
  end;

  % direction is 1 if arrow at component else -1
  direction = -sign(index(:,2)-1.5*one);
  signed_bond_list = bond_list.*direction;
  







<





<


|

>
>
>
>



|
>
|
>







|
|
|
>
|
>
|
>


>
>
>


|

|
>
>
>
>

|
<
<
|

>







64
65
66
67
68
69
70

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
    arrow_end;
 
% Locate the bond end nearest to each port
for i = 1:n_ports
  near_bond = adjbond(rports(i,1:2),arrow_end,other_end);
  port_near_bond(i,:) = [near_bond, rports(i,3)];
end;


% Locate the components at the ends of each bond
for i = 1:n_bonds
  comp_near_bond(i,:) = adjcomp(arrow_end(i,:),other_end(i,:),rcomponents);
end;


% Produce a list of bonds on each component - sorted if explicit port numbers
for i = 1:n_components    
  [index,n] = getindex(comp_near_bond,i);
    % Error message in case we need it!
  port_error = sprintf(... 
      'Component at (%1.3f,%1.3f) has inconsistent port numbers', ...
      rcomponents(i,1)/scale, rcomponents(i,2)/scale);

  if index(1,1) ~= 0 % Then its a genuine component 
    one = ones(n,1);
    bond_list = index(:,1); %  bond at component
    bond_end = index(:,2);  % which end of bond at component?


    % Default sort of bonds (ie no change)
    sort_index = [1:n]'; 
    
    if n_ports>0
      % Are the component ports numbered? (either they all are or none are)
      k=0;
      for j = 1:n
	b = bond_list(j); e = bond_end(j);
	% Find all ports on this bond
	[port_indices,m] = getindex(port_near_bond(:,1),b);
	% Now find the one at this end
	for l=1:m
	  port_index = port_indices(l);
	  if port_near_bond(port_index,2)==e
	    break;
	  end;
	end;
	% and put the corresponding number in the list
	k=k+1;
	port_number(k,1) = port_near_bond(port_index,3);
      end;

	% Must have a lable for each port or non at all
      if k==n
	[sorted,sort_index]=sort(port_number);
	if sum(sorted==[1:n]')~=n % The there is something wrong
	  mtt_info(port_error,fnum);
	  mtt_info(sprintf('\t it must have ports from 1:%1.0f\n', n), fnum);
	end;
      elseif k~=0
	mtt_info(port_error,fnum);


	mtt_info(sprintf('\t it must have 0 or %1.0f ports\n', n), fnum);
      end;
 
    end;
  end;

  % direction is 1 if arrow at component else -1
  direction = -sign(index(:,2)-1.5*one);
  signed_bond_list = bond_list.*direction;
  

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