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

Download this file

ecfixedvoltage.cpp    58 lines (45 with data), 2.0 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
/***************************************************************************
* Copyright (C) 2003-2004 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 "ecfixedvoltage.h"
#include "circuit.h"
#include "property.h"
#include <voltagepoint.h>
#include <elementmap.h>
#include <ecnode.h>
#include <QDebug>
ECFixedVoltage::ECFixedVoltage(Circuit &ownerCircuit)
: Component(ownerCircuit) {
m_voltagePoint = new VoltagePoint();
m_map = new ElementMap(m_voltagePoint);
m_elementMapList.append(m_map);
// the line below makes some tests fail, so this is not good
// m_map->pin(0)->setGroundType(Pin::gt_high);
m_pinMap.insert("p1", new ECNode(ownerCircuit, m_map->pin(0)));
Property *voltage = new Property("voltage", Variant::Type::Double);
voltage->setUnit("V");
voltage->setCaption(tr("Voltage"));
voltage->setMinValue(-1e15);
voltage->setMaxValue(1e15);
voltage->setValue(5.0);
addProperty(voltage);
ownerCircuit.addComponent(this);
}
ECFixedVoltage::~ECFixedVoltage() {
circuit().removeComponent(this);
}
void ECFixedVoltage::propertyChanged(Property& theProperty, QVariant newValue, QVariant oldValue)
{
Q_UNUSED(oldValue);
if(theProperty.name() == "voltage"){
double voltage = newValue.toDouble();
m_voltagePoint->setVoltage(voltage);
} else
qCritical() << "ECFixedVoltage: unknown property: " << theProperty.name();
}