00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "dependentsource.h"
00012 #include "ecnode.h"
00013 #include "libraryitem.h"
00014 #include "pin.h"
00015
00016 #include "cccs.h"
00017 #include "ccvs.h"
00018 #include "vccs.h"
00019 #include "vcvs.h"
00020
00021 #include <klocale.h>
00022 #include <qpainter.h>
00023
00024
00025 DependentSource::DependentSource( ICNDocument *icnDocument, bool newItem, const char *id )
00026 : Component( icnDocument, newItem, id )
00027 {
00028 setSize( -16, -16, 32, 32 );
00029
00030 init2PinLeft();
00031 init2PinRight();
00032
00033 createProperty( "gain", Variant::Type::Double );
00034 property("gain")->setCaption( i18n("Gain") );
00035 property("gain")->setValue(1.0);
00036
00037 addDisplayText( "gain", QRect( -16, -32, 32, 16 ), "" );
00038 }
00039
00040
00041 DependentSource::~DependentSource()
00042 {
00043 }
00044
00045
00046 void DependentSource::drawOutline( QPainter & p )
00047 {
00048 const int _x = (int)x()-16;
00049 const int _y = (int)y()-32;
00050
00051
00052 p.drawRect( _x, _y+19, width(), 11 );
00053
00054 p.save();
00055 bool canSetCol = (p.pen().color() != Qt::color0) && (p.pen().color() != Qt::color1);
00056
00057
00058 if (canSetCol)
00059 p.setPen( m_pNNode[1]->isSelected() ? m_selectedCol : Qt::black );
00060 p.drawLine( _x, _y+40, _x+8, _y+40 );
00061
00062 if (canSetCol)
00063 p.setPen( m_pPNode[1]->isSelected() ? m_selectedCol : Qt::black );
00064 p.drawLine( _x+width(), _y+40, _x+24, _y+40 );
00065
00066 p.restore();
00067
00068
00069 QPointArray pa4(4);
00070 pa4[0] = QPoint( _x+6, _y+40 );
00071 pa4[1] = QPoint( _x+16, _y+32 );
00072 pa4[2] = QPoint( _x+26, _y+40 );
00073 pa4[3] = QPoint( _x+16, _y+48 );
00074 p.drawPolygon(pa4);
00075 }
00076
00077
00078 void DependentSource::drawTopArrow( QPainter & p )
00079 {
00080 const int _x = (int)x()-16;
00081 const int _y = (int)y()-32;
00082
00083 if ( p.pen().color() == m_selectedCol )
00084 p.setPen(Qt::black);
00085
00086 if ( p.brush().color() == m_brushCol )
00087 p.setBrush(Qt::black);
00088
00089 p.drawLine( _x+8, _y+24, _x+24, _y+24 );
00090
00091 QPointArray pa3(3);
00092 pa3[0] = QPoint( _x+24, _y+24 );
00093 pa3[1] = QPoint( _x+19, _y+21 );
00094 pa3[2] = QPoint( _x+19, _y+27 );
00095 p.drawPolygon(pa3);
00096 }
00097
00098
00099 void DependentSource::drawBottomArrow( QPainter & p )
00100 {
00101 const int _x = (int)x()-16;
00102 const int _y = (int)y()-32;
00103
00104 if ( p.pen().color() == m_selectedCol )
00105 p.setPen(Qt::black);
00106
00107 if ( p.brush().color() == m_brushCol )
00108 p.setBrush(Qt::black);
00109
00110 p.drawLine( _x+11, _y+40, _x+21, _y+40 );
00111
00112 QPointArray pa3(3);
00113 pa3[0] = QPoint( _x+21, _y+40 );
00114 pa3[1] = QPoint( _x+16, _y+37 );
00115 pa3[2] = QPoint( _x+16, _y+43 );
00116 p.drawPolygon(pa3);
00117 }
00118
00119
00120
00121
00122 Item* ECCCCS::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00123 {
00124 return new ECCCCS( (ICNDocument*)itemDocument, newItem, id );
00125 }
00126
00127 LibraryItem* ECCCCS::libraryItem()
00128 {
00129 return new LibraryItem(
00130 QString("ec/cccs"),
00131 i18n("CCCS"),
00132 i18n("Sources"),
00133 "cccs.png",
00134 LibraryItem::lit_component,
00135 ECCCCS::construct );
00136 }
00137
00138 ECCCCS::ECCCCS( ICNDocument *icnDocument, bool newItem, const char *id )
00139 : DependentSource( icnDocument, newItem, id ? id : "cccs" )
00140 {
00141 m_name = i18n("Current Controlled Currrent Source");
00142 m_cccs = createCCCS( m_pNNode[0], m_pPNode[0], m_pNNode[1], m_pPNode[1], 1. );
00143 m_pNNode[1]->pin()->setGroundType( Pin::gt_medium );
00144 }
00145
00146 ECCCCS::~ECCCCS()
00147 {
00148 }
00149
00150 void ECCCCS::dataChanged()
00151 {
00152 double gain = dataDouble("gain");
00153
00154 QString display = QString::number( gain / getMultiplier(gain), 'g', 3 ) + getNumberMag(gain) + QChar(' ');
00155 setDisplayText( "gain", display );
00156
00157 m_cccs->setGain(gain);
00158 }
00159
00160 void ECCCCS::drawShape( QPainter &p )
00161 {
00162 initPainter(p);
00163 drawOutline(p);
00164 drawTopArrow(p);
00165 drawBottomArrow(p);
00166 deinitPainter(p);
00167 }
00168
00169
00170
00171
00172 Item* ECCCVS::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00173 {
00174 return new ECCCVS( (ICNDocument*)itemDocument, newItem, id );
00175 }
00176
00177 LibraryItem* ECCCVS::libraryItem()
00178 {
00179 return new LibraryItem(
00180 QString("ec/ccvs"),
00181 i18n("CCVS"),
00182 i18n("Sources"),
00183 "ccvs.png",
00184 LibraryItem::lit_component,
00185 ECCCVS::construct );
00186 }
00187
00188 ECCCVS::ECCCVS( ICNDocument *icnDocument, bool newItem, const char *id )
00189 : DependentSource( icnDocument, newItem, id ? id : "ccvs" )
00190 {
00191 m_name = i18n("Current Controlled Voltage Source");
00192 m_ccvs = createCCVS( m_pNNode[0], m_pPNode[0], m_pNNode[1], m_pPNode[1], 1. );
00193 m_pNNode[1]->pin()->setGroundType( Pin::gt_medium );
00194 }
00195
00196 ECCCVS::~ECCCVS()
00197 {
00198 }
00199
00200 void ECCCVS::dataChanged()
00201 {
00202 double gain = dataDouble("gain");
00203
00204 QString display = QString::number( gain / getMultiplier(gain), 'g', 3 ) + getNumberMag(gain) + QChar(' ');
00205 setDisplayText( "gain", display );
00206
00207 m_ccvs->setGain(gain);
00208 }
00209
00210 void ECCCVS::drawShape( QPainter &p )
00211 {
00212 initPainter(p);
00213 drawOutline(p);
00214 drawTopArrow(p);
00215 deinitPainter(p);
00216 }
00217
00218
00219
00220
00221 Item* ECVCCS::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00222 {
00223 return new ECVCCS( (ICNDocument*)itemDocument, newItem, id );
00224 }
00225
00226 LibraryItem* ECVCCS::libraryItem()
00227 {
00228 return new LibraryItem(
00229 QString("ec/vccs"),
00230 i18n("VCCS"),
00231 i18n("Sources"),
00232 "vccs.png",
00233 LibraryItem::lit_component,
00234 ECVCCS::construct );
00235 }
00236
00237 ECVCCS::ECVCCS( ICNDocument *icnDocument, bool newItem, const char *id )
00238 : DependentSource( icnDocument, newItem, id ? id : "vccs" )
00239 {
00240 m_name = i18n("Voltage Controlled Current Source");
00241 m_vccs = createVCCS( m_pNNode[0], m_pPNode[0], m_pNNode[1], m_pPNode[1], 1. );
00242 m_pNNode[1]->pin()->setGroundType( Pin::gt_medium );
00243 }
00244
00245 ECVCCS::~ECVCCS()
00246 {
00247 }
00248
00249 void ECVCCS::dataChanged()
00250 {
00251 double gain = dataDouble("gain");
00252
00253 QString display = QString::number( gain / getMultiplier(gain), 'g', 3 ) + getNumberMag(gain) + QChar(' ');
00254 setDisplayText( "gain", display );
00255
00256 m_vccs->setGain(gain);
00257 }
00258
00259 void ECVCCS::drawShape( QPainter &p )
00260 {
00261 initPainter(p);
00262 drawOutline(p);
00263 drawBottomArrow(p);
00264 deinitPainter(p);
00265 }
00266
00267
00268
00269
00270 Item* ECVCVS::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00271 {
00272 return new ECVCVS( (ICNDocument*)itemDocument, newItem, id );
00273 }
00274
00275 LibraryItem* ECVCVS::libraryItem()
00276 {
00277 return new LibraryItem(
00278 QString("ec/vcvs"),
00279 i18n("VCVS"),
00280 i18n("Sources"),
00281 "vcvs.png",
00282 LibraryItem::lit_component,
00283 ECVCVS::construct );
00284 }
00285
00286 ECVCVS::ECVCVS( ICNDocument *icnDocument, bool newItem, const char *id )
00287 : DependentSource( icnDocument, newItem, id ? id : "vcvs" )
00288 {
00289 m_name = i18n("Voltage Controlled Voltage Source");
00290 m_vcvs = createVCVS( m_pNNode[0], m_pPNode[0], m_pNNode[1], m_pPNode[1], 1. );
00291 m_pNNode[1]->pin()->setGroundType( Pin::gt_medium );
00292 }
00293
00294 ECVCVS::~ECVCVS()
00295 {
00296 }
00297
00298 void ECVCVS::dataChanged()
00299 {
00300 double gain = dataDouble("gain");
00301
00302 QString display = QString::number( gain / getMultiplier(gain), 'g', 3 ) + getNumberMag(gain) + QChar(' ');
00303 setDisplayText( "gain", display );
00304
00305 m_vcvs->setGain(gain);
00306 }
00307
00308 void ECVCVS::drawShape( QPainter &p )
00309 {
00310 initPainter(p);
00311 drawOutline(p);
00312 deinitPainter(p);
00313 }
00314