[6454] | 1 | %
|
---|
| 2 | % definition for the kml_style sub (derived) class.
|
---|
| 3 | %
|
---|
| 4 | % [kml]=kml_style(varargin)
|
---|
| 5 | %
|
---|
| 6 | % where the optional varargin and defaults are:
|
---|
| 7 | % id (char, style id, '')
|
---|
| 8 | % icon (char, icon style, '')
|
---|
| 9 | % label (char, label style, '')
|
---|
| 10 | % line (char, line style, '')
|
---|
| 11 | % poly (char, poly style, '')
|
---|
| 12 | % balloon (char, balloon style, '')
|
---|
| 13 | % list (char, list style, '')
|
---|
| 14 | %
|
---|
| 15 | % note that zero arguments constructs a default instance; one
|
---|
| 16 | % argument of the class copies the instance; and two or more
|
---|
| 17 | % arguments constructs a new instance from the arguments.
|
---|
| 18 | %
|
---|
| 19 | classdef kml_style < kml_styleselector
|
---|
| 20 | properties
|
---|
| 21 | % icon =kml_iconstyle.empty();
|
---|
| 22 | % label =kml_labelstyle.empty();
|
---|
| 23 | icon =[];
|
---|
| 24 | label =[];
|
---|
| 25 | line =kml_linestyle.empty();
|
---|
| 26 | poly =kml_polystyle.empty();
|
---|
| 27 | % balloon =kml_balloonstyle.empty();
|
---|
| 28 | % list =kml_liststyle.empty();
|
---|
| 29 | balloon =[];
|
---|
| 30 | list =[];
|
---|
| 31 | end
|
---|
| 32 |
|
---|
| 33 | methods
|
---|
| 34 | function [kml]=kml_style(varargin)
|
---|
| 35 |
|
---|
| 36 | kml=kml@kml_styleselector(varargin{:});
|
---|
| 37 |
|
---|
| 38 | switch nargin
|
---|
| 39 |
|
---|
| 40 | % create a default object
|
---|
| 41 |
|
---|
| 42 | case 0
|
---|
| 43 |
|
---|
| 44 | % copy the object or create the object from the input
|
---|
| 45 |
|
---|
| 46 | otherwise
|
---|
| 47 | if (nargin == 1) && isa(varargin{1},class(kml))
|
---|
| 48 | kml=varargin{1};
|
---|
| 49 |
|
---|
| 50 | else
|
---|
| 51 | fnames=fieldnames(kml);
|
---|
| 52 |
|
---|
| 53 | for i=length(fieldnames(kml_styleselector()))+1:min(nargin,length(fnames))
|
---|
| 54 | if isa(varargin{i},class(kml.(fnames{i})))
|
---|
| 55 | if ~isempty(varargin{i})
|
---|
| 56 | kml.(fnames{i})=varargin{i};
|
---|
| 57 | end
|
---|
| 58 | else
|
---|
| 59 | if ~isempty(inputname(i))
|
---|
[6455] | 60 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
[6454] | 61 | inputname(i),fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
---|
| 62 | else
|
---|
[6455] | 63 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
[6454] | 64 | i ,fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
---|
| 65 | end
|
---|
| 66 | end
|
---|
| 67 | end
|
---|
| 68 | end
|
---|
| 69 |
|
---|
| 70 | end
|
---|
| 71 |
|
---|
| 72 | end
|
---|
| 73 |
|
---|
| 74 | % display the object
|
---|
| 75 |
|
---|
| 76 | function []=disp(kml)
|
---|
| 77 |
|
---|
| 78 | for i=1:numel(kml)
|
---|
| 79 | disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
|
---|
| 80 | class(kml),inputname(1),string_dim(kml,i)));
|
---|
| 81 | disp@kml_styleselector(kml(i));
|
---|
| 82 | disp(sprintf(' icon: %s %s' ,string_size(kml(i).icon),...
|
---|
| 83 | class(kml(i).icon)));
|
---|
| 84 | disp(sprintf(' label: %s %s' ,string_size(kml(i).label),...
|
---|
| 85 | class(kml(i).label)));
|
---|
| 86 | disp(sprintf(' line: %s %s' ,string_size(kml(i).line),...
|
---|
| 87 | class(kml(i).line)));
|
---|
| 88 | disp(sprintf(' poly: %s %s' ,string_size(kml(i).poly),...
|
---|
| 89 | class(kml(i).poly)));
|
---|
| 90 | disp(sprintf(' balloon: %s %s' ,string_size(kml(i).balloon),...
|
---|
| 91 | class(kml(i).balloon)));
|
---|
| 92 | disp(sprintf(' list: %s %s\n' ,string_size(kml(i).list),...
|
---|
| 93 | class(kml(i).list)));
|
---|
| 94 | end
|
---|
| 95 |
|
---|
| 96 | end
|
---|
| 97 |
|
---|
[6479] | 98 | % return the fieldnames of the object
|
---|
| 99 |
|
---|
| 100 | function [fnames]=fieldnames(kml)
|
---|
| 101 |
|
---|
| 102 | % fieldnames for a sub (derived) class list those before super (base)
|
---|
| 103 |
|
---|
| 104 | fnames=fieldnames(kml_styleselector());
|
---|
| 105 | fnames={fnames{:} ...
|
---|
| 106 | 'icon' ...
|
---|
| 107 | 'label' ...
|
---|
| 108 | 'line' ...
|
---|
| 109 | 'poly' ...
|
---|
| 110 | 'balloon' ...
|
---|
| 111 | 'list' ...
|
---|
| 112 | }';
|
---|
| 113 |
|
---|
| 114 | end
|
---|
| 115 |
|
---|
[6455] | 116 | % set the properties of the object
|
---|
| 117 |
|
---|
| 118 | function [kml]=set(kml,varargin)
|
---|
| 119 |
|
---|
| 120 | kmlref=feval(class(kml));
|
---|
[6456] | 121 | fnames=fieldnames(kmlref);
|
---|
[6455] | 122 |
|
---|
| 123 | % loop through each parameter in the input list (comparing to the reference
|
---|
| 124 | % object in case property types have been changed)
|
---|
| 125 |
|
---|
| 126 | for i=1:2:length(varargin)
|
---|
[6456] | 127 | if ismember(varargin{i},fnames) && (i+1 <= length(varargin))
|
---|
[6455] | 128 | if isa(varargin{i+1},class(kmlref.(varargin{i})))
|
---|
| 129 | kml.(varargin{i})=varargin{i+1};
|
---|
| 130 | else
|
---|
| 131 | if ~isempty(inputname(i+1))
|
---|
| 132 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
[6456] | 133 | inputname(i+2),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
[6455] | 134 | else
|
---|
| 135 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
[6456] | 136 | i+2 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
[6455] | 137 | end
|
---|
| 138 | end
|
---|
| 139 | else
|
---|
| 140 | warning('Property ''%s'' for class ''%s'' does not exist.',...
|
---|
| 141 | varargin{i},class(kmlref));
|
---|
| 142 | end
|
---|
| 143 | end
|
---|
| 144 |
|
---|
| 145 | end
|
---|
| 146 |
|
---|
[6454] | 147 | % write the object
|
---|
| 148 |
|
---|
| 149 | function []=kml_write(kml,fid,indent)
|
---|
| 150 |
|
---|
| 151 | if ~exist('fid','var') || isempty(fid)
|
---|
| 152 | fid=1;
|
---|
| 153 | end
|
---|
| 154 | if ~exist('indent','var') || isempty(indent)
|
---|
| 155 | indent='';
|
---|
| 156 | end
|
---|
| 157 |
|
---|
| 158 | % loop over the styles
|
---|
| 159 |
|
---|
| 160 | for i=1:numel(kml)
|
---|
| 161 | if ~isempty(kml(i).id)
|
---|
| 162 | fprintf(fid,'%s<Style id="%s">\n',indent,kml(i).id);
|
---|
| 163 | else
|
---|
| 164 | fprintf(fid,'%s<Style>\n',indent);
|
---|
| 165 | end
|
---|
| 166 | kml_write@kml_styleselector(kml(i),fid,indent);
|
---|
| 167 | % if isa(kml(i).icon,'kml_iconstyle')
|
---|
[6460] | 168 | % kml_write(kml(i).icon,fid,[indent ' ']);
|
---|
[6454] | 169 | % else
|
---|
| 170 | % warning('kml(%d).icon is a ''%s'' class object, not ''%s''.',...
|
---|
| 171 | % i,class(kml(i).icon),'kml_iconstyle');
|
---|
| 172 | % end
|
---|
| 173 | % if isa(kml(i).label,'kml_labelstyle')
|
---|
[6460] | 174 | % kml_write(kml(i).label,fid,[indent ' ']);
|
---|
[6454] | 175 | % else
|
---|
| 176 | % warning('kml(%d).label is a ''%s'' class object, not ''%s''.',...
|
---|
| 177 | % i,class(kml(i).label),'kml_labelstyle');
|
---|
| 178 | % end
|
---|
| 179 | if isa(kml(i).line,'kml_linestyle')
|
---|
[6460] | 180 | kml_write(kml(i).line,fid,[indent ' ']);
|
---|
[6454] | 181 | else
|
---|
| 182 | warning('kml(%d).line is a ''%s'' class object, not ''%s''.',...
|
---|
| 183 | i,class(kml(i).line),'kml_linestyle');
|
---|
| 184 | end
|
---|
| 185 | if isa(kml(i).poly,'kml_polystyle')
|
---|
[6460] | 186 | kml_write(kml(i).poly,fid,[indent ' ']);
|
---|
[6454] | 187 | else
|
---|
| 188 | warning('kml(%d).poly is a ''%s'' class object, not ''%s''.',...
|
---|
| 189 | i,class(kml(i).poly),'kml_polystyle');
|
---|
| 190 | end
|
---|
| 191 | % if isa(kml(i).balloon,'kml_balloonstyle')
|
---|
[6460] | 192 | % kml_write(kml(i).balloon,fid,[indent ' ']);
|
---|
[6454] | 193 | % else
|
---|
| 194 | % warning('kml(%d).balloon is a ''%s'' class object, not ''%s''.',...
|
---|
| 195 | % i,class(kml(i).balloon),'kml_balloonstyle');
|
---|
| 196 | % end
|
---|
| 197 | % if isa(kml(i).list,'kml_liststyle')
|
---|
[6460] | 198 | % kml_write(kml(i).list,fid,[indent ' ']);
|
---|
[6454] | 199 | % else
|
---|
| 200 | % warning('kml(%d).list is a ''%s'' class object, not ''%s''.',...
|
---|
| 201 | % i,class(kml(i).list),'kml_liststyle');
|
---|
| 202 | % end
|
---|
| 203 | fprintf(fid,'%s</Style>\n',indent);
|
---|
| 204 | end
|
---|
| 205 |
|
---|
| 206 | end
|
---|
| 207 |
|
---|
| 208 | end
|
---|
| 209 |
|
---|
| 210 | end
|
---|
| 211 |
|
---|