ecresistor.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "ecresistor.h"
00012 
00013 #include "libraryitem.h"
00014 #include "resistance.h"
00015 
00016 #include <klocale.h>
00017 #include <qpainter.h>
00018 
00019 Item* ECResistor::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00020 {
00021         return new ECResistor( (ICNDocument*)itemDocument, newItem, id );
00022 }
00023 
00024 LibraryItem* ECResistor::libraryItem()
00025 {
00026         return new LibraryItem(
00027                 "ec/resistor",
00028                 i18n("Resistor"),
00029                 i18n("Discrete"),
00030                 "resistor.png",
00031                 LibraryItem::lit_component,
00032                 ECResistor::construct );
00033 }
00034 
00035 ECResistor::ECResistor( ICNDocument *icnDocument, bool newItem, const char *id )
00036         : Component( icnDocument, newItem, id ? id : "resistor" )
00037 {
00038         m_name = i18n("Resistor");
00039         m_desc = i18n("Limits the flow of current, obeying Ohms Law");
00040         setSize( -16, -8, 32, 16 );
00041         
00042         init1PinLeft();
00043         init1PinRight();
00044         m_resistance = createResistance( m_pPNode[0], m_pNNode[0], 1. );
00045         
00046         createProperty( "resistance", Variant::Type::Double );
00047         property("resistance")->setCaption( i18n("Resistance") );
00048         property("resistance")->setUnit( QChar(0x3a9) );
00049         property("resistance")->setValue(1e4);
00050         property("resistance")->setMinValue(1e-6);
00051 
00052 // TODO: there are standard resistor values dependant on tolerance, user should
00053 // be offered these before a custom resistor type. 
00054         
00055         addDisplayText( "res", QRect( -16, -22, 32, 12 ), "", false );
00056 }
00057 
00058 ECResistor::~ECResistor()
00059 {
00060 }
00061 
00062 void ECResistor::dataChanged()
00063 {
00064         double resistance = dataDouble("resistance");
00065         
00066         QString display = QString::number( resistance / getMultiplier(resistance), 'g', 3 ) + getNumberMag(resistance) + QChar(0x3a9);
00067         setDisplayText( "res", display );
00068         
00069         m_resistance->setResistance(resistance);
00070 }
00071 
00072 void ECResistor::drawShape( QPainter &p )
00073 {
00074         initPainter(p);
00075         p.drawRect( (int)x()-16, (int)y()-6, width(), 12 );
00076         deinitPainter(p);
00077 }
00078 
00079 

Generated on Tue May 8 17:05:29 2007 for KTechLab by  doxygen 1.5.1