Skip to content
Snippets Groups Projects
Commit 5f73506d authored by Federico Felici's avatar Federico Felici
Browse files

Cleanups & split bus definition code

parent a97f3737
No related branches found
No related tags found
No related merge requests found
......@@ -133,19 +133,20 @@ classdef SCDclass_algo
designDataObj = getSection(dict, 'Design Data');
end
function dictionaryObj = createdatadictionary(obj,varargin)
function createdatadictionary(obj,varargin)
% create data dictionary in path obj.folder/obj.getdatadictionary
dd = obj.getdatadictionary;
ddpath = fullfile(obj.folder,dd);
% Close all open models.
bdclose all
% Close all open data dictionaries
Simulink.data.dictionary.closeAll('-discard');
% Create if not existing already
if isempty(ddpath)
if isempty(which(ddpath))
fprintf('generating data dictionary %s\n',fullfile(obj.folder,obj.getdatadictionary));
dictionaryObj = Simulink.data.dictionary.create(ddpath);
else
dictionaryObj = Simulink.data.dictionary.open(ddpath);
fprintf('Data dictionary %s already exists, not created\n',ddpath);
Simulink.data.dictionary.create(ddpath);
end
end
......@@ -181,6 +182,8 @@ classdef SCDclass_algo
if nargin==3
assert(isa(default_function, 'function_handle'),'SCDclass_algo:addtunparamstruct', 'third argument, if present, must be a function handle');
obj.exportedtpsdefaults{end+1} = default_function; % add defaults to list
else
obj.exportedtpsdefaults{end+1} = []; % empty, no default assigned for this tp
end
end
......@@ -259,6 +262,32 @@ classdef SCDclass_algo
evalin('base','clear temp;');
end
function addbuses(obj)
% Add buses to data dictionary from .m file descriptions, if
% available. Bus names in obj.inBus, obj.outBus
if ~isempty(which(obj.inBus)) && ~isempty(which(obj.outBus))
designDataObj = opendatadictionarydesigndata(obj);
fprintf('Add buses to data dictionary: %s, %s\n',obj.inBus,obj.outBus);
eval(obj.inBus); % eval buses in base workspace
eval(obj.outBus);
if ~designDataObj.exist(obj.inBus)
addEntry(designDataObj,obj.inBus ,evalin('base',obj.inBus ));
else
entryObj = getEntry(designDataObj,obj.inBus);
setValue(entryObj,evalin('base',obj.inBus ));
end
if ~designDataObj.exist(obj.outBus)
addEntry(designDataObj,obj.outBus,evalin('base',obj.outBus));
else
entryObj = getEntry(designDataObj,obj.outBus);
setValue(entryObj,evalin('base',obj.outBus));
end
evalin('base',sprintf('clear %s %s',obj.inBus,obj.outBus));
else
fprintf('no buses imported in datadictionary - assuming they are already there\n')
end
end
%% MDS container methods forwarders
function obj = addparameter(obj, param)
......@@ -359,8 +388,7 @@ classdef SCDclass_algo
function init(obj)
% generate/initialize data dictionary
dictionaryObj = obj.createdatadictionary;
designDataObj = opendatadictionarydesigndata(obj);
obj.createdatadictionary;
obj.callinits; % call generic algorithm init functions
......@@ -375,23 +403,19 @@ classdef SCDclass_algo
obj.updatetemplatetp;
% add buses
if ~isempty(which(obj.inBus)) && ~isempty(which(obj.outBus))
fprintf('Add buses to data dictionary: %s, %s\n',obj.inBus,obj.outBus);
eval(obj.inBus); % eval buses in base workspace
eval(obj.outBus);
addEntry(designDataObj,obj.inBus ,evalin('base',obj.inBus ));
addEntry(designDataObj,obj.outBus,evalin('base',obj.outBus));
evalin('base',sprintf('clear %s %s',obj.inBus,obj.outBus));
else
fprintf('no buses imported in datadictionary - assuming they are already there\n')
end
obj.addbuses;
% add configurations.sldd as referenced data dictionary, plus
% other optional data dictionaries (e.g. used by lower-level components of an algorithm)
for refdd = ['configurations.sldd',obj.refdatadictionaries]
dictionaryObj = Simulink.data.dictionary.open(obj.getdatadictionary);
fprintf('adding referenced data dictionary %s to %s \n',refdd{:},obj.getdatadictionary)
refddpath = which(refdd{:});
assert(~isempty(refddpath),'could not find %s');
dictionaryObj.addDataSource(refdd{:});
end
dictionaryObj.saveChanges;
end
function callinits(obj)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment