www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@breakpointeditor/pPlotPoint.m
function pPlotPoint(obj,i) %PPLOTPOINT Private method. % % obj.pPlotPoint(index) % The parameter is the index of the breakpoint to plot. % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. % to cope with vector inputs... if length(i)>1 for n=1:length(i) % ignore out-of-range indices if i(n)<=length(obj.BP) obj.pPlotPoint( i(n) ); end end return; end % to do the work for a scalar input... d = obj.userdata; BP = obj.BP; BPL = obj.BPL; V = obj.V; if BPL(i)==0 % not locked line_menu = d.LineContextMenu; line_color = 'red'; line_function = {@i_point_click,obj,i}; point_menu = d.PointContextMenu; point_color = 'blue'; point_marker = 'o'; point_markersize = 6; point_function = {@i_point_click,obj,i}; else line_menu = d.LockedLineContextMenu; line_color = 'k'; line_function = []; point_menu = d.LockedPointContextMenu; point_color = 'k'; point_marker = '.'; point_markersize = 18; point_function = []; end ylimits = get(obj.LineAxes,'YLim'); d.Lines(i) = line([BP(i);BP(i)], ylimits,... 'Color',line_color,... 'Parent',obj.LineAxes,... 'UIContextMenu',line_menu.menu,... 'ButtonDownFcn',line_function); if obj.shownormaliser % plot the "point": actually line with only one point d.Points(i) = line(BP(i),V(i),... 'Parent',obj.PointAxes,... 'Color',point_color,... 'Marker',point_marker,... 'MarkerSize',point_markersize,... 'UIContextMenu',point_menu.menu,... 'ButtonDownFcn',point_function); if i~=1 % join to the previous "point" with a line d.PointJoin{i} = line(BP(i-1:i),V(i-1:i),... 'Parent',obj.PointAxes,... 'HitTest','off',... 'Color','blue'); d.MissingLines{i} = []; % incase any old handles are floating around d.MissingPoints{i} = []; % on the line axes, check for missing breakpoints. see note below this function for j = V(i-1):V(i) if isempty(intersect(j,[V(i-1) ; V(i)])) % these is a value missing between this breakpoint and the previous [uniqueV,iV] = unique(V,'first'); missing_bp = interp1(uniqueV,BP(iV),j); newline = line([missing_bp,missing_bp],ylimits,... 'Color','green',... 'Parent',obj.LineAxes,... 'UIContextMenu',d.DeletedLineContextMenu.menu); d.MissingLines{i} = [d.MissingLines{i} newline]; newpoint = line(missing_bp,j,... 'Color','green',... 'Parent',obj.PointAxes,... 'UIContextMenu',d.DeletedLineContextMenu.menu,... 'Marker',point_marker,... 'MarkerSize',point_markersize); d.MissingPoints{i} = [d.MissingPoints{i} newpoint]; end end end end obj.userdata = d; % Note on checking for missing breakpoints. % Values are consecutive integers unless a breakpoint has been deleted. % The loop "for j=V(i-1):V(i)" runs twice if the two values are % consecutive integers; more times otherwise. % The line "intersect(j,[V(i-1);V(i)]) will return a non-empty value for % the cases j==V(i-1) and j==V(i). Thus, the isempty() statement will % run only if j also takes a different value, which can only be an integer % between these limits: i.e. a deleted breakpoint % We use the same functions for handling the dragging of lines % as for the dragging of points. %-------------------------------------- function i_point_click(src,evt,obj,index) set(obj.fig, 'WindowButtonMotionFcn',{@i_point_drag,obj,index}); bm = xregGui.ButtonUpManager(obj.fig); bm.getNextEvent({@i_point_release,obj,index}); % select whole row of table (i.e. two columns) obj.TableWrapper.selectRows(index); send(obj,'TableCellsSelected',handle.EventData(obj,'TableCellsSelected')); d = obj.userdata; % store the handles for all the relevant lines, for quicker access later on. if index==1 temp = get(obj.PointAxes,'XLim'); drag.left_limit = temp(1); drag.left_missing_lines = []; % array of handles to "missing breakpoint" lines drag.left_missing_points = []; % array of handles to "missing breakpoint" points else temp = obj.BP; drag.left_limit = temp(index-1); drag.left_missing_lines = d.MissingLines{index}; drag.left_missing_points = d.MissingPoints{index}; end if index==length(obj.BP) temp = get(obj.PointAxes,'XLim'); drag.right_limit = temp(2); drag.right_missing_lines = []; drag.right_missing_points = []; else temp = obj.BP; drag.right_limit = temp(index+1); drag.right_missing_lines = d.MissingLines{index+1}; drag.right_missing_points = d.MissingPoints{index+1}; end drag.peer = obj.TableWrapper.Peer; obj.DragData = drag; %-------------------------------------- function i_point_drag(~,~,obj,index) d = obj.userdata; drag = obj.DragData; left_limit = drag.left_limit; right_limit = drag.right_limit; left_missing_lines = drag.left_missing_lines; right_missing_lines = drag.right_missing_lines; left_missing_points = drag.left_missing_points; right_missing_points = drag.right_missing_points; % get mouse position and apply limits mouse_position = get(obj.PointAxes,'CurrentPoint'); newx = mouse_position(1); if newx>right_limit newx = right_limit; elseif newx<left_limit newx = left_limit; end if obj.shownormaliser % reposition point and joining lines set(d.Points(index),'XData',newx); if index~=1 join = d.PointJoin{index}; xvals = get(join,'XData'); xvals(2) = newx; set(join,'XData',xvals); end if index~=length(obj.BP) join = d.PointJoin{index+1}; xvals = get(join,'XData'); xvals(1) = newx; set(join,'XData',xvals); end end % reposition line and any "missing" breakpoints which depend on it set(d.Lines(index),'XData',[newx newx]); if ~isempty(left_missing_lines) % linearly space the "missing" breakpoints between the two existing ones xvals = linspace(left_limit,newx,length(left_missing_lines)+2); xvals = xvals(2:end-1); % remove either end for k=1:length(left_missing_lines) % unfortunately, this doesn't seem to vectorise set(left_missing_lines(k),'XData', [xvals(k) xvals(k)]); set(left_missing_points(k),'XData', xvals(k)); end end if ~isempty(right_missing_lines) % linearly space the "missing" breakpoints between the two existing ones xvals = linspace(newx,right_limit,length(right_missing_lines)+2); xvals = xvals(2:end-1); % remove either end for k=1:length(right_missing_lines) % unfortunately, this doesn't seem to vectorise set(right_missing_lines(k),'XData', [xvals(k) xvals(k)]); set(right_missing_points(k),'XData', xvals(k)); end end drag.peer.setNormaliserDataAt(index-1, 0, newx); %-------------------------------------- function i_point_release(src,evt,obj,index) d = obj.userdata; obj.DragData = []; set(obj.fig, 'WindowButtonMotionFcn',''); % get new X-value from Line (since Point does not % necessarily exist) newx = get(d.Lines(index),'XData'); newx = newx(1); obj.changedesc = 'Set From Breakpoint editor graphs'; BP = obj.BP; oldx = BP(index); BP(index) = newx; try obj.BP = BP; catch obj.pClearPoint([index,index+1]); obj.pPlotPoint([index,index+1]); obj.TableWrapper.Peer.setNormaliserDataAt(index-1,0,oldx); end