function createPolygon
fig = figure('Name','高精度地质建模工具', 'NumberTitle','off',...
'Position',[200 200 1200 700], 'MenuBar','none',...
'CloseRequestFcn',@closeApp);
% 绘图区域
ax = axes('Parent', fig, ...
'Position',[0.1, 0.1, 0.6, 0.8],...
'Box','on', 'XGrid','on', 'YGrid','on',...
'YDir','reverse' ... % 添加纵轴倒转
);
hPoly = drawpolygon(ax, 'Color', rand(1,3), 'LineWidth',1.5,...
'InteractionsAllowed','all',...
'Tag','Polygon');
function closeApp(~,~)
selection = questdlg('确认退出?', '关闭程序',...
'保存并退出', '直接退出', '取消', '保存并退出');
switch selection
case '保存并退出'
exportData();
delete(fig);
case '直接退出'
delete(fig);
otherwise
return
end
end
end
这是我的基础代码。
这三张图片显示了,绘制多边形后,分别是多边形的面、线和顶点处右键的菜单。我现在发现在面和线的右键菜单可以重新自定义,然而在顶点处的菜单无法找到自定义位置。
修改菜单的代码如下
function createPolygon
fig = figure('Name','高精度地质建模工具', 'NumberTitle','off',...
'Position',[200 200 1200 700], 'MenuBar','none',...
'CloseRequestFcn',@closeApp);
% 绘图区域
ax = axes('Parent', fig, ...
'Position',[0.1, 0.1, 0.6, 0.8],...
'Box','on', 'XGrid','on', 'YGrid','on',...
'YDir','reverse' ... % 添加纵轴倒转
);
hPoly = drawpolygon(ax, 'Color', rand(1,3), 'LineWidth',1.5,...
'InteractionsAllowed','all',...
'Tag','Polygon');
menuItems = uicontextmenu(fig);
uimenu(menuItems, 'Text', '重命名', ...
'MenuSelectedFcn',@(src,evt)renamePolygon(hPoly),...
'Separator','on');
uimenu(menuItems, 'Text', '多边形属性', ...
'MenuSelectedFcn',@(~,~)editPolygonProperties(hPoly), ...
'Separator','on');
uimenu(menuItems, 'Text','删除多边形', ...
'MenuSelectedFcn',@(src,evt)deletePolygon(hPoly), ...
'Separator','on');
uimenu(menuItems, 'Text','编辑顶点', ...
'MenuSelectedFcn',@(src,evt)deletePolygon(hPoly), ...
'Separator','on');
uimenu(menuItems, 'Text','删除顶点', ...
'MenuSelectedFcn',@(src,evt)deletePolygon(hPoly), ...
'Separator','on');
hPoly.ContextMenu = menuItems;
function closeApp(~,~)
selection = questdlg('确认退出?', '关闭程序',...
'保存并退出', '直接退出', '取消', '保存并退出');
switch selection
case '保存并退出'
exportData();
delete(fig);
case '直接退出'
delete(fig);
otherwise
return
end
end
end
结果如下:
在顶点的菜单没有被覆盖。
我现在希望找到方法可以覆盖原始的顶点菜单,进行自定义。