##

BuildingMaker.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 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.
*
*/
#ifndef _GAZEBO_GUI_BUILDING_BUILDINGMAKER_HH_
#define _GAZEBO_GUI_BUILDING_BUILDINGMAKER_HH_
#include <string>
#include <vector>
#include <memory>
#include <ignition/math/Pose3.hh>
#include <ignition/math/Vector3.hh>
#include "gazebo/common/KeyEvent.hh"
#include "gazebo/common/MouseEvent.hh"
#include "gazebo/gui/qt.h"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace gui
{
class BuildingModelManip;
class EditorItem;
// Forward declare provate data.
class BuildingMakerPrivate;
class GZ_GUI_VISIBLE BuildingMaker
{
public: BuildingMaker();
public: ~BuildingMaker();
public: void OnEdit(bool _checked);
public: void SetModelName(const std::string &_modelName);
public: void FinishModel();
public: std::string AddPart(const std::string &_type,
const QVector3D &_size, const QVector3D &_pos, double _angle);
public: std::string AddWall(const QVector3D &_size, const QVector3D &_pos,
double _angle);
public: std::string AddWindow(const QVector3D &_size,
const QVector3D &_pos, double _angle);
public: std::string AddDoor(const QVector3D &_size, const QVector3D &_pos,
double _angle);
public: std::string AddStairs(const QVector3D &_size,
const QVector3D &_pos, double _angle, int _steps);
public: std::string AddFloor(const QVector3D &_size,
const QVector3D &_pos, double _angle);
public: void RemovePart(const std::string &_partName);
public: void RemoveWall(const std::string &_wallName);
public: void ConnectItem(const std::string &_partName,
const EditorItem *_item);
public: void AttachManip(const std::string &_child,
const std::string &_parent);
public: void DetachFromParent(const std::string &_child);
public: void DetachAllChildren(const std::string &_parent);
public: bool IsAttached(const std::string &_child) const;
public: BuildingModelManip *ManipByName(const std::string &_name);
public: static ignition::math::Vector3d ConvertSize(
const double _width, const double _depth, const double _height);
public: static ignition::math::Pose3d ConvertPose(const double _x,
const double _y, const double _z, const double _roll,
const double _pitch, const double _yaw);
public: static double Convert(double _value);
public: static double ConvertAngle(double _angle);
public: void Reset();
public: void GenerateSDF();
public: void BuildingChanged();
public: std::string ModelSDF() const;
private: void CreateTheEntity();
private: bool Init();
private: std::string CreateModel();
private: void GenerateSDFWithCSG();
private: std::string TemplateSDFString() const;
private: static bool PointCompareY(const QPointF &_a, const QPointF &_b);
private: static bool RectCompareX(const QRectF &_a, const QRectF &_b);
private: static bool RectCompareY(const QRectF &_a, const QRectF &_b);
private: void SubdivideRectSurface(const QRectF &_surface,
const std::vector<QRectF> &_holes, std::vector<QRectF> &_subdivisions);
private: void SaveModelFiles();
private: bool OnSave();
private: bool OnSaveAs();
private: void OnNameChanged(const std::string &_modelName);
private: void OnNew();
private: void OnExit();
private: void OnChangeLevel(int _level);
private: void StopMaterialModes();
private: void ResetHoverVis();
private: void OnColorSelected(QColor _color);
private: void OnTextureSelected(QString _texture);
private: bool On3dMouseMove(const common::MouseEvent &_event);
private: bool On3dMousePress(const common::MouseEvent &_event);
private: bool On3dMouseRelease(const common::MouseEvent &_event);
private: bool On3dKeyPress(const common::KeyEvent &_event);
public: static const double conversionScale;
private: std::unique_ptr<BuildingMakerPrivate> dataPtr;
};
}
}
#endif
gazebo::gui::BuildingMaker::GenerateSDF
void GenerateSDF()
Generate the SDF from building part visuals.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::gui::BuildingMaker::OnEdit
void OnEdit(bool _checked)
QT callback when entering or leaving building edit mode.
qt.h
gazebo::gui::EditorItem
Base class of an item in the editor.
Definition: EditorItem.hh:42
gazebo::gui::BuildingMaker::ConvertAngle
static double ConvertAngle(double _angle)
Convert an angle from editor unit to Gazebo unit.
gazebo::gui::BuildingMaker::ManipByName
BuildingModelManip * ManipByName(const std::string &_name)
Detach all child building parts from the given manip.
gazebo::gui::BuildingMaker::ConnectItem
void ConnectItem(const std::string &_partName, const EditorItem *_item)
Connect the 2D editor item Qt signals to the 3D building part.
gazebo::gui::BuildingMaker::AddFloor
std::string AddFloor(const QVector3D &_size, const QVector3D &_pos, double _angle)
Add a floor to the model.
gazebo::gui::BuildingMaker::SetModelName
void SetModelName(const std::string &_modelName)
Set the name of this building model.
gazebo::msgs::Convert
GAZEBO_VISIBLE msgs::Vector3d Convert(const ignition::math::Vector3d &_v)
Convert a ignition::math::Vector3 to a msgs::Vector3d.
system.hh
gazebo::gui::BuildingMaker::ConvertPose
static ignition::math::Pose3d ConvertPose(const double _x, const double _y, const double _z, const double _roll, const double _pitch, const double _yaw)
Helper method to convert pose from editor coordinate system to Gazebo coordinate system.
gazebo::gui::BuildingMaker::~BuildingMaker
~BuildingMaker()
Destructor.
gazebo::gui::BuildingMaker::RemoveWall
void RemoveWall(const std::string &_wallName)
Remove a wall from the model.
gazebo::gui::BuildingMaker::AddDoor
std::string AddDoor(const QVector3D &_size, const QVector3D &_pos, double _angle)
Add a door to the model.
gazebo::gui::BuildingMaker::AddWall
std::string AddWall(const QVector3D &_size, const QVector3D &_pos, double _angle)
Add a wall to the model.
gazebo::gui::BuildingMaker::DetachAllChildren
void DetachAllChildren(const std::string &_parent)
Detach all child building parts from the given manip.
gazebo::gui::BuildingMaker::conversionScale
static const double conversionScale
Conversion scale used by the Convert helper functions.
Definition: BuildingMaker.hh:303
gazebo::gui::BuildingMaker::FinishModel
void FinishModel()
Finish the model and create the entity on the gzserver.
gazebo::gui::BuildingMaker::BuildingMaker
BuildingMaker()
Constructor.
gazebo::gui::BuildingMaker::ConvertSize
static ignition::math::Vector3d ConvertSize(const double _width, const double _depth, const double _height)
Helper method to convert size from editor coordinate system to Gazebo coordinate system.
gazebo::gui::BuildingMaker
Create and manage 3D visuals of a building.
Definition: BuildingMaker.hh:48
gazebo::common::KeyEvent
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::gui::BuildingModelManip
Manipulate a 3D visual associated to a 2D editor item.
Definition: BuildingModelManip.hh:43
gazebo::gui::BuildingMaker::AddStairs
std::string AddStairs(const QVector3D &_size, const QVector3D &_pos, double _angle, int _steps)
Add a staircase to the model.
gui
gui
Definition: KeyEventHandler.hh:29
KeyEvent.hh
gazebo::gui::BuildingMaker::Reset
void Reset()
Reset the building maker and the SDF.
gazebo::gui::BuildingMaker::AddWindow
std::string AddWindow(const QVector3D &_size, const QVector3D &_pos, double _angle)
Add a window to the model.
gazebo::gui::BuildingMaker::ModelSDF
std::string ModelSDF() const
Get the last generated SDF as string.
gazebo::gui::BuildingMaker::IsAttached
bool IsAttached(const std::string &_child) const
Whether the given manip is attached to another manip or not.
gazebo::gui::BuildingMaker::RemovePart
void RemovePart(const std::string &_partName)
Remove a building part from the model.
gazebo::gui::BuildingMaker::AttachManip
void AttachManip(const std::string &_child, const std::string &_parent)
Attach a building part to another, this is currently used for making holes in walls and floors.
gazebo::gui::BuildingMaker::DetachFromParent
void DetachFromParent(const std::string &_child)
Detach a child building part from its parent.
gazebo::gui::BuildingMaker::Convert
static double Convert(double _value)
gazebo::gui::BuildingMaker::AddPart
std::string AddPart(const std::string &_type, const QVector3D &_size, const QVector3D &_pos, double _angle)
Add a building part to the model.
MouseEvent.hh
gazebo::common::MouseEvent
Generic description of a mouse event.
Definition: MouseEvent.hh:35
gazebo::gui::BuildingMaker::BuildingChanged
void BuildingChanged()
Set save state upon a change to the building.