ecbjt.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2005 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 "bjt.h"
00012 #include "ecbjt.h"
00013 #include "ecnode.h"
00014 #include "libraryitem.h"
00015 
00016 #include <kiconloader.h>
00017 #include <klocale.h>
00018 #include <qpainter.h>
00019 
00020 Item * ECBJT::constructNPN( ItemDocument * itemDocument, bool newItem, const char * id )
00021 {
00022         return new ECBJT( true, (ICNDocument*)itemDocument, newItem, id );
00023 }
00024 
00025 
00026 Item * ECBJT::constructPNP( ItemDocument * itemDocument, bool newItem, const char * id )
00027 {
00028         return new ECBJT( false, (ICNDocument*)itemDocument, newItem, id );
00029 }
00030 
00031 
00032 LibraryItem* ECBJT::libraryItemNPN()
00033 {
00034         return new LibraryItem(
00035                 "ec/npnbjt",
00036                 i18n("NPN"),
00037                 i18n("Discrete"),
00038                 "npn.png",
00039                 LibraryItem::lit_component,
00040                 ECBJT::constructNPN );
00041 }
00042 
00043 
00044 LibraryItem* ECBJT::libraryItemPNP()
00045 {
00046         return new LibraryItem(
00047                 "ec/pnpbjt",
00048                 i18n("PNP"),
00049                 i18n("Discrete"),
00050                 "pnp.png",
00051                 LibraryItem::lit_component,
00052                 ECBJT::constructPNP );
00053 }
00054 
00055 
00056 ECBJT::ECBJT( bool isNPN, ICNDocument * icnDocument, bool newItem, const char * id )
00057         : Component( icnDocument, newItem, id ? id : (isNPN ? "npnbjt" : "pnpbjt") )
00058 {
00059         m_bIsNPN = isNPN;
00060         if ( m_bIsNPN )
00061                 m_name = i18n("NPN Transistor");
00062         else
00063                 m_name = i18n("PNP Transistor");
00064         
00065         setSize( -8, -8, 16, 16 );
00066         m_pBJT = createBJT( createPin( 8, -16, 90, "c" ), createPin( -16, 0, 0, "b" ), createPin( 8, 16, 270, "e" ), m_bIsNPN );
00067         
00068         BJTSettings s; // will be created with the default settings
00069         
00070         Variant * v = createProperty( "I_S", Variant::Type::Double );
00071         v->setCaption("Saturation Current");
00072         v->setUnit("A");
00073         v->setMinValue(1e-20);
00074         v->setMaxValue(1e-0);
00075         v->setValue( s.I_S );
00076         v->setAdvanced(true);
00077         
00078         v = createProperty( "N_F", Variant::Type::Double );
00079         v->setCaption( i18n("Forward Coefficient") );
00080         v->setMinValue(1e0);
00081         v->setMaxValue(1e1);
00082         v->setValue( s.N_F );
00083         v->setAdvanced(true);
00084         
00085         v = createProperty( "N_R", Variant::Type::Double );
00086         v->setCaption( i18n("Reverse Coefficient") );
00087         v->setMinValue(1e0);
00088         v->setMaxValue(1e1);
00089         v->setValue( s.N_R );
00090         v->setAdvanced(true);
00091         
00092         v = createProperty( "B_F", Variant::Type::Double );
00093         v->setCaption( i18n("Forward Beta") );
00094         v->setMinValue(1e-1);
00095         v->setMaxValue(1e3);
00096         v->setValue( s.B_F );
00097         v->setAdvanced(true);
00098         
00099         v = createProperty( "B_R", Variant::Type::Double );
00100         v->setCaption( i18n("Reverse Beta") );
00101         v->setMinValue(1e-1);
00102         v->setMaxValue(1e3);
00103         v->setValue( s.B_R );
00104         v->setAdvanced(true);
00105 }
00106 
00107 ECBJT::~ECBJT()
00108 {
00109 }
00110 
00111 
00112 void ECBJT::dataChanged()
00113 {
00114         BJTSettings s;
00115         s.I_S = dataDouble( "I_S" );
00116         s.N_F = dataDouble( "N_F" );
00117         s.N_R = dataDouble( "N_R" );
00118         s.B_F = dataDouble( "B_F" );
00119         s.B_R = dataDouble( "B_R" );
00120         
00121         m_pBJT->setBJTSettings( s );
00122 }
00123 
00124 
00125 void ECBJT::drawShape( QPainter &p )
00126 {
00127         const int _x = int(x());
00128         const int _y = int(y());
00129         
00130         initPainter(p);
00131         
00132         p.drawLine( _x-8, _y-8, _x-8, _y+8 );
00133         p.drawLine( _x+8, _y-8, _x-8, _y );
00134         p.drawLine( _x+8, _y+8, _x-8, _y );
00135         
00136         QPointArray pa(3);
00137         if ( m_bIsNPN )
00138         {
00139                 pa[0] = QPoint( _x+6, _y+7 );
00140                 pa[1] = QPoint( _x+2, _y+8 );
00141                 pa[2] = QPoint( _x+6, _y+3 );
00142         }
00143         else
00144         {
00145                 pa[0] = QPoint( _x-7, _y+1 );
00146                 pa[1] = QPoint( _x-4, _y+5 );
00147                 pa[2] = QPoint( _x-2, _y );
00148         }
00149         p.setBrush( p.pen().color() );
00150         p.drawPolygon(pa);
00151         
00152         deinitPainter(p);
00153 }

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