Skip to content
Snippets Groups Projects
Commit 1d057a42 authored by Marco Luigi Gaibotti's avatar Marco Luigi Gaibotti
Browse files

[chad-updates] Mission now adds corresponding path automatically

When setting the mission name, the corresponding mission gets added to the MATLAB path, while others are removed.

To disable this, set 'changeMatlabPath' to false during creation of the mission
parent f540fdfe
No related branches found
No related tags found
1 merge request!16[chad-updates] Added useful properties and methods for chad
......@@ -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)
......
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