| 1 | #pragma once |
| 2 | |
| 3 | #include <simgear/structure/subsystem_mgr.hxx> |
| 4 | #include <osg/Node> |
| 5 | |
| 6 | #include <string> |
| 7 | #include <set> |
| 8 | |
| 9 | /* Represents a menu item. */ |
| 10 | struct HighlightMenu |
| 11 | { |
| 12 | HighlightMenu(int menu, int item) : menu(menu), item(item) |
| 13 | {} |
| 14 | int menu; /* Number of menu in the menubar, e.g. 0 is 'File'. */ |
| 15 | int item; /* Number of item in the menu. */ |
| 16 | std::string description() const; /* E.g. "0/6: File/Joystick Configuration". */ |
| 17 | }; |
| 18 | |
| 19 | /* Information about OSG nodes, dialogs etc that are associated with a |
| 20 | particular property. */ |
| 21 | struct HighlightInfo |
| 22 | { |
| 23 | /* OSG Nodes that are animated by the property. */ |
| 24 | std::set<osg::ref_ptr<osg::Node>> nodes; |
| 25 | |
| 26 | /* Dialogues that modify the property.*/ |
| 27 | std::set<std::string> dialogs; |
| 28 | |
| 29 | /* Keypresses that modify the property. */ |
| 30 | std::set<std::string> keypresses; |
| 31 | |
| 32 | /* Menu items that modify the property. */ |
| 33 | std::set<HighlightMenu> menus; |
| 34 | }; |
| 35 | |
| 36 | struct Highlight : SGSubsystem |
| 37 | { |
| 38 | Highlight(); |
| 39 | ~Highlight(); |
| 40 | |
| 41 | void bind() override; |
| 42 | void init() override; |
| 43 | void reinit() override; |
| 44 | void shutdown() override; |
| 45 | void unbind() override; |
| 46 | void update(double dt) override; |
| 47 | |
| 48 | static const char* staticSubsystemClassId() { return "reflect"; } |
| 49 | |
| 50 | /* If specified node is animated, highlights it and other nodes |
| 51 | that are animated by the same or related properties. Also updates |
| 52 | /sim/highlighting/current to contain information about associated dialogs, |
| 53 | menus, and keypresses. |
| 54 | |
| 55 | Returns the number of properties found. Returns -1 if highlighting is not |
| 56 | currently enabled. */ |
| 57 | int highlightNodes(osg::Node* node); |
| 58 | |
| 59 | /* Returns information about nodes and UI elements that are associated with a |
| 60 | specific property. */ |
| 61 | const HighlightInfo& findPropertyInfo(const std::string& property); |
| 62 | |
| 63 | |
| 64 | /* Below are individual functions that return properties that are associated |
| 65 | with a particular node or UI element. */ |
| 66 | |
| 67 | /* Returns list of properties that are used to animate the specified OSG node. |
| 68 | */ |
| 69 | const std::set<std::string>& findNodeProperties(osg::Node* node); |
| 70 | |
| 71 | /* Returns list of properties affected by specified dialog. */ |
| 72 | const std::set<std::string>& findDialogProperties(const std::string& dialog); |
| 73 | |
| 74 | /* Returns list of properties affected by specified keypress. */ |
| 75 | const std::set<std::string>& findKeypressProperties(const std::string& keypress); |
| 76 | |
| 77 | /* Returns list of properties affected by specified menu. */ |
| 78 | const std::set<std::string>& findMenuProperties(const HighlightMenu& menu); |
| 79 | |
| 80 | /* Returns list of properties that are influenced by the specified property, |
| 81 | /e.g. if <property> is controls/flight/rudder, the returned set could contain |
| 82 | /surface-positions/rudder-pos-norm. */ |
| 83 | const std::set<std::string>& findPropertyToProperties(const std::string& property); |
| 84 | |
| 85 | /* Returns list of properties that influence the specified property, e.g. |
| 86 | if <property> is /surface-positions/rudder-pos-norm, the returned set could |
| 87 | contain /controls/flight/rudder. */ |
| 88 | const std::set<std::string>& findPropertyFromProperties(const std::string& property); |
| 89 | |
| 90 | /* Returns list of menus that open the specified dialog. */ |
| 91 | const std::set<HighlightMenu>& findMenuFromDialog(const std::string& dialog); |
| 92 | |
| 93 | |
| 94 | /* Below are functions that are used to set up associations. */ |
| 95 | |
| 96 | /* Should be called if <node> is animated using <property>. */ |
| 97 | void addPropertyNode(const std::string& property, osg::ref_ptr<osg::Node> node); |
| 98 | |
| 99 | /* Should be called if <dialog> affects <property>. */ |
| 100 | void addPropertyDialog(const std::string& property, const std::string& dialog); |
| 101 | |
| 102 | /* Should be called if <keypress> affects <property>. */ |
| 103 | void addPropertyKeypress(const std::string& property, const std::string& keypress); |
| 104 | |
| 105 | /* Should be called if <menu> affects <property>. */ |
| 106 | void addPropertyMenu(HighlightMenu menu, const std::string& property); |
| 107 | |
| 108 | /* Should be called if <menu> opens <dialog>. */ |
| 109 | void addMenuDialog(HighlightMenu menu, const std::string& dialog); |
| 110 | |
| 111 | /* Should be called if two properties are associated, for example YASim |
| 112 | associates /controls/flight/flaps with /surface-positions/flap-pos-norm. */ |
| 113 | void addPropertyProperty(const std::string& property1, const std::string& property2); |
| 114 | }; |