NDEVR
API Documentation
DesignCommandManager.h
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/DesignCommand.h>
4#include <NDEVR/TranslatedString.h>
5#include <NDEVR/Dictionary.h>
6namespace NDEVR
7{
8 class Thread;
9 class RLock;
10 class WLock;
20 class NDEVR_DESIGN_API DesignCommandManager
21 {
22 public:
29
34
38 void clear();
39
45
51
57
62
63
69 //const Buffer<UUID>& finishedCommands() const { return m_undo_commands; };
70
75 const Buffer<UUID>& undoneCommands() const { return m_undone_commands; };
76
83 template<class t_type>
85 {
86 postCommand(command.template as<DesignCommand>());
87 }
88
95 virtual void postCommand(const DynamicPointer<DesignCommand>& command);
96
103 template<class t_type>
105 {
106 runCommand(command.template as<DesignCommand>());
107 }
108
113 virtual void runCommand(const DynamicPointer<DesignCommand>& command);
114
119 virtual void finishCommand(const DynamicPointer<DesignCommand>& command);
120
126 bool hasCommand(UUID id);
127
132 bool canUndo() const { return m_undo_commands.size() > 0; }
133
138 bool canRedo() const { return m_undone_commands.size() > 0; }
139
144 bool hasPendingCommands() const;
145
151
157
162 virtual void undoCommand(UUID command);
163
169
176
180 public:
182 protected:
187#if NDEVR_SUPPORTS_THREADING
190#endif
193 };
194}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Resource< bool > command_lock
Whether the command system is currently locked, preventing new commands.
virtual void postCommand(const DynamicPointer< DesignCommand > &command)
Posts a command for deferred execution.
Resource< UUID > command_id
The UUID of the currently active command.
LogPtr m_log
Logger for recording command execution, undo, and redo activity.
const DynamicPointer< DesignCommand > & lastPendingCommand() const
Returns the most recently posted pending command.
void executePendingCommands()
Executes all commands that have been posted but not yet run.
Resource< TranslatedString > command_name
The display name of the currently active command.
WLock tryCommandLock()
Attempts to acquire a write lock on the command system without blocking.
void runCommand(const DynamicPointer< t_type > &command)
Runs a typed command immediately.
Buffer< UUID > m_undo_commands
Stack of command UUIDs available for undo (most recent last).
Dictionary< UUID, DynamicPointer< DesignCommand > > m_commands
Map of all known commands keyed by their UUID.
virtual void runCommand(const DynamicPointer< DesignCommand > &command)
Runs a command immediately within the command system.
Buffer< UUID > redo()
Redoes the most recently undone command.
Resource< TranslatedString > command_hint
A user-facing hint or description for the currently active command.
Buffer< UUID > m_undone_commands
Stack of command UUIDs that have been undone and are available for redo.
DesignObjectLookup * m_lookup
The design object lookup used to resolve objects during command operations.
void postCommand(const DynamicPointer< t_type > &command)
Posts a typed command for deferred execution.
Buffer< UUID > m_thread_pending_commands
Commands posted from background threads, awaiting transfer to the main pending queue.
const DynamicPointer< DesignCommand > & getCommand(UUID command_id) const
Retrieves a command by its UUID.
WLock commandLock()
Acquires a write lock on the command system.
void clear()
Clears all stored commands, including undo, redo, and pending command histories.
RLock commandReadLock()
Acquires a read lock on the command system.
Buffer< UUID > undo()
Undoes the most recent command.
const Buffer< UUID > & undoneCommands() const
Returns the list of command UUIDs that have been undone and are available for redo.
Buffer< UUID > m_pending_commands
Queue of command UUIDs waiting to be executed.
bool hasPendingCommands() const
Checks whether there are any commands waiting to be executed.
bool canRedo() const
Checks whether there are any commands available to redo.
virtual ~DesignCommandManager()
Virtual destructor for proper cleanup of derived classes.
bool hasCommand(UUID id)
Checks whether a command with the given UUID exists in the manager.
virtual void finishCommand(const DynamicPointer< DesignCommand > &command)
Marks a command as finished after execution completes.
DesignCommandManager(DesignObjectLookup *lookup, InfoPipe *log)
Constructs a DesignCommandManager.
virtual void undoCommand(UUID command)
Undoes a specific command identified by its UUID.
Thread * m_command_thread
The thread used for asynchronous command execution.
virtual void executeCommand(DynamicPointer< DesignCommand > command)
Executes a command immediately within the command system.
bool canUndo() const
Checks whether there are any commands available to undo.
A core class where all Design Objects including models, materials, and geometries are stored.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
A light-weight base class for Log that allows processes to update, without the need for additional in...
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Used to lock a particular variable for reading.
Definition RWLock.h:157
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Resource.h:42
The default thread class for executing concurrent sequences in the NDEVR API.
Definition Thread.h:113
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.