Changeset 296 for trunk/src/mouse_down.m


Ignore:
Timestamp:
Nov 22, 2011, 1:39:47 PM (12 years ago)
Author:
sommeria
Message:

various

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mouse_down.m

    r292 r296  
    3636    hcurrentfig=hObject;%usual plot
    3737end
    38     set(hcurrentfig,'Units','pixels')
    39     currentfig_pos=get(hcurrentfig,'Position');%position of the GUI series (in pixels)
    40     set(hcurrentfig,'Units','normalized')
     38set(hcurrentfig,'Units','pixels')
     39GUI_pos=get(hcurrentfig,'Position');%position of the GUI series (in pixels)
     40set(hcurrentfig,'Units','normalized')
    4141hhcurrentfig=guidata(hcurrentfig);
    4242test_zoom=get(hhcurrentfig.CheckZoom,'Value');%test for zoom action, first priority
     
    7171xy=[];%default
    7272xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo)
    73 hchild=get(hObject,'Children');%handles of all objects in the current figure
     73hchildren=get(hObject,'Children');%handles of all objects in the current figure
    7474haxes=[];
    7575
    7676%% loop on all the objects in the current figure (selected by the last mouse click)
    77 %CurrentOrigin=get(hObject,'CurrentPoint')
    78 for ichild=1:length(hchild)
    79     obj_pos=get(hchild(ichild),'Position');%position of the object
     77output_str='';
     78for ichild=1:length(hchildren)
     79    hchild=hchildren(ichild); %handle of the current object
     80    obj_pos=get(hchild,'Position');%position of the object
    8081    if xy_fig(1) >=obj_pos(1) & xy_fig(2) >= obj_pos(2)& xy_fig(1) <=obj_pos(1)+obj_pos(3) & xy_fig(2) <= obj_pos(2)+obj_pos(4);
    81         htype=get(hchild(ichild),'Type');%type of object child of the current figure
    82         %if the mouse is over an axis, look at the data
    83         if isequal(htype,'axes')
    84             y_lim=get(hchild(ichild),'YLim');
    85             x_lim=get(hchild(ichild),'XLim');
    86             haxes=hchild(ichild);
    87             xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
    88             if xy(1,1)>x_lim(1) && xy(1,1)<x_lim(2) && xy(1,2)>y_lim(1) && xy(1,2)<y_lim(2)
    89                 AxeData=get(haxes,'UserData');% data attached to the axis
    90                 AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin
    91                 if test_edit_vect && ~isequal(tag_obj,'proj_object') & ~test_create
    92                     ivec=[];
    93                     FigData=get(hcurrentfig,'UserData');
    94                     tagaxes=get(haxes,'tag');
    95                     if isfield(FigData,tagaxes)
    96                         eval(['Field=FigData.' tagaxes ';'])
    97                         [CellVarIndex,NbDim,VarType]=find_field_indices(Field);%analyse the physical fields contained in Field
    98                         for icell=1:numel(CellVarIndex)%look for all physical fields
    99                             if NbDim(icell)==2 % select 2D field
    100                                 if  isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data
    101                                     eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';'])
    102                                     eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';'])
    103                                     flag_vec=(X<(xy(1,1)+Field.Mesh/4) & X>(xy(1,1)-Field.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse
    104                                         (Y<(xy(1,2)+Field.Mesh/4) & Y>(xy(1,2)-Field.Mesh/4));%f
    105                                     ivec=find(flag_vec,1);% search the (first) selected vector index ivec
     82        htype=get(hchild,'Type');%type of object child of the current figure
     83
     84        switch htype
     85            %if the mouse is over an axis, look at the data
     86            case 'axes'
     87                y_lim=get(hchild,'YLim');
     88                x_lim=get(hchild,'XLim');
     89                haxes=hchild;
     90                xy=get(hchild,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
     91                if xy(1,1)>x_lim(1) && xy(1,1)<x_lim(2) && xy(1,2)>y_lim(1) && xy(1,2)<y_lim(2)
     92                    AxeData=get(hchild,'UserData');% data attached to the axis
     93                    AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin
     94                    if test_edit_vect && ~isequal(tag_obj,'proj_object') & ~test_create
     95                        ivec=[];
     96                        FigData=get(hcurrentfig,'UserData');
     97                        tagaxes=get(hchild,'tag');
     98                        if isfield(FigData,tagaxes)
     99                            eval(['Field=FigData.' tagaxes ';'])
     100                            [CellVarIndex,NbDim,VarType]=find_field_indices(Field);%analyse the physical fields contained in Field
     101                            for icell=1:numel(CellVarIndex)%look for all physical fields
     102                                if NbDim(icell)==2 % select 2D field
     103                                    if  isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data
     104                                        eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';'])
     105                                        eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';'])
     106                                        flag_vec=(X<(xy(1,1)+Field.Mesh/4) & X>(xy(1,1)-Field.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse
     107                                            (Y<(xy(1,2)+Field.Mesh/4) & Y>(xy(1,2)-Field.Mesh/4));%f
     108                                        ivec=find(flag_vec,1);% search the (first) selected vector index ivec
     109                                    end
    106110                                end
    107111                            end
    108112                        end
    109113                    end
     114                else
     115                    hchild=[];%mouse out of axes
    110116                end
    111             else
    112                 haxes=[];%mouse out of axes
    113             end
    114             break
    115         elseif isequal(get(hObject,'SelectionType'),'alt') && isequal(htype,'uicontrol') && isequal(get(hchild(ichild),'Visible'),'on') && ~isequal(get(hchild(ichild),'tag'),'frame_object')&&...
    116              ~isequal(get(hchild(ichild),'tag'),'list_object_2') && ~isequal(get(hchild(ichild),'tag'),'list_object_1')
    117                 msg_pos(1:2)=currentfig_pos(1:2)+obj_pos(1:2).*currentfig_pos(3:4);
    118                 msgbox_uvmat(['uicontrol: ' get(hchild(ichild),'Tag')],'',get(hchild(ichild),'String'),msg_pos)
    119             break
    120         end
    121     end
    122 end
    123 
     117                break
     118            case 'uicontrol'  %if the mouse is over a uicontrol, duplicate the display  in an editable  zoom window
     119                if isequal(get(hObject,'SelectionType'),'alt')  && isequal(get(hchild,'Visible'),'on') && ~isequal(get(hchild,'tag'),'frame_object')&&...
     120                        ~isequal(get(hchild,'tag'),'list_object_2') && ~isequal(get(hchild,'tag'),'list_object_1')
     121                    if strcmp(get(hchild,'Visible'),'on')
     122                        msg_pos(1:2)=GUI_pos(1:2)+obj_pos(1:2).*GUI_pos(3:4);
     123                        output_str=msgbox_uvmat(['uicontrol: ' get(hchild,'Tag')],'',get(hchild,'String'),msg_pos);
     124                        break
     125                    end
     126                end
     127            case 'uipanel'
     128                panel_pos=obj_pos;%position of the panel
     129                hhchildren=get(hchild,'Children');%handles of all objects in the current GUI
     130                %% loop on all the objects in the current figure (selected by the last mouse click)
     131                for iichild=1:length(hhchildren)
     132                    hchild=hhchildren(iichild);
     133                    rel_pos=get(hchild,'Position');%position of the object relative to the uipanel
     134                    obj_pos(1:2)=panel_pos(1:2)+rel_pos(1:2).*panel_pos(3:4);
     135                    obj_pos(3:4)=panel_pos(3:4).*rel_pos(3:4);
     136                    if numel(obj_pos)>=4 && xy_fig(1) >=obj_pos(1) && xy_fig(2) >= obj_pos(2)&& xy_fig(1) <=obj_pos(1)+obj_pos(3) && xy_fig(2) <= obj_pos(2)+obj_pos(4);
     137                        htype=get(hchild,'Type');%type of object child of the current figure
     138                        %if the mouse is over a uicontrol, look at the data
     139                        if strcmp(htype,'uicontrol') && strcmp(get(hchild,'Visible'),'on')
     140                            msg_pos(1:2)=GUI_pos(1:2)+obj_pos(1:2).*GUI_pos(3:4);
     141                            output_str=msgbox_uvmat(['uicontrol: ' get(hchild,'Tag')],'',get(hchild,'String'),msg_pos);
     142                            break
     143                        end
     144                    end
     145                end
     146        end
     147    end
     148end
     149if ~isempty(output_str)               
     150    set(hObject,'Units','pixels')
     151    set(hchild,'String',output_str)
     152end
     153   
    124154%% desable  object creation and vector editing if NbDim different from 2
    125155if ~(isfield(AxeData,'NbDim') && isequal(AxeData.NbDim,2))
     
    138168     AxeData.Drawing='zoom'; %initiate drawing mode
    139169     AxeData.CurrentObject=[];%unselect objects
    140      set(haxes,'UserData',AxeData);
     170     set(hchild,'UserData',AxeData);
    141171     return
    142172end
     
    151181    AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
    152182    AxeData.Drawing='ruler';
    153     set(haxes,'UserData',AxeData);
     183    set(hchild,'UserData',AxeData);
    154184    return
    155185end
     
    219249            end
    220250            set_object(UvData.Object{IndexObj})
    221             axes(haxes);%set back the current axes haxes
     251            axes(hchild);%set back the current axes haxes
    222252            testdeform=0;
    223253            set(gcbo,'Pointer','circle');
Note: See TracChangeset for help on using the changeset viewer.