Vous êtes sur la page 1sur 41

Exercise 3 : Dishwasher

90

Dishwasher
Create a new project Dishwasher; make sure that it is created in its own folder.

Draw a single class Dishwasher.


91

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,

Save / Generate / a!e


/efore adding a statechart# be sure there are no errors b doing a build. (a!e 0enerate 1 %ake 1 2un.

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

Creating concurrent states


Click And Line to create concurrent states.

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.

Draw this line first.

Concurrent states

96

Disp"aying state names


*ach of the three A8D (tates names can be displa ed b selecting the state and using Dis&!a) O&ti$ns to show the 8ame.

99

#aming the concurrent states


4ith the concurrent states names displa ed# the can be changed using the features to running# ser!ice# and mode.

100

A$$ing neste$ states


(elect the Stamp mode

then add the following states$

7o change the si5e of an outer state# without changing the inner states# press Alt when changing the si5e.

101

A$$ing history an$ $iagram connectors


Add a 9istor connector to the on state. Add two Diagram connectors both named d$ne.

102

A$$ing $e%au"t transitions


Add Default 7ransitions$

10"

A$$ing the transitions


Add 7ransitions and Actions$

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.

;nce an action has been set# the s mbol is shown.

10,

Save / Generate / a!e / &un


(a!e 1 0enerate 1 %ake 1 2un. Click Go idle to create a Dishwasher instance.

'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

Design "eve" $ebugging


Click Go and watch the animation. Does our Dishwasher work as e-pected= 4hat happens if ou open the door when it is on# does it remember what state it was in= 4h does the Dishwasher become fault after four c cles= Can ou get the Dishwasher back to the normal state=

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"

-sing the simu"ate$ time mo$e"


At the moment# ( stem tick is used for all the timeouts and so a timeout of 1000ms takes 1000ms# which means that all simulations can be long. 7here is an alternati!e time model that ma be used# that is the Si% !ated time model. 4ith the Si% !ated time model# all the timeouts are e-ecuted in the appropriate order. /ut rather than waiting# the shortest timeout immediatel times out. 7his means models can be tested much <uicker. %ake a cop of the De( # configuration# rename it to Si%, and set the 'i%e M$de! to Si% !ated.

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.

Fanel Diagrams can onl be used with animation configurations.

11.

.ane" $iagram
Add C*Ds# push buttons# le!el indicators# and a digital displa to the panel.

113

&enaming pane" e"ements


Double)click the te-t of each C*D and the digital displa # renaming the panel elements as shown$

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.

4hen using the panel# ou should use the Debug configuration.


12"

Exten$e$ exercise 3 0 Creating a test script


Another wa of testing Dishwasher is b running a script. 7he script can be created in the following wa $
'n the 7est Component# select Add New File. 8ame the file 'estScri&t.cf#.

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$

2emember ) ou can use the cheat sheet.

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

&unning the script


(a!e 1 0enerate 1 %ake 1 2un. >se the command prompt to run the script.

;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

Events an$ receptions


Bor each e!ent that was added to the statechart# the class has a -ece&ti$n# whereas the e!ent itself is declared in the package so that it can be reused b other classes. *ach e!ent is a class that inherits from the framework base class OMEvent.
*!ents 2eceptions

1"0

Vous aimerez peut-être aussi