NDEVR
API Documentation
BuildActionProgramLogic.h
1#pragma once
2#include "BuildActions.h"
3#include "BuildActionWidget.h"
4#include "BuildActionItemsWidget.h"
5#include "BuildActionUISetupWidget.h"
6#include <NDEVR/CustomModelLogic.h>
7#include <NDEVR/QTWindowManager.h>
8#include <NDEVR/SceneTreeWidget.h>
9#include <NDEVR/Ribbon.h>
10#include <NDEVR/RibbonSubGroup.h>
11#include <NDEVR/RibbonGroup.h>
12#include <NDEVR/NDEVRRibbon.h>
13#include <NDEVR/SceneTree.h>
14#include <NDEVR/DesignObjectDialog.h>
15#include <NDEVR/QTIconManager.h>
16#include <NDEVR/Button.h>
17#include <NDEVR/QTTools.h>
18#include <QPointer>
19namespace NDEVR
20{
24 {
25 public:
31 , m_window_manager(window_manager)
32 {
33 setSorter([](const Model& a, const Model& b)
34 {
35 Model parent_a = a.getParent();
36 Model parent_b = b.getParent();
37 if (parent_a == parent_b && parent_a.isValid())
38 return a.getChildIndex() > b.getChildIndex();
39 else
40 return a.get<NDPO::creation_time>()
42 });
43 }
44
48 {
49 Button* b = new Button(definition.displayName()
50 , definition.getIcon()
51 , [definition, this](Button* b)
52 {
53 ShowPropertiesSettings settings(definition.get<NDPO::guid>(), b);
54 m_window_manager->showModelProperties(settings);
55 });
56 m_buttons[definition.get<NDPO::guid>()].add(b);
57 return b;
58 }
59
61 bool canBeHandledBySelectionWidget() const override
62 {
63 return false;
64 }
65
67 void setupUI(const BuildActionDefinition& definition)
68 {
69 if (m_buttons.hasKey(definition.get<NDPO::guid>()))
70 {
71 for (auto iter : m_buttons[definition.get<NDPO::guid>()])
72 {
73 if (!iter.isNull())
74 delete iter;
75 }
76 m_buttons.clear();
77 m_window_manager->ribbon()->ribbon()->cleanupEmpty();
78 }
79 BuildActionUIDefinition ui = definition.uiDefinition();
81 m_window_manager->sceneTree()->widget().addButton(createButton(definition));
82 if (ui.show_on_ribbon)
83 {
84 String group = ui.ribbon_group;
85 RibbonGroup* ribbon_group = nullptr;
86 if (group.size() == 0)
87 ribbon_group = m_window_manager->ribbon()->homeRibbonGroup();
88 else
89 ribbon_group = &m_window_manager->ribbon()->ribbon()->group(TranslatedString(group));
90 String sub_group = ui.ribbon_sub_group;
91 if (sub_group.size() == 0)
92 sub_group = "General";
93 RibbonSubGroup& ribbon_sub_group = (*ribbon_group)[TranslatedString(sub_group)];
94 ribbon_sub_group.addButton(createButton(definition), Constant<uint04>::Invalid, true);
95 }
96 }
97 //Override the below to add custom program behavior
98 protected:
99 //Adds menu items to context menus when model of type is selected
100 QAction* m_run_menu_action = nullptr;
101 QAction* m_create_new_action_before = nullptr;
102 QAction* m_create_new_action_after = nullptr;
103 QAction* m_create_child_action = nullptr;
104 virtual void addMenuItems(Model& model, QTModelManager*, QMenu& menu, const Buffer<UUID>&, const SelectionInfo&) override
105 {
106 m_run_menu_action = menu.addAction(QTIconManager::GetIconResourceBlocking("play"), _tqa("Run"));
107 BuildActionDefinition definition(model);
108 switch (definition.action())
109 {
115 m_create_child_action = menu.addAction(QTIconManager::GetIconResourceBlocking("plus"), _tqa("Create Child Action"));
116 break;
117 default:
118 m_create_child_action = nullptr;
119 break;
120 }
121 Model parent = model.getParent();
122 if (parent.isValid())
123 {
124 m_create_new_action_before = menu.addAction(QTIconManager::GetIconResourceBlocking("plus"), _tqa("Create Action Before"));
125 m_create_new_action_after = menu.addAction(QTIconManager::GetIconResourceBlocking("plus"), _tqa("Create Action After"));
126 }
127 else
128 {
131 }
132 }
133 //executes menu items to context menus when model of type is selected
134 void executeMenuItems(Model& model, QTModelManager* manager, QAction* action, const Buffer<UUID>&, const SelectionInfo&, PopupInfo info) override
135 {
136 if (action == m_run_menu_action)
137 {
139 LogPtr info_pipe = manager->logManager()->getLog(definition.defaultLogName());
140 definition.executeThreaded(manager->lockPtr(), info_pipe);
141 }
142 if (action == m_create_child_action)
143 {
144 createAndShowChildDefinition(model, info);
145 }
146 if (action == m_create_new_action_before || action == m_create_new_action_after)
147 {
148 WLock lock = manager->writeLock();
149 Model parent = model.getParent();
150 if (!parent.isValid())
151 return;
152 uint04 idx = model.getChildIndex();
153 if (action == m_create_new_action_after)
154 idx++;
155 BuildActionDefinition definition(parent.createChild(idx));
156 parent.updateModifiedTime();
157 manager->addModel(definition);
159 manager->ShowProperties(settings);
160 }
161 }
162 //modifies property dialogs when objects are created
163 virtual void setupPropertiesDialog(DesignObjectDialog* dialog, const DynamicPointer<QTDesignObject>& object) override
164 {
165 dialog->addTabDialog(new BuildActionWidget(object));
166 dialog->addTabDialog(new BuildActionItemsWidget(object));
167 dialog->addTabDialog(new BuildActionUISetupWidget(object, this));
168 }
169 //performs any needed setup for the model when it is read in via ndv file
170 virtual void setupModel(Model& model) override
171 {
173 return;
174 BuildActionDefinition def(model);
175 def.set<NDPO::application_locked>(false);
176 def.set<NDPN::model_color>(Constant<RGBColor>::Invalid);
178 }
179 //custom buttons that appear when selected or selected with the tree
180 virtual void setTreeWidgetsForSelection(const Model& model, Buffer<QWidget*>& widgets, SceneTree* tree) override
181 {
182 widgets.setSize(1);
183 if (m_play_button == nullptr)
184 {
185 m_play_button = new Button(_t("Run"), "play", [this, tree](Button*)
186 {
188 LogPtr info = tree->manager()->logManager()->getLog(definition.defaultLogName());
189 definition.executeThreaded(tree->manager()->lockPtr(), info);
190 });
191 m_play_button->setButtonState(Button::e_small);
192 m_play_button->setFlat(true);
193 }
194 BuildActionDefinition definition(model);
195 switch (definition.action())
196 {
202 {
203 m_create_child_button = new Button(_t("Create Child"), "new", [this, tree](Button* b)
204 {
206 });
207 m_create_child_button->setButtonState(Button::e_small);
208 m_create_child_button->setFlat(true);
209 widgets.add(m_create_child_button);
210 }
211 default:
212 break;
213 }
214 m_last_model = model;
215 widgets.add(m_play_button);
216 };
217
221 {
222 WLock lock = m_manager->writeLock();
223 auto definition = BuildActionDefinition(model).createChildBuildDefinition();
224 m_manager->addModel(definition);
226 m_manager->ShowProperties(settings);
227 }
233 };
234
235}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:190
A Model subclass that defines a single build action or workflow step, holding its action type,...
BuildActionUIDefinition uiDefinition() const
Returns the UI definition for this action.
void executeThreaded(const void *lock_ptr, LogPtr log=nullptr)
Executes this action on a background thread.
String defaultLogName() const
Returns the default log name for this action.
BuildActionDefinition createChildBuildDefinition()
Creates a new child build action definition under this one.
BuildAction action() const
Returns the build action type.
static constexpr StringView TypeName()
Returns the type name used for model registration.
Editor widget for configuring the detail items of a build action such as failure behavior and conditi...
void executeMenuItems(Model &model, QTModelManager *manager, QAction *action, const Buffer< UUID > &, const SelectionInfo &, PopupInfo info) override
Override to handle execution of custom context menu actions.
Dictionary< UUID, Buffer< QPointer< Button > > > m_buttons
Maps action UUIDs to their UI buttons.
Button * m_create_child_button
Create-child button for the tree widget.
virtual void addMenuItems(Model &model, QTModelManager *, QMenu &menu, const Buffer< UUID > &, const SelectionInfo &) override
Override to add custom context menu items when a model of this type is selected.
BuildActionProgramLogic(QTWindowManager *window_manager, QTModelManager *manager)
Constructs the build action program logic.
void createAndShowChildDefinition(Model &model, PopupInfo info)
Creates a child build action definition under the given model and shows its editor.
Button * m_play_button
Play button for the tree widget.
virtual void setupModel(Model &model) override
Override to perform setup when a model of this type is read from an NDV file.
virtual void setupPropertiesDialog(DesignObjectDialog *dialog, const DynamicPointer< QTDesignObject > &object) override
Override to customize property dialogs when objects of this type are created.
QAction * m_create_child_action
Context menu action to create a child action.
void setupUI(const BuildActionDefinition &definition)
Sets up ribbon and tree buttons for the given build action definition.
QAction * m_run_menu_action
Context menu action to run the build action.
bool canBeHandledBySelectionWidget() const override
Returns whether this model type can be handled by the generic selection widget.
QAction * m_create_new_action_before
Context menu action to insert an action before.
QTWindowManager * m_window_manager
The window manager for UI operations.
QAction * m_create_new_action_after
Context menu action to insert an action after.
Model m_last_model
The most recently selected model.
Button * createButton(const BuildActionDefinition &definition)
Creates a button that opens the property dialog for the given build action.
virtual void setTreeWidgetsForSelection(const Model &model, Buffer< QWidget * > &widgets, SceneTree *tree) override
Override to provide custom tree widgets shown when the model is selected.
Editor widget for configuring how a build action is presented in the UI, such as ribbon placement and...
The primary editor widget for configuring a build action definition, including action type selection,...
A core widget that allows the user to click one of many button types.
Definition Button.h:68
@ e_small
Small button with icon only.
Definition Button.h:80
QTModelManager * m_manager
The model manager providing data context.
void setSorter(const std::function< bool(const Model &a, const Model &b)> &sort_function)
Sets a custom sorting function for models of this type.
CustomModelLogic(QTModelManager *manager, const StringView &type_name)
Constructs a CustomModelLogic for a single model type name.
A popup dialog for showing options or information to the user for a particular DesignObject.
void addTabDialog(QWidget *editor, uint04 index=Constant< uint04 >::Invalid)
Adds a generic widget as a tab in the dialog.
const void * lockPtr() const
Returns a raw pointer to the internal lock primitive.
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.
bool isValid() const
Checks whether this design object has a valid index into the database.
bool is(t_property_type property, const StringView &value) const
Checks whether a string property matches the given StringView value.
StringView getIcon() const
Retrieves the icon identifier string associated with this design object.
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
InfoPipe * getLog(const StringView &log_name) const
Retrieves the log pipe associated with the given name.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
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.
TranslatedString displayName() const
Returns the translated display name for this model.
Model getParent() const
Returns the parent model of this model.
Model createChild()
Creates a new child model and appends it to this model's child list.
uint04 getChildIndex(uint04 child) const
Returns the database index of the child at the given slot.
static QIcon GetIconResourceBlocking(const StringView &icon, QIcon::Mode mode=QIcon::Mode::Normal)
Synchronously fetches an icon resource using the current theme.
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
virtual void ShowProperties(const ShowPropertiesSettings &settings)
Shows a properties dialog for a design object.
virtual LogManager * logManager() const override
Retrieves the log manager used for diagnostic output.
virtual void addModel(Model object) override
Adds a model to the manager and emits appropriate signals.
Manages all windows and logic surrounding dialogs and views for displaying and managing a 3D environm...
Represents the "Tab" of a widget.
Definition RibbonGroup.h:52
Represents a sub-section of "Tab" of a ribbon representing a grouping of buttons or widgets within a ...
Button * addButton(Button *button, uint04 index=Constant< uint04 >::Invalid, bool update_layout=false)
Adds a button to this sub-group at the specified index.
Shows all objects in a QTModelManager in a tree hierarchy view that allows for user interaction.
Definition SceneTree.h:54
QTModelManager * manager() const
Retrieves the model manager used by this tree.
Responsible for turning a user interaction into a selection within a DesignObjectLookup.
Definition Selector.h:52
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
Definition Model.h:58
@ model_color
The color assigned directly to this model node.
Definition Model.h:68
@ e_process_files
Processes files with child actions.
@ e_workflow
A container action that executes child actions sequentially.
@ e_variable_loop
Loops over a set of variable values.
@ e_file_loop
Loops over files matching a pattern.
@ e_index_loop
Loops over a range of integer indices.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
@ creation_time
Timestamp when the object was created.
@ guid
A 128-bit globally unique identifier for the object.
@ application_locked
Whether the application has locked this object from editing.
@ e_object_creation
Dialog for creating a new object.
Describes how a build action should be presented in the application UI, including ribbon and tree pla...
String ribbon_sub_group
The ribbon sub-group name.
bool show_on_ribbon
Whether to show a button on the ribbon.
String ribbon_group
The ribbon group name to place the action in.
bool show_at_bottom_of_tree
Whether to show the action at the bottom of the tree.
Class which is used to pass arguments and requests for creating a popup dialog or widget.
Definition PopupInfo.h:16
Stores settings for setting up and displaying a DesignObjectDialog such as whether the dialog is part...