]> git.mxchange.org Git - flightgear.git/commitdiff
Refactor PropertyBasedElement and Manager
authorThomas Geymayer <tomgey@gmail.com>
Mon, 29 Oct 2012 15:15:10 +0000 (16:15 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 29 Oct 2012 15:19:13 +0000 (16:19 +0100)
14 files changed:
src/Canvas/CMakeLists.txt
src/Canvas/canvas.hxx
src/Canvas/canvas_fwd.hpp
src/Canvas/canvas_mgr.cxx
src/Canvas/canvas_mgr.hxx
src/Canvas/gui_mgr.cxx
src/Canvas/gui_mgr.hxx
src/Canvas/property_based_element.cxx [deleted file]
src/Canvas/property_based_element.hxx [deleted file]
src/Canvas/property_based_mgr.cxx [deleted file]
src/Canvas/property_based_mgr.hxx [deleted file]
src/Canvas/property_helper.cxx
src/Canvas/property_helper.hxx
src/Canvas/window.hxx

index ac1f66275af6f68d162ebf5ed82fdbf037bdc78c..2483f353dc85200fc856174794d8fac108a41b9e 100644 (file)
@@ -11,8 +11,6 @@ set(SOURCES
   elements/CanvasImage.cxx
   gui_mgr.cxx
   placement.cxx
-  property_based_element.cxx
-  property_based_mgr.cxx
   property_helper.cxx
   window.cxx
 )
@@ -28,8 +26,6 @@ set(HEADERS
   elements/CanvasImage.hxx
   gui_mgr.hxx
   placement.hxx
-  property_based_element.hxx
-  property_based_mgr.hxx
   property_helper.hxx
   window.hxx
 )
index 2071452997cb88364f9c091a5523b4dd274df985..85f233cd47614381b6f2365594af5d8769ff7189 100644 (file)
 #define CANVAS_HXX_
 
 #include "placement.hxx"
-#include "property_based_element.hxx"
 
 #include <Canvas/canvas_fwd.hpp>
 #include <Cockpit/od_gauge.hxx>
 
+#include <simgear/props/PropertyBasedElement.hxx>
 #include <simgear/props/propertyObject.hxx>
 #include <osg/NodeCallback>
 #include <osg/observer_ptr>
@@ -33,7 +33,7 @@
 #include <string>
 
 class Canvas:
-  public PropertyBasedElement
+  public simgear::PropertyBasedElement
 {
   public:
 
index 004fb253bb8f35c3859b6a884e14baa752a9304a..356ea1c57f29929bdf1b5834e516fb04102733a9 100644 (file)
@@ -30,10 +30,6 @@ class Canvas;
 typedef boost::shared_ptr<Canvas> CanvasPtr;
 typedef boost::weak_ptr<Canvas> CanvasWeakPtr;
 
-class PropertyBasedElement;
-typedef boost::shared_ptr<PropertyBasedElement> PropertyBasedElementPtr;
-typedef boost::weak_ptr<PropertyBasedElement> PropertyBasedElementWeakPtr;
-
 namespace canvas
 {
   const std::string VG_INIT_SIGNAL = "/sim/signals/vg-initialized-frame";
index a175076237112b4583c097e2069a582a8ac682fc..028d70d040bce8ffadfc3fd921be63903feb4c4b 100644 (file)
@@ -19,6 +19,8 @@
 #include "canvas_mgr.hxx"
 #include "canvas.hxx"
 
+#include <Main/fg_props.hxx>
+
 #include <boost/bind.hpp>
 
 typedef boost::shared_ptr<Canvas> CanvasPtr;
@@ -30,7 +32,9 @@ CanvasPtr canvasFactory(SGPropertyNode* node)
 
 //------------------------------------------------------------------------------
 CanvasMgr::CanvasMgr():
-  PropertyBasedMgr("/canvas/by-index", "texture", &canvasFactory)
+  PropertyBasedMgr( fgGetNode("/canvas/by-index", true),
+                    "texture",
+                    &canvasFactory )
 {
   Canvas::addPlacementFactory
   (
index 568da3d61615b65825034cacdce86f7c534328b6..0ae272537c103acb6aaf0b0eafc2db08bc3aae0b 100644 (file)
 #define CANVAS_MGR_H_
 
 #include "canvas_fwd.hpp"
-#include "property_based_mgr.hxx"
+#include <simgear/props/PropertyBasedMgr.hxx>
 
 class CanvasMgr:
-  public PropertyBasedMgr
+  public simgear::PropertyBasedMgr
 {
   public:
     CanvasMgr();
index 44cad8bd06f0ac3404555f076a03ca8df481fa49..f3436dbaf0191df5738fdbf415b4d2d2d202a99c 100644 (file)
@@ -20,6 +20,7 @@
 #include <Canvas/window.hxx>
 #include <Canvas/canvas.hxx>
 
+#include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 #include <Viewer/CameraGroup.hxx>
 #include <Viewer/renderer.hxx>
@@ -105,7 +106,9 @@ WindowPtr windowFactory(SGPropertyNode* node)
 
 //------------------------------------------------------------------------------
 GUIMgr::GUIMgr():
-  PropertyBasedMgr("/sim/gui/canvas", "window", &windowFactory),
+  PropertyBasedMgr( fgGetNode("/sim/gui/canvas", true),
+                    "window",
+                    &windowFactory ),
   _event_handler( new GUIEventHandler(this) ),
   _transform( new osg::MatrixTransform ),
   _width(_props, "size[0]"),
@@ -164,7 +167,7 @@ void GUIMgr::shutdown()
 }
 
 //------------------------------------------------------------------------------
-void GUIMgr::elementCreated(PropertyBasedElementPtr element)
+void GUIMgr::elementCreated(simgear::PropertyBasedElementPtr element)
 {
   canvas::WindowPtr window =
     boost::static_pointer_cast<canvas::Window>(element);
index 8a1ccf786e405aa8874037d14b79e400c4ce1457..927d73eb16966ac9695862eb592a53bab999d244 100644 (file)
 #ifndef CANVAS_GUI_MGR_HXX_
 #define CANVAS_GUI_MGR_HXX_
 
-#include "property_based_mgr.hxx"
 #include <Canvas/canvas_fwd.hpp>
 #include <Canvas/placement.hxx>
 
+#include <simgear/props/PropertyBasedMgr.hxx>
 #include <simgear/props/propertyObject.hxx>
 
 #include <osg/ref_ptr>
@@ -36,7 +36,7 @@ namespace osgGA
 
 class GUIEventHandler;
 class GUIMgr:
-  public PropertyBasedMgr
+  public simgear::PropertyBasedMgr
 {
   public:
     GUIMgr();
@@ -44,7 +44,7 @@ class GUIMgr:
     virtual void init();
     virtual void shutdown();
 
-    virtual void elementCreated(PropertyBasedElementPtr element);
+    virtual void elementCreated(simgear::PropertyBasedElementPtr element);
 
     bool handleEvent(const osgGA::GUIEventAdapter& ea);
 
diff --git a/src/Canvas/property_based_element.cxx b/src/Canvas/property_based_element.cxx
deleted file mode 100644 (file)
index 8672539..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// Base class for elements of property controlled subsystems
-//
-// Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
-#include "property_based_element.hxx"
-
-//------------------------------------------------------------------------------
-PropertyBasedElement::PropertyBasedElement(SGPropertyNode* node):
-  _node(node)
-{
-  _node->addChangeListener(this);
-}
-
-//------------------------------------------------------------------------------
-PropertyBasedElement::~PropertyBasedElement()
-{
-  _node->removeChangeListener(this);
-}
-
-//------------------------------------------------------------------------------
-SGConstPropertyNode_ptr PropertyBasedElement::getProps() const
-{
-  return _node;
-}
-
-//------------------------------------------------------------------------------
-SGPropertyNode_ptr PropertyBasedElement::getProps()
-{
-  return _node;
-}
diff --git a/src/Canvas/property_based_element.hxx b/src/Canvas/property_based_element.hxx
deleted file mode 100644 (file)
index a41914d..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-// Base class for elements of property controlled subsystems
-//
-// Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
-#ifndef PROPERTY_BASED_ELEMENT_HXX_
-#define PROPERTY_BASED_ELEMENT_HXX_
-
-#include <Canvas/canvas_fwd.hpp>
-#include <simgear/props/props.hxx>
-
-/**
- * Base class for a property controlled element
- */
-class PropertyBasedElement:
-  public SGPropertyChangeListener
-{
-  public:
-    PropertyBasedElement(SGPropertyNode* node);
-    virtual ~PropertyBasedElement();
-
-    virtual void update(double delta_time_sec) = 0;
-
-    SGConstPropertyNode_ptr getProps() const;
-    SGPropertyNode_ptr getProps();
-
-  protected:
-
-    friend class PropertyBasedMgr;
-
-    SGPropertyNode_ptr _node;
-    PropertyBasedElementWeakPtr _self;
-};
-
-
-#endif /* PROPERTY_BASED_ELEMENT_HXX_ */
diff --git a/src/Canvas/property_based_mgr.cxx b/src/Canvas/property_based_mgr.cxx
deleted file mode 100644 (file)
index 148c96e..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-// Base class for all property controlled subsystems
-//
-// Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
-#include "property_based_mgr.hxx"
-#include "property_helper.hxx"
-#include <Main/fg_props.hxx>
-
-#include <stdexcept>
-#include <string>
-
-//------------------------------------------------------------------------------
-void PropertyBasedMgr::init()
-{
-  _props->addChangeListener(this);
-  canvas::triggerChangeRecursive(_props);
-}
-
-//------------------------------------------------------------------------------
-void PropertyBasedMgr::shutdown()
-{
-  _props->removeChangeListener(this);
-}
-
-//------------------------------------------------------------------------------
-void PropertyBasedMgr::update(double delta_time_sec)
-{
-  for( size_t i = 0; i < _elements.size(); ++i )
-    if( _elements[i] )
-      _elements[i]->update(delta_time_sec);
-}
-
-//------------------------------------------------------------------------------
-void PropertyBasedMgr::childAdded( SGPropertyNode * parent,
-                                   SGPropertyNode * child )
-{
-  if( parent != _props || child->getNameString() != _name_elements )
-    return;
-
-  size_t index = child->getIndex();
-
-  if( index >= _elements.size() )
-  {
-    if( index > _elements.size() )
-      SG_LOG
-      (
-        SG_GENERAL,
-        SG_WARN,
-        "Skipping unused " << _name_elements << " slot(s)!"
-      );
-
-    _elements.resize(index + 1);
-  }
-  else if( _elements[index] )
-    SG_LOG
-    (
-      SG_GENERAL,
-      SG_WARN,
-      _name_elements << "[" << index << "] already exists!"
-    );
-
-  PropertyBasedElementPtr el = _element_factory(child);
-  el->_self = el;
-  _elements[index] = el;
-  elementCreated( el );
-}
-
-//------------------------------------------------------------------------------
-void PropertyBasedMgr::childRemoved( SGPropertyNode * parent,
-                                     SGPropertyNode * child )
-{
-  if( parent != _props )
-    return canvas::triggerRemoveRecursive(child);
-  else if( child->getNameString() != _name_elements )
-    return;
-
-  size_t index = child->getIndex();
-
-  if( index >= _elements.size() )
-    SG_LOG
-    (
-      SG_GENERAL,
-      SG_WARN,
-      "can't removed unknown " << _name_elements << "[" << index << "]!"
-    );
-  else
-    // remove the element...
-    _elements[index].reset();
-}
-
-//------------------------------------------------------------------------------
-const SGPropertyNode* PropertyBasedMgr::getPropertyRoot() const
-{
-  return _props;
-}
-
-//------------------------------------------------------------------------------
-PropertyBasedMgr::PropertyBasedMgr( const std::string& path_root,
-                                    const std::string& name_elements,
-                                    ElementFactory element_factory ):
-  _props( fgGetNode(path_root, true) ),
-  _name_elements( name_elements ),
-  _element_factory( element_factory )
-{
-
-}
-
-//------------------------------------------------------------------------------
-PropertyBasedMgr::~PropertyBasedMgr()
-{
-
-}
diff --git a/src/Canvas/property_based_mgr.hxx b/src/Canvas/property_based_mgr.hxx
deleted file mode 100644 (file)
index e80f85c..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-// Base class for all property controlled subsystems
-//
-// Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
-#ifndef PROPERTY_BASED_MGR_HXX_
-#define PROPERTY_BASED_MGR_HXX_
-
-#include "property_based_element.hxx"
-#include <simgear/structure/subsystem_mgr.hxx>
-
-#include <boost/shared_ptr.hpp>
-#include <boost/function.hpp>
-#include <vector>
-
-class PropertyBasedMgr:
-  public SGSubsystem,
-  public SGPropertyChangeListener
-{
-  public:
-    virtual void init();
-    virtual void shutdown();
-
-    virtual void update (double delta_time_sec);
-
-    virtual void childAdded( SGPropertyNode * parent,
-                             SGPropertyNode * child );
-    virtual void childRemoved( SGPropertyNode * parent,
-                               SGPropertyNode * child );
-
-    virtual void elementCreated(PropertyBasedElementPtr element) {}
-
-    virtual const SGPropertyNode* getPropertyRoot() const;
-
-  protected:
-
-    typedef boost::function<PropertyBasedElementPtr(SGPropertyNode*)>
-            ElementFactory;
-
-    /** Branch in the property tree for this property managed subsystem */
-    SGPropertyNode*      _props;
-
-    /** Property name of managed elements */
-    const std::string       _name_elements;
-
-    /** The actually managed elements */
-    std::vector<PropertyBasedElementPtr> _elements;
-
-    /** Function object which creates a new element */
-    ElementFactory          _element_factory;
-
-    /**
-     * @param path_root     Path to property branch used for controlling this
-     *                      subsystem
-     * @param name_elements The name of the nodes for the managed elements
-     */
-    PropertyBasedMgr( const std::string& path_root,
-                      const std::string& name_elements,
-                      ElementFactory element_factory );
-    virtual ~PropertyBasedMgr() = 0;
-
-};
-
-#endif /* PROPERTY_BASED_MGR_HXX_ */
index 3579ad6e1fcae980de87cd18ef68b588555f7d4b..5b35a970c1805831116ea3fc5b9c739d74495e05 100644 (file)
@@ -132,27 +132,4 @@ namespace canvas
     for( size_t i = 0; i < num_channels; ++i )
       nodes.push_back( getChildDefault(color, channels[i], def[i]) );
   }
-
-  //----------------------------------------------------------------------------
-  void triggerChangeRecursive(SGPropertyNode* node)
-  {
-    node->getParent()->fireChildAdded(node);
-
-    if( node->nChildren() == 0 && node->getType() != simgear::props::NONE )
-      return node->fireValueChanged();
-
-    for( int i = 0; i < node->nChildren(); ++i )
-      triggerChangeRecursive( node->getChild(i) );
-  }
-
-  //----------------------------------------------------------------------------
-  void triggerRemoveRecursive(SGPropertyNode* node)
-  {
-    for( int i = 0; i < node->nChildren(); ++i )
-    {
-      SGPropertyNode* child = node->getChild(i);
-      node->fireChildRemoved( child );
-      triggerRemoveRecursive( child );
-    }
-  }
 }
index 92e556afcfd617b7d90214d0d64af325103386e6..ff2d12451e115b1eca7cab0fee4d3d41409088ab 100644 (file)
@@ -92,18 +92,6 @@ namespace canvas
                        std::vector<SGPropertyNode_ptr>& nodes,
                        const osg::Vec4& def = osg::Vec4(0,0,0,1) );
 
-  /**
-   * Trigger a childAdded and valueChanged event for every child of node
-   * (Unlimited depth) and node itself.
-   */
-  void triggerChangeRecursive(SGPropertyNode* node);
-
-  /**
-   * Trigger a childRemoved event for every child of node (Unlimited depth) and
-   * node itself.
-   */
-  void triggerRemoveRecursive(SGPropertyNode* node);
-
 } // namespace canvas
 
 #endif /* PROPERTY_HELPER_HXX_ */
index cce5b1aa9c96792a1a8a437379bd51ba1035b2e2..fdc0eb513943ebac663d86958a88e5220a094cfd 100644 (file)
 #ifndef CANVAS_WINDOW_HXX_
 #define CANVAS_WINDOW_HXX_
 
-#include "property_based_element.hxx"
 #include <Canvas/elements/CanvasImage.hxx>
 #include <Canvas/MouseEvent.hxx>
 
+#include <simgear/props/PropertyBasedElement.hxx>
 #include <simgear/props/propertyObject.hxx>
 
 #include <osg/Geode>
@@ -31,7 +31,7 @@
 namespace canvas
 {
   class Window:
-    public PropertyBasedElement
+    public simgear::PropertyBasedElement
   {
     public:
       Window(SGPropertyNode* node);