| 1 | |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | // SPDX-FileCopyrightText: 2009 Torsten Dreyer |
| 4 | |
| 5 | #pragma once |
| 6 | |
| 7 | /* |
| 8 | FGEventSetting |
| 9 | stores one value or property node together with an optional condition |
| 10 | Multiple FGEventSetting can be assigned to one FGInputEvent |
| 11 | */ |
| 12 | class FGEventSetting : public SGReferenced |
| 13 | { |
| 14 | public: |
| 15 | FGEventSetting(SGPropertyNode_ptr base); |
| 16 | // return evaluated condition or true if condition is nullptr |
| 17 | bool Test(); |
| 18 | // return either value of valueNode or value if valueNode is nullptr |
| 19 | double GetValue(); |
| 20 | |
| 21 | protected: |
| 22 | double value{0.0}; |
| 23 | SGPropertyNode_ptr valueNode; |
| 24 | SGSharedPtr<const SGCondition> condition; |
| 25 | }; |
| 26 | |
| 27 | typedef SGSharedPtr<FGEventSetting> FGEventSetting_ptr; |
| 28 | typedef std::vector<FGEventSetting_ptr> setting_list_t; |
| 29 | |
| 30 | class FGReportSetting : public SGReferenced, |
| 31 | public SGPropertyChangeListener |
| 32 | { |
| 33 | public: |
| 34 | enum class Type { |
| 35 | Output, |
| 36 | Feature |
| 37 | }; |
| 38 | |
| 39 | FGReportSetting(SGPropertyNode_ptr base); |
| 40 | unsigned int getReportId() const { return reportId; } |
| 41 | Type getReportType() const |
| 42 | { |
| 43 | return _type; |
| 44 | } |
| 45 | |
| 46 | bool hasError() const |
| 47 | { |
| 48 | return error; |
| 49 | } |
| 50 | |
| 51 | void markAsError() |
| 52 | { |
| 53 | error = true; |
| 54 | } |
| 55 | |
| 56 | std::string getNasalFunctionName() const { return nasalFunction; } |
| 57 | bool Test(); |
| 58 | simgear::UInt8Vector reportBytes(const std::string& moduleName) const; |
| 59 | virtual void valueChanged(SGPropertyNode* node); |
| 60 | |
| 61 | protected: |
| 62 | unsigned int reportId = 0; |
| 63 | Type _type = Type::Output; |
| 64 | std::string nasalFunction; |
| 65 | bool dirty = true; |
| 66 | bool error = false; |
| 67 | SGSourceLocation location; |
| 68 | |
| 69 | // we only dirty when the value of a watched node changes. |
| 70 | // record the value as a string |
| 71 | // FIXME: use a more correct+efficient storage of the previous value, |
| 72 | // either `std::any` or make `SGRaw*` accessible + comparable on SGPropertyNode |
| 73 | std::map<SGPropertyNode_ptr, std::string> watchValueCache; |
| 74 | }; |
| 75 | |
| 76 | typedef SGSharedPtr<FGReportSetting> FGReportSetting_ptr; |
| 77 | typedef std::vector<FGReportSetting_ptr> report_setting_list_t; |