| 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_style());
|
|---|
| 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))
|
|---|
| 60 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
|---|
| 61 | inputname(i),fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
|---|
| 62 | else
|
|---|
| 63 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 116 | % set the properties of the object
|
|---|
| 117 |
|
|---|
| 118 | function [kml]=setprops(kml,varargin)
|
|---|
| 119 |
|
|---|
| 120 | kmlref=feval(class(kml));
|
|---|
| 121 | fnames=fieldnames(kmlref);
|
|---|
| 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)
|
|---|
| 127 | if ismember(varargin{i},fnames) && (i+1 <= length(varargin))
|
|---|
| 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''.',...
|
|---|
| 133 | inputname(i+2),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
|---|
| 134 | else
|
|---|
| 135 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
|---|
| 136 | i+2 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
|---|
| 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 |
|
|---|
| 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 | kmli=kml(i);
|
|---|
| 162 | if ~isempty(kmli.id)
|
|---|
| 163 | fprintf(fid,'%s<Style id="%s">\n',indent,kmli.id);
|
|---|
| 164 | else
|
|---|
| 165 | fprintf(fid,'%s<Style>\n',indent);
|
|---|
| 166 | end
|
|---|
| 167 | kml_write@kml_styleselector(kmli,fid,indent);
|
|---|
| 168 | % if isa(kmli.icon,'kml_iconstyle')
|
|---|
| 169 | % kml_write(kmli.icon,fid,[indent ' ']);
|
|---|
| 170 | % else
|
|---|
| 171 | % warning('kml(%d).icon is a ''%s'' class object, not ''%s''.',...
|
|---|
| 172 | % i,class(kmli.icon),'kml_iconstyle');
|
|---|
| 173 | % end
|
|---|
| 174 | % if isa(kmli.label,'kml_labelstyle')
|
|---|
| 175 | % kml_write(kmli.label,fid,[indent ' ']);
|
|---|
| 176 | % else
|
|---|
| 177 | % warning('kml(%d).label is a ''%s'' class object, not ''%s''.',...
|
|---|
| 178 | % i,class(kmli.label),'kml_labelstyle');
|
|---|
| 179 | % end
|
|---|
| 180 | if isa(kmli.line,'kml_linestyle')
|
|---|
| 181 | kml_write(kmli.line,fid,[indent ' ']);
|
|---|
| 182 | else
|
|---|
| 183 | warning('kml(%d).line is a ''%s'' class object, not ''%s''.',...
|
|---|
| 184 | i,class(kmli.line),'kml_linestyle');
|
|---|
| 185 | end
|
|---|
| 186 | if isa(kmli.poly,'kml_polystyle')
|
|---|
| 187 | kml_write(kmli.poly,fid,[indent ' ']);
|
|---|
| 188 | else
|
|---|
| 189 | warning('kml(%d).poly is a ''%s'' class object, not ''%s''.',...
|
|---|
| 190 | i,class(kmli.poly),'kml_polystyle');
|
|---|
| 191 | end
|
|---|
| 192 | % if isa(kmli.balloon,'kml_balloonstyle')
|
|---|
| 193 | % kml_write(kmli.balloon,fid,[indent ' ']);
|
|---|
| 194 | % else
|
|---|
| 195 | % warning('kml(%d).balloon is a ''%s'' class object, not ''%s''.',...
|
|---|
| 196 | % i,class(kmli.balloon),'kml_balloonstyle');
|
|---|
| 197 | % end
|
|---|
| 198 | % if isa(kmli.list,'kml_liststyle')
|
|---|
| 199 | % kml_write(kmli.list,fid,[indent ' ']);
|
|---|
| 200 | % else
|
|---|
| 201 | % warning('kml(%d).list is a ''%s'' class object, not ''%s''.',...
|
|---|
| 202 | % i,class(kmli.list),'kml_liststyle');
|
|---|
| 203 | % end
|
|---|
| 204 | fprintf(fid,'%s</Style>\n',indent);
|
|---|
| 205 | end
|
|---|
| 206 |
|
|---|
| 207 | end
|
|---|
| 208 |
|
|---|
| 209 | % string write the object
|
|---|
| 210 |
|
|---|
| 211 | function [sbuf]=kml_swrite(kml,sbuf,indent)
|
|---|
| 212 |
|
|---|
| 213 | if ~exist('sbuf','var') || isempty(sbuf)
|
|---|
| 214 | sbuf=string_buf;
|
|---|
| 215 | end
|
|---|
| 216 | if ~exist('indent','var') || isempty(indent)
|
|---|
| 217 | indent='';
|
|---|
| 218 | end
|
|---|
| 219 |
|
|---|
| 220 | % loop over the styles
|
|---|
| 221 |
|
|---|
| 222 | for i=1:numel(kml)
|
|---|
| 223 | kmli=kml(i);
|
|---|
| 224 | if ~isempty(kmli.id)
|
|---|
| 225 | sbuf=add(sbuf,sprintf('%s<Style id="%s">\n',indent,kmli.id));
|
|---|
| 226 | else
|
|---|
| 227 | sbuf=add(sbuf,sprintf('%s<Style>\n',indent));
|
|---|
| 228 | end
|
|---|
| 229 | sbuf=kml_swrite@kml_styleselector(kmli,sbuf,indent);
|
|---|
| 230 | % if isa(kmli.icon,'kml_iconstyle')
|
|---|
| 231 | % sbuf=kml_swrite(kmli.icon,sbuf,[indent ' ']);
|
|---|
| 232 | % else
|
|---|
| 233 | % warning('kml(%d).icon is a ''%s'' class object, not ''%s''.',...
|
|---|
| 234 | % i,class(kmli.icon),'kml_iconstyle');
|
|---|
| 235 | % end
|
|---|
| 236 | % if isa(kmli.label,'kml_labelstyle')
|
|---|
| 237 | % sbuf=kml_swrite(kmli.label,sbuf,[indent ' ']);
|
|---|
| 238 | % else
|
|---|
| 239 | % warning('kml(%d).label is a ''%s'' class object, not ''%s''.',...
|
|---|
| 240 | % i,class(kmli.label),'kml_labelstyle');
|
|---|
| 241 | % end
|
|---|
| 242 | if isa(kmli.line,'kml_linestyle')
|
|---|
| 243 | sbuf=kml_swrite(kmli.line,sbuf,[indent ' ']);
|
|---|
| 244 | else
|
|---|
| 245 | warning('kml(%d).line is a ''%s'' class object, not ''%s''.',...
|
|---|
| 246 | i,class(kmli.line),'kml_linestyle');
|
|---|
| 247 | end
|
|---|
| 248 | if isa(kmli.poly,'kml_polystyle')
|
|---|
| 249 | sbuf=kml_swrite(kmli.poly,sbuf,[indent ' ']);
|
|---|
| 250 | else
|
|---|
| 251 | warning('kml(%d).poly is a ''%s'' class object, not ''%s''.',...
|
|---|
| 252 | i,class(kmli.poly),'kml_polystyle');
|
|---|
| 253 | end
|
|---|
| 254 | % if isa(kmli.balloon,'kml_balloonstyle')
|
|---|
| 255 | % sbuf=kml_swrite(kmli.balloon,sbuf,[indent ' ']);
|
|---|
| 256 | % else
|
|---|
| 257 | % warning('kml(%d).balloon is a ''%s'' class object, not ''%s''.',...
|
|---|
| 258 | % i,class(kmli.balloon),'kml_balloonstyle');
|
|---|
| 259 | % end
|
|---|
| 260 | % if isa(kmli.list,'kml_liststyle')
|
|---|
| 261 | % sbuf=kml_swrite(kmli.list,sbuf,[indent ' ']);
|
|---|
| 262 | % else
|
|---|
| 263 | % warning('kml(%d).list is a ''%s'' class object, not ''%s''.',...
|
|---|
| 264 | % i,class(kmli.list),'kml_liststyle');
|
|---|
| 265 | % end
|
|---|
| 266 | sbuf=add(sbuf,sprintf('%s</Style>\n',indent));
|
|---|
| 267 | end
|
|---|
| 268 |
|
|---|
| 269 | end
|
|---|
| 270 |
|
|---|
| 271 | % delete the object
|
|---|
| 272 |
|
|---|
| 273 | function []=delete(kml)
|
|---|
| 274 |
|
|---|
| 275 | % loop over the styles
|
|---|
| 276 |
|
|---|
| 277 | for i=numel(kml):-1:1
|
|---|
| 278 | kmli=kml(i);
|
|---|
| 279 | % if isa(kmli.icon,'kml_iconstyle')
|
|---|
| 280 | % delete(kmli.icon);
|
|---|
| 281 | % else
|
|---|
| 282 | % warning('kml(%d).icon is a ''%s'' class object, not ''%s''.',...
|
|---|
| 283 | % i,class(kmli.icon),'kml_iconstyle');
|
|---|
| 284 | % end
|
|---|
| 285 | % kmli.icon =kml_iconstyle.empty();
|
|---|
| 286 | % if isa(kmli.label,'kml_labelstyle')
|
|---|
| 287 | % delete(kmli.label);
|
|---|
| 288 | % else
|
|---|
| 289 | % warning('kml(%d).label is a ''%s'' class object, not ''%s''.',...
|
|---|
| 290 | % i,class(kmli.label),'kml_labelstyle');
|
|---|
| 291 | % end
|
|---|
| 292 | % kmli.label =kml_labelstyle.empty();
|
|---|
| 293 | if isa(kmli.line,'kml_linestyle')
|
|---|
| 294 | delete(kmli.line);
|
|---|
| 295 | else
|
|---|
| 296 | warning('kml(%d).line is a ''%s'' class object, not ''%s''.',...
|
|---|
| 297 | i,class(kmli.line),'kml_linestyle');
|
|---|
| 298 | end
|
|---|
| 299 | kmli.line =kml_linestyle.empty();
|
|---|
| 300 | if isa(kmli.poly,'kml_polystyle')
|
|---|
| 301 | delete(kmli.poly);
|
|---|
| 302 | else
|
|---|
| 303 | warning('kml(%d).poly is a ''%s'' class object, not ''%s''.',...
|
|---|
| 304 | i,class(kmli.poly),'kml_polystyle');
|
|---|
| 305 | end
|
|---|
| 306 | kmli.poly =kml_polystyle.empty();
|
|---|
| 307 | % if isa(kmli.balloon,'kml_balloonstyle')
|
|---|
| 308 | % delete(kmli.balloon);
|
|---|
| 309 | % else
|
|---|
| 310 | % warning('kml(%d).balloon is a ''%s'' class object, not ''%s''.',...
|
|---|
| 311 | % i,class(kmli.balloon),'kml_balloonstyle');
|
|---|
| 312 | % end
|
|---|
| 313 | % kmli.balloon =kml_balloonstyle.empty();
|
|---|
| 314 | % if isa(kmli.list,'kml_liststyle')
|
|---|
| 315 | % delete(kmli.list);
|
|---|
| 316 | % else
|
|---|
| 317 | % warning('kml(%d).list is a ''%s'' class object, not ''%s''.',...
|
|---|
| 318 | % i,class(kmli.list),'kml_liststyle');
|
|---|
| 319 | % end
|
|---|
| 320 | % kmli.list =kml_liststyle.empty();
|
|---|
| 321 | end
|
|---|
| 322 |
|
|---|
| 323 | end
|
|---|
| 324 |
|
|---|
| 325 | end
|
|---|
| 326 |
|
|---|
| 327 | end
|
|---|
| 328 |
|
|---|