function [isMasked, parent] = isUnderMaskedSubsystem(daObject)
    % ISUNDERMASKEDSUBSYSTEM Returns true if the simulink object is under a
    % masked subsystem and also optionally returns the masked subsystem
    % if the masked subsystem is not found, return the selected simulink
    % object as the parent
    
    % Copyright 2015-2022 The MathWorks, Inc.
    
    parent = daObject;
    isMasked = parent.isMasked;
    % loop until an appropriate subsystem is found
    while ~isa(parent,'Simulink.BlockDiagram')
        if fxptds.isStateflowChartObject(parent)
            if isMasked
                return;
            end
            parent = parent.up;
        else
            obj = parent.getParent;
            % if the selected subsystem is masked and its parent is the top
            % model or if the selected subsytem is masked and its parent is 
            % a stateflow chart, do not update the parent and return
            if isMasked && ...
                    (isa(obj,'Simulink.BlockDiagram') ||  fxptds.isStateflowChartObject(obj))
                return;
            end
    
            if isempty(obj)
                pName = get_param(parent.getFullName,'Parent');
                parent = get_param(pName,'Object');
            else
                parent = obj;
            end
        end
        if parent.isMasked
            isMasked = true;
            return;
        end
    end
end
