Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[812dd5]: src / lib / simulator / src / electronics / ecnode.cpp Maximize Restore History

Download this file

ecnode.cpp    133 lines (109 with data), 3.2 kB

  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
/***************************************************************************
* Copyright (C) 2003-2005 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. *
***************************************************************************/
#include "ecnode.h"
#include "circuit.h"
#include "connector.h"
#include "electronicconnector.h"
#include <QDebug>
ECNode::ECNode(Circuit &c)
: Node(), m_circuit(c) {
// create 1 pin
m_pins.clear();
Pin *pin = new Pin();
m_ownsPins = true;
m_pins.append(pin);
// register
c.addPin(pin);
}
ECNode::ECNode(Circuit &c, Pin* pin): Node(), m_circuit(c)
{
Q_ASSERT(pin);
m_pins.clear();
m_pins.append(pin);
m_ownsPins = false;
// ...
c.addPin(pin);
}
ECNode::~ECNode() {
// connectors
foreach(Connector *con, m_connectorList){
delete con;
}
m_connectorList.clear();
// pins
foreach(Pin *pin, m_pins){
m_circuit.removePin(pin);
}
if(m_ownsPins){
foreach(Pin *pin, m_pins){
delete pin;
}
}
m_pins.clear();
}
// TODO FIXME implement the removal/adding of pins from/to the circuit
// TODO FIXME deal with connectors when setting the pin count
void ECNode::setNumPins(unsigned num) {
unsigned oldNum = m_pins.size();
if (num == oldNum) return;
if(!m_ownsPins)
qCritical() << "ECNode::setNumPins: BUG: setting pin cound on a node which doesn't own its pins!\n";
qCritical() << "ECNode::setNumPins: setting pin count is not completely implemented!" <<
"expect crashes!";
if(num > oldNum){
// create pins
for(int i=oldNum; i<num; i++){
Pin *p = new Pin();
m_pins.append(p);
}
} else {
// delete pins
for(int i=num; i<oldNum; i++){
Pin *p = m_pins.at(i);
m_pins.removeAt(i);
delete p;
}
}
Q_ASSERT(m_pins.size() == num);
}
int ECNode::numPins() const
{
return m_pins.size();
}
PinList ECNode::pins() const
{
return m_pins;
}
Pin* ECNode::pin(unsigned int num) const
{
if(num >= m_pins.size()){
qDebug() << "BUG: tried to access nonexsitent pin in an EcNode!\n";
return NULL;
}
return m_pins.at(num);
}
// -- connector related --
void ECNode::addConnector(Connector *connector) {
Q_ASSERT(connector);
m_connectorList.append(connector);
}
void ECNode::removeConnector(Connector *connector) {
Q_ASSERT(connector);
m_connectorList.removeAll(connector);
}
int ECNode::numCon() const
{
return m_connectorList.size();
}
ConnectorList ECNode::allConnectors() const
{
return m_connectorList;
}
#include "ecnode.moc"