% Wicklung umfasst Wickelkörper und aufgewickelten Kupferlackdraht

classdef RotWicklung
    %% Konstanten
    properties (Constant = true, Hidden = true)
        % Standard-Nenndurchmesser des Kupferlackdrahtes; [d_Cu_std] = m
        d_Cu_std = 1e-3;
        
        % Standard-Anzahl Drahwindungen in jede Richtung; [N_std] = 1 (dimensionslos)
        N_std = uint8(2);
        
        % Standard-Dicke des Wicklungskörpers in jede Richtung; [b_std] = m
        b_std = 1e-3;
        
        % Standardwert des inneren Radius des Wicklungskörpers; [r_i_std] = m
        r_i_std = 1e-3;
        
        % Wicklungskörper-Darstellung
        WK_Fuellung_Farbe = [0 0 0.8];
        WK_Fuellung_Transp = 1.0;
            
        % Windungsfenster-Kupfer-Darstellung
        WF_Fuellung_Farbe = [0.8 0.4 0];
        WF_Fuellung_Transp = 1.0;
        
        % Interpreter
        Interpreter = 'tex';
    end
    
    %% Lese-Attribute
    properties (GetAccess = public, SetAccess = protected)
        % Name der Instanz
        Name = '';
    end
    
    %% freie Attribute
    properties (Access = public)
        % Nenndurchmesser des Kupferlackdrahtes; [d_Cu] = m
        d_Cu;
        
        % Anzahl Drahwindungen in axialer Richtung; [N_ax] = 1 (dimensionslos)
        N_ax = uint8(1);
        
        % Anzahl Drahwindungen in radialer Richtung; [N_rad] = 1 (dimensionslos)
        N_rad = uint8(1);
        
        % Dicke des Wicklungskörpers in axialer Richtung; [b_ax] = m
        b_ax;
        
        % Dicke des Wicklungskörpers in radialer Richtung; [b_rad] = m
        b_rad;
        
        % innerer Radius des Wicklungskörpers; [r_i] = m
        r_i = 0;
    end
    
    %% abhängige Attribute
    properties (Dependent)
        % Anzahl Drahtwindungen
        N;
        
        % Länge des Wicklungskörpers in axialer Richtung; [l_ax] = m
        l_ax;
        
        % Länge des Wicklungskörpers in radialer Richtung; [l_rad] = m
        l_rad;
        
        % äußerer Radius des Wicklungskörpers; [r_a] = m
        r_a;
    end
    
    %% abhängige Attribute (intern)
    properties (Dependent, Hidden = true)
        % Wicklungskörper-Koordinaten in axiale Richtung; [WK_KO_ax] = m
        WK_KO_ax;
        
        % Wicklungskörper-Koordinaten in radiale Richtung; [WK_KO_rad] = m
        WK_KO_rad;
        
        % Wicklungsfenster-Koordinaten in axiale Richtung; [WF_KO_ax] = m
        WF_KO_ax;
        
        % Wicklungsfenster-Koordinaten in radiale Richtung; [WF_KO_rad] = m
        WF_KO_rad;
    end

    %% Methoden
    methods
        %% Konstruktor
        function obj = RotWicklung(Name)
            obj.Name = Name;
            obj.d_Cu = obj.d_Cu_std;
            obj.N_ax = obj.N_std;
            obj.N_rad = obj.N_std;
            obj.b_ax = obj.b_std;
            obj.b_rad = obj.b_std;
            obj.r_i = obj.r_i_std;
        end
        
        %% Set-Methoden
        function obj = set.d_Cu(obj, d_Cu)
            if d_Cu <= 0
                obj.d_Cu = obj.d_Cu_std;
            else
                obj.d_Cu = d_Cu;
            end
        end
        function obj = set.N_ax(obj, N_ax)
            if N_ax < 1
                obj.N_ax = obj.N_std;
            else
                obj.N_ax = uint8(N_ax);
            end
        end
        function obj = set.N_rad(obj, N_rad)
            if N_rad < 1
                obj.N_rad = obj.N_std;
            else
                obj.N_rad = uint8(N_rad);
            end
        end
        function obj = set.b_ax(obj, b_ax)
            if b_ax <= 0
                obj.b_ax = obj.b_std;
            else
                obj.b_ax = b_ax;
            end
        end
        function obj = set.b_rad(obj, b_rad)
            if b_rad <= 0
                obj.b_rad = obj.b_std;
            else
                obj.b_rad = b_rad;
            end
        end
        
        %% Get-Methoden für Dependent-Attribute
        function N = get.N(obj)
            N = uint16(obj.N_ax) * uint16(obj.N_rad);
        end
        function l_ax = get.l_ax(obj)
            l_ax = 2 * obj.b_ax + double(obj.N_ax) * obj.d_Cu;
        end
        function l_rad = get.l_rad(obj)
            l_rad = obj.b_rad + double(obj.N_rad) * obj.d_Cu;
        end
        function r_a = get.r_a(obj)
            r_a = obj.r_i + obj.l_rad;
        end
        
        %% Get-Methoden für versteckte Dependent-Attribute
        function WK_KO_ax = get.WK_KO_ax(obj)
            WK_KO_ax = [(0) (obj.l_ax) (obj.l_ax) (obj.l_ax - obj.b_ax) (obj.l_ax - obj.b_ax) (0 + obj.b_ax) (0 + obj.b_ax) (0)];
        end
        function WK_KO_rad = get.WK_KO_rad(obj)
            WK_KO_rad = [(obj.r_i) (obj.r_i) (obj.r_a) (obj.r_a) (obj.r_i + obj.b_rad) (obj.r_i + obj.b_rad) (obj.r_a) (obj.r_a)];
        end
        function WF_KO_ax = get.WF_KO_ax(obj)
            WF_KO_ax = [(0 + obj.b_ax) (obj.l_ax - obj.b_ax) (obj.l_ax - obj.b_ax) (0 + obj.b_ax)];
        end
        function WF_KO_rad = get.WF_KO_rad(obj)
            WF_KO_rad = [(obj.r_i) (obj.r_i) (obj.r_a) (obj.r_a)];
        end
        
        %% Darstellungs-Methoden
        function ZeichneQuerschnittPur(obj, Deltaz)
            % Wicklungskörper-Polygone definieren
            WK_Polygon_oben = polyshape(obj.WK_KO_ax - Deltaz, obj.WK_KO_rad);
            WK_Polygon_unten = polyshape(obj.WK_KO_ax - Deltaz, -1 * obj.WK_KO_rad);           
            
            % Figure and Subplot definieren
            fig = figure(1);
            fig.Name = 'ClassDef RotWicklung.m: ZeichneQuerschnitt';
            fig_sp = subplot(1, 1, 1);
            hold(fig_sp, 'on');
            fig_sp.DataAspectRatioMode = 'manual';
            fig_sp.DataAspectRatio = [1 1 1];
            
            % Wicklungskörper zeichnen
            plot(fig_sp, WK_Polygon_oben, 'FaceColor', obj.WK_Fuellung_Farbe, 'FaceAlpha', obj.WK_Fuellung_Transp);
            plot(fig_sp, WK_Polygon_unten, 'FaceColor', obj.WK_Fuellung_Farbe, 'FaceAlpha', obj.WK_Fuellung_Transp);
            
            % Windungen zeichnen
            for i_ax = 0:1:(obj.N_ax - 1)
                for i_rad = 0:1:(obj.N_rad - 1)
                    Cu_oben = [(obj.b_ax + double(i_ax) * obj.d_Cu - Deltaz) (obj.r_i + obj.b_rad + double(i_rad) * obj.d_Cu) (obj.d_Cu) (obj.d_Cu)];
                    Cu_unten = [(obj.b_ax + double(i_ax) * obj.d_Cu - Deltaz) (-1 * (obj.r_i + obj.b_rad) - double(i_rad + 1) * obj.d_Cu) (obj.d_Cu) (obj.d_Cu)];
                    rectangle(fig_sp, 'Position', Cu_oben, 'Curvature', 1, 'FaceColor', [obj.WF_Fuellung_Farbe obj.WF_Fuellung_Transp]);
                    rectangle(fig_sp, 'Position', Cu_unten, 'Curvature', 1, 'FaceColor', [obj.WF_Fuellung_Farbe obj.WF_Fuellung_Transp]);
                end
            end
        end
        function ZeichneQuerschnitt(obj)
            % Wicklungskörper-Polygone definieren
            WK_Polygon_oben = polyshape(obj.WK_KO_ax, obj.WK_KO_rad);
            WK_Polygon_unten = polyshape(obj.WK_KO_ax, -1 * obj.WK_KO_rad);           
            
            % Figure and Subplot definieren
            fig = figure(1);
            fig.Name = 'ClassDef RotWicklung.m: ZeichneQuerschnitt';
            fig_sp = subplot(1, 1, 1);
            hold(fig_sp, 'on');
            fig_sp.DataAspectRatioMode = 'manual';
            fig_sp.DataAspectRatio = [1 1 1];
            
            fig_sp.Title.String = 'Wicklungskoerper';
            fig_sp.Title.Interpreter = obj.Interpreter;
            %fig_sp.Title.Position = [(0.5 * obj.l_ax) (1.2 * fig_sp.YLim(1,2)) 0];
            fig_sp.Title.HorizontalAlignment = 'Center';
            fig_sp.Title.VerticalAlignment = 'Bottom';

            fig_sp.XAxisLocation = 'origin';
            fig_sp.XLabel.String = 'Rotationsachse';
            fig_sp.XLabel.Interpreter = obj.Interpreter;
            fig_sp.XLabel.Position = [(1.1 * obj.l_ax) 0 0];
            fig_sp.XLabel.HorizontalAlignment = 'Left';
            fig_sp.XLabel.VerticalAlignment = 'Middle';
            
            fig_sp.YAxisLocation = 'left';
            fig_sp.YLabel.String = 'Angaben in m';
            fig_sp.YLabel.Interpreter = obj.Interpreter;
            
            % Wicklungskörper zeichnen
            plot(fig_sp, WK_Polygon_oben, 'FaceColor', obj.WK_Fuellung_Farbe, 'FaceAlpha', obj.WK_Fuellung_Transp);
            plot(fig_sp, WK_Polygon_unten, 'FaceColor', obj.WK_Fuellung_Farbe, 'FaceAlpha', obj.WK_Fuellung_Transp);
            
            % Windungen zeichnen
            for i_ax = 0:1:(obj.N_ax - 1)
                for i_rad = 0:1:(obj.N_rad - 1)
                    Cu_oben = [(obj.b_ax + double(i_ax) * obj.d_Cu) (obj.r_i + obj.b_rad + double(i_rad) * obj.d_Cu) (obj.d_Cu) (obj.d_Cu)];
                    Cu_unten = [(obj.b_ax + double(i_ax) * obj.d_Cu) (-1 * (obj.r_i + obj.b_rad) - double(i_rad + 1) * obj.d_Cu) (obj.d_Cu) (obj.d_Cu)];
                    rectangle(fig_sp, 'Position', Cu_oben, 'Curvature', 1, 'FaceColor', [obj.WF_Fuellung_Farbe obj.WF_Fuellung_Transp]);
                    rectangle(fig_sp, 'Position', Cu_unten, 'Curvature', 1, 'FaceColor', [obj.WF_Fuellung_Farbe obj.WF_Fuellung_Transp]);
                end
            end
        end
    end
end