0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function blk = g_copyfcnCallback(oldSelection,newSelection)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 try %#ok<ALIGN> % the try syntax is due to eventual multiple (or no) outports of the parent block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % if numel(newSelection)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % for ii=1:numel(newSelection), blockPosition(ii,1:4) = get_param(newSelection(ii),'Position'); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % if ii>1, delete_block(getfullname(newSelection(ii))); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % meanPosition = [mean(blockPosition(:,1)) , mean(blockPosition(:,2)) , blockPosition(1,3) , blockPosition(1,4)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % set_param(newSelection(1),'Position',meanPosition);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % newSelection(2:end)=[];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 if numel(newSelection)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 for ii=2:numel(newSelection)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 delete_block(getfullname(newSelection(ii)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 newSelection(2:end)=[];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 functionName = get_param(find_system(newSelection(1),'LookUnderMasks','all','BlockType','M-S-Function'),'Tag');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 if isempty(functionName), functionName = 'hollow'; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % To replace the copied block with the hollow one:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 load_system('ltpda_library');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 blk = replace_block(gcs,'Name',get(newSelection,'Name'),'ltpda_library/Commonly Used Blocks/hollow','noprompt');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 blk = get_param(blk{1},'Handle');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 set(blk,'LinkStatus','inactive','MaskDisplay','disp(''hollow'')')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 set(utils.prog.find_in_models(blk,'LookUnderMasks','all','BlockType','M-S-Function','FunctionName','ltpdasim'),'Tag','','Name','hollow');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 set(blk,'Selected','on')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 set(blk,'UserData',[functionName,'-',num2str(oldSelection(1),20)])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % To add the line properly connecting the old block to the new one:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 if numel(oldSelection)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 set(blk,'UserData','none - 1')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 g_numberDataInput('',1,numel(oldSelection))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 for ii=1:numel(oldSelection)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 add_line(gcs,[get(oldSelection(ii),'Name'),'/1'],[get(blk,'Name'),'/',num2str(ii)],'autorouting','on')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 add_line(gcs,[get(oldSelection,'Name'),'/1'],[get(blk,'Name'),'/1'],'autorouting','on')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 catch, end;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 end |