[37] | 1 | %'create_grid': associated with GUI create_grid.fig to display message boxes, for error, warning or input calls
|
---|
| 2 | % create_grid(title,display)
|
---|
| 3 | %
|
---|
| 4 | % OUTPUT:
|
---|
| 5 | % answer (text string)= 'yes', 'No', 'cancel', or the text string introduced as input
|
---|
| 6 | %
|
---|
| 7 | %INPUT:
|
---|
| 8 | % title: string indicating the type of message box:
|
---|
| 9 | % title= 'INPUT_TXT','CONFIMATION' ,'ERROR', 'WARNING', 'INPUT_Y-N', default = 'INPUT_TXT' (the title is displayed in the upper bar of the fig).
|
---|
| 10 | % if title='INPUT_TXT', input data is asked in an edit box
|
---|
| 11 | % if title='CONFIMATION'', 'ERROR', 'WARNING', the figure remains opened until a button 'OK' is pressed
|
---|
| 12 | % if title='INPUT_Y-N', an answer Yes/No is requested
|
---|
| 13 | % display, displayed text
|
---|
| 14 | % default_answer: default answer in the edit box (only used with title='INPUT_TXT')
|
---|
| 15 |
|
---|
| 16 | function varargout = create_grid(varargin)
|
---|
| 17 |
|
---|
| 18 | % Last Modified by GUIDE v2.5 05-Mar-2010 21:57:44
|
---|
| 19 |
|
---|
| 20 | % Begin initialization code - DO NOT EDIT
|
---|
| 21 | gui_Singleton = 1;
|
---|
| 22 | gui_State = struct('gui_Name', mfilename, ...
|
---|
| 23 | 'gui_Singleton', gui_Singleton, ...
|
---|
| 24 | 'gui_OpeningFcn', @create_grid_OpeningFcn, ...
|
---|
| 25 | 'gui_OutputFcn', @create_grid_OutputFcn, ...
|
---|
| 26 | 'gui_LayoutFcn', [] , ...
|
---|
| 27 | 'gui_Callback', []);
|
---|
| 28 | if nargin && ischar(varargin{1})
|
---|
| 29 | gui_State.gui_Callback = str2func(varargin{1});
|
---|
| 30 | end
|
---|
| 31 |
|
---|
| 32 | if nargout
|
---|
| 33 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
|
---|
| 34 | else
|
---|
| 35 | gui_mainfcn(gui_State, varargin{:});
|
---|
| 36 | end
|
---|
| 37 | % End initialization code - DO NOT EDIT
|
---|
| 38 |
|
---|
| 39 | %------------------------------------------------------------------------
|
---|
| 40 | % --- Executes just before create_grid is made visible.
|
---|
| 41 | function create_grid_OpeningFcn(hObject, eventdata, handles,input_grid)
|
---|
| 42 | %------------------------------------------------------------------------
|
---|
| 43 | % This function has no output args, see OutputFcn.
|
---|
| 44 |
|
---|
| 45 | % Choose default command line output for create_grid
|
---|
| 46 | handles.output = 'Cancel';
|
---|
| 47 |
|
---|
| 48 | % Update handles structure
|
---|
| 49 | guidata(hObject, handles);
|
---|
| 50 | testNo=0;
|
---|
| 51 | testCancel=1;
|
---|
| 52 | testinputstring=0;
|
---|
| 53 | icontype='quest';%default question icon (text input asked)
|
---|
| 54 |
|
---|
| 55 | % Determine the position of the dialog - centered on the screen
|
---|
| 56 | FigPos=get(0,'DefaultFigurePosition');
|
---|
| 57 | OldUnits = get(hObject, 'Units');
|
---|
| 58 | set(hObject, 'Units', 'pixels');
|
---|
| 59 | OldPos = get(hObject,'Position');
|
---|
| 60 | FigWidth = OldPos(3);
|
---|
| 61 | FigHeight = OldPos(4);
|
---|
| 62 | ScreenUnits=get(0,'Units');
|
---|
| 63 | set(0,'Units','pixels');
|
---|
| 64 | ScreenSize=get(0,'ScreenSize');
|
---|
| 65 | set(0,'Units',ScreenUnits);
|
---|
| 66 |
|
---|
| 67 | FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
|
---|
| 68 | FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
|
---|
| 69 | FigPos(3:4)=[FigWidth FigHeight];
|
---|
| 70 | set(hObject, 'Position', FigPos);
|
---|
| 71 | set(hObject, 'Units', OldUnits);
|
---|
| 72 |
|
---|
| 73 | % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
|
---|
| 74 | load dialogicons.mat
|
---|
| 75 | eval(['IconData=' icontype 'IconData;'])
|
---|
| 76 | eval(['IconCMap=' icontype 'IconMap;'])
|
---|
| 77 | questIconMap(256,:) = get(handles.figure1, 'Color');
|
---|
| 78 | Img=image(IconData, 'Parent', handles.axes1);
|
---|
| 79 | set(handles.figure1, 'Colormap', IconCMap);
|
---|
| 80 | set(handles.axes1, ...
|
---|
| 81 | 'Visible', 'off', ...
|
---|
| 82 | 'YDir' , 'reverse' , ...
|
---|
| 83 | 'XLim' , get(Img,'XData'), ...
|
---|
| 84 | 'YLim' , get(Img,'YData') ...
|
---|
| 85 | );
|
---|
| 86 |
|
---|
| 87 | if exist('input_grid','var') && ~isempty(input_grid)
|
---|
| 88 | if isfield(input_grid,'x_0')
|
---|
| 89 | set(handles.x_0,'String',num2str(input_grid.x_0));
|
---|
| 90 | end
|
---|
| 91 | if isfield(input_grid,'x_1')
|
---|
| 92 | set(handles.x_1,'String',num2str(input_grid.x_1));
|
---|
| 93 | end
|
---|
| 94 | if isfield(input_grid,'Dx')
|
---|
| 95 | set(handles.Dx,'String',num2str(input_grid.Dx));
|
---|
| 96 | end
|
---|
| 97 | if isfield(input_grid,'y_0')
|
---|
| 98 | set(handles.x_0,'String',num2str(input_grid.x_0));
|
---|
| 99 | end
|
---|
| 100 | if isfield(input_grid,'y_1')
|
---|
| 101 | set(handles.x_1,'String',num2str(input_grid.x_1));
|
---|
| 102 | end
|
---|
| 103 | if isfield(input_grid,'Dy')
|
---|
| 104 | set(handles.Dx,'String',num2str(input_grid.Dx));
|
---|
| 105 | end
|
---|
| 106 | if isfield(input_grid,'z')
|
---|
| 107 | set(handles.z,'String',num2str(input_grid.z));
|
---|
| 108 | end
|
---|
| 109 | end
|
---|
| 110 |
|
---|
| 111 | set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
|
---|
| 112 | % UIWAIT makes create_grid wait for user response (see UIRESUME)
|
---|
| 113 | uiwait(handles.figure1);
|
---|
| 114 |
|
---|
| 115 | %------------------------------------------------------------------------
|
---|
| 116 | % --- Outputs from this function are returned to the command line.
|
---|
| 117 | function varargout = create_grid_OutputFcn(hObject, eventdata, handles)
|
---|
| 118 | %------------------------------------------------------------------------
|
---|
| 119 | % Get default command line output from handles structure
|
---|
| 120 | varargout{1}=[0 0 0];%default
|
---|
| 121 | if ~isequal(handles.output,'Cancel')
|
---|
| 122 | x_0=str2num(get(handles.x_0,'String'));
|
---|
| 123 | Dx=str2num(get(handles.Dx,'String'));
|
---|
| 124 | x_1=str2num(get(handles.x_1,'String'));
|
---|
| 125 | xarray=[x_0:Dx:x_1];
|
---|
| 126 | y_0=str2num(get(handles.y_0,'String'));
|
---|
| 127 | Dy=str2num(get(handles.Dy,'String'));
|
---|
| 128 | y_1=str2num(get(handles.y_1,'String'));
|
---|
| 129 | yarray=[y_0:Dy:y_1];
|
---|
| 130 | [yarray,xarray]=meshgrid(yarray,xarray);
|
---|
| 131 | xarray=reshape(xarray,numel(xarray),1);
|
---|
| 132 | yarray=reshape(yarray,numel(yarray),1);
|
---|
| 133 | z_0=str2num(get(handles.z_0,'String'));
|
---|
| 134 | if isempty(z_0)
|
---|
| 135 | z_0=0;
|
---|
| 136 | end
|
---|
| 137 | zarray=z_0*ones(size(yarray));
|
---|
| 138 | varargout{1}=[xarray yarray zarray];
|
---|
| 139 | % if ~isempty(x_shift)
|
---|
| 140 | % varargout{1}(1)=x_shift;
|
---|
| 141 | % end
|
---|
| 142 | % if ~isempty(y_shift)
|
---|
| 143 | % varargout{1}(2)=y_shift;
|
---|
| 144 | % end
|
---|
| 145 | % if ~isempty(z_shift)
|
---|
| 146 | % varargout{1}(3)=z_shift;
|
---|
| 147 | % end
|
---|
| 148 | end
|
---|
| 149 | % The figure can be deleted now
|
---|
| 150 | delete(handles.figure1);
|
---|
| 151 |
|
---|
| 152 | %------------------------------------------------------------------------
|
---|
| 153 | % --- Executes on button press in OK.
|
---|
| 154 | function OK_Callback(hObject, eventdata, handles)
|
---|
| 155 | %------------------------------------------------------------------------
|
---|
| 156 | handles.output = get(hObject,'String');
|
---|
| 157 | guidata(hObject, handles);% Update handles structure
|
---|
| 158 | uiresume(handles.figure1);
|
---|
| 159 |
|
---|
| 160 | %------------------------------------------------------------------------
|
---|
| 161 | % --- Executes on button press in Cancel.
|
---|
| 162 | function Cancel_Callback(hObject, eventdata, handles)
|
---|
| 163 | %------------------------------------------------------------------------
|
---|
| 164 | handles.output = get(hObject,'String');
|
---|
| 165 | guidata(hObject, handles); % Update handles structure
|
---|
| 166 | uiresume(handles.figure1);
|
---|
| 167 |
|
---|
| 168 | %------------------------------------------------------------------------
|
---|
| 169 | % --- Executes when user attempts to close figure1.
|
---|
| 170 | function figure1_CloseRequestFcn(hObject, eventdata, handles)
|
---|
| 171 | %------------------------------------------------------------------------
|
---|
| 172 | if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
|
---|
| 173 | % The GUI is still in UIWAIT, us UIRESUME
|
---|
| 174 | uiresume(handles.figure1);
|
---|
| 175 | else
|
---|
| 176 | % The GUI is no longer waiting, just close it
|
---|
| 177 | delete(handles.figure1);
|
---|
| 178 | end
|
---|
| 179 |
|
---|
| 180 | %------------------------------------------------------------------------
|
---|
| 181 | % --- Executes on key press over figure1 with no controls selected.
|
---|
| 182 | function figure1_KeyPressFcn(hObject, eventdata, handles)
|
---|
| 183 | %------------------------------------------------------------------------
|
---|
| 184 | % Check for "enter" or "escape"
|
---|
| 185 | if isequal(get(hObject,'CurrentKey'),'escape')
|
---|
| 186 | % User said no by hitting escape
|
---|
| 187 | handles.output = 'Cancel';
|
---|
| 188 |
|
---|
| 189 | % Update handles structure
|
---|
| 190 | guidata(hObject, handles);
|
---|
| 191 |
|
---|
| 192 | uiresume(handles.figure1);
|
---|
| 193 | end
|
---|
| 194 | if isequal(get(hObject,'CurrentKey'),'return')
|
---|
| 195 | uiresume(handles.figure1);
|
---|
| 196 | end
|
---|
| 197 |
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 |
|
---|