compatibility.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, Fizyr BV
3  * Copyright (c) 2019, Bielefeld University
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the Willow Garage, Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef OGRE_HELPERS_COMPATIBILITY_H
32 #define OGRE_HELPERS_COMPATIBILITY_H
33 
35 #include <OgreSimpleRenderable.h>
36 #include <OgreSceneNode.h>
37 
38 #if OGRE_VERSION < OGRE_VERSION_CHECK(1, 10, 8)
39 #include <OgreSceneManager.h>
40 #else
41 #include <OgreMaterialManager.h>
42 #endif
43 
44 #include <string>
45 
46 namespace rviz
47 {
48 /* This header provides helper functions to maintain compatibility with Ogre versions 1.9 ... 1.12+.
49  *
50  * setMaterial() allows setting the material of a renderable by either name or MaterialPtr.
51  * OGRE 1.10.8 added: renderable.setMaterial(const Ogre::MaterialPtr &)
52  * OGRE 1.11 removed: renderable.setMaterial(const std::string &)
53  *
54  * removeAndDestroyChildNode(parent, child) allows removal of a SceneNode*.
55  * OGRE 1.10.8 added: SceneNode::removeAndDestroyChild(SceneNode* child)
56  */
57 
58 #if OGRE_VERSION < OGRE_VERSION_CHECK(1, 10, 8)
59 inline void setMaterial(Ogre::SimpleRenderable& renderable, const std::string& material_name)
60 {
61  renderable.setMaterial(material_name);
62 }
63 
64 inline void setMaterial(Ogre::SimpleRenderable& renderable, const Ogre::MaterialPtr& material)
65 {
66  renderable.setMaterial(material->getName());
67 }
68 #else
69 inline void setMaterial(Ogre::SimpleRenderable& renderable, const std::string& material_name)
70 {
71  Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(material_name);
72  // OGRE 1.11 also deprecated their own SharedPtr class and switched to std::shared_ptr.
73  // Checking for nullptr with .get() works in both versions.
74  if (!material.get())
75  {
76  OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Could not find material " + material_name,
77  "SimpleRenderable::setMaterial");
78  }
79  renderable.setMaterial(material);
80 }
81 
82 inline void setMaterial(Ogre::SimpleRenderable& renderable, const Ogre::MaterialPtr& material)
83 {
84  renderable.setMaterial(material);
85 }
86 #endif
87 
88 #if OGRE_VERSION < OGRE_VERSION_CHECK(1, 10, 8)
89 inline void removeAndDestroyChildNode(Ogre::SceneNode* parent, Ogre::SceneNode* child)
90 {
91  child->removeAndDestroyAllChildren();
92  parent->removeChild(child);
93  child->getCreator()->destroySceneNode(child);
94 }
95 #else
96 inline void removeAndDestroyChildNode(Ogre::SceneNode* parent, Ogre::SceneNode* child)
97 {
98  parent->removeAndDestroyChild(child);
99 }
100 #endif
101 } // namespace rviz
102 
103 #endif
version_check.h
rviz::setMaterial
void setMaterial(Ogre::SimpleRenderable &renderable, const std::string &material_name)
Definition: compatibility.h:69
rviz::removeAndDestroyChildNode
void removeAndDestroyChildNode(Ogre::SceneNode *parent, Ogre::SceneNode *child)
Definition: compatibility.h:96
rviz
Definition: add_display_dialog.cpp:54


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:09