Context menu rotate3d works once !
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm working with MatlabR2012b and uicontrols.
I'm trying to activate a contextual menu into an axe to
- swap between rotate3d / zoom / save picture
- Axe is into a figure (that will contain uicontrols).
- For FUNCTION (here: ctx_save) and ZOOM : everything is correct
- For ROTATE3D : it works only ONCE !!!
(code is below)
Scenario : run my function context_menu_rotate_zoom
(other function ctx_save, ctx_rotate, ctx_zoom will be in seperate files)
- right button into the fig : context menu appears (Rotation/zoom/save)
- right button into the axe : context menu appears (Rotation/zoom/save)
- right button on the surface : nothing but it's ok as hittest is on
== 1/ right button and select context menu zoom : (pop up window+zoom on) : it's OK
You can zoom using left button
You can click on right button context menu to zoom and save several times.. it's OK
right button into the figure : Nothing !
QUESTION 1 >> Does "ZOOM ON" desactivate context menu for parent ?
== 2.1/ right button and select in context menu ROTATION: (pop up window+rotate on) : it's OK you can rotate the picture
== 2.2/ right button and select a second time on context menu ROTATION: (pop up window+rotate on) : it's OK
== 2.3/ right button... The rotate3d context menu appears with :reset to original view/Goto X-Z...
QUESTION 2 >> How can I overwrite Context menu for ROTATE3D the same way it works for ZOOM ?
Thank you for your help ! Alain
==============================================================
% -------------------------------
function context_menu_rotate_zoom
% -------------------------------
% Creation of axe into figure
myfig=figure('MenuBar','None');
myaxe = axes;
% Plot something
axes(myaxe);
axis vis3d;
[X,Y] = meshgrid(-5:0.1:5,-5:0.1:5);
pp=plot3(X,Y,X.*X+Y.*Y);
% creation of callback
var_Rotation = strcat('ctx_Rotation(',num2str(myaxe,'%.16f'),');');
var_Zoom = strcat('ctx_Zoom(',num2str(myaxe,'%.16f'),');');
var_Save = strcat('ctx_Save(',num2str(myaxe,'%.16f'),');');
%
% Creation of context menu for the fig
cmenu_fig = uicontextmenu;
uimenu(cmenu_fig,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_fig,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_fig,'label','Save','Callback',var_Save);
set(myfig,'uicontextmenu',cmenu_fig);
% Creation of context menu for the axe...
cmenu_axe = uicontextmenu;
uimenu(cmenu_axe,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_axe,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_axe,'label','Save','Callback',var_Save);
set(myaxe,'uicontextmenu',cmenu_axe);
end
% ----------------------------
function ctx_Zoom(monaxe)
% ----------------------------
% creation of callback
var_Rotation = strcat('ctx_Rotation(',num2str(monaxe,'%.16f'),');');
var_Zoom = strcat('ctx_Zoom(',num2str(monaxe,'%.16f'),');');
var_Save = strcat('ctx_Save(',num2str(monaxe,'%.16f'),');');
% Creation contextuel menu for zoom
cmenu_zoom = uicontextmenu;
uimenu(cmenu_zoom,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_zoom,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_zoom,'label','Save','Callback',var_Save);
%set(monaxe,'uicontextmenu',cmenu);
% overwrite context menu for zoom
hZoom = zoom;
zoom('off') % cannot change context if zoom on !
set(hZoom,'UIContextMenu',cmenu_zoom);
zoom('on')
msgbox('Context menu in Zoom');
end
% ----------------------------
function ctx_Rotation(monaxe)
% ----------------------------
% creation of callback
var_Rotation = strcat('ctx_Rotation(',num2str(monaxe,'%.16f'),');');
var_Zoom = strcat('ctx_Zoom(',num2str(monaxe,'%.16f'),');');
var_Save = strcat('ctx_Save(',num2str(monaxe,'%.16f'),');');
% Creation of contextuel menu
cmenu_rot = uicontextmenu;
uimenu(cmenu_rot,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_rot,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_rot,'label','Save','Callback',var_Save);
% overwrite context menu for rotate3d
hrotate = rotate3d;
rotate3d('off')
set(hrotate,'UIContextMenu',cmenu_rot);
rotate3d('on')
msgbox('Context menu in Rotation');
end
% ----------------------------
function ctx_Save(monaxe)
% ----------------------------
% creation of callback
var_Rotation = strcat('ctx_Rotation(',num2str(monaxe,'%.16f'),');');
var_Zoom = strcat('ctx_Zoom(',num2str(monaxe,'%.16f'),');');
var_Save = strcat('ctx_Save(',num2str(monaxe,'%.16f'),');');
% Creation contextuel menu for axe
cmenu_axe = uicontextmenu;
uimenu(cmenu_axe,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_axe,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_axe,'label','Save','Callback',var_Save);
set(monaxe,'uicontextmenu',cmenu_axe);
msgbox('Context menu in save the image');
end
end
1 个评论
derboo
2016-7-14
Hey Alain,
I know it's been a long time since you ask this question, but I'm facing the same problem now.
When I create an UIContextMenu with one menu entry for rotation, I can overwrite the standard rotation UIContextMenu. Everything looks fine, when I click on this menu - rotation mode is activated. When I right click again, I also find my UIContextMenu and can deactivate rotation again. But when I rotate an axes and I try to open my context menu again, my context menu has been reseted with the standard rotate3d context menu with :reset to original view/Goto X-Z
You also described this behaviour in your question.
Have you or anyone else found a solution for this? (I'm using Matlab 2013b)
Thanks for your help, Jan
回答(1 个)
Will Jackson
2016-7-21
Hello,
This is a bug in MATLAB that was fixed in R2014a. As you say, after rotating, rotate would reset some user set values before the next rotation.
Will
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!