source: trunk/src/set_object.m @ 962

Last change on this file since 962 was 961, checked in by sommeria, 5 years ago

NomType? level introduced

File size: 35.7 KB
Line 
1%'set_object': GUI to edit a projection object
2%------------------------------------------------------------------------
3% function hset_object= set_object(data, PlotHandles,ZBounds)
4% associated with the GUI set_object.fig
5%
6% OUTPUT:
7% hset_object: handle of the GUI figure
8%
9% INPUT:u
10% data: structure describing the object properties
11%    .Style=...
12%    .ProjMode
13%    .CoordType: 'phys' or 'px'
14%    .num_DX,.num_DY,.num_DZ : mesh along each dirction
15%    .RangeX, RangeY
16%    .Coord(j,i), i=1, 2, 3,  components x, y, z of j=1...n position(s) characterizing the object components
17% PlotHandles: handles for projection plots NO MORE USED
18% Zbounds: bounds on Z ( 3D case)
19
20%=======================================================================
21% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
22%   http://www.legi.grenoble-inp.fr
23%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
24%
25%     This file is part of the toolbox UVMAT.
26%
27%     UVMAT is free software; you can redistribute it and/or modify
28%     it under the terms of the GNU General Public License as published
29%     by the Free Software Foundation; either version 2 of the license,
30%     or (at your option) any later version.
31%
32%     UVMAT is distributed in the hope that it will be useful,
33%     but WITHOUT ANY WARRANTY; without even the implied warranty of
34%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35%     GNU General Public License (see LICENSE.txt) for more details.
36%=======================================================================
37
38function varargout = set_object(varargin)
39
40% Last Modified by GUIDE v2.5 16-Jun-2015 00:33:59
41
42% Begin initialization code - DO NOT REFRESH
43gui_Singleton = 1;
44gui_State = struct('gui_Name',       mfilename, ...
45                   'gui_Singleton',  gui_Singleton, ...
46                   'gui_OpeningFcn', @set_object_OpeningFcn, ...
47                   'gui_OutputFcn',  @set_object_OutputFcn, ...
48                   'gui_LayoutFcn',  [] , ...
49                   'gui_Callback',   []);
50if nargin & ischar(varargin{1})
51    gui_State.gui_Callback = str2func(varargin{1});
52end
53
54if nargout
55    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
56else
57    gui_mainfcn(gui_State, varargin{:});
58end
59% End initialization code - DO NOT REFRESH
60%------------------------------------------------------------------------
61%------------------------------------------------------------------------
62% --- Executes just before set_object is made visible.
63%INPUT:
64% handles: handles of the set_object interface elements
65%'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify
66%        if =[] or absent: index still undefined (create mode in uvmat)
67%        if=0; no associated object (used for series), the button 'REFRESH' is  then unvisible
68%'data': read from an existing object selected in the interface
69%      .Name : class of object ('POINTS','LINE',....)
70%      .num_DX,num_DY,num_DZ; meshes for regular grids
71%      .Coord: object position coordinates
72%      .ParentButton: handle of the uicontrol object calling the interface
73% PlotHandles: set of handles of the elements contolling the plotting of the projected field:
74%  if =[] or absent, no refresh (mask mode in uvmat)
75% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
76function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds)
77%-------------------------------------------------------------------
78% Choose default command line output for set_object
79handles.output = hObject;
80% Update handles structure
81guidata(hObject, handles);
82
83%% position
84set(0,'Unit','pixels')
85ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
86PosGUI=get(handles.set_object,'Position');% fig width in pixels
87Width=PosGUI(3);%width of the gui set_object in pixels
88Height=PosGUI(4);
89Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
90Bottom=ScreenSize(4)-Height-40; %put fig at top right
91set(handles.set_object,'Unit','pixels')
92set(handles.set_object,'Position',[Left Bottom Width Height])
93
94%default
95if ~exist('ZBounds','var')
96    ZBounds=0; %default
97end
98set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
99set(hObject,'DeleteFcn',{@closefcn})
100
101% fill the interface as set in the input data:
102if exist('data','var')
103    if isfield(data,'Coord') &&size(data.Coord,2)==3
104        set(handles.z_slider,'Visible','on')
105    else
106        set(handles.z_slider,'Visible','off')
107    end
108    if isfield(data,'TypeMenu')
109        set(handles.Type,'String',data.TypeMenu)
110    end
111    if isfield(data,'ProjModeMenu')
112        set(handles.ProjMode,'UserData',data.ProjModeMenu)% data.ProjModeMenu as default menu (used in Type_Callback)
113    end     
114    errormsg=fill_GUI(data,handles.set_object);
115    if ~isempty(errormsg)
116        msgbox_uvmat('ERROR','bad data input in set_object')
117        return
118    end
119    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type   
120    set(handles.REFRESH,'BackgroundColor',[1 0 0])
121    if isfield(data,'RangeZ')
122        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
123        if length(ZBounds) >= 2
124            DZ=max(data.RangeZ);%slider step
125            if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1)
126                rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
127                rel_step(2)=0.1;
128                set(handles.z_slider,'Visible','on')
129                set(handles.z_slider,'Min',ZBounds(1))
130                set(handles.z_slider,'Max',ZBounds(2))
131                set(handles.z_slider,'SliderStep',rel_step)
132                set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
133            end
134        end
135    end
136    if isfield(data,'RangeX')&& ~strcmp(data.Type,'plane_z')%TODO: generalise
137        if ischar(data.RangeX)
138            data.RangeX=str2num(data.RangeX);
139        end
140        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
141        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
142    end
143    if isfield(data,'RangeY')&& ~strcmp(data.Type,'plane_z')%TODO: generalise
144        if ischar(data.RangeY)
145            data.RangeY=str2num(data.RangeY);
146        end
147        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
148        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
149    end
150    if isfield(data,'RangeZ')&& ~strcmp(data.Type,'plane_z')%TODO: generalise
151        if ischar(data.RangeZ)
152            data.RangeZ=str2num(data.RangeZ);
153        end
154        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
155        if numel(data.RangeZ)>=2
156            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
157        end
158    end 
159    if ~isfield(data,'Angle')
160        data.Angle=[0 0 0];
161    end
162%     if isfield(data,'Angle') && isequal(numel(data.Angle),3)
163         set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
164         set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
165%         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
166%     end
167end
168set(get(handles.set_object,'children'),'enable','off')
169set(handles.SAVE,'enable','on')
170% set(handles.REFRESH,'enable','off')
171
172
173%------------------------------------------------------------------------
174% --- Outputs from this function are returned to the command line.
175function varargout = set_object_OutputFcn(hObject, eventdata, handles)
176%------------------------------------------------------------------------
177% Get default command line output from handles structure
178varargout{1} = handles.output;
179varargout{2}=handles;
180
181%------------------------------------------------------------------------
182% executed when closing the GUI set_object
183function closefcn(gcbo,eventdata)
184%------------------------------------------------------------------------
185huvmat=findobj(allchild(0),'Tag','uvmat');%find the current uvmat interface handle
186if ~isempty(huvmat)
187    hhuvmat=guidata(huvmat);
188    set(hhuvmat.CheckViewObject,'value',0)%
189    set(hhuvmat.CheckEditObject,'Value',0)% desactivate the edit option
190    % deselect the object in ListObject when view_field is closed
191    if isempty(findobj(allchild(0),'Tag','view_field'))
192        ObjIndex=get(hhuvmat.ListObject,'Value');
193        ObjIndex=ObjIndex(1);%keep only the first object selected
194        set(hhuvmat.ListObject,'Value',ObjIndex)
195        % draw all object colors in blue (unselected) in uvmat
196        hother=[findobj(hhuvmat.PlotAxes,'Tag','proj_object');findobj(hhuvmat.PlotAxes,'Tag','DeformPoint')];%find all the proj object and deform point representations
197        for iobj=1:length(hother)
198            if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
199                set(hother(iobj),'EdgeColor','b')
200                if isequal(get(hother(iobj),'FaceColor'),'m')
201                    set(hother(iobj),'FaceColor','b')
202                end
203            elseif isequal(get(hother(iobj),'Type'),'image')
204                Acolor=get(hother(iobj),'CData');
205                Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
206                set(hother(iobj),'CData',Acolor);
207            else
208                set(hother(iobj),'Color','b')
209            end
210            set(hother(iobj),'Selected','off')
211        end
212    end
213end
214hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
215if ~isempty(hseries)
216    hhseries=guidata(hseries);
217    set(hhseries.EditObject,'Value',0)
218end
219
220
221%------------------------------------------------------------------------
222% --- Executes on selection change in Type.
223function Type_Callback(hObject, eventdata, handles)
224%------------------------------------------------------------------------
225
226ListType=get(handles.Type,'String');
227Type=ListType{get(handles.Type,'Value')};
228% make correspondance between different object styles
229Coord=get(handles.Coord,'Data');
230
231%% set the number of lines in the Coord table depending on object type
232switch Type
233    case{'line'}
234        if size(Coord,1)<2
235            if isequal(size(Coord,2),3)
236                Coord=[Coord; 0 0 0];%add a line for edition (3D case)
237            else
238                Coord=[Coord; 0 0]; %add a line for edition (2D case)
239            end
240        else
241            Coord=Coord(1:2,:);
242        end
243    case{'rectangle','ellipse','plane','volume'}
244        Coord=Coord(1,:);
245end
246set(handles.Coord,'Data',Coord)
247
248%% set the projection menu and the corresponding options
249if isempty(get(handles.ProjMode,'UserData'))
250    switch Type
251        case 'polyline'
252            menu_proj={'interp_lin';'interp_tps';'none'};
253        case {'polygon','rectangle','ellipse'}
254            menu_proj={'inside';'outside';'mask_inside';'mask_outside';'interp_lin';'interp_tps';'none'};
255        case 'volume'
256            menu_proj={'interp_lin';'none'};
257        otherwise
258            menu_proj={'projection';'interp_lin';'interp_tps';'none'};%default
259    end
260else
261    menu_proj=get(handles.ProjMode,'UserData');
262end
263ProjModeList=get(handles.ProjMode,'String');
264menu_index=find(strcmp(ProjModeList{get(handles.ProjMode,'Value')},menu_proj));
265if isempty(menu_index)
266    menu_index=1;%
267end
268set(handles.ProjMode,'Value',menu_index);% value index must not exceed the menu length
269set(handles.ProjMode,'String',menu_proj)
270ProjMode_Callback(hObject, eventdata, handles)
271
272%------------------------------------------------------------------------
273% --- Executes on selection change in ProjMode.
274%------------------------------------------------------------------------
275function ProjMode_Callback(hObject, eventdata, handles)
276
277set(handles.REFRESH,'BackgroundColor',[1 0 1])
278menu=get(handles.ProjMode,'String');
279value=get(handles.ProjMode,'Value');
280ProjMode=menu{value};
281menu=get(handles.Type,'String');
282value=get(handles.Type,'Value');
283ObjectStyle=menu{value};
284%%%%%%%%% TODO
285test3D=strcmp(ObjectStyle,'plane_z'); %TODO: generalize
286%%%%%%%%%
287%default setting
288set(handles.num_Angle_1,'Visible','off')
289set(handles.num_Angle_2,'Visible','off')
290%set(handles.num_Angle_3,'Visible','off')
291set(handles.num_RangeX_1,'Visible','off')
292set(handles.num_RangeX_2,'Visible','off')
293set(handles.num_RangeY_1,'Visible','off')
294if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
295    set(handles.num_RangeY_2,'Visible','off')
296else
297    set(handles.num_RangeY_2,'Visible','on')
298end
299if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
300    set(handles.num_RangeX_2,'Visible','on')
301else
302   set(handles.num_RangeX_2,'Visible','off')
303end
304set(handles.num_RangeZ_1,'Visible','off')
305set(handles.num_RangeZ_2,'Visible','off')
306set(handles.num_DX,'Visible','off')
307set(handles.num_DY,'Visible','off')
308set(handles.num_DZ,'Visible','off')
309set(handles.num_RangeInterp,'Visible','off')
310
311switch ObjectStyle
312    case 'points'
313        set(handles.num_RangeY_2,'TooltipString','num_RangeY_2: range of projection around each point')
314%         set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
315%         set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
316%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
317    case {'line','polyline','polygon'}
318        set(handles.num_RangeY_2,'TooltipString','num_RangeY_2: range of projection around the line')
319         set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line')
320%         set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
321%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
322        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
323            set(handles.num_DX,'Visible','on')
324            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
325            set(handles.num_RangeInterp,'Visible','on')
326        end       
327    case {'rectangle','ellipse'}
328        set(handles.num_RangeX_2,'TooltipString',['num_RangeX_2: half length of the ' ObjectStyle])
329        set(handles.num_RangeY_2,'TooltipString',['num_RangeY_2: half width of the ' ObjectStyle])
330    case {'plane','plane_z'} 
331%        set(handles.num_Angle_3,'Visible','on')
332        set(handles.num_RangeX_1,'Visible','on')
333        set(handles.num_RangeX_2,'Visible','on')
334        set(handles.num_RangeY_1,'Visible','on')
335        set(handles.num_RangeY_2,'Visible','on')
336        set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane')
337        if test3D
338            set(handles.num_Angle_2,'Visible','on')
339            set(handles.num_Angle_1,'Visible','on')
340            set(handles.num_Angle_1,'String','90')
341            set(handles.Coord,'Data',[0 0 0])
342            set(handles.num_RangeZ_2,'Visible','on')
343        end
344        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
345            set(handles.num_DX,'Visible','on')
346            set(handles.num_DY,'Visible','on')
347            set(handles.num_RangeInterp,'Visible','on')
348        else
349            set(handles.num_DX,'Visible','off')
350            set(handles.num_DY,'Visible','off')
351        end
352%         if  isequal(ProjMode,'interp_lin')
353%             set(handles.num_DZ,'Visible','on') 
354%         end
355     case {'volume'} 
356        set(handles.num_RangeX_1,'Visible','on')
357        set(handles.num_RangeX_2,'Visible','on')
358        set(handles.num_RangeY_1,'Visible','on')
359        set(handles.num_RangeY_2,'Visible','on')
360        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
361        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
362        set(handles.num_Angle_1,'Visible','on')
363        set(handles.num_Angle_2,'Visible','on')
364        set(handles.num_Angle_3,'Visible','on')
365        set(handles.num_RangeZ_1,'Visible','on')
366        set(handles.num_RangeZ_2,'Visible','on')
367        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
368            set(handles.num_DX,'Visible','on')
369            set(handles.num_DY,'Visible','on')
370            set(handles.num_DZ,'Visible','on')
371        else
372            set(handles.num_DX,'Visible','off')
373            set(handles.num_DY,'Visible','off')
374            set(handles.num_DZ,'Visible','off')
375        end
376end
377% set default values read in the plot of uvmat to initiate the mesh
378if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
379            huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
380        UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
381    if isempty(str2num(get(handles.num_DX,'String')))||isempty(str2num(get(handles.num_DY,'String')));     
382%         Field=UvData.Field;
383        if  isfield(UvData.Field,'CoordMesh')&&~isempty(UvData.Field.CoordMesh)
384            set(handles.num_DX,'String',num2str(UvData.Field.CoordMesh))
385            set(handles.num_DY,'String',num2str(UvData.Field.CoordMesh))
386            set(handles.num_RangeX_1,'String',num2str(UvData.Field.XMin))
387            set(handles.num_RangeX_2,'String',num2str(UvData.Field.XMax))
388            set(handles.num_RangeY_1,'String',num2str(UvData.Field.YMin))
389            set(handles.num_RangeY_2,'String',num2str(UvData.Field.YMax))
390        end
391        if isempty(get(handles.CoordUnit,'String'))&& isfield(UvData.Field,'CoordUnit')
392            set(handles.CoordUnit,'String',UvData.Field.CoordUnit)
393        end       
394    end
395    if isempty(str2num(get(handles.num_RangeInterp,'String'))) && isfield(UvData,'Field')
396     set(handles.num_RangeInterp,'String',num2str(3*UvData.Field.CoordMesh))% default interpolationlength= 3 meshes
397    end
398end
399
400%------------------------------------------------------------------------
401
402%------------------------------------------------------------------------
403function num_Angle_1_Callback(hObject, eventdata, handles)
404update_slider(hObject, eventdata,handles)
405%------------------------------------------------------------------------
406%------------------------------------------------------------------------
407function num_Angle_2_Callback(hObject, eventdata, handles)
408update_slider(hObject, eventdata,handles)
409%------------------------------------------------------------------------
410function update_slider(hObject, eventdata,handles)
411%rotation angles
412PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first  angle in degrees
413PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second  angle in degrees
414PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second  angle in degrees
415om=norm(PlaneAngle);%norm of rotation angle in radians
416OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
417cos_om=cos(pi*om/180);
418sin_om=sin(pi*om/180);
419coeff=OmAxis(3)*(1-cos_om);
420%components of the unity vector norm_plane normal to the projection plane
421norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
422norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
423norm_plane(3)=OmAxis(3)*coeff+cos_om;
424huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
425UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
426if isfield(UvData,'X') && isfield(UvData,'Y') && isfield(UvData,'Z')
427    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
428    set(handles.z_slider,'Min',min(Z))
429    set(handles.z_slider,'Max',max(Z))
430    ZMax_Callback(hObject, eventdata, handles)
431end
432%------------------------------------------------------------------------
433function num_DX_Callback(hObject, eventdata, handles)
434%------------------------------------------------------------------------
435%------------------------------------------------------------------------
436function num_DY_Callback(hObject, eventdata, handles)
437%------------------------------------------------------------------------
438%------------------------------------------------------------------------
439function num_DZ_Callback(hObject, eventdata, handles)
440%------------------------------------------------------------------------
441
442
443%------------------------------------------------------------------------
444% --- Executes on button press in REFRESH: refresh the current object , refresh the object and its projected field
445%------------------------------------------------------------------------
446function REFRESH_Callback(hObject, eventdata, handles)
447
448set(handles.REFRESH,'BackgroundColor',[1 1 0])% indicate activation of REFRESH
449drawnow
450
451%% update the object in the GUI series if relevant
452if strcmp(get(handles.set_object,'Name'),'edit_object_series')
453    hseries=findobj(allchild(0),'Tag','series');
454    if ~isempty(hseries)
455        SeriesData=get(hseries,'UserData');
456    SeriesData.ProjObject=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
457    set(hseries,'UserData',SeriesData);
458    end
459    set(handles.REFRESH,'BackgroundColor',[1 0 0])
460    return
461end
462
463%% read the object parameters in the GUI set_object
464ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
465if isfield(ObjectData,'CoordLine')% remove CoordLine (not used as object feature)
466    ObjectData=rmfield(ObjectData,'CoordLine');
467end
468if iscell(ObjectData.Coord)%check for empty line
469    ObjectData.Coord=[0 0 0];
470    hhset_object=guidata(handles.set_object);
471    set(hhset_object.Coord,'Data',ObjectData.Coord)
472end
473checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines
474if ~isempty(checknan)
475    ObjectData.Coord(checknan,:)=[];%remove the NaN lines
476end
477ObjectName=ObjectData.Name;%name of the current object defined in set_object
478if isempty(ObjectName)
479     ObjectName=ObjectData.Type;% name the object by the object type type by default
480end
481
482%% read the current object selection in the GUI uvmat
483huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle
484UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
485hhuvmat=guidata(huvmat);%handles of the objects children of the  GUI uvmat
486ListObject=get(hhuvmat.ListObject,'String');% list of objects displayed in uvmat
487
488if isequal(get(hhuvmat.CheckEditObject,'Value'),0) %we append a new object
489    ListObject=[ListObject;{''}];
490    IndexObj=length(ListObject);
491    set(hhuvmat.ListObject,'String',ListObject)
492    set(hhuvmat.ListObject,'Value',IndexObj)
493    UvData.ProjObject{IndexObj}=[]; %create a new empty object
494    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
495    UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
496else   
497    IndexObj=get(hhuvmat.ListObject,'Value');% index of the selected object for display in uvmat
498end
499
500%set or modify(edit mode) the name of the currently selected object
501detectname=1;
502ObjectNameNew=ObjectName;
503vers=0;% index of the name
504ListOther=ListObject;
505ListOther(IndexObj)=[];
506while ~isempty(detectname)
507    detectname=find(strcmp(ObjectNameNew,ListOther),1);%test the existence of the proposed name in the list
508    if detectname% if the object name already exists
509        indstr=regexp(ObjectNameNew,'\D');%indices of non number characters
510        if indstr(end)<length(ObjectNameNew) %object name ends by a number
511            vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
512            ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
513        else
514            vers=vers+1;
515            ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
516        end
517    end
518end
519ObjectName=ObjectNameNew;
520set(handles.Name,'String',ObjectName)% display the default name in set_object
521ListObject{IndexObj}=ObjectName;
522set(hhuvmat.ListObject,'String',ListObject);%complement the object list
523set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
524set(hhuvmat.CheckViewObject,'Value',1)% indicate that the currently selected objected is viewed on set_object
525check_handle=isfield(UvData.ProjObject{IndexObj},'DisplayHandle') && isfield(UvData.ProjObject{IndexObj}.DisplayHandle,'uvmat')...
526    && ~isempty(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat) && ishandle(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat);
527if check_handle
528    obj_handle=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
529end
530UvData.ProjObject{IndexObj}=ObjectData;%record the current object properties in uvmat
531if check_handle
532    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=obj_handle; %preserve the object plot handle if valid
533else
534    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; %axes taken as object display handle by defualt
535end
536
537%% refresh the field projected on the object
538hview_field=[];%default
539IndexObj_1=get(hhuvmat.ListObject_1,'Value');
540if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none')
541    PlotType='text';
542else
543    % create tps coeff if needed for ProjMode 'interp_tps'
544    if strcmp(ObjectData.ProjMode,'interp_tps')&&~isfield(UvData.Field,'Coord_tps')
545        %UvData.Field=calc_tps(UvData.Field,1);
546        [UvData.Field,errormsg]=tps_coeff_field(UvData.Field,1);
547        if ~isempty(errormsg)
548            msgbox_uvmat('ERROR', ['set_object/tps_coeff_field/' errormsg])
549            set(handles.REFRESH,'enable','on')
550            return
551        end
552    end
553    [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
554    if ~isempty(errormsg)
555        msgbox_uvmat('ERROR', ['set_object/proj_field/' errormsg])
556        set(handles.REFRESH,'enable','on')
557        return
558    end
559    if isequal(IndexObj_1,IndexObj) % if  the projection is in uvmat
560        PlotType=plot_field(ProjData,hhuvmat.PlotAxes,read_GUI(get(hhuvmat.PlotAxes,'parent')));%update the current uvmat plot
561    else  % if the projection is in view_field
562        hview_field=findobj(allchild(0),'tag','view_field');
563        if isempty(hview_field)
564            hview_field=view_field(ProjData); %open the view_field GUI for plot
565        else
566            hhview_field=guidata(hview_field);
567            [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%update an existing  plot in view_field
568            errormsg=fill_GUI(PlotParam,hview_field);
569            if ~isempty(errormsg)
570                msgbox_uvmat('ERROR',errormsg)
571                return
572            end
573            %     write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
574        end
575        haxes=findobj(hview_field,'tag','axes3');
576        Data=get(hview_field,'UserData');
577        if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
578            h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
579            pos_table=get(h_TableDisplay,'Position');
580            pos=get(hview_field,'Position');
581            set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
582            drawnow
583            set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing
584        else
585            set(hview_field,'Position',Data.GUISize)
586        end
587    end
588end
589
590%% update the object refresh
591hobject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
592% if we are editing the object used for projection in uvmat
593if isequal(IndexObj_1,IndexObj)
594    %update the representation of the current object for projection field represented in view_field
595    for iobj=1:numel(UvData.ProjObject)
596        UvData.ProjObject{iobj}.DisplayHandle.uvmat=...
597            plot_object(UvData.ProjObject{iobj},UvData.ProjObject{IndexObj_1},UvData.ProjObject{iobj}.DisplayHandle.uvmat,'b');
598    end
599else %  we are editing the object used for projection field represented in view_field
600    %update the representation of the current object in uvmat
601    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=...
602             plot_object(UvData.ProjObject{IndexObj},UvData.ProjObject{IndexObj_1},UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'m');
603    %indicate the object index in the user data of the object refresh (needed for further mouse editing)
604    ObjectInfo=get(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'UserData');
605    ObjectInfo.IndexObj=IndexObj;
606    set(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'UserData',ObjectInfo)
607    % update the representation of all objects in view_field
608    for iobj=1:numel(UvData.ProjObject)
609        if isfield(UvData.ProjObject{iobj},'DisplayHandle') && isfield(UvData.ProjObject{iobj}.DisplayHandle,'view_field')
610            UvData.ProjObject{iobj}.DisplayHandle.view_field=...
611                plot_object(UvData.ProjObject{iobj},UvData.ProjObject{iobj},UvData.ProjObject{iobj}.DisplayHandle.view_field,'b');
612        end
613    end
614end
615set(huvmat,'UserData',UvData)
616
617%% update the GUI uvmat
618set(hhuvmat.CheckEditObject,'Value',1) % set uvmat to object edit mode to allow further object update
619set(hhuvmat.CheckViewField,'Value',1)
620
621set(handles.REFRESH,'BackgroundColor',[1 0 0])
622set(handles.num_RangeY_2,'BackgroundColor',[1 1 1])
623
624% --- Executes on button press in DisplayCoord.
625function DisplayCoord_Callback(hObject, eventdata, handles)
626global Coord
627Coord=get(handles.Coord,'Data');
628evalin('base','global Coord')%make Coord global in the workspace
629display('object coordinates:')
630evalin('base','Coord') %display Coord in the workspace
631commandwindow; %brings the Matlab command window to the front
632
633%----------------------------------------------------
634function num_RangeY_1_Callback(hObject, eventdata, handles)
635%------------------------------------------------------------------------
636
637function num_RangeZ_1_Callback(hObject, eventdata, handles)
638%------------------------------------------------------------------------
639
640function num_RangeZ_2_Callback(hObject, eventdata, handles)
641DZ=str2num(get(handles.num_RangeZ_2,'String'));
642ZMin=get(handles.z_slider,'Min');
643ZMax=get(handles.z_slider,'Max');
644if ~isequal(ZMax-ZMin,0)
645    rel_step(1)=DZ/(ZMax-ZMin);
646    rel_step(2)=0.2;
647    set(handles.z_slider,'SliderStep',rel_step)
648end
649%------------------------------------------------------------------------
650function num_RangeY_2_Callback(hObject, eventdata, handles)
651%------------------------------------------------------------------------
652
653function num_RangeX_1_Callback(hObject, eventdata, handles)
654%------------------------------------------------------------------------
655
656function num_RangeX_2_Callback(hObject, eventdata, handles)
657
658%------------------------------------------------------------------------
659%------------------------------------------------------------------------
660function SAVE_Callback(hObject, eventdata, handles)
661% ------------------------------------------------------
662Object=read_GUI(handles.set_object);
663if isfield(Object,'CoordLine')% remove CoordLine (not used as object feature)
664    Object=rmfield(Object,'CoordLine');
665end
666huvmat=findobj('Tag','uvmat');
667if isempty(huvmat)
668    huvmat=findobj(allchild(0),'Name','series');
669end
670hchild=get(huvmat,'Children');
671hrootpath=findobj(hchild,'Tag','RootPath');
672if isempty(hrootpath)
673    RootPath='';
674else
675    RootPath=get(hrootpath,'String');
676    if iscell(RootPath)
677        RootPath=RootPath{1};
678    end
679end
680title={'object name'};
681dir_save=uigetfile_uvmat('select the folder for the new xml object file:',RootPath,'uigetdir');
682if ~isempty(dir_save)
683    ObjectName=get(handles.Name,'String');
684    if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
685        def=[ObjectName '.xml'];
686    else
687        def=[Object.Style '.xml'];
688    end
689    displ_txt={['save object in' dir_save]; 'with file name (.xml):'};%default display
690    menu=get(handles.ProjMode,'String');
691    value=get(handles.ProjMode,'Value');
692    ProjMode=menu{value};
693    if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
694        displ_txt=[displ_txt; '(note: to create a mask image, use ''Tools/make mask'' on the upper bar menu of uvmat)'];
695    end
696    answer=msgbox_uvmat('INPUT_TXT',displ_txt,def);
697    if ischar(answer)
698        FullName=fullfile(dir_save,answer);
699        t=struct2xml(Object);
700        t=set(t,1,'name','ProjObject');
701        try
702            save(t,FullName)
703            msgbox_uvmat('CONFIRMATION',[FullName  ' saved'])
704        catch ME
705            msgbox_uvmat('ERROR',ME.message)
706        end
707    end
708end
709
710%------------------------------------------------------------------------
711% --- Executes on slider movement.
712function z_slider_Callback(hObject, eventdata, handles)
713%---------------------------------------------------------
714Z_value=get(handles.z_slider,'Value');
715%rotation angles
716PlaneAngle=[0 0 0];
717norm_plane=[0 0 1];
718cos_om=1;
719sin_om=0;
720
721PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
722PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
723PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
724PlaneAngle=(pi/180)*PlaneAngle;
725om=norm(PlaneAngle);%norm of rotation angle in radians
726if isequal(om,0)
727    norm_plane=[0 0 1];
728else
729    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
730    cos_om=cos(om);
731    sin_om=sin(om);
732    coeff=OmAxis(3)*(1-cos_om);
733    %components of the unity vector norm_plane normal to the projection plane
734    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
735    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
736    norm_plane(3)=OmAxis(3)*coeff+cos_om;
737end
738Coord=get(handles.Coord,'Data');
739Coord(3)=Z_value;
740set(handles.Coord,'Data',Coord)
741
742% update graph
743REFRESH_Callback(hObject, eventdata, handles)
744
745%------------------------------------------------------------------------
746% --- Executes on button press in HELP.
747function HELP_Callback(hObject, eventdata, handles)
748%------------------------------------------------------------------------
749web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#ProjObject')
750
751%------------------------------------------------------------------------
752% --- Executes when selected cell(s) is changed in ListCoord.
753%------------------------------------------------------------------------
754function Coord_CellSelectionCallback(hObject, eventdata, handles)
755if ~isempty(eventdata.Indices)
756    iline=eventdata.Indices(1);% selected line number
757    set(handles.CoordLine,'String',num2str(iline))
758end
759
760
761function num_Angle_3_Callback(hObject, eventdata, handles)
762
763%------------------------------------------------------------------------
764% --- Executes on key press with selection of a uicontrol
765%------------------------------------------------------------------------
766function KeyPressFcn(hObject, eventdata, handles)
767set(handles.REFRESH,'BackgroundColor',[1 0 1])% se REFRESH to magenta color, indicates that refresh needs to be done
768if strcmp(get(hObject,'Tag'),'num_Angle_3')
769    set(handles.num_RangeX_1,'String','')
770    set(handles.num_RangeX_2,'String','')
771        set(handles.num_RangeY_1,'String','')
772    set(handles.num_RangeY_2,'String','')
773end
774
775%------------------------------------------------------------------------
776% --- Executes on key press with focus on Coord and none of its controls.
777%------------------------------------------------------------------------
778function Coord_KeyPressFcn(hObject, eventdata, handles)
779
780set(handles.REFRESH,'BackgroundColor',[1 0 1])
781xx=double(get(handles.set_object,'CurrentCharacter')); %get the keyboard character
782if ismember(xx,[127 31])% delete, or downward
783    Coord=get(handles.Coord,'Data');
784    iline=str2double(get(handles.CoordLine,'String'));
785            if isequal(xx, 31)
786                if isequal(iline,size(Coord,1))% arrow downward
787                Coord=[Coord;zeros(1,size(Coord,2))];
788                end
789            else
790    Coord(iline,:)=[];% suppress the current line
791            end
792    set(handles.Coord,'Data',Coord);
793end
794
795%------------------------------------------------------------------------
796% --- Executes on button press in clear_line.
797%------------------------------------------------------------------------
798function clear_line_Callback(hObject, eventdata, handles)
799
800Coord=get(handles.Coord,'Data');
801iline=str2double(get(handles.CoordLine,'String'));
802if isempty(iline)
803    msgbox_uvmat('WARNING','no line suppressed, select a line in the table')
804else
805    Coord(iline,:)=[];
806    set(handles.REFRESH,'BackgroundColor',[1 0 1])
807    set(handles.Coord,'Data',Coord);
808    set(handles.CoordLine,'String','')
809    REFRESH_Callback(hObject,eventdata,handles)
810end
811
812
813
814function num_RangeInterp_Callback(hObject, eventdata, handles)
Note: See TracBrowser for help on using the repository browser.