/* port over here */
static bContext *C;
-static void set_active_base() {}
static void error_libdata() {}
/* ********************************** */
/* --------------------------------- */
+/* simple API for object selection, rather than just using the flag
+ * this takes into account the 'restrict selection in 3d view' flag.
+ * deselect works always, the restriction just prevents selection */
+
+/* Note: send a NC_SCENE|ND_OB_SELECT notifier yourself! */
+
+void ED_base_object_select(Base *base, short mode)
+{
+ if (base) {
+ if (mode==BA_SELECT) {
+ if (!(base->object->restrictflag & OB_RESTRICT_SELECT))
+ if (mode==BA_SELECT) base->flag |= SELECT;
+ }
+ else if (mode==BA_DESELECT) {
+ base->flag &= ~SELECT;
+ }
+ base->object->flag= base->flag;
+ }
+}
+
+/* also to set active NULL */
+void ED_base_object_activate(bContext *C, Base *base)
+{
+ Scene *scene= CTX_data_scene(C);
+ Base *tbase;
+
+ /* activating a non-mesh, should end a couple of modes... */
+ // if(base && base->object->type!=OB_MESH)
+ // XXX exit_paint_modes();
+
+ /* sets scene->basact */
+ BASACT= base;
+
+ if(base) {
+
+ /* XXX old signals, remember to handle notifiers now! */
+ // allqueue(REDRAWIPO, base->object->ipowin);
+ // select_actionchannel_by_name(base->object->action, "Object", 1);
+
+ /* disable temporal locks */
+ for(tbase=FIRSTBASE; tbase; tbase= tbase->next) {
+ if(base!=tbase && (tbase->object->shapeflag & OB_SHAPE_TEMPLOCK)) {
+ tbase->object->shapeflag &= ~OB_SHAPE_TEMPLOCK;
+ DAG_object_flush_update(scene, tbase->object, OB_RECALC_DATA);
+ }
+ }
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, base->object);
+ }
+ else
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, NULL);
+}
+
+
+
+
/*
* Returns true if the Object is a from an external blend file (libdata)
*/
// XXX if (G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
ob= add_object(type);
- set_active_base(BASACT);
+// ED_base_object_activate(C, BASACT);
base_init_from_view3d(BASACT, v3d);
/* only undo pushes on objects without editmode... */
/* If the original object is active then make this object active */
if (ob == obact) {
- set_active_base( basen );
+ // XXX ED_base_object_activate(C, basen);
basact = basen;
}
}
/* If the original object is active then make this object active */
if (ob == obact) {
- set_active_base( basen );
+ // XXX ED_base_object_activate(C, basen);
basact = basen;
}
// initTransform(TFM_TRANSLATION, CTX_NONE);
// Transform();
}
- set_active_base(BASACT);
+ // XXX ED_base_object_activate(C, BASACT);
if(mode!=2) { /* mode of 2 is used by python to avoid unrequested redraws */
allqueue(REDRAWNLA, 0);
allqueue(REDRAWACTION, 0); /* also oops */
#include "UI_view2d.h"
#include "UI_text.h"
+#include "ED_object.h"
+
#include "outliner_intern.h"
#ifdef INTERNATIONAL
return 0;
}
-static void tree_element_active_object(Scene *scene, SpaceOops *soops, TreeElement *te)
+static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te)
{
TreeStoreElem *tselem= TREESTORE(te);
Scene *sce;
if(base) {
if(shift) {
/* swap select */
- if(base->flag & SELECT) base->flag &= ~SELECT;
- else if ((base->object->restrictflag & OB_RESTRICT_VIEW)==0) base->flag |= SELECT;
- base->object->flag= base->flag;
+ if(base->flag & SELECT)
+ ED_base_object_select(base, BA_DESELECT);
+ else
+ ED_base_object_select(base, BA_SELECT);
}
else {
Base *b;
b->flag &= ~SELECT;
b->object->flag= b->flag;
}
- if ((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
- base->flag |= SELECT;
- base->object->flag |= SELECT;
- }
+ ED_base_object_select(base, BA_SELECT);
}
-// XXX set_active_base(base); /* editview.c */
-
- allqueue(REDRAWVIEW3D, 1);
- allqueue(REDRAWOOPS, 0);
- allqueue(REDRAWINFO, 1);
+ if(C)
+ ED_base_object_activate(C, base); /* adds notifier */
}
// XXX if(ob!=G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
}
/* generic call for non-id data to make/check active in UI */
-static int tree_element_type_active(Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
+/* Context can be NULL when set==0 */
+static int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
{
switch(tselem->type) {
case TSE_MODIFIER:
return tree_element_active_modifier(te, tselem, set);
case TSE_LINKED_OB:
- if(set) tree_element_active_object(scene, soops, te);
+ if(set) tree_element_set_active_object(C, scene, soops, te);
else if(tselem->id==(ID *)OBACT) return 1;
break;
case TSE_LINKED_PSYS:
return 0;
}
-static int do_outliner_mouse_event(Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, short event, float *mval)
+static int do_outliner_mouse_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, short event, float *mval)
{
int shift= 0, ctrl= 0; // XXX
} else {
/* always makes active object */
if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
- tree_element_active_object(scene, soops, te);
+ tree_element_set_active_object(C, scene, soops, te);
if(tselem->type==0) { // the lib blocks
/* editmode? */
}
}
- else tree_element_type_active(scene, soops, te, tselem, 1);
+ else tree_element_type_active(C, scene, soops, te, tselem, 1);
}
}
else if(event==RIGHTMOUSE) {
}
for(te= te->subtree.first; te; te= te->next) {
- if(do_outliner_mouse_event(scene, ar, soops, te, event, mval)) return 1;
+ if(do_outliner_mouse_event(C, scene, ar, soops, te, event, mval)) return 1;
}
return 0;
}
UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
for(te= soops->tree.first; te; te= te->next) {
- if(do_outliner_mouse_event(scene, ar, soops, te, event->type, fmval)) break;
+ if(do_outliner_mouse_event(C, scene, ar, soops, te, event->type, fmval)) break;
}
if(te) {
else if(G.obedit && G.obedit->data==tselem->id) active= 1;
else active= tree_element_active(scene, soops, te, 0);
}
- else active= tree_element_type_active(scene, soops, te, tselem, 0);
+ else active= tree_element_type_active(NULL, scene, soops, te, tselem, 0);
if(active) {
uiSetRoundBox(15);
}
}
else {
- if( tree_element_type_active(scene, soops, te, tselem, 0) ) active= 2;
+ if( tree_element_type_active(NULL, scene, soops, te, tselem, 0) ) active= 2;
glColor4ub(220, 220, 255, 100);
}
char newname[32];
// always make current object active
- tree_element_active_object(scene, soops, te);
+ tree_element_set_active_object(C, scene, soops, te);
ob= OBACT;
/* restore bone name */
char newname[32];
// always make current object active
- tree_element_active_object(scene, soops, te);
+ tree_element_set_active_object(C, scene, soops, te);
ob= OBACT;
/* restore bone name */
#include "RNA_access.h"
#include "RNA_define.h"
+#include "ED_object.h"
#include "ED_screen.h"
#include "ED_types.h"
#endif
}
-/* simple API for object selection, rather than just using the flag
- * this takes into account the 'restrict selection in 3d view' flag.
- * deselect works always, the restriction just prevents selection */
-void select_base_v3d(Base *base, short mode)
-{
- if (base) {
- if (mode==BA_SELECT) {
- if (!(base->object->restrictflag & OB_RESTRICT_SELECT))
- if (mode==BA_SELECT) base->flag |= SELECT;
- }
- else if (mode==BA_DESELECT) {
- base->flag &= ~SELECT;
- }
- base->object->flag= base->flag;
- }
-}
/* *********************** GESTURE AND LASSO ******************* */
project_short(ar, v3d, base->object->obmat[3], &base->sx);
if(lasso_inside(mcords, moves, base->sx, base->sy)) {
- if(select) select_base_v3d(base, BA_SELECT);
- else select_base_v3d(base, BA_DESELECT);
+ if(select) ED_base_object_select(base, BA_SELECT);
+ else ED_base_object_select(base, BA_DESELECT);
base->object->flag= base->flag;
}
if(base->object->flag & OB_POSEMODE) {
/* The max number of menu items in an object select menu */
#define SEL_MENU_SIZE 22
-void set_active_base(Scene *scene, Base *base)
-{
- Base *tbase;
-
- /* activating a non-mesh, should end a couple of modes... */
-// if(base && base->object->type!=OB_MESH)
-// XXX exit_paint_modes();
-
- /* sets scene->basact */
- BASACT= base;
-
- if(base) {
-
- /* signals to buttons */
-// redraw_test_buttons(base->object);
-
- /* signal to ipo */
-// allqueue(REDRAWIPO, base->object->ipowin);
-
-// allqueue(REDRAWACTION, 0);
-// allqueue(REDRAWNLA, 0);
-// allqueue(REDRAWNODE, 0);
-
- /* signal to action */
-// select_actionchannel_by_name(base->object->action, "Object", 1);
-
- /* disable temporal locks */
- for(tbase=FIRSTBASE; tbase; tbase= tbase->next) {
- if(base!=tbase && (tbase->object->shapeflag & OB_SHAPE_TEMPLOCK)) {
- tbase->object->shapeflag &= ~OB_SHAPE_TEMPLOCK;
- DAG_object_flush_update(scene, tbase->object, OB_RECALC_DATA);
- }
- }
- }
-}
-
static void deselectall_except(Scene *scene, Base *b) /* deselect all except b */
{
for(base= FIRSTBASE; base; base= base->next) {
if (base->flag & SELECT) {
if(b!=base) {
- select_base_v3d(base, BA_DESELECT);
+ ED_base_object_select(base, BA_DESELECT);
}
}
}
}
/* mval is region coords */
-static void mouse_select(Scene *scene, ARegion *ar, View3D *v3d, short *mval)
+static void mouse_select(bContext *C, short *mval)
{
+ ARegion *ar= CTX_wm_region(C);
+ View3D *v3d= (View3D *)CTX_wm_space_data(C);
+ Scene *scene= CTX_data_scene(C);
Base *base, *startbase=NULL, *basact=NULL, *oldbasact=NULL;
unsigned int buffer[4*MAXPICKBUF];
int temp, a, dist=100;
/* prevent activating */
basact= NULL;
}
+
+ WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, basact->object);
+ WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, basact->object);
+
}
/* prevent bone selecting to pass on to object selecting */
if(basact==BASACT)
if(G.obedit) {
/* only do select */
deselectall_except(scene, basact);
- select_base_v3d(basact, BA_SELECT);
+ ED_base_object_select(basact, BA_SELECT);
}
/* also prevent making it active on mouse selection */
else if (BASE_SELECTABLE(v3d, basact)) {
if(shift==0) {
deselectall_except(scene, basact);
- select_base_v3d(basact, BA_SELECT);
+ ED_base_object_select(basact, BA_SELECT);
}
else if(shift && alt) {
// XXX select_all_from_groups(basact);
else {
if(basact->flag & SELECT) {
if(basact==oldbasact)
- select_base_v3d(basact, BA_DESELECT);
+ ED_base_object_select(basact, BA_DESELECT);
}
- else select_base_v3d(basact, BA_SELECT);
+ else ED_base_object_select(basact, BA_SELECT);
}
if(oldbasact != basact) {
- set_active_base(scene, basact);
+ ED_base_object_activate(C, basact); /* adds notifier */
}
- /* for visual speed, only in wire mode */
- if(v3d->drawtype==OB_WIRE) {
- /* however, not for posemodes */
-// XXX if(basact->object->flag & OB_POSEMODE);
-// else if(oldbasact && (oldbasact->object->flag & OB_POSEMODE));
-// else {
-// if(oldbasact && oldbasact != basact && (oldbasact->lay & v3d->lay))
-// draw_object_ext(oldbasact);
-// draw_object_ext(basact);
-// }
- }
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
}
}
- /* note; make it notifier! */
- ED_region_tag_redraw(ar);
-
}
/* ******************** border and circle ************************************** */
if (hits>0) { /* no need to loop if there's no hit */
base= FIRSTBASE;
col = vbuffer + 3;
+
while(base && hits) {
Base *next = base->next;
if(base->lay & v3d->lay) {
}
else if(!bone_only) {
if (selecting)
- select_base_v3d(base, BA_SELECT);
+ ED_base_object_select(base, BA_SELECT);
else
- select_base_v3d(base, BA_DESELECT);
+ ED_base_object_select(base, BA_DESELECT);
}
col+=4; /* next color */
base= next;
}
+
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
+
}
MEM_freeN(vbuffer);
}
static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
- ScrArea *sa= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
- View3D *v3d= sa->spacedata.first;
- Scene *scene= CTX_data_scene(C);
short mval[2];
mval[0]= event->x - ar->winrct.xmin;
view3d_operator_needs_opengl(C);
- mouse_select(scene, ar, v3d, mval);
+ mouse_select(C, mval);
return OPERATOR_FINISHED;
}
static int view3d_select_by_type_exec(bContext *C, wmOperator *op)
{
- ARegion *ar= CTX_wm_region(C);
short obtype;
obtype = RNA_enum_get(op->ptr, "type");
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if(base->object->type==obtype) {
- select_base_v3d(base, BA_SELECT);
+ ED_base_object_select(base, BA_SELECT);
}
}
CTX_DATA_END;
/* undo? */
- ED_region_tag_redraw(ar);
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
static int view3d_select_by_layer_exec(bContext *C, wmOperator *op)
{
- ARegion *ar= CTX_wm_region(C);
unsigned int layernum;
layernum = RNA_int_get(op->ptr, "layer");
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if(base->lay == (1<< (layernum -1)))
- select_base_v3d(base, BA_SELECT);
+ ED_base_object_select(base, BA_SELECT);
}
CTX_DATA_END;
/* undo? */
- ED_region_tag_redraw(ar);
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
{
ScrArea *sa= CTX_wm_area(C);
View3D *v3d= sa->spacedata.first;
- ARegion *ar= CTX_wm_region(C);
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if (TESTBASE(v3d, base))
- select_base_v3d(base, BA_DESELECT);
+ ED_base_object_select(base, BA_DESELECT);
else
- select_base_v3d(base, BA_SELECT);
+ ED_base_object_select(base, BA_SELECT);
}
CTX_DATA_END;
/* undo? */
- ED_region_tag_redraw(ar);
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
{
ScrArea *sa= CTX_wm_area(C);
View3D *v3d= sa->spacedata.first;
- ARegion *ar= CTX_wm_region(C);
int a=0, ok=0;
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if (!ok) return OPERATOR_PASS_THROUGH;
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
- if (a) select_base_v3d(base, BA_DESELECT);
- else select_base_v3d(base, BA_SELECT);
+ if (a) ED_base_object_select(base, BA_DESELECT);
+ else ED_base_object_select(base, BA_SELECT);
}
CTX_DATA_END;
/* undo? */
- ED_region_tag_redraw(ar);
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
{
ScrArea *sa= CTX_wm_area(C);
View3D *v3d= sa->spacedata.first;
- ARegion *ar= CTX_wm_region(C);
int percent;
percent = RNA_int_get(op->ptr, "percent");
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if ((!TESTBASE(v3d, base) && (BLI_frand() * 100) < percent)) {
- select_base_v3d(base, BA_SELECT);
+ ED_base_object_select(base, BA_SELECT);
}
}
CTX_DATA_END;
/* undo? */
- ED_region_tag_redraw(ar);
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
// force_draw(0);
}
+/* not a real operator, only for circle test */
static int view3d_circle_select(bContext *C, wmOperator *op)
{
ScrArea *sa= CTX_wm_area(C);
int dx= base->sx-x;
int dy= base->sy-y;
if( dx*dx + dy*dy < radius*radius)
- select_base_v3d(base, BA_SELECT);
+ ED_base_object_select(base, BA_SELECT);
}
}
}
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return 0;
}