File indexing completed on 2024-04-28 13:39:06

0001 /***************************************************************************
0002  *   Copyright (C) 2003-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 ECNODE_H
0012 #define ECNODE_H
0013 
0014 #include "node.h"
0015 
0016 // #include <q3valuevector.h>
0017 
0018 class ECNode;
0019 class Element;
0020 class Pin;
0021 class Switch;
0022 class QTimer;
0023 
0024 typedef QList<ECNode *> ECNodeList;
0025 typedef QList<Element *> ElementList;
0026 typedef QVector<Pin *> PinVector;
0027 
0028 /**
0029 @short Electrical node with voltage / current / etc properties
0030 @author David Saxton
0031 */
0032 class ECNode : public Node
0033 {
0034     Q_OBJECT
0035 public:
0036     ECNode(ICNDocument *icnDocument, Node::node_type type, int dir, const QPoint &pos, QString *id = nullptr);
0037     ~ECNode() override;
0038 
0039     void setParentItem(CNItem *parentItem) override;
0040 
0041     /**
0042      *  draws the ECNode; still only a pure virtual function
0043      */
0044     void drawShape(QPainter &p) override = 0;
0045     /**
0046      * Set the number of pins "contained" in this node.
0047      */
0048     void setNumPins(unsigned num);
0049     /**
0050      * @return the number of pins in this node.
0051      * @see setNumPins
0052      */
0053     unsigned numPins() const
0054     {
0055         return m_pins.size();
0056     }
0057     /**
0058      * @return the pins in the node, as a vector
0059      */
0060     PinVector pins() const
0061     {
0062         return m_pins;
0063     }
0064 
0065     /**
0066      * @param num number of the
0067      * @return pointer to a pin in this node, given by num
0068      */
0069     Pin *pin(unsigned num = 0) const;
0070     //{ return (num < m_pins.size()) ? m_pins[num] : nullptr; }
0071 
0072     bool showVoltageBars() const
0073     {
0074         return m_bShowVoltageBars;
0075     }
0076     void setShowVoltageBars(bool show)
0077     {
0078         m_bShowVoltageBars = show;
0079     }
0080     bool showVoltageColor() const
0081     {
0082         return m_bShowVoltageColor;
0083     }
0084     void setShowVoltageColor(bool show)
0085     {
0086         m_bShowVoltageColor = show;
0087     }
0088     void setNodeChanged();
0089 
0090     /**
0091      * Returns true if this node is connected (or is the same as) the node given
0092      * by other connectors or nodes (although not through CNItems)
0093      * checkedNodes is a list of nodes that have already been checked for
0094      * being the connected nodes, and so can simply return if they are in there.
0095      * If it is null, it will assume that it is the first ndoe & will create a list
0096      */
0097     bool isConnected(Node *node, NodeList *checkedNodes = nullptr) override;
0098     /**
0099      * Sets the node's visibility, as well as updating the visibility of the
0100      * attached connectors as appropriate
0101      */
0102     void setVisible(bool yes) override;
0103     /**
0104      * Registers an input connector (i.e. this is the end node) as connected
0105      * to this node.
0106      */
0107     void addConnector(Connector *const connector);
0108     /**
0109      * Creates a new connector, sets this as the end node to the connector
0110      * and returns a pointer to the connector.
0111      */
0112     Connector *createConnector(Node *node);
0113 
0114     // TODO oups, the following two methods do the same thing. Only one is needed.
0115     /**
0116      * Returns a list of the attached connectors; implemented inline
0117      */
0118     ConnectorList connectorList() const
0119     {
0120         return m_connectorList;
0121     }
0122 
0123     /**
0124      * @return the list of all the connectors attached to the node
0125      */
0126     ConnectorList getAllConnectors() const override
0127     {
0128         return m_connectorList;
0129     }
0130 
0131     /**
0132      * Removes all the NULL connectors
0133      */
0134     void removeNullConnectors() override;
0135 
0136     /**
0137      * Returns the total number of connections to the node. This is the number
0138      * of connectors and the parent
0139      * item connector if it exists and is requested.
0140      * @param includeParentItem Count the parent item as a connector if it exists
0141      * @param includeHiddenConnectors hidden connectors are those as e.g. part of a subcircuit
0142      */
0143     int numCon(bool includeParentItem, bool includeHiddenConnectors) const override;
0144     /**
0145      * Removes a specific connector
0146      */
0147     void removeConnector(Connector *connector) override;
0148 
0149     /**
0150      * For an electric node: returns the first connector
0151      * If the node isn't connected to anyithing, returns null ( 0 )
0152      * @return pointer to the desired connector
0153      */
0154     Connector *getAConnector() const override;
0155 
0156 signals:
0157     void numPinsChanged(unsigned newNum);
0158 
0159 public slots:
0160     // -- from node.h --
0161     void checkForRemoval(Connector *connector);
0162 
0163 protected slots:
0164     void removeElement(Element *e);
0165     void removeSwitch(Switch *sw);
0166 
0167 protected:
0168     bool m_bShowVoltageBars;
0169     bool m_bShowVoltageColor;
0170     double m_prevV;
0171     double m_prevI;
0172     KtlQCanvasRectangle *m_pinPoint;
0173     PinVector m_pins;
0174 
0175     // -- functionality from node.h --
0176     /** If this node has precisely two connectors emerging from it, then this
0177      * function will trace the two connectors until the point where they
0178      * diverge; this point is returned.
0179      * TODO: find a meaning for this function, for an electronic node...
0180      */
0181     QPoint findConnectorDivergePoint(bool *found) override;
0182 
0183     /** The attached connectors to this electronic node. No directionality here */
0184     ConnectorList m_connectorList;
0185 
0186     /** (please document this) registers some signals for the node and the new connector (?) */
0187     bool handleNewConnector(Connector *newConnector);
0188 };
0189 
0190 #endif