2009-01-13 15:18:41 +00:00
|
|
|
/**
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** 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,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) Blender Foundation
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_arithb.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_group_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_depsgraph.h"
|
|
|
|
|
#include "BKE_group.h"
|
|
|
|
|
#include "BKE_global.h"
|
2009-01-20 03:41:23 +00:00
|
|
|
#include "BKE_context.h"
|
2009-01-13 15:18:41 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
#include "ED_view3d.h"
|
|
|
|
|
#include "ED_space_api.h"
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
#include "ED_types.h"
|
|
|
|
|
#include "ED_util.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
#include "object_intern.h"
|
|
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
|
static void BIF_undo_push() {}
|
|
|
|
|
static void error() {}
|
|
|
|
|
static int pupmenu() {return 0;}
|
|
|
|
|
static int pupmenu_col() {return 0;}
|
|
|
|
|
|
|
|
|
|
void add_selected_to_act_ob_groups(Scene *scene, View3D *v3d)
|
|
|
|
|
{
|
|
|
|
|
Object *ob= OBACT, *obt;
|
|
|
|
|
Base *base;
|
|
|
|
|
Group *group;
|
|
|
|
|
|
|
|
|
|
if (!ob) return;
|
|
|
|
|
|
|
|
|
|
/* linking to same group requires its own loop so we can avoid
|
|
|
|
|
looking up the active objects groups each time */
|
|
|
|
|
|
|
|
|
|
group= G.main->group.first;
|
|
|
|
|
while(group) {
|
|
|
|
|
if(object_in_group(ob, group)) {
|
|
|
|
|
/* Assign groups to selected objects */
|
|
|
|
|
base= FIRSTBASE;
|
|
|
|
|
while(base) {
|
|
|
|
|
if(TESTBASE(v3d, base)) {
|
|
|
|
|
obt= base->object;
|
|
|
|
|
add_to_group(group, obt);
|
|
|
|
|
obt->flag |= OB_FROMGROUP;
|
|
|
|
|
base->flag |= OB_FROMGROUP;
|
|
|
|
|
}
|
|
|
|
|
base= base->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
group= group->id.next;
|
|
|
|
|
}
|
|
|
|
|
DAG_scene_sort(scene);
|
|
|
|
|
BIF_undo_push("Add to Active Objects Group");
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
static int group_remove_exec(bContext *C, wmOperator *op)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
2009-01-20 03:41:23 +00:00
|
|
|
Group *group= NULL;
|
|
|
|
|
Group *group_array[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
|
int gid,i=0; //group id
|
|
|
|
|
|
|
|
|
|
gid = RNA_int_get(op->ptr, "GID");
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
/*remove from all groups*/
|
|
|
|
|
if (gid == 26) {
|
|
|
|
|
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
|
2009-01-13 15:18:41 +00:00
|
|
|
group = NULL;
|
|
|
|
|
while( (group = find_group(base->object, group)) ) {
|
|
|
|
|
rem_from_group(group, base->object);
|
|
|
|
|
}
|
|
|
|
|
base->object->flag &= ~OB_FROMGROUP;
|
|
|
|
|
base->flag &= ~OB_FROMGROUP;
|
|
|
|
|
}
|
2009-01-20 03:41:23 +00:00
|
|
|
CTX_DATA_END;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2009-01-20 03:41:23 +00:00
|
|
|
else {
|
|
|
|
|
/* build array of the groups that are in menu*/
|
|
|
|
|
for(group= G.main->group.first; group && i<24; group= group->id.next) {
|
|
|
|
|
if(group->id.lib==NULL) {
|
|
|
|
|
GroupObject *go;
|
|
|
|
|
for(go= group->gobject.first; go; go= go->next) {
|
|
|
|
|
if(go->ob->id.flag & LIB_DOIT) {
|
|
|
|
|
group_array[i] = group;
|
|
|
|
|
i++;
|
|
|
|
|
break; /* Only want to know if this group should go in the list*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
|
|
|
|
|
/* if we are removed and are not in any group, set our flag */
|
|
|
|
|
if(rem_from_group(group, base->object) && find_group(base->object, NULL)==NULL) {
|
|
|
|
|
base->object->flag &= ~OB_FROMGROUP;
|
|
|
|
|
base->flag &= ~OB_FROMGROUP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DAG_scene_sort(CTX_data_scene(C));
|
|
|
|
|
ED_undo_push(C,"Remove From Group");
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE, CTX_data_scene(C));
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
}
|
|
|
|
|
static int group_remove_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
|
|
|
|
Group *group= NULL;
|
2009-01-20 03:41:23 +00:00
|
|
|
char *menutext= MEM_callocN(30+(22*22), "group rem menu"), *menupt;
|
|
|
|
|
int i = 0;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
|
/* UnSet Tags for Objects and Groups */
|
|
|
|
|
for(group= G.main->group.first; group; group= group->id.next) {
|
|
|
|
|
if(group->id.lib==NULL) {
|
|
|
|
|
group->id.flag &= ~LIB_DOIT;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 03:41:23 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object*, ob, visible_objects) {
|
2009-01-13 15:18:41 +00:00
|
|
|
ob->id.flag &= ~LIB_DOIT;
|
|
|
|
|
}
|
2009-01-20 03:41:23 +00:00
|
|
|
CTX_DATA_END;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
|
/* Not tag selected objects */
|
2009-01-20 03:41:23 +00:00
|
|
|
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
|
2009-01-13 15:18:41 +00:00
|
|
|
base->object->id.flag |= LIB_DOIT;
|
|
|
|
|
}
|
2009-01-20 03:41:23 +00:00
|
|
|
CTX_DATA_END;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
|
menupt = menutext;
|
2009-01-20 03:41:23 +00:00
|
|
|
|
|
|
|
|
menupt += sprintf(menupt, "Remove From %%t|");
|
|
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
/* Build a list of groups that contain selected objects */
|
|
|
|
|
for(group= G.main->group.first; group && i<24; group= group->id.next) {
|
|
|
|
|
if(group->id.lib==NULL) {
|
|
|
|
|
GroupObject *go;
|
|
|
|
|
for(go= group->gobject.first; go; go= go->next) {
|
|
|
|
|
if(go->ob->id.flag & LIB_DOIT) {
|
|
|
|
|
menupt += sprintf(menupt, "|%s", group->id.name+2);
|
|
|
|
|
i++;
|
|
|
|
|
break; /* Only want to know if this group should go in the list*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 03:41:23 +00:00
|
|
|
menupt += sprintf(menupt, "|%s %%x%d", "ALL", 26);
|
2009-01-13 15:18:41 +00:00
|
|
|
/* do we have any groups? */
|
2009-01-20 03:41:23 +00:00
|
|
|
if (i = 0) error("Object selection contains no groups");
|
|
|
|
|
else uiPupmenuOperator(C, 0, op, "GID", menutext);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(menutext);
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
void GROUP_OT_group_remove(wmOperatorType *ot)
|
|
|
|
|
{
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "remove Selected from group";
|
|
|
|
|
ot->idname= "GROUP_OT_group_remove";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke = group_remove_invoke;
|
|
|
|
|
ot->exec= group_remove_exec;
|
|
|
|
|
ot->poll= ED_operator_scene_editable;
|
|
|
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "GID", 0, INT_MIN, INT_MAX, "Group", "", INT_MIN, INT_MAX);
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2009-01-20 03:41:23 +00:00
|
|
|
static int group_create_exec(bContext *C, wmOperator *op)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
|
|
|
|
Group *group= NULL;
|
2009-01-20 03:41:23 +00:00
|
|
|
int gid; //group id
|
|
|
|
|
|
|
|
|
|
gid = RNA_int_get(op->ptr, "GID");
|
|
|
|
|
|
|
|
|
|
if(gid>0) group= BLI_findlink(&G.main->group, gid-1);
|
|
|
|
|
else if (gid == 0 ) group= add_group( "Group" );
|
|
|
|
|
else return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
|
|
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
|
|
|
|
|
add_to_group(group, base->object);
|
|
|
|
|
base->object->flag |= OB_FROMGROUP;
|
|
|
|
|
base->flag |= OB_FROMGROUP;
|
|
|
|
|
base->object->recalc= OB_RECALC_OB;
|
|
|
|
|
}
|
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
|
|
|
|
DAG_scene_sort(CTX_data_scene(C));
|
|
|
|
|
ED_undo_push(C,"Add to Group");
|
|
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SCENE, CTX_data_scene(C));
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
static int group_create_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Group *group= NULL;
|
|
|
|
|
int tot= BLI_countlist(&G.main->group);
|
|
|
|
|
char *strp= MEM_callocN(tot*32 + 32, "group menu"), *strp1;
|
|
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
/* are there existing groups? */
|
|
|
|
|
for(group= G.main->group.first; group; group= group->id.next)
|
|
|
|
|
if(group->id.lib==NULL)
|
|
|
|
|
break;
|
2009-01-20 03:41:23 +00:00
|
|
|
strp1= strp;
|
|
|
|
|
strp1 += sprintf(strp1, "Add To %%t|");
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
strp1 += sprintf(strp1, "%s %%x%d|", "ADD NEW", 0);
|
|
|
|
|
|
|
|
|
|
for(tot=1, group= G.main->group.first; group; group= group->id.next, tot++) {
|
|
|
|
|
if(group->id.lib==NULL) {
|
|
|
|
|
strp1 += sprintf(strp1, "%s %%x%d|", group->id.name+2, tot);
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 03:41:23 +00:00
|
|
|
uiPupmenuOperator(C, 0, op, "GID", strp);
|
|
|
|
|
MEM_freeN(strp);
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
void GROUP_OT_group_create(wmOperatorType *ot)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
|
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Add Selected to group";
|
|
|
|
|
ot->idname= "GROUP_OT_group_create";
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke = group_create_invoke;
|
|
|
|
|
ot->exec= group_create_exec;
|
|
|
|
|
ot->poll= ED_operator_scene_editable;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2009-01-20 03:41:23 +00:00
|
|
|
RNA_def_int(ot->srna, "GID", 0, INT_MIN, INT_MAX, "Group", "", INT_MIN, INT_MAX);
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
|