⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fm_linedlg.m

📁 这是一个很适合研究和学习用的电力系统仿真软件
💻 M
📖 第 1 页 / 共 2 页
字号:
            headingPosition = [LMarginW+RowLabelW+ColW+2*ColPadW Y RowLabelW uiH];
        end
        Y = Y-RowH;
        if ~isempty(prompt{iRow})
            headingPosition(2) = Y;
            uicontrol(tProps,...
                'String', prompt{iRow,1},...
                'Tag', prompt{iRow,1},...
                'Enable',enables{iRow}, ...
                'Position', headingPosition);
        end
    end

    iGroup = 1;

    Y = figPos(4)-TopMarginH;
    headingPosition = [LMarginW+RowLabelW+ColPadW Y ColW uiH];
    for iRow=1:nRows
        if iRow ==5 % start new column
            Y = figPos(4)-TopMarginH;
            headingPosition = [LMarginW+2*RowLabelW+ColW+3*ColPadW Y ColW uiH];
        end
        Y = Y-RowH;
        if ~isempty(prompt{iRow})
            headingPosition(2) = Y;
            uic = uicontrol(editProps,...
                'Style', properties{iRow,1},...
                'Callback', properties{iRow,2},...
                'Tag', properties{iRow,3},...
                'ToolTip', properties{iRow,3},...
                'String', strings{iRow},...
                'Value', values{iRow},...
                'UserData', data{iRow},...
                'Enable',enables{iRow}, ...
                'Position', headingPosition);
            localData.LimCheck(iGroup) = uic;
            localData.Prop{iGroup} = properties{iRow,3};
            if strcmp(properties{iRow,1},'edit')  % edit text box
                localData.OldVal{iGroup} = str2double(strings{iRow});
            end
            iGroup = iGroup + 1;
        end
    end

    % set color on color button
    % Check for common color, otherwise use white
    col  = cat(1,GetData(:).Color);
    col = unique(col,'rows');
    if size(col,1)>1,
        BGC = [1 1 1];
        localData.CommonColor = 0;
        ColVis='off';
    else,
        BGC = col;
        ColVis='on';
    end

    Y = figPos(4)-TopMarginH-4*RowH;
    headingPosition = [LMarginW+RowLabelW+ColPadW+(.1067*ColW) Y+(.164*uiH) ...
            ColW-(.205*ColW) uiH-(.3*uiH)];

    colorSwatch = uicontrol(editProps,...
        'BackgroundColor',BGC, ...
        'Style','frame', ...
        'Tag','Color', ...
        'ToolTip', 'Color', ...
        'Visible',ColVis, ...
        'Position', headingPosition);

    headingPosition = [LMarginW+RowLabelW+ColW+2*ColPadW Y RowLabelW uiH];
    uicontrol(editProps,...
        'Style', 'pushbutton',...
        'Callback', 'fm_linedlg getcolor me',...
        'Tag', '',...
        'BackgroundColor',Theme.color01,...
        'ForegroundColor',fgcolor,...
        'FontName','Helvetica', ...
        'Horiz','center', ...
        'String', 'Select...',...
        'UserData', colorSwatch,...
        'Position', headingPosition);

    % OK, Apply, Cancel, Help
    buttonX(1) = (figPos(3)-3*1.5*buttonW-2*buttonPad)/2;
    for ib = 2:3
        buttonX(ib) = buttonX(ib-1) + 1.5*buttonW + buttonPad;
    end

    buttonProps = struct(...
        'Parent', f,...
        'Units','character',...
        'BackgroundColor', Theme.color01,...
        'ForegroundColor', fgcolor,...
        'Position', [0 BotMarginH 1.5*buttonW 1.5*buttonH],...
        'Style', 'pushbutton');

    buttonProps.Position(1) = buttonX(1);
    uicontrol(buttonProps,...
        'Interruptible', 'off',...
        'String', 'OK',...
        'Callback', 'fm_linedlg button ok', ...
        'ForegroundColor',Theme.color04, ...
        'FontWeight','bold', ...
        'BackgroundColor',Theme.color03);

    buttonProps.Position(1) = buttonX(2);
    uicontrol(buttonProps,...
        'Interruptible', 'off',...
        'String', 'Cancel',...
        'Callback', 'fm_linedlg button cancel');

    buttonProps.Position(1) = buttonX(3);
    uicontrol(buttonProps,...
        'Interruptible', 'on',...
        'String', 'Apply',...
        'Callback', 'fm_linedlg button apply');

    set(fig,'Pointer',oldPointer);
    set(f,'Visible','on','Pointer','arrow');
    localData.HG = HG;

catch
    if exist('f')
        delete(f);
    end
    set(fig,'Pointer',oldPointer);
    for ct=1:length(HG),
        set(HG,'Selected',localData.Selected{ct});
    end
    lasterr
end

function localData = keypress(selection, localData)
key = double(get(gcbf,'CurrentCharacter'));
switch key
case 13, localData = button('ok',localData);
case 27, localData = button('cancel',localData);
end


function localData = showhelp(selection, localData)
try
    helpview([docroot '/mapfiles/plotedit.map'], ...
        'pe_line_change_props', 'PlotEditPlain');
catch
    fm_disp(['Unable to display help for Line Properties:' ...
            sprintf('\n') lasterr ],2);
end

function localData = button(selection, localData);
switch selection
case 'close'
    for ct=1:length(localData.HG)
        set(localData.HG(ct),'Selected',localData.Selected{ct});
    end
    delete(gcbf);
    localData = [];
case 'cancel'
    close(gcbf);
case 'ok'
    set(gcbf,'Pointer','watch');
    localData = LApplySettings(gcbf,localData);
    close(gcbf);
case 'apply'
    set(gcbf,'Pointer','watch');
    localData = LApplySettings(gcbf,localData);
    set(gcbf,'Pointer','arrow');
end


function val = getval(f,tag)
uic = findobj(f,'Tag',tag);
switch get(uic,'Style')
case 'edit'
    val = get(uic, 'String');
case {'checkbox' 'radiobutton'}
    val = get(uic, 'Value');
case 'popupmenu'
    choices = get(uic, 'UserData');
    val = choices{get(uic,'Value')};
case 'frame'
    val = get(uic, 'BackgroundColor');
end


function val = setval(f,tag,val)
uic = findobj(f,'Tag',tag);
switch get(uic,'Style')
case 'edit'
    set(uic, 'String',val);
case {'checkbox' 'radiobutton' 'popupmenu'}
    set(uic, 'Value',val);
end


function localData = verifyposnumber(uic, localData)
iGroup = find(uic==localData.LimCheck);
val = str2double(get(uic,'String'));
if ~isnan(val)
    if length(val)==1 & val>0
        % if it's a single number greater than zero, then it's fine
        localData.OldVal{iGroup} = val;
        return
    end
end
% trap errors
set(uic,'String',num2str(localData.OldVal{iGroup}));
fieldName = get(uic,'ToolTip');
fm_disp([fieldName ' field requires a single positive numeric input'],2)


function localData = getcolor(uic, localData)
colorSwatch = get(uic,'UserData');
currentColor = get(colorSwatch,'BackgroundColor');
c = uisetcolor(currentColor);

%---Trap when cancel is pressed.
if ~isequal(c,currentColor)
    set(colorSwatch,'BackgroundColor',c,'Visible','on');
end

function localData = LApplySettings(f, localData)

global Fig

hdl_line = get(Fig.line,'UserData');
hdl_line = hdl_line(end:-1:1);
Hdl_legend   = findobj(Fig.plot,'Tag','Checkbox2');
Hdl_listplot = findobj(Fig.plot,'Tag','Listbox2');
Hdl_tipoplot = findobj(Fig.plot,'Tag','PopupMenu1');
allbaby      = get(Fig.plot,'Children');
hdlfig       = allbaby(end-1);

HG = localData.HG;

try

    %---Only change LineWidth if not set to Current
    LW = str2double(getval(f,'LineWidth'));
    if ~isnan(LW),
        lineSettings.LineWidth = LW;
        localData.CommonWidth = 1;
    end % if strcmp(Marker...'Current')

    %---Only change Linestyle if not set to Current
    if ~strcmp(getval(f,'LineStyle'),'Current'),
        lineSettings.LineStyle = getval(f,'LineStyle');
        if ~localData.CommonStyle,
            StylePopup = findobj(f,'Tag','LineStyle');
            StyleVal = get(StylePopup,'Value');
            ud=get(StylePopup,'UserData');
            str = get(StylePopup,'String');
            set(StylePopup,'UserData',ud(2:end),'String',str(2:end), ...
                'Value',StyleVal-1);
            localData.CommonStyle= 1;
        end
    end % if strcmp(Linestyle...'Current')

    %---Only change the color if the colorswatch is visible
    colorSwatch = findobj(f,'Tag','Color');
    if strcmp(get(colorSwatch,'Visible'),'on');
        lineSettings.Color = getval(f,'Color');
    end % if colorswatch is visible

    %---Store subset for arrows
    arrowSettings = lineSettings;

    %---Only change the MarkerSize if on is actually entered
    MS = str2double(getval(f,'MarkerSize'));
    if ~isnan(MS),
        lineSettings.MarkerSize = MS;
    end % if strcmp(Marker...'Current')

    %---Only change Marker if not set to Current
    if ~strcmp(getval(f,'Marker'),'Current'),
        lineSettings.Marker= getval(f,'Marker');
        if ~localData.CommonMarker,
            StylePopup = findobj(f,'Tag','Marker');
            StyleVal = get(StylePopup,'Value');
            ud=get(StylePopup,'UserData');
            str = get(StylePopup,'String');
            set(StylePopup,'UserData',ud(2:end),'String',str(2:end), ...
                'Value',StyleVal-1);
            localData.CommonMarker = 1;
        end
    end % if strcmp(Marker...'Current')

    for ctHG=1:length(HG)
        if ishandle(HG(ctHG))
            set(HG(ctHG), lineSettings);
        else
            if isa(HG(ctHG),'editline'),
                settings = lineSettings;
            elseif isa(HG(ctHG),'arrowline'),
                settings = arrowSettings;
            end  % if/else isa(HG...
            props = fieldnames(settings)';
            for i = props
                i=i{1};
                set(HG(ctHG),i,getfield(settings,i));
            end % for i
        end
        hdl = legend(get(HG(ctHG),'Parent'));

    end

    if get(Hdl_legend,'Value')

        n_var = length(get(Hdl_listplot,'String'));
        tipoplot = get(Hdl_tipoplot,'Value');

        if tipoplot == 4 | tipoplot == 5

            h = findobj(hdl,'Type','line');

            for i = 0:n_var-1
                marker = get(hdl_line(n_var+i+1),'Marker');
                markersize = get(hdl_line(n_var+i+1),'MarkerSize');
                markercolor = get(hdl_line(n_var+i+1),'MarkerEdgeColor');
                %xdata = get(h(-i*2+3*n_var),'XData');
                %ydata = get(h(-i*2+3*n_var),'YData');
                %hmarker = plot((xdata(2)-xdata(1))/1.2,ydata(1));
                set(h(i+1),'Marker',marker,'MarkerEdgeColor',markercolor,'MarkerSize',markersize);
            end

        end
    end

catch
    fm_disp(lasterr,2)
    fm_disp('Unable to set line properties.',2);
end


function LNoLineError
fm_disp(['No lines are selected.  Click on an line to select it.'],2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -