Index: trunk/src/dataview.m
===================================================================
--- trunk/src/dataview.m	(revision 2)
+++ trunk/src/dataview.m	(revision 12)
@@ -1,3 +1,3 @@
-%TEST 'dataview': function for scanning directories in a campaign (TEST)
+%'dataview': function for scanning directories in a campaign 
 %------------------------------------------------------------------------
 % function varargout = series(varargin)
@@ -22,5 +22,5 @@
 function varargout = dataview(varargin)
 
-% Last Modified by GUIDE v2.5 28-Apr-2009 00:12:36
+% Last Modified by GUIDE v2.5 13-Jan-2010 07:28:19
 
 % Begin initialization code - DO NOT EDIT
@@ -32,5 +32,5 @@
                    'gui_LayoutFcn',  [] , ...
                    'gui_Callback',   []);
-if nargin & isstr(varargin{1})
+if nargin & ischar(varargin{1})
     gui_State.gui_Callback = str2func(varargin{1});
 end
@@ -45,28 +45,82 @@
 
 % --- Executes just before dataview is made visible.
-function dataview_OpeningFcn(hObject, eventdata, handles, varargin)
+function dataview_OpeningFcn(hObject, eventdata, handles, RootDir, SubCampaignTst,GeometryCalib)
 
 % Choose default command line output for dataview
-handles.output = hObject;
+handles.output = 'Cancel';
 
 % Update handles structure
 guidata(hObject, handles);
-
-%----------------------------------------------------------------
+testCancel=1;
+testinputstring=0;
+icontype='quest';%default question icon (text input asked)
+
+% Determine the position of the dialog - centered on the screen
+FigPos=get(0,'DefaultFigurePosition');
+OldUnits = get(hObject, 'Units');
+set(hObject, 'Units', 'pixels');
+OldPos = get(hObject,'Position');
+FigWidth = OldPos(3);
+FigHeight = OldPos(4);
+ScreenUnits=get(0,'Units');
+set(0,'Units','pixels');
+ScreenSize=get(0,'ScreenSize');
+set(0,'Units',ScreenUnits);
+
+FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
+FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
+FigPos(3:4)=[FigWidth FigHeight];
+set(hObject, 'Position', FigPos);
+set(hObject, 'Units', OldUnits);
+
+% % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
+% load dialogicons.mat
+% eval(['IconData=' icontype 'IconData;'])
+% eval(['IconCMap=' icontype 'IconMap;'])
+% questIconMap(256,:) = get(handles.figure1, 'Color');
+% Img=image(IconData, 'Parent', handles.axes1);
+% set(handles.figure1, 'Colormap', IconCMap);
+% set(handles.axes1, ...
+%     'Visible', 'off', ...
+%     'YDir'   , 'reverse'       , ...
+%     'XLim'   , get(Img,'XData'), ...
+%     'YLim'   , get(Img,'YData')  ...
+%     );
+if exist('GeometryCalib','var')
+    DataviewData.GeometryCalib=GeometryCalib;
+    set(hObject,'UserData',DataviewData)
+end
+if exist('SubCampaignTst','var') && isequal(SubCampaignTst,'y')
+   set(handles.SubCampaignTest,'Value',1);
+end
+if exist('RootDir','var') 
+   set(handles.RootDirectory,'String',RootDir);
+   set(handles.clean_civ_cmx,'Visible','off')
+   set(handles.edit_xml,'Visible','off')
+   set(handles.HELP,'Visible','off')
+   set(handles.OK,'Visible','on')
+   set(handles.Cancel,'Visible','on')
+   set(handles.figure,'WindowStyle','modal')% Make% Make the GUI modal 
+   RootDirectory_Callback(hObject, eventdata, handles)
+   % UIWAIT makes translate_points wait for user response (see UIRESUME)
+   uiwait(handles.figure);
+end
+
+
+
+%------------------------------------------------------------------------
 % --- Outputs from this function are returned to the command line.
 function varargout = dataview_OutputFcn(hObject, eventdata, handles)
-
+%------------------------------------------------------------------------
 % Get default command line output from handles structure
 varargout{1} = handles.output;
-
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%------------------------------------------------------
+delete(handles.figure)
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%------------------------------------------------------------------------
 % --- Executes on button press in browser.
 function browser_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------   
-
-CurrentFile='/coriolis/bigone/PROJETS';%get(handles.RootDirectory,'String');
+%------------------------------------------------------------------------
+CurrentFile='/raid/PROJETS';%get(handles.RootDirectory,'String');
 set(handles.SubCampaignTest,'Value',0)
 CampaignDir=uigetdir(CurrentFile,'Open the Campaign directory'); %file browser
@@ -74,6 +128,8 @@
 RootDirectory_Callback(hObject, eventdata, handles)
 
+%------------------------------------------------------------------------
 % --- Executes on button press in open_SubCampaign.
 function OpenSubCampaign_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 CurrentFile='/coriolis/bigone/PROJETS';%get(handles.RootDirectory,'String');
 set(handles.SubCampaignTest,'Value',1)
@@ -84,7 +140,8 @@
 
 %------------------------------------------------------------------------
-
 function RootDirectory_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 CampaignDir=get(handles.RootDirectory,'String');
+ExpName={''};
 if exist(CampaignDir,'dir')
     hdir=dir(CampaignDir); %list files and dirs
@@ -106,5 +163,5 @@
     ListExperiments_Callback(hObject, eventdata, handles)
 else
-    warndlg_uvmat(['The input ' CampaignDir ' is not a directory'],'ERROR')
+    msgbox_uvmat('ERROR',['The input ' CampaignDir ' is not a directory'])
 end
 
@@ -112,4 +169,5 @@
 % --- Executes on selection change in ListExperiments.
  function ListExperiments_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
 CurrentPath=get(handles.RootDirectory,'String');
 ListExperiments=get(handles.ListExperiments,'String');
@@ -131,9 +189,10 @@
 set(handles.ListXml,'String',[{'*'};ListXml'])
 if testList
-    hh=get(handles.ListExperiments,'parent');
-    set(hh,'UserData',List)
+    DataviewData=get(handles.figure,'UserData');
+    DataView.List=List;
+    set(handles.figure,'UserData',DataviewData)
 end
 set(handles.CampaignDoc,'Visible','on')
-set(handles.edit_xml,'Visible','on')
+% set(handles.edit_xml,'Visible','on')
 
 %------------------------------------------------------------------------
@@ -184,6 +243,6 @@
 set(handles.ListExperiments,'Value',1)
 ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
-hh=get(handles.CampaignDoc,'parent');
-List=get(hh,'UserData');
+DataviewData=get(handles.figure,'UserData');
+List=DataviewData.List;
 Currentpath=get(handles.RootDirectory,'String');
 [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
@@ -422,4 +481,5 @@
 end
 
+%------------------------------------------------------------------------
 % --- Executes on button press in HELP.
 function HELP_Callback(hObject, eventdata, handles)
@@ -427,14 +487,9 @@
 pathelp=fileparts(path_to_uvmat);
 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
-if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
 else
 web([helpfile '#dataview'])    
 end
 
-
-
-
-% --- Executes on button press in SubCampaignTest.
-function SubCampaignTest_Callback(hObject, eventdata, handles)
 
 
@@ -456,6 +511,6 @@
 set(handles.ListExperiments,'Value',1)
 ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
-hh=get(handles.CampaignDoc,'parent');
-List=get(hh,'UserData');
+DataviewData=get(handles.figure,'UserData');
+List=DataviewData.List;
 Currentpath=get(handles.RootDirectory,'String');
 [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
@@ -510,4 +565,164 @@
 
 
-
-
+% --- Executes on button press in OK.
+function OK_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+CurrentPath=get(handles.RootDirectory,'String');
+ListExperiments=get(handles.ListExperiments,'String');
+IndicesExp=get(handles.ListExperiments,'Value');
+if ~isequal(IndicesExp,1)
+    ListExperiments=ListExperiments(IndicesExp);
+end
+ListDevices=get(handles.ListDevices,'String');
+Value=get(handles.ListDevices,'Value');
+if isequal(Value,1)
+    msgbox_uvmat('ERROR','manually select in the GUI dataview the device being calibrated')
+    return
+else 
+    ListDevices=ListDevices(Value);
+end
+ListRecords=get(handles.ListRecords,'String');
+Value=get(handles.ListRecords,'Value');
+if ~isequal(Value,1)
+    ListRecords=ListRecords(Value);
+end
+[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
+ListXml=get(handles.ListXml,'String');
+Value=get(handles.ListXml,'Value');
+if isequal(Value,1)
+    msgbox_uvmat('ERROR','you need to select in the GUI dataview the xml files to edit')
+    return
+else
+    ListXml=ListXml(Value);
+end
+
+%update all the selected xml files
+DataviewData=get(handles.figure,'UserData');
+% answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' ...
+%     DataviewData.GeometryCalib.CalibrationType ' calibration data'])
+% if ~isequal(answer,'Yes')
+%     return
+% end
+%List.Experiment{1}.Device{1}
+%List.Experiment{2}.Device{1}
+for iexp=1:length(List.Experiment)
+    ExpName=List.Experiment{iexp}.name;
+    set(handles.ListExperiments,'Value',IndicesExp(iexp));
+    if isfield(List.Experiment{iexp},'Device')
+        for idevice=1:length(List.Experiment{iexp}.Device)
+            DeviceName=List.Experiment{iexp}.Device{idevice}.name;      
+            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
+                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
+                    for ilistxml=1:length(ListXml)
+                        if isequal(FileName,ListXml{ilistxml})
+                            set(handles.ListXml,'Value',Value(ilistxml))
+                            drawnow
+                            xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
+                            update_imadoc(DataviewData.GeometryCalib,xmlfullname)
+                            display([xmlfullname ' updated'])
+                            break
+                        end
+                    end
+                end
+             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
+                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
+                            for ilistxml=1:length(ListXml)
+                                if isequal(FileName,ListXml{ilistxml})
+                                    set(handles.ListXml,'Value',Value(ilistxml))
+                                    drawnow
+                                    xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
+                                    update_imadoc(DataviewData.GeometryCalib,xmlfullname)
+                                    display([xmlfullname ' updated'])
+                                    break
+                                end
+                            end
+                        end
+                    end
+                end
+            end
+        end
+    end
+end
+set(handles.ListXml,'Value',Value)   
+%     
+%     
+%     
+%     
+%     
+%     
+%     
+% CurrentPath=get(handles.RootDirectory,'String');%= get(hObject,'String');
+% ListExperiments=get(handles.ListExperiments,'String');
+% Value=get(handles.ListExperiments,'Value');
+% if ~isequal(Value,1)
+%     ListExperiments=ListExperiments(Value);
+% end
+% ListDevices=get(handles.ListDevices,'String');
+% Value=get(handles.ListDevices,'Value');
+% if isequal(Value,1)
+%     msgbox_uvmat('ERROR','manually select in the GUI dataview the device being calibrated')
+%     return
+% else 
+%     ListDevices=ListDevices(Value);
+% end
+% ListRecords=get(handles.ListRecords,'String');
+% Value=get(handles.ListRecords,'Value');
+% if ~isequal(Value,1)
+%     ListRecords=ListRecords(Value);
+% end
+% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
+% ListXml=get(handles.ListXml,'String');
+% Value=get(handles.ListXml,'Value');
+% if isequal(Value,1)
+%     msgbox_uvmat('ERROR','you need to select in the GUI dataview the xml files to edit')
+%     return
+% else
+%     ListXml=ListXml(Value);
+% end
+% handles.output.CurrentPath=CurrentPath;
+% handles.output.ListExperiments=ListExperiments;
+% handles.output.ListDevices=ListDevices;
+% handles.output.ListRecords=ListRecords;
+% handles.output.ListXml=ListXml;
+% handles.output.List=List;
+handles.output ='OK, Calibration replicated';
+guidata(hObject, handles);% Update handles structure
+uiresume(handles.figure);
+
+% --- Executes on button press in Cancel.
+function Cancel_Callback(hObject, eventdata, handles)
+handles.output = get(hObject,'String');
+guidata(hObject, handles); % Update handles structure
+% Use UIRESUME instead of delete because the OutputFcn needs
+uiresume(handles.figure);
+
+% --- Executes when user attempts to close figure.
+function figure_CloseRequestFcn(hObject, eventdata, handles)
+if isequal(get(handles.figure, 'waitstatus'), 'waiting')
+    % The GUI is still in UIWAIT, us UIRESUME
+    uiresume(handles.figure);
+else
+    % The GUI is no longer waiting, just close it
+    delete(handles.figure);
+end
+
+% --- Executes on key press over figure1 with no controls selected.
+function figure_KeyPressFcn(hObject, eventdata, handles)
+% Check for "enter" or "escape"
+if isequal(get(hObject,'CurrentKey'),'escape')
+    % User said no by hitting escape
+    handles.output = 'Cancel';
+    
+    % Update handles structure
+    guidata(hObject, handles);
+    
+    uiresume(handles.figure);
+end
+if isequal(get(hObject,'CurrentKey'),'return')
+    uiresume(handles.figure);
+end 
