OpenModelica/C3/Icon-and-Diagram-Views/English

From Script | Spoken-Tutorial
Jump to: navigation, search
Visual Cue Narration
Slide:

Title Slide

Welcome to the spoken tutorial on Icon and Diagram Views.
Slide:

Learning Objectives

In this tutorial, we are going to learn:
  • How to specify icon and diagram views of a class.
  • How to insert a polygon and ellipse in Icon/Diagram View.
Slide:

System Requirements

To record this tutorial, I am using:
  • OpenModelica version 1.9.2
  • You may use any of the following operating systems to practice this tutorial:

Linux, Windows, Mac OS X or FOSSEE OS on ARM.

Slide:

Prerequisites

* To understand and practice this tutorial, you need knowledge of class definition in Modelica.
  • You need to know how to specify annotations.
  • Prerequisite tutorials are mentioned on our website.

Please go through them.

Slide:

Icon and Diagram Views

Icon and Diagram Views enable viewing a model graphically.

Annotations can be used to specify Icon and Diagram Views of a model.

Icon View is specified using Icon Annotation whereas Diagram View is specified using Diagram Annotation.

They enable drag-and-drop functionality for component-oriented modeling.

We will discuss more about this feature in upcoming tutorials.

Slide:

Icon/Diagram Annotation

Now, let us try to understand the syntax of Icon and Diagram Annotations.

As we saw in previous tutorials, annotations can be better understood as records.


Hence, Icon and Diagram annotations can be considered

  • as records with coordinateSystem
  • and graphics as the fields.


We will look at each one of them individually.

Slide:

coordinateSystem

coordinateSystem may be considered as a record with the following fields:
  • extent,
  • initialScale,
  • preserveAspectRatio and
  • grid.

We will understand them through an example.

Slide:

Syntax of Icon/Diagram Annotation

Here is an example demonstrating the syntax of Icon/Diagram Annotation.
Switch to OMEdit Now et me switch to OMEdit.

We will understand icon and diagram annotations through an example named bouncingBallWithAnnotations.

Please download this file from our website.

This model was used in previous tutorials.

Please watch prerequisite tutorials for more information on this model.

Double-click icon I have already opened bouncingBallWithAnnotations in OMEdit.

Double-click on its icon in Libraries Browser.

Switch to Icon View The model is now open in Icon View.

Switch to Icon View if it opens in either Diagram or Text View.

Switch to OMEdit Let me shift OMEdit window to the left for better visibility.
Right-click on white space >> Select Properties. You can observe a circle on white background in Icon View of this model.
Point to the white space I will be referring to the white space in Icon View as canvas.

Note that the canvas is divided into grids.

We will first learn how to manipulate the properties of canvas.

Then we shall learn how to insert a circle and a polygon.

Right-click on canvas >> select Properties Right-click on the canvas beside circle.

Select Properties.

OMEdit - Properties A dialog box pop ups as shown.

Note that there are categories named

  • Extent,
  • Grid and
  • Component.
Point to Extent Extent signifies the extent of canvas.
Hover over Left and Top. The fields named Left and Top correspond to coordinates of top left corner of the canvas.

Left corresponds to the horizontal coordinate and Top corresponds to the vertical coordinate.

Hover over Bottom and Right Similarly, Bottom and Right correspond to the coordinates of bottom right corner of canvas.
‘Left’ → -200.00

Click on Ok.

Now, let us change the Left field to -200 units.

Click on Ok.

/* Icon View */ Note that the canvas expanded to the left by 100 units.
Right-click on white space. Select Properties. Right-click on canvas once again and select Properties.
Point to Grid Grid signifies the size of grid.

Note that the units of extent and grid differ by the Scale Factor.

Horizontal field = 4 >> click Ok Change horizontal field in grid to 4 units.

Click on OK.

Note that the size of grid has increased in the canvas.
These properties of Icon View can also be manipulated using Icon annotation in the Text View.

Note that any change in Icon View is accordingly reflected in Icon annotation.

Click on Text View >> Scroll down Let us try to understand this.

Go to the top of modeling area and click on Text View.

Scroll down a little bit.

/* bouncingBallWithAnnotations */

// Icon(coordinateSystem(extent = {{-200, -100}, {100, 100}}, grid = {4, 2})

//

coordinateSystem, as we have seen in slides, is a field in Icon annotation.
// Icon(coordinateSystem(extent = {{-200, -100}, {100, 100}}, grid = {4, 2})

//

extent is a field in coordinateSystem.

It has two pairs of numbers.

We have already seen how to manipulate the extent using Properties dialog box.

// Icon(coordinateSystem(extent = {{-200, -100}, {100, 100}}, .

//

The first pair of numbers is {-200,-100}.
// Icon(coordinateSystem(extent = {{-200, -100}, {100, 100}}, .

//

The first number of this pair that is -200 denotes the horizontal coordinate of the top left hand corner of canvas.
// Icon(coordinateSystem(extent = {{-200, -100}, {100, 100}}, .

//

Similarly, -100 represents the vertical coordinate of the same point.
// Icon(coordinateSystem(extent = {{-200, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {4, 2})

//

The second pair represents the coordinates of bottom right corner of white space.

Note that these 4 numbers correspond to top, bottom, left and right fields, we have seen in Properties dialog box.

Point to extent Now, let me change extent using Properties dialog box of Icon View.

We will then see if it changes correspondingly in annotation of Text View.

Click on Icon View. Let me switch to Icon View.
Right-click on white space >> Select Properties. Right-click on the canvas and select Properties.
Left → -150.00 >> Click on Ok. Change the Left field to -150.00.

Click on Ok.

Click on Text View. Click on Text View.

Scroll down.

// Icon(coordinateSystem(extent = {{-150, -100}, {100, 100}}, grid = {2, 2})

//

Notice that the first pair of coordinates in extent has changed to {-150,-100} from {-200,-100}.

This is due to the change that we have made in Icon View using Properties dialog box.

Hence, any change in Icon annotation creates a corresponding change in Icon View and vice-versa.

// Icon(coordinateSystem(extent = {{-150, -100}, {100, 100}}, grid = {4, 2})

//

A discussion of other fields of coordinateSystem like ScaleFactor is beyond the scope of this tutorial.
Back to the slides Let me go back to the slides.
Slide:

Graphical Items

We have discussed earlier that Icon annotation has coordinateSystem and graphics as its elements.

graphics record may have the following items:

  • Line
  • Rectangle
  • Ellipse
  • Polygon
  • Text and
  • Bitmap

Now, we will discuss how to insert these items in Icon and Diagram views.

Back to OMEdit Let me go back to OMEdit.
Point to circle We shall understand these annotations in three steps.

bouncingBallWithAnnotations already has a circle inserted in its Icon View.

The circle is obtained using Ellipse annotation.

Let us first try to modify its properties.

// graphics = {Ellipse(lineColor = {0, 0, 255}, fillColor = {85, 170, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}, endAngle = 360)} // Note that an Ellipse is inserted and its properties specified in graphics field of icon annotation.

Let me go to Icon View.

Right-click on blue space >> Select Properties. Right-click on the blue space within circle.

Select Properties.

Hover over OriginX and OriginY. OriginX is the horizontal coordinate of center of ellipse.

Similarly, OriginY is the vertical coordinate of the center of ellipse.

Hover over Extent1X Extent1X is the horizontal coordinate of left-most point on the ellipse.
Hover over Extent1Y Extent1Y is the vertical coordinate of top-most point on the ellipse.
Similarly, Extent2X and Extent2Y correspond to the right-most and bottom-most points on the ellipse.
Hover over Line Style Line Style is used to vary the properties of border line.
Click on Color. Choose Red in Color Palette. Click on Color under Line Style.

This allows you to change the color of border.

Let me choose red and click on OK.

Click on Pattern. Click on Pattern drop down menu under Line Style.

This allows you to change the pattern of border.

I have chosen a solid line.

Click on Thickness. Thickness field specifies the thickness of border.

Change it to 0.5 units.

Click on Ok. Click on Ok
Notice the change in color of border to red and the increase in thickness.
Right-click on Ellipse. Select Properties Now right click on the circle once again and select Properties.
Click on Color Fill Style Under Fill Style, click on Color.
Choose Black in Color Palette. Choose Black in the Color Palette.

Click on Ok.

This color represents the color to be filled in the interior of the ellipse.

Click on FillPattern >> click on Ok Now click on Fill Pattern drop-down menu.

Choose FillPattern.Horizontal and click on Ok.

Note that the fill color changed to black

and the pattern changed from solid to horizontal lines.

Click on Text View Let me now switch to Text View to explain Ellipse annotation.

Click on Text View.

Scroll down.

// graphics = {Ellipse(lineColor = {0, 0, 255}, fillColor = {85, 170, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}, endAngle = 360) // lineColor takes three numbers which define the color of border.

Each of these three numbers can take values between 0 and 255.

They correspond to the RGB intensity of the color used.

graphics = {Ellipse(lineColor = {0, 0, 255}, fillColor = {85, 170, 255}, fillPattern = FillPattern.Horizontal, extent = {{-100, 100}, {100, -100}}, endAngle = 360) fillPattern specifies the pattern to be filled in the interior.
graphics = {Ellipse(lineColor = {0, 0, 255}, fillColor = {85, 170, 255}, fillPattern = FillPattern.Horizontal, extent = {{-100, 100}, {100, -100}}, endAngle = 360) extent is identical in context to the extent field of coordinateSystem.

LineThickness represents the thickness of border.

Note that all these fields can be changed using Properties dialog box as we have already seen.

Click on Icon View. Now, let me switch to Icon View to construct a new ellipse using the tool bar.

Click on Icon View.

Let me rearrange the existing circle to free up some space.
Right-click on circle and select Properties. Right click on the circle and choose properties.
‘Extent2Y’ → 0

Click on Ok.

Change Extent2Y to 0 units.

Click on Ok.

Click on Ellipse button in the toolbar Now to insert a new ellipse, click on Ellipse button in the toolbar.
Hold and drag the cursor Left click somewhere in the canvas and hold the mouse and drag it.

Leave the mouse after an ellipse has been created.

Right-click on Ellipse >> Click on Ok Right-click on the ellipse and select Properties to change its properties as you wish.

Click on Ok

Hover over the following tools:
  • Line
  • Polygon
  • Rectangle
  • Text
Similarly, you may insert a Line, Polygon, Rectangle and Text using the Tool Bar.
Click on Diagram View Now, let me explain Diagram View.

Click on Diagram View.

Note that a line has been inserted here.

The properties of this line are specified in Diagram annotation.

Click on Text View. Switch to Text View to understand Diagram annotation.

Scroll down.

Diagram(...) Diagram annotation is similar in its syntax to Icon annotation.

It has coordinateSystem and graphics as its component records.

Diagram(...,, graphics = {Line(origin = {-10, 0}, points = {{-50, -50}, {50, 50}}, color = {0, 0, 255}, pattern = LinePattern.Dash, thickness = 3)}) The properties of the Line inserted in Diagram View are specified here.

The fields of Line annotation can be easily understood.

Now, let us understand the difference between Icon and Diagram Views.

Shift OMEdit Window to the right Let me shift OMEdit Window to the right.
Press Ctrl+S Save the model by pressing Ctrl + S.
The figure shown in Icon View appears as an icon in the Libraries Browser as can be seen here.
Whereas the Diagram View is used significantly in component-oriented modeling.

We shall learn more about component-oriented modeling in the upcoming tutorials.

Back to the slides Now let me go back to the slides.
Slide: Ellipse Ellipse has the following fields as we have already discussed.
Slide:

Assignment

As an assignment, insert a line, polygon, rectangle and text in the Icon View of model.

Modify their properties and understand their annotations.

This brings us to the end of this tutorial.
Slide:

About the Spoken Tutorial project

Watch the video available at the following link.

It summarises the spoken tutorial project.

Slide:

Spoken Tutorial Workshops

We conduct workshops using spoken tutorials

Please contact us.

Slide:

Forum to answer questions

If you have questions in this spoken tutorial, please visit the following website.
Slide:

Textbook Companion Project

We coordinate coding of solved examples of popular books.

Please visit the website shown.

Slide:

Lab Migration Project

We help migrate commercial simulator labs to OpenModelica.

Please visit the website for more information on our lab migration project.

Slide:

Acknowledgements

Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
Slide:

Thanks

We thank the development team of OpenModelica for their support.

Thank you for joining me in this tutorial.

Contributors and Content Editors

Kaushik Datta, Nancyvarkey