summaryrefslogtreecommitdiffstats
path: root/src/conrouter.h
blob: eae40517bf29738a0ea2f33871403c6d38faa468 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/***************************************************************************
 *   Copyright (C) 2003-2004 by David Saxton                               *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef CONROUTER_H
#define CONROUTER_H

#include "cells.h"

#include <tqpoint.h>
#include <tqvaluelist.h>

class ICNDocument;
class Cell;

typedef TQValueList<TQPoint> TQPointList;
typedef TQValueList<TQPointList> TQPointListList;

/**
Abstraction for the routing of a connector.

NB: As a general rule of thumb, the point references stored as members of this
class are in Cell-space (i.e. 8^2 x smaller than Canvas-space), and the
interfacing functions take or give point references in Canvas-space (unless
otherwise indicated).

@author David Saxton
*/
class ConRouter
{
public:
	ConRouter( ICNDocument *cv );
	~ConRouter();
	
	/**
	 * What this class is all about - finding a route, from (sx,sy) to (ex,ey).
	 */
	void mapRoute( int sx, int sy, int ex, int ey );
	/**
	 * Translates the precalculated routepoints by the given amount
	 */
	void translateRoute( int dx, int dy );
	/**
	 * Sets the route to the given canvas points
	 * @param reverse if true, the points in pointList will be reversed
	 */
	void setPoints( const TQPointList &pointList, bool reverse = false );
	/**
	 * Sets the route to the given route points
	 */
	void setRoutePoints( const TQPointList &pointList );
	/**
	 * @returns true if the start or end points differ from that of the current route
	 */
	bool needsRouting( int sx, int sy, int ex, int ey ) const;
	/**
	 * Returns the list of canvas points
	 */
	TQPointList pointList( bool reverse ) const;
	/**
	 * Returns a pointer to the internall cellPointList
	 */
	TQPointList *cellPointList() { return &m_cellPointList; }
	/**
	 * This will return two lists of Canvas points from the splitting of the
	 * route at the Canvas point "pos". The internall stored points are not
	 * affected.
	 */
	TQPointListList splitPoints( const TQPoint &pos ) const;
	/**
	 * This will return a list of Canvas pointLists from the route, divided
	 * into n parts (at n-1 equally spaced places).
	 */
	TQPointListList dividePoints( uint n ) const;

protected:
	/**
	 * Check a line of the ICNDocument cells for a valid route
	 */
	bool checkLineRoute( int scx, int scy, int ecx, int ecy, int maxConScore, int maxCIScore );
	void checkACell( int x, int y, Cell *prev, int prevX, int prevY, int nextScore );
	void checkCell( int x, int y ); // Gets the shortest route from the final cell
	/**
	 * Remove duplicated points from the route
	 */
	void removeDuplicatePoints();
	
	int xcells, ycells;
	int m_lcx, m_lcy; // Last x / y from mapRoute, if we need a point on the route
	Cells *cellsPtr;
	TempLabelMap tempLabels;
	ICNDocument *p_icnDocument;
	TQPointList m_cellPointList;
};

#endif