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