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
|
/***************************************************************************
* Copyright (C) 2003-2004 by David Saxton *
* [email protected] *
* *
* 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 "currentsignal.h"
#include "eccurrentsignal.h"
#include "ecnode.h"
#include "libraryitem.h"
#include "pin.h"
#include "simulator.h"
#include <klocale.h>
#include <qpainter.h>
Item* ECCurrentSignal::construct( ItemDocument *itemDocument, bool newItem, const char *id )
{
return new ECCurrentSignal( (ICNDocument*)itemDocument, newItem, id );
}
LibraryItem* ECCurrentSignal::libraryItem()
{
return new LibraryItem(
QString("ec/ac_current"),
i18n("Current Signal"),
i18n("Sources"),
"currentsignal.png",
LibraryItem::lit_component,
ECCurrentSignal::construct );
}
ECCurrentSignal::ECCurrentSignal( ICNDocument *icnDocument, bool newItem, const char *id )
: Component( icnDocument, newItem, (id) ? id : "current_signal" )
{
m_name = i18n("Current Signal");
m_desc = i18n("Provides a variety of current signals");
setSize( -8, -8, 16, 16 );
init1PinLeft();
init1PinRight();
m_pNNode[0]->pin()->setGroundType( Pin::gt_low );
m_currentSignal = createCurrentSignal( m_pNNode[0], m_pPNode[0], 0. );
m_currentSignal->setStep( 1./LINEAR_UPDATE_RATE, ElementSignal::st_sinusoidal, 50. );
createProperty( "1-frequency", Variant::Type::Double );
property("1-frequency")->setCaption( i18n("Frequency") );
property("1-frequency")->setUnit("Hz");
property("1-frequency")->setMinValue(1e-9);
property("1-frequency")->setMaxValue(1e3);
property("1-frequency")->setValue(50.0);
createProperty( "1-current", Variant::Type::Double );
property("1-current")->setCaption( i18n("Current Range") );
property("1-current")->setUnit("A");
property("1-current")->setMinValue(-1e12);
property("1-current")->setMaxValue(1e12);
property("1-current")->setValue(0.02);
addDisplayText( "~", QRect( -8, -8, 16, 16 ), "~" );
addDisplayText( "current", QRect( -16, -24, 32, 16 ), "" );
}
ECCurrentSignal::~ECCurrentSignal()
{
}
void ECCurrentSignal::dataChanged()
{
const double current = dataDouble("1-current");
const double frequency = dataDouble("1-frequency");
QString display = QString::number( current / getMultiplier(current), 'g', 3 ) + getNumberMag(current) + "A";
setDisplayText( "current", display );
m_currentSignal->setStep( 1./LINEAR_UPDATE_RATE, ElementSignal::st_sinusoidal, frequency );
m_currentSignal->setCurrent(current);
}
void ECCurrentSignal::drawShape( QPainter &p )
{
initPainter(p);
p.drawEllipse( (int)x()-8, (int)y()-8, width(), height() );
deinitPainter(p);
}
|