source: issm/trunk/src/m/kml/kml_feature.m@ 6456

Last change on this file since 6456 was 6456, checked in by jschierm, 14 years ago

Probably should test before checking in...

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