2#include "simgear/misc/strutils.hxx"
9#include <simgear/scene/util/StateAttributeFactory.hxx>
11#include <osg/Material>
12#include <osg/PolygonMode>
13#include <osg/PolygonOffset>
14#include <osg/Texture2D>
27 std::string
name = node->getStringValue(
"label",
"");
29 name = node->getStringValue(
"name");
30 return globals->get_props()->getStringValue(
"sim/intl/locale/strings/menu/" +
name,
name.c_str());
35 std::string ret = std::to_string(this->
menu) +
"/" + std::to_string(this->
item) +
": ";
36 SGPropertyNode* menubar =
globals->get_props()->getNode(
"sim/menubar/default");
39 SGPropertyNode*
menu = menubar->getChild(
"menu", this->menu);
42 SGPropertyNode*
item =
menu->getChild(
"item", this->item);
102 m_node(
globals->get_props()->getNode(
"sim/highlighting/material", true ))
109 osg::Texture2D* white = simgear::StateAttributeFactory::instance()->getWhiteTexture();
113 osg::StateAttribute::ON
114 | osg::StateAttribute::OVERRIDE
115 | osg::StateAttribute::PROTECTED
118 osg::PolygonOffset* polygonOffset =
new osg::PolygonOffset;
119 polygonOffset->setFactor(-1);
120 polygonOffset->setUnits(-1);
121 m_state_set->setAttribute(polygonOffset, osg::StateAttribute::OVERRIDE);
123 GL_POLYGON_OFFSET_LINE,
124 osg::StateAttribute::ON
125 | osg::StateAttribute::OVERRIDE
128 osg::PolygonMode* polygonMode =
new osg::PolygonMode;
129 polygonMode->setMode(
130 osg::PolygonMode::FRONT_AND_BACK,
131 osg::PolygonMode::FILL
133 m_state_set->setAttribute(polygonMode, osg::StateAttribute::OVERRIDE);
135 osg::Material* material =
new osg::Material;
136 material->setColorMode(osg::Material::OFF);
137 material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(0, 0, 0, 0));
138 material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(0, 0, 0, 0));
139 material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(0, 0, 0, 0));
140 material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0, 0, 0, 0));
143 osg::StateAttribute::OVERRIDE
144 | osg::StateAttribute::PROTECTED
149 osg::Uniform* colorModeUniform =
new osg::Uniform(osg::Uniform::INT,
"colorMode");
150 colorModeUniform->set(0);
151 colorModeUniform->setDataVariance(osg::Object::STATIC);
154 osg::StateAttribute::OVERRIDE
155 | osg::StateAttribute::ON
170 m_node->addChangeListener(
this,
true );
174 double red,
double green,
double blue,
double alpha)
185 SGPropertyNode*
property = root->getNode(path,
false );
186 if (!property) root->setDoubleValue(path, default_value);
192 osg::StateAttribute* material0 =
m_state_set->getAttribute(osg::StateAttribute::MATERIAL);
193 osg::Material* material =
dynamic_cast<osg::Material*
>(material0);
201 red =
m_node->getDoubleValue(
"ambient/red");
202 green =
m_node->getDoubleValue(
"ambient/green");
203 blue =
m_node->getDoubleValue(
"ambient/blue");
204 alpha =
m_node->getDoubleValue(
"ambient/alpha");
205 material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(red, green, blue, alpha));
207 red =
m_node->getDoubleValue(
"diffuse/red");
208 green =
m_node->getDoubleValue(
"diffuse/green");
209 blue =
m_node->getDoubleValue(
"diffuse/blue");
210 alpha =
m_node->getDoubleValue(
"diffuse/alpha");
211 material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(red, green, blue, alpha));
213 red =
m_node->getDoubleValue(
"emission/red");
214 green =
m_node->getDoubleValue(
"emission/green");
215 blue =
m_node->getDoubleValue(
"emission/blue");
216 alpha =
m_node->getDoubleValue(
"emission/alpha");
217 material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(red, green, blue, alpha));
219 red =
m_node->getDoubleValue(
"ambient/red");
220 green =
m_node->getDoubleValue(
"ambient/green");
221 blue =
m_node->getDoubleValue(
"ambient/blue");
222 alpha =
m_node->getDoubleValue(
"ambient/alpha");
223 material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(red, green, blue, alpha));
225 red =
m_node->getDoubleValue(
"specular/red");
226 green =
m_node->getDoubleValue(
"specular/green");
227 blue =
m_node->getDoubleValue(
"specular/blue");
228 alpha =
m_node->getDoubleValue(
"specular/alpha");
229 material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(red, green, blue, alpha));
236 osg::Group* group = node->asGroup();
237 if (!group)
return 0;
247 group->setStateSet(it_group_stateset->second);
270 m_node->removeChangeListener(
this);
330 SG_LOG(SG_GENERAL, SG_DEBUG,
"Getting property associations from FDM");
335 FGInterface* fginterface = fdmshell->getInterface();
337 fginterface->property_associations(
338 [highlight](
const std::string& from,
const std::string& to)
340 SG_LOG(SG_GENERAL, SG_DEBUG,
"fdm property association: " << from <<
" => " << to);
341 highlight->addPropertyProperty(from, to);
358 globals->get_props()->setStringValue(
"sim/highlighting/current",
"");
359 globals->get_props()->setStringValue(
"sim/highlighting/current-ptr",
"/sim/highlighting/current");
380 return simgear::strutils::replace(property,
"[0]",
"");
389 SG_LOG(SG_GENERAL, SG_DEBUG,
"Sizes of internal maps:"
418 std::set<NameValue> items;
438 items.insert(
NameValue(
"property", property1));
443 items.insert(
NameValue(
"property", property2));
449 items.insert(
NameValue(
"property", property3));
455 items.insert(
NameValue(
"property", property4));
462 for (
auto& nv: items)
464 const std::string&
property = nv.value;
465 SG_LOG(SG_GENERAL, SG_DEBUG,
"Looking at property=" << property);
467 for (
auto& node: info.
nodes)
471 for (
auto& dialog: info.
dialogs)
473 items.insert(
NameValue(
"dialog", dialog));
476 items.insert(
NameValue(
"menu", menu.description()));
481 items.insert(
NameValue(
"keypress", keypress));
483 for (
auto& menu: info.
menus)
485 items.insert(
NameValue(
"menu", menu.description()));
506 std::set<NameValue> properties_new;
507 std::set<NameValue> properties_removed;
509 items.begin(), items.end(),
511 std::inserter(properties_new, properties_new.begin())
515 items.begin(), items.end(),
516 std::inserter(properties_removed, properties_removed.begin())
518 SGPropertyNode* current =
globals->get_props()->getNode(
"sim/highlighting/current",
true );
519 for (
int pos=0; pos<current->nChildren(); ++pos)
521 SGPropertyNode* child = current->getChild(pos);
522 auto nv =
NameValue(child->getNameString(), child->getStringValue());
523 if (properties_removed.find(nv) != properties_removed.end())
525 current->removeChild(pos);
529 for (
auto& name_value: properties_new)
531 current->addChild(name_value.name)->setStringValue(name_value.value);
551 std::string property2 =
canonical(property);
587 std::string property2 =
canonical(property);
595 std::string property2 =
canonical(property);
613 std::string property2 =
canonical(property);
616 SG_LOG(SG_GENERAL, SG_DEBUG,
"node=" << node.get() <<
" property=" << property2);
621 std::string property2 =
canonical(property);
624 SG_LOG(SG_GENERAL, SG_DEBUG,
"dialog=" << dialog <<
" property=" << property2);
629 std::string property2 =
canonical(property);
632 SG_LOG(SG_GENERAL, SG_DEBUG,
"keypress=" << keypress <<
" property=" << property2);
637 std::string property2 =
canonical(property);
640 SG_LOG(SG_GENERAL, SG_DEBUG,
"menu=(" << menu.
menu <<
" " << menu.
item <<
") property=" << property2);
647 SG_LOG(SG_GENERAL, SG_DEBUG,
"menu (" << menu.
menu <<
" " << menu.
item <<
") dialog=" << dialog);
654 if (from == to)
return;
674 SGSubsystemMgr::INIT);
static std::string canonical(const std::string property)
static bool s_output_stats
static SGPropertyNode_ptr s_prop_enabled
static std::unique_ptr< struct NodeHighlighting > s_node_highlighting
static bool operator<(const HighlightMenu &a, const HighlightMenu &b)
static std::map< std::string, std::set< std::string > > s_property_to_properties
static std::map< HighlightMenu, std::string > s_menu_to_dialog
static std::map< std::string, std::set< HighlightMenu > > s_dialog_to_menus
static std::map< std::string, std::set< std::string > > s_property_from_properties
static std::string s_getMenuName(SGPropertyNode *node)
static std::map< std::string, std::set< std::string > > s_dialog_to_properties
static std::map< osg::ref_ptr< osg::Node >, std::set< std::string > > s_node_to_properties
static const std::set< std::string > set_string_empty
static std::map< std::string, HighlightInfo > s_property_to_info
static std::set< NameValue > s_property_tree_items
SGSubsystemMgr::Registrant< Highlight > registrantHighlight(SGSubsystemMgr::INIT)
static const std::set< HighlightMenu > set_menu_empty
static std::map< HighlightMenu, std::set< std::string > > s_menu_to_properties
static std::map< std::string, std::set< std::string > > s_keypress_to_properties
std::unique_ptr< struct FdmInitialisedListener > s_fdm_initialised_listener
static const HighlightInfo info_empty
Wrap an FDM implementation in a subsystem with standard semantics Notably, deal with the various case...
~FdmInitialisedListener()
void valueChanged(SGPropertyNode *node) override
SGPropertyNode_ptr m_fdm_initialised
std::set< std::string > keypresses
std::set< HighlightMenu > menus
std::set< std::string > dialogs
std::set< osg::ref_ptr< osg::Node > > nodes
void addPropertyProperty(const std::string &property1, const std::string &property2)
const std::set< std::string > & findDialogProperties(const std::string &dialog)
void addPropertyDialog(const std::string &property, const std::string &dialog)
int highlightNodes(osg::Node *node)
void addPropertyMenu(HighlightMenu menu, const std::string &property)
void addMenuDialog(HighlightMenu menu, const std::string &dialog)
const std::set< std::string > & findNodeProperties(osg::Node *node)
const HighlightInfo & findPropertyInfo(const std::string &property)
const std::set< HighlightMenu > & findMenuFromDialog(const std::string &dialog)
const std::set< std::string > & findKeypressProperties(const std::string &keypress)
const std::set< std::string > & findMenuProperties(const HighlightMenu &menu)
const std::set< std::string > & findPropertyFromProperties(const std::string &property)
const std::set< std::string > & findPropertyToProperties(const std::string &property)
void update(double dt) override
void addPropertyNode(const std::string &property, osg::ref_ptr< osg::Node > node)
void addPropertyKeypress(const std::string &property, const std::string &keypress)
bool operator<(const NameValue &rhs) const
NameValue(const std::string &name, const std::string &value)
std::map< osg::ref_ptr< osg::Group >, osg::ref_ptr< osg::StateSet > > m_group_to_old_state_set
int highlight(osg::Node *node, bool highlight)
static void setRgbaDefault(SGPropertyNode *root, const std::string &path, double red, double green, double blue, double alpha)
virtual void valueChanged(SGPropertyNode *node)
static void setPropertyDefault(SGPropertyNode *root, const std::string &path, double default_value)
osg::ref_ptr< osg::StateSet > m_state_set
SGPropertyNode_ptr m_node