NDEVR
API Documentation
DesignCommand.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: DesignCommand
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/UUID.h>
35#include <NDEVR/Resource.h>
36#include <NDEVR/Pointer.h>
37#include <NDEVR/String.h>
38#include <NDEVR/Time.h>
39#include <NDEVR/InfoPipe.h>
40#include <NDEVR/TranslatedString.h>
41namespace NDEVR
42{
43
44 class RWLock;
45 class DesignObjectLookup;
46
55 {
56 public:
58 NDEVR_DESIGN_API DesignCommand();
61 NDEVR_DESIGN_API DesignCommand(const DesignCommand& command) = default;
63 virtual ~DesignCommand(){};
68 virtual void execute(DesignObjectLookup*) {};
74 virtual bool canGroupWith(const DynamicPointer<DesignCommand>&) { return false; }
80 virtual bool canCombineWith(const DynamicPointer<DesignCommand>&) { return false; };
85 virtual bool isAsyncExecution() const { return false; };
91 virtual bool addTarget(UUID) { return false; }
96 NDEVR_DESIGN_API virtual void combineWith(const DynamicPointer<DesignCommand>& command);
101 NDEVR_DESIGN_API void setUndoRedoID(UUID undo_redo_group);
106 NDEVR_DESIGN_API UUID undoRedoID() const;
111 virtual TranslatedString name() const = 0;
116 virtual StringView icon() const = 0;
117 public:
119 Time time = Constant<Time>::Invalid;
121 bool has_executed = false;
122 bool is_undo = false;
123 bool can_undo = true;
125 protected:
127 };
128
135 {
136 public:
140
152 NDEVR_DESIGN_API DesignCommandGroup(std::initializer_list<DynamicPointer<DesignCommand>> l);
162 NDEVR_DESIGN_API virtual TranslatedString name() const override;
167 NDEVR_DESIGN_API virtual StringView icon() const override;
172 NDEVR_DESIGN_API virtual void execute(DesignObjectLookup* lookup) override;
177 template<class t_type>
179 {
180 m_group.add(val.template as<DesignCommand>());
181 }
182
186 template<class t_type>
187 void add(t_type&& val)
188 {
189 add(DynamicPointer<t_type>(std::move(val)));
190 }
191
196 NDEVR_DESIGN_API virtual bool addTarget(UUID id) override;
201 NDEVR_DESIGN_API virtual bool isAsyncExecution() const override;
202 private:
203 TranslatedString m_name;
204 String m_icon;
206 };
207}
208
209
210
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
DesignCommandGroup(const TranslatedString &name, StringView icon=StringView())
Constructs a command group with a display name and optional icon.
DesignCommandGroup(const Buffer< DynamicPointer< DesignCommand > > &buffer)
Constructs a command group from a buffer of commands.
void add(t_type &&val)
Adds a command to this group via move semantics.
virtual TranslatedString name() const override
Gets the display name of this command group.
virtual void execute(DesignObjectLookup *lookup) override
Executes all commands in this group sequentially against the given lookup.
void add(const DynamicPointer< t_type > &val)
Adds a command to this group via a DynamicPointer.
DesignCommandGroup(std::initializer_list< DynamicPointer< DesignCommand > > l)
Constructs a command group from an initializer list of commands.
virtual ~DesignCommandGroup()
Virtual destructor.
virtual bool addTarget(UUID id) override
Adds a target UUID to all commands in this group.
DesignCommandGroup()
Default constructor.
virtual bool isAsyncExecution() const override
Checks whether any command in this group requires async execution.
virtual StringView icon() const override
Gets the icon identifier for this command group.
bool update_project_modified
Whether executing this command should mark the project as modified.
DesignCommand(const DesignCommand &command)=default
Default copy constructor.
virtual void combineWith(const DynamicPointer< DesignCommand > &command)
Combines this command with another compatible command, merging their operations.
DesignCommand()
Default constructor.
virtual bool canCombineWith(const DynamicPointer< DesignCommand > &)
Checks whether this command can be combined with another command into a single operation.
void setUndoRedoID(UUID undo_redo_group)
Sets the undo-redo group identifier for this command.
bool has_executed
Whether this command has already been executed.
Time time
Timestamp of when the command was created or executed.
UUID id
Unique identifier for this command instance.
virtual void execute(DesignObjectLookup *)
Executes this command against the given DesignObjectLookup.
LogPtr log
Log pipe for reporting command progress and errors.
virtual bool canGroupWith(const DynamicPointer< DesignCommand > &)
Checks whether this command can be grouped with another command for batch execution.
bool can_undo
Whether this command supports being undone.
virtual TranslatedString name() const =0
Gets the human-readable name of this command for display in the UI.
bool is_undo
Whether this command represents an undo operation.
virtual bool addTarget(UUID)
Adds a target object by UUID to this command.
UUID undoRedoID() const
Gets the undo-redo group identifier for this command.
virtual ~DesignCommand()
Virtual destructor.
virtual bool isAsyncExecution() const
Whether this command should be executed asynchronously.
virtual StringView icon() const =0
Gets the icon identifier for this command.
UUID m_undo_redo_group
The undo-redo group this command belongs to, for batch undo/redo.
A core class where all Design Objects including models, materials, and geometries are stored.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
A readers-writer lock allowing concurrent reads or exclusive writes.
Definition RWLock.h:49
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
The primary namespace for the NDEVR SDK.