rhapsody in c++ tool training "essential" © i-logix 1999-2003 v4.1 01/01/2003 e1-1...

28
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-20 03 v4.1 01/01/2003 E1-1 Essential Rhapsody in C++ Part One Basic Rhapsod

Upload: taylor-almy

Post on 14-Dec-2015

218 views

Category:

Documents


2 download

TRANSCRIPT

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-1

Essential Rhapsody in C++

Part OneBasic Rhapsody

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-2

Part One: Basic Rhapsody

• Setting up Rhapsody in C++

• Example : Hello world

• Example : Count down

• Properties

• Example : Dishwasher

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-3

Setting Up Rhapsody

• Install Visual C++ 6.0 (or alternatively Visual Studio .NET or Borland bcc55)

• Install Rhapsody in C++ V4.1

• Install license (License.dat)

• Create a work directory ex: “C:\Work”

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-4

Before We Start

• Rhapsody uses C++ which is CASE sensitive. Most of the errors that occur during the training are generally due to entering text incorrectly.

• During this training, all classes will start with an upper case ex: “Training”.

• Often during the training course, students take differing lengths of time for completing the exercises. For those students who finish early, there is often an “Extended Exercise”.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-5

C++ Refresher

• The following concepts (possibly unfamiliar to C users) will be used during the training:– Constructor– Constructor initializer– Operator overloading– Destructor– New & Delete– Inheritance– Virtual operations

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-6

Part One : Example 1

Basic RhapsodyHello World

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-7

Creating a Project

• Start up Rhapsody in C++ (development edition)• Within Rhapsody, use the icon or file->new to create a new

project called Hello in directory c:\work

• Click Yes to create project.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-8

The Browser• The browser showing everything in the model is automatically started on opening a

project.

• An Object Model Diagram has also been created and displayed.

Browser

ObjectModel

Diagram

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-9

Drawing a Class

• In this Object Model Diagram, use the class icon to draw a class named Display.

There are two ways of deleting a class. It can be deleted from just the view “Remove from View” or deleted from the entire model “Delete from Model”.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-10

Adding a constructor• Expand the browser to see the class that we have just added.• Right-click on this class and “Add New ►Constructor”• We don’t need any arguments for our constructor so just click

OK.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-11

The Features Window

• Right-click on the constructor and display the Features.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-12

Adding some code

• Select the Implementation tab and enter the following:

std::cout << "Hello World" << std::endl;

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-13

Renaming a Component

• In order to generate code, we must first create a component. Expand the Components in the browser and rename the existing component called DefaultComponent to Test

Note that this component will generate an executable.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-14

The Test Component

• Now expand the Configurations and rename the DefaultConfig to Release

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-15

Initial Instance• Select the Initialization

tab, expand the Default package and select the Display class.

• This will now create an initial instance of the Display class

We will explain the difference between Explicit and Derived later.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-16

Settings

• We need to select an environment so that Rhapsody knows how to create an appropriate make file. Since we have Microsoft Visual C++ as our compiler, we’ll use the default setting which is Microsoft.

We’ll explain later the other settings such as instrumentation

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-17

Renaming our OMD

• Expand the Object Model Diagrams in the browser and use the features dialog to rename the diagram from Model1 to Overview.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-18

Generating Code

• We’re now ready to generate code.• First close the Features window (click OK)• Save the model • then Generate/Make/Run• Answer Yes to the question:

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-19

Hello World

• You should see the following:

• Stop the executable by either closing the console window or by using the command

If during compilation, there is a problem, then simply double-click on the error to go directly to the diagram or the part of the browser where the error occurred.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-20

The generated files

• The generated files will be in the directory C:\Work\Hello\Test\Release

executable

main

make file

Display class

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-21

Editing the Code

• We can edit the generated files from within Rhapsody.• Select the class Display in the browser, right-click and

select Edit Class

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-22

Modifying the Code• We can modify the generated code• In the Display.cpp file change:

std::cout << “Hello World” << std::endl;• to:

– std::cout << “Constructed” << std::endl;• Transfer the focus to another window to roundtrip the

modifications back into the model. • Note that the model has been automatically updated.

In general the roundtripping works pretty well, but beware not everything can be roundtripped!

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-23

Why doesn’t the constructor show up on the OMD?

• It doesn’t show up simply because we added it from the browser

• To display it on our diagram we can select the class on the Overview OMD, right-click and select Display Options …

• Select to display All or explicitly select the operation and it will appear.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-24

Displaying the Main and Make

• The Main and Make files can be displayed from within Rhapsody by simply right-clicking on the configuration and selecting edit :

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-25

Project Files

Generated files for the Test component

AutoSave

The model

ReverseEngineering Log(appeared when we

roundtripped)

Event History List(Will be used later when we animate)

RhapsodyWork Space

Visual BasicMacros

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-26

Part One : Example 2

Basic RhapsodyCount Down

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-27

Copying a Project• Select File -> Save As• Press to select the Work folder• Press to create a new folder• Rename “new folder” to “CountDown”• Select the new folder “CountDown”• Save the project as CountDown.rpy• The new CountDown project is opened in Rhapsody with the

previous project workspace preserved

Each time there is an auto-save, Rhapsody will only save just what has changed since the last auto-save.

Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003E1-28

3המשך בתרגיל • עד אז!countdownתשמור את תקיה של •שמירה ברשת:•

תעתיק את התקיה הראשית של הפרויקט החדש –לרשת. תפתח הפרויקט ברשת לוודא שהקבצים לא

השתבשו.ליתר ביטחון תשמור את הפרויקט במדיה נשלפת –

.disk on keyכמו , ליתר ביטחון תעשה את disk on keyאם אין לך –

וכדומה ותעתיר אותו zipהפרויקט החדש קובץ לרשת

בשום פנים ואופן אל תעבוד בפרויקט ברשת. –תעתיק אותו לדיסק המקומי, ורק בסוף תשמור אותו

ברשת.