- if (node->hasChild("width")) {
- float w = node->getFloatValue("width");
- float h = node->getFloatValue("height", w);
- xy0.x() = -w * 0.5;
- xy0.y() = -h * 0.5;
- xy1.x() = w * 0.5;
- xy1.y() = h * 0.5;
- } else {
- xy0.x() = node->getFloatValue("x0", 0.0);
- xy0.y() = node->getFloatValue("y0", 0.0);
- xy1.x() = node->getFloatValue("x1", 5);
- xy1.y() = node->getFloatValue("y1", 5);
- }
+
+ return true;
+ }
+
+ void setDefinition(SymbolDef* d)
+ {
+ definition = d;
+ }
+
+ SymbolDef* getDefinition() const
+ { return definition; }
+
+ bool matches(const string_set& states) const
+ {
+ BOOST_FOREACH(const string& s, required_states) {
+ if (states.count(s) == 0) {
+ return false;
+ }
+ }
+
+ BOOST_FOREACH(const string& s, excluded_states) {
+ if (states.count(s) != 0) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ // return if the enabled state changed (needs a cache update)
+ bool checkEnabled()
+ {
+ if (enable.get()) {
+ bool wasEnabled = enabled;
+ enabled = enable->test();
+ return (enabled != wasEnabled);
+ } else {
+ enabled = true;
+ return false;
+ }
+ }
+
+ bool enabled; // cached enabled state
+ std::string type;
+
+ // record instances for limiting by count
+ int instanceCount;
+private:
+ SymbolDef* definition;
+
+ std::auto_ptr<SGCondition> enable;
+ string_set required_states;
+ string_set excluded_states;
+};
+
+class SymbolDef
+{
+public:
+ SymbolDef() : limitCount(0) { }
+
+ bool initFromNode(SGPropertyNode* node, NavDisplay* owner)
+ {
+ if (node->getChild("type")) {
+ SymbolRule* builtinRule = new SymbolRule;
+ builtinRule->initFromNode(node, owner);
+ builtinRule->setDefinition(this);
+ owner->addRule(builtinRule);
+ }
+
+ if (node->hasChild("width")) {
+ float w = node->getFloatValue("width");
+ float h = node->getFloatValue("height", w);
+ xy0.x() = -w * 0.5;
+ xy0.y() = -h * 0.5;
+ xy1.x() = w * 0.5;
+ xy1.y() = h * 0.5;
+ } else {
+ xy0.x() = node->getFloatValue("x0", 0.0);
+ xy0.y() = node->getFloatValue("y0", 0.0);
+ xy1.x() = node->getFloatValue("x1", 5);
+ xy1.y() = node->getFloatValue("y1", 5);
+ }