Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Prm Class Reference

#include <prm.h>

Inheritance diagram for Prm:

[legend]
Collaboration diagram for Prm:
[legend]
List of all members.
Date:
14-May-2011
Author:
Luiz F. Martha
Version:
1.0
This file contains the implementation of the primitive class the current project.

See class definition in hearder file "prm.h".

For specification see class notes of course CIV-2802 "Sistemas Graficos para Engenharia", period 2011.1.

Revisions:

  • Version 1.0 by L.F. Martha on 14-May-2011: Initial version. Stolen from Trab3 of CIV2802-2010.1 and modified.


 Prm ()
 This function creates a new primitive, puts it at the beginning of the list of primitives.
 Prm (int back)
 This function creates a new primitive, puts it at the end of the list of primitives if the "back" argument is true (1).
virtual ~Prm ()
 This function removes a primitive from the current list of primitives and releases memory that is used by it.
PrmNext (void)
 This function returns a pointer to the next primitive in relation to the current primitive.
PrmPrevious (void)
 This function returns a pointer to the previous primitive in relation to the given current primitive.
void MoveFront (void)
 This function moves the current primitive to the first position in the list of primitives.
void MoveBack (void)
 This function moves the current primitive to the last position in the list of primitives.
Prm::Type GetType (void)
 This function returns (as its value) a code indicating the type of the current primitive.
void Select (void)
 This function selects the current primitive, i.e.
void Unselect (void)
 This function unselects the given current primitive, i.e.
int CheckSelected (void)
 This function returns the selection status (false = 0; true = 1) of the current primitive.
void SetColor (long int color)
 This function sets the color of the current primitive.
long int GetColor (void)
 This function returns the color of the current primitive.
void SetHeight (double height)
 This function sets the height of the current primitive.
double GetHeight (void)
 This function returns the height of the given primitive.
static bool ChkEmptyModel (void)
 This function returns a status indicating whether the current the model is empty.
static void DeleteList (void)
 This function realeases the memory that is used by the current list of primitives and resets the list.
static PrmFirst (void)
 This function returns a pointer to the first primitive of the current list.
static PrmLast (void)
 This function returns a pointer to the last primitive of the current list.
static void SelectAll (void)
 This function selects all the primitives in the current list of primitives, i.e.
static void UnselectAll (void)
 This function unselects all the primitives in the current list of primitives, i.e.
static int GetGlobalBox (double *xmin, double *xmax, double *ymin, double *ymax)
 This function returns the limiting rectangle that involves all the primitives in the current list.
void Reset (void)
 This function sets a null value for the next and previous pointers, sets an undefined primitive type, and sets a null color, selection flag, and height values.
void InsertFront (void)
 This function inserts the current primitive at the beginning of the list of primitives.
void InsertBack (void)
 This function inserts the current primitive at the end of the list of primitives.
void RemoveFromList (void)
 This function removes the current primitive from the list.
static Prmprm_head = 0L
 Head of doubly-linked list of primitives.

Public Types

enum  Type { PRM_UNDEF, PRM_QUAD, PRM_CIRC, NumPrmTypes }
 Primitive types. More...

Public Member Functions

virtual void Read (FILE *fd)=0
 This function reads geometry data of a primitive from a file (given by its pointer) and loads the data into the primitive attributes.
virtual void Write (FILE *fd)=0
 This function writes the geometry attribute data of a primitive to a file (given by its pointer).
virtual int GetNPts (void)=0
 This function returns (as its value) the number of vertices of the current primitive.
virtual void SetCoords (int id, double x, double y)=0
 This function replaces the x and y coordinates of a vertex of the current primitive by the given pair of coordinates.
virtual void GetCoords (int id, double *x, double *y)=0
 This function returns the x and y coordinates of a vertex of the current primitive.
virtual void Set1stPt (double x, double y)=0
 This function is used during interactive construction of a primitive.
virtual void Set2ndPt (double x, double y)=0
 This function is used during interactive construction of a primitive.
virtual int PickArea (double x, double y)=0
 This function checks whether a given point is in the interior of a primitive.
virtual int PickVertex (double x, double y, double tol, int *id)=0
 This function selects a vertex on the boundary of a primitive based on the given point position.
virtual int PickSide (double x, double y, double tol, int *id)=0
 This function selects a side on the boundary of a primitive based on the given point position.
virtual void Translate (double dx, double dy)=0
 This function translates the current primitive All the vertices of the primitive are translated by the given translation factors.
virtual void TranslateVertex (int id, double dx, double dy)=0
 This function translates a vertex of a primitive using the given translation factors.
virtual void TranslateSide (int id, double dx, double dy)=0
 This function translates the two vertices of a side of a primitive using the given translation factors.
virtual void GetBox (double *xmin, double *xmax, double *ymin, double *ymax)=0
 This function returns the limiting rectangle that involves the current primitive.
virtual void DisplayBoundary (cdCanvas *canvas)=0
 This function displays the boundary of the current primitive.
virtual void DisplayInterior (cdCanvas *canvas)=0
 This function displays the interior of the current primitive The interior area is filled with the currently specified background color.

Protected Attributes

Type type
 Primitive type.

Private Attributes

Prmnext
 Next primitive in linked list.
Prmprev
 Previous primitive in linked list.
int sel
 Flag for selected primitive.
long int color
 Coded RGB color.
double height
 Height of primitive (only used in 3D).

Classes

struct  Coord
 Primitive vertex coordinate structure. More...

Member Enumeration Documentation

enum Prm::Type
 

Primitive types.

Enumeration values:
PRM_UNDEF  Undefined primitive.
PRM_QUAD  Quadrilateral primitive.
PRM_CIRC  Circle primitive.
NumPrmTypes  Total number of primitives.

Definition at line 74 of file prm.h.


Constructor & Destructor Documentation

Prm::Prm  ) 
 

This function creates a new primitive, puts it at the beginning of the list of primitives.

The head pointer to the list is modified accordingly. The special case of a current empty list is also treated.

Definition at line 53 of file prm.cpp.

References InsertFront(), and Reset().

Prm::Prm int  back  ) 
 

This function creates a new primitive, puts it at the end of the list of primitives if the "back" argument is true (1).

If the "back" is false (0), the primitive is put at the beginning of the list of primitives. The head pointer to the list is modified accordingly. The special case of a current empty list is also treated.

Parameters:
back - back status (1 => end, 0 => beginning) (in)

Definition at line 61 of file prm.cpp.

References InsertBack(), InsertFront(), and Reset().

Prm::~Prm  )  [virtual]
 

This function removes a primitive from the current list of primitives and releases memory that is used by it.

The head pointer to the list of primitives may be modified accordingly. The special case of a resulting empty list is also treated.

Definition at line 72 of file prm.cpp.

References RemoveFromList().


Member Function Documentation

int Prm::CheckSelected void   ) 
 

This function returns the selection status (false = 0; true = 1) of the current primitive.

Returns:
Selection flag (false = 0; true = 1) of the given primitive.

Definition at line 343 of file prm.cpp.

References sel.

Referenced by Model::Display().

bool Prm::ChkEmptyModel void   )  [static]
 

This function returns a status indicating whether the current the model is empty.

The returned status is true if the model is empty. Otherwise the returned status is false.

Definition at line 84 of file prm.cpp.

References First().

Referenced by Model::ChkEmptyModel(), PrmEd::DeleteSelPrm(), PrmEd::FinishDragPrm(), PrmEd::GetHeightFac(), PrmEd::MoveSelPrmToBack(), PrmEd::MoveSelPrmToFront(), Model::Save(), PrmEd::SelectDragPrm(), PrmEd::SetColor(), PrmEd::SetHeightFac(), and PrmEd::UpdateDragPrm().

void Prm::DeleteList void   )  [static]
 

This function realeases the memory that is used by the current list of primitives and resets the list.

The function sets a null value for its head pointer.

Definition at line 91 of file prm.cpp.

References prm_head.

Referenced by Model::Open(), Model::Reset(), and Model::~Model().

virtual void Prm::DisplayBoundary cdCanvas *  canvas  )  [pure virtual]
 

This function displays the boundary of the current primitive.

The function only deals with the geometric attributes of the primitive. This means that other attributes such as foreground color, line style, or mark type are specified outside this function.

Parameters:
canvas - CD handle to data canvas (in)

Implemented in Circ, and Quad.

Referenced by Model::Display(), and PrmEd::DspTmpPrmLines().

virtual void Prm::DisplayInterior cdCanvas *  canvas  )  [pure virtual]
 

This function displays the interior of the current primitive The interior area is filled with the currently specified background color.

The function only deals with the geometric attributes of the primitive. This means that other attributes such as background color or interior style are specified outside this function.

Parameters:
canvas - CD handle to data canvas (in)

Implemented in Circ, and Quad.

Referenced by Model::Display().

Prm * Prm::First void   )  [static]
 

This function returns a pointer to the first primitive of the current list.

Returns:
Pointer to first primitive. If the list is empty, it returns a null pointer.

Definition at line 101 of file prm.cpp.

References prm_head.

Referenced by ChkEmptyModel(), GetGlobalBox(), SelectAll(), PrmEd::SelectDragPrm(), UnselectAll(), and PrmIO::WriteList().

virtual void Prm::GetBox double *  xmin,
double *  xmax,
double *  ymin,
double *  ymax
[pure virtual]
 

This function returns the limiting rectangle that involves the current primitive.

This rectangle is the primitive bounding box, which is parallel to the x and y axes, with the minimum and maximum x and y coordinates of the primitive's vertices.

Parameters:
xmin,xmax - limiting x coordinates of primitive (out)
ymin,ymax - limiting y coordinates of primitive (out)

Implemented in Circ, and Quad.

Referenced by GetGlobalBox().

long int Prm::GetColor void   ) 
 

This function returns the color of the current primitive.

The color is returned in a long integer with a coded RGB color (adopted in the CD graphics system).

Returns:
Coded RGB color of given primitive.

Definition at line 357 of file prm.cpp.

References color.

Referenced by Model::Display(), and PrmIO::WriteList().

virtual void Prm::GetCoords int  id,
double *  x,
double *  y
[pure virtual]
 

This function returns the x and y coordinates of a vertex of the current primitive.

The vertex is indicated by an index to the local array of vertices of the primitive. Nothing will happen if the given index is outside the range of valid indices of vertices.

Parameters:
id - index of target vertex in primitive (in)
x - vertex x coordinate (out)
y - vertex y coordinate (out)

Implemented in Circ, and Quad.

int Prm::GetGlobalBox double *  xmin,
double *  xmax,
double *  ymin,
double *  ymax
[static]
 

This function returns the limiting rectangle that involves all the primitives in the current list.

This rectangle is the bounding box of the current set of primitives, which is parallel to the x and y axes, with the minimum and maximum x and y coordinates of all primitive's vertices.

Parameters:
xmin,xmax - limiting x coordinates of all primitives (out)
ymin,ymax - limiting y coordinates of all primitives (out)
Returns:
If the list of primitives is empty, a false (0) status is returned. Otherwise, a true (1) status is returned.

Definition at line 142 of file prm.cpp.

References First(), GetBox(), Next(), next, and prm_head.

Referenced by Model::GetGlobalBox(), and Model::Open().

double Prm::GetHeight void   ) 
 

This function returns the height of the given primitive.

The height is used only in 3D applications.

Returns:
Height of given primitive (3D only).

Definition at line 371 of file prm.cpp.

References height.

Referenced by PrmEd::GetHeightFac(), and PrmIO::WriteList().

virtual int Prm::GetNPts void   )  [pure virtual]
 

This function returns (as its value) the number of vertices of the current primitive.

Returns:
The number of vertices of the given primitive.

Implemented in Circ, and Quad.

Prm::Type Prm::GetType void   ) 
 

This function returns (as its value) a code indicating the type of the current primitive.

Returns:
The type the given primitive.

Definition at line 322 of file prm.cpp.

References type.

Referenced by PrmIO::WriteList().

void Prm::InsertBack void   )  [private]
 

This function inserts the current primitive at the end of the list of primitives.

It handles the case of an empty list (this is indicated by a null head pointer). In this case, it sets the previous and next pointers of the current primitive pointing to itself. Otherwise, it sets the next pointer of the current primitive to point to the first primitive, sets the previous pointer of the current primitive to point to the last primitive, sets the previous pointer of the first primitive to point to the current primitive, and sets the next pointer of the last primitive to point to the current primitive. If the list is not empty, the list head pointer is not changed.

Definition at line 210 of file prm.cpp.

References next, prev, and prm_head.

Referenced by MoveBack(), and Prm().

void Prm::InsertFront void   )  [private]
 

This function inserts the current primitive at the beginning of the list of primitives.

It handles the case of an empty list (this is indicated by a null head pointer). In this case, it sets the previous and next pointers of the current primitive pointing to itself. Otherwise, it sets the next pointer of the current primitive to point to the first primitive, sets the previous pointer of the current primitive to point to the last primitive, sets the previous pointer of the first primitive to point to the current primitive, and sets the next pointer of the last primitive to point to the current primitive. In any case, the list head pointer will point to the current primitive.

Definition at line 189 of file prm.cpp.

References next, prev, and prm_head.

Referenced by MoveFront(), and Prm().

Prm * Prm::Last void   )  [static]
 

This function returns a pointer to the last primitive of the current list.

Returns:
Pointer to last primitive. If the list is empty, it returns a null pointer.

Definition at line 108 of file prm.cpp.

References prev, and prm_head.

Referenced by Model::Display().

void Prm::MoveBack void   ) 
 

This function moves the current primitive to the last position in the list of primitives.

Nothing will happen if the given primitive is already the last of the list.

Definition at line 301 of file prm.cpp.

References InsertBack(), prev, prm_head, and RemoveFromList().

Referenced by PrmIO::Interpret(), and PrmEd::MoveSelPrmToBack().

void Prm::MoveFront void   ) 
 

This function moves the current primitive to the first position in the list of primitives.

The head pointer to the list is modified accordingly. Nothing will happen if the given primitive is already the first of the list.

Definition at line 280 of file prm.cpp.

References InsertFront(), prm_head, and RemoveFromList().

Referenced by PrmIO::Interpret(), and PrmEd::MoveSelPrmToFront().

Prm * Prm::Next void   ) 
 

This function returns a pointer to the next primitive in relation to the current primitive.

Returns:
Pointer to next primitive. If the given primitive is the last in the list, a null pointer is returned.

Definition at line 260 of file prm.cpp.

References next, prev, and prm_head.

Referenced by GetGlobalBox(), SelectAll(), PrmEd::SelectDragPrm(), UnselectAll(), and PrmIO::WriteList().

virtual int Prm::PickArea double  x,
double  y
[pure virtual]
 

This function checks whether a given point is in the interior of a primitive.

Parameters:
x - x coordinate of given point (in)
y - y coordinate of given point (in)
Returns:
In case the given point is inside the given primitive, a true (1) status is returned. Otherwise, a false (0) status is returned.

Implemented in Circ, and Quad.

Referenced by PrmEd::SelectDragPrm().

virtual int Prm::PickSide double  x,
double  y,
double  tol,
int *  id
[pure virtual]
 

This function selects a side on the boundary of a primitive based on the given point position.

Parameters:
x - x coordinate of given point (in)
y - y coordinate of given point (in)
tol - tolerance value to check proximity (in)
id - returned primitive side index (out)
Returns:
In case the given point is close to a side of the target primitive, the function returns a true (1) status and the index of the selected side is returned as a parameter. In case no side if found close to the given point, the function returns a false (0) status.

Implemented in Circ, and Quad.

Referenced by PrmEd::SelectDragPrm().

virtual int Prm::PickVertex double  x,
double  y,
double  tol,
int *  id
[pure virtual]
 

This function selects a vertex on the boundary of a primitive based on the given point position.

Parameters:
x - x coordinate of given point (in)
y - y coordinate of given point (in)
tol - tolerance value to check proximity (in)
id - returned primitive vertex index (out)
Returns:
In case the given point is close to a vertex on the boundary of the primitive, the function returns a true (1) status and returns the index of the found vertex. Otherwise, the function returns a false (0) status.

Implemented in Circ, and Quad.

Referenced by PrmEd::SelectDragPrm().

Prm * Prm::Previous void   ) 
 

This function returns a pointer to the previous primitive in relation to the given current primitive.

Returns:
Pointer to previous primitive. If the given primitive is the first in the list, a null pointer is returned.

Definition at line 270 of file prm.cpp.

References prev, and prm_head.

Referenced by Model::Display().

virtual void Prm::Read FILE *  fd  )  [pure virtual]
 

This function reads geometry data of a primitive from a file (given by its pointer) and loads the data into the primitive attributes.

Parameters:
fd - ponter to file descriptor (in)

Implemented in Circ, and Quad.

Referenced by PrmIO::Interpret().

void Prm::RemoveFromList void   )  [private]
 

This function removes the current primitive from the list.

The primitive removal from list modifies the next pointer of the previous primitive in the list and modifies the previous pointer of the next primitive in the list. This function also treates the situation of a single primitive list, in which case the list head pointer is reset to a null value. Otherwise, the list head pointer will be affected only in the case in which the primitive being removed is at the beginning of the list: the new list head pointer will point to the primitive next to the primitive being removed.

Definition at line 231 of file prm.cpp.

References next, prev, and prm_head.

Referenced by MoveBack(), MoveFront(), and ~Prm().

void Prm::Reset void   )  [private]
 

This function sets a null value for the next and previous pointers, sets an undefined primitive type, and sets a null color, selection flag, and height values.

Definition at line 175 of file prm.cpp.

References color, height, next, prev, PRM_UNDEF, sel, and type.

Referenced by Prm().

void Prm::Select void   ) 
 

This function selects the current primitive, i.e.

, it sets the selection flag of the primitive.

Definition at line 329 of file prm.cpp.

References sel.

Referenced by PrmEd::InsertPrm1stPt(), and PrmEd::SelectDragPrm().

void Prm::SelectAll void   )  [static]
 

This function selects all the primitives in the current list of primitives, i.e.

, it sets the selection flag of all the primitives.

Definition at line 118 of file prm.cpp.

References First(), Next(), and sel.

virtual void Prm::Set1stPt double  x,
double  y
[pure virtual]
 

This function is used during interactive construction of a primitive.

It sets the x and y coordinates of the first construction point of the current primitive by the given pair of coordinates.

Parameters:
x - first point x coordinate (in)
y - first point y coordinate (in)

Implemented in Circ, and Quad.

Referenced by PrmEd::InsertPrm1stPt().

virtual void Prm::Set2ndPt double  x,
double  y
[pure virtual]
 

This function is used during interactive construction of a primitive.

It sets the x and y coordinates of the second construction point of the current primitive by the given pair of coordinates.

Parameters:
x - second point x coordinate (in)
y - second point y coordinate (in)

Implemented in Circ, and Quad.

Referenced by PrmEd::EchoPrm2ndPt(), and PrmEd::InsertPrm2ndPt().

void Prm::SetColor long int  color  ) 
 

This function sets the color of the current primitive.

The color is given by a long integer with a coded RGB color (adopted in the CD graphics system).

Parameters:
color - coded RGB color (in)

Definition at line 350 of file prm.cpp.

Referenced by PrmEd::InsertPrm1stPt(), PrmIO::Interpret(), and PrmEd::SetColor().

virtual void Prm::SetCoords int  id,
double  x,
double  y
[pure virtual]
 

This function replaces the x and y coordinates of a vertex of the current primitive by the given pair of coordinates.

The vertex is indicated by an index to the local array of vertices of the primitive. Nothing will happen if the given index is outside the range of valid indices of vertices.

Parameters:
id - index of target vertex in primitive (in)
x - new vertex x coordinate (in)
y - new vertex y coordinate (in)

Implemented in Circ, and Quad.

void Prm::SetHeight double  height  ) 
 

This function sets the height of the current primitive.

The height is used only in 3D applications.

Parameters:
height - height of primitive (3D only) (in)

Definition at line 364 of file prm.cpp.

Referenced by PrmIO::Interpret(), and PrmEd::SetHeightFac().

virtual void Prm::Translate double  dx,
double  dy
[pure virtual]
 

This function translates the current primitive All the vertices of the primitive are translated by the given translation factors.

Parameters:
dx,dy - translation factors in x & y directions (in)

Implemented in Circ, and Quad.

Referenced by PrmEd::FinishDragPrm(), PrmIO::Interpret(), and PrmEd::UpdateDragPrm().

virtual void Prm::TranslateSide int  id,
double  dx,
double  dy
[pure virtual]
 

This function translates the two vertices of a side of a primitive using the given translation factors.

The target side is indicated by an index, which should have a value between 0 and the number of primitive vertices minus one. Nothing will happen if the given index is outside this range. The index of a side corresponds to the index of its first vertex.

Parameters:
id - index of side to translate (0..npts-1) (in)
dx,dy - translation factors in x & y directions (in)

Implemented in Circ, and Quad.

Referenced by PrmEd::FinishDragPrm(), PrmIO::Interpret(), and PrmEd::UpdateDragPrm().

virtual void Prm::TranslateVertex int  id,
double  dx,
double  dy
[pure virtual]
 

This function translates a vertex of a primitive using the given translation factors.

The target vertex is indicated by its index to the primitive coordinate vector, which should have a value between 0 and the number of vertices minus one. Nothing will happen if the given index is outside this range.

Parameters:
id - index of vertex to translate (0..npts-1) (in)
dx,dy - translation factors in x & y directions (in)

Implemented in Circ, and Quad.

Referenced by PrmEd::FinishDragPrm(), PrmIO::Interpret(), and PrmEd::UpdateDragPrm().

void Prm::Unselect void   ) 
 

This function unselects the given current primitive, i.e.

, it resets (sets to null) the selection flag of the primitive.

Definition at line 336 of file prm.cpp.

References sel.

void Prm::UnselectAll void   )  [static]
 

This function unselects all the primitives in the current list of primitives, i.e.

, it resets (sets to null) the selection flag of all the primitives.

Definition at line 130 of file prm.cpp.

References First(), Next(), and sel.

Referenced by PrmEd::SelectDragPrm(), and PrmEd::UnselectAllPrm().

virtual void Prm::Write FILE *  fd  )  [pure virtual]
 

This function writes the geometry attribute data of a primitive to a file (given by its pointer).

Parameters:
fd - ponter to file descriptor (in)

Implemented in Circ, and Quad.

Referenced by PrmIO::WriteList().


Member Data Documentation

long int Prm::color [private]
 

Coded RGB color.

Definition at line 116 of file prm.h.

Referenced by GetColor(), and Reset().

double Prm::height [private]
 

Height of primitive (only used in 3D).

Definition at line 119 of file prm.h.

Referenced by GetHeight(), and Reset().

Prm* Prm::next [private]
 

Next primitive in linked list.

Definition at line 107 of file prm.h.

Referenced by GetGlobalBox(), InsertBack(), InsertFront(), Next(), RemoveFromList(), and Reset().

Prm* Prm::prev [private]
 

Previous primitive in linked list.

Definition at line 110 of file prm.h.

Referenced by InsertBack(), InsertFront(), Last(), MoveBack(), Next(), Previous(), RemoveFromList(), and Reset().

Prm * Prm::prm_head = 0L [static, private]
 

Head of doubly-linked list of primitives.

Definition at line 44 of file prm.cpp.

Referenced by DeleteList(), First(), GetGlobalBox(), InsertBack(), InsertFront(), Last(), MoveBack(), MoveFront(), Next(), Previous(), and RemoveFromList().

int Prm::sel [private]
 

Flag for selected primitive.

Definition at line 113 of file prm.h.

Referenced by CheckSelected(), Reset(), Select(), SelectAll(), Unselect(), and UnselectAll().

Type Prm::type [protected]
 

Primitive type.

Definition at line 127 of file prm.h.

Referenced by Circ::Circ(), GetType(), Quad::Quad(), and Reset().


The documentation for this class was generated from the following files:
Generated on Mon May 16 23:26:11 2011 for Trab7 by  doxygen 1.4.2-20050421