summaryrefslogtreecommitdiffstats
path: root/src/electronics/components/fulladder.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 01:49:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 01:49:02 +0000
commit5de3dd4762ca33a0f92e79ffa4fe2ff67069d531 (patch)
treebad482b7afa4cdf47422d60a5dd2c61c7e333b09 /src/electronics/components/fulladder.cpp
downloadktechlab-5de3dd4762ca33a0f92e79ffa4fe2ff67069d531.tar.gz
ktechlab-5de3dd4762ca33a0f92e79ffa4fe2ff67069d531.zip
Added KDE3 version of ktechlab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktechlab@1095338 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/electronics/components/fulladder.cpp')
-rw-r--r--src/electronics/components/fulladder.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/electronics/components/fulladder.cpp b/src/electronics/components/fulladder.cpp
new file mode 100644
index 0000000..ad5e40c
--- /dev/null
+++ b/src/electronics/components/fulladder.cpp
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * Copyright (C) 2004 by David Saxton *
+ * david@bluehaze.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+
+#include "fulladder.h"
+
+#include "logic.h"
+#include "libraryitem.h"
+
+#include <kiconloader.h>
+#include <klocale.h>
+
+
+Item* FullAdder::construct( ItemDocument *itemDocument, bool newItem, const char *id )
+{
+ return new FullAdder( (ICNDocument*)itemDocument, newItem, id );
+}
+
+LibraryItem* FullAdder::libraryItem()
+{
+ return new LibraryItem(
+ QString("ec/adder"),
+ i18n("Adder"),
+ i18n("Integrated Circuits"),
+ "ic1.png",
+ LibraryItem::lit_component,
+ FullAdder::construct
+ );
+}
+
+FullAdder::FullAdder( ICNDocument *icnDocument, bool newItem, const char *id )
+ : Component( icnDocument, newItem, (id) ? id : "adder" )
+{
+ m_name = i18n("Adder");
+// m_desc = i18n("Insert missing adder help here.");
+
+ ALogic = BLogic = inLogic = 0l;
+ outLogic = SLogic = 0l;
+
+ QStringList pins = QStringList::split( ',', "A,B,>,,S,C", true );
+ initDIPSymbol( pins, 48 );
+ initDIP(pins);
+
+ ECNode *node;
+
+ node = ecNodeWithID("S");
+ SLogic = createLogicOut( node, false );
+
+ node = ecNodeWithID("C");
+ outLogic = createLogicOut( node, false );
+
+ node = ecNodeWithID("A");
+ ALogic = createLogicIn(node);
+
+ node = ecNodeWithID("B");
+ BLogic = createLogicIn(node);
+
+ node = ecNodeWithID(">");
+ inLogic = createLogicIn(node);
+
+
+ ALogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
+ BLogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
+ inLogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
+}
+
+FullAdder::~FullAdder()
+{
+}
+
+
+void FullAdder::inStateChanged( bool /*state*/ )
+{
+ const bool A = ALogic->isHigh();
+ const bool B = BLogic->isHigh();
+ const bool in = inLogic->isHigh();
+
+ const bool out = (!A && B && in) || (A && !B && in) || (A && B);
+ const bool S = (!A && !B && in) || (!A && B && !in) || (A && !B && !in) || (A && B && in);
+
+ SLogic->setHigh(S);
+ outLogic->setHigh(out);
+}
+
+