📄 topgui.m
字号:
% ******************* Rri_patch ******************** %
function h=patch3(x,y,dof,handles)
% Draw Constrain triangle
% [x y] - Coordinates of constrained node
% dof - 1=Ux fixed 2=Uy fixed
height=handles.constrain_triangle_height; %底边上的高
len_base=handles.constrain_triangle_width; %底边长
switch dof
case 1 % Ux fixed
x1=x-height;
x2=x-height;
y1=y-0.5*len_base;
y2=y+0.5*len_base;
case 2 % Uy fixed
x1=x-0.5*len_base;
x2=x+0.5*len_base;
y1=y+height;
y2=y+height;
end
h=patch([x x1 x2],[y y1 y2],'r');
set(h,'Facecolor',handles.constrain_triangle_FaceColor); % patch's face is transparent
set(h,'linewidth',handles.constrain_triangle_LineWidth); % line width of patch edge
function handles = apply_forces(nodes_index_array, dof, force, handles);
% node_index_array=[x1 x2 ... xn
% y1 y2 ... yn]
index_selected_nodes = IJ2index(nodes_index_array, handles);
switch dof
case 1 % Fx
dofs_force=2*index_selected_nodes-1;
case 2 % Fy
dofs_force=2*index_selected_nodes;
otherwise
return;
end
% Update F
handles.F(dofs_force)=handles.F(dofs_force) + force;
% Redraw forces
% delete old arrows
delete(handles.F_arrow);
% initialize handle array
handles.F_arrow=[];
index_dofs=find(handles.F~=0); % non-zero element in sparse handles.F
n=length(index_dofs);
num_fx = 0;
num_fy = 0;
for i=1:n
idof=index_dofs(i);
force=handles.F(idof);
if(mod(idof,2)==0) % Fy
num_fy=num_fy+1;
inode=idof/2;
if(force<0)
dof=-2;
else
dof=+2;
end
else % Fx
num_fx=num_fx+1;
inode=(idof+1)/2;
if(force<0)
dof=-1;
else
dof=+1;
end
end
y=mod(inode,handles.nely+1);
x=(inode-y)/(handles.nely+1)+1;
if y==0
y=handles.nely+1;
x=x-1;
end
[h_line,h_arrow] = drawF(x,y,dof,handles);
handles.F_arrow=[handles.F_arrow [h_line h_arrow]'];
end % end loop for all non-zero elements in handles.F
% Update force number
h_num_force_fx=findobj('tag','text_num_force_fx');
h_num_force_fy=findobj('tag','text_num_force_fy');
set(h_num_force_fx,'string',num2str(num_fx));
set(h_num_force_fy,'string',num2str(num_fy));
% Save handles
guidata(gcbo,handles);
% --- DrawF
function [h_line,h_patch]=drawF(x,y,dof,handles)
% Draw Forces 以节点[x y]为起点 作箭头(arrow=line+patch)
% [x y] - Coordinates of Node
% dof : 1=Fx>0 -1=Fx<0 2=Fy>0 -2=Fy<0
%% 用带箭头的直线连接两点 起点(x1,y1)-->终点(x2,y2)
len = handles.force_arrow_line_length; % line 的长度
width_arrow = handles.force_arrow_patch_width; %箭头底边宽度
height_arrow = handles.force_arrow_patch_height; %箭头长度
x1=x;
y1=y;
switch dof
case -1 % Fx<0
x2=x1-len;
y2=y1;
p1_x=x2-height_arrow;
p1_y=y2;
p2_x=x2;
p3_x=x2;
p2_y=y2-0.5*width_arrow;
p3_y=y2+0.5*width_arrow;
case +1 % Fx>0
x2=x1+len;
y2=y1;
p1_x=x2+height_arrow;
p1_y=y2;
p2_x=x2;
p3_x=x2;
p2_y=y2-0.5*width_arrow;
p3_y=y2+0.5*width_arrow;
case -2 % Fy<0
x2=x1;
y2=y1-len;
p1_x=x2;
p1_y=y2-height_arrow;
p2_y=y2;
p3_y=y2;
p2_x=x2-0.5*width_arrow;
p3_x=x2+0.5*width_arrow;
case 2 % Fy
x2=x1;
y2=y1+len;
p1_x=x2;
p1_y=y2+height_arrow;
p2_y=y2;
p3_y=y2;
p2_x=x2-0.5*width_arrow;
p3_x=x2+0.5*width_arrow;
end
h_line=line([x1 x2],[y1 y2]);
set(h_line,'color',handles.force_arrow_line_color);
set(h_line,'LineWidth',handles.force_arrow_line_width);
h_patch=patch([p1_x p2_x p3_x],[p1_y p2_y p3_y],handles.force_arrow_patch_facecolor);
set(h_patch,'EdgeColor',handles.force_arrow_patch_edgecolor);% --- Executes on mouse motion over figure - except title and menu.function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)% hObject handle to figure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
handles = guidata(gcbo);
h_figure=hObject;
h_axes=gca;
units_figure = get(h_figure,'units');
units_axes = get(h_axes,'units');
if_units_consistent = 1;
if ~strcmp(units_figure,units_axes)
if_units_consistent=0;
set(h_axes,'units',units_figure); % To be sure that units of figure and axes are consistent
end
% Check if cusor on axes
pos_axes=get(gca,'position'); % [left bottom width height]
pos_cursor=get(hObject,'currentpoint'); % [left bottom]
% If on homepage, change cursor to hand
% h_homepage=findobj('tag','text_homepage');
% pos_homepage=get(h_homepage,'position');
% if_cursor_on_homepage = ( pos_cursor(1) > pos_homepage(1) & pos_cursor(1) < pos_homepage(1) + pos_homepage(3) & ...
% pos_cursor(2) > pos_homepage(2) & pos_cursor(2) < pos_homepage(2) + pos_homepage(4) );
% pos_cursor
% [pos_cursor(1)>pos_homepage(1) pos_cursor(1)<pos_homepage(1)+pos_homepage(3) pos_cursor(2)>pos_homepage(2) pos_cursor(2)<pos_homepage(2)+pos_homepage(4)]
% if if_cursor_on_homepage
% setptr(h_figure,'glass');
% end
% If not on axes,return
if ( pos_cursor(1) < pos_axes(1) | pos_cursor(1) > pos_axes(1) + pos_axes(3) | ...
pos_cursor(2) < pos_axes(2) | pos_cursor(2) > pos_axes(2) + pos_axes(4) )
return;
end
% Recover units of axes,if original units of figure and axes are not consistent.
if ~if_units_consistent
set(h_axes,'units',units_axes);
end
% Below : Cursor on axes
[x,y]=gpos(gca);
i_node=round(x);
i_node=max(1,i_node);
i_node=min(handles.nelx+1,i_node);
j_node=round(y);
j_node=max(1,j_node);
j_node=min(handles.nely+1,j_node);
i_elem=floor(x);
i_elem=max(1,i_elem);
i_elem=min(handles.nelx,i_elem);
j_elem=floor(y);
j_elem=max(1,j_elem);
j_elem=min(handles.nely,j_elem);
% Update current position
% Current node
h_node_x=findobj('tag','text_node_x');
h_node_y=findobj('tag','text_node_y');
set(h_node_x,'string',num2str(i_node));
set(h_node_y,'string',num2str(j_node));
% Current element
h_elem_i=findobj('tag','text_elem_i');
h_elem_j=findobj('tag','text_elem_j');
set(h_elem_i,'string',num2str(i_elem));
set(h_elem_j,'string',num2str(j_elem));
% If in picking mode
if handles.if_picking
x1=handles.pt1(1);
y1=handles.pt1(2);
x3=x;
y3=y;
handles.pt3(1)=x3;
handles.pt3(2)=y3;
xdata=[x1 x1 x3 x3 x1];
ydata=[y1 y3 y3 y1 y1];
if handles.h_rect>0
set(handles.h_rect,'XData',xdata,'YData',ydata,'Visible','on');
end
end
guidata(gcbo,handles);
function [x,y]=gpos(h_axes)
%GPOS Get current position of cusor and return its coordinates in axes with handle h_axes
% h_axes - handle of specified axes
% [x,y] - cursor coordinates in axes h_aexs
h_figure=gcf;
units_figure = get(h_figure,'units');
units_axes = get(h_axes,'units');
if_units_consistent = 1;
if ~strcmp(units_figure,units_axes)
if_units_consistent=0;
set(h_axes,'units',units_figure); % To be sure that units of figure and axes are consistent
end
% Position of origin in figure [left bottom]
pos_axes_unitfig = get(h_axes,'position');
width_axes_unitfig = pos_axes_unitfig(3);
height_axes_unitfig = pos_axes_unitfig(4);
xDir_axes=get(h_axes,'XDir');
yDir_axes=get(h_axes,'YDir');
% Cursor position in figure
pos_cursor_unitfig = get( h_figure, 'currentpoint'); % [left bottom]
if strcmp(xDir_axes,'normal')
left_origin_unitfig = pos_axes_unitfig(1);
x_cursor2origin_unitfig = pos_cursor_unitfig(1) - left_origin_unitfig;
else
left_origin = pos_axes_unitfig(1) + width_axes_unitfig;
x_cursor2origin_unitfig = -( pos_cursor_unitfig(1) - left_origin_unitfig );
end
if strcmp(yDir_axes,'normal')
bottom_origin_unitfig = pos_axes_unitfig(2);
y_cursor2origin_unitfig = pos_cursor_unitfig(2) - bottom_origin_unitfig;
else
bottom_origin_unitfig = pos_axes_unitfig(2) + height_axes_unitfig;
y_cursor2origin_unitfig = -( pos_cursor_unitfig(2) - bottom_origin_unitfig );
end
xlim_axes=get(h_axes,'XLim');
width_axes_unitaxes=xlim_axes(2)-xlim_axes(1);
ylim_axes=get(h_axes,'YLim');
height_axes_unitaxes=ylim_axes(2)-ylim_axes(1);
x = xlim_axes(1) + x_cursor2origin_unitfig / width_axes_unitfig * width_axes_unitaxes;
y = ylim_axes(1) + y_cursor2origin_unitfig / height_axes_unitfig * height_axes_unitaxes;
% Recover units of axes,if original units of figure and axes are not consistent.
if ~if_units_consistent
set(h_axes,'units',units_axes);
end% --- Executes on mouse press over figure background, over a disabled or% --- inactive control, or over an axes background.function figure1_WindowButtonUpFcn(hObject, eventdata, handles)% hObject handle to figure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
handles = guidata(gcbo);
if handles.if_picking handles.if_picking=0;
if handles.h_rect>0
delete(handles.h_rect);
end
handles.h_rect=0;
set(gcf,'Pointer','arrow');
set(gcf,'userdata','ButtonUp');
guidata(gcbo,handles);
end% % --- Executes on mouse press over axes background.% function axes1_ButtonDownFcn(hObject, eventdata, handles)% % hObject handle to axes1 (see GCBO)% % eventdata reserved - to be defined in a future version of MATLAB% % handles structure with handles and user data (see GUIDATA)
%
% if handles.if_picking% [x,y]=gpos(gca);
% handles.pt1=[x,y];
% set(gcf,'userdata','ButtonDown');
% guidata(gcbo,handles);
% end
% --- check if any nodes are selected when apply/cancel constrains or forces
function if_nodes = if_nodes_selected( handles )
if_nodes = 1;
if ( length( handles.selected_nodes ) == 0 )
if_nodes = 0;
h = msgbox('No nodes selected!','Error!','error','modal');
waitfor(h); % Wait until dialog is deleted
end% --- Executes on mouse press over figure background, over a disabled or% --- inactive control, or over an axes background.function figure1_WindowButtonDownFcn(hObject, eventdata, handles)% hObject handle to figure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
if handles.if_picking str_sel_type = get(gcf,'SelectionType');
if strcmp(str_sel_type , 'normal')
[x,y]=gpos(gca);
handles.pt1=[x,y];
set(gcf,'userdata','ButtonDown');;
elseif strcmp(str_sel_type , 'alt') % Right click and quit the piking mode
handles.if_picking = 0;
set( gcf, 'Pointer', 'arrow');
end
end
guidata(gcbo,handles);% --- Executes on button press in pushbutton_homepage.function pushbutton_homepage_Callback(hObject, eventdata, handles)% hObject handle to pushbutton_homepage (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)web http://www.geocities.com/chinakkong/research/topgui/ -browser
% --- Creates and returns a handle to the GUI figure.
function h1 = topgui_LayoutFcn(policy)
% policy - create a new figure or use a singleton. 'new' or 'reuse'.
persistent hsingleton;
if strcmpi(policy, 'reuse') & ishandle(hsingleton)
h1 = hsingleton;
return;
end
h1 = figure(...
'Units','normalized',...
'PaperUnits','normalized',...
'Color',[0 0.501960784313725 0.752941176470588],...
'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
'IntegerHandle','off',...
'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
'MenuBar','none',...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -