summaryrefslogtreecommitdiffstats
path: root/src/electronics/components/ecvoltagesignal.cpp
blob: 1590766cbe960773d21e8fed523847ee116e47e6 (plain)
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
/***************************************************************************
 *   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 "ecnode.h"
#include "ecvoltagesignal.h"
#include "libraryitem.h"
#include "pin.h"
#include "simulator.h"
#include "voltagesignal.h"

#include <klocale.h>
#include <tqpainter.h>

const double conductance = 1e5; // Internal resistance

Item* ECVoltageSignal::construct( ItemDocument *itemDocument, bool newItem, const char *id )
{
	return new ECVoltageSignal( (ICNDocument*)itemDocument, newItem, id );
}

LibraryItem* ECVoltageSignal::libraryItem()
{
	return new LibraryItem(
		TQString("ec/voltage_signal"),
		i18n("Voltage Signal"),
		i18n("Sources"),
		"voltagesignal.png",
		LibraryItem::lit_component,
		ECVoltageSignal::construct );
}

ECVoltageSignal::ECVoltageSignal( ICNDocument *icnDocument, bool newItem, const char *id )
	: Component( icnDocument, newItem, (id) ? id : "voltage_signal" )
{
	m_name = i18n("Voltage Signal");
	m_desc = i18n("Provides a variety of voltage signals.");
	setSize( -8, -8, 16, 16 );
	
	init1PinLeft();
	init1PinRight();
	
	m_pNNode[0]->pin()->setGroundType( Pin::gt_medium );
	m_voltageSignal = createVoltageSignal( m_pNNode[0], m_pPNode[0], 0. );
	m_voltageSignal->setStep( 1./LINEAR_UPDATE_RATE, ElementSignal::st_sinusoidal, 50. );
	
	createProperty( "frequency", Variant::Type::Double );
	property("frequency")->setCaption( i18n("Frequency") );
	property("frequency")->setUnit("Hz");
	property("frequency")->setMinValue(1e-9);
	property("frequency")->setMaxValue(1e3);
	property("frequency")->setValue(50.0);
	
	createProperty( "voltage", Variant::Type::Double );
	property("voltage")->setCaption( i18n("Voltage Range") );
	property("voltage")->setUnit("V");	
	property("voltage")->setMinValue(-1e12);
	property("voltage")->setMaxValue(1e12);
	property("voltage")->setValue(5.0);
	
	addDisplayText( "~", TQRect( -8, -8, 16, 16 ), "~" );
	addDisplayText( "voltage", TQRect( -16, -24, 32, 16 ), "" );
}


ECVoltageSignal::~ECVoltageSignal()
{
}

void ECVoltageSignal::dataChanged()
{
	const double voltage = dataDouble("voltage");
	const double frequency = dataDouble("frequency");
	
	TQString display = TQString::number( voltage / getMultiplier(voltage), 'g', 3 ) + getNumberMag(voltage) + "V";
	setDisplayText( "voltage", display );
	
	m_voltageSignal->setStep( 1./LINEAR_UPDATE_RATE, ElementSignal::st_sinusoidal, frequency );
	m_voltageSignal->setVoltage(voltage);
}


void ECVoltageSignal::drawShape( TQPainter &p )
{
	initPainter(p);
	p.drawEllipse( (int)x()-8, (int)y()-8, width(), height() );
	deinitPainter(p);
}