Skip to content
TTdiag.m 2.61 KiB
Newer Older
Colin Eles's avatar
Colin Eles committed
function TTdiag(varargin)

orig_gcbh = gcbh;


Action = varargin{1};

if 1 ~= nargin
    DAStudio.warning('improper function use')
end

switch Action,
    case 'Open',
        blockHandleTTTopMask = orig_gcbh;
        LocalOpenBlockFcn(blockHandleTTTopMask);
        
    case 'Close',
        blockHandleTTTopMask = orig_gcbh;
        LocalCloseBlockFcn(blockHandleTTTopMask);

    case 'Copy',
        blockHandleTTTopMask = orig_gcbh;
        LocalCopyBlockFcn(blockHandleTTTopMask);
        DAStudio.ModelExplorer
Colin Eles's avatar
Colin Eles committed
        
    otherwise,
        DAStudio.error('Simulink:dialog:UnknownAction',Action);
    
end
    
end

function LocalCopyBlockFcn(blockHandleTTTopMask)
    data = get(blockHandleTTTopMask,'UserData')
    if(~isempty(data))
        data_new = data.clone(blockHandleTTTopMask);  
  
        set_param(blockHandleTTTopMask,'UserData',data_new)
Colin Eles's avatar
Colin Eles committed
    end
end

function LocalOpenBlockFcn(blockHandleTTTopMask)

        modelHandle = bdroot(blockHandleTTTopMask);
Colin Eles's avatar
Colin Eles committed


    % check if the user is trying to open the block from the library
    if strcmp(get_param(modelHandle,'Lock'), 'on') || ...
Colin Eles's avatar
Colin Eles committed
     strcmp(get_param(blockHandleTTTopMask,'LinkStatus'),'implicit')

      errordlg(...
          DAStudio.message('can not open Model Locked, Add to new model to use'),...
Colin Eles's avatar
Colin Eles committed
          'Error', 'modal')

     

    data = get_param(blockHandleTTTopMask,'UserData');
    
    if isempty(data)
        data = Data();
        data.init();
    else
        if ~data.valid
             errordlg(...
          DAStudio.message('Block Data has been corputed'),...
          'Error', 'modal')
            return
        end
        if data.open
            if ishghandle(data.fig)
             figure(data.fig)

            end
            return
        end
Colin Eles's avatar
Colin Eles committed
        
    end
    
    gui = GUI(blockHandleTTTopMask);   
    
    gui.setData(data)
    gui.init();
        set_param(blockHandleTTTopMask,'UserData',data); 
Colin Eles's avatar
Colin Eles committed
        set_param(blockHandleTTTopMask, 'UserDataPersistent', 'on');

Colin Eles's avatar
Colin Eles committed
end

function LocalCloseRequestBlockFcn(blockHandleTTTopMask)
modelHandle = bdroot(blockHandleTTTopMask);


data = get_param(blockHandleTTTopMask,'UserData')
Colin Eles's avatar
Colin Eles committed

if ~isempty(data)
    if data.open
        delete(data.fig)
    end
end
        %set_param(gui.fig,'Visible','off')
Colin Eles's avatar
Colin Eles committed
end

% Make a copy of a handle object. 
        function new = copy(this,h) 
            % Instantiate new object of the same class. 
            new = feval(class(this),h); 
            % Copy all non-hidden properties. 
            p = properties(this); 
            for i = 1:length(p) 
                new.(p{i}) = this.(p{i}); 
            end 
        end