Home > Codi > Menu_Canvia_Lots.m

Menu_Canvia_Lots

PURPOSE ^

Pantalla que permet canviar lots d'un objecte DATa a un altre, accedr a

SYNOPSIS ^

function varargout = Menu_Canvia_Lots(varargin)

DESCRIPTION ^

Pantalla que permet canviar lots d'un objecte DATa a un altre, accedr a
certs grafics per representar les dades contingudes en aquests objectes i
modificar-ne els noms o classes dels lots.

Per invocar directament des de consola aquesta pantalla nomes cal
invocar-ne la funcio sense cap parametre extra:
Menu_Canvia_Lots();

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = Menu_Canvia_Lots(varargin)
0002 %Pantalla que permet canviar lots d'un objecte DATa a un altre, accedr a
0003 %certs grafics per representar les dades contingudes en aquests objectes i
0004 %modificar-ne els noms o classes dels lots.
0005 %
0006 %Per invocar directament des de consola aquesta pantalla nomes cal
0007 %invocar-ne la funcio sense cap parametre extra:
0008 %Menu_Canvia_Lots();
0009 %
0010 
0011 gui_Singleton = 1;
0012 gui_State = struct('gui_Name',       mfilename, ...
0013                    'gui_Singleton',  gui_Singleton, ...
0014                    'gui_OpeningFcn', @Menu_Canvia_Lots_OpeningFcn, ...
0015                    'gui_OutputFcn',  @Menu_Canvia_Lots_OutputFcn, ...
0016                    'gui_LayoutFcn',  [] , ...
0017                    'gui_Callback',   []);
0018 if nargin && ischar(varargin{1})
0019     gui_State.gui_Callback = str2func(varargin{1});
0020 end
0021 
0022 if nargout
0023     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0024 else
0025     gui_mainfcn(gui_State, varargin{:});
0026 end
0027 
0028 function Menu_Canvia_Lots_OpeningFcn(hObject, ~, handles, varargin)
0029 %funció que s'invoca en crear la finestra a varargin ens arriven el
0030 %possibles parametres extres d'invocació de Pantalla. No els
0031 %utilitzarem per res. hObject i handles els modificarem.
0032 handles.output = hObject;
0033 handles=menu(handles);
0034 
0035 guidata(hObject, handles);
0036 
0037 %busquem objectes dades
0038 x=evalin('base','whos();');
0039 list=[];
0040 for i=1:length(x)
0041     if strcmp(x(i).class,'DATA') ~=0
0042        list=[list; {x(i).name}];
0043     end
0044 end
0045 if isempty(list)
0046     list={'No DATA obsects in workspace'};
0047 end
0048 set(handles.popupmenu1,'String',list);
0049 %tambe posem la llista al popupmenu2!
0050 set(handles.popupmenu2,'String',list);
0051 
0052 set(handles.listbox1,'Max',999999);
0053 set(handles.listbox2,'Max',999999);
0054 
0055 function pushbutton3_Callback(~, ~, handles)
0056 %comprobem que hi hagi lots seleccionats
0057 if isempty(get(handles.listbox2,'String'))
0058     errordlg('You must select one object!','Error');
0059 
0060 else
0061     
0062     %nom de l'objecte dades2
0063     dade=get(handles.popupmenu2,'String');
0064     dade=dade{get(handles.popupmenu2,'Value')};
0065     
0066     
0067     %treiem tots els lots!
0068     inst=[  dade '.deleteBatch(1:' num2str(evalin('base',[dade '.getBatchCount()'])) ');'];
0069     evalin('base',inst);
0070     
0071     %actualitzem la llista dels lots
0072     aux=evalin('base',[dade '.getBatchLabel()']);
0073     set(handles.listbox2,'String', aux);
0074     set(handles.listbox2,'Value',length(aux));
0075     
0076     dad=get(handles.popupmenu1,'String');
0077     dad=dad{get(handles.popupmenu1,'Value')};
0078     if strcmp(dade,dad)
0079         set(handles.listbox1,'String', aux);
0080         set(handles.listbox1,'Value',length(aux));
0081     end
0082 end
0083 
0084 function popupmenu2_Callback(~, ~, handles)
0085 %nom de l'objecte dades2
0086 dade=get(handles.popupmenu2,'String');
0087 dade=dade{get(handles.popupmenu2,'Value')};
0088 
0089 
0090 %actualitzem la llista dels lots
0091 aux=evalin('base',[dade '.getBatchLabel()']);
0092 
0093 %si no te noms de lot els generem asignant-hi la posicio actual del lot!!
0094 if(isempty(aux) && (evalin('base',[dade '.getBatchCount()']) > 0))
0095     evalin('base',[dade '.setBatchLabel(num2cell(1:' dade '.getBatchCount))']);
0096     warndlg('Selected object had no batch names. Automatic ones ware assigned.','Attention!')
0097 
0098     aux=evalin('base',[dade '.getBatchLabel()']);
0099 end
0100 
0101 set(handles.listbox2,'String',aux);
0102 set(handles.listbox2,'Value',1);
0103 set(handles.listbox2,'ListboxTop', 1);
0104 
0105 function popupmenu1_Callback(~, ~, handles)
0106 %nom de l'objecte dades1
0107 dade=get(handles.popupmenu1,'String');
0108 dade=dade{get(handles.popupmenu1,'Value')};
0109 
0110 
0111 %actualitzem la llista dels lots
0112 aux=evalin('base',[dade '.getBatchLabel()']);
0113 
0114 %si no te noms de lot els generem asignant-hi la posicio actual del lot!!
0115 if(isempty(aux) && (evalin('base',[dade '.getBatchCount()']) > 0))
0116     evalin('base',[dade '.setBatchLabel(num2cell(1:' dade '.getBatchCount))']);
0117     warndlg('Selected object had no batch names. Automatic ones ware assigned.','Attention!')
0118 
0119     aux=evalin('base',[dade '.getBatchLabel()']);
0120 end
0121 set(handles.listbox1,'String',aux);
0122 set(handles.listbox1,'Value',1);
0123 set(handles.listbox1,'ListboxTop', 1);
0124 
0125 function pushbutton4_Callback(~, ~, handles)
0126 %comprobem que hi hagi lots seleccionats
0127 if isempty(get(handles.listbox1,'String'))
0128     errordlg('Select one object!','Error');
0129 
0130 else
0131     
0132     %nom de l'objecte dades1
0133     dade=get(handles.popupmenu1,'String');
0134     dade=dade{get(handles.popupmenu1,'Value')};
0135     
0136     
0137     %treiem tots els lots!
0138     inst=[  dade '.deleteBatch( 1:' num2str(evalin('base',[dade '.getBatchCount()'])) ' );'];
0139     evalin('base',inst);
0140     
0141     %actualitzem la llista dels lots
0142     aux=evalin('base',[dade '.getBatchLabel()']);
0143     set(handles.listbox1,'String', aux);
0144     set(handles.listbox1,'Value',length(aux));
0145     
0146     dad=get(handles.popupmenu2,'String');
0147     dad=dad{get(handles.popupmenu2,'Value')};
0148     if strcmp(dade,dad)
0149         set(handles.listbox2,'String', aux);
0150         set(handles.listbox2,'Value',length(aux));
0151     end
0152 end
0153 
0154 function pushbutton5_Callback(~, ~, ~)
0155 uiwait(Menu_Load_Dades());
0156 
0157 function Update(hObject, ~, handles) 
0158 handles.output = hObject;
0159 handles=menu(handles);
0160 
0161 %Tornem a crear la llista d'objectes DATA
0162 x=evalin('base','whos();');
0163 list=[];
0164 for i=1:length(x)
0165     if strcmp(x(i).class,'DATA') ~=0
0166         list=[list; {x(i).name}];
0167     end
0168 end
0169 if isempty(list)
0170     list={'No DATA obsects in workspace'};
0171 end
0172 
0173 %busquem el valor que te el popupmenu actualment
0174 nom=get(handles.popupmenu1,'String');
0175 nom=nom{get(handles.popupmenu1,'Value')};
0176 
0177 nom2=get(handles.popupmenu2,'String');
0178 nom2=nom2{get(handles.popupmenu2,'Value')};
0179 
0180 %busquem aquest nom entre la llista actual
0181 val=find(strcmp(nom,list));
0182 
0183 %posem la nova llista de noms
0184 set(handles.popupmenu1,'String',list);
0185 set(handles.popupmenu2,'String',list);
0186 if isempty(val)
0187     set(handles.popupmenu1,'Value',1);
0188     %i desactivem els menus!
0189 set(handles.listbox1,'String',[]);
0190 set(handles.listbox1,'value',1);
0191     
0192 else
0193     set(handles.popupmenu1,'Value',val);
0194 end
0195 
0196 
0197 %busquem aquest nom entre la llista actual
0198 val=find(strcmp(nom2,list));
0199 if isempty(val)
0200     set(handles.popupmenu2,'Value',1);
0201     %i desactivem els menus!
0202 set(handles.listbox2,'String',[]);
0203 set(handles.listbox2,'value',1);
0204     
0205 else
0206     set(handles.popupmenu2,'Value',val);
0207 end
0208 
0209 guidata(hObject, handles);
0210 
0211 function pushbutton7_Callback(~, ~, handles)
0212 %comprovem que hi hagi algun lot seleccionat
0213 if isempty(get(handles.listbox2,'String')) || isempty(get(handles.listbox1,'String'))
0214     errordlg('Select at least one object!','Error');
0215 
0216 else
0217     
0218     %nom de l'objecte dades que s'esta mostran al list dreta
0219     dade=get(handles.popupmenu2,'String');
0220     dade1=dade{get(handles.popupmenu2,'Value')};
0221     
0222  
0223     %nom de l'objecte dades que s'esta mostran al list esquerre
0224     dade=get(handles.popupmenu1,'String');
0225     dade2=dade{get(handles.popupmenu1,'Value')};
0226     
0227     
0228     
0229     %L'element seleccionat a la dreta
0230     lot=get(handles.listbox2,'Value');%la posició del lot!
0231     inst=[ dade1 '.getBatch([' num2str(lot) ']);'];
0232     [dades , ~, nom] = evalin('base',inst);
0233     
0234     
0235     %L'element seleccionat a la esquerre
0236     lot=get(handles.listbox1,'Value');%la posició del lot!
0237     inst=[ dade2 '.getBatch([' num2str(lot) ']);'];
0238     [dades2 , ~, nom2] = evalin('base',inst);
0239     
0240     
0241     %DATA hi tenim les variables en columnes
0242     m=floor(size(dades,2)/2);
0243     n=floor( (size(dades,2)+1)/2 );
0244     
0245     figure;
0246     
0247     tit = evalin('base',[dade1 '.getVariableLabel()']); 
0248     if isempty(tit)
0249         tit = 1:size(dades,2);
0250     end
0251     
0252     hold on;
0253     color_table=[winter(size(dades,3)); autumn(size(dades2,3))]; %tons blaus
0254     %color_table=[color_table ; rand(size(dades2,3),1)*0.5+0.5,rand(size(dades2,3),1)*0.5+0.5 ,rand(size(dades2,3),1)*0.5+0.5]; %tons verds
0255     
0256     if(m == 0)
0257         m=1;
0258     end
0259     for i = 1:size(dades,2) %per cada variable
0260         subplot(m,n,i)
0261         
0262         hold on
0263         ti = {};%nem preparant el legend
0264         for j= 1:size(dades,3)%per cada variable
0265             plot(1:size(dades,1),dades(:,i,j),'color',color_table(j,:))
0266             ti = {ti{:} ['Batch:' num2str(nom{j}) ' -- Object:' dade1]};
0267         end
0268         for j= 1:size(dades2,3)%per cada variable
0269             plot(1:size(dades2,1),dades2(:,i,j),'color',color_table(j+size(dades,3),:))
0270             ti = {ti{:} ['Batch:' num2str(nom2{j}) ' -- Object:' dade2]};
0271         end
0272 
0273         title(tit(i))
0274         
0275         legend(ti);
0276         legend('off');
0277         
0278         hold off
0279     end
0280     hold off;
0281 end
0282 
0283 function listbox2_Callback(~, ~, handles)
0284     %nom de l'objecte dades que s'esta mostran al list dreta
0285     dade=get(handles.popupmenu2,'String');
0286     dade=dade{get(handles.popupmenu2,'Value')};
0287     
0288     
0289     %L'element seleccionat a la dreta
0290     lot=get(handles.listbox2,'Value');%la posició del lot!
0291     if isempty(lot) || length(lot) ~=1
0292         set(handles.edit2,'String','');
0293     else
0294         inst=[ dade '.getBatch(' num2str(lot) ');'];
0295         [~, class ,~] = evalin('base',inst);
0296         set(handles.edit2,'String',num2str(class));
0297     end
0298     
0299 function listbox1_Callback(~, ~, handles)
0300     %nom de l'objecte dades que s'esta mostran al list esquerre
0301     dade=get(handles.popupmenu1,'String');
0302     dade=dade{get(handles.popupmenu1,'Value')};
0303     
0304     
0305     %L'element seleccionat a la dreta
0306     lot=get(handles.listbox1,'Value');%la posició del lot!
0307     if isempty(lot) || length(lot) ~=1
0308         set(handles.edit1,'String','');
0309     else
0310         inst=[ dade '.getBatch(' num2str(lot) ');'];
0311         [~, class, ~] = evalin('base',inst);
0312         set(handles.edit1,'String',num2str(class));
0313     end
0314     
0315     
0316 % -----Quan acciona el submenu seleccionem l'element de la llista-----
0317 function contextm_Callback(~, ~, handles)
0318 %fem un click dret per seleccionar l'element de la llista
0319 
0320 if length(get(handles.listbox1,'Value')) <= 1
0321     R=java.awt.Robot;
0322     R.setAutoWaitForIdle(1);
0323     R.mousePress(java.awt.event.InputEvent.BUTTON1_MASK);
0324     R.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);
0325 end
0326 function cuntextmd_Callback(~, ~, handles)
0327 %fem un click dret per seleccionar l'element de la llista
0328 if length(get(handles.listbox2,'Value')) <= 1
0329     R=java.awt.Robot;
0330     R.setAutoWaitForIdle(1);
0331     R.mousePress(java.awt.event.InputEvent.BUTTON1_MASK);
0332     R.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);
0333 end
0334 
0335 % --------------------------------------------------------------------
0336 %callbacks del menu del list dret
0337 function EliminaDre_Callback(~, ~, handles)
0338 %nom de l'objecte dades que s'esta mostran al list dret
0339 dade=get(handles.popupmenu2,'String');
0340 dade1=dade{get(handles.popupmenu2,'Value')};
0341 
0342 
0343 %L'element sobre el qual s'ha cridat el menu indica el lot a eliminar!!
0344 lot1=num2str(get(handles.listbox2,'Value'));%la posició del lot!
0345 
0346 %comprobem que hi hagi lots seleccionats
0347 if isempty(get(handles.listbox2,'String'))
0348     errordlg('Select one object!','Error');
0349 
0350 else
0351     
0352     %construim la instruccio que l'eliminara
0353     inst=[  dade1 '.deleteBatch([' num2str(lot1) ']);'];
0354     evalin('base',inst);%la evaluo
0355     
0356     %actualitzem la llista dels lots
0357     aux=evalin('base',[dade1 '.getBatchLabel()']);
0358     set(handles.listbox2,'String', aux);
0359     set(handles.listbox2,'Value',length(aux));
0360     
0361     dad=get(handles.popupmenu1,'String');
0362     dad=dad{get(handles.popupmenu1,'Value')};
0363     if strcmp(dade,dad)
0364         set(handles.listbox1,'String', aux);
0365         set(handles.listbox1,'Value',length(aux));
0366     end
0367 end
0368 
0369 function MouDre_Callback(~, ~, handles)
0370 % listbox1 <-- listbox2
0371 %comprovem que hi hagi algun lot seleccionat
0372 if isempty(get(handles.listbox2,'String'))
0373     errordlg('Select one object!','Error');
0374 
0375 else
0376     
0377     %nom de l'objecte dades1
0378     dade=get(handles.popupmenu1,'String');
0379     dade1=dade{get(handles.popupmenu1,'Value')};
0380     
0381     
0382     %nom de l'objecte dades2
0383     dade=get(handles.popupmenu2,'String');
0384     dade2=dade{get(handles.popupmenu2,'Value')};
0385     
0386     
0387     if strcmp(dade1,dade2)
0388         errordlg('Selected objects are the same. Invalid action!','Error')
0389 
0390     else
0391         lot=get(handles.listbox2,'Value');%la posició del lot!
0392         inst=[ '[Temp_a1 Temp_a2 Temp_a3] =' dade2 '.getBatch([' num2str(lot) ']);'];
0393         evalin('base',inst);
0394         
0395         inst=[dade1 '.addBatch( Temp_a1, Temp_a2 ,Temp_a3 );'];
0396         evalin('base',inst);
0397         
0398         inst='clear Temp_a1 Temp_a2 Temp_a3 ';
0399         evalin('base',inst);
0400         
0401         inst=[  dade2 '.deleteBatch([' num2str(lot) ']);'];
0402         evalin('base',inst);
0403         
0404         %actualitzem la llista dels lots
0405         aux=evalin('base',[dade1 '.getBatchLabel()']);
0406         set(handles.listbox1,'String', aux);
0407         set(handles.listbox1,'Value',length(aux));
0408         
0409         aux=evalin('base',[dade2 '.getBatchLabel()']);
0410         set(handles.listbox2,'String', aux);
0411         set(handles.listbox2,'Value',length(aux));
0412     end
0413 end
0414 
0415 function CopyDre_Callback(~, ~, handles)
0416 % listbox1 <-- listbox2
0417 %comprovem que hi hagi algun lot seleccionat
0418 if isempty(get(handles.listbox2,'String'))
0419     errordlg('Select one object!','Error');
0420 
0421 else
0422     
0423     %nom de l'objecte dades1
0424     dade=get(handles.popupmenu1,'String');
0425     dade1=dade{get(handles.popupmenu1,'Value')};
0426     
0427     
0428     %nom de l'objecte dades2
0429     dade=get(handles.popupmenu2,'String');
0430     dade2=dade{get(handles.popupmenu2,'Value')};
0431     
0432     
0433     if strcmp(dade1,dade2)
0434         errordlg('Selected objects are the same. Invalid action!','Error')
0435 
0436     else
0437     lot=get(handles.listbox2,'Value');%la posició del lot!
0438     inst=[ '[Temp_a1 Temp_a2 Temp_a3] =' dade2 '.getBatch([' num2str(lot) ']);'];
0439     evalin('base',inst);
0440     
0441     inst=[dade1 '.addBatch( Temp_a1, Temp_a2 ,Temp_a3 );'];
0442     evalin('base',inst);
0443     
0444     inst='clear Temp_a1 Temp_a2 Temp_a3 ';
0445     evalin('base',inst);
0446     
0447     % %com l'anterior pero sense treure
0448     % inst=[  dade2 '.deleteBatch(' num2str(lot) ');'];
0449     % evalin('base',inst);
0450     
0451     %actualitzem la llista dels lots
0452     aux=evalin('base',[dade1 '.getBatchLabel()']);
0453     set(handles.listbox1,'String', aux);
0454     set(handles.listbox1,'Value',length(aux));
0455     
0456     %aux=evalin('base',[dade2 '.getBatchLabel()']);
0457     %set(handles.listbox2,'String', aux);
0458     %set(handles.listbox2,'Value',length(aux));
0459     end
0460 end
0461 
0462 function PlotVarsDre_Callback(~, ~, handles)
0463 %comprovem que hi hagi algun lot seleccionat
0464 if isempty(get(handles.listbox2,'String'))
0465     errordlg('Select one object!','Error');
0466 
0467 else
0468     
0469     %nom de l'objecte dades que s'esta mostran al list dreta
0470     dade=get(handles.popupmenu2,'String');
0471     dade1=dade{get(handles.popupmenu2,'Value')};
0472     
0473     
0474     %L'element sobre el qual s'ha cridat el menu indica el lot a fer el plot
0475     lot=get(handles.listbox2,'Value');%la posició del lot!
0476     inst=[ dade1 '.getBatch([' num2str(lot) ']);'];
0477     [dades , ~, nom] = evalin('base',inst);
0478     
0479     %DATA hi tenim les variables en columnes
0480     m=floor(size(dades,2)/2);
0481     n=floor( (size(dades,2)+1)/2 );
0482     
0483     figure;
0484     
0485     tit = evalin('base',[dade1 '.getVariableLabel()']); 
0486     if isempty(tit)
0487         tit = 1:size(dades,2);
0488     end
0489     
0490     color_table = jet(size(dades,3));
0491     hold on;
0492     if(m == 0)
0493         m=1;
0494     end
0495     for i = 1:size(dades,2) %per cada variable
0496         subplot(m,n,i)
0497         if i == 1
0498             ti = {};%nem preparant el legend
0499             hold on;
0500             for j= 1:size(dades,3)%per cada variable
0501                 plot(1:size(dades,1),dades(:,i,j),'color',color_table(j,:))
0502                 ti = {ti{:} ['Batch:' num2str(nom{j}) ' -- Object:' dade1]};
0503             end
0504             hold off;
0505         else
0506             %nomes cal calcular la llegenda 1 cop!
0507             hold on;
0508             for j= 1:size(dades,3)%per cada variable
0509                 plot(1:size(dades,1),dades(:,i,j),'color',color_table(j,:))
0510             end
0511             hold off;
0512         end
0513         %plot(1:size(dades,1),dades(:,i))
0514         title(tit(i))
0515         %legend({strcat('Lot:',num2str(nom{1}),' -- Objecte:', dade1)})
0516         legend(ti)
0517         legend('off')
0518     end
0519     hold off;
0520 end
0521 
0522 function CanviaClasseDre_Callback(~, ~, handles)
0523 if isempty(get(handles.listbox2,'String'))
0524     errordlg('Select one object!','Error');
0525 
0526 else
0527     %nom de l'objecte dades2
0528     dade=get(handles.popupmenu2,'String');
0529     dade2=dade{get(handles.popupmenu2,'Value')};
0530     
0531     
0532     class = evalin('base',[dade2 '.getClass()']);
0533     index = get(handles.listbox2,'Value');%la posició del lot a canviar
0534     
0535      answer = inputdlg('Wich class should have?');
0536      answer = str2double(answer);
0537      
0538      while isnan(answer)
0539          errordlg('Classes must be Integer!','Error')
0540          
0541          uiwait(gcf);
0542          answer = inputdlg('Wich class should have?');
0543          answer = str2double(answer);
0544      end
0545     
0546      if ~isempty(answer)
0547          class(index) = answer;
0548          evalin('base',[dade2 '.setClass([' num2str(class) ']);']);
0549          set(handles.edit2,'String',num2str(answer));
0550          if (get(handles.popupmenu2,'Value')== get(handles.popupmenu1,'Value')) && (get(handles.listbox2,'Value') == get(handles.listbox1,'Value'))
0551             set(handles.edit1,'String',num2str(answer));
0552          end
0553      end
0554 end
0555 
0556 function CanviaNomDre_Callback(~, ~, handles)
0557 if isempty(get(handles.listbox2,'String'))
0558     errordlg('select one object!','Error');
0559 
0560 else
0561     %nom de l'objecte dades2
0562     dade=get(handles.popupmenu2,'String');
0563     dade2=dade{get(handles.popupmenu2,'Value')};
0564     
0565     
0566     class = evalin('base',[dade2 '.getBatchLabel()']);
0567     index = get(handles.listbox2,'Value');%la posició del lot a canviar
0568     
0569      answer = inputdlg('Which name should have?');
0570     
0571      if ~isempty(answer)
0572          class(index) = answer;
0573          aux =  evalin('base',[dade2 '.copy();']);
0574          aux.setBatchLabel(class);
0575          
0576          
0577          assignin('base',dade2, aux);
0578 
0579          set(handles.listbox2,'String', class)
0580          
0581          if (get(handles.popupmenu2,'Value')== get(handles.popupmenu1,'Value'))
0582             set(handles.listbox1,'String', class)
0583          end
0584      end
0585 end
0586 
0587 
0588 % --------------------------------------------------------------------
0589 %callbacks del menu del list esquerre
0590 function EliminaEsq_Callback(~, ~, handles)
0591 %nom de l'objecte dades que s'esta mostran al list esquerre
0592 dade=get(handles.popupmenu1,'String');
0593 dade1=dade{get(handles.popupmenu1,'Value')};
0594 
0595 
0596 %L'element sobre el qual s'ha cridat el menu indica el lot a eliminar!!
0597 lot1=num2str(get(handles.listbox1,'Value'));%la posició del lot!
0598 
0599 %comprobem que hi hagi lots seleccionats
0600 if isempty(get(handles.listbox1,'String'))
0601     errordlg('Select one object!','Error');
0602 
0603 else
0604     
0605     %construim la instruccio que l'eliminara
0606     inst=[  dade1 '.deleteBatch([' num2str(lot1) ']);'];
0607     evalin('base',inst);%la evaluo
0608     
0609     %actualitzem la llista dels lots
0610     aux=evalin('base',[dade1 '.getBatchLabel()']);
0611     set(handles.listbox1,'String', aux);
0612     set(handles.listbox1,'Value',length(aux));
0613     
0614     dad=get(handles.popupmenu2,'String');
0615     dad=dad{get(handles.popupmenu2,'Value')};
0616     if strcmp(dade1,dad)
0617         set(handles.listbox2,'String', aux);
0618         set(handles.listbox2,'Value',length(aux));
0619     end
0620 end
0621 
0622 function MouEsq_Callback(~, ~, handles)
0623 % listbox1 --> listbox2
0624 
0625 %comprobem que hi hagi lots seleccionats
0626 if isempty(get(handles.listbox1,'String'))
0627     errordlg('Select one object!','Error');
0628 else
0629     
0630     %nom de l'objecte dades1
0631     dade=get(handles.popupmenu1,'String');
0632     dade1=dade{get(handles.popupmenu1,'Value')};
0633     
0634     
0635     %nom de l'objecte dades2
0636     dade=get(handles.popupmenu2,'String');
0637     dade2=dade{get(handles.popupmenu2,'Value')};
0638     
0639     
0640     if strcmp(dade1,dade2)
0641         errordlg('Selected objects are the same. Invalid action!','Error')
0642 
0643     else
0644         lot=get(handles.listbox1,'Value');%la posició del lot!
0645         inst=[ '[Temp_a1 Temp_a2 Temp_a3] =' dade1 '.getBatch([' num2str(lot) ']);'];
0646         evalin('base',inst);
0647         
0648         inst=[dade2 '.addBatch( Temp_a1, Temp_a2 ,Temp_a3 );'];
0649         evalin('base',inst);
0650         
0651         inst='clear Temp_a1 Temp_a2 Temp_a3 ';
0652         evalin('base',inst);
0653         
0654         inst=[  dade1 '.deleteBatch([' num2str(lot) ']);'];
0655         evalin('base',inst);
0656         
0657         %actualitzem la llista dels lots
0658         aux=evalin('base',[dade1 '.getBatchLabel()']);
0659         set(handles.listbox1,'String', aux);
0660         set(handles.listbox1,'Value',length(aux));
0661         
0662         aux=evalin('base',[dade2 '.getBatchLabel()']);
0663         set(handles.listbox2,'String', aux);
0664         set(handles.listbox2,'Value',length(aux));
0665     end
0666 end
0667 
0668 function CopyEsq_Callback(~, ~, handles)
0669 % listbox1 --> listbox2
0670 
0671 %comprobem que hi hagi lots seleccionats
0672 if isempty(get(handles.listbox1,'String'))
0673     errordlg('Select one object!','Error');
0674 
0675 else
0676     
0677     %nom de l'objecte dades1
0678     dade=get(handles.popupmenu1,'String');
0679     dade1=dade{get(handles.popupmenu1,'Value')};
0680     
0681     
0682     %nom de l'objecte dades2
0683     dade=get(handles.popupmenu2,'String');
0684     dade2=dade{get(handles.popupmenu2,'Value')};
0685     
0686     
0687     if strcmp(dade1,dade2)
0688         errordlg('Selected objects are the same. Invalid action!','Error')
0689 
0690     else
0691         lot=get(handles.listbox1,'Value');%la posició del lot!
0692         inst=[ '[Temp_a1 Temp_a2 Temp_a3] =' dade1 '.getBatch([' num2str(lot) ']);'];
0693         evalin('base',inst);
0694         
0695         inst=[dade2 '.addBatch( Temp_a1, Temp_a2 ,Temp_a3 );'];
0696         evalin('base',inst);
0697         
0698         inst='clear Temp_a1 Temp_a2 Temp_a3 ';
0699         evalin('base',inst);
0700         
0701         %actualitzem la llista dels lots
0702         %    aux=evalin('base',[dade1 '.getBatchLabel()']);
0703         %    set(handles.listbox1,'String', aux);
0704         %    set(handles.listbox1,'Value',length(aux));
0705         
0706         aux=evalin('base',[dade2 '.getBatchLabel()']);
0707         set(handles.listbox2,'String', aux);
0708         set(handles.listbox2,'Value',length(aux));
0709     end
0710 end
0711 
0712 function PlotVarsEsq_Callback(~, ~, handles)
0713 %comprobem que hi hagi lots seleccionats
0714 if isempty(get(handles.listbox1,'String'))
0715     errordlg('Select one object!','Error');
0716 
0717 else
0718     
0719     %nom de l'objecte dades que s'esta mostran al list esquerre
0720     dade=get(handles.popupmenu1,'String');
0721     dade1=dade{get(handles.popupmenu1,'Value')};
0722     
0723     
0724     %L'element sobre el qual s'ha cridat el menu indica el lot a fer el plot
0725     lot=get(handles.listbox1,'Value');%la posició del lot!
0726     inst=[ dade1 '.getBatch([' num2str(lot) ']);'];
0727     [dades , ~, nom] = evalin('base',inst);
0728     
0729     %DATA hi tenim les variables en columnes
0730     m=floor(size(dades,2)/2);
0731     n=floor( (size(dades,2)+1)/2 );
0732     
0733     figure;
0734     
0735     %agafem els noms de les variables
0736     tit = evalin('base',[dade1 '.getVariableLabel()']); 
0737     if isempty(tit)
0738         tit = 1:size(dades,2);
0739     end
0740     color_table = jet(size(dades,3));
0741     hold on;
0742     if(m == 0)
0743         m=1;
0744     end
0745     for i = 1:size(dades,2) %per cada variable
0746         subplot(m,n,i)
0747         
0748         if i == 1
0749             ti = {};%nem preparant el legend
0750             hold on;
0751             for j= 1:size(dades,3)%per cada variable
0752                 plot(1:size(dades,1),dades(:,i,j),'color',color_table(j,:))
0753                 ti = {ti{:} ['Batch:' num2str(nom{j}) ' -- Object:' dade1]};
0754             end
0755             hold off;
0756         else
0757             %nomes cal calcular la llegenda 1 cop!
0758             hold on;
0759             for j= 1:size(dades,3)%per cada variable
0760                 plot(1:size(dades,1),dades(:,i,j),'color',color_table(j,:))
0761             end
0762             hold off;
0763         end
0764         
0765         %plot(1:size(dades,1),dades(:,i))
0766         title(tit(i))
0767         
0768         legend(ti)
0769         legend('off')
0770     end
0771     hold off;
0772 end
0773 
0774 function CanviaClasseEsq_Callback(~, ~, handles)
0775 if isempty(get(handles.listbox1,'String'))
0776     errordlg('Select one object!','Error');
0777 
0778 else
0779     %nom de l'objecte dades1 (el de l'esquerre)
0780     dade=get(handles.popupmenu1,'String');
0781     dade2=dade{get(handles.popupmenu1,'Value')};
0782     
0783     
0784     class = evalin('base',[dade2 '.getClass()']);
0785     index = get(handles.listbox1,'Value');%la posició del lot a canviar
0786     
0787      answer = inputdlg('Which class should have?');
0788      answer = str2double(answer);
0789      
0790      while isnan(answer)
0791          errordlg('Classes must be Integers!','Error')
0792 
0793          uiwait(gcf);
0794         answer = inputdlg('Wich class should have?');
0795         answer = str2double(answer);
0796      end
0797     
0798      if ~isempty(answer)
0799          class(index) = answer;
0800          evalin('base',[dade2 '.setClass([' num2str(class) ']);']);
0801          set(handles.edit1,'String',num2str(answer));
0802          if (get(handles.popupmenu2,'Value')== get(handles.popupmenu1,'Value')) && (get(handles.listbox2,'Value') == get(handles.listbox1,'Value'))
0803             set(handles.edit2,'String',num2str(answer));
0804          end
0805      end
0806 end
0807 
0808 
0809 function CanviaNomEsq_Callback(~, ~, handles)
0810 if isempty(get(handles.listbox1,'String'))
0811     errordlg('Select one object!','Error');
0812 else
0813     %nom de l'objecte dades2
0814     dade=get(handles.popupmenu1,'String');
0815     dade2=dade{get(handles.popupmenu1,'Value')};
0816     
0817     
0818     class = evalin('base',[dade2 '.getBatchLabel()']);
0819     index = get(handles.listbox1,'Value');%la posició del lot a canviar
0820     
0821      answer = inputdlg('which name should have?');
0822     
0823      if ~isempty(answer)
0824          class(index) = answer;
0825          aux =  evalin('base',[dade2 '.copy();']);
0826          aux.setBatchLabel(class);
0827          
0828          assignin('base',dade2, aux);
0829 
0830          set(handles.listbox1,'String', class)
0831          
0832          if (get(handles.popupmenu2,'Value')== get(handles.popupmenu1,'Value'))
0833             set(handles.listbox2,'String', class)
0834          end
0835      end
0836 end
0837 
0838 
0839 %% -- INUTILS --
0840 function popupmenu1_CreateFcn(hObject, ~, ~)
0841 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0842     set(hObject,'BackgroundColor','white');
0843 end
0844 function listbox1_CreateFcn(hObject, ~, ~)
0845 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0846     set(hObject,'BackgroundColor','white');
0847 end
0848 function popupmenu2_CreateFcn(hObject, ~, ~)
0849 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0850     set(hObject,'BackgroundColor','white');
0851 end
0852 function listbox2_CreateFcn(hObject, ~, ~)
0853 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0854     set(hObject,'BackgroundColor','white');
0855 end
0856 function varargout = Menu_Canvia_Lots_OutputFcn(~, ~, handles) 
0857 varargout{1} = handles.output;
0858 function edit2_Callback(~, ~, ~)
0859 function edit2_CreateFcn(hObject, ~, ~)
0860 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0861     set(hObject,'BackgroundColor','white');
0862 end
0863 function edit1_Callback(~, ~, ~)
0864 function edit1_CreateFcn(hObject, ~, ~)
0865 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0866     set(hObject,'BackgroundColor','white');
0867 end
0868 
0869 
0870 % --------------------------------------------------------------------
0871 function Untitled_1_Callback(~, ~, ~)

Generated on Wed 12-Sep-2012 13:03:54 by m2html © 2005