Changeset 67 for trunk/src/mouse_down.m


Ignore:
Timestamp:
Mar 25, 2010, 6:48:48 PM (14 years ago)
Author:
sommeria
Message:

civ: RUN civ lounched out of the Matlab work space. RUN and BATCH now runned by a unique sub-function lounch.m.
FiLE PARAM.xml modified to provide different paths for Batch and Run !!!!!
RUN_FIX: minor error message modif
geometry_calib: calib point editing by the mouse
improvement of the interactions between the different GUIs. Close function...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mouse_down.m

    r65 r67  
    2323
    2424function xy=mouse_down(hObject,eventdata)
    25 testzoom=0;%default
     25
    2626MouseAction='none'; %default
    2727huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle which controls theoption of  mouse action
     
    3131hhuvmat=guidata(huvmat);%handles of elements in uvmat
    3232UvData=get(huvmat,'UserData');
     33MouseAction='none'; %default
    3334testzoom=get(hhuvmat.zoom,'Value');% get the mouse action from the uvmat GUI: options:
    3435if isfield(UvData,'MouseAction')
     
    4041test_cal=strcmp(MouseAction,'calib');
    4142test_ruler=strcmp(MouseAction,'ruler');
    42 % menu_coord=get(hhuvmat.transform_fct,'String');
    43 % coord_choice=get(hhuvmat.transform_fct,'Value');
    44 % coord_type=menu_coord{coord_choice};
    4543test_edit=strcmp(MouseAction,'edit_object');
    4644test_edit_vect=strcmp(MouseAction,'edit_vect');
    4745xdisplay=[];%default
    4846ydisplay=[];%default
    49 haxes=[];
    5047AxeData=[];%default
    5148
     
    5855xy_fig=get(hcurrentfig,'CurrentPoint');% current point of the current figure (gcbo)
    5956hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure
     57haxes=[];
    6058% loop on all the objects in the current figure (selected by the last mouse click)
    6159for ichild=1:length(hchild)
     
    8381                    flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/4) & AxeData.X>(xy(1,1)-AxeData.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse
    8482                      (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f
    85                     ivec=find(flag_vec);% search the selected vector index ivec
    86                     if length(ivec)>0
    87                         ivec=ivec(1);%choice the first selected vector if several are selected                       
    88                     end
     83                    ivec=find(flag_vec,1);% search the (first) selected vector index ivec
    8984                end
    9085            end
     
    113108     AxeData.Drawing='zoom'; %initiate drawing mode
    114109     AxeData.CurrentObject=[];%unselect objects
    115 elseif ~isempty(huvmat)
    116     %selection of an existing projection object
    117     if  test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint'))
    118         if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
    119             userdata=get(hcurrentobject,'UserData');
    120             if ishandle(userdata)%the selected line depends on a parent line
    121                 AxeData.CurrentObject=userdata;% the parent object becomes the current one
    122             else
    123                 AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
    124             end
    125             ObjectData=get(AxeData.CurrentObject,'UserData');
    126             if test_edit & isfield(ObjectData,'IndexObj')
    127                 hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
    128                 set(hother,'Color','b');%reset all the proj objects in 'blue' by default
    129                 set(hother,'Selected','off')
    130                 hother=findobj('Tag','proj_object','Type','rectangle');
    131                 set(hother,'EdgeColor','b');
    132                 set(hother,'Selected','off');
    133                 hother=findobj('Tag','proj_object','Type','image');
    134                 for iobj=1:length(hother)
    135                        Acolor=get(hother(iobj),'CData');
    136                        Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
    137                        set(hother(iobj),'CData',Acolor);
    138                 end
    139                 hother=findobj('Tag','DeformPoint');
    140                 set(hother,'Color','b');
    141                 set(hother,'Selected','off')   
    142                 if isequal(get(AxeData.CurrentObject,'Type'),'line')
    143                     set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
    144                 elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
    145                      set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
    146                 end
    147                 if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
    148                     for iobj=1:length(ObjectData.SubObject)
    149                         hsub=ObjectData.SubObject(iobj);
    150                         if isequal(get(hsub,'Type'),'rectangle')
    151                             set(hsub,'EdgeColor','m'); %set the selected object to magenta color
    152                         elseif isequal(get(hsub,'Type'),'image')
    153                            Acolor=get(hsub,'CData');
    154                            Acolor(:,:,1)=Acolor(:,:,3);
    155                            set(hsub,'CData',Acolor);
    156                         else
    157                             set(hsub,'Color','m')
    158                         end
     110     return
     111end
     112if isempty(huvmat)
     113    return
     114end
     115
     116%selection of an existing projection object
     117if  test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint'))
     118    if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
     119        userdata=get(hcurrentobject,'UserData');
     120        if ishandle(userdata)%the selected line depends on a parent line
     121            AxeData.CurrentObject=userdata;% the parent object becomes the current one
     122        else
     123            AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
     124        end
     125        ObjectData=get(AxeData.CurrentObject,'UserData');
     126        if test_edit & isfield(ObjectData,'IndexObj')
     127            hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
     128            set(hother,'Color','b');%reset all the proj objects in 'blue' by default
     129            set(hother,'Selected','off')
     130            hother=findobj('Tag','proj_object','Type','rectangle');
     131            set(hother,'EdgeColor','b');
     132            set(hother,'Selected','off');
     133            hother=findobj('Tag','proj_object','Type','image');
     134            for iobj=1:length(hother)
     135                   Acolor=get(hother(iobj),'CData');
     136                   Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
     137                   set(hother(iobj),'CData',Acolor);
     138            end
     139            hother=findobj('Tag','DeformPoint');
     140            set(hother,'Color','b');
     141            set(hother,'Selected','off')   
     142            if isequal(get(AxeData.CurrentObject,'Type'),'line')
     143                set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
     144            elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
     145                 set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
     146            end
     147            if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
     148                for iobj=1:length(ObjectData.SubObject)
     149                    hsub=ObjectData.SubObject(iobj);
     150                    if isequal(get(hsub,'Type'),'rectangle')
     151                        set(hsub,'EdgeColor','m'); %set the selected object to magenta color
     152                    elseif isequal(get(hsub,'Type'),'image')
     153                       Acolor=get(hsub,'CData');
     154                       Acolor(:,:,1)=Acolor(:,:,3);
     155                       set(hsub,'CData',Acolor);
     156                    else
     157                        set(hsub,'Color','m')
    159158                    end
    160159                end
    161                 if isequal(tag_obj,'DeformPoint')
    162                      set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
    163                 end
    164                 IndexObj=ObjectData.IndexObj;
    165                 set(hhuvmat.list_object_1,'Value',IndexObj);
    166                 set(hhuvmat.list_object_2,'Value',IndexObj);
    167                 testdeform=0;
    168                 set(gcbo,'Pointer','circle');
    169                 AxeData.Drawing='deform';
    170                 if isequal(tag_obj,'DeformPoint')       
    171                    if isfield(ObjectData,'DeformPoint')
    172                        set(hcurrentobject,'Selected','on')
    173                        for ipt=1:length(ObjectData.DeformPoint)
    174                            if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
    175                                 AxeData.CurrentIndex=ipt;
    176                                 testdeform=1;
    177                            end
     160            end
     161            if isequal(tag_obj,'DeformPoint')
     162                 set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
     163            end
     164            IndexObj=ObjectData.IndexObj;
     165            set(hhuvmat.list_object_1,'Value',IndexObj);
     166            set(hhuvmat.list_object_2,'Value',IndexObj);
     167            testdeform=0;
     168            set(gcbo,'Pointer','circle');
     169            AxeData.Drawing='deform';
     170            if isequal(tag_obj,'DeformPoint')       
     171               if isfield(ObjectData,'DeformPoint')
     172                   set(hcurrentobject,'Selected','on')
     173                   for ipt=1:length(ObjectData.DeformPoint)
     174                       if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
     175                            AxeData.CurrentIndex=ipt;
     176                            testdeform=1;
    178177                       end
    179178                   end
    180                 end
    181                 if testdeform==0
    182                     AxeData.Drawing='translate';
    183                     set(AxeData.CurrentObject,'Selected','on')
    184                     set(gcbo,'Pointer','fleur');
    185                 end
    186             end
    187         end
    188     end
    189     %  create new projection  object
    190     if  test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create'))
    191             ObjectData=read_set_object(UvData.sethandles);
    192             ObjectData.Coord=[]; %reset previous object coordinates
    193             ObjectData.Coord(1,1)=xy(1,1);
    194             ObjectData.Coord(1,2)=xy(1,2);
    195             ObjectData.Coord(1,3)=0;
    196             if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
    197                  ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
    198             end
    199             AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject
    200             if isfield(UvData,'Object')
    201                 IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface
    202             else
    203                 IndexObj=2;
    204             end 
    205             UvData.Object{IndexObj}=ObjectData;
    206             UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject;
    207             set(huvmat,'UserData',UvData)
    208             list_str=get(hhuvmat.list_object_1,'String');
    209             list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style];
    210             if ~isequal(list_str{end},'...')
    211                  list_str{end+1}='...';
    212             end
    213             set(hhuvmat.list_object_1,'String',list_str)
    214             set(hhuvmat.list_object_2,'String',list_str)
    215             if strcmp(fig_tag,'view_field')%we are in view_field plot
    216                   set(hhuvmat.list_object_1,'Value',IndexObj)
    217             else%we are in uvmat plot
    218                 set(hhuvmat.list_object_2,'Value',IndexObj)
    219             end
    220             PlotData=get(AxeData.CurrentObject,'UserData');
    221             PlotData.IndexObj=IndexObj;
    222             set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph
    223             AxeData.Drawing='create';
    224     end
    225 
    226     % create calibration points if the GUI geometry_calib is opened
    227     if test_cal & ~isempty(xy)
    228         h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
    229         hh_geometry_calib=guidata(h_geometry_calib);
    230         h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
    231         h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append');
    232         if isequal(get(h_edit_append,'Value'),1)
    233             coord_value=get(hhuvmat.transform_fct,'Value');
    234             if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys)
    235                 set(hhuvmat.transform_fct,'Value',1)
    236                 set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
    237                 set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
    238                 uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
    239                 return
    240             end
    241 %             if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
    242                 strline=[ '    |    '  '    |    '  '    |    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)];
    243 %             else %phys cordinates
    244 %                 strline=[ num2str(xy(1,1),4) '    |    '  num2str(xy(1,2),4) '    |    0      |    '  '    |    ' ];
    245 %             end
    246             Coord=get(h_ListCoord,'String');
    247             val=get(h_ListCoord,'Value');
    248             if isequal(Coord,{''})
    249                 val=0;
    250             end
    251             if length(Coord)>val
    252                 Coord(val+2:length(Coord)+1)=Coord(val+1:length(Coord));% push the list forward beyond the current point
    253             end
    254             Coord{val+1}=strline;
    255             set(h_ListCoord,'String',Coord)
    256             set(h_ListCoord,'Value',val+1)
    257             geometry_calib('ListCoord_Callback',hObject,eventdata,hh_geometry_calib)
    258             data=read_geometry_calib(Coord);
    259 %             if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
    260                 XCoord=data.Coord(:,4);
    261                 YCoord=data.Coord(:,5);
    262 %             else %phys cordinates
    263 %                 XCoord=data.Coord(:,1);
    264 %                 YCoord=data.Coord(:,2);
    265 %             end
    266             hh=findobj('Tag','calib_points');           
    267             if isempty(hh)
    268                 line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
    269             else
    270                 set(hh,'XData',XCoord)
    271                 set(hh,'YData',YCoord)
    272             end
    273             hhh=findobj('Tag','calib_marker');
    274             if ~isempty(hhh)
    275                 set(hhh,'XData',xy(1,1))
    276                 set(hhh,'YData',xy(1,2))
    277             else
    278                 line(xy(1,1),xy(1,2),'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20);
    279             end
    280             %uistack(h_geometry_calib,'top')
    281         end
    282     end
    283 
    284     % edit vectors
    285     if test_edit_vect & ~isempty(ivec)
    286     %     FF_100=FF-100*double(uint(abs(FF)/100); %value of FF without units and dizaines
    287         if ~(isfield(AxeData,'FF')&& ~isempty(AxeData.FF))
    288             AxeData.FF=zeros(size(AxeData.X));
    289         end
    290         if isequal(AxeData.FF(ivec),0)
    291             AxeData.FF(ivec)=100; %mark vector #ivec as false
     179               end
     180            end
     181            if testdeform==0
     182                AxeData.Drawing='translate';
     183                set(AxeData.CurrentObject,'Selected','on')
     184                set(gcbo,'Pointer','fleur');
     185            end
     186        end
     187    end
     188end
     189%  create new projection  object
     190if  test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create'))
     191        ObjectData=read_set_object(UvData.sethandles);
     192        ObjectData.Coord=[]; %reset previous object coordinates
     193        ObjectData.Coord(1,1)=xy(1,1);
     194        ObjectData.Coord(1,2)=xy(1,2);
     195        ObjectData.Coord(1,3)=0;
     196        if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
     197             ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
     198        end
     199        AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject
     200        if isfield(UvData,'Object')
     201            IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface
    292202        else
    293             AxeData.FF(ivec)=0;
    294         end
    295         PlotParam=read_plot_param(hhuvmat);
    296         [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1);
    297     end   
    298    
    299     %create ruler
    300     if test_ruler
    301         UvData.RulerCoord(1,1)=xy(1,1);
    302         UvData.RulerCoord(1,2)=xy(1,2);
    303         UvData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
     203            IndexObj=2;
     204        end 
     205        UvData.Object{IndexObj}=ObjectData;
     206        UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject;
    304207        set(huvmat,'UserData',UvData)
    305     end
     208        list_str=get(hhuvmat.list_object_1,'String');
     209        list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style];
     210        if ~isequal(list_str{end},'...')
     211             list_str{end+1}='...';
     212        end
     213        set(hhuvmat.list_object_1,'String',list_str)
     214        set(hhuvmat.list_object_2,'String',list_str)
     215        if strcmp(fig_tag,'view_field')%we are in view_field plot
     216              set(hhuvmat.list_object_1,'Value',IndexObj)
     217        else%we are in uvmat plot
     218            set(hhuvmat.list_object_2,'Value',IndexObj)
     219        end
     220        PlotData=get(AxeData.CurrentObject,'UserData');
     221        PlotData.IndexObj=IndexObj;
     222        set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph
     223        AxeData.Drawing='create';
     224end
     225
     226% create calibration points if the GUI geometry_calib is opened, if the main axes axes3 of uvmat has ben selected
     227if test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'axes3')
     228    h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
     229    hh_geometry_calib=guidata(h_geometry_calib);
     230    h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
     231    h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append');
     232    if isequal(get(h_edit_append,'Value'),1)
     233        coord_value=get(hhuvmat.transform_fct,'Value');% set uvmat to pixel coordinates, run it again if not
     234        if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys)
     235            set(hhuvmat.transform_fct,'Value',1)
     236            set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
     237            set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
     238            uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
     239            return
     240        end
     241        Coord=get(h_ListCoord,'String');
     242        data=read_geometry_calib(Coord)%transform char cell to numbers
     243        ind_range=10;%range of research around each existing point
     244        test_newpoint=1;
     245        if size(data.Coord,2)>=5 %if calibration points already exist
     246            XCoord=(data.Coord(:,4));
     247            YCoord=(data.Coord(:,5));
     248            index_point=find((XCoord<xy(1,1)+ind_range) & (XCoord>xy(1,1)-ind_range) & ...%flagx=1 for the vectors with x position selected by the mouse
     249                          (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse
     250            test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position
     251        end
     252        %create a new calib point if we are not close to an existing one
     253        if test_newpoint                 
     254             strline=[ '    |    '  '    |    '  '    |    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)];
     255             val=get(h_ListCoord,'Value');
     256             if length(Coord)>=val
     257                 Coord(val+1:length(Coord)+1)=Coord(val:length(Coord))% push the list forward beyond the current point
     258             end
     259             Coord{val}=strline;
     260             set(h_ListCoord,'String',Coord)
     261             set(h_ListCoord,'Value',val+1)
     262             data=read_geometry_calib(Coord);%transform char cell to numbers
     263             XCoord=data.Coord(:,4);
     264             YCoord=data.Coord(:,5);
     265        end
     266        hh=findobj('Tag','calib_points');%look for handle of calibration points           
     267        if isempty(hh)
     268            hh=line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
     269        else
     270            set(hh,'XData',XCoord)
     271            set(hh,'YData',YCoord)
     272        end
     273        set(hh,'UserData','edit_mode')% flag the points to edit mode
     274        hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
     275        if ~isempty(hhh)
     276            set(hhh,'XData',xy(1,1))
     277            set(hhh,'YData',xy(1,2))
     278        else
     279            line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20);
     280        end
     281    end
     282end
     283
     284% edit vectors
     285if test_edit_vect & ~isempty(ivec)
     286    if ~(isfield(AxeData,'FF')&& ~isempty(AxeData.FF))
     287        AxeData.FF=zeros(size(AxeData.X));
     288    end
     289    if isequal(AxeData.FF(ivec),0)
     290        AxeData.FF(ivec)=100; %mark vector #ivec as false
     291    else
     292        AxeData.FF(ivec)=0;
     293    end
     294    PlotParam=read_plot_param(hhuvmat);
     295    [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1);
     296end   
     297
     298%create ruler
     299if test_ruler
     300    UvData.RulerCoord(1,1)=xy(1,1);
     301    UvData.RulerCoord(1,2)=xy(1,2);
     302    UvData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
     303    set(huvmat,'UserData',UvData)
    306304end
    307305set(haxes,'UserData',AxeData);
Note: See TracChangeset for help on using the changeset viewer.