📄 editlines.m
字号:
function editlines(action)
% EDITLINES: a general digital editing tool for line data.
% mouse action definitions:
%
% When in normal edit mode ('modify' mode) the mouse buttons act as follows:
% button 1 click - select line for editing or add a point.
% If the click occurs on a line which is not currently
% being edited, then it becomes the current editable
% line. If the click line is being edited, then a new
% point is added at the clicked location. If the click
% is not on any editable line, then all lines are
% unselected for editing.
% button 1 drag - move a single point.
% The point on the current line nearest the clicked
% point is dragged as the cursor is dragged. Anchor
% points cannot be moved.
% button 2 click - kill a single point.
% The point on the current line nearest the clicked
% point is deleted. Anchor points cannot be deleted.
% button 2 drag - drag-kill many points
% Points are killed as the cursor is dragged near them
% button 3 click - set or free an anchor point.
% Anchor points may not be moved or killed. They are
% denoted as points with a double circle around them.
% If the point clicked is a normal point, it becomes an
% anchor. If it is already an anchor, it is freed.
% button 3 drag - move many points
% All points between the clicked point and anchors on
% either side are dragged together. If in elastic drag
% mode, the magnitude of the displacement tapers to zero
% at the anchors and is a maximum only at the clicked
% point. If the line has no anchors, then the entire
% line is dragged. If in constant drag mode, then all
% points between two anchors are dragged with the same
% displacement. When no anchors are present, the two
% drag modes are identical.
%
% When in link mode, the button actions are:
% MB1 click ... select a line for link editing.
% MB1 drag ... move a point. If it is released over another line, then
% a link is formed. A link is defined as an anchored point
% which exists on both lines
% MB2 click ... break a line into segments
% MB3 click or drag same as modify mode
%
% EDITLINES is intended to be incorporated within larger tools with specific
% editing tasks. Someone using it within such a larger tool need read no
% further. For further information on how to build EDITLINES into a tool
% of your own, type: help editlinesinit
%
% by G.F. Margrave December 1993
%
% NOTE: It is illegal for you to use this software for a purpose other
% than non-profit education or research UNLESS you are employed by a CREWES
% Project sponsor. By using this software, you are agreeing to the terms
% detailed in this software's Matlab source file.
% BEGIN TERMS OF USE LICENSE
%
% This SOFTWARE is maintained by the CREWES Project at the Department
% of Geology and Geophysics of the University of Calgary, Calgary,
% Alberta, Canada. The copyright and ownership is jointly held by
% its author (identified above) and the CREWES Project. The CREWES
% project may be contacted via email at: crewesinfo@crewes.org
%
% The term 'SOFTWARE' refers to the Matlab source code, translations to
% any other computer language, or object code
%
% Terms of use of this SOFTWARE
%
% 1) Use of this SOFTWARE by any for-profit commercial organization is
% expressly forbidden unless said organization is a CREWES Project
% Sponsor.
%
% 2) A CREWES Project sponsor may use this SOFTWARE under the terms of the
% CREWES Project Sponsorship agreement.
%
% 3) A student or employee of a non-profit educational institution may
% use this SOFTWARE subject to the following terms and conditions:
% - this SOFTWARE is for teaching or research purposes only.
% - this SOFTWARE may be distributed to other students or researchers
% provided that these license terms are included.
% - reselling the SOFTWARE, or including it or any portion of it, in any
% software that will be resold is expressly forbidden.
% - transfering the SOFTWARE in any form to a commercial firm or any
% other for-profit organization is expressly forbidden.
%
% END TERMS OF USE LICENSE
% mouse button assignments
% button1 up ... current line becomes selected. If it is already selected, then a
% point is added to the line at the clicked location.
% button1 motion ... point on current line closest to the pointer location is
% dragged
% button2 up ... point closest to the pointer is deleted.
% button2 motion ... points near the pointer are deleted
% button3 up ... Point closest to the pointer location becomes an anchor point
% unless it already is, in which case it is freed.
% button3 motion ... point closest to the pointer is dragged. Other points on the
% line are dragged with the magnitude of the displacement vector tapering to
% zero at the closest anchor points. If no anchor points, then the entire line
% is dragged.
%
% the anchors vector [hcurve1 n1 x1(1) y1(1) ... x1(n) y1(n) hcurve2 n2 x2(1)
% y2(1) ... x2(n2) y2(n2) .... ]
% Is passed via the current axis userdata. At the end of editing, it may be
% retrieved from there for future reference.
%
% EDITLINES actions:
% strcmp(action,'init') ... initialize
% strcmp(action,'fini') ... terminate editing
%strcmp(action,'tempfini') ... temporarily terminate when the user has clicked
% outside of all lines
% strcmp(action,'buttondown') ... a general button down handler
% strcmp(action,'button1up') ... button 1 up to create a single point
% strcmp(action,'button2up') ... delete a single point
% strcmp(action,'button3up') ... toggle anchor status
% strcmp(action,'button1motion') ... drag a single point
% strcmp(action,'button2motion') ... drag kill
% strcmp(action,'button3motion') ... group moves
% strcmp(action,'stopmotion') ... turn off the motion function
% strcmp(action,'xonly') ... toggle x only
% strcmp(action,'yonly') ... toggle y only
% strcmp(action,'xandy') ... full free motion
% strcmp(action,'locate') ... toggle locate
% strcmp(action,'dragmode') ... toggle dragmode
% strcmp(action,'elasticdrag') ... set dragmode to elastic
% strcmp(action,'constantdrag') ... set dragmode to constant
% strcmp(action,'undo') ... undo the last whatever
% strcmp(action,'smoothon') ... turn on smooth mode
% strcmp(action,'smoothoff') ... turn off smoothmode
% strcmp(action,'linkmode') ... toggle linkmode
% strcmp(action,'polymode') ... toggle polymode
% (note linkmode-> pdata(3)==1 & polymode-> pdata(3)==-1)
% strcmp(action,'link') ... link 2 curves
% strcmp(action,'linkpoly') ... make or break a polygon
% strcmp(action,'autoseg') ... autmatically segment a curve
% strcmp(action,'linkon') ... turn link mode on
% strcmp(action,'linkoff') ... link mode off
% strcmp(action,'smoothon') ... smooth mode on
% strcmp(action,'smoothoff') ... smooth mode off
% strcmp(action,'smooth') ... smooth the current line between anchors
% strcmp(action,'smooth3') ... smooth the entire current line
% strcmp(action,'multnanon') ... all the presence of multiple nans in a row
% strcmp(action,'multnanoff') ... do not allow multiple nans. Any time 2
% consecutive nans occur, toss one. Also get rid of any leading and
% trailing nans.
% ***NOTE*** default behavior is to allow multiple nans
% strcmp(action,'deleteon') ... allow deletion of points
% strcmp(action,'deleteoff') ... do not allow deletion of points
% ***** default is allow ****
% strcmp(action,'addon') ... allow addition of new of points
% strcmp(action,'addoff') ... do not allow addition of new of points
% ***** default is allow ****
% strcmp(action,'clearanch') ... clear anchors on active line. Undo will unclear.
% Has no effect if nothing is active.
% strcmp(action,'clearallanch') ... clear all anchors. Works even if nothing is
% active. No true undo. If one line is active, then undo will restore
% anchors for that line ONLY.
%
valid_anchors=[]; line_anchors=[]; kclose=[];
if( strcmp(action,'init') )
el_init
return;
end
if(strcmp(action,'fini') )
el_fini
return % $$$$ possibly extra
end
if(strcmp(action,'tempfini'))
el_tempfini
return;
end
if( strcmp(action,'buttondown') )
el_buttondown
return;
end
if( strcmp(action,'button1up') | strcmp(action,'button2up') ...
| strcmp(action,'button3up') )
el_buttonup(action)
return;
end
if( strcmp(action,'button1motion') | strcmp(action,'button2motion') |...
strcmp(action,'button3motion') )
el_buttonmotion(action)
return;
end
if(strcmp(action,'stopmotion') )
el_stopmotion
return;
end
if(strcmp(action,'xonly')) %toggle xonly
% Get the storage bucket
h=get(gcf,'children');
for k=1:length(h)
if( strcmp(get(h(k),'type'),'uicontrol') )
if( strcmp(get(h(k),'style'),'text') )
if( strcmp(get(h(k),'string'),'yrag_params') )
hparams=h(k);
break;
end
end
end
end
% get the parameters
pdata=get(hparams,'userdata');
xonly=pdata(1);
if( xonly )
pdata(1)=0;
else
pdata(1)=1;
end
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'yonly')) %toggle yonly
% Get the storage bucket
h=get(gcf,'children');
for k=1:length(h)
if( strcmp(get(h(k),'type'),'uicontrol') )
if( strcmp(get(h(k),'style'),'text') )
if( strcmp(get(h(k),'string'),'yrag_params') )
hparams=h(k);
break;
end
end
end
end
% get the parameters
pdata=get(hparams,'userdata');
yonly=pdata(2);
if( yonly )
pdata(2)=0;
else
pdata(2)=1;
end
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'xandy')) %toggle yonly
% Get the storage bucket
h=get(gcf,'children');
for k=1:length(h)
if( strcmp(get(h(k),'type'),'uicontrol') )
if( strcmp(get(h(k),'style'),'text') )
if( strcmp(get(h(k),'string'),'yrag_params') )
hparams=h(k);
break;
end
end
end
end
% get the parameters
pdata=get(hparams,'userdata');
xonly=pdata(1);
yonly=pdata(2);
pdata(1)=0;
pdata(2)=0;
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'locate')|strcmp(action,'locateon')|strcmp(action,'locateoff'))
%toggle locate
% Get the storage bucket
h=get(gcf,'children');
for k=1:length(h)
if( strcmp(get(h(k),'type'),'uicontrol') )
if( strcmp(get(h(k),'style'),'text') )
if( strcmp(get(h(k),'string'),'yrag_params') )
hparams=h(k);
break;
end
end
end
end
% get the parameters
pdata=get(hparams,'userdata');
if(strcmp(action,'locate'))
locate=pdata(4);
if( locate )
pdata(4)=0;
else
pdata(4)=1;
end
elseif(strcmp(action,'locateon'))
pdata(4)=1;
else
pdata(4)=0;
end
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'dragmode')|strcmp(action,'elasticdrag')|...
strcmp(action,'constantdrag')) %toggle dragmode
% Get the storage bucket
h=get(gcf,'children');
for k=1:length(h)
if( strcmp(get(h(k),'type'),'uicontrol') )
if( strcmp(get(h(k),'style'),'text') )
if( strcmp(get(h(k),'string'),'yrag_params') )
hparams=h(k);
break;
end
end
end
end
% get the parameters
pdata=get(hparams,'userdata');
dragmode=pdata(5);
if(strcmp(action,'dragmode'))
if( dragmode )
pdata(5)=0;
else
pdata(5)=1;
end
elseif(strcmp(action,'elasticdrag'))
pdata(5)=0;
elseif(strcmp(action,'constantdrag'))
pdata(5)=1;
end
set(hparams,'userdata',pdata);
return;
end
if( strcmp(action,'undo') )
el_undo
return;
end
if(strcmp(action,'smoothon')|strcmp(action,'smoothoff')|...
strcmp(action,'linkon')|strcmp(action,'linkoff') ) %toggle smoothmode
% Get the storage bucket
h=get(gcf,'children');
for k=1:length(h)
if( strcmp(get(h(k),'type'),'uicontrol') )
if( strcmp(get(h(k),'style'),'text') )
if( strcmp(get(h(k),'string'),'yrag_params') )
hparams=h(k);
break;
end
end
end
end
% get the parameters
pdata=get(hparams,'userdata');
if( strcmp(action,'smoothon') )
%see if linkmode is on and turn it off
if(pdata(3))
editlines('linkoff');
end
pdata(6)=1;
set(gcf,'pointer','circle');
elseif( strcmp(action,'smoothoff') )
pdata(6)=0;
set(gcf,'pointer','arrow');
elseif( strcmp(action,'linkon') )
%see if smoothmode is on and turn it off
if(pdata(6))
editlines('smoothoff');
end
pdata(3)=1;
set(gcf,'pointer','crosshair');
elseif( strcmp(action,'linkoff') )
pdata(3)=0;
set(gcf,'pointer','arrow');
end
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'faston')|strcmp(action,'fastoff') )%toggle fastopt
% Get the storage bucket
h=get(gcf,'children');
for k=1:length(h)
if( strcmp(get(h(k),'type'),'uicontrol') )
if( strcmp(get(h(k),'style'),'text') )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -