]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/panel_io.cxx
Use !strcmp for all property string-value comparisons.
[flightgear.git] / src / Cockpit / panel_io.cxx
index bd8389aa195e24ac510c7c9b76aec6e984b7dbe2..b81717430377f78988ba13e832d70cb0bbbd1cb3 100644 (file)
@@ -73,7 +73,7 @@ public:
 FGMagRibbon::FGMagRibbon (int w, int h)
   : FGTexturedLayer(w, h)
 {
-  FGCroppedTexture texture("Aircraft/c172/Instruments/Textures/compass-ribbon.rgb");
+  FGCroppedTexture texture("Aircraft/Instruments/Textures/compass-ribbon.rgb");
   setTexture(texture);
 }
 
@@ -174,13 +174,31 @@ FGMagRibbon::draw ()
 static FGCroppedTexture
 readTexture (const SGPropertyNode * node)
 {
-  FGCroppedTexture texture(node->getStringValue("path"),
-                          node->getFloatValue("x1"),
-                          node->getFloatValue("y1"),
-                          node->getFloatValue("x2", 1.0),
-                          node->getFloatValue("y2", 1.0));
-  SG_LOG(SG_COCKPIT, SG_DEBUG, "Read texture " << node->getName());
-  return texture;
+    FGCroppedTexture texture(node->getStringValue("path"),
+                            node->getFloatValue("x1"),
+                            node->getFloatValue("y1"),
+                            node->getFloatValue("x2", 1.0),
+                            node->getFloatValue("y2", 1.0));
+    SG_LOG(SG_COCKPIT, SG_DEBUG, "Read texture " << node->getName());
+    return texture;
+}
+
+
+/**
+ * Test for a condition in the current node.
+ */
+\f
+////////////////////////////////////////////////////////////////////////
+// Read a condition and use it if necessary.
+////////////////////////////////////////////////////////////////////////
+
+static void
+readConditions (FGConditional * component, const SGPropertyNode * node)
+{
+  const SGPropertyNode * conditionNode = node->getChild("condition");
+  if (conditionNode != 0)
+                               // The top level is implicitly AND
+    component->setCondition(fgReadCondition(conditionNode));
 }
 
 
@@ -224,12 +242,13 @@ readAction (const SGPropertyNode * node, float w_scale, float h_scale)
   FGPanelAction * action = new FGPanelAction(button, x, y, w, h);
 
   vector<const SGPropertyNode *>bindings = node->getChildren("binding");
-  for (int i = 0; i < bindings.size(); i++) {
+  for (unsigned int i = 0; i < bindings.size(); i++) {
     SG_LOG(SG_INPUT, SG_INFO, "Reading binding "
           << bindings[i]->getStringValue("command"));
-    action->addBinding(FGBinding(bindings[i])); // TODO: allow modifiers
+    action->addBinding(new FGBinding(bindings[i])); // TODO: allow modifiers
   }
 
+  readConditions(action, node);
   return action;
 }
 
@@ -276,8 +295,8 @@ readTransformation (const SGPropertyNode * node, float w_scale, float h_scale)
     type = "rotation";
   }
 
-  if (propName != (string)"") {
-    target = fgGetNode(propName, true);
+  if (!propName.empty()) {
+    target = fgGetNode(propName.c_str(), true);
   }
 
   t->node = target;
@@ -294,7 +313,7 @@ readTransformation (const SGPropertyNode * node, float w_scale, float h_scale)
     t->table = new SGInterpTable();
     for(int i = 0; i < trans_table->nChildren(); i++) {
       const SGPropertyNode * node = trans_table->getChild(i);
-      if (node->getName() == "entry") {
+      if (string(node->getName()) == "entry") {
        double ind = node->getDoubleValue("ind", 0.0);
        double dep = node->getDoubleValue("dep", 0.0);
        SG_LOG( SG_COCKPIT, SG_INFO, "Adding interpolation entry "
@@ -340,6 +359,7 @@ readTransformation (const SGPropertyNode * node, float w_scale, float h_scale)
     return 0;
   }
 
+  readConditions(t, node);
   SG_LOG( SG_COCKPIT, SG_DEBUG, "Read transformation " << name );
   return t;
 }
@@ -393,7 +413,7 @@ readTextChunk (const SGPropertyNode * node)
   else if (type == "number-value") {
     string propName = node->getStringValue("property");
     float scale = node->getFloatValue("scale", 1.0);
-    SGPropertyNode * target = fgGetNode(propName, true);
+    SGPropertyNode * target = fgGetNode(propName.c_str(), true);
     chunk = new FGTextLayer::Chunk(FGTextLayer::DOUBLE_VALUE, target,
                                   format, scale);
   }
@@ -405,6 +425,7 @@ readTextChunk (const SGPropertyNode * node)
     return 0;
   }
 
+  readConditions(chunk, node);
   return chunk;
 }
 
@@ -458,6 +479,19 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
     layer = new FGTexturedLayer(texture, w, h);
   }
 
+                               // A group of sublayers.
+  else if (type == "group") {
+    layer = new FGGroupLayer();
+    for (int i = 0; i < node->nChildren(); i++) {
+      const SGPropertyNode * child = node->getChild(i);
+      cerr << "Trying child " << child->getName() << endl;
+      if (string(child->getName()) == "layer") {
+       cerr << "succeeded!" << endl;
+       ((FGGroupLayer *)layer)->addLayer(readLayer(child, w_scale, h_scale));
+      }
+    }
+  }
+
 
                                // A textual instrument layer.
   else if (type == "text") {
@@ -474,14 +508,15 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
     tlayer->setPointSize(pointSize);
 
                                // Set the font.
-    // TODO
+    string fontName = node->getStringValue("font", "default");
+    tlayer->setFontName(fontName);
 
     const SGPropertyNode * chunk_group = node->getNode("chunks");
     if (chunk_group != 0) {
       int nChunks = chunk_group->nChildren();
       for (int i = 0; i < nChunks; i++) {
        const SGPropertyNode * node = chunk_group->getChild(i);
-       if (node->getName() == "chunk") {
+       if (string(node->getName()) == "chunk") {
          FGTextLayer::Chunk * chunk = readTextChunk(node);
          if (chunk != 0)
            tlayer->addChunk(chunk);
@@ -499,9 +534,9 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
     SGPropertyNode * target =
       fgGetNode(node->getStringValue("property"), true);
     FGInstrumentLayer * layer1 =
-      readLayer(node->getNode("layer1"), w_scale, h_scale);
+      readLayer(node->getNode("layer[0]"), w_scale, h_scale);
     FGInstrumentLayer * layer2 =
-      readLayer(node->getNode("layer2"), w_scale, h_scale);
+      readLayer(node->getNode("layer[1]"), w_scale, h_scale);
     layer = new FGSwitchLayer(w, h, target, layer1, layer2);
   }
 
@@ -541,7 +576,7 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
     int nTransformations = trans_group->nChildren();
     for (int i = 0; i < nTransformations; i++) {
       const SGPropertyNode * node = trans_group->getChild(i);
-      if (node->getName() == "transformation") {
+      if (string(node->getName()) == "transformation") {
        FGPanelTransformation * t = readTransformation(node, w_scale, h_scale);
        if (t != 0)
          layer->addTransformation(t);
@@ -551,7 +586,8 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
       }
     }
   }
-  
+
+  readConditions(layer, node);
   SG_LOG( SG_COCKPIT, SG_DEBUG, "Read layer " << name );
   return layer;
 }
@@ -609,7 +645,7 @@ readInstrument (const SGPropertyNode * node)
     int nActions = action_group->nChildren();
     for (int i = 0; i < nActions; i++) {
       const SGPropertyNode * node = action_group->getChild(i);
-      if (node->getName() == "action") {
+      if (string(node->getName()) == "action") {
        FGPanelAction * action = readAction(node, w_scale, h_scale);
        if (action != 0)
          instrument->addAction(action);
@@ -628,7 +664,7 @@ readInstrument (const SGPropertyNode * node)
     int nLayers = layer_group->nChildren();
     for (int i = 0; i < nLayers; i++) {
       const SGPropertyNode * node = layer_group->getChild(i);
-      if (node->getName() == "layer") {
+      if (string(node->getName()) == "layer") {
        FGInstrumentLayer * layer = readLayer(node, w_scale, h_scale);
        if (layer != 0)
          instrument->addLayer(layer);
@@ -638,7 +674,8 @@ readInstrument (const SGPropertyNode * node)
       }
     }
   }
-    
+
+  readConditions(instrument, node);
   SG_LOG( SG_COCKPIT, SG_DEBUG, "Done reading instrument " << name );
   return instrument;
 }
@@ -669,6 +706,8 @@ readPanel (const SGPropertyNode * root)
   if (!fgHasNode("/sim/panel/x-offset"))
     fgSetInt("/sim/panel/x-offset", root->getIntValue("x-offset", 0));
 
+  // conditional removed by jim wilson to allow panel xml code 
+  // with y-offset defined to work...
   if (!fgHasNode("/sim/panel/y-offset"))
     fgSetInt("/sim/panel/y-offset", root->getIntValue("y-offset", 0));
 
@@ -681,6 +720,59 @@ readPanel (const SGPropertyNode * root)
   panel->setBackground(FGTextureManager::createTexture(bgTexture.c_str()));
   SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << bgTexture );
 
+  //
+  // Get multibackground if any...
+  //
+  string mbgTexture = root->getStringValue("multibackground[0]");
+  if (!mbgTexture.empty()) {
+    panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 0);
+    SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
+
+    mbgTexture = root->getStringValue("multibackground[1]");
+    if (mbgTexture == "")
+      mbgTexture = "FOO";
+    panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 1);
+    SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
+
+    mbgTexture = root->getStringValue("multibackground[2]");
+    if (mbgTexture == "")
+      mbgTexture = "FOO";
+    panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 2);
+    SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
+
+    mbgTexture = root->getStringValue("multibackground[3]");
+    if (mbgTexture == "")
+      mbgTexture = "FOO";
+    panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 3);
+    SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
+
+    mbgTexture = root->getStringValue("multibackground[4]");
+    if (mbgTexture == "")
+      mbgTexture = "FOO";
+    panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 4);
+    SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
+
+    mbgTexture = root->getStringValue("multibackground[5]");
+    if (mbgTexture == "")
+      mbgTexture = "FOO";
+    panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 5);
+    SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
+
+    mbgTexture = root->getStringValue("multibackground[6]");
+    if (mbgTexture == "")
+      mbgTexture = "FOO";
+    panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 6);
+    SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
+
+    mbgTexture = root->getStringValue("multibackground[7]");
+    if (mbgTexture == "")
+      mbgTexture = "FOO";
+    panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 7);
+    SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
+
+  }
+  
+
 
   //
   // Create each instrument.
@@ -691,7 +783,7 @@ readPanel (const SGPropertyNode * root)
     int nInstruments = instrument_group->nChildren();
     for (int i = 0; i < nInstruments; i++) {
       const SGPropertyNode * node = instrument_group->getChild(i);
-      if (node->getName() == "instrument") {
+      if (string(node->getName()) == "instrument") {
        FGPanelInstrument * instrument = readInstrument(node);
        if (instrument != 0)
          panel->addInstrument(instrument);
@@ -761,3 +853,6 @@ fgReadPanel (const string &relative_path)
 
 
 // end of panel_io.cxx
+
+
+