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

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 PROBE_H
0012 #define PROBE_H
0013 
0014 #include <component.h>
0015 #include <logic.h>
0016 
0017 class LogicProbeData;
0018 class ProbeData;
0019 class FloatingProbeData;
0020 class Simulator;
0021 
0022 /**
0023 @author David Saxton
0024 */
0025 class Probe : public Component
0026 {
0027 public:
0028     Probe(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0029     ~Probe() override;
0030 
0031 protected:
0032     void dataChanged() override;
0033 
0034     ProbeData *p_probeData; // As obtained via registering with the oscilloscope
0035     QColor m_color;
0036 };
0037 
0038 /**
0039 @author David Saxton
0040  */
0041 class FloatingProbe : public Probe
0042 {
0043 public:
0044     FloatingProbe(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0045     ~FloatingProbe() override;
0046 
0047     bool doesStepNonLogic() const override
0048     {
0049         return true;
0050     }
0051 
0052 protected:
0053     void dataChanged() override;
0054     void drawShape(QPainter &p) override;
0055 
0056     FloatingProbeData *m_pFloatingProbeData;
0057 };
0058 
0059 /**
0060 @author David Saxton
0061  */
0062 class VoltageProbe : public FloatingProbe
0063 {
0064 public:
0065     VoltageProbe(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0066     ~VoltageProbe() override;
0067 
0068     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0069     static LibraryItem *libraryItem();
0070 
0071     void stepNonLogic() override;
0072 
0073 protected:
0074     Pin *m_pPin1;
0075     Pin *m_pPin2;
0076 };
0077 
0078 /**
0079 @author David Saxton
0080  */
0081 class CurrentProbe : public FloatingProbe
0082 {
0083 public:
0084     CurrentProbe(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0085     ~CurrentProbe() override;
0086 
0087     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0088     static LibraryItem *libraryItem();
0089 
0090     void stepNonLogic() override;
0091 
0092 protected:
0093     VoltageSource *m_voltageSource;
0094 };
0095 
0096 /**
0097 @author David Saxton
0098  */
0099 class LogicProbe : public CallbackClass, public Probe
0100 {
0101 public:
0102     LogicProbe(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0103     ~LogicProbe() override;
0104 
0105     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0106     static LibraryItem *libraryItem();
0107 
0108     void logicCallback(bool value);
0109 
0110 protected:
0111     void drawShape(QPainter &p) override;
0112 
0113     LogicProbeData *p_logicProbeData;
0114     LogicIn *m_pIn;
0115     Simulator *m_pSimulator;
0116 };
0117 
0118 #endif