summaryrefslogtreecommitdiffstats
path: root/src/electronics/wire.h
blob: 368004c0e24ac0b74a32ee6e886c7677b7624764 (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
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   [email protected]                                                    *
 *                                                                         *
 *   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 WIRE_H
#define WIRE_H

#include <qguardedptr.h>
#include <qobject.h>

class Pin;

/**
@author David Saxton
*/
class Wire : public QObject
{
	public:
		Wire( Pin * startPin, Pin * endPin );
		~Wire();

		/**
		 * Attempts to calculate the current that is flowing through
		 * the connector. Returns true if successfuly, otherwise returns false
		 */
		bool calculateCurrent();
		/**
		 * Returns true if the current flowing through the connector is known
		 */
		bool currentIsKnown() const { return m_bCurrentIsKnown; }
		/**
		 * Set whether the actual current flowing into this node is known (in some
		 * cases - such as this node being ground - it is not known, and so the
		 * value returned by current() cannot be relied on.
		 */
		void setCurrentKnown( bool known );
		/**
		 * Returns the current flowing through the connector.
		 * This only applies for electronic connectors
		 */
		double current() const { return m_current; } 
		/**
		 * Returns the voltage at the connector. This is an average of the
		 * voltages at either end.
		 */
		double voltage() const;
		
		Pin * startPin() const { return m_pStartPin; }
		Pin * endPin() const { return m_pEndPin; }
		
	protected:
		double m_current;
		bool m_bCurrentIsKnown;
		QGuardedPtr<Pin> m_pStartPin;
		QGuardedPtr<Pin> m_pEndPin;
};

#endif