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