File indexing completed on 2024-05-05 05:46:07
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 METER_H 0012 #define METER_H 0013 0014 #include <component.h> 0015 0016 /** 0017 @author David Saxton 0018 */ 0019 class Meter : public Component 0020 { 0021 public: 0022 Meter(ICNDocument *icnDocument, bool newItem, const char *id); 0023 ~Meter() override; 0024 0025 void stepNonLogic() override; 0026 bool doesStepNonLogic() const override 0027 { 0028 return true; 0029 } 0030 void drawShape(QPainter &p) override; 0031 bool contentChanged() const override; 0032 0033 protected: 0034 QString displayText(); 0035 void dataChanged() override; 0036 /** 0037 * Return the value / current, or whatever the meter is measuring 0038 */ 0039 virtual double meterValue() = 0; 0040 0041 double calcProp(double v) const; 0042 0043 bool b_firstRun; // If true, then update the text dispalyed 0044 bool b_timerStarted; // The timer to change the text is started on change 0045 double m_timeSinceUpdate; 0046 double m_avgValue; 0047 double m_old_value; 0048 double m_minValue; 0049 double m_maxValue; 0050 Text *p_displayText; 0051 QString m_unit; 0052 0053 double m_prevProp; // Used in contentChanged() 0054 }; 0055 0056 /** 0057 @short Measures the frequency at a point in the circuit 0058 @author David Saxton 0059 */ 0060 class FrequencyMeter : public Meter 0061 { 0062 public: 0063 FrequencyMeter(ICNDocument *icnDocument, bool newItem, const char *id = nullptr); 0064 ~FrequencyMeter() override; 0065 0066 static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id); 0067 static LibraryItem *libraryItem(); 0068 0069 protected: 0070 double meterValue() override; 0071 ECNode *m_probeNode; 0072 }; 0073 0074 /** 0075 @short Simple resistor 0076 @author David Saxton 0077 */ 0078 class ECAmmeter : public Meter 0079 { 0080 public: 0081 ECAmmeter(ICNDocument *icnDocument, bool newItem, const char *id = nullptr); 0082 ~ECAmmeter() override; 0083 0084 static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id); 0085 static LibraryItem *libraryItem(); 0086 0087 protected: 0088 double meterValue() override; 0089 0090 private: 0091 VoltageSource *m_voltageSource; 0092 }; 0093 0094 /** 0095 @short Displays voltage across terminals 0096 @author David Saxton 0097 */ 0098 class ECVoltMeter : public Meter 0099 { 0100 public: 0101 ECVoltMeter(ICNDocument *icnDocument, bool newItem, const char *id = nullptr); 0102 ~ECVoltMeter() override; 0103 0104 static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id); 0105 static LibraryItem *libraryItem(); 0106 0107 protected: 0108 double meterValue() override; 0109 }; 0110 0111 #endif