source: trunk/src/set_object.m @ 648

Last change on this file since 648 was 648, checked in by sommeria, 11 years ago

get_field updated, several bugs corrected,open_uvmat suppressd

File size: 33.4 KB
RevLine 
[204]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%
[445]9% INPUT:u
[204]10% data: structure describing the object properties
11%    .Style=...
12%    .ProjMode
13%    .CoordType: 'phys' or 'px'
[379]14%    .num_DX,.num_DY,.num_DZ : mesh along each dirction
[204]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
[379]38% Last Modified by GUIDE v2.5 26-Jan-2012 22:00:47
[204]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
[379]67%      .Name : class of object ('POINTS','LINE',....)
68%      .num_DX,num_DY,num_DZ; meshes for regular grids
[204]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
[613]81%% position
82set(0,'Unit','points')
83ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
84Width=300;% fig width in points (1/72 inch)
85Height=min(0.8*ScreenSize(4),500);
86Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
87Bottom=ScreenSize(4)-Height-40; %put fig at top right
88set(handles.set_object,'Unit','points')
89set(handles.set_object,'Position',[Left Bottom Width Height])
90
[204]91%default
[206]92if ~exist('ZBounds','var')
93    ZBounds=0; %default
[204]94end
95set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front)
[309]96set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
[402]97set(hObject,'DeleteFcn',{@closefcn})
[204]98
99% fill the interface as set in the input data:
100if exist('data','var')
[379]101    if isfield(data,'Coord') &&size(data.Coord,2)==3
102        set(handles.z_slider,'Visible','on')
103    else
[204]104        set(handles.z_slider,'Visible','off')
105    end
[387]106    if isfield(data,'TypeMenu')
107        set(handles.Type,'String',data.TypeMenu)
108    end
109    if isfield(data,'ProjModeMenu')
110        set(handles.ProjMode,'UserData',data.ProjModeMenu)% data.ProjModeMenu as default menu (used in Type_Callback)
111    end
[591]112    errormsg=fill_GUI(data,handles.set_object);
[410]113    if ~isempty(errormsg)
114        msgbox_uvmat('ERROR','bad data input in set_object')
115        return
116    end
[387]117    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type   
118
[204]119    if isfield(data,'RangeZ') && length(ZBounds) >= 2
[379]120        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
[204]121        DZ=max(data.RangeZ);%slider step
[206]122        if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1)
[204]123            rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
124            rel_step(2)=0.1;
125            set(handles.z_slider,'Visible','on')
126            set(handles.z_slider,'Min',ZBounds(1))
127            set(handles.z_slider,'Max',ZBounds(2))
128            set(handles.z_slider,'SliderStep',rel_step)
129            set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
130        end
131    end
132    if isfield(data,'RangeX')
133        if ischar(data.RangeX)
134            data.RangeX=str2num(data.RangeX);
135        end
[379]136        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
137        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
[204]138    end
139    if isfield(data,'RangeY')
140        if ischar(data.RangeY)
141            data.RangeY=str2num(data.RangeY);
142        end
[379]143        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
144        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
[204]145    end
146    if isfield(data,'RangeZ')
147        if ischar(data.RangeZ)
148            data.RangeZ=str2num(data.RangeZ);
149        end
[379]150        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
[204]151        if numel(data.RangeZ)>=2
[379]152            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
[204]153        end
154    end 
[625]155    if ~isfield(data,'Angle')
156        data.Angle=[0 0 0];
157    end
158%     if isfield(data,'Angle') && isequal(numel(data.Angle),3)
[379]159         set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
160         set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
161         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
[625]162%     end
[204]163end
[625]164set(get(handles.set_object,'children'),'enable','off')
165set(handles.SAVE,'enable','on')
166% set(handles.PLOT,'enable','off')
[204]167
[625]168
[204]169%------------------------------------------------------------------------
170% --- Outputs from this function are returned to the command line.
171function varargout = set_object_OutputFcn(hObject, eventdata, handles)
172%------------------------------------------------------------------------
173% Get default command line output from handles structure
174varargout{1} = handles.output;
175varargout{2}=handles;
176
177%------------------------------------------------------------------------
[402]178% executed when closing the GUI set_object
179function closefcn(gcbo,eventdata)
180%------------------------------------------------------------------------
181huvmat=findobj(allchild(0),'Tag','uvmat');%find the current uvmat interface handle
182if ~isempty(huvmat)
183    hhuvmat=guidata(huvmat);
[424]184%     set(hhuvmat.ViewObject_1,'value',0)% desactivate the two view buttons
[410]185    set(hhuvmat.ViewObject,'value',0)%
186    set(hhuvmat.edit_object,'Value',0)% desactivate the edit option
[625]187%    set(hhuvmat.edit_object,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
[402]188    % deselect the object in ListObject when view_field is closed
189    if isempty(findobj(allchild(0),'Tag','view_field'))
190        ObjIndex=get(hhuvmat.ListObject,'Value');
191        ObjIndex=ObjIndex(1);%keep only the first object selected
192        set(hhuvmat.ListObject,'Value',ObjIndex)
193        % draw all object colors in blue (unselected) in uvmat
[511]194        hother=[findobj(hhuvmat.PlotAxes,'Tag','proj_object');findobj(hhuvmat.PlotAxes,'Tag','DeformPoint')];%find all the proj object and deform point representations
[402]195        for iobj=1:length(hother)
196            if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
197                set(hother(iobj),'EdgeColor','b')
198                if isequal(get(hother(iobj),'FaceColor'),'m')
199                    set(hother(iobj),'FaceColor','b')
200                end
201            elseif isequal(get(hother(iobj),'Type'),'image')
202                Acolor=get(hother(iobj),'CData');
203                Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
204                set(hother(iobj),'CData',Acolor);
205            else
206                set(hother(iobj),'Color','b')
207            end
208            set(hother(iobj),'Selected','off')
209        end
210    end
211end
212hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
213if ~isempty(hseries)
214    hhseries=guidata(hseries);
[606]215    set(hhseries.ViewObject,'Value',0)
[402]216end
217
218
219%------------------------------------------------------------------------
[379]220% --- Executes on selection change in Type.
221function Type_Callback(hObject, eventdata, handles)
[204]222%------------------------------------------------------------------------
[379]223%style_prev=get(handles.Type,'UserData');%previous object style
224ListType=get(handles.Type,'String');
225Type=ListType{get(handles.Type,'Value')};
[204]226% make correspondance between different object styles
[379]227Coord=get(handles.Coord,'Data');
228
229%% set the number of lines in the Coord table depending on object type
230switch Type
231    case{'line'}
232        if size(Coord,1)<2
233            if isequal(size(Coord,2),3)
234                Coord=[Coord; 0 0 0];%add a line for edition (3D case)
235            else
236                Coord=[Coord; 0 0]; %add a line for edition (2D case)
237            end
238        else
239            Coord=Coord(1:2,:);
240        end
241    case{'rectangle','ellipse','plane','volume'}
242        Coord=Coord(1,:);
[204]243end
[379]244set(handles.Coord,'Data',Coord)
[204]245
[379]246%% set the projection menu and the corresponding options
[387]247if isempty(get(handles.ProjMode,'UserData'))
248    switch Type
[648]249        case {'points','line','plane'}
[581]250            menu_proj={'projection';'interp_lin';'interp_tps';'none'};
[648]251        case 'polyline'
252            menu_proj={'interp_lin';'interp_tps';'none'};
[387]253        case {'polygon','rectangle','ellipse'}
[648]254            menu_proj={'inside';'outside';'mask_inside';'mask_outside';'interp_lin';'interp_tps';'none'};
[387]255        case 'volume'
[581]256            menu_proj={'interp_lin';'none'};
[387]257        otherwise
[581]258            menu_proj={'projection';'interp_lin';'interp_tps';'none'};%default
[387]259    end
260else
261    menu_proj=get(handles.ProjMode,'UserData');
262end
[410]263ProjModeList=get(handles.ProjMode,'String');
264menu_index=find(strcmp(ProjModeList{get(handles.ProjMode,'Value')},menu_proj));
265if isempty(menu_index)
266    menu_index=1;%
[204]267end
[410]268set(handles.ProjMode,'Value',menu_index);% value index must not exceed the menu length
[204]269set(handles.ProjMode,'String',menu_proj)
270ProjMode_Callback(hObject, eventdata, handles)
[379]271
[204]272%------------------------------------------------------------------------
273% --- Executes on selection change in ProjMode.
274function ProjMode_Callback(hObject, eventdata, handles)
275menu=get(handles.ProjMode,'String');
276value=get(handles.ProjMode,'Value');
277ProjMode=menu{value};
[379]278menu=get(handles.Type,'String');
279value=get(handles.Type,'Value');
[204]280ObjectStyle=menu{value};
[379]281%%%%%%%%% TODO
282test3D=0; %TODO: update  test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
283%%%%%%%%%
[204]284%default setting
[379]285set(handles.num_Angle_1,'Visible','off')
286set(handles.num_Angle_2,'Visible','off')
287set(handles.num_Angle_3,'Visible','off')
288set(handles.num_RangeX_1,'Visible','off')
289set(handles.num_RangeX_2,'Visible','off')
290set(handles.num_RangeY_1,'Visible','off')
[589]291if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[379]292    set(handles.num_RangeY_2,'Visible','off')
[204]293else
[379]294    set(handles.num_RangeY_2,'Visible','on')
[204]295end
296if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
[379]297    set(handles.num_RangeX_2,'Visible','on')
[204]298else
[379]299   set(handles.num_RangeX_2,'Visible','off')
[204]300end
[379]301set(handles.num_RangeZ_1,'Visible','off')
302set(handles.num_RangeZ_2,'Visible','off')
303set(handles.num_DX,'Visible','off')
304set(handles.num_DY,'Visible','off')
305set(handles.num_DZ,'Visible','off')
[204]306
307switch ObjectStyle
308    case 'points'
[379]309        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around each point')
310%         set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
311%         set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
312%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
[204]313    case {'line','polyline','polygon'}
[379]314        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around the line')
315         set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line')
316%         set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
317%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
[581]318        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[379]319            set(handles.num_DX,'Visible','on')
320            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
[204]321        end       
322    case {'rectangle','ellipse'}
[379]323        set(handles.num_RangeX_2,'TooltipString',['num_XMax: half length of the ' ObjectStyle])
324        set(handles.num_RangeY_2,'TooltipString',['num_YMax: half width of the ' ObjectStyle])
325%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' Type ' centre'])
326%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' Type ' centre'])
[204]327    case {'plane'} 
[379]328        set(handles.num_Angle_3,'Visible','on')
329        set(handles.num_RangeX_1,'Visible','on')
330        set(handles.num_RangeX_2,'Visible','on')
331        set(handles.num_RangeY_1,'Visible','on')
332        set(handles.num_RangeY_2,'Visible','on')
333%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' Type])
334%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' Type])
335        set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane')
[204]336        if test3D
[379]337            set(handles.num_Angle_2,'Visible','on')
338            set(handles.num_Angle_1,'Visible','on')
339            set(handles.num_RangeZ_2,'Visible','on')
[204]340        end
[581]341        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[379]342            set(handles.num_DX,'Visible','on')
343            set(handles.num_DY,'Visible','on')
[204]344        else
[379]345            set(handles.num_DX,'Visible','off')
346            set(handles.num_DY,'Visible','off')
[204]347        end
[581]348        if  isequal(ProjMode,'interp_lin')
[379]349            set(handles.num_DZ,'Visible','on') 
[204]350        end
351     case {'volume'} 
[379]352        set(handles.num_RangeX_1,'Visible','on')
353        set(handles.num_RangeX_2,'Visible','on')
354        set(handles.num_RangeY_1,'Visible','on')
355        set(handles.num_RangeY_2,'Visible','on')
[204]356        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
357        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
[379]358        set(handles.num_Angle_1,'Visible','on')
359        set(handles.num_Angle_2,'Visible','on')
360        set(handles.num_Angle_3,'Visible','on')
361        set(handles.num_RangeZ_1,'Visible','on')
362        set(handles.num_RangeZ_2,'Visible','on')
[581]363        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[379]364            set(handles.num_DX,'Visible','on')
365            set(handles.num_DY,'Visible','on')
366            set(handles.num_DZ,'Visible','on')
[204]367        else
[379]368            set(handles.num_DX,'Visible','off')
369            set(handles.num_DY,'Visible','off')
370            set(handles.num_DZ,'Visible','off')
[204]371        end
372end
373%------------------------------------------------------------------------
374
375%------------------------------------------------------------------------
[379]376function num_Angle_1_Callback(hObject, eventdata, handles)
[204]377update_slider(hObject, eventdata,handles)
378%------------------------------------------------------------------------
379%------------------------------------------------------------------------
[379]380function num_Angle_2_Callback(hObject, eventdata, handles)
[204]381update_slider(hObject, eventdata,handles)
382%------------------------------------------------------------------------
383function update_slider(hObject, eventdata,handles)
384%rotation angles
[379]385PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first  angle in degrees
386PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second  angle in degrees
387PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second  angle in degrees
[212]388om=norm(PlaneAngle);%norm of rotation angle in radians
389OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
390cos_om=cos(pi*om/180);
391sin_om=sin(pi*om/180);
392coeff=OmAxis(3)*(1-cos_om);
393%components of the unity vector norm_plane normal to the projection plane
394norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
395norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
396norm_plane(3)=OmAxis(3)*coeff+cos_om;
[204]397huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
398UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
399if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
[212]400    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
[204]401    set(handles.z_slider,'Min',min(Z))
402    set(handles.z_slider,'Max',max(Z))
403    ZMax_Callback(hObject, eventdata, handles)
404end
405%------------------------------------------------------------------------
[379]406function num_DX_Callback(hObject, eventdata, handles)
[204]407%------------------------------------------------------------------------
408%------------------------------------------------------------------------
[379]409function num_DY_Callback(hObject, eventdata, handles)
[204]410%------------------------------------------------------------------------
411%------------------------------------------------------------------------
[379]412function num_DZ_Callback(hObject, eventdata, handles)
[204]413%------------------------------------------------------------------------
414
415
416%------------------------------------------------------------------------
[432]417% --- Executes on button press in PLOT: refresh the current object , plot the object and its projected field
[204]418function PLOT_Callback(hObject, eventdata, handles)
419
[508]420set(handles.PLOT,'BackgroundColor',[1 1 0])
421drawnow
422
[630]423%% update the object in the GUI series if relevant
424if strcmp(get(handles.set_object,'Name'),'edit_object_series')
425    hseries=findobj(allchild(0),'Tag','series');
426    if ~isempty(hseries)
427        SeriesData=get(hseries,'UserData');
428    SeriesData.ProjObject=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
429    set(hseries,'UserData',SeriesData);
430    end
431    set(handles.PLOT,'BackgroundColor',[1 0 0])
432    return
433end
434
[410]435%% read the object parameters in the GUI set_object
[388]436ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
[397]437if iscell(ObjectData.Coord)%check for empty line
438    ObjectData.Coord=[0 0 0];
439    hhset_object=guidata(handles.set_object);
440    set(hhset_object.Coord,'Data',ObjectData.Coord)
441end
[388]442checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines
443if ~isempty(checknan)
444    ObjectData.Coord(checknan,:)=[];%remove the NaN lines
445end
[402]446ObjectName=ObjectData.Name;%name of the current object defined in set_object
[309]447if isempty(ObjectName)
[432]448     ObjectName=ObjectData.Type;% name the object by the object type type by default
[204]449end
[413]450
[432]451%% read the current object selection in the GUI uvmat
[413]452huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle
453UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
454hhuvmat=guidata(huvmat);%handles of the objects children of the  GUI uvmat
[432]455ListObject=get(hhuvmat.ListObject,'String');% list of objects displayed in uvmat
[625]456
457if isequal(get(hhuvmat.edit_object,'Value'),0) %we append a new object
458    ListObject=[ListObject;{''}];
459    IndexObj=length(ListObject);
460    set(hhuvmat.ListObject,'String',ListObject)
461    set(hhuvmat.ListObject,'Value',IndexObj)
462    UvData.ProjObject{IndexObj}=[]; %create a new empty object
463    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
464    UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
[630]465else   
[625]466    IndexObj=get(hhuvmat.ListObject,'Value');% index of the selected object for display in uvmat
467end
468
[630]469%set or modify(edit mode) the name of the currently selected object
[445]470detectname=1;
471ObjectNameNew=ObjectName;
472vers=0;% index of the name
473ListOther=ListObject;
474ListOther(IndexObj)=[];
475while ~isempty(detectname)
476    detectname=find(strcmp(ObjectNameNew,ListOther),1);%test the existence of the proposed name in the list
477    if detectname% if the object name already exists
478        indstr=regexp(ObjectNameNew,'\D');%indices of non number characters
479        if indstr(end)<length(ObjectNameNew) %object name ends by a number
480            vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
481            ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
482        else
483            vers=vers+1;
484            ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
[204]485        end
486    end
[445]487end
488ObjectName=ObjectNameNew;
489set(handles.Name,'String',ObjectName)% display the default name in set_object
490ListObject{IndexObj}=ObjectName;
491set(hhuvmat.ListObject,'String',ListObject);%complement the object list
[625]492set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
[445]493set(hhuvmat.ViewObject,'Value',1)% indicate that the currently selected objected is viewed on set_object
[622]494check_handle=isfield(UvData.ProjObject{IndexObj},'DisplayHandle') && isfield(UvData.ProjObject{IndexObj}.DisplayHandle,'uvmat')...
495    && ~isempty(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat) && ishandle(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat);
[445]496if check_handle
[622]497    obj_handle=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
[445]498end
[622]499UvData.ProjObject{IndexObj}=ObjectData;%record the current object properties in uvmat
[445]500if check_handle
[622]501    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=obj_handle; %preserve the object plot handle if valid
[445]502else
[622]503    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; %axes taken as object display handle by defualt
[204]504end
[309]505
[413]506%% plot the field projected on the object
[432]507hview_field=[];%default
[445]508IndexObj_1=get(hhuvmat.ListObject_1,'Value');
[388]509if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none')
510    PlotType='text';
511else
[581]512    % create tps coeff if needed for ProjMode 'interp_tps'
[586]513    if strcmp(ObjectData.ProjMode,'interp_tps')&&~isfield(UvData.Field,'Coord_tps')
514        %UvData.Field=calc_tps(UvData.Field,1);
515        [UvData.Field,errormsg]=tps_coeff_field(UvData.Field,1);
516        if ~isempty(errormsg)
517            msgbox_uvmat('ERROR', ['set_object/tps_coeff_field/' errormsg])
518            set(handles.PLOT,'enable','on')
519            return
520        end
[508]521    end
[388]522    [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
523    if ~isempty(errormsg)
[586]524        msgbox_uvmat('ERROR', ['set_object/proj_field/' errormsg])
[508]525        set(handles.PLOT,'enable','on')
[388]526        return
[586]527    end
[445]528    if isequal(IndexObj_1,IndexObj) % if  the projection is in uvmat
[586]529        PlotType=plot_field(ProjData,hhuvmat.PlotAxes,read_GUI(get(hhuvmat.PlotAxes,'parent')));%update the current uvmat plot
[491]530    else  % if the projection is in view_field
[413]531        hview_field=findobj(allchild(0),'tag','view_field');
532        if isempty(hview_field)
[429]533            hview_field=view_field(ProjData); %open the view_field GUI for plot
[413]534        else
535            hhview_field=guidata(hview_field);
[511]536            [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%update an existing  plot in view_field
[591]537            errormsg=fill_GUI(PlotParam,hview_field);
[569]538            if ~isempty(errormsg)
539                msgbox_uvmat('ERROR',errormsg)
540                return
541            end
[586]542            %     write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
[413]543        end
[429]544        haxes=findobj(hview_field,'tag','axes3');
545        Data=get(hview_field,'UserData');
546        if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
547            h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
548            pos_table=get(h_TableDisplay,'Position');
549            pos=get(hview_field,'Position');
550            set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
551            drawnow
552            set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing
553        else
554            set(hview_field,'Position',Data.GUISize)
555        end
[586]556        %  set(hhuvmat.ViewField,'Value',1)% indicate that the field projection on the current object is plotted in view_field
[388]557    end
[227]558end
[429]559
[432]560%% update the object plot
[622]561hobject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
[445]562% if we are editing the object used for projection in uvmat
563if isequal(IndexObj_1,IndexObj)
564    %update the representation of the current object for projection field represented in view_field
[622]565    for iobj=1:numel(UvData.ProjObject)
566        UvData.ProjObject{iobj}.DisplayHandle.uvmat=...
567            plot_object(UvData.ProjObject{iobj},UvData.ProjObject{IndexObj_1},UvData.ProjObject{iobj}.DisplayHandle.uvmat,'b');
[432]568    end
[445]569else %  we are editing the object used for projection field represented in view_field
570    %update the representation of the current object in uvmat
[622]571    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=...
572             plot_object(UvData.ProjObject{IndexObj},UvData.ProjObject{IndexObj_1},UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'m');
[445]573    %indicate the object index in the user data of the object plot (needed for further mouse editing)
[622]574    ObjectInfo=get(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'UserData');
[445]575    ObjectInfo.IndexObj=IndexObj;
[622]576    set(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'UserData',ObjectInfo)
[445]577    % update the representation of all objects in view_field
[622]578    for iobj=1:numel(UvData.ProjObject)
579        if isfield(UvData.ProjObject{iobj}.DisplayHandle,'view_field')
580            UvData.ProjObject{iobj}.DisplayHandle.view_field=...
581                plot_object(UvData.ProjObject{iobj},UvData.ProjObject{iobj},UvData.ProjObject{iobj}.DisplayHandle.view_field,'b');
[445]582        end
[432]583    end
584end
585set(huvmat,'UserData',UvData)
586
[204]587%% update the GUI uvmat
[627]588% set(hhuvmat.MenuEditObject,'enable','on')
[204]589set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
[625]590%set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
[427]591set(hhuvmat.ViewField,'Value',1)
[508]592% set(handles.PLOT,'enable','on')
593set(handles.PLOT,'BackgroundColor',[1 0 0])
[204]594%------------------------------------------------------------------------
595% --- Executes on button press in MenuCoord.
596function MenuCoord_Callback(hObject, eventdata, handles)
597%------------------------------------------------------------------------
598%----------------------------------------------------
[379]599function num_RangeY_1_Callback(hObject, eventdata, handles)
[204]600%------------------------------------------------------------------------
601
[379]602function num_RangeZ_1_Callback(hObject, eventdata, handles)
[204]603%------------------------------------------------------------------------
604
[379]605function num_RangeZ_2_Callback(hObject, eventdata, handles)
606DZ=str2num(get(handles.num_RangeZ_2,'String'));
[204]607ZMin=get(handles.z_slider,'Min');
608ZMax=get(handles.z_slider,'Max');
609if ~isequal(ZMax-ZMin,0)
610    rel_step(1)=DZ/(ZMax-ZMin);
611    rel_step(2)=0.2;
612    set(handles.z_slider,'SliderStep',rel_step)
613end
614%------------------------------------------------------------------------
[379]615function num_RangeY_2_Callback(hObject, eventdata, handles)
[204]616%------------------------------------------------------------------------
617
[379]618function num_RangeX_1_Callback(hObject, eventdata, handles)
[204]619%------------------------------------------------------------------------
620
[379]621function num_RangeX_2_Callback(hObject, eventdata, handles)
[204]622%------------------------------------------------------------------------
623%------------------------------------------------------------------------
624function SAVE_Callback(hObject, eventdata, handles)
625% ------------------------------------------------------
[379]626%Object=read_set_object(handles);
627Object=read_GUI(handles.set_object);
[204]628huvmat=findobj('Tag','uvmat');
629% UvData=get(huvmat,'UserData');
630if isempty(huvmat)
631    huvmat=findobj(allchild(0),'Name','series');
632end
633hchild=get(huvmat,'Children');
634hrootpath=findobj(hchild,'Tag','RootPath');
635if isempty(hrootpath)
636    RootPath='';
637else
638    RootPath=get(hrootpath,'String');
639    if iscell(RootPath)
640        RootPath=RootPath{1};
641    end
642end
643title={'object name'};
644dir_save=uigetdir(RootPath);
[379]645ObjectName=get(handles.Name,'String');
[204]646if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
647    def={fullfile(dir_save,[ObjectName '.xml'])};
648else
649    def={fullfile(dir_save,[Object.Style '.xml'])};
650end
651displ_txt='save object as an .xml file';%default display
652menu=get(handles.ProjMode,'String');
653value=get(handles.ProjMode,'Value');
654ProjMode=menu{value};
655if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
656    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
657end
658answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
659if ~isempty(answer)
660    t=struct2xml(Object);
[477]661    t=set(t,1,'name','ProjObject');
[204]662    save(t,answer{1})
663end
664msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
[227]665
[204]666%------------------------------------------------------------------------
667% --- Executes on slider movement.
668function z_slider_Callback(hObject, eventdata, handles)
669%---------------------------------------------------------
670Z_value=get(handles.z_slider,'Value');
671%rotation angles
[227]672PlaneAngle=[0 0 0];
673norm_plane=[0 0 1];
674cos_om=1;
675sin_om=0;
676
[379]677PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
678PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
679PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
[227]680PlaneAngle=(pi/180)*PlaneAngle;
[212]681om=norm(PlaneAngle);%norm of rotation angle in radians
[227]682if isequal(om,0)
683    norm_plane=[0 0 1];
684else
685    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
686    cos_om=cos(om);
687    sin_om=sin(om);
688    coeff=OmAxis(3)*(1-cos_om);
689    %components of the unity vector norm_plane normal to the projection plane
690    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
691    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
692    norm_plane(3)=OmAxis(3)*coeff+cos_om;
693end
[204]694
[388]695% update graph
[204]696PLOT_Callback(hObject, eventdata, handles)
[227]697
[204]698%------------------------------------------------------------------------
699% --- Executes on button press in HELP.
700function HELP_Callback(hObject, eventdata, handles)
[227]701%------------------------------------------------------------------------
[646]702web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#a6-Projectionobjects:')
703% path_to_uvmat=which ('uvmat');% check the path of uvmat
704% pathelp=fileparts(path_to_uvmat);
705% helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
706% if ~isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
707%     addpath (fullfile(pathelp,'uvmat_doc'))
708%     web([helpfile '#set_object'])
709% end
[204]710%------------------------------------------------------------------------
711
[379]712function Name_Callback(hObject, eventdata, handles)
713% hObject    handle to Name (see GCBO)
714% eventdata  reserved - to be defined in a future version of MATLAB
715% handles    structure with handles and user data (see GUIDATA)
[204]716
[379]717% Hints: get(hObject,'String') returns contents of Name as text
718%        str2double(get(hObject,'String')) returns contents of Name as a double
719
720%------------------------------------------------------------------------
721% --- Executes when entered data in editable cell(s) in Coord.
722function Coord_CellEditCallback(hObject, eventdata, handles)
723%------------------------------------------------------------------------
724ListType=get(handles.Type,'String');
725Type=ListType{get(handles.Type,'Value')};
726switch Type
727    % add lines if multi line input needed
728    case{'points','polyline','polygon'}
729        Coord=get(handles.Coord,'Data');
[388]730        if ~isnan(Coord(end,1))
731            if isequal(size(Coord,2),3)
732                %Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case)
733                Coord=[Coord;NaN NaN NaN]; %add a line for edition (3D case)
734            else
735                Coord=[Coord;NaN NaN]; %add a line for edition (2D case)
736            end
737            set(handles.Coord,'Data',Coord)
[379]738        end
739end
740
741
742
743function num_Angle_3_Callback(hObject, eventdata, handles)
744% hObject    handle to num_Angle_3 (see GCBO)
745% eventdata  reserved - to be defined in a future version of MATLAB
746% handles    structure with handles and user data (see GUIDATA)
747
748% Hints: get(hObject,'String') returns contents of num_Angle_3 as text
749%        str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double
Note: See TracBrowser for help on using the repository browser.