1 /*************************************************************************** 2 * Copyright (C) 2003-2005 by David Saxton * 3 * david@bluehaze.org * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 ***************************************************************************/ 10 11 #ifndef ECNODE_H 12 #define ECNODE_H 13 14 #include "node.h" 15 16 // #include <q3valuevector.h> 17 18 class ECNode; 19 class Element; 20 class Pin; 21 class Switch; 22 class QTimer; 23 24 typedef QList<ECNode*> ECNodeList; 25 typedef QList<Element*> ElementList; 26 typedef QVector<Pin*> PinVector; 27 28 /** 29 @short Electrical node with voltage / current / etc properties 30 @author David Saxton 31 */ 32 class ECNode : public Node 33 { 34 Q_OBJECT 35 public: 36 ECNode( ICNDocument *icnDocument, Node::node_type type, int dir, const QPoint &pos, QString *id = nullptr ); 37 ~ECNode() override; 38 39 void setParentItem( CNItem *parentItem ) override; 40 41 /** 42 * draws the ECNode; still only a pure virtual function 43 */ 44 void drawShape( QPainter &p ) override = 0; 45 /** 46 * Set the number of pins "contained" in this node. 47 */ 48 void setNumPins( unsigned num ); 49 /** 50 * @return the number of pins in this node. 51 * @see setNumPins 52 */ numPins()53 unsigned numPins() const { return m_pins.size(); } 54 /** 55 * @return the pins in the node, as a vector 56 */ pins()57 PinVector pins() const { return m_pins; } 58 59 /** 60 * @param num number of the 61 * @return pointer to a pin in this node, given by num 62 */ 63 Pin *pin( unsigned num = 0 ) const ; 64 //{ return (num < m_pins.size()) ? m_pins[num] : nullptr; } 65 showVoltageBars()66 bool showVoltageBars() const { return m_bShowVoltageBars; } setShowVoltageBars(bool show)67 void setShowVoltageBars( bool show ) { m_bShowVoltageBars = show; } showVoltageColor()68 bool showVoltageColor() const { return m_bShowVoltageColor; } setShowVoltageColor(bool show)69 void setShowVoltageColor( bool show ) { m_bShowVoltageColor = show; } 70 void setNodeChanged(); 71 72 /** 73 * Returns true if this node is connected (or is the same as) the node given 74 * by other connectors or nodes (although not through CNItems) 75 * checkedNodes is a list of nodes that have already been checked for 76 * being the connected nodes, and so can simply return if they are in there. 77 * If it is null, it will assume that it is the first ndoe & will create a list 78 */ 79 bool isConnected( Node *node, NodeList *checkedNodes = nullptr ) override; 80 /** 81 * Sets the node's visibility, as well as updating the visibility of the 82 * attached connectors as appropriate 83 */ 84 void setVisible( bool yes ) override; 85 /** 86 * Registers an input connector (i.e. this is the end node) as connected 87 * to this node. 88 */ 89 void addConnector( Connector * const connector ); 90 /** 91 * Creates a new connector, sets this as the end node to the connector 92 * and returns a pointer to the connector. 93 */ 94 Connector* createConnector( Node * node); 95 96 // TODO oups, the following two methods do the same thing. Only one is needed. 97 /** 98 * Returns a list of the attached connectors; implemented inline 99 */ connectorList()100 ConnectorList connectorList() const { return m_connectorList; } 101 102 /** 103 * @return the list of all the connectors attached to the node 104 */ getAllConnectors()105 ConnectorList getAllConnectors() const override { return m_connectorList; } 106 107 /** 108 * Removes all the NULL connectors 109 */ 110 void removeNullConnectors() override; 111 112 /** 113 * Returns the total number of connections to the node. This is the number 114 * of connectors and the parent 115 * item connector if it exists and is requested. 116 * @param includeParentItem Count the parent item as a connector if it exists 117 * @param includeHiddenConnectors hidden connectors are those as e.g. part of a subcircuit 118 */ 119 int numCon( bool includeParentItem, bool includeHiddenConnectors ) const override; 120 /** 121 * Removes a specific connector 122 */ 123 void removeConnector( Connector *connector ) override; 124 125 /** 126 * For an electric node: returns the first connector 127 * If the node isn't connected to anyithing, returns null ( 0 ) 128 * @return pointer to the desired connector 129 */ 130 Connector* getAConnector() const override ; 131 132 signals: 133 void numPinsChanged( unsigned newNum ); 134 135 public slots: 136 // -- from node.h -- 137 void checkForRemoval( Connector *connector ); 138 139 protected slots: 140 void removeElement( Element * e ); 141 void removeSwitch( Switch * sw ); 142 143 protected: 144 bool m_bShowVoltageBars; 145 bool m_bShowVoltageColor; 146 double m_prevV; 147 double m_prevI; 148 KtlQCanvasRectangle * m_pinPoint; 149 PinVector m_pins; 150 151 // -- functionality from node.h -- 152 /** If this node has precisely two connectors emerging from it, then this 153 * function will trace the two connectors until the point where they 154 * diverge; this point is returned. 155 * TODO: find a meaning for this function, for an electronic node... 156 */ 157 QPoint findConnectorDivergePoint( bool * found ) override; 158 159 /** The attached connectors to this electronic node. No directionality here */ 160 ConnectorList m_connectorList; 161 162 /** (please document this) registers some signals for the node and the new connector (?) */ 163 bool handleNewConnector( Connector * newConnector ); 164 }; 165 166 #endif 167 168