source: trunk/src/set_object.m @ 844

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