]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/panel_io.cxx
Viewer update from Jim Wilson:
[flightgear.git] / src / Cockpit / panel_io.cxx
1 //  panel_io.cxx - I/O for 2D panel.
2 //
3 //  Written by David Megginson, started January 2000.
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License as
7 //  published by the Free Software Foundation; either version 2 of the
8 //  License, or (at your option) any later version.
9 // 
10 //  This program is distributed in the hope that it will be useful, but
11 //  WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 //  General Public License for more details.
14 // 
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 //  $Id$
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #ifdef HAVE_WINDOWS_H          
26 #  include <windows.h>
27 #endif
28
29 #include <string.h>             // for strcmp()
30
31 #include <simgear/compiler.h>
32 #include <simgear/misc/exception.hxx>
33
34 #include <simgear/misc/sg_path.hxx>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/misc/props.hxx>
37
38 #include STL_IOSTREAM
39 #include STL_FSTREAM
40 #include STL_STRING
41
42 #include <Main/globals.hxx>
43 #include <Main/fg_props.hxx>
44
45 #include <GUI/gui.h>
46
47 #include "panel.hxx"
48 #include "steam.hxx"
49 #include "panel_io.hxx"
50
51 #if !defined (SG_HAVE_NATIVE_SGI_COMPILERS)
52 SG_USING_STD(istream);
53 SG_USING_STD(ifstream);
54 #endif
55 SG_USING_STD(string);
56
57
58 \f
59 ////////////////////////////////////////////////////////////////////////
60 // Built-in layer for the magnetic compass ribbon layer.
61 //
62 // TODO: move this out into a special directory for built-in
63 // layers of various sorts.
64 ////////////////////////////////////////////////////////////////////////
65
66 class FGMagRibbon : public FGTexturedLayer
67 {
68 public:
69   FGMagRibbon (int w, int h);
70   virtual ~FGMagRibbon () {}
71
72   virtual void draw ();
73 };
74
75 FGMagRibbon::FGMagRibbon (int w, int h)
76   : FGTexturedLayer(w, h)
77 {
78   FGCroppedTexture texture("Aircraft/Instruments/Textures/compass-ribbon.rgb");
79   setTexture(texture);
80 }
81
82 void
83 FGMagRibbon::draw ()
84 {
85   double heading = FGSteam::get_MH_deg();
86   double xoffset, yoffset;
87
88   while (heading >= 360.0) {
89     heading -= 360.0;
90   }
91   while (heading < 0.0) {
92     heading += 360.0;
93   }
94
95   if (heading >= 60.0 && heading <= 180.0) {
96     xoffset = heading / 240.0;
97     yoffset = 0.75;
98   } else if (heading >= 150.0 && heading <= 270.0) {
99     xoffset = (heading - 90.0) / 240.0;
100     yoffset = 0.50;
101   } else if (heading >= 240.0 && heading <= 360.0) {
102     xoffset = (heading - 180.0) / 240.0;
103     yoffset = 0.25;
104   } else {
105     if (heading < 270.0)
106       heading += 360.0;
107     xoffset = (heading - 270.0) / 240.0;
108     yoffset = 0.0;
109   }
110
111   xoffset = 1.0 - xoffset;
112                                 // Adjust to put the number in the centre
113   xoffset -= 0.25;
114
115   FGCroppedTexture &t = getTexture();
116   t.setCrop(xoffset, yoffset, xoffset + 0.5, yoffset + 0.25);
117   FGTexturedLayer::draw();
118 }
119
120
121 \f
122 ////////////////////////////////////////////////////////////////////////
123 // Read and construct a panel.
124 //
125 // The panel is specified as a regular property list, and each of the
126 // instruments is its own, separate property list (and thus, a separate
127 // XML document).  The functions in this section read in the files
128 // as property lists, then extract properties to set up the panel
129 // itself.
130 //
131 // A panel contains zero or more instruments.
132 //
133 // An instrument contains one or more layers and zero or more actions.
134 //
135 // A layer contains zero or more transformations.
136 //
137 // Some special types of layers also contain other objects, such as 
138 // chunks of text or other layers.
139 //
140 // There are currently four types of layers:
141 //
142 // 1. Textured Layer (type="texture"), the default
143 // 2. Text Layer (type="text")
144 // 3. Switch Layer (type="switch")
145 // 4. Built-in Layer (type="built-in", must also specify class)
146 //
147 // The only built-in layer so far is the ribbon for the magnetic compass
148 // (class="compass-ribbon").
149 //
150 // There are three types of actions:
151 //
152 // 1. Adjust (type="adjust"), the default
153 // 2. Swap (type="swap")
154 // 3. Toggle (type="toggle")
155 //
156 // There are three types of transformations:
157 //
158 // 1. X shift (type="x-shift"), the default
159 // 2. Y shift (type="y-shift")
160 // 3. Rotation (type="rotation")
161 //
162 // Each of these may be associated with a property, so that a needle
163 // will rotate with the airspeed, for example, or may have a fixed
164 // floating-point value.
165 ////////////////////////////////////////////////////////////////////////
166
167
168 /**
169  * Read a cropped texture from the instrument's property list.
170  *
171  * The x1 and y1 properties give the starting position of the texture
172  * (between 0.0 and 1.0), and the the x2 and y2 properties give the
173  * ending position.  For example, to use the bottom-left quarter of a
174  * texture, x1=0.0, y1=0.0, x2=0.5, y2=0.5.
175  */
176 static FGCroppedTexture
177 readTexture (const SGPropertyNode * node)
178 {
179     FGCroppedTexture texture(node->getStringValue("path"),
180                              node->getFloatValue("x1"),
181                              node->getFloatValue("y1"),
182                              node->getFloatValue("x2", 1.0),
183                              node->getFloatValue("y2", 1.0));
184     SG_LOG(SG_COCKPIT, SG_DEBUG, "Read texture " << node->getName());
185     return texture;
186 }
187
188
189 /**
190  * Test for a condition in the current node.
191  */
192 \f
193 ////////////////////////////////////////////////////////////////////////
194 // Read a condition and use it if necessary.
195 ////////////////////////////////////////////////////////////////////////
196
197 static void
198 readConditions (FGConditional * component, const SGPropertyNode * node)
199 {
200   const SGPropertyNode * conditionNode = node->getChild("condition");
201   if (conditionNode != 0)
202                                 // The top level is implicitly AND
203     component->setCondition(fgReadCondition(conditionNode));
204 }
205
206
207 /**
208  * Read an action from the instrument's property list.
209  *
210  * The action will be performed when the user clicks a mouse button
211  * within the specified region of the instrument.  Actions always work
212  * by modifying the value of a property (see the SGPropertyNode
213  * class).
214  *
215  * The following action types are defined:
216  *
217  * "adjust" - modify the value of a floating-point property by
218  *    the increment specified.  This is the default.
219  *
220  * "swap" - swap the values of two-floating-point properties.
221  *
222  * "toggle" - toggle the value of a boolean property between true and
223  *    false.
224  *
225  * For the adjust action, it is possible to specify an increment
226  * (use a negative number for a decrement), a minimum allowed value,
227  * a maximum allowed value, and a flag to indicate whether the value
228  * should freeze or wrap-around when it reachs the minimum or maximum.
229  *
230  * The action will be scaled automatically if the instrument is not
231  * being drawn at its regular size.
232  */
233 static FGPanelAction *
234 readAction (const SGPropertyNode * node, float w_scale, float h_scale)
235 {
236   string name = node->getStringValue("name");
237
238   int button = node->getIntValue("button");
239   int x = int(node->getIntValue("x") * w_scale);
240   int y = int(node->getIntValue("y") * h_scale);
241   int w = int(node->getIntValue("w") * w_scale);
242   int h = int(node->getIntValue("h") * h_scale);
243
244   FGPanelAction * action = new FGPanelAction(button, x, y, w, h);
245
246   vector<const SGPropertyNode *>bindings = node->getChildren("binding");
247   for (unsigned int i = 0; i < bindings.size(); i++) {
248     SG_LOG(SG_INPUT, SG_INFO, "Reading binding "
249            << bindings[i]->getStringValue("command"));
250     action->addBinding(new FGBinding(bindings[i])); // TODO: allow modifiers
251   }
252
253   readConditions(action, node);
254   return action;
255 }
256
257
258 /**
259  * Read a transformation from the instrument's property list.
260  *
261  * The panel module uses the transformations to slide or spin needles,
262  * knobs, and other indicators, and to place layers in the correct
263  * positions.  Every layer starts centered exactly on the x,y co-ordinate,
264  * and many layers need to be moved or rotated simply to display the
265  * instrument correctly.
266  *
267  * There are three types of transformations:
268  *
269  * "x-shift" - move the layer horizontally.
270  *
271  * "y-shift" - move the layer vertically.
272  *
273  * "rotation" - rotate the layer.
274  *
275  * Each transformation may have a fixed offset, and may also have
276  * a floating-point property value to add to the offset.  The
277  * floating-point property may be clamped to a minimum and/or
278  * maximum range and scaled (after clamping).
279  *
280  * Note that because of the way OpenGL works, transformations will
281  * appear to be applied backwards.
282  */
283 static FGPanelTransformation *
284 readTransformation (const SGPropertyNode * node, float w_scale, float h_scale)
285 {
286   FGPanelTransformation * t = new FGPanelTransformation;
287
288   string name = node->getName();
289   string type = node->getStringValue("type");
290   string propName = node->getStringValue("property", "");
291   SGPropertyNode * target = 0;
292
293   if (type.empty()) {
294     SG_LOG( SG_COCKPIT, SG_ALERT,
295             "No type supplied for transformation " << name
296             << " assuming \"rotation\"" );
297     type = "rotation";
298   }
299
300   if (!propName.empty()) {
301     target = fgGetNode(propName.c_str(), true);
302   }
303
304   t->node = target;
305   t->min = node->getFloatValue("min", -9999999);
306   t->max = node->getFloatValue("max", 99999999);
307   t->factor = node->getFloatValue("scale", 1.0);
308   t->offset = node->getFloatValue("offset", 0.0);
309
310                                 // Check for an interpolation table
311   const SGPropertyNode * trans_table = node->getNode("interpolation");
312   if (trans_table != 0) {
313     SG_LOG( SG_COCKPIT, SG_INFO, "Found interpolation table with "
314             << trans_table->nChildren() << "children" );
315     t->table = new SGInterpTable();
316     for(int i = 0; i < trans_table->nChildren(); i++) {
317       const SGPropertyNode * node = trans_table->getChild(i);
318       if (!strcmp(node->getName(), "entry")) {
319         double ind = node->getDoubleValue("ind", 0.0);
320         double dep = node->getDoubleValue("dep", 0.0);
321         SG_LOG( SG_COCKPIT, SG_INFO, "Adding interpolation entry "
322                 << ind << "==>" << dep );
323         t->table->addEntry(ind, dep);
324       } else {
325         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
326                 << " in interpolation" );
327       }
328     }
329   } else {
330     t->table = 0;
331   }
332   
333                                 // Move the layer horizontally.
334   if (type == "x-shift") {
335     t->type = FGPanelTransformation::XSHIFT;
336 //     t->min *= w_scale; //removed by Martin Dressler
337 //     t->max *= w_scale; //removed by Martin Dressler
338     t->offset *= w_scale;
339     t->factor *= w_scale; //Added by Martin Dressler
340   } 
341
342                                 // Move the layer vertically.
343   else if (type == "y-shift") {
344     t->type = FGPanelTransformation::YSHIFT;
345     //t->min *= h_scale; //removed
346     //t->max *= h_scale; //removed
347     t->offset *= h_scale;
348     t->factor *= h_scale; //Added
349   } 
350
351                                 // Rotate the layer.  The rotation
352                                 // is in degrees, and does not need
353                                 // to scale with the instrument size.
354   else if (type == "rotation") {
355     t->type = FGPanelTransformation::ROTATION;
356   } 
357
358   else {
359     SG_LOG( SG_COCKPIT, SG_ALERT, "Unrecognized transformation type " << type );
360     delete t;
361     return 0;
362   }
363
364   readConditions(t, node);
365   SG_LOG( SG_COCKPIT, SG_DEBUG, "Read transformation " << name );
366   return t;
367 }
368
369
370 /**
371  * Read a chunk of text from the instrument's property list.
372  *
373  * A text layer consists of one or more chunks of text.  All chunks
374  * share the same font size and color (and eventually, font), but
375  * each can come from a different source.  There are three types of
376  * text chunks:
377  *
378  * "literal" - a literal text string (the default)
379  *
380  * "text-value" - the current value of a string property
381  *
382  * "number-value" - the current value of a floating-point property.
383  *
384  * All three may also include a printf-style format string.
385  */
386 FGTextLayer::Chunk *
387 readTextChunk (const SGPropertyNode * node)
388 {
389   FGTextLayer::Chunk * chunk;
390   string name = node->getStringValue("name");
391   string type = node->getStringValue("type");
392   string format = node->getStringValue("format");
393
394                                 // Default to literal text.
395   if (type.empty()) {
396     SG_LOG( SG_COCKPIT, SG_INFO, "No type provided for text chunk " << name
397             << " assuming \"literal\"");
398     type = "literal";
399   }
400
401                                 // A literal text string.
402   if (type == "literal") {
403     string text = node->getStringValue("text");
404     chunk = new FGTextLayer::Chunk(text, format);
405   }
406
407                                 // The value of a string property.
408   else if (type == "text-value") {
409     SGPropertyNode * target =
410       fgGetNode(node->getStringValue("property"), true);
411     chunk = new FGTextLayer::Chunk(FGTextLayer::TEXT_VALUE, target, format);
412   }
413
414                                 // The value of a float property.
415   else if (type == "number-value") {
416     string propName = node->getStringValue("property");
417     float scale = node->getFloatValue("scale", 1.0);
418     SGPropertyNode * target = fgGetNode(propName.c_str(), true);
419     chunk = new FGTextLayer::Chunk(FGTextLayer::DOUBLE_VALUE, target,
420                                    format, scale);
421   }
422
423                                 // Unknown type.
424   else {
425     SG_LOG( SG_COCKPIT, SG_ALERT, "Unrecognized type " << type
426             << " for text chunk " << name );
427     return 0;
428   }
429
430   readConditions(chunk, node);
431   return chunk;
432 }
433
434
435 /**
436  * Read a single layer from an instrument's property list.
437  *
438  * Each instrument consists of one or more layers stacked on top
439  * of each other; the lower layers show through only where the upper
440  * layers contain an alpha component.  Each layer can be moved
441  * horizontally and vertically and rotated using transformations.
442  *
443  * This module currently recognizes four kinds of layers:
444  *
445  * "texture" - a layer containing a texture (the default)
446  *
447  * "text" - a layer containing text
448  *
449  * "switch" - a layer that switches between two other layers
450  *   based on the current value of a boolean property.
451  *
452  * "built-in" - a hard-coded layer supported by C++ code in FlightGear.
453  *
454  * Currently, the only built-in layer class is "compass-ribbon".
455  */
456 static FGInstrumentLayer *
457 readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
458 {
459   FGInstrumentLayer * layer = NULL;
460   string name = node->getStringValue("name");
461   string type = node->getStringValue("type");
462   int w = node->getIntValue("w", -1);
463   int h = node->getIntValue("h", -1);
464   if (w != -1)
465     w = int(w * w_scale);
466   if (h != -1)
467     h = int(h * h_scale);
468
469
470   if (type.empty()) {
471     SG_LOG( SG_COCKPIT, SG_ALERT,
472             "No type supplied for layer " << name
473             << " assuming \"texture\"" );
474     type = "texture";
475   }
476
477
478                                 // A textured instrument layer.
479   if (type == "texture") {
480     FGCroppedTexture texture = readTexture(node->getNode("texture"));
481     layer = new FGTexturedLayer(texture, w, h);
482   }
483
484                                 // A group of sublayers.
485   else if (type == "group") {
486     layer = new FGGroupLayer();
487     for (int i = 0; i < node->nChildren(); i++) {
488       const SGPropertyNode * child = node->getChild(i);
489       cerr << "Trying child " << child->getName() << endl;
490       if (!strcmp(child->getName(), "layer")) {
491         cerr << "succeeded!" << endl;
492         ((FGGroupLayer *)layer)->addLayer(readLayer(child, w_scale, h_scale));
493       }
494     }
495   }
496
497
498                                 // A textual instrument layer.
499   else if (type == "text") {
500     FGTextLayer * tlayer = new FGTextLayer(w, h); // FIXME
501
502                                 // Set the text color.
503     float red = node->getFloatValue("color/red", 0.0);
504     float green = node->getFloatValue("color/green", 0.0);
505     float blue = node->getFloatValue("color/blue", 0.0);
506     tlayer->setColor(red, green, blue);
507
508                                 // Set the point size.
509     float pointSize = node->getFloatValue("point-size", 10.0) * w_scale;
510     tlayer->setPointSize(pointSize);
511
512                                 // Set the font.
513     string fontName = node->getStringValue("font", "default");
514     tlayer->setFontName(fontName);
515
516     const SGPropertyNode * chunk_group = node->getNode("chunks");
517     if (chunk_group != 0) {
518       int nChunks = chunk_group->nChildren();
519       for (int i = 0; i < nChunks; i++) {
520         const SGPropertyNode * node = chunk_group->getChild(i);
521         if (!strcmp(node->getName(), "chunk")) {
522           FGTextLayer::Chunk * chunk = readTextChunk(node);
523           if (chunk != 0)
524             tlayer->addChunk(chunk);
525         } else {
526           SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
527                   << " in chunks" );
528         }
529       }
530       layer = tlayer;
531     }
532   }
533
534                                 // A switch instrument layer.
535   else if (type == "switch") {
536     SGPropertyNode * target =
537       fgGetNode(node->getStringValue("property"), true);
538     FGInstrumentLayer * layer1 =
539       readLayer(node->getNode("layer[0]"), w_scale, h_scale);
540     FGInstrumentLayer * layer2 =
541       readLayer(node->getNode("layer[1]"), w_scale, h_scale);
542     layer = new FGSwitchLayer(w, h, target, layer1, layer2);
543   }
544
545                                 // A built-in instrument layer.
546   else if (type == "built-in") {
547     string layerclass = node->getStringValue("class");
548
549     if (layerclass == "mag-ribbon") {
550       layer = new FGMagRibbon(w, h);
551     }
552
553     else if (layerclass.empty()) {
554       SG_LOG( SG_COCKPIT, SG_ALERT, "No class provided for built-in layer "
555               << name );
556       return 0;
557     }
558
559     else {
560       SG_LOG( SG_COCKPIT, SG_ALERT, "Unknown built-in layer class "
561               << layerclass);
562       return 0;
563     }
564   }
565
566                                 // An unknown type.
567   else {
568     SG_LOG( SG_COCKPIT, SG_ALERT, "Unrecognized layer type " << type );
569     delete layer;
570     return 0;
571   }
572   
573   //
574   // Get the transformations for each layer.
575   //
576   const SGPropertyNode * trans_group = node->getNode("transformations");
577   if (trans_group != 0) {
578     int nTransformations = trans_group->nChildren();
579     for (int i = 0; i < nTransformations; i++) {
580       const SGPropertyNode * node = trans_group->getChild(i);
581       if (!strcmp(node->getName(), "transformation")) {
582         FGPanelTransformation * t = readTransformation(node, w_scale, h_scale);
583         if (t != 0)
584           layer->addTransformation(t);
585       } else {
586         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
587                 << " in transformations" );
588       }
589     }
590   }
591
592   readConditions(layer, node);
593   SG_LOG( SG_COCKPIT, SG_DEBUG, "Read layer " << name );
594   return layer;
595 }
596
597
598 /**
599  * Read an instrument from a property list.
600  *
601  * The instrument consists of a preferred width and height
602  * (the panel may override these), together with a list of layers
603  * and a list of actions to be performed when the user clicks 
604  * the mouse over the instrument.  All co-ordinates are relative
605  * to the instrument's position, so instruments are fully relocatable;
606  * likewise, co-ordinates for actions and transformations will be
607  * scaled automatically if the instrument is not at its preferred size.
608  */
609 static FGPanelInstrument *
610 readInstrument (const SGPropertyNode * node)
611 {
612   const string &name = node->getStringValue("name");
613   int x = node->getIntValue("x", -1);
614   int y = node->getIntValue("y", -1);
615   int real_w = node->getIntValue("w", -1);
616   int real_h = node->getIntValue("h", -1);
617   int w = node->getIntValue("w-base", -1);
618   int h = node->getIntValue("h-base", -1);
619
620   if (x == -1 || y == -1) {
621     SG_LOG( SG_COCKPIT, SG_ALERT,
622             "x and y positions must be specified and > 0" );
623     return 0;
624   }
625
626   float w_scale = 1.0;
627   float h_scale = 1.0;
628   if (real_w != -1) {
629     w_scale = float(real_w) / float(w);
630     w = real_w;
631   }
632   if (real_h != -1) {
633     h_scale = float(real_h) / float(h);
634     h = real_h;
635   }
636
637   SG_LOG( SG_COCKPIT, SG_DEBUG, "Reading instrument " << name );
638
639   FGLayeredInstrument * instrument =
640     new FGLayeredInstrument(x, y, w, h);
641
642   //
643   // Get the actions for the instrument.
644   //
645   const SGPropertyNode * action_group = node->getNode("actions");
646   if (action_group != 0) {
647     int nActions = action_group->nChildren();
648     for (int i = 0; i < nActions; i++) {
649       const SGPropertyNode * node = action_group->getChild(i);
650       if (!strcmp(node->getName(), "action")) {
651         FGPanelAction * action = readAction(node, w_scale, h_scale);
652         if (action != 0)
653           instrument->addAction(action);
654       } else {
655         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
656                 << " in actions" );
657       }
658     }
659   }
660
661   //
662   // Get the layers for the instrument.
663   //
664   const SGPropertyNode * layer_group = node->getNode("layers");
665   if (layer_group != 0) {
666     int nLayers = layer_group->nChildren();
667     for (int i = 0; i < nLayers; i++) {
668       const SGPropertyNode * node = layer_group->getChild(i);
669       if (!strcmp(node->getName(), "layer")) {
670         FGInstrumentLayer * layer = readLayer(node, w_scale, h_scale);
671         if (layer != 0)
672           instrument->addLayer(layer);
673       } else {
674         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
675                 << " in layers" );
676       }
677     }
678   }
679
680   readConditions(instrument, node);
681   SG_LOG( SG_COCKPIT, SG_DEBUG, "Done reading instrument " << name );
682   return instrument;
683 }
684
685
686 /**
687  * Construct the panel from a property tree.
688  */
689 FGPanel *
690 readPanel (const SGPropertyNode * root)
691 {
692   SG_LOG( SG_COCKPIT, SG_INFO, "Reading properties for panel " <<
693           root->getStringValue("name", "[Unnamed Panel]") );
694
695   FGPanel * panel = new FGPanel();
696   panel->setWidth(root->getIntValue("w", 1024));
697   panel->setHeight(root->getIntValue("h", 443));
698
699   //
700   // Grab the visible external viewing area, default to 
701   //
702   panel->setViewHeight(root->getIntValue("view-height",
703                                          768 - panel->getHeight() + 2));
704
705   //
706   // Grab the panel's initial offsets, default to 0, 0.
707   //
708   if (!fgHasNode("/sim/panel/x-offset"))
709     fgSetInt("/sim/panel/x-offset", root->getIntValue("x-offset", 0));
710
711   // conditional removed by jim wilson to allow panel xml code 
712   // with y-offset defined to work...
713   if (!fgHasNode("/sim/panel/y-offset"))
714     fgSetInt("/sim/panel/y-offset", root->getIntValue("y-offset", 0));
715
716   //
717   // Assign the background texture, if any, or a bogus chequerboard.
718   //
719   string bgTexture = root->getStringValue("background");
720   if (bgTexture.empty())
721     bgTexture = "FOO";
722   panel->setBackground(FGTextureManager::createTexture(bgTexture.c_str()));
723   SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << bgTexture );
724
725   //
726   // Get multibackground if any...
727   //
728   string mbgTexture = root->getStringValue("multibackground[0]");
729   if (!mbgTexture.empty()) {
730     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 0);
731     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
732
733     mbgTexture = root->getStringValue("multibackground[1]");
734     if (mbgTexture.empty())
735       mbgTexture = "FOO";
736     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 1);
737     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
738
739     mbgTexture = root->getStringValue("multibackground[2]");
740     if (mbgTexture.empty())
741       mbgTexture = "FOO";
742     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 2);
743     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
744
745     mbgTexture = root->getStringValue("multibackground[3]");
746     if (mbgTexture.empty())
747       mbgTexture = "FOO";
748     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 3);
749     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
750
751     mbgTexture = root->getStringValue("multibackground[4]");
752     if (mbgTexture.empty())
753       mbgTexture = "FOO";
754     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 4);
755     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
756
757     mbgTexture = root->getStringValue("multibackground[5]");
758     if (mbgTexture.empty())
759       mbgTexture = "FOO";
760     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 5);
761     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
762
763     mbgTexture = root->getStringValue("multibackground[6]");
764     if (mbgTexture.empty())
765       mbgTexture = "FOO";
766     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 6);
767     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
768
769     mbgTexture = root->getStringValue("multibackground[7]");
770     if (mbgTexture.empty())
771       mbgTexture = "FOO";
772     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 7);
773     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
774
775   }
776   
777
778
779   //
780   // Create each instrument.
781   //
782   SG_LOG( SG_COCKPIT, SG_INFO, "Reading panel instruments" );
783   const SGPropertyNode * instrument_group = root->getChild("instruments");
784   if (instrument_group != 0) {
785     int nInstruments = instrument_group->nChildren();
786     for (int i = 0; i < nInstruments; i++) {
787       const SGPropertyNode * node = instrument_group->getChild(i);
788       if (!strcmp(node->getName(), "instrument")) {
789         FGPanelInstrument * instrument = readInstrument(node);
790         if (instrument != 0)
791           panel->addInstrument(instrument);
792       } else {
793         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
794                 << " in instruments section" );
795       }
796     }
797   }
798   SG_LOG( SG_COCKPIT, SG_INFO, "Done reading panel instruments" );
799
800
801   //
802   // Return the new panel.
803   //
804   return panel;
805 }
806
807
808 /**
809  * Read a panel from a property list.
810  *
811  * Each panel instrument will appear in its own, separate
812  * property list.  The top level simply names the panel and
813  * places the instruments in their appropriate locations (and
814  * optionally resizes them if necessary).
815  *
816  * Returns 0 if the read fails for any reason.
817  */
818 FGPanel *
819 fgReadPanel (istream &input)
820 {
821   SGPropertyNode root;
822
823   try {
824     readProperties(input, &root);
825   } catch (const sg_exception &e) {
826     guiErrorMessage("Error reading panel: ", e);
827     return 0;
828   }
829   return readPanel(&root);
830 }
831
832
833 /**
834  * Read a panel from a property list.
835  *
836  * This function opens a stream to a file, then invokes the
837  * main fgReadPanel() function.
838  */
839 FGPanel *
840 fgReadPanel (const string &relative_path)
841 {
842   SGPath path(globals->get_fg_root());
843   path.append(relative_path);
844   SGPropertyNode root;
845
846   try {
847     readProperties(path.str(), &root);
848   } catch (const sg_exception &e) {
849     guiErrorMessage("Error reading panel: ", e);
850     return 0;
851   }
852   return readPanel(&root);
853 }
854
855
856
857 // end of panel_io.cxx
858
859
860