Workbench: Option to use Object color
[blender.git] / release / scripts / startup / bl_ui / properties_collection.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Panel
22
23
24 class CollectionButtonsPanel:
25     bl_space_type = 'PROPERTIES'
26     bl_region_type = 'WINDOW'
27     bl_context = "collection"
28
29
30 def get_collection_from_context(context):
31     active_object = context.active_object
32
33     if active_object and active_object.dupli_group and context.space_data.collection_context == 'GROUP':
34         group = active_object.dupli_group
35         return group.view_layer.collections.active
36     else:
37         return context.layer_collection
38
39
40 class COLLECTION_PT_context_collection(CollectionButtonsPanel, Panel):
41     bl_label = ""
42     bl_options = {'HIDE_HEADER'}
43
44     def draw(self, context):
45         layout = self.layout
46         space = context.space_data
47         active_object = context.active_object
48
49         if active_object and active_object.dupli_group:
50             split = layout.split(percentage=0.2)
51             split.row().prop(space, "collection_context", expand=True)
52             layout = split
53
54         collection = get_collection_from_context(context)
55         name = collection.name
56         if name == 'Master Collection':
57             layout.label(text=name, icon='COLLAPSEMENU')
58         else:
59             layout.prop(collection, "name", text="", icon='COLLAPSEMENU')
60
61
62 class COLLECTION_PT_clay_settings(CollectionButtonsPanel, Panel):
63     bl_label = "Render Settings"
64     COMPAT_ENGINES = {'BLENDER_CLAY'}
65
66     @classmethod
67     def poll(cls, context):
68         return context.engine in cls.COMPAT_ENGINES
69
70     def draw(self, context):
71         layout = self.layout
72         scene_props = context.scene.collection_properties['BLENDER_CLAY']
73         collection = get_collection_from_context(context)
74         collection_props = collection.engine_overrides['BLENDER_CLAY']
75
76         col = layout.column()
77         col.template_override_property(collection_props, scene_props, "matcap_icon", custom_template="icon_view")
78         col.template_override_property(collection_props, scene_props, "matcap_rotation")
79         col.template_override_property(collection_props, scene_props, "matcap_hue")
80         col.template_override_property(collection_props, scene_props, "matcap_saturation")
81         col.template_override_property(collection_props, scene_props, "matcap_value")
82         col.template_override_property(collection_props, scene_props, "ssao_factor_cavity")
83         col.template_override_property(collection_props, scene_props, "ssao_factor_edge")
84         col.template_override_property(collection_props, scene_props, "ssao_distance")
85         col.template_override_property(collection_props, scene_props, "ssao_attenuation")
86         col.template_override_property(collection_props, scene_props, "hair_brightness_randomness")
87
88
89 class COLLECTION_PT_workbench_settings(CollectionButtonsPanel, Panel):
90     bl_label = "Workbench Settings"
91
92     def draw(self, context):
93         layout = self.layout
94         scene_props = context.scene.collection_properties['BLENDER_WORKBENCH']
95         collection = get_collection_from_context(context)
96         collection_props = collection.engine_overrides['BLENDER_WORKBENCH']
97
98         col = layout.column()
99         col.template_override_property(collection_props, scene_props, "object_color_type")
100         col.template_override_property(collection_props, scene_props, "object_color")
101
102
103 class COLLECTION_PT_object_mode_settings(CollectionButtonsPanel, Panel):
104     bl_label = "Object Mode Settings"
105
106     @classmethod
107     def poll(cls, context):
108         ob = context.object
109         return ob and ob.mode == 'OBJECT'
110
111     def draw(self, context):
112         layout = self.layout
113         scene_props = context.scene.collection_properties['ObjectMode']
114         collection = get_collection_from_context(context)
115         collection_props = collection.engine_overrides['ObjectMode']
116
117         col = layout.column()
118         col.template_override_property(collection_props, scene_props, "show_wire")
119         col.template_override_property(collection_props, scene_props, "show_backface_culling")
120
121
122 class COLLECTION_PT_edit_mode_settings(CollectionButtonsPanel, Panel):
123     bl_label = "Edit Mode Settings"
124
125     @classmethod
126     def poll(cls, context):
127         ob = context.object
128         return ob and ob.mode == 'EDIT'
129
130     def draw(self, context):
131         layout = self.layout
132         scene_props = context.scene.collection_properties['EditMode']
133         collection = get_collection_from_context(context)
134         collection_props = collection.engine_overrides['EditMode']
135
136         col = layout.column()
137         col.template_override_property(collection_props, scene_props, "show_occlude_wire")
138         col.template_override_property(collection_props, scene_props, "backwire_opacity")
139         col.template_override_property(collection_props, scene_props, "face_normals_show")
140         col.template_override_property(collection_props, scene_props, "vert_normals_show")
141         col.template_override_property(collection_props, scene_props, "loop_normals_show")
142         col.template_override_property(collection_props, scene_props, "normals_length")
143         col.template_override_property(collection_props, scene_props, "show_weight")
144
145
146 class COLLECTION_PT_paint_weight_mode_settings(CollectionButtonsPanel, Panel):
147     bl_label = "Weight Paint Mode Settings"
148
149     @classmethod
150     def poll(cls, context):
151         ob = context.object
152         return ob and ob.mode == 'WEIGHT_PAINT'
153
154     def draw(self, context):
155         layout = self.layout
156         scene_props = context.scene.collection_properties['WeightPaintMode']
157         collection = get_collection_from_context(context)
158         collection_props = collection.engine_overrides['WeightPaintMode']
159
160         col = layout.column()
161         col.template_override_property(collection_props, scene_props, "use_shading")
162         col.template_override_property(collection_props, scene_props, "use_wire")
163
164
165 class COLLECTION_PT_paint_vertex_mode_settings(CollectionButtonsPanel, Panel):
166     bl_label = "Vertex Paint Mode Settings"
167
168     @classmethod
169     def poll(cls, context):
170         ob = context.object
171         return ob and ob.mode == 'VERTEX_PAINT'
172
173     def draw(self, context):
174         layout = self.layout
175         scene_props = context.scene.collection_properties['VertexPaintMode']
176         collection = get_collection_from_context(context)
177         collection_props = collection.engine_overrides['VertexPaintMode']
178
179         col = layout.column()
180         col.template_override_property(collection_props, scene_props, "use_shading")
181         col.template_override_property(collection_props, scene_props, "use_wire")
182
183
184 classes = (
185     COLLECTION_PT_context_collection,
186     COLLECTION_PT_clay_settings,
187     COLLECTION_PT_workbench_settings,
188     COLLECTION_PT_object_mode_settings,
189     COLLECTION_PT_edit_mode_settings,
190     COLLECTION_PT_paint_weight_mode_settings,
191     COLLECTION_PT_paint_vertex_mode_settings,
192 )
193
194 if __name__ == "__main__":  # only for live edit.
195     from bpy.utils import register_class
196     for cls in classes:
197         register_class(cls)