summaryrefslogtreecommitdiffstats
path: root/src/nodegroup.h
blob: acdd055cd8a75f28c221282f1c27452123dcb84f (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/***************************************************************************
 *   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 NODEGROUP_H
#define NODEGROUP_H

#include <tqguardedptr.h>
#include <tqobject.h>
#include <tqvaluelist.h>
#include <tqvaluevector.h>

class ICNDocument;
class Connector;
class ConRouter;
class Node;
class NodeGroup;

class TQTimer;

typedef TQValueList<int> IntList;
typedef TQValueList<NodeGroup*> NodeGroupList;
typedef TQValueList<TQGuardedPtr<Node> > NodeList;

/**
Controls a group of nodes who are not attached to any CNItems (poor things!)
along with their associated connectors.
@author David Saxton
*/
class NodeGroup : public TQObject
{
Q_OBJECT
  TQ_OBJECT
public:
	NodeGroup( ICNDocument *icnDocument, const char *name = 0);
	~NodeGroup();
	/**
	 * Adds a node to the group (this checks to make sure that the node is not
	 * a child node). If checkSurrouding is true, then surrounding nodes will be
	 * checked to see if they are valid for inclusion - and if so, include them.
	 */
	void addNode( Node *node, bool checkSurrouding );
	/**
	 * Returns the list of internal nodes
	 */
	NodeList internalNodeList() const { return m_nodeList; }
	/**
	 * Returns the list of external nodes
	 */
	NodeList externalNodeList() const { return m_extNodeList; }
	/**
	 * Returns the list of connectors
	 */
	ConnectorList connectorList() const { return m_conList; }
	/**
	 * Translates the routes by the given amount
	 */
	void translate( int dx, int dy );
	void init();
	/**
	 * @returns true if node is an internal node to this group
	 */
	bool tqcontains( Node *node ) const { return m_nodeList.tqcontains(node); }
	/**
	 * Reroute the NodeGroup. This function should only ever be called by
	 * ICNDocument::rerouteInvalidatedConnectors(), as it is important that
	 * there is only ever one entity controlling the routing of connectors.
	 */
	void updateRoutes();
	/**
	 * Sets the visibility of all nodes in the group.
	 */
	void setVisible( bool visible );
	
public slots:
	/**
	 * Called when an internal or external node is deleted
	 */
	void nodeRemoved( Node *node );
	/**
	 * Called when a connector is removed
	 */
	void connectorRemoved( Connector *connector );
	
	
protected:
	void clearConList();
	/**
	 * Finds the common connector between two nodes
	 */
	Connector* findCommonConnector( Node *n1, Node *n2 );
	/**
	 * Find the best pair of nodes in the given list to route between. These
	 * will be nodes that give a ncie path (e.g. if they're aligned horizontally
	 * or vertically), or otherwise the closest such pair. The two nodes will be
	 * returned in n1 and n2.
	 */
	void findBestPair( NodeList *list, Node **n1, Node **n2 );
	/**
	 * Finds the nodes along the route with the given start and end nodes (which
	 * will be unique). The end nodes are not included in the returned list.
	 */
	NodeList findRoute( Node *startNode, Node *endNode );
	
	ConnectorList m_conList;
	NodeList m_nodeList;
	NodeList m_extNodeList;
	ICNDocument *p_icnDocument;
	TQValueVector<bool> b_routedMap; // Routes between different nodes
	bool b_visible;
	
private:
	IntList findRoute( IntList used, int currentNode, int endNode, bool *success = 0l );
	void resetRoutedMap();
	/**
	 * Looks at b_routedMap as well as the connectors coming out of nodes, and
	 * removes the nodes from the given list that have all of their connectors
	 * routed.
	 */
	void removeRoutedNodes( NodeList *nodes, Node *n1, Node *n2 );
	void addExtNode( Node *node );
	/**
	 * Looks at b_mappedRoute to see if there is a completely unrouted set of
	 * connectors between the two given nodes;
	 */
	bool canRoute( Node *n1, Node *n2 );
	void getReachable( IntList *reachable, int node );
	/**
	 * Either: position of node in m_nodeList,
	 * or: (position of node in m_extNodeList) + m_nodeList.size()
	 * or: -1
	 */
	int getNodePos( Node *n );
	/**
	 * Essentially the inverse of getNodePos
	 */
	Node* getNodePtr( int n );
};

#endif