hDialog{1}.hasUnappliedChanges
    pidpack.PIDConfig.syncDataTypeWidgets(hDialog{1},false);
    return;
end
% Get Simulation Status Info.
simStatus   = get_param(bdroot(blk), 'SimulationStatus');
isRunning   = strcmp(simStatus, 'running') || strcmp(simStatus, 'paused');
%% Building the Subsystem
try
    isCurrent = pidpack.PIDConfig.isBlockDiagramCurrent(currentblock);
    if ~isRunning
        if ~isCurrent
            % Clear Susbsytem
            pidpack.PIDConfig.clearSubsystem(currentblock);
            % Building the Controller
            pidpack.PIDConfig.addPorts(currentblock);
            addController(currentblock);
            pidpack.PIDConfig.addSatWindupTracking(currentblock);
        end
        pidpack.PIDConfig.setParam(currentblock);
    else
        % DO NOTHING:
        % - Cannot modify Subsystem while running
        % - Cannot change dialog parameters of under mask blocks. (Non tunable)
    end
catch E
    if ~strcmp(E.identifier,'Simulink:Masking:CannotExecuteMethodDuringSimulation')
        % ignore warnings coming from updates triggered by scope blocks
        disp(E.message);
    end
end
%% Icon related for the most part
try
    iconstr = pidpack.PIDConfig.getMaskDisplayString(currentblock);
    if ~strcmp(blkH.MaskDisplay,iconstr)
        blkH.MaskDisplay = iconstr;
    end
catch E
    disp(E.message);
end
end
% PID Form and Structure (Only set_param position, i/o size, and Name)
function addController(currentblock)
blkH = handle(currentblock);
maskH = get_param(currentblock, 'MaskObject');
if strcmp(blkH.Controller,'PID')
    createPID(currentblock);
elseif strcmp(blkH.Controller,'PI')
    createPI(currentblock);
elseif strcmp(blkH.Controller,'PD')
    createPD(currentblock);
end

maskH.resetPromotedParameters();
% Connect Integrators to RESET and I0 and D0 ports
pidpack.PIDConfig.connectIntegrators(currentblock);
end
% Create PID (Only set_param position, i/o size, and Name)
function createPID(currentblock)
blkH = handle(currentblock);
blk = getfullname(currentblock);
posI =           [285 115 315 145];
posIntegratorI = [495 98 570 162];
posSum =         [595 120 615 140];
posD =           [285 250 315 280];
posSumD =        [415 255 435 275];
posN =           [515 250 545 280];
posIntegratorD = [495 303 570 367];
posDifferentiator =  [495 233 570 297];
posSum1 =        [185 -10 205 10];
posSum2 =        [185 88 205 172];
posSum3 =        [185 255 205 275];
posb =           [100 -20 130 10];
posc =           [100 245 130 275];
if strcmp(blkH.Form,'Parallel')
    posP = [285 -15 315 15];
else % Ideal
    posP = [650 115 680 145];
end
% Add required blocks with the right orientation, position, number of
% ports.
externalResetSetting = {'ExternalReset', blkH.ExternalReset};
initialConditionSourceSetting = {'InitialConditionSource', blkH.InitialConditionSource};
if strcmp(blkH.TimeDomain,'Discrete-time')
    integrator = 'built-in/DiscreteIntegrator';
    initialConditionModeSetting = {'InitialConditionMode','State (most efficient)'};
else
    integrator = 'built-in/Integrator';
    initialConditionModeSetting = {};
end
if strcmp(blkH.ControllerParametersSource,'internal')
    pBlock = 'Proportional Gain';
    iBlock = 'Integral Gain';
    dBlock = 'Derivative Gain';
    nBlock = 'Filter Coefficient';
    bBlock = sprintf('Setpoint Weighting\n(Proportional)');
    cBlock = sprintf('Setpoint Weighting\n(Derivative)');
    pidnBlockType = 'built-in/Gain';
    pidnBlockSettings = {};
else
    pBlock = 'POut';
    iBlock = 'IOut';
    dBlock = 'DOut';
    nBlock = 'NOut';
    bBlock = 'bOut';
   