1
2 //
3 // This source file is part of appleseed.
4 // Visit https://appleseedhq.net/ for additional information and resources.
5 //
6 // This software is released under the MIT license.
7 //
8 // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9 // Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 // THE SOFTWARE.
28 //
29
30 #pragma once
31
32 // appleseed.studio headers.
33 #include "mainwindow/project/attributeeditor.h"
34 #include "mainwindow/project/entitybrowser.h"
35 #include "mainwindow/project/entityeditor.h"
36 #include "mainwindow/project/entityeditorcontext.h"
37 #include "mainwindow/project/entityitem.h"
38 #include "mainwindow/project/projectbuilder.h"
39 #include "mainwindow/project/singlemodelentityeditorformfactory.h"
40 #include "mainwindow/project/tools.h"
41
42 // appleseed.renderer headers.
43 #include "renderer/api/entity.h"
44 #include "renderer/api/utility.h"
45
46 // appleseed.foundation headers.
47 #include "foundation/platform/compiler.h"
48 #include "foundation/utility/containers/dictionary.h"
49
50 // Standard headers.
51 #include <memory>
52 #include <string>
53
54 namespace appleseed {
55 namespace studio {
56
57 //
58 // Entity item class for single-model entities such as object instances,
59 // texture instances or environments.
60 //
61
62 template <typename Entity, typename ParentEntity, typename CollectionItem>
63 class SingleModelEntityItem
64 : public EntityItem<Entity, ParentEntity, CollectionItem>
65 {
66 public:
67 SingleModelEntityItem(
68 EntityEditorContext& editor_context,
69 Entity* entity,
70 ParentEntity& parent,
71 CollectionItem* collection_item);
72
73 foundation::Dictionary get_values() const override;
74
75 private:
76 typedef EntityItem<Entity, ParentEntity, CollectionItem> Base;
77 typedef typename renderer::EntityTraits<Entity> EntityTraitsType;
78
79 void slot_edit(AttributeEditor* attribute_editor) override;
80 };
81
82
83 //
84 // SingleModelEntityItem class implementation.
85 //
86
87 template <typename Entity, typename ParentEntity, typename CollectionItem>
SingleModelEntityItem(EntityEditorContext & editor_context,Entity * entity,ParentEntity & parent,CollectionItem * collection_item)88 SingleModelEntityItem<Entity, ParentEntity, CollectionItem>::SingleModelEntityItem(
89 EntityEditorContext& editor_context,
90 Entity* entity,
91 ParentEntity& parent,
92 CollectionItem* collection_item)
93 : Base(editor_context, entity, parent, collection_item)
94 {
95 }
96
97 template <typename Entity, typename ParentEntity, typename CollectionItem>
get_values()98 foundation::Dictionary SingleModelEntityItem<Entity, ParentEntity, CollectionItem>::get_values() const
99 {
100 return renderer::EntityTraits<Entity>::get_entity_values(Base::m_entity);
101 }
102
103 template <typename Entity, typename ParentEntity, typename CollectionItem>
slot_edit(AttributeEditor * attribute_editor)104 void SingleModelEntityItem<Entity, ParentEntity, CollectionItem>::slot_edit(AttributeEditor* attribute_editor)
105 {
106 if (!Base::allows_edition())
107 return;
108
109 typedef typename EntityTraitsType::FactoryType FactoryType;
110
111 std::unique_ptr<EntityEditor::IFormFactory> form_factory(
112 new SingleModelEntityEditorFormFactory(
113 Base::m_entity->get_name(),
114 FactoryType::get_input_metadata()));
115
116 std::unique_ptr<EntityEditor::IEntityBrowser> entity_browser(
117 new EntityBrowser<ParentEntity>(Base::m_parent));
118
119 if (attribute_editor)
120 {
121 attribute_editor->edit(
122 std::move(form_factory),
123 std::move(entity_browser),
124 std::unique_ptr<CustomEntityUI>(),
125 get_values(),
126 this,
127 SLOT(slot_edit_accepted(foundation::Dictionary)));
128 }
129 else
130 {
131 const std::string window_title =
132 std::string("Edit ") +
133 EntityTraitsType::get_human_readable_entity_type_name();
134
135 open_entity_editor(
136 QTreeWidgetItem::treeWidget(),
137 window_title,
138 Base::m_editor_context.m_project,
139 Base::m_editor_context.m_settings,
140 std::move(form_factory),
141 std::move(entity_browser),
142 get_values(),
143 this,
144 SLOT(slot_edit_accepted(foundation::Dictionary)),
145 SLOT(slot_edit_accepted(foundation::Dictionary)),
146 SLOT(slot_edit_accepted(foundation::Dictionary)));
147 }
148 }
149
150 } // namespace studio
151 } // namespace appleseed
152