File indexing completed on 2024-07-21 05:07:44

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef WIRE_H
0012 #define WIRE_H
0013 
0014 #include <pin.h>
0015 
0016 #include <QObject>
0017 #include <QPointer>
0018 
0019 class Pin;
0020 
0021 /**
0022 @author David Saxton
0023 */
0024 class Wire : public QObject
0025 {
0026 public:
0027     Wire(Pin *startPin, Pin *endPin);
0028     ~Wire() override;
0029 
0030     /**
0031      * Attempts to calculate the current that is flowing through
0032      * the connector. Returns true if successfuly, otherwise returns false
0033      */
0034     bool calculateCurrent();
0035     /**
0036      * Returns true if the current flowing through the connector is known
0037      */
0038     bool currentIsKnown() const
0039     {
0040         return m_bCurrentIsKnown;
0041     }
0042     /**
0043      * Set whether the actual current flowing into this node is known (in some
0044      * cases - such as this node being ground - it is not known, and so the
0045      * value returned by current() cannot be relied on.
0046      */
0047     void setCurrentKnown(bool known);
0048     /**
0049      * Returns the current flowing through the connector.
0050      * This only applies for electronic connectors
0051      */
0052     double current() const
0053     {
0054         return m_current;
0055     }
0056     /**
0057      * Returns the voltage at the connector. This is an average of the
0058      * voltages at either end.
0059      */
0060     double voltage() const;
0061 
0062     Pin *startPin() const
0063     {
0064         return m_pStartPin;
0065     }
0066     Pin *endPin() const
0067     {
0068         return m_pEndPin;
0069     }
0070 
0071     // protected:
0072 
0073 private:
0074     double m_current;
0075     bool m_bCurrentIsKnown;
0076     QPointer<Pin> m_pStartPin;
0077     QPointer<Pin> m_pEndPin;
0078 };
0079 
0080 #endif