File indexing completed on 2024-05-05 05:46:04

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef DISCRETELOGIC_H
0012 #define DISCRETELOGIC_H
0013 
0014 #include "component.h"
0015 #include "logic.h"
0016 
0017 class Simulator;
0018 
0019 /**
0020 @short Boolean NOT
0021 @author David Saxton
0022 */
0023 class Inverter : public CallbackClass, public Component
0024 {
0025 public:
0026     Inverter(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0027     ~Inverter() override;
0028 
0029     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0030     static LibraryItem *libraryItem();
0031 
0032 public: // internal interface
0033     void inStateChanged(bool newState);
0034 protected:
0035     void drawShape(QPainter &p) override;
0036 
0037     LogicIn *m_pIn;
0038     LogicOut *m_pOut;
0039 };
0040 
0041 /**
0042 @short Buffer
0043 @author David Saxton
0044 */
0045 class Buffer : public CallbackClass, public Component
0046 {
0047 public:
0048     Buffer(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0049     ~Buffer() override;
0050 
0051     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0052     static LibraryItem *libraryItem();
0053 
0054 public: // internal interface
0055     void inStateChanged(bool newState);
0056 private:
0057     void drawShape(QPainter &p) override;
0058 
0059     LogicIn *m_pIn;
0060     LogicOut *m_pOut;
0061 };
0062 
0063 /**
0064 @short Boolean logic input
0065 @author David Saxton
0066 */
0067 class ECLogicInput : public Component
0068 {
0069 public:
0070     ECLogicInput(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0071     ~ECLogicInput() override;
0072 
0073     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0074     static LibraryItem *libraryItem();
0075 
0076     void buttonStateChanged(const QString &id, bool state) override;
0077 
0078 private:
0079     void dataChanged() override;
0080     void drawShape(QPainter &p) override;
0081 
0082     LogicOut *m_pOut;
0083     bool b_state;
0084 };
0085 
0086 /**
0087 @short Boolean logic output
0088 @author David Saxton
0089 */
0090 class ECLogicOutput : public CallbackClass, public Component
0091 {
0092 public:
0093     ECLogicOutput(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0094     ~ECLogicOutput() override;
0095 
0096     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0097     static LibraryItem *libraryItem();
0098 
0099 public: // internal interface
0100     void inStateChanged(bool newState);
0101 protected:
0102     void drawShape(QPainter &p) override;
0103 
0104     unsigned long long m_lastDrawTime;
0105     unsigned long long m_lastSwitchTime;
0106     unsigned long long m_highTime;
0107     bool m_bLastState;
0108 
0109     double m_lastDrawState;
0110     LogicIn *m_pIn;
0111     Simulator *m_pSimulator;
0112 };
0113 
0114 #endif