fulladder.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 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 "fulladder.h"
00012 
00013 #include "logic.h"
00014 #include "libraryitem.h"
00015 
00016 #include <kiconloader.h>
00017 #include <klocale.h>
00018 
00019 
00020 Item* FullAdder::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00021 {
00022         return new FullAdder( (ICNDocument*)itemDocument, newItem, id );
00023 }
00024 
00025 LibraryItem* FullAdder::libraryItem()
00026 {
00027         return new LibraryItem(
00028                 QString("ec/adder"),
00029                 i18n("Adder"),
00030                 i18n("Integrated Circuits"),
00031                 "ic1.png",
00032                 LibraryItem::lit_component,
00033                 FullAdder::construct
00034                         );
00035 }
00036 
00037 FullAdder::FullAdder( ICNDocument *icnDocument, bool newItem, const char *id )
00038         : Component( icnDocument, newItem, (id) ? id : "adder" )
00039 {
00040         m_name = i18n("Adder");
00041 //      m_desc = i18n("Insert missing adder help here.");
00042 
00043         ALogic = BLogic = inLogic = 0;
00044         outLogic = SLogic = 0;
00045 
00046         QStringList pins = QStringList::split( ',', "A,B,>,,S,C", true );
00047         initDIPSymbol( pins, 48 );
00048         initDIP(pins);
00049         
00050         ECNode *node;
00051         
00052         node =  ecNodeWithID("S");
00053         SLogic = createLogicOut( node, false );
00054         
00055         node = ecNodeWithID("C");
00056         outLogic = createLogicOut( node, false );
00057         
00058         node = ecNodeWithID("A");
00059         ALogic = createLogicIn(node);
00060         
00061         node = ecNodeWithID("B");
00062         BLogic = createLogicIn(node);
00063         
00064         node = ecNodeWithID(">");
00065         inLogic = createLogicIn(node);
00066         
00067         
00068         ALogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
00069         BLogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
00070         inLogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
00071 }
00072 
00073 FullAdder::~FullAdder()
00074 {
00075 }
00076 
00077 
00078 void FullAdder::inStateChanged( bool /*state*/ )
00079 {
00080         const bool A = ALogic->isHigh();
00081         const bool B = BLogic->isHigh();
00082         const bool in = inLogic->isHigh();
00083         
00084         const bool out = (!A && B && in) || (A && !B && in) || (A && B);
00085         const bool S = (!A && !B && in) || (!A && B && !in) || (A && !B && !in) || (A && B && in);
00086         
00087         SLogic->setHigh(S);
00088         outLogic->setHigh(out);
00089 }
00090 
00091 

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