File indexing completed on 2024-05-05 05:46:04
0001 /*************************************************************************** 0002 * Copyright (C) 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 "ecjfet.h" 0012 #include "jfet.h" 0013 #include "libraryitem.h" 0014 0015 #include <KLocalizedString> 0016 #include <QPainter> 0017 0018 Item *ECJFET::constructNJFET(ItemDocument *itemDocument, bool newItem, const char *id) 0019 { 0020 return new ECJFET(JFET::nJFET, static_cast<ICNDocument *>(itemDocument), newItem, id ? id : "njfet"); 0021 } 0022 0023 Item *ECJFET::constructPJFET(ItemDocument *itemDocument, bool newItem, const char *id) 0024 { 0025 return new ECJFET(JFET::pJFET, static_cast<ICNDocument *>(itemDocument), newItem, id ? id : "pjfet"); 0026 } 0027 0028 LibraryItem *ECJFET::libraryItemNJFET() 0029 { 0030 return new LibraryItem(QStringList(QString("ec/njfet")), 0031 // i18n("n JFET"), 0032 i18n("n-JFET"), 0033 i18n("Discrete"), 0034 "njfet.png", 0035 LibraryItem::lit_component, 0036 ECJFET::constructNJFET); 0037 } 0038 0039 LibraryItem *ECJFET::libraryItemPJFET() 0040 { 0041 return new LibraryItem(QStringList(QString("ec/pjfet")), 0042 // i18n("p JFET"), 0043 i18n("p-JFET"), 0044 i18n("Discrete"), 0045 "pjfet.png", 0046 LibraryItem::lit_component, 0047 ECJFET::constructPJFET); 0048 } 0049 0050 ECJFET::ECJFET(int JFET_type, ICNDocument *icnDocument, bool newItem, const char *id) 0051 : Component(icnDocument, newItem, id) 0052 { 0053 m_JFET_type = JFET_type; 0054 if (JFET_type == JFET::nJFET) 0055 m_name = i18n("N-Channel JFET"); 0056 else 0057 m_name = i18n("P-Channel JFET"); 0058 0059 setSize(-8, -8, 16, 16); 0060 m_pJFET = createJFET(createPin(8, -16, 90, "D"), createPin(-16, 0, 0, "G"), createPin(8, 16, 270, "S"), JFET_type); 0061 0062 JFETSettings s; // will be created with the default settings 0063 0064 Variant *v = createProperty("V_Th", Variant::Type::Double); 0065 v->setCaption(i18n("Threshold voltage")); 0066 v->setUnit("V"); 0067 v->setMinValue(-1e6); 0068 v->setMaxValue(1e6); 0069 v->setValue(s.V_Th); 0070 v->setAdvanced(true); 0071 0072 v = createProperty("beta", Variant::Type::Double); 0073 v->setCaption(i18n("Transcondutance")); 0074 v->setUnit(QString("A/V") + QChar(0xb2)); 0075 v->setMinValue(1e-12); 0076 v->setMaxValue(1e0); 0077 v->setValue(s.beta); 0078 v->setAdvanced(true); 0079 0080 v = createProperty("I_S", Variant::Type::Double); 0081 v->setCaption(i18n("Saturation current")); 0082 v->setUnit("A"); 0083 v->setMinValue(1e-20); 0084 v->setMaxValue(1e0); 0085 v->setValue(s.I_S); 0086 v->setAdvanced(true); 0087 0088 v = createProperty("N", Variant::Type::Double); 0089 v->setCaption(i18n("PN emission coefficient")); 0090 v->setUnit(""); 0091 v->setMinValue(0.0); 0092 v->setMaxValue(10.0); 0093 v->setValue(s.N); 0094 v->setAdvanced(true); 0095 0096 v = createProperty("N_R", Variant::Type::Double); 0097 v->setCaption(i18n("Isr emission coefficient")); 0098 v->setUnit(""); 0099 v->setMinValue(0.0); 0100 v->setMaxValue(10.0); 0101 v->setValue(s.N_R); 0102 v->setAdvanced(true); 0103 } 0104 0105 ECJFET::~ECJFET() 0106 { 0107 } 0108 0109 void ECJFET::dataChanged() 0110 { 0111 JFETSettings s; 0112 s.V_Th = dataDouble("V_Th"); 0113 s.beta = dataDouble("beta"); 0114 s.I_S = dataDouble("I_S"); 0115 s.N = dataDouble("N"); 0116 s.N_R = dataDouble("N_R"); 0117 0118 m_pJFET->setJFETSettings(s); 0119 } 0120 0121 void ECJFET::drawShape(QPainter &p) 0122 { 0123 const int _x = int(x()); 0124 const int _y = int(y()); 0125 0126 initPainter(p); 0127 0128 // back lines 0129 p.drawLine(_x - 8, _y, _x + 2, _y); 0130 p.drawLine(_x + 2, _y - 8, _x + 2, _y + 8); 0131 0132 // top corner 0133 p.drawLine(_x + 2, _y - 5, _x + 8, _y - 5); 0134 p.drawLine(_x + 8, _y - 5, _x + 8, _y - 8); 0135 0136 // bottom corner 0137 p.drawLine(_x + 2, _y + 5, _x + 8, _y + 5); 0138 p.drawLine(_x + 8, _y + 5, _x + 8, _y + 8); 0139 0140 QPolygon pa(3); 0141 if (m_JFET_type == JFET::nJFET) { 0142 // right pointing arrow 0143 pa[0] = QPoint(1, 0); 0144 pa[1] = QPoint(-4, -3); 0145 pa[2] = QPoint(-4, +3); 0146 } else { 0147 // left pointing arrow 0148 pa[0] = QPoint(-8, 0); 0149 pa[1] = QPoint(-3, -3); 0150 pa[2] = QPoint(-3, +3); 0151 } 0152 pa.translate(_x, _y); 0153 p.setBrush(p.pen().color()); 0154 p.drawPolygon(pa); 0155 0156 deinitPainter(p); 0157 }