time | Calls | line |
---|
| | 1 | function varargout = plotedit(varargin)
|
| | 2 | %PLOTEDIT Tools for editing and annotating plots
|
| | 3 | % PLOTEDIT ON starts plot edit mode for the current figure.
|
| | 4 | % PLOTEDIT OFF ends plot edit mode for the current figure.
|
| | 5 | % PLOTEDIT with no arguments toggles the plot edit mode for
|
| | 6 | % the current figure.
|
| | 7 | %
|
| | 8 | % PLOTEDIT(FIG) toggles the plot edit mode for figure FIG.
|
| | 9 | % PLOTEDIT(FIG,'STATE') specifies the PLOTEDIT STATE for
|
| | 10 | % the figure FIG.
|
| | 11 | % PLOTEDIT('STATE') specifies the PLOTEDIT STATE for
|
| | 12 | % the current figure.
|
| | 13 | %
|
| | 14 | % STATE can be one of the strings:
|
| | 15 | % ON - starts plot edit mode
|
| | 16 | % OFF - ends plot edit mode
|
| | 17 | % SHOWTOOLSMENU - displays the Tools menu (the default)
|
| | 18 | % HIDETOOLSMENU - removes the Tools menu from the menubar
|
| | 19 | %
|
| | 20 | % When PLOTEDIT is ON, use the Tools menu to add and
|
| | 21 | % modify objects, or select the annotation toolbar buttons
|
| | 22 | % to add annotations such as text, line and arrows.
|
| | 23 | % Click and drag objects to move or resize them.
|
| | 24 | %
|
| | 25 | % To edit object properties, right click or double click on
|
| | 26 | % the object.
|
| | 27 | %
|
| | 28 | % Shift-click to select multiple objects.
|
| | 29 | %
|
| | 30 | % See also PROPEDIT.
|
| | 31 |
|
| | 32 | % Internal interfaces for toolbox-plotedit compatibility
|
| | 33 | %
|
| | 34 | % plotedit(FIG,'hidetoolsmenu')
|
| | 35 | % makes the standard figure 'Tools' menu Visible off
|
| | 36 | % plotedit(FIG,'showtoolsmenu')
|
| | 37 | % makes the standard figure 'Tools' menu Visible on
|
| | 38 | % h = plotedit(FIG,'gettoolbuttons')
|
| | 39 | % returns a list plot editing and annotation buttons in
|
| | 40 | % the toolbar. Used by UISUSPEND and UIRESTORE.
|
| | 41 | % h = plotedit(FIG,'locktoolbarvisibility')
|
| | 42 | % freezes the current state of the toolbar.
|
| | 43 | % plotedit(FIG,'setsystemeditmenus')
|
| | 44 | % restores the system Edit menu.
|
| | 45 | % plotedit(FIG,'setploteditmenus')
|
| | 46 | % restores the plotedit Edit menu.
|
| | 47 | % plotedit(FIG,'plotedittoolbar',action)
|
| | 48 | % applies the action to the plot edit toolbar.
|
| | 49 | %
|
| | 50 | % these are used by UISUSPEND/UIRESTORE
|
| | 51 | % a = plotedit(FIG,'getenabletools')
|
| | 52 | % returns the enable state of the plot editing tools
|
| | 53 | % plotedit(FIG,'setenabletools','off')
|
| | 54 | % disables the plot editing tools under Tools menu
|
| | 55 | % and disables the Tools menu callback which updates
|
| | 56 | % the status of the tools menu, and disables the plot
|
| | 57 | % editing tools in the Toolbar
|
| | 58 | % plotedit(FIG,'setenabletools','on')
|
| | 59 | % enables the Tools menu and the items underneath it
|
| | 60 | % and enables the plot editing buttons in the Toolbar
|
| | 61 | %
|
| | 62 | % To hide the figure toolbar, set the figure 'ToolBar'
|
| | 63 | % property (hidden) to 'none'.
|
| | 64 | % fig.ToolBar = 'none';
|
| | 65 | %
|
| | 66 | % plotedit({'subfcn',...}) fevals the subfunction and passes
|
| | 67 | % it the rest of the inputs.
|
| | 68 | %
|
| | 69 | % plotedit(FIG,'on','pointer',POINTER) if the current pointer is a watch
|
| | 70 | % sets the pointer to return to when exiting plotedit mode to
|
| | 71 | % POINTER. If not specified use the default pointer.
|
| | 72 |
|
| | 73 | % Copyright 1984-2017 The MathWorks, Inc.
|
| | 74 |
|
< 0.001 | 2 | 75 | pointer = [];
|
< 0.001 | 2 | 76 | switch nargin
|
< 0.001 | 2 | 77 | case 0
|
| | 78 | % plotedit
|
| | 79 | if nargout > 0
|
| | 80 | error(message('MATLAB:graph2d:plotedit:InvalidInputForOutArg'))
|
| | 81 | end
|
| | 82 | fig = gcf;
|
| | 83 | action = 'toggle';
|
< 0.001 | 2 | 84 | case 1
|
< 0.001 | 2 | 85 | if iscell(varargin{1})
|
| | 86 | % switchyard to subfunctions or private functions
|
< 0.001 | 2 | 87 | args = varargin{1};
|
< 0.001 | 2 | 88 | if nargout > 0
|
< 0.001 | 2 | 89 | [varargout{1:nargout}] = feval(args{:});
|
| | 90 | else
|
| | 91 | feval(args{:});
|
< 0.001 | 2 | 92 | end
|
< 0.001 | 2 | 93 | return;
|
| | 94 | elseif ischar(varargin{1}) || isstring(varargin{1})
|
| | 95 | if nargout > 0
|
| | 96 | error(message('MATLAB:graph2d:plotedit:InvalidInputForOutArg'))
|
| | 97 | end
|
| | 98 | % plotedit [on | off ]
|
| | 99 | fig = gcf;
|
| | 100 | action = varargin{1};
|
| | 101 | matlab.ui.internal.prepareFigureFor(fig, mfilename('fullpath'));
|
| | 102 | else
|
| | 103 | if nargout > 0
|
| | 104 | error(message('MATLAB:graph2d:plotedit:InvalidInputForOutArg'))
|
| | 105 | end
|
| | 106 | % plotedit(fig)
|
| | 107 | if any(ishghandle(varargin{1}, 'figure'))
|
| | 108 | matlab.ui.internal.prepareFigureFor(varargin{1}, mfilename('fullpath'));
|
| | 109 | matlab.ui.internal.UnsupportedInUifigure(varargin{1}); %throw error for a uifigure
|
| | 110 | fig = varargin{1};
|
| | 111 | else
|
| | 112 | fig = gcf;
|
| | 113 | matlab.ui.internal.prepareFigureFor(fig, mfilename('fullpath'));
|
| | 114 | end
|
| | 115 | action = 'toggle';
|
| | 116 | end
|
| | 117 | case 2
|
| | 118 | if nargout > 0 && ~isValidActionForOutput(varargin{2})
|
| | 119 | error(message('MATLAB:graph2d:plotedit:InvalidInputForOutArg'))
|
| | 120 | end
|
| | 121 | % we can accept multiple figures, but only scalar uipanels or
|
| | 122 | % uitabs since there could be multiple parented to the same figure
|
| | 123 | if any(ishghandle(varargin{1}, 'figure'))
|
| | 124 | matlab.ui.internal.prepareFigureFor(varargin{1}, mfilename('fullpath'));
|
| | 125 | fig = varargin{1};
|
| | 126 | if ~matlab.uitools.internal.uimode.isLiveEditorFigure(fig)
|
| | 127 | matlab.ui.internal.UnsupportedInUifigure(fig); %throw error for a uifigure
|
| | 128 | end
|
| | 129 | elseif strcmp(varargin{2},'getmode') && ...
|
| | 130 | (~isempty(varargin{1}) && ...
|
| | 131 | (ishghandle(varargin{1}, 'uipanel') || ...
|
| | 132 | ishghandle(varargin{1},'uitab')))
|
| | 133 | fig = varargin{1};
|
| | 134 | else
|
| | 135 | fig = gcf;
|
| | 136 | end
|
| | 137 | matlab.ui.internal.prepareFigureFor(fig, mfilename('fullpath'));
|
| | 138 | action = varargin{2};
|
| | 139 | case {3 4}
|
| | 140 | if nargout > 0
|
| | 141 | error(message('MATLAB:graph2d:plotedit:InvalidInputForOutArg'))
|
| | 142 | end
|
| | 143 | if any(ishghandle(varargin{1}, 'figure'))
|
| | 144 | matlab.ui.internal.prepareFigureFor(varargin{1}, mfilename('fullpath'));
|
| | 145 | matlab.ui.internal.UnsupportedInUifigure(varargin{1}); %throw error for a uifigure
|
| | 146 | fig = varargin{1};
|
| | 147 | else
|
| | 148 | fig = gcf;
|
| | 149 | matlab.ui.internal.prepareFigureFor(fig, mfilename('fullpath'));
|
| | 150 | end
|
| | 151 | action = varargin{2};
|
| | 152 | parameter = varargin{3}; % silent: don't switch button
|
| | 153 | switch parameter
|
| | 154 | case 'pointer'
|
| | 155 | pointer = varargin{4};
|
| | 156 | end
|
| | 157 | end
|
| | 158 |
|
| | 159 | % For legacy reasons, exit early if the action is "promoteoverlay" (this is
|
| | 160 | % R13-era code.
|
| | 161 | if strcmpi(action,'promoteoverlay')
|
| | 162 | return;
|
| | 163 | end
|
| | 164 |
|
| | 165 | % If the mode has never been constructed and the action is "off",
|
| | 166 | % short-circuit:
|
| | 167 | if strcmpi(action,'off') && ~hasuimode(fig,'Standard.EditPlot')
|
| | 168 | return;
|
| | 169 | end
|
| | 170 |
|
| | 171 | % If the mode has never been constructed and the action is "isactive",
|
| | 172 | % return false and short-circuit:
|
| | 173 | if strcmpi(action,'isactive') && ~hasuimode(fig,'Standard.EditPlot')
|
| | 174 | varargout{1} = 0;
|
| | 175 | return;
|
| | 176 | end
|
| | 177 | persistent firstTimeStart;
|
| | 178 | oldptr = [];
|
| | 179 | oldPointerShapeCData = [];
|
| | 180 | switch lower(action)
|
| | 181 | case {'on','toggle'}
|
| | 182 | % If we start for the first time, change the pointer to watch,
|
| | 183 | % beacuse it can take some time for the mode to get initialized
|
| | 184 | if isempty(firstTimeStart)
|
| | 185 | oldptr = fig.Pointer;
|
| | 186 | oldPointerShapeCData = fig.PointerShapeCData;
|
| | 187 | % At first time creation temporarily set the wait cursor
|
| | 188 | fig.UIModeEnabled = 'on';
|
| | 189 | fig.Pointer = 'watch';
|
| | 190 | drawnow expose;
|
| | 191 | firstTimeStart = 0;
|
| | 192 | end
|
| | 193 |
|
| | 194 | hMode = localGetMode(fig);
|
| | 195 |
|
| | 196 | if strcmpi(hMode.Enable,'off')
|
| | 197 | % Activate the mode
|
| | 198 | activateuimode(fig,'Standard.EditPlot');
|
| | 199 |
|
| | 200 | % If the pointer is sent as an additional input argument,
|
| | 201 | % augment the mode to take care of this behind the scenes
|
| | 202 | if ~isempty(pointer)
|
| | 203 | hMode.FigureState.Pointer = pointer;
|
| | 204 | end
|
| | 205 | elseif strcmpi(action,'toggle')
|
| | 206 | activateuimode(fig,'');
|
| | 207 | end
|
| | 208 |
|
| | 209 | % If this is a cold start, (firsttime) was initialized above, then
|
| | 210 | % reset the cached plot edit mode cursor information to its initial
|
| | 211 | % value so the cursor does not revert to the temporary wait state when
|
| | 212 | % the user exits the mode.
|
| | 213 | if ~isempty(oldptr)
|
| | 214 | % If the mode was turned on the call activateuimode(fig,'Standard.EditPlot');
|
| | 215 | % will have set the FigureState.Pointer to 'watch'. Restore the
|
| | 216 | % oldptr setting
|
| | 217 | setFigureState(hMode, 'Pointer', oldptr)
|
| | 218 |
|
| | 219 | oldptr =[]; %#ok<NASGU>
|
| | 220 | end
|
| | 221 | if ~isempty(oldPointerShapeCData)
|
| | 222 | setFigureState(hMode, 'PointerShapeCData', oldPointerShapeCData)
|
| | 223 | oldPointerShapeCData = []; %#ok<NASGU>
|
| | 224 | end
|
| | 225 | case 'off'
|
| | 226 | hMode = localGetMode(fig);
|
| | 227 | if strcmpi(hMode.Enable,'off') % already off
|
| | 228 | return;
|
| | 229 | end
|
| | 230 | activateuimode(fig,'');
|
| | 231 | case 'cut'
|
| | 232 | hMode = localGetMode(fig);
|
| | 233 | if hMode.ModeStateData.PlotSelectMode.ModeStateData.CutCopyPossible
|
| | 234 | scribeccp(fig, 'cut');
|
| | 235 | end
|
| | 236 | case 'copy'
|
| | 237 | hMode = localGetMode(fig);
|
| | 238 | if hMode.ModeStateData.PlotSelectMode.ModeStateData.CutCopyPossible
|
| | 239 | scribeccp(fig, 'copy');
|
| | 240 | end
|
| | 241 | case 'paste'
|
| | 242 | hMode = localGetMode(fig);
|
| | 243 | % If a paste is not possible, assume we are pasting into the
|
| | 244 | % figure. This is for ^C^V shortcuts to execute properly.
|
| | 245 | if ~hMode.ModeStateData.PlotSelectMode.ModeStateData.PastePossible
|
| | 246 | selectobject(fig,'replace');
|
| | 247 | end
|
| | 248 | if hMode.ModeStateData.PlotSelectMode.ModeStateData.PastePossible
|
| | 249 | scribeccp(fig, 'paste');
|
| | 250 | end
|
| | 251 | case 'clear'
|
| | 252 | scribeccp(fig, 'clear');
|
| | 253 | case 'delete'
|
| | 254 | hMode = localGetMode(fig);
|
| | 255 | if hMode.ModeStateData.PlotSelectMode.ModeStateData.DeletePossible
|
| | 256 | scribeccp(fig, 'delete');
|
| | 257 | end
|
| | 258 | case 'selectall'
|
| | 259 | hMode = localGetMode(fig);
|
| | 260 | localSelectAll(hMode);
|
| | 261 | case 'hidetoolsmenu'
|
| | 262 | set(findobj(allchild(fig),'flat','Type','uimenu','Tag','figMenuTools'),...
|
| | 263 | 'visible','off');
|
| | 264 | case 'showtoolsmenu'
|
| | 265 | set(findobj(allchild(fig),'flat','Type','uimenu','Tag','figMenuTools'),...
|
| | 266 | 'visible','on');
|
| | 267 | case 'plotedittoolbar'
|
| | 268 | if nargin < 3
|
| | 269 | parameter = 'toggle';
|
| | 270 | end
|
| | 271 | plotedittoolbar(fig,parameter);
|
| | 272 | case 'setenabletools'
|
| | 273 | if nargin==3
|
| | 274 | setappdata(fig,'ScribePloteditEnable',parameter);
|
| | 275 | % disable toolbar
|
| | 276 | toolButtons = plotedit(fig,'gettoolbuttons');
|
| | 277 | set(toolButtons,'Enable',parameter);
|
| | 278 | % disable Tools menu
|
| | 279 | % happens within the Tools menu callback, by polling the
|
| | 280 | % ScribePloteditEnable state
|
| | 281 | end
|
| | 282 | case 'showinspector'
|
| | 283 | % Shows the property inspector
|
| | 284 | matlab.graphics.internal.propertyinspector.propertyinspector('show');
|
| | 285 | case 'hideinspector'
|
| | 286 | % Hides the inspector window
|
| | 287 | matlab.graphics.internal.propertyinspector.propertyinspector('hide');
|
| | 288 | case 'openandrestoreinspector'
|
| | 289 | % Opens the property inspector and restores auto behavior
|
| | 290 | matlab.graphics.internal.propertyinspector.propertyinspector('openandrestoreinspector');
|
| | 291 | case 'getenabletools'
|
| | 292 | ploteditEnable = getappdata(fig,'ScribePloteditEnable');
|
| | 293 | if isempty(ploteditEnable)
|
| | 294 | varargout{1} = 'on'; % default
|
| | 295 | else
|
| | 296 | varargout{1} = ploteditEnable;
|
| | 297 | end
|
| | 298 | case 'setsystemeditmenus'
|
| | 299 | localModifyFigMenus(fig,'off');
|
| | 300 | case 'setploteditmenus'
|
| | 301 | localModifyFigMenus(fig,'on');
|
| | 302 | case 'gettoolbuttons'
|
| | 303 | % Call subfunctions that return the toolbar buttons and insert/plottools
|
| | 304 | % menu items.
|
| | 305 | h = getScribeToolbarButtons(fig);
|
| | 306 | hmenuitems = [getScribeMenuItems(fig);getPlotToolsMenuItems(fig)];
|
| | 307 | if nargout>0
|
| | 308 | varargout{1} = [h;hmenuitems];
|
| | 309 | end
|
| | 310 | case 'locktoolbarvisibility'
|
| | 311 | toolbarShowing = ~isempty(findall(fig,'Tag','FigureToolBar'));
|
| | 312 | % Only set the Toolbar state if it changes to prevent affecting the
|
| | 313 | % ToolBarMode property. The ToolBarMode is used by the Live Editor
|
| | 314 | % when restoring figures to determine of the ToolBar should be
|
| | 315 | % restored.
|
| | 316 | if toolbarShowing && ~strcmp(get(fig,'Toolbar'),'figure')
|
| | 317 | set(fig,'Toolbar','figure');
|
| | 318 | elseif ~toolbarShowing && ~strcmp(get(fig,'Toolbar'),'none')
|
| | 319 | set(fig,'Toolbar','none');
|
| | 320 | end
|
| | 321 | case 'isactive'
|
| | 322 | hMode = localGetMode(fig);
|
| | 323 | switch hMode.Enable
|
| | 324 | case 'on'
|
| | 325 | varargout{1} = 1;
|
| | 326 | case 'off'
|
| | 327 | varargout{1} = 0;
|
| | 328 | end
|
| | 329 | case 'getmode'
|
| | 330 | hMode = localGetMode(fig);
|
| | 331 | varargout{1} = hMode;
|
| | 332 | otherwise
|
| | 333 | error(message('MATLAB:graph2d:plotedit:InvalidPlotEditState'))
|
| | 334 | end
|
Other subfunctions in this file are not included in this listing.