ecvoltagesignal.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2004 by David Saxton                               *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "ecnode.h"
00012 #include "ecvoltagesignal.h"
00013 #include "libraryitem.h"
00014 #include "pin.h"
00015 #include "simulator.h"
00016 #include "voltagesignal.h"
00017 
00018 #include <klocale.h>
00019 #include <qpainter.h>
00020 
00021 Item* ECVoltageSignal::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00022 {
00023         return new ECVoltageSignal( (ICNDocument*)itemDocument, newItem, id );
00024 }
00025 
00026 LibraryItem* ECVoltageSignal::libraryItem()
00027 {
00028         return new LibraryItem(
00029                 QString("ec/voltage_signal"),
00030                 i18n("Voltage Signal"),
00031                 i18n("Sources"),
00032                 "voltagesignal.png",
00033                 LibraryItem::lit_component,
00034                 ECVoltageSignal::construct );
00035 }
00036 
00037 ECVoltageSignal::ECVoltageSignal( ICNDocument *icnDocument, bool newItem, const char *id )
00038         : Component( icnDocument, newItem, (id) ? id : "voltage_signal" )
00039 {
00040         m_name = i18n("Voltage Signal");
00041         m_desc = i18n("Provides a variety of voltage signals.");
00042         setSize( -8, -8, 16, 16 );
00043         
00044         init1PinLeft();
00045         init1PinRight();
00046         
00047         m_pNNode[0]->pin()->setGroundType( Pin::gt_medium );
00048         m_voltageSignal = createVoltageSignal( m_pNNode[0], m_pPNode[0], 0. );
00049         m_voltageSignal->setStep( 1./LINEAR_UPDATE_RATE, ElementSignal::st_sinusoidal, 50. );
00050 
00051 // TODO: NEEDS PHASE ANGLE PARAMETER =))))
00052 // Ideally phase angle is entered in units of PI so 180 degrees is simply "1.0"
00053 
00054         createProperty( "frequency", Variant::Type::Double );
00055         property("frequency")->setCaption( i18n("Frequency") );
00056         property("frequency")->setUnit("Hz");
00057         property("frequency")->setMinValue(1e-9);
00058         property("frequency")->setMaxValue(1e3);
00059         property("frequency")->setValue(50.0);
00060         
00061         createProperty( "voltage", Variant::Type::Double );
00062         property("voltage")->setCaption( i18n("Voltage Range") );
00063         property("voltage")->setUnit("V");      
00064         property("voltage")->setMinValue(-1e12);
00065         property("voltage")->setMaxValue(1e12);
00066         property("voltage")->setValue(5.0);
00067         
00068         addDisplayText( "~", QRect( -8, -8, 16, 16 ), "~" );
00069         addDisplayText( "voltage", QRect( -16, -24, 32, 16 ), "" );
00070 }
00071 
00072 
00073 ECVoltageSignal::~ECVoltageSignal()
00074 {
00075 }
00076 
00077 void ECVoltageSignal::dataChanged()
00078 {
00079         const double voltage = dataDouble("voltage");
00080         const double frequency = dataDouble("frequency");
00081         
00082         QString display = QString::number( voltage / getMultiplier(voltage), 'g', 3 ) + getNumberMag(voltage) + "V";
00083         setDisplayText( "voltage", display );
00084         
00085         m_voltageSignal->setStep( 1./LINEAR_UPDATE_RATE, ElementSignal::st_sinusoidal, frequency );
00086         m_voltageSignal->setVoltage(voltage);
00087 }
00088 
00089 
00090 void ECVoltageSignal::drawShape( QPainter &p )
00091 {
00092         initPainter(p);
00093         p.drawEllipse( (int)x()-8, (int)y()-8, width(), height() );
00094         deinitPainter(p);
00095 }
00096 

Generated on Tue May 8 17:05:29 2007 for KTechLab by  doxygen 1.5.1