view m-toolbox/m/gui/gltpda/g_copyfcnCallback.m @ 33:5e7477b94d94 database-connection-manager

Add known repositories list to LTPDAPreferences
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

function blk = g_copyfcnCallback(oldSelection,newSelection)
   
   try %#ok<ALIGN> % the try syntax is due to eventual multiple (or no) outports of the parent block
      
%       if numel(newSelection)>1
%          for ii=1:numel(newSelection), blockPosition(ii,1:4) = get_param(newSelection(ii),'Position'); end
%          if ii>1, delete_block(getfullname(newSelection(ii))); end
%          meanPosition = [mean(blockPosition(:,1)) , mean(blockPosition(:,2)) , blockPosition(1,3) , blockPosition(1,4)];
%          set_param(newSelection(1),'Position',meanPosition);
%          newSelection(2:end)=[];
%       end

      if numel(newSelection)>1
         for ii=2:numel(newSelection)
            delete_block(getfullname(newSelection(ii)))
         end
         newSelection(2:end)=[];
      end
      
      functionName = get_param(find_system(newSelection(1),'LookUnderMasks','all','BlockType','M-S-Function'),'Tag');
      if isempty(functionName), functionName = 'hollow'; end
      
    % To replace the copied block with the hollow one:
      load_system('ltpda_library');
      blk = replace_block(gcs,'Name',get(newSelection,'Name'),'ltpda_library/Commonly Used Blocks/hollow','noprompt');
      blk = get_param(blk{1},'Handle');
      set(blk,'LinkStatus','inactive','MaskDisplay','disp(''hollow'')')
      set(utils.prog.find_in_models(blk,'LookUnderMasks','all','BlockType','M-S-Function','FunctionName','ltpdasim'),'Tag','','Name','hollow');
      set(blk,'Selected','on')
      set(blk,'UserData',[functionName,'-',num2str(oldSelection(1),20)])
      
   % To add the line properly connecting the old block to the new one:
     if numel(oldSelection)>1
         set(blk,'UserData','none - 1')
         g_numberDataInput('',1,numel(oldSelection))
         for ii=1:numel(oldSelection)
            add_line(gcs,[get(oldSelection(ii),'Name'),'/1'],[get(blk,'Name'),'/',num2str(ii)],'autorouting','on')
         end
         
      else
         add_line(gcs,[get(oldSelection,'Name'),'/1'],[get(blk,'Name'),'/1'],'autorouting','on')
      end

   catch, end;
   
end