Canvas troubleshooting: Difference between revisions

Jump to navigation Jump to search
m
→‎Dumping Canvas scene graphs to disk: adding patches from topic branch
m (→‎Dumping Canvas scene graphs to disk: adding patches from topic branch)
Line 270: Line 270:


=== Dumping Canvas scene graphs to disk ===
=== Dumping Canvas scene graphs to disk ===
Here's the required SimGear changes to add a new method for dumping the scene graph for each Canvas to a file:
Here's the required SimGear changes to add a new method for dumping the scene graph for each Canvas element to a file (simply invoke the method on the top-level group to dump the whole canvas):
<syntaxhighlight lang="diff">
<syntaxhighlight lang="diff">diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx
index 6d8c930..6e0dc9b 100644
--- a/simgear/canvas/elements/CanvasElement.cxx
+++ b/simgear/canvas/elements/CanvasElement.cxx
@@ -222,6 +222,14 @@ namespace canvas
    }
  }
+  void Element::dumpSceneGraph(const std::string&filename)
+{
+      osgDB::writeNodeFile(*_transform.get(), filename);
+      SG_LOG(SG_GENERAL, SG_ALERT, "dumping Canvas scene graph to file:"<<filename);
+
+}
+
+
  //----------------------------------------------------------------------------
  void Element::onDestroy()
  {
diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx
index 37e12de..5a2cec8 100644
--- a/simgear/canvas/elements/CanvasElement.hxx
+++ b/simgear/canvas/elements/CanvasElement.hxx
@@ -25,6 +25,8 @@
#include <simgear/props/PropertyBasedElement.hxx>
#include <simgear/misc/stdint.hxx> // for uint32_t
+#include <osgDB/WriteFile>
+
#include <osg/BoundingBox>
#include <osg/MatrixTransform>
@@ -212,6 +214,8 @@ namespace canvas
        return ElementPtr( new Derived(canvas, node, style, parent) );
      }
+
+      void dumpSceneGraph(const std::string& filename);
    protected:
      enum Attributes
@@ -276,6 +280,7 @@ namespace canvas
        return false;
      }
+
      /**
        * Register a function for setting a style specified by the given property
        *
 
</syntaxhighlight>
</syntaxhighlight>


Line 277: Line 326:
<syntaxhighlight lang="diff">
<syntaxhighlight lang="diff">
diff --git a/src/Scripting/NasalCanvas.cxx b/src/Scripting/NasalCanvas.cxx
diff --git a/src/Scripting/NasalCanvas.cxx b/src/Scripting/NasalCanvas.cxx
index 4fa7652..2b63f02 100644
index 4fa7652..ffa8211 100644
--- a/src/Scripting/NasalCanvas.cxx
--- a/src/Scripting/NasalCanvas.cxx
+++ b/src/Scripting/NasalCanvas.cxx
+++ b/src/Scripting/NasalCanvas.cxx
@@ -478,7 +478,8 @@ naRef initNasalCanvas(naRef globals, naContext c)
@@ -492,7 +492,8 @@ naRef initNasalCanvas(naRef globals, naContext c)
     .method("dispatchEvent", &sc::Canvas::dispatchEvent)
     .method("setFocus", &sc::Element::setFocus)
     .method("setLayout", &sc::Canvas::setLayout)
     .method("dispatchEvent", &sc::Element::dispatchEvent)
     .method("setFocusElement", &sc::Canvas::setFocusElement)
     .method("getBoundingBox", &sc::Element::getBoundingBox)
-    .method("clearFocusElement", &sc::Canvas::clearFocusElement);
-    .method("getTightBoundingBox", &sc::Element::getTightBoundingBox);
+    .method("clearFocusElement", &sc::Canvas::clearFocusElement)
+    .method("getTightBoundingBox", &sc::Element::getTightBoundingBox)
+    .method("dumpSceneGraph", &sc::Canvas::dumpSceneGraph);
+    .method("dumpSceneGraph", &sc::Element::dumpSceneGraph);
</syntaxhighlight>
  canvas_module.set("_newCanvasGhost", f_createCanvas);
 
  canvas_module.set("_getCanvasGhost", f_getCanvas);
And here's the Nasal code to test the new API via the [[Nasal Console]]:
<syntaxhighlight lang="nasal">
var window = canvas.Window.new([320,160],"dialog");
var myCanvas = window.createCanvas().set("background", canvas.style.getColor("bg_color"));
var root = myCanvas.createGroup();
 
var myGroup = root.createChild('group', 'my group');
var textNode = myGroup.createChild("text")
        .setText("Some text")
        .setTranslation(20, 200)
        .set("alignment", "left-center")
        .set("character-size", 15)
        .set("font", "LiberationFonts/LiberationSans-Bold.ttf")
        .set("fill", "#ff0000");
 
textNode.dumpSceneGraph('textnode.osg');
</syntaxhighlight>
</syntaxhighlight>


This is what a simple Canvas scene graph may look like:
This is what a simple Canvas scene graph may look like:

Navigation menu