00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "ecnode.h"
00012 #include "libraryitem.h"
00013 #include "logic.h"
00014 #include "pin.h"
00015 #include "probe.h"
00016 #include "oscilloscope.h"
00017 #include "oscilloscopedata.h"
00018 #include "simulator.h"
00019 #include "voltagesource.h"
00020
00021 #include <klocale.h>
00022 #include <qpainter.h>
00023
00024
00025 Probe::Probe( ICNDocument *icnDocument, bool newItem, const char *id )
00026 : Component( icnDocument, newItem, id )
00027 {
00028 p_probeData = 0;
00029 setSize( -16, -8, 32, 16 );
00030
00031 createProperty( "color", Variant::Type::Color );
00032 property("color")->setCaption( i18n("Color") );
00033 property("color")->setValue( Qt::black );
00034 }
00035
00036
00037 Probe::~ Probe()
00038 {
00039 delete p_probeData;
00040 }
00041
00042
00043 void Probe::dataChanged()
00044 {
00045 m_color = dataColor("color");
00046 if (p_probeData)
00047 p_probeData->setColor(m_color);
00048 setChanged();
00049 }
00050
00051
00052
00053
00054
00055 FloatingProbe::FloatingProbe( ICNDocument *icnDocument, bool newItem, const char *id )
00056 : Probe( icnDocument, newItem, id )
00057 {
00058 p_probeData = m_pFloatingProbeData = static_cast<FloatingProbeData*>(registerProbe(this));
00059 property("color")->setValue( p_probeData->color() );
00060
00061 createProperty( "scaling", Variant::Type::Select );
00062 property("scaling")->setCaption( i18n("Scaling") );
00063 property("scaling")->setAllowed( QStringList::split( ',', "Linear,Logarithmic") );
00064 property("scaling")->setValue("Linear");
00065 property("scaling")->setAdvanced( true );
00066
00067 createProperty( "upper_abs_value", Variant::Type::Double );
00068 property("upper_abs_value")->setCaption( i18n("Upper Absolute Value") );
00069 property("upper_abs_value")->setValue(10.0);
00070 property("upper_abs_value")->setMinValue(0.0);
00071 property("upper_abs_value")->setUnit("V");
00072 property("upper_abs_value")->setAdvanced(true);
00073
00074 createProperty( "lower_abs_value", Variant::Type::Double );
00075 property("lower_abs_value")->setCaption( i18n("Lower Absolute Value") );
00076 property("lower_abs_value")->setValue(0.1);
00077 property("lower_abs_value")->setMinValue(0.0);
00078 property("lower_abs_value")->setUnit("V");
00079 property("lower_abs_value")->setAdvanced(true);
00080 }
00081
00082
00083 FloatingProbe::~FloatingProbe()
00084 {
00085 }
00086
00087
00088 void FloatingProbe::dataChanged()
00089 {
00090 Probe::dataChanged();
00091
00092 if ( dataString("scaling") == "Linear" )
00093 m_pFloatingProbeData->setScaling( FloatingProbeData::Linear );
00094 else
00095 m_pFloatingProbeData->setScaling( FloatingProbeData::Logarithmic );
00096
00097 m_pFloatingProbeData->setUpperAbsValue( dataDouble("upper_abs_value") );
00098 m_pFloatingProbeData->setLowerAbsValue( dataDouble("lower_abs_value") );
00099 }
00100
00101
00102 void FloatingProbe::drawShape( QPainter &p )
00103 {
00104 initPainter(p);
00105
00106 int _x = int(x())-16;
00107 int _y = int(y())-8;
00108
00109 p.drawRect( _x, _y, 32, 16 );
00110
00111 QPointArray bezier(4);
00112
00113 bezier[0] = QPoint( _x+4, _y+10 );
00114 bezier[1] = QPoint( _x+12, _y-6 );
00115 bezier[2] = QPoint( _x+20, _y+24 );
00116 bezier[3] = QPoint( _x+28, _y+4 );
00117
00118 p.setPen( QPen( m_color, 2 ) );
00119 p.drawCubicBezier(bezier);
00120
00121 deinitPainter(p);
00122 }
00123
00124
00125
00126
00127
00128 Item* VoltageProbe::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00129 {
00130 return new VoltageProbe( (ICNDocument*)itemDocument, newItem, id );
00131 }
00132
00133 LibraryItem* VoltageProbe::libraryItem()
00134 {
00135 return new LibraryItem(
00136 "ec/voltageprobe",
00137 i18n("Voltage Probe"),
00138 i18n("Outputs"),
00139 "floatingprobe.png",
00140 LibraryItem::lit_component,
00141 VoltageProbe::construct );
00142 }
00143
00144 VoltageProbe::VoltageProbe( ICNDocument *icnDocument, bool newItem, const char *id )
00145 : FloatingProbe( icnDocument, newItem, id ? id : "voltageprobe" )
00146 {
00147 m_name = i18n("Voltage Probe");
00148 m_desc = i18n("Displays the voltage at the probe point on the oscilloscope.");
00149
00150 init1PinLeft();
00151 init1PinRight();
00152 m_pPin1 = m_pNNode[0]->pin();
00153 m_pPin2 = m_pPNode[0]->pin();
00154 }
00155
00156
00157 VoltageProbe::~VoltageProbe()
00158 {
00159 }
00160
00161
00162 void VoltageProbe::stepNonLogic()
00163 {
00164 m_pFloatingProbeData->addDataPoint(m_pPin1->voltage() - m_pPin2->voltage());
00165 }
00166
00167
00168
00169
00170
00171 Item* CurrentProbe::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00172 {
00173 return new CurrentProbe( (ICNDocument*)itemDocument, newItem, id );
00174 }
00175
00176 LibraryItem* CurrentProbe::libraryItem()
00177 {
00178 return new LibraryItem(
00179 "ec/currentprobe",
00180 i18n("Current Probe"),
00181 i18n("Outputs"),
00182 "floatingprobe.png",
00183 LibraryItem::lit_component,
00184 CurrentProbe::construct );
00185 }
00186
00187 CurrentProbe::CurrentProbe( ICNDocument *icnDocument, bool newItem, const char *id )
00188 : FloatingProbe( icnDocument, newItem, id ? id : "currentprobe" )
00189 {
00190 m_name = i18n("Current Probe");
00191 m_desc = i18n("Displays the current at the probe point on the oscilloscope.");
00192
00193
00194 init1PinLeft(0);
00195 init1PinRight(0);
00196
00197 m_voltageSource = createVoltageSource( m_pNNode[0], m_pPNode[0], 0. );
00198 }
00199
00200
00201 CurrentProbe::~CurrentProbe()
00202 {
00203 }
00204
00205
00206 void CurrentProbe::stepNonLogic()
00207 {
00208 m_pFloatingProbeData->addDataPoint( -m_voltageSource->cbranchCurrent(0) );
00209 }
00210
00211
00212
00213
00214
00215
00216 Item* LogicProbe::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00217 {
00218 return new LogicProbe( (ICNDocument*)itemDocument, newItem, id );
00219 }
00220
00221 LibraryItem* LogicProbe::libraryItem()
00222 {
00223 QStringList ids;
00224 ids << "ec/probe" << "ec/logicprobe";
00225 return new LibraryItem(
00226 ids,
00227 i18n("Logic Probe"),
00228 i18n("Outputs"),
00229 "logicprobe.png",
00230 LibraryItem::lit_component,
00231 LogicProbe::construct );
00232 }
00233
00234 LogicProbe::LogicProbe( ICNDocument *icnDocument, bool newItem, const char *id )
00235 : Probe( icnDocument, newItem, id ? id : "probe" )
00236 {
00237 m_name = i18n("Logic Probe");
00238 m_desc = i18n("Connect this probe the the point in the circuit to measure the logic value. The output will be displayed in the Oscilloscope view.");
00239
00240 init1PinRight();
00241 m_pIn = createLogicIn( m_pPNode[0] );
00242
00243 p_probeData = p_logicProbeData = static_cast<LogicProbeData*>(registerProbe(this));
00244 property("color")->setValue( p_probeData->color() );
00245
00246 m_pSimulator = Simulator::self();
00247 m_pIn->setCallback( this, (CallbackPtr)(&LogicProbe::logicCallback) );
00248 logicCallback(false);
00249 }
00250
00251
00252 LogicProbe::~LogicProbe()
00253 {
00254 }
00255
00256
00257 void LogicProbe::logicCallback( bool value )
00258 {
00259 p_logicProbeData->addDataPoint( LogicDataPoint( value, m_pSimulator->time() ) );
00260 }
00261
00262
00263 void LogicProbe::drawShape( QPainter &p )
00264 {
00265 initPainter(p);
00266
00267 int _x = int(x())-16;
00268 int _y = int(y())-8;
00269
00270 p.drawRect( _x, _y, 32, 16 );
00271
00272 p.setPen( QPen( m_color, 2 ) );
00273
00274 p.drawLine( _x+4, _y+11, _x+6, _y+11 );
00275 p.drawLine( _x+6, _y+11, _x+6, _y+4 );
00276 p.drawLine( _x+6, _y+4, _x+10, _y+4 );
00277 p.drawLine( _x+10, _y+4, _x+10, _y+11 );
00278 p.drawLine( _x+10, _y+11, _x+16, _y+11 );
00279 p.drawLine( _x+16, _y+11, _x+16, _y+4 );
00280 p.drawLine( _x+16, _y+4, _x+23, _y+4 );
00281 p.drawLine( _x+23, _y+4, _x+23, _y+11 );
00282 p.drawLine( _x+23, _y+11, _x+28, _y+11 );
00283
00284
00285
00286
00287 deinitPainter(p);
00288 }
00289
00290
00291