www.gusucode.com > sl3ddemos工具箱matlab源码程序 > sl3ddemos/sl3ddemo_callbacks.m

    function sl3ddemo_callbacks(varargin)
%SL3DDEMO_CALLBACKS Process callbacks for Simulink 3D Animation examples.
%   SL3DDEMO_CALLBACKS processes callbacks for Simulink 3D Animation
%   examples.
%
%   Not to be called directly.

%   Copyright 1998-2014 HUMUSOFT s.r.o. and The MathWorks, Inc.


% the switchboard
feval(varargin{:});


%=============================================================================
function DelayedError(mdl, msgtype, msg)   %#ok<DEFNU> called by switchboard



% create error record and push it
sldiagviewer.reportError(msg,'Component','SL3D','Category',msgtype);
% show the error with delay so it is not covered by other model windows
t = timer( ...
  'ObjectVisibility', 'off', ...
  'ExecutionMode', 'singleShot', ...
  'StartDelay', 5, ...
  'TimerFcn', @(~, ~) slsfnagctlr('View'), ...
  'StopFcn', @(this, ~) delete(this) ...
);
start(t);



%============================================================================
function VRMEMB1_PostLoad   %#ok<DEFNU> called by switchboard

% get the handle to the model
h = get_param(gcs,'Handle');
bd = get_param(bdroot(h), 'Object');
bd.addCallback('PreShow', sprintf('VRMEMB1_%s', bd.Name), @() VRMEMB1_PreShow(h));

   
   
%============================================================================
function VRMEMB1_PreShow(h)

% find and open ZOOM slider block, read its position, move it to the left and down a bit
zoomh = find_system(h, 'Name', 'ZOOM slider');
set_param(zoomh, 'UserData', []);    % clean any previous dialog
open_system(zoomh);
zoompos = get(get_param(zoomh, 'UserData'), 'Position');
zoompos(1:2) = [30 0.5*zoompos(2)];
zoomfigh = get_param(zoomh, 'UserData');
set(zoomfigh, 'Position', zoompos);

% find and open Rotation speed slider block, change its position
roth = find_system(h, 'Name', 'Rotation speed slider');
set_param(roth, 'UserData', []);    % clean any previous dialog
open_system(roth);
rotpos = [zoompos(1) zoompos(2)-1.5*zoompos(4) zoompos(3:4)];
set(get_param(roth, 'UserData'), 'Position', rotpos);

% hook slider callback so that zoom also works when model is not running
zoomslidh = findobj(zoomfigh, 'Type','UIControl', 'Style','Slider');
set(zoomslidh, 'Callback', sprintf('%s; sl3ddemo_callbacks(''VRMEMB1_ZoomSlider'',''%s'');', ...
                           get(zoomslidh, 'Callback'), gcs) );
                       
% window position changes should not dirty the model
set_param(h, 'Dirty', 'off');



%============================================================================
function VRMEMB1_ZoomSlider(sys)   %#ok<DEFNU> called by switchboard

% don't do anything if simulation running
if strcmpi(get_param(sys, 'SimulationStatus'), 'running')
  return;
end

% do the zoom as if simulation was running
udb = get_param([sys, '/VR Sink'], 'UserData');
udf = get(gcbf,'UserData');
udb.World.View1.fieldOfView = str2double(get(udf.GainEdit, 'String'));