1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/*
* Copyright 2019 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "sdf/Scene.hh"
#include "Utils.hh"
using namespace sdf;
/// \brief Scene private data.
class sdf::ScenePrivate
{
/// \brief True if grid should be enabled
public: bool grid = true;
/// \brief True if shadows should be enabled
public: bool shadows = true;
/// \brief True if originVisual should be enabled
public: bool originVisual = true;
/// \brief Ambient light color of the scene.
public: ignition::math::Color ambient =
ignition::math::Color(0.4f, 0.4f, 0.4f);
/// \brief Background color of the scene.
public: ignition::math::Color background =
ignition::math::Color(0.7f, 0.7f, .7f);
/// \brief The SDF element pointer used during load.
public: sdf::ElementPtr sdf;
};
/////////////////////////////////////////////////
Scene::Scene()
: dataPtr(new ScenePrivate)
{
}
/////////////////////////////////////////////////
Scene::~Scene()
{
delete this->dataPtr;
this->dataPtr = nullptr;
}
/////////////////////////////////////////////////
Scene::Scene(const Scene &_scene)
: dataPtr(new ScenePrivate(*_scene.dataPtr))
{
}
/////////////////////////////////////////////////
Scene::Scene(Scene &&_scene) noexcept
: dataPtr(std::exchange(_scene.dataPtr, nullptr))
{
}
/////////////////////////////////////////////////
Scene &Scene::operator=(const Scene &_scene)
{
return *this = Scene(_scene);
}
/////////////////////////////////////////////////
Scene &Scene::operator=(Scene &&_scene)
{
std::swap(this->dataPtr, _scene.dataPtr);
return *this;
}
/////////////////////////////////////////////////
Errors Scene::Load(ElementPtr _sdf)
{
Errors errors;
this->dataPtr->sdf = _sdf;
// Check that the provided SDF element is a <scene> element.
// This is an error that cannot be recovered, so return an error.
if (_sdf->GetName() != "scene")
{
errors.push_back({ErrorCode::ELEMENT_INCORRECT_TYPE,
"Attempting to load a Scene, but the provided SDF element is not a "
"<scene>."});
return errors;
}
// Get the ambient property
this->dataPtr->ambient= _sdf->Get<ignition::math::Color>("ambient",
this->dataPtr->ambient).first;
// Get the background color property
this->dataPtr->background = _sdf->Get<ignition::math::Color>("background",
this->dataPtr->background).first;
// Get the grid property
this->dataPtr->grid = _sdf->Get<bool>("grid",
this->dataPtr->grid).first;
// Get the shadows property
this->dataPtr->shadows = _sdf->Get<bool>("shadows",
this->dataPtr->shadows).first;
// Get the origin_visual property
this->dataPtr->originVisual = _sdf->Get<bool>("origin_visual",
this->dataPtr->originVisual).first;
return errors;
}
/////////////////////////////////////////////////
ignition::math::Color Scene::Ambient() const
{
return this->dataPtr->ambient;
}
/////////////////////////////////////////////////
void Scene::SetAmbient(const ignition::math::Color &_ambient)
{
this->dataPtr->ambient = _ambient;
}
/////////////////////////////////////////////////
ignition::math::Color Scene::Background() const
{
return this->dataPtr->background;
}
/////////////////////////////////////////////////
void Scene::SetBackground(const ignition::math::Color &_background)
{
this->dataPtr->background = _background;
}
/////////////////////////////////////////////////
bool Scene::Grid() const
{
return this->dataPtr->grid;
}
/////////////////////////////////////////////////
void Scene::SetGrid(const bool _enabled)
{
this->dataPtr->grid = _enabled;
}
/////////////////////////////////////////////////
bool Scene::Shadows() const
{
return this->dataPtr->shadows;
}
/////////////////////////////////////////////////
void Scene::SetShadows(const bool _enabled)
{
this->dataPtr->shadows = _enabled;
}
/////////////////////////////////////////////////
bool Scene::OriginVisual() const
{
return this->dataPtr->originVisual;
}
/////////////////////////////////////////////////
void Scene::SetOriginVisual(const bool _enabled)
{
this->dataPtr->originVisual = _enabled;
}
/////////////////////////////////////////////////
sdf::ElementPtr Scene::Element() const
{
return this->dataPtr->sdf;
}
|