source: trunk/src/set_object.m @ 153

Last change on this file since 153 was 153, checked in by sommeria, 13 years ago

civ.m: bug on field numbers repaired
other: various cleaning and bug repair for the creation of a new object

File size: 33.4 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:
10% data: structure describing the object properties
11%    .Style=...
12%    .ProjMode
13%    .CoordType: 'phys' or 'px'
14%    .DX,.DY,.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%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
21%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
22%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
23%     This file is part of the toolbox UVMAT.
24%
25%     UVMAT is free software; you can redistribute it and/or modify
26%     it under the terms of the GNU General Public License as published by
27%     the Free Software Foundation; either version 2 of the License, or
28%     (at your option) any later version.
29%
30%     UVMAT is distributed in the hope that it will be useful,
31%     but WITHOUT ANY WARRANTY; without even the implied warranty of
32%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
34%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
35
36function varargout = set_object(varargin)
37
38% Last Modified by GUIDE v2.5 24-Nov-2008 14:29:06
39
40% Begin initialization code - DO NOT PLOT
41gui_Singleton = 1;
42gui_State = struct('gui_Name',       mfilename, ...
43                   'gui_Singleton',  gui_Singleton, ...
44                   'gui_OpeningFcn', @set_object_OpeningFcn, ...
45                   'gui_OutputFcn',  @set_object_OutputFcn, ...
46                   'gui_LayoutFcn',  [] , ...
47                   'gui_Callback',   []);
48if nargin & isstr(varargin{1})
49    gui_State.gui_Callback = str2func(varargin{1});
50end
51
52if nargout
53    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
54else
55    gui_mainfcn(gui_State, varargin{:});
56end
57% End initialization code - DO NOT PLOT
58%------------------------------------------------------------------------
59%------------------------------------------------------------------------
60% --- Executes just before set_object is made visible.
61%INPUT:
62% handles: handles of the set_object interface elements
63%'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify
64%        if =[] or absent: index still undefined (create mode in uvmat)
65%        if=0; no associated object (used for series), the button 'PLOT' is  then unvisible
66%'data': read from an existing object selected in the interface
67%      .TITLE : class of object ('POINTS','LINE',....)
68%      .DX,DY,DZ; meshes for regular grids
69%      .Coord: object position coordinates
70%      .ParentButton: handle of the uicontrol object calling the interface
71% PlotHandles: set of handles of the elements contolling the plotting of the projected field:
72%  if =[] or absent, no plot (mask mode in uvmat)
73% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
74function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds)
75%-------------------------------------------------------------------
76% Choose default command line output for set_object
77handles.output = hObject;
78% Update handles structure
79guidata(hObject, handles);
80
81%default
82if ~exist('ZBound','var')
83    ZBound=0; %default
84end
85set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front)
86set(handles.MenuCoord,'ListboxTop',1)
87% if ~exist('PlotHandles','var')
88%      PlotHandles=[];
89% end
90enable_plot=0;%default: does not allow plot of object and projection
91% SetData.PlotHandles=PlotHandles;
92% set(hObject,'UserData',SetData)
93
94% fill the interface as set in the input data:
95if exist('data','var')
96    if isfield(data,'enable_plot')
97        enable_plot=data.enable_plot;%test to desable button PLOT (display mode)
98    end
99    if isfield(data,'Name')
100        set(handles.TITLE,'String',data.Name)
101%         set(hObject,'name',data.Name)
102    end
103    if ~isfield(data,'NbDim')||~isequal(data.NbDim,3)%2D case
104        set(handles.ZObject,'Visible','off')
105        set(handles.z_slider,'Visible','off')
106    else
107        set(handles.ZObject,'Visible','on')
108        set(handles.z_slider,'Visible','on')
109        if isfield(data,'Coord') && size(data.Coord,2)==3
110            set(handles.ZObject,'String',num2str(data.Coord(1,3),4))
111        end
112    end
113    if isfield(data,'StyleMenu')
114        set(handles.ObjectStyle,'String',data.StyleMenu);
115    end
116    if isfield(data,'Style')
117        menu=get(handles.ObjectStyle,'String');
118        for iline=1:length(menu)
119            if isequal(menu{iline},data.Style)
120                set(handles.ObjectStyle,'Value',iline)
121                break
122            end
123        end
124    end
125    ObjectStyle_Callback(hObject, eventdata, handles)
126    if isfield(data,'ProjMenu')
127        set(handles.ProjMode,'String',data.ProjMenu);
128    end
129    if isfield(data,'ProjMode')
130        menu=get(handles.ProjMode,'String');
131        for iline=1:length(menu)
132            if isequal(menu{iline},data.ProjMode)
133                set(handles.ProjMode,'Value',iline)
134                break
135            end
136        end
137    end
138    ProjMode_Callback(hObject, eventdata, handles)
139    if isfield(data,'Coord')
140        if ischar(data.Coord)
141            data.Coord=str2num(data.Coord);
142        elseif iscell(data.Coord)
143            CoordCell=data.Coord;
144            data.Coord=zeros(numel(CoordCell),3);
145            data.Coord(:,3)=zeros(numel(CoordCell),1); % z component set to 0 by default
146            for iline=1:numel(CoordCell)
147                line_vec=str2num(CoordCell{iline});
148                if numel(line_vec)==2
149                    data.Coord(iline,1:2)=str2num(CoordCell{iline});
150                else
151                    data.Coord(iline,:)=str2num(CoordCell{iline});
152                end
153            end
154        end
155        if size(data.Coord,2)>=2
156            sizcoord=size(data.Coord);
157            for i=1:sizcoord(1)
158                XObject{i}=num2str(data.Coord(i,1),4);
159                YObject{i}=num2str(data.Coord(i,2),4);
160            end
161            set(handles.XObject,'String',XObject)
162            set(handles.YObject,'String',YObject)
163            if sizcoord(2)>3
164                for i=1:sizcoord(1)
165                    ZObject{i}=num2str(data.Coord(i,3),4);
166                end
167                set(handles.ZObject,'String',ZObject)
168            end
169        end
170    end
171    if isfield(data,'DX')
172        if ~ischar(handles.DX)
173            data.DX=num2str(data.DX,3);
174        end
175        set(handles.DX,'String',data.DX)
176    end
177    if isfield(data,'DY')
178        if ~ischar(handles.DY)
179            data.DY=num2str(data.DY,3);
180        end
181        set(handles.DY,'String',data.DX)
182    end
183    if isfield(data,'RangeZ') && length(ZBounds) >= 2
184        set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
185        DZ=max(data.RangeZ);%slider step
186        if ZBounds(2)~=ZBounds(1)
187            rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
188            rel_step(2)=0.1;
189            set(handles.z_slider,'Visible','on')
190            set(handles.z_slider,'Min',ZBounds(1))
191            set(handles.z_slider,'Max',ZBounds(2))
192            set(handles.z_slider,'SliderStep',rel_step)
193            set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
194        end
195    end
196    if isfield(data,'RangeX')
197        if ischar(data.RangeX)
198            data.RangeX=str2num(data.RangeX);
199        end
200        set(handles.XMax,'String',num2str(max(data.RangeX),3))
201        set(handles.XMin,'String',num2str(min(data.RangeX),3))
202    end
203    if isfield(data,'RangeY')
204        if ischar(data.RangeY)
205            data.RangeY=str2num(data.RangeY);
206        end
207        set(handles.YMax,'String',num2str(max(data.RangeY),3))
208        set(handles.YMin,'String',num2str(min(data.RangeY),3))
209    end
210    if isfield(data,'RangeZ')
211        if ischar(data.RangeZ)
212            data.RangeZ=str2num(data.RangeZ);
213        end
214        set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
215        if numel(data.RangeZ)>=2
216            set(handles.ZMin,'String',num2str(min(data.RangeZ),3))
217        end
218    end 
219    if isfield(data,'Phi')
220        if ~ischar(handles.Phi)
221            data.DY=num2str(data.Phi,3);
222        end
223         set(handles.Phi,'String',data.Phi)
224    end
225    if isfield(data,'Theta')
226        if ~ischar(handles.Theta)
227            data.DY=num2str(data.Theta,3);
228        end
229        set(handles.Theta,'String',data.Theta)
230    end
231    if isfield(data,'Psi')
232         if ~ischar(handles.Psi)
233            data.DY=num2str(data.Psi,3);
234        end
235         set(handles.Psi,'String',data.Psi)
236    end 
237    if isfield(data,'DZ')
238        if ~ischar(handles.DZ)
239            data.DY=num2str(data.DZ,3);
240        end
241        set(handles.DZ,'String',data.DZ)
242    end
243    if isfield(data,'CoordType')&& isequal(data.CoordType,'px')
244%         if isequal(data.CoordType,'phys')
245%             set(handles.MenuCoord,'Value',1)
246%         elseif isequal(data.CoordType,'px')
247             set(handles.MenuCoord,'Value',2)
248%         end
249    end
250end
251if enable_plot
252   set(handles.PLOT,'enable','on')
253else
254   set(handles.PLOT,'enable','off')
255end
256huvmat=findobj(allchild(0),'tag','uvmat');
257UvData=get(huvmat,'UserData');
258pos_uvmat=get(huvmat,'Position');
259%position the set_object GUI with respect to uvmat
260if isfield(UvData,'SetObjectOrigin')
261    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
262    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
263    set(hObject,'Position',pos_set_object)
264end
265
266% --- Outputs from this function are returned to the command line.
267function varargout = set_object_OutputFcn(hObject, eventdata, handles)
268% varargout  cell array for returning output args (see VARARGOUT);
269% hObject    handle to figure
270% eventdata  reserved - to be defined in a future version of MATLAB
271% handles    structure with handles and user data (see GUIDATA)
272
273% Get default command line output from handles structure
274varargout{1} = handles.output;
275varargout{2}=handles;
276
277%------------------------------------------------------------------------
278% --- Executes on selection change in ObjectStyle.
279function ObjectStyle_Callback(hObject, eventdata, handles)
280style_prev=get(handles.ObjectStyle,'UserData');%previous object style
281str=get(handles.ObjectStyle,'String');
282val=get(handles.ObjectStyle,'Value');
283style=str{val};
284% make correspondance between different object styles
285% if ~isequal(str{val},style_prev)
286Xcolumn=get(handles.XObject,'String');
287Ycolumn=get(handles.YObject,'String');
288if ischar(Xcolumn)
289    sizchar=size(Xcolumn);
290    for icol=1:sizchar(1)
291        Xcolumn_cell{icol}=Xcolumn(icol,:);
292    end
293    Xcolumn=Xcolumn_cell;
294end
295if ischar(Ycolumn)
296    sizchar=size(Ycolumn);
297    for icol=1:sizchar(1)
298        Ycolumn_cell{icol}=Ycolumn(icol,:);
299    end
300    Ycolumn=Ycolumn_cell;
301end
302Zcolumn={};%default
303z_new={};
304if isequal(get(handles.ZObject,'Visible'),'on')
305    data.NbDim=3; %test 3D object
306    Zcolumn=get(handles.ZObject,'String');
307    if ischar(Zcolumn)
308        Zcolumn={Zcolumn};
309    end
310end
311x_new{1}=Xcolumn{1};
312y_new{1}=Ycolumn{1};
313if ~isempty(Zcolumn)
314    z_new{1}=Zcolumn{1};
315end
316if isequal(style,'line')
317    if isequal(style_prev,'rectangle')|isequal(style_prev,'ellipse')
318        XMax=get(handles.XMax,'String');
319        YMax=get(handles.YMax,'String');
320        x_new{2}=num2str(XMax,4);
321        y_new{2}=num2str(YMax,4);
322        set(handles.XObject,'String',x_new)
323        set(handles.YObject,'String',y_new)
324        set(handles.ZObject,'String',z_new)
325    end
326elseif isequal(style,'polyline')
327elseif isequal(style,'rectangle')| isequal(style,'ellipse')
328     set(handles.XObject,'String',x_new)
329     set(handles.YObject,'String',y_new)
330     set(handles.ZObject,'String',z_new)
331end
332% end
333switch style
334    case {'points','line','polyline','plane'}
335        menu_proj={'projection';'interp';'filter';'none'};
336    case {'polygon','rectangle','ellipse'}
337        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
338    case 'volume'
339        menu_proj={'interp';'none'};
340end   
341proj_index=get(handles.ProjMode,'Value');
342if proj_index<numel(menu_proj)
343    set(handles.ProjMode,'Value',1);% value index must not exceed the menu length
344end
345set(handles.ProjMode,'String',menu_proj)
346ProjMode_Callback(hObject, eventdata, handles)
347%store the current option
348str=get(handles.ObjectStyle,'String');
349val=get(handles.ObjectStyle,'Value');
350set(handles.ObjectStyle,'UserData',style)
351
352%------------------------------------------------------------------------
353function xObject_Callback(hObject, eventdata, handles)
354
355%------------------------------------------------------------------------
356function yObject_Callback(hObject, eventdata, handles)
357
358%------------------------------------------------------------------------
359% --- Executes on selection change in zObject.
360function zObject_Callback(hObject, eventdata, handles)
361%------------------------------------------------------------------------
362
363%------------------------------------------------------------------------
364% --- Executes on selection change in ProjMode.
365function ProjMode_Callback(hObject, eventdata, handles)
366menu=get(handles.ProjMode,'String');
367value=get(handles.ProjMode,'Value');
368ProjMode=menu{value};
369menu=get(handles.ObjectStyle,'String');
370value=get(handles.ObjectStyle,'Value');
371ObjectStyle=menu{value};
372test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
373
374%default setting
375set(handles.Phi,'Visible','off')
376set(handles.Theta,'Visible','off')
377set(handles.Psi,'Visible','off')
378set(handles.XMin,'Visible','off')
379set(handles.XMax,'Visible','off')
380set(handles.YMin,'Visible','off')
381if isequal(ProjMode,'interp')
382    set(handles.YMax,'Visible','off')
383else
384    set(handles.YMax,'Visible','on')
385end
386if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse')
387    set(handles.XMax,'Visible','on')
388else
389   set(handles.XMax,'Visible','off')
390end
391set(handles.ZMin,'Visible','off')
392set(handles.ZMax,'Visible','off')
393set(handles.DX,'Visible','off')
394set(handles.DY,'Visible','off')
395set(handles.DZ,'Visible','off')
396
397switch ObjectStyle
398    case 'points'
399        set(handles.YMax,'TooltipString','YMax: range of averaging around each point')
400        set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
401        set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
402        set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
403    case {'line','polyline','polygon'}
404        set(handles.YMax,'TooltipString','YMax: range of averaging around the line')
405        set(handles.XObject,'TooltipString','XObject: set of x coordinates defining the line')
406        set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
407        set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
408        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
409            set(handles.DX,'Visible','on')
410            set(handles.DX,'TooltipString','DX: mesh for the interpolated field along the line')
411        end       
412    case {'rectangle','ellipse'}
413        set(handles.XMax,'TooltipString',['XMax: half length of the ' ObjectStyle])
414        set(handles.YMax,'TooltipString',['YMax: half width of the ' ObjectStyle])
415        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' ObjectStyle ' centre'])
416        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' ObjectStyle ' centre'])
417    case {'plane'} 
418        set(handles.Phi,'Visible','on')
419        set(handles.XMin,'Visible','on')
420        set(handles.XMax,'Visible','on')
421        set(handles.YMin,'Visible','on')
422        set(handles.YMax,'Visible','on')
423        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
424        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
425        set(handles.ZMax,'TooltipString',['ZMax: range of projection normal to the plane'])
426        if test3D
427            set(handles.Theta,'Visible','on')
428            set(handles.Psi,'Visible','on')
429            set(handles.ZMax,'Visible','on')
430        end
431        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
432            set(handles.DX,'Visible','on')
433            set(handles.DY,'Visible','on')
434        else
435            set(handles.DX,'Visible','off')
436            set(handles.DY,'Visible','off')
437        end
438        if isequal(ObjectStyle,'volume') && isequal(ProjMode,'interp')
439            set(handles.DZ,'Visible','on') 
440        end
441     case {'volume'} 
442        set(handles.Phi,'Visible','on')
443        set(handles.XMin,'Visible','on')
444        set(handles.XMax,'Visible','on')
445        set(handles.YMin,'Visible','on')
446        set(handles.YMax,'Visible','on')
447        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
448        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
449        if test3D
450            set(handles.Theta,'Visible','on')
451            set(handles.Psi,'Visible','on')
452            set(handles.ZMin,'Visible','on')
453            set(handles.ZMax,'Visible','on')
454        end
455        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
456            set(handles.DX,'Visible','on')
457            set(handles.DY,'Visible','on')
458        else
459            set(handles.DX,'Visible','off')
460            set(handles.DY,'Visible','off')
461        end
462        if isequal(ObjectStyle,'volume') && isequal(ProjMode,'interp')
463            set(handles.DZ,'Visible','on') 
464        end
465end
466%------------------------------------------------------------------------
467
468%------------------------------------------------------------------------
469function Phi_Callback(hObject, eventdata, handles)
470update_slider(hObject, eventdata,handles)
471%------------------------------------------------------------------------
472%------------------------------------------------------------------------
473function Theta_Callback(hObject, eventdata, handles)
474update_slider(hObject, eventdata,handles)
475%------------------------------------------------------------------------
476function update_slider(hObject, eventdata,handles)
477%rotation angles
478Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
479Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
480
481%components of the unitiy vector normal to the projection plane
482NormVec_X=-sin(Phi)*sin(Theta);
483NormVec_Y=cos(Phi)*sin(Theta);
484NormVec_Z=cos(Theta);
485huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
486UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
487if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
488    Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
489    set(handles.z_slider,'Min',min(Z))
490    set(handles.z_slider,'Max',max(Z))
491    ZMax_Callback(hObject, eventdata, handles)
492end
493%------------------------------------------------------------------------
494function DX_Callback(hObject, eventdata, handles)
495%------------------------------------------------------------------------
496%------------------------------------------------------------------------
497function DY_Callback(hObject, eventdata, handles)
498%------------------------------------------------------------------------
499%------------------------------------------------------------------------
500function DZ_Callback(hObject, eventdata, handles)
501%------------------------------------------------------------------------
502
503%------------------------------------------------------------------------
504%-----------------------------------------------------
505% --- Executes on button press in OPEN: DESACTIVATED use uvmat browser
506function OPEN_Callback(hObject, eventdata, handles)
507%get the object file
508oldfile=' ';
509huvmat=findobj('Tag','uvmat');
510hchild=get(huvmat,'Children');
511hrootpath=findobj(hchild,'Tag','RootPath');
512if ~isempty(hrootpath)
513    oldfile=get(hrootpath,'String');
514    if iscell(oldfile)
515        oldfile=oldfile{1};
516    end
517end
518[FileName, PathName, filterindex] = uigetfile( ...
519       {'*.xml;*.mat', ' (*.xml,*.mat)';
520       '*.xml',  '.xml files '; ...
521        '*.mat',  '.mat matlab files '}, ...
522        'Pick a file',oldfile);
523fileinput=[PathName FileName];%complete file name
524testblank=findstr(fileinput,' ');%look for blanks
525if ~isempty(testblank)
526    msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
527    return
528end
529sizf=size(fileinput);
530if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
531
532%read the file
533 t=xmltree(fileinput);
534 s=convert(t);
535 if ~isfield(s,'Style')
536     s.Style='points';
537 end
538 if ~isfield(s,'ProjMode')
539     s.ProjMode='none';
540 end
541%Display title
542% title=set_title(s.Style,s.ProjMode);%update the title
543% if ~isempty(huvmat)
544%     hhuvmat=guidata(huvmat);
545% end
546% menu=get(handles.TITLE,'String');
547% for iline=1:length(menu)
548%      if isequal(menu{iline},title)
549%          set(handles.TITLE,'Value',iline)
550%          break
551%      end
552% end
553%TITLE_Callback(hObject, eventdata, handles)
554teststyle=0;
555
556switch s.Style
557    case {'points','line','polyline','plane'}
558        menu_proj={'projection';'interp';'filter';'none'};
559    case {'polygon','rectangle','ellipse'}
560        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
561    case 'volume'
562        menu_proj={'none'};
563end
564set(handles.ObjectStyle,'String',menu_proj)
565menu=get(handles.ObjectStyle,'String');
566for iline=1:length(menu)
567    if isequal(menu{iline},s.Style)
568        set(handles.ObjectStyle,'Value',iline)
569        teststyle=1;
570        break
571    end
572end
573testmode=0;
574%menu=get(handles.ProjMode,'String');
575for iline=1:length(menu_proj)
576    if isequal(menu_proj{iline},s.ProjMode)
577        set(handles.ProjMode,'Value',iline)
578        testmode=1;
579        break
580    end
581end
582
583ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
584if isfield(s,'CoordType')
585    if isequal(s.CoordType,'phys')
586        set(handles.MenuCoord,'Value',1)
587    elseif isequal(s.CoordType,'px')
588        set(handles.MenuCoord,'Value',2)
589    else
590        warndlg('unknown CoordType (px or phys) in set_object.m')
591    end
592end
593if isfield(s,'XMax')
594    set(handles.XMax,'String',s.XMax)
595end
596if isfield(s,'XMin')
597    set(handles.XMin,'String',s.XMin)
598end
599if isfield(s,'YMax')
600    set(handles.YMax,'String',s.YMax)
601end
602if isfield(s,'YMin')
603    set(handles.YMin,'String',s.YMin)
604end
605Range=0;
606if isfield(s,'Range')
607    if ischar(s.Range)
608        Range=str2num(s.Range);
609    else
610        Range(1,:)=str2num(s.Range{1});
611        Range(2,:)=str2num(s.Range{2});
612    end
613end
614if size(Range,2)>=3
615    if size(Range,1)>=2
616       set(handles.ZMin,'String',num2str(Range(2,3),3))
617    end
618    if size(Range,1)>=2
619       set(handles.ZMax,'String',num2str(Range(1,3),3))
620    end
621end
622if size(Range,2)>=2
623    if size(Range,1)>=2
624       set(handles.YMin,'String',num2str(Range(2,2),3))
625    end
626    if size(Range,1)>=2
627       set(handles.YMax,'String',num2str(Range(1,2),3))
628    end
629end
630if size(Range,2)>=1
631    if size(Range,1)>=2
632       set(handles.XMin,'String',num2str(Range(2,1),3))
633    end
634    if size(Range,1)>=2
635       set(handles.XMax,'String',num2str(Range(1,1),3))
636    end
637end
638if isfield(s,'RangeX') & ischar(s.RangeX)
639     RangeX=str2num(s.RangeX);
640    set(handles.XMax,'String',num2str(max(RangeX),3))
641    set(handles.XMin,'String',num2str(min(RangeX),3))
642end
643
644if isfield(s,'RangeY')
645    if ischar(s.RangeY)
646        RangeY=str2num(s.RangeY);
647        set(handles.YMax,'String',num2str(max(RangeY),3))
648        set(handles.YMin,'String',num2str(min(RangeY),3))
649    end
650end
651if isfield(s,'RangeZ')
652    if ischar(s.RangeZ)
653        RangeZ=str2num(s.RangeZ);
654        set(handles.ZMax,'String',num2str(max(RangeZ),3))
655        set(handles.ZMin,'String',num2str(min(RangeZ),3))
656    end
657end
658if isfield(s,'Phi')
659    set(handles.Phi,'String',s.Phi)
660end
661if isfield(s,'Theta')
662    set(handles.Theta,'String',s.Theta)
663end
664if isfield(s,'Psi')
665    set(handles.Psi,'String',s.Psi)
666end
667
668if isfield(s,'DX')
669    set(handles.DX,'String',s.DX)
670end
671if isfield(s,'DY')
672    set(handles.DY,'String',s.DY)
673end
674if ~isfield(s,'Coord')
675    XObject='0';%default
676    YObject='0';
677elseif ischar(s.Coord)
678    line=str2num(s.Coord);
679    XObject=num2str(line(1),4);
680    YObject=num2str(line(2),4);
681else
682    for i=1:length(s.Coord)
683        line=str2num(s.Coord{i});
684        XObject{i}=num2str(line(1),4);
685        YObject{i}=num2str(line(2),4);
686    end
687end
688set(handles.XObject,'String',XObject)
689set(handles.YObject,'String',YObject)
690%METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening
691%------------------------------------------------------------------------
692%----------------------------------------------------
693% executed when closing: set the parent interface button to value 0
694function closefcn(gcbo,eventdata,parent_button)
695
696huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
697if ~isempty(huvmat)
698    hhuvmat=guidata(huvmat);
699%     set(hhuvmat.create,'Value',0)
700%     set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
701%     set(hhuvmat.LINE,'Value',0)
702%     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
703%     set(hhuvmat.PATCH,'Value',0)
704%     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
705%     set(hhuvmat.PLANE,'Value',0)
706%     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
707%     set(hhuvmat.VOLUME,'Value',0)
708%     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
709    set(hhuvmat.edit,'Value',0)
710    set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
711end
712hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
713if ~isempty(hseries)
714    hhseries=guidata(hseries);
715    set(hhseries.GetObject,'Value',0)
716    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
717end
718
719%------------------------------------------------------------------------
720% --- Executes on button press in PLOT: PLOT the defined object and its projected field
721function PLOT_Callback(hObject, eventdata, handles)
722
723huvmat=findobj('tag','uvmat');%find the current uvmat interface handle
724UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
725hhuvmat=guidata(huvmat);%handles in the uvmat GUI
726ObjectName=get(handles.TITLE,'String');%name of the current object
727ListObject=get(hhuvmat.list_object_1,'String');%position in the objet list
728IndexObj_1=get(hhuvmat.list_object_1,'Value');
729IndexObj_2=get(hhuvmat.list_object_2,'Value');
730ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object
731testnew=0;
732PlotHandles=get_plot_handles(hhuvmat);
733projview='';
734if strcmp(ListObject{IndexObj_1},ObjectName)% we are editing the object whose projection is viewed in the uvmat frame
735   ObjectData.HandlesDisplay=hhuvmat.axes3;
736    IndexObj=IndexObj_1;
737    projview='uvmat';
738elseif IndexObj_2<=numel(ListObject)&& strcmp(ListObject{IndexObj_2},ObjectName)% we are editing the object whose projection is viewed in view_field
739    hview_field=findobj(allchild(0),'tag','view_field');
740    if ~isempty(hview_field)
741        PlotHandles=guidata(hview_field);
742        ObjectData.HandlesDisplay=PlotHandles.axes3;%handle of axes3 in view_field
743    end
744    IndexObj=IndexObj_2;
745    projview='view_field';
746else %new object
747    testnew=1; 
748    IndexObj=numel(ListObject)+1;
749end
750if length(ObjectName)<1% name of object not defined in set_object
751    ObjectName=[num2str(IndexObj) '-' ObjectData.Style];%default name
752elseif ~get(hhuvmat.edit,'Value')%not in edit mode (new object created)
753    detectname=1;
754    ObjectNameNew=ObjectName;
755    vers=0;
756    while detectname==1 %create a new subdir if the netcdf files already exist
757        detectname=find(strcmp(ObjectNameNew,ListObject),1)%test the existence of the proposed name in the list
758        if detectname% if athe object name already exists
759            indstr=regexp(ObjectNameNew,'\D')
760            if indstr(end)<length(ObjectNameNew) %object name ends by a number
761                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
762                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
763            else
764                vers=vers+1
765                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)]     
766            end
767        end
768    end
769    ObjectName=ObjectNameNew;
770end
771ListObject{IndexObj,1}=ObjectName;
772set(hhuvmat.list_object_1,'String',ListObject)
773set(hhuvmat.list_object_2,'String',[ListObject;{'...'}])
774if testnew
775    set(hhuvmat.list_object_2,'Value',IndexObj)
776end
777
778% update the object plot and projection field
779UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,PlotHandles);
780if strcmp(projview,'view_field')
781    ViewFieldData=get(hview_field,'UserData');
782    ViewFieldData.axes3=ObjectData;
783    set(hview_field,'UserData',ViewFieldData)
784else
785    UvData.axes3=ObjectData;
786end
787
788%set uvmat to object edit mode to allow further object update
789hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
790set(hhuvmat.MenuEditObject,'enable','on')
791set(hhuvmat.edit,'Value',1)
792set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
793UvData.MouseAction='edit_object'; % set the edit button to 'on'
794set(huvmat,'UserData',UvData)
795%------------------------------------------------------------------------
796% --- Executes on button press in MenuCoord.
797function MenuCoord_Callback(hObject, eventdata, handles)
798%------------------------------------------------------------------------
799%----------------------------------------------------
800function YMin_Callback(hObject, eventdata, handles)
801%------------------------------------------------------------------------
802
803function ZMin_Callback(hObject, eventdata, handles)
804%------------------------------------------------------------------------
805
806function ZMax_Callback(hObject, eventdata, handles)
807DZ=str2num(get(handles.ZMax,'String'));
808ZMin=get(handles.z_slider,'Min');
809ZMax=get(handles.z_slider,'Max');
810if ~isequal(ZMax-ZMin,0)
811    rel_step(1)=DZ/(ZMax-ZMin);
812    rel_step(2)=0.2;
813    set(handles.z_slider,'SliderStep',rel_step)
814end
815%------------------------------------------------------------------------
816function YMax_Callback(hObject, eventdata, handles)
817%------------------------------------------------------------------------
818
819function XMin_Callback(hObject, eventdata, handles)
820%------------------------------------------------------------------------
821
822function XMax_Callback(hObject, eventdata, handles)
823%------------------------------------------------------------------------
824%------------------------------------------------------------------------
825function SAVE_Callback(hObject, eventdata, handles)
826% ------------------------------------------------------
827Object=read_set_object(handles);
828huvmat=findobj('Tag','uvmat');
829% UvData=get(huvmat,'UserData');
830if isempty(huvmat)
831    huvmat=findobj(allchild(0),'Name','series');
832end
833hchild=get(huvmat,'Children');
834hrootpath=findobj(hchild,'Tag','RootPath');
835if isempty(hrootpath)
836    RootPath='';
837else
838    RootPath=get(hrootpath,'String');
839    if iscell(RootPath)
840        RootPath=RootPath{1};
841    end
842end
843title={'object name'};
844dir_save=uigetdir(RootPath);
845ObjectName=get(handles.TITLE,'String');
846if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
847    def={fullfile(dir_save,[ObjectName Object.CoordType '.xml'])};
848else
849    def={fullfile(dir_save,[Object.Style Object.CoordType '.xml'])};
850end
851options.Resize='on';
852displ_txt='save object as an .xml file';%default display
853menu=get(handles.ProjMode,'String');
854value=get(handles.ProjMode,'Value');
855ProjMode=menu{value};
856if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
857    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
858end
859answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
860%answer=inputdlg('','save object in a new .xml file',1,def,'on');
861if ~isempty(answer)
862    t=struct2xml(Object);
863    save(t,answer{1})
864end
865msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
866%------------------------------------------------------------------------
867%------------------------------------------------------------------------
868% --- Executes on slider movement.
869function z_slider_Callback(hObject, eventdata, handles)
870%---------------------------------------------------------
871%A ADAPTER
872Z_value=get(handles.z_slider,'Value');
873
874%rotation angles
875Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
876Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
877
878%components of the unity vector normal to the projection plane
879NormVec_X=-sin(Phi)*sin(Theta);
880NormVec_Y=cos(Phi)*sin(Theta);
881NormVec_Z=cos(Theta);
882
883%set new plane position and update graph
884set(handles.XObject,'String',num2str(NormVec_X*Z_value,4))
885set(handles.YObject,'String',num2str(NormVec_Y*Z_value,4))
886set(handles.ZObject,'String',num2str(NormVec_Z*Z_value,4))
887PLOT_Callback(hObject, eventdata, handles)
888%------------------------------------------------------------------------
889%------------------------------------------------------------------------
890% --- Executes on button press in HELP.
891function HELP_Callback(hObject, eventdata, handles)
892path_to_uvmat=which ('uvmat');% check the path of uvmat
893pathelp=fileparts(path_to_uvmat);
894helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
895if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
896else
897    addpath (fullfile(pathelp,'uvmat_doc'))
898    web([helpfile '#set_object'])
899end
900%------------------------------------------------------------------------
901
902
Note: See TracBrowser for help on using the repository browser.