Changeset 625 for trunk/src/mouse_down.m


Ignore:
Timestamp:
May 2, 2013, 7:51:42 PM (8 years ago)
Author:
sommeria
Message:

system of object creation by mouse ilmproved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mouse_down.m

    r623 r625  
    2828FigData=get(hObject,'UserData'); %default data stored on the current object
    2929if ishandle(FigData)% case of a zoom plot, the handle of the parent rectangle is stored in UserData, its parent is the plotting axes of the rectangle
    30     hcurrentfig=get(get(FigData,'parent'),'parent');%handle of the current GUI: zoom plot
     30    hCurrentGUI=get(get(FigData,'parent'),'parent');%handle of the current GUI: zoom plot
    3131else
    32     hcurrentfig=hObject; % handle of the current GUI: usual plot
    33 end
    34 hhcurrentfig=guidata(hcurrentfig);% tags of the children of the current GUI
     32    hCurrentGUI=hObject; % handle of the current GUI: usual plot
     33end
     34hhCurrentGUI=guidata(hCurrentGUI);% tags of the children of the current GUI
    3535CheckZoom=0;
    36 if isfield(hhcurrentfig,'CheckZoom') && get(hhcurrentfig.CheckZoom,'Value');%test for zoom action, first priority
     36if isfield(hhCurrentGUI,'CheckZoom') && get(hhCurrentGUI.CheckZoom,'Value');%test for zoom action, first priority
    3737    CheckZoom=1;
    3838end
    3939test_piv=isfield(FigData,'CivHandle');
    40 set(hcurrentfig,'Units','pixels')
    41 GUI_pos=get(hcurrentfig,'Position');%position of the GUI series on the screen (in pixels), used to position message boxes
    42 set(hcurrentfig,'Units','normalized')% back to current unit for fig position
     40set(hCurrentGUI,'Units','pixels')
     41GUI_pos=get(hCurrentGUI,'Position');%position of the GUI series on the screen (in pixels), used to position message boxes
     42set(hCurrentGUI,'Units','normalized')% back to current unit for fig position
    4343
    4444%% determine the currently selected items
    4545hcurrentobject=gco;% current object handle (selected by the mouse)
    46 fig_tag=get(hcurrentfig,'Tag');
     46CurrentGUI_tag=get(hCurrentGUI,'Tag');
    4747obj_tag=get(gco,'Tag');%tag of the currently selected object
    4848xy=[];%default
     
    6363    if ~isempty(hset_object)
    6464        hPLOT=findobj(hset_object,'tag','PLOT');
    65         test_create=strcmp(get(hPLOT,'enable'),'on') &&~test_edit;% create new object if set_object is in mode enable and uvmat not in mode 'edit_object'
     65        test_create=strcmp(get(hPLOT,'enable'),'on') &&~get(hhuvmat.edit_object,'Value');% create new object if set_object is in mode enable and uvmat not in mode 'edit_object'
    6666    end
    6767    test_edit_vect=get(hhuvmat.edit_vect,'Value') && ~test_create && ~(isequal(obj_tag,'proj_object')||isequal(obj_tag,'DeformPoint')) ;%test for vector editing,  priority 4
     
    8181%% loop on all the objects in the current figure (selected by the last mouse click)
    8282hchildren=get(hObject,'Children');%handles of all objects in the current figure
    83 check_visible=strcmp(get(hchildren,'Visible'),'on');% if visible='on', =0 otherwise
    84 hchildren=hchildren(check_visible); %kkep only the visible children
     83check_visible=strcmp(get(hchildren,'Visible'),'on')& ~strcmp(get(hchildren,'Type'),'uimenu');% if visible='on', =0 otherwise
     84hchildren=hchildren(check_visible); %keep only the visible children
     85set(hchildren,'Units','normalized');
    8586PosChildren=get(hchildren,'Position');% set of object positions
    8687if iscell(PosChildren)% only one child
     
    9697ind_object=find(check_pos(:,1) & check_pos(:,2),1);% select the index of the (first) object under the mouse
    9798hchild=hchildren(ind_object);% corresponding object handle
    98 if isempty(hchild)
    99 %     if test_edit||test_create
    100 %         hPlotAxes=findobj(hcurrentfig,'Tag','PlotAxes');
    101 %         if ~isempty( hPlotAxes)
    102 %             PosPlotAxes=get(hPlotAxes,'Position');
    103 %             PosDiff(1)=xy_fig(1)-PosPlotAxes(1)-PosPlotAxes(3);% distance to the right axes edge
    104 %             PosDiff(2)=PosPlotAxes(1)-xy_fig(1);% distance to the left axes edge
    105 %             PosDiff(3)=xy_fig(2)-PosPlotAxes(1)-PosPlotAxes(3);% distance to the top axes edge
    106 %             PosDiff(4)=PosPlotAxes(2)-xy_fig(2);% distance to the low axes edge
    107 %             [tild,ind_sel]=max(PosDiff);
    108 %             list_arrow=[29 28 30 31];
    109 %             arrow_option=list_arrow(ind_sel);
    110 %             keyboard_callback(hcurrentfig,arrow_option)
    111 %             return
    112 %         end
    113 %     end
    114 else
     99if ~isempty(hchild)
    115100    htype=get(hchild,'Type');%type of object child of the current figure
    116101    switch htype
     
    129114            if test_edit_vect
    130115                ivec=[];
    131                 FigData=get(hcurrentfig,'UserData');
     116                FigData=get(hCurrentGUI,'UserData');
    132117                tagaxes=get(hchild,'tag');
    133118                if isfield(FigData,tagaxes)
     
    200185
    201186%% creation of a zoom subfig
    202 if isfield(hhcurrentfig,'CheckZoomFig') && get(hhcurrentfig.CheckZoomFig,'Value')
     187if isfield(hhCurrentGUI,'CheckZoomFig') && get(hhCurrentGUI.CheckZoomFig,'Value')
    203188    AxeData.Drawing='zoom'; %initiate drawing mode
    204189    AxeData.CurrentObject=[];%unselect objects
     
    212197
    213198%% ruler has second priority
    214 if test_ruler
     199if test_ruler && ~isempty(xy)
    215200    AxeData.RulerCoord(1,1:2)=xy(1,1:2);
    216201    AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
     
    287272            IndexObj=ObjectData.IndexObj;
    288273                    %indicate on the list of the GUI uvmat which object has been selected
    289             if strcmp(get(hcurrentfig,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
     274            if strcmp(get(hCurrentGUI,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
    290275%                 IndexObj=get(hhuvmat.ListObject,'Value');
    291276%                 if IndexObj>IndexObj_old(1)
     
    331316
    332317%%  create  projection  object
    333 if  test_create && ~isempty(xy)
     318if  test_create && ~isempty(xy) && ~strcmp(get(hCurrentGUI,'SelectionType'),'alt')
    334319    % activate this option if the GUI set_object is opened
    335     if ~isempty(hset_object) && ~strcmp(get(hcurrentfig,'SelectionType'),'alt')
    336         sethandles=guidata(hset_object);% handles of the elements in the GUI set_object
    337         ObjectData=read_GUI(hset_object); %read object parameters in the GUI set_object
    338         IndexObj=length(UvData.ProjObject);
    339         %initiate a new object (no data .Coord yet recorded)
    340         if ~isfield(UvData.ProjObject{IndexObj},'Coord');
    341             ObjectData.Coord=[];
    342             ObjectNameNew=ObjectData.Name;
    343             if isempty(ObjectNameNew)
    344                 ObjectNameNew=ObjectData.Type;
    345             end
    346             % add an index to the object name if the proposed name already exists
    347             vers=0;% index of the name
    348             ListObject=get(hhuvmat.ListObject,'String');
    349             detectname=1;
    350             while ~isempty(detectname)
    351                 detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
    352                 if detectname% if the object name already exists
    353                     indstr=regexp(ObjectNameNew,'\D');
    354                     if indstr(end)<length(ObjectNameNew) %object name ends by a number
    355                         vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
    356                         ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
    357                     else
    358                         vers=vers+1;
    359                         ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
    360                     end
     320    sethandles=guidata(hset_object);% handles of the elements in the GUI set_object
     321    ObjectData=read_GUI(hset_object); %read object parameters in the GUI set_object
     322    IndexObj=length(UvData.ProjObject);
     323    % if the currently selected object is already finished, a new object is initiated
     324    if ~isfield(UvData.ProjObject{IndexObj},'CreateMode')
     325        IndexObj=IndexObj+1;%start new object
     326        ObjectData.Coord=[];
     327        ObjectNameNew=ObjectData.Name;
     328        if isempty(ObjectNameNew)
     329            ObjectNameNew=ObjectData.Type;
     330        end
     331        % add an index to the object name if the proposed name already exists
     332        vers=0;% index of the name
     333        ListObject=get(hhuvmat.ListObject,'String');
     334        detectname=1;
     335        while ~isempty(detectname)
     336            detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
     337            if detectname% if the object name already exists
     338                indstr=regexp(ObjectNameNew,'\D');
     339                if indstr(end)<length(ObjectNameNew) %object name ends by a number
     340                    vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
     341                    ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
     342                else
     343                    vers=vers+1;
     344                    ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
    361345                end
    362346            end
    363             ObjectName=ObjectNameNew;
    364             set(sethandles.Name,'String',ObjectName)% display the default name in set_object
    365             if isempty(ListObject)
    366                 ListObject={ObjectName};
    367             else
    368                 ListObject{end}=ObjectName;
    369             end
    370             set(hhuvmat.ListObject,'String',ListObject);%complement the object list
    371             set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
     347        end
     348        ObjectName=ObjectNameNew;
     349        set(sethandles.Name,'String',ObjectName)% display the default name in set_object
     350        ListObject=[ListObject;{ObjectName}];
     351        set(hhuvmat.ListObject,'String',ListObject);%complement the object list
     352        set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
     353        if strcmp(CurrentGUI_tag,'uvmat')
    372354            set(hhuvmat.ListObject,'Value',IndexObj)
    373             set(hhuvmat.ViewObject,'Value',1)
    374         end
    375         ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object
    376                                                          %TODO replace 0 by z coord for 3D       
    377         hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(fig_tag);
    378         if isempty(hobject)
    379             hobject=haxes;
    380         end
     355        else
     356            set(hhuvmat.ListObject_1,'Value',IndexObj)
     357        end
     358        UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
     359        UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
     360        set(hhuvmat.ViewObject,'Value',1)
     361    end
     362    ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object
     363    %TODO replace 0 by z coord for 3D
     364    hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag);
     365    if isempty(hobject)
     366        hobject=haxes;
     367    end
     368    if strcmp(CurrentGUI_tag,'uvmat')
    381369        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
    382         AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
    383         UvData.ProjObject{IndexObj}=ObjectData;
    384         UvData.ProjObject{IndexObj}.DisplayHandle.(fig_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object
    385         set(huvmat,'UserData',UvData)
    386         PlotData=get(AxeData.CurrentObject,'UserData');
    387         PlotData.IndexObj=IndexObj;
    388         set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion)
    389         AxeData.Drawing='create';% flag for mouse motion
    390         %show object coordinates in the GUI set_object
    391         h_set_object=findobj(allchild(0),'Tag','set_object');
    392         hh_set_object=guidata(h_set_object);
    393         set(hh_set_object.Coord,'Data',ObjectData.Coord);
    394     end
     370    else
     371        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')};
     372    end
     373    AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
     374    UvData.ProjObject{IndexObj}=ObjectData;
     375    UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object
     376    UvData.ProjObject{IndexObj}.CreateMode='on';% mark the object as in the course of creation
     377    set(huvmat,'UserData',UvData)
     378    PlotData=get(AxeData.CurrentObject,'UserData');
     379    PlotData.IndexObj=IndexObj;
     380    set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion)
     381    AxeData.Drawing='create';% flag for mouse motion
     382   
     383   
     384    %initiate a new object (no data .Coord yet recorded)
     385    %if ~isfield(UvData.ProjObject{IndexObj},'Coord');
     386    %     ObjectData.Coord=[];
     387   
     388    %             if isempty(ListObject)
     389    %                 ListObject={ObjectName};
     390    %             else
     391    %                 ListObject{end}=ObjectName;
     392    %             end
     393    %                 UvData.ProjObject{IndexObj}=[]; %create a new empty object
     394    %     UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
     395    %     UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
     396   
     397    %         PlotData=get(AxeData.CurrentObject,'UserData');
     398    %         PlotData.IndexObj=IndexObj;
     399    %         set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion)
     400    %         AxeData.Drawing='create';% flag for mouse motion
     401    %show object coordinates in the GUI set_object
     402    h_set_object=findobj(allchild(0),'Tag','set_object');
     403    hh_set_object=guidata(h_set_object);
     404    set(hh_set_object.Coord,'Data',ObjectData.Coord);
    395405end
    396406
     
    475485        Field.FF(ivec)=0;
    476486    end
    477     PlotParam=read_GUI(hcurrentfig);
     487    PlotParam=read_GUI(hCurrentGUI);
    478488    plot_field(Field,haxes,PlotParam);
    479489    eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData
    480     set(hcurrentfig,'UserData',FigData);
     490    set(hCurrentGUI,'UserData',FigData);
    481491end 
    482492set(haxes,'UserData',AxeData);
Note: See TracChangeset for help on using the changeset viewer.