주요 콘텐츠

sfclipboard

설명

clipboard = sfclipboardStateflow.Clipboard 객체를 반환합니다. 동일한 차트 내, 동일한 Clipboard 모델의 차트 간 또는 서로 다른 모델의 차트 간에 객체를 복사하여 붙여넣으려면 Simulink® 객체를 사용하십시오.

예제

예제

모두 축소

상태를 그룹화하고 그 내용을 차트에 복사합니다. 상태, 상자 또는 그래픽 함수를 그룹화할 때 그룹화된 객체에 포함된 모든 객체를 비롯하여 이러한 객체 간의 모든 관계도 복사하여 붙여넣을 수 있습니다. 이 방법은 프로그래밍 방식으로 객체를 복사하여 붙여넣을 수 있는 가장 간단한 방법입니다. 상태가 그룹화되지 않은 경우 상태를 복사해도 그 내용이 복사되지 않습니다.

Stateflow chart with a hierarchy of states. The outer state is called A. It contains two inner states called A1 and A2.

모델을 열고 차트의 Stateflow.Chart 객체에 액세스합니다.

open_system("sfHierarchyAPIExample")
ch = find(sfroot,"-isa","Stateflow.Chart");

이름이 AStateflow.State 객체를 찾습니다.

sA = find(ch,"-isa","Stateflow.State",Name="A");

sAIsGrouped 속성을 true로 설정하여 상태 A와 그 내용을 그룹화합니다. 이 속성의 이전 설정을 저장하면 나중에 해당 설정으로 되돌릴 수 있습니다.

prevGrouping = sA.IsGrouped;
sA.IsGrouped = true;

상태 이름을 Copy_of_A로 변경합니다. 이전 이름을 저장하면 나중에 해당 이름으로 되돌릴 수 있습니다.

prevName = sA.Name;
newName = "Copy_of_"+prevName;
sA.Name = newName;

클립보드 객체에 액세스합니다.

cb = sfclipboard;

그룹화된 상태를 클립보드에 복사합니다.

copy(cb,sA);

상태 속성을 원래 설정으로 복원합니다.

sA.IsGrouped = prevGrouping;
sA.Name = prevName;

객체의 사본을 클립보드에서 차트로 붙여넣습니다.

pasteTo(cb,ch);

새로운 상태의 상태 속성을 조정합니다.

sNew = find(ch,"-isa","Stateflow.State",Name=newName);
sNew.Position = sA.Position + [400 0 0 0];
sNew.IsGrouped = prevGrouping;

Chart showing result of pasting a copy of state A and its contents.

차트에서 상태 A1A2를 두 상태 간의 천이와 함께 새 상태로 복사합니다. 객체 간의 천이 연결과 포함 관계를 유지하려면 연결된 모든 객체를 한 번에 복사합니다.

Stateflow chart with a hierarchy of states. The outer state is called A. It contains two inner states called A1 and A2.

모델을 열고 차트의 Stateflow.Chart 객체에 액세스합니다.

open_system("sfHierarchyAPIExample")
ch = find(sfroot,"-isa","Stateflow.Chart");

이름이 AStateflow.State 객체를 찾습니다.

sA = find(ch,"-isa","Stateflow.State",Name="A");

이름이 B인 새 상태를 추가합니다. B의 내부에 다른 객체 붙여넣기를 활성화하기 위해 새 상태를 서브차트로 변환합니다.

sB = Stateflow.State(ch);
sB.Name = "B";
sB.Position = sA.Position + [400 0 0 0];
sB.IsSubchart = true;

상태 A의 상태와 천이 상태가 포함된 objArray라는 배열을 만듭니다. 복사할 객체 배열에서 상태 A를 제거하려면 setdiff 함수를 사용하십시오.

objArrayS = find(sA,"-isa","Stateflow.State");
objArrayS = setdiff(objArrayS,sA);
objArrayT = find(sA,"-isa","Stateflow.Transition");
objArray = [objArrayS objArrayT];

클립보드 객체에 액세스합니다.

cb = sfclipboard;

objArray의 객체를 복사하여 서브차트 B에 붙여넣습니다.

copy(cb,objArray);
pasteTo(cb,sB);

B를 이전 상태로 되돌립니다.

sB.IsSubchart = false;
Assertion failed:  Deviant 'root deviant' not opened for transactions.
Attempt to modify object of type 'StateflowDI.Transition' [id = -1 ]  at kernel/deviant/Deviant.cpp:70: Assertion failed:  Deviant 'root deviant' not opened for transactions.
Attempt to modify object of type 'StateflowDI.Transition' [id = -1 ]  at kernel/deviant/Deviant.cpp:70: Assertion failed:  Deviant 'root deviant' not opened for transactions.
Attempt to modify object of type 'StateflowDI.State' [id = -1 ]  at kernel/deviant/Deviant.cpp:70: Assertion failed:  Deviant 'root deviant' not opened for transactions.
Attempt to modify object of type 'StateflowDI.State' [id = -1 ]  at kernel/deviant/Deviant.cpp:70: 
sB.IsGrouped = false;

B의 상태와 천이를 재배치합니다.

newStates = find(sB,"-isa","Stateflow.State");
newStates = setdiff(newStates,sB);

newTransitions = find(sB,"-isa","Stateflow.Transition");
newOClocks = get(newTransitions,{"SourceOClock","DestinationOClock"});

for i = 1:numel(newStates)
    newStates(i).Position = newStates(i).Position + [25 35 0 0];
end
set(newTransitions,{"SourceOClock","DestinationOClock"},newOClocks);

Chart showing result of copying contents of state A and pasting them into state B.

버전 내역

R2006a 이전에 개발됨

참고 항목

함수

객체

도움말 항목