LayoutCanvas Class Reference

Class which draws a grid. More...

#include <layoutCanvas.hpp>

Collaboration diagram for LayoutCanvas:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 LayoutCanvas (wxWindow *parent, wxWindowID id, Grid initialLayout)
 Constructor.
 ~LayoutCanvas ()
 Destructor.
void setCellSize (int newCellSize)
 Member setting.
void setFittingCellSize ()
 Calculates the optimal cell size for the window size.
void drawScene ()
 The grid is drawn in this method.
void setGrid (Grid newGrid, bool changed)
 Sets the grid to be painted.
void setVisible (bool enableds, bool disableds, bool inputs, bool outputs, bool spaces)
 Sets the cell status that have to be drawn.
void setAssignedInputs (vector< coordinate > inputs)
 Sets the coordinates of the assigned inputs.
void setAssignedOutputs (vector< coordinate > outputs)
 Sets the coordinates of the assigned outputs.

Private Member Functions

void OnPaint (wxPaintEvent &WXUNUSED(event))
 Paint event.
void OnLeftDown (wxMouseEvent &event)
 Left button mouse click event.
void OnScroll (wxScrollWinEvent &event)
 Scrollbar change method.
void OnTimer (wxTimerEvent &event)
 Timer event method.
void adjustScrollbars ()
 Sets the scrollbars of the window.
void adjustCenter ()
 Calculates the top/left of the painting.
void drawMargins (wxDC &dc)
 Draws the margins of the grid.
void drawGrid (wxDC &dc)
 Draws the grid points.
void drawCells (wxDC &dc)
 Draws the cells of the grid.
void drawIO (wxDC &dc)
 Draws the assigned inputs and outputs.
void drawNumber (int i, int j, int number, wxDC &dc)
 Draws a number.
void OnResize (wxSizeEvent &event)
 Resize method.
coordinate viewToReal (coordinate view)
 Converts a window coordinate to a grid logical coordinate.
coordinate realToView (coordinate real)
 Converts a grid logical coordinate to a window coordinate.
void drawCell (int i, int j, wxColour color, wxDC &dc)
 Draws a cell.
void clear (wxDC &dc)
 Erases the window.
void initTransitions ()
 Initializes the transition grid.
void resetTransitions (int value)
 Sets all the cells of the transition grid.
wxColour calculateColour (wxColour initial, wxColour final, int percent)
 Calculates an intermediate colour.

Private Attributes

int width
 Width of the grid.
int height
 Height of the grid.
int centerX
 X coordinate of the centered top/left of the grid.
int centerY
 Y coordinate of the centered top/left of the grid.
int cellSize
 Size in pixels of the molecules to be drawn.
int scrollX
 X coordinate of the widget scoll bars.
int scrollY
 Y coordinate of the widget scoll bars.
bool inputs
 Show inputs?
bool outputs
 Show outputs?
bool enableds
 Show enabled molecules?
bool disableds
 Show disabled molecules?
bool spaces
 Show no space molecules?
Grid layout
 The grid being drawn.
Grid previous
 The previous grid (used for some eye candy feature).
matrix transitions
 Matrix of transition percentage.
wxTimer chrono
 Timer.
vector< coordinateassignedInputs
 List of assigned inputs to be drawn as numbers.
vector< coordinateassignedOutputs
 List of assigned outputs to be drawn as numbers.
bool transition
 Should we use gradient transitions?

Detailed Description

Class which draws a grid.

This class is a wxWindows widget which draws a grid on the screen. It has an event which is triggered when clicking on a cell of the grid to allow the modification of it.

Author:
Bernat Rāfales Mulet <the_bell@users.sourceforge.net>
Version:
Revision
1.18

Definition at line 47 of file layoutCanvas.hpp.


Constructor & Destructor Documentation

LayoutCanvas::LayoutCanvas wxWindow *  parent,
wxWindowID  id,
Grid  initialLayout
 

Constructor.

Parameters:
parent parent window.
id window identifier.
initialLayout grid to be painted.

Definition at line 105 of file layoutCanvas.cpp.

References CELL_SIZE, NUMTRANSITIONS, and TIMERINTERVAL.

LayoutCanvas::~LayoutCanvas  ) 
 

Destructor.

Definition at line 132 of file layoutCanvas.cpp.


Member Function Documentation

void LayoutCanvas::adjustCenter  )  [private]
 

Calculates the top/left of the painting.

The painting have to be centered if the window size is bigger than the painting size. The centered top and left coordinates are calculated here.

Definition at line 278 of file layoutCanvas.cpp.

References cellSize, centerX, centerY, height, and width.

Referenced by adjustScrollbars(), OnResize(), setCellSize(), and setGrid().

void LayoutCanvas::adjustScrollbars  )  [private]
 

Sets the scrollbars of the window.

Because the painting can be bigger than the actual size of the window, two scrollbars are set to allow the user to navigate through all the area of the painting.

Definition at line 191 of file layoutCanvas.cpp.

References adjustCenter(), cellSize, drawScene(), height, and width.

Referenced by OnResize(), setCellSize(), and setGrid().

Here is the call graph for this function:

wxColour LayoutCanvas::calculateColour wxColour  initial,
wxColour  final,
int  percent
[private]
 

Calculates an intermediate colour.

Parameters:
initial the initial colour.
final the final colour.
percent the percent gradient.
Returns:
A colour between the initial colour and the final colour that is percent of the final colour and 100-percent of the initial colour.

Definition at line 805 of file layoutCanvas.cpp.

References NUMTRANSITIONS.

Referenced by drawCells().

void LayoutCanvas::clear wxDC &  dc  )  [private]
 

Erases the window.

Parameters:
dc the device context.

Definition at line 727 of file layoutCanvas.cpp.

Referenced by drawScene(), and OnPaint().

void LayoutCanvas::drawCell int  i,
int  j,
wxColour  color,
wxDC &  dc
[private]
 

Draws a cell.

Parameters:
i the x logical coordinate of the grid.
j the y logical coordinate of the grid.
color the colour of the cell to be painted.
dc the device context where to paint.

Definition at line 353 of file layoutCanvas.cpp.

References cellSize, realToView(), coordinate::x, and coordinate::y.

Referenced by drawCells().

Here is the call graph for this function:

void LayoutCanvas::drawCells wxDC &  dc  )  [private]
 

Draws the cells of the grid.

Parameters:
dc the device context.

Definition at line 410 of file layoutCanvas.cpp.

References calculateColour(), disableds, drawCell(), enableds, Grid::getHeight(), Grid::getWidth(), inputs, layout, nDISABLED, nDONTCARE, nENABLED, nINPUT, nNOSPACE, nOUTPUT, outputs, previous, spaces, and transitions.

Referenced by drawScene(), and OnPaint().

Here is the call graph for this function:

void LayoutCanvas::drawGrid wxDC &  dc  )  [private]
 

Draws the grid points.

Draws the grid of the grid. This is, the points of the grid but not the cells.

Parameters:
dc the device context.

Definition at line 390 of file layoutCanvas.cpp.

References cellSize, centerX, centerY, height, scrollX, scrollY, and width.

Referenced by drawScene(), and OnPaint().

void LayoutCanvas::drawIO wxDC &  dc  )  [private]
 

Draws the assigned inputs and outputs.

Parameters:
dc the context device.

Definition at line 665 of file layoutCanvas.cpp.

References assignedInputs, drawNumber(), and inputs.

Referenced by drawScene(), and OnPaint().

Here is the call graph for this function:

void LayoutCanvas::drawMargins wxDC &  dc  )  [private]
 

Draws the margins of the grid.

Those margins are drawn around the grid when the window size is bigger than the grid painting size.

Parameters:
dc the device context.

Definition at line 585 of file layoutCanvas.cpp.

References cellSize, centerX, centerY, height, scrollX, scrollY, and width.

Referenced by drawScene(), and OnPaint().

void LayoutCanvas::drawNumber int  i,
int  j,
int  number,
wxDC &  dc
[private]
 

Draws a number.

Parameters:
i x logical grid coordinate.
j y logical grid coordinate.
number number to be painted.
dc the device context.

Definition at line 708 of file layoutCanvas.cpp.

References realToView(), coordinate::x, and coordinate::y.

Referenced by drawIO().

Here is the call graph for this function:

void LayoutCanvas::drawScene  ) 
 

The grid is drawn in this method.

The draw scene has been split into several draw methods. This method has to be called when anything of the grid changes to refresh the window.

Definition at line 246 of file layoutCanvas.cpp.

References clear(), drawCells(), drawGrid(), drawIO(), and drawMargins().

Referenced by adjustScrollbars(), OnResize(), OnScroll(), setVisible(), and LayoutView::updateCanvas().

Here is the call graph for this function:

void LayoutCanvas::initTransitions  )  [private]
 

Initializes the transition grid.

Definition at line 734 of file layoutCanvas.cpp.

References Grid::getHeight(), Grid::getWidth(), layout, NUMTRANSITIONS, and transitions.

Referenced by setGrid().

Here is the call graph for this function:

void LayoutCanvas::OnLeftDown wxMouseEvent &  event  )  [private]
 

Left button mouse click event.

Method called when the left button of the mouse is clicked on the window. The event is sent here if necessary.

Parameters:
event the event

Definition at line 159 of file layoutCanvas.cpp.

References height, LayoutCanvasEvent::setX(), LayoutCanvasEvent::setY(), transition, viewToReal(), width, coordinate::x, and coordinate::y.

Here is the call graph for this function:

void LayoutCanvas::OnPaint wxPaintEvent &  WXUNUSED(event)  )  [private]
 

Paint event.

This method is called every time the window receives a paint event. The grid must be painted here.

Definition at line 142 of file layoutCanvas.cpp.

References clear(), drawCells(), drawGrid(), drawIO(), and drawMargins().

Here is the call graph for this function:

void LayoutCanvas::OnResize wxSizeEvent &  event  )  [private]
 

Resize method.

This method is called on the window resize events. The grid is redrawn.

Parameters:
event the event.

Definition at line 264 of file layoutCanvas.cpp.

References adjustCenter(), adjustScrollbars(), and drawScene().

Here is the call graph for this function:

void LayoutCanvas::OnScroll wxScrollWinEvent &  event  )  [private]
 

Scrollbar change method.

Method called when the user uses the scrollbars. Some painting variables are updated and the window is repainted to show the scrolled zone.

Parameters:
event the event.

Definition at line 216 of file layoutCanvas.cpp.

References drawScene(), scrollX, and scrollY.

Here is the call graph for this function:

void LayoutCanvas::OnTimer wxTimerEvent &  event  )  [private]
 

Timer event method.

Method called on every timer event. The transition grid is refreshed in this method.

Parameters:
event the event.

Definition at line 754 of file layoutCanvas.cpp.

References NUMTRANSITIONS, and transitions.

coordinate LayoutCanvas::realToView coordinate  real  )  [private]
 

Converts a grid logical coordinate to a window coordinate.

Parameters:
real the grid logical coordinate.
Returns:
The window coordinate of the center of the logical grid coordinate. Used to know where to paint the cells in the window.

Definition at line 336 of file layoutCanvas.cpp.

References cellSize, centerX, centerY, scrollX, scrollY, coordinate::x, and coordinate::y.

Referenced by drawCell(), and drawNumber().

void LayoutCanvas::resetTransitions int  value  )  [private]
 

Sets all the cells of the transition grid.

Parameters:
value the value to set

Definition at line 784 of file layoutCanvas.cpp.

References Grid::getHeight(), layout, and transitions.

Referenced by setGrid().

Here is the call graph for this function:

void LayoutCanvas::setAssignedInputs vector< coordinate newInputs  ) 
 

Sets the coordinates of the assigned inputs.

The input cells that have been assigned must be painted in a different way, this method is used to set the coordinates of the assigned inputs.

Parameters:
newInputs vector of assigned inputs. The index of the vector is the input (position 0 is the first input, position 1 is the second input...). If a position has the coordinates -1, -1 means that that input is not assigned.

Definition at line 640 of file layoutCanvas.cpp.

References assignedInputs.

Referenced by ResultsView::setInputs(), and LayoutView::updateInputs().

void LayoutCanvas::setAssignedOutputs vector< coordinate newOutputs  ) 
 

Sets the coordinates of the assigned outputs.

The output cells that have been assigned must be painted in a different way, this method is used to set the coordinates of the assigned outputs.

Parameters:
newOutputs vector of assigned outputs. The index of the vector is the output (position 0 is the first output, position 1 is the second output...). If a position has the coordinates -1, -1 means that that output is not assigned.

Definition at line 655 of file layoutCanvas.cpp.

References assignedOutputs.

Referenced by ResultsView::setOutputs(), and LayoutView::updateOutputs().

void LayoutCanvas::setCellSize int  newCellSize  ) 
 

Member setting.

Sets the size (in pixels) of the cells.

Parameters:
newCellSize the cell size.

Definition at line 373 of file layoutCanvas.cpp.

References adjustCenter(), adjustScrollbars(), and cellSize.

Referenced by setFittingCellSize().

Here is the call graph for this function:

void LayoutCanvas::setFittingCellSize  ) 
 

Calculates the optimal cell size for the window size.

This method calculates the maximum cell size that can be used to allow all the grid to be painted in the window, without having to use scrollbars.

Definition at line 528 of file layoutCanvas.cpp.

References height, setCellSize(), and width.

Here is the call graph for this function:

void LayoutCanvas::setGrid Grid  newGrid,
bool  changed
 

Sets the grid to be painted.

Parameters:
newGrid the grid to be painted.
changed false if the new grid is only a cell status change or it's really an entire new grid.

Definition at line 551 of file layoutCanvas.cpp.

References adjustCenter(), adjustScrollbars(), chrono, Grid::getHeight(), Grid::getWidth(), height, Grid::init(), initTransitions(), layout, previous, resetTransitions(), TIMERINTERVAL, and width.

Referenced by SimulationView::setGrid(), ResultsView::updateGrid(), RuleView::updateGrids(), LayoutView::updateGrids(), ForbiddenPatternView::updateGrids(), and ResultsView::updateInitialGrid().

Here is the call graph for this function:

void LayoutCanvas::setVisible bool  enableds,
bool  disableds,
bool  inputs,
bool  outputs,
bool  spaces
 

Sets the cell status that have to be drawn.

The cell status which it's wanted to be painted can be customized. This way we can paint only inputs and outputs, for example.

Parameters:
enableds true iif we want the nENABLED cells to be painted.
disableds true iif we want the nDISABLED cells to be painted.
inputs true iif we want the nINPUT cells to be painted.
outputs true iif we want the nOUTPUT cells to be painted.
spaces true iif we want the nNOSPACE cells to be painted.

Definition at line 620 of file layoutCanvas.cpp.

References drawScene().

Referenced by LayoutView::OnAssignInput(), LayoutView::OnAssignOutput(), and LayoutView::onlyAssign().

Here is the call graph for this function:

coordinate LayoutCanvas::viewToReal coordinate  view  )  [private]
 

Converts a window coordinate to a grid logical coordinate.

Parameters:
view the window coordinate.
Returns:
The logical coordinate of the grid corresponding to the window coordinate. If the window coordinate is outbounds, the returned coordinate is -1, -1.

Definition at line 310 of file layoutCanvas.cpp.

References cellSize, centerX, centerY, height, scrollX, scrollY, width, coordinate::x, and coordinate::y.

Referenced by OnLeftDown().


Member Data Documentation

vector<coordinate> LayoutCanvas::assignedInputs [private]
 

List of assigned inputs to be drawn as numbers.

Definition at line 119 of file layoutCanvas.hpp.

Referenced by drawIO(), and setAssignedInputs().

vector<coordinate> LayoutCanvas::assignedOutputs [private]
 

List of assigned outputs to be drawn as numbers.

Definition at line 121 of file layoutCanvas.hpp.

Referenced by setAssignedOutputs().

int LayoutCanvas::cellSize [private]
 

Size in pixels of the molecules to be drawn.

Definition at line 90 of file layoutCanvas.hpp.

Referenced by adjustCenter(), adjustScrollbars(), drawCell(), drawGrid(), drawMargins(), realToView(), setCellSize(), and viewToReal().

int LayoutCanvas::centerX [private]
 

X coordinate of the centered top/left of the grid.

Definition at line 86 of file layoutCanvas.hpp.

Referenced by adjustCenter(), drawGrid(), drawMargins(), realToView(), and viewToReal().

int LayoutCanvas::centerY [private]
 

Y coordinate of the centered top/left of the grid.

Definition at line 88 of file layoutCanvas.hpp.

Referenced by adjustCenter(), drawGrid(), drawMargins(), realToView(), and viewToReal().

wxTimer LayoutCanvas::chrono [private]
 

Timer.

Definition at line 117 of file layoutCanvas.hpp.

Referenced by setGrid().

bool LayoutCanvas::disableds [private]
 

Show disabled molecules?

Definition at line 102 of file layoutCanvas.hpp.

Referenced by drawCells().

bool LayoutCanvas::enableds [private]
 

Show enabled molecules?

Definition at line 100 of file layoutCanvas.hpp.

Referenced by drawCells().

int LayoutCanvas::height [private]
 

Height of the grid.

Definition at line 84 of file layoutCanvas.hpp.

Referenced by adjustCenter(), adjustScrollbars(), drawGrid(), drawMargins(), OnLeftDown(), setFittingCellSize(), setGrid(), and viewToReal().

bool LayoutCanvas::inputs [private]
 

Show inputs?

Definition at line 96 of file layoutCanvas.hpp.

Referenced by drawCells(), and drawIO().

Grid LayoutCanvas::layout [private]
 

The grid being drawn.

Definition at line 106 of file layoutCanvas.hpp.

Referenced by drawCells(), initTransitions(), resetTransitions(), and setGrid().

bool LayoutCanvas::outputs [private]
 

Show outputs?

Definition at line 98 of file layoutCanvas.hpp.

Referenced by drawCells().

Grid LayoutCanvas::previous [private]
 

The previous grid (used for some eye candy feature).

Definition at line 108 of file layoutCanvas.hpp.

Referenced by drawCells(), and setGrid().

int LayoutCanvas::scrollX [private]
 

X coordinate of the widget scoll bars.

Definition at line 92 of file layoutCanvas.hpp.

Referenced by drawGrid(), drawMargins(), OnScroll(), realToView(), and viewToReal().

int LayoutCanvas::scrollY [private]
 

Y coordinate of the widget scoll bars.

Definition at line 94 of file layoutCanvas.hpp.

Referenced by drawGrid(), drawMargins(), OnScroll(), realToView(), and viewToReal().

bool LayoutCanvas::spaces [private]
 

Show no space molecules?

Definition at line 104 of file layoutCanvas.hpp.

Referenced by drawCells().

bool LayoutCanvas::transition [private]
 

Should we use gradient transitions?

Definition at line 123 of file layoutCanvas.hpp.

Referenced by OnLeftDown().

matrix LayoutCanvas::transitions [private]
 

Matrix of transition percentage.

This matrix is the grandient percentage to be drawn between the actual grid and the previous one. Is used to draw the molecules in a gradient way to make it more eye candy to the user.

Definition at line 115 of file layoutCanvas.hpp.

Referenced by drawCells(), initTransitions(), OnTimer(), and resetTransitions().

int LayoutCanvas::width [private]
 

Width of the grid.

Definition at line 82 of file layoutCanvas.hpp.

Referenced by adjustCenter(), adjustScrollbars(), drawGrid(), drawMargins(), OnLeftDown(), setFittingCellSize(), setGrid(), and viewToReal().


The documentation for this class was generated from the following files:
Generated on Fri Sep 1 23:57:37 2006 for NanoComp by  doxygen 1.4.6