From bf7b5bce7034ffba653182a8b37d780754aee791 Mon Sep 17 00:00:00 2001
From: Mauco03 <marco.gaibotti@skywarder.eu>
Date: Tue, 14 May 2024 22:51:11 +0200
Subject: [PATCH] [refactoring-ode][classes] Implemented copyability

---
 classes/Component.m                   | 13 +++++++++-
 classes/Config.m                      |  3 +--
 classes/Rocket.m                      |  9 ++++---
 functions/miscellaneous/PoolWaitbar.m | 36 +++++++++++++++------------
 4 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/classes/Component.m b/classes/Component.m
index 5e0869d..d99c1c5 100644
--- a/classes/Component.m
+++ b/classes/Component.m
@@ -1,4 +1,4 @@
-classdef Component < Config
+classdef Component < Config & matlab.mixin.Copyable
 % Component: Represents an abstraction layer for all components
 %   Components standardize object construction, config and data loading
 %
@@ -78,6 +78,17 @@ classdef Component < Config
     end
     
     methods(Access = protected)
+        function cp = copyElement(obj)
+            fields = obj.getProperties('readable', NonCopyable = 0);
+            cp = copyElement@matlab.mixin.Copyable(obj); %shallow copy of all elements
+
+            for field = fields
+                if isa(obj.(field), 'matlab.mixin.Copyable')
+                    cp.(field) = copy(obj.(field));
+                end
+            end
+        end
+
         function outputVariables = getConfig(obj, mission)
             fileName = obj.configName;
             filePath = mission.configPath;
diff --git a/classes/Config.m b/classes/Config.m
index aff4e5b..cec711a 100644
--- a/classes/Config.m
+++ b/classes/Config.m
@@ -15,9 +15,7 @@ classdef(Abstract) Config < handle
             fields = obj.getProperties('readable');
             for j = 1:size(fields, 2), structOut.(fields{j}) = obj.(fields{j}); end
         end
-    end
 
-    methods
         function [propertiesOut, valuesOut] = getProperties(obj, preset, options, attributes)
         % This function returns properties that match specific attributes
         %   You can specify presets to include combinations of properties:
@@ -44,6 +42,7 @@ classdef(Abstract) Config < handle
             attributes.Transient    logical {mustBeMember(attributes.Transient, [0, 1])}                    = []
             attributes.Hidden       logical {mustBeMember(attributes.Hidden, [0, 1])}                       = []
             attributes.AbortSet     logical {mustBeMember(attributes.AbortSet, [0, 1])}                     = []
+            attributes.NonCopyable  logical {mustBeMember(attributes.NonCopyable, [0, 1])}                  = []
         end
         
             if ~isempty(preset)
diff --git a/classes/Rocket.m b/classes/Rocket.m
index 26968d3..3f3e895 100644
--- a/classes/Rocket.m
+++ b/classes/Rocket.m
@@ -22,6 +22,7 @@ classdef Rocket < Component
         parachutes          Para            % [-]       (nParachutes, nStages) Parachutes onboard
 
         length              double          % [m]       Total length
+        lengthCenter        double          % [m]       Center length - no nose, boat
         lengthCenterNoMot   double          % [m]       Center length - no nose, no motor
         diameter            double          % [m]       Diameter
         mass                double          % [kg]      Total mass
@@ -32,18 +33,18 @@ classdef Rocket < Component
         xCgNoMotor          double          % [m]       xCg without motor
 
         stagesMass          double          % [kg]      Mass of stage 2, 3, .. without chutes
+
+        coefficients                        % [-]       Aerodynamic coefficients
+        coefficientsHighAOA                 % [-]       Aerodynamic coefficients for high angle of attacks
     end
 
     properties(SetAccess = protected)
-        lengthCenter        double          % [m]       Center length - no nose, boat
+        crossSection                        % [m^2]     Rocket cross sectional area
         inertiaDot          double          % [kg*m^2/s]Total inertia time derivative
         cutoffInertia       double          % [kg*m^2]  Total inertia at motor cutoff
         cutoffMass          double          % [m]       Total mass at motor cutoff
-        coefficients                        % [-]       Aerodynamic coefficients
-        coefficientsHighAOA                 % [-]       Aerodynamic coefficients for high angle of attacks
         absolutePositions   dictionary ...  % [m]       Bay start positions - 0 is set at nose base
             = dictionary()
-        crossSection                        % [m^2]     Rocket cross sectional area
         bays                dictionary ...  % [Bay]     All bays
             = dictionary()
     end
diff --git a/functions/miscellaneous/PoolWaitbar.m b/functions/miscellaneous/PoolWaitbar.m
index ce3ed55..012a62f 100644
--- a/functions/miscellaneous/PoolWaitbar.m
+++ b/functions/miscellaneous/PoolWaitbar.m
@@ -1,47 +1,51 @@
-%{
-    Example:
-    n = 20
-    pw = PoolWaitbar(n, 'Example');
-    parfor ii = 1:20
-        increment(pw)
-    end
-Copyright © 2021, Skyward Experimental Rocketry, AFD department
-All rights reserved
-
-SPDX-License-Identifier: GPL-3.0-or-later
-
-%}
 classdef PoolWaitbar < handle
+% Example:
+% n = 20
+% pw = PoolWaitbar(n, 'Example');
+% parfor ii = 1:20
+%     increment(pw)
+% end
+% Copyright © 2021, Skyward Experimental Rocketry, AFD department
+% All rights reserved
+% 
+% SPDX-License-Identifier: GPL-3.0-or-later
+
     properties (SetAccess = immutable, GetAccess = private)
         Queue
-        N
+        n
     end
+
     properties (Access = private, Transient)
         ClientHandle = []
         Count = 0
     end
+
     properties (SetAccess = immutable, GetAccess = private, Transient)
         Listener = []
     end
+
     methods (Access = private)
         function localIncrement(obj)
             obj.Count = 1 + obj.Count;
-            waitbar(obj.Count / obj.N, obj.ClientHandle);
+            waitbar(obj.Count / obj.n, obj.ClientHandle);
         end
     end
+    
     methods
         function obj = PoolWaitbar(N, message)
             if nargin < 2
                 message = 'PoolWaitbar';
             end
-            obj.N = N;
+            obj.n = N;
             obj.ClientHandle = waitbar(0, message);
             obj.Queue = parallel.pool.DataQueue;
             obj.Listener = afterEach(obj.Queue, @(~) localIncrement(obj));
         end
+
         function increment(obj)
             send(obj.Queue, true);
         end
+
         function delete(obj)
             delete(obj.ClientHandle);
             delete(obj.Queue);
-- 
GitLab