File indexing completed on 2024-05-05 05:46:06

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "inductor.h"
0012 #include "inductance.h"
0013 #include "libraryitem.h"
0014 
0015 #include <KLocalizedString>
0016 #include <QPainter>
0017 
0018 Item *Inductor::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0019 {
0020     return new Inductor(static_cast<ICNDocument *>(itemDocument), newItem, id);
0021 }
0022 
0023 LibraryItem *Inductor::libraryItem()
0024 {
0025     return new LibraryItem(QStringList(QString("ec/inductor")), i18n("Inductor"), i18n("Passive"), "inductor.png", LibraryItem::lit_component, Inductor::construct);
0026 }
0027 
0028 Inductor::Inductor(ICNDocument *icnDocument, bool newItem, const char *id)
0029     : Component(icnDocument, newItem, id ? id : "inductor")
0030 {
0031     m_name = i18n("Inductor");
0032     setSize(-16, -8, 32, 16);
0033 
0034     init1PinLeft();
0035     init1PinRight();
0036 
0037     m_pInductance = createInductance(m_pNNode[0], m_pPNode[0], 0.001);
0038 
0039     createProperty("Inductance", Variant::Type::Double);
0040     property("Inductance")->setCaption(i18n("Inductance"));
0041     property("Inductance")->setUnit("H");
0042     property("Inductance")->setMinValue(1e-12);
0043     property("Inductance")->setMaxValue(1e12);
0044     property("Inductance")->setValue(1e-3);
0045 
0046     addDisplayText("inductance", QRect(-8, -24, 16, 16), "", false);
0047 }
0048 
0049 Inductor::~Inductor()
0050 {
0051 }
0052 
0053 void Inductor::dataChanged()
0054 {
0055     double inductance = dataDouble("Inductance");
0056 
0057     QString display = QString::number(inductance / getMultiplier(inductance), 'g', 3) + getNumberMag(inductance) + "H";
0058     setDisplayText("inductance", display);
0059 
0060     m_pInductance->setInductance(inductance);
0061 }
0062 
0063 void Inductor::drawShape(QPainter &p)
0064 {
0065     initPainter(p);
0066     int _y = int(y());
0067     int _x = int(x());
0068 
0069     p.drawArc(_x - 16, _y - 5, 11, 11, 0, 180 * 16);
0070     p.drawArc(_x - 5, _y - 5, 11, 11, 0, 180 * 16);
0071     p.drawArc(_x + 6, _y - 5, 11, 11, 0, 180 * 16);
0072 
0073     deinitPainter(p);
0074 }