summaryrefslogtreecommitdiffstats
path: root/src/electronics/components/inductor.cpp
blob: 3790fcb29e7a43b9df16e54a0b140f8f4fadf158 (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
/***************************************************************************
 *   Copyright (C) 2005 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 "inductance.h"
#include "inductor.h"
#include "libraryitem.h"

#include <tdelocale.h>
#include <tqpainter.h>

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

LibraryItem* Inductor::libraryItem()
{
	return new LibraryItem(
		"ec/inductor",
		i18n("Inductor"),
		i18n("Discrete"),
		"inductor.png",
		LibraryItem::lit_component,
		Inductor::construct
						  );
}

Inductor::Inductor( ICNDocument *icnDocument, bool newItem, const char *id )
	: Component( icnDocument, newItem, id ? id : "inductor" )
{
	m_name = i18n("Inductor");
// 	m_desc = i18n("Stores electrical charge.<br><br>"
// 			"The voltage across the inductor and inductance are related by <i>Charge = Inductance x Voltage</i>.");
	setSize( -16, -8, 32, 16 );
	
	init1PinLeft();
	init1PinRight();
	
	m_pInductance = createInductance( m_pNNode[0], m_pPNode[0], 0.001 );
	
	createProperty( "Inductance", Variant::Type::Double );
	property("Inductance")->setCaption( i18n("Inductance") );
	property("Inductance")->setUnit("H");
	property("Inductance")->setMinValue(1e-12);
	property("Inductance")->setMaxValue(1e12);
	property("Inductance")->setValue(1e-3);
	
	addDisplayText( "inductance", TQRect( -8, -24, 16, 16 ), "", false );
}

Inductor::~Inductor()
{
}

void Inductor::dataChanged()
{
	double inductance = dataDouble("Inductance");
	
	TQString display = TQString::number( inductance / getMultiplier(inductance), 'g', 3 ) + getNumberMag(inductance) + "H";
	setDisplayText( "inductance", display );
	
	m_pInductance->setInductance(inductance);
}

void Inductor::drawShape( TQPainter &p )
{
	initPainter(p);
	int _y = int(y());
	int _x = int(x());
	
	p.drawArc( _x-16, _y-5, 11, 11, 0, 180*16 );
	p.drawArc( _x-5, _y-5, 11, 11, 0, 180*16 );
	p.drawArc( _x+6, _y-5, 11, 11, 0, 180*16 );
	
	deinitPainter(p);
}