www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@breakpointeditor/breakpointeditor.m
function obj=breakpointeditor(parent) % cgtools.breakpointeditor Constructor. % Copyright 2000-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. obj = cgtools.breakpointeditor; obj.Parent = parent; panel = mbcgui.container.titlebarpanel(... 'Parent', parent, ... 'Visible', obj.Visible, ... 'BarTitle', 'none'); obj.fig = ancestor(parent,'figure'); obj.connect(xregfigurehook(parent),'up'); uic = uicontextmenu('Parent', obj.fig); % Creates the table viewing panes. Returns the layout object it sits in % and a data structure to be bolted onto the figure userdata. P = com.mathworks.toolbox.mbc.gui.peer.NormaliserTablePeer; obj.TableWrapper = mbcwidgets.Table1D(P, ... 'parent', panel, ... 'editable', true, ... 'uicontextmenu', uic, ... 'SelectionMode', 'MultiRegion', ... 'valuechangedcallback', {@i_tableEditCallback,obj}, ... 'selectionchangedcallback', {@i_tableSelectionChanged,obj}); obj.TableWrapper.createCopyPasteMenus(uic); uimenu(uic, 'Label', '&Lock breakpoint', ... 'Callback', {@i_cellLock,obj,1}, ... 'Separator', 'on'); uimenu(uic, 'Label', '&Unlock breakpoint', ... 'Callback', {@i_cellLock,obj,0}); uimenu(uic, 'Label', 'Show &History', ... 'Callback', {@i_showHistory,obj}); d.LineAxesWrapper = mbcgui.widget.AxesContainer(... 'Parent',panel,... 'Border', [25 30 5 20]); obj.LineAxes = d.LineAxesWrapper.AxesHandle; % set up model behaviour graphs set(obj.LineAxes,... 'Units','pixels',... 'Box','on',... 'Position',[0 0 100 100],... 'HandleVisibility','callback'); line_label = get(obj.LineAxes,'XLabel'); set(line_label,'Interpreter','none'); line_title = get(obj.LineAxes,'Title'); set(line_title,'String','Breakpoint Spacing'); d.ModelLines= []; % Set up a field where we'll store the model behaviour lines later on. %set up Normaliser display graph d.PointAxesWrapper = mbcgui.widget.AxesContainer(... 'Parent',panel,... 'Border', [25 30 5 20]); obj.PointAxes = d.PointAxesWrapper.AxesHandle; set(obj.PointAxes,... 'Units','pixels',... 'Box','on',... 'Position',[0 0 100 100],... 'HandleVisibility','callback',... 'XGrid','on',... 'YGrid','on'); point_label = get(obj.PointAxes,'XLabel'); set(point_label,'Interpreter','none'); point_title=get(obj.PointAxes,'Title'); set(point_title,'String','Normalizer Display'); % Now create the context menu for the model behaviour line. d.ModelMenu = uicontextmenu('Parent',obj.fig); d.ModelDisplay = uimenu('Parent',d.ModelMenu,... 'Label','&Display'); d.Behaviour(1) = uimenu(d.ModelDisplay,... 'Label','&Model',... 'Callback',{@i_blueline_style,obj,1},... 'Checked','on'); d.Behaviour(2) = uimenu(d.ModelDisplay,... 'Label','Model &Curvature',... 'Callback',{@i_blueline_style,obj,2}); d.LineNumber = uimenu(d.ModelMenu,... 'Label','Number of Lines'); for i = 1:20; d.LineMenu(i) = uimenu(d.LineNumber,... 'Label',sprintf('%d',i),... 'Checked','off',... 'Callback',{@i_line_number,obj,i}); end set(d.LineMenu(1),'Checked','on'); d.LineCount = 1; d.ModelFlag = 1; % Create the context menus for: % (yellow) points (lock breakpoint) % black points (unlock breakpoint) % red lines (delete breakpoint/lock breakpoint) % black lines (unlock breakpoint) % green lines (add breakpoint) d.PointContextMenu = xregGui.popupmenu(obj.fig); d.PointContextMenu.init(... {'&Lock Breakpoint', '&Delete Breakpoint'},... {{@i_pointLock,obj,1}, {@i_pointDelete,obj}},... {'on', 'on'},... {'off', 'on'} ); d.LockedPointContextMenu = xregGui.popupmenu(obj.fig); d.LockedPointContextMenu.init({'&Unlock Breakpoint'},{{@i_pointLock,obj,0}}); d.LineContextMenu = xregGui.popupmenu(obj.fig); d.LineContextMenu.init(... {'&Lock Breakpoint', '&Delete Breakpoint'},... {{@i_lineLock,obj,1}, {@i_lineDelete,obj}},... {'on', 'on'},... {'off', 'on'} ); d.DeletedLineContextMenu = xregGui.popupmenu(obj.fig); d.DeletedLineContextMenu.init({'&Add Breakpoint'},{{@i_AddBreakpoint,obj}}); d.LockedLineContextMenu = xregGui.popupmenu(obj.fig); d.LockedLineContextMenu.init({'&Unlock Breakpoint'},{{@i_lineLock,obj,0}}); % Put graphs together d.TableGrid = xreggridbaglayout(panel,... 'packstatus','off',... 'elements',{obj.TableWrapper,d.PointAxesWrapper,d.LineAxesWrapper},... 'dimension',[1 3],... 'border',[5 5 5 5],... 'colsizes',[160 -1 -1]); set(panel,'ContentHandle',{d.TableGrid}); obj.layout = panel; obj.userdata = d; %---------------------------- function i_blueline_style(src,event,obj,newflag) d = obj.userdata; d.ModelFlag = newflag; % 1 means just show model, 2 means curvature set(d.Behaviour,'Checked','off'); set(d.Behaviour(newflag),'Checked','on'); obj.userdata = d; obj.pPlotModel; %---------------------------- function i_line_number(src,event,obj,num) set(obj.userdata.LineMenu(obj.userdata.LineCount),'Checked','off'); obj.userdata.LineCount = num; set(obj.userdata.LineMenu(num),'Checked','on'); obj.pPlotModel; %---------------------------- function i_lineLock(src,event,obj,lock) d = obj.userdata; h = gco; % the current object is the line which was clicked for n=1:length(d.Lines) if d.Lines(n)==h i_Lock(obj,n,lock); return; end end error(message('mbc:cgtools:breakpointeditor:InvalidState')); %---------------------------- function i_pointLock(src,event,obj,lock) d = obj.userdata; h = gco; % the current object is the "point" which was clicked for n=1:length(d.Points) if d.Points(n)==h i_Lock(obj,n,lock); return; end end error(message('mbc:cgtools:breakpointeditor:InvalidState')); %---------------------------- function i_showHistory(unused1,unused2,obj) send(obj,'ShowHistory',handle.EventData(obj,'ShowHistory')); %------------------------- % Callback from cell popup menu %------------------------- function i_cellLock(menu,eventdata,obj,lock) BPL = obj.BPL; rows = double(obj.TableWrapper.getSelectedRows); % Lock / Unlock BPL(rows) = lock; i_Lock(obj,rows,BPL(rows)); obj.TableWrapper.clearSelection; %------------------------- function i_tableSelectionChanged(table,eventdata,obj) send(obj,'TableCellsSelected',handle.EventData(obj,'TableCellsSelected')); %--------------------------- function i_Lock(obj,rows,locks) BPL = obj.BPL; BPL(rows) = locks; obj.BPL = BPL; % update table obj.TableWrapper.Peer.setNormaliserLocks(BPL); obj.pClearPoint(unique([rows,rows+1])); obj.pPlotPoint(unique([rows,rows+1])); %--------------------------- function i_tableEditCallback(wrapper,evt,obj) data = obj.matrix; rows = evt.data.Rows; columns = evt.data.Columns; data(rows, columns) = evt.data.NewValue; obj.changedesc = 'Manual entry from breakpoint editor'; % we don't need to worry about where exactly the change was made try obj.matrix = data; catch obj.TableWrapper.Peer.setNormaliserData(obj.matrix); return end RedrawRows = unique([rows(:); rows(:)+1]); obj.pClearPoint(RedrawRows); obj.pPlotPoint(RedrawRows); %--------------------------- function i_AddBreakpoint(src,evt,obj) d = obj.userdata; h = gco; % the current object is the line which was clicked for n=1:length(d.MissingLines) mb = [d.MissingLines{n} d.MissingPoints{n}]; for k=1:length(mb) if mb(k)==h newx = get(h,'XData'); newx = newx(1); % the missing line is to the left of line 'n', % so the new breakpoint takes index n. i_Add(obj,n,newx); return; end end end error(message('mbc:cgtools:breakpointeditor:InvalidState')); %---------------------------- function i_pointDelete(src,event,obj) d = obj.userdata; h = gco; % the current object is the point which was clicked for n=1:length(d.Points) if d.Points(n)==h i_Delete(obj,n); return; end end error(message('mbc:cgtools:breakpointeditor:InvalidState')); %---------------------------- function i_lineDelete(src,event,obj) d = obj.userdata; h = gco; % the current object is the line which was clicked for n=1:length(d.Lines) if d.Lines(n)==h i_Delete(obj,n); return; end end error(message('mbc:cgtools:breakpointeditor:InvalidState')); %---------------------------- function i_Delete(obj,index) % set the specified breakpoint, lock and value to empty. % this is UDD, so we have to do it the long way. BP = obj.BP; BPL = obj.BPL; V = obj.V; BP(index) = []; BPL(index) = []; V(index) = []; obj.pClearAxes; obj.changedesc = 'Breakpoint deleted'; obj.matrix = [BP V]; obj.BPL = BPL; % the listeners on these variables will cause the normaliser % itself to be updated. % We need to redo everything because the length of all the % vectors has changed. obj.showbreakpoints(obj.normptr,obj.SFData); %---------------------------- function i_Add(obj,n,x) % set the specified breakpoint, lock and value to empty. % this is UDD, so we have to do it the long way. BP = obj.BP; BPL = obj.BPL; V = obj.V; newV = interp1( [BP(n-1);BP(n)], [V(n-1);V(n)], x); newV = round(newV); % to avoid spurious ~10^-16 errors BP = [ BP(1:n-1) ; x ; BP(n:end) ]; BPL = [ BPL(1:n-1); 0 ; BPL(n:end) ]; % unlocked V = [ V(1:n-1) ; newV; V(n:end) ]; obj.changedesc = 'Breakpoint added'; obj.matrix = [BP V]; obj.BPL = BPL; % the listeners on these variables will cause the normaliser % itself to be updated. obj.showbreakpoints(obj.normptr,obj.SFData);