CLASS windows IS

 PASSIVE

pragmas

PRAGMA init_bloc
        (init_op => initialize)

DESCRIPTION

PROBLEM

Statement of the Problem (text)

Manager for simple, nonoverlapping windows for alpha-numeric console.

Referenced Documents (text)

This application is the HOOD version of "Dining Philosophers - Ada95 edition" from Michael B. Feldman, The George Washington University, July 1995.
HOOD adaptation was performed by Pierre Dissaux, TNI, June 1998, with STOOD toolset.

Analysis of Requirements

Structural Requirements (text)

SR4: This modules implements an abstract simple window manager. (cf.SR4/Display_windows:)

Functionnal Requirements (text)

FR4: Open and initialize a window. (cf.FR4/Open&initialize_window:)
FR5: Write messages at a specified location on the window. (cf.FR5/Write_messages:)

Behavioural Requirements (text)

Windows are passive unshared objects. There is no particular behaviour requirements.

Local Environment

Parent General Description (text)

Please refer to parent module description.

SOLUTION

General Strategy (text)

Window module is designed as a passive HOOD4 class.
It describes a window data structure and all relevant functional services.

Code generator will produce a package containing a tagged type.

Structural Description

Identification of Data Structures (text)

SR4: type Window is a class which attributes describe first, last and current positions of the cursor on the screen.

Functional Description

Identification of Operations (text)

Following operations are primitive operations of type Window:
FR4: 
- Initialize: package init block is used to clear the screen.
- Open: instanciates a new window and initialize its attributes with passed values.
- Title: writes a title and optionnaly a separation line.
- Borders: draws top, right, left and bottom lines.
FR5:
- MoveCursor: sets current cursor position.
- Put#1: writes a character at current cursor position.
- Put#2: writes a string at current cursor location.
- New_Line: puts current cursor position at the beginning of next line.
- EraseToEndOfLine: erases from current location to the end of line.

Grouping Operations (text)

None

Behavioural Description

Identification of Local Behaviour (text)

None

Justification of Design Decisions (text)

A few changes in initial source code were done to best fit HOOD4 design rules:
- Window was declared as a HOOD4 class, so code generator produces a tagged type by default.
- Name of the parameter of type Window in all primitive operation declarations was set to "me".

PROVIDED_INTERFACE

TYPES

Window

type description (text)

First : coordinates of upper left corner;
Last : coordinates of lower right corner;
Current : current cursor position.

class inheritance (hood)

INHERITANCE NONE

type attributes (hood)

ATTRIBUTES First : screen.Position, Last : screen.Position, Current : screen.Position

type enumeration (hood)

ENUMERATION NONE

type pre-declaration (ada)

type Window is private;

OPERATIONS

open

operation spec. description (text)

Pre:        UpperLeft, Weight, and Width are defined
Post:        returns a Window with the given upper-left corner, height, and width

operation declaration (hood)

open(
        UpperLeft : in Screen.Position;
        Height : in Screen.Height;
        Width : in Screen.Width
)        return Window;

real time attributes (hood)

WCET

title

operation spec. description (text)

Pre:         me, Name, and Under are defined
Post:        Name is displayed at the top of the window me, underlined with the character Under

operation declaration (hood)

title(
        me : in out Window;
        Name : in String;
        Under : in Character
);

real time attributes (hood)

WCET

borders

operation spec. description (text)

Pre:        All parameters are defined
Post:        Draw border around current writable area in window with characters specified. 
        Call this BEFORE Title.

operation declaration (hood)

borders(
        me : in out Window;
        Corner : in Character;
        Down : in Character;
        Across : in Character
);

real time attributes (hood)

WCET

movecursor

operation spec. description (text)

Pre:        me, and P are defined, and P lies within the area of me
Post:        Cursor is moved to the specified position.
        Coordinates are relative to the upper left corner of me, which is (1,1)

operation declaration (hood)

movecursor(me : in out Window; P : in Screen.Position);

real time attributes (hood)

WCET

put#1

operation spec. description (text)

Pre:        me, and Ch are defined.
Post:        Ch is displayed in the window at the next available position.
        If end of column, go to the next row.
        If end of window, go to the top of the window.

operation declaration (hood)

put#1(me : in out Window; Ch : in Character);

real time attributes (hood)

WCET

put#2

operation spec. description (text)

Pre:        me, and S are defined.
Post:        Ch is displayed in the window, "line-wrapped" if necessary

operation declaration (hood)

put#2(me : in out Window; S : in String);

real time attributes (hood)

WCET

new_line

operation spec. description (text)

Pre:        me is defined.
Post:        Cursor moves to beginning of next line of me;
        line is not blanked until next character is written

operation declaration (hood)

new_line(me : in out Window);

real time attributes (hood)

WCET

REQUIRED_INTERFACE

OBJECT screen;
        TYPES
                Height; Position; Width;
        CONSTANTS
                NONE
        OPERATION_SETS
                NONE
        OPERATIONS
                MoveCursor; ClearScreen;
        EXCEPTIONS
                NONE
OBJECT standard;
        TYPES
                Character; String;
        CONSTANTS
                NONE
        OPERATION_SETS
                NONE
        OPERATIONS
                NONE
        EXCEPTIONS
                NONE
OBJECT text_io;
        TYPES
                NONE
        CONSTANTS
                NONE
        OPERATION_SETS
                NONE
        OPERATIONS
                Put; New_Line;
        EXCEPTIONS
                NONE

INTERNALS

OPERATIONS

erasetoendofline

operation spec. description (text)

Used to erase partially the screen.

operation declaration (hood)

erasetoendofline(me : in out Window);

real time attributes (hood)

WCET

initialize

operation spec. description (text)

This HOOD operation will not be generated as an Ada procedure, but as package initialization block.
This result is obtained by setting pragma "init_bloc(initialize)" when generating Ada code.

operation declaration (hood)

initialize;

real time attributes (hood)

WCET

OPERATION_CONTROL_STRUCTURES

OPERATION open IS

operation body description (text)

Instanciates a new Window named "Result"
Sets Result attributes (Current, First and Last)
Returns Result.

operation code (ada)

  Result : Window;
begin
  Result.Current := UpperLeft;
  Result.First := UpperLeft;
  Result.Last := (Row => UpperLeft.Row + Height - 1,
                  Column => UpperLeft.Column + Width - 1);
  return Result;

END open

OPERATION title IS

operation body description (text)

Sets cursor at the beginning of first line.
Writes title string
If "Under" is blank then continue
else draw a separation line
Reduces writable area as required.

used operations

windows.put
windows.new_line

operation code (ada)

begin

  -- Put name on top line
  me.Current := me.First;
  Put(me, Name);
  New_Line(me);

  -- Underline name if desired, and reduce the writable area
  -- of the window by one line
  if Under = ' ' then
    -- no underlining
    me.First.Row := me.First.Row + 1;
  else
    -- go across the row, underlining
    for Count in me.First.Column..me.Last.Column loop
      Put(me, Under);
    end loop;
    New_Line(me);
    -- reduce writable area
    me.First.Row := me.First.Row + 2;
  end if;

call tree from Ada code

END title

OPERATION borders IS

operation body description (text)

Draws top line border.
Draws the two side lines.
Draws the bottom line of the border.
Make the Window smaller by one character on each side.

used operations

screen.MoveCursor
text_io.Put

operation code (ada)

begin

  -- Put top line of border
  Screen.MoveCursor(me.First);
  Text_IO.Put(Corner);
  for Count in me.First.Column+1 .. me.Last.Column-1 loop
    Text_IO.Put(Across);
  end loop;
  Text_IO.Put(Corner);

  -- Put the two side lines
  for Count in me.First.Row+1 .. me.Last.Row-1 loop
    Screen.MoveCursor((Row => Count,Column => me.First.Column));
    Text_IO.Put(Down);
    Screen.MoveCursor((Row => Count,Column => me.Last.Column));
    Text_IO.Put(Down);
  end loop;

  -- Put the bottom line of the border
  Screen.MoveCursor((Row => me.Last.Row,Column => me.First.Column));
  Text_IO.Put(corner);
  for Count in me.First.Column+1 .. me.Last.Column-1 loop
    Text_IO.Put (Across);
  end loop;
  Text_IO.Put(Corner);

  -- Make the Window smaller by one character on each side
  me.First := (Row => me.First.Row+1,Column => me.First.Column+1);
  me.Last := (Row => me.Last.Row-1,Column => me.Last.Column-1);
  me.Current := me.First;

call tree from Ada code

END borders

OPERATION movecursor IS

operation body description (text)

Cursor position passed as parameter is relative to window boundaries.

operation code (ada)

-- Relative to writable Window boundaries, of course
begin
  me.Current.Row := me.First.Row + P.Row;
  me.Current.Column := me.First.Column + P.Column;

END movecursor

OPERATION put#1 IS

operation body description (text)

If at end of current line then move to next line.
If at beginning of current line then erase the entire line.
Writes given character.

used operations

windows.erasetoendofline
screen.MoveCursor
text_io.Put

operation code (ada)

begin

  -- If at end of current line, move to next line
  if me.Current.Column > me.Last.Column then
    if me.Current.Row = me.Last.Row then
      me.Current.Row := me.First.Row;
    else
      me.Current.Row := me.Current.Row + 1;
    end if;
    me.Current.Column := me.First.Column;
  end if;

  -- If at First char, erase line
  if me.Current.Column = me.First.Column then
    EraseToEndOfLine(me);
  end if;

  Screen.MoveCursor(To => me.Current);

  -- here is where we actually write the character!
  Text_IO.Put(Ch);
  me.Current.Column := me.Current.Column + 1;

call tree from Ada code

END put#1

OPERATION put#2 IS

operation body description (text)

Uses put#1 to write each character of the string.

operation code (ada)

begin
  for Count in S'Range loop
    Put(me, S (Count));
  end loop;

END put#2

OPERATION new_line IS

operation body description (text)

If cursor is at beginning of a line then first erase this line.
If cursor is on last line then put it on first line.
Else put it on next line.

used operations

windows.erasetoendofline

operation code (ada)

begin
  if me.Current.Column = 1 then
    EraseToEndOfLine(me);
  end if;
  if me.Current.Row = me.Last.Row then
    me.Current.Row := me.First.Row;
  else
    me.Current.Row := me.Current.Row + 1;
  end if;
  me.Current.Column := me.First.Column;

call tree from Ada code

END new_line

OPERATION erasetoendofline IS

operation body description (text)

Puts blank characters from current cursor position to the end of current line.
Current cursor position remains unchanged.

used operations

screen.MoveCursor
text_io.Put

operation code (ada)

begin
  Screen.MoveCursor (me.Current);
    for Count in me.Current.Column .. me.Last.Column loop
      Text_IO.Put (' ');
    end loop;
  Screen.MoveCursor (me.Current);

call tree from Ada code

END erasetoendofline

OPERATION initialize IS

operation body description (text)

Clears the screen.

used operations

text_io.New_Line
screen.ClearScreen

operation code (ada)

begin
  Text_IO.New_Line;
  Screen.ClearScreen;
  Text_IO.New_Line;

call tree from Ada code

END initialize

END windows