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);
|
---|
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 | % set the properties of the object
|
---|
100 |
|
---|
101 | function [kml]=set(kml,varargin)
|
---|
102 |
|
---|
103 | kmlref=feval(class(kml));
|
---|
104 |
|
---|
105 | % loop through each parameter in the input list (comparing to the reference
|
---|
106 | % object in case property types have been changed)
|
---|
107 |
|
---|
108 | for i=1:2:length(varargin)
|
---|
109 | if isfield(kmlref,varargin{i})
|
---|
110 | if isa(varargin{i+1},class(kmlref.(varargin{i})))
|
---|
111 | kml.(varargin{i})=varargin{i+1};
|
---|
112 | else
|
---|
113 | if ~isempty(inputname(i+1))
|
---|
114 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
115 | inputname(i+1),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
116 | else
|
---|
117 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
118 | i+1 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
119 | end
|
---|
120 | end
|
---|
121 | else
|
---|
122 | warning('Property ''%s'' for class ''%s'' does not exist.',...
|
---|
123 | varargin{i},class(kmlref));
|
---|
124 | end
|
---|
125 | end
|
---|
126 |
|
---|
127 | end
|
---|
128 |
|
---|
129 | % write the object
|
---|
130 |
|
---|
131 | function []=kml_write(kml,fid,indent)
|
---|
132 |
|
---|
133 | if ~exist('fid','var') || isempty(fid)
|
---|
134 | fid=1;
|
---|
135 | end
|
---|
136 | if ~exist('indent','var') || isempty(indent)
|
---|
137 | indent='';
|
---|
138 | end
|
---|
139 |
|
---|
140 | % loop over the features
|
---|
141 |
|
---|
142 | for i=1:numel(kml)
|
---|
143 | if strcmp(class(kml),'kml_feature')
|
---|
144 | if ~isempty(kml(i).id)
|
---|
145 | fprintf(fid,'%s<!Feature id="%s">\n',indent,kml(i).id);
|
---|
146 | else
|
---|
147 | fprintf(fid,'%s<!Feature>\n',indent);
|
---|
148 | end
|
---|
149 | end
|
---|
150 | kml_write@kml_object(kml(i),fid,indent);
|
---|
151 | if ~isempty(kml(i).name)
|
---|
152 | fprintf(fid,'%s <name>%s</name>\n',indent,kml(i).name);
|
---|
153 | end
|
---|
154 | fprintf(fid,'%s <visibility>%d</visibility>\n',indent,kml(i).visibility);
|
---|
155 | fprintf(fid,'%s <open>%d</open>\n',indent,kml(i).open);
|
---|
156 | if ~isempty(kml(i).snippet)
|
---|
157 | fprintf(fid,'%s <Snippet maxLines="2">%s</Snippet>\n',indent,kml(i).snippet);
|
---|
158 | end
|
---|
159 | if ~isempty(kml(i).descript)
|
---|
160 | fprintf(fid,'%s <description>%s</description>\n',indent,kml(i).descript);
|
---|
161 | end
|
---|
162 | if ~isempty(kml(i).styleurl)
|
---|
163 | fprintf(fid,'%s <styleUrl>%s</styleUrl>\n',indent,kml(i).styleurl);
|
---|
164 | end
|
---|
165 |
|
---|
166 | % loop over the styles for each feature
|
---|
167 |
|
---|
168 | for j=1:numel(kml(i).style)
|
---|
169 | if ~isempty(kml(i).style{j})
|
---|
170 | if isa(kml(i).style{j},'kml_styleselector')
|
---|
171 | kml_write(kml(i).style{j},fid,[indent ' ']);
|
---|
172 | else
|
---|
173 | warning('kml(%d).style{%d} is a ''%s'' class object, not ''%s''.',...
|
---|
174 | i,j,class(kml(i).style{j}),'kml_styleselector');
|
---|
175 | end
|
---|
176 | end
|
---|
177 | end
|
---|
178 |
|
---|
179 | if strcmp(class(kml),'kml_feature')
|
---|
180 | fprintf(fid,'%s<!/Feature>\n',indent);
|
---|
181 | end
|
---|
182 | end
|
---|
183 |
|
---|
184 | end
|
---|
185 |
|
---|
186 | end
|
---|
187 |
|
---|
188 | end
|
---|
189 |
|
---|