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 
34 namespace 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 
149  public: MEUserCmdManager();
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 
std::unique_ptr< MEUserCmdPrivate > dataPtr
Definition: MEUserCmdManager.hh:139
Class which represents a user command, which can be "undone" and "redone".
Definition: MEUserCmdManager.hh:46
std::shared_ptr< MEUserCmd > MEUserCmdPtr
Definition: ModelEditorTypes.hh:37
Class which manages user commands in the model editor.
Definition: MEUserCmdManager.hh:144
CmdType
Types of user commands.
Definition: MEUserCmdManager.hh:50
Class which manages user commands in the client side.
Definition: UserCmdHistory.hh:36