00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "ecvoltagesource.h"
00012
00013 #include "ecnode.h"
00014 #include "voltagesource.h"
00015 #include "libraryitem.h"
00016 #include "pin.h"
00017
00018 #include <klocale.h>
00019 #include <qpainter.h>
00020
00021 Item* ECCell::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00022 {
00023 return new ECCell( (ICNDocument*)itemDocument, newItem, id );
00024 }
00025
00026 LibraryItem* ECCell::libraryItem()
00027 {
00028 QStringList ids;
00029 ids << "ec/battery" << "ec/cell";
00030 return new LibraryItem(
00031 ids,
00032 i18n("Battery"),
00033 i18n("Sources"),
00034 "cell.png",
00035 LibraryItem::lit_component,
00036 ECCell::construct );
00037 }
00038
00039 ECCell::ECCell( ICNDocument *icnDocument, bool newItem, const char *id )
00040 : Component( icnDocument, newItem, (id) ? id : "cell" )
00041 {
00042 m_name = i18n("Battery");
00043 m_desc = i18n("Provides a potential-difference.");
00044 setSize( -8, -8, 16, 16 );
00045 voltage = 0;
00046
00047 init1PinLeft();
00048 init1PinRight();
00049
00050 m_pNNode[0]->pin()->setGroundType( Pin::gt_medium );
00051 m_voltageSource = createVoltageSource( m_pNNode[0], m_pPNode[0], voltage );
00052
00053 createProperty( "voltage", Variant::Type::Double );
00054 property("voltage")->setUnit("V");
00055 property("voltage")->setCaption( i18n("Voltage") );
00056 property("voltage")->setMinValue(-1e12);
00057 property("voltage")->setMaxValue(1e12);
00058 property("voltage")->setValue(5.0);
00059
00060 addDisplayText( "voltage", QRect( -16, -24, 32, 16 ), "" );
00061 }
00062
00063 ECCell::~ECCell()
00064 {
00065 }
00066
00067 void ECCell::dataChanged()
00068 {
00069 voltage = dataDouble("voltage");
00070 m_voltageSource->setVoltage(voltage);
00071
00072 QString display = QString::number( voltage / getMultiplier(voltage), 'g', 3 ) + getNumberMag(voltage) + "V";
00073 setDisplayText( "voltage", display );
00074 }
00075
00076 void ECCell::drawShape( QPainter &p )
00077 {
00078 initPainter(p);
00079
00080 int _x = (int)x()-8;
00081 int _y = (int)y()-24;
00082
00083 p.drawLine( _x, _y+20, _x, _y+28 );
00084 p.drawLine( _x+5, _y+16, _x+5, _y+32 );
00085 p.drawLine( _x+10, _y+20, _x+10, _y+28 );
00086 p.drawLine( _x+15, _y+16, _x+15, _y+32 );
00087
00088 deinitPainter(p);
00089
00090 }
00091