classdef SCDclass_component % Superclass for SCD component % Can be a wrapper or a node or all SCD % Anything that has a model, a data dictionary % and optionally an associated algorithm properties loadverbose = 1; end properties (SetAccess = private) name % name mdlname % simulink model name ddname % data dictionary name algos % algorithms contained in this wrapper end properties (Abstract=true) type % set by subclasses end methods function obj = SCDclass_component(name) obj.name = name; obj.algos = []; obj.ddname = [name,'.sldd']; obj.mdlname = [name,'.slx']; assert(~isempty(which(obj.mdlname)),... 'could not find %s for SCD component %s',obj.mdlname,obj.name) end function obj = addalgo(obj,algo) assert(isa(algo,'SCDclass_algo')); obj.algos = [obj.algos;algo]; end function obj = linkalgodd(obj) % Set up data dictionary to link to all algo data % dictionaries as data sources % wrapper data dictionary ddObj = Simulink.data.dictionary.open(obj.ddname); % already linked sources prevsources = ddObj.DataSources; prevsources_algo = prevsources(startsWith(prevsources,'SCDalgo')); % make algo data dictionary list list reqsources = cell(numel(obj.algos),1); for ii=1:numel(obj.algos) myalgo = obj.algos(ii); reqsources{ii} = myalgo.getdatadictionary; end % removing unnecessary ones for ii=1:numel(prevsources_algo) mysource = prevsources_algo{ii}; if ~contains(reqsources,mysource) obj.printlog('Removing algorithm data source %s from %s',mysource,obj.ddname); ddObj.removeDataSource(prevsources_algo{ii}) end end % add new ones not yet present for ii=1:numel(reqsources) mysource = reqsources{ii}; assert(startsWith(mysource,'SCDalgo'),... 'attempting to add algo dd: %s that does not start with ''SCDalgo''-aborting',mysource); if contains(prevsources,mysource) obj.printlog('Not adding algorithm data source %s - already exists',mysource); else obj.printlog('Adding algorithm data source %s to %s',mysource,obj.ddname); ddObj.addDataSource(mysource); end end end function obj=printlog(obj,str,varargin) % printlog, allows sprintf()-like expressions if obj.loadverbose==1 fprintf('%s:%s, ',obj.type,obj.name); fprintf(str,varargin{:}); fprintf('\n'); end end end end