Académique Documents
Professionnel Documents
Culture Documents
90
Dishwasher
Create a new project Dishwasher; make sure that it is created in its own folder.
Attributes
Add the following attributes all of which are of t pe int and with initial !alue of 0.
92
Operations
Add the following operations# with appropriate return t pes and implementations$
%ake sure that the setup operation returns !oid# and all the others return bool.
9"
Types
'n the implementation for the operation isInNeedOfService(), a constant called MAX_CYCLES is used. (elect the Defa !t package# right) click and select Add New > Type. *nter MAX_CYCLES as name# ensure that "ind is set to Lan# a#e and add declaration$ const int %s=3;
+s is a shortcut for the name of the t pe.
9&
Creating a component
As in the pre!ious e-ercise# rename the Defa !tC$%&$nent to 'est and the Defa !tC$nfi# to De( #. (elect Animation and create an initial instance of Dishwasher.
9,
9.
Creating a statechart
Add a (tatechart to the Dishwasher class. Draw a single state as large as possible called active.
4hen drawing a comple- diagram such as a (tatechart# it is strongl recommended ou ma-imi5e the (tatechart window and close all other windows.
93
7his bo- with active inside appears when the A8D lines are drawn.
7o draw the A8D line# either click and drag the line or click to start the line then double)click to end it.
Concurrent states
96
99
100
7o change the si5e of an outer state# without changing the inner states# press Alt when changing the si5e.
101
102
10"
4hen ou need to t pe a name of an e-isting operation or attribute# ou can use Ctrl: (pace to facilitate entering these names.
10&
Action on entry
'n the n$r%a! state# add an Acti$n $n entr) to set c)c!es*+,. Click to displa the action.
10,
'f there is no instance created# then it is probable that an initial instance of Dishwasher was not selected in the configuration.
10.
Animate$ statechart
Check that there are three concurrent animated states$
"
103
'n(ecting events
7he Dishwasher is in an idle state waiting for some e!ents. 0enerate the e!ent evStart b right)clicking an where in the animated statechart and selecting Generate Event 7he e!ent evStart should appear in the e!ent <ueue.
*!ents can also be generated !ia the Command prompt or !ia the *!ent 0enerator.
106
109
'ntense / )uic!
%odif the set & operation so that the timings are different in the <uick and intense modes.
>se the '(?'8 macro to test if the object is in a particular state.
(a!e 1 0enerate 1 %ake 1 2un. 't should now be <uicker to get the Dishwasher into the fault state.
110
Exten$e$ exercise *
>sing the '(?'8 macro and a guard# pre!ent the Dishwasher from being started if it is fault .
111
Exten$e$ exercise +
7he setup@A operation has conditional beha!ior.
Add a flowchart to !isuali5e its logic.
A Blowchart is a speciali5ation of a >%C Acti!it Diagram. 'f a Blowchart is present# it defines the implementation for an operation and the contents of the implementation tab are ignored b the code generator.
112
,rea!points
(etting breakpoints can be done in a similar wa to injecting e!ents. (impl right)click on the animated state where ou would like to break# choose Add Breakpoint and click OK. /reakpoints can be
added1remo!ed !ia the breakpoint icon on the animation toolbar.
11"
11&
Comman$ prompt
*!ents and breakpoints can also be generated through the command prompt. Bor e-ample# ou could inject the evStart b t ping Dishwasher->GEN(evStart) in the command window. >sing the command window to in!oke scripts is !er useful.
0*8 is a macro that creates the e!ent before sending it to the object. 0*8@e!(tartA D send@new e!(tart#E A.
11,
.ane" $iagram
;ne wa of testing the Dishwasher is to use a panel. Add a Fanel Diagram called Dishwasher Fanel.
11.
.ane" $iagram
Add C*Ds# push buttons# le!el indicators# and a digital displa to the panel.
113
116
/eve" in$icators
Bor each le!el indicator$
>se the Displa ;ptions to select None. >se Beatures to set the %a-imum !alue to ,.
119
.ush buttons
Bor each push button$
>se the Control Displa ;ptions to select None. >se the Beatures to set the Caption appropriatel $
120
,ox
Draw a bo- around the panel. 2ight)click and select Send to Back. 2ight)click and select Format to change the fill color. Add te-t Rational Rhapsody Dishwasher Panel# with desired font and si5e.
121
,in$
Double)click on each panel element and bind them to the appropriate e!ent# attribute# or state$
122
.ane"
7here is no need to generate or make# just 2un >se the panel to dri!e the dishwasher.
12&
TestScript1c%g
(et the Fath to .. .. (et the Bile 7 pe to Ot!er
7he script ou are about to create is contained inside the model and is generated e!er time that code is generated.
12,
Script contents
(elect the Element" tab. Add a 8ew 7e-t *lement. *nter Script Contents as the name. Click to start the te-t editor.
12.
Script
*nter the following$
7his script logs e!er thing that happens including timing information to a file called 7est(cript.log Bor more information on the scripting language# search for e-ample GtimestampH in the user reference manual. Do not lea!e an blank lines or an leading spaces. 8ote also that there is no roundtripping of this file.
123
;nce the script has run and terminated# stop the animation. 7he script should ha!e created a file called 'estScri&t.!$#. 7his file can be edited b adding another file called 'estScri&t.!$# of t pe Other and Fath ..I.. .
'f the script is called OMAni%at$r.cf## it automaticall runs when the animation is started. 7his script must be located in the project director .
126
&ea$ing TestScript1"og
(elect the 'estScri&t.!$# file in the browser# right)click and select Edit File
*lapsed 7ime
129
1"0