File indexing completed on 2024-05-05 05:46:04
0001 /*************************************************************************** 0002 * Copyright (C) 2003 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 "eccurrentsource.h" 0012 #include "currentsource.h" 0013 #include "ecnode.h" 0014 #include "libraryitem.h" 0015 #include "pin.h" 0016 0017 #include <KLocalizedString> 0018 #include <QPainter> 0019 0020 Item *ECCurrentSource::construct(ItemDocument *itemDocument, bool newItem, const char *id) 0021 { 0022 return new ECCurrentSource(static_cast<ICNDocument *>(itemDocument), newItem, id); 0023 } 0024 0025 LibraryItem *ECCurrentSource::libraryItem() 0026 { 0027 return new LibraryItem(QStringList(QString("ec/current_source")), i18n("Current Source"), i18n("Sources"), "current_source.png", LibraryItem::lit_component, ECCurrentSource::construct); 0028 } 0029 0030 ECCurrentSource::ECCurrentSource(ICNDocument *icnDocument, bool newItem, const char *id) 0031 : Component(icnDocument, newItem, id ? id : "current_source") 0032 { 0033 m_name = i18n("Current Source"); 0034 setSize(-16, -8, 24, 24); 0035 0036 init1PinLeft(8); 0037 init1PinRight(8); 0038 m_pNNode[0]->pin()->setGroundType(Pin::gt_low); 0039 0040 m_currentSource = createCurrentSource(m_pNNode[0], m_pPNode[0], 0.); 0041 0042 createProperty("current", Variant::Type::Double); 0043 property("current")->setCaption(i18n("Current")); 0044 property("current")->setUnit("A"); 0045 property("current")->setMinValue(-1e12); 0046 property("current")->setMaxValue(1e12); 0047 property("current")->setValue(0.02); 0048 0049 addDisplayText("current", QRect(-16, -16, 24, 0), ""); 0050 } 0051 0052 ECCurrentSource::~ECCurrentSource() 0053 { 0054 } 0055 0056 void ECCurrentSource::dataChanged() 0057 { 0058 double current = dataDouble("current"); 0059 m_currentSource->setCurrent(current); 0060 0061 QString display = QString::number(current / getMultiplier(current), 'g', 3) + getNumberMag(current) + "A"; 0062 setDisplayText("current", display); 0063 } 0064 0065 void ECCurrentSource::drawShape(QPainter &p) 0066 { 0067 initPainter(p); 0068 0069 int _x = int(x()) - 16; 0070 int _y = int(y()) - 24; 0071 0072 // Top arrow indicating current direction 0073 p.drawLine(_x + width(), _y + 19, _x, _y + 19); 0074 p.drawLine(_x + width(), _y + 19, _x + width() - 3, _y + 16); 0075 p.drawLine(_x + width(), _y + 19, _x + width() - 3, _y + 22); 0076 0077 // Double circules 0078 p.drawEllipse(_x, _y + 24, 16, 16); 0079 p.drawEllipse(_x + 8, _y + 24, 16, 16); 0080 0081 deinitPainter(p); 0082 }