classdef ShapeEditor < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        ShapesUIFigure              matlab.ui.Figure
        CloseButton                 matlab.ui.control.Button
        ApplyButton                 matlab.ui.control.Button
        OKButton                    matlab.ui.control.Button
        SizeinZEditField            matlab.ui.control.NumericEditField
        SizeinZEditFieldLabel       matlab.ui.control.Label
        SizeinYEditField            matlab.ui.control.NumericEditField
        SizeinYEditFieldLabel       matlab.ui.control.Label
        SizeinXEditField            matlab.ui.control.NumericEditField
        SizeinXEditFieldLabel       matlab.ui.control.Label
        PrimitiveshapesButtonGroup  matlab.ui.container.ButtonGroup
        coneButton                  matlab.ui.control.RadioButton
        pyramidButton               matlab.ui.control.RadioButton
        cylinderButton              matlab.ui.control.RadioButton
        sphereButton                matlab.ui.control.RadioButton
        boxButton                   matlab.ui.control.RadioButton
    end

    
    properties (Access = private)
        Actors = []; % Description
    end
    

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

        % Code that executes after component creation
        function startupFcn(app, Actors)
            app.Actors = Actors;
        end

        % Button pushed function: CloseButton
        function CloseButtonPushed(app, event)
            app.delete;
        end

        % Button pushed function: OKButton
        function OKButtonPushed(app, event)
            ApplyButtonPushed(app, event);
            set(app.Actors, 'Selected', false);
            app.delete;
        end

        % Button pushed function: ApplyButton
        function ApplyButtonPushed(app, event)
            Size = [app.SizeinXEditField.Value app.SizeinYEditField.Value app.SizeinZEditField.Value];
            Shape = app.PrimitiveshapesButtonGroup.SelectedObject.Text;
            app.Actors.createShape(Shape, Size);
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create ShapesUIFigure and hide until all components are created
            app.ShapesUIFigure = uifigure('Visible', 'off');
            app.ShapesUIFigure.Position = [100 100 381 237];
            app.ShapesUIFigure.Name = 'Shapes';

            % Create PrimitiveshapesButtonGroup
            app.PrimitiveshapesButtonGroup = uibuttongroup(app.ShapesUIFigure);
            app.PrimitiveshapesButtonGroup.Title = 'Primitive shapes';
            app.PrimitiveshapesButtonGroup.Position = [22 78 123 140];

            % Create boxButton
            app.boxButton = uiradiobutton(app.PrimitiveshapesButtonGroup);
            app.boxButton.Text = 'box';
            app.boxButton.Position = [11 94 58 22];
            app.boxButton.Value = true;

            % Create sphereButton
            app.sphereButton = uiradiobutton(app.PrimitiveshapesButtonGroup);
            app.sphereButton.Text = 'sphere';
            app.sphereButton.Position = [11 72 65 22];

            % Create cylinderButton
            app.cylinderButton = uiradiobutton(app.PrimitiveshapesButtonGroup);
            app.cylinderButton.Text = 'cylinder';
            app.cylinderButton.Position = [11 50 65 22];

            % Create pyramidButton
            app.pyramidButton = uiradiobutton(app.PrimitiveshapesButtonGroup);
            app.pyramidButton.Text = 'pyramid';
            app.pyramidButton.Position = [11 28 65 22];

            % Create coneButton
            app.coneButton = uiradiobutton(app.PrimitiveshapesButtonGroup);
            app.coneButton.Text = 'cone';
            app.coneButton.Position = [11 5 48 22];

            % Create SizeinXEditFieldLabel
            app.SizeinXEditFieldLabel = uilabel(app.ShapesUIFigure);
            app.SizeinXEditFieldLabel.HorizontalAlignment = 'right';
            app.SizeinXEditFieldLabel.Position = [192 196 53 22];
            app.SizeinXEditFieldLabel.Text = 'Size in X';

            % Create SizeinXEditField
            app.SizeinXEditField = uieditfield(app.ShapesUIFigure, 'numeric');
            app.SizeinXEditField.Limits = [0 Inf];
            app.SizeinXEditField.Position = [260 196 100 22];
            app.SizeinXEditField.Value = 1;

            % Create SizeinYEditFieldLabel
            app.SizeinYEditFieldLabel = uilabel(app.ShapesUIFigure);
            app.SizeinYEditFieldLabel.HorizontalAlignment = 'right';
            app.SizeinYEditFieldLabel.Position = [192 156 52 22];
            app.SizeinYEditFieldLabel.Text = 'Size in Y';

            % Create SizeinYEditField
            app.SizeinYEditField = uieditfield(app.ShapesUIFigure, 'numeric');
            app.SizeinYEditField.Limits = [0 Inf];
            app.SizeinYEditField.Position = [259 156 100 22];
            app.SizeinYEditField.Value = 1;

            % Create SizeinZEditFieldLabel
            app.SizeinZEditFieldLabel = uilabel(app.ShapesUIFigure);
            app.SizeinZEditFieldLabel.HorizontalAlignment = 'right';
            app.SizeinZEditFieldLabel.Position = [192 116 52 22];
            app.SizeinZEditFieldLabel.Text = 'Size in Z';

            % Create SizeinZEditField
            app.SizeinZEditField = uieditfield(app.ShapesUIFigure, 'numeric');
            app.SizeinZEditField.Limits = [0 Inf];
            app.SizeinZEditField.Position = [259 116 100 22];
            app.SizeinZEditField.Value = 1;

            % Create OKButton
            app.OKButton = uibutton(app.ShapesUIFigure, 'push');
            app.OKButton.ButtonPushedFcn = createCallbackFcn(app, @OKButtonPushed, true);
            app.OKButton.Position = [42 16 100 22];
            app.OKButton.Text = 'OK';

            % Create ApplyButton
            app.ApplyButton = uibutton(app.ShapesUIFigure, 'push');
            app.ApplyButton.ButtonPushedFcn = createCallbackFcn(app, @ApplyButtonPushed, true);
            app.ApplyButton.Position = [152 16 100 22];
            app.ApplyButton.Text = {'Apply'; ''};

            % Create CloseButton
            app.CloseButton = uibutton(app.ShapesUIFigure, 'push');
            app.CloseButton.ButtonPushedFcn = createCallbackFcn(app, @CloseButtonPushed, true);
            app.CloseButton.Position = [262 16 100 22];
            app.CloseButton.Text = {'Close'; ''};

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

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = ShapeEditor(varargin)

            % Create UIFigure and components
            createComponents(app)

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

            % Execute the startup function
            runStartupFcn(app, @(app)startupFcn(app, varargin{:}))

            if nargout == 0
                clear app
            end
        end

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

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