File indexing completed on 2024-05-05 05:46:04

0001 /***************************************************************************
0002  *   Copyright (C) 2003,2005 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 "ecdiode.h"
0012 #include "diode.h"
0013 #include "ecnode.h"
0014 #include "libraryitem.h"
0015 
0016 #include <KLocalizedString>
0017 #include <QPainter>
0018 
0019 Item *ECDiode::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new ECDiode(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *ECDiode::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("ec/diode")), i18n("Diode"), i18n("Discrete"), "diode.png", LibraryItem::lit_component, ECDiode::construct);
0027 }
0028 
0029 ECDiode::ECDiode(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : Component(icnDocument, newItem, id ? id : "diode")
0031 {
0032     m_name = i18n("Diode");
0033 
0034     setSize(-8, -8, 16, 16);
0035 
0036     init1PinLeft();
0037     init1PinRight();
0038 
0039     m_diode = createDiode(m_pNNode[0], m_pPNode[0]);
0040 
0041     DiodeSettings ds; // it will have the default properties that we use
0042 
0043     createProperty("I_S", Variant::Type::Double);
0044     property("I_S")->setCaption("Saturation Current");
0045     property("I_S")->setUnit("A");
0046     property("I_S")->setMinValue(1e-20);
0047     property("I_S")->setMaxValue(1e-0);
0048     property("I_S")->setValue(ds.I_S);
0049     property("I_S")->setAdvanced(true);
0050 
0051     createProperty("N", Variant::Type::Double);
0052     property("N")->setCaption(i18n("Emission Coefficient"));
0053     property("N")->setMinValue(1e0);
0054     property("N")->setMaxValue(1e1);
0055     property("N")->setValue(ds.N);
0056     property("N")->setAdvanced(true);
0057 
0058     createProperty("V_B", Variant::Type::Double);
0059     property("V_B")->setCaption(i18n("Breakdown Voltage"));
0060     property("V_B")->setUnit("V");
0061     property("V_B")->setMinAbsValue(1e-5);
0062     property("V_B")->setMaxValue(1e10);
0063     property("V_B")->setValue(ds.V_B);
0064     property("V_B")->setAdvanced(true);
0065 
0066     //  createProperty( "R", Variant::Type::Double );
0067     //  property("R")->setCaption( i18n("Series Resistance") );
0068     //  property("R")->setUnit( QChar(0x3a9) );
0069     //  property("R")->setMinValue(1e-5);
0070     //  property("R")->setMaxValue(1e0);
0071     //  property("R")->setValue( ds.R );
0072     //  property("R")->setAdvanced(true);
0073 }
0074 
0075 ECDiode::~ECDiode()
0076 {
0077 }
0078 
0079 void ECDiode::dataChanged()
0080 {
0081     DiodeSettings ds;
0082 
0083     ds.I_S = dataDouble("I_S");
0084     ds.V_B = dataDouble("V_B");
0085     ds.N = dataDouble("N");
0086     //  ds.R = dataDouble("R");
0087 
0088     m_diode->setDiodeSettings(ds);
0089 }
0090 
0091 void ECDiode::drawShape(QPainter &p)
0092 {
0093     initPainter(p);
0094 
0095     int _x = int(x());
0096     int _y = int(y());
0097 
0098     QPolygon pa(3);
0099     pa[0] = QPoint(8, 0);
0100     pa[1] = QPoint(-8, -8);
0101     pa[2] = QPoint(-8, 8);
0102     pa.translate(_x, _y);
0103     p.drawPolygon(pa);
0104     p.drawPolyline(pa);
0105 
0106     p.drawLine(_x + 8, _y - 8, _x + 8, _y + 8);
0107 
0108     deinitPainter(p);
0109 }