1
/***************************************************************************
2
* Copyright (C) 2016 by santiago González *
3
* santigoro@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, see <http://www.gnu.org/licenses/>. *
18
***************************************************************************/
20
#include "resistordip.h"
21
#include "circuitwidget.h"
22
#include "itemlibrary.h"
23
#include "connector.h"
24
#include "simulator.h"
29
Component* ResistorDip::construct( QObject* parent, QString type, QString id )
30
{ return new ResistorDip( parent, type, id ); }
32
LibraryItem* ResistorDip::libraryItem()
34
return new LibraryItem(
39
ResistorDip::construct);
42
ResistorDip::ResistorDip( QObject* parent, QString type, QString id )
43
: Component( parent, type, id )
55
//m_valLabel->setEnabled( false );
56
m_valLabel->setAcceptedMouseButtons( 0 );
59
setLabelPos(-24,-40, 0);
61
ResistorDip::~ResistorDip(){}
63
void ResistorDip::createResistors( int c )
67
m_resistor.resize( m_size );
68
m_pin.resize( m_size*2 );
70
for( int i=start; i<m_size; i++ )
74
reid.append(QString("-resistor"+QString::number(i)));
75
m_resistor[i] = new eResistor( reid );
77
QPoint pinpos = QPoint(-16,-32+8+i*8 );
78
Pin* pin = new Pin( 180, pinpos, reid+"-ePin"+QString::number(index), 0, this);
79
m_resistor[i]->setEpin( 0, pin );
82
pinpos = QPoint( 16,-32+8+i*8 );
83
pin = new Pin( 0, pinpos, reid+"-ePin"+QString::number(index+1), 0, this);
84
m_resistor[i]->setEpin( 1, pin );
90
void ResistorDip::deleteResistors( int d )
92
if( d > m_size ) d = m_size;
95
for( int i=start*2; i<m_size*2; i++ )
98
if( pin->isConnected() ) pin->connector()->remove();
102
for( int i=start; i<m_size; i++ ) delete m_resistor[i];
104
m_resistor.resize( m_size );
105
m_pin.resize( m_size*2 );
106
//Circuit::self()->update();
109
int ResistorDip::size()
114
void ResistorDip::setSize( int size )
116
if( Simulator::self()->isRunning() ) CircuitWidget::self()->powerCircOff();
118
if( size == 0 ) size = 8;
120
if ( size < m_size ) deleteResistors( m_size-size );
121
else if( size > m_size ) createResistors( size-m_size );
123
m_area = QRect( -10, -30, 20, m_size*8+4 );
126
Circuit::self()->update();
129
double ResistorDip::resist() { return m_value; }
131
void ResistorDip::setResist( double r )
133
bool pauseSim = Simulator::self()->isRunning();
134
if( pauseSim ) Simulator::self()->pauseSim();
136
if( r == 0 ) r = 0.001;
137
Component::setValue( r ); // Takes care about units multiplier
139
setRes( m_value*m_unitMult );
141
if( pauseSim ) Simulator::self()->resumeSim();
144
void ResistorDip::setUnit( QString un )
146
bool pauseSim = Simulator::self()->isRunning();
147
if( pauseSim ) Simulator::self()->pauseSim();
149
Component::setUnit( un );
150
setRes( m_value*m_unitMult );
152
if( pauseSim ) Simulator::self()->resumeSim();
155
void ResistorDip::remove()
157
deleteResistors( m_size );
161
void ResistorDip::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget )
163
Component::paint( p, option, widget );
165
//p->setBrush( QColor( 80, 80, 80) );
167
p->drawRoundRect( QRect( -9, -28, 18, m_size*8 ), 2, 2 );
170
#include "moc_resistordip.cpp"