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{
9 {
10 public:
11 NewModelCommand(const TranslatedString& name, const std::function<void(Model& model)>& model)
13 , on_create(model)
15 {}
16 virtual String icon() const override
17 {
18 return "new";
19 }
20 virtual TranslatedString name() const override
21 {
22 return _t("New");
23 }
24 virtual void execute(DesignObjectLookup* lookup) override
25 {
26 if (is_undo)
27 {
28 WLock lock(lookup->writeLock());
29 for(UUID target_id : targets)
30 lookup->deleteObject(target_id);
31 targets.clear();
32 }
33 else
34 {
35 if (targets.size() > 0)
36 {
37 WLock lock(lookup->writeLock());
38 for (uint04 i = 0; i < targets.size(); i++)
39 {
40 if (lookup->hasModelID(targets[i], true))
41 {
42 lookup->restoreModel(targets[i]);
43 }
44 else
45 {
46 Scene scene(model_name);
47 if (on_create)
48 on_create(scene);
50 lookup->addScene(scene);
52 finished_callback(scene);
53 }
54 }
55
56 }
57 else if (isNaN(parent_id))
58 {
59 Scene scene(model_name);
60 if (on_create)
61 on_create(scene);
62 WLock lock(lookup->writeLock());
63 lookup->addScene(scene);
64 targets.add(scene.uuid());
66 finished_callback(scene);
67 }
68 else
69 {
70 WLock lock(lookup->writeLock());
71 Model parent(lookup->model(parent_id));
72 Model model = parent.createChild();
74 if (on_create)
75 on_create(model);
76 lookup->addModel(model);
77 parent.updateModifiedTime();
78 targets.add(model.uuid());
80 finished_callback(model);
81
82 }
83
84 }
85 }
86 std::function<void(Model& model)> on_create;
87 std::function<void(Model& model)> finished_callback;
91 };
92}
#define _t(english_string)
Definition Translator.h:87
Definition DesignCommand.h:46
bool is_undo
Definition DesignCommand.h:65
Buffer< UUID > targets
Definition DesignCommand.h:62
UUID uuid() const
Definition DesignObject.cpp:533
void setProperty(DesignProperty property, const t_type &value)
Definition DesignObject.h:184
@ e_name
Definition DesignObject.h:100
@ e_guid
Definition DesignObject.h:95
Definition DesignObjectLookup.h:61
bool hasModelID(const UUID &id, bool allow_deleted=false) const
Definition DesignObjectLookup.cpp:1815
virtual void addScene(Scene scene, bool ignore_application_scene=false)
Definition DesignObjectLookup.cpp:215
virtual Model restoreModel(UUID id)
Definition DesignObjectLookup.cpp:820
WLock writeLock()
Definition DesignObjectLookup.cpp:965
Model model(const UUID &id, bool allow_deleted=false) const
Definition DesignObjectLookup.cpp:1683
virtual void addModel(Model object)
Definition DesignObjectLookup.cpp:268
virtual void deleteObject(UUID id)
Definition DesignObjectLookup.cpp:724
Definition Model.h:54
void updateModifiedTime(Time time=Time::SystemTime())
Definition Model.cpp:2289
Model createChild()
Definition Model.cpp:3020
Definition NewModelCommand.h:9
std::function< void(Model &model)> on_create
Definition NewModelCommand.h:86
String type
Definition NewModelCommand.h:90
virtual void execute(DesignObjectLookup *lookup) override
Definition NewModelCommand.h:24
virtual TranslatedString name() const override
Definition NewModelCommand.h:20
TranslatedString model_name
Definition NewModelCommand.h:88
NewModelCommand(const TranslatedString &name, const std::function< void(Model &model)> &model)
Definition NewModelCommand.h:11
UUID parent_id
Definition NewModelCommand.h:89
virtual String icon() const override
Definition NewModelCommand.h:16
std::function< void(Model &model)> finished_callback
Definition NewModelCommand.h:87
Definition Model.h:491
Definition String.h:40
Definition TranslatedString.h:9
Definition UUID.h:66
Definition RWLock.h:99
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200