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