www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgprecfix/pCreateFixedPointEditor.m

    function BitFrame = pCreateFixedPointEditor(obj, hInfo) %#ok<INUSL>
%PCREATEFIXEDPOINTEDITOR Create editing layout for fixed point properties
%
%  LYT = PCREATEFIXEDPOINTEDITOR(OBJ, HINFO) creates and returns a layout
%  that can be used for editing the fixed point bit properties of the
%  precision object.  This function is designed to be called from the
%  editor pages of child classes.

%   Copyright 2000-2015 The MathWorks, Inc.


hGroup = hInfo.PageGroup;
hParent = hInfo.Parent;
hData = xregGui.RunTimePointer;

BitFrame = mbcgui.container.layoutpanel('Parent', hParent, ...
    'Visible', 'off', ...
    'BorderType', 'etchedin', ...
    'Title', 'Fixed point storage', ...
    'LayoutBorder', [10 0 10 5]);

% Radio buttons and edit box for the number of bits
ud.hBitRadios = xregGui.rbgroup('Parent', BitFrame, ...
    'nx', 1, 'ny', 4, ...
    'Callback', {@i_rbeditbits, hInfo, hData}, ...
    'String', {'Byte (8 bits)'; 'Word (16 bits)'; 'Long (32 bits)'; 'Custom:'});
ud.hBitEdit = mbcgui.widget.Spinner('Parent', BitFrame, ...
    'Rule', 'int', ....
    'Min', 1, ...
    'Max', 32, ...
    'Callback', {@i_editbits, hInfo, hData});
ud.hNumBitsLabel = xregGui.labelcontrol('Parent', BitFrame, ...
    'String', 'Number of bits:', ...
    'LabelSizeMode', 'absolute', ...
    'ControlSizeMode', 'absolute', ...
    'BaselineOffsetZero', 'top', ...
    'BaselineOffset', -14, ...
    'BaselineOffsetMode', 'manual', ...
    'LabelSize', 130, ...
    'ControlSize', 90, ...
    'Control', ud.hBitRadios);

% Fixed point position
ud.hFixedPoint = mbcgui.widget.Spinner('Parent', BitFrame, ...
    'Rule', 'int', ....
    'Min', 0, ...
    'Max', 32, ...
    'Callback', {@i_editfixedpos, hInfo, hData});    
ud.hFixedPointLabel = xregGui.labelcontrol('Parent', BitFrame, ...
    'String', 'Fixed point position:', ...
    'LabelSizeMode', 'absolute', ...
    'ControlSizeMode', 'absolute', ...
    'LabelSize', 130, ...
    'ControlSize', 60, ...
    'Control', ud.hFixedPoint);

% Signed/unsigned
ud.hSigned = uicontrol('Parent', BitFrame, ...
    'Style', 'checkbox', ...
    'String', 'Signed', ...
    'Callback', {@i_editsigned, hInfo, hData});

BitLyt = xreggridbaglayout(BitFrame, ...
    'dimension', [6 2], ...
    'rowsizes', [60 20 10 20 5 15], ...
    'colsizes', [225 60], ...
    'mergeblock', {[1 2], [1 1]}, ...
    'elements', {ud.hNumBitsLabel, [], [], ud.hFixedPointLabel, [], ud.hSigned, [], ud.hBitEdit});
set(BitFrame, 'LayoutComponent', {BitLyt});

ud.ObjList = event.listener(hGroup, 'ObjectChanged', @(h,evt) i_update(hInfo, hData));
hData.info = ud;

i_update(hInfo, hData);



function i_update(hInfo, hData)
obj = hInfo.getObject;
ud = hData.info;

NBits = get(obj, 'bits');
RBOptionIdx = find(NBits==[8 16 32]);
CustomEn = 'off';
if isempty(RBOptionIdx)
    RBOptionIdx = 4;
    CustomEn = 'on';
end

set(ud.hBitRadios, 'Selected', RBOptionIdx);
ud.hBitEdit.Value = NBits;
ud.hBitEdit.Enable = CustomEn;

ud.hFixedPoint.Value = get(obj, 'ptpos');
set(ud.hSigned, 'Value', get(obj, 'signed'));

i_updatewritable(hInfo, hData);


function i_updatewritable(hInfo, hData)
obj = hInfo.getObject;
ud = hData.info;
CustomEn = 'off';
if get(obj, 'writable')
    en = 'on';
    if ud.hBitRadios.Selected==4
        CustomEn = 'on';
    end
else
    en = 'off';
end

ud.hNumBitsLabel.Enable = en;
ud.hFixedPointLabel.Enable = en;
set(ud.hSigned, 'Enable', en);
ud.hBitEdit.Enable = CustomEn;


function i_rbeditbits(src, evt, hInfo, hData)
ud = hData.info;
RBOptionIdx = src.Selected;
if RBOptionIdx==4 
    % Enable the edit box
    ud.hBitEdit.Enable = 'on';
else
    % Disable the edit box
    ud.hBitEdit.Enable = 'off';
    
    % Update the edit box with a new value
    Presets = [8 16 32];
    ud.hBitEdit.Value = Presets(RBOptionIdx);
end
i_editbits(ud.hBitEdit, evt, hInfo, hData);

function i_editbits(src, evt, hInfo, hData)
obj = hInfo.getObject;
obj = set(obj, 'bits', src.Value);
i_quietupdate(hInfo, obj, hData.info);


function i_editfixedpos(src, evt, hInfo, hData)
obj = hInfo.getObject;
obj = set(obj, 'ptpos', src.Value);
i_quietupdate(hInfo, obj, hData.info);


function i_editsigned(src, evt, hInfo, hData)
obj = hInfo.getObject;
obj = set(obj, 'signed', get(src, 'Value'));
i_quietupdate(hInfo, obj, hData.info);


function i_quietupdate(hInfo, obj, ud)
ud.ObjList.Enabled = false;
hInfo.updateObject(obj);
ud.ObjList.Enabled = true;