summaryrefslogtreecommitdiffstats
path: root/src/electronics/components/ecbjt.cpp
blob: b4b59f2d5f55087cf7bb9361b27186bb7abfa7cf (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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/***************************************************************************
 *   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 "bjt.h"
#include "ecbjt.h"
#include "ecnode.h"
#include "libraryitem.h"

#include <kiconloader.h>
#include <klocale.h>
#include <qpainter.h>

Item * ECBJT::constructNPN( ItemDocument * itemDocument, bool newItem, const char * id )
{
	return new ECBJT( true, (ICNDocument*)itemDocument, newItem, id );
}


Item * ECBJT::constructPNP( ItemDocument * itemDocument, bool newItem, const char * id )
{
	return new ECBJT( false, (ICNDocument*)itemDocument, newItem, id );
}


LibraryItem* ECBJT::libraryItemNPN()
{
	return new LibraryItem(
		"ec/npnbjt",
		i18n("NPN"),
		i18n("Discrete"),
		"npn.png",
		LibraryItem::lit_component,
		ECBJT::constructNPN );
}


LibraryItem* ECBJT::libraryItemPNP()
{
	return new LibraryItem(
		"ec/pnpbjt",
		i18n("PNP"),
		i18n("Discrete"),
		"pnp.png",
		LibraryItem::lit_component,
		ECBJT::constructPNP );
}


ECBJT::ECBJT( bool isNPN, ICNDocument * icnDocument, bool newItem, const char * id )
	: Component( icnDocument, newItem, id ? id : (isNPN ? "npnbjt" : "pnpbjt") )
{
	m_bIsNPN = isNPN;
	if ( m_bIsNPN )
		m_name = i18n("NPN Transistor");
	else
		m_name = i18n("PNP Transistor");
	
	setSize( -8, -8, 16, 16 );
	m_pBJT = createBJT( createPin( 8, -16, 90, "c" ), createPin( -16, 0, 0, "b" ), createPin( 8, 16, 270, "e" ), m_bIsNPN );
	
	BJTSettings s; // will be created with the default settings
	
	Variant * v = createProperty( "I_S", Variant::Type::Double );
	v->setCaption("Saturation Current");
	v->setUnit("A");
	v->setMinValue(1e-20);
	v->setMaxValue(1e-0);
	v->setValue( s.I_S );
	v->setAdvanced(true);
	
	v = createProperty( "N_F", Variant::Type::Double );
	v->setCaption( i18n("Forward Coefficient") );
	v->setMinValue(1e0);
	v->setMaxValue(1e1);
	v->setValue( s.N_F );
	v->setAdvanced(true);
	
	v = createProperty( "N_R", Variant::Type::Double );
	v->setCaption( i18n("Reverse Coefficient") );
	v->setMinValue(1e0);
	v->setMaxValue(1e1);
	v->setValue( s.N_R );
	v->setAdvanced(true);
	
	v = createProperty( "B_F", Variant::Type::Double );
	v->setCaption( i18n("Forward Beta") );
	v->setMinValue(1e-1);
	v->setMaxValue(1e3);
	v->setValue( s.B_F );
	v->setAdvanced(true);
	
	v = createProperty( "B_R", Variant::Type::Double );
	v->setCaption( i18n("Reverse Beta") );
	v->setMinValue(1e-1);
	v->setMaxValue(1e3);
	v->setValue( s.B_R );
	v->setAdvanced(true);
}

ECBJT::~ECBJT()
{
}


void ECBJT::dataChanged()
{
	BJTSettings s;
	s.I_S = dataDouble( "I_S" );
	s.N_F = dataDouble( "N_F" );
	s.N_R = dataDouble( "N_R" );
	s.B_F = dataDouble( "B_F" );
	s.B_R = dataDouble( "B_R" );
	
	m_pBJT->setBJTSettings( s );
}


void ECBJT::drawShape( QPainter &p )
{
	const int _x = int(x());
	const int _y = int(y());
	
	initPainter(p);
	
	p.drawLine( _x-8, _y-8, _x-8, _y+8 );
	p.drawLine( _x+8, _y-8, _x-8, _y );
	p.drawLine( _x+8, _y+8, _x-8, _y );
	
	QPointArray pa(3);
	if ( m_bIsNPN )
	{
		pa[0] = QPoint( _x+6, _y+7 );
		pa[1] = QPoint( _x+2, _y+8 );
		pa[2] = QPoint( _x+6, _y+3 );
	}
	else
	{
		pa[0] = QPoint( _x-7, _y+1 );
		pa[1] = QPoint( _x-4, _y+5 );
		pa[2] = QPoint( _x-2, _y );
	}
	p.setBrush( p.pen().color() );
	p.drawPolygon(pa);
	
	deinitPainter(p);
}