Skip to content

Commit

Permalink
Merge branch 'release/v3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer committed May 23, 2022
2 parents f9837cf + 25d3500 commit 0a06eae
Show file tree
Hide file tree
Showing 218 changed files with 10,431 additions and 6,015 deletions.
8 changes: 0 additions & 8 deletions +FMIKit/getBlockDialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
block = get_param(block, 'Handle');
end

% check library version
libraryVersion = char(fmikit.ui.FMUBlockDialog.FMI_KIT_VERSION);

% still using the 2.7 format for userData struct
if ~strcmp(fmikit.ui.FMUBlockDialog.FMI_KIT_VERSION, '2.7')
error(['Wrong fmikit.jar version. Expected 2.7 but was ' libraryVersion '.'])
end

dialog = javaMethod('getDialog', 'fmikit.ui.FMUBlockDialog', block);

end
18 changes: 0 additions & 18 deletions +FMIKit/getInportLabels.m

This file was deleted.

18 changes: 0 additions & 18 deletions +FMIKit/getOutportLabels.m

This file was deleted.

7 changes: 5 additions & 2 deletions +FMIKit/getStartValue.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
% returns the start value of variable 'step' or '' if no start
% value is defined.

assert(strcmp(get_param(block, 'ReferenceBlock'), 'FMIKit_blocks/FMU'), 'Block is not an FMU')
assert(ischar(variableName), 'variableName must be a string')
userData = getUserData(block);

assert(~isempty(userData), 'Block is not an FMU');

assert(ischar(variableName), 'variableName must be a string');

dialog = FMIKit.showBlockDialog(block, false);

Expand Down
19 changes: 8 additions & 11 deletions +FMIKit/initialize.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ function initialize()
% add the FMIKit folder to the MATLAB path
addpath(folder);

% add the src folder to the MATLAB path
if isempty(which('FMU.cpp'))
src_folder = fullfile(folder, 'src');
if exist(src_folder, 'dir')
addpath(src_folder);
msg = true;
end
end

% add the GRTFMI target to the MATLAB path
if isempty(which('grtfmi.tlc'))
grtfmi_folder = fullfile(folder, 'grtfmi');
Expand Down Expand Up @@ -65,6 +56,13 @@ function initialize()
msg = true;
end

% check fmikit.jar version
jarVersion = char(fmikit.ui.FMUBlockDialog.FMI_KIT_VERSION);
if ~strcmp(jarVersion, FMIKit.version)
error(['Wrong fmikit.jar version. Expected ' FMIKit.version ...
' but was ' jarVersion '.'])
end

% delete re-saved block library
close_system('FMIKit_blocks', 0);
library_file = fullfile(folder, 'FMIKit_blocks.slx');
Expand Down Expand Up @@ -99,8 +97,7 @@ function initialize()
end

if msg
disp(['Initializing FMI Kit ' [num2str(FMIKit.majorVersion) '.' ...
num2str(FMIKit.minorVersion) '.' num2str(FMIKit.patchVersion)]])
disp(['Initializing FMI Kit ' FMIKit.version])

% check MATLAB version
rel = version('-release');
Expand Down
15 changes: 15 additions & 0 deletions +FMIKit/isResettable.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function resettable = isResettable(block)
% FMIKit.isResettable True if the FMU block is resettable
%
% Example:
%
% resettable = FMIKit.isResettable(gcb)
resettable = false;

userData = getUserData(block);

if ~isempty(userData)
resettable = userData.resettable;
end

end
6 changes: 0 additions & 6 deletions +FMIKit/majorVersion.m

This file was deleted.

6 changes: 0 additions & 6 deletions +FMIKit/minorVersion.m

This file was deleted.

6 changes: 0 additions & 6 deletions +FMIKit/patchVersion.m

This file was deleted.

47 changes: 43 additions & 4 deletions +FMIKit/private/applyDialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,51 @@ function applyDialog(dialog)

%#ok<*AGROW>

block = dialog.blockHandle;

% break the library link
set_param(block, 'LinkStatus', 'none');

mask = Simulink.Mask.get(block);

mask.removeAllParameters();

userData = dialog.getUserData();

% add dialog parameters
for i = 0:userData.startValues.size()-1
p = userData.startValues.get(i);
mask.addParameter(...
'Name', char(p.name), ...
'Prompt', char(p.prompt), ...
'Value', char(p.value));
end

% set the user data
userData = userDataToStruct(dialog.getUserData());
set_param(dialog.blockHandle, 'UserData', userData, 'UserDataPersistent', 'on');
set_param(block, 'UserData', userData, 'UserDataPersistent', 'on');

% set the S-function parameters
FMIKit.setSFunctionParameters(dialog.blockHandle)
FMIKit.setSFunctionParameters(block)

% draw the port labels
display = '';

ports = get_param(block, 'Ports');

for i = 1:min(numel(userData.inputPorts), ports(1))
display = [display 'port_label(''input'', ' num2str(i) ', ''' userData.inputPorts(i).label ''');' sprintf('\n')];
end

if FMIKit.isResettable(gcb)
display = [display 'port_label(''input'', ' num2str(ports(1)) ', ''reset'');' sprintf('\n')];
end

for i = 1:min(numel(userData.outputPorts), ports(2))
display = [display 'port_label(''output'', ' num2str(i) ', ''' userData.outputPorts(i).label ''');' sprintf('\n')];
end

mask.Display = display;

if userData.useSourceCode

Expand All @@ -28,7 +67,7 @@ function applyDialog(dialog)
% mex_args{end+1} = '-g';

% custom inlcude directories
include_dirs = get_param(gcs, 'SimUserIncludeDirs');
include_dirs = get_param(bdroot, 'SimUserIncludeDirs');
include_dirs = split_paths(include_dirs);
for i = 1:numel(include_dirs)
mex_args{end+1} = ['-I"' include_dirs{i} '"'];
Expand All @@ -40,7 +79,7 @@ function applyDialog(dialog)
end

% custom libraries
libraries = get_param(gcs, 'SimUserLibraries');
libraries = get_param(bdroot, 'SimUserLibraries');
libraries = split_paths(libraries);
for i = 1:numel(libraries)
[library_path, library_name, ~] = fileparts(libraries{i});
Expand Down
57 changes: 7 additions & 50 deletions +FMIKit/private/getUserData.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,17 @@
return
end

if any(strcmp(userData.fmiKitVersion, {'2.4', '2.6'}))
mask = Simulink.Mask.get(block);

disp(['Updating ' getfullname(block) ' that was imported with an older version of FMI Kit.'])
userData.startValues = containers.Map;

userData.fmiKitVersion = '2.7';
set_param(block, 'UserData', userData);

% re-import the FMU
dialog = FMIKit.showBlockDialog(block, false);
dialog.loadFMU(false);
applyDialog(dialog);

model = bdroot(block);
set_param(model, 'Dirty', 'on');

disp('Save the model to apply the changes.')

userData = get_param(block, 'UserData');

end

if ~isfield(userData, 'relativeTolerance')
disp(['Adding userData.relativeTolerance to ' getfullname(block)])
userData.relativeTolerance = '0';
set_param(block, 'UserData', userData, 'UserDataPersistent', 'on')
save_system
end

if ~isfield(userData, 'logFMICalls')
disp(['Adding userData.logFMICalls to ' getfullname(block)])
userData.logFMICalls = false;
set_param(block, 'UserData', userData, 'UserDataPersistent', 'on')
save_system
end

if ~isfield(userData, 'logLevel')
disp(['Adding userData.logLevel to ' getfullname(block)])
userData.logLevel = 0;
set_param(block, 'UserData', userData, 'UserDataPersistent', 'on')
save_system
end

if ~isfield(userData, 'logFile')
disp(['Adding userData.logFile to ' getfullname(block)])
userData.logFile = '';
set_param(block, 'UserData', userData, 'UserDataPersistent', 'on')
save_system
for i = 1:numel(mask.Parameters)
parameter = mask.Parameters(i);
userData.startValues(parameter.Prompt) = parameter.Value;
end

if ~isfield(userData, 'logToFile')
disp(['Adding userData.logToFile to ' getfullname(block)])
userData.logToFile = false;
set_param(block, 'UserData', userData, 'UserDataPersistent', 'on')
save_system
if ~strcmp(userData.fmiKitVersion, FMIKit.version)
error([getfullname(block) ' was imported with an incompatible version of FMI Kit. Please re-import the FMU.']);
end

end
7 changes: 1 addition & 6 deletions +FMIKit/private/userDataFromStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@
userData.outputPorts.add(port);
end

for key = keys(ud.startValues)
userData.startValues.put(...
java.lang.String(key{1}), ...
java.lang.String(ud.startValues(key{1})));
end

userData.useSourceCode = ud.useSourceCode;
userData.functionName = ud.functionName;
userData.parameters = ud.parameters;
userData.resettable = ud.resettable;

end
10 changes: 3 additions & 7 deletions +FMIKit/private/userDataToStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
'startValues', containers.Map, ...
'useSourceCode', [], ...
'functionName', [], ...
'parameters', [] ...
'parameters', [], ...
'resettable', [] ...
);

% TODO: check version
Expand Down Expand Up @@ -53,14 +54,9 @@
end
end

it = userData.startValues.entrySet().iterator();
while it.hasNext()
entry = it.next();
ud.startValues(entry.getKey()) = entry.getValue();
end

ud.useSourceCode = userData.useSourceCode;
ud.functionName = char(userData.functionName);
ud.parameters = char(userData.parameters);
ud.resettable = userData.resettable;

end
20 changes: 20 additions & 0 deletions +FMIKit/setResettable.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function setResettable(block, resettable)
% FMIKit.setResettable Enable the resettable option of an FMU block.
%
% Example:
%
% FMIKit.setResettable(gcb, true)

assert(strcmp(get_param(block, 'ReferenceBlock'), 'FMIKit_blocks/FMU'), 'Block is not an FMU')

userData = getUserData(block);

userData.resettable = resettable;

set_param(block, 'UserData', userData, 'UserDataPersistent', 'on');

dialog = FMIKit.showBlockDialog(block, false);

applyDialog(dialog);

end
Loading

0 comments on commit 0a06eae

Please sign in to comment.