📄 editlines.m
字号:
function editlines(action)% EDITLINES is 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') ) anchors=get(gca,'userdata'); if(isempty(anchors)) % search the figure for the handles of all lines h=get(gca,'children'); for k=1:length(h) if( strcmp(get(h(k),'type'),'line') ) anchors = [anchors h(k) 0]; end end end set(gca,'userdata',[]); % make an invisible storage bucket hstore=uicontrol('style','text','visible','off','string','yrag'); hparams=uicontrol('style','text','visible','off','string','yrag_params'); hundo=uicontrol('style','text','visible','off','string','yrag_undo'); hhor=uicontrol('style','text','visible','off','string','yrag_hors'); % parameters % pdat(1) == xonly ... if 1 then y is not changed % pdat(2) == yonly ... if 1 then x is not changed % pdat(3) == linkmode ... if 1 thenwe are in link mode % pdat(4) == locate ... if 1 then we write the cursor location out % pdat(5) == dragmode ... if 0 then group drag is elastic, else it is constant % pdat(6) == smoothmode ... if 1 then we are in smooth mode % pdat(7) == fastopt ... if 1, then dragging a single point is done with a % less annoying display which, though less accurate, is much faster % graphically % pdat(8) == multiple nans ... if 0 then we allow multiple nans, otherwise, % we cull them % pdat(9) == nodelete ... if 0 then points can be delete if 1 they cannot % defaults to 0 % pdat(10) == noadd ... if 0 then points can be added, if 1 they cannot % defaults to 0 pdat=zeros(1,10); set(hparams,'userdata',pdat); % search for a negative anchor which indicates we should go ahead an select that % line for editing. Also in this loop, we create a vector of the handles alone % to facilitate quickly searching all lines in link mode % We also check to see that any handles found are children of the current % axes. If not, they are deleted. h=anchors(1); nh=1; hstart=0; hors=[]; hkids=get(gca,'children'); while( h ~= 0 ) test=find(abs(h)==hkids); if(isempty(test)) %its bogus, toss it npts=anchors(nh+1); anchors(nh:nh+1+2*npts)=[]; if(nh>length(anchors) ) h=0; else h=anchors(nh); end else hors=[hors abs(h)]; if( h<0 ) if(hstart==0); % only the first negative handle is honored hstart=abs(h); end anchors(nh)=abs(h); end npts=anchors(nh+1); nh=nh+2*npts+2; if( nh >length(anchors) )h=0; else h=anchors(nh); end end end % make another storage bucket for the anchors hanchors=uicontrol('style','text','visible','off','string','yrag_anchors',... 'userdata',anchors); % put the horizon vector in its bucket set(hhor,'userdata',hors); %make sure pointer is an arrow set(gcf,'pointer','arrow'); % start editing if requested if(hstart) set(gcf,'currentobject',hstart); editlines('buttondown'); end return;endif(strcmp(action,'fini') ) % clean up graphics if needed % Get the storage buckets h=get(gcf,'children'); found=0; 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') ) hstor=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_anchors') ) hanchors=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_undo') ) hundo=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_hors') ) hhors=h(k); found=found+1; end if( found== 5) break; end end end end % delete any locate information that may be on stuff=get(gca,'userdata'); if( length(stuff)>6 ) htext=stuff(2,6); else htext=0; end if(htext) delete(htext); htext=0; stuff(2,6)=0; set(gca,'userdata',stuff); end dat=get(hstor,'userdata'); % get the anchor info anchors=get(hanchors,'userdata'); % reset and exit if( length(dat)>0 ) delete(dat(7)); if(dat(8)>0) delete(dat(8)); end if(dat(2)==1) ls='-'; elseif(dat(2)==2) ls='--'; elseif(dat(2)==3) ls=':'; elseif(dat(2)==4) ls='-.'; elseif(dat(2)==5) ls='o'; elseif(dat(2)==6) ls='+'; elseif(dat(2)==7) ls='.'; elseif(dat(2)==8) ls='*'; elseif(dat(2)==9) ls='x'; end if (dat(2) < 5) set(dat(1),'linestyle',ls,'linewidth',dat(3),... 'color',dat(4:6),'erasemode','normal'); elseif (dat(2) >= 5) set(dat(1),'marker',ls,'linewidth',dat(3),... 'color',dat(4:6),'erasemode','normal'); end set(hstor,'userdata',[]); % save the anchor information ind=find( anchors==dat(1) ); line_anchors=dat(9:length(dat)); nanchors=length(line_anchors)/2; front=anchors(1:ind); back=anchors(ind+2+2*anchors(ind+1):length(anchors)); anchors=[front nanchors line_anchors back]; if( anchors==0 )anchors=[]; end end % put the anchor info in gca set(gca,'userdata',anchors); delete(hstor); delete(hanchors); delete(hparams); delete(hundo); delete(hhors); % make sure pointer is an arrow set(gcf,'pointer','arrow');endif(strcmp(action,'tempfini'))% this causes a temporary termination of editing. To fully terminate, % editlines('fini') must be called % reset and exit % Get the storage buckets h=get(gcf,'children'); found=0; 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') ) hstor=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_anchors') ) hanchors=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_undo') ) hundo=h(k); found=found+1; end if( found== 4) break; end end end end % delete any locate information that may be on stuff=get(gca,'userdata'); if( length(stuff)>6 ) htext=stuff(2,6); else htext=0; end if(htext) delete(htext); htext=0; stuff(2,6)=0; set(gca,'userdata',stuff); end dat=get(hstor,'userdata'); % get the anchor info anchors=get(hanchors,'userdata'); if( length(dat)>0 ) delete(dat(7)); if(dat(8)) delete(dat(8)); end if(dat(2)==1) ls='-'; elseif(dat(2)==2) ls='--'; elseif(dat(2)==3) ls=':'; elseif(dat(2)==4) ls='-.'; elseif(dat(2)==5) ls='o'; elseif(dat(2)==6) ls='+'; elseif(dat(2)==7) ls='.'; elseif(dat(2)==8) ls='*'; elseif(dat(2)==9) ls='x'; end if (dat(2) < 5) set(dat(1),'linestyle',ls,'linewidth',dat(3),... 'color',dat(4:6),'erasemode','normal'); elseif (dat(2) >= 5) set(dat(1),'marker',ls,'linewidth',dat(3),... 'color',dat(4:6),'erasemode','normal'); end % save the anchor information ind=find( anchors==dat(1) ); line_anchors=dat(9:length(dat)); nanchors=length(line_anchors)/2; front=anchors(1:ind); back=anchors(ind+2+2*anchors(ind+1):length(anchors)); anchors=[front nanchors line_anchors back]; if( anchors==0 )anchors=[]; end set(hanchors,'userdata',anchors); set(hstor,'userdata',[]); end %set(gca,'userdata',[]); set(hstor,'userdata',[]); set(hundo,'userdata',[]); return;endif( strcmp(action,'buttondown') ) % Get the storage bucket h=get(gcf,'children'); found=0; 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') ) hstor=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_anchors') ) hanchors=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_undo') ) hundo=h(k); found=found+1; end if( found== 4) break; end end end end dat=get(hstor,'userdata'); % the user data of hstor is: % dat(1) = handle of the selected line % dat(2) = original linestyle % dat(3) = original linewidth % dat(4:6) = original color % dat(7) = handle of duplicate line % dat(8) = handle of the anchor line % dat(9:length(dat)) = (x,y)'s of the anchors of the selected line % get the parameters % pdata(1) ... xonly flag % pdata(2) ... yonly flag % pdata(3) ... linkmode flag % pdata(4) ... locate flag % pdata(5) ... dragmode flag % pdata(6) ... smoothmode % pdata(7) ... fastopt % pdata(8) ... multiple nans % pdata(9) ... nodelete % pdata(10) ... noadd pdata=get(hparams,'userdata'); xonly=pdata(1); yonly=pdata(2); linkmode=pdata(3); locate=pdata(4); dragmode=pdata(5); smoothmode=pdata(6); fastopt=pdata(7); singnan=pdata(8); nodelete=pdata(9); noadd=pdata(10);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -