SDFormat Editor
Loading...
Searching...
No Matches
command_factory.h
1/*
2* sdformat-editor
3* Copyright 2025 sdformat-editor
4*
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*
17* Developer: Zaid Duraid, Ean Wheeler, Evan Vokey
18*/
19
20#ifndef COMMAND_FACTORY_HH_
21#define COMMAND_FACTORY_HH_
22
23// SDFormat dependencies
24#include <sdf/sdf.hh>
25#include "interfaces/command_factory_interface.h"
26
27// Commands
28#include "commands/DeleteElementCommand.h"
29#include "commands/OpenFileCommand.h"
30#include "commands/SaveFileCommand.h"
31#include "commands/DeleteElementCommand.h"
32#include "commands/GenericCommand.h"
33#include "commands/OpenFileCommand.h"
34#include "commands/CreateFileCommand.h"
35#include "commands/ModifyAttributeCommand.h"
36#include "commands/ModifyElementCommand.h"
37#include "commands/AddElementCommand.h"
38#include "commands/RenderModelCommand.h"
39#include "commands/OpenModelViewerCommand.h"
40#include "commands/CloseModelViewerCommand.h"
41
44{
45
50 public: CommandFactory(std::shared_ptr<GUII> gui, std::shared_ptr<SDFormatParserI> sdformatParser,
51 std::shared_ptr<ModelViewerI> model_viewer);
52
57 private: void Initialize(std::shared_ptr<GUII> gui, std::shared_ptr<SDFormatParserI> sdformatParser,
58 std::shared_ptr<ModelViewerI> model_viewer);
59
63 private: std::unique_ptr<CommandI> MakeOpenFileCommand(std::string file_path) override;
64
68 private: std::unique_ptr<CommandI> MakeDeleteElementCommand(sdf::ElementPtr element_to_delete) override;
69
74 private: std::unique_ptr<CommandI> MakeAddElementCommand(
75 sdf::ElementPtr parent_element, sdf::ElementPtr new_element) override;
76
79 private: std::unique_ptr<CommandI> MakeSaveFileCommand() override;
80
84 private: std::unique_ptr<CommandI> MakeRenderModelCommand(bool render_collisions_in_model_viewer) override;
85
88 public: std::unique_ptr<CommandI> MakeOpenModelViewerCommand() override;
89
92 public: std::unique_ptr<CommandI> MakeCloseModelViewerCommand() override;
93
96 private: std::unique_ptr<CommandI> MakeCreateFileCommand() override;
97
100 private: std::unique_ptr<CommandI> MakeUndoCommand() override;
101
104 private: std::unique_ptr<CommandI> MakeRedoCommand() override;
105
110 private: std::unique_ptr<CommandI> MakeModifyAttributeCommand(sdf::ParamPtr attribute_to_modify, std::string new_value) override;
111
116 private: std::unique_ptr<CommandI> MakeModifyAttributeCommand(sdf::ParamPtr attribute_to_modify, bool new_value) override;
117
122 private: std::unique_ptr<CommandI> MakeModifyElementCommand(sdf::ElementPtr element_to_modify, std::string new_value) override;
123
128 private: std::unique_ptr<CommandI> MakeModifyElementCommand(sdf::ElementPtr element_to_modify, bool new_value) override;
129
131 private: void ClearStack(std::stack<std::unique_ptr<CommandI>>& stack);
132
134 private: void ClearUndoRedoStacks() override;
135
139 private: void PushToUndoCommandsStack(std::unique_ptr<CommandI> command, const bool new_change = true) override;
140
143 private: void PushToRedoCommandsStack(std::unique_ptr<CommandI> command) override;
144
146 private: void PopFromUndoCommandsStack();
147
149 private: void PopFromRedoCommandsStack();
150
152 private: std::shared_ptr<GUII> gui;
153
155 private: std::shared_ptr<SDFormatParserI> sdformatParser;
156
158 private: std::shared_ptr<ModelViewerI> model_viewer;
159
161 std::stack<std::unique_ptr<CommandI>> undo_commands_stack;
162
164 std::stack<std::unique_ptr<CommandI>> redo_commands_stack;
165};
166
167#endif
Interface for the SDFormat Editor's Command Factory.
Definition command_factory_interface.h:37
Implementation of CommandFactoryI.
Definition command_factory.h:44
std::unique_ptr< CommandI > MakeOpenModelViewerCommand() override
Create a open model viewer model command.
Definition command_factory.cpp:46
std::unique_ptr< CommandI > MakeDeleteElementCommand(sdf::ElementPtr element_to_delete) override
Implementation of interface method.
Definition command_factory.cpp:66
std::shared_ptr< GUII > gui
Pointer to the GUI obejct.
Definition command_factory.h:152
std::unique_ptr< CommandI > MakeModifyElementCommand(sdf::ElementPtr element_to_modify, std::string new_value) override
Implementation of interface method.
Definition command_factory.cpp:79
void PushToUndoCommandsStack(std::unique_ptr< CommandI > command, const bool new_change=true) override
Pushes to the undo commands stack.
Definition command_factory.cpp:98
std::unique_ptr< CommandI > MakeRedoCommand() override
Implementation of interface method.
Definition command_factory.cpp:61
std::unique_ptr< CommandI > MakeSaveFileCommand() override
Implementation of interface method.
Definition command_factory.cpp:153
std::unique_ptr< CommandI > MakeUndoCommand() override
Implementation of interface method.
Definition command_factory.cpp:56
std::unique_ptr< CommandI > MakeCloseModelViewerCommand() override
Create a close model viewer model command.
Definition command_factory.cpp:93
std::shared_ptr< ModelViewerI > model_viewer
Pointer to the model viewer object.
Definition command_factory.h:158
void PopFromUndoCommandsStack()
Pops from the undo commands stack and executes the popped command.
Definition command_factory.cpp:112
std::stack< std::unique_ptr< CommandI > > redo_commands_stack
Stack for redo functionality.
Definition command_factory.h:164
std::stack< std::unique_ptr< CommandI > > undo_commands_stack
Stack for undo functionality.
Definition command_factory.h:161
std::unique_ptr< CommandI > MakeRenderModelCommand(bool render_collisions_in_model_viewer) override
Implementation of interface method.
Definition command_factory.cpp:41
void ClearUndoRedoStacks() override
Implementation of interface method.
Definition command_factory.cpp:139
void Initialize(std::shared_ptr< GUII > gui, std::shared_ptr< SDFormatParserI > sdformatParser, std::shared_ptr< ModelViewerI > model_viewer)
Implementation of interface method, wrapped by constructor.
Definition command_factory.cpp:28
void PushToRedoCommandsStack(std::unique_ptr< CommandI > command) override
Pushes to the redo commands stack.
Definition command_factory.cpp:107
void PopFromRedoCommandsStack()
Pops from the redo commands stack and executes the popped command.
Definition command_factory.cpp:125
std::shared_ptr< SDFormatParserI > sdformatParser
Pointer to the sdformat parser object.
Definition command_factory.h:155
std::unique_ptr< CommandI > MakeAddElementCommand(sdf::ElementPtr parent_element, sdf::ElementPtr new_element) override
Create an add element command.
Definition command_factory.cpp:87
std::unique_ptr< CommandI > MakeModifyAttributeCommand(sdf::ParamPtr attribute_to_modify, std::string new_value) override
Implementation of interface method.
Definition command_factory.cpp:71
void ClearStack(std::stack< std::unique_ptr< CommandI > > &stack)
Clears the undo stack.
Definition command_factory.cpp:145
std::unique_ptr< CommandI > MakeCreateFileCommand() override
Implementation of interface method.
Definition command_factory.cpp:51
std::unique_ptr< CommandI > MakeOpenFileCommand(std::string file_path) override
Implementation of interface method.
Definition command_factory.cpp:36