1bafe15c4c
If /sim/highlighting/enabled is true, we highlight animated objects under the pointer, and also highlight other objects that are animated by the same or related properties. The intent here is to be able to give a visual indication of what cockpit controls do or what cockpit controls affect particular aircraft objects - for example moving the pointer over the flaps will highlight the flaps and also highlight any controls or rotary indicators in the cockpit that are associated with the flaps. To make this work, we have to discover associations between properties. This is currently done for YASim (e.g. associations between /controls/flight/flaps and /surface-positions/flap-pos-norm) and autopilot filters (e.g. with the 777, digital filters associate /controls/flight/rudder-nul with /fcs/fbw/yaw/rudder-ratio-out). We don't currently gather associations between properties in JSBSim We also detect associations between dialogs, menus and keypresses and properties, which is used to populate /sim/highlighting/current with information about dialogs, menus and keypresses that are associated with the currently highlighted nodes' properties. Details: src/GUI/Highlight.cxx src/GUI/Highlight.hxx src/GUI/CMakeLists.txt src/Main/fg_init.cxx New subsystem called 'highlight', with support for registering and recovering links between menus, dialogs, keypresses and OSG node animations. Provides a function Highlight::highlight_nodes() which highlights related nodes using internal NodeHighlighting class, and populates /sim/highlighting/current with information about related dialogs, menus and keypresses. The NodeHighlighting class works by making nodes use an alternative StateSet which shows up as a distinct material on screen. We remember each highlighted node's original StateSet so that we can un-highlight. We update the material parameters using a listener for /sim/highlighting/material, which allows some control over the appearence of highlighted nodes. src/FDM/flight.cxx src/FDM/flight.hxx Added virtual method FGInterface::property_associations() which returns property associations from the FDM. Default implementation returns empty set. Implemented in YASim, but not (yet) in JSBSim. Uses a simple function pointer at the moment to avoid requring FDMs to use recent C++ features. src/FDM/YASim/FGFDM.cpp src/FDM/YASim/FGFDM.hpp src/FDM/YASim/YASim.cxx src/FDM/YASim/YASim.hxx Gathers information about property associations on startup such as /controls/flight/flaps => /surface-positions/flap-pos-norm, then YASim::property_associations() overrides default implementation to return these associations. src/Autopilot/analogcomponent.cxx src/Autopilot/analogcomponent.hxx src/Autopilot/digitalfilter.cxx src/Autopilot/inputvalue.cxx src/Autopilot/inputvalue.hxx Filters now gather information about their input/output properties and register with Highlight::add_property_property(). For example this makes highlighting work on the 777, where pilot controls affect control surfaces only via filters. src/GUI/new_gui.cxx Scan menus, keypresses and dialogs and register associations with Highlight::add_*(). src/GUI/property_list.cxx src/GUI/property_list.hxx src/GUI/FGPUIDialog.cxx Added <readonly> flag to property-list. If set, we don't show .. or . items and don't respond to mouse/keyboard. Used by fgdata's new Highlighting dialogue. src/Model/acmodel.cxx src/Model/acmodel.hxx Visit the user aircraft's scene graph when it is loaded, gathering information about osg::Node's that are animated by properties, and register these associations with Highlight::add_property_node(). src/Viewer/renderer.cxx When scanning for pick highlights, use Highlight::highlight_nodes() to highlight animated objects under the pointer and related objects.
114 lines
4.3 KiB
C++
114 lines
4.3 KiB
C++
#pragma once
|
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
|
#include <osg/Node>
|
|
|
|
#include <string>
|
|
#include <set>
|
|
|
|
/* Represents a menu item. */
|
|
struct HighlightMenu
|
|
{
|
|
HighlightMenu(int menu, int item) : menu(menu), item(item)
|
|
{}
|
|
int menu; /* Number of menu in the menubar, e.g. 0 is 'File'. */
|
|
int item; /* Number of item in the menu. */
|
|
std::string description() const; /* E.g. "0/6: File/Joystick Configuration". */
|
|
};
|
|
|
|
/* Information about OSG nodes, dialogs etc that are associated with a
|
|
particular property. */
|
|
struct HighlightInfo
|
|
{
|
|
/* OSG Nodes that are animated by the property. */
|
|
std::set<osg::ref_ptr<osg::Node>> nodes;
|
|
|
|
/* Dialogues that modify the property.*/
|
|
std::set<std::string> dialogs;
|
|
|
|
/* Keypresses that modify the property. */
|
|
std::set<std::string> keypresses;
|
|
|
|
/* Menu items that modify the property. */
|
|
std::set<HighlightMenu> menus;
|
|
};
|
|
|
|
struct Highlight : SGSubsystem
|
|
{
|
|
Highlight();
|
|
~Highlight();
|
|
|
|
void bind() override;
|
|
void init() override;
|
|
void reinit() override;
|
|
void shutdown() override;
|
|
void unbind() override;
|
|
void update(double dt) override;
|
|
|
|
static const char* staticSubsystemClassId() { return "reflect"; }
|
|
|
|
/* If specified node is animated, highlights it and other nodes
|
|
that are animated by the same or related properties. Also updates
|
|
/sim/highlighting/current to contain information about associated dialogs,
|
|
menus, and keypresses.
|
|
|
|
Returns the number of properties found. Returns -1 if highlighting is not
|
|
currently enabled. */
|
|
int highlight_nodes(osg::Node* node);
|
|
|
|
/* Returns information about nodes and UI elements that are associated with a
|
|
specific property. */
|
|
const HighlightInfo& find_property_info(const std::string& property);
|
|
|
|
|
|
/* Below are individual functions that return properties that are associated
|
|
with a particular node or UI element. */
|
|
|
|
/* Returns list of properties that are used to animate the specified OSG node.
|
|
*/
|
|
const std::set<std::string>& find_node_properties(osg::Node* node);
|
|
|
|
/* Returns list of properties affected by specified dialog. */
|
|
const std::set<std::string>& find_dialog_properties(const std::string& dialog);
|
|
|
|
/* Returns list of properties affected by specified keypress. */
|
|
const std::set<std::string>& find_keypress_properties(const std::string& keypress);
|
|
|
|
/* Returns list of properties affected by specified menu. */
|
|
const std::set<std::string>& find_menu_properties(const HighlightMenu& menu);
|
|
|
|
/* Returns list of properties that are influenced by the specified property,
|
|
/e.g. if <property> is controls/flight/rudder, the returned set could contain
|
|
/surface-positions/rudder-pos-norm. */
|
|
const std::set<std::string>& find_property_to_properties(const std::string& property);
|
|
|
|
/* Returns list of properties that influence the specified property, e.g.
|
|
if <property> is /surface-positions/rudder-pos-norm, the returned set could
|
|
contain /controls/flight/rudder. */
|
|
const std::set<std::string>& find_property_from_properties(const std::string& property);
|
|
|
|
/* Returns list of menus that open the specified dialog. */
|
|
const std::set<HighlightMenu>& find_menu_from_dialog(const std::string& dialog);
|
|
|
|
|
|
/* Below are functions that are used to set up associations. */
|
|
|
|
/* Should be called if <node> is animated using <property>. */
|
|
void add_property_node(const std::string& property, osg::ref_ptr<osg::Node> node);
|
|
|
|
/* Should be called if <dialog> affects <property>. */
|
|
void add_property_dialog(const std::string& property, const std::string& dialog);
|
|
|
|
/* Should be called if <keypress> affects <property>. */
|
|
void add_property_keypress(const std::string& property, const std::string& keypress);
|
|
|
|
/* Should be called if <menu> affects <property>. */
|
|
void add_property_menu(HighlightMenu menu, const std::string& property);
|
|
|
|
/* Should be called if <menu> opens <dialog>. */
|
|
void add_menu_dialog(HighlightMenu menu, const std::string& dialog);
|
|
|
|
/* Should be called if two properties are associated, for example YASim
|
|
associates /controls/flight/flaps with /surface-positions/flap-pos-norm. */
|
|
void add_property_property(const std::string& property1, const std::string& property2);
|
|
};
|