CATIA-Systems / FMIKit-Simulink

Import and export Functional Mock-up Units with Simulink
Other
157 stars 51 forks source link

Avoid adding duplicate paths to build info #192

Closed Marvin-TMG closed 4 years ago

Marvin-TMG commented 4 years ago

FMIKit regularly adds duplicate paths when clicking apply or OK in the dialog box. A more robust check is needed to see if the path is already in the list of existing paths, before adding it.

For exmaple, the build paths below were all automatically added by the latest version of FMIKit:

"C:\WORK\Git\FMIKit-Simulink-2.8\include" "C:\Users\struijm\Desktop\DymolaSimulink\Simulink\HPCmodel_0Valve_0IO_Patch\sources" "C:\Users\struijm\Desktop\DymolaSimulink\Simulink\TS050_Internal_Chassis\sources" "C:\WORK\Git\FMIKit-Simulink-2.8\include" "C:\Users\struijm\Desktop\DymolaSimulink\Simulink\TS050_Internal_Chassis\sources"

Marvin-TMG commented 4 years ago

There is a better way of doing it, but for now I just changed the function setSrcParam in setSFunctionParameters as follows:

function setSrcParam(object, name, value)
value = strrep(value, '" "', '"|||"');
values = strsplit(value, '|||');
for i = 1 : length(values)
    value = values{i};
    if ~isempty(value)
        old_value = get_param(object, name);
        if ~contains(old_value, value)
            new_value = [old_value ' ' value];
            set_param(object, name, new_value);
        end
    end
end
end
Marvin-TMG commented 4 years ago

There is a problem with this code, when there is no RTW, the code needs to be wrapped in a try catch or something:

Error using FMIKit.setSFunctionParameters>setSrcParams (line 68) Cannot change 'CustomInclude' when 'Use the same custom code settings as Simulation Target' is checked.

Error in FMIKit.setSFunctionParameters (line 51) setSrcParams(mdl, 'CustomInclude', include_dirs);

Error in applyDialog (line 10) FMIKit.setSFunctionParameters(dialog.blockHandle)

Error in FMIKit.showBlockDialog>okButtonClicked (line 60) applyDialog(dialog);

Marvin-TMG commented 4 years ago

Thanks, this works!