WXP::Graph Class Reference

This class plots to a device independent graphics interface. More...

#include "../include/Graph.h"

Inheritance diagram for WXP::Graph:
WXP::Listener WXP::GraphAttr

List of all members.

Public Member Functions

 Graph ()
 Graph (const char *device, const char *param)
 ~Graph ()
int init ()
int setDevice (const char *device, const char *params)
int getDevice (String &str)
int open ()
int open (const char *dev, const char *params)
bool isOpen ()
int close ()
int update ()
int manage ()
int unmanage ()
bool isManaged ()
void callback (const char *ev_str, const char *ev_data, const void *data)
int doCallback (const char *ev_str, const char *ev_data)
int addCallback (const char *ev, Listener *list, const void *data)
int setSize (float width, float height)
int setOffset (float rx, float ry)
int setInverse (bool val)
bool getInverse ()
int setBackground (const char *str)
int setIcon (bool val)
int setTitle (const char *str)
int setTran (int num)
int setViewportAspect (Rect &limit, float aspect, int halign, int valign)
int setViewportAspect (Rect &limit, float aspect)
int setViewport (int num, Rect &rect)
int setViewport (Rect &rect)
int getViewport (Rect &rect)
Rect getViewport ()
int getDeviceViewport (Rect &rect)
Rect getDeviceViewport ()
int getMaxViewport (Rect &rect)
Rect getMaxViewport ()
int setWindow (int num, Rect &rect)
int setWindow (Rect &rect)
int getWindow (Rect &rect)
Rect getWindow ()
int getTran ()
int activateTran ()
int activateTran (int val)
int tranPlotWindow (float x1, float y1, float &x2, float &y2)
int tranPlotWindow (Point &pt1, Point &pt2)
int tranWindow (int tran1, float x1, float y1, int tran2, float &x2, float &y2)
int tranWindow (int tran1, Point &pt1, int tran2, Point &pt2)
int clear ()
int clearRect (Rect &rect)
int allocColor (float red, float grn, float blu)
int allocColor (RGB &rgb)
int drawLine (float x1, float y1, float x2, float y2)
int drawLine (Point &p1, Point &p2)
int drawLine (Points &data)
int drawRect (float x1, float y1, float x2, float y2)
int drawRect (Rect &rect)
int drawCircle (float x1, float y1, float rad)
int drawCircle (Point &pt, float rad)
int setLineColor (int index)
int setLineWidth (float width)
int setLineStyle (int style)
int drawFill (Rect &rect)
int drawFill (Points &data)
int drawFillarea (Points &data)
int setFillColor (int index)
int setFillStyle (int index)
int drawMarkLine (float x, float y, float size)
int drawMark (float x, float y)
int drawMark (Point pt)
int setMarkColor (int index)
int setMarkSize (float size)
int setMarkType (int type)
int setMarkWidth (float width)
int drawText (float ox, float oy, const char *string)
int drawText (Point pt, const char *string)
int drawFormText (float x, float y, const char *format,...)
int drawFormText (Point pt, const char *format,...)
int setTextColor (int color)
int setFontSpec ()
int setFont (const char *str)
int setTextBoxColor (int index)
int setDropColor (int index)
int setDropShadow (int val)
int getDropShadow ()
int setDropWidth (int val)
int setTextExpansion (float expansion)
int setTextWidth (float width)
int setTextHeight (float height)
int setTextDirection (float x, float y)
int setTextAlign (int hor, int vert)
int setTextCharWidth (float space)
int setTextSpacing (float space)
int setSymbol (const char *file)
int drawSymbol (float ox, float oy, const char *string, float size)
int drawSymbol (Point pt, const char *string, float size)
int setImageAlign (int h, int v)
int drawImage (Image &image, float x, float y)
int drawImage (Image &image, int color, float x, float y)
int getImage (Image &image)
int setCursor (int type)
bool isLooping ()
int getFrame ()
int setFrame (int ind)
int newFrame ()
int deleteFrame (int ind)
int getNumFrames ()
int bell ()
int message (const char *str,...)
int printTran ()

Static Public Attributes

static const int DEVICE_NONE = 0
static const int DEVICE_WINDOW = 1
static const int DEVICE_POSTSCRIPT = 2
static const int DEVICE_HPGL = 3
static const int DEVICE_METAFILE = 4

Detailed Description

This class plots to a device independent graphics interface.

Author:
Dan Vietor

Constructor & Destructor Documentation

Graph::Graph (  ) 

Constructor. Initializes class values

Graph::Graph ( const char *  device,
const char *  params 
)

Constructor. Opens device with specified parameters

Parameters:
device Device to open (display, postscript, hpgl)
params A character string of device parameters

References setDevice().

Graph::~Graph (  ) 

Destructor

References close().


Member Function Documentation

int Graph::activateTran ( int  val  ) 

Activates a specific transformation.

Parameters:
val The transformation to activate
int Graph::activateTran (  ) 

Activates the current transformation. This sets the clipping rectangle on the specific device.

Referenced by callback().

int Graph::addCallback ( const char *  ev,
Listener list,
const void *  data 
)

Adds a callback to list

Parameters:
ev Event to trigger callback
list Listener object
data Listener specific data
int Graph::allocColor ( float  red,
float  grn,
float  blu 
)

Allocates a color within the device.

Parameters:
red Red value (0-1)
grn Green value (0-1)
blu Blue value (0-1)
Returns:
Device specific index value (use for future reference).

Referenced by WXP::Plot::allocColor(), and WXP::Plot::setColorMap().

int Graph::bell (  ) 

Sends a bell command to device

Referenced by WXP::Plot::callback().

void Graph::callback ( const char *  ev_str,
const char *  ev_data,
const void *  data 
) [virtual]

Internal event callback to redraw window

Parameters:
ev_str Event name
ev_data Event specific data
data User specific data for the event

Implements WXP::Listener.

References activateTran(), and WXP::StrLib::equal().

int Graph::clear (  ) 

Clears the window of all graphics

int Graph::close (  ) 

Closes the window

Referenced by WXP::Plot::callback(), WXP::Plot::close(), and ~Graph().

int Graph::deleteFrame ( int  ind  ) 

Deletes a frame in the loop

Parameters:
ind Index of the frame to delete
int Graph::doCallback ( const char *  ev_str,
const char *  ev_data 
)

Forces the triggering of callbacks

Parameters:
ev_str Type of event (can be random)
ev_data Any extra data specific to event

Referenced by WXP::Plot::callback().

int Graph::drawCircle ( Point pt,
float  rad 
)

Draws a circle

Parameters:
pt Center point
rad Radius of circle

References drawCircle(), WXP::Point::x, and WXP::Point::y.

int Graph::drawCircle ( float  x1,
float  y1,
float  rad 
)

Draws a circle

Parameters:
x1 X point of center
y1 Y point of center
rad Radius of circle

References WXP::Points::add(), and WXP::Const::DRC.

Referenced by WXP::Plot::drawCircle(), and drawCircle().

int Graph::drawFill ( Points data  ) 

Draws a filled area to the window

Parameters:
data Points array defining polygon

References WXP::Points::add(), and WXP::Points::getNum().

int Graph::drawFill ( Rect rect  ) 

Draws a filled rect to the window

Parameters:
rect Rectangle coordinates

References WXP::Points::add().

Referenced by WXP::Plot::drawFill(), drawFillarea(), and drawSymbol().

int Graph::drawFillarea ( Points data  ) 

Draws a filles area (depricated)

Parameters:
data Data points

References drawFill().

int Graph::drawFormText ( Point  pt,
const char *  format,
  ... 
)

Draws formatted text to the window

Parameters:
pt Point to draw the text
format Format of text to plot

References drawText(), WXP::Point::x, and WXP::Point::y.

int Graph::drawFormText ( float  x,
float  y,
const char *  format,
  ... 
)

Draws formatted text to the window

Parameters:
x X point to draw the text
y Y point to draw the text
format Format of text to plot

References drawText().

int Graph::drawImage ( Image image,
int  color,
float  x,
float  y 
)

Draws an image to the window at a specific location using a transparent color

Parameters:
image Image to draw to window
color Transparent color value
x X location of upper left corner
y Y location of upper left corner

References WXP::GTran::windowPlotX(), and WXP::GTran::windowPlotY().

int Graph::drawImage ( Image image,
float  x,
float  y 
)

Draws an image to the window at a specific location

Parameters:
image Image to draw to window
x X location of upper left corner
y Y location of upper left corner

References WXP::GTran::windowPlotX(), and WXP::GTran::windowPlotY().

int Graph::drawLine ( Points data  ) 

Draws a line between a set of points

Parameters:
data The set of points

References WXP::Points::add(), WXP::Points::getNum(), and WXP::Points::offset().

int Graph::drawLine ( Point p1,
Point p2 
)

Draws a line between two points

Parameters:
p1 First point
p2 Second point

References drawLine(), WXP::Point::x, and WXP::Point::y.

int Graph::drawLine ( float  x1,
float  y1,
float  x2,
float  y2 
)

Draws a line between two points

Parameters:
x1 First X value
y1 First Y value
x2 Second X value
y2 Second Y value

Referenced by WXP::Plot::drawLine(), drawLine(), WXP::Plot::drawSpline(), and drawSymbol().

int Graph::drawMark ( Point  pt  ) 

Draws a marker

Parameters:
pt Location of marker

References drawMark(), WXP::Point::x, and WXP::Point::y.

int Graph::drawMark ( float  x,
float  y 
)

Draws a marker. This manages drawing the marker and calls drawMarkLine to do actual plotting.

Parameters:
x X location of marker
y Y location of marker

References drawMarkLine(), WXP::GTran::windowPlotX(), and WXP::GTran::windowPlotY().

Referenced by WXP::Plot::drawMark(), and drawMark().

int Graph::drawMarkLine ( float  x,
float  y,
float  size 
)

Draws a marker at a specific location

Parameters:
x X location of marker
y Y location of marker
size Size of marker

References WXP::Points::add().

Referenced by drawMark().

int Graph::drawRect ( Rect rect  ) 

Draws a rectangle

Parameters:
rect Rectangle coordinates

References drawRect().

int Graph::drawRect ( float  x1,
float  y1,
float  x2,
float  y2 
)

Draws a rectangle between two points

Parameters:
x1 First X value
y1 First Y value
x2 Second X value
y2 Second Y value

References WXP::Points::add().

Referenced by WXP::Plot::drawRect(), and drawRect().

int Graph::drawSymbol ( Point  pt,
const char *  string,
float  size 
)

Draws a symbol

Parameters:
pt Location of symbol
string String defining symbol to plot
size Size of symbol

References drawSymbol(), WXP::Point::x, and WXP::Point::y.

int Graph::drawSymbol ( float  rx,
float  ry,
const char *  string,
float  size 
)

Draws a symbol to the window

Parameters:
rx X location of symbol
ry Y location of symbol
string String defining symbol to plot
size Size of symbol

References WXP::Points::add(), drawFill(), drawLine(), WXP::Point::x, and WXP::Point::y.

Referenced by drawSymbol().

int Graph::drawText ( Point  pt,
const char *  string 
)

Draws text to the window

Parameters:
pt Point to draw the text
string String to plot

References drawText(), WXP::Point::x, and WXP::Point::y.

int Graph::drawText ( float  rx,
float  ry,
const char *  string 
)

Draws text to the window. This handles both hard and soft fonts. Soft fonts go to drawTextLine for output. Hard fonts get rendered to the device in Device::drawText

Parameters:
rx X location of text
ry Y location of text
string Text to draw

References WXP::StrLib::copy(), WXP::Strings::getNum(), WXP::Strings::getString(), WXP::Point::set(), WXP::GTran::windowPlotX(), and WXP::GTran::windowPlotY().

Referenced by WXP::Plot::drawFormText(), drawFormText(), WXP::Plot::drawText(), and drawText().

int Graph::getDevice ( String str  ) 

Gets the device specifications

Parameters:
str Specification string
int Graph::getDropShadow (  ) 

Gets drop shadow scale value. This is the amount of drop shadowing to appear. 0 means no shadowing.

int Graph::getFrame (  ) 

Returns current frame index

Returns:
Index of the current frame

Referenced by WXP::Plot::callback().

int Graph::getImage ( Image image  ) 

Retrieves an image from the window

Return values:
image Image class to put window snapshot
bool Graph::getInverse (  ) 

Gets the inverse setting

Returns:
True if inverse
int Graph::getNumFrames (  ) 

Returns the number of frames in the loop

Returns:
Number of frames

Referenced by WXP::Plot::callback().

int Graph::getTran (  ) 

Gets the current transformation number

Returns:
Current transformation number

Referenced by WXP::Plot::drawFill(), and WXP::Plot::drawLine().

Rect Graph::getViewport (  ) 

Returns the current viewport

Returns:
The viewport rectangle

References WXP::GTran::getViewport().

int Graph::getViewport ( Rect rect  ) 

Gets the current viewport

Return values:
rect The viewport rectangle

References WXP::GTran::getViewport().

Rect Graph::getWindow (  ) 

Gets the current window coordinates.

Returns:
The limits of the window

References WXP::GTran::getWindow().

int Graph::getWindow ( Rect rect  ) 

Gets the current window coordinates.

Return values:
rect The limits of the window

References WXP::GTran::getWindow().

int Graph::init (  ) 

Initializes the class values

Referenced by open().

bool Graph::isLooping (  ) 

Returns if looping

Returns:
True if looping

Referenced by WXP::Plot::callback().

bool Graph::isOpen (  ) 

Returns whether graphics interface is open.

Returns:
True if open
int Graph::manage (  ) 

Manages the window. Goes into a loop waiting for device events

Referenced by WXP::Plot::manage().

int Graph::message ( const char *  format,
  ... 
)

Outputs a message to the device

Parameters:
format Format (see sprintf)
int Graph::newFrame (  ) 

Creates a new frame on the device to plot to. Print devices its a new page. Display devices its a new frame in a loop.

Parameters:
rsecs Seconds since 1/1/1970 (Unix time)
int Graph::open ( const char *  dev,
const char *  params 
)

Opens a window for drawing

References open(), and setDevice().

int Graph::open (  ) 

Opens a window for drawing

References WXP::FileTool::addPath(), WXP::String::get(), WXP::Wxp::getDatabasePath(), and init().

Referenced by open().

int Graph::setBackground ( const char *  str  ) 

Sets the background color

Parameters:
str String specifying color name
int Graph::setCursor ( int  type  ) 

Sets the cursor type

int Graph::setDevice ( const char *  dev,
const char *  params 
)

Sets the device and its parameters

Parameters:
dev Device
params String containing device specific setup commands

References WXP::Strings::equal(), WXP::StrLib::equal(), and WXP::Strings::getNum().

Referenced by Graph(), and open().

int Graph::setDropColor ( int  index  ) 

Sets drop color. This is the color of the drop shadowing on drawing primitives

Parameters:
index Color index
int Graph::setDropShadow ( int  val  ) 

Sets drop shadow scale value. This is the amount of drop shadowing to appear. 0 means no shadowing.

Parameters:
val Drop shadow value

Referenced by WXP::Plot::setLine().

int Graph::setDropWidth ( int  val  ) 

Sets drop shadow width. This is the width of lines to be drawn in the drop shadowing.

Parameters:
val Line width
int Graph::setFillColor ( int  index  ) 

Sets the fill color

Parameters:
index Color index

Referenced by WXP::Plot::setFill(), and WXP::Plot::setFillColor().

int Graph::setFillStyle ( int  index  ) 

Sets the fill style

Parameters:
index Fill pattern index

Referenced by WXP::Plot::setFill(), and WXP::Plot::setFillStyle().

int Graph::setFont ( const char *  str  ) 

Sets up fonts. Takes font specification and searches for font name in wxp.fnl file. Then, determines if font is hard or soft font. If soft font, reads in WXP font file. If hard font, calls setFontSpec

Parameters:
str Font specification string

References WXP::FileTool::addPath(), WXP::StrLib::copy(), WXP::StrLib::equal(), WXP::String::get(), WXP::Wxp::getDatabasePath(), WXP::File::getLine(), WXP::StrLib::index(), WXP::File::isOpen(), WXP::File::open(), and setFontSpec().

Referenced by WXP::Plot::setText().

int Graph::setFontSpec (  ) 
int Graph::setFrame ( int  ind  ) 

Specified the current drawing frame

Parameters:
ind Index of the frame to draw to

Referenced by WXP::Plot::callback().

int Graph::setIcon ( bool  val  ) 

Sets up icon mode. This will attempt to open window in iconic state

Parameters:
val True if icon
int Graph::setImageAlign ( int  h,
int  v 
)

Specifies alignment of image (default LEFT, BOTTOM)

Parameters:
h Horizontal alignment (IMAGE_HLEFT, IMAGE_HCENTER, IMAGE_HRIGHT)
v Vertical alignment (IMAGE_VTOP, IMAGE_VCENTER, IMAGE_VBOTTOM)
int Graph::setInverse ( bool  val  ) 

Sets up inverse tag. This will invert default foreground and background colors.

Parameters:
val True for inverse
int Graph::setLineColor ( int  index  ) 

Sets the line color

Parameters:
index Color index

Referenced by WXP::Plot::setLine(), and WXP::Plot::setLineColor().

int Graph::setLineStyle ( int  style  ) 

Sets the line style

Parameters:
style Style index

Referenced by WXP::Plot::setLine(), and WXP::Plot::setLineStyle().

int Graph::setLineWidth ( float  width  ) 

Sets the line width

Parameters:
width Line width scale factor

Referenced by WXP::Plot::setLine(), and WXP::Plot::setLineWidth().

int Graph::setMarkColor ( int  index  ) 

Sets marker color

Parameters:
index Color index

Referenced by WXP::Plot::setMark().

int Graph::setMarkSize ( float  size  ) 

Sets marker size

Parameters:
size Size of marker in plot coordinates

Referenced by WXP::Plot::setMark().

int Graph::setMarkType ( int  type  ) 

Sets the marker type

Parameters:
type Marker type index
int Graph::setMarkWidth ( float  width  ) 

Sets the marker line width

Parameters:
width Line width

Referenced by WXP::Plot::setMark().

int Graph::setOffset ( float  rx,
float  ry 
)

Sets the offset of the window on the screen

Parameters:
rx X location
ry Y location
int Graph::setSize ( float  width,
float  height 
)

Sets the size of the window

Parameters:
width Width in pixels
height Height in pixels
int Graph::setSymbol ( const char *  file  ) 

Sets up the symbol set to use. This will read the symbols in from file.

Parameters:
file Filename of symbol data

References WXP::FileTool::addPath(), WXP::StrLib::copy(), WXP::StrLib::equal(), WXP::String::get(), and WXP::Wxp::getDatabasePath().

int Graph::setTextAlign ( int  hor,
int  vert 
)

Sets the text alignment

Parameters:
hor Horizontal alignment: HALIGN_LEFT, HALIGN_CENTER, HALIGN_RIGHT
vert Vertical alignment: VALIGN_CAP, VALIGN_TOP, VALIGN_HALF, VALIGN_BOTTOM, VALIGN_BASE

Referenced by WXP::Plot::setText().

int Graph::setTextBoxColor ( int  index  ) 

Sets text box color. This is the color of a box surrounding text (unimplemented)

Parameters:
index Color index
int Graph::setTextCharWidth ( float  width  ) 

Sets the text character width. This is used if a fixed spacing is needed for text such as use in tables, etc.

Parameters:
width Character width

Referenced by WXP::Plot::setText().

int Graph::setTextColor ( int  index  ) 

Sets the text color

Parameters:
index Color index

Referenced by WXP::Plot::setText(), and WXP::Plot::setTextColor().

int Graph::setTextDirection ( float  x,
float  y 
)

Sets text direction in terms of an up vector.

Parameters:
x Vector X value
y Vector Y value

Referenced by WXP::Plot::setText(), and WXP::Plot::setTextDirection().

int Graph::setTextExpansion ( float  expansion  ) 

Sets the text horizontal expansion factor

Parameters:
expansion Expansion scale factor (def=1)

Referenced by WXP::Plot::setText().

int Graph::setTextHeight ( float  height  ) 

Sets the text height

Parameters:
height Height of text in plot coordinates

References setFontSpec().

Referenced by WXP::Plot::setText().

int Graph::setTextSpacing ( float  space  ) 

Sets text spacing. This is the amount of space between each character

Parameters:
space Spacing value
int Graph::setTextWidth ( float  width  ) 

Sets text line width factor. This is the width used in drawing soft font text.

Parameters:
width Line width

Referenced by WXP::Plot::setText().

int Graph::setTitle ( const char *  str  ) 

Sets the window title

Parameters:
str Window title
int Graph::setTran ( int  val  ) 

Sets the current tranformation number

Parameters:
val Transform number
int Graph::setViewport ( Rect rect  ) 

Sets the viewport for the current transformation

Parameters:
rect The rectangle specifying viewport extent

References WXP::GTran::setViewport().

int Graph::setViewport ( int  num,
Rect rect 
)

Sets the viewport for a specific transformation

Parameters:
num The transformation number
rect The rectangle specifying viewport extent

References WXP::GTran::setViewport().

int Graph::setViewportAspect ( Rect limit,
float  aspect 
)

Sets the viewport based on drawing area specifics. The output is the largest area centered within limit of an area with aspect ratio aspect.

Parameters:
limit Outer limit of drawing area
aspect Aspect ratio of plot

References setViewportAspect().

int Graph::setViewportAspect ( Rect limit,
float  aspect,
int  halign,
int  valign 
)

Sets the viewport based on drawing area specifics. The output is the largest area within limit of an area with aspect ratio aspect.

Parameters:
limit Outer limit of drawing area
aspect Aspect ratio of plot
halign Horizontal alignment of area
valign Vertical alignment of area

References WXP::GTran::getNdc(), WXP::Wxp::isDebug(), and WXP::GTran::setViewport().

Referenced by setViewportAspect().

int Graph::setWindow ( Rect rect  ) 

Sets the window coordinate system for the current viewport

Parameters:
rect The limits of the window

References WXP::GTran::setWindow().

int Graph::setWindow ( int  num,
Rect rect 
)

Sets the window coordinate system for the viewport

Parameters:
num The transformation number to set
rect The limits of the window

References WXP::GTran::setWindow().

int Graph::tranPlotWindow ( Point pt1,
Point pt2 
)

Converts plot coordinates to window coordinates

Parameters:
pt1 The plot coordinate
Return values:
pt2 The window coordinate

References tranPlotWindow(), WXP::Point::x, and WXP::Point::y.

int Graph::tranPlotWindow ( float  x1,
float  y1,
float &  x2,
float &  y2 
)

Converts plot coordinates to window coordinates

Parameters:
x1 The X plot coordinate
y1 The Y plot coordinate
Return values:
x2 The X window coordinate
y2 The Y window coordinate

References WXP::GTran::plotWindowX(), and WXP::GTran::plotWindowY().

Referenced by WXP::Plot::callback(), and tranPlotWindow().

int Graph::tranWindow ( int  tran1,
Point pt1,
int  tran2,
Point pt2 
)

Converts window coordinates from one transformation to another

Parameters:
tran1 The initial transformation
pt1 The initial window coordinates
tran2 The final transformation
Return values:
pt2 The window coordinates

References tranWindow(), WXP::Point::x, and WXP::Point::y.

int Graph::tranWindow ( int  tran1,
float  x1,
float  y1,
int  tran2,
float &  x2,
float &  y2 
)

Converts window coordinates from one transformation to another

Parameters:
tran1 The initial transformation
x1 The initial X window coordinate
y1 The initial Y window coordinate
tran2 The final transformation
Return values:
x2 The X window coordinate
y2 The Y window coordinate

References WXP::GTran::plotWindowX(), WXP::GTran::plotWindowY(), WXP::GTran::windowPlotX(), and WXP::GTran::windowPlotY().

Referenced by tranWindow().

int Graph::unmanage (  ) 

Unmanages the window and returns control back to the program

Referenced by WXP::Plot::callback().

int Graph::update (  ) 

Update the window.

Referenced by WXP::Plot::update().


The documentation for this class was generated from the following files:

Generated on 8 Jan 2010 for WXP C++ Library by  doxygen 1.6.1