MEUserCmdManager.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17
18#ifndef GAZEBO_GUI_MODEL_MEUSERCMDMANAGER_HH_
19#define GAZEBO_GUI_MODEL_MEUSERCMDMANAGER_HH_
20
21#include <map>
22#include <memory>
23#include <string>
24#include <utility>
25#include <vector>
26#include <sdf/sdf.hh>
27
28#include "gazebo/gui/qt.h"
31
32#include "gazebo/util/system.hh"
33
34namespace gazebo
35{
36 namespace gui
37 {
38 class UserCmdHistory;
39
40 // Forward declare private data.
41 class MEUserCmdPrivate;
42 class MEUserCmdManagerPrivate;
43
46 class GZ_GUI_VISIBLE MEUserCmd
47 {
50 public: enum CmdType
51 {
53 INSERTING_LINK = 0,
54
56 DELETING_LINK = 1,
57
59 INSERTING_NESTED_MODEL = 2,
60
62 DELETING_NESTED_MODEL = 3,
63
65 INSERTING_JOINT = 4,
66
68 DELETING_JOINT = 5,
69
71 MOVING_LINK = 6,
72
74 MOVING_NESTED_MODEL = 7,
75
77 SCALING_LINK = 8,
78
80 INSERTING_MODEL_PLUGIN = 9,
81
83 DELETING_MODEL_PLUGIN = 10
84 };
85
91 public: MEUserCmd(const unsigned int _id, const std::string &_description,
92 MEUserCmd::CmdType _type);
93
95 public: virtual ~MEUserCmd();
96
98 public: virtual void Undo();
99
101 public: virtual void Redo();
102
105 public: unsigned int Id() const;
106
109 public: std::string Description() const;
110
113 public: void SetSDF(sdf::ElementPtr _sdf);
114
117 public: void SetScopedName(const std::string &_name);
118
121 public: void SetJointId(const std::string &_id);
122
127 public: void SetPoseChange(const ignition::math::Pose3d &_before,
128 const ignition::math::Pose3d &_after);
129
133 public: void SetScaleChange(
134 const std::map<std::string, ignition::math::Vector3d> &_before,
135 const std::map<std::string, ignition::math::Vector3d> &_after);
136
139 protected: std::unique_ptr<MEUserCmdPrivate> dataPtr;
140 };
141
144 class GZ_GUI_VISIBLE MEUserCmdManager : public UserCmdHistory
145 {
146 Q_OBJECT
147
150
152 public: virtual ~MEUserCmdManager();
153
155 public: void Reset();
156
162 public: MEUserCmdPtr NewCmd(const std::string &_description,
163 const MEUserCmd::CmdType _type);
164
167 private slots: void OnUndoCommand(QAction *_action);
168
171 private slots: void OnRedoCommand(QAction *_action);
172
175 private: virtual bool HasUndo() const;
176
179 private: virtual bool HasRedo() const;
180
183 private: virtual std::vector<std::pair<unsigned int, std::string>>
184 Cmds(const bool _undo) const;
185
188 private: std::unique_ptr<MEUserCmdManagerPrivate> dataPtr;
189 };
190 }
191}
192#endif
193
194
gui
Definition KeyEventHandler.hh:29
Class which manages user commands in the model editor.
Definition MEUserCmdManager.hh:145
MEUserCmdPtr NewCmd(const std::string &_description, const MEUserCmd::CmdType _type)
Register that a new command has been executed by the user.
void Reset()
Reset commands.
virtual ~MEUserCmdManager()
Destructor.
Class which represents a user command, which can be "undone" and "redone".
Definition MEUserCmdManager.hh:47
void SetJointId(const std::string &_id)
Set the unique id of the joint related to this command.
std::string Description() const
Return this command's description.
void SetScaleChange(const std::map< std::string, ignition::math::Vector3d > &_before, const std::map< std::string, ignition::math::Vector3d > &_after)
Set the scale factors before and after the command.
virtual ~MEUserCmd()
Destructor.
void SetSDF(sdf::ElementPtr _sdf)
Set the SDF element relevant to this command.
MEUserCmd(const unsigned int _id, const std::string &_description, MEUserCmd::CmdType _type)
Constructor.
virtual void Redo()
Redo this command.
CmdType
Types of user commands.
Definition MEUserCmdManager.hh:51
@ DELETING_NESTED_MODEL
Delete a nested model.
Definition MEUserCmdManager.hh:62
@ DELETING_LINK
Delete a link.
Definition MEUserCmdManager.hh:56
@ DELETING_JOINT
Delete a joint.
Definition MEUserCmdManager.hh:68
@ INSERTING_NESTED_MODEL
Insert a nested model.
Definition MEUserCmdManager.hh:59
@ DELETING_MODEL_PLUGIN
Delete a model plugin.
Definition MEUserCmdManager.hh:83
@ INSERTING_JOINT
Insert a joint.
Definition MEUserCmdManager.hh:65
@ INSERTING_LINK
Insert a link.
Definition MEUserCmdManager.hh:53
@ MOVING_NESTED_MODEL
Move a nested model.
Definition MEUserCmdManager.hh:74
@ SCALING_LINK
Scale a link.
Definition MEUserCmdManager.hh:77
@ INSERTING_MODEL_PLUGIN
Insert a model plugin.
Definition MEUserCmdManager.hh:80
@ MOVING_LINK
Move a link.
Definition MEUserCmdManager.hh:71
void SetPoseChange(const ignition::math::Pose3d &_before, const ignition::math::Pose3d &_after)
Set the pose before and after the command.
std::unique_ptr< MEUserCmdPrivate > dataPtr
Definition MEUserCmdManager.hh:139
void SetScopedName(const std::string &_name)
Set the scoped name of the entity related to this command.
unsigned int Id() const
Return this command's unique ID.
virtual void Undo()
Undo this command.
Class which manages user commands in the client side.
Definition UserCmdHistory.hh:37
std::shared_ptr< MEUserCmd > MEUserCmdPtr
Definition ModelEditorTypes.hh:37
Forward declarations for the common classes.
Definition Animation.hh:27