[6454] | 1 | %
|
---|
| 2 | % definition for the kml_geometry super (base) and sub (derived) class.
|
---|
| 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 | %
|
---|
| 13 | classdef kml_geometry < kml_object
|
---|
| 14 | properties
|
---|
| 15 | end
|
---|
| 16 |
|
---|
| 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
|
---|
| 35 | fnames=fieldnames(kml);
|
---|
| 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 |
|
---|
[6455] | 75 | % set the properties of the object
|
---|
| 76 |
|
---|
| 77 | function [kml]=set(kml,varargin)
|
---|
| 78 |
|
---|
| 79 | kmlref=feval(class(kml));
|
---|
| 80 |
|
---|
| 81 | % loop through each parameter in the input list (comparing to the reference
|
---|
| 82 | % object in case property types have been changed)
|
---|
| 83 |
|
---|
| 84 | for i=1:2:length(varargin)
|
---|
| 85 | if isfield(kmlref,varargin{i})
|
---|
| 86 | if isa(varargin{i+1},class(kmlref.(varargin{i})))
|
---|
| 87 | kml.(varargin{i})=varargin{i+1};
|
---|
| 88 | else
|
---|
| 89 | if ~isempty(inputname(i+1))
|
---|
| 90 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
| 91 | inputname(i+1),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
| 92 | else
|
---|
| 93 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
| 94 | i+1 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
| 95 | end
|
---|
| 96 | end
|
---|
| 97 | else
|
---|
| 98 | warning('Property ''%s'' for class ''%s'' does not exist.',...
|
---|
| 99 | varargin{i},class(kmlref));
|
---|
| 100 | end
|
---|
| 101 | end
|
---|
| 102 |
|
---|
| 103 | end
|
---|
| 104 |
|
---|
[6454] | 105 | % write the object
|
---|
| 106 |
|
---|
| 107 | function []=kml_write(kml,fid,indent)
|
---|
| 108 |
|
---|
| 109 | if ~exist('fid','var') || isempty(fid)
|
---|
| 110 | fid=1;
|
---|
| 111 | end
|
---|
| 112 | if ~exist('indent','var') || isempty(indent)
|
---|
| 113 | indent='';
|
---|
| 114 | end
|
---|
| 115 |
|
---|
| 116 | % loop over the geometries
|
---|
| 117 |
|
---|
| 118 | for i=1:numel(kml)
|
---|
| 119 | if strcmp(class(kml),'kml_geometry')
|
---|
| 120 | if ~isempty(kml(i).id)
|
---|
| 121 | fprintf(fid,'%s<!Geometry id="%s">\n',indent,kml(i).id);
|
---|
| 122 | else
|
---|
| 123 | fprintf(fid,'%s<!Geometry>\n',indent);
|
---|
| 124 | end
|
---|
| 125 | end
|
---|
| 126 | kml_write@kml_object(kml(i),fid,indent);
|
---|
| 127 | if strcmp(class(kml),'kml_geometry')
|
---|
| 128 | fprintf(fid,'%s</!Geometry>\n',indent);
|
---|
| 129 | end
|
---|
| 130 | end
|
---|
| 131 |
|
---|
| 132 | end
|
---|
| 133 |
|
---|
| 134 | end
|
---|
| 135 |
|
---|
| 136 | end
|
---|
| 137 |
|
---|