File indexing completed on 2024-05-05 05:46:05
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 "ecvoltagesource.h" 0012 0013 #include "ecnode.h" 0014 #include "libraryitem.h" 0015 #include "pin.h" 0016 #include "voltagesource.h" 0017 0018 #include <KLocalizedString> 0019 #include <QPainter> 0020 0021 Item *ECCell::construct(ItemDocument *itemDocument, bool newItem, const char *id) 0022 { 0023 return new ECCell(static_cast<ICNDocument *>(itemDocument), newItem, id); 0024 } 0025 0026 LibraryItem *ECCell::libraryItem() 0027 { 0028 QStringList ids; 0029 ids << "ec/battery" 0030 << "ec/cell"; 0031 return new LibraryItem(ids, i18n("Battery"), i18n("Sources"), "cell.png", LibraryItem::lit_component, ECCell::construct); 0032 } 0033 0034 ECCell::ECCell(ICNDocument *icnDocument, bool newItem, const char *id) 0035 : Component(icnDocument, newItem, id ? id : "cell") 0036 { 0037 m_name = i18n("Battery"); 0038 setSize(-8, -8, 16, 16); 0039 voltage = 0; 0040 0041 init1PinLeft(); 0042 init1PinRight(); 0043 0044 m_pNNode[0]->pin()->setGroundType(Pin::gt_medium); 0045 m_voltageSource = createVoltageSource(m_pNNode[0], m_pPNode[0], voltage); 0046 0047 createProperty("voltage", Variant::Type::Double); 0048 property("voltage")->setUnit("V"); 0049 property("voltage")->setCaption(i18n("Voltage")); 0050 property("voltage")->setMinValue(-1e12); 0051 property("voltage")->setMaxValue(1e12); 0052 property("voltage")->setValue(5.0); 0053 0054 addDisplayText("voltage", QRect(-16, -24, 32, 16), ""); 0055 } 0056 0057 ECCell::~ECCell() 0058 { 0059 } 0060 0061 void ECCell::dataChanged() 0062 { 0063 voltage = dataDouble("voltage"); 0064 m_voltageSource->setVoltage(voltage); 0065 0066 QString display = QString::number(voltage / getMultiplier(voltage), 'g', 3) + getNumberMag(voltage) + "V"; 0067 setDisplayText("voltage", display); 0068 } 0069 0070 void ECCell::drawShape(QPainter &p) 0071 { 0072 initPainter(p); 0073 0074 int _x = int(x()) - 8; 0075 int _y = int(y()) - 24; 0076 0077 p.drawLine(_x, _y + 20, _x, _y + 28); 0078 p.drawLine(_x + 5, _y + 16, _x + 5, _y + 32); 0079 p.drawLine(_x + 10, _y + 20, _x + 10, _y + 28); 0080 p.drawLine(_x + 15, _y + 16, _x + 15, _y + 32); 0081 0082 deinitPainter(p); 0083 // p.drawPolyline( areaPoints() ); 0084 }