diff --git a/classes/Mission.m b/classes/Mission.m index 3b5cb60506475ba64b191c83e72a806dfc2ef5ed..25b1eacfaf872d1f9adc39b94eb550516a2ca167 100644 --- a/classes/Mission.m +++ b/classes/Mission.m @@ -24,12 +24,14 @@ classdef Mission < Config properties(Access = protected) configName = 'missionConfig.m' variableName = '' + changeMatlabPath (1,1) logical end methods - function obj = Mission(mission) + function obj = Mission(mission, options) arguments mission {mustBeA(mission, {'logical', 'string', 'char'})} = false + options.changeMatlabPath = true; end if nargin == 0 @@ -39,6 +41,7 @@ classdef Mission < Config filePath = fullfile(fileparts(mfilename("fullpath")), '..', 'missions'); filePath = trimPath(filePath); + obj.changeMatlabPath = options.changeMatlabPath; obj.currentPath = filePath; if isa(mission, 'char') || isa(mission, 'string') obj.name = mission; @@ -70,20 +73,11 @@ classdef Mission < Config obj.name = name; end obj.updatePath(); + obj.updateMatlabPath(); end end methods(Access = protected) - function updatePath(obj) - if isempty(obj.name) || isempty(obj.currentPath), return; end - - obj.configPath = fullfile(obj.currentPath, obj.name, 'config'); - obj.dataPath = fullfile(obj.currentPath, obj.name, 'data'); - obj.msaPath = trimPath( ... - fullfile(obj.currentPath, '..', '..', '..', 'msa-toolkit') ... - ); - end - function loadConfig(obj) fileName = obj.configName; filePath = obj.currentPath; @@ -97,6 +91,39 @@ classdef Mission < Config configObj = eval(varName); obj.name = configObj.name; end + + function updatePath(obj) + if isempty(obj.name) || isempty(obj.currentPath), return; end + + obj.configPath = fullfile(obj.currentPath, obj.name, 'config'); + obj.dataPath = fullfile(obj.currentPath, obj.name, 'data'); + obj.msaPath = trimPath( ... + fullfile(obj.currentPath, '..', '..', '..', 'msa-toolkit') ... + ); + end + + function updateMatlabPath(obj) + if isempty(obj.name) || isempty(obj.currentPath), return; end + if ~obj.changeMatlabPath, return; end + matlabPath = path; + % Checking if other missions are in path + pattern = 'missions\\[^\\/]*;'; % Matches any config folder under mission in path + missionsInPath = regexp(matlabPath, pattern); + % Checking if right mission is in path + pattern = strcat('missions[\\/]', obj.name,';'); + missionInPath = regexp(matlabPath, pattern, 'once'); + + if length(missionsInPath) > 1 || isempty(missionInPath) + warning('off'); + rmpath( ... + genpath(obj.currentPath)); + addpath( ... + obj.currentPath, ... + genpath( ... + fullfile(obj.currentPath, obj.name))); + warning('on'); + end + end end methods(Static, Access = protected)