File SBCUndoCommand.hpp#
FileList > Core > Undo > SBCUndoCommand.hpp
#include "SBCUndoExport.hpp"
#include "SBCMetaMacros.hpp"
#include "SBCMetaRegister.hpp"
#include "SBCReferencePointer.hpp"
#include <string>
Classes#
Type | Name |
---|---|
class | SBCUndoCommand This class is the base class of all commands that can undergo undo and redo operations. |
Public Types#
Type | Name |
---|---|
typedef SBCUndoCommand | SBUndoCommand The short name of SBCUndoCommand . |
Public Functions#
Type | Name |
---|---|
SB_REGISTER_TYPE (SBCUndoCommand, "SBUndoCommand", "FAA6289E-26BB-8061-4277-99D2816CC928") |
Macros#
Type | Name |
---|---|
define | SB_HOLD_ADD (ATTRIBUTE_OWNER_CLASS, ATTRIBUTE_NAME, NEW_VALUE, OWNER) Macro for holding the undo command implemented with SB_HOLD_ADD_IMPLEMENTATION. |
define | SB_HOLD_ADD_IMPLEMENTATION (ATTRIBUTE_OWNER_CLASS, ATTRIBUTE_TYPE, ATTRIBUTE_NAME, MESSAGE) Macro for creating a class for an undoable command to set for the first time a property ATTRIBUTE_NAME of typeATTRIBUTE_TYPE in a classATTRIBUTE_OWNER_CLASS . |
define | SB_HOLD_CLEAR (ATTRIBUTE_OWNER_CLASS, ATTRIBUTE_NAME, OLD_VALUE, OWNER) Macro for holding the undo command implemented with SB_HOLD_CLEAR_IMPLEMENTATION. |
define | SB_HOLD_CLEAR_IMPLEMENTATION (ATTRIBUTE_OWNER_CLASS, ATTRIBUTE_TYPE, ATTRIBUTE_NAME, MESSAGE) Macro for creating a class for an undoable command to clear a property ATTRIBUTE_NAME of typeATTRIBUTE_TYPE in a classATTRIBUTE_OWNER_CLASS . |
define | SB_HOLD_SET (ATTRIBUTE_OWNER_CLASS, ATTRIBUTE_NAME, OLD_VALUE, NEW_VALUE, OWNER) Macro for holding the undo command implemented with SB_HOLD_SET_IMPLEMENTATION. |
define | SB_HOLD_SET_IMPLEMENTATION (ATTRIBUTE_OWNER_CLASS, ATTRIBUTE_TYPE, ATTRIBUTE_NAME, MESSAGE) Macro for creating a class for an undoable command to set a property ATTRIBUTE_NAME of typeATTRIBUTE_TYPE in a classATTRIBUTE_OWNER_CLASS . |
define | SB_HOLD_SET_POINTER_IMPLEMENTATION (ATTRIBUTE_OWNER_CLASS, ATTRIBUTE_TYPE, ATTRIBUTE_NAME, MESSAGE) The specialized version of the SB_HOLD_SET_IMPLEMENTATION macro that stores internally the old and new values in SAMSON pointers of ATTRIBUTE_TYPE (i.e., SBPointer<ATTRIBUTE_TYPE>) to prevent the deletion of these objects. |
Public Types Documentation#
typedef SBUndoCommand#
The short name of SBCUndoCommand .
Public Functions Documentation#
function SB_REGISTER_TYPE#
Macro Definition Documentation#
define SB_HOLD_ADD#
Macro for holding the undo command implemented with SB_HOLD_ADD_IMPLEMENTATION.
If SAMSON is holding, i.e. this operation is encapsulated in SAMSON::beginHolding and SAMSON::endHolding, then it will create the corresponding undo command and pass there the new value (NEW_VALUE) and a pointer to the object (OWNER).
See also: SB_HOLD_ADD_IMPLEMENTATION
define SB_HOLD_ADD_IMPLEMENTATION#
Macro for creating a class for an undoable command to set for the first time a propertyATTRIBUTE_NAME
of typeATTRIBUTE_TYPE
in a classATTRIBUTE_OWNER_CLASS
.
#define SB_HOLD_ADD_IMPLEMENTATION (
ATTRIBUTE_OWNER_CLASS,
ATTRIBUTE_TYPE,
ATTRIBUTE_NAME,
MESSAGE
)
This is useful when the attribute can be cleared, e.g. when it is stored via a pointer or in some property map.
The created class can be used via the SB_HOLD_ADD macro. The name of the created class will be a concatenation of "add" + ATTRIBUTE_OWNER_CLASS + ATTRIBUTE_NAME + "Command".
Note that the owner is stored in SBPointer, so the class ATTRIBUTE_OWNER_CLASS needs to inherit from SBCReferenceTarget (see References).
Let's say we have the following functions in our class MyClass for changing and accessing the corresponding property:
bool hasInfo() const;
const std::string& getInfo() const;
void setInfo(const std::string& newValue);
void clearInfo();
Then to make the set
and clear
operations undoable , we can implement the following code in the source file for the set
and clear
functions:
// Create the undo command classes
SB_HOLD_SET_IMPLEMENTATION(MyClass, std::string, Info, "info");
SB_HOLD_ADD_IMPLEMENTATION(MyClass, std::string, Info, "info");
SB_HOLD_CLEAR_IMPLEMENTATION(MyClass, std::string, Info, "info");
void MyClass::setInfo(const std::string& newValue) {
if (hasInfo()) {
// Skip if the new value is the same as the current one
if (d->info == newValue) return;
// Use the convenience macro SB_HOLD_SET to make this operation undoable.
// If SAMSON is holding, i.e. this operation is encapsulated in SAMSON::beginHolding and SAMSON::endHolding,
// then it will create the command and pass there the old and new values, and a pointer to the object.
SB_HOLD_SET(MyClass, Info, getInfo(), newValue, this);
}
else {
// Create the storing value if necessary
if (this->info == nullptr)
this->info = new std::string();
// Use the convenience macro SB_HOLD_ADD to make this operation undoable.
// If SAMSON is holding, i.e. this operation is encapsulated in SAMSON::beginHolding and SAMSON::endHolding,
// then it will create the command and pass there the new value and a pointer to the object.
SB_HOLD_ADD(MyClass, Info, newValue, this);
}
// Set the new value
*this->info = newValue
}
void MyClass::clearInfo() {
if (hasInfo()) {
// Use the convenience macro SB_HOLD_CLEAR to make this operation undoable.
// If SAMSON is holding, i.e. this operation is encapsulated in SAMSON::beginHolding and SAMSON::endHolding,
// then it will create the command and pass there the old value and a pointer to the object.
SB_HOLD_CLEAR(MyClass, Info, getInfo(), this);
// Delete the property
delete this->info;
this->info = nullptr;
}
}
See also: SB_HOLD_ADD, SB_HOLD_CLEAR_IMPLEMENTATION, SB_HOLD_SET_IMPLEMENTATION
define SB_HOLD_CLEAR#
Macro for holding the undo command implemented with SB_HOLD_CLEAR_IMPLEMENTATION.
If SAMSON is holding, i.e. this operation is encapsulated in SAMSON::beginHolding and SAMSON::endHolding, then it will create the corresponding undo command and pass there the old value (OLD_VALUE) and a pointer to the object (OWNER).
See also: SB_HOLD_CLEAR_IMPLEMENTATION
define SB_HOLD_CLEAR_IMPLEMENTATION#
Macro for creating a class for an undoable command to clear a propertyATTRIBUTE_NAME
of typeATTRIBUTE_TYPE
in a classATTRIBUTE_OWNER_CLASS
.
#define SB_HOLD_CLEAR_IMPLEMENTATION (
ATTRIBUTE_OWNER_CLASS,
ATTRIBUTE_TYPE,
ATTRIBUTE_NAME,
MESSAGE
)
This is useful when the attribute can be cleared, e.g. when it is stored via a pointer or in some property map.
The created class can be used via the SB_HOLD_CLEAR macro. The name of the created class will be a concatenation of "clear" + ATTRIBUTE_OWNER_CLASS + ATTRIBUTE_NAME + "Command".
Please refer to SB_HOLD_ADD_IMPLEMENTATION for the usage example.
See also: SB_HOLD_CLEAR, SB_HOLD_ADD_IMPLEMENTATION, SB_HOLD_SET_IMPLEMENTATION
define SB_HOLD_SET#
Macro for holding the undo command implemented with SB_HOLD_SET_IMPLEMENTATION.
If SAMSON is holding, i.e. this operation is encapsulated in SAMSON::beginHolding and SAMSON::endHolding, then it will create the corresponding undo command and pass there the old value (OLD_VALUE), the new value (NEW_VALUE), and a pointer to the object (OWNER).
See also: SB_HOLD_SET_IMPLEMENTATION, SB_HOLD_SET_POINTER_IMPLEMENTATION
define SB_HOLD_SET_IMPLEMENTATION#
Macro for creating a class for an undoable command to set a propertyATTRIBUTE_NAME
of typeATTRIBUTE_TYPE
in a classATTRIBUTE_OWNER_CLASS
.
#define SB_HOLD_SET_IMPLEMENTATION (
ATTRIBUTE_OWNER_CLASS,
ATTRIBUTE_TYPE,
ATTRIBUTE_NAME,
MESSAGE
)
The created class can be used via the SB_HOLD_SET macro. The name of the created class will be a concatenation of "set" + ATTRIBUTE_OWNER_CLASS + ATTRIBUTE_NAME + "Command"
Note that the owner is stored in SBPointer, so the class ATTRIBUTE_OWNER_CLASS needs to inherit from SBCReferenceTarget (see References).
Let's say we have the following setter function in our class MyClass for changing the corresponding property:
Then to make the set
operation undoable , we can implement the following code in the source file for the set
function:
// Create the undo command class
SB_HOLD_SET_IMPLEMENTATION(MyClass, SBQuantity::length, Resolution, "resolution");
void MyClass::setResolution(const SBQuantity::length& newValue) {
// Skip if the new value is the same as the current one
if (newValue == this->resolution) return;
// Use the convenience macro SB_HOLD_SET to make this operation undoable.
// If SAMSON is holding, i.e. this operation is encapsulated in SAMSON::beginHolding and SAMSON::endHolding,
// then it will create the command and pass there the old and new values, and a pointer to the object.
SB_HOLD_SET(MyClass, Resolution, this->resolution, newValue, this);
this->resolution = newValue;
}
See also: SB_HOLD_SET, SB_HOLD_SET_POINTER_IMPLEMENTATION, SB_HOLD_ADD_IMPLEMENTATION, SB_HOLD_CLEAR_IMPLEMENTATION
define SB_HOLD_SET_POINTER_IMPLEMENTATION#
The specialized version of the SB_HOLD_SET_IMPLEMENTATION macro that stores internally the old and new values in SAMSON pointers of ATTRIBUTE_TYPE (i.e., SBPointer<ATTRIBUTE_TYPE>) to prevent the deletion of these objects.
#define SB_HOLD_SET_POINTER_IMPLEMENTATION (
ATTRIBUTE_OWNER_CLASS,
ATTRIBUTE_TYPE,
ATTRIBUTE_NAME,
MESSAGE
)
Note that the class ATTRIBUTE_TYPE should derive from SBCReferenceTarget.
Let's say we have the following setter function in our class MyClass for setting the current structural model:
void setCurrentStructuralModel(SBStructuralModel* model);
// Note: internally in MyClass we store the model in SBPointer as well
SBPointer<SBStructuralModel> currentStructuralModel;
Then to make the set
operation undoable , we can implement the following code in the source file for the set
function:
// Create the undo command class
SB_HOLD_SET_IMPLEMENTATION(MyClass, SBStructuralModel, CurrentStructuralModel, "current structural model");
void MyClass::setCurrentStructuralModel(SBStructuralModel* model) {
// Skip if the new model is the same as the current one
if (model == this->currentStructuralModel()) return;
// Use the convenience macro SB_HOLD_SET to make this operation undoable.
// If SAMSON is holding, i.e. this operation is encapsulated in SAMSON::beginHolding and SAMSON::endHolding,
// then it will create the command and pass there the old and new values, and a pointer to the object.
SB_HOLD_SET(MyClass, CurrentStructuralModel, this->currentStructuralModel(), model, this);
this->currentStructuralModel = model;
}
See also: SB_HOLD_SET