source: trunk/src/set_object.m @ 159

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

bug in civ corrected: civ2 was not lauched for Windows system
various bugs corrections and cleaning

File size: 34.9 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 & ischar(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)
86%set(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,'CoordUnit')
244        set(handles.CoordUnit,'String',data.CoordUnit)
245    end
246%     if isfield(data,'CoordType')&& isequal(data.CoordType,'px')
247% %         if isequal(data.CoordType,'phys')
248% %             set(handles.MenuCoord,'Value',1)
249% %         elseif isequal(data.CoordType,'px')
250%              set(handles.MenuCoord,'Value',2)
251% %         end
252%     end
253end
254if enable_plot
255   set(handles.PLOT,'enable','on')
256else
257   set(handles.PLOT,'enable','off')
258end
259huvmat=findobj(allchild(0),'tag','uvmat');
260UvData=get(huvmat,'UserData');
261pos_uvmat=get(huvmat,'Position');
262%position the set_object GUI with respect to uvmat
263if isfield(UvData,'SetObjectOrigin')
264    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
265    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
266    set(hObject,'Position',pos_set_object)
267end
268
269% --- Outputs from this function are returned to the command line.
270function varargout = set_object_OutputFcn(hObject, eventdata, handles)
271% varargout  cell array for returning output args (see VARARGOUT);
272% hObject    handle to figure
273% eventdata  reserved - to be defined in a future version of MATLAB
274% handles    structure with handles and user data (see GUIDATA)
275
276% Get default command line output from handles structure
277varargout{1} = handles.output;
278varargout{2}=handles;
279
280%------------------------------------------------------------------------
281% --- Executes on selection change in ObjectStyle.
282function ObjectStyle_Callback(hObject, eventdata, handles)
283style_prev=get(handles.ObjectStyle,'UserData');%previous object style
284str=get(handles.ObjectStyle,'String');
285val=get(handles.ObjectStyle,'Value');
286style=str{val};
287% make correspondance between different object styles
288% if ~isequal(str{val},style_prev)
289Xcolumn=get(handles.XObject,'String');
290Ycolumn=get(handles.YObject,'String');
291if ischar(Xcolumn)
292    sizchar=size(Xcolumn);
293    for icol=1:sizchar(1)
294        Xcolumn_cell{icol}=Xcolumn(icol,:);
295    end
296    Xcolumn=Xcolumn_cell;
297end
298if ischar(Ycolumn)
299    sizchar=size(Ycolumn);
300    for icol=1:sizchar(1)
301        Ycolumn_cell{icol}=Ycolumn(icol,:);
302    end
303    Ycolumn=Ycolumn_cell;
304end
305Zcolumn={};%default
306z_new={};
307if isequal(get(handles.ZObject,'Visible'),'on')
308    data.NbDim=3; %test 3D object
309    Zcolumn=get(handles.ZObject,'String');
310    if ischar(Zcolumn)
311        Zcolumn={Zcolumn};
312    end
313end
314x_new{1}=Xcolumn{1};
315y_new{1}=Ycolumn{1};
316if ~isempty(Zcolumn)
317    z_new{1}=Zcolumn{1};
318end
319if isequal(style,'line')
320    if strcmp(style_prev,'rectangle')||strcmp(style_prev,'ellipse')
321        XMax=get(handles.XMax,'String');
322        YMax=get(handles.YMax,'String');
323        x_new{2}=num2str(XMax,4);
324        y_new{2}=num2str(YMax,4);
325        set(handles.XObject,'String',x_new)
326        set(handles.YObject,'String',y_new)
327        set(handles.ZObject,'String',z_new)
328    end
329elseif isequal(style,'polyline')
330elseif strcmp(style,'rectangle')|| strcmp(style,'ellipse')
331     set(handles.XObject,'String',x_new)
332     set(handles.YObject,'String',y_new)
333     set(handles.ZObject,'String',z_new)
334end
335% end
336switch style
337    case {'points','line','polyline','plane'}
338        menu_proj={'projection';'interp';'filter';'none'};
339    case {'polygon','rectangle','ellipse'}
340        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
341    case 'volume'
342        menu_proj={'interp';'none'};
343end   
344proj_index=get(handles.ProjMode,'Value');
345if proj_index<numel(menu_proj)
346    set(handles.ProjMode,'Value',1);% value index must not exceed the menu length
347end
348set(handles.ProjMode,'String',menu_proj)
349ProjMode_Callback(hObject, eventdata, handles)
350%store the current option
351str=get(handles.ObjectStyle,'String');
352val=get(handles.ObjectStyle,'Value');
353set(handles.ObjectStyle,'UserData',style)
354
355%------------------------------------------------------------------------
356function xObject_Callback(hObject, eventdata, handles)
357
358%------------------------------------------------------------------------
359function yObject_Callback(hObject, eventdata, handles)
360
361%------------------------------------------------------------------------
362% --- Executes on selection change in zObject.
363function zObject_Callback(hObject, eventdata, handles)
364%------------------------------------------------------------------------
365
366%------------------------------------------------------------------------
367% --- Executes on selection change in ProjMode.
368function ProjMode_Callback(hObject, eventdata, handles)
369menu=get(handles.ProjMode,'String');
370value=get(handles.ProjMode,'Value');
371ProjMode=menu{value};
372menu=get(handles.ObjectStyle,'String');
373value=get(handles.ObjectStyle,'Value');
374ObjectStyle=menu{value};
375test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
376
377%default setting
378set(handles.Phi,'Visible','off')
379set(handles.Theta,'Visible','off')
380set(handles.Psi,'Visible','off')
381set(handles.XMin,'Visible','off')
382set(handles.XMax,'Visible','off')
383set(handles.YMin,'Visible','off')
384if isequal(ProjMode,'interp')
385    set(handles.YMax,'Visible','off')
386else
387    set(handles.YMax,'Visible','on')
388end
389if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
390    set(handles.XMax,'Visible','on')
391else
392   set(handles.XMax,'Visible','off')
393end
394set(handles.ZMin,'Visible','off')
395set(handles.ZMax,'Visible','off')
396set(handles.DX,'Visible','off')
397set(handles.DY,'Visible','off')
398set(handles.DZ,'Visible','off')
399
400switch ObjectStyle
401    case 'points'
402        set(handles.YMax,'TooltipString','YMax: range of averaging around each point')
403        set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
404        set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
405        set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
406    case {'line','polyline','polygon'}
407        set(handles.YMax,'TooltipString','YMax: range of averaging around the line')
408        set(handles.XObject,'TooltipString','XObject: set of x coordinates defining the line')
409        set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
410        set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
411        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
412            set(handles.DX,'Visible','on')
413            set(handles.DX,'TooltipString','DX: mesh for the interpolated field along the line')
414        end       
415    case {'rectangle','ellipse'}
416        set(handles.XMax,'TooltipString',['XMax: half length of the ' ObjectStyle])
417        set(handles.YMax,'TooltipString',['YMax: half width of the ' ObjectStyle])
418        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' ObjectStyle ' centre'])
419        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' ObjectStyle ' centre'])
420    case {'plane'} 
421        set(handles.Phi,'Visible','on')
422        set(handles.XMin,'Visible','on')
423        set(handles.XMax,'Visible','on')
424        set(handles.YMin,'Visible','on')
425        set(handles.YMax,'Visible','on')
426        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
427        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
428        set(handles.ZMax,'TooltipString',['ZMax: range of projection normal to the plane'])
429        if test3D
430            set(handles.Theta,'Visible','on')
431            set(handles.Psi,'Visible','on')
432            set(handles.ZMax,'Visible','on')
433        end
434        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
435            set(handles.DX,'Visible','on')
436            set(handles.DY,'Visible','on')
437        else
438            set(handles.DX,'Visible','off')
439            set(handles.DY,'Visible','off')
440        end
441        if isequal(ObjectStyle,'volume') && isequal(ProjMode,'interp')
442            set(handles.DZ,'Visible','on') 
443        end
444     case {'volume'} 
445        set(handles.Phi,'Visible','on')
446        set(handles.XMin,'Visible','on')
447        set(handles.XMax,'Visible','on')
448        set(handles.YMin,'Visible','on')
449        set(handles.YMax,'Visible','on')
450        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
451        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
452        if test3D
453            set(handles.Theta,'Visible','on')
454            set(handles.Psi,'Visible','on')
455            set(handles.ZMin,'Visible','on')
456            set(handles.ZMax,'Visible','on')
457        end
458        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
459            set(handles.DX,'Visible','on')
460            set(handles.DY,'Visible','on')
461        else
462            set(handles.DX,'Visible','off')
463            set(handles.DY,'Visible','off')
464        end
465        if isequal(ObjectStyle,'volume') && isequal(ProjMode,'interp')
466            set(handles.DZ,'Visible','on') 
467        end
468end
469%------------------------------------------------------------------------
470
471%------------------------------------------------------------------------
472function Phi_Callback(hObject, eventdata, handles)
473update_slider(hObject, eventdata,handles)
474%------------------------------------------------------------------------
475%------------------------------------------------------------------------
476function Theta_Callback(hObject, eventdata, handles)
477update_slider(hObject, eventdata,handles)
478%------------------------------------------------------------------------
479function update_slider(hObject, eventdata,handles)
480%rotation angles
481Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
482Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
483
484%components of the unitiy vector normal to the projection plane
485NormVec_X=-sin(Phi)*sin(Theta);
486NormVec_Y=cos(Phi)*sin(Theta);
487NormVec_Z=cos(Theta);
488huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
489UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
490if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
491    Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
492    set(handles.z_slider,'Min',min(Z))
493    set(handles.z_slider,'Max',max(Z))
494    ZMax_Callback(hObject, eventdata, handles)
495end
496%------------------------------------------------------------------------
497function DX_Callback(hObject, eventdata, handles)
498%------------------------------------------------------------------------
499%------------------------------------------------------------------------
500function DY_Callback(hObject, eventdata, handles)
501%------------------------------------------------------------------------
502%------------------------------------------------------------------------
503function DZ_Callback(hObject, eventdata, handles)
504%------------------------------------------------------------------------
505
506%------------------------------------------------------------------------
507%-----------------------------------------------------
508% --- Executes on button press in OPEN: DESACTIVATED use uvmat browser
509function OPEN_Callback(hObject, eventdata, handles)
510%get the object file
511oldfile=' ';
512huvmat=findobj('Tag','uvmat');
513hchild=get(huvmat,'Children');
514hrootpath=findobj(hchild,'Tag','RootPath');
515if ~isempty(hrootpath)
516    oldfile=get(hrootpath,'String');
517    if iscell(oldfile)
518        oldfile=oldfile{1};
519    end
520end
521[FileName, PathName, filterindex] = uigetfile( ...
522       {'*.xml;*.mat', ' (*.xml,*.mat)';
523       '*.xml',  '.xml files '; ...
524        '*.mat',  '.mat matlab files '}, ...
525        'Pick a file',oldfile);
526fileinput=[PathName FileName];%complete file name
527testblank=findstr(fileinput,' ');%look for blanks
528if ~isempty(testblank)
529    msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
530    return
531end
532sizf=size(fileinput);
533if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
534
535%read the file
536 t=xmltree(fileinput);
537 s=convert(t);
538 if ~isfield(s,'Style')
539     s.Style='points';
540 end
541 if ~isfield(s,'ProjMode')
542     s.ProjMode='none';
543 end
544%Display title
545% title=set_title(s.Style,s.ProjMode);%update the title
546% if ~isempty(huvmat)
547%     hhuvmat=guidata(huvmat);
548% end
549% menu=get(handles.TITLE,'String');
550% for iline=1:length(menu)
551%      if isequal(menu{iline},title)
552%          set(handles.TITLE,'Value',iline)
553%          break
554%      end
555% end
556%TITLE_Callback(hObject, eventdata, handles)
557teststyle=0;
558
559switch s.Style
560    case {'points','line','polyline','plane'}
561        menu_proj={'projection';'interp';'filter';'none'};
562    case {'polygon','rectangle','ellipse'}
563        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
564    case 'volume'
565        menu_proj={'none'};
566end
567set(handles.ObjectStyle,'String',menu_proj)
568menu=get(handles.ObjectStyle,'String');
569for iline=1:length(menu)
570    if isequal(menu{iline},s.Style)
571        set(handles.ObjectStyle,'Value',iline)
572        teststyle=1;
573        break
574    end
575end
576testmode=0;
577%menu=get(handles.ProjMode,'String');
578for iline=1:length(menu_proj)
579    if isequal(menu_proj{iline},s.ProjMode)
580        set(handles.ProjMode,'Value',iline)
581        testmode=1;
582        break
583    end
584end
585
586ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
587% if isfield(s,'CoordType')
588%     if isequal(s.CoordType,'phys')
589%         set(handles.MenuCoord,'Value',1)
590%     elseif isequal(s.CoordType,'px')
591%         set(handles.MenuCoord,'Value',2)
592%     else
593%         warndlg('unknown CoordType (px or phys) in set_object.m')
594%     end
595% end
596if isfield(s,'XMax')
597    set(handles.XMax,'String',s.XMax)
598end
599if isfield(s,'XMin')
600    set(handles.XMin,'String',s.XMin)
601end
602if isfield(s,'YMax')
603    set(handles.YMax,'String',s.YMax)
604end
605if isfield(s,'YMin')
606    set(handles.YMin,'String',s.YMin)
607end
608Range=0;
609if isfield(s,'Range')
610    if ischar(s.Range)
611        Range=str2num(s.Range);
612    else
613        Range(1,:)=str2num(s.Range{1});
614        Range(2,:)=str2num(s.Range{2});
615    end
616end
617if size(Range,2)>=3
618    if size(Range,1)>=2
619       set(handles.ZMin,'String',num2str(Range(2,3),3))
620    end
621    if size(Range,1)>=2
622       set(handles.ZMax,'String',num2str(Range(1,3),3))
623    end
624end
625if size(Range,2)>=2
626    if size(Range,1)>=2
627       set(handles.YMin,'String',num2str(Range(2,2),3))
628    end
629    if size(Range,1)>=2
630       set(handles.YMax,'String',num2str(Range(1,2),3))
631    end
632end
633if size(Range,2)>=1
634    if size(Range,1)>=2
635       set(handles.XMin,'String',num2str(Range(2,1),3))
636    end
637    if size(Range,1)>=2
638       set(handles.XMax,'String',num2str(Range(1,1),3))
639    end
640end
641if isfield(s,'RangeX') & ischar(s.RangeX)
642     RangeX=str2num(s.RangeX);
643    set(handles.XMax,'String',num2str(max(RangeX),3))
644    set(handles.XMin,'String',num2str(min(RangeX),3))
645end
646
647if isfield(s,'RangeY')
648    if ischar(s.RangeY)
649        RangeY=str2num(s.RangeY);
650        set(handles.YMax,'String',num2str(max(RangeY),3))
651        set(handles.YMin,'String',num2str(min(RangeY),3))
652    end
653end
654if isfield(s,'RangeZ')
655    if ischar(s.RangeZ)
656        RangeZ=str2num(s.RangeZ);
657        set(handles.ZMax,'String',num2str(max(RangeZ),3))
658        set(handles.ZMin,'String',num2str(min(RangeZ),3))
659    end
660end
661if isfield(s,'Phi')
662    set(handles.Phi,'String',s.Phi)
663end
664if isfield(s,'Theta')
665    set(handles.Theta,'String',s.Theta)
666end
667if isfield(s,'Psi')
668    set(handles.Psi,'String',s.Psi)
669end
670
671if isfield(s,'DX')
672    set(handles.DX,'String',s.DX)
673end
674if isfield(s,'DY')
675    set(handles.DY,'String',s.DY)
676end
677if ~isfield(s,'Coord')
678    XObject='0';%default
679    YObject='0';
680elseif ischar(s.Coord)
681    line=str2num(s.Coord);
682    XObject=num2str(line(1),4);
683    YObject=num2str(line(2),4);
684else
685    for i=1:length(s.Coord)
686        line=str2num(s.Coord{i});
687        XObject{i}=num2str(line(1),4);
688        YObject{i}=num2str(line(2),4);
689    end
690end
691set(handles.XObject,'String',XObject)
692set(handles.YObject,'String',YObject)
693%METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening
694%------------------------------------------------------------------------
695%----------------------------------------------------
696% executed when closing: set the parent interface button to value 0
697function closefcn(gcbo,eventdata,parent_button)
698
699huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
700if ~isempty(huvmat)
701    hhuvmat=guidata(huvmat);
702%     set(hhuvmat.create,'Value',0)
703%     set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
704%     set(hhuvmat.LINE,'Value',0)
705%     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
706%     set(hhuvmat.PATCH,'Value',0)
707%     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
708%     set(hhuvmat.PLANE,'Value',0)
709%     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
710%     set(hhuvmat.VOLUME,'Value',0)
711%     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
712    set(hhuvmat.edit,'Value',0)
713    set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
714end
715hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
716if ~isempty(hseries)
717    hhseries=guidata(hseries);
718    set(hhseries.GetObject,'Value',0)
719    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
720end
721
722%------------------------------------------------------------------------
723% --- Executes on button press in PLOT: PLOT the defined object and its projected field
724function PLOT_Callback(hObject, eventdata, handles)
725
726%% reading the object parameters on the GUI uvmat
727huvmat=findobj('tag','uvmat');%find the current uvmat interface handle
728UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
729hhuvmat=guidata(huvmat);%handles in the uvmat GUI
730ObjectName=get(handles.TITLE,'String');%name of the current object
731ListObject=get(hhuvmat.list_object_1,'String');%position in the objet list
732IndexObj_1=get(hhuvmat.list_object_1,'Value');
733if isequal(get(hhuvmat.list_object_2,'Visible'),'on')
734    IndexObj_2=get(hhuvmat.list_object_2,'Value');
735else
736    IndexObj_2=[];
737end
738testnew=0;
739PlotHandles=get_plot_handles(hhuvmat);
740projview='view_field';%default
741if strcmp(ListObject{IndexObj_1},ObjectName)% we are editing the object whose projection is viewed in the uvmat frame
742%    ObjectData.HandlesDisplay=hhuvmat.axes3;
743%     Object_set{iobj}.DisplayHandle_view_field
744    IndexObj=IndexObj_1;
745    projview='uvmat';
746     plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
747elseif ~isempty(IndexObj_2) && IndexObj_2<=numel(ListObject)&& strcmp(ListObject{IndexObj_2},ObjectName)% we are editing the object whose projection is viewed in view_field 
748    IndexObj=IndexObj_2;
749%     projview='view_field';
750else %new object
751    testnew=1;
752    IndexObj=numel(ListObject)+1;
753    hview_field=findobj(allchild(0),'tag','view_field');
754    if ~isempty(hview_field)
755        PlotHandles=guidata(hview_field);
756        plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
757%         ObjectData.HandlesDisplay=PlotHandles.axes3;%handle of axes3 in view_field
758    end
759end
760if strcmp(projview,'view_field')
761    hview_field=findobj(allchild(0),'tag','view_field');
762    if isempty(hview_field)
763        hview_field=view_field;
764    end
765    PlotHandles=guidata(hview_field);
766    plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
767end   
768ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object
769
770%% naming the object
771if length(ObjectName)<1% name of object not defined in set_object
772    ObjectName=[num2str(IndexObj) '-' ObjectData.Style];%default name
773elseif ~get(hhuvmat.edit_object,'Value')%not in edit mode (new object created)
774    detectname=1;
775    ObjectNameNew=ObjectName;
776    vers=0;
777    while detectname==1
778        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
779        if detectname% if the object name already exists
780            indstr=regexp(ObjectNameNew,'\D');
781            if indstr(end)<length(ObjectNameNew) %object name ends by a number
782                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
783                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
784            else
785                vers=vers+1;
786                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];     
787            end
788        end
789    end
790    ObjectName=ObjectNameNew;
791end
792ListObject{IndexObj,1}=ObjectName;
793set(hhuvmat.list_object_1,'String',ListObject)
794set(hhuvmat.list_object_2,'String',[ListObject;{'...'}])
795
796%% update the object plot and projection field
797if testnew
798    set(hhuvmat.list_object_2,'Value',IndexObj)
799    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
800    ObjectData.DisplayHandle_view_field=[];
801elseif ~isfield(UvData.Object{IndexObj},'DisplayHandle_uvmat')% save the previous object graph handles
802    ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj}.DisplayHandle_uvmat;
803    ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj}.DisplayHandle_view_field;
804else
805    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
806    ObjectData.DisplayHandle_view_field=[];
807end
808UvData.Object{IndexObj}=ObjectData;%update the current object properties
809UvData.Object=update_obj(UvData,IndexObj_1,IndexObj_2);
810
811%% plot the field projected on the object and store it the corresponding figue
812get(plotaxes,'tag')
813ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
814[PlotType,Object_out{IndexObj}.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotHandles);%update an existing field plot
815if strcmp(projview,'view_field')
816    ViewFieldData=get(hview_field,'UserData');
817    ViewFieldData.axes3=ObjectData;
818    set(hview_field,'UserData',ViewFieldData)
819else
820    UvData.axes3=ObjectData;
821end
822
823%% update the GUI uvmat
824hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
825set(hhuvmat.MenuEditObject,'enable','on')
826set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
827set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
828%UvData.MouseAction='edit_object'; % set the edit button to 'on'
829set(huvmat,'UserData',UvData)
830%------------------------------------------------------------------------
831% --- Executes on button press in MenuCoord.
832function MenuCoord_Callback(hObject, eventdata, handles)
833%------------------------------------------------------------------------
834%----------------------------------------------------
835function YMin_Callback(hObject, eventdata, handles)
836%------------------------------------------------------------------------
837
838function ZMin_Callback(hObject, eventdata, handles)
839%------------------------------------------------------------------------
840
841function ZMax_Callback(hObject, eventdata, handles)
842DZ=str2num(get(handles.ZMax,'String'));
843ZMin=get(handles.z_slider,'Min');
844ZMax=get(handles.z_slider,'Max');
845if ~isequal(ZMax-ZMin,0)
846    rel_step(1)=DZ/(ZMax-ZMin);
847    rel_step(2)=0.2;
848    set(handles.z_slider,'SliderStep',rel_step)
849end
850%------------------------------------------------------------------------
851function YMax_Callback(hObject, eventdata, handles)
852%------------------------------------------------------------------------
853
854function XMin_Callback(hObject, eventdata, handles)
855%------------------------------------------------------------------------
856
857function XMax_Callback(hObject, eventdata, handles)
858%------------------------------------------------------------------------
859%------------------------------------------------------------------------
860function SAVE_Callback(hObject, eventdata, handles)
861% ------------------------------------------------------
862Object=read_set_object(handles);
863huvmat=findobj('Tag','uvmat');
864% UvData=get(huvmat,'UserData');
865if isempty(huvmat)
866    huvmat=findobj(allchild(0),'Name','series');
867end
868hchild=get(huvmat,'Children');
869hrootpath=findobj(hchild,'Tag','RootPath');
870if isempty(hrootpath)
871    RootPath='';
872else
873    RootPath=get(hrootpath,'String');
874    if iscell(RootPath)
875        RootPath=RootPath{1};
876    end
877end
878title={'object name'};
879dir_save=uigetdir(RootPath);
880ObjectName=get(handles.TITLE,'String');
881if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
882    def={fullfile(dir_save,[ObjectName '.xml'])};
883else
884    def={fullfile(dir_save,[Object.Style '.xml'])};
885end
886displ_txt='save object as an .xml file';%default display
887menu=get(handles.ProjMode,'String');
888value=get(handles.ProjMode,'Value');
889ProjMode=menu{value};
890if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
891    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
892end
893answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
894if ~isempty(answer)
895    t=struct2xml(Object);
896    save(t,answer{1})
897end
898msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
899%------------------------------------------------------------------------
900%------------------------------------------------------------------------
901% --- Executes on slider movement.
902function z_slider_Callback(hObject, eventdata, handles)
903%---------------------------------------------------------
904%A ADAPTER
905Z_value=get(handles.z_slider,'Value');
906
907%rotation angles
908Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
909Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
910
911%components of the unity vector normal to the projection plane
912NormVec_X=-sin(Phi)*sin(Theta);
913NormVec_Y=cos(Phi)*sin(Theta);
914NormVec_Z=cos(Theta);
915
916%set new plane position and update graph
917set(handles.XObject,'String',num2str(NormVec_X*Z_value,4))
918set(handles.YObject,'String',num2str(NormVec_Y*Z_value,4))
919set(handles.ZObject,'String',num2str(NormVec_Z*Z_value,4))
920PLOT_Callback(hObject, eventdata, handles)
921%------------------------------------------------------------------------
922%------------------------------------------------------------------------
923% --- Executes on button press in HELP.
924function HELP_Callback(hObject, eventdata, handles)
925path_to_uvmat=which ('uvmat');% check the path of uvmat
926pathelp=fileparts(path_to_uvmat);
927helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
928if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
929else
930    addpath (fullfile(pathelp,'uvmat_doc'))
931    web([helpfile '#set_object'])
932end
933%------------------------------------------------------------------------
934
935
Note: See TracBrowser for help on using the repository browser.