classdef stackUp < handle
%STACKUP Create a PC Board stack up definition
%
% s = stackUp creates an PC Board stack up object with 5 layers. Layer 2
% and Layer 4 accept gerber files, specified in the form of a character
% array, as input. By default, they are empty. Layer 1, 3, and 5 accept
% objects of the dielectric class. By default, Layer 1 and 5 are assigned
% air as the dielectric and Layer 3 is assigned to be FR4.
%
%   stackUp properties:
%
%   Layer1 - Top-most layer in stack-up specified as a dielectric
%   Layer2 - Second layer specified as gerber file (.gtl or.gbr) or empty
%   Layer3 - Third layer specified as dielectric          
%   Layer4 - Fourth layer specifed as gerber file (.gbl or.gbr) or empty
%   Layer5 - Fifth layer specified as dielectric
%
%   % Examples
%
%   % Example 1: % Create a PC Board stack up definition
%
%   p = stackUp
%
    
%   Copyright 2020 The MathWorks, Inc.
    
    properties(Constant)
        NumLayers = 5
    end
    properties
       % Top-most layer in stack-up specified as a dielectric
       Layer1 {mustBeDielectric(Layer1,1)} = dielectric('Thickness',0.1e-3)
       % Second layer specified as gerber file (.gtl or.gbr) or empty
       Layer2 {mustBeGerberOrEmpty(Layer2,2)} = []
       % Third layer specified as dielectric
       Layer3 {mustBeDielectric(Layer3,3)} = dielectric('FR4')
       % Fourth layer specifed as gerber file (.gbl or.gbr) or empty
       Layer4 {mustBeGerberOrEmpty(Layer4,4)} = []
       % Fifth layer specified as dielectric
       Layer5 {mustBeDielectric(Layer5,5)} = dielectric('Thickness',0.1e-3)
    end
    
end

function mustBeDielectric(Layer,n)
    if ~isa(Layer,'dielectric')
       error(message('antenna:antennaerrors:Unsupported',class(Layer), ['Layer' num2str(n)]));
    end
end

function mustBeGerberOrEmpty(Layer,n)
    if ~isempty(Layer) && (~ischar(Layer)&&~isstring(Layer))
        error(message('antenna:antennaerrors:Unsupported', class(Layer), ['Layer' num2str(n)]));
    end
end
