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/entityactions.h"
34 #include "mainwindow/project/instancecollectionitem.h"
35 #include "mainwindow/project/itembase.h"
36 #include "mainwindow/project/singlemodelentityitem.h"
37 
38 // appleseed.foundation headers.
39 #include "foundation/platform/compiler.h"
40 
41 // Qt headers.
42 #include <QList>
43 #include <QObject>
44 
45 // Forward declarations.
46 namespace appleseed     { namespace studio { class EntityEditorContext; } }
47 namespace appleseed     { namespace studio { class ObjectInstanceItem; } }
48 namespace foundation    { class Dictionary; }
49 namespace renderer      { class Assembly; }
50 namespace renderer      { class ObjectInstance; }
51 class QMenu;
52 class QString;
53 class QVariant;
54 
55 namespace appleseed {
56 namespace studio {
57 
58 typedef InstanceCollectionItem<
59     renderer::ObjectInstance,
60     ObjectInstanceItem,
61     renderer::Assembly
62 > ObjectInstanceCollectionItem;
63 
64 class ObjectInstanceItem
65   : public SingleModelEntityItem<renderer::ObjectInstance, renderer::Assembly, ObjectInstanceCollectionItem>
66 {
67     Q_OBJECT
68 
69   public:
70     // The name of the default material slot, when the object does not have any slot.
71     static const char* DefaultSlotName;
72 
73     ObjectInstanceItem(
74         EntityEditorContext&            editor_context,
75         renderer::ObjectInstance*       object_instance,
76         renderer::Assembly&             parent,
77         ObjectInstanceCollectionItem*   collection_item);
78 
79     const renderer::Assembly& get_assembly() const;
80 
81     QMenu* get_single_item_context_menu() const override;
82     QMenu* get_multiple_items_context_menu(const QList<ItemBase*>& items) const override;
83 
84     void assign_material(
85         const QString&                  page_name,
86         const QString&                  entity_name,
87         const QVariant&                 untyped_data);
88 
89     void clear_material(const QVariant& untyped_data);
90 
91     void update_style();
92 
93   private slots:
94     void slot_assign_new_disney_material();
95     void slot_open_material_assignment_editor();
96     void slot_assign_material();
97     void slot_assign_material_accepted(QString page_name, QString entity_name, QVariant data);
98     void slot_clear_material();
99 
100   private:
101     friend class EntityDeletionAction<ObjectInstanceItem>;
102     friend class AssignNewDisneyMaterialAction;
103 
104     typedef SingleModelEntityItem<renderer::ObjectInstance, renderer::Assembly, ObjectInstanceCollectionItem> Base;
105 
106     void delete_multiple(const QList<ItemBase*>& items) override;
107     void do_delete();
108 
109     void add_material_assignment_menu_actions(
110         QMenu*                          menu,
111         const QList<ItemBase*>&         items = QList<ItemBase*>()) const;
112 
113     void add_material_assignment_menu_actions(
114         QMenu*                          menu,
115         const char*                     slot,
116         const QList<ItemBase*>&         items) const;
117 
118     void do_assign_material(
119         const char*                     slot_name,
120         const int                       sides,
121         const char*                     material_name);
122 
123     void do_unassign_material(
124         const char*                     slot_name,
125         const int                       sides);
126 };
127 
128 }   // namespace studio
129 }   // namespace appleseed
130