2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-12 18:47:12 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-12 18:47:12 +00:00
|
|
|
*
|
2008-12-20 12:36:14 +00:00
|
|
|
* The Original Code is Copyright (C) 2004-2008 Blender Foundation.
|
2008-12-12 18:47:12 +00:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_view3d/view3d_header.c
|
|
|
|
|
* \ingroup spview3d
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-12 18:47:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
2008-12-20 12:36:14 +00:00
|
|
|
#include <stdlib.h>
|
2008-12-12 18:47:12 +00:00
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
2010-08-10 05:41:51 +00:00
|
|
|
#include "DNA_object_types.h"
|
2012-02-19 22:17:30 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2011-09-20 07:39:25 +00:00
|
|
|
#include "BLF_translation.h"
|
2011-06-15 11:41:15 +00:00
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "BKE_context.h"
|
2008-12-20 12:36:14 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
|
|
|
|
#include "BKE_effect.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
|
#include "BKE_modifier.h"
|
2009-08-15 19:48:50 +00:00
|
|
|
#include "BKE_paint.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
#include "BKE_screen.h"
|
2009-05-18 10:29:37 +00:00
|
|
|
#include "BKE_tessmesh.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
#include "RNA_enum_types.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2009-01-01 18:05:12 +00:00
|
|
|
#include "ED_mesh.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
#include "ED_util.h"
|
2009-01-05 19:32:04 +00:00
|
|
|
#include "ED_screen.h"
|
2009-07-08 16:17:47 +00:00
|
|
|
#include "ED_transform.h"
|
2008-12-19 12:48:30 +00:00
|
|
|
#include "ED_types.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
|
|
#include "view3d_intern.h"
|
|
|
|
|
|
|
|
|
|
|
2008-12-20 12:36:14 +00:00
|
|
|
/* View3d->modeselect
|
|
|
|
|
* This is a bit of a dodgy hack to enable a 'mode' menu with icons+labels
|
|
|
|
|
* rather than those buttons.
|
|
|
|
|
* I know the implementation's not good - it's an experiment to see if this
|
|
|
|
|
* approach would work well
|
|
|
|
|
*
|
|
|
|
|
* This can be cleaned when I make some new 'mode' icons.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* end XXX ************* */
|
|
|
|
|
|
2009-02-10 15:38:00 +00:00
|
|
|
static void do_view3d_header_buttons(bContext *C, void *arg, int event);
|
2008-12-20 12:36:14 +00:00
|
|
|
|
|
|
|
|
#define B_MODESELECT 108
|
2012-03-25 23:54:33 +00:00
|
|
|
#define B_SEL_VERT 110
|
|
|
|
|
#define B_SEL_EDGE 111
|
|
|
|
|
#define B_SEL_FACE 112
|
|
|
|
|
#define B_MAN_TRANS 116
|
|
|
|
|
#define B_MAN_ROT 117
|
|
|
|
|
#define B_MAN_SCALE 118
|
|
|
|
|
#define B_MAN_MODE 120
|
2009-10-26 12:42:25 +00:00
|
|
|
|
2012-07-08 20:36:00 +00:00
|
|
|
/* XXX quickly ported across */
|
|
|
|
|
static void handle_view3d_lock(bContext *C)
|
2009-07-03 04:24:19 +00:00
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
2009-07-03 04:24:19 +00:00
|
|
|
|
|
|
|
|
if (v3d != NULL && sa != NULL) {
|
2012-03-25 23:54:33 +00:00
|
|
|
if (v3d->localvd == NULL && v3d->scenelock && sa->spacetype == SPACE_VIEW3D) {
|
2009-07-03 04:24:19 +00:00
|
|
|
/* copy to scene */
|
2012-03-25 23:54:33 +00:00
|
|
|
scene->lay = v3d->lay;
|
|
|
|
|
scene->layact = v3d->layact;
|
|
|
|
|
scene->camera = v3d->camera;
|
2009-10-26 12:42:25 +00:00
|
|
|
|
2012-03-04 04:35:12 +00:00
|
|
|
/* not through notifier, listener don't have context
|
2012-03-03 16:31:46 +00:00
|
|
|
* and non-open screens or spaces need to be updated too */
|
2010-04-22 19:57:18 +00:00
|
|
|
BKE_screen_view3d_main_sync(&bmain->screen, scene);
|
2009-07-03 04:24:19 +00:00
|
|
|
|
2009-10-19 04:56:19 +00:00
|
|
|
/* notifiers for scene update */
|
2012-03-25 23:54:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
|
2009-07-03 04:24:19 +00:00
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-03 16:31:46 +00:00
|
|
|
/**
|
|
|
|
|
* layer code is on three levels actually:
|
|
|
|
|
* - here for operator
|
|
|
|
|
* - uiTemplateLayers in interface/ code for buttons
|
|
|
|
|
* - ED_view3d_scene_layer_set for RNA
|
2011-03-19 16:30:52 +00:00
|
|
|
*/
|
2011-03-30 15:28:38 +00:00
|
|
|
static void view3d_layers_editmode_ensure(Scene *scene, View3D *v3d)
|
|
|
|
|
{
|
|
|
|
|
/* sanity check - when in editmode disallow switching the editmode layer off since its confusing
|
|
|
|
|
* an alternative would be to always draw the editmode object. */
|
2012-03-25 23:54:33 +00:00
|
|
|
if (scene->obedit && (scene->obedit->lay & v3d->lay) == 0) {
|
2011-03-30 15:28:38 +00:00
|
|
|
int bit;
|
2012-03-25 23:54:33 +00:00
|
|
|
for (bit = 0; bit < 32; bit++) {
|
|
|
|
|
if (scene->obedit->lay & (1 << bit)) {
|
|
|
|
|
v3d->lay |= 1 << bit;
|
2011-03-30 15:28:38 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-13 14:16:36 +00:00
|
|
|
static int view3d_layers_exec(bContext *C, wmOperator *op)
|
2008-12-20 12:36:14 +00:00
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
|
View3D *v3d = sa->spacedata.first;
|
|
|
|
|
int nr = RNA_int_get(op->ptr, "nr");
|
2013-03-22 04:40:45 +00:00
|
|
|
const bool toggle = RNA_boolean_get(op->ptr, "toggle");
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (nr < 0)
|
2009-02-20 18:01:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2010-03-26 08:32:54 +00:00
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (nr == 0) {
|
2009-09-22 04:40:16 +00:00
|
|
|
/* all layers */
|
2012-02-22 16:52:06 +00:00
|
|
|
if (!v3d->layact)
|
2012-03-25 23:54:33 +00:00
|
|
|
v3d->layact = 1;
|
2010-03-26 08:32:54 +00:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if (toggle && v3d->lay == ((1 << 20) - 1)) {
|
2010-03-26 08:32:54 +00:00
|
|
|
/* return to active layer only */
|
|
|
|
|
v3d->lay = v3d->layact;
|
2011-03-30 15:28:38 +00:00
|
|
|
|
|
|
|
|
view3d_layers_editmode_ensure(scene, v3d);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:54:33 +00:00
|
|
|
v3d->lay |= (1 << 20) - 1;
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-01-30 15:23:17 +00:00
|
|
|
int bit;
|
2009-09-22 04:40:16 +00:00
|
|
|
nr--;
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (RNA_boolean_get(op->ptr, "extend")) {
|
2012-03-25 23:54:33 +00:00
|
|
|
if (toggle && v3d->lay & (1 << nr) && (v3d->lay & ~(1 << nr)))
|
|
|
|
|
v3d->lay &= ~(1 << nr);
|
2010-01-03 04:21:40 +00:00
|
|
|
else
|
2012-03-25 23:54:33 +00:00
|
|
|
v3d->lay |= (1 << nr);
|
2012-02-22 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:54:33 +00:00
|
|
|
v3d->lay = (1 << nr);
|
2010-01-30 15:23:17 +00:00
|
|
|
}
|
2011-03-30 15:28:38 +00:00
|
|
|
|
|
|
|
|
view3d_layers_editmode_ensure(scene, v3d);
|
|
|
|
|
|
2009-09-22 04:40:16 +00:00
|
|
|
/* set active layer, ensure to always have one */
|
2012-03-25 23:54:33 +00:00
|
|
|
if (v3d->lay & (1 << nr))
|
|
|
|
|
v3d->layact = 1 << nr;
|
|
|
|
|
else if ((v3d->lay & v3d->layact) == 0) {
|
|
|
|
|
for (bit = 0; bit < 32; bit++) {
|
|
|
|
|
if (v3d->lay & (1 << bit)) {
|
|
|
|
|
v3d->layact = 1 << bit;
|
2009-09-22 04:40:16 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2009-07-19 16:53:57 +00:00
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
2009-07-19 16:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (v3d->scenelock) handle_view3d_lock(C);
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2013-03-20 23:14:18 +00:00
|
|
|
DAG_on_visible_update(CTX_data_main(C), false);
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-02-20 18:01:33 +00:00
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-20 18:01:33 +00:00
|
|
|
/* applies shift and alt, lazy coding or ok? :) */
|
|
|
|
|
/* the local per-keymap-entry keymap will solve it */
|
2013-03-13 09:03:46 +00:00
|
|
|
static int view3d_layers_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2008-12-20 12:36:14 +00:00
|
|
|
{
|
2012-02-22 16:52:06 +00:00
|
|
|
if (event->ctrl || event->oskey)
|
2009-02-20 18:01:33 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (event->shift)
|
2012-01-16 16:12:03 +00:00
|
|
|
RNA_boolean_set(op->ptr, "extend", TRUE);
|
2012-01-26 07:33:14 +00:00
|
|
|
else
|
2013-03-20 23:14:18 +00:00
|
|
|
RNA_boolean_set(op->ptr, "extend", false);
|
2009-02-20 18:01:33 +00:00
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (event->alt) {
|
2013-03-22 04:40:45 +00:00
|
|
|
const int nr = RNA_int_get(op->ptr, "nr") + 10;
|
2009-02-20 18:01:33 +00:00
|
|
|
RNA_int_set(op->ptr, "nr", nr);
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
2011-02-13 14:16:36 +00:00
|
|
|
view3d_layers_exec(C, op);
|
2009-02-20 18:01:33 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-13 14:16:36 +00:00
|
|
|
static int view3d_layers_poll(bContext *C)
|
2010-01-03 04:21:40 +00:00
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
return (ED_operator_view3d_active(C) && CTX_wm_view3d(C)->localvd == NULL);
|
2010-01-03 04:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-20 18:01:33 +00:00
|
|
|
void VIEW3D_OT_layers(wmOperatorType *ot)
|
2008-12-20 12:36:14 +00:00
|
|
|
{
|
2009-02-20 18:01:33 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Layers";
|
|
|
|
|
ot->description = "Toggle layer(s) visibility";
|
|
|
|
|
ot->idname = "VIEW3D_OT_layers";
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-02-20 18:01:33 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = view3d_layers_invoke;
|
|
|
|
|
ot->exec = view3d_layers_exec;
|
|
|
|
|
ot->poll = view3d_layers_poll;
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-02-20 18:01:33 +00:00
|
|
|
/* flags */
|
2012-03-25 23:54:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-09-22 04:40:16 +00:00
|
|
|
RNA_def_int(ot->srna, "nr", 1, 0, 20, "Number", "The layer number to set, zero for all layers", 0, 20);
|
|
|
|
|
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Add this layer to the current view layers");
|
2010-01-03 04:21:40 +00:00
|
|
|
RNA_def_boolean(ot->srna, "toggle", 1, "Toggle", "Toggle the layer");
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-19 10:32:53 +00:00
|
|
|
static int modeselect_addmode(char *str, const char *title, int id, int icon)
|
|
|
|
|
{
|
|
|
|
|
static char formatstr[] = "|%s %%x%d %%i%d";
|
|
|
|
|
|
2011-10-20 20:38:26 +00:00
|
|
|
return sprintf(str, formatstr, IFACE_(title), id, icon);
|
2011-09-19 10:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-20 12:36:14 +00:00
|
|
|
static char *view3d_modeselect_pup(Scene *scene)
|
|
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
Object *ob = OBACT;
|
2011-12-22 16:00:34 +00:00
|
|
|
static char string[512];
|
2012-03-25 23:54:33 +00:00
|
|
|
const char *title = IFACE_("Mode: %t");
|
2008-12-20 12:36:14 +00:00
|
|
|
char *str = string;
|
|
|
|
|
|
2011-09-22 18:42:16 +00:00
|
|
|
BLI_strncpy(str, title, sizeof(string));
|
2011-09-23 10:43:25 +00:00
|
|
|
|
2011-09-19 10:32:53 +00:00
|
|
|
str += modeselect_addmode(str, N_("Object Mode"), OB_MODE_OBJECT, ICON_OBJECT_DATA);
|
2011-09-23 10:43:25 +00:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if (ob == NULL || ob->data == NULL) return string;
|
2012-02-22 16:52:06 +00:00
|
|
|
if (ob->id.lib) return string;
|
2011-09-23 10:43:25 +00:00
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (!((ID *)ob->data)->lib) {
|
2011-08-17 12:09:02 +00:00
|
|
|
/* if active object is editable */
|
2012-04-28 10:33:32 +00:00
|
|
|
if (ob->type == OB_ARMATURE) {
|
2011-08-17 12:09:02 +00:00
|
|
|
if (ob->mode & OB_MODE_POSE)
|
2012-03-25 23:54:33 +00:00
|
|
|
str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT | OB_MODE_POSE, ICON_EDITMODE_HLT);
|
2011-08-17 12:09:02 +00:00
|
|
|
else
|
2011-09-19 10:32:53 +00:00
|
|
|
str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT, ICON_EDITMODE_HLT);
|
2012-04-28 10:33:32 +00:00
|
|
|
}
|
|
|
|
|
else if (OB_TYPE_SUPPORT_EDITMODE(ob->type)) {
|
|
|
|
|
str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT, ICON_EDITMODE_HLT);
|
2011-08-17 12:09:02 +00:00
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2011-08-17 12:09:02 +00:00
|
|
|
if (ob->type == OB_MESH) {
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2011-09-19 10:32:53 +00:00
|
|
|
str += modeselect_addmode(str, N_("Sculpt Mode"), OB_MODE_SCULPT, ICON_SCULPTMODE_HLT);
|
|
|
|
|
str += modeselect_addmode(str, N_("Vertex Paint"), OB_MODE_VERTEX_PAINT, ICON_VPAINT_HLT);
|
|
|
|
|
str += modeselect_addmode(str, N_("Texture Paint"), OB_MODE_TEXTURE_PAINT, ICON_TPAINT_HLT);
|
|
|
|
|
str += modeselect_addmode(str, N_("Weight Paint"), OB_MODE_WEIGHT_PAINT, ICON_WPAINT_HLT);
|
2011-08-17 12:09:02 +00:00
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
2011-09-23 10:43:25 +00:00
|
|
|
|
2008-12-20 12:36:14 +00:00
|
|
|
/* if active object is an armature */
|
2012-03-25 23:54:33 +00:00
|
|
|
if (ob->type == OB_ARMATURE) {
|
2011-09-19 10:32:53 +00:00
|
|
|
str += modeselect_addmode(str, N_("Pose Mode"), OB_MODE_POSE, ICON_POSE_HLT);
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if (ob->particlesystem.first ||
|
|
|
|
|
modifiers_findByType(ob, eModifierType_Cloth) ||
|
|
|
|
|
modifiers_findByType(ob, eModifierType_Softbody))
|
2011-12-22 00:03:20 +00:00
|
|
|
{
|
2011-09-19 10:32:53 +00:00
|
|
|
str += modeselect_addmode(str, N_("Particle Mode"), OB_MODE_PARTICLE_EDIT, ICON_PARTICLEMODE);
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
2011-04-23 12:57:03 +00:00
|
|
|
(void)str;
|
2008-12-20 12:36:14 +00:00
|
|
|
return (string);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-14 01:22:14 +00:00
|
|
|
static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event)
|
2008-12-20 12:36:14 +00:00
|
|
|
{
|
2012-03-02 12:09:49 +00:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
|
View3D *v3d = sa->spacedata.first;
|
2012-11-11 23:33:59 +00:00
|
|
|
const int ctrl = win->eventstate->ctrl, shift = win->eventstate->shift;
|
2009-08-16 16:38:32 +00:00
|
|
|
PointerRNA props_ptr;
|
2012-11-13 05:44:49 +00:00
|
|
|
|
2008-12-20 12:36:14 +00:00
|
|
|
/* watch it: if sa->win does not exist, check that when calling direct drawing routines */
|
|
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
switch (event) {
|
|
|
|
|
case B_MODESELECT:
|
|
|
|
|
WM_operator_properties_create(&props_ptr, "OBJECT_OT_mode_set");
|
|
|
|
|
RNA_enum_set(&props_ptr, "mode", v3d->modeselect);
|
|
|
|
|
WM_operator_name_call(C, "OBJECT_OT_mode_set", WM_OP_EXEC_REGION_WIN, &props_ptr);
|
|
|
|
|
WM_operator_properties_free(&props_ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case B_SEL_VERT:
|
2012-11-13 05:44:49 +00:00
|
|
|
if (EDBM_selectmode_toggle(C, SCE_SELECT_VERTEX, -1, shift, ctrl)) {
|
2012-03-25 23:54:33 +00:00
|
|
|
ED_undo_push(C, "Selectmode Set: Vertex");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case B_SEL_EDGE:
|
2012-11-13 05:44:49 +00:00
|
|
|
if (EDBM_selectmode_toggle(C, SCE_SELECT_EDGE, -1, shift, ctrl)) {
|
2012-03-25 23:54:33 +00:00
|
|
|
ED_undo_push(C, "Selectmode Set: Edge");
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
2012-03-25 23:54:33 +00:00
|
|
|
break;
|
|
|
|
|
case B_SEL_FACE:
|
2012-11-13 05:44:49 +00:00
|
|
|
if (EDBM_selectmode_toggle(C, SCE_SELECT_FACE, -1, shift, ctrl)) {
|
2012-03-25 23:54:33 +00:00
|
|
|
ED_undo_push(C, "Selectmode Set: Face");
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
2012-03-25 23:54:33 +00:00
|
|
|
break;
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
case B_MAN_TRANS:
|
|
|
|
|
if (shift == 0 || v3d->twtype == 0) {
|
|
|
|
|
v3d->twtype = V3D_MANIP_TRANSLATE;
|
|
|
|
|
}
|
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
|
break;
|
|
|
|
|
case B_MAN_ROT:
|
|
|
|
|
if (shift == 0 || v3d->twtype == 0) {
|
|
|
|
|
v3d->twtype = V3D_MANIP_ROTATE;
|
|
|
|
|
}
|
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
|
break;
|
|
|
|
|
case B_MAN_SCALE:
|
|
|
|
|
if (shift == 0 || v3d->twtype == 0) {
|
|
|
|
|
v3d->twtype = V3D_MANIP_SCALE;
|
|
|
|
|
}
|
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
|
break;
|
|
|
|
|
case B_MAN_MODE:
|
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-16 16:38:32 +00:00
|
|
|
/* Returns the icon associated with an object mode */
|
|
|
|
|
static int object_mode_icon(int mode)
|
|
|
|
|
{
|
|
|
|
|
EnumPropertyItem *item = object_mode_items;
|
|
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
while (item->name != NULL) {
|
2012-05-09 09:24:15 +00:00
|
|
|
if (item->value == mode) {
|
2009-08-16 16:38:32 +00:00
|
|
|
return item->icon;
|
2012-05-09 09:24:15 +00:00
|
|
|
}
|
|
|
|
|
item++;
|
2009-08-16 16:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ICON_OBJECT_DATAMODE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 11:34:57 +00:00
|
|
|
void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
|
|
|
|
|
{
|
|
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
2012-03-25 23:54:33 +00:00
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
2011-05-02 11:34:57 +00:00
|
|
|
|
|
|
|
|
uiBlockSetHandleFunc(block, do_view3d_header_buttons, NULL);
|
|
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (obedit && (obedit->type == OB_MESH)) {
|
2012-03-02 12:09:49 +00:00
|
|
|
BMEditMesh *em = BMEdit_FromObject(obedit);
|
2011-05-02 11:34:57 +00:00
|
|
|
uiLayout *row;
|
|
|
|
|
|
2012-06-19 23:08:16 +00:00
|
|
|
row = uiLayoutRow(layout, TRUE);
|
2012-03-25 23:54:33 +00:00
|
|
|
block = uiLayoutGetBlock(row);
|
2012-11-11 23:33:59 +00:00
|
|
|
uiDefIconButBitS(block, TOG, SCE_SELECT_VERTEX, B_SEL_VERT, ICON_VERTEXSEL,
|
|
|
|
|
0, 0, UI_UNIT_X, UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0,
|
2013-02-24 15:40:28 +00:00
|
|
|
TIP_("Vertex select - Shift-Click for multiple modes"));
|
2012-11-11 23:33:59 +00:00
|
|
|
uiDefIconButBitS(block, TOG, SCE_SELECT_EDGE, B_SEL_EDGE, ICON_EDGESEL,
|
|
|
|
|
0, 0, UI_UNIT_X, UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0,
|
2013-02-24 15:40:28 +00:00
|
|
|
TIP_("Edge select - Shift-Click for multiple modes, Ctrl-Click expands selection"));
|
2012-11-11 23:33:59 +00:00
|
|
|
uiDefIconButBitS(block, TOG, SCE_SELECT_FACE, B_SEL_FACE, ICON_FACESEL,
|
|
|
|
|
0, 0, UI_UNIT_X, UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0,
|
2013-02-24 15:40:28 +00:00
|
|
|
TIP_("Face select - Shift-Click for multiple modes, Ctrl-Click expands selection"));
|
2011-05-02 11:34:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-11 13:32:20 +00:00
|
|
|
void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
|
2008-12-20 12:36:14 +00:00
|
|
|
{
|
2012-03-25 23:54:33 +00:00
|
|
|
bScreen *screen = CTX_wm_screen(C);
|
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
|
View3D *v3d = sa->spacedata.first;
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
ToolSettings *ts = CTX_data_tool_settings(C);
|
2009-11-29 02:42:47 +00:00
|
|
|
PointerRNA v3dptr, toolsptr, sceneptr;
|
2012-03-25 23:54:33 +00:00
|
|
|
Object *ob = OBACT;
|
2008-12-31 22:43:29 +00:00
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
2008-12-20 12:36:14 +00:00
|
|
|
uiBlock *block;
|
2011-08-18 17:09:23 +00:00
|
|
|
uiBut *but;
|
2009-11-01 14:04:37 +00:00
|
|
|
uiLayout *row;
|
2012-03-25 23:54:33 +00:00
|
|
|
const float dpi_fac = UI_DPI_FAC;
|
2012-02-17 06:59:32 +00:00
|
|
|
int is_paint = 0;
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2012-10-21 05:46:41 +00:00
|
|
|
RNA_pointer_create(&screen->id, &RNA_SpaceView3D, v3d, &v3dptr);
|
2009-11-28 19:38:05 +00:00
|
|
|
RNA_pointer_create(&scene->id, &RNA_ToolSettings, ts, &toolsptr);
|
2009-11-29 02:42:47 +00:00
|
|
|
RNA_pointer_create(&scene->id, &RNA_Scene, scene, &sceneptr);
|
2009-11-28 19:38:05 +00:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
block = uiLayoutGetBlock(layout);
|
2009-02-10 15:38:00 +00:00
|
|
|
uiBlockSetHandleFunc(block, do_view3d_header_buttons, NULL);
|
2008-12-20 12:36:14 +00:00
|
|
|
|
|
|
|
|
/* other buttons: */
|
|
|
|
|
uiBlockSetEmboss(block, UI_EMBOSS);
|
|
|
|
|
|
|
|
|
|
/* mode */
|
2012-02-22 16:52:06 +00:00
|
|
|
if (ob) {
|
2009-08-16 16:38:32 +00:00
|
|
|
v3d->modeselect = ob->mode;
|
2012-03-25 23:54:33 +00:00
|
|
|
is_paint = ELEM4(ob->mode, OB_MODE_SCULPT, OB_MODE_VERTEX_PAINT, OB_MODE_WEIGHT_PAINT, OB_MODE_TEXTURE_PAINT);
|
2011-12-04 23:13:28 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2009-08-16 16:38:32 +00:00
|
|
|
v3d->modeselect = OB_MODE_OBJECT;
|
2010-01-13 07:26:11 +00:00
|
|
|
}
|
2011-12-04 23:13:28 +00:00
|
|
|
|
2012-06-19 23:08:16 +00:00
|
|
|
row = uiLayoutRow(layout, TRUE);
|
2012-03-25 23:54:33 +00:00
|
|
|
uiDefIconTextButS(block, MENU, B_MODESELECT, object_mode_icon(v3d->modeselect), view3d_modeselect_pup(scene),
|
|
|
|
|
0, 0, 126 * dpi_fac, UI_UNIT_Y, &(v3d->modeselect), 0, 0, 0, 0, TIP_("Mode"));
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-11-28 21:27:28 +00:00
|
|
|
/* Draw type */
|
2011-02-27 18:03:19 +00:00
|
|
|
uiItemR(layout, &v3dptr, "viewport_shade", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if (obedit == NULL && is_paint) {
|
2013-02-26 18:35:16 +00:00
|
|
|
|
|
|
|
|
if (ob->mode & OB_MODE_WEIGHT_PAINT) {
|
|
|
|
|
/* Only for Weight Paint. makes no sense in other paint modes. */
|
|
|
|
|
row = uiLayoutRow(layout, TRUE);
|
|
|
|
|
uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-17 06:59:32 +00:00
|
|
|
/* Manipulators aren't used in paint modes */
|
|
|
|
|
if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT)) {
|
|
|
|
|
/* masks aren't used for sculpt and particle painting */
|
|
|
|
|
PointerRNA meshptr;
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2012-02-17 06:59:32 +00:00
|
|
|
RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr);
|
2012-03-25 23:54:33 +00:00
|
|
|
if (ob->mode & (OB_MODE_TEXTURE_PAINT | OB_MODE_VERTEX_PAINT)) {
|
2012-02-17 06:59:32 +00:00
|
|
|
uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-06-19 23:08:16 +00:00
|
|
|
row = uiLayoutRow(layout, TRUE);
|
2012-02-17 06:59:32 +00:00
|
|
|
uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
}
|
2011-07-20 15:56:35 +00:00
|
|
|
}
|
2012-02-22 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-12-03 17:05:21 +00:00
|
|
|
const char *str_menu;
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2012-06-19 23:08:16 +00:00
|
|
|
row = uiLayoutRow(layout, TRUE);
|
2011-02-27 18:03:19 +00:00
|
|
|
uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
2011-10-06 10:06:53 +00:00
|
|
|
|
|
|
|
|
/* pose/object only however we want to allow in weight paint mode too
|
2013-02-26 18:35:16 +00:00
|
|
|
* so don't be totally strict and just check not-editmode for now
|
|
|
|
|
* XXX We never get here when we are in Weight Paint mode
|
|
|
|
|
*/
|
2011-10-06 10:06:53 +00:00
|
|
|
if (obedit == NULL) {
|
|
|
|
|
uiItemR(row, &v3dptr, "use_pivot_point_align", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-11-28 20:02:10 +00:00
|
|
|
/* Transform widget / manipulators */
|
2012-06-19 23:08:16 +00:00
|
|
|
row = uiLayoutRow(layout, TRUE);
|
2011-02-27 18:03:19 +00:00
|
|
|
uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
2012-03-25 23:54:33 +00:00
|
|
|
block = uiLayoutGetBlock(row);
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2012-02-22 16:52:06 +00:00
|
|
|
if (v3d->twflag & V3D_USE_MANIPULATOR) {
|
2012-12-23 01:18:35 +00:00
|
|
|
but = uiDefIconButBitC(block, TOG, V3D_MANIP_TRANSLATE, B_MAN_TRANS, ICON_MAN_TRANS,
|
|
|
|
|
0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0,
|
|
|
|
|
TIP_("Translate manipulator - Shift-Click for multiple modes"));
|
2011-08-18 17:09:23 +00:00
|
|
|
uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
|
2012-12-23 01:18:35 +00:00
|
|
|
but = uiDefIconButBitC(block, TOG, V3D_MANIP_ROTATE, B_MAN_ROT, ICON_MAN_ROT,
|
|
|
|
|
0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0,
|
|
|
|
|
TIP_("Rotate manipulator - Shift-Click for multiple modes"));
|
2011-08-18 17:09:23 +00:00
|
|
|
uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
|
2012-12-23 01:18:35 +00:00
|
|
|
but = uiDefIconButBitC(block, TOG, V3D_MANIP_SCALE, B_MAN_SCALE, ICON_MAN_SCALE,
|
|
|
|
|
0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0,
|
|
|
|
|
TIP_("Scale manipulator - Shift-Click for multiple modes"));
|
2011-08-18 17:09:23 +00:00
|
|
|
uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
|
2009-11-28 20:02:10 +00:00
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-11-28 20:02:10 +00:00
|
|
|
if (v3d->twmode > (BIF_countTransformOrientation(C) - 1) + V3D_MANIP_CUSTOM) {
|
|
|
|
|
v3d->twmode = 0;
|
|
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-11-28 20:02:10 +00:00
|
|
|
str_menu = BIF_menustringTransformOrientation(C, "Orientation");
|
2012-12-23 01:18:35 +00:00
|
|
|
but = uiDefButC(block, MENU, B_MAN_MODE, str_menu, 0, 0, 70 * dpi_fac, UI_UNIT_Y, &v3d->twmode, 0, 0, 0, 0,
|
|
|
|
|
TIP_("Transform Orientation"));
|
2011-08-18 17:09:23 +00:00
|
|
|
uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
|
2010-12-03 17:05:21 +00:00
|
|
|
MEM_freeN((void *)str_menu);
|
2009-11-28 20:02:10 +00:00
|
|
|
}
|
2011-04-21 15:53:30 +00:00
|
|
|
|
2012-03-25 23:54:33 +00:00
|
|
|
if (obedit == NULL && v3d->localvd == NULL) {
|
2010-10-19 01:21:22 +00:00
|
|
|
unsigned int ob_lay = ob ? ob->lay : 0;
|
2011-11-05 11:04:28 +00:00
|
|
|
|
2009-11-29 06:04:39 +00:00
|
|
|
/* Layers */
|
2011-11-05 11:04:28 +00:00
|
|
|
uiTemplateLayers(layout, v3d->scenelock ? &sceneptr : &v3dptr, "layers", &v3dptr, "layers_used", ob_lay);
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2009-11-28 21:27:28 +00:00
|
|
|
/* Scene lock */
|
2011-02-27 18:03:19 +00:00
|
|
|
uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
2009-11-28 20:02:10 +00:00
|
|
|
}
|
2010-01-30 01:25:02 +00:00
|
|
|
|
2011-05-02 11:34:57 +00:00
|
|
|
uiTemplateEditModeSelection(layout, C);
|
2008-12-12 18:47:12 +00:00
|
|
|
}
|