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 <memory>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 #include <sdf/sdf.hh>
26 
27 #include "gazebo/gui/qt.h"
30 
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace gui
36  {
37  class UserCmdHistory;
38 
39  // Forward declare private data.
40  class MEUserCmdPrivate;
41  class MEUserCmdManagerPrivate;
42 
45  class GZ_GUI_VISIBLE MEUserCmd
46  {
49  public: enum CmdType
50  {
52  INSERTING_LINK = 0,
53 
55  DELETING_LINK = 1,
56 
58  INSERTING_NESTED_MODEL = 2,
59 
61  DELETING_NESTED_MODEL = 3,
62 
64  INSERTING_JOINT = 4,
65 
67  DELETING_JOINT = 5
68  };
69 
75  public: MEUserCmd(const unsigned int _id, const std::string &_description,
76  MEUserCmd::CmdType _type);
77 
79  public: virtual ~MEUserCmd();
80 
82  public: virtual void Undo();
83 
85  public: virtual void Redo();
86 
89  public: unsigned int Id() const;
90 
93  public: std::string Description() const;
94 
97  public: void SetSDF(sdf::ElementPtr _sdf);
98 
101  public: void SetScopedName(const std::string &_name);
102 
105  public: void SetJointId(const std::string &_id);
106 
109  protected: std::unique_ptr<MEUserCmdPrivate> dataPtr;
110  };
111 
114  class GZ_GUI_VISIBLE MEUserCmdManager : public UserCmdHistory
115  {
116  Q_OBJECT
117 
119  public: MEUserCmdManager();
120 
122  public: virtual ~MEUserCmdManager();
123 
125  public: void Reset();
126 
132  public: MEUserCmdPtr NewCmd(const std::string &_description,
133  const MEUserCmd::CmdType _type);
134 
137  private slots: void OnUndoCommand(QAction *_action);
138 
141  private slots: void OnRedoCommand(QAction *_action);
142 
145  private: virtual bool HasUndo() const;
146 
149  private: virtual bool HasRedo() const;
150 
153  private: virtual std::vector<std::pair<unsigned int, std::string>>
154  Cmds(const bool _undo) const;
155 
158  private: std::unique_ptr<MEUserCmdManagerPrivate> dataPtr;
159  };
160  }
161 }
162 #endif
163 
164 
std::unique_ptr< MEUserCmdPrivate > dataPtr
Definition: MEUserCmdManager.hh:109
Class which represents a user command, which can be "undone" and "redone".
Definition: MEUserCmdManager.hh:45
std::shared_ptr< MEUserCmd > MEUserCmdPtr
Definition: ModelEditorTypes.hh:37
Class which manages user commands in the model editor.
Definition: MEUserCmdManager.hh:114
CmdType
Types of user commands.
Definition: MEUserCmdManager.hh:49
Class which manages user commands in the client side.
Definition: UserCmdHistory.hh:36