classdef app4 < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                     matlab.ui.Figure
        Menu                         matlab.ui.container.Menu
        HelpMenu                     matlab.ui.container.Menu
        Image                        matlab.ui.control.Image
        OKButton                     matlab.ui.control.Button
        AnnulerButton                matlab.ui.control.Button
        TabGroup                     matlab.ui.container.TabGroup
        DCLinkTab                    matlab.ui.container.Tab
        afficherlesparametresButton  matlab.ui.control.Button
        SelectionneruncomposantDropDown  matlab.ui.control.DropDown
        SelectionneruncomposantDropDownLabel  matlab.ui.control.Label
        Panel                        matlab.ui.container.Panel
        Label_3                      matlab.ui.control.Label
        Label_2                      matlab.ui.control.Label
        Label                        matlab.ui.control.Label
        yearsLabel                   matlab.ui.control.Label
        HzLabel                      matlab.ui.control.Label
        HLabel                       matlab.ui.control.Label
        FLabel                       matlab.ui.control.Label
        VLabel                       matlab.ui.control.Label
        ALabel_2                     matlab.ui.control.Label
        ALabel                       matlab.ui.control.Label
        mLabel_2                     matlab.ui.control.Label
        CLabel                       matlab.ui.control.Label
        mLabel                       matlab.ui.control.Label
        AjouterButton                matlab.ui.control.Button
        LeEditField                  matlab.ui.control.NumericEditField
        LeEditFieldLabel             matlab.ui.control.Label
        f1EditField_2                matlab.ui.control.NumericEditField
        f1EditField_2Label           matlab.ui.control.Label
        CdEditField                  matlab.ui.control.NumericEditField
        CdEditFieldLabel             matlab.ui.control.Label
        LcEditField                  matlab.ui.control.NumericEditField
        LcEditFieldLabel             matlab.ui.control.Label
        VripEditField                matlab.ui.control.NumericEditField
        VripEditFieldLabel           matlab.ui.control.Label
        InEditField                  matlab.ui.control.NumericEditField
        InEditFieldLabel             matlab.ui.control.Label
        CosEditField                 matlab.ui.control.NumericEditField
        CosLabel                     matlab.ui.control.Label
        MEditField                   matlab.ui.control.NumericEditField
        MEditFieldLabel              matlab.ui.control.Label
        KfEditField                  matlab.ui.control.NumericEditField
        KfEditFieldLabel             matlab.ui.control.Label
        IripEditField                matlab.ui.control.NumericEditField
        IripEditFieldLabel           matlab.ui.control.Label
        RthEditField                 matlab.ui.control.NumericEditField
        RthEditFieldLabel            matlab.ui.control.Label
        TlimEditField                matlab.ui.control.NumericEditField
        TlimEditFieldLabel           matlab.ui.control.Label
        IDducomposantEditField       matlab.ui.control.EditField
        IDducomposantEditFieldLabel  matlab.ui.control.Label
        ESREditField                 matlab.ui.control.NumericEditField
        ESREditFieldLabel            matlab.ui.control.Label
        ModuleTransistorTab          matlab.ui.container.Tab
        MachineMoteurTab             matlab.ui.container.Tab
        CycleProfilVhiculeTab        matlab.ui.container.Tab
    end

    % Callbacks that handle component events
    methods (Access = private)

        % Button pushed function: AjouterButton
        function AjouterButtonPushed(app, event)
            T = table( app.ESREditField.Value , app.TlimEditField.Value ,app.RthEditField.Value ,app.KfEditField.Value);
            writetable(T,strcat(app.IDducomposantEditField.Value,'.txt'));
        end

        % Value changed function: SelectionneruncomposantDropDown
        function SelectionneruncomposantDropDownValueChanged(app, event)
            
                    mydata = load(strcat(app.SelectionneruncomposantDropDown.Value,'.mat'));
                    app.IDducomposantEditField.Value = app.SelectionneruncomposantDropDown.Value;
                    app.ESREditField.Value=mydata.ESR;
                    app.TlimEditField.Value=mydata.Tlim;
                    app.RthEditField.Value=mydata.Rth;
                    app.KfEditField.Value=mydata.Kf;
                    app.IripEditField.Value=mydata.Irip;
                    app.MEditField.Value=mydata.M;
                    app.LeEditField.Value=mydata.Le;
                    app.InEditField.Value=mydata.In;
                    app.CosEditField.Value=mydata.Cos;
                    app.VripEditField.Value=mydata.Vrip;
                    app.CdEditField.Value=mydata.Cd;
                    app.LcEditField.Value=mydata.Lc;
                    app.f1EditField_2.Value=mydata.f1;
 
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Color = [0 0.4471 0.7412];
            app.UIFigure.Position = [100 100 640 480];
            app.UIFigure.Name = 'UI Figure';

            % Create Menu
            app.Menu = uimenu(app.UIFigure);
            app.Menu.Text = 'Menu';

            % Create HelpMenu
            app.HelpMenu = uimenu(app.UIFigure);
            app.HelpMenu.Text = 'Help ?';

            % Create TabGroup
            app.TabGroup = uitabgroup(app.UIFigure);
            app.TabGroup.Position = [7 35 628 437];

            % Create DCLinkTab
            app.DCLinkTab = uitab(app.TabGroup);
            app.DCLinkTab.Title = 'DC-Link';
            app.DCLinkTab.BackgroundColor = [0.9412 0.9412 0.9412];

            % Create Panel
            app.Panel = uipanel(app.DCLinkTab);
            app.Panel.BackgroundColor = [0.902 0.902 0.902];
            app.Panel.Position = [13 43 604 280];

            % Create ESREditFieldLabel
            app.ESREditFieldLabel = uilabel(app.Panel);
            app.ESREditFieldLabel.Tooltip = {'Equivalent'; 'series resistances'};
            app.ESREditFieldLabel.Position = [27 207 31 22];
            app.ESREditFieldLabel.Text = 'ESR';

            % Create ESREditField
            app.ESREditField = uieditfield(app.Panel, 'numeric');
            app.ESREditField.Tooltip = {'Equivalent'; 'series resistances'};
            app.ESREditField.Position = [83 207 100 22];

            % Create IDducomposantEditFieldLabel
            app.IDducomposantEditFieldLabel = uilabel(app.Panel);
            app.IDducomposantEditFieldLabel.HorizontalAlignment = 'right';
            app.IDducomposantEditFieldLabel.Position = [120 249 97 22];
            app.IDducomposantEditFieldLabel.Text = 'ID du composant';

            % Create IDducomposantEditField
            app.IDducomposantEditField = uieditfield(app.Panel, 'text');
            app.IDducomposantEditField.Position = [232 249 238 22];

            % Create TlimEditFieldLabel
            app.TlimEditFieldLabel = uilabel(app.Panel);
            app.TlimEditFieldLabel.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.TlimEditFieldLabel.Position = [27 178 37 22];
            app.TlimEditFieldLabel.Text = 'ΔTlim';

            % Create TlimEditField
            app.TlimEditField = uieditfield(app.Panel, 'numeric');
            app.TlimEditField.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.TlimEditField.Position = [83 178 100 22];

            % Create RthEditFieldLabel
            app.RthEditFieldLabel = uilabel(app.Panel);
            app.RthEditFieldLabel.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.RthEditFieldLabel.Position = [27 149 21 22];
            app.RthEditFieldLabel.Text = 'Rth';

            % Create RthEditField
            app.RthEditField = uieditfield(app.Panel, 'numeric');
            app.RthEditField.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.RthEditField.Position = [83 149 100 22];

            % Create IripEditFieldLabel
            app.IripEditFieldLabel = uilabel(app.Panel);
            app.IripEditFieldLabel.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.IripEditFieldLabel.Position = [27 90 37 22];
            app.IripEditFieldLabel.Text = 'Irip';

            % Create IripEditField
            app.IripEditField = uieditfield(app.Panel, 'numeric');
            app.IripEditField.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.IripEditField.Position = [83 90 100 22];

            % Create KfEditFieldLabel
            app.KfEditFieldLabel = uilabel(app.Panel);
            app.KfEditFieldLabel.Tooltip = {'Equivalent'; 'series resistances'};
            app.KfEditFieldLabel.Position = [27 119 31 22];
            app.KfEditFieldLabel.Text = 'K(f)';

            % Create KfEditField
            app.KfEditField = uieditfield(app.Panel, 'numeric');
            app.KfEditField.Tooltip = {'Equivalent'; 'series resistances'};
            app.KfEditField.Position = [83 119 100 22];

            % Create MEditFieldLabel
            app.MEditFieldLabel = uilabel(app.Panel);
            app.MEditFieldLabel.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.MEditFieldLabel.Position = [27 61 26 22];
            app.MEditFieldLabel.Text = 'M';

            % Create MEditField
            app.MEditField = uieditfield(app.Panel, 'numeric');
            app.MEditField.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.MEditField.Position = [83 61 100 22];

            % Create CosLabel
            app.CosLabel = uilabel(app.Panel);
            app.CosLabel.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.CosLabel.Position = [355 178 43 22];
            app.CosLabel.Text = 'Cos(φ)';

            % Create CosEditField
            app.CosEditField = uieditfield(app.Panel, 'numeric');
            app.CosEditField.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.CosEditField.Position = [416 178 100 22];

            % Create InEditFieldLabel
            app.InEditFieldLabel = uilabel(app.Panel);
            app.InEditFieldLabel.Tooltip = {'Equivalent'; 'series resistances'};
            app.InEditFieldLabel.Position = [355 207 31 22];
            app.InEditFieldLabel.Text = 'In';

            % Create InEditField
            app.InEditField = uieditfield(app.Panel, 'numeric');
            app.InEditField.Tooltip = {'Equivalent'; 'series resistances'};
            app.InEditField.Position = [416 207 100 22];

            % Create VripEditFieldLabel
            app.VripEditFieldLabel = uilabel(app.Panel);
            app.VripEditFieldLabel.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.VripEditFieldLabel.Position = [355 149 26 22];
            app.VripEditFieldLabel.Text = 'Vrip';

            % Create VripEditField
            app.VripEditField = uieditfield(app.Panel, 'numeric');
            app.VripEditField.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.VripEditField.Position = [416 149 100 22];

            % Create LcEditFieldLabel
            app.LcEditFieldLabel = uilabel(app.Panel);
            app.LcEditFieldLabel.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.LcEditFieldLabel.Position = [355 90 37 22];
            app.LcEditFieldLabel.Text = 'Lc';

            % Create LcEditField
            app.LcEditField = uieditfield(app.Panel, 'numeric');
            app.LcEditField.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.LcEditField.Position = [416 90 100 22];

            % Create CdEditFieldLabel
            app.CdEditFieldLabel = uilabel(app.Panel);
            app.CdEditFieldLabel.Tooltip = {'Equivalent'; 'series resistances'};
            app.CdEditFieldLabel.Position = [355 119 31 22];
            app.CdEditFieldLabel.Text = 'Cd';

            % Create CdEditField
            app.CdEditField = uieditfield(app.Panel, 'numeric');
            app.CdEditField.Tooltip = {'Equivalent'; 'series resistances'};
            app.CdEditField.Position = [416 119 100 22];

            % Create f1EditField_2Label
            app.f1EditField_2Label = uilabel(app.Panel);
            app.f1EditField_2Label.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.f1EditField_2Label.Position = [355 61 26 22];
            app.f1EditField_2Label.Text = 'f1';

            % Create f1EditField_2
            app.f1EditField_2 = uieditfield(app.Panel, 'numeric');
            app.f1EditField_2.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.f1EditField_2.Position = [416 61 100 22];

            % Create LeEditFieldLabel
            app.LeEditFieldLabel = uilabel(app.Panel);
            app.LeEditFieldLabel.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.LeEditFieldLabel.Position = [27 32 26 22];
            app.LeEditFieldLabel.Text = 'Le';

            % Create LeEditField
            app.LeEditField = uieditfield(app.Panel, 'numeric');
            app.LeEditField.Tooltip = {'Allowed capacitor over temperature in C°'};
            app.LeEditField.Position = [83 32 100 22];

            % Create AjouterButton
            app.AjouterButton = uibutton(app.Panel, 'push');
            app.AjouterButton.ButtonPushedFcn = createCallbackFcn(app, @AjouterButtonPushed, true);
            app.AjouterButton.Position = [467 11 100 22];
            app.AjouterButton.Text = 'Ajouter';

            % Create mLabel
            app.mLabel = uilabel(app.Panel);
            app.mLabel.Position = [193 207 25 22];
            app.mLabel.Text = 'mΩ';

            % Create CLabel
            app.CLabel = uilabel(app.Panel);
            app.CLabel.Position = [193 178 25 22];
            app.CLabel.Text = '°C';

            % Create mLabel_2
            app.mLabel_2 = uilabel(app.Panel);
            app.mLabel_2.Position = [193 149 25 22];
            app.mLabel_2.Text = 'mΩ';

            % Create ALabel
            app.ALabel = uilabel(app.Panel);
            app.ALabel.Position = [193 90 25 22];
            app.ALabel.Text = 'A';

            % Create ALabel_2
            app.ALabel_2 = uilabel(app.Panel);
            app.ALabel_2.Position = [524 207 25 22];
            app.ALabel_2.Text = 'A';

            % Create VLabel
            app.VLabel = uilabel(app.Panel);
            app.VLabel.Position = [524 149 25 22];
            app.VLabel.Text = 'V';

            % Create FLabel
            app.FLabel = uilabel(app.Panel);
            app.FLabel.Position = [524 119 25 22];
            app.FLabel.Text = 'μF';

            % Create HLabel
            app.HLabel = uilabel(app.Panel);
            app.HLabel.Position = [524 90 25 22];
            app.HLabel.Text = 'μH';

            % Create HzLabel
            app.HzLabel = uilabel(app.Panel);
            app.HzLabel.Position = [524 61 25 22];
            app.HzLabel.Text = 'Hz';

            % Create yearsLabel
            app.yearsLabel = uilabel(app.Panel);
            app.yearsLabel.Position = [193 32 35 22];
            app.yearsLabel.Text = 'years';

            % Create Label
            app.Label = uilabel(app.Panel);
            app.Label.Position = [193 61 25 22];
            app.Label.Text = '----';

            % Create Label_2
            app.Label_2 = uilabel(app.Panel);
            app.Label_2.Position = [192 119 25 22];
            app.Label_2.Text = '----';

            % Create Label_3
            app.Label_3 = uilabel(app.Panel);
            app.Label_3.Position = [524 178 25 22];
            app.Label_3.Text = '----';

            % Create SelectionneruncomposantDropDownLabel
            app.SelectionneruncomposantDropDownLabel = uilabel(app.DCLinkTab);
            app.SelectionneruncomposantDropDownLabel.HorizontalAlignment = 'right';
            app.SelectionneruncomposantDropDownLabel.Position = [164 366 151 22];
            app.SelectionneruncomposantDropDownLabel.Text = 'Selectionner un composant';

            % Create SelectionneruncomposantDropDown
            app.SelectionneruncomposantDropDown = uidropdown(app.DCLinkTab);
            app.SelectionneruncomposantDropDown.Items = {'capa1', 'capa2'};
            app.SelectionneruncomposantDropDown.ValueChangedFcn = createCallbackFcn(app, @SelectionneruncomposantDropDownValueChanged, true);
            app.SelectionneruncomposantDropDown.Position = [330 366 100 22];
            app.SelectionneruncomposantDropDown.Value = 'capa1';

            % Create afficherlesparametresButton
            app.afficherlesparametresButton = uibutton(app.DCLinkTab, 'push');
            app.afficherlesparametresButton.Position = [13 345 141 22];
            app.afficherlesparametresButton.Text = 'afficher les parametres ';

            % Create ModuleTransistorTab
            app.ModuleTransistorTab = uitab(app.TabGroup);
            app.ModuleTransistorTab.Title = 'Module/Transistor';
            app.ModuleTransistorTab.BackgroundColor = [0.9412 0.9412 0.9412];

            % Create MachineMoteurTab
            app.MachineMoteurTab = uitab(app.TabGroup);
            app.MachineMoteurTab.Title = 'Machine/Moteur';
            app.MachineMoteurTab.BackgroundColor = [0.9412 0.9412 0.9412];

            % Create CycleProfilVhiculeTab
            app.CycleProfilVhiculeTab = uitab(app.TabGroup);
            app.CycleProfilVhiculeTab.Title = 'Cycle/Profil/Véhicule';
            app.CycleProfilVhiculeTab.BackgroundColor = [0.9412 0.9412 0.9412];

            % Create AnnulerButton
            app.AnnulerButton = uibutton(app.UIFigure, 'push');
            app.AnnulerButton.IconAlignment = 'right';
            app.AnnulerButton.BackgroundColor = [0.902 0.902 0.902];
            app.AnnulerButton.FontWeight = 'bold';
            app.AnnulerButton.Position = [534 8 89 22];
            app.AnnulerButton.Text = 'Annuler';

            % Create OKButton
            app.OKButton = uibutton(app.UIFigure, 'push');
            app.OKButton.IconAlignment = 'right';
            app.OKButton.BackgroundColor = [0.902 0.902 0.902];
            app.OKButton.FontWeight = 'bold';
            app.OKButton.Position = [435 8 89 22];
            app.OKButton.Text = 'OK';

            % Create Image
            app.Image = uiimage(app.UIFigure);
            app.Image.Position = [20 5 45 25];
            app.Image.ImageSource = 'logo_punch_powertrain.png';

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = app4

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end