NDEVR
API Documentation
NewModelCommand.h
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/DesignCommand.h>
4#include <NDEVR/DesignObjectLookup.h>
5#include <NDEVR/TranslatedString.h>
6namespace NDEVR
7{
14 {
15 public:
19 NewModelCommand(const TranslatedString& name, const std::function<void(Model& model)>& on_finished)
21 , on_create(on_finished)
23 {}
24
28 virtual StringView icon() const override
29 {
30 return "new";
31 }
32
36 virtual TranslatedString name() const override
37 {
38 return _t("New");
39 }
40
50 virtual void execute(DesignObjectLookup* lookup) override
51 {
52 if (is_undo)
53 {
54 WLock lock(lookup->writeLock());
55 for(UUID target_id : targets)
56 lookup->deleteObject(target_id);
57 targets.clear();
58 }
59 else
60 {
61 if (targets.size() > 0)
62 {
63 WLock lock(lookup->writeLock());
64 for (uint04 i = 0; i < targets.size(); i++)
65 {
66 if (lookup->hasModelID(targets[i], true))
67 {
68 lookup->restoreModel(targets[i]);
69 }
70 else
71 {
72 Scene scene(model_name);
73 if (on_create)
74 on_create(scene);
75 scene.set<NDPO::guid>(targets[i]);
76 lookup->addScene(scene);
78 finished_callback(scene);
79 }
80 }
81
82 }
83 else if (IsInvalid(parent_id))
84 {
85 Scene scene(model_name);
86 if (on_create)
87 on_create(scene);
88 WLock lock(lookup->writeLock());
89 lookup->addScene(scene);
90 targets.add(scene.get<NDPO::guid>());
92 finished_callback(scene);
93 }
94 else
95 {
96 WLock lock(lookup->writeLock());
97 Model parent(lookup->model(parent_id));
98 Model model = parent.createChild();
100 if (on_create)
101 on_create(model);
102 lookup->addModel(model);
103 parent.updateModifiedTime();
104 targets.add(model.get<NDPO::guid>());
106 finished_callback(model);
107
108 }
109
110 }
111 }
112
117 virtual bool addTarget(UUID target_id) override { targets.add(target_id); return true; }
118 public:
119 std::function<void(Model& model)> on_create;
120 std::function<void(Model& model)> finished_callback;
124 };
125}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
DesignCommand()
Default constructor.
bool is_undo
Whether this command represents an undo operation.
A core class where all Design Objects including models, materials, and geometries are stored.
virtual void addModel(Model object)
Registers a model in the lookup.
virtual void deleteObject(UUID id)
Marks a design object as deleted by its UUID.
virtual void addScene(Scene scene, bool add_all_scene_models=true)
Adds a scene to the lookup and optionally registers all of its models.
bool hasModelID(const UUID &id, bool allow_deleted=false) const
Checks whether a model with the given UUID exists.
Model model(const UUID &id, bool allow_deleted=false) const
Retrieves a model by its UUID.
virtual Model restoreModel(UUID id)
Restores a previously deleted model back into the lookup.
WLock writeLock() const
Acquires an exclusive write lock on the design object store.
constexpr decltype(auto) get(t_property_type property) const
Retrieves a property value from the database, cast to the requested type.
void set(t_property_type property, const t_type &value)
Sets a property value in the database.
A core class that represents a node on model hierarchy.
Definition Model.h:292
void updateModifiedTime(Time time=Time::SystemTime())
Updates the modified timestamp for this model.
Model createChild()
Creates a new child model and appends it to this model's child list.
std::function< void(Model &model)> on_create
Callback invoked on the model immediately after creation, before it is added to the lookup.
virtual bool addTarget(UUID target_id) override
Adds a target UUID to this command's target list.
virtual void execute(DesignObjectLookup *lookup) override
Executes the new model command against the given lookup.
TranslatedString model_name
The display name assigned to the newly created model.
UUID parent_id
The UUID of the parent model. If invalid, a top-level Scene is created instead.
NewModelCommand(const TranslatedString &name, const std::function< void(Model &model)> &on_finished)
Creates a model with the specified name and calls on_finished at the end of the command.
virtual TranslatedString name() const override
Returns the display name of this command.
std::function< void(Model &model)> finished_callback
Callback invoked after the model has been fully created and added to the lookup.
virtual StringView icon() const override
Returns the icon identifier for this command.
Buffer< UUID > targets
The UUIDs of models created by this command, used for undo/redo tracking.
The root Model that is responsible for storing the underlying data for all Scene Models.
Definition Scene.h:52
The core String View class for the NDEVR API.
Definition StringView.h:58
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
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
@ name
The calculated/translated display name.
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
Definition Angle.h:388
@ guid
A 128-bit globally unique identifier for the object.