diff --git a/+PlotID/@config/config.m b/+PlotID/@config/config.m new file mode 100644 index 0000000000000000000000000000000000000000..359903437691fec8faeebf875babee00651ad42d --- /dev/null +++ b/+PlotID/@config/config.m @@ -0,0 +1,62 @@ +classdef config + %CONFIG class handles methoths and attributes related to the config + %file + % Detailed explanation goes here + + properties (SetAccess = protected) + configData + configFileName + end + + methods + function obj = config(configFileName) + %CONFIG Construct an instance of this class + % Detailed explanation goes here + obj.configFileName = configFileName; + try + txt = fileread(obj.configFileName); + obj.configData = jsondecode(txt); + checkConfig(obj); + catch + msg = ['no valid config File with the filename ',... + obj.configFileName, ' found.' newline,... + 'Please enter the required information manually']; + disp(msg); + obj.configData = obj.wizard('initilise'); + m = input('Do you want to save the config, Y/N [Y]:','s'); + if ismember(m,{'Y','y'}) + obj.writeConfig(fullfile(pwd)); + end + end%try + + end + + function outputArg = checkConfig(obj) + %checkConfig validates the config file + % TODo; + outputArg = true; + end + + function outputArg = writeConfig(obj,path) + %writeConfig writes the config file to path + % TODo; + fid = fopen(fullfile(path,obj.configFileName),'w'); + txt = jsonencode(obj.configData,'PrettyPrint',true); + fprintf(fid,txt); + fclose(fid); + end + + function outputArg = method1(obj,inputArg) + %METHOD1 Summary of this method goes here + % Detailed explanation goes here + outputArg = obj.Property1 + inputArg; + end + + end + + methods (Static) + configStruct = wizard(mode) + optionStruct = plotID_options(input) + end +end + diff --git a/+PlotID/@config/plotID_options.m b/+PlotID/@config/plotID_options.m new file mode 100644 index 0000000000000000000000000000000000000000..74be992b099c0d959b3f95b9541c85fbd2618b88 --- /dev/null +++ b/+PlotID/@config/plotID_options.m @@ -0,0 +1,19 @@ +function [options] = plotID_options(input) +%PLOTID_OPTIONS Summary of this function goes here +% Detailed explanation goes here + +switch input + case 'default' + options = struct(); + options.Location = 'local'; % storage path + options.Method = 'individual'; + options.ParentFolder = 'export'; + options.ConfigFileName = 'config.json';%individual config names possible + options.CopyUserFCN = true; + options.CSV = false; + options.ShowMessages = true; + options.ForcePublish = false; %publish anyway +end + +end + diff --git a/+PlotID/@config/wizard.m b/+PlotID/@config/wizard.m new file mode 100644 index 0000000000000000000000000000000000000000..1b274f48d7ba307712f054e9b71f62d924344506 --- /dev/null +++ b/+PlotID/@config/wizard.m @@ -0,0 +1,39 @@ +function config = wizard(mode) +%wizard creates config files depending on the selected mode +% initilise ask only for the input that is neccessary to run plotID + +config = struct(); +switch mode + case 'initilise' + config.Author = inputRequired('your Name'); + config.ProjectID = inputRequired('your Project Number'); + + msg = ['Do you want to add a remote path?' newline,... + 'Otherwise your files will be stored locally.' newline,... + '>ou can add this later by rerunning the initilisation.']; + disp(msg); + m = input('Do you want add a remothe path, Y/N [Y]:','s'); + + if ismember(m,{'Y','y'}) + config.ServerPath = uigetdir(); + end + otherwise + error('wizard mode undefined in CLASS config'); +end %switch + +end + +function usrTxt = inputRequired(msg) +%Input Dialog that repeats if left empty +inputRequired = true; +while inputRequired + prompt = ['Please enter ', msg , ':']; + inpt = input(prompt,'s'); + if isempty(inpt) + disp('Input must not be empty!'); + else + usrTxt = inpt; + inputRequired = false; + end +end +end \ No newline at end of file diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m index 8559d8d5829a6d6c631526a0f42adead508c7ff7..589dc845891198e67cf3be7ffe3bd5d614e66bae 100644 --- a/+PlotID/Publish.m +++ b/+PlotID/Publish.m @@ -67,16 +67,19 @@ if isempty(ID) warning(msg); end +%% read config file +configObj = PlotID.config(options.ConfigFileName); +% try +% txt = fileread('config.json'); +% config = jsondecode(txt); +% catch +% dlgObj.configError = true; +% end + + % Error and MSG handeling dlgObj = PlotID.userDLG(ID,options); -%% read config file -try - txt = fileread('config.json'); - config = jsondecode(txt); -catch - dlgObj.configError = true; -end %% storage location switch options.Location @@ -183,20 +186,23 @@ dlgObj.rdFilesPublished = status; dlgObj.userMSG(msg); %% Write Config File -if ~dlgObj.configError - % copy config file - configPath = PlotID.createFileCopy('config.json',folderName,... - storPath,ID, 'data'); -else - %create config file - configPath = fullfile(storPath,folderName,'config.json'); - config = options; -end -%write config -fid = fopen(char(configPath),'w'); -txt = jsonencode(config,'PrettyPrint',true); -fprintf(fid,txt); -fclose(fid); +exportPath = fullfile(storPath,folderName); +configObj.writeConfig(exportPath); + +% if ~dlgObj.configError +% % copy config file +% configPath = PlotID.createFileCopy('config.json',folderName,... +% storPath,ID, 'data'); +% else +% %create config file +% configPath = fullfile(storPath,folderName,'config.json'); +% config = options; +% end +% %write config +% fid = fopen(char(configPath),'w'); +% txt = jsonencode(config,'PrettyPrint',true); +% fprintf(fid,txt); +% fclose(fid); % add further Metadata meta =struct(); diff --git a/+PlotID/TagPlot.m b/+PlotID/TagPlot.m index c72ae4b416ea807187b940f4eec500adb856e02c..89f95ae7d30aeaca79a82002bae5118e9954ecb4 100644 --- a/+PlotID/TagPlot.m +++ b/+PlotID/TagPlot.m @@ -18,25 +18,13 @@ arguments options.Color (1,3) {mustBeNonnegative} = 0.65*[1 1 1] % grey options.Location (1,:) {mustBeText} = 'east' options.Position (1,2) {mustBeVector} = [1,0.4] % default for east - options.Rotation (1,1) {mustBeReal} = NaN + options.Rotation (1,1) {mustBeReal} = NaN + options.ConfigFileName (1,:) {mustBeText} = 'config.json' end if isempty(options.ProjectID) - try - txt = fileread('config.json'); - config = jsondecode(txt); - catch - config =struct; - config.ProjectID = ''; - warning("No ProjectID was definded and no config.json could be found"); - - end - - if ~isempty(config.ProjectID) - options.ProjectID = config.ProjectID; - else - warning('no project options.ProjectID defined') - end + configObj = PlotID.config(options.ConfigFileName); + configData = configObj.configData; end switch options.Location diff --git a/+PlotID/initilise.m b/+PlotID/initilise.m new file mode 100644 index 0000000000000000000000000000000000000000..4f893441299d085fa8f5a06fbd4dc36b105df04c --- /dev/null +++ b/+PlotID/initilise.m @@ -0,0 +1,7 @@ +function [status] = initilise() +%INITILISE Initilisation for first time úsage + + + +end + diff --git a/example-config.json b/example-config.json deleted file mode 100644 index 92b8621a1d43e5fc26290fa6acce3be448471d3e..0000000000000000000000000000000000000000 --- a/example-config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Author": "Example Author", - "ProjectID": "AB01", - "ServerPath": "\\\\Server\\path\\folder" -} diff --git a/example.m b/example.m index 3f86ce5b8528dd67ac5fd78664ccd2a6265391e7..b64044db476204bb46edce6332f08ddb80be7573 100644 --- a/example.m +++ b/example.m @@ -62,8 +62,8 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]); % PlotID Implementation starts here. % TagPlot adds a visible ID to the figure(s) and to the figures property % 'Tag' -[fig, ID] = PlotID.TagPlot(fig, 'ProjectID', ProjectID); - +% [fig, ID] = PlotID.TagPlot(fig, 'ProjectID', ProjectID); +[fig, ID] = PlotID.TagPlot(fig); %% Publishing % Second part of plotID % The functions needs the file location of the script, the location of the @@ -76,7 +76,7 @@ scriptPath = [mfilename('fullpath'),'.m']; %(defined above:) dataset1 = 'test_data.mat'; dataset2 = 'testdata2.h5' locations = {dataset1,dataset2} ; % don't forget the extension -locations = {string(dataset1),dataset2} +locations = {string(dataset1),dataset2}; %call publishing PlotID.Publish(locations,scriptPath, fig(1), 'Location', 'local' ,'Method','individual')