API Documentation
Loading...
Searching...
No Matches
NewModelCommand.h
Go to the documentation of this file.
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{
8 /**--------------------------------------------------------------------------------------------------
9 \brief A DesignCommand that creates a new Model to some specification
10 **/
12 {
13 public:
14 NewModelCommand(const TranslatedString& name, const std::function<void(Model& model)>& model)
16 , on_create(model)
18 {}
19 virtual String icon() const override
20 {
21 return "new";
22 }
23 virtual TranslatedString name() const override
24 {
25 return _t("New");
26 }
27 virtual void execute(DesignObjectLookup* lookup) override
28 {
29 if (is_undo)
30 {
31 WLock lock(lookup->writeLock());
32 for(UUID target_id : targets)
33 lookup->deleteObject(target_id);
34 targets.clear();
35 }
36 else
37 {
38 if (targets.size() > 0)
39 {
40 WLock lock(lookup->writeLock());
41 for (uint04 i = 0; i < targets.size(); i++)
42 {
43 if (lookup->hasModelID(targets[i], true))
44 {
45 lookup->restoreModel(targets[i]);
46 }
47 else
48 {
49 Scene scene(model_name);
50 if (on_create)
51 on_create(scene);
53 lookup->addScene(scene);
55 finished_callback(scene);
56 }
57 }
58
59 }
60 else if (IsInvalid(parent_id))
61 {
62 Scene scene(model_name);
63 if (on_create)
64 on_create(scene);
65 WLock lock(lookup->writeLock());
66 lookup->addScene(scene);
67 targets.add(scene.uuid());
69 finished_callback(scene);
70 }
71 else
72 {
73 WLock lock(lookup->writeLock());
74 Model parent(lookup->model(parent_id));
75 Model model = parent.createChild();
77 if (on_create)
78 on_create(model);
79 lookup->addModel(model);
80 parent.updateModifiedTime();
81 targets.add(model.uuid());
83 finished_callback(model);
84
85 }
86
87 }
88 }
89 std::function<void(Model& model)> on_create;
90 std::function<void(Model& model)> finished_callback;
94 };
95}
#define _t(english_string)
Definition Translator.h:90
A command for safely modifying something in a DesignObjectLookup. Modifications will be done in a sep...
Definition DesignCommand.h:52
bool is_undo
Definition DesignCommand.h:71
Buffer< UUID > targets
Definition DesignCommand.h:68
UUID uuid() const
void setProperty(DesignProperty property, const t_type &value)
Definition DesignObject.h:177
@ e_name
Definition DesignObject.h:99
@ e_guid
Definition DesignObject.h:94
A core class where all Design Objects including models, materials, and geometries are stored....
Definition DesignObjectLookup.h:65
virtual void deleteObject(UUID id)
virtual Model restoreModel(UUID id)
bool hasModelID(const UUID &id, bool allow_deleted=false) const
Model model(const UUID &id, bool allow_deleted=false) const
virtual void addModel(Model object)
virtual void addScene(Scene scene, bool ignore_application_scene=false)
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
void updateModifiedTime(Time time=Time::SystemTime())
Model createChild()
A DesignCommand that creates a new Model to some specification.
Definition NewModelCommand.h:12
std::function< void(Model &model)> on_create
Definition NewModelCommand.h:89
String type
Definition NewModelCommand.h:93
virtual void execute(DesignObjectLookup *lookup) override
Definition NewModelCommand.h:27
virtual TranslatedString name() const override
Definition NewModelCommand.h:23
TranslatedString model_name
Definition NewModelCommand.h:91
NewModelCommand(const TranslatedString &name, const std::function< void(Model &model)> &model)
Definition NewModelCommand.h:14
UUID parent_id
Definition NewModelCommand.h:92
virtual String icon() const override
Definition NewModelCommand.h:19
std::function< void(Model &model)> finished_callback
Definition NewModelCommand.h:90
The root Model that is responsible for storing the underlying data for all Scene Models.
Definition Model.h:492
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
Used to lock a particular variable for writing. Only one write lock can be created when no read locks...
Definition RWLock.h:115
Definition ACIColor.h:37
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96