source: issm/trunk/src/m/kml/kml_geometry.m@ 13975

Last change on this file since 13975 was 13975, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 13974

File size: 5.7 KB
RevLine 
[6454]1%
[7460]2% definition for the kml_geometry super (base) and sub (derived) abstract class.
[6454]3%
4% [kml]=kml_geometry(varargin)
5%
6% where the optional varargin and defaults are:
7% id (char, geometry id, '')
8%
9% note that zero arguments constructs a default instance; one
10% argument of the class copies the instance; and two or more
11% arguments constructs a new instance from the arguments.
12%
13classdef kml_geometry < kml_object
14 properties
15 end
[13975]16
[6454]17 methods
18 function [kml]=kml_geometry(varargin)
19
20 kml=kml@kml_object(varargin{:});
21
22 switch nargin
23
24% create a default object
25
26 case 0
27
28% copy the object or create the object from the input
29
30 otherwise
31 if (nargin == 1) && isa(varargin{1},class(kml))
32 kml=varargin{1};
33
34 else
[6480]35 fnames=fieldnames(kml_geometry());
[6454]36
37 for i=length(fieldnames(kml_object()))+1:min(nargin,length(fnames))
38 if isa(varargin{i},class(kml.(fnames{i})))
39 if ~isempty(varargin{i})
40 kml.(fnames{i})=varargin{i};
41 end
42 else
43 if ~isempty(inputname(i))
[6455]44 warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
[6454]45 inputname(i),fnames{i},class(varargin{i}),class(kml.(fnames{i})));
46 else
[6455]47 warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
[6454]48 i ,fnames{i},class(varargin{i}),class(kml.(fnames{i})));
49 end
50 end
51 end
52 end
53
54 end
55
56 end
57
58% display the object
59
60 function []=disp(kml)
61
62 for i=1:numel(kml)
63 if strcmp(class(kml),'kml_geometry')
64 disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
65 class(kml),inputname(1),string_dim(kml,i)));
66 end
67 disp@kml_object(kml(i));
68 if strcmp(class(kml),'kml_geometry')
69 disp(sprintf('\n'));
70 end
71 end
72
73 end
74
[6479]75% return the fieldnames of the object
76
77 function [fnames]=fieldnames(kml)
78
79% fieldnames for a sub (derived) class list those before super (base)
80
81 fnames=fieldnames(kml_object());
82
83 end
84
[6455]85% set the properties of the object
86
[7460]87 function [kml]=setprops(kml,varargin)
[6455]88
89 kmlref=feval(class(kml));
[6456]90 fnames=fieldnames(kmlref);
[6455]91
92% loop through each parameter in the input list (comparing to the reference
93% object in case property types have been changed)
94
95 for i=1:2:length(varargin)
[6456]96 if ismember(varargin{i},fnames) && (i+1 <= length(varargin))
[6455]97 if isa(varargin{i+1},class(kmlref.(varargin{i})))
98 kml.(varargin{i})=varargin{i+1};
99 else
100 if ~isempty(inputname(i+1))
101 warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
[6456]102 inputname(i+2),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
[6455]103 else
104 warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
[6456]105 i+2 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
[6455]106 end
107 end
108 else
109 warning('Property ''%s'' for class ''%s'' does not exist.',...
110 varargin{i},class(kmlref));
111 end
112 end
113
114 end
115
[6454]116% write the object
117
118 function []=kml_write(kml,fid,indent)
119
120 if ~exist('fid','var') || isempty(fid)
121 fid=1;
122 end
123 if ~exist('indent','var') || isempty(indent)
124 indent='';
125 end
126
127% loop over the geometries
128
129 for i=1:numel(kml)
[7460]130 kmli=kml(i);
[6454]131 if strcmp(class(kml),'kml_geometry')
[7460]132 if ~isempty(kmli.id)
133 fprintf(fid,'%s<!Geometry id="%s">\n',indent,kmli.id);
[6454]134 else
135 fprintf(fid,'%s<!Geometry>\n',indent);
136 end
137 end
[7460]138 kml_write@kml_object(kmli,fid,indent);
[6454]139 if strcmp(class(kml),'kml_geometry')
140 fprintf(fid,'%s</!Geometry>\n',indent);
141 end
142 end
143
144 end
[13975]145
[7297]146% string write the object
147
148 function [sbuf]=kml_swrite(kml,sbuf,indent)
149
150 if ~exist('sbuf','var') || isempty(sbuf)
151 sbuf=string_buf;
152 end
153 if ~exist('indent','var') || isempty(indent)
154 indent='';
155 end
156
157% loop over the geometries
158
159 for i=1:numel(kml)
160 kmli=kml(i);
161 if strcmp(class(kml),'kml_geometry')
162 if ~isempty(kmli.id)
163 sbuf=add(sbuf,sprintf('%s<!Geometry id="%s">\n',indent,kmli.id));
164 else
165 sbuf=add(sbuf,sprintf('%s<!Geometry>\n',indent));
166 end
167 end
168 sbuf=kml_swrite@kml_object(kmli,sbuf,indent);
169 if strcmp(class(kml),'kml_geometry')
170 sbuf=add(sbuf,sprintf('%s</!Geometry>\n',indent));
171 end
172 end
173
174 end
[13975]175
[6454]176 end
[13975]177
[6454]178end
Note: See TracBrowser for help on using the repository browser.